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