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 */ 43 int is_wifi_driver_loaded(); 44 45 46 /** 47 * Start supplicant. 48 * 49 * @return 0 on success, < 0 on failure. 50 */ 51 int wifi_start_supplicant(int p2pSupported); 52 53 /** 54 * Stop supplicant. 55 * 56 * @return 0 on success, < 0 on failure. 57 */ 58 int wifi_stop_supplicant(int p2pSupported); 59 60 /** 61 * Open a connection to supplicant 62 * 63 * @return 0 on success, < 0 on failure. 64 */ 65 int wifi_connect_to_supplicant(); 66 67 /** 68 * Close connection to supplicant 69 * 70 * @return 0 on success, < 0 on failure. 71 */ 72 void 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 */ 86 int 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 * See wifi/java/android/net/wifi/WifiNative.java for the details of 96 * driver commands that are supported 97 * 98 * @param command is the string command (preallocated with 32 bytes) 99 * @param commandlen is command buffer length 100 * @param reply is a buffer to receive a reply string 101 * @param reply_len on entry, this is the maximum length of 102 * the reply buffer. On exit, the number of 103 * bytes in the reply buffer. 104 * 105 * @return 0 if successful, < 0 if an error. 106 */ 107 int wifi_command(const char *command, char *reply, size_t *reply_len); 108 109 /** 110 * do_dhcp_request() issues a dhcp request and returns the acquired 111 * information. 112 * 113 * All IPV4 addresses/mask are in network byte order. 114 * 115 * @param ipaddr return the assigned IPV4 address 116 * @param gateway return the gateway being used 117 * @param mask return the IPV4 mask 118 * @param dns1 return the IPV4 address of a DNS server 119 * @param dns2 return the IPV4 address of a DNS server 120 * @param server return the IPV4 address of DHCP server 121 * @param lease return the length of lease in seconds. 122 * 123 * @return 0 if successful, < 0 if error. 124 */ 125 int do_dhcp_request(int *ipaddr, int *gateway, int *mask, 126 int *dns1, int *dns2, int *server, int *lease); 127 128 /** 129 * Return the error string of the last do_dhcp_request(). 130 */ 131 const char *get_dhcp_error_string(); 132 133 /** 134 * Return the path to requested firmware 135 */ 136 #define WIFI_GET_FW_PATH_STA 0 137 #define WIFI_GET_FW_PATH_AP 1 138 #define WIFI_GET_FW_PATH_P2P 2 139 const char *wifi_get_fw_path(int fw_type); 140 141 /** 142 * Change the path to firmware for the wlan driver 143 */ 144 int wifi_change_fw_path(const char *fwpath); 145 146 /** 147 * Check and create if necessary initial entropy file 148 */ 149 #define WIFI_ENTROPY_FILE "/data/misc/wifi/entropy.bin" 150 int ensure_entropy_file_exists(); 151 152 #if __cplusplus 153 }; // extern "C" 154 #endif 155 156 #endif // _WIFI_H 157