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