1 /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */
4 * Macros, types, and functions for handling 802.11 MAC headers
6 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
7 * --------------------------------------------------------------------
11 * --------------------------------------------------------------------
13 * Inquiries regarding the linux-wlan Open Source project can be
16 * AbsoluteValue Systems Inc.
18 * http://www.linux-wlan.com
20 * --------------------------------------------------------------------
22 * Portions of the development of this software were funded by
23 * Intersil Corporation as part of PRISM(R) chipset product development.
25 * --------------------------------------------------------------------
27 * This file declares the constants and types used in the interface
28 * between a wlan driver and the user mode utilities.
31 * - Constant values are always in HOST byte order. To assign
32 * values to multi-byte fields they _must_ be converted to
33 * ieee byte order. To retrieve multi-byte values from incoming
34 * frames, they must be converted to host order.
36 * All functions declared here are implemented in p80211.c
37 * --------------------------------------------------------------------
43 #include <linux/if_ether.h>
45 /*--- Sizes -----------------------------------------------*/
46 #define WLAN_CRC_LEN 4
47 #define WLAN_BSSID_LEN 6
48 #define WLAN_HDR_A3_LEN 24
49 #define WLAN_HDR_A4_LEN 30
50 #define WLAN_SSID_MAXLEN 32
51 #define WLAN_DATA_MAXLEN 2312
52 #define WLAN_WEP_IV_LEN 4
53 #define WLAN_WEP_ICV_LEN 4
55 /*--- Frame Control Field -------------------------------------*/
57 #define WLAN_FTYPE_MGMT 0x00
58 #define WLAN_FTYPE_CTL 0x01
59 #define WLAN_FTYPE_DATA 0x02
63 #define WLAN_FSTYPE_ASSOCREQ 0x00
64 #define WLAN_FSTYPE_ASSOCRESP 0x01
65 #define WLAN_FSTYPE_REASSOCREQ 0x02
66 #define WLAN_FSTYPE_REASSOCRESP 0x03
67 #define WLAN_FSTYPE_PROBEREQ 0x04
68 #define WLAN_FSTYPE_PROBERESP 0x05
69 #define WLAN_FSTYPE_BEACON 0x08
70 #define WLAN_FSTYPE_ATIM 0x09
71 #define WLAN_FSTYPE_DISASSOC 0x0a
72 #define WLAN_FSTYPE_AUTHEN 0x0b
73 #define WLAN_FSTYPE_DEAUTHEN 0x0c
76 #define WLAN_FSTYPE_BLOCKACKREQ 0x8
77 #define WLAN_FSTYPE_BLOCKACK 0x9
78 #define WLAN_FSTYPE_PSPOLL 0x0a
79 #define WLAN_FSTYPE_RTS 0x0b
80 #define WLAN_FSTYPE_CTS 0x0c
81 #define WLAN_FSTYPE_ACK 0x0d
82 #define WLAN_FSTYPE_CFEND 0x0e
83 #define WLAN_FSTYPE_CFENDCFACK 0x0f
86 #define WLAN_FSTYPE_DATAONLY 0x00
87 #define WLAN_FSTYPE_DATA_CFACK 0x01
88 #define WLAN_FSTYPE_DATA_CFPOLL 0x02
89 #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
90 #define WLAN_FSTYPE_NULL 0x04
91 #define WLAN_FSTYPE_CFACK 0x05
92 #define WLAN_FSTYPE_CFPOLL 0x06
93 #define WLAN_FSTYPE_CFACK_CFPOLL 0x07
95 /*--- FC Macros ----------------------------------------------*/
96 /* Macros to get/set the bitfields of the Frame Control Field */
97 /* GET_FC_??? - takes the host byte-order value of an FC */
98 /* and retrieves the value of one of the */
99 /* bitfields and moves that value so its lsb is */
101 /* SET_FC_??? - takes a host order value for one of the FC */
102 /* bitfields and moves it to the proper bit */
103 /* location for ORing into a host order FC. */
104 /* To send the FC produced from SET_FC_???, */
105 /* one must put the bytes in IEEE order. */
107 /* printf("the frame subtype is %x", */
108 /* GET_FC_FTYPE( ieee2host( rx.fc ))) */
110 /* tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) | */
111 /* SET_FC_FSTYPE(WLAN_FSTYPE_RTS) ); */
112 /*------------------------------------------------------------*/
114 #define WLAN_GET_FC_FTYPE(n) ((((u16)(n)) & GENMASK(3, 2)) >> 2)
115 #define WLAN_GET_FC_FSTYPE(n) ((((u16)(n)) & GENMASK(7, 4)) >> 4)
116 #define WLAN_GET_FC_TODS(n) ((((u16)(n)) & (BIT(8))) >> 8)
117 #define WLAN_GET_FC_FROMDS(n) ((((u16)(n)) & (BIT(9))) >> 9)
118 #define WLAN_GET_FC_ISWEP(n) ((((u16)(n)) & (BIT(14))) >> 14)
120 #define WLAN_SET_FC_FTYPE(n) (((u16)(n)) << 2)
121 #define WLAN_SET_FC_FSTYPE(n) (((u16)(n)) << 4)
122 #define WLAN_SET_FC_TODS(n) (((u16)(n)) << 8)
123 #define WLAN_SET_FC_FROMDS(n) (((u16)(n)) << 9)
124 #define WLAN_SET_FC_ISWEP(n) (((u16)(n)) << 14)
126 #define DOT11_RATE5_ISBASIC_GET(r) (((u8)(r)) & BIT(7))
128 /* Generic 802.11 Header types */
131 __le16 frame_control;
133 u8 address1[ETH_ALEN];
134 u8 address2[ETH_ALEN];
135 u8 address3[ETH_ALEN];
136 u16 sequence_control;
137 u8 address4[ETH_ALEN];
140 /* Frame and header length macros */
142 static inline u16 wlan_ctl_framelen(u16 fstype)
145 case WLAN_FSTYPE_BLOCKACKREQ:
147 case WLAN_FSTYPE_BLOCKACK:
149 case WLAN_FSTYPE_PSPOLL:
150 case WLAN_FSTYPE_RTS:
151 case WLAN_FSTYPE_CFEND:
152 case WLAN_FSTYPE_CFENDCFACK:
154 case WLAN_FSTYPE_CTS:
155 case WLAN_FSTYPE_ACK:
162 #define WLAN_FCS_LEN 4
164 /* ftcl in HOST order */
165 static inline u16 p80211_headerlen(u16 fctl)
169 switch (WLAN_GET_FC_FTYPE(fctl)) {
170 case WLAN_FTYPE_MGMT:
171 hdrlen = WLAN_HDR_A3_LEN;
173 case WLAN_FTYPE_DATA:
174 hdrlen = WLAN_HDR_A3_LEN;
175 if (WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl))
179 hdrlen = wlan_ctl_framelen(WLAN_GET_FC_FSTYPE(fctl)) -
183 hdrlen = WLAN_HDR_A3_LEN;
189 #endif /* _P80211HDR_H */