linux/drivers/staging/rtl8188eu/include/wifi.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2/******************************************************************************
   3 *
   4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
   5 *
   6 ******************************************************************************/
   7#ifndef _WIFI_H_
   8#define _WIFI_H_
   9
  10#define WLAN_HDR_A3_LEN         24
  11#define WLAN_HDR_A3_QOS_LEN     26
  12
  13#define P80211CAPTURE_VERSION   0x80211001
  14
  15/*  This value is tested by WiFi 11n Test Plan 5.2.3. */
  16/*  This test verifies the WLAN NIC can update the NAV through sending
  17 *  the CTS with large duration.
  18 */
  19#define WiFiNavUpperUs                          30000   /*  30 ms */
  20
  21enum WIFI_FRAME_TYPE {
  22        WIFI_MGT_TYPE  =        (0),
  23        WIFI_CTRL_TYPE =        (BIT(2)),
  24        WIFI_DATA_TYPE =        (BIT(3)),
  25        WIFI_QOS_DATA_TYPE      = (BIT(7) | BIT(3)),    /*  QoS Data */
  26};
  27
  28#define SetToDs(pbuf)   \
  29        *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_TODS)
  30
  31#define GetToDs(pbuf)   (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_TODS)) != 0)
  32
  33#define ClearToDs(pbuf) \
  34        *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_TODS))
  35
  36#define SetFrDs(pbuf)   \
  37        *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_FROMDS)
  38
  39#define GetFrDs(pbuf)   (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_FROMDS)) != 0)
  40
  41#define ClearFrDs(pbuf) \
  42        *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_FROMDS))
  43
  44#define get_tofr_ds(pframe)     ((GetToDs(pframe) << 1) | GetFrDs(pframe))
  45
  46#define SetMFrag(pbuf)  \
  47        *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)
  48
  49#define GetMFrag(pbuf)  (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) != 0)
  50
  51#define ClearMFrag(pbuf)        \
  52        *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREFRAGS))
  53
  54#define SetRetry(pbuf)  \
  55        *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_RETRY)
  56
  57#define GetRetry(pbuf)  (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_RETRY)) != 0)
  58
  59#define ClearRetry(pbuf)        \
  60        *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_RETRY))
  61
  62#define SetPwrMgt(pbuf) \
  63        *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PM)
  64
  65#define GetPwrMgt(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_PM)) != 0)
  66
  67#define ClearPwrMgt(pbuf)       \
  68        *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_PM))
  69
  70#define SetMData(pbuf)  \
  71        *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREDATA)
  72
  73#define GetMData(pbuf)  (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_MOREDATA)) != 0)
  74
  75#define ClearMData(pbuf)        \
  76        *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREDATA))
  77
  78#define SetPrivacy(pbuf)        \
  79        *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PROTECTED)
  80
  81#define GetPrivacy(pbuf)                                        \
  82        (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_PROTECTED)) != 0)
  83
  84#define GetOrder(pbuf)                                  \
  85        (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_ORDER)) != 0)
  86
  87#define GetFrameType(pbuf)                              \
  88        (le16_to_cpu(*(__le16 *)(pbuf)) & (BIT(3) | BIT(2)))
  89
  90#define GetFrameSubType(pbuf)   (le16_to_cpu(*(__le16 *)(pbuf)) & (BIT(7) |\
  91         BIT(6) | BIT(5) | BIT(4) | BIT(3) | BIT(2)))
  92
  93#define SetFrameSubType(pbuf, type) \
  94        do {    \
  95                *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) |    \
  96                 BIT(5) | BIT(4) | BIT(3) | BIT(2))); \
  97                *(__le16 *)(pbuf) |= cpu_to_le16(type); \
  98        } while (0)
  99
 100#define GetSequence(pbuf)                       \
 101        (le16_to_cpu(*(__le16 *)((size_t)(pbuf) + 22)) >> 4)
 102
 103#define GetFragNum(pbuf)                        \
 104        (le16_to_cpu(*(__le16 *)((size_t)(pbuf) + 22)) & 0x0f)
 105
 106#define SetSeqNum(pbuf, num) \
 107        do {    \
 108                *(__le16 *)((size_t)(pbuf) + 22) = \
 109                        ((*(__le16 *)((size_t)(pbuf) + 22)) & cpu_to_le16((unsigned short)0x000f)) | \
 110                        cpu_to_le16((unsigned short)(0xfff0 & (num << 4))); \
 111        } while (0)
 112
 113#define SetDuration(pbuf, dur) \
 114        *(__le16 *)((size_t)(pbuf) + 2) = cpu_to_le16(0xffff & (dur))
 115
 116#define SetPriority(pbuf, tid)  \
 117        *(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf)
 118
 119#define GetPriority(pbuf)       ((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf)
 120
 121#define SetEOSP(pbuf, eosp)     \
 122                *(__le16 *)(pbuf) |= cpu_to_le16((eosp & 1) << 4)
 123
 124#define SetAckpolicy(pbuf, ack) \
 125        *(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5)
 126
 127#define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
 128
 129#define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
 130
 131#define GetAid(pbuf)    (le16_to_cpu(*(__le16 *)((size_t)(pbuf) + 2)) & 0x3fff)
 132
 133#define GetAddr1Ptr(pbuf)       ((unsigned char *)((size_t)(pbuf) + 4))
 134
 135#define GetAddr2Ptr(pbuf)       ((unsigned char *)((size_t)(pbuf) + 10))
 136
 137#define GetAddr3Ptr(pbuf)       ((unsigned char *)((size_t)(pbuf) + 16))
 138
 139static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
 140{
 141        unsigned char   *sa;
 142        unsigned int    to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
 143
 144        switch (to_fr_ds) {
 145        case 0x00:      /*  ToDs=0, FromDs=0 */
 146                sa = GetAddr3Ptr(pframe);
 147                break;
 148        case 0x01:      /*  ToDs=0, FromDs=1 */
 149                sa = GetAddr2Ptr(pframe);
 150                break;
 151        case 0x02:      /*  ToDs=1, FromDs=0 */
 152                sa = GetAddr1Ptr(pframe);
 153                break;
 154        case 0x03:      /*  ToDs=1, FromDs=1 */
 155                sa = GetAddr1Ptr(pframe);
 156                break;
 157        default:
 158                sa = NULL; /*  */
 159                break;
 160        }
 161        return sa;
 162}
 163
 164/*-----------------------------------------------------------------------------
 165                        Below is for the security related definition
 166------------------------------------------------------------------------------*/
 167#define _ASOCREQ_IE_OFFSET_     4       /*  excluding wlan_hdr */
 168#define _ASOCRSP_IE_OFFSET_     6
 169#define _REASOCREQ_IE_OFFSET_   10
 170#define _REASOCRSP_IE_OFFSET_   6
 171#define _PROBEREQ_IE_OFFSET_    0
 172#define _PROBERSP_IE_OFFSET_    12
 173#define _AUTH_IE_OFFSET_        6
 174#define _DEAUTH_IE_OFFSET_      0
 175#define _BEACON_IE_OFFSET_      12
 176#define _PUBLIC_ACTION_IE_OFFSET_       8
 177
 178#define _FIXED_IE_LENGTH_       _BEACON_IE_OFFSET_
 179
 180/* ---------------------------------------------------------------------------
 181                                        Below is the fixed elements...
 182-----------------------------------------------------------------------------*/
 183#define _AUTH_ALGM_NUM_         2
 184#define _AUTH_SEQ_NUM_          2
 185#define _BEACON_ITERVAL_        2
 186#define _CAPABILITY_            2
 187#define _CURRENT_APADDR_        6
 188#define _LISTEN_INTERVAL_       2
 189#define _RSON_CODE_             2
 190#define _ASOC_ID_               2
 191#define _STATUS_CODE_           2
 192#define _TIMESTAMP_             8
 193
 194#define AUTH_ODD_TO             0
 195#define AUTH_EVEN_TO            1
 196
 197/*-----------------------------------------------------------------------------
 198                                Below is the definition for 802.11i / 802.1x
 199------------------------------------------------------------------------------*/
 200#define _IEEE8021X_MGT_                 1       /*  WPA */
 201#define _IEEE8021X_PSK_                 2       /*  WPA with pre-shared key */
 202
 203/*
 204 * #define _NO_PRIVACY_                 0
 205 * #define _WEP_40_PRIVACY_             1
 206 * #define _TKIP_PRIVACY_               2
 207 * #define _WRAP_PRIVACY_               3
 208 * #define _CCMP_PRIVACY_               4
 209 * #define _WEP_104_PRIVACY_            5
 210 * #define _WEP_WPA_MIXED_PRIVACY_ 6    WEP + WPA
 211 */
 212
 213/*-----------------------------------------------------------------------------
 214                                Below is the definition for WMM
 215------------------------------------------------------------------------------*/
 216#define _WMM_IE_Length_                         7  /*  for WMM STA */
 217
 218/*-----------------------------------------------------------------------------
 219                                Below is the definition for 802.11n
 220------------------------------------------------------------------------------*/
 221
 222/**
 223 * struct rtw_ieee80211_ht_cap - HT additional information
 224 *
 225 * This structure refers to "HT information element" as
 226 * described in 802.11n draft section 7.3.2.53
 227 */
 228struct ieee80211_ht_addt_info {
 229        unsigned char   control_chan;
 230        unsigned char   ht_param;
 231        unsigned short  operation_mode;
 232        unsigned short  stbc_param;
 233        unsigned char   basic_set[16];
 234} __packed;
 235
 236struct HT_info_element {
 237        unsigned char   primary_channel;
 238        unsigned char   infos[5];
 239        unsigned char   MCS_rate[16];
 240} __packed;
 241
 242struct AC_param {
 243        unsigned char           ACI_AIFSN;
 244        unsigned char           CW;
 245        __le16  TXOP_limit;
 246} __packed;
 247
 248struct WMM_para_element {
 249        unsigned char           QoS_info;
 250        unsigned char           reserved;
 251        struct AC_param ac_param[4];
 252} __packed;
 253
 254struct ADDBA_request {
 255        unsigned char   dialog_token;
 256        __le16          BA_para_set;
 257        unsigned short  BA_timeout_value;
 258        unsigned short  BA_starting_seqctrl;
 259} __packed;
 260
 261enum ht_cap_ampdu_factor {
 262        MAX_AMPDU_FACTOR_8K     = 0,
 263        MAX_AMPDU_FACTOR_16K    = 1,
 264        MAX_AMPDU_FACTOR_32K    = 2,
 265        MAX_AMPDU_FACTOR_64K    = 3,
 266};
 267
 268#define OP_MODE_PURE                    0
 269#define OP_MODE_MAY_BE_LEGACY_STAS      1
 270#define OP_MODE_20MHZ_HT_STA_ASSOCED    2
 271#define OP_MODE_MIXED                   3
 272
 273#define HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK        ((u8)BIT(0) | BIT(1))
 274#define HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE           ((u8)BIT(0))
 275#define HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW           ((u8)BIT(0) | BIT(1))
 276#define HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH           ((u8)BIT(2))
 277#define HT_INFO_HT_PARAM_RIFS_MODE                      ((u8)BIT(3))
 278#define HT_INFO_HT_PARAM_CTRL_ACCESS_ONLY               ((u8)BIT(4))
 279#define HT_INFO_HT_PARAM_SRV_INTERVAL_GRANULARITY       ((u8)BIT(5))
 280
 281#define HT_INFO_OPERATION_MODE_OP_MODE_MASK     \
 282                ((u16)(0x0001 | 0x0002))
 283#define HT_INFO_OPERATION_MODE_OP_MODE_OFFSET           0
 284#define HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT      ((u8)BIT(2))
 285#define HT_INFO_OPERATION_MODE_TRANSMIT_BURST_LIMIT     ((u8)BIT(3))
 286#define HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT       ((u8)BIT(4))
 287
 288/*      ===============WPS Section=============== */
 289/*      For WPSv1.0 */
 290#define WPSOUI                                  0x0050f204
 291/*      WPS attribute ID */
 292#define WPS_ATTR_VER1                           0x104A
 293#define WPS_ATTR_SIMPLE_CONF_STATE              0x1044
 294#define WPS_ATTR_RESP_TYPE                      0x103B
 295#define WPS_ATTR_UUID_E                         0x1047
 296#define WPS_ATTR_MANUFACTURER                   0x1021
 297#define WPS_ATTR_MODEL_NAME                     0x1023
 298#define WPS_ATTR_MODEL_NUMBER                   0x1024
 299#define WPS_ATTR_SERIAL_NUMBER                  0x1042
 300#define WPS_ATTR_PRIMARY_DEV_TYPE               0x1054
 301#define WPS_ATTR_SEC_DEV_TYPE_LIST              0x1055
 302#define WPS_ATTR_DEVICE_NAME                    0x1011
 303#define WPS_ATTR_CONF_METHOD                    0x1008
 304#define WPS_ATTR_RF_BANDS                       0x103C
 305#define WPS_ATTR_DEVICE_PWID                    0x1012
 306#define WPS_ATTR_REQUEST_TYPE                   0x103A
 307#define WPS_ATTR_ASSOCIATION_STATE              0x1002
 308#define WPS_ATTR_CONFIG_ERROR                   0x1009
 309#define WPS_ATTR_VENDOR_EXT                     0x1049
 310#define WPS_ATTR_SELECTED_REGISTRAR             0x1041
 311
 312/*      Value of WPS Request Type Attribute */
 313#define WPS_REQ_TYPE_ENROLLEE_INFO_ONLY         0x00
 314#define WPS_REQ_TYPE_ENROLLEE_OPEN_8021X        0x01
 315#define WPS_REQ_TYPE_REGISTRAR                  0x02
 316#define WPS_REQ_TYPE_WLAN_MANAGER_REGISTRAR     0x03
 317
 318/*      Value of WPS Response Type Attribute */
 319#define WPS_RESPONSE_TYPE_INFO_ONLY     0x00
 320#define WPS_RESPONSE_TYPE_8021X         0x01
 321#define WPS_RESPONSE_TYPE_REGISTRAR     0x02
 322#define WPS_RESPONSE_TYPE_AP            0x03
 323
 324/*      Value of WPS WiFi Simple Configuration State Attribute */
 325#define WPS_WSC_STATE_NOT_CONFIG        0x01
 326#define WPS_WSC_STATE_CONFIG            0x02
 327
 328/*      Value of WPS Version Attribute */
 329#define WPS_VERSION_1                   0x10
 330
 331/*      Value of WPS Configuration Method Attribute */
 332#define WPS_CONFIG_METHOD_FLASH         0x0001
 333#define WPS_CONFIG_METHOD_ETHERNET      0x0002
 334#define WPS_CONFIG_METHOD_LABEL         0x0004
 335#define WPS_CONFIG_METHOD_DISPLAY       0x0008
 336#define WPS_CONFIG_METHOD_E_NFC         0x0010
 337#define WPS_CONFIG_METHOD_I_NFC         0x0020
 338#define WPS_CONFIG_METHOD_NFC           0x0040
 339#define WPS_CONFIG_METHOD_PBC           0x0080
 340#define WPS_CONFIG_METHOD_KEYPAD        0x0100
 341#define WPS_CONFIG_METHOD_VPBC          0x0280
 342#define WPS_CONFIG_METHOD_PPBC          0x0480
 343#define WPS_CONFIG_METHOD_VDISPLAY      0x2008
 344#define WPS_CONFIG_METHOD_PDISPLAY      0x4008
 345
 346/*      Value of WPS RF Bands Attribute */
 347#define WPS_RF_BANDS_2_4_GHZ            0x01
 348#define WPS_RF_BANDS_5_GHZ              0x02
 349
 350#define IP_MCAST_MAC(mac)                               \
 351        ((mac[0] == 0x01) && (mac[1] == 0x00) && (mac[2] == 0x5e))
 352#define ICMPV6_MCAST_MAC(mac)                           \
 353        ((mac[0] == 0x33) && (mac[1] == 0x33) && (mac[2] != 0xff))
 354
 355#endif /*  _WIFI_H_ */
 356