Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /******************************************************************************
0003  *
0004  * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
0005  *
0006  * Modifications for inclusion into the Linux staging tree are
0007  * Copyright(c) 2010 Larry Finger. All rights reserved.
0008  *
0009  * Contact information:
0010  * WLAN FAE <wlanfae@realtek.com>
0011  * Larry Finger <Larry.Finger@lwfinger.net>
0012  *
0013  ******************************************************************************/
0014 #ifndef _WIFI_H_
0015 #define _WIFI_H_
0016 
0017 #include <linux/compiler.h>
0018 #include <linux/ieee80211.h>
0019 
0020 #define WLAN_HDR_A3_LEN     24
0021 #define WLAN_HDR_A3_QOS_LEN 26
0022 
0023 enum WIFI_FRAME_TYPE {
0024     WIFI_QOS_DATA_TYPE  = (BIT(7) | BIT(3)),    /*!< QoS Data */
0025 };
0026 
0027 #define SetToDs(pbuf) ({ \
0028     *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_TODS); \
0029 })
0030 
0031 #define GetToDs(pbuf)   (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_TODS)) != 0)
0032 
0033 #define ClearToDs(pbuf) ({ \
0034     *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_TODS)); \
0035 })
0036 
0037 #define SetFrDs(pbuf) ({ \
0038     *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_FROMDS); \
0039 })
0040 
0041 #define GetFrDs(pbuf)   (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_FROMDS)) != 0)
0042 
0043 #define ClearFrDs(pbuf) ({ \
0044     *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_FROMDS)); \
0045 })
0046 
0047 static inline unsigned char get_tofr_ds(unsigned char *pframe)
0048 {
0049     return ((GetToDs(pframe) << 1) | GetFrDs(pframe));
0050 }
0051 
0052 #define SetMFrag(pbuf) ({ \
0053     *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS); \
0054 })
0055 
0056 #define GetMFrag(pbuf)  (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) != 0)
0057 
0058 #define ClearMFrag(pbuf) ({ \
0059     *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)); \
0060 })
0061 
0062 #define SetRetry(pbuf) ({ \
0063     *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_RETRY); \
0064 })
0065 
0066 #define GetRetry(pbuf)  (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_RETRY)) != 0)
0067 
0068 #define ClearRetry(pbuf) ({ \
0069     *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_RETRY)); \
0070 })
0071 
0072 #define SetPwrMgt(pbuf) ({ \
0073     *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PM); \
0074 })
0075 
0076 #define GetPwrMgt(pbuf) (((*(__le16 *)(pbuf)) & \
0077             cpu_to_le16(IEEE80211_FCTL_PM)) != 0)
0078 
0079 #define ClearPwrMgt(pbuf) ({ \
0080     *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_PM)); \
0081 })
0082 
0083 #define SetMData(pbuf) ({ \
0084     *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); \
0085 })
0086 
0087 #define GetMData(pbuf)  (((*(__le16 *)(pbuf)) & \
0088             cpu_to_le16(IEEE80211_FCTL_MOREDATA)) != 0)
0089 
0090 #define ClearMData(pbuf) ({ \
0091     *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREDATA)); \
0092 })
0093 
0094 #define SetPrivacy(pbuf) ({ \
0095     *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); \
0096 })
0097 
0098 #define GetPrivacy(pbuf)    (((*(__le16 *)(pbuf)) & \
0099                 cpu_to_le16(IEEE80211_FCTL_PROTECTED)) != 0)
0100 
0101 #define GetOrder(pbuf)  (((*(__le16 *)(pbuf)) & \
0102             cpu_to_le16(IEEE80211_FCTL_ORDER)) != 0)
0103 
0104 #define GetFrameType(pbuf)  (le16_to_cpu(*(__le16 *)(pbuf)) & \
0105                 (BIT(3) | BIT(2)))
0106 
0107 #define SetFrameType(pbuf, type)    \
0108     do {    \
0109         *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(3) | \
0110         BIT(2))); \
0111         *(__le16 *)(pbuf) |= cpu_to_le16(type); \
0112     } while (0)
0113 
0114 #define GetFrameSubType(pbuf)   (le16_to_cpu(*(__le16 *)(pbuf)) & \
0115                 (BIT(7) | BIT(6) | BIT(5) | BIT(4) | BIT(3) | \
0116                 BIT(2)))
0117 
0118 #define SetFrameSubType(pbuf, type) \
0119     do {    \
0120         *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) | \
0121         BIT(5) | BIT(4) | BIT(3) | BIT(2))); \
0122         *(__le16 *)(pbuf) |= cpu_to_le16(type); \
0123     } while (0)
0124 
0125 #define GetSequence(pbuf)   (le16_to_cpu(*(__le16 *)\
0126                 ((addr_t)(pbuf) + 22)) >> 4)
0127 
0128 #define GetFragNum(pbuf)    (le16_to_cpu(*(__le16 *)((addr_t)\
0129                 (pbuf) + 22)) & 0x0f)
0130 
0131 #define SetSeqNum(pbuf, num) ({ \
0132     *(__le16 *)((addr_t)(pbuf) + 22) = \
0133     cpu_to_le16((le16_to_cpu(*(__le16 *)((addr_t)(pbuf) + 22)) & \
0134     0x000f) | (0xfff0 & (num << 4))); \
0135 })
0136 
0137 #define SetPriority(pbuf, tid) ({ \
0138     *(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf); \
0139 })
0140 
0141 #define GetPriority(pbuf)   ((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf)
0142 
0143 #define SetAckpolicy(pbuf, ack) ({ \
0144     *(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \
0145 })
0146 
0147 #define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
0148 
0149 #define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
0150 
0151 #define GetAddr1Ptr(pbuf)   ((unsigned char *)((addr_t)(pbuf) + 4))
0152 
0153 #define GetAddr2Ptr(pbuf)   ((unsigned char *)((addr_t)(pbuf) + 10))
0154 
0155 #define GetAddr3Ptr(pbuf)   ((unsigned char *)((addr_t)(pbuf) + 16))
0156 
0157 #define GetAddr4Ptr(pbuf)   ((unsigned char *)((addr_t)(pbuf) + 24))
0158 
0159 static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
0160 {
0161     unsigned char   *sa;
0162     unsigned int    to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
0163 
0164     switch (to_fr_ds) {
0165     case 0x00:  /* ToDs=0, FromDs=0 */
0166         sa = GetAddr3Ptr(pframe);
0167         break;
0168     case 0x01:  /* ToDs=0, FromDs=1 */
0169         sa = GetAddr2Ptr(pframe);
0170         break;
0171     case 0x02:  /* ToDs=1, FromDs=0 */
0172         sa = GetAddr1Ptr(pframe);
0173         break;
0174     default:    /* ToDs=1, FromDs=1 */
0175         sa = NULL;
0176         break;
0177     }
0178     return sa;
0179 }
0180 
0181 /* ---------------------------------------------------------------------------
0182  *          Below is the fixed elements...
0183  * ---------------------------------------------------------------------------
0184  */
0185 #define _BEACON_ITERVAL_        2
0186 #define _CAPABILITY_            2
0187 #define _TIMESTAMP_             8
0188 
0189 /*-----------------------------------------------------------------------------
0190  *          Below is the definition for WMM
0191  *------------------------------------------------------------------------------
0192  */
0193 #define _WMM_IE_Length_             7  /* for WMM STA */
0194 
0195 #endif /* _WIFI_H_ */
0196