1 /* 2 * Copyright (C) 2016 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 /* Pre selected Power scenarios to be applied from BDF file */ 40 typedef enum { 41 WIFI_POWER_SCENARIO_VOICE_CALL = 0, 42 } wifi_power_scenario; 43 44 typedef int wifi_radio; 45 typedef int wifi_channel; 46 47 typedef struct { 48 wifi_channel_width width; 49 int center_frequency0; 50 int center_frequency1; 51 int primary_frequency; 52 } wifi_channel_spec; 53 54 typedef enum { 55 WIFI_SUCCESS = 0, 56 WIFI_ERROR_NONE = 0, 57 WIFI_ERROR_UNKNOWN = -1, 58 WIFI_ERROR_UNINITIALIZED = -2, 59 WIFI_ERROR_NOT_SUPPORTED = -3, 60 WIFI_ERROR_NOT_AVAILABLE = -4, // Not available right now, but try later 61 WIFI_ERROR_INVALID_ARGS = -5, 62 WIFI_ERROR_INVALID_REQUEST_ID = -6, 63 WIFI_ERROR_TIMED_OUT = -7, 64 WIFI_ERROR_TOO_MANY_REQUESTS = -8, // Too many instances of this request 65 WIFI_ERROR_OUT_OF_MEMORY = -9, 66 WIFI_ERROR_BUSY = -10, 67 } wifi_error; 68 69 typedef unsigned char byte; 70 typedef unsigned char u8; 71 typedef signed char s8; 72 typedef uint16_t u16; 73 typedef uint32_t u32; 74 typedef int32_t s32; 75 typedef uint64_t u64; 76 typedef int64_t s64; 77 typedef int wifi_request_id; 78 typedef int wifi_channel; // indicates channel frequency in MHz 79 typedef int wifi_rssi; 80 typedef byte mac_addr[6]; 81 typedef byte oui[3]; 82 typedef int64_t wifi_timestamp; // In microseconds (us) 83 typedef int64_t wifi_timespan; // In picoseconds (ps) 84 85 struct wifi_info; 86 struct wifi_interface_info; 87 typedef struct wifi_info *wifi_handle; 88 typedef struct wifi_interface_info *wifi_interface_handle; 89 90 /* Initialize/Cleanup */ 91 92 wifi_error wifi_initialize(wifi_handle *handle); 93 typedef void (*wifi_cleaned_up_handler) (wifi_handle handle); 94 void wifi_cleanup(wifi_handle handle, wifi_cleaned_up_handler handler); 95 void wifi_event_loop(wifi_handle handle); 96 97 /* Error handling */ 98 void wifi_get_error_info(wifi_error err, const char **msg); // return a pointer to a static string 99 100 /* Feature enums */ 101 #define WIFI_FEATURE_INFRA 0x0001 // Basic infrastructure mode 102 #define WIFI_FEATURE_INFRA_5G 0x0002 // Support for 5 GHz Band 103 #define WIFI_FEATURE_HOTSPOT 0x0004 // Support for GAS/ANQP 104 #define WIFI_FEATURE_P2P 0x0008 // Wifi-Direct 105 #define WIFI_FEATURE_SOFT_AP 0x0010 // Soft AP 106 #define WIFI_FEATURE_GSCAN 0x0020 // Google-Scan APIs 107 #define WIFI_FEATURE_NAN 0x0040 // Neighbor Awareness Networking 108 #define WIFI_FEATURE_D2D_RTT 0x0080 // Device-to-device RTT 109 #define WIFI_FEATURE_D2AP_RTT 0x0100 // Device-to-AP RTT 110 #define WIFI_FEATURE_BATCH_SCAN 0x0200 // Batched Scan (legacy) 111 #define WIFI_FEATURE_PNO 0x0400 // Preferred network offload 112 #define WIFI_FEATURE_ADDITIONAL_STA 0x0800 // Support for two STAs 113 #define WIFI_FEATURE_TDLS 0x1000 // Tunnel directed link setup 114 #define WIFI_FEATURE_TDLS_OFFCHANNEL 0x2000 // Support for TDLS off channel 115 #define WIFI_FEATURE_EPR 0x4000 // Enhanced power reporting 116 #define WIFI_FEATURE_AP_STA 0x8000 // Support for AP STA Concurrency 117 #define WIFI_FEATURE_LINK_LAYER_STATS 0x10000 // Link layer stats collection 118 #define WIFI_FEATURE_LOGGER 0x20000 // WiFi Logger 119 #define WIFI_FEATURE_HAL_EPNO 0x40000 // WiFi PNO enhanced 120 #define WIFI_FEATURE_RSSI_MONITOR 0x80000 // RSSI Monitor 121 #define WIFI_FEATURE_MKEEP_ALIVE 0x100000 // WiFi mkeep_alive 122 #define WIFI_FEATURE_CONFIG_NDO 0x200000 // ND offload configure 123 #define WIFI_FEATURE_TX_TRANSMIT_POWER 0x400000 // Capture Tx transmit power levels 124 #define WIFI_FEATURE_CONTROL_ROAMING 0x800000 // Enable/Disable firmware roaming 125 #define WIFI_FEATURE_IE_WHITELIST 0x1000000 // Support Probe IE white listing 126 #define WIFI_FEATURE_SCAN_RAND 0x2000000 // Support MAC & Probe Sequence Number randomization 127 #define WIFI_FEATURE_SET_TX_POWER_LIMIT 0x4000000 // Support Tx Power Limit setting 128 // Add more features here 129 130 131 typedef int feature_set; 132 133 #define IS_MASK_SET(mask, flags) (((flags) & (mask)) == (mask)) 134 135 #define IS_SUPPORTED_FEATURE(feature, featureSet) IS_MASK_SET(feature, featureSet) 136 137 /* Feature set */ 138 wifi_error wifi_get_supported_feature_set(wifi_interface_handle handle, feature_set *set); 139 140 /* 141 * Each row represents a valid feature combination; 142 * all other combinations are invalid! 143 */ 144 wifi_error wifi_get_concurrency_matrix(wifi_interface_handle handle, int set_size_max, 145 feature_set set[], int *set_size); 146 147 /* multiple interface support */ 148 149 wifi_error wifi_get_ifaces(wifi_handle handle, int *num_ifaces, wifi_interface_handle **ifaces); 150 wifi_error wifi_get_iface_name(wifi_interface_handle iface, char *name, size_t size); 151 wifi_interface_handle wifi_get_iface_handle(wifi_handle handle, char *name); 152 153 /* Configuration events */ 154 155 typedef struct { 156 void (*on_country_code_changed)(char code[2]); // We can get this from supplicant too 157 158 // More event handlers 159 } wifi_event_handler; 160 161 typedef struct { 162 void (*on_rssi_threshold_breached)(wifi_request_id id, u8 *cur_bssid, s8 cur_rssi); 163 } wifi_rssi_event_handler; 164 165 wifi_error wifi_set_iface_event_handler(wifi_request_id id, wifi_interface_handle iface, wifi_event_handler eh); 166 wifi_error wifi_reset_iface_event_handler(wifi_request_id id, wifi_interface_handle iface); 167 168 wifi_error wifi_set_nodfs_flag(wifi_interface_handle handle, u32 nodfs); 169 wifi_error wifi_select_tx_power_scenario(wifi_interface_handle handle, wifi_power_scenario scenario); 170 wifi_error wifi_reset_tx_power_scenario(wifi_interface_handle handle); 171 172 typedef struct rx_data_cnt_details_t { 173 int rx_unicast_cnt; /*Total rx unicast packet which woke up host */ 174 int rx_multicast_cnt; /*Total rx multicast packet which woke up host */ 175 int rx_broadcast_cnt; /*Total rx broadcast packet which woke up host */ 176 } RX_DATA_WAKE_CNT_DETAILS; 177 178 typedef struct rx_wake_pkt_type_classification_t { 179 int icmp_pkt; /*wake icmp packet count */ 180 int icmp6_pkt; /*wake icmp6 packet count */ 181 int icmp6_ra; /*wake icmp6 RA packet count */ 182 int icmp6_na; /*wake icmp6 NA packet count */ 183 int icmp6_ns; /*wake icmp6 NS packet count */ 184 //ToDo: Any more interesting classification to add? 185 } RX_WAKE_PKT_TYPE_CLASSFICATION; 186 187 typedef struct rx_multicast_cnt_t{ 188 int ipv4_rx_multicast_addr_cnt; /*Rx wake packet was ipv4 multicast */ 189 int ipv6_rx_multicast_addr_cnt; /*Rx wake packet was ipv6 multicast */ 190 int other_rx_multicast_addr_cnt;/*Rx wake packet was non-ipv4 and non-ipv6*/ 191 } RX_MULTICAST_WAKE_DATA_CNT; 192 193 /* 194 * Structure holding all the driver/firmware wake count reasons. 195 * 196 * Buffers for the array fields (cmd_event_wake_cnt/driver_fw_local_wake_cnt) 197 * are allocated and freed by the framework. The size of each allocated 198 * array is indicated by the corresponding |_cnt| field. HAL needs to fill in 199 * the corresponding |_used| field to indicate the number of elements used in 200 * the array. 201 */ 202 typedef struct wlan_driver_wake_reason_cnt_t { 203 int total_cmd_event_wake; /* Total count of cmd event wakes */ 204 int *cmd_event_wake_cnt; /* Individual wake count array, each index a reason */ 205 int cmd_event_wake_cnt_sz; /* Max number of cmd event wake reasons */ 206 int cmd_event_wake_cnt_used; /* Number of cmd event wake reasons specific to the driver */ 207 208 int total_driver_fw_local_wake; /* Total count of drive/fw wakes, for local reasons */ 209 int *driver_fw_local_wake_cnt; /* Individual wake count array, each index a reason */ 210 int driver_fw_local_wake_cnt_sz; /* Max number of local driver/fw wake reasons */ 211 int driver_fw_local_wake_cnt_used; /* Number of local driver/fw wake reasons specific to the driver */ 212 213 int total_rx_data_wake; /* total data rx packets, that woke up host */ 214 RX_DATA_WAKE_CNT_DETAILS rx_wake_details; 215 RX_WAKE_PKT_TYPE_CLASSFICATION rx_wake_pkt_classification_info; 216 RX_MULTICAST_WAKE_DATA_CNT rx_multicast_wake_pkt_info; 217 } WLAN_DRIVER_WAKE_REASON_CNT; 218 219 /* include various feature headers */ 220 221 #include "gscan.h" 222 #include "link_layer_stats.h" 223 #include "rtt.h" 224 #include "tdls.h" 225 #include "wifi_logger.h" 226 #include "wifi_config.h" 227 #include "wifi_nan.h" 228 #include "wifi_offload.h" 229 #include "roam.h" 230 231 //wifi HAL function pointer table 232 typedef struct { 233 wifi_error (* wifi_initialize) (wifi_handle *); 234 void (* wifi_cleanup) (wifi_handle, wifi_cleaned_up_handler); 235 void (*wifi_event_loop)(wifi_handle); 236 void (* wifi_get_error_info) (wifi_error , const char **); 237 wifi_error (* wifi_get_supported_feature_set) (wifi_interface_handle, feature_set *); 238 wifi_error (* wifi_get_concurrency_matrix) (wifi_interface_handle, int, feature_set *, int *); 239 wifi_error (* wifi_set_scanning_mac_oui) (wifi_interface_handle, unsigned char *); 240 wifi_error (* wifi_get_supported_channels)(wifi_handle, int *, wifi_channel *); 241 wifi_error (* wifi_is_epr_supported)(wifi_handle); 242 wifi_error (* wifi_get_ifaces) (wifi_handle , int *, wifi_interface_handle **); 243 wifi_error (* wifi_get_iface_name) (wifi_interface_handle, char *name, size_t); 244 wifi_error (* wifi_set_iface_event_handler) (wifi_request_id,wifi_interface_handle , 245 wifi_event_handler); 246 wifi_error (* wifi_reset_iface_event_handler) (wifi_request_id, wifi_interface_handle); 247 wifi_error (* wifi_start_gscan) (wifi_request_id, wifi_interface_handle, wifi_scan_cmd_params, 248 wifi_scan_result_handler); 249 wifi_error (* wifi_stop_gscan)(wifi_request_id, wifi_interface_handle); 250 wifi_error (* wifi_get_cached_gscan_results)(wifi_interface_handle, byte, int, 251 wifi_cached_scan_results *, int *); 252 wifi_error (* wifi_set_bssid_hotlist)(wifi_request_id, wifi_interface_handle, 253 wifi_bssid_hotlist_params, wifi_hotlist_ap_found_handler); 254 wifi_error (* wifi_reset_bssid_hotlist)(wifi_request_id, wifi_interface_handle); 255 wifi_error (* wifi_set_significant_change_handler)(wifi_request_id, wifi_interface_handle, 256 wifi_significant_change_params, wifi_significant_change_handler); 257 wifi_error (* wifi_reset_significant_change_handler)(wifi_request_id, wifi_interface_handle); 258 wifi_error (* wifi_get_gscan_capabilities)(wifi_interface_handle, wifi_gscan_capabilities *); 259 wifi_error (* wifi_set_link_stats) (wifi_interface_handle, wifi_link_layer_params); 260 wifi_error (* wifi_get_link_stats) (wifi_request_id,wifi_interface_handle, 261 wifi_stats_result_handler); 262 wifi_error (* wifi_clear_link_stats)(wifi_interface_handle,u32, u32 *, u8, u8 *); 263 wifi_error (* wifi_get_valid_channels)(wifi_interface_handle,int, int, wifi_channel *, int *); 264 wifi_error (* wifi_rtt_range_request)(wifi_request_id, wifi_interface_handle, unsigned, 265 wifi_rtt_config[], wifi_rtt_event_handler); 266 wifi_error (* wifi_rtt_range_cancel)(wifi_request_id, wifi_interface_handle, unsigned, 267 mac_addr[]); 268 wifi_error (* wifi_get_rtt_capabilities)(wifi_interface_handle, wifi_rtt_capabilities *); 269 wifi_error (* wifi_rtt_get_responder_info)(wifi_interface_handle iface, 270 wifi_rtt_responder *responder_info); 271 wifi_error (* wifi_enable_responder)(wifi_request_id id, wifi_interface_handle iface, 272 wifi_channel_info channel_hint, unsigned max_duration_seconds, 273 wifi_rtt_responder *responder_info); 274 wifi_error (* wifi_disable_responder)(wifi_request_id id, wifi_interface_handle iface); 275 wifi_error (* wifi_set_nodfs_flag)(wifi_interface_handle, u32); 276 wifi_error (* wifi_start_logging)(wifi_interface_handle, u32, u32, u32, u32, char *); 277 wifi_error (* wifi_set_epno_list)(wifi_request_id, wifi_interface_handle, 278 const wifi_epno_params *, wifi_epno_handler); 279 wifi_error (* wifi_reset_epno_list)(wifi_request_id, wifi_interface_handle); 280 wifi_error (* wifi_set_country_code)(wifi_interface_handle, const char *); 281 wifi_error (* wifi_get_firmware_memory_dump)( wifi_interface_handle iface, 282 wifi_firmware_memory_dump_handler handler); 283 wifi_error (* wifi_set_log_handler)(wifi_request_id id, wifi_interface_handle iface, 284 wifi_ring_buffer_data_handler handler); 285 wifi_error (* wifi_reset_log_handler)(wifi_request_id id, wifi_interface_handle iface); 286 wifi_error (* wifi_set_alert_handler)(wifi_request_id id, wifi_interface_handle iface, 287 wifi_alert_handler handler); 288 wifi_error (* wifi_reset_alert_handler)(wifi_request_id id, wifi_interface_handle iface); 289 wifi_error (* wifi_get_firmware_version)(wifi_interface_handle iface, char *buffer, 290 int buffer_size); 291 wifi_error (* wifi_get_ring_buffers_status)(wifi_interface_handle iface, 292 u32 *num_rings, wifi_ring_buffer_status *status); 293 wifi_error (* wifi_get_logger_supported_feature_set)(wifi_interface_handle iface, 294 unsigned int *support); 295 wifi_error (* wifi_get_ring_data)(wifi_interface_handle iface, char *ring_name); 296 wifi_error (* wifi_enable_tdls)(wifi_interface_handle, mac_addr, wifi_tdls_params *, 297 wifi_tdls_handler); 298 wifi_error (* wifi_disable_tdls)(wifi_interface_handle, mac_addr); 299 wifi_error (*wifi_get_tdls_status) (wifi_interface_handle, mac_addr, wifi_tdls_status *); 300 wifi_error (*wifi_get_tdls_capabilities)(wifi_interface_handle iface, 301 wifi_tdls_capabilities *capabilities); 302 wifi_error (* wifi_get_driver_version)(wifi_interface_handle iface, char *buffer, 303 int buffer_size); 304 wifi_error (* wifi_set_passpoint_list)(wifi_request_id id, wifi_interface_handle iface, 305 int num, wifi_passpoint_network *networks, wifi_passpoint_event_handler handler); 306 wifi_error (* wifi_reset_passpoint_list)(wifi_request_id id, wifi_interface_handle iface); 307 wifi_error (*wifi_set_lci) (wifi_request_id id, wifi_interface_handle iface, 308 wifi_lci_information *lci); 309 wifi_error (*wifi_set_lcr) (wifi_request_id id, wifi_interface_handle iface, 310 wifi_lcr_information *lcr); 311 wifi_error (*wifi_start_sending_offloaded_packet)(wifi_request_id id, 312 wifi_interface_handle iface, u8 *ip_packet, u16 ip_packet_len, 313 u8 *src_mac_addr, u8 *dst_mac_addr, u32 period_msec); 314 wifi_error (*wifi_stop_sending_offloaded_packet)(wifi_request_id id, 315 wifi_interface_handle iface); 316 wifi_error (*wifi_start_rssi_monitoring)(wifi_request_id id, wifi_interface_handle 317 iface, s8 max_rssi, s8 min_rssi, wifi_rssi_event_handler eh); 318 wifi_error (*wifi_stop_rssi_monitoring)(wifi_request_id id, wifi_interface_handle iface); 319 wifi_error (*wifi_get_wake_reason_stats)(wifi_interface_handle iface, 320 WLAN_DRIVER_WAKE_REASON_CNT *wifi_wake_reason_cnt); 321 wifi_error (*wifi_configure_nd_offload)(wifi_interface_handle iface, u8 enable); 322 wifi_error (*wifi_get_driver_memory_dump)(wifi_interface_handle iface, 323 wifi_driver_memory_dump_callbacks callbacks); 324 wifi_error (*wifi_start_pkt_fate_monitoring)(wifi_interface_handle iface); 325 wifi_error (*wifi_get_tx_pkt_fates)(wifi_interface_handle handle, 326 wifi_tx_report *tx_report_bufs, 327 size_t n_requested_fates, 328 size_t *n_provided_fates); 329 wifi_error (*wifi_get_rx_pkt_fates)(wifi_interface_handle handle, 330 wifi_rx_report *rx_report_bufs, 331 size_t n_requested_fates, 332 size_t *n_provided_fates); 333 334 /* NAN functions */ 335 wifi_error (*wifi_nan_enable_request)(transaction_id id, 336 wifi_interface_handle iface, 337 NanEnableRequest* msg); 338 wifi_error (*wifi_nan_disable_request)(transaction_id id, 339 wifi_interface_handle iface); 340 wifi_error (*wifi_nan_publish_request)(transaction_id id, 341 wifi_interface_handle iface, 342 NanPublishRequest* msg); 343 wifi_error (*wifi_nan_publish_cancel_request)(transaction_id id, 344 wifi_interface_handle iface, 345 NanPublishCancelRequest* msg); 346 wifi_error (*wifi_nan_subscribe_request)(transaction_id id, 347 wifi_interface_handle iface, 348 NanSubscribeRequest* msg); 349 wifi_error (*wifi_nan_subscribe_cancel_request)(transaction_id id, 350 wifi_interface_handle iface, 351 NanSubscribeCancelRequest* msg); 352 wifi_error (*wifi_nan_transmit_followup_request)(transaction_id id, 353 wifi_interface_handle iface, 354 NanTransmitFollowupRequest* msg); 355 wifi_error (*wifi_nan_stats_request)(transaction_id id, 356 wifi_interface_handle iface, 357 NanStatsRequest* msg); 358 wifi_error (*wifi_nan_config_request)(transaction_id id, 359 wifi_interface_handle iface, 360 NanConfigRequest* msg); 361 wifi_error (*wifi_nan_tca_request)(transaction_id id, 362 wifi_interface_handle iface, 363 NanTCARequest* msg); 364 wifi_error (*wifi_nan_beacon_sdf_payload_request)(transaction_id id, 365 wifi_interface_handle iface, 366 NanBeaconSdfPayloadRequest* msg); 367 wifi_error (*wifi_nan_register_handler)(wifi_interface_handle iface, 368 NanCallbackHandler handlers); 369 wifi_error (*wifi_nan_get_version)(wifi_handle handle, 370 NanVersion* version); 371 wifi_error (*wifi_nan_get_capabilities)(transaction_id id, 372 wifi_interface_handle iface); 373 wifi_error (*wifi_nan_data_interface_create)(transaction_id id, 374 wifi_interface_handle iface, 375 char *iface_name); 376 wifi_error (*wifi_nan_data_interface_delete)(transaction_id id, 377 wifi_interface_handle iface, 378 char *iface_name); 379 wifi_error (*wifi_nan_data_request_initiator)( 380 transaction_id id, wifi_interface_handle iface, 381 NanDataPathInitiatorRequest *msg); 382 wifi_error (*wifi_nan_data_indication_response)( 383 transaction_id id, wifi_interface_handle iface, 384 NanDataPathIndicationResponse *msg); 385 wifi_error (*wifi_nan_data_end)(transaction_id id, 386 wifi_interface_handle iface, 387 NanDataPathEndRequest *msg); 388 wifi_error (*wifi_select_tx_power_scenario)(wifi_interface_handle iface, 389 wifi_power_scenario scenario); 390 wifi_error (*wifi_reset_tx_power_scenario)(wifi_interface_handle iface); 391 392 /** 393 * Returns the chipset's hardware filtering capabilities: 394 * @param version pointer to version of the packet filter interpreter 395 * supported, filled in upon return. 0 indicates no support. 396 * @param max_len pointer to maximum size of the filter bytecode, filled in 397 * upon return. 398 */ 399 wifi_error (*wifi_get_packet_filter_capabilities)(wifi_interface_handle handle, 400 u32 *version, u32 *max_len); 401 /** 402 * Programs the packet filter. 403 * @param program pointer to the program byte-code. 404 * @param len length of the program byte-code. 405 */ 406 wifi_error (*wifi_set_packet_filter)(wifi_interface_handle handle, 407 const u8 *program, u32 len); 408 wifi_error (*wifi_get_roaming_capabilities)(wifi_interface_handle handle, 409 wifi_roaming_capabilities *caps); 410 wifi_error (*wifi_enable_firmware_roaming)(wifi_interface_handle handle, 411 fw_roaming_state_t state); 412 wifi_error (*wifi_configure_roaming)(wifi_interface_handle handle, 413 wifi_roaming_config *roaming_config); 414 } wifi_hal_fn; 415 wifi_error init_wifi_vendor_hal_func_table(wifi_hal_fn *fn); 416 #ifdef __cplusplus 417 } 418 #endif 419 420 #endif 421