80211hdr.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. *
  20. * File: 80211hdr.h
  21. *
  22. * Purpose: 802.11 MAC headers related pre-defines and macros.
  23. *
  24. *
  25. * Author: Lyndon Chen
  26. *
  27. * Date: Apr 8, 2002
  28. *
  29. */
  30. #ifndef __80211HDR_H__
  31. #define __80211HDR_H__
  32. #include "ttype.h"
  33. /* bit type */
  34. #define BIT0 0x00000001
  35. #define BIT1 0x00000002
  36. #define BIT2 0x00000004
  37. #define BIT3 0x00000008
  38. #define BIT4 0x00000010
  39. #define BIT5 0x00000020
  40. #define BIT6 0x00000040
  41. #define BIT7 0x00000080
  42. #define BIT8 0x00000100
  43. #define BIT9 0x00000200
  44. #define BIT10 0x00000400
  45. #define BIT11 0x00000800
  46. #define BIT12 0x00001000
  47. #define BIT13 0x00002000
  48. #define BIT14 0x00004000
  49. #define BIT15 0x00008000
  50. #define BIT16 0x00010000
  51. #define BIT17 0x00020000
  52. #define BIT18 0x00040000
  53. #define BIT19 0x00080000
  54. #define BIT20 0x00100000
  55. #define BIT21 0x00200000
  56. #define BIT22 0x00400000
  57. #define BIT23 0x00800000
  58. #define BIT24 0x01000000
  59. #define BIT25 0x02000000
  60. #define BIT26 0x04000000
  61. #define BIT27 0x08000000
  62. #define BIT28 0x10000000
  63. #define BIT29 0x20000000
  64. #define BIT30 0x40000000
  65. #define BIT31 0x80000000
  66. /* 802.11 frame related, defined as 802.11 spec */
  67. #define WLAN_ADDR_LEN 6
  68. #define WLAN_CRC_LEN 4
  69. #define WLAN_CRC32_LEN 4
  70. #define WLAN_FCS_LEN 4
  71. #define WLAN_BSSID_LEN 6
  72. #define WLAN_BSS_TS_LEN 8
  73. #define WLAN_HDR_ADDR2_LEN 16
  74. #define WLAN_HDR_ADDR3_LEN 24
  75. #define WLAN_HDR_ADDR4_LEN 30
  76. #define WLAN_IEHDR_LEN 2
  77. #define WLAN_SSID_MAXLEN 32
  78. #define WLAN_RATES_MAXLEN 16
  79. #define WLAN_RATES_MAXLEN_11B 4
  80. #define WLAN_RSN_MAXLEN 32
  81. #define WLAN_DATA_MAXLEN 2312
  82. #define WLAN_A3FR_MAXLEN (WLAN_HDR_ADDR3_LEN + WLAN_DATA_MAXLEN + \
  83. WLAN_CRC_LEN)
  84. #define WLAN_BEACON_FR_MAXLEN WLAN_A3FR_MAXLEN
  85. #define WLAN_ATIM_FR_MAXLEN (WLAN_HDR_ADDR3_LEN + 0)
  86. #define WLAN_NULLDATA_FR_MAXLEN (WLAN_HDR_ADDR3_LEN + 0)
  87. #define WLAN_DISASSOC_FR_MAXLEN (WLAN_HDR_ADDR3_LEN + 2)
  88. #define WLAN_ASSOCREQ_FR_MAXLEN WLAN_A3FR_MAXLEN
  89. #define WLAN_ASSOCRESP_FR_MAXLEN WLAN_A3FR_MAXLEN
  90. #define WLAN_REASSOCREQ_FR_MAXLEN WLAN_A3FR_MAXLEN
  91. #define WLAN_REASSOCRESP_FR_MAXLEN WLAN_A3FR_MAXLEN
  92. #define WLAN_PROBEREQ_FR_MAXLEN WLAN_A3FR_MAXLEN
  93. #define WLAN_PROBERESP_FR_MAXLEN WLAN_A3FR_MAXLEN
  94. #define WLAN_AUTHEN_FR_MAXLEN WLAN_A3FR_MAXLEN
  95. #define WLAN_DEAUTHEN_FR_MAXLEN (WLAN_HDR_ADDR3_LEN + 2)
  96. #define WLAN_WEP_NKEYS 4
  97. #define WLAN_WEP40_KEYLEN 5
  98. #define WLAN_WEP104_KEYLEN 13
  99. #define WLAN_WEP232_KEYLEN 29
  100. #define WLAN_WEPMAX_KEYLEN 32
  101. #define WLAN_CHALLENGE_IE_MAXLEN 255
  102. #define WLAN_CHALLENGE_IE_LEN 130
  103. #define WLAN_CHALLENGE_LEN 128
  104. #define WLAN_WEP_IV_LEN 4
  105. #define WLAN_WEP_ICV_LEN 4
  106. #define WLAN_FRAGS_MAX 16
  107. /* Frame Type */
  108. #define WLAN_TYPE_MGR 0x00
  109. #define WLAN_TYPE_CTL 0x01
  110. #define WLAN_TYPE_DATA 0x02
  111. #define WLAN_FTYPE_MGMT 0x00
  112. #define WLAN_FTYPE_CTL 0x01
  113. #define WLAN_FTYPE_DATA 0x02
  114. /* Frame Subtypes */
  115. #define WLAN_FSTYPE_ASSOCREQ 0x00
  116. #define WLAN_FSTYPE_ASSOCRESP 0x01
  117. #define WLAN_FSTYPE_REASSOCREQ 0x02
  118. #define WLAN_FSTYPE_REASSOCRESP 0x03
  119. #define WLAN_FSTYPE_PROBEREQ 0x04
  120. #define WLAN_FSTYPE_PROBERESP 0x05
  121. #define WLAN_FSTYPE_BEACON 0x08
  122. #define WLAN_FSTYPE_ATIM 0x09
  123. #define WLAN_FSTYPE_DISASSOC 0x0a
  124. #define WLAN_FSTYPE_AUTHEN 0x0b
  125. #define WLAN_FSTYPE_DEAUTHEN 0x0c
  126. #define WLAN_FSTYPE_ACTION 0x0d
  127. /* Control */
  128. #define WLAN_FSTYPE_PSPOLL 0x0a
  129. #define WLAN_FSTYPE_RTS 0x0b
  130. #define WLAN_FSTYPE_CTS 0x0c
  131. #define WLAN_FSTYPE_ACK 0x0d
  132. #define WLAN_FSTYPE_CFEND 0x0e
  133. #define WLAN_FSTYPE_CFENDCFACK 0x0f
  134. /* Data */
  135. #define WLAN_FSTYPE_DATAONLY 0x00
  136. #define WLAN_FSTYPE_DATA_CFACK 0x01
  137. #define WLAN_FSTYPE_DATA_CFPOLL 0x02
  138. #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
  139. #define WLAN_FSTYPE_NULL 0x04
  140. #define WLAN_FSTYPE_CFACK 0x05
  141. #define WLAN_FSTYPE_CFPOLL 0x06
  142. #define WLAN_FSTYPE_CFACK_CFPOLL 0x07
  143. #ifdef __BIG_ENDIAN
  144. /* GET & SET Frame Control bit */
  145. #define WLAN_GET_FC_PRVER(n) (((unsigned short)(n) >> 8) & (BIT0 | BIT1))
  146. #define WLAN_GET_FC_FTYPE(n) ((((unsigned short)(n) >> 8) & (BIT2 | BIT3)) >> 2)
  147. #define WLAN_GET_FC_FSTYPE(n) ((((unsigned short)(n) >> 8) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
  148. #define WLAN_GET_FC_TODS(n) ((((unsigned short)(n) << 8) & (BIT8)) >> 8)
  149. #define WLAN_GET_FC_FROMDS(n) ((((unsigned short)(n) << 8) & (BIT9)) >> 9)
  150. #define WLAN_GET_FC_MOREFRAG(n) ((((unsigned short)(n) << 8) & (BIT10)) >> 10)
  151. #define WLAN_GET_FC_RETRY(n) ((((unsigned short)(n) << 8) & (BIT11)) >> 11)
  152. #define WLAN_GET_FC_PWRMGT(n) ((((unsigned short)(n) << 8) & (BIT12)) >> 12)
  153. #define WLAN_GET_FC_MOREDATA(n) ((((unsigned short)(n) << 8) & (BIT13)) >> 13)
  154. #define WLAN_GET_FC_ISWEP(n) ((((unsigned short)(n) << 8) & (BIT14)) >> 14)
  155. #define WLAN_GET_FC_ORDER(n) ((((unsigned short)(n) << 8) & (BIT15)) >> 15)
  156. /* Sequence Field bit */
  157. #define WLAN_GET_SEQ_FRGNUM(n) (((unsigned short)(n) >> 8) & (BIT0|BIT1|BIT2|BIT3))
  158. #define WLAN_GET_SEQ_SEQNUM(n) ((((unsigned short)(n) >> 8) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
  159. /* Capability Field bit */
  160. #define WLAN_GET_CAP_INFO_ESS(n) (((n) >> 8) & BIT0)
  161. #define WLAN_GET_CAP_INFO_IBSS(n) ((((n) >> 8) & BIT1) >> 1)
  162. #define WLAN_GET_CAP_INFO_CFPOLLABLE(n) ((((n) >> 8) & BIT2) >> 2)
  163. #define WLAN_GET_CAP_INFO_CFPOLLREQ(n) ((((n) >> 8) & BIT3) >> 3)
  164. #define WLAN_GET_CAP_INFO_PRIVACY(n) ((((n) >> 8) & BIT4) >> 4)
  165. #define WLAN_GET_CAP_INFO_SHORTPREAMBLE(n) ((((n) >> 8) & BIT5) >> 5)
  166. #define WLAN_GET_CAP_INFO_PBCC(n) ((((n) >> 8) & BIT6) >> 6)
  167. #define WLAN_GET_CAP_INFO_AGILITY(n) ((((n) >> 8) & BIT7) >> 7)
  168. #define WLAN_GET_CAP_INFO_SPECTRUMMNG(n) ((((n)) & BIT8) >> 10)
  169. #define WLAN_GET_CAP_INFO_SHORTSLOTTIME(n) ((((n)) & BIT10) >> 10)
  170. #define WLAN_GET_CAP_INFO_DSSSOFDM(n) ((((n)) & BIT13) >> 13)
  171. #define WLAN_GET_CAP_INFO_GRPACK(n) ((((n)) & BIT14) >> 14)
  172. #else
  173. /* GET & SET Frame Control bit */
  174. #define WLAN_GET_FC_PRVER(n) (((unsigned short)(n)) & (BIT0 | BIT1))
  175. #define WLAN_GET_FC_FTYPE(n) ((((unsigned short)(n)) & (BIT2 | BIT3)) >> 2)
  176. #define WLAN_GET_FC_FSTYPE(n) ((((unsigned short)(n)) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
  177. #define WLAN_GET_FC_TODS(n) ((((unsigned short)(n)) & (BIT8)) >> 8)
  178. #define WLAN_GET_FC_FROMDS(n) ((((unsigned short)(n)) & (BIT9)) >> 9)
  179. #define WLAN_GET_FC_MOREFRAG(n) ((((unsigned short)(n)) & (BIT10)) >> 10)
  180. #define WLAN_GET_FC_RETRY(n) ((((unsigned short)(n)) & (BIT11)) >> 11)
  181. #define WLAN_GET_FC_PWRMGT(n) ((((unsigned short)(n)) & (BIT12)) >> 12)
  182. #define WLAN_GET_FC_MOREDATA(n) ((((unsigned short)(n)) & (BIT13)) >> 13)
  183. #define WLAN_GET_FC_ISWEP(n) ((((unsigned short)(n)) & (BIT14)) >> 14)
  184. #define WLAN_GET_FC_ORDER(n) ((((unsigned short)(n)) & (BIT15)) >> 15)
  185. /* Sequence Field bit */
  186. #define WLAN_GET_SEQ_FRGNUM(n) (((unsigned short)(n)) & (BIT0|BIT1|BIT2|BIT3))
  187. #define WLAN_GET_SEQ_SEQNUM(n) ((((unsigned short)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
  188. /* Capability Field bit */
  189. #define WLAN_GET_CAP_INFO_ESS(n) ((n) & BIT0)
  190. #define WLAN_GET_CAP_INFO_IBSS(n) (((n) & BIT1) >> 1)
  191. #define WLAN_GET_CAP_INFO_CFPOLLABLE(n) (((n) & BIT2) >> 2)
  192. #define WLAN_GET_CAP_INFO_CFPOLLREQ(n) (((n) & BIT3) >> 3)
  193. #define WLAN_GET_CAP_INFO_PRIVACY(n) (((n) & BIT4) >> 4)
  194. #define WLAN_GET_CAP_INFO_SHORTPREAMBLE(n) (((n) & BIT5) >> 5)
  195. #define WLAN_GET_CAP_INFO_PBCC(n) (((n) & BIT6) >> 6)
  196. #define WLAN_GET_CAP_INFO_AGILITY(n) (((n) & BIT7) >> 7)
  197. #define WLAN_GET_CAP_INFO_SPECTRUMMNG(n) (((n) & BIT8) >> 10)
  198. #define WLAN_GET_CAP_INFO_SHORTSLOTTIME(n) (((n) & BIT10) >> 10)
  199. #define WLAN_GET_CAP_INFO_DSSSOFDM(n) (((n) & BIT13) >> 13)
  200. #define WLAN_GET_CAP_INFO_GRPACK(n) (((n) & BIT14) >> 14)
  201. #endif /*#ifdef __BIG_ENDIAN */
  202. #define WLAN_SET_CAP_INFO_ESS(n) (n)
  203. #define WLAN_SET_CAP_INFO_IBSS(n) ((n) << 1)
  204. #define WLAN_SET_CAP_INFO_CFPOLLABLE(n) ((n) << 2)
  205. #define WLAN_SET_CAP_INFO_CFPOLLREQ(n) ((n) << 3)
  206. #define WLAN_SET_CAP_INFO_PRIVACY(n) ((n) << 4)
  207. #define WLAN_SET_CAP_INFO_SHORTPREAMBLE(n) ((n) << 5)
  208. #define WLAN_SET_CAP_INFO_SPECTRUMMNG(n) ((n) << 8)
  209. #define WLAN_SET_CAP_INFO_PBCC(n) ((n) << 6)
  210. #define WLAN_SET_CAP_INFO_AGILITY(n) ((n) << 7)
  211. #define WLAN_SET_CAP_INFO_SHORTSLOTTIME(n) ((n) << 10)
  212. #define WLAN_SET_CAP_INFO_DSSSOFDM(n) ((n) << 13)
  213. #define WLAN_SET_CAP_INFO_GRPACK(n) ((n) << 14)
  214. #define WLAN_SET_FC_PRVER(n) ((unsigned short)(n))
  215. #define WLAN_SET_FC_FTYPE(n) (((unsigned short)(n)) << 2)
  216. #define WLAN_SET_FC_FSTYPE(n) (((unsigned short)(n)) << 4)
  217. #define WLAN_SET_FC_TODS(n) (((unsigned short)(n)) << 8)
  218. #define WLAN_SET_FC_FROMDS(n) (((unsigned short)(n)) << 9)
  219. #define WLAN_SET_FC_MOREFRAG(n) (((unsigned short)(n)) << 10)
  220. #define WLAN_SET_FC_RETRY(n) (((unsigned short)(n)) << 11)
  221. #define WLAN_SET_FC_PWRMGT(n) (((unsigned short)(n)) << 12)
  222. #define WLAN_SET_FC_MOREDATA(n) (((unsigned short)(n)) << 13)
  223. #define WLAN_SET_FC_ISWEP(n) (((unsigned short)(n)) << 14)
  224. #define WLAN_SET_FC_ORDER(n) (((unsigned short)(n)) << 15)
  225. #define WLAN_SET_SEQ_FRGNUM(n) ((unsigned short)(n))
  226. #define WLAN_SET_SEQ_SEQNUM(n) (((unsigned short)(n)) << 4)
  227. /* ERP Field bit */
  228. #define WLAN_GET_ERP_NONERP_PRESENT(n) ((n) & BIT0)
  229. #define WLAN_GET_ERP_USE_PROTECTION(n) (((n) & BIT1) >> 1)
  230. #define WLAN_GET_ERP_BARKER_MODE(n) (((n) & BIT2) >> 2)
  231. #define WLAN_SET_ERP_NONERP_PRESENT(n) (n)
  232. #define WLAN_SET_ERP_USE_PROTECTION(n) ((n) << 1)
  233. #define WLAN_SET_ERP_BARKER_MODE(n) ((n) << 2)
  234. /* Support & Basic Rates field */
  235. #define WLAN_MGMT_IS_BASICRATE(b) ((b) & BIT7)
  236. #define WLAN_MGMT_GET_RATE(b) ((b) & ~BIT7)
  237. /* TIM field */
  238. #define WLAN_MGMT_IS_MULTICAST_TIM(b) ((b) & BIT0)
  239. #define WLAN_MGMT_GET_TIM_OFFSET(b) (((b) & ~BIT0) >> 1)
  240. /* 3-Addr & 4-Addr */
  241. #define WLAN_HDR_A3_DATA_PTR(p) (((unsigned char *)(p)) + WLAN_HDR_ADDR3_LEN)
  242. #define WLAN_HDR_A4_DATA_PTR(p) (((unsigned char *)(p)) + WLAN_HDR_ADDR4_LEN)
  243. /* IEEE ADDR */
  244. #define IEEE_ADDR_UNIVERSAL 0x02
  245. #define IEEE_ADDR_GROUP 0x01
  246. typedef struct {
  247. unsigned char abyAddr[6];
  248. } IEEE_ADDR, *PIEEE_ADDR;
  249. /* 802.11 Header Format */
  250. typedef struct tagWLAN_80211HDR_A2 {
  251. unsigned short wFrameCtl;
  252. unsigned short wDurationID;
  253. unsigned char abyAddr1[WLAN_ADDR_LEN];
  254. unsigned char abyAddr2[WLAN_ADDR_LEN];
  255. } __attribute__ ((__packed__))
  256. WLAN_80211HDR_A2, *PWLAN_80211HDR_A2;
  257. typedef struct tagWLAN_80211HDR_A3 {
  258. unsigned short wFrameCtl;
  259. unsigned short wDurationID;
  260. unsigned char abyAddr1[WLAN_ADDR_LEN];
  261. unsigned char abyAddr2[WLAN_ADDR_LEN];
  262. unsigned char abyAddr3[WLAN_ADDR_LEN];
  263. unsigned short wSeqCtl;
  264. } __attribute__ ((__packed__))
  265. WLAN_80211HDR_A3, *PWLAN_80211HDR_A3;
  266. typedef struct tagWLAN_80211HDR_A4 {
  267. unsigned short wFrameCtl;
  268. unsigned short wDurationID;
  269. unsigned char abyAddr1[WLAN_ADDR_LEN];
  270. unsigned char abyAddr2[WLAN_ADDR_LEN];
  271. unsigned char abyAddr3[WLAN_ADDR_LEN];
  272. unsigned short wSeqCtl;
  273. unsigned char abyAddr4[WLAN_ADDR_LEN];
  274. } __attribute__ ((__packed__))
  275. WLAN_80211HDR_A4, *PWLAN_80211HDR_A4;
  276. typedef union tagUWLAN_80211HDR {
  277. WLAN_80211HDR_A2 sA2;
  278. WLAN_80211HDR_A3 sA3;
  279. WLAN_80211HDR_A4 sA4;
  280. } UWLAN_80211HDR, *PUWLAN_80211HDR;
  281. #endif /* __80211HDR_H__ */