00001 /* 00002 * Copyright (C) 2008 The Android Open Source Project 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef _WIFI_H 00018 #define _WIFI_H 00019 00020 #if __cplusplus 00021 extern "C" { 00022 #endif 00023 00024 /** 00025 * Load the Wi-Fi driver. 00026 * 00027 * @return 0 on success, < 0 on failure. 00028 */ 00029 int wifi_load_driver(); 00030 00031 /** 00032 * Unload the Wi-Fi driver. 00033 * 00034 * @return 0 on success, < 0 on failure. 00035 */ 00036 int wifi_unload_driver(); 00037 00038 /** 00039 * Start supplicant. 00040 * 00041 * @return 0 on success, < 0 on failure. 00042 */ 00043 int wifi_start_supplicant(); 00044 00045 /** 00046 * Stop supplicant. 00047 * 00048 * @return 0 on success, < 0 on failure. 00049 */ 00050 int wifi_stop_supplicant(); 00051 00052 /** 00053 * Open a connection to supplicant. 00054 * 00055 * @return 0 on success, < 0 on failure. 00056 */ 00057 int wifi_connect_to_supplicant(); 00058 00059 /** 00060 * Close connection supplicant. 00061 * 00062 * @return 0 on success, < 0 on failure. 00063 */ 00064 void wifi_close_supplicant_connection(); 00065 00066 /** 00067 * wifi_wait_for_event() performs a blocking call to 00068 * get a Wi-Fi event and returns a string representing 00069 * a Wi-Fi event when it occurs. 00070 * 00071 * @param buf is the buffer that receives the event 00072 * @param len is the maximum length of the buffer 00073 * 00074 * @returns number of bytes in buffer, 0 if no 00075 * event (for instance, no connection), and less than 0 00076 * if there is an error. 00077 */ 00078 int wifi_wait_for_event(char *buf, size_t len); 00079 00080 /** 00081 * wifi_command() issues a command to the Wi-Fi driver. 00082 * 00083 * Android extends the standard commands listed at 00084 * /link http://hostap.epitest.fi/wpa_supplicant/devel/ctrl_iface_page.html 00085 * to include support for sending commands to the driver: 00086 * 00087 * <table border="2" cellspacing="2" cellpadding="2"> 00088 * <tr> 00089 * <td><strong>Command / Command summary</strong></td> 00090 * <td><strong>Form of Response</strong></td> 00091 * <td><strong>Processing</strong></td> 00092 * </tr> 00093 * <tr> 00094 * <td>DRIVER START<BR> Turn on Wi-Fi Hardware</td> 00095 * <td>OK if successful</td> 00096 * <td>OK ? true : false</td> 00097 * </tr> 00098 * <tr> 00099 * <td>DRIVER STOP<BR> Turn off Wi-Fi hardware</td> 00100 * <td>OK if successful</td> 00101 * <td>OK ? true : false</td> 00102 * </tr> 00103 * <tr> 00104 * <td>DRIVER RSSI<BR> Return received signal strength indicator in -db for current AP</td> 00105 * <td><ssid> Rssi xx</td> 00106 * <td>%*s %*s %d", &rssi</td> 00107 * </tr> 00108 * <tr> 00109 * <td>DRIVER LINKSPEED<BR> Return link speed in MBPS</td> 00110 * <td>LinkSpeed xx</td> 00111 * <td>%*s %d", &linkspd</td> 00112 * </tr> 00113 * <tr> 00114 * <td>DRIVER MACADDR<BR> Return mac address of the station</td> 00115 * <td>Macaddr = xx.xx.xx.xx.xx.xx</td> 00116 * <td>"%*s = %s", &macadr</td> 00117 * </tr> 00118 * <tr> 00119 * <td>DRIVER SCAN-ACTIVE<BR> Set scan type to active</td> 00120 * <td>"OK" if successful</td> 00121 * <td>"OK" ? true : false</td> 00122 * </tr> 00123 * <tr> 00124 * <td>DRIVER SCAN-PASSIVE<BR> Set scan type to passive</td> 00125 * <td>"OK" if successful</td> 00126 * <td>"OK" ? true : false</td> 00127 * </tr> 00128 * </table> 00129 * 00130 * See libs/android_runtime/android_net_wifi_Wifi.cpp for more information 00131 * describing how these and other commands are invoked. 00132 * 00133 * @param command is the string command 00134 * @param reply is a buffer to receive a reply string 00135 * @param reply_len on entry, this is the maximum length of 00136 * the reply buffer. On exit, the number of 00137 * bytes in the reply buffer. 00138 * 00139 * @return 0 if successful, < 0 if an error. 00140 */ 00141 int wifi_command(const char *command, char *reply, size_t *reply_len); 00142 00143 /** 00144 * do_dhcp_request() issues a dhcp request and returns the acquired 00145 * information. 00146 * 00147 * All IPV4 addresses/mask are in network byte order. 00148 * 00149 * @param ipaddr return the assigned IPV4 address 00150 * @param gateway return the gateway being used 00151 * @param mask return the IPV4 mask 00152 * @param dns1 return the IPV4 address of a DNS server 00153 * @param dns2 return the IPV4 address of a DNS server 00154 * @param server return the IPV4 address of DHCP server 00155 * @param lease return the length of lease in seconds. 00156 * 00157 * @return 0 if successful, < 0 if error. 00158 */ 00159 int do_dhcp_request(int *ipaddr, int *gateway, int *mask, 00160 int *dns1, int *dns2, int *server, int *lease); 00161 00162 /** 00163 * Return the error string of the last do_dhcp_request(). 00164 */ 00165 const char *get_dhcp_error_string(); 00166 00167 #if __cplusplus 00168 }; // extern "C" 00169 #endif 00170 00171 #endif // _WIFI_H