Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
0002 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
0003 
0004 #ifndef __IEEE80211_H
0005 #define __IEEE80211_H
0006 
0007 #include "osdep_service.h"
0008 #include "drv_types.h"
0009 #include "wifi.h"
0010 #include <linux/wireless.h>
0011 
0012 #define MGMT_QUEUE_NUM 5
0013 
0014 #define ETH_TYPE_LEN        2
0015 #define PAYLOAD_TYPE_LEN    1
0016 
0017 #define RTL_IOCTL_HOSTAPD (SIOCIWFIRSTPRIV + 28)
0018 
0019 /* STA flags */
0020 #define WLAN_STA_AUTH BIT(0)
0021 #define WLAN_STA_ASSOC BIT(1)
0022 #define WLAN_STA_PS BIT(2)
0023 #define WLAN_STA_TIM BIT(3)
0024 #define WLAN_STA_PERM BIT(4)
0025 #define WLAN_STA_AUTHORIZED BIT(5)
0026 #define WLAN_STA_PENDING_POLL BIT(6) /* pending activity poll not ACKed */
0027 #define WLAN_STA_SHORT_PREAMBLE BIT(7)
0028 #define WLAN_STA_PREAUTH BIT(8)
0029 #define WLAN_STA_WME BIT(9)
0030 #define WLAN_STA_MFP BIT(10)
0031 #define WLAN_STA_HT BIT(11)
0032 #define WLAN_STA_WPS BIT(12)
0033 #define WLAN_STA_MAYBE_WPS BIT(13)
0034 #define WLAN_STA_NONERP BIT(31)
0035 
0036 #define IEEE_CMD_SET_WPA_PARAM          1
0037 #define IEEE_CMD_SET_WPA_IE             2
0038 #define IEEE_CMD_SET_ENCRYPTION         3
0039 #define IEEE_CMD_MLME                       4
0040 
0041 #define IEEE_PARAM_WPA_ENABLED              1
0042 #define IEEE_PARAM_TKIP_COUNTERMEASURES     2
0043 #define IEEE_PARAM_DROP_UNENCRYPTED         3
0044 #define IEEE_PARAM_PRIVACY_INVOKED          4
0045 #define IEEE_PARAM_AUTH_ALGS                    5
0046 #define IEEE_PARAM_IEEE_802_1X              6
0047 #define IEEE_PARAM_WPAX_SELECT              7
0048 
0049 #define AUTH_ALG_OPEN_SYSTEM            0x1
0050 #define AUTH_ALG_SHARED_KEY         0x2
0051 #define AUTH_ALG_LEAP               0x00000004
0052 
0053 #define IEEE_MLME_STA_DEAUTH                1
0054 #define IEEE_MLME_STA_DISASSOC          2
0055 
0056 #define IEEE_CRYPT_ERR_UNKNOWN_ALG          2
0057 #define IEEE_CRYPT_ERR_UNKNOWN_ADDR         3
0058 #define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED        4
0059 #define IEEE_CRYPT_ERR_KEY_SET_FAILED           5
0060 #define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED        6
0061 #define IEEE_CRYPT_ERR_CARD_CONF_FAILED     7
0062 
0063 #define IEEE_CRYPT_ALG_NAME_LEN         16
0064 
0065 #define WPA_CIPHER_NONE     BIT(0)
0066 #define WPA_CIPHER_WEP40    BIT(1)
0067 #define WPA_CIPHER_WEP104 BIT(2)
0068 #define WPA_CIPHER_TKIP     BIT(3)
0069 #define WPA_CIPHER_CCMP     BIT(4)
0070 
0071 
0072 #define WPA_SELECTOR_LEN 4
0073 extern u8 RTW_WPA_OUI_TYPE[];
0074 extern u16 RTW_WPA_VERSION;
0075 extern u8 WPA_AUTH_KEY_MGMT_NONE[];
0076 extern u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[];
0077 extern u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[];
0078 extern u8 WPA_CIPHER_SUITE_NONE[];
0079 extern u8 WPA_CIPHER_SUITE_WEP40[];
0080 extern u8 WPA_CIPHER_SUITE_TKIP[];
0081 extern u8 WPA_CIPHER_SUITE_WRAP[];
0082 extern u8 WPA_CIPHER_SUITE_CCMP[];
0083 extern u8 WPA_CIPHER_SUITE_WEP104[];
0084 
0085 #define RSN_HEADER_LEN 4
0086 #define RSN_SELECTOR_LEN 4
0087 
0088 extern u16 RSN_VERSION_BSD;
0089 extern u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X[];
0090 extern u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X[];
0091 extern u8 RSN_CIPHER_SUITE_NONE[];
0092 extern u8 RSN_CIPHER_SUITE_WEP40[];
0093 extern u8 RSN_CIPHER_SUITE_TKIP[];
0094 extern u8 RSN_CIPHER_SUITE_WRAP[];
0095 extern u8 RSN_CIPHER_SUITE_CCMP[];
0096 extern u8 RSN_CIPHER_SUITE_WEP104[];
0097 
0098 enum ratr_table_mode {
0099     RATR_INX_WIRELESS_NGB = 0,  /*  BGN 40 Mhz 2SS 1SS */
0100     RATR_INX_WIRELESS_NG = 1,   /*  GN or N */
0101     RATR_INX_WIRELESS_NB = 2,   /*  BGN 20 Mhz 2SS 1SS  or BN */
0102     RATR_INX_WIRELESS_N = 3,
0103     RATR_INX_WIRELESS_GB = 4,
0104     RATR_INX_WIRELESS_G = 5,
0105     RATR_INX_WIRELESS_B = 6,
0106     RATR_INX_WIRELESS_MC = 7,
0107     RATR_INX_WIRELESS_AC_N = 8,
0108 };
0109 
0110 enum NETWORK_TYPE {
0111     WIRELESS_INVALID = 0,
0112     /* Sub-Element */
0113     WIRELESS_11B = BIT(0), /* tx:cck only, rx:cck only, hw: cck */
0114     WIRELESS_11G = BIT(1), /* tx:ofdm only, rx:ofdm & cck, hw:cck & ofdm*/
0115     WIRELESS_11_24N = BIT(3), /* tx:MCS only, rx:MCS & cck, hw:MCS & cck */
0116 
0117     /* Combination */
0118     /*  tx: cck & ofdm, rx: cck & ofdm & MCS, hw: cck & ofdm */
0119     WIRELESS_11BG = (WIRELESS_11B | WIRELESS_11G),
0120     /*  tx: ofdm & MCS, rx: ofdm & cck & MCS, hw: cck & ofdm */
0121     WIRELESS_11G_24N = (WIRELESS_11G | WIRELESS_11_24N),
0122     /*  tx: ofdm & cck & MCS, rx: ofdm & cck & MCS, hw: ofdm & cck */
0123     WIRELESS_11BG_24N = (WIRELESS_11B | WIRELESS_11G | WIRELESS_11_24N),
0124 };
0125 
0126 struct ieee_param {
0127     u32 cmd;
0128     u8 sta_addr[ETH_ALEN];
0129     union {
0130         struct {
0131             u8 name;
0132             u32 value;
0133         } wpa_param;
0134         struct {
0135             u32 len;
0136             u8 reserved[32];
0137             u8 data[];
0138         } wpa_ie;
0139         struct {
0140             int command;
0141             int reason_code;
0142         } mlme;
0143         struct {
0144             u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
0145             u8 set_tx;
0146             u32 err;
0147             u8 idx;
0148             u8 seq[8]; /* sequence counter (set: RX, get: TX) */
0149             u16 key_len;
0150             u8 key[];
0151         } crypt;
0152         struct {
0153             u16 aid;
0154             u16 capability;
0155             int flags;
0156             u8 tx_supp_rates[16];
0157             struct ieee80211_ht_cap ht_cap;
0158         } add_sta;
0159         struct {
0160             u8  reserved[2];/* for set max_num_sta */
0161             u8  buf[];
0162         } bcn_ie;
0163     } u;
0164 };
0165 
0166 #define IEEE80211_DATA_LEN      2304
0167 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
0168    6.2.1.1.2.
0169 
0170    The figure in section 7.1.2 suggests a body size of up to 2312
0171    bytes is allowed, which is a bit confusing, I suspect this
0172    represents the 2304 bytes of real data, plus a possible 8 bytes of
0173    WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
0174 
0175 #define IEEE80211_HLEN          30
0176 #define IEEE80211_FRAME_LEN     (IEEE80211_DATA_LEN + IEEE80211_HLEN)
0177 
0178 /* this is stolen from ipw2200 driver */
0179 #define IEEE_IBSS_MAC_HASH_SIZE 31
0180 
0181 #define IEEE80211_3ADDR_LEN 24
0182 #define IEEE80211_4ADDR_LEN 30
0183 #define IEEE80211_FCS_LEN    4
0184 
0185 #define MIN_FRAG_THRESHOLD     256U
0186 #define MAX_FRAG_THRESHOLD     2346U
0187 
0188 /* Frame control field constants */
0189 #define RTW_IEEE80211_FCTL_VERS     0x0003
0190 #define RTW_IEEE80211_FCTL_FTYPE    0x000c
0191 #define RTW_IEEE80211_FCTL_STYPE    0x00f0
0192 #define RTW_IEEE80211_FCTL_TODS     0x0100
0193 #define RTW_IEEE80211_FCTL_FROMDS   0x0200
0194 #define RTW_IEEE80211_FCTL_MOREFRAGS    0x0400
0195 #define RTW_IEEE80211_FCTL_RETRY    0x0800
0196 #define RTW_IEEE80211_FCTL_PM       0x1000
0197 #define RTW_IEEE80211_FCTL_MOREDATA 0x2000
0198 #define RTW_IEEE80211_FCTL_PROTECTED    0x4000
0199 #define RTW_IEEE80211_FCTL_ORDER    0x8000
0200 #define RTW_IEEE80211_FCTL_CTL_EXT  0x0f00
0201 
0202 #define RTW_IEEE80211_FTYPE_MGMT    0x0000
0203 #define RTW_IEEE80211_FTYPE_CTL     0x0004
0204 #define RTW_IEEE80211_FTYPE_DATA    0x0008
0205 #define RTW_IEEE80211_FTYPE_EXT     0x000c
0206 
0207 /* management */
0208 #define RTW_IEEE80211_STYPE_ASSOC_REQ   0x0000
0209 #define RTW_IEEE80211_STYPE_ASSOC_RESP  0x0010
0210 #define RTW_IEEE80211_STYPE_REASSOC_REQ 0x0020
0211 #define RTW_IEEE80211_STYPE_REASSOC_RESP    0x0030
0212 #define RTW_IEEE80211_STYPE_PROBE_REQ   0x0040
0213 #define RTW_IEEE80211_STYPE_PROBE_RESP  0x0050
0214 #define RTW_IEEE80211_STYPE_BEACON  0x0080
0215 #define RTW_IEEE80211_STYPE_ATIM    0x0090
0216 #define RTW_IEEE80211_STYPE_DISASSOC    0x00A0
0217 #define RTW_IEEE80211_STYPE_AUTH    0x00B0
0218 #define RTW_IEEE80211_STYPE_DEAUTH  0x00C0
0219 #define RTW_IEEE80211_STYPE_ACTION  0x00D0
0220 
0221 /* control */
0222 #define RTW_IEEE80211_STYPE_CTL_EXT 0x0060
0223 #define RTW_IEEE80211_STYPE_BACK_REQ    0x0080
0224 #define RTW_IEEE80211_STYPE_BACK    0x0090
0225 #define RTW_IEEE80211_STYPE_PSPOLL  0x00A0
0226 #define RTW_IEEE80211_STYPE_RTS     0x00B0
0227 #define RTW_IEEE80211_STYPE_CTS     0x00C0
0228 #define RTW_IEEE80211_STYPE_ACK     0x00D0
0229 #define RTW_IEEE80211_STYPE_CFEND   0x00E0
0230 #define RTW_IEEE80211_STYPE_CFENDACK    0x00F0
0231 
0232 /* data */
0233 #define RTW_IEEE80211_STYPE_DATA    0x0000
0234 #define RTW_IEEE80211_STYPE_DATA_CFACK  0x0010
0235 #define RTW_IEEE80211_STYPE_DATA_CFPOLL 0x0020
0236 #define RTW_IEEE80211_STYPE_DATA_CFACKPOLL  0x0030
0237 #define RTW_IEEE80211_STYPE_NULLFUNC    0x0040
0238 #define RTW_IEEE80211_STYPE_CFACK   0x0050
0239 #define RTW_IEEE80211_STYPE_CFPOLL  0x0060
0240 #define RTW_IEEE80211_STYPE_CFACKPOLL   0x0070
0241 #define RTW_IEEE80211_STYPE_QOS_DATA    0x0080
0242 #define RTW_IEEE80211_STYPE_QOS_DATA_CFACK  0x0090
0243 #define RTW_IEEE80211_STYPE_QOS_DATA_CFPOLL 0x00A0
0244 #define RTW_IEEE80211_STYPE_QOS_DATA_CFACKPOLL  0x00B0
0245 #define RTW_IEEE80211_STYPE_QOS_NULLFUNC    0x00C0
0246 #define RTW_IEEE80211_STYPE_QOS_CFACK       0x00D0
0247 #define RTW_IEEE80211_STYPE_QOS_CFPOLL      0x00E0
0248 #define RTW_IEEE80211_STYPE_QOS_CFACKPOLL   0x00F0
0249 
0250 /* sequence control field */
0251 #define RTW_IEEE80211_SCTL_FRAG 0x000F
0252 #define RTW_IEEE80211_SCTL_SEQ  0xFFF0
0253 
0254 #define RTW_ERP_INFO_NON_ERP_PRESENT BIT(0)
0255 #define RTW_ERP_INFO_USE_PROTECTION BIT(1)
0256 #define RTW_ERP_INFO_BARKER_PREAMBLE_MODE BIT(2)
0257 
0258 /* QoS, QOS */
0259 #define NORMAL_ACK          0
0260 #define NO_ACK              1
0261 #define NON_EXPLICIT_ACK        2
0262 #define BLOCK_ACK           3
0263 
0264 #ifndef ETH_P_PAE
0265 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
0266 #endif /* ETH_P_PAE */
0267 
0268 #define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
0269 
0270 #define ETH_P_ECONET    0x0018
0271 
0272 #ifndef ETH_P_80211_RAW
0273 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
0274 #endif
0275 
0276 /* IEEE 802.11 defines */
0277 
0278 #define P80211_OUI_LEN 3
0279 
0280 struct ieee80211_snap_hdr {
0281     u8    dsap;   /* always 0xAA */
0282     u8    ssap;   /* always 0xAA */
0283     u8    ctrl;   /* always 0x03 */
0284     u8    oui[P80211_OUI_LEN];    /* organizational universal id */
0285 } __packed;
0286 
0287 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
0288 
0289 #define WLAN_FC_GET_TYPE(fc) ((fc) & RTW_IEEE80211_FCTL_FTYPE)
0290 #define WLAN_FC_GET_STYPE(fc) ((fc) & RTW_IEEE80211_FCTL_STYPE)
0291 
0292 #define WLAN_QC_GET_TID(qc) ((qc) & 0x0f)
0293 
0294 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTW_IEEE80211_SCTL_FRAG)
0295 #define WLAN_GET_SEQ_SEQ(seq)  ((seq) & RTW_IEEE80211_SCTL_SEQ)
0296 
0297 /* Authentication algorithms */
0298 #define WLAN_AUTH_OPEN 0
0299 #define WLAN_AUTH_SHARED_KEY 1
0300 
0301 #define WLAN_AUTH_CHALLENGE_LEN 128
0302 
0303 #define WLAN_CAPABILITY_BSS (1<<0)
0304 #define WLAN_CAPABILITY_IBSS (1<<1)
0305 #define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
0306 #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
0307 #define WLAN_CAPABILITY_PRIVACY (1<<4)
0308 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
0309 #define WLAN_CAPABILITY_PBCC (1<<6)
0310 #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
0311 #define WLAN_CAPABILITY_SHORT_SLOT (1<<10)
0312 
0313 /* Status codes */
0314 #define WLAN_STATUS_SUCCESS 0
0315 #define WLAN_STATUS_UNSPECIFIED_FAILURE 1
0316 #define WLAN_STATUS_CAPS_UNSUPPORTED 10
0317 #define WLAN_STATUS_REASSOC_NO_ASSOC 11
0318 #define WLAN_STATUS_ASSOC_DENIED_UNSPEC 12
0319 #define WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG 13
0320 #define WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION 14
0321 #define WLAN_STATUS_CHALLENGE_FAIL 15
0322 #define WLAN_STATUS_AUTH_TIMEOUT 16
0323 #define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
0324 #define WLAN_STATUS_ASSOC_DENIED_RATES 18
0325 /* 802.11b */
0326 #define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
0327 #define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
0328 #define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
0329 
0330 /* Reason codes */
0331 #define WLAN_REASON_UNSPECIFIED 1
0332 #define WLAN_REASON_PREV_AUTH_NOT_VALID 2
0333 #define WLAN_REASON_DEAUTH_LEAVING 3
0334 #define WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY 4
0335 #define WLAN_REASON_DISASSOC_AP_BUSY 5
0336 #define WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
0337 #define WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7
0338 #define WLAN_REASON_DISASSOC_STA_HAS_LEFT 8
0339 #define WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
0340 #define WLAN_REASON_JOIN_WRONG_CHANNEL       65534
0341 #define WLAN_REASON_EXPIRATION_CHK 65535
0342 
0343 /* Information Element IDs */
0344 #define WLAN_EID_SSID 0
0345 #define WLAN_EID_SUPP_RATES 1
0346 #define WLAN_EID_FH_PARAMS 2
0347 #define WLAN_EID_DS_PARAMS 3
0348 #define WLAN_EID_CF_PARAMS 4
0349 #define WLAN_EID_TIM 5
0350 #define WLAN_EID_IBSS_PARAMS 6
0351 #define WLAN_EID_CHALLENGE 16
0352 /* EIDs defined by IEEE 802.11h - START */
0353 #define WLAN_EID_PWR_CONSTRAINT 32
0354 #define WLAN_EID_PWR_CAPABILITY 33
0355 #define WLAN_EID_TPC_REQUEST 34
0356 #define WLAN_EID_TPC_REPORT 35
0357 #define WLAN_EID_SUPPORTED_CHANNELS 36
0358 #define WLAN_EID_CHANNEL_SWITCH 37
0359 #define WLAN_EID_MEASURE_REQUEST 38
0360 #define WLAN_EID_MEASURE_REPORT 39
0361 #define WLAN_EID_QUITE 40
0362 #define WLAN_EID_IBSS_DFS 41
0363 /* EIDs defined by IEEE 802.11h - END */
0364 #define WLAN_EID_ERP_INFO 42
0365 #define WLAN_EID_HT_CAP 45
0366 #define WLAN_EID_RSN 48
0367 #define WLAN_EID_EXT_SUPP_RATES 50
0368 #define WLAN_EID_MOBILITY_DOMAIN 54
0369 #define WLAN_EID_FAST_BSS_TRANSITION 55
0370 #define WLAN_EID_TIMEOUT_INTERVAL 56
0371 #define WLAN_EID_RIC_DATA 57
0372 #define WLAN_EID_HT_OPERATION 61
0373 #define WLAN_EID_SECONDARY_CHANNEL_OFFSET 62
0374 #define WLAN_EID_20_40_BSS_COEXISTENCE 72
0375 #define WLAN_EID_20_40_BSS_INTOLERANT 73
0376 #define WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS 74
0377 #define WLAN_EID_MMIE 76
0378 #define WLAN_EID_VENDOR_SPECIFIC 221
0379 #define WLAN_EID_GENERIC (WLAN_EID_VENDOR_SPECIFIC)
0380 
0381 #define IEEE80211_MGMT_HDR_LEN 24
0382 #define IEEE80211_DATA_HDR3_LEN 24
0383 #define IEEE80211_DATA_HDR4_LEN 30
0384 
0385 #define IEEE80211_STATMASK_SIGNAL (1<<0)
0386 #define IEEE80211_STATMASK_RSSI (1<<1)
0387 #define IEEE80211_STATMASK_NOISE (1<<2)
0388 #define IEEE80211_STATMASK_RATE (1<<3)
0389 #define IEEE80211_STATMASK_WEMASK 0x7
0390 
0391 #define IEEE80211_CCK_MODULATION    (1<<0)
0392 #define IEEE80211_OFDM_MODULATION   (1<<1)
0393 
0394 #define IEEE80211_24GHZ_BAND     (1<<0)
0395 #define IEEE80211_52GHZ_BAND     (1<<1)
0396 
0397 #define IEEE80211_CCK_RATE_LEN          4
0398 #define IEEE80211_NUM_OFDM_RATESLEN 8
0399 
0400 #define IEEE80211_CCK_RATE_1MB          0x02
0401 #define IEEE80211_CCK_RATE_2MB          0x04
0402 #define IEEE80211_CCK_RATE_5MB          0x0B
0403 #define IEEE80211_CCK_RATE_11MB         0x16
0404 #define IEEE80211_OFDM_RATE_LEN         8
0405 #define IEEE80211_OFDM_RATE_6MB         0x0C
0406 #define IEEE80211_OFDM_RATE_9MB         0x12
0407 #define IEEE80211_OFDM_RATE_12MB        0x18
0408 #define IEEE80211_OFDM_RATE_18MB        0x24
0409 #define IEEE80211_OFDM_RATE_24MB        0x30
0410 #define IEEE80211_OFDM_RATE_36MB        0x48
0411 #define IEEE80211_OFDM_RATE_48MB        0x60
0412 #define IEEE80211_OFDM_RATE_54MB        0x6C
0413 #define IEEE80211_BASIC_RATE_MASK       0x80
0414 
0415 #define IEEE80211_CCK_RATE_1MB_MASK     (1<<0)
0416 #define IEEE80211_CCK_RATE_2MB_MASK     (1<<1)
0417 #define IEEE80211_CCK_RATE_5MB_MASK     (1<<2)
0418 #define IEEE80211_CCK_RATE_11MB_MASK        (1<<3)
0419 #define IEEE80211_OFDM_RATE_6MB_MASK        (1<<4)
0420 #define IEEE80211_OFDM_RATE_9MB_MASK        (1<<5)
0421 #define IEEE80211_OFDM_RATE_12MB_MASK       (1<<6)
0422 #define IEEE80211_OFDM_RATE_18MB_MASK       (1<<7)
0423 #define IEEE80211_OFDM_RATE_24MB_MASK       (1<<8)
0424 #define IEEE80211_OFDM_RATE_36MB_MASK       (1<<9)
0425 #define IEEE80211_OFDM_RATE_48MB_MASK       (1<<10)
0426 #define IEEE80211_OFDM_RATE_54MB_MASK       (1<<11)
0427 
0428 #define IEEE80211_CCK_RATES_MASK        0x0000000F
0429 #define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
0430     IEEE80211_CCK_RATE_2MB_MASK)
0431 #define IEEE80211_CCK_DEFAULT_RATES_MASK                \
0432     (IEEE80211_CCK_BASIC_RATES_MASK |               \
0433     IEEE80211_CCK_RATE_5MB_MASK |                   \
0434     IEEE80211_CCK_RATE_11MB_MASK)
0435 
0436 #define IEEE80211_OFDM_RATES_MASK       0x00000FF0
0437 #define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
0438     IEEE80211_OFDM_RATE_12MB_MASK |                 \
0439     IEEE80211_OFDM_RATE_24MB_MASK)
0440 #define IEEE80211_OFDM_DEFAULT_RATES_MASK               \
0441     (IEEE80211_OFDM_BASIC_RATES_MASK |              \
0442     IEEE80211_OFDM_RATE_9MB_MASK  |                 \
0443     IEEE80211_OFDM_RATE_18MB_MASK |                 \
0444     IEEE80211_OFDM_RATE_36MB_MASK |                 \
0445     IEEE80211_OFDM_RATE_48MB_MASK |                 \
0446     IEEE80211_OFDM_RATE_54MB_MASK)
0447 #define IEEE80211_DEFAULT_RATES_MASK                    \
0448     (IEEE80211_OFDM_DEFAULT_RATES_MASK |                \
0449      IEEE80211_CCK_DEFAULT_RATES_MASK)
0450 
0451 #define IEEE80211_NUM_OFDM_RATES    8
0452 #define IEEE80211_NUM_CCK_RATES     4
0453 #define IEEE80211_OFDM_SHIFT_MASK_A 4
0454 
0455 /* IEEE 802.11 requires that STA supports concurrent reception of at least
0456  * three fragmented frames. This define can be increased to support more
0457  * concurrent frames, but it should be noted that each entry can consume about
0458  * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
0459 #define IEEE80211_FRAG_CACHE_LEN 4
0460 
0461 #define SEC_KEY_1   (1<<0)
0462 #define SEC_KEY_2   (1<<1)
0463 #define SEC_KEY_3   (1<<2)
0464 #define SEC_KEY_4   (1<<3)
0465 #define SEC_ACTIVE_KEY  (1<<4)
0466 #define SEC_AUTH_MODE   (1<<5)
0467 #define SEC_UNICAST_GROUP (1<<6)
0468 #define SEC_LEVEL   (1<<7)
0469 #define SEC_ENABLED     (1<<8)
0470 
0471 #define SEC_LEVEL_0      0 /* None */
0472 #define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
0473 #define SEC_LEVEL_2      2 /* Level 1 + TKIP */
0474 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
0475 #define SEC_LEVEL_3      4 /* Level 2 + CCMP */
0476 
0477 #define WEP_KEYS 4
0478 #define WEP_KEY_LEN 13
0479 
0480 /*
0481 
0482  802.11 data frame from AP
0483 
0484       ,-------------------------------------------------------------------.
0485 Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
0486       |------|------|---------|---------|---------|------|---------|------|
0487 Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
0488       |      | tion | (BSSID) |  |   | ence |  data   |      |
0489       `-------------------------------------------------------------------'
0490 
0491 Total: 28-2340 bytes
0492 
0493 */
0494 
0495 #define BEACON_PROBE_SSID_ID_POSITION 12
0496 
0497 /* Management Frame Information Element Types */
0498 #define MFIE_TYPE_SSID      0
0499 #define MFIE_TYPE_RATES     1
0500 #define MFIE_TYPE_FH_SET    2
0501 #define MFIE_TYPE_DS_SET    3
0502 #define MFIE_TYPE_CF_SET    4
0503 #define MFIE_TYPE_TIM       5
0504 #define MFIE_TYPE_IBSS_SET  6
0505 #define MFIE_TYPE_CHALLENGE 16
0506 #define MFIE_TYPE_ERP       42
0507 #define MFIE_TYPE_RSN       48
0508 #define MFIE_TYPE_RATES_EX  50
0509 #define MFIE_TYPE_GENERIC   221
0510 
0511 /*
0512  * These are the data types that can make up management packets
0513  *
0514     u16 auth_algorithm;
0515     u16 auth_sequence;
0516     u16 beacon_interval;
0517     u16 capability;
0518     u8 current_ap[ETH_ALEN];
0519     u16 listen_interval;
0520     struct {
0521         u16 association_id:14, reserved:2;
0522     } __packed;
0523     u32 time_stamp[2];
0524     u16 reason;
0525     u16 status;
0526 */
0527 
0528 #define IEEE80211_DEFAULT_TX_ESSID "Penguin"
0529 #define IEEE80211_DEFAULT_BASIC_RATE 10
0530 
0531 /* SWEEP TABLE ENTRIES NUMBER*/
0532 #define MAX_SWEEP_TAB_ENTRIES         42
0533 #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
0534 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
0535  * only use 8, and then use extended rates for the remaining supported
0536  * rates.  Other APs, however, stick all of their supported rates on the
0537  * main rates information element... */
0538 #define MAX_RATES_LENGTH        ((u8)12)
0539 #define MAX_RATES_EX_LENGTH     ((u8)16)
0540 #define MAX_NETWORK_COUNT       128
0541 #define MAX_CHANNEL_NUMBER      161
0542 #define IEEE80211_SOFTMAC_SCAN_TIME 400
0543 /* HZ / 2) */
0544 #define IEEE80211_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
0545 
0546 #define CRC_LENGTH       4U
0547 
0548 #define MAX_WPA_IE_LEN (256)
0549 #define MAX_WPS_IE_LEN (512)
0550 #define MAX_P2P_IE_LEN (256)
0551 #define MAX_WFD_IE_LEN (128)
0552 
0553 #define NETWORK_EMPTY_ESSID (1<<0)
0554 #define NETWORK_HAS_OFDM    (1<<1)
0555 #define NETWORK_HAS_CCK     (1<<2)
0556 
0557 #define IEEE80211_DTIM_MBCAST 4
0558 #define IEEE80211_DTIM_UCAST 2
0559 #define IEEE80211_DTIM_VALID 1
0560 #define IEEE80211_DTIM_INVALID 0
0561 
0562 #define IEEE80211_PS_DISABLED 0
0563 #define IEEE80211_PS_UNICAST IEEE80211_DTIM_UCAST
0564 #define IEEE80211_PS_MBCAST IEEE80211_DTIM_MBCAST
0565 #define IW_ESSID_MAX_SIZE 32
0566 /*
0567 join_res:
0568 -1: authentication fail
0569 -2: association fail
0570 > 0: TID
0571 */
0572 
0573 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
0574 #define DEFAULT_FTS 2346
0575 
0576 static inline int is_multicast_mac_addr(const u8 *addr)
0577 {
0578     return ((addr[0] != 0xff) && (0x01 & addr[0]));
0579 }
0580 
0581 static inline int is_broadcast_mac_addr(const u8 *addr)
0582 {
0583     return (addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
0584            (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff);
0585 }
0586 
0587 #define CFG_IEEE80211_RESERVE_FCS (1<<0)
0588 #define CFG_IEEE80211_COMPUTE_FCS (1<<1)
0589 
0590 #define MAXTID  16
0591 
0592 /* Action category code */
0593 enum rtw_ieee80211_category {
0594     RTW_WLAN_CATEGORY_P2P = 0x7f,/* P2P action frames */
0595 };
0596 
0597 /* SPECTRUM_MGMT action code */
0598 enum rtw_ieee80211_spectrum_mgmt_actioncode {
0599     RTW_WLAN_ACTION_SPCT_MSR_REQ = 0,
0600     RTW_WLAN_ACTION_SPCT_MSR_RPRT = 1,
0601     RTW_WLAN_ACTION_SPCT_TPC_REQ = 2,
0602     RTW_WLAN_ACTION_SPCT_TPC_RPRT = 3,
0603     RTW_WLAN_ACTION_SPCT_CHL_SWITCH = 4,
0604     RTW_WLAN_ACTION_SPCT_EXT_CHL_SWITCH = 5,
0605 };
0606 
0607 enum _PUBLIC_ACTION {
0608     ACT_PUBLIC_BSSCOEXIST = 0, /*  20/40 BSS Coexistence */
0609     ACT_PUBLIC_DSE_ENABLE = 1,
0610     ACT_PUBLIC_DSE_DEENABLE = 2,
0611     ACT_PUBLIC_DSE_REG_LOCATION = 3,
0612     ACT_PUBLIC_EXT_CHL_SWITCH = 4,
0613     ACT_PUBLIC_DSE_MSR_REQ = 5,
0614     ACT_PUBLIC_DSE_MSR_RPRT = 6,
0615     ACT_PUBLIC_MP = 7, /*  Measurement Pilot */
0616     ACT_PUBLIC_DSE_PWR_CONSTRAINT = 8,
0617     ACT_PUBLIC_VENDOR = 9, /*  for WIFI_DIRECT */
0618     ACT_PUBLIC_GAS_INITIAL_REQ = 10,
0619     ACT_PUBLIC_GAS_INITIAL_RSP = 11,
0620     ACT_PUBLIC_GAS_COMEBACK_REQ = 12,
0621     ACT_PUBLIC_GAS_COMEBACK_RSP = 13,
0622     ACT_PUBLIC_TDLS_DISCOVERY_RSP = 14,
0623     ACT_PUBLIC_LOCATION_TRACK = 15,
0624     ACT_PUBLIC_MAX
0625 };
0626 
0627 #define OUI_MICROSOFT 0x0050f2 /* Microsoft (also used in Wi-Fi specs)
0628                 * 00:50:F2 */
0629 #define WME_OUI_TYPE 2
0630 #define WME_OUI_SUBTYPE_INFORMATION_ELEMENT 0
0631 #define WME_OUI_SUBTYPE_PARAMETER_ELEMENT 1
0632 #define WME_OUI_SUBTYPE_TSPEC_ELEMENT 2
0633 #define WME_VERSION 1
0634 
0635 #define WME_ACTION_CODE_SETUP_REQUEST 0
0636 #define WME_ACTION_CODE_SETUP_RESPONSE 1
0637 #define WME_ACTION_CODE_TEARDOWN 2
0638 
0639 #define WME_SETUP_RESPONSE_STATUS_ADMISSION_ACCEPTED 0
0640 #define WME_SETUP_RESPONSE_STATUS_INVALID_PARAMETERS 1
0641 #define WME_SETUP_RESPONSE_STATUS_REFUSED 3
0642 
0643 #define WME_TSPEC_DIRECTION_UPLINK 0
0644 #define WME_TSPEC_DIRECTION_DOWNLINK 1
0645 #define WME_TSPEC_DIRECTION_BI_DIRECTIONAL 3
0646 
0647 #define OUI_BROADCOM 0x00904c /* Broadcom (Epigram) */
0648 
0649 #define VENDOR_HT_CAPAB_OUI_TYPE 0x33 /* 00-90-4c:0x33 */
0650 
0651 /**
0652  * enum rtw_ieee80211_channel_flags - channel flags
0653  *
0654  * Channel flags set by the regulatory control code.
0655  *
0656  * @RTW_IEEE80211_CHAN_DISABLED: This channel is disabled.
0657  * @RTW_IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
0658  *      on this channel.
0659  * @RTW_IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
0660  * @RTW_IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
0661  * @RTW_IEEE80211_CHAN_NO_HT40PLUS: extension channel above this channel
0662  *      is not permitted.
0663  * @RTW_IEEE80211_CHAN_NO_HT40MINUS: extension channel below this channel
0664  *      is not permitted.
0665  */
0666 enum rtw_ieee80211_channel_flags {
0667     RTW_IEEE80211_CHAN_DISABLED  = 1<<0,
0668     RTW_IEEE80211_CHAN_PASSIVE_SCAN     = 1<<1,
0669     RTW_IEEE80211_CHAN_NO_IBSS    = 1<<2,
0670     RTW_IEEE80211_CHAN_RADAR        = 1<<3,
0671     RTW_IEEE80211_CHAN_NO_HT40PLUS      = 1<<4,
0672     RTW_IEEE80211_CHAN_NO_HT40MINUS     = 1<<5,
0673 };
0674 
0675 #define RTW_IEEE80211_CHAN_NO_HT40 \
0676       (RTW_IEEE80211_CHAN_NO_HT40PLUS | RTW_IEEE80211_CHAN_NO_HT40MINUS)
0677 
0678 /* Represent channel details, subset of ieee80211_channel */
0679 struct rtw_ieee80211_channel {
0680     u16 hw_value;
0681     u32 flags;
0682 };
0683 
0684 #define CHAN_FMT \
0685     "hw_value:%u, " \
0686     "flags:0x%08x" \
0687 
0688 #define CHAN_ARG(channel) \
0689     (channel)->hw_value \
0690     , (channel)->flags \
0691 
0692 /* Parsed Information Elements */
0693 struct rtw_ieee802_11_elems {
0694     u8 *ssid;
0695     u8 ssid_len;
0696     u8 *supp_rates;
0697     u8 supp_rates_len;
0698     u8 *fh_params;
0699     u8 fh_params_len;
0700     u8 *ds_params;
0701     u8 ds_params_len;
0702     u8 *cf_params;
0703     u8 cf_params_len;
0704     u8 *tim;
0705     u8 tim_len;
0706     u8 *ibss_params;
0707     u8 ibss_params_len;
0708     u8 *challenge;
0709     u8 challenge_len;
0710     u8 *erp_info;
0711     u8 erp_info_len;
0712     u8 *ext_supp_rates;
0713     u8 ext_supp_rates_len;
0714     u8 *wpa_ie;
0715     u8 wpa_ie_len;
0716     u8 *rsn_ie;
0717     u8 rsn_ie_len;
0718     u8 *wme;
0719     u8 wme_len;
0720     u8 *wme_tspec;
0721     u8 wme_tspec_len;
0722     u8 *wps_ie;
0723     u8 wps_ie_len;
0724     u8 *power_cap;
0725     u8 power_cap_len;
0726     u8 *supp_channels;
0727     u8 supp_channels_len;
0728     u8 *mdie;
0729     u8 mdie_len;
0730     u8 *ftie;
0731     u8 ftie_len;
0732     u8 *timeout_int;
0733     u8 timeout_int_len;
0734     u8 *ht_capabilities;
0735     u8 ht_capabilities_len;
0736     u8 *ht_operation;
0737     u8 ht_operation_len;
0738     u8 *vendor_ht_cap;
0739     u8 vendor_ht_cap_len;
0740 };
0741 
0742 enum parse_res {
0743     ParseOK = 0,
0744     ParseUnknown = 1,
0745     ParseFailed = -1
0746 };
0747 
0748 enum parse_res rtw_ieee802_11_parse_elems(u8 *start, uint len,
0749                       struct rtw_ieee802_11_elems *elems,
0750                       int show_errors);
0751 
0752 u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len,
0753              unsigned char *source, unsigned int *frlen);
0754 u8 *rtw_set_ie(u8 *pbuf, int index, uint len, u8 *source, uint *frlen);
0755 u8 *rtw_get_ie(u8 *pbuf, int index, int *len, int limit);
0756 
0757 void rtw_set_supported_rate(u8 *SupportedRates, uint mode);
0758 
0759 unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit);
0760 unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit);
0761 int rtw_get_wpa_cipher_suite(u8 *s);
0762 int rtw_get_wpa2_cipher_suite(u8 *s);
0763 int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len);
0764 int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
0765              int *pairwise_cipher, int *is_8021x);
0766 int rtw_parse_wpa2_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
0767               int *pairwise_cipher, int *is_8021x);
0768 
0769 int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len,
0770            u8 *wpa_ie, u16 *wpa_len);
0771 
0772 u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen);
0773 u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen);
0774 u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id,
0775              u8 *buf_attr, u32 *len_attr);
0776 u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id,
0777                  u8 *buf_content, uint *len_content);
0778 
0779 /**
0780  * for_each_ie - iterate over continuous IEs
0781  * @ie:
0782  * @buf:
0783  * @buf_len:
0784  */
0785 #define for_each_ie(ie, buf, buf_len) \
0786     for (ie = (void *)buf; (((u8 *)ie) - ((u8 *)buf) + 1) < buf_len;    \
0787         ie = (void *)(((u8 *)ie) + *(((u8 *)ie)+1) + 2))
0788 
0789 u8 *rtw_get_p2p_ie(u8 *in_ie, int in_len, u8 *p2p_ie, uint *p2p_ielen);
0790 u8 *rtw_get_p2p_attr(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id,
0791              u8 *buf_attr, u32 *len_attr);
0792 u8 *rtw_get_p2p_attr_content(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id,
0793                  u8 *buf_content, uint *len_content);
0794 u32 rtw_set_p2p_attr_content(u8 *pbuf, u8 attr_id, u16 attr_len,
0795                  u8 *pdata_attr);
0796 void rtw_wlan_bssid_ex_remove_p2p_attr(struct wlan_bssid_ex *bss_ex,
0797                        u8 attr_id);
0798 uint    rtw_get_rateset_len(u8  *rateset);
0799 
0800 struct registry_priv;
0801 int rtw_generate_ie(struct registry_priv *pregistrypriv);
0802 
0803 int rtw_get_bit_value_from_ieee_value(u8 val);
0804 
0805 bool    rtw_is_cckrates_included(u8 *rate);
0806 
0807 bool    rtw_is_cckratesonly_included(u8 *rate);
0808 
0809 int rtw_check_network_type(unsigned char *rate, int ratelen, int channel);
0810 
0811 void rtw_get_bcn_info(struct wlan_network *pnetwork);
0812 
0813 void rtw_macaddr_cfg(u8 *mac_addr);
0814 
0815 u16 rtw_mcs_rate(u8 bw_40MHz, u8 short_GI_20, u8 short_GI_40, unsigned char *MCS_rate);
0816 
0817 #endif /* IEEE80211_H */