1 /*- 2 * Copyright (c) 2020-2024 The FreeBSD Foundation 3 * 4 * This software was developed by Björn Zeeb under sponsorship from 5 * the FreeBSD Foundation. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _LINUXKPI_LINUX_IEEE80211_H 30 #define _LINUXKPI_LINUX_IEEE80211_H 31 32 #include <sys/types.h> 33 #include <net80211/ieee80211.h> 34 35 #include <asm/unaligned.h> 36 #include <linux/kernel.h> 37 #include <linux/bitops.h> 38 #include <linux/if_ether.h> 39 40 41 /* 9.4.2.55 Management MIC element (CMAC-256, GMAC-128, and GMAC-256). */ 42 struct ieee80211_mmie_16 { 43 uint8_t element_id; 44 uint8_t length; 45 uint16_t key_id; 46 uint8_t ipn[6]; 47 uint8_t mic[16]; 48 }; 49 50 #define IEEE80211_CCMP_HDR_LEN 8 /* 802.11i .. net80211 comment */ 51 #define IEEE80211_CCMP_PN_LEN 6 52 #define IEEE80211_CCMP_MIC_LEN 8 /* || 16 */ 53 #define IEEE80211_CCMP_256_HDR_LEN 8 54 #define IEEE80211_CCMP_256_MIC_LEN 16 55 #define IEEE80211_GCMP_HDR_LEN 8 56 #define IEEE80211_GCMP_MIC_LEN 16 57 #define IEEE80211_GCMP_PN_LEN 6 58 #define IEEE80211_GMAC_PN_LEN 6 59 60 #define IEEE80211_MAX_PN_LEN 16 61 62 #define IEEE80211_INVAL_HW_QUEUE ((uint8_t)-1) 63 64 #define IEEE80211_MAX_AMPDU_BUF_HT IEEE80211_AGGR_BAWMAX 65 #define IEEE80211_MAX_AMPDU_BUF_HE 256 66 #define IEEE80211_MAX_AMPDU_BUF_EHT 1024 67 68 #define IEEE80211_MAX_FRAME_LEN 2352 69 #define IEEE80211_MAX_DATA_LEN (2300 + IEEE80211_CRC_LEN) 70 71 #define IEEE80211_MAX_MPDU_LEN_HT_BA 4095 /* 9.3.2.1 Format of Data frames; non-VHT non-DMG STA */ 72 #define IEEE80211_MAX_MPDU_LEN_HT_3839 3839 73 #define IEEE80211_MAX_MPDU_LEN_HT_7935 7935 74 #define IEEE80211_MAX_MPDU_LEN_VHT_3895 3895 75 #define IEEE80211_MAX_MPDU_LEN_VHT_7991 7991 76 #define IEEE80211_MAX_MPDU_LEN_VHT_11454 11454 77 78 #define IEEE80211_MAX_RTS_THRESHOLD 2346 /* net80211::IEEE80211_RTS_MAX */ 79 80 #define IEEE80211_MIN_ACTION_SIZE 23 /* ? */ 81 82 /* Wi-Fi Peer-to-Peer (P2P) Technical Specification */ 83 #define IEEE80211_P2P_OPPPS_CTWINDOW_MASK 0x7f 84 #define IEEE80211_P2P_OPPPS_ENABLE_BIT BIT(7) 85 86 /* 802.11-2016, 9.2.4.5.1, Table 9-6 QoS Control Field */ 87 #define IEEE80211_QOS_CTL_TAG1D_MASK 0x0007 88 #define IEEE80211_QOS_CTL_TID_MASK IEEE80211_QOS_TID 89 #define IEEE80211_QOS_CTL_EOSP 0x0010 90 #define IEEE80211_QOS_CTL_A_MSDU_PRESENT 0x0080 91 #define IEEE80211_QOS_CTL_ACK_POLICY_MASK 0x0060 92 #define IEEE80211_QOS_CTL_ACK_POLICY_NOACK 0x0020 93 #define IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT 0x0100 94 95 #define IEEE80211_RATE_SHORT_PREAMBLE BIT(0) 96 97 enum ieee80211_rate_control_changed_flags { 98 IEEE80211_RC_BW_CHANGED = BIT(0), 99 IEEE80211_RC_NSS_CHANGED = BIT(1), 100 IEEE80211_RC_SUPP_RATES_CHANGED = BIT(2), 101 IEEE80211_RC_SMPS_CHANGED = BIT(3), 102 }; 103 104 #define IEEE80211_SCTL_FRAG IEEE80211_SEQ_FRAG_MASK 105 #define IEEE80211_SCTL_SEQ IEEE80211_SEQ_SEQ_MASK 106 107 #define IEEE80211_TKIP_ICV_LEN 4 108 #define IEEE80211_TKIP_IV_LEN 8 /* WEP + KID + EXT */ 109 110 #define IEEE80211_VHT_EXT_NSS_BW_CAPABLE (1 << 13) /* assigned to tx_highest */ 111 112 #define IEEE80211_VHT_MAX_AMPDU_1024K 7 /* 9.4.2.56.3 A-MPDU Parameters field, Table 9-163 */ 113 114 #define IEEE80211_WEP_IV_LEN 3 /* net80211: IEEE80211_WEP_IVLEN */ 115 #define IEEE80211_WEP_ICV_LEN 4 116 117 #define WLAN_AUTH_OPEN __LINE__ /* TODO FIXME brcmfmac */ 118 #define WLAN_CAPABILITY_IBSS __LINE__ /* TODO FIXME no longer used? */ 119 #define WLAN_CAPABILITY_SHORT_PREAMBLE __LINE__ /* TODO FIXME brcmfmac */ 120 #define WLAN_CAPABILITY_SHORT_SLOT_TIME __LINE__ /* TODO FIXME brcmfmac */ 121 122 enum wlan_ht_cap_sm_ps { 123 WLAN_HT_CAP_SM_PS_STATIC = 0, 124 WLAN_HT_CAP_SM_PS_DYNAMIC, 125 WLAN_HT_CAP_SM_PS_INVALID, 126 WLAN_HT_CAP_SM_PS_DISABLED, 127 }; 128 129 #define WLAN_MAX_KEY_LEN 32 130 #define WLAN_PMKID_LEN 16 131 #define WLAN_PMK_LEN_SUITE_B_192 48 132 133 #define WLAN_KEY_LEN_WEP40 5 134 #define WLAN_KEY_LEN_WEP104 13 135 #define WLAN_KEY_LEN_TKIP 32 136 #define WLAN_KEY_LEN_CCMP 16 137 #define WLAN_KEY_LEN_GCMP 16 138 #define WLAN_KEY_LEN_AES_CMAC 16 139 #define WLAN_KEY_LEN_GCMP_256 32 140 #define WLAN_KEY_LEN_BIP_CMAC_256 32 141 #define WLAN_KEY_LEN_BIP_GMAC_128 16 142 #define WLAN_KEY_LEN_BIP_GMAC_256 32 143 144 /* 802.11-2020, 9.4.2.55.3, Table 9-185 Subfields of the A-MPDU Parameters field */ 145 enum ieee80211_min_mpdu_start_spacing { 146 IEEE80211_HT_MPDU_DENSITY_NONE = 0, 147 #if 0 148 IEEE80211_HT_MPDU_DENSITY_XXX = 1, /* 1/4 us */ 149 #endif 150 IEEE80211_HT_MPDU_DENSITY_0_5 = 2, /* 1/2 us */ 151 IEEE80211_HT_MPDU_DENSITY_1 = 3, /* 1 us */ 152 IEEE80211_HT_MPDU_DENSITY_2 = 4, /* 2 us */ 153 IEEE80211_HT_MPDU_DENSITY_4 = 5, /* 4us */ 154 IEEE80211_HT_MPDU_DENSITY_8 = 6, /* 8us */ 155 IEEE80211_HT_MPDU_DENSITY_16 = 7, /* 16us */ 156 }; 157 158 /* 9.4.2.57, Table 9-168, HT Operation element fields and subfields */ 159 #define IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT 0x0080 /* B24.. */ 160 161 #define IEEE80211_FCTL_FTYPE IEEE80211_FC0_TYPE_MASK 162 #define IEEE80211_FCTL_STYPE IEEE80211_FC0_SUBTYPE_MASK 163 #define IEEE80211_FCTL_ORDER (IEEE80211_FC1_ORDER << 8) 164 #define IEEE80211_FCTL_PROTECTED (IEEE80211_FC1_PROTECTED << 8) 165 #define IEEE80211_FCTL_FROMDS (IEEE80211_FC1_DIR_FROMDS << 8) 166 #define IEEE80211_FCTL_TODS (IEEE80211_FC1_DIR_TODS << 8) 167 #define IEEE80211_FCTL_MOREFRAGS (IEEE80211_FC1_MORE_FRAG << 8) 168 #define IEEE80211_FCTL_PM (IEEE80211_FC1_PWR_MGT << 8) 169 170 #define IEEE80211_FTYPE_MGMT IEEE80211_FC0_TYPE_MGT 171 #define IEEE80211_FTYPE_CTL IEEE80211_FC0_TYPE_CTL 172 #define IEEE80211_FTYPE_DATA IEEE80211_FC0_TYPE_DATA 173 174 #define IEEE80211_STYPE_ASSOC_REQ IEEE80211_FC0_SUBTYPE_ASSOC_REQ 175 #define IEEE80211_STYPE_REASSOC_REQ IEEE80211_FC0_SUBTYPE_REASSOC_REQ 176 #define IEEE80211_STYPE_PROBE_REQ IEEE80211_FC0_SUBTYPE_PROBE_REQ 177 #define IEEE80211_STYPE_DISASSOC IEEE80211_FC0_SUBTYPE_DISASSOC 178 #define IEEE80211_STYPE_AUTH IEEE80211_FC0_SUBTYPE_AUTH 179 #define IEEE80211_STYPE_DEAUTH IEEE80211_FC0_SUBTYPE_DEAUTH 180 #define IEEE80211_STYPE_CTS IEEE80211_FC0_SUBTYPE_CTS 181 #define IEEE80211_STYPE_RTS IEEE80211_FC0_SUBTYPE_RTS 182 #define IEEE80211_STYPE_ACTION IEEE80211_FC0_SUBTYPE_ACTION 183 #define IEEE80211_STYPE_DATA IEEE80211_FC0_SUBTYPE_DATA 184 #define IEEE80211_STYPE_QOS_DATA IEEE80211_FC0_SUBTYPE_QOS_DATA 185 #define IEEE80211_STYPE_QOS_NULLFUNC IEEE80211_FC0_SUBTYPE_QOS_NULL 186 #define IEEE80211_STYPE_QOS_CFACK 0xd0 /* XXX-BZ reserved? */ 187 188 #define IEEE80211_NUM_ACS 4 /* net8021::WME_NUM_AC */ 189 190 #define IEEE80211_MAX_SSID_LEN 32 /* 9.4.2.2 SSID element, net80211: IEEE80211_NWID_LEN */ 191 192 193 /* Figure 9-27, BAR Control field */ 194 #define IEEE80211_BAR_CTRL_TID_INFO_MASK 0xf000 195 #define IEEE80211_BAR_CTRL_TID_INFO_SHIFT 12 196 197 #define IEEE80211_PPE_THRES_INFO_PPET_SIZE 1 /* TODO FIXME ax? */ 198 #define IEEE80211_PPE_THRES_NSS_MASK 2 /* TODO FIXME ax? */ 199 #define IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS 3 /* TODO FIXME ax? */ 200 #define IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK 8 /* TODO FIXME ax? */ 201 #define IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE 16 /* TODO FIXME ax? */ 202 203 /* 802.11-2012, Table 8-130-HT Operation element fields and subfields, HT Protection */ 204 #define IEEE80211_HT_OP_MODE_PROTECTION IEEE80211_HTINFO_OPMODE /* Mask. */ 205 #define IEEE80211_HT_OP_MODE_PROTECTION_NONE IEEE80211_HTINFO_OPMODE_PURE /* No protection */ 206 #define IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER IEEE80211_HTINFO_OPMODE_PROTOPT /* Nonmember protection */ 207 #define IEEE80211_HT_OP_MODE_PROTECTION_20MHZ IEEE80211_HTINFO_OPMODE_HT20PR /* 20 MHz protection */ 208 #define IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED IEEE80211_HTINFO_OPMODE_MIXED /* Non-HT mixed */ 209 210 211 /* 9.6.13.1, Table 9-342 TDLS Action field values. */ 212 enum ieee80211_tdls_action_code { 213 WLAN_TDLS_SETUP_REQUEST = 0, 214 WLAN_TDLS_SETUP_RESPONSE = 1, 215 WLAN_TDLS_SETUP_CONFIRM = 2, 216 WLAN_TDLS_TEARDOWN = 3, 217 WLAN_TDLS_PEER_TRAFFIC_INDICATION = 4, 218 WLAN_TDLS_CHANNEL_SWITCH_REQUEST = 5, 219 WLAN_TDLS_CHANNEL_SWITCH_RESPONSE = 6, 220 WLAN_TDLS_PEER_PSM_REQUEST = 7, 221 WLAN_TDLS_PEER_PSM_RESPONSE = 8, 222 WLAN_TDLS_PEER_TRAFFIC_RESPONSE = 9, 223 WLAN_TDLS_DISCOVERY_REQUEST = 10, 224 /* 11-255 reserved */ 225 }; 226 227 /* 802.11-2020 9.4.2.26, Table 9-153. Extended Capabilities field. */ 228 /* This is split up into octets CAPA1 = octet 1, ... */ 229 #define WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING BIT(2 % 8) 230 #define WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT BIT(22 % 8) 231 #define WLAN_EXT_CAPA3_TIMING_MEASUREMENT_SUPPORT BIT(23 % 8) 232 #define WLAN_EXT_CAPA8_OPMODE_NOTIF BIT(62 % 8) 233 #define WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB BIT(63 % 8) 234 #define WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB BIT(64 % 8) 235 #define WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT BIT(77 % 8) 236 #define WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT BIT(78 % 8) 237 #define WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT BIT(79 % 8) 238 239 #define WLAN_EXT_CAPA11_EMA_SUPPORT 0x00 /* XXX TODO FIXME */ 240 241 242 /* iwlwifi/mvm/utils:: for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_VI; ac++) */ 243 /* Would be so much easier if we'd define constants to the same. */ 244 enum ieee80211_ac_numbers { 245 IEEE80211_AC_VO = 0, /* net80211::WME_AC_VO */ 246 IEEE80211_AC_VI = 1, /* net80211::WME_AC_VI */ 247 IEEE80211_AC_BE = 2, /* net80211::WME_AC_BE */ 248 IEEE80211_AC_BK = 3, /* net80211::WME_AC_BK */ 249 }; 250 251 #define IEEE80211_MAX_QUEUES 16 /* Assume IEEE80211_NUM_TIDS for the moment. */ 252 253 #define IEEE80211_WMM_IE_STA_QOSINFO_AC_VO 1 254 #define IEEE80211_WMM_IE_STA_QOSINFO_AC_VI 2 255 #define IEEE80211_WMM_IE_STA_QOSINFO_AC_BK 4 256 #define IEEE80211_WMM_IE_STA_QOSINFO_AC_BE 8 257 #define IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL 0xf 258 259 260 /* Define the LinuxKPI names directly to the net80211 ones. */ 261 #define IEEE80211_HT_CAP_LDPC_CODING IEEE80211_HTCAP_LDPC 262 #define IEEE80211_HT_CAP_SUP_WIDTH_20_40 IEEE80211_HTCAP_CHWIDTH40 263 #define IEEE80211_HT_CAP_SM_PS IEEE80211_HTCAP_SMPS 264 #define IEEE80211_HT_CAP_SM_PS_SHIFT 2 265 #define IEEE80211_HT_CAP_GRN_FLD IEEE80211_HTCAP_GREENFIELD 266 #define IEEE80211_HT_CAP_SGI_20 IEEE80211_HTCAP_SHORTGI20 267 #define IEEE80211_HT_CAP_SGI_40 IEEE80211_HTCAP_SHORTGI40 268 #define IEEE80211_HT_CAP_TX_STBC IEEE80211_HTCAP_TXSTBC 269 #define IEEE80211_HT_CAP_RX_STBC IEEE80211_HTCAP_RXSTBC 270 #define IEEE80211_HT_CAP_RX_STBC_SHIFT IEEE80211_HTCAP_RXSTBC_S 271 #define IEEE80211_HT_CAP_MAX_AMSDU IEEE80211_HTCAP_MAXAMSDU 272 #define IEEE80211_HT_CAP_DSSSCCK40 IEEE80211_HTCAP_DSSSCCK40 273 #define IEEE80211_HT_CAP_LSIG_TXOP_PROT IEEE80211_HTCAP_LSIGTXOPPROT 274 275 #define IEEE80211_HT_MCS_TX_DEFINED 0x0001 276 #define IEEE80211_HT_MCS_TX_RX_DIFF 0x0002 277 #define IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT 2 278 #define IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK 0x0c 279 #define IEEE80211_HT_MCS_RX_HIGHEST_MASK 0x3ff 280 #define IEEE80211_HT_MCS_MASK_LEN 10 281 282 #define IEEE80211_MLD_MAX_NUM_LINKS 15 283 #define IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP 0x0060 284 #define IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP_SAME 1 285 286 struct ieee80211_mcs_info { 287 uint8_t rx_mask[IEEE80211_HT_MCS_MASK_LEN]; 288 uint16_t rx_highest; 289 uint8_t tx_params; 290 uint8_t __reserved[3]; 291 }; 292 293 /* 802.11-2020, 9.4.2.55.1 HT Capabilities element structure */ 294 struct ieee80211_ht_cap { 295 uint16_t cap_info; 296 uint8_t ampdu_params_info; 297 struct ieee80211_mcs_info mcs; 298 uint16_t extended_ht_cap_info; 299 uint32_t tx_BF_cap_info; 300 uint8_t antenna_selection_info; 301 }; 302 303 #define IEEE80211_HT_MAX_AMPDU_FACTOR 13 304 #define IEEE80211_HE_HT_MAX_AMPDU_FACTOR 16 305 #define IEEE80211_HE_VHT_MAX_AMPDU_FACTOR 20 306 #define IEEE80211_HE_6GHZ_MAX_AMPDU_FACTOR 13 307 308 enum ieee80211_ht_max_ampdu_len { 309 IEEE80211_HT_MAX_AMPDU_64K 310 }; 311 312 enum ieee80211_ampdu_mlme_action { 313 IEEE80211_AMPDU_RX_START, 314 IEEE80211_AMPDU_RX_STOP, 315 IEEE80211_AMPDU_TX_OPERATIONAL, 316 IEEE80211_AMPDU_TX_START, 317 IEEE80211_AMPDU_TX_STOP_CONT, 318 IEEE80211_AMPDU_TX_STOP_FLUSH, 319 IEEE80211_AMPDU_TX_STOP_FLUSH_CONT 320 }; 321 322 #define IEEE80211_AMPDU_TX_START_IMMEDIATE 1 323 #define IEEE80211_AMPDU_TX_START_DELAY_ADDBA 2 324 325 enum ieee80211_chanctx_switch_mode { 326 CHANCTX_SWMODE_REASSIGN_VIF, 327 CHANCTX_SWMODE_SWAP_CONTEXTS, 328 }; 329 330 enum ieee80211_chanctx_change_flags { 331 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH = BIT(0), 332 IEEE80211_CHANCTX_CHANGE_RADAR = BIT(1), 333 IEEE80211_CHANCTX_CHANGE_RX_CHAINS = BIT(2), 334 IEEE80211_CHANCTX_CHANGE_WIDTH = BIT(3), 335 IEEE80211_CHANCTX_CHANGE_CHANNEL = BIT(4), 336 IEEE80211_CHANCTX_CHANGE_PUNCTURING = BIT(5), 337 }; 338 339 enum ieee80211_frame_release_type { 340 IEEE80211_FRAME_RELEASE_PSPOLL = 1, 341 IEEE80211_FRAME_RELEASE_UAPSD = 2, 342 }; 343 344 enum ieee80211_p2p_attr_ids { 345 IEEE80211_P2P_ATTR_DEVICE_ID, 346 IEEE80211_P2P_ATTR_DEVICE_INFO, 347 IEEE80211_P2P_ATTR_GROUP_ID, 348 IEEE80211_P2P_ATTR_LISTEN_CHANNEL, 349 IEEE80211_P2P_ATTR_ABSENCE_NOTICE, 350 }; 351 352 enum ieee80211_reconfig_type { 353 IEEE80211_RECONFIG_TYPE_RESTART, 354 IEEE80211_RECONFIG_TYPE_SUSPEND, 355 }; 356 357 enum ieee80211_roc_type { 358 IEEE80211_ROC_TYPE_MGMT_TX, 359 IEEE80211_ROC_TYPE_NORMAL, 360 }; 361 362 enum ieee80211_smps_mode { 363 IEEE80211_SMPS_OFF, 364 IEEE80211_SMPS_STATIC, 365 IEEE80211_SMPS_DYNAMIC, 366 IEEE80211_SMPS_AUTOMATIC, 367 IEEE80211_SMPS_NUM_MODES, 368 }; 369 370 /* net80211::IEEE80211_S_* different but represents the state machine. */ 371 /* Note: order here is important! */ 372 enum ieee80211_sta_state { 373 IEEE80211_STA_NOTEXIST = 0, 374 IEEE80211_STA_NONE = 1, 375 IEEE80211_STA_AUTH = 2, 376 IEEE80211_STA_ASSOC = 3, 377 IEEE80211_STA_AUTHORIZED = 4, /* 802.1x */ 378 }; 379 380 enum ieee80211_sta_rx_bw { 381 IEEE80211_STA_RX_BW_20, 382 IEEE80211_STA_RX_BW_40, 383 IEEE80211_STA_RX_BW_80, 384 IEEE80211_STA_RX_BW_160, 385 IEEE80211_STA_RX_BW_320, 386 }; 387 388 enum ieee80211_tx_info_flags { 389 /* XXX TODO .. right shift numbers - not sure where that came from? */ 390 IEEE80211_TX_CTL_AMPDU = BIT(0), 391 IEEE80211_TX_CTL_ASSIGN_SEQ = BIT(1), 392 IEEE80211_TX_CTL_NO_ACK = BIT(2), 393 IEEE80211_TX_CTL_SEND_AFTER_DTIM = BIT(3), 394 IEEE80211_TX_CTL_TX_OFFCHAN = BIT(4), 395 IEEE80211_TX_CTL_REQ_TX_STATUS = BIT(5), 396 IEEE80211_TX_STATUS_EOSP = BIT(6), 397 IEEE80211_TX_STAT_ACK = BIT(7), 398 IEEE80211_TX_STAT_AMPDU = BIT(8), 399 IEEE80211_TX_STAT_AMPDU_NO_BACK = BIT(9), 400 IEEE80211_TX_STAT_TX_FILTERED = BIT(10), 401 IEEE80211_TX_STAT_NOACK_TRANSMITTED = BIT(11), 402 IEEE80211_TX_CTL_FIRST_FRAGMENT = BIT(12), 403 IEEE80211_TX_INTFL_DONT_ENCRYPT = BIT(13), 404 IEEE80211_TX_CTL_NO_CCK_RATE = BIT(14), 405 IEEE80211_TX_CTL_INJECTED = BIT(15), 406 IEEE80211_TX_CTL_HW_80211_ENCAP = BIT(16), 407 IEEE80211_TX_CTL_USE_MINRATE = BIT(17), 408 IEEE80211_TX_CTL_RATE_CTRL_PROBE = BIT(18), 409 IEEE80211_TX_CTL_LDPC = BIT(19), 410 IEEE80211_TX_CTL_STBC = BIT(20), 411 }; 412 413 enum ieee80211_tx_status_flags { 414 IEEE80211_TX_STATUS_ACK_SIGNAL_VALID = BIT(0), 415 }; 416 417 enum ieee80211_tx_control_flags { 418 /* XXX TODO .. right shift numbers */ 419 IEEE80211_TX_CTRL_PORT_CTRL_PROTO = BIT(0), 420 IEEE80211_TX_CTRL_PS_RESPONSE = BIT(1), 421 IEEE80211_TX_CTRL_RATE_INJECT = BIT(2), 422 IEEE80211_TX_CTRL_MLO_LINK = 0xF0000000, /* This is IEEE80211_LINK_UNSPECIFIED on the high bits. */ 423 }; 424 425 enum ieee80211_tx_rate_flags { 426 /* XXX TODO .. right shift numbers */ 427 IEEE80211_TX_RC_40_MHZ_WIDTH = BIT(0), 428 IEEE80211_TX_RC_80_MHZ_WIDTH = BIT(1), 429 IEEE80211_TX_RC_160_MHZ_WIDTH = BIT(2), 430 IEEE80211_TX_RC_GREEN_FIELD = BIT(3), 431 IEEE80211_TX_RC_MCS = BIT(4), 432 IEEE80211_TX_RC_SHORT_GI = BIT(5), 433 IEEE80211_TX_RC_VHT_MCS = BIT(6), 434 IEEE80211_TX_RC_USE_SHORT_PREAMBLE = BIT(7), 435 }; 436 437 #define IEEE80211_RNR_TBTT_PARAMS_PSD_RESERVED -128 438 439 #define IEEE80211_HT_CTL_LEN 4 440 441 struct ieee80211_hdr { /* net80211::ieee80211_frame_addr4 */ 442 __le16 frame_control; 443 __le16 duration_id; 444 uint8_t addr1[ETH_ALEN]; 445 uint8_t addr2[ETH_ALEN]; 446 uint8_t addr3[ETH_ALEN]; 447 __le16 seq_ctrl; 448 uint8_t addr4[ETH_ALEN]; 449 }; 450 451 struct ieee80211_hdr_3addr { /* net80211::ieee80211_frame */ 452 __le16 frame_control; 453 __le16 duration_id; 454 uint8_t addr1[ETH_ALEN]; 455 uint8_t addr2[ETH_ALEN]; 456 uint8_t addr3[ETH_ALEN]; 457 __le16 seq_ctrl; 458 }; 459 460 struct ieee80211_qos_hdr { /* net80211:ieee80211_qosframe */ 461 __le16 frame_control; 462 __le16 duration_id; 463 uint8_t addr1[ETH_ALEN]; 464 uint8_t addr2[ETH_ALEN]; 465 uint8_t addr3[ETH_ALEN]; 466 __le16 seq_ctrl; 467 __le16 qos_ctrl; 468 }; 469 470 struct ieee80211_vendor_ie { 471 }; 472 473 /* 802.11-2020, Table 9-359-Block Ack Action field values */ 474 enum ieee80211_back { 475 WLAN_ACTION_ADDBA_REQ = 0, 476 }; 477 478 /* 802.11-2020, Table 9-51-Category values */ 479 enum ieee80211_category { 480 WLAN_CATEGORY_BACK = 3, 481 }; 482 483 /* 80211-2020 9.3.3.2 Format of Management frames */ 484 struct ieee80211_mgmt { 485 __le16 frame_control; 486 __le16 duration_id; 487 uint8_t da[ETH_ALEN]; 488 uint8_t sa[ETH_ALEN]; 489 uint8_t bssid[ETH_ALEN]; 490 __le16 seq_ctrl; 491 union { 492 /* 9.3.3.3 Beacon frame format */ 493 struct { 494 uint64_t timestamp; 495 uint16_t beacon_int; 496 uint16_t capab_info; 497 uint8_t variable[0]; 498 } beacon; 499 /* 9.3.3.10 Probe Request frame format */ 500 struct { 501 uint8_t variable[0]; 502 } probe_req; 503 /* 9.3.3.11 Probe Response frame format */ 504 struct { 505 uint64_t timestamp; 506 uint16_t beacon_int; 507 uint16_t capab_info; 508 uint8_t variable[0]; 509 } probe_resp; 510 /* 9.3.3.14 Action frame format */ 511 struct { 512 /* 9.4.1.11 Action field */ 513 uint8_t category; 514 /* 9.6.8 Public Action details */ 515 union { 516 /* 9.6.2.5 TPC Report frame format */ 517 struct { 518 uint8_t spec_mgmt; 519 uint8_t dialog_token; 520 /* uint32_t tpc_rep_elem:: */ 521 uint8_t tpc_elem_id; 522 uint8_t tpc_elem_length; 523 uint8_t tpc_elem_tx_power; 524 uint8_t tpc_elem_link_margin; 525 } tpc_report; 526 /* 9.6.8.33 Fine Timing Measurement frame format */ 527 struct { 528 uint8_t dialog_token; 529 uint8_t follow_up; 530 uint8_t tod[6]; 531 uint8_t toa[6]; 532 uint16_t tod_error; 533 uint16_t toa_error; 534 uint8_t variable[0]; 535 } ftm; 536 /* 802.11-2016, 9.6.5.2 ADDBA Request frame format */ 537 struct { 538 uint8_t action_code; 539 uint8_t dialog_token; 540 uint16_t capab; 541 uint16_t timeout; 542 uint16_t start_seq_num; 543 /* Optional follows... */ 544 uint8_t variable[0]; 545 } addba_req; 546 /* XXX */ 547 struct { 548 uint8_t dialog_token; 549 } wnm_timing_msr; 550 } u; 551 } action; 552 DECLARE_FLEX_ARRAY(uint8_t, body); 553 } u; 554 }; 555 556 struct ieee80211_cts { /* net80211::ieee80211_frame_cts */ 557 __le16 frame_control; 558 __le16 duration; 559 uint8_t ra[ETH_ALEN]; 560 } __packed; 561 562 struct ieee80211_rts { /* net80211::ieee80211_frame_rts */ 563 __le16 frame_control; 564 __le16 duration; 565 uint8_t ra[ETH_ALEN]; 566 uint8_t ta[ETH_ALEN]; 567 } __packed; 568 569 #define MHZ_TO_KHZ(_f) ((_f) * 1000) 570 #define DBI_TO_MBI(_g) ((_g) * 100) 571 #define MBI_TO_DBI(_x) ((_x) / 100) 572 #define DBM_TO_MBM(_g) ((_g) * 100) 573 #define MBM_TO_DBM(_x) ((_x) / 100) 574 575 #define IEEE80211_SEQ_TO_SN(_seqn) (((_seqn) & IEEE80211_SEQ_SEQ_MASK) >> \ 576 IEEE80211_SEQ_SEQ_SHIFT) 577 #define IEEE80211_SN_TO_SEQ(_sn) (((_sn) << IEEE80211_SEQ_SEQ_SHIFT) & \ 578 IEEE80211_SEQ_SEQ_MASK) 579 580 /* Time unit (TU) to .. See net80211: IEEE80211_DUR_TU */ 581 #define TU_TO_JIFFIES(_tu) (usecs_to_jiffies(_tu) * 1024) 582 #define TU_TO_EXP_TIME(_tu) (jiffies + TU_TO_JIFFIES(_tu)) 583 584 /* 9.4.2.21.1, Table 9-82. */ 585 #define IEEE80211_SPCT_MSR_RPRT_TYPE_LCI 8 586 #define IEEE80211_SPCT_MSR_RPRT_TYPE_CIVIC 11 587 588 /* 9.4.2.1, Table 9-77. Element IDs. */ 589 enum ieee80211_eid { 590 WLAN_EID_SSID = 0, 591 WLAN_EID_SUPP_RATES = 1, 592 WLAN_EID_DS_PARAMS = 3, 593 WLAN_EID_TIM = 5, 594 WLAN_EID_COUNTRY = 7, /* IEEE80211_ELEMID_COUNTRY */ 595 WLAN_EID_REQUEST = 10, 596 WLAN_EID_CHANNEL_SWITCH = 37, 597 WLAN_EID_MEASURE_REPORT = 39, 598 WLAN_EID_HT_CAPABILITY = 45, /* IEEE80211_ELEMID_HTCAP */ 599 WLAN_EID_RSN = 48, /* IEEE80211_ELEMID_RSN */ 600 WLAN_EID_EXT_SUPP_RATES = 50, 601 WLAN_EID_EXT_NON_INHERITANCE = 56, 602 WLAN_EID_EXT_CHANSWITCH_ANN = 60, 603 WLAN_EID_MULTIPLE_BSSID = 71, /* IEEE80211_ELEMID_MULTIBSSID */ 604 WLAN_EID_MULTI_BSSID_IDX = 85, 605 WLAN_EID_EXT_CAPABILITY = 127, 606 WLAN_EID_VHT_CAPABILITY = 191, /* IEEE80211_ELEMID_VHT_CAP */ 607 WLAN_EID_VENDOR_SPECIFIC = 221, /* IEEE80211_ELEMID_VENDOR */ 608 }; 609 610 enum ieee80211_eid_ext { 611 WLAN_EID_EXT_HE_CAPABILITY = 35, 612 }; 613 614 #define for_each_element(_elem, _data, _len) \ 615 for (_elem = (const struct element *)(_data); \ 616 (((const uint8_t *)(_data) + (_len) - (const uint8_t *)_elem) >= sizeof(*_elem)) && \ 617 (((const uint8_t *)(_data) + (_len) - (const uint8_t *)_elem) >= (sizeof(*_elem) + _elem->datalen)); \ 618 _elem = (const struct element *)(_elem->data + _elem->datalen)) 619 620 #define for_each_element_id(_elem, _eid, _data, _len) \ 621 for_each_element(_elem, _data, _len) \ 622 if (_elem->id == (_eid)) 623 624 /* 9.4.1.7, Table 9-45. Reason codes. */ 625 enum ieee80211_reason_code { 626 /* reserved = 0, */ 627 WLAN_REASON_UNSPECIFIED = 1, 628 WLAN_REASON_DEAUTH_LEAVING = 3, /* LEAVING_NETWORK_DEAUTH */ 629 WLAN_REASON_TDLS_TEARDOWN_UNREACHABLE = 25, 630 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED = 26, 631 }; 632 633 /* 9.4.1.9, Table 9-46. Status codes. */ 634 enum ieee80211_status_code { 635 WLAN_STATUS_SUCCESS = 0, 636 WLAN_STATUS_AUTH_TIMEOUT = 16, /* REJECTED_SEQUENCE_TIMEOUT */ 637 }; 638 639 /* 9.3.1.22 Trigger frame format; 80211ax-2021 */ 640 struct ieee80211_trigger { 641 __le16 frame_control; 642 __le16 duration_id; 643 uint8_t ra[ETH_ALEN]; 644 uint8_t ta[ETH_ALEN]; 645 __le64 common_info; /* 8+ really */ 646 uint8_t variable[]; 647 }; 648 649 /* Table 9-29c-Trigger Type subfield encoding */ 650 enum { 651 IEEE80211_TRIGGER_TYPE_BASIC = 0x0, 652 IEEE80211_TRIGGER_TYPE_MU_BAR = 0x2, 653 #if 0 654 /* Not seen yet. */ 655 BFRP = 0x1, 656 MU-RTS = 0x3, 657 BSRP = 0x4, 658 GCR MU-BAR = 0x5, 659 BQRP = 0x6, 660 NFRP = 0x7, 661 /* 0x8..0xf reserved */ 662 #endif 663 IEEE80211_TRIGGER_TYPE_MASK = 0xf 664 }; 665 666 #define IEEE80211_TRIGGER_ULBW_MASK 0xc0000 667 #define IEEE80211_TRIGGER_ULBW_20MHZ 0x0 668 #define IEEE80211_TRIGGER_ULBW_40MHZ 0x1 669 #define IEEE80211_TRIGGER_ULBW_80MHZ 0x2 670 #define IEEE80211_TRIGGER_ULBW_160_80P80MHZ 0x3 671 672 /* 802.11-2020, Figure 9-687-Control field format; 802.11ax-2021 */ 673 #define IEEE80211_TWT_CONTROL_NEG_TYPE_BROADCAST BIT(3) 674 #define IEEE80211_TWT_CONTROL_RX_DISABLED BIT(4) 675 #define IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT BIT(5) 676 677 /* 802.11-2020, Figure 9-688-Request Type field format; 802.11ax-2021 */ 678 #define IEEE80211_TWT_REQTYPE_SETUP_CMD (BIT(1) | BIT(2) | BIT(3)) 679 #define IEEE80211_TWT_REQTYPE_TRIGGER BIT(4) 680 #define IEEE80211_TWT_REQTYPE_IMPLICIT BIT(5) 681 #define IEEE80211_TWT_REQTYPE_FLOWTYPE BIT(6) 682 #define IEEE80211_TWT_REQTYPE_FLOWID (BIT(7) | BIT(8) | BIT(9)) 683 #define IEEE80211_TWT_REQTYPE_WAKE_INT_EXP (BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14)) 684 #define IEEE80211_TWT_REQTYPE_PROTECTION BIT(15) 685 686 struct ieee80211_twt_params { 687 int mantissa, min_twt_dur, twt; 688 uint16_t req_type; 689 }; 690 691 struct ieee80211_twt_setup { 692 int control; 693 struct ieee80211_twt_params *params; 694 }; 695 696 /* 802.11-2020, Table 9-297-TWT Setup Command field values */ 697 enum ieee80211_twt_setup_cmd { 698 TWT_SETUP_CMD_REQUEST = 0, 699 TWT_SETUP_CMD_SUGGEST = 1, 700 /* DEMAND = 2, */ 701 /* GROUPING = 3, */ 702 TWT_SETUP_CMD_ACCEPT = 4, 703 /* ALTERNATE = 5 */ 704 TWT_SETUP_CMD_DICTATE = 6, 705 TWT_SETUP_CMD_REJECT = 7, 706 }; 707 708 struct ieee80211_bssid_index { 709 int bssid_index; 710 }; 711 712 enum ieee80211_ap_reg_power { 713 IEEE80211_REG_UNSET_AP, 714 IEEE80211_REG_LPI_AP, 715 IEEE80211_REG_SP_AP, 716 IEEE80211_REG_VLP_AP, 717 }; 718 719 /* 720 * 802.11ax-2021, Table 9-277-Meaning of Maximum Transmit Power Count subfield 721 * if Maximum Transmit Power Interpretation subfield is 1 or 3 722 */ 723 #define IEEE80211_MAX_NUM_PWR_LEVEL 8 724 725 /* 726 * 802.11ax-2021, Table 9-275a-Maximum Transmit Power Interpretation subfield 727 * encoding (4) * Table E-12-Regulatory Info subfield encoding in the 728 * United States (2) 729 */ 730 #define IEEE80211_TPE_MAX_IE_NUM 8 731 732 /* 802.11ax-2021, 9.4.2.161 Transmit Power Envelope element */ 733 struct ieee80211_tx_pwr_env { 734 uint8_t tx_power_info; 735 uint8_t tx_power[IEEE80211_MAX_NUM_PWR_LEVEL]; 736 }; 737 738 /* 802.11ax-2021, Figure 9-617-Transmit Power Information field format */ 739 /* These are field masks (3bit/3bit/2bit). */ 740 #define IEEE80211_TX_PWR_ENV_INFO_COUNT 0x07 741 #define IEEE80211_TX_PWR_ENV_INFO_INTERPRET 0x38 742 #define IEEE80211_TX_PWR_ENV_INFO_CATEGORY 0xc0 743 744 /* 745 * 802.11ax-2021, Table 9-275a-Maximum Transmit Power Interpretation subfield 746 * encoding 747 */ 748 enum ieee80211_tx_pwr_interpretation_subfield_enc { 749 IEEE80211_TPE_LOCAL_EIRP, 750 IEEE80211_TPE_LOCAL_EIRP_PSD, 751 IEEE80211_TPE_REG_CLIENT_EIRP, 752 IEEE80211_TPE_REG_CLIENT_EIRP_PSD, 753 }; 754 755 756 /* net80211: IEEE80211_IS_CTL() */ 757 static __inline bool 758 ieee80211_is_ctl(__le16 fc) 759 { 760 __le16 v; 761 762 fc &= htole16(IEEE80211_FC0_TYPE_MASK); 763 v = htole16(IEEE80211_FC0_TYPE_CTL); 764 765 return (fc == v); 766 } 767 768 /* net80211: IEEE80211_IS_DATA() */ 769 static __inline bool 770 ieee80211_is_data(__le16 fc) 771 { 772 __le16 v; 773 774 fc &= htole16(IEEE80211_FC0_TYPE_MASK); 775 v = htole16(IEEE80211_FC0_TYPE_DATA); 776 777 return (fc == v); 778 } 779 780 /* net80211: IEEE80211_IS_QOSDATA() */ 781 static __inline bool 782 ieee80211_is_data_qos(__le16 fc) 783 { 784 __le16 v; 785 786 fc &= htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA | IEEE80211_FC0_TYPE_MASK); 787 v = htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA | IEEE80211_FC0_TYPE_DATA); 788 789 return (fc == v); 790 } 791 792 /* net80211: IEEE80211_IS_MGMT() */ 793 static __inline bool 794 ieee80211_is_mgmt(__le16 fc) 795 { 796 __le16 v; 797 798 fc &= htole16(IEEE80211_FC0_TYPE_MASK); 799 v = htole16(IEEE80211_FC0_TYPE_MGT); 800 801 return (fc == v); 802 } 803 804 805 /* Derived from net80211::ieee80211_anyhdrsize. */ 806 static __inline unsigned int 807 ieee80211_hdrlen(__le16 fc) 808 { 809 unsigned int size; 810 811 if (ieee80211_is_ctl(fc)) { 812 switch (fc & htole16(IEEE80211_FC0_SUBTYPE_MASK)) { 813 case htole16(IEEE80211_FC0_SUBTYPE_CTS): 814 case htole16(IEEE80211_FC0_SUBTYPE_ACK): 815 return sizeof(struct ieee80211_frame_ack); 816 case htole16(IEEE80211_FC0_SUBTYPE_BAR): 817 return sizeof(struct ieee80211_frame_bar); 818 } 819 return (sizeof(struct ieee80211_frame_min)); 820 } 821 822 size = sizeof(struct ieee80211_frame); 823 if (ieee80211_is_data(fc)) { 824 if ((fc & htole16(IEEE80211_FC1_DIR_MASK << 8)) == 825 htole16(IEEE80211_FC1_DIR_DSTODS << 8)) 826 size += IEEE80211_ADDR_LEN; 827 if ((fc & htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA | 828 IEEE80211_FC0_TYPE_MASK)) == 829 htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA | 830 IEEE80211_FC0_TYPE_DATA)) 831 size += sizeof(uint16_t); 832 } 833 834 if (ieee80211_is_mgmt(fc)) { 835 #ifdef __notyet__ 836 printf("XXX-BZ %s: TODO? fc %#04x size %u\n", 837 __func__, fc, size); 838 #endif 839 ; 840 } 841 842 return (size); 843 } 844 845 static inline bool 846 ieee80211_is_trigger(__le16 fc) 847 { 848 __le16 v; 849 850 fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK); 851 v = htole16(IEEE80211_FC0_SUBTYPE_TRIGGER | IEEE80211_FC0_TYPE_CTL); 852 853 return (fc == v); 854 } 855 856 #endif /* _LINUXKPI_LINUX_IEEE80211_H */ 857