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