cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

ieee80211.h (24986B)


      1/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
      2/* Copyright(c) 2007 - 2011 Realtek Corporation. */
      3
      4#ifndef __IEEE80211_H
      5#define __IEEE80211_H
      6
      7#include "osdep_service.h"
      8#include "drv_types.h"
      9#include "wifi.h"
     10#include <linux/wireless.h>
     11
     12#define MGMT_QUEUE_NUM 5
     13
     14#define ETH_TYPE_LEN		2
     15#define PAYLOAD_TYPE_LEN	1
     16
     17#define RTL_IOCTL_HOSTAPD (SIOCIWFIRSTPRIV + 28)
     18
     19/* STA flags */
     20#define WLAN_STA_AUTH BIT(0)
     21#define WLAN_STA_ASSOC BIT(1)
     22#define WLAN_STA_PS BIT(2)
     23#define WLAN_STA_TIM BIT(3)
     24#define WLAN_STA_PERM BIT(4)
     25#define WLAN_STA_AUTHORIZED BIT(5)
     26#define WLAN_STA_PENDING_POLL BIT(6) /* pending activity poll not ACKed */
     27#define WLAN_STA_SHORT_PREAMBLE BIT(7)
     28#define WLAN_STA_PREAUTH BIT(8)
     29#define WLAN_STA_WME BIT(9)
     30#define WLAN_STA_MFP BIT(10)
     31#define WLAN_STA_HT BIT(11)
     32#define WLAN_STA_WPS BIT(12)
     33#define WLAN_STA_MAYBE_WPS BIT(13)
     34#define WLAN_STA_NONERP BIT(31)
     35
     36#define IEEE_CMD_SET_WPA_PARAM			1
     37#define IEEE_CMD_SET_WPA_IE				2
     38#define IEEE_CMD_SET_ENCRYPTION			3
     39#define IEEE_CMD_MLME						4
     40
     41#define IEEE_PARAM_WPA_ENABLED				1
     42#define IEEE_PARAM_TKIP_COUNTERMEASURES		2
     43#define IEEE_PARAM_DROP_UNENCRYPTED			3
     44#define IEEE_PARAM_PRIVACY_INVOKED			4
     45#define IEEE_PARAM_AUTH_ALGS					5
     46#define IEEE_PARAM_IEEE_802_1X				6
     47#define IEEE_PARAM_WPAX_SELECT				7
     48
     49#define AUTH_ALG_OPEN_SYSTEM			0x1
     50#define AUTH_ALG_SHARED_KEY			0x2
     51#define AUTH_ALG_LEAP				0x00000004
     52
     53#define IEEE_MLME_STA_DEAUTH				1
     54#define IEEE_MLME_STA_DISASSOC			2
     55
     56#define IEEE_CRYPT_ERR_UNKNOWN_ALG			2
     57#define IEEE_CRYPT_ERR_UNKNOWN_ADDR			3
     58#define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED		4
     59#define IEEE_CRYPT_ERR_KEY_SET_FAILED			5
     60#define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED		6
     61#define IEEE_CRYPT_ERR_CARD_CONF_FAILED		7
     62
     63#define	IEEE_CRYPT_ALG_NAME_LEN			16
     64
     65#define WPA_CIPHER_NONE		BIT(0)
     66#define WPA_CIPHER_WEP40	BIT(1)
     67#define WPA_CIPHER_WEP104 BIT(2)
     68#define WPA_CIPHER_TKIP		BIT(3)
     69#define WPA_CIPHER_CCMP		BIT(4)
     70
     71
     72#define WPA_SELECTOR_LEN 4
     73extern u8 RTW_WPA_OUI_TYPE[];
     74extern u16 RTW_WPA_VERSION;
     75extern u8 WPA_AUTH_KEY_MGMT_NONE[];
     76extern u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[];
     77extern u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[];
     78extern u8 WPA_CIPHER_SUITE_NONE[];
     79extern u8 WPA_CIPHER_SUITE_WEP40[];
     80extern u8 WPA_CIPHER_SUITE_TKIP[];
     81extern u8 WPA_CIPHER_SUITE_WRAP[];
     82extern u8 WPA_CIPHER_SUITE_CCMP[];
     83extern u8 WPA_CIPHER_SUITE_WEP104[];
     84
     85#define RSN_HEADER_LEN 4
     86#define RSN_SELECTOR_LEN 4
     87
     88extern u16 RSN_VERSION_BSD;
     89extern u8 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X[];
     90extern u8 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X[];
     91extern u8 RSN_CIPHER_SUITE_NONE[];
     92extern u8 RSN_CIPHER_SUITE_WEP40[];
     93extern u8 RSN_CIPHER_SUITE_TKIP[];
     94extern u8 RSN_CIPHER_SUITE_WRAP[];
     95extern u8 RSN_CIPHER_SUITE_CCMP[];
     96extern u8 RSN_CIPHER_SUITE_WEP104[];
     97
     98enum ratr_table_mode {
     99	RATR_INX_WIRELESS_NGB = 0,	/*  BGN 40 Mhz 2SS 1SS */
    100	RATR_INX_WIRELESS_NG = 1,	/*  GN or N */
    101	RATR_INX_WIRELESS_NB = 2,	/*  BGN 20 Mhz 2SS 1SS  or BN */
    102	RATR_INX_WIRELESS_N = 3,
    103	RATR_INX_WIRELESS_GB = 4,
    104	RATR_INX_WIRELESS_G = 5,
    105	RATR_INX_WIRELESS_B = 6,
    106	RATR_INX_WIRELESS_MC = 7,
    107	RATR_INX_WIRELESS_AC_N = 8,
    108};
    109
    110enum NETWORK_TYPE {
    111	WIRELESS_INVALID = 0,
    112	/* Sub-Element */
    113	WIRELESS_11B = BIT(0), /* tx:cck only, rx:cck only, hw: cck */
    114	WIRELESS_11G = BIT(1), /* tx:ofdm only, rx:ofdm & cck, hw:cck & ofdm*/
    115	WIRELESS_11_24N = BIT(3), /* tx:MCS only, rx:MCS & cck, hw:MCS & cck */
    116
    117	/* Combination */
    118	/*  tx: cck & ofdm, rx: cck & ofdm & MCS, hw: cck & ofdm */
    119	WIRELESS_11BG = (WIRELESS_11B | WIRELESS_11G),
    120	/*  tx: ofdm & MCS, rx: ofdm & cck & MCS, hw: cck & ofdm */
    121	WIRELESS_11G_24N = (WIRELESS_11G | WIRELESS_11_24N),
    122	/*  tx: ofdm & cck & MCS, rx: ofdm & cck & MCS, hw: ofdm & cck */
    123	WIRELESS_11BG_24N = (WIRELESS_11B | WIRELESS_11G | WIRELESS_11_24N),
    124};
    125
    126struct ieee_param {
    127	u32 cmd;
    128	u8 sta_addr[ETH_ALEN];
    129	union {
    130		struct {
    131			u8 name;
    132			u32 value;
    133		} wpa_param;
    134		struct {
    135			u32 len;
    136			u8 reserved[32];
    137			u8 data[];
    138		} wpa_ie;
    139		struct {
    140			int command;
    141			int reason_code;
    142		} mlme;
    143		struct {
    144			u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
    145			u8 set_tx;
    146			u32 err;
    147			u8 idx;
    148			u8 seq[8]; /* sequence counter (set: RX, get: TX) */
    149			u16 key_len;
    150			u8 key[];
    151		} crypt;
    152		struct {
    153			u16 aid;
    154			u16 capability;
    155			int flags;
    156			u8 tx_supp_rates[16];
    157			struct ieee80211_ht_cap ht_cap;
    158		} add_sta;
    159		struct {
    160			u8	reserved[2];/* for set max_num_sta */
    161			u8	buf[];
    162		} bcn_ie;
    163	} u;
    164};
    165
    166#define IEEE80211_DATA_LEN		2304
    167/* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
    168   6.2.1.1.2.
    169
    170   The figure in section 7.1.2 suggests a body size of up to 2312
    171   bytes is allowed, which is a bit confusing, I suspect this
    172   represents the 2304 bytes of real data, plus a possible 8 bytes of
    173   WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
    174
    175#define IEEE80211_HLEN			30
    176#define IEEE80211_FRAME_LEN		(IEEE80211_DATA_LEN + IEEE80211_HLEN)
    177
    178/* this is stolen from ipw2200 driver */
    179#define IEEE_IBSS_MAC_HASH_SIZE 31
    180
    181#define IEEE80211_3ADDR_LEN 24
    182#define IEEE80211_4ADDR_LEN 30
    183#define IEEE80211_FCS_LEN    4
    184
    185#define MIN_FRAG_THRESHOLD     256U
    186#define	MAX_FRAG_THRESHOLD     2346U
    187
    188/* Frame control field constants */
    189#define RTW_IEEE80211_FCTL_VERS		0x0003
    190#define RTW_IEEE80211_FCTL_FTYPE	0x000c
    191#define RTW_IEEE80211_FCTL_STYPE	0x00f0
    192#define RTW_IEEE80211_FCTL_TODS		0x0100
    193#define RTW_IEEE80211_FCTL_FROMDS	0x0200
    194#define RTW_IEEE80211_FCTL_MOREFRAGS	0x0400
    195#define RTW_IEEE80211_FCTL_RETRY	0x0800
    196#define RTW_IEEE80211_FCTL_PM		0x1000
    197#define RTW_IEEE80211_FCTL_MOREDATA	0x2000
    198#define RTW_IEEE80211_FCTL_PROTECTED	0x4000
    199#define RTW_IEEE80211_FCTL_ORDER	0x8000
    200#define RTW_IEEE80211_FCTL_CTL_EXT	0x0f00
    201
    202#define RTW_IEEE80211_FTYPE_MGMT	0x0000
    203#define RTW_IEEE80211_FTYPE_CTL		0x0004
    204#define RTW_IEEE80211_FTYPE_DATA	0x0008
    205#define RTW_IEEE80211_FTYPE_EXT		0x000c
    206
    207/* management */
    208#define RTW_IEEE80211_STYPE_ASSOC_REQ	0x0000
    209#define RTW_IEEE80211_STYPE_ASSOC_RESP	0x0010
    210#define RTW_IEEE80211_STYPE_REASSOC_REQ	0x0020
    211#define RTW_IEEE80211_STYPE_REASSOC_RESP	0x0030
    212#define RTW_IEEE80211_STYPE_PROBE_REQ	0x0040
    213#define RTW_IEEE80211_STYPE_PROBE_RESP	0x0050
    214#define RTW_IEEE80211_STYPE_BEACON	0x0080
    215#define RTW_IEEE80211_STYPE_ATIM	0x0090
    216#define RTW_IEEE80211_STYPE_DISASSOC	0x00A0
    217#define RTW_IEEE80211_STYPE_AUTH	0x00B0
    218#define RTW_IEEE80211_STYPE_DEAUTH	0x00C0
    219#define RTW_IEEE80211_STYPE_ACTION	0x00D0
    220
    221/* control */
    222#define RTW_IEEE80211_STYPE_CTL_EXT	0x0060
    223#define RTW_IEEE80211_STYPE_BACK_REQ	0x0080
    224#define RTW_IEEE80211_STYPE_BACK	0x0090
    225#define RTW_IEEE80211_STYPE_PSPOLL	0x00A0
    226#define RTW_IEEE80211_STYPE_RTS		0x00B0
    227#define RTW_IEEE80211_STYPE_CTS		0x00C0
    228#define RTW_IEEE80211_STYPE_ACK		0x00D0
    229#define RTW_IEEE80211_STYPE_CFEND	0x00E0
    230#define RTW_IEEE80211_STYPE_CFENDACK	0x00F0
    231
    232/* data */
    233#define RTW_IEEE80211_STYPE_DATA	0x0000
    234#define RTW_IEEE80211_STYPE_DATA_CFACK	0x0010
    235#define RTW_IEEE80211_STYPE_DATA_CFPOLL	0x0020
    236#define RTW_IEEE80211_STYPE_DATA_CFACKPOLL	0x0030
    237#define RTW_IEEE80211_STYPE_NULLFUNC	0x0040
    238#define RTW_IEEE80211_STYPE_CFACK	0x0050
    239#define RTW_IEEE80211_STYPE_CFPOLL	0x0060
    240#define RTW_IEEE80211_STYPE_CFACKPOLL	0x0070
    241#define RTW_IEEE80211_STYPE_QOS_DATA	0x0080
    242#define RTW_IEEE80211_STYPE_QOS_DATA_CFACK	0x0090
    243#define RTW_IEEE80211_STYPE_QOS_DATA_CFPOLL	0x00A0
    244#define RTW_IEEE80211_STYPE_QOS_DATA_CFACKPOLL	0x00B0
    245#define RTW_IEEE80211_STYPE_QOS_NULLFUNC	0x00C0
    246#define RTW_IEEE80211_STYPE_QOS_CFACK		0x00D0
    247#define RTW_IEEE80211_STYPE_QOS_CFPOLL		0x00E0
    248#define RTW_IEEE80211_STYPE_QOS_CFACKPOLL	0x00F0
    249
    250/* sequence control field */
    251#define RTW_IEEE80211_SCTL_FRAG	0x000F
    252#define RTW_IEEE80211_SCTL_SEQ	0xFFF0
    253
    254#define RTW_ERP_INFO_NON_ERP_PRESENT BIT(0)
    255#define RTW_ERP_INFO_USE_PROTECTION BIT(1)
    256#define RTW_ERP_INFO_BARKER_PREAMBLE_MODE BIT(2)
    257
    258/* QoS, QOS */
    259#define NORMAL_ACK			0
    260#define NO_ACK				1
    261#define NON_EXPLICIT_ACK		2
    262#define BLOCK_ACK			3
    263
    264#ifndef ETH_P_PAE
    265#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
    266#endif /* ETH_P_PAE */
    267
    268#define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
    269
    270#define ETH_P_ECONET	0x0018
    271
    272#ifndef ETH_P_80211_RAW
    273#define ETH_P_80211_RAW (ETH_P_ECONET + 1)
    274#endif
    275
    276/* IEEE 802.11 defines */
    277
    278#define P80211_OUI_LEN 3
    279
    280struct ieee80211_snap_hdr {
    281	u8    dsap;   /* always 0xAA */
    282	u8    ssap;   /* always 0xAA */
    283	u8    ctrl;   /* always 0x03 */
    284	u8    oui[P80211_OUI_LEN];    /* organizational universal id */
    285} __packed;
    286
    287#define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
    288
    289#define WLAN_FC_GET_TYPE(fc) ((fc) & RTW_IEEE80211_FCTL_FTYPE)
    290#define WLAN_FC_GET_STYPE(fc) ((fc) & RTW_IEEE80211_FCTL_STYPE)
    291
    292#define WLAN_QC_GET_TID(qc) ((qc) & 0x0f)
    293
    294#define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTW_IEEE80211_SCTL_FRAG)
    295#define WLAN_GET_SEQ_SEQ(seq)  ((seq) & RTW_IEEE80211_SCTL_SEQ)
    296
    297/* Authentication algorithms */
    298#define WLAN_AUTH_OPEN 0
    299#define WLAN_AUTH_SHARED_KEY 1
    300
    301#define WLAN_AUTH_CHALLENGE_LEN 128
    302
    303#define WLAN_CAPABILITY_BSS (1<<0)
    304#define WLAN_CAPABILITY_IBSS (1<<1)
    305#define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
    306#define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
    307#define WLAN_CAPABILITY_PRIVACY (1<<4)
    308#define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
    309#define WLAN_CAPABILITY_PBCC (1<<6)
    310#define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
    311#define WLAN_CAPABILITY_SHORT_SLOT (1<<10)
    312
    313/* Status codes */
    314#define WLAN_STATUS_SUCCESS 0
    315#define WLAN_STATUS_UNSPECIFIED_FAILURE 1
    316#define WLAN_STATUS_CAPS_UNSUPPORTED 10
    317#define WLAN_STATUS_REASSOC_NO_ASSOC 11
    318#define WLAN_STATUS_ASSOC_DENIED_UNSPEC 12
    319#define WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG 13
    320#define WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION 14
    321#define WLAN_STATUS_CHALLENGE_FAIL 15
    322#define WLAN_STATUS_AUTH_TIMEOUT 16
    323#define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
    324#define WLAN_STATUS_ASSOC_DENIED_RATES 18
    325/* 802.11b */
    326#define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
    327#define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
    328#define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
    329
    330/* Reason codes */
    331#define WLAN_REASON_UNSPECIFIED 1
    332#define WLAN_REASON_PREV_AUTH_NOT_VALID 2
    333#define WLAN_REASON_DEAUTH_LEAVING 3
    334#define WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY 4
    335#define WLAN_REASON_DISASSOC_AP_BUSY 5
    336#define WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
    337#define WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7
    338#define WLAN_REASON_DISASSOC_STA_HAS_LEFT 8
    339#define WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
    340#define WLAN_REASON_JOIN_WRONG_CHANNEL       65534
    341#define WLAN_REASON_EXPIRATION_CHK 65535
    342
    343/* Information Element IDs */
    344#define WLAN_EID_SSID 0
    345#define WLAN_EID_SUPP_RATES 1
    346#define WLAN_EID_FH_PARAMS 2
    347#define WLAN_EID_DS_PARAMS 3
    348#define WLAN_EID_CF_PARAMS 4
    349#define WLAN_EID_TIM 5
    350#define WLAN_EID_IBSS_PARAMS 6
    351#define WLAN_EID_CHALLENGE 16
    352/* EIDs defined by IEEE 802.11h - START */
    353#define WLAN_EID_PWR_CONSTRAINT 32
    354#define WLAN_EID_PWR_CAPABILITY 33
    355#define WLAN_EID_TPC_REQUEST 34
    356#define WLAN_EID_TPC_REPORT 35
    357#define WLAN_EID_SUPPORTED_CHANNELS 36
    358#define WLAN_EID_CHANNEL_SWITCH 37
    359#define WLAN_EID_MEASURE_REQUEST 38
    360#define WLAN_EID_MEASURE_REPORT 39
    361#define WLAN_EID_QUITE 40
    362#define WLAN_EID_IBSS_DFS 41
    363/* EIDs defined by IEEE 802.11h - END */
    364#define WLAN_EID_ERP_INFO 42
    365#define WLAN_EID_HT_CAP 45
    366#define WLAN_EID_RSN 48
    367#define WLAN_EID_EXT_SUPP_RATES 50
    368#define WLAN_EID_MOBILITY_DOMAIN 54
    369#define WLAN_EID_FAST_BSS_TRANSITION 55
    370#define WLAN_EID_TIMEOUT_INTERVAL 56
    371#define WLAN_EID_RIC_DATA 57
    372#define WLAN_EID_HT_OPERATION 61
    373#define WLAN_EID_SECONDARY_CHANNEL_OFFSET 62
    374#define WLAN_EID_20_40_BSS_COEXISTENCE 72
    375#define WLAN_EID_20_40_BSS_INTOLERANT 73
    376#define WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS 74
    377#define WLAN_EID_MMIE 76
    378#define WLAN_EID_VENDOR_SPECIFIC 221
    379#define WLAN_EID_GENERIC (WLAN_EID_VENDOR_SPECIFIC)
    380
    381#define IEEE80211_MGMT_HDR_LEN 24
    382#define IEEE80211_DATA_HDR3_LEN 24
    383#define IEEE80211_DATA_HDR4_LEN 30
    384
    385#define IEEE80211_STATMASK_SIGNAL (1<<0)
    386#define IEEE80211_STATMASK_RSSI (1<<1)
    387#define IEEE80211_STATMASK_NOISE (1<<2)
    388#define IEEE80211_STATMASK_RATE (1<<3)
    389#define IEEE80211_STATMASK_WEMASK 0x7
    390
    391#define IEEE80211_CCK_MODULATION    (1<<0)
    392#define IEEE80211_OFDM_MODULATION   (1<<1)
    393
    394#define IEEE80211_24GHZ_BAND     (1<<0)
    395#define IEEE80211_52GHZ_BAND     (1<<1)
    396
    397#define IEEE80211_CCK_RATE_LEN			4
    398#define IEEE80211_NUM_OFDM_RATESLEN	8
    399
    400#define IEEE80211_CCK_RATE_1MB			0x02
    401#define IEEE80211_CCK_RATE_2MB			0x04
    402#define IEEE80211_CCK_RATE_5MB			0x0B
    403#define IEEE80211_CCK_RATE_11MB			0x16
    404#define IEEE80211_OFDM_RATE_LEN			8
    405#define IEEE80211_OFDM_RATE_6MB			0x0C
    406#define IEEE80211_OFDM_RATE_9MB			0x12
    407#define IEEE80211_OFDM_RATE_12MB		0x18
    408#define IEEE80211_OFDM_RATE_18MB		0x24
    409#define IEEE80211_OFDM_RATE_24MB		0x30
    410#define IEEE80211_OFDM_RATE_36MB		0x48
    411#define IEEE80211_OFDM_RATE_48MB		0x60
    412#define IEEE80211_OFDM_RATE_54MB		0x6C
    413#define IEEE80211_BASIC_RATE_MASK		0x80
    414
    415#define IEEE80211_CCK_RATE_1MB_MASK		(1<<0)
    416#define IEEE80211_CCK_RATE_2MB_MASK		(1<<1)
    417#define IEEE80211_CCK_RATE_5MB_MASK		(1<<2)
    418#define IEEE80211_CCK_RATE_11MB_MASK		(1<<3)
    419#define IEEE80211_OFDM_RATE_6MB_MASK		(1<<4)
    420#define IEEE80211_OFDM_RATE_9MB_MASK		(1<<5)
    421#define IEEE80211_OFDM_RATE_12MB_MASK		(1<<6)
    422#define IEEE80211_OFDM_RATE_18MB_MASK		(1<<7)
    423#define IEEE80211_OFDM_RATE_24MB_MASK		(1<<8)
    424#define IEEE80211_OFDM_RATE_36MB_MASK		(1<<9)
    425#define IEEE80211_OFDM_RATE_48MB_MASK		(1<<10)
    426#define IEEE80211_OFDM_RATE_54MB_MASK		(1<<11)
    427
    428#define IEEE80211_CCK_RATES_MASK		0x0000000F
    429#define IEEE80211_CCK_BASIC_RATES_MASK	(IEEE80211_CCK_RATE_1MB_MASK | \
    430	IEEE80211_CCK_RATE_2MB_MASK)
    431#define IEEE80211_CCK_DEFAULT_RATES_MASK				\
    432	(IEEE80211_CCK_BASIC_RATES_MASK |				\
    433	IEEE80211_CCK_RATE_5MB_MASK |					\
    434	IEEE80211_CCK_RATE_11MB_MASK)
    435
    436#define IEEE80211_OFDM_RATES_MASK		0x00000FF0
    437#define IEEE80211_OFDM_BASIC_RATES_MASK	(IEEE80211_OFDM_RATE_6MB_MASK | \
    438	IEEE80211_OFDM_RATE_12MB_MASK |					\
    439	IEEE80211_OFDM_RATE_24MB_MASK)
    440#define IEEE80211_OFDM_DEFAULT_RATES_MASK				\
    441	(IEEE80211_OFDM_BASIC_RATES_MASK |				\
    442	IEEE80211_OFDM_RATE_9MB_MASK  |					\
    443	IEEE80211_OFDM_RATE_18MB_MASK |					\
    444	IEEE80211_OFDM_RATE_36MB_MASK |					\
    445	IEEE80211_OFDM_RATE_48MB_MASK |					\
    446	IEEE80211_OFDM_RATE_54MB_MASK)
    447#define IEEE80211_DEFAULT_RATES_MASK					\
    448	(IEEE80211_OFDM_DEFAULT_RATES_MASK |				\
    449	 IEEE80211_CCK_DEFAULT_RATES_MASK)
    450
    451#define IEEE80211_NUM_OFDM_RATES	8
    452#define IEEE80211_NUM_CCK_RATES		4
    453#define IEEE80211_OFDM_SHIFT_MASK_A	4
    454
    455/* IEEE 802.11 requires that STA supports concurrent reception of at least
    456 * three fragmented frames. This define can be increased to support more
    457 * concurrent frames, but it should be noted that each entry can consume about
    458 * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
    459#define IEEE80211_FRAG_CACHE_LEN 4
    460
    461#define SEC_KEY_1	(1<<0)
    462#define SEC_KEY_2	(1<<1)
    463#define SEC_KEY_3	(1<<2)
    464#define SEC_KEY_4	(1<<3)
    465#define SEC_ACTIVE_KEY  (1<<4)
    466#define SEC_AUTH_MODE   (1<<5)
    467#define SEC_UNICAST_GROUP (1<<6)
    468#define SEC_LEVEL	(1<<7)
    469#define SEC_ENABLED     (1<<8)
    470
    471#define SEC_LEVEL_0      0 /* None */
    472#define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
    473#define SEC_LEVEL_2      2 /* Level 1 + TKIP */
    474#define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
    475#define SEC_LEVEL_3      4 /* Level 2 + CCMP */
    476
    477#define WEP_KEYS 4
    478#define WEP_KEY_LEN 13
    479
    480/*
    481
    482 802.11 data frame from AP
    483
    484      ,-------------------------------------------------------------------.
    485Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
    486      |------|------|---------|---------|---------|------|---------|------|
    487Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
    488      |      | tion | (BSSID) |	 |	 | ence |  data   |      |
    489      `-------------------------------------------------------------------'
    490
    491Total: 28-2340 bytes
    492
    493*/
    494
    495#define BEACON_PROBE_SSID_ID_POSITION 12
    496
    497/* Management Frame Information Element Types */
    498#define MFIE_TYPE_SSID		0
    499#define MFIE_TYPE_RATES		1
    500#define MFIE_TYPE_FH_SET	2
    501#define MFIE_TYPE_DS_SET	3
    502#define MFIE_TYPE_CF_SET	4
    503#define MFIE_TYPE_TIM		5
    504#define MFIE_TYPE_IBSS_SET	6
    505#define MFIE_TYPE_CHALLENGE	16
    506#define MFIE_TYPE_ERP		42
    507#define MFIE_TYPE_RSN		48
    508#define MFIE_TYPE_RATES_EX	50
    509#define MFIE_TYPE_GENERIC	221
    510
    511/*
    512 * These are the data types that can make up management packets
    513 *
    514	u16 auth_algorithm;
    515	u16 auth_sequence;
    516	u16 beacon_interval;
    517	u16 capability;
    518	u8 current_ap[ETH_ALEN];
    519	u16 listen_interval;
    520	struct {
    521		u16 association_id:14, reserved:2;
    522	} __packed;
    523	u32 time_stamp[2];
    524	u16 reason;
    525	u16 status;
    526*/
    527
    528#define IEEE80211_DEFAULT_TX_ESSID "Penguin"
    529#define IEEE80211_DEFAULT_BASIC_RATE 10
    530
    531/* SWEEP TABLE ENTRIES NUMBER*/
    532#define MAX_SWEEP_TAB_ENTRIES		  42
    533#define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
    534/* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
    535 * only use 8, and then use extended rates for the remaining supported
    536 * rates.  Other APs, however, stick all of their supported rates on the
    537 * main rates information element... */
    538#define MAX_RATES_LENGTH		((u8)12)
    539#define MAX_RATES_EX_LENGTH		((u8)16)
    540#define MAX_NETWORK_COUNT		128
    541#define MAX_CHANNEL_NUMBER		161
    542#define IEEE80211_SOFTMAC_SCAN_TIME	400
    543/* HZ / 2) */
    544#define IEEE80211_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
    545
    546#define CRC_LENGTH		 4U
    547
    548#define MAX_WPA_IE_LEN (256)
    549#define MAX_WPS_IE_LEN (512)
    550#define MAX_P2P_IE_LEN (256)
    551#define MAX_WFD_IE_LEN (128)
    552
    553#define NETWORK_EMPTY_ESSID (1<<0)
    554#define NETWORK_HAS_OFDM    (1<<1)
    555#define NETWORK_HAS_CCK     (1<<2)
    556
    557#define IEEE80211_DTIM_MBCAST 4
    558#define IEEE80211_DTIM_UCAST 2
    559#define IEEE80211_DTIM_VALID 1
    560#define IEEE80211_DTIM_INVALID 0
    561
    562#define IEEE80211_PS_DISABLED 0
    563#define IEEE80211_PS_UNICAST IEEE80211_DTIM_UCAST
    564#define IEEE80211_PS_MBCAST IEEE80211_DTIM_MBCAST
    565#define IW_ESSID_MAX_SIZE 32
    566/*
    567join_res:
    568-1: authentication fail
    569-2: association fail
    570> 0: TID
    571*/
    572
    573#define DEFAULT_MAX_SCAN_AGE (15 * HZ)
    574#define DEFAULT_FTS 2346
    575
    576static inline int is_multicast_mac_addr(const u8 *addr)
    577{
    578	return ((addr[0] != 0xff) && (0x01 & addr[0]));
    579}
    580
    581static inline int is_broadcast_mac_addr(const u8 *addr)
    582{
    583	return (addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
    584	       (addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff);
    585}
    586
    587#define CFG_IEEE80211_RESERVE_FCS (1<<0)
    588#define CFG_IEEE80211_COMPUTE_FCS (1<<1)
    589
    590#define MAXTID	16
    591
    592/* Action category code */
    593enum rtw_ieee80211_category {
    594	RTW_WLAN_CATEGORY_P2P = 0x7f,/* P2P action frames */
    595};
    596
    597/* SPECTRUM_MGMT action code */
    598enum rtw_ieee80211_spectrum_mgmt_actioncode {
    599	RTW_WLAN_ACTION_SPCT_MSR_REQ = 0,
    600	RTW_WLAN_ACTION_SPCT_MSR_RPRT = 1,
    601	RTW_WLAN_ACTION_SPCT_TPC_REQ = 2,
    602	RTW_WLAN_ACTION_SPCT_TPC_RPRT = 3,
    603	RTW_WLAN_ACTION_SPCT_CHL_SWITCH = 4,
    604	RTW_WLAN_ACTION_SPCT_EXT_CHL_SWITCH = 5,
    605};
    606
    607enum _PUBLIC_ACTION {
    608	ACT_PUBLIC_BSSCOEXIST = 0, /*  20/40 BSS Coexistence */
    609	ACT_PUBLIC_DSE_ENABLE = 1,
    610	ACT_PUBLIC_DSE_DEENABLE = 2,
    611	ACT_PUBLIC_DSE_REG_LOCATION = 3,
    612	ACT_PUBLIC_EXT_CHL_SWITCH = 4,
    613	ACT_PUBLIC_DSE_MSR_REQ = 5,
    614	ACT_PUBLIC_DSE_MSR_RPRT = 6,
    615	ACT_PUBLIC_MP = 7, /*  Measurement Pilot */
    616	ACT_PUBLIC_DSE_PWR_CONSTRAINT = 8,
    617	ACT_PUBLIC_VENDOR = 9, /*  for WIFI_DIRECT */
    618	ACT_PUBLIC_GAS_INITIAL_REQ = 10,
    619	ACT_PUBLIC_GAS_INITIAL_RSP = 11,
    620	ACT_PUBLIC_GAS_COMEBACK_REQ = 12,
    621	ACT_PUBLIC_GAS_COMEBACK_RSP = 13,
    622	ACT_PUBLIC_TDLS_DISCOVERY_RSP = 14,
    623	ACT_PUBLIC_LOCATION_TRACK = 15,
    624	ACT_PUBLIC_MAX
    625};
    626
    627/* BACK action code */
    628enum rtw_ieee80211_back_actioncode {
    629	RTW_WLAN_ACTION_ADDBA_REQ = 0,
    630	RTW_WLAN_ACTION_ADDBA_RESP = 1,
    631	RTW_WLAN_ACTION_DELBA = 2,
    632};
    633
    634#define OUI_MICROSOFT 0x0050f2 /* Microsoft (also used in Wi-Fi specs)
    635				* 00:50:F2 */
    636#define WME_OUI_TYPE 2
    637#define WME_OUI_SUBTYPE_INFORMATION_ELEMENT 0
    638#define WME_OUI_SUBTYPE_PARAMETER_ELEMENT 1
    639#define WME_OUI_SUBTYPE_TSPEC_ELEMENT 2
    640#define WME_VERSION 1
    641
    642#define WME_ACTION_CODE_SETUP_REQUEST 0
    643#define WME_ACTION_CODE_SETUP_RESPONSE 1
    644#define WME_ACTION_CODE_TEARDOWN 2
    645
    646#define WME_SETUP_RESPONSE_STATUS_ADMISSION_ACCEPTED 0
    647#define WME_SETUP_RESPONSE_STATUS_INVALID_PARAMETERS 1
    648#define WME_SETUP_RESPONSE_STATUS_REFUSED 3
    649
    650#define WME_TSPEC_DIRECTION_UPLINK 0
    651#define WME_TSPEC_DIRECTION_DOWNLINK 1
    652#define WME_TSPEC_DIRECTION_BI_DIRECTIONAL 3
    653
    654#define OUI_BROADCOM 0x00904c /* Broadcom (Epigram) */
    655
    656#define VENDOR_HT_CAPAB_OUI_TYPE 0x33 /* 00-90-4c:0x33 */
    657
    658/**
    659 * enum rtw_ieee80211_channel_flags - channel flags
    660 *
    661 * Channel flags set by the regulatory control code.
    662 *
    663 * @RTW_IEEE80211_CHAN_DISABLED: This channel is disabled.
    664 * @RTW_IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
    665 *      on this channel.
    666 * @RTW_IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
    667 * @RTW_IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
    668 * @RTW_IEEE80211_CHAN_NO_HT40PLUS: extension channel above this channel
    669 *      is not permitted.
    670 * @RTW_IEEE80211_CHAN_NO_HT40MINUS: extension channel below this channel
    671 *      is not permitted.
    672 */
    673enum rtw_ieee80211_channel_flags {
    674	RTW_IEEE80211_CHAN_DISABLED	 = 1<<0,
    675	RTW_IEEE80211_CHAN_PASSIVE_SCAN     = 1<<1,
    676	RTW_IEEE80211_CHAN_NO_IBSS	  = 1<<2,
    677	RTW_IEEE80211_CHAN_RADAR	    = 1<<3,
    678	RTW_IEEE80211_CHAN_NO_HT40PLUS      = 1<<4,
    679	RTW_IEEE80211_CHAN_NO_HT40MINUS     = 1<<5,
    680};
    681
    682#define RTW_IEEE80211_CHAN_NO_HT40 \
    683	  (RTW_IEEE80211_CHAN_NO_HT40PLUS | RTW_IEEE80211_CHAN_NO_HT40MINUS)
    684
    685/* Represent channel details, subset of ieee80211_channel */
    686struct rtw_ieee80211_channel {
    687	u16 hw_value;
    688	u32 flags;
    689};
    690
    691#define CHAN_FMT \
    692	"hw_value:%u, " \
    693	"flags:0x%08x" \
    694
    695#define CHAN_ARG(channel) \
    696	(channel)->hw_value \
    697	, (channel)->flags \
    698
    699/* Parsed Information Elements */
    700struct rtw_ieee802_11_elems {
    701	u8 *ssid;
    702	u8 ssid_len;
    703	u8 *supp_rates;
    704	u8 supp_rates_len;
    705	u8 *fh_params;
    706	u8 fh_params_len;
    707	u8 *ds_params;
    708	u8 ds_params_len;
    709	u8 *cf_params;
    710	u8 cf_params_len;
    711	u8 *tim;
    712	u8 tim_len;
    713	u8 *ibss_params;
    714	u8 ibss_params_len;
    715	u8 *challenge;
    716	u8 challenge_len;
    717	u8 *erp_info;
    718	u8 erp_info_len;
    719	u8 *ext_supp_rates;
    720	u8 ext_supp_rates_len;
    721	u8 *wpa_ie;
    722	u8 wpa_ie_len;
    723	u8 *rsn_ie;
    724	u8 rsn_ie_len;
    725	u8 *wme;
    726	u8 wme_len;
    727	u8 *wme_tspec;
    728	u8 wme_tspec_len;
    729	u8 *wps_ie;
    730	u8 wps_ie_len;
    731	u8 *power_cap;
    732	u8 power_cap_len;
    733	u8 *supp_channels;
    734	u8 supp_channels_len;
    735	u8 *mdie;
    736	u8 mdie_len;
    737	u8 *ftie;
    738	u8 ftie_len;
    739	u8 *timeout_int;
    740	u8 timeout_int_len;
    741	u8 *ht_capabilities;
    742	u8 ht_capabilities_len;
    743	u8 *ht_operation;
    744	u8 ht_operation_len;
    745	u8 *vendor_ht_cap;
    746	u8 vendor_ht_cap_len;
    747};
    748
    749enum parse_res {
    750	ParseOK = 0,
    751	ParseUnknown = 1,
    752	ParseFailed = -1
    753};
    754
    755enum parse_res rtw_ieee802_11_parse_elems(u8 *start, uint len,
    756					  struct rtw_ieee802_11_elems *elems,
    757					  int show_errors);
    758
    759u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len,
    760		     unsigned char *source, unsigned int *frlen);
    761u8 *rtw_set_ie(u8 *pbuf, int index, uint len, u8 *source, uint *frlen);
    762u8 *rtw_get_ie(u8 *pbuf, int index, int *len, int limit);
    763
    764void rtw_set_supported_rate(u8 *SupportedRates, uint mode);
    765
    766unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit);
    767unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit);
    768int rtw_get_wpa_cipher_suite(u8 *s);
    769int rtw_get_wpa2_cipher_suite(u8 *s);
    770int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len);
    771int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
    772		     int *pairwise_cipher, int *is_8021x);
    773int rtw_parse_wpa2_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
    774		      int *pairwise_cipher, int *is_8021x);
    775
    776int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len,
    777		   u8 *wpa_ie, u16 *wpa_len);
    778
    779u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen);
    780u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen);
    781u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id,
    782		     u8 *buf_attr, u32 *len_attr);
    783u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id,
    784			     u8 *buf_content, uint *len_content);
    785
    786/**
    787 * for_each_ie - iterate over continuous IEs
    788 * @ie:
    789 * @buf:
    790 * @buf_len:
    791 */
    792#define for_each_ie(ie, buf, buf_len) \
    793	for (ie = (void *)buf; (((u8 *)ie) - ((u8 *)buf) + 1) < buf_len;	\
    794		ie = (void *)(((u8 *)ie) + *(((u8 *)ie)+1) + 2))
    795
    796u8 *rtw_get_p2p_ie(u8 *in_ie, int in_len, u8 *p2p_ie, uint *p2p_ielen);
    797u8 *rtw_get_p2p_attr(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id,
    798		     u8 *buf_attr, u32 *len_attr);
    799u8 *rtw_get_p2p_attr_content(u8 *p2p_ie, uint p2p_ielen, u8 target_attr_id,
    800			     u8 *buf_content, uint *len_content);
    801u32 rtw_set_p2p_attr_content(u8 *pbuf, u8 attr_id, u16 attr_len,
    802			     u8 *pdata_attr);
    803void rtw_wlan_bssid_ex_remove_p2p_attr(struct wlan_bssid_ex *bss_ex,
    804				       u8 attr_id);
    805uint	rtw_get_rateset_len(u8	*rateset);
    806
    807struct registry_priv;
    808int rtw_generate_ie(struct registry_priv *pregistrypriv);
    809
    810int rtw_get_bit_value_from_ieee_value(u8 val);
    811
    812bool	rtw_is_cckrates_included(u8 *rate);
    813
    814bool	rtw_is_cckratesonly_included(u8 *rate);
    815
    816int rtw_check_network_type(unsigned char *rate, int ratelen, int channel);
    817
    818void rtw_get_bcn_info(struct wlan_network *pnetwork);
    819
    820void rtw_macaddr_cfg(u8 *mac_addr);
    821
    822u16 rtw_mcs_rate(u8 bw_40MHz, u8 short_GI_20, u8 short_GI_40, unsigned char *MCS_rate);
    823
    824#endif /* IEEE80211_H */