Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  ieee80211.h   Sprache: C

 
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * IEEE 802.11 defines
 *
 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
 * <jkmaline@cc.hut.fi>
 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
 * Copyright (c) 2005, Devicescape Software, Inc.
 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
 * Copyright (c) 2013 - 2014 Intel Mobile Communications GmbH
 * Copyright (c) 2016 - 2017 Intel Deutschland GmbH
 * Copyright (c) 2018 - 2025 Intel Corporation
 */


#ifndef LINUX_IEEE80211_H
#define LINUX_IEEE80211_H

#include <linux/types.h>
#include <linux/if_ether.h>
#include <linux/etherdevice.h>
#include <linux/bitfield.h>
#include <asm/byteorder.h>
#include <linux/unaligned.h>

/*
 * DS bit usage
 *
 * TA = transmitter address
 * RA = receiver address
 * DA = destination address
 * SA = source address
 *
 * ToDS    FromDS  A1(RA)  A2(TA)  A3      A4      Use
 * -----------------------------------------------------------------
 *  0       0       DA      SA      BSSID   -       IBSS/DLS
 *  0       1       DA      BSSID   SA      -       AP -> STA
 *  1       0       BSSID   SA      DA      -       AP <- STA
 *  1       1       RA      TA      DA      SA      unspecified (WDS)
 */


#define FCS_LEN 4

#define IEEE80211_FCTL_VERS  0x0003
#define IEEE80211_FCTL_FTYPE  0x000c
#define IEEE80211_FCTL_STYPE  0x00f0
#define IEEE80211_FCTL_TODS  0x0100
#define IEEE80211_FCTL_FROMDS  0x0200
#define IEEE80211_FCTL_MOREFRAGS 0x0400
#define IEEE80211_FCTL_RETRY  0x0800
#define IEEE80211_FCTL_PM  0x1000
#define IEEE80211_FCTL_MOREDATA  0x2000
#define IEEE80211_FCTL_PROTECTED 0x4000
#define IEEE80211_FCTL_ORDER  0x8000
#define IEEE80211_FCTL_CTL_EXT  0x0f00

#define IEEE80211_SCTL_FRAG  0x000F
#define IEEE80211_SCTL_SEQ  0xFFF0

#define IEEE80211_FTYPE_MGMT  0x0000
#define IEEE80211_FTYPE_CTL  0x0004
#define IEEE80211_FTYPE_DATA  0x0008
#define IEEE80211_FTYPE_EXT  0x000c

/* management */
#define IEEE80211_STYPE_ASSOC_REQ 0x0000
#define IEEE80211_STYPE_ASSOC_RESP 0x0010
#define IEEE80211_STYPE_REASSOC_REQ 0x0020
#define IEEE80211_STYPE_REASSOC_RESP 0x0030
#define IEEE80211_STYPE_PROBE_REQ 0x0040
#define IEEE80211_STYPE_PROBE_RESP 0x0050
#define IEEE80211_STYPE_BEACON  0x0080
#define IEEE80211_STYPE_ATIM  0x0090
#define IEEE80211_STYPE_DISASSOC 0x00A0
#define IEEE80211_STYPE_AUTH  0x00B0
#define IEEE80211_STYPE_DEAUTH  0x00C0
#define IEEE80211_STYPE_ACTION  0x00D0

/* control */
#define IEEE80211_STYPE_TRIGGER  0x0020
#define IEEE80211_STYPE_CTL_EXT  0x0060
#define IEEE80211_STYPE_BACK_REQ 0x0080
#define IEEE80211_STYPE_BACK  0x0090
#define IEEE80211_STYPE_PSPOLL  0x00A0
#define IEEE80211_STYPE_RTS  0x00B0
#define IEEE80211_STYPE_CTS  0x00C0
#define IEEE80211_STYPE_ACK  0x00D0
#define IEEE80211_STYPE_CFEND  0x00E0
#define IEEE80211_STYPE_CFENDACK 0x00F0

/* data */
#define IEEE80211_STYPE_DATA   0x0000
#define IEEE80211_STYPE_DATA_CFACK  0x0010
#define IEEE80211_STYPE_DATA_CFPOLL  0x0020
#define IEEE80211_STYPE_DATA_CFACKPOLL  0x0030
#define IEEE80211_STYPE_NULLFUNC  0x0040
#define IEEE80211_STYPE_CFACK   0x0050
#define IEEE80211_STYPE_CFPOLL   0x0060
#define IEEE80211_STYPE_CFACKPOLL  0x0070
#define IEEE80211_STYPE_QOS_DATA  0x0080
#define IEEE80211_STYPE_QOS_DATA_CFACK  0x0090
#define IEEE80211_STYPE_QOS_DATA_CFPOLL  0x00A0
#define IEEE80211_STYPE_QOS_DATA_CFACKPOLL 0x00B0
#define IEEE80211_STYPE_QOS_NULLFUNC  0x00C0
#define IEEE80211_STYPE_QOS_CFACK  0x00D0
#define IEEE80211_STYPE_QOS_CFPOLL  0x00E0
#define IEEE80211_STYPE_QOS_CFACKPOLL  0x00F0

/* extension, added by 802.11ad */
#define IEEE80211_STYPE_DMG_BEACON  0x0000
#define IEEE80211_STYPE_S1G_BEACON  0x0010

/* bits unique to S1G beacon */
#define IEEE80211_S1G_BCN_NEXT_TBTT 0x100
#define IEEE80211_S1G_BCN_CSSID  0x200
#define IEEE80211_S1G_BCN_ANO  0x400

/* see 802.11ah-2016 9.9 NDP CMAC frames */
#define IEEE80211_S1G_1MHZ_NDP_BITS 25
#define IEEE80211_S1G_1MHZ_NDP_BYTES 4
#define IEEE80211_S1G_2MHZ_NDP_BITS 37
#define IEEE80211_S1G_2MHZ_NDP_BYTES 5

#define IEEE80211_NDP_FTYPE_CTS   0
#define IEEE80211_NDP_FTYPE_CF_END  0
#define IEEE80211_NDP_FTYPE_PS_POLL  1
#define IEEE80211_NDP_FTYPE_ACK   2
#define IEEE80211_NDP_FTYPE_PS_POLL_ACK  3
#define IEEE80211_NDP_FTYPE_BA   4
#define IEEE80211_NDP_FTYPE_BF_REPORT_POLL 5
#define IEEE80211_NDP_FTYPE_PAGING  6
#define IEEE80211_NDP_FTYPE_PREQ  7

#define SM64(f, v) ((((u64)v) << f##_S) & f)

/* NDP CMAC frame fields */
#define IEEE80211_NDP_FTYPE                    0x0000000000000007
#define IEEE80211_NDP_FTYPE_S                  0x0000000000000000

/* 1M Probe Request 11ah 9.9.3.1.1 */
#define IEEE80211_NDP_1M_PREQ_ANO      0x0000000000000008
#define IEEE80211_NDP_1M_PREQ_ANO_S                     3
#define IEEE80211_NDP_1M_PREQ_CSSID    0x00000000000FFFF0
#define IEEE80211_NDP_1M_PREQ_CSSID_S                   4
#define IEEE80211_NDP_1M_PREQ_RTYPE    0x0000000000100000
#define IEEE80211_NDP_1M_PREQ_RTYPE_S                  20
#define IEEE80211_NDP_1M_PREQ_RSV      0x0000000001E00000
#define IEEE80211_NDP_1M_PREQ_RSV      0x0000000001E00000
/* 2M Probe Request 11ah 9.9.3.1.2 */
#define IEEE80211_NDP_2M_PREQ_ANO      0x0000000000000008
#define IEEE80211_NDP_2M_PREQ_ANO_S                     3
#define IEEE80211_NDP_2M_PREQ_CSSID    0x0000000FFFFFFFF0
#define IEEE80211_NDP_2M_PREQ_CSSID_S                   4
#define IEEE80211_NDP_2M_PREQ_RTYPE    0x0000001000000000
#define IEEE80211_NDP_2M_PREQ_RTYPE_S                  36

#define IEEE80211_ANO_NETTYPE_WILD              15

/* control extension - for IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTL_EXT */
#define IEEE80211_CTL_EXT_POLL  0x2000
#define IEEE80211_CTL_EXT_SPR  0x3000
#define IEEE80211_CTL_EXT_GRANT 0x4000
#define IEEE80211_CTL_EXT_DMG_CTS 0x5000
#define IEEE80211_CTL_EXT_DMG_DTS 0x6000
#define IEEE80211_CTL_EXT_SSW  0x8000
#define IEEE80211_CTL_EXT_SSW_FBACK 0x9000
#define IEEE80211_CTL_EXT_SSW_ACK 0xa000


#define IEEE80211_SN_MASK  ((IEEE80211_SCTL_SEQ) >> 4)
#define IEEE80211_MAX_SN  IEEE80211_SN_MASK
#define IEEE80211_SN_MODULO  (IEEE80211_MAX_SN + 1)


/* PV1 Layout IEEE 802.11-2020 9.8.3.1 */
#define IEEE80211_PV1_FCTL_VERS  0x0003
#define IEEE80211_PV1_FCTL_FTYPE 0x001c
#define IEEE80211_PV1_FCTL_STYPE 0x00e0
#define IEEE80211_PV1_FCTL_FROMDS  0x0100
#define IEEE80211_PV1_FCTL_MOREFRAGS 0x0200
#define IEEE80211_PV1_FCTL_PM  0x0400
#define IEEE80211_PV1_FCTL_MOREDATA 0x0800
#define IEEE80211_PV1_FCTL_PROTECTED 0x1000
#define IEEE80211_PV1_FCTL_END_SP       0x2000
#define IEEE80211_PV1_FCTL_RELAYED      0x4000
#define IEEE80211_PV1_FCTL_ACK_POLICY   0x8000
#define IEEE80211_PV1_FCTL_CTL_EXT 0x0f00

static inline bool ieee80211_sn_less(u16 sn1, u16 sn2)
{
 return ((sn1 - sn2) & IEEE80211_SN_MASK) > (IEEE80211_SN_MODULO >> 1);
}

static inline bool ieee80211_sn_less_eq(u16 sn1, u16 sn2)
{
 return ((sn2 - sn1) & IEEE80211_SN_MASK) <= (IEEE80211_SN_MODULO >> 1);
}

static inline u16 ieee80211_sn_add(u16 sn1, u16 sn2)
{
 return (sn1 + sn2) & IEEE80211_SN_MASK;
}

static inline u16 ieee80211_sn_inc(u16 sn)
{
 return ieee80211_sn_add(sn, 1);
}

static inline u16 ieee80211_sn_sub(u16 sn1, u16 sn2)
{
 return (sn1 - sn2) & IEEE80211_SN_MASK;
}

#define IEEE80211_SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
#define IEEE80211_SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)

/* miscellaneous IEEE 802.11 constants */
#define IEEE80211_MAX_FRAG_THRESHOLD 2352
#define IEEE80211_MAX_RTS_THRESHOLD 2353
#define IEEE80211_MAX_AID  2007
#define IEEE80211_MAX_AID_S1G  8191
#define IEEE80211_MAX_TIM_LEN  251
#define IEEE80211_MAX_MESH_PEERINGS 63
/* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
   6.2.1.1.2.

   802.11e clarifies the figure in section 7.1.2. The frame body is
   up to 2304 octets long (maximum MSDU size) plus any crypt overhead. */

#define IEEE80211_MAX_DATA_LEN  2304
/* 802.11ad extends maximum MSDU size for DMG (freq > 40Ghz) networks
 * to 7920 bytes, see 8.2.3 General frame format
 */

#define IEEE80211_MAX_DATA_LEN_DMG 7920
/* 30 byte 4 addr hdr, 2 byte QoS, 2304 byte MSDU, 12 byte crypt, 4 byte FCS */
#define IEEE80211_MAX_FRAME_LEN  2352

/* Maximal size of an A-MSDU that can be transported in a HT BA session */
#define IEEE80211_MAX_MPDU_LEN_HT_BA  4095

/* Maximal size of an A-MSDU */
#define IEEE80211_MAX_MPDU_LEN_HT_3839  3839
#define IEEE80211_MAX_MPDU_LEN_HT_7935  7935

#define IEEE80211_MAX_MPDU_LEN_VHT_3895  3895
#define IEEE80211_MAX_MPDU_LEN_VHT_7991  7991
#define IEEE80211_MAX_MPDU_LEN_VHT_11454 11454

#define IEEE80211_MAX_SSID_LEN  32

#define IEEE80211_MAX_MESH_ID_LEN 32

#define IEEE80211_FIRST_TSPEC_TSID 8
#define IEEE80211_NUM_TIDS  16

/* number of user priorities 802.11 uses */
#define IEEE80211_NUM_UPS  8
/* number of ACs */
#define IEEE80211_NUM_ACS  4

#define IEEE80211_QOS_CTL_LEN  2
/* 1d tag mask */
#define IEEE80211_QOS_CTL_TAG1D_MASK  0x0007
/* TID mask */
#define IEEE80211_QOS_CTL_TID_MASK  0x000f
/* EOSP */
#define IEEE80211_QOS_CTL_EOSP   0x0010
/* ACK policy */
#define IEEE80211_QOS_CTL_ACK_POLICY_NORMAL 0x0000
#define IEEE80211_QOS_CTL_ACK_POLICY_NOACK 0x0020
#define IEEE80211_QOS_CTL_ACK_POLICY_NO_EXPL 0x0040
#define IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK 0x0060
#define IEEE80211_QOS_CTL_ACK_POLICY_MASK 0x0060
/* A-MSDU 802.11n */
#define IEEE80211_QOS_CTL_A_MSDU_PRESENT 0x0080
/* Mesh Control 802.11s */
#define IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT  0x0100

/* Mesh Power Save Level */
#define IEEE80211_QOS_CTL_MESH_PS_LEVEL  0x0200
/* Mesh Receiver Service Period Initiated */
#define IEEE80211_QOS_CTL_RSPI   0x0400

/* U-APSD queue for WMM IEs sent by AP */
#define IEEE80211_WMM_IE_AP_QOSINFO_UAPSD (1<<7)
#define IEEE80211_WMM_IE_AP_QOSINFO_PARAM_SET_CNT_MASK 0x0f

/* U-APSD queues for WMM IEs sent by STA */
#define IEEE80211_WMM_IE_STA_QOSINFO_AC_VO (1<<0)
#define IEEE80211_WMM_IE_STA_QOSINFO_AC_VI (1<<1)
#define IEEE80211_WMM_IE_STA_QOSINFO_AC_BK (1<<2)
#define IEEE80211_WMM_IE_STA_QOSINFO_AC_BE (1<<3)
#define IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK 0x0f

/* U-APSD max SP length for WMM IEs sent by STA */
#define IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL 0x00
#define IEEE80211_WMM_IE_STA_QOSINFO_SP_2 0x01
#define IEEE80211_WMM_IE_STA_QOSINFO_SP_4 0x02
#define IEEE80211_WMM_IE_STA_QOSINFO_SP_6 0x03
#define IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK 0x03
#define IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT 5

#define IEEE80211_HT_CTL_LEN  4

/* trigger type within common_info of trigger frame */
#define IEEE80211_TRIGGER_TYPE_MASK  0xf
#define IEEE80211_TRIGGER_TYPE_BASIC  0x0
#define IEEE80211_TRIGGER_TYPE_BFRP  0x1
#define IEEE80211_TRIGGER_TYPE_MU_BAR  0x2
#define IEEE80211_TRIGGER_TYPE_MU_RTS  0x3
#define IEEE80211_TRIGGER_TYPE_BSRP  0x4
#define IEEE80211_TRIGGER_TYPE_GCR_MU_BAR 0x5
#define IEEE80211_TRIGGER_TYPE_BQRP  0x6
#define IEEE80211_TRIGGER_TYPE_NFRP  0x7

/* UL-bandwidth within common_info of trigger frame */
#define IEEE80211_TRIGGER_ULBW_MASK  0xc0000
#define IEEE80211_TRIGGER_ULBW_20MHZ  0x0
#define IEEE80211_TRIGGER_ULBW_40MHZ  0x1
#define IEEE80211_TRIGGER_ULBW_80MHZ  0x2
#define IEEE80211_TRIGGER_ULBW_160_80P80MHZ 0x3

struct ieee80211_hdr {
 __le16 frame_control;
 __le16 duration_id;
 struct_group(addrs,
  u8 addr1[ETH_ALEN];
  u8 addr2[ETH_ALEN];
  u8 addr3[ETH_ALEN];
 );
 __le16 seq_ctrl;
 u8 addr4[ETH_ALEN];
} __packed __aligned(2);

struct ieee80211_hdr_3addr {
 __le16 frame_control;
 __le16 duration_id;
 u8 addr1[ETH_ALEN];
 u8 addr2[ETH_ALEN];
 u8 addr3[ETH_ALEN];
 __le16 seq_ctrl;
} __packed __aligned(2);

struct ieee80211_qos_hdr {
 __le16 frame_control;
 __le16 duration_id;
 u8 addr1[ETH_ALEN];
 u8 addr2[ETH_ALEN];
 u8 addr3[ETH_ALEN];
 __le16 seq_ctrl;
 __le16 qos_ctrl;
} __packed __aligned(2);

struct ieee80211_qos_hdr_4addr {
 __le16 frame_control;
 __le16 duration_id;
 u8 addr1[ETH_ALEN];
 u8 addr2[ETH_ALEN];
 u8 addr3[ETH_ALEN];
 __le16 seq_ctrl;
 u8 addr4[ETH_ALEN];
 __le16 qos_ctrl;
} __packed __aligned(2);

struct ieee80211_trigger {
 __le16 frame_control;
 __le16 duration;
 u8 ra[ETH_ALEN];
 u8 ta[ETH_ALEN];
 __le64 common_info;
 u8 variable[];
} __packed __aligned(2);

/**
 * ieee80211_has_tods - check if IEEE80211_FCTL_TODS is set
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame has to-DS set
 */

static inline bool ieee80211_has_tods(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_TODS)) != 0;
}

/**
 * ieee80211_has_fromds - check if IEEE80211_FCTL_FROMDS is set
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame has from-DS set
 */

static inline bool ieee80211_has_fromds(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FROMDS)) != 0;
}

/**
 * ieee80211_has_a4 - check if IEEE80211_FCTL_TODS and IEEE80211_FCTL_FROMDS are set
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not it's a 4-address frame (from-DS and to-DS set)
 */

static inline bool ieee80211_has_a4(__le16 fc)
{
 __le16 tmp = cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS);
 return (fc & tmp) == tmp;
}

/**
 * ieee80211_has_morefrags - check if IEEE80211_FCTL_MOREFRAGS is set
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame has more fragments (more frags bit set)
 */

static inline bool ieee80211_has_morefrags(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) != 0;
}

/**
 * ieee80211_has_retry - check if IEEE80211_FCTL_RETRY is set
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the retry flag is set
 */

static inline bool ieee80211_has_retry(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_RETRY)) != 0;
}

/**
 * ieee80211_has_pm - check if IEEE80211_FCTL_PM is set
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the power management flag is set
 */

static inline bool ieee80211_has_pm(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_PM)) != 0;
}

/**
 * ieee80211_has_moredata - check if IEEE80211_FCTL_MOREDATA is set
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the more data flag is set
 */

static inline bool ieee80211_has_moredata(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_MOREDATA)) != 0;
}

/**
 * ieee80211_has_protected - check if IEEE80211_FCTL_PROTECTED is set
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the protected flag is set
 */

static inline bool ieee80211_has_protected(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_PROTECTED)) != 0;
}

/**
 * ieee80211_has_order - check if IEEE80211_FCTL_ORDER is set
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the order flag is set
 */

static inline bool ieee80211_has_order(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_ORDER)) != 0;
}

/**
 * ieee80211_is_mgmt - check if type is IEEE80211_FTYPE_MGMT
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame type is management
 */

static inline bool ieee80211_is_mgmt(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_MGMT);
}

/**
 * ieee80211_is_ctl - check if type is IEEE80211_FTYPE_CTL
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame type is control
 */

static inline bool ieee80211_is_ctl(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_CTL);
}

/**
 * ieee80211_is_data - check if type is IEEE80211_FTYPE_DATA
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a data frame
 */

static inline bool ieee80211_is_data(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_DATA);
}

/**
 * ieee80211_is_ext - check if type is IEEE80211_FTYPE_EXT
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame type is extended
 */

static inline bool ieee80211_is_ext(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_EXT);
}


/**
 * ieee80211_is_data_qos - check if type is IEEE80211_FTYPE_DATA and IEEE80211_STYPE_QOS_DATA is set
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a QoS data frame
 */

static inline bool ieee80211_is_data_qos(__le16 fc)
{
 /*
 * mask with QOS_DATA rather than IEEE80211_FCTL_STYPE as we just need
 * to check the one bit
 */

 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_STYPE_QOS_DATA)) ==
        cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA);
}

/**
 * ieee80211_is_data_present - check if type is IEEE80211_FTYPE_DATA and has data
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a QoS data frame that has data
 * (i.e. is not null data)
 */

static inline bool ieee80211_is_data_present(__le16 fc)
{
 /*
 * mask with 0x40 and test that that bit is clear to only return true
 * for the data-containing substypes.
 */

 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | 0x40)) ==
        cpu_to_le16(IEEE80211_FTYPE_DATA);
}

/**
 * ieee80211_is_assoc_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ASSOC_REQ
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is an association request
 */

static inline bool ieee80211_is_assoc_req(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ASSOC_REQ);
}

/**
 * ieee80211_is_assoc_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ASSOC_RESP
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is an association response
 */

static inline bool ieee80211_is_assoc_resp(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ASSOC_RESP);
}

/**
 * ieee80211_is_reassoc_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_REASSOC_REQ
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a reassociation request
 */

static inline bool ieee80211_is_reassoc_req(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_REASSOC_REQ);
}

/**
 * ieee80211_is_reassoc_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_REASSOC_RESP
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a reassociation response
 */

static inline bool ieee80211_is_reassoc_resp(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_REASSOC_RESP);
}

/**
 * ieee80211_is_probe_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_PROBE_REQ
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a probe request
 */

static inline bool ieee80211_is_probe_req(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ);
}

/**
 * ieee80211_is_probe_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_PROBE_RESP
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a probe response
 */

static inline bool ieee80211_is_probe_resp(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
}

/**
 * ieee80211_is_beacon - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_BEACON
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a (regular, not S1G) beacon
 */

static inline bool ieee80211_is_beacon(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
}

/**
 * ieee80211_is_s1g_beacon - check if IEEE80211_FTYPE_EXT &&
 * IEEE80211_STYPE_S1G_BEACON
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is an S1G beacon
 */

static inline bool ieee80211_is_s1g_beacon(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE |
     IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_EXT | IEEE80211_STYPE_S1G_BEACON);
}

/**
 * ieee80211_s1g_has_next_tbtt - check if IEEE80211_S1G_BCN_NEXT_TBTT
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame contains the variable-length
 * next TBTT field
 */

static inline bool ieee80211_s1g_has_next_tbtt(__le16 fc)
{
 return ieee80211_is_s1g_beacon(fc) &&
  (fc & cpu_to_le16(IEEE80211_S1G_BCN_NEXT_TBTT));
}

/**
 * ieee80211_s1g_has_ano - check if IEEE80211_S1G_BCN_ANO
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame contains the variable-length
 * ANO field
 */

static inline bool ieee80211_s1g_has_ano(__le16 fc)
{
 return ieee80211_is_s1g_beacon(fc) &&
  (fc & cpu_to_le16(IEEE80211_S1G_BCN_ANO));
}

/**
 * ieee80211_s1g_has_cssid - check if IEEE80211_S1G_BCN_CSSID
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame contains the variable-length
 * compressed SSID field
 */

static inline bool ieee80211_s1g_has_cssid(__le16 fc)
{
 return ieee80211_is_s1g_beacon(fc) &&
  (fc & cpu_to_le16(IEEE80211_S1G_BCN_CSSID));
}

/**
 * ieee80211_is_atim - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ATIM
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is an ATIM frame
 */

static inline bool ieee80211_is_atim(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ATIM);
}

/**
 * ieee80211_is_disassoc - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_DISASSOC
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a disassociation frame
 */

static inline bool ieee80211_is_disassoc(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DISASSOC);
}

/**
 * ieee80211_is_auth - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_AUTH
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is an authentication frame
 */

static inline bool ieee80211_is_auth(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH);
}

/**
 * ieee80211_is_deauth - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_DEAUTH
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a deauthentication frame
 */

static inline bool ieee80211_is_deauth(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH);
}

/**
 * ieee80211_is_action - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ACTION
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is an action frame
 */

static inline bool ieee80211_is_action(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION);
}

/**
 * ieee80211_is_back_req - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_BACK_REQ
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a block-ACK request frame
 */

static inline bool ieee80211_is_back_req(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK_REQ);
}

/**
 * ieee80211_is_back - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_BACK
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a block-ACK frame
 */

static inline bool ieee80211_is_back(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK);
}

/**
 * ieee80211_is_pspoll - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_PSPOLL
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a PS-poll frame
 */

static inline bool ieee80211_is_pspoll(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
}

/**
 * ieee80211_is_rts - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_RTS
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is an RTS frame
 */

static inline bool ieee80211_is_rts(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
}

/**
 * ieee80211_is_cts - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CTS
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a CTS frame
 */

static inline bool ieee80211_is_cts(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
}

/**
 * ieee80211_is_ack - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_ACK
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is an ACK frame
 */

static inline bool ieee80211_is_ack(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK);
}

/**
 * ieee80211_is_cfend - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CFEND
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a CF-end frame
 */

static inline bool ieee80211_is_cfend(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CFEND);
}

/**
 * ieee80211_is_cfendack - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CFENDACK
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a CF-end-ack frame
 */

static inline bool ieee80211_is_cfendack(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CFENDACK);
}

/**
 * ieee80211_is_nullfunc - check if frame is a regular (non-QoS) nullfunc frame
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a nullfunc frame
 */

static inline bool ieee80211_is_nullfunc(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC);
}

/**
 * ieee80211_is_qos_nullfunc - check if frame is a QoS nullfunc frame
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a QoS nullfunc frame
 */

static inline bool ieee80211_is_qos_nullfunc(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_NULLFUNC);
}

/**
 * ieee80211_is_trigger - check if frame is trigger frame
 * @fc: frame control field in little-endian byteorder
 * Return: whether or not the frame is a trigger frame
 */

static inline bool ieee80211_is_trigger(__le16 fc)
{
 return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
        cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_TRIGGER);
}

/**
 * ieee80211_is_any_nullfunc - check if frame is regular or QoS nullfunc frame
 * @fc: frame control bytes in little-endian byteorder
 * Return: whether or not the frame is a nullfunc or QoS nullfunc frame
 */

static inline bool ieee80211_is_any_nullfunc(__le16 fc)
{
 return (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc));
}

/**
 * ieee80211_is_first_frag - check if IEEE80211_SCTL_FRAG is not set
 * @seq_ctrl: frame sequence control bytes in little-endian byteorder
 * Return: whether or not the frame is the first fragment (also true if
 * it's not fragmented at all)
 */

static inline bool ieee80211_is_first_frag(__le16 seq_ctrl)
{
 return (seq_ctrl & cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0;
}

/**
 * ieee80211_is_frag - check if a frame is a fragment
 * @hdr: 802.11 header of the frame
 * Return: whether or not the frame is a fragment
 */

static inline bool ieee80211_is_frag(struct ieee80211_hdr *hdr)
{
 return ieee80211_has_morefrags(hdr->frame_control) ||
        hdr->seq_ctrl & cpu_to_le16(IEEE80211_SCTL_FRAG);
}

static inline u16 ieee80211_get_sn(struct ieee80211_hdr *hdr)
{
 return le16_get_bits(hdr->seq_ctrl, IEEE80211_SCTL_SEQ);
}

struct ieee80211s_hdr {
 u8 flags;
 u8 ttl;
 __le32 seqnum;
 u8 eaddr1[ETH_ALEN];
 u8 eaddr2[ETH_ALEN];
} __packed __aligned(2);

/* Mesh flags */
#define MESH_FLAGS_AE_A4  0x1
#define MESH_FLAGS_AE_A5_A6 0x2
#define MESH_FLAGS_AE  0x3
#define MESH_FLAGS_PS_DEEP 0x4

/**
 * enum ieee80211_preq_flags - mesh PREQ element flags
 *
 * @IEEE80211_PREQ_PROACTIVE_PREP_FLAG: proactive PREP subfield
 */

enum ieee80211_preq_flags {
 IEEE80211_PREQ_PROACTIVE_PREP_FLAG = 1<<2,
};

/**
 * enum ieee80211_preq_target_flags - mesh PREQ element per target flags
 *
 * @IEEE80211_PREQ_TO_FLAG: target only subfield
 * @IEEE80211_PREQ_USN_FLAG: unknown target HWMP sequence number subfield
 */

enum ieee80211_preq_target_flags {
 IEEE80211_PREQ_TO_FLAG = 1<<0,
 IEEE80211_PREQ_USN_FLAG = 1<<2,
};

/**
 * struct ieee80211_quiet_ie - Quiet element
 * @count: Quiet Count
 * @period: Quiet Period
 * @duration: Quiet Duration
 * @offset: Quiet Offset
 *
 * This structure represents the payload of the "Quiet element" as
 * described in IEEE Std 802.11-2020 section 9.4.2.22.
 */

struct ieee80211_quiet_ie {
 u8 count;
 u8 period;
 __le16 duration;
 __le16 offset;
} __packed;

/**
 * struct ieee80211_msrment_ie - Measurement element
 * @token: Measurement Token
 * @mode: Measurement Report Mode
 * @type: Measurement Type
 * @request: Measurement Request or Measurement Report
 *
 * This structure represents the payload of both the "Measurement
 * Request element" and the "Measurement Report element" as described
 * in IEEE Std 802.11-2020 sections 9.4.2.20 and 9.4.2.21.
 */

struct ieee80211_msrment_ie {
 u8 token;
 u8 mode;
 u8 type;
 u8 request[];
} __packed;

/**
 * struct ieee80211_channel_sw_ie - Channel Switch Announcement element
 * @mode: Channel Switch Mode
 * @new_ch_num: New Channel Number
 * @count: Channel Switch Count
 *
 * This structure represents the payload of the "Channel Switch
 * Announcement element" as described in IEEE Std 802.11-2020 section
 * 9.4.2.18.
 */

struct ieee80211_channel_sw_ie {
 u8 mode;
 u8 new_ch_num;
 u8 count;
} __packed;

/**
 * struct ieee80211_ext_chansw_ie - Extended Channel Switch Announcement element
 * @mode: Channel Switch Mode
 * @new_operating_class: New Operating Class
 * @new_ch_num: New Channel Number
 * @count: Channel Switch Count
 *
 * This structure represents the "Extended Channel Switch Announcement
 * element" as described in IEEE Std 802.11-2020 section 9.4.2.52.
 */

struct ieee80211_ext_chansw_ie {
 u8 mode;
 u8 new_operating_class;
 u8 new_ch_num;
 u8 count;
} __packed;

/**
 * struct ieee80211_sec_chan_offs_ie - secondary channel offset IE
 * @sec_chan_offs: secondary channel offset, uses IEEE80211_HT_PARAM_CHA_SEC_*
 * values here
 * This structure represents the "Secondary Channel Offset element"
 */

struct ieee80211_sec_chan_offs_ie {
 u8 sec_chan_offs;
} __packed;

/**
 * struct ieee80211_mesh_chansw_params_ie - mesh channel switch parameters IE
 * @mesh_ttl: Time To Live
 * @mesh_flags: Flags
 * @mesh_reason: Reason Code
 * @mesh_pre_value: Precedence Value
 *
 * This structure represents the payload of the "Mesh Channel Switch
 * Parameters element" as described in IEEE Std 802.11-2020 section
 * 9.4.2.102.
 */

struct ieee80211_mesh_chansw_params_ie {
 u8 mesh_ttl;
 u8 mesh_flags;
 __le16 mesh_reason;
 __le16 mesh_pre_value;
} __packed;

/**
 * struct ieee80211_wide_bw_chansw_ie - wide bandwidth channel switch IE
 * @new_channel_width: New Channel Width
 * @new_center_freq_seg0: New Channel Center Frequency Segment 0
 * @new_center_freq_seg1: New Channel Center Frequency Segment 1
 *
 * This structure represents the payload of the "Wide Bandwidth
 * Channel Switch element" as described in IEEE Std 802.11-2020
 * section 9.4.2.160.
 */

struct ieee80211_wide_bw_chansw_ie {
 u8 new_channel_width;
 u8 new_center_freq_seg0, new_center_freq_seg1;
} __packed;

/**
 * struct ieee80211_tim_ie - Traffic Indication Map information element
 * @dtim_count: DTIM Count
 * @dtim_period: DTIM Period
 * @bitmap_ctrl: Bitmap Control
 * @required_octet: "Syntatic sugar" to force the struct size to the
 *                  minimum valid size when carried in a non-S1G PPDU
 * @virtual_map: Partial Virtual Bitmap
 *
 * This structure represents the payload of the "TIM element" as
 * described in IEEE Std 802.11-2020 section 9.4.2.5. Note that this
 * definition is only applicable when the element is carried in a
 * non-S1G PPDU. When the TIM is carried in an S1G PPDU, the Bitmap
 * Control and Partial Virtual Bitmap may not be present.
 */

struct ieee80211_tim_ie {
 u8 dtim_count;
 u8 dtim_period;
 u8 bitmap_ctrl;
 union {
  u8 required_octet;
  DECLARE_FLEX_ARRAY(u8, virtual_map);
 };
} __packed;

/**
 * struct ieee80211_meshconf_ie - Mesh Configuration element
 * @meshconf_psel: Active Path Selection Protocol Identifier
 * @meshconf_pmetric: Active Path Selection Metric Identifier
 * @meshconf_congest: Congestion Control Mode Identifier
 * @meshconf_synch: Synchronization Method Identifier
 * @meshconf_auth: Authentication Protocol Identifier
 * @meshconf_form: Mesh Formation Info
 * @meshconf_cap: Mesh Capability (see &enum mesh_config_capab_flags)
 *
 * This structure represents the payload of the "Mesh Configuration
 * element" as described in IEEE Std 802.11-2020 section 9.4.2.97.
 */

struct ieee80211_meshconf_ie {
 u8 meshconf_psel;
 u8 meshconf_pmetric;
 u8 meshconf_congest;
 u8 meshconf_synch;
 u8 meshconf_auth;
 u8 meshconf_form;
 u8 meshconf_cap;
} __packed;

/**
 * enum mesh_config_capab_flags - Mesh Configuration IE capability field flags
 *
 * @IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS: STA is willing to establish
 * additional mesh peerings with other mesh STAs
 * @IEEE80211_MESHCONF_CAPAB_FORWARDING: the STA forwards MSDUs
 * @IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING: TBTT adjustment procedure
 * is ongoing
 * @IEEE80211_MESHCONF_CAPAB_POWER_SAVE_LEVEL: STA is in deep sleep mode or has
 * neighbors in deep sleep mode
 *
 * Enumerates the "Mesh Capability" as described in IEEE Std
 * 802.11-2020 section 9.4.2.97.7.
 */

enum mesh_config_capab_flags {
 IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS  = 0x01,
 IEEE80211_MESHCONF_CAPAB_FORWARDING  = 0x08,
 IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING  = 0x20,
 IEEE80211_MESHCONF_CAPAB_POWER_SAVE_LEVEL = 0x40,
};

#define IEEE80211_MESHCONF_FORM_CONNECTED_TO_GATE 0x1

/*
 * mesh channel switch parameters element's flag indicator
 *
 */

#define WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT BIT(0)
#define WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR BIT(1)
#define WLAN_EID_CHAN_SWITCH_PARAM_REASON BIT(2)

/**
 * struct ieee80211_rann_ie - RANN (root announcement) element
 * @rann_flags: Flags
 * @rann_hopcount: Hop Count
 * @rann_ttl: Element TTL
 * @rann_addr: Root Mesh STA Address
 * @rann_seq: HWMP Sequence Number
 * @rann_interval: Interval
 * @rann_metric: Metric
 *
 * This structure represents the payload of the "RANN element" as
 * described in IEEE Std 802.11-2020 section 9.4.2.111.
 */

struct ieee80211_rann_ie {
 u8 rann_flags;
 u8 rann_hopcount;
 u8 rann_ttl;
 u8 rann_addr[ETH_ALEN];
 __le32 rann_seq;
 __le32 rann_interval;
 __le32 rann_metric;
} __packed;

enum ieee80211_rann_flags {
 RANN_FLAG_IS_GATE = 1 << 0,
};

enum ieee80211_ht_chanwidth_values {
 IEEE80211_HT_CHANWIDTH_20MHZ = 0,
 IEEE80211_HT_CHANWIDTH_ANY = 1,
};

/**
 * enum ieee80211_vht_opmode_bits - VHT operating mode field bits
 * @IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK: channel width mask
 * @IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ: 20 MHz channel width
 * @IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ: 40 MHz channel width
 * @IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ: 80 MHz channel width
 * @IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ: 160 MHz or 80+80 MHz channel width
 * @IEEE80211_OPMODE_NOTIF_BW_160_80P80: 160 / 80+80 MHz indicator flag
 * @IEEE80211_OPMODE_NOTIF_RX_NSS_MASK: number of spatial streams mask
 * (the NSS value is the value of this field + 1)
 * @IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT: number of spatial streams shift
 * @IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF: indicates streams in SU-MIMO PPDU
 * using a beamforming steering matrix
 */

enum ieee80211_vht_opmode_bits {
 IEEE80211_OPMODE_NOTIF_CHANWIDTH_MASK = 0x03,
 IEEE80211_OPMODE_NOTIF_CHANWIDTH_20MHZ = 0,
 IEEE80211_OPMODE_NOTIF_CHANWIDTH_40MHZ = 1,
 IEEE80211_OPMODE_NOTIF_CHANWIDTH_80MHZ = 2,
 IEEE80211_OPMODE_NOTIF_CHANWIDTH_160MHZ = 3,
 IEEE80211_OPMODE_NOTIF_BW_160_80P80 = 0x04,
 IEEE80211_OPMODE_NOTIF_RX_NSS_MASK = 0x70,
 IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT = 4,
 IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF = 0x80,
};

/**
 * enum ieee80211_s1g_chanwidth - S1G channel widths
 * These are defined in IEEE802.11-2016ah Table 10-20
 * as BSS Channel Width
 *
 * @IEEE80211_S1G_CHANWIDTH_1MHZ: 1MHz operating channel
 * @IEEE80211_S1G_CHANWIDTH_2MHZ: 2MHz operating channel
 * @IEEE80211_S1G_CHANWIDTH_4MHZ: 4MHz operating channel
 * @IEEE80211_S1G_CHANWIDTH_8MHZ: 8MHz operating channel
 * @IEEE80211_S1G_CHANWIDTH_16MHZ: 16MHz operating channel
 */

enum ieee80211_s1g_chanwidth {
 IEEE80211_S1G_CHANWIDTH_1MHZ = 0,
 IEEE80211_S1G_CHANWIDTH_2MHZ = 1,
 IEEE80211_S1G_CHANWIDTH_4MHZ = 3,
 IEEE80211_S1G_CHANWIDTH_8MHZ = 7,
 IEEE80211_S1G_CHANWIDTH_16MHZ = 15,
};

#define WLAN_SA_QUERY_TR_ID_LEN 2
#define WLAN_MEMBERSHIP_LEN 8
#define WLAN_USER_POSITION_LEN 16

/**
 * struct ieee80211_tpc_report_ie - TPC Report element
 * @tx_power: Transmit Power
 * @link_margin: Link Margin
 *
 * This structure represents the payload of the "TPC Report element" as
 * described in IEEE Std 802.11-2020 section 9.4.2.16.
 */

struct ieee80211_tpc_report_ie {
 u8 tx_power;
 u8 link_margin;
} __packed;

#define IEEE80211_ADDBA_EXT_FRAG_LEVEL_MASK GENMASK(2, 1)
#define IEEE80211_ADDBA_EXT_FRAG_LEVEL_SHIFT 1
#define IEEE80211_ADDBA_EXT_NO_FRAG  BIT(0)
#define IEEE80211_ADDBA_EXT_BUF_SIZE_MASK GENMASK(7, 5)
#define IEEE80211_ADDBA_EXT_BUF_SIZE_SHIFT 10

struct ieee80211_addba_ext_ie {
 u8 data;
} __packed;

/**
 * struct ieee80211_s1g_bcn_compat_ie - S1G Beacon Compatibility element
 * @compat_info: Compatibility Information
 * @beacon_int: Beacon Interval
 * @tsf_completion: TSF Completion
 *
 * This structure represents the payload of the "S1G Beacon
 * Compatibility element" as described in IEEE Std 802.11-2020 section
 * 9.4.2.196.
 */

struct ieee80211_s1g_bcn_compat_ie {
 __le16 compat_info;
 __le16 beacon_int;
 __le32 tsf_completion;
} __packed;

/**
 * struct ieee80211_s1g_oper_ie - S1G Operation element
 * @ch_width: S1G Operation Information Channel Width
 * @oper_class: S1G Operation Information Operating Class
 * @primary_ch: S1G Operation Information Primary Channel Number
 * @oper_ch: S1G Operation Information  Channel Center Frequency
 * @basic_mcs_nss: Basic S1G-MCS and NSS Set
 *
 * This structure represents the payload of the "S1G Operation
 * element" as described in IEEE Std 802.11-2020 section 9.4.2.212.
 */

struct ieee80211_s1g_oper_ie {
 u8 ch_width;
 u8 oper_class;
 u8 primary_ch;
 u8 oper_ch;
 __le16 basic_mcs_nss;
} __packed;

/**
 * struct ieee80211_aid_response_ie - AID Response element
 * @aid: AID/Group AID
 * @switch_count: AID Switch Count
 * @response_int: AID Response Interval
 *
 * This structure represents the payload of the "AID Response element"
 * as described in IEEE Std 802.11-2020 section 9.4.2.194.
 */

struct ieee80211_aid_response_ie {
 __le16 aid;
 u8 switch_count;
 __le16 response_int;
} __packed;

struct ieee80211_s1g_cap {
 u8 capab_info[10];
 u8 supp_mcs_nss[5];
} __packed;

struct ieee80211_ext {
 __le16 frame_control;
 __le16 duration;
 union {
  struct {
   u8 sa[ETH_ALEN];
   __le32 timestamp;
   u8 change_seq;
   u8 variable[];
  } __packed s1g_beacon;
 } u;
} __packed __aligned(2);

/**
 * ieee80211_s1g_optional_len - determine length of optional S1G beacon fields
 * @fc: frame control bytes in little-endian byteorder
 * Return: total length in bytes of the optional fixed-length fields
 *
 * S1G beacons may contain up to three optional fixed-length fields that
 * precede the variable-length elements. Whether these fields are present
 * is indicated by flags in the frame control field.
 *
 * From IEEE 802.11-2024 section 9.3.4.3:
 *  - Next TBTT field may be 0 or 3 bytes
 *  - Short SSID field may be 0 or 4 bytes
 *  - Access Network Options (ANO) field may be 0 or 1 byte
 */

static inline size_t
ieee80211_s1g_optional_len(__le16 fc)
{
 size_t len = 0;

 if (ieee80211_s1g_has_next_tbtt(fc))
  len += 3;

 if (ieee80211_s1g_has_cssid(fc))
  len += 4;

 if (ieee80211_s1g_has_ano(fc))
  len += 1;

 return len;
}

#define IEEE80211_TWT_CONTROL_NDP   BIT(0)
#define IEEE80211_TWT_CONTROL_RESP_MODE   BIT(1)
#define IEEE80211_TWT_CONTROL_NEG_TYPE_BROADCAST BIT(3)
#define IEEE80211_TWT_CONTROL_RX_DISABLED  BIT(4)
#define IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT  BIT(5)

#define IEEE80211_TWT_REQTYPE_REQUEST   BIT(0)
#define IEEE80211_TWT_REQTYPE_SETUP_CMD   GENMASK(3, 1)
#define IEEE80211_TWT_REQTYPE_TRIGGER   BIT(4)
#define IEEE80211_TWT_REQTYPE_IMPLICIT   BIT(5)
#define IEEE80211_TWT_REQTYPE_FLOWTYPE   BIT(6)
#define IEEE80211_TWT_REQTYPE_FLOWID   GENMASK(9, 7)
#define IEEE80211_TWT_REQTYPE_WAKE_INT_EXP  GENMASK(14, 10)
#define IEEE80211_TWT_REQTYPE_PROTECTION  BIT(15)

enum ieee80211_twt_setup_cmd {
 TWT_SETUP_CMD_REQUEST,
 TWT_SETUP_CMD_SUGGEST,
 TWT_SETUP_CMD_DEMAND,
 TWT_SETUP_CMD_GROUPING,
 TWT_SETUP_CMD_ACCEPT,
 TWT_SETUP_CMD_ALTERNATE,
 TWT_SETUP_CMD_DICTATE,
 TWT_SETUP_CMD_REJECT,
};

struct ieee80211_twt_params {
 __le16 req_type;
 __le64 twt;
 u8 min_twt_dur;
 __le16 mantissa;
 u8 channel;
} __packed;

struct ieee80211_twt_setup {
 u8 dialog_token;
 u8 element_id;
 u8 length;
 u8 control;
 u8 params[];
} __packed;

#define IEEE80211_TTLM_MAX_CNT    2
#define IEEE80211_TTLM_CONTROL_DIRECTION  0x03
#define IEEE80211_TTLM_CONTROL_DEF_LINK_MAP  0x04
#define IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT 0x08
#define IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT 0x10
#define IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE  0x20

#define IEEE80211_TTLM_DIRECTION_DOWN  0
#define IEEE80211_TTLM_DIRECTION_UP  1
#define IEEE80211_TTLM_DIRECTION_BOTH  2

/**
 * struct ieee80211_ttlm_elem - TID-To-Link Mapping element
 *
 * Defined in section 9.4.2.314 in P802.11be_D4
 *
 * @control: the first part of control field
 * @optional: the second part of control field
 */

struct ieee80211_ttlm_elem {
 u8 control;
 u8 optional[];
} __packed;

/**
 * struct ieee80211_bss_load_elem - BSS Load elemen
 *
 * Defined in section 9.4.2.26 in IEEE 802.11-REVme D4.1
 *
 * @sta_count: total number of STAs currently associated with the AP.
 * @channel_util: Percentage of time that the access point sensed the channel
 * was busy. This value is in range [0, 255], the highest value means
 * 100% busy.
 * @avail_admission_capa: remaining amount of medium time used for admission
 * control.
 */

struct ieee80211_bss_load_elem {
 __le16 sta_count;
 u8 channel_util;
 __le16 avail_admission_capa;
} __packed;

struct ieee80211_mgmt {
 __le16 frame_control;
 __le16 duration;
 u8 da[ETH_ALEN];
 u8 sa[ETH_ALEN];
 u8 bssid[ETH_ALEN];
 __le16 seq_ctrl;
 union {
  struct {
   __le16 auth_alg;
   __le16 auth_transaction;
   __le16 status_code;
   /* possibly followed by Challenge text */
   u8 variable[];
  } __packed auth;
  struct {
   __le16 reason_code;
  } __packed deauth;
  struct {
   __le16 capab_info;
   __le16 listen_interval;
   /* followed by SSID and Supported rates */
   u8 variable[];
  } __packed assoc_req;
  struct {
   __le16 capab_info;
   __le16 status_code;
   __le16 aid;
   /* followed by Supported rates */
   u8 variable[];
  } __packed assoc_resp, reassoc_resp;
  struct {
   __le16 capab_info;
   __le16 status_code;
   u8 variable[];
  } __packed s1g_assoc_resp, s1g_reassoc_resp;
  struct {
   __le16 capab_info;
   __le16 listen_interval;
   u8 current_ap[ETH_ALEN];
   /* followed by SSID and Supported rates */
   u8 variable[];
  } __packed reassoc_req;
  struct {
   __le16 reason_code;
  } __packed disassoc;
  struct {
   __le64 timestamp;
   __le16 beacon_int;
   __le16 capab_info;
   /* followed by some of SSID, Supported rates,
 * FH Params, DS Params, CF Params, IBSS Params, TIM */

   u8 variable[];
  } __packed beacon;
  struct {
   /* only variable items: SSID, Supported rates */
   DECLARE_FLEX_ARRAY(u8, variable);
  } __packed probe_req;
  struct {
   __le64 timestamp;
   __le16 beacon_int;
   __le16 capab_info;
   /* followed by some of SSID, Supported rates,
 * FH Params, DS Params, CF Params, IBSS Params */

   u8 variable[];
  } __packed probe_resp;
  struct {
   u8 category;
   union {
    struct {
     u8 action_code;
     u8 dialog_token;
     u8 status_code;
     u8 variable[];
    } __packed wme_action;
    struct{
     u8 action_code;
     u8 variable[];
    } __packed chan_switch;
    struct{
     u8 action_code;
     struct ieee80211_ext_chansw_ie data;
     u8 variable[];
    } __packed ext_chan_switch;
    struct{
     u8 action_code;
     u8 dialog_token;
     u8 element_id;
     u8 length;
     struct ieee80211_msrment_ie msr_elem;
    } __packed measurement;
    struct{
     u8 action_code;
     u8 dialog_token;
     __le16 capab;
     __le16 timeout;
     __le16 start_seq_num;
     /* followed by BA Extension */
     u8 variable[];
    } __packed addba_req;
    struct{
     u8 action_code;
     u8 dialog_token;
     __le16 status;
     __le16 capab;
     __le16 timeout;
     /* followed by BA Extension */
     u8 variable[];
    } __packed addba_resp;
    struct{
     u8 action_code;
     __le16 params;
     __le16 reason_code;
    } __packed delba;
    struct {
     u8 action_code;
     u8 variable[];
    } __packed self_prot;
    struct{
     u8 action_code;
     u8 variable[];
    } __packed mesh_action;
    struct {
     u8 action;
     u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];
    } __packed sa_query;
    struct {
     u8 action;
     u8 smps_control;
    } __packed ht_smps;
    struct {
     u8 action_code;
     u8 chanwidth;
    } __packed ht_notify_cw;
    struct {
     u8 action_code;
     u8 dialog_token;
     __le16 capability;
     u8 variable[];
    } __packed tdls_discover_resp;
    struct {
     u8 action_code;
     u8 operating_mode;
    } __packed vht_opmode_notif;
    struct {
     u8 action_code;
     u8 membership[WLAN_MEMBERSHIP_LEN];
     u8 position[WLAN_USER_POSITION_LEN];
    } __packed vht_group_notif;
    struct {
     u8 action_code;
     u8 dialog_token;
     u8 tpc_elem_id;
     u8 tpc_elem_length;
     struct ieee80211_tpc_report_ie tpc;
    } __packed tpc_report;
    struct {
     u8 action_code;
     u8 dialog_token;
     u8 follow_up;
     u8 tod[6];
     u8 toa[6];
     __le16 tod_error;
     __le16 toa_error;
     u8 variable[];
    } __packed ftm;
    struct {
     u8 action_code;
     u8 variable[];
    } __packed s1g;
    struct {
     u8 action_code;
     u8 dialog_token;
     u8 follow_up;
     u32 tod;
     u32 toa;
     u8 max_tod_error;
     u8 max_toa_error;
    } __packed wnm_timing_msr;
    struct {
     u8 action_code;
     u8 dialog_token;
     u8 variable[];
    } __packed ttlm_req;
    struct {
     u8 action_code;
     u8 dialog_token;
     __le16 status_code;
     u8 variable[];
    } __packed ttlm_res;
    struct {
     u8 action_code;
    } __packed ttlm_tear_down;
    struct {
     u8 action_code;
     u8 dialog_token;
     u8 variable[];
    } __packed ml_reconf_req;
    struct {
     u8 action_code;
     u8 dialog_token;
     u8 count;
     u8 variable[];
    } __packed ml_reconf_resp;
    struct {
     u8 action_code;
     u8 variable[];
    } __packed epcs;
   } u;
  } __packed action;
  DECLARE_FLEX_ARRAY(u8, body); /* Generic frame body */
 } u;
} __packed __aligned(2);

/* Supported rates membership selectors */
#define BSS_MEMBERSHIP_SELECTOR_HT_PHY 127
#define BSS_MEMBERSHIP_SELECTOR_VHT_PHY 126
#define BSS_MEMBERSHIP_SELECTOR_GLK 125
#define BSS_MEMBERSHIP_SELECTOR_EPD 124
#define BSS_MEMBERSHIP_SELECTOR_SAE_H2E 123
#define BSS_MEMBERSHIP_SELECTOR_HE_PHY 122
#define BSS_MEMBERSHIP_SELECTOR_EHT_PHY 121

#define BSS_MEMBERSHIP_SELECTOR_MIN BSS_MEMBERSHIP_SELECTOR_EHT_PHY

/* mgmt header + 1 byte category code */
#define IEEE80211_MIN_ACTION_SIZE offsetof(struct ieee80211_mgmt, u.action.u)


/* Management MIC information element (IEEE 802.11w) */
struct ieee80211_mmie {
 u8 element_id;
 u8 length;
 __le16 key_id;
 u8 sequence_number[6];
 u8 mic[8];
} __packed;

/* Management MIC information element (IEEE 802.11w) for GMAC and CMAC-256 */
struct ieee80211_mmie_16 {
 u8 element_id;
 u8 length;
 __le16 key_id;
 u8 sequence_number[6];
 u8 mic[16];
} __packed;

struct ieee80211_vendor_ie {
 u8 element_id;
 u8 len;
 u8 oui[3];
 u8 oui_type;
} __packed;

struct ieee80211_wmm_ac_param {
 u8 aci_aifsn; /* AIFSN, ACM, ACI */
 u8 cw; /* ECWmin, ECWmax (CW = 2^ECW - 1) */
 __le16 txop_limit;
} __packed;

struct ieee80211_wmm_param_ie {
 u8 element_id; /* Element ID: 221 (0xdd); */
 u8 len; /* Length: 24 */
 /* required fields for WMM version 1 */
 u8 oui[3]; /* 00:50:f2 */
 u8 oui_type; /* 2 */
 u8 oui_subtype; /* 1 */
 u8 version; /* 1 for WMM version 1.0 */
 u8 qos_info; /* AP/STA specific QoS info */
 u8 reserved; /* 0 */
 /* AC_BE, AC_BK, AC_VI, AC_VO */
 struct ieee80211_wmm_ac_param ac[4];
} __packed;

/* Control frames */
struct ieee80211_rts {
 __le16 frame_control;
 __le16 duration;
 u8 ra[ETH_ALEN];
 u8 ta[ETH_ALEN];
} __packed __aligned(2);

struct ieee80211_cts {
 __le16 frame_control;
 __le16 duration;
 u8 ra[ETH_ALEN];
} __packed __aligned(2);

struct ieee80211_pspoll {
 __le16 frame_control;
 __le16 aid;
 u8 bssid[ETH_ALEN];
 u8 ta[ETH_ALEN];
} __packed __aligned(2);

/* TDLS */

/* Channel switch timing */
struct ieee80211_ch_switch_timing {
 __le16 switch_time;
 __le16 switch_timeout;
} __packed;

/* Link-id information element */
struct ieee80211_tdls_lnkie {
 u8 ie_type; /* Link Identifier IE */
 u8 ie_len;
 u8 bssid[ETH_ALEN];
 u8 init_sta[ETH_ALEN];
 u8 resp_sta[ETH_ALEN];
} __packed;

struct ieee80211_tdls_data {
 u8 da[ETH_ALEN];
 u8 sa[ETH_ALEN];
 __be16 ether_type;
 u8 payload_type;
 u8 category;
 u8 action_code;
 union {
  struct {
   u8 dialog_token;
   __le16 capability;
   u8 variable[];
  } __packed setup_req;
  struct {
   __le16 status_code;
   u8 dialog_token;
   __le16 capability;
   u8 variable[];
  } __packed setup_resp;
  struct {
   __le16 status_code;
   u8 dialog_token;
   u8 variable[];
  } __packed setup_cfm;
  struct {
   __le16 reason_code;
   u8 variable[];
  } __packed teardown;
  struct {
   u8 dialog_token;
   u8 variable[];
  } __packed discover_req;
  struct {
   u8 target_channel;
   u8 oper_class;
   u8 variable[];
  } __packed chan_switch_req;
  struct {
   __le16 status_code;
   u8 variable[];
  } __packed chan_switch_resp;
 } u;
} __packed;

/*
 * Peer-to-Peer IE attribute related definitions.
 */

/*
 * enum ieee80211_p2p_attr_id - identifies type of peer-to-peer attribute.
 */

enum ieee80211_p2p_attr_id {
 IEEE80211_P2P_ATTR_STATUS = 0,
 IEEE80211_P2P_ATTR_MINOR_REASON,
 IEEE80211_P2P_ATTR_CAPABILITY,
 IEEE80211_P2P_ATTR_DEVICE_ID,
 IEEE80211_P2P_ATTR_GO_INTENT,
 IEEE80211_P2P_ATTR_GO_CONFIG_TIMEOUT,
 IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
 IEEE80211_P2P_ATTR_GROUP_BSSID,
 IEEE80211_P2P_ATTR_EXT_LISTEN_TIMING,
 IEEE80211_P2P_ATTR_INTENDED_IFACE_ADDR,
 IEEE80211_P2P_ATTR_MANAGABILITY,
 IEEE80211_P2P_ATTR_CHANNEL_LIST,
 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
 IEEE80211_P2P_ATTR_DEVICE_INFO,
 IEEE80211_P2P_ATTR_GROUP_INFO,
 IEEE80211_P2P_ATTR_GROUP_ID,
 IEEE80211_P2P_ATTR_INTERFACE,
 IEEE80211_P2P_ATTR_OPER_CHANNEL,
 IEEE80211_P2P_ATTR_INVITE_FLAGS,
 /* 19 - 220: Reserved */
 IEEE80211_P2P_ATTR_VENDOR_SPECIFIC = 221,

 IEEE80211_P2P_ATTR_MAX
};

/* Notice of Absence attribute - described in P2P spec 4.1.14 */
/* Typical max value used here */
#define IEEE80211_P2P_NOA_DESC_MAX 4

struct ieee80211_p2p_noa_desc {
 u8 count;
 __le32 duration;
 __le32 interval;
 __le32 start_time;
} __packed;

struct ieee80211_p2p_noa_attr {
 u8 index;
 u8 oppps_ctwindow;
 struct ieee80211_p2p_noa_desc desc[IEEE80211_P2P_NOA_DESC_MAX];
} __packed;

#define IEEE80211_P2P_OPPPS_ENABLE_BIT  BIT(7)
#define IEEE80211_P2P_OPPPS_CTWINDOW_MASK 0x7F

/**
 * struct ieee80211_bar - Block Ack Request frame format
 * @frame_control: Frame Control
 * @duration: Duration
 * @ra: RA
 * @ta: TA
 * @control: BAR Control
 * @start_seq_num: Starting Sequence Number (see Figure 9-37)
 *
 * This structure represents the "BlockAckReq frame format"
 * as described in IEEE Std 802.11-2020 section 9.3.1.7.
*/

struct ieee80211_bar {
 __le16 frame_control;
 __le16 duration;
 __u8 ra[ETH_ALEN];
 __u8 ta[ETH_ALEN];
 __le16 control;
 __le16 start_seq_num;
} __packed;

/* 802.11 BAR control masks */
#define IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL 0x0000
#define IEEE80211_BAR_CTRL_MULTI_TID  0x0002
#define IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA 0x0004
#define IEEE80211_BAR_CTRL_TID_INFO_MASK 0xf000
#define IEEE80211_BAR_CTRL_TID_INFO_SHIFT 12

#define IEEE80211_HT_MCS_MASK_LEN  10

/**
 * struct ieee80211_mcs_info - Supported MCS Set field
 * @rx_mask: RX mask
 * @rx_highest: highest supported RX rate. If set represents
 * the highest supported RX data rate in units of 1 Mbps.
 * If this field is 0 this value should not be used to
 * consider the highest RX data rate supported.
 * @tx_params: TX parameters
 * @reserved: Reserved bits
 *
 * This structure represents the "Supported MCS Set field" as
 * described in IEEE Std 802.11-2020 section 9.4.2.55.4.
 */

struct ieee80211_mcs_info {
 u8 rx_mask[IEEE80211_HT_MCS_MASK_LEN];
 __le16 rx_highest;
 u8 tx_params;
 u8 reserved[3];
} __packed;

/* 802.11n HT capability MSC set */
#define IEEE80211_HT_MCS_RX_HIGHEST_MASK 0x3ff
#define IEEE80211_HT_MCS_TX_DEFINED  0x01
#define IEEE80211_HT_MCS_TX_RX_DIFF  0x02
/* value 0 == 1 stream etc */
#define IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK 0x0C
#define IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT 2
#define  IEEE80211_HT_MCS_TX_MAX_STREAMS 4
#define IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION 0x10

#define IEEE80211_HT_MCS_CHAINS(mcs) ((mcs) == 32 ? 1 : (1 + ((mcs) >> 3)))

/*
 * 802.11n D5.0 20.3.5 / 20.6 says:
 * - indices 0 to 7 and 32 are single spatial stream
 * - 8 to 31 are multiple spatial streams using equal modulation
 *   [8..15 for two streams, 16..23 for three and 24..31 for four]
 * - remainder are multiple spatial streams using unequal modulation
 */

#define IEEE80211_HT_MCS_UNEQUAL_MODULATION_START 33
#define IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE \
 (IEEE80211_HT_MCS_UNEQUAL_MODULATION_START / 8)

/**
 * struct ieee80211_ht_cap - HT capabilities element
 * @cap_info: HT Capability Information
 * @ampdu_params_info: A-MPDU Parameters
 * @mcs: Supported MCS Set
 * @extended_ht_cap_info: HT Extended Capabilities
 * @tx_BF_cap_info: Transmit Beamforming Capabilities
 * @antenna_selection_info: ASEL Capability
 *
 * This structure represents the payload of the "HT Capabilities
 * element" as described in IEEE Std 802.11-2020 section 9.4.2.55.
 */

struct ieee80211_ht_cap {
 __le16 cap_info;
 u8 ampdu_params_info;

 /* 16 bytes MCS information */
 struct ieee80211_mcs_info mcs;

 __le16 extended_ht_cap_info;
 __le32 tx_BF_cap_info;
 u8 antenna_selection_info;
} __packed;

/* 802.11n HT capabilities masks (for cap_info) */
#define IEEE80211_HT_CAP_LDPC_CODING  0x0001
#define IEEE80211_HT_CAP_SUP_WIDTH_20_40 0x0002
#define IEEE80211_HT_CAP_SM_PS   0x000C
#define  IEEE80211_HT_CAP_SM_PS_SHIFT 2
#define IEEE80211_HT_CAP_GRN_FLD  0x0010
#define IEEE80211_HT_CAP_SGI_20   0x0020
#define IEEE80211_HT_CAP_SGI_40   0x0040
#define IEEE80211_HT_CAP_TX_STBC  0x0080
#define IEEE80211_HT_CAP_RX_STBC  0x0300
#define  IEEE80211_HT_CAP_RX_STBC_SHIFT 8
#define IEEE80211_HT_CAP_DELAY_BA  0x0400
#define IEEE80211_HT_CAP_MAX_AMSDU  0x0800
#define IEEE80211_HT_CAP_DSSSCCK40  0x1000
#define IEEE80211_HT_CAP_RESERVED  0x2000
#define IEEE80211_HT_CAP_40MHZ_INTOLERANT 0x4000
#define IEEE80211_HT_CAP_LSIG_TXOP_PROT  0x8000

/* 802.11n HT extended capabilities masks (for extended_ht_cap_info) */
#define IEEE80211_HT_EXT_CAP_PCO  0x0001
#define IEEE80211_HT_EXT_CAP_PCO_TIME  0x0006
#define  IEEE80211_HT_EXT_CAP_PCO_TIME_SHIFT 1
#define IEEE80211_HT_EXT_CAP_MCS_FB  0x0300
#define  IEEE80211_HT_EXT_CAP_MCS_FB_SHIFT 8
#define IEEE80211_HT_EXT_CAP_HTC_SUP  0x0400
#define IEEE80211_HT_EXT_CAP_RD_RESPONDER 0x0800

/* 802.11n HT capability AMPDU settings (for ampdu_params_info) */
#define IEEE80211_HT_AMPDU_PARM_FACTOR  0x03
#define IEEE80211_HT_AMPDU_PARM_DENSITY  0x1C
#define  IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT 2

/*
 * Maximum length of AMPDU that the STA can receive in high-throughput (HT).
 * Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
 */

enum ieee80211_max_ampdu_length_exp {
 IEEE80211_HT_MAX_AMPDU_8K = 0,
 IEEE80211_HT_MAX_AMPDU_16K = 1,
 IEEE80211_HT_MAX_AMPDU_32K = 2,
 IEEE80211_HT_MAX_AMPDU_64K = 3
};

/*
 * Maximum length of AMPDU that the STA can receive in VHT.
 * Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
 */

enum ieee80211_vht_max_ampdu_length_exp {
 IEEE80211_VHT_MAX_AMPDU_8K = 0,
 IEEE80211_VHT_MAX_AMPDU_16K = 1,
 IEEE80211_VHT_MAX_AMPDU_32K = 2,
 IEEE80211_VHT_MAX_AMPDU_64K = 3,
 IEEE80211_VHT_MAX_AMPDU_128K = 4,
 IEEE80211_VHT_MAX_AMPDU_256K = 5,
 IEEE80211_VHT_MAX_AMPDU_512K = 6,
 IEEE80211_VHT_MAX_AMPDU_1024K = 7
};

#define IEEE80211_HT_MAX_AMPDU_FACTOR 13

/* Minimum MPDU start spacing */
enum ieee80211_min_mpdu_spacing {
 IEEE80211_HT_MPDU_DENSITY_NONE = 0, /* No restriction */
 IEEE80211_HT_MPDU_DENSITY_0_25 = 1, /* 1/4 usec */
 IEEE80211_HT_MPDU_DENSITY_0_5 = 2, /* 1/2 usec */
 IEEE80211_HT_MPDU_DENSITY_1 = 3, /* 1 usec */
 IEEE80211_HT_MPDU_DENSITY_2 = 4, /* 2 usec */
 IEEE80211_HT_MPDU_DENSITY_4 = 5, /* 4 usec */
 IEEE80211_HT_MPDU_DENSITY_8 = 6, /* 8 usec */
 IEEE80211_HT_MPDU_DENSITY_16 = 7 /* 16 usec */
};

/**
 * struct ieee80211_ht_operation - HT operation IE
 * @primary_chan: Primary Channel
 * @ht_param: HT Operation Information parameters
 * @operation_mode: HT Operation Information operation mode
 * @stbc_param: HT Operation Information STBC params
 * @basic_set: Basic HT-MCS Set
 *
 * This structure represents the payload of the "HT Operation
 * element" as described in IEEE Std 802.11-2020 section 9.4.2.56.
 */

struct ieee80211_ht_operation {
 u8 primary_chan;
 u8 ht_param;
 __le16 operation_mode;
 __le16 stbc_param;
 u8 basic_set[16];
} __packed;

/* for ht_param */
#define IEEE80211_HT_PARAM_CHA_SEC_OFFSET  0x03
#define  IEEE80211_HT_PARAM_CHA_SEC_NONE  0x00
#define  IEEE80211_HT_PARAM_CHA_SEC_ABOVE 0x01
#define  IEEE80211_HT_PARAM_CHA_SEC_BELOW 0x03
#define IEEE80211_HT_PARAM_CHAN_WIDTH_ANY  0x04
#define IEEE80211_HT_PARAM_RIFS_MODE   0x08

/* for operation_mode */
#define IEEE80211_HT_OP_MODE_PROTECTION   0x0003
#define  IEEE80211_HT_OP_MODE_PROTECTION_NONE  0
#define  IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER 1
#define  IEEE80211_HT_OP_MODE_PROTECTION_20MHZ  2
#define  IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED 3
#define IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT  0x0004
#define IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT  0x0010
#define IEEE80211_HT_OP_MODE_CCFS2_SHIFT  5
#define IEEE80211_HT_OP_MODE_CCFS2_MASK   0x1fe0

/* for stbc_param */
#define IEEE80211_HT_STBC_PARAM_DUAL_BEACON  0x0040
#define IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT  0x0080
#define IEEE80211_HT_STBC_PARAM_STBC_BEACON  0x0100
#define IEEE80211_HT_STBC_PARAM_LSIG_TXOP_FULLPROT 0x0200
#define IEEE80211_HT_STBC_PARAM_PCO_ACTIVE  0x0400
#define IEEE80211_HT_STBC_PARAM_PCO_PHASE  0x0800


/* block-ack parameters */
#define IEEE80211_ADDBA_PARAM_AMSDU_MASK 0x0001
#define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
#define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
#define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFC0
#define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
#define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800

/*
 * A-MPDU buffer sizes
 * According to HT size varies from 8 to 64 frames
 * HE adds the ability to have up to 256 frames.
 * EHT adds the ability to have up to 1K frames.
 */

#define IEEE80211_MIN_AMPDU_BUF  0x8
#define IEEE80211_MAX_AMPDU_BUF_HT 0x40
#define IEEE80211_MAX_AMPDU_BUF_HE 0x100
#define IEEE80211_MAX_AMPDU_BUF_EHT 0x400


/* Spatial Multiplexing Power Save Modes (for capability) */
#define WLAN_HT_CAP_SM_PS_STATIC 0
#define WLAN_HT_CAP_SM_PS_DYNAMIC 1
#define WLAN_HT_CAP_SM_PS_INVALID 2
#define WLAN_HT_CAP_SM_PS_DISABLED 3

/* for SM power control field lower two bits */
#define WLAN_HT_SMPS_CONTROL_DISABLED 0
#define WLAN_HT_SMPS_CONTROL_STATIC 1
#define WLAN_HT_SMPS_CONTROL_DYNAMIC 3

/**
 * struct ieee80211_vht_mcs_info - VHT MCS information
 * @rx_mcs_map: RX MCS map 2 bits for each stream, total 8 streams
 * @rx_highest: Indicates highest long GI VHT PPDU data rate
 * STA can receive. Rate expressed in units of 1 Mbps.
 * If this field is 0 this value should not be used to
 * consider the highest RX data rate supported.
 * The top 3 bits of this field indicate the Maximum NSTS,total
 * (a beamformee capability.)
 * @tx_mcs_map: TX MCS map 2 bits for each stream, total 8 streams
 * @tx_highest: Indicates highest long GI VHT PPDU data rate
 * STA can transmit. Rate expressed in units of 1 Mbps.
 * If this field is 0 this value should not be used to
 * consider the highest TX data rate supported.
 * The top 2 bits of this field are reserved, the
 * 3rd bit from the top indiciates VHT Extended NSS BW
 * Capability.
 */

struct ieee80211_vht_mcs_info {
 __le16 rx_mcs_map;
 __le16 rx_highest;
 __le16 tx_mcs_map;
 __le16 tx_highest;
} __packed;

/* for rx_highest */
#define IEEE80211_VHT_MAX_NSTS_TOTAL_SHIFT 13
#define IEEE80211_VHT_MAX_NSTS_TOTAL_MASK (7 << IEEE80211_VHT_MAX_NSTS_TOTAL_SHIFT)

/* for tx_highest */
#define IEEE80211_VHT_EXT_NSS_BW_CAPABLE (1 << 13)

/**
 * enum ieee80211_vht_mcs_support - VHT MCS support definitions
 * @IEEE80211_VHT_MCS_SUPPORT_0_7: MCSes 0-7 are supported for the
 * number of streams
 * @IEEE80211_VHT_MCS_SUPPORT_0_8: MCSes 0-8 are supported
 * @IEEE80211_VHT_MCS_SUPPORT_0_9: MCSes 0-9 are supported
 * @IEEE80211_VHT_MCS_NOT_SUPPORTED: This number of streams isn't supported
 *
 * These definitions are used in each 2-bit subfield of the @rx_mcs_map
 * and @tx_mcs_map fields of &struct ieee80211_vht_mcs_info, which are
 * both split into 8 subfields by number of streams. These values indicate
 * which MCSes are supported for the number of streams the value appears
 * for.
 */

enum ieee80211_vht_mcs_support {
 IEEE80211_VHT_MCS_SUPPORT_0_7 = 0,
 IEEE80211_VHT_MCS_SUPPORT_0_8 = 1,
 IEEE80211_VHT_MCS_SUPPORT_0_9 = 2,
 IEEE80211_VHT_MCS_NOT_SUPPORTED = 3,
};

/**
 * struct ieee80211_vht_cap - VHT capabilities
 *
 * This structure is the "VHT capabilities element" as
 * described in 802.11ac D3.0 8.4.2.160
 * @vht_cap_info: VHT capability info
 * @supp_mcs: VHT MCS supported rates
 */

struct ieee80211_vht_cap {
 __le32 vht_cap_info;
 struct ieee80211_vht_mcs_info supp_mcs;
} __packed;

/**
 * enum ieee80211_vht_chanwidth - VHT channel width
 * @IEEE80211_VHT_CHANWIDTH_USE_HT: use the HT operation IE to
 * determine the channel width (20 or 40 MHz)
 * @IEEE80211_VHT_CHANWIDTH_80MHZ: 80 MHz bandwidth
 * @IEEE80211_VHT_CHANWIDTH_160MHZ: 160 MHz bandwidth
 * @IEEE80211_VHT_CHANWIDTH_80P80MHZ: 80+80 MHz bandwidth
 */

enum ieee80211_vht_chanwidth {
 IEEE80211_VHT_CHANWIDTH_USE_HT  = 0,
 IEEE80211_VHT_CHANWIDTH_80MHZ  = 1,
 IEEE80211_VHT_CHANWIDTH_160MHZ  = 2,
 IEEE80211_VHT_CHANWIDTH_80P80MHZ = 3,
};

/**
 * struct ieee80211_vht_operation - VHT operation IE
 *
 * This structure is the "VHT operation element" as
 * described in 802.11ac D3.0 8.4.2.161
 * @chan_width: Operating channel width
 * @center_freq_seg0_idx: center freq segment 0 index
 * @center_freq_seg1_idx: center freq segment 1 index
 * @basic_mcs_set: VHT Basic MCS rate set
 */

struct ieee80211_vht_operation {
 u8 chan_width;
 u8 center_freq_seg0_idx;
 u8 center_freq_seg1_idx;
 __le16 basic_mcs_set;
} __packed;

/**
 * struct ieee80211_he_cap_elem - HE capabilities element
 * @mac_cap_info: HE MAC Capabilities Information
 * @phy_cap_info: HE PHY Capabilities Information
 *
 * This structure represents the fixed fields of the payload of the
 * "HE capabilities element" as described in IEEE Std 802.11ax-2021
 * sections 9.4.2.248.2 and 9.4.2.248.3.
 */

struct ieee80211_he_cap_elem {
 u8 mac_cap_info[6];
 u8 phy_cap_info[11];
} __packed;

#define IEEE80211_TX_RX_MCS_NSS_DESC_MAX_LEN 5

/**
 * enum ieee80211_he_mcs_support - HE MCS support definitions
--> --------------------

--> maximum size reached

--> --------------------

Messung V0.5
C=92 H=98 G=94

¤ Dauer der Verarbeitung: 0.21 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge