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