wifi.h revision 2bb990bfd2580f9be93a413e3a5325057977a828
1/*
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 Wi-Fi driver.
26 *
27 * @return 0 on success, < 0 on failure.
28 */
29int wifi_load_driver();
30
31/**
32 * Unload the Wi-Fi driver.
33 *
34 * @return 0 on success, < 0 on failure.
35 */
36int wifi_unload_driver();
37
38/**
39 * Check if the Wi-Fi driver is loaded.
40 *
41 * @return 0 on success, < 0 on failure.
42 */
43int is_wifi_driver_loaded();
44
45
46/**
47 * Start supplicant.
48 *
49 * @return 0 on success, < 0 on failure.
50 */
51int wifi_start_supplicant();
52
53/**
54 * Stop supplicant.
55 *
56 * @return 0 on success, < 0 on failure.
57 */
58int wifi_stop_supplicant();
59
60/**
61 * Open a connection to supplicant.
62 *
63 * @return 0 on success, < 0 on failure.
64 */
65int wifi_connect_to_supplicant();
66
67/**
68 * Close connection supplicant.
69 *
70 * @return 0 on success, < 0 on failure.
71 */
72void wifi_close_supplicant_connection();
73
74/**
75 * wifi_wait_for_event() performs a blocking call to
76 * get a Wi-Fi event and returns a string representing
77 * a Wi-Fi event when it occurs.
78 *
79 * @param buf is the buffer that receives the event
80 * @param len is the maximum length of the buffer
81 *
82 * @returns number of bytes in buffer, 0 if no
83 * event (for instance, no connection), and less than 0
84 * if there is an error.
85 */
86int wifi_wait_for_event(char *buf, size_t len);
87
88/**
89 * wifi_command() issues a command to the Wi-Fi driver.
90 *
91 * Android extends the standard commands listed at
92 * /link http://hostap.epitest.fi/wpa_supplicant/devel/ctrl_iface_page.html
93 * to include support for sending commands to the driver:
94 *
95 * <table border="2" cellspacing="2" cellpadding="2">
96 *   <tr>
97 *     <td><strong>Command / Command summary</strong></td>
98 *     <td><strong>Form of Response</strong></td>
99 *     <td><strong>Processing</strong></td>
100 *   </tr>
101 *   <tr>
102 *     <td>DRIVER START<BR>&nbsp;&nbsp;Turn on Wi-Fi Hardware</td>
103 *     <td>OK if successful</td>
104 *     <td>OK ? true : false</td>
105 *   </tr>
106 *   <tr>
107 *     <td>DRIVER STOP<BR>&nbsp;&nbsp;Turn off Wi-Fi hardware</td>
108 *     <td>OK if successful</td>
109 *     <td>OK ? true : false</td>
110 *   </tr>
111 *   <tr>
112 *     <td>DRIVER RSSI<BR>&nbsp;&nbsp;Return received signal strength indicator in -db for current AP</td>
113 *     <td>&lt;ssid&gt; Rssi xx</td>
114 *     <td>%*s %*s %d", &rssi</td>
115 *   </tr>
116 *   <tr>
117 *     <td>DRIVER LINKSPEED<BR>&nbsp;&nbsp;Return link speed in MBPS</td>
118 *     <td>LinkSpeed xx</td>
119 *     <td>%*s %d", &linkspd</td>
120 *   </tr>
121 *   <tr>
122 *     <td>DRIVER MACADDR<BR>&nbsp;&nbsp;Return mac address of the station</td>
123 *     <td>Macaddr = xx.xx.xx.xx.xx.xx</td>
124 *     <td>"%*s = %s", &macadr</td>
125 *   </tr>
126 *   <tr>
127 *     <td>DRIVER SCAN-ACTIVE<BR>&nbsp;&nbsp;Set scan type to active</td>
128 *     <td>"OK" if successful</td>
129 *     <td>"OK" ? true : false</td>
130 *   </tr>
131 *   <tr>
132 *     <td>DRIVER SCAN-PASSIVE<BR>&nbsp;&nbsp;Set scan type to passive</td>
133 *     <td>"OK" if successful</td>
134 *     <td>"OK" ? true : false</td>
135 *   </tr>
136 * </table>
137 *
138 * See libs/android_runtime/android_net_wifi_Wifi.cpp for more information
139 * describing how these and other commands are invoked.
140 *
141 * @param command is the string command
142 * @param reply is a buffer to receive a reply string
143 * @param reply_len on entry, this is the maximum length of
144 *        the reply buffer. On exit, the number of
145 *        bytes in the reply buffer.
146 *
147 * @return 0 if successful, < 0 if an error.
148 */
149int wifi_command(const char *command, char *reply, size_t *reply_len);
150
151/**
152 * do_dhcp_request() issues a dhcp request and returns the acquired
153 * information.
154 *
155 * All IPV4 addresses/mask are in network byte order.
156 *
157 * @param ipaddr return the assigned IPV4 address
158 * @param gateway return the gateway being used
159 * @param mask return the IPV4 mask
160 * @param dns1 return the IPV4 address of a DNS server
161 * @param dns2 return the IPV4 address of a DNS server
162 * @param server return the IPV4 address of DHCP server
163 * @param lease return the length of lease in seconds.
164 *
165 * @return 0 if successful, < 0 if error.
166 */
167int do_dhcp_request(int *ipaddr, int *gateway, int *mask,
168                   int *dns1, int *dns2, int *server, int *lease);
169
170/**
171 * Return the error string of the last do_dhcp_request().
172 */
173const char *get_dhcp_error_string();
174
175#if __cplusplus
176};  // extern "C"
177#endif
178
179#endif  // _WIFI_H
180