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

wifi.h (5447B)


      1/* SPDX-License-Identifier: GPL-2.0 */
      2/******************************************************************************
      3 *
      4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
      5 *
      6 * Modifications for inclusion into the Linux staging tree are
      7 * Copyright(c) 2010 Larry Finger. All rights reserved.
      8 *
      9 * Contact information:
     10 * WLAN FAE <wlanfae@realtek.com>
     11 * Larry Finger <Larry.Finger@lwfinger.net>
     12 *
     13 ******************************************************************************/
     14#ifndef _WIFI_H_
     15#define _WIFI_H_
     16
     17#include <linux/compiler.h>
     18#include <linux/ieee80211.h>
     19
     20#define WLAN_HDR_A3_LEN		24
     21#define WLAN_HDR_A3_QOS_LEN	26
     22
     23enum WIFI_FRAME_TYPE {
     24	WIFI_QOS_DATA_TYPE	= (BIT(7) | BIT(3)),	/*!< QoS Data */
     25};
     26
     27#define SetToDs(pbuf) ({ \
     28	*(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_TODS); \
     29})
     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
     37#define SetFrDs(pbuf) ({ \
     38	*(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_FROMDS); \
     39})
     40
     41#define GetFrDs(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_FROMDS)) != 0)
     42
     43#define ClearFrDs(pbuf)	({ \
     44	*(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_FROMDS)); \
     45})
     46
     47static inline unsigned char get_tofr_ds(unsigned char *pframe)
     48{
     49	return ((GetToDs(pframe) << 1) | GetFrDs(pframe));
     50}
     51
     52#define SetMFrag(pbuf) ({ \
     53	*(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS); \
     54})
     55
     56#define GetMFrag(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) != 0)
     57
     58#define ClearMFrag(pbuf) ({ \
     59	*(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)); \
     60})
     61
     62#define SetRetry(pbuf) ({ \
     63	*(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_RETRY); \
     64})
     65
     66#define GetRetry(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_RETRY)) != 0)
     67
     68#define ClearRetry(pbuf) ({ \
     69	*(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_RETRY)); \
     70})
     71
     72#define SetPwrMgt(pbuf) ({ \
     73	*(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PM); \
     74})
     75
     76#define GetPwrMgt(pbuf)	(((*(__le16 *)(pbuf)) & \
     77			cpu_to_le16(IEEE80211_FCTL_PM)) != 0)
     78
     79#define ClearPwrMgt(pbuf) ({ \
     80	*(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_PM)); \
     81})
     82
     83#define SetMData(pbuf) ({ \
     84	*(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); \
     85})
     86
     87#define GetMData(pbuf)	(((*(__le16 *)(pbuf)) & \
     88			cpu_to_le16(IEEE80211_FCTL_MOREDATA)) != 0)
     89
     90#define ClearMData(pbuf) ({ \
     91	*(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREDATA)); \
     92})
     93
     94#define SetPrivacy(pbuf) ({ \
     95	*(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); \
     96})
     97
     98#define GetPrivacy(pbuf)	(((*(__le16 *)(pbuf)) & \
     99				cpu_to_le16(IEEE80211_FCTL_PROTECTED)) != 0)
    100
    101#define GetOrder(pbuf)	(((*(__le16 *)(pbuf)) & \
    102			cpu_to_le16(IEEE80211_FCTL_ORDER)) != 0)
    103
    104#define GetFrameType(pbuf)	(le16_to_cpu(*(__le16 *)(pbuf)) & \
    105				(BIT(3) | BIT(2)))
    106
    107#define SetFrameType(pbuf, type)	\
    108	do {	\
    109		*(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(3) | \
    110		BIT(2))); \
    111		*(__le16 *)(pbuf) |= cpu_to_le16(type); \
    112	} while (0)
    113
    114#define GetFrameSubType(pbuf)	(le16_to_cpu(*(__le16 *)(pbuf)) & \
    115				(BIT(7) | BIT(6) | BIT(5) | BIT(4) | BIT(3) | \
    116				BIT(2)))
    117
    118#define SetFrameSubType(pbuf, type) \
    119	do {    \
    120		*(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) | \
    121		BIT(5) | BIT(4) | BIT(3) | BIT(2))); \
    122		*(__le16 *)(pbuf) |= cpu_to_le16(type); \
    123	} while (0)
    124
    125#define GetSequence(pbuf)	(le16_to_cpu(*(__le16 *)\
    126				((addr_t)(pbuf) + 22)) >> 4)
    127
    128#define GetFragNum(pbuf)	(le16_to_cpu(*(__le16 *)((addr_t)\
    129				(pbuf) + 22)) & 0x0f)
    130
    131#define SetSeqNum(pbuf, num) ({ \
    132	*(__le16 *)((addr_t)(pbuf) + 22) = \
    133	cpu_to_le16((le16_to_cpu(*(__le16 *)((addr_t)(pbuf) + 22)) & \
    134	0x000f) | (0xfff0 & (num << 4))); \
    135})
    136
    137#define SetPriority(pbuf, tid) ({ \
    138	*(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf); \
    139})
    140
    141#define GetPriority(pbuf)	((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf)
    142
    143#define SetAckpolicy(pbuf, ack) ({ \
    144	*(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \
    145})
    146
    147#define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
    148
    149#define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
    150
    151#define GetAddr1Ptr(pbuf)	((unsigned char *)((addr_t)(pbuf) + 4))
    152
    153#define GetAddr2Ptr(pbuf)	((unsigned char *)((addr_t)(pbuf) + 10))
    154
    155#define GetAddr3Ptr(pbuf)	((unsigned char *)((addr_t)(pbuf) + 16))
    156
    157#define GetAddr4Ptr(pbuf)	((unsigned char *)((addr_t)(pbuf) + 24))
    158
    159static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
    160{
    161	unsigned char	*sa;
    162	unsigned int	to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
    163
    164	switch (to_fr_ds) {
    165	case 0x00:	/* ToDs=0, FromDs=0 */
    166		sa = GetAddr3Ptr(pframe);
    167		break;
    168	case 0x01:	/* ToDs=0, FromDs=1 */
    169		sa = GetAddr2Ptr(pframe);
    170		break;
    171	case 0x02:	/* ToDs=1, FromDs=0 */
    172		sa = GetAddr1Ptr(pframe);
    173		break;
    174	default:	/* ToDs=1, FromDs=1 */
    175		sa = NULL;
    176		break;
    177	}
    178	return sa;
    179}
    180
    181/* ---------------------------------------------------------------------------
    182 *			Below is the fixed elements...
    183 * ---------------------------------------------------------------------------
    184 */
    185#define _BEACON_ITERVAL_		2
    186#define _CAPABILITY_			2
    187#define _TIMESTAMP_				8
    188
    189/*-----------------------------------------------------------------------------
    190 *			Below is the definition for WMM
    191 *------------------------------------------------------------------------------
    192 */
    193#define _WMM_IE_Length_				7  /* for WMM STA */
    194
    195#endif /* _WIFI_H_ */
    196