1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Portions copyright (C) 2017 Broadcom Limited 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #include <hardware_legacy/wifi_hal.h> 20 21 #ifndef __WIFI_HAL_COMMON_H__ 22 #define __WIFI_HAL_COMMON_H__ 23 24 #define LOG_TAG "WifiHAL" 25 26 #include <log/log.h> 27 #include "nl80211_copy.h" 28 #include "sync.h" 29 30 #define SOCKET_BUFFER_SIZE (32768U) 31 #define RECV_BUF_SIZE (4096) 32 #define DEFAULT_EVENT_CB_SIZE (64) 33 #define DEFAULT_CMD_SIZE (64) 34 #define DOT11_OUI_LEN 3 35 #define DOT11_MAX_SSID_LEN 32 36 37 #define ETHERTYPE_IP 0x0800 /* IP */ 38 #define ETHERTYPE_IPV6 0x86dd /* IP protocol version 6 */ 39 #define MAX_PROBE_RESP_IE_LEN 2048 40 /* 41 Vendor OUI - This is a unique identifier that identifies organization. Lets 42 code Android specific functions with Google OUI; although vendors can do more 43 with their own OUI's as well. 44 */ 45 46 const uint32_t GOOGLE_OUI = 0x001A11; 47 const uint32_t BRCM_OUI = 0x001018; 48 /* TODO: define vendor OUI here */ 49 50 51 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] 52 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" 53 54 #define NMR2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5], (a)[6], (a)[7] 55 #define NMRSTR "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" 56 #define NAN_MASTER_RANK_LEN 8 57 #define NAN_SCID_INFO_LEN 16 58 59 #define SAR_CONFIG_SCENARIO_COUNT 100 60 #define MAX_NUM_RADIOS 3 61 #define MAX_CMD_RESP_BUF_LEN 8192 62 63 #define NL_MSG_MAX_LEN 5120u 64 65 /* nl_msg->nm_nlh->nlmsg_len is added by data len of the attributes 66 * NL80211_ATTR_VENDOR_ID, NL80211_ATTR_VENDOR_SUBCMD, 67 * NL80211_ATTR_IFINDEX, APF_PROGRAM_LEN by 56u 68 * To keep the additioanl room and aligned, 69 * keeping the overhead of 128u 70 */ 71 #define NL_MSG_HDR_OVERHEAD_LEN 128u 72 #define NL_MSG_DEFAULT_LEN (getpagesize() - NL_MSG_HDR_OVERHEAD_LEN) 73 74 /* 75 This enum defines ranges for various commands; commands themselves 76 can be defined in respective feature headers; i.e. find gscan command 77 definitions in gscan.cpp 78 */ 79 80 typedef int (*nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg); 81 typedef enum { 82 /* don't use 0 as a valid subcommand */ 83 VENDOR_NL80211_SUBCMD_UNSPECIFIED, 84 85 /* define all vendor startup commands between 0x0 and 0x0FFF */ 86 VENDOR_NL80211_SUBCMD_RANGE_START = 0x0001, 87 VENDOR_NL80211_SUBCMD_RANGE_END = 0x0FFF, 88 89 /* define all GScan related commands between 0x1000 and 0x10FF */ 90 ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START = 0x1000, 91 ANDROID_NL80211_SUBCMD_GSCAN_RANGE_END = 0x10FF, 92 93 /* define all NearbyDiscovery related commands between 0x1100 and 0x11FF */ 94 ANDROID_NL80211_SUBCMD_NBD_RANGE_START = 0x1100, 95 ANDROID_NL80211_SUBCMD_NBD_RANGE_END = 0x11FF, 96 97 /* define all RTT related commands between 0x1100 and 0x11FF */ 98 ANDROID_NL80211_SUBCMD_RTT_RANGE_START = 0x1100, 99 ANDROID_NL80211_SUBCMD_RTT_RANGE_END = 0x11FF, 100 101 ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START = 0x1200, 102 ANDROID_NL80211_SUBCMD_LSTATS_RANGE_END = 0x12FF, 103 104 /* define all Logger related commands between 0x1400 and 0x14FF */ 105 ANDROID_NL80211_SUBCMD_DEBUG_RANGE_START = 0x1400, 106 ANDROID_NL80211_SUBCMD_DEBUG_RANGE_END = 0x14FF, 107 108 /* define all wifi offload related commands between 0x1600 and 0x16FF */ 109 ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_START = 0x1600, 110 ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_END = 0x16FF, 111 112 /* define all NAN related commands between 0x1700 and 0x17FF */ 113 ANDROID_NL80211_SUBCMD_NAN_RANGE_START = 0x1700, 114 ANDROID_NL80211_SUBCMD_NAN_RANGE_END = 0x17FF, 115 116 /* define all Android Packet Filter related commands between 0x1800 and 0x18FF */ 117 ANDROID_NL80211_SUBCMD_PKT_FILTER_RANGE_START = 0x1800, 118 ANDROID_NL80211_SUBCMD_PKT_FILTER_RANGE_END = 0x18FF, 119 120 /* define all tx power related commands between 0x1900 and 0x1910 */ 121 ANDROID_NL80211_SUBCMD_TX_POWER_RANGE_START = 0x1900, 122 ANDROID_NL80211_SUBCMD_TX_POWER_RANGE_END = 0x1910, 123 124 /* define all thermal mode related commands between 0x1920 and 0x192F */ 125 ANDROID_NL80211_SUBCMD_MITIGATION_RANGE_START = 0x1920, 126 ANDROID_NL80211_SUBCMD_MITIGATION_RANGE_END = 0x192F, 127 128 /* define all DSCP related commands between 0x2000 and 0x20FF */ 129 ANDROID_NL80211_SUBCMD_DSCP_RANGE_START = 0x2000, 130 ANDROID_NL80211_SUBCMD_DSCP_RANGE_END = 0x20FF, 131 132 /* define all Channel Avoidance related commands between 0x2100 and 0x211F */ 133 ANDROID_NL80211_SUBCMD_CHAVOID_RANGE_START = 0x2100, 134 ANDROID_NL80211_SUBCMD_CHAVOID_RANGE_END = 0x211F, 135 136 /* define all OTA Download related commands between 0x2120 and 0x212F */ 137 ANDROID_NL80211_SUBCMD_OTA_DOWNLOAD_START = 0x2120, 138 ANDROID_NL80211_SUBCMD_OTA_DOWNLOAD_END = 0x212F, 139 140 /* define all VOIP mode config related commands between 0x2130 and 0x213F */ 141 ANDROID_NL80211_SUBCMD_VIOP_MODE_START = 0x2130, 142 ANDROID_NL80211_SUBCMD_VIOP_MODE_END = 0x213F, 143 144 /* define all TWT related commands between 0x2140 and 0x214F */ 145 ANDROID_NL80211_SUBCMD_TWT_START = 0x2140, 146 ANDROID_NL80211_SUBCMD_TWT_END = 0x214F, 147 148 /* define all Usable Channel related commands between 0x2150 and 0x215F */ 149 ANDROID_NL80211_SUBCMD_USABLE_CHANNEL_START = 0x2150, 150 ANDROID_NL80211_SUBCMD_USABLE_CHANNEL_END = 0x215F, 151 152 /* define all init/deinit related commands between 0x2160 and 0x216F */ 153 ANDROID_NL80211_SUBCMD_INIT_DEINIT_RANGE_START = 0x2160, 154 ANDROID_NL80211_SUBCMD_INIT_DEINIT_RANGE_END = 0x216F, 155 156 /* This is reserved for future usage */ 157 158 } ANDROID_VENDOR_SUB_COMMAND; 159 160 typedef enum { 161 162 GSCAN_SUBCMD_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START, 163 164 GSCAN_SUBCMD_SET_CONFIG, /* 0x1001 */ 165 166 GSCAN_SUBCMD_SET_SCAN_CONFIG, /* 0x1002 */ 167 GSCAN_SUBCMD_ENABLE_GSCAN, /* 0x1003 */ 168 GSCAN_SUBCMD_GET_SCAN_RESULTS, /* 0x1004 */ 169 GSCAN_SUBCMD_SCAN_RESULTS, /* 0x1005 */ 170 171 GSCAN_SUBCMD_SET_HOTLIST, /* 0x1006 */ 172 173 GSCAN_SUBCMD_SET_SIGNIFICANT_CHANGE_CONFIG, /* 0x1007 */ 174 GSCAN_SUBCMD_ENABLE_FULL_SCAN_RESULTS, /* 0x1008 */ 175 GSCAN_SUBCMD_GET_CHANNEL_LIST, /* 0x1009 */ 176 177 WIFI_SUBCMD_GET_FEATURE_SET, /* 0x100A */ 178 WIFI_SUBCMD_GET_FEATURE_SET_MATRIX, /* 0x100B */ 179 WIFI_SUBCMD_SET_PNO_RANDOM_MAC_OUI, /* 0x100C */ 180 WIFI_SUBCMD_NODFS_SET, /* 0x100D */ 181 WIFI_SUBCMD_SET_COUNTRY_CODE, /* 0x100E */ 182 /* Add more sub commands here */ 183 GSCAN_SUBCMD_SET_EPNO_SSID, /* 0x100F */ 184 185 WIFI_SUBCMD_SET_SSID_WHITE_LIST, /* 0x1010 */ 186 WIFI_SUBCMD_SET_ROAM_PARAMS, /* 0x1011 */ 187 WIFI_SUBCMD_ENABLE_LAZY_ROAM, /* 0x1012 */ 188 WIFI_SUBCMD_SET_BSSID_PREF, /* 0x1013 */ 189 WIFI_SUBCMD_SET_BSSID_BLACKLIST, /* 0x1014 */ 190 191 GSCAN_SUBCMD_ANQPO_CONFIG, /* 0x1015 */ 192 WIFI_SUBCMD_SET_RSSI_MONITOR, /* 0x1016 */ 193 WIFI_SUBCMD_CONFIG_ND_OFFLOAD, /* 0x1017 */ 194 WIFI_SUBCMD_CONFIG_TCPACK_SUP, /* 0x1018 */ 195 WIFI_SUBCMD_FW_ROAM_POLICY, /* 0x1019 */ 196 WIFI_SUBCMD_ROAM_CAPABILITY, /* 0x101a */ 197 WIFI_SUBCMD_SET_LATENCY_MODE, /* 0x101b */ 198 WIFI_SUBCMD_SET_MULTISTA_PRIMARY_CONNECTION, /* 0x101c */ 199 WIFI_SUBCMD_SET_MULTISTA_USE_CASE, /* 0x101d */ 200 WIFI_SUBCMD_SET_DTIM_CONFIG, /* 0x101e */ 201 WIFI_SUBCMD_CONFIG_INDOOR_STATE, 202 203 GSCAN_SUBCMD_MAX, 204 205 /* NAN related */ 206 NAN_SUBCMD_ENABLE = ANDROID_NL80211_SUBCMD_NAN_RANGE_START, 207 NAN_SUBCMD_DISABLE, /* 0x1701 */ 208 NAN_SUBCMD_PUBLISH, /* 0x1702 */ 209 NAN_SUBCMD_SUBSCRIBE, /* 0x1703 */ 210 NAN_SUBCMD_PUBLISH_CANCEL, /* 0x1704 */ 211 NAN_SUBCMD_SUBSCRIBE_CANCEL, /* 0x1705 */ 212 NAN_SUBCMD_TRANSMIT_FOLLOWUP, /* 0x1706 */ 213 NAN_SUBCMD_CONFIG, /* 0x1707 */ 214 NAN_SUBCMD_TCA, /* 0x1708 */ 215 NAN_SUBCMD_STATS, /* 0x1709 */ 216 NAN_SUBCMD_GET_CAPABILITIES, /* 0x170A */ 217 NAN_SUBCMD_DATA_PATH_IFACE_CREATE, /* 0x170B */ 218 NAN_SUBCMD_DATA_PATH_IFACE_DELETE, /* 0x170C */ 219 NAN_SUBCMD_DATA_PATH_REQUEST, /* 0x170D */ 220 NAN_SUBCMD_DATA_PATH_RESPONSE, /* 0x170E */ 221 NAN_SUBCMD_DATA_PATH_END, /* 0x170F */ 222 NAN_SUBCMD_DATA_PATH_SEC_INFO, /* 0x1710 */ 223 NAN_SUBCMD_VERSION_INFO, /* 0x1711 */ 224 NAN_SUBCMD_ENABLE_MERGE, /* 0x1712 */ 225 APF_SUBCMD_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_PKT_FILTER_RANGE_START, 226 APF_SUBCMD_SET_FILTER, 227 APF_SUBCMD_READ_FILTER, 228 WIFI_SUBCMD_TX_POWER_SCENARIO = ANDROID_NL80211_SUBCMD_TX_POWER_RANGE_START, 229 WIFI_SUBCMD_THERMAL_MITIGATION = ANDROID_NL80211_SUBCMD_MITIGATION_RANGE_START, 230 DSCP_SUBCMD_SET_TABLE = ANDROID_NL80211_SUBCMD_DSCP_RANGE_START, 231 DSCP_SUBCMD_RESET_TABLE, /* 0x2001 */ 232 CHAVOID_SUBCMD_SET_CONFIG = ANDROID_NL80211_SUBCMD_CHAVOID_RANGE_START, 233 234 TWT_SUBCMD_GETCAPABILITY = ANDROID_NL80211_SUBCMD_TWT_START, 235 TWT_SUBCMD_SETUP_REQUEST, 236 TWT_SUBCMD_TEAR_DOWN_REQUEST, 237 TWT_SUBCMD_INFO_FRAME_REQUEST, 238 TWT_SUBCMD_GETSTATS, 239 TWT_SUBCMD_CLR_STATS, 240 241 WIFI_SUBCMD_CONFIG_VOIP_MODE = ANDROID_NL80211_SUBCMD_VIOP_MODE_START, 242 243 WIFI_SUBCMD_GET_OTA_CURRUNT_INFO = ANDROID_NL80211_SUBCMD_OTA_DOWNLOAD_START, 244 WIFI_SUBCMD_OTA_UPDATE, 245 WIFI_SUBCMD_USABLE_CHANNEL = ANDROID_NL80211_SUBCMD_USABLE_CHANNEL_START, 246 WIFI_SUBCMD_TRIGGER_SSR = ANDROID_NL80211_SUBCMD_INIT_DEINIT_RANGE_START, 247 WIFI_SUBCMD_GET_RADIO_COMBO_MATRIX, 248 } WIFI_SUB_COMMAND; 249 250 typedef enum { 251 BRCM_RESERVED1 = 0, 252 BRCM_RESERVED2 = 1, 253 GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS = 2, 254 GSCAN_EVENT_HOTLIST_RESULTS_FOUND = 3, 255 GSCAN_EVENT_SCAN_RESULTS_AVAILABLE = 4, 256 GSCAN_EVENT_FULL_SCAN_RESULTS = 5, 257 RTT_EVENT_COMPLETE = 6, 258 GSCAN_EVENT_COMPLETE_SCAN = 7, 259 GSCAN_EVENT_HOTLIST_RESULTS_LOST = 8, 260 GSCAN_EVENT_EPNO_EVENT = 9, 261 GOOGLE_DEBUG_RING_EVENT = 10, 262 GOOGLE_DEBUG_MEM_DUMP_EVENT = 11, 263 GSCAN_EVENT_ANQPO_HOTSPOT_MATCH = 12, 264 GOOGLE_RSSI_MONITOR_EVENT = 13, 265 GOOGLE_MKEEP_ALIVE = 14, 266 267 /* 268 * BRCM specific events should be placed after the Generic events 269 * in order to match between the DHD and HAL 270 */ 271 NAN_EVENT_ENABLED = 15, 272 NAN_EVENT_DISABLED = 16, 273 NAN_EVENT_SUBSCRIBE_MATCH = 17, 274 NAN_EVENT_PUBLISH_REPLIED_IND = 18, 275 NAN_EVENT_PUBLISH_TERMINATED = 19, 276 NAN_EVENT_SUBSCRIBE_TERMINATED = 20, 277 NAN_EVENT_DE_EVENT = 21, 278 NAN_EVENT_FOLLOWUP = 22, 279 NAN_EVENT_TRANSMIT_FOLLOWUP_IND = 23, 280 NAN_EVENT_DATA_REQUEST = 24, 281 NAN_EVENT_DATA_CONFIRMATION = 25, 282 NAN_EVENT_DATA_END = 26, 283 NAN_EVENT_BEACON = 27, 284 NAN_EVENT_SDF = 28, 285 NAN_EVENT_TCA = 29, 286 NAN_EVENT_SUBSCRIBE_UNMATCH = 30, 287 NAN_EVENT_UNKNOWN = 31, 288 BRCM_VENDOR_EVENT_HANGED = 33, 289 ROAM_EVENT_START, 290 GOOGLE_FILE_DUMP_EVENT = 37, 291 NAN_ASYNC_RESPONSE_DISABLED = 40, 292 BRCM_VENDOR_EVENT_TWT = 43, 293 BRCM_TPUT_DUMP_EVENT = 44, 294 NAN_EVENT_MATCH_EXPIRY = 45 295 } WIFI_EVENT; 296 297 typedef void (*wifi_internal_event_handler) (wifi_handle handle, int events); 298 299 class WifiCommand; 300 301 typedef struct { 302 int nl_cmd; 303 uint32_t vendor_id; 304 int vendor_subcmd; 305 nl_recvmsg_msg_cb_t cb_func; 306 void *cb_arg; 307 } cb_info; 308 309 typedef struct { 310 wifi_request_id id; 311 WifiCommand *cmd; 312 } cmd_info; 313 314 typedef struct { 315 wifi_handle handle; // handle to wifi data 316 char name[IFNAMSIZ+1]; // interface name + trailing null 317 int id; // id to use when talking to driver 318 bool is_virtual; // mark each iface as virtual or static 319 } interface_info; 320 321 typedef struct { 322 323 struct nl_sock *cmd_sock; // command socket object 324 struct nl_sock *event_sock; // event socket object 325 int nl80211_family_id; // family id for 80211 driver 326 int cleanup_socks[2]; // sockets used to implement wifi_cleanup 327 328 bool in_event_loop; // Indicates that event loop is active 329 bool clean_up; // Indication to exit since cleanup has started 330 331 wifi_internal_event_handler event_handler; // default event handler 332 wifi_cleaned_up_handler cleaned_up_handler; // socket cleaned up handler 333 334 cb_info *event_cb; // event callbacks 335 int num_event_cb; // number of event callbacks 336 int alloc_event_cb; // number of allocated callback objects 337 pthread_mutex_t cb_lock; // mutex for the event_cb access 338 339 cmd_info *cmd; // Outstanding commands 340 int num_cmd; // number of commands 341 int alloc_cmd; // number of commands allocated 342 343 interface_info **interfaces; // array of interfaces 344 int num_interfaces; // number of interfaces 345 int max_num_interfaces; // max number of interfaces 346 wifi_subsystem_restart_handler restart_handler; // trigger sub system handler 347 348 349 // add other details 350 } hal_info; 351 352 #define PNO_SSID_FOUND 0x1 353 #define PNO_SSID_LOST 0x2 354 355 typedef struct wifi_pno_result { 356 unsigned char ssid[DOT11_MAX_SSID_LEN]; 357 unsigned char ssid_len; 358 signed char rssi; 359 u16 channel; 360 u16 flags; 361 mac_addr bssid; 362 } wifi_pno_result_t; 363 364 typedef struct wifi_gscan_result { 365 u64 ts; // Time of discovery 366 u8 ssid[DOT11_MAX_SSID_LEN+1]; // null terminated 367 mac_addr bssid; // BSSID 368 u32 channel; // channel frequency in MHz 369 s32 rssi; // in db 370 u64 rtt; // in nanoseconds 371 u64 rtt_sd; // standard deviation in rtt 372 u16 beacon_period; // units are Kusec 373 u16 capability; // Capability information 374 u32 pad; 375 } wifi_gscan_result_t; 376 377 typedef struct wifi_gscan_full_result { 378 wifi_gscan_result_t fixed; 379 u32 scan_ch_bucket; // scan chbucket bitmask 380 u32 ie_length; // byte length of Information Elements 381 u8 ie_data[1]; // IE data to follow 382 } wifi_gscan_full_result_t; 383 384 void twt_deinit_handler(); 385 386 typedef enum { 387 TWT_EVENT_INVALID = 0, 388 TWT_SETUP_RESPONSE = 1, 389 TWT_TEARDOWN_COMPLETION = 2, 390 TWT_INFORM_FRAME = 3, 391 TWT_NOTIFY = 4, 392 TWT_EVENT_LAST 393 } TwtEventType; 394 395 typedef enum { 396 TWT_INVALID = 0, 397 TWT_SETUP_REQUEST = 1, 398 TWT_INFO_FRAME_REQUEST = 2, 399 TWT_TEAR_DOWN_REQUEST = 3, 400 TWT_LAST 401 } TwtRequestType; 402 403 typedef enum { 404 TWT_ATTRIBUTE_INVALID = 0, 405 TWT_ATTRIBUTE_CONFIG_ID = 1, 406 TWT_ATTRIBUTE_NEG_TYPE = 2, 407 TWT_ATTRIBUTE_TRIGGER_TYPE = 3, 408 TWT_ATTRIBUTE_WAKE_DUR_US = 4, 409 TWT_ATTRIBUTE_WAKE_INT_US = 5, 410 TWT_ATTRIBUTE_WAKE_INT_MIN_US = 6, 411 TWT_ATTRIBUTE_WAKE_INT_MAX_US = 7, 412 TWT_ATTRIBUTE_WAKE_DUR_MIN_US = 8, 413 TWT_ATTRIBUTE_WAKE_DUR_MAX_US = 9, 414 TWT_ATTRIBUTE_AVG_PKT_SIZE = 10, 415 TWT_ATTRIBUTE_AVG_PKT_NUM = 11, 416 TWT_ATTRIBUTE_WAKE_TIME_OFF_US = 12, 417 TWT_ATTRIBUTE_ALL_TWT = 13, 418 TWT_ATTRIBUTE_RESUME_TIME_US = 14, 419 TWT_ATTRIBUTE_AVG_EOSP_DUR = 15, 420 TWT_ATTRIBUTE_EOSP_COUNT = 16, 421 TWT_ATTRIBUTE_NUM_SP = 17, 422 TWT_ATTRIBUTE_DEVICE_CAP = 18, 423 TWT_ATTRIBUTE_PEER_CAP = 19, 424 TWT_ATTRIBUTE_STATUS = 20, 425 TWT_ATTRIBUTE_REASON_CODE = 21, 426 TWT_ATTRIBUTE_RESUMED = 22, 427 TWT_ATTRIBUTE_NOTIFICATION = 23, 428 TWT_ATTRIBUTE_SUB_EVENT = 24, 429 TWT_ATTRIBUTE_NUM_PEER_STATS = 25, 430 TWT_ATTRIBUTE_AVG_PKT_NUM_TX = 26, 431 TWT_ATTRIBUTE_AVG_PKT_SIZE_TX = 27, 432 TWT_ATTRIBUTE_AVG_PKT_NUM_RX = 28, 433 TWT_ATTRIBUTE_AVG_PKT_SIZE_RX = 29, 434 TWT_ATTRIBUTE_MAX 435 } TWT_ATTRIBUTE; 436 437 wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_t func, void *arg); 438 wifi_error wifi_register_vendor_handler(wifi_handle handle, 439 uint32_t id, int subcmd, nl_recvmsg_msg_cb_t func, void *arg); 440 441 void wifi_unregister_handler(wifi_handle handle, int cmd); 442 void wifi_unregister_vendor_handler_without_lock(wifi_handle handle, uint32_t id, int subcmd); 443 void wifi_unregister_vendor_handler(wifi_handle handle, uint32_t id, int subcmd); 444 445 wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd); 446 WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id); 447 WifiCommand *wifi_get_cmd(wifi_handle handle, int id); 448 void wifi_unregister_cmd(wifi_handle handle, WifiCommand *cmd); 449 450 interface_info *getIfaceInfo(wifi_interface_handle); 451 wifi_handle getWifiHandle(wifi_interface_handle handle); 452 hal_info *getHalInfo(wifi_handle handle); 453 hal_info *getHalInfo(wifi_interface_handle handle); 454 wifi_handle getWifiHandle(hal_info *info); 455 wifi_interface_handle getIfaceHandle(interface_info *info); 456 wifi_error wifi_cancel_cmd(wifi_request_id id, wifi_interface_handle iface); 457 wifi_error wifi_get_cancel_cmd(wifi_request_id id, wifi_interface_handle iface); 458 wifi_error nan_deinit_handler(); 459 wifi_error wifi_start_hal(wifi_interface_handle iface); 460 wifi_error wifi_stop_hal(wifi_interface_handle iface); 461 wifi_interface_handle wifi_get_wlan_interface(wifi_handle info, 462 wifi_interface_handle *ifaceHandles, int numIfaceHandles); 463 #ifdef RING_DUMP 464 wifi_error wifi_start_ring_dump(wifi_interface_handle iface, 465 wifi_ring_buffer_data_handler ring_handle); 466 wifi_error wifi_stop_ring_dump(wifi_interface_handle iface); 467 #endif /* RING_DUMP */ 468 wifi_error wifi_hal_ota_update(wifi_interface_handle iface, uint32_t ota_version); 469 wifi_error wifi_hal_preInit(wifi_interface_handle iface); 470 /* API to get wake reason statistics */ 471 wifi_error wifi_get_wake_reason_stats(wifi_interface_handle handle, 472 WLAN_DRIVER_WAKE_REASON_CNT *wifi_wake_reason_cnt); 473 wifi_error wifi_virtual_interface_create(wifi_handle handle, const char* ifname, 474 wifi_interface_type iface_type); 475 wifi_error wifi_virtual_interface_delete(wifi_handle handle, const char* ifname); 476 wifi_error wifi_set_coex_unsafe_channels(wifi_handle handle, u32 num_channels, 477 wifi_coex_unsafe_channel channels[], u32 restrictions); 478 wifi_error wifi_set_voip_mode(wifi_interface_handle handle, wifi_voip_mode mode); 479 wifi_error wifi_set_dtim_config(wifi_interface_handle handle, u32 multiplier); 480 void set_hautil_mode(bool halutil_mode); 481 bool get_halutil_mode(); 482 483 /* API's to support TWT */ 484 485 /**@brief twt_get_capability 486 * Request TWT capability 487 * @param wifi_interface_handle: 488 * @return Synchronous wifi_error and TwtCapabilitySet 489 */ 490 wifi_error twt_get_capability(wifi_interface_handle iface, TwtCapabilitySet* twt_cap_set); 491 492 /**@brief twt_register_handler 493 * Request to register TWT callback 494 * @param wifi_interface_handle: 495 * @param TwtCallbackHandler: 496 * @return Synchronous wifi_error 497 */ 498 wifi_error twt_register_handler(wifi_interface_handle iface, TwtCallbackHandler handler); 499 500 /**@brief twt_setup_request 501 * Request to send TWT setup frame 502 * @param wifi_interface_handle: 503 * @param TwtSetupRequest: 504 * @return Synchronous wifi_error 505 * @return Asynchronous EventTwtSetupResponse CB return TwtSetupResponse 506 */ 507 wifi_error twt_setup_request(wifi_interface_handle iface, TwtSetupRequest* msg); 508 509 /**@brief twt_teardown_request 510 * Request to send TWT teardown frame 511 * @param wifi_interface_handle: 512 * @param TwtTeardownRequest: 513 * @return Synchronous wifi_error 514 * @return Asynchronous EventTwtTeardownCompletion CB return TwtTeardownCompletion 515 * TwtTeardownCompletion may also be received due to other events 516 * like CSA, BTCX, TWT scheduler, MultiConnection, peer-initiated teardown, etc. 517 */ 518 wifi_error twt_teardown_request(wifi_interface_handle iface, TwtTeardownRequest* msg); 519 520 /**@brief twt_info_frame_request 521 * Request to send TWT info frame 522 * @param wifi_interface_handle: 523 * @param TwtInfoFrameRequest: 524 * @return Synchronous wifi_error 525 * @return Asynchronous EventTwtInfoFrameReceived CB return TwtInfoFrameReceived 526 * Driver may also receive Peer-initiated TwtInfoFrame 527 */ 528 wifi_error twt_info_frame_request(wifi_interface_handle iface, TwtInfoFrameRequest* msg); 529 530 /**@brief twt_get_stats 531 * Request to get TWT stats 532 * @param wifi_interface_handle: 533 * @param config_id: 534 * @return Synchronous wifi_error and TwtStats 535 */ 536 wifi_error twt_get_stats(wifi_interface_handle iface, u8 config_id, TwtStats* stats); 537 538 /**@brief twt_clear_stats 539 * Request to clear TWT stats 540 * @param wifi_interface_handle: 541 * @param config_id: 542 * @return Synchronous wifi_error 543 */ 544 wifi_error twt_clear_stats(wifi_interface_handle iface, u8 config_id); 545 546 wifi_error wifi_trigger_subsystem_restart(wifi_handle handle); 547 // some common macros 548 549 #define min(x, y) ((x) < (y) ? (x) : (y)) 550 #define max(x, y) ((x) > (y) ? (x) : (y)) 551 552 #define NULL_CHECK_RETURN(ptr, str, ret) \ 553 do { \ 554 if (!(ptr)) { \ 555 ALOGE("%s(): null pointer - #ptr (%s)\n", __FUNCTION__, str); \ 556 return ret; \ 557 } \ 558 } while (0) 559 560 #endif 561 562