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