wifi.h revision 29a4d4d74b512e450a7d2ae97d4222c24a13b87e
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> 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> 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> Return received signal strength indicator in -db for current AP</td> 113 * <td><ssid> Rssi xx</td> 114 * <td>%*s %*s %d", &rssi</td> 115 * </tr> 116 * <tr> 117 * <td>DRIVER LINKSPEED<BR> 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> 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> 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> 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/** 176 * Return the path to requested firmware 177 */ 178#define WIFI_GET_FW_PATH_STA 0 179#define WIFI_GET_FW_PATH_AP 1 180#define WIFI_GET_FW_PATH_P2P 2 181const char *wifi_get_fw_path(int fw_type); 182 183/** 184 * Change the path to firmware for the wlan driver 185 */ 186int wifi_change_fw_path(const char *fwpath); 187 188#if __cplusplus 189}; // extern "C" 190#endif 191 192#endif // _WIFI_H 193