blob: 0b1acdc14d0bfe3388c500424611b50ead94fe75 [file] [log] [blame]
The Android Open Source Projectd6054a32008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _WIFI_H
18#define _WIFI_H
19
20#if __cplusplus
21extern "C" {
22#endif
23
24/**
25 * Load the wifi driver.
26 *
27 * @return 0 on success, < 0 on failure.
28 */
29int wifi_load_driver();
30
31/**
32 * Unload the wifi driver.
33 *
34 * @return 0 on success, < 0 on failure.
35 */
36int wifi_unload_driver();
37
38/**
39 * Start supplicant.
40 *
41 * @return 0 on success, < 0 on failure.
42 */
43int wifi_start_supplicant();
44
45/**
46 * Stop supplicant.
47 *
48 * @return 0 on success, < 0 on failure.
49 */
50int wifi_stop_supplicant();
51
52/**
53 * Open a connection to supplicant.
54 *
55 * @return 0 on success, < 0 on failure.
56 */
57int wifi_connect_to_supplicant();
58
59/**
60 * Close connection supplicant.
61 *
62 * @return 0 on success, < 0 on failure.
63 */
64void wifi_close_supplicant_connection();
65
66/**
67 * Do a blocking call to get a wifi event and
68 * return a string representing a wifi event
69 * when it occurs.
70 *
71 * @param buf is the buffer that receives the event
72 * @param len is the maximum length of the buffer
73 *
74 * @returns number of bytes in buffer, 0 if no
75 * event, for instance no connection, < 0 if an
76 * error.
77 */
78int wifi_wait_for_event(char *buf, size_t len);
79
80/**
81 * Issue a command to the wifi driver.
82 *
83 * see \link http://hostap.epitest.fi/wpa_supplicant/devel/ctrl_iface_page.html
84 * for the list of the standard commands. Android has extended these to include
85 * support for sending commands to the driver:
86 *
87 *------------------------------------------------------------------------------
88 * command form of response processing
89 * Summary of the command
90 *------------------------------------------------------------------------------
91 * "DRIVER START" -> "OK" if successful -> "OK" ? true : false
92 * Turn on WiFi Hardware
93 *
94 * "DRIVER STOP" -> "OK" if successful -> "OK" ? true : false
95 * Turn off WiFi Hardware
96 *
97 * "DRIVER RSSI" -> "<ssid> Rssi xx" -> "%*s %*s %d", &rssi
98 * Return received signal strength indicator in -db for current AP
99 *
100 * "DRIVER LINKSPEED" -> "LinkSpeed xx" -> "%*s %d", &linkspd
101 * Return link speed in MBPS
102 *
103 * "DRIVER MACADDR" -> "Macaddr = xx.xx.xx.xx.xx.xx" -> "%*s = %s", &macadr
104 * Return mac address of the station
105 *
106 * "DRIVER SCAN-ACTIVE" -> "OK" if successful -> "OK" ? true : false
107 * Set scan type to active
108 *
109 * "DRIVER SCAN-PASSIVE" -> "OK" if successful -> "OK" ? true : false
110 * Set scan type to passive
111 *------------------------------------------------------------------------------
112 *
113 * See libs/android_runtime/android_net_wifi_Wifi.cpp for more information
114 * on how these and other commands invoked.
115 *
116 * @param command is the string command
117 * @param reply is a buffer to receive a reply string
118 * @param reply_len on entry is the maximum length of
119 * reply buffer and on exit the number of
120 * bytes in the reply buffer.
121 *
122 * @return 0 if successful, < 0 if an error.
123 */
124int wifi_command(const char *command, char *reply, size_t *reply_len);
125
126/**
127 * Issues a dhcp request returning the acquired
128 * information. All IPV4 addresses/mask are in
129 * network byte order.
130 *
131 * @param ipaddr return the assigned IPV4 address
132 * @param gateway return the gateway being used
133 * @param mask return the IPV4 mask
134 * @param dns1 return the IPV4 address of a dns server
135 * @param dns2 return the IPV4 address of a dns server
136 * @param serverAddress return the IPV4 address of dhcp server
137 * @param lease return the length of lease in seconds.
138 *
139 * @return 0 if successful, < 0 if error.
140 */
141int do_dhcp_request(int *ipaddr, int *gateway, int *mask,
142 int *dns1, int *dns2, int *server, int *lease);
143
144/**
145 * Return the error string of the last do_dhcp_request.
146 */
147const char *get_dhcp_error_string();
148
149#if __cplusplus
150}; // extern "C"
151#endif
152
153#endif // _WIFI_H