1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
6 * Modifications for inclusion into the Linux staging tree are
7 * Copyright(c) 2010 Larry Finger. All rights reserved.
10 * WLAN FAE <wlanfae@realtek.com>
11 * Larry Finger <Larry.Finger@lwfinger.net>
13 ******************************************************************************/
17 #include <linux/compiler.h>
18 #include <linux/ieee80211.h>
20 #define WLAN_HDR_A3_LEN 24
21 #define WLAN_HDR_A3_QOS_LEN 26
23 enum WIFI_FRAME_TYPE
{
24 WIFI_QOS_DATA_TYPE
= (BIT(7) | BIT(3)), /*!< QoS Data */
27 #define SetToDs(pbuf) ({ \
28 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_TODS); \
31 #define GetToDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_TODS)) != 0)
33 #define ClearToDs(pbuf) ({ \
34 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_TODS)); \
37 #define SetFrDs(pbuf) ({ \
38 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_FROMDS); \
41 #define GetFrDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_FROMDS)) != 0)
43 #define ClearFrDs(pbuf) ({ \
44 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_FROMDS)); \
47 static inline unsigned char get_tofr_ds(unsigned char *pframe
)
49 return ((GetToDs(pframe
) << 1) | GetFrDs(pframe
));
52 #define SetMFrag(pbuf) ({ \
53 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS); \
56 #define GetMFrag(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) != 0)
58 #define ClearMFrag(pbuf) ({ \
59 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)); \
62 #define SetRetry(pbuf) ({ \
63 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_RETRY); \
66 #define GetRetry(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_RETRY)) != 0)
68 #define ClearRetry(pbuf) ({ \
69 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_RETRY)); \
72 #define SetPwrMgt(pbuf) ({ \
73 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PM); \
76 #define GetPwrMgt(pbuf) (((*(__le16 *)(pbuf)) & \
77 cpu_to_le16(IEEE80211_FCTL_PM)) != 0)
79 #define ClearPwrMgt(pbuf) ({ \
80 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_PM)); \
83 #define SetMData(pbuf) ({ \
84 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); \
87 #define GetMData(pbuf) (((*(__le16 *)(pbuf)) & \
88 cpu_to_le16(IEEE80211_FCTL_MOREDATA)) != 0)
90 #define ClearMData(pbuf) ({ \
91 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREDATA)); \
94 #define SetPrivacy(pbuf) ({ \
95 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); \
98 #define GetPrivacy(pbuf) (((*(__le16 *)(pbuf)) & \
99 cpu_to_le16(IEEE80211_FCTL_PROTECTED)) != 0)
101 #define GetOrder(pbuf) (((*(__le16 *)(pbuf)) & \
102 cpu_to_le16(IEEE80211_FCTL_ORDER)) != 0)
104 #define GetFrameType(pbuf) (le16_to_cpu(*(__le16 *)(pbuf)) & \
107 #define SetFrameType(pbuf, type) \
109 *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(3) | \
111 *(__le16 *)(pbuf) |= cpu_to_le16(type); \
114 #define GetFrameSubType(pbuf) (le16_to_cpu(*(__le16 *)(pbuf)) & \
115 (BIT(7) | BIT(6) | BIT(5) | BIT(4) | BIT(3) | \
118 #define SetFrameSubType(pbuf, type) \
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); \
125 #define GetSequence(pbuf) (le16_to_cpu(*(__le16 *)\
126 ((addr_t)(pbuf) + 22)) >> 4)
128 #define GetFragNum(pbuf) (le16_to_cpu(*(__le16 *)((addr_t)\
129 (pbuf) + 22)) & 0x0f)
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))); \
137 #define SetPriority(pbuf, tid) ({ \
138 *(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf); \
141 #define GetPriority(pbuf) ((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf)
143 #define SetAckpolicy(pbuf, ack) ({ \
144 *(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \
147 #define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
149 #define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
151 #define GetAddr1Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 4))
153 #define GetAddr2Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 10))
155 #define GetAddr3Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 16))
157 #define GetAddr4Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 24))
159 static inline unsigned char *get_hdr_bssid(unsigned char *pframe
)
162 unsigned int to_fr_ds
= (GetToDs(pframe
) << 1) | GetFrDs(pframe
);
165 case 0x00: /* ToDs=0, FromDs=0 */
166 sa
= GetAddr3Ptr(pframe
);
168 case 0x01: /* ToDs=0, FromDs=1 */
169 sa
= GetAddr2Ptr(pframe
);
171 case 0x02: /* ToDs=1, FromDs=0 */
172 sa
= GetAddr1Ptr(pframe
);
174 default: /* ToDs=1, FromDs=1 */
181 /* ---------------------------------------------------------------------------
182 * Below is the fixed elements...
183 * ---------------------------------------------------------------------------
185 #define _BEACON_ITERVAL_ 2
186 #define _CAPABILITY_ 2
187 #define _TIMESTAMP_ 8
189 /*-----------------------------------------------------------------------------
190 * Below is the definition for WMM
191 *------------------------------------------------------------------------------
193 #define _WMM_IE_Length_ 7 /* for WMM STA */
195 #endif /* _WIFI_H_ */