1 /* 2 * Copyright (C) 2014 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_HAL_H__ 18 #define __WIFI_HAL_H__ 19 20 #ifdef __cplusplus 21 extern "C" 22 { 23 #endif 24 #include <stdint.h> 25 26 /* WiFi Common definitions */ 27 /* channel operating width */ 28 typedef enum { 29 WIFI_CHAN_WIDTH_20 = 0, 30 WIFI_CHAN_WIDTH_40 = 1, 31 WIFI_CHAN_WIDTH_80 = 2, 32 WIFI_CHAN_WIDTH_160 = 3, 33 WIFI_CHAN_WIDTH_80P80 = 4, 34 WIFI_CHAN_WIDTH_5 = 5, 35 WIFI_CHAN_WIDTH_10 = 6, 36 WIFI_CHAN_WIDTH_INVALID = -1 37 } wifi_channel_width; 38 39 typedef int wifi_radio; 40 typedef int wifi_channel; 41 42 typedef struct { 43 wifi_channel_width width; 44 int center_frequency0; 45 int center_frequency1; 46 int primary_frequency; 47 } wifi_channel_spec; 48 49 typedef enum { 50 WIFI_SUCCESS = 0, 51 WIFI_ERROR_NONE = 0, 52 WIFI_ERROR_UNKNOWN = -1, 53 WIFI_ERROR_UNINITIALIZED = -2, 54 WIFI_ERROR_NOT_SUPPORTED = -3, 55 WIFI_ERROR_NOT_AVAILABLE = -4, // Not available right now, but try later 56 WIFI_ERROR_INVALID_ARGS = -5, 57 WIFI_ERROR_INVALID_REQUEST_ID = -6, 58 WIFI_ERROR_TIMED_OUT = -7, 59 WIFI_ERROR_TOO_MANY_REQUESTS = -8, // Too many instances of this request 60 WIFI_ERROR_OUT_OF_MEMORY = -9 61 } wifi_error; 62 63 typedef unsigned char byte; 64 typedef unsigned char u8; 65 typedef signed char s8; 66 typedef uint16_t u16; 67 typedef uint32_t u32; 68 typedef int32_t s32; 69 typedef uint64_t u64; 70 typedef int64_t s64; 71 typedef int wifi_request_id; 72 typedef int wifi_channel; // indicates channel frequency in MHz 73 typedef int wifi_rssi; 74 typedef byte mac_addr[6]; 75 typedef byte oui[3]; 76 typedef int64_t wifi_timestamp; // In microseconds (us) 77 typedef int64_t wifi_timespan; // In nanoseconds (ns) 78 79 typedef struct wifi_info *wifi_handle; 80 typedef struct wifi_interface_info *wifi_interface_handle; 81 82 /* Initialize/Cleanup */ 83 84 wifi_error wifi_initialize(wifi_handle *handle); 85 typedef void (*wifi_cleaned_up_handler) (wifi_handle handle); 86 void wifi_cleanup(wifi_handle handle, wifi_cleaned_up_handler handler); 87 void wifi_event_loop(wifi_handle handle); 88 89 /* Error handling */ 90 void wifi_get_error_info(wifi_error err, const char **msg); // return a pointer to a static string 91 92 /* Feature enums */ 93 #define WIFI_FEATURE_INFRA 0x0001 // Basic infrastructure mode 94 #define WIFI_FEATURE_INFRA_5G 0x0002 // Support for 5 GHz Band 95 #define WIFI_FEATURE_HOTSPOT 0x0004 // Support for GAS/ANQP 96 #define WIFI_FEATURE_P2P 0x0008 // Wifi-Direct 97 #define WIFI_FEATURE_SOFT_AP 0x0010 // Soft AP 98 #define WIFI_FEATURE_GSCAN 0x0020 // Google-Scan APIs 99 #define WIFI_FEATURE_NAN 0x0040 // Neighbor Awareness Networking 100 #define WIFI_FEATURE_D2D_RTT 0x0080 // Device-to-device RTT 101 #define WIFI_FEATURE_D2AP_RTT 0x0100 // Device-to-AP RTT 102 #define WIFI_FEATURE_BATCH_SCAN 0x0200 // Batched Scan (legacy) 103 #define WIFI_FEATURE_PNO 0x0400 // Preferred network offload 104 #define WIFI_FEATURE_ADDITIONAL_STA 0x0800 // Support for two STAs 105 #define WIFI_FEATURE_TDLS 0x1000 // Tunnel directed link setup 106 #define WIFI_FEATURE_TDLS_OFFCHANNEL 0x2000 // Support for TDLS off channel 107 #define WIFI_FEATURE_EPR 0x4000 // Enhanced power reporting 108 #define WIFI_FEATURE_AP_STA 0x8000 // Support for AP STA Concurrency 109 #define WIFI_FEATURE_LINK_LAYER_STATS 0x10000 // Link layer stats collection 110 #define WIFI_FEATURE_LOGGER 0x20000 // WiFi Logger 111 #define WIFI_FEATURE_HAL_EPNO 0x40000 // WiFi PNO enhanced 112 #define WIFI_FEATURE_RSSI_MONITOR 0x80000 // RSSI Monitor 113 #define WIFI_FEATURE_MKEEP_ALIVE 0x100000 // WiFi mkeep_alive 114 115 // Add more features here 116 117 118 typedef int feature_set; 119 120 #define IS_MASK_SET(mask, flags) ((flags & mask) == mask) 121 #define IS_MASK_RESET(mask, flags) ((flags & mask) == 0) 122 123 #define IS_SUPPORTED_FEATURE(feature, featureSet) IS_MASK_SET(feature, fetureSet) 124 #define IS_UNSUPPORTED_FEATURE(feature, featureSet) IS_MASK_RESET(feature, fetureSet) 125 126 /* Feature set */ 127 wifi_error wifi_get_supported_feature_set(wifi_interface_handle handle, feature_set *set); 128 129 /* 130 * Each row represents a valid feature combination; 131 * all other combinations are invalid! 132 */ 133 wifi_error wifi_get_concurrency_matrix(wifi_interface_handle handle, int set_size_max, 134 feature_set set[], int *set_size); 135 136 /* multiple interface support */ 137 138 wifi_error wifi_get_ifaces(wifi_handle handle, int *num_ifaces, wifi_interface_handle **ifaces); 139 wifi_error wifi_get_iface_name(wifi_interface_handle iface, char *name, size_t size); 140 141 /* Configuration events */ 142 143 typedef struct { 144 void (*on_country_code_changed)(char code[2]); // We can get this from supplicant too 145 146 // More event handlers 147 } wifi_event_handler; 148 149 typedef struct { 150 void (*on_rssi_threshold_breached)(wifi_request_id id, u8 *cur_bssid, s8 cur_rssi); 151 } wifi_rssi_event_handler; 152 153 wifi_error wifi_set_iface_event_handler(wifi_request_id id, wifi_interface_handle iface, wifi_event_handler eh); 154 wifi_error wifi_reset_iface_event_handler(wifi_request_id id, wifi_interface_handle iface); 155 156 wifi_error wifi_set_nodfs_flag(wifi_interface_handle handle, u32 nodfs); 157 158 /* include various feature headers */ 159 160 #include "gscan.h" 161 #include "link_layer_stats.h" 162 #include "rtt.h" 163 #include "tdls.h" 164 #include "wifi_logger.h" 165 #include "wifi_config.h" 166 #include "wifi_nan.h" 167 #include "wifi_offload.h" 168 169 //wifi HAL function pointer table 170 typedef struct { 171 wifi_error (* wifi_initialize) (wifi_handle *); 172 void (* wifi_cleanup) (wifi_handle, wifi_cleaned_up_handler); 173 void (*wifi_event_loop)(wifi_handle); 174 void (* wifi_get_error_info) (wifi_error , const char **); 175 wifi_error (* wifi_get_supported_feature_set) (wifi_interface_handle, feature_set *); 176 wifi_error (* wifi_get_concurrency_matrix) (wifi_interface_handle, int, feature_set *, int *); 177 wifi_error (* wifi_set_scanning_mac_oui) (wifi_interface_handle, unsigned char *); 178 wifi_error (* wifi_get_supported_channels)(wifi_handle, int *, wifi_channel *); 179 wifi_error (* wifi_is_epr_supported)(wifi_handle); 180 wifi_error (* wifi_get_ifaces) (wifi_handle , int *, wifi_interface_handle **); 181 wifi_error (* wifi_get_iface_name) (wifi_interface_handle, char *name, size_t); 182 wifi_error (* wifi_set_iface_event_handler) (wifi_request_id,wifi_interface_handle , 183 wifi_event_handler); 184 wifi_error (* wifi_reset_iface_event_handler) (wifi_request_id, wifi_interface_handle); 185 wifi_error (* wifi_start_gscan) (wifi_request_id, wifi_interface_handle, wifi_scan_cmd_params, 186 wifi_scan_result_handler); 187 wifi_error (* wifi_stop_gscan)(wifi_request_id, wifi_interface_handle); 188 wifi_error (* wifi_get_cached_gscan_results)(wifi_interface_handle, byte, int, 189 wifi_cached_scan_results *, int *); 190 wifi_error (* wifi_set_bssid_hotlist)(wifi_request_id, wifi_interface_handle, 191 wifi_bssid_hotlist_params, wifi_hotlist_ap_found_handler); 192 wifi_error (* wifi_reset_bssid_hotlist)(wifi_request_id, wifi_interface_handle); 193 wifi_error (* wifi_set_significant_change_handler)(wifi_request_id, wifi_interface_handle, 194 wifi_significant_change_params, wifi_significant_change_handler); 195 wifi_error (* wifi_reset_significant_change_handler)(wifi_request_id, wifi_interface_handle); 196 wifi_error (* wifi_get_gscan_capabilities)(wifi_interface_handle, wifi_gscan_capabilities *); 197 wifi_error (* wifi_set_link_stats) (wifi_interface_handle, wifi_link_layer_params); 198 wifi_error (* wifi_get_link_stats) (wifi_request_id,wifi_interface_handle, 199 wifi_stats_result_handler); 200 wifi_error (* wifi_clear_link_stats)(wifi_interface_handle,u32, u32 *, u8, u8 *); 201 wifi_error (* wifi_get_valid_channels)(wifi_interface_handle,int, int, wifi_channel *, int *); 202 wifi_error (* wifi_rtt_range_request)(wifi_request_id, wifi_interface_handle, unsigned, 203 wifi_rtt_config[], wifi_rtt_event_handler); 204 wifi_error (* wifi_rtt_range_cancel)(wifi_request_id, wifi_interface_handle, unsigned, 205 mac_addr[]); 206 wifi_error (* wifi_get_rtt_capabilities)(wifi_interface_handle, wifi_rtt_capabilities *); 207 wifi_error (* wifi_set_nodfs_flag)(wifi_interface_handle, u32); 208 wifi_error (* wifi_start_logging)(wifi_interface_handle, u32, u32, u32, u32, char *); 209 wifi_error (* wifi_set_epno_list)(int, wifi_interface_info *, int, wifi_epno_network *, 210 wifi_epno_handler); 211 wifi_error (* wifi_set_country_code)(wifi_interface_handle, const char *); 212 wifi_error (* wifi_get_firmware_memory_dump)( wifi_interface_handle iface, 213 wifi_firmware_memory_dump_handler handler); 214 wifi_error (* wifi_set_log_handler)(wifi_request_id id, wifi_interface_handle iface, 215 wifi_ring_buffer_data_handler handler); 216 wifi_error (* wifi_reset_log_handler)(wifi_request_id id, wifi_interface_handle iface); 217 wifi_error (* wifi_set_alert_handler)(wifi_request_id id, wifi_interface_handle iface, 218 wifi_alert_handler handler); 219 wifi_error (* wifi_reset_alert_handler)(wifi_request_id id, wifi_interface_handle iface); 220 wifi_error (* wifi_get_firmware_version)(wifi_interface_handle iface, char *buffer, 221 int buffer_size); 222 wifi_error (* wifi_get_ring_buffers_status)(wifi_interface_handle iface, 223 u32 *num_rings, wifi_ring_buffer_status *status); 224 wifi_error (* wifi_get_logger_supported_feature_set)(wifi_interface_handle iface, 225 unsigned int *support); 226 wifi_error (* wifi_get_ring_data)(wifi_interface_handle iface, char *ring_name); 227 wifi_error (* wifi_enable_tdls)(wifi_interface_handle, mac_addr, wifi_tdls_params *, 228 wifi_tdls_handler); 229 wifi_error (* wifi_disable_tdls)(wifi_interface_handle, mac_addr); 230 wifi_error (*wifi_get_tdls_status) (wifi_interface_handle, mac_addr, wifi_tdls_status *); 231 wifi_error (*wifi_get_tdls_capabilities)(wifi_interface_handle iface, 232 wifi_tdls_capabilities *capabilities); 233 wifi_error (* wifi_get_driver_version)(wifi_interface_handle iface, char *buffer, 234 int buffer_size); 235 wifi_error (* wifi_set_passpoint_list)(wifi_request_id id, wifi_interface_handle iface, 236 int num, wifi_passpoint_network *networks, wifi_passpoint_event_handler handler); 237 wifi_error (* wifi_reset_passpoint_list)(wifi_request_id id, wifi_interface_handle iface); 238 wifi_error (*wifi_set_bssid_blacklist)(wifi_request_id id, wifi_interface_handle iface, 239 wifi_bssid_params params); 240 wifi_error (*wifi_enable_lazy_roam)(wifi_request_id id, 241 wifi_interface_handle iface, int enable); 242 wifi_error (*wifi_set_bssid_preference)(wifi_request_id id, wifi_interface_handle iface, 243 int num_bssid, wifi_bssid_preference *prefs); 244 wifi_error (*wifi_set_gscan_roam_params)(wifi_request_id id, wifi_interface_handle iface, 245 wifi_roam_params * params); 246 wifi_error (*wifi_set_ssid_white_list)(wifi_request_id id, wifi_interface_handle iface, 247 int num_networks, wifi_ssid *ssids); 248 wifi_error (*wifi_set_lci) (wifi_request_id id, wifi_interface_handle iface, 249 wifi_lci_information *lci); 250 wifi_error (*wifi_set_lcr) (wifi_request_id id, wifi_interface_handle iface, 251 wifi_lcr_information *lcr); 252 wifi_error (*wifi_start_sending_offloaded_packet)(wifi_request_id id, 253 wifi_interface_handle iface, u8 *ip_packet, u16 ip_packet_len, 254 u8 *src_mac_addr, u8 *dst_mac_addr, u32 period_msec); 255 wifi_error (*wifi_stop_sending_offloaded_packet)(wifi_request_id id, 256 wifi_interface_handle iface); 257 wifi_error (*wifi_start_rssi_monitoring)(wifi_request_id id, wifi_interface_handle 258 iface, s8 max_rssi, s8 min_rssi, wifi_rssi_event_handler eh); 259 wifi_error (*wifi_stop_rssi_monitoring)(wifi_request_id id, wifi_interface_handle iface); 260 } wifi_hal_fn; 261 wifi_error init_wifi_vendor_hal_func_table(wifi_hal_fn *fn); 262 #ifdef __cplusplus 263 } 264 #endif 265 266 #endif 267 268