1 /* 2 * Copyright 2023, Cypress Semiconductor Corporation (an Infineon company) 3 * SPDX-License-Identifier: Apache-2.0 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #ifndef INCLUDED_WHD_CHIP_H 19 #define INCLUDED_WHD_CHIP_H 20 21 #include "cyabs_rtos.h" /* For cy_semaphore_t */ 22 23 #include "whd_endian.h" 24 #include "whd.h" 25 #include "whd_wifi_api.h" 26 27 #ifdef __cplusplus 28 extern "C" 29 { 30 #endif 31 32 /****************************************************** 33 * Constants 34 ******************************************************/ 35 #define WHD_WLAN_WAKE_TIMEOUT (10000) 36 #define WHD_SHARED_MEMORY_POLLING_DELAY (10) 37 #define SICF_CPUHALT (0x0020) 38 39 /****************************************************** 40 * Enumerations 41 ******************************************************/ 42 /** 43 * Enumerated list of aggregate codes and edit WHD_COUNTRY_AGGREGATE_CUSTOMER for supporting new aggregate 44 * as per customer like XZ/278 45 */ 46 typedef enum 47 { 48 WHD_COUNTRY_AGGREGATE_XA_0 = MK_CNTRY('X', 'A', 0), 49 WHD_COUNTRY_AGGREGATE_XT_0 = MK_CNTRY('X', 'T', 0), 50 WHD_COUNTRY_AGGREGATE_XV_0 = MK_CNTRY('X', 'V', 0), 51 WHD_COUNTRY_AGGREGATE_CUSTOMER = MK_CNTRY('X', 'Z', 278), 52 } whd_aggregate_code_t; 53 54 typedef enum 55 { 56 /* Note : If changing this, core_base_address must be changed also */ 57 WLAN_ARM_CORE = 0, SOCRAM_CORE = 1, SDIOD_CORE = 2 58 } device_core_t; 59 60 typedef enum 61 { 62 WLAN_DOWN, WLAN_UP, WLAN_OFF 63 } wlan_state_t; 64 65 typedef enum 66 { 67 WLAN_CORE_FLAG_NONE, WLAN_CORE_FLAG_CPU_HALT, 68 } wlan_core_flag_t; 69 70 /** 71 * Enumeration of AKM (authentication and key management) suites. Table 8-140 802.11mc D3.0. 72 */ 73 typedef enum 74 { 75 WHD_AKM_RESERVED = 0, 76 WHD_AKM_8021X = 1, /**< WPA2 enterprise */ 77 WHD_AKM_PSK = 2, /**< WPA2 PSK */ 78 WHD_AKM_FT_8021X = 3, /**< 802.11r Fast Roaming enterprise */ 79 WHD_AKM_FT_PSK = 4, /**< 802.11r Fast Roaming PSK */ 80 WHD_AKM_8021X_SHA256 = 5, 81 WHD_AKM_PSK_SHA256 = 6, 82 WHD_AKM_TDLS = 7, /**< Tunneled Direct Link Setup */ 83 WHD_AKM_SAE_SHA256 = 8, 84 WHD_AKM_FT_SAE_SHA256 = 9, 85 WHD_AKM_AP_PEER_KEY_SHA256 = 10, 86 WHD_AKM_SUITEB_8021X_HMAC_SHA256 = 11, 87 WHD_AKM_SUITEB_8021X_HMAC_SHA384 = 12, 88 WHD_AKM_SUITEB_FT_8021X_HMAC_SHA384 = 13, 89 } whd_akm_suite_t; 90 91 /** 92 * Enumeration of cipher suites. Table 8-138 802.11mc D3.0. 93 */ 94 typedef enum 95 { 96 WHD_CIPHER_GROUP = 0, /**< Use group cipher suite */ 97 WHD_CIPHER_WEP_40 = 1, /**< WEP-40 */ 98 WHD_CIPHER_TKIP = 2, /**< TKIP */ 99 WHD_CIPHER_RESERVED = 3, /**< Reserved */ 100 WHD_CIPHER_CCMP_128 = 4, /**< CCMP-128 - default pairwise and group cipher suite in an RSNA */ 101 WHD_CIPHER_WEP_104 = 5, /**< WEP-104 - also known as WEP-128 */ 102 WHD_CIPHER_BIP_CMAC_128 = 6, /**< BIP-CMAC-128 - default management frame cipher suite */ 103 WHD_CIPHER_GROUP_DISALLOWED = 7, /**< Group address traffic not allowed */ 104 WHD_CIPHER_GCMP_128 = 8, /**< GCMP-128 - default for 60 GHz STAs */ 105 WHD_CIPHER_GCMP_256 = 9, /**< GCMP-256 - introduced for Suite B */ 106 WHD_CIPHER_CCMP_256 = 10, /**< CCMP-256 - introduced for suite B */ 107 WHD_CIPHER_BIP_GMAC_128 = 11, /**< BIP-GMAC-128 - introduced for suite B */ 108 WHD_CIPHER_BIP_GMAC_256 = 12, /**< BIP-GMAC-256 - introduced for suite B */ 109 WHD_CIPHER_BIP_CMAC_256 = 13, /**< BIP-CMAC-256 - introduced for suite B */ 110 } whd_80211_cipher_t; 111 112 /****************************************************** 113 * Structures 114 ******************************************************/ 115 116 typedef struct whd_chip_info 117 { 118 uint16_t chip_id; 119 whd_bool_t save_restore_enable; 120 uint32_t fwcap_flags; 121 } whd_chip_info_t; 122 123 typedef struct whd_fwcap 124 { 125 whd_fwcap_id_t feature; 126 const char *const fwcap_name; 127 } whd_fwcap_t; 128 129 typedef struct 130 { 131 wlan_state_t state; 132 whd_country_code_t country_code; 133 whd_aggregate_code_t aggregate_code; 134 uint32_t keep_wlan_awake; 135 } whd_wlan_status_t; 136 137 #pragma pack(1) 138 139 /* 802.11 Information Element structures */ 140 141 /* Country Information */ 142 #define COUNTRY_INFO_IE_MINIMUM_LENGTH (6) 143 144 typedef struct 145 { 146 uint8_t first_chan_num; 147 uint8_t num_chans; 148 uint8_t max_tx_pwr_level; 149 } country_chan_info_t; 150 151 /* Structures for TLVs with 8-bit type and 8-bit length */ 152 typedef struct 153 { 154 uint8_t type; 155 uint8_t length; 156 } whd_tlv8_header_t; 157 158 typedef struct 159 { 160 uint8_t type; 161 uint8_t length; 162 uint8_t data[1]; 163 } whd_tlv8_data_t; 164 165 typedef struct 166 { 167 whd_tlv8_header_t tlv_header; /* id, length */ 168 char ccode[2]; /* dot11CountryString MIB octet 1~2, two letter country code */ 169 uint8_t env; /* dot11CountryString MIB octet 3, indicate indoor/outdoor environment */ 170 country_chan_info_t country_chan_info[1]; /* At least one country channel info triples */ 171 } country_info_ie_fixed_portion_t; 172 173 /* Robust Secure Network */ 174 typedef struct 175 { 176 whd_tlv8_header_t tlv_header; /* id, length */ 177 uint16_t version; 178 uint32_t group_key_suite; /* See whd_80211_cipher_t for values */ 179 uint16_t pairwise_suite_count; 180 uint32_t pairwise_suite_list[1]; 181 } rsn_ie_fixed_portion_t; 182 183 #define RSN_IE_MINIMUM_LENGTH (8) 184 185 typedef struct 186 { 187 whd_tlv8_header_t tlv_header; /* id, length */ 188 uint8_t oui[4]; 189 } vendor_specific_ie_header_t; 190 191 #define VENDOR_SPECIFIC_IE_MINIMUM_LENGTH (4) 192 193 /* WPA IE */ 194 typedef struct 195 { 196 vendor_specific_ie_header_t vendor_specific_header; 197 uint16_t version; 198 uint32_t multicast_suite; 199 uint16_t unicast_suite_count; 200 uint8_t unicast_suite_list[1][4]; 201 } wpa_ie_fixed_portion_t; 202 203 #define WPA_IE_MINIMUM_LENGTH (12) 204 205 typedef struct 206 { 207 uint16_t akm_suite_count; 208 uint32_t akm_suite_list[1]; 209 } akm_suite_portion_t; 210 211 /* RSNX IE */ 212 typedef struct 213 { 214 whd_tlv8_header_t tlv_header; /* id, length */ 215 uint8_t data[1]; 216 } rsnx_ie_t; 217 218 #define DOT11_RSNX_CAP_LEN 1 /* Extended RSN Capabilities length in octets (1 octet) */ 219 #define DOT11_RSNX_SAE_H2E 5 /* Extended RSN Capabilities */ 220 221 typedef struct 222 { 223 whd_tlv8_header_t tlv_header; /* id, length */ 224 uint16_t ht_capabilities_info; 225 uint8_t ampdu_parameters; 226 uint8_t rx_mcs[10]; 227 uint16_t rxhighest_supported_data_rate; 228 uint8_t tx_supported_mcs_set; 229 uint8_t tx_mcs_info[3]; 230 uint16_t ht_extended_capabilities; 231 uint32_t transmit_beam_forming_capabilities; 232 uint8_t antenna_selection_capabilities; 233 } ht_capabilities_ie_t; 234 235 #define HT_CAPABILITIES_INFO_LDPC_CODING_CAPABILITY (1 << 0) 236 #define HT_CAPABILITIES_INFO_SUPPORTED_CHANNEL_WIDTH_SET (1 << 1) 237 #define HT_CAPABILITIES_INFO_SM_POWER_SAVE_OFFSET (1 << 2) 238 #define HT_CAPABILITIES_INFO_SM_POWER_SAVE_MASK (3 << 2) 239 #define HT_CAPABILITIES_INFO_HT_GREENFIELD (1 << 4) 240 #define HT_CAPABILITIES_INFO_SHORT_GI_FOR_20MHZ (1 << 5) 241 #define HT_CAPABILITIES_INFO_SHORT_GI_FOR_40MHZ (1 << 6) 242 #define HT_CAPABILITIES_INFO_TX_STBC (1 << 7) 243 #define HT_CAPABILITIES_INFO_RX_STBC_OFFSET (1 << 8) 244 #define HT_CAPABILITIES_INFO_RX_STBC_MASK (3 << 8) 245 #define HT_CAPABILITIES_INFO_HT_DELAYED_BLOCK_ACK (1 << 10) 246 #define HT_CAPABILITIES_INFO_MAXIMUM_A_MSDU_LENGTH (1 << 11) 247 #define HT_CAPABILITIES_INFO_DSSS_CCK_MODE_IN_40MHZ (1 << 12) 248 /* bit 13 reserved */ 249 #define HT_CAPABILITIES_INFO_40MHZ_INTOLERANT (1 << 14) 250 #define HT_CAPABILITIES_INFO_L_SIG_TXOP_PROTECTION_SUPPORT (1 << 15) 251 252 typedef unsigned int uint; 253 typedef struct 254 { 255 uint buf; 256 uint buf_size; 257 uint idx; 258 uint out_idx; /* output index */ 259 } hnd_log_t; 260 261 #define CBUF_LEN 128 262 263 typedef struct 264 { 265 /* Virtual UART 266 * When there is no UART (e.g. Quickturn), the host should write a complete 267 * input line directly into cbuf and then write the length into vcons_in. 268 * This may also be used when there is a real UART (at risk of conflicting with 269 * the real UART). vcons_out is currently unused. 270 */ 271 volatile uint vcons_in; 272 volatile uint vcons_out; 273 274 /* Output (logging) buffer 275 * Console output is written to a ring buffer log_buf at index log_idx. 276 * The host may read the output when it sees log_idx advance. 277 * Output will be lost if the output wraps around faster than the host polls. 278 */ 279 hnd_log_t log; 280 281 /* Console input line buffer 282 * Characters are read one at a time into cbuf until <CR> is received, then 283 * the buffer is processed as a command line. Also used for virtual UART. 284 */ 285 uint cbuf_idx; 286 char cbuf[CBUF_LEN]; 287 } hnd_cons_t; 288 289 typedef struct wifi_console 290 { 291 uint count; /* Poll interval msec counter */ 292 uint log_addr; /* Log struct address (fixed) */ 293 hnd_log_t log; /* Log struct (host copy) */ 294 uint bufsize; /* Size of log buffer */ 295 char *buf; /* Log buffer (host copy) */ 296 uint last; /* Last buffer read index */ 297 } wifi_console_t; 298 299 typedef struct 300 { 301 uint flags; 302 uint trap_addr; 303 uint assert_exp_addr; 304 uint assert_file_addr; 305 uint assert_line; 306 uint console_addr; 307 uint msgtrace_addr; 308 uint fwid; 309 } wlan_shared_t; 310 311 /* Buffer size to be allocated to read wlan log */ 312 #define WLAN_LOG_BUF_LEN (4 * 1024) 313 314 #define WHD_IOCTL_LOG_SIZE 64 315 #define WHD_IOVAR_STRING_SIZE 128 316 #define WHD_MAX_DATA_SIZE 64 317 318 typedef struct 319 { 320 uint32_t ioct_log; 321 uint8_t is_this_event; 322 uint8_t data[WHD_MAX_DATA_SIZE]; 323 uint32_t data_size; 324 uint16_t flag; 325 uint32_t reason; 326 }whd_ioctl_log_t; 327 328 whd_result_t whd_ioctl_log_add(whd_driver_t whd_driver, uint32_t cmd, whd_buffer_t buffer); 329 whd_result_t whd_ioctl_log_add_event(whd_driver_t whd_driver, uint32_t cmd, uint16_t flag, uint32_t data); 330 331 whd_result_t whd_ioctl_print(whd_driver_t whd_driver); 332 333 #pragma pack() 334 335 typedef struct whd_internal_info 336 { 337 whd_wlan_status_t whd_wlan_status; 338 wifi_console_t *c; 339 wifi_console_t console; 340 wlan_shared_t sh; 341 uint32_t console_addr; 342 whd_scan_result_callback_t scan_result_callback; 343 whd_scan_result_t *whd_scan_result_ptr; 344 /* The semaphore used to wait for completion of a join; 345 * whd_wifi_join_halt uses this to release waiting threads (if any) */ 346 cy_semaphore_t *active_join_semaphore; 347 whd_bool_t active_join_mutex_initted; 348 cy_semaphore_t active_join_mutex; 349 uint con_lastpos; 350 whd_bool_t whd_wifi_p2p_go_is_up; 351 uint32_t whd_join_status[3]; 352 whd_auth_result_callback_t auth_result_callback; 353 } whd_internal_info_t; 354 355 #pragma pack(1) 356 357 typedef struct 358 { 359 char abbrev[3]; 360 uint8_t rev; 361 uint8_t data[64]; 362 } whd_country_info_t; 363 364 #pragma pack() 365 366 whd_result_t whd_internal_info_init(whd_driver_t whd_driver); 367 whd_result_t whd_internal_info_deinit(whd_driver_t whd_driver); 368 369 /****************************************************** 370 * Function Declarations 371 ******************************************************/ 372 373 extern void whd_wifi_chip_info_init(whd_driver_t whd_driver); 374 extern whd_result_t whd_wlan_bus_complete_ds_wake(whd_driver_t whd_driver, whd_bool_t wake_from_firmware, 375 uint32_t wake_event_indication_addr, uint32_t wake_indication_addr, 376 uint32_t sdio_control_addr); 377 extern whd_result_t whd_wifi_set_custom_country_code(whd_interface_t ifp, const whd_country_info_t *country_code); 378 379 /* Device core control functions */ 380 extern whd_result_t whd_disable_device_core(whd_driver_t whd_driver, device_core_t core_id, wlan_core_flag_t core_flag); 381 extern whd_result_t whd_reset_device_core(whd_driver_t whd_driver, device_core_t core_id, wlan_core_flag_t core_flag); 382 extern whd_result_t whd_reset_core(whd_driver_t whd_driver, device_core_t core_id, uint32_t bits, uint32_t resetbits); 383 extern whd_result_t whd_wlan_armcore_run(whd_driver_t whd_driver, device_core_t core_id, wlan_core_flag_t core_flag); 384 extern whd_result_t whd_device_core_is_up(whd_driver_t whd_driver, device_core_t core_id); 385 386 /* Chip specific functions */ 387 extern whd_result_t whd_allow_wlan_bus_to_sleep(whd_driver_t whd_driver); 388 extern whd_result_t whd_ensure_wlan_bus_is_up(whd_driver_t whd_driver); 389 390 extern whd_result_t whd_chip_specific_init(whd_driver_t whd_driver); 391 extern whd_result_t whd_chip_specific_socsram_init(whd_driver_t whd_driver); 392 extern whd_result_t whd_wifi_read_wlan_log(whd_driver_t whd_driver, char *buffer, uint32_t buffer_size); 393 extern whd_result_t whd_wifi_print_whd_log(whd_driver_t whd_driver); 394 extern whd_result_t whd_wifi_read_wlan_log_unsafe(whd_driver_t whd_driver, uint32_t wlan_shared_address, char *buffer, 395 uint32_t buffer_size); 396 extern whd_result_t whd_wifi_read_fw_capabilities(whd_interface_t ifp); 397 extern void whd_wifi_peek(whd_driver_t whd_driver, uint32_t address, uint8_t register_length, uint8_t *value); 398 extern void whd_wifi_poke(whd_driver_t whd_driver, uint32_t address, uint8_t register_length, uint32_t value); 399 extern uint32_t whd_wifi_get_btc_params(whd_driver_t whd_driver, uint32_t address, whd_interface_t interface); 400 401 #ifdef __cplusplus 402 } /* extern "C" */ 403 #endif 404 405 #endif /* ifndef INCLUDED_WHD_CHIP_H */ 406 407