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 * Check if the Wi-Fi driver is loaded. 41 42 * @return 0 on success, < 0 on failure. 43 */ 44 int is_wifi_driver_loaded(); 45 46 47 /** 48 * Start supplicant. 49 * 50 * @return 0 on success, < 0 on failure. 51 */ 52 int wifi_start_supplicant(int p2pSupported); 53 54 /** 55 * Stop supplicant. 56 * 57 * @return 0 on success, < 0 on failure. 58 */ 59 int wifi_stop_supplicant(int p2pSupported); 60 61 /** 62 * Open a connection to supplicant 63 * 64 * @return 0 on success, < 0 on failure. 65 */ 66 int wifi_connect_to_supplicant(); 67 68 /** 69 * Close connection to supplicant 70 * 71 * @return 0 on success, < 0 on failure. 72 */ 73 void wifi_close_supplicant_connection(); 74 75 /** 76 * wifi_wait_for_event() performs a blocking call to 77 * get a Wi-Fi event and returns a string representing 78 * a Wi-Fi event when it occurs. 79 * 80 * @param buf is the buffer that receives the event 81 * @param len is the maximum length of the buffer 82 * 83 * @returns number of bytes in buffer, 0 if no 84 * event (for instance, no connection), and less than 0 85 * if there is an error. 86 */ 87 int wifi_wait_for_event(char *buf, size_t len); 88 89 /** 90 * wifi_command() issues a command to the Wi-Fi driver. 91 * 92 * Android extends the standard commands listed at 93 * /link http://hostap.epitest.fi/wpa_supplicant/devel/ctrl_iface_page.html 94 * to include support for sending commands to the driver: 95 * 96 * See wifi/java/android/net/wifi/WifiNative.java for the details of 97 * driver commands that are supported 98 * 99 * @param command is the string command (preallocated with 32 bytes) 100 * @param commandlen is command buffer length 101 * @param reply is a buffer to receive a reply string 102 * @param reply_len on entry, this is the maximum length of 103 * the reply buffer. On exit, the number of 104 * bytes in the reply buffer. 105 * 106 * @return 0 if successful, < 0 if an error. 107 */ 108 int wifi_command(const char *command, char *reply, size_t *reply_len); 109 110 /** 111 * do_dhcp_request() issues a dhcp request and returns the acquired 112 * information. 113 * 114 * All IPV4 addresses/mask are in network byte order. 115 * 116 * @param ipaddr return the assigned IPV4 address 117 * @param gateway return the gateway being used 118 * @param mask return the IPV4 mask 119 * @param dns1 return the IPV4 address of a DNS server 120 * @param dns2 return the IPV4 address of a DNS server 121 * @param server return the IPV4 address of DHCP server 122 * @param lease return the length of lease in seconds. 123 * 124 * @return 0 if successful, < 0 if error. 125 */ 126 int do_dhcp_request(int *ipaddr, int *gateway, int *mask, 127 int *dns1, int *dns2, int *server, int *lease); 128 129 /** 130 * Return the error string of the last do_dhcp_request(). 131 */ 132 const char *get_dhcp_error_string(); 133 134 /** 135 * Return the path to requested firmware 136 */ 137 #define WIFI_GET_FW_PATH_STA 0 138 #define WIFI_GET_FW_PATH_AP 1 139 #define WIFI_GET_FW_PATH_P2P 2 140 const char *wifi_get_fw_path(int fw_type); 141 142 /** 143 * Change the path to firmware for the wlan driver 144 */ 145 int wifi_change_fw_path(const char *fwpath); 146 147 /** 148 * Check and create if necessary initial entropy file 149 */ 150 #define WIFI_ENTROPY_FILE "/data/misc/wifi/entropy.bin" 151 int ensure_entropy_file_exists(); 152 153 #if __cplusplus 154 }; // extern "C" 155 #endif 156 157 #endif // _WIFI_H 158