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