You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

p80211hdr.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /* src/include/wlan/p80211hdr.h
  2. *
  3. * Macros, types, and functions for handling 802.11 MAC headers
  4. *
  5. * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
  6. * --------------------------------------------------------------------
  7. *
  8. * linux-wlan
  9. *
  10. * The contents of this file are subject to the Mozilla Public
  11. * License Version 1.1 (the "License"); you may not use this file
  12. * except in compliance with the License. You may obtain a copy of
  13. * the License at http://www.mozilla.org/MPL/
  14. *
  15. * Software distributed under the License is distributed on an "AS
  16. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  17. * implied. See the License for the specific language governing
  18. * rights and limitations under the License.
  19. *
  20. * Alternatively, the contents of this file may be used under the
  21. * terms of the GNU Public License version 2 (the "GPL"), in which
  22. * case the provisions of the GPL are applicable instead of the
  23. * above. If you wish to allow the use of your version of this file
  24. * only under the terms of the GPL and not to allow others to use
  25. * your version of this file under the MPL, indicate your decision
  26. * by deleting the provisions above and replace them with the notice
  27. * and other provisions required by the GPL. If you do not delete
  28. * the provisions above, a recipient may use your version of this
  29. * file under either the MPL or the GPL.
  30. *
  31. * --------------------------------------------------------------------
  32. *
  33. * Inquiries regarding the linux-wlan Open Source project can be
  34. * made directly to:
  35. *
  36. * AbsoluteValue Systems Inc.
  37. * info@linux-wlan.com
  38. * http://www.linux-wlan.com
  39. *
  40. * --------------------------------------------------------------------
  41. *
  42. * Portions of the development of this software were funded by
  43. * Intersil Corporation as part of PRISM(R) chipset product development.
  44. *
  45. * --------------------------------------------------------------------
  46. *
  47. * This file declares the constants and types used in the interface
  48. * between a wlan driver and the user mode utilities.
  49. *
  50. * Note:
  51. * - Constant values are always in HOST byte order. To assign
  52. * values to multi-byte fields they _must_ be converted to
  53. * ieee byte order. To retrieve multi-byte values from incoming
  54. * frames, they must be converted to host order.
  55. *
  56. * All functions declared here are implemented in p80211.c
  57. * --------------------------------------------------------------------
  58. */
  59. #ifndef _P80211HDR_H
  60. #define _P80211HDR_H
  61. /*================================================================*/
  62. /* System Includes */
  63. /*================================================================*/
  64. /* Project Includes */
  65. #ifndef _WLAN_COMPAT_H
  66. #include <wlan/wlan_compat.h>
  67. #endif
  68. /*================================================================*/
  69. /* Constants */
  70. /*--- Sizes -----------------------------------------------*/
  71. #define WLAN_ADDR_LEN 6
  72. #define WLAN_CRC_LEN 4
  73. #define WLAN_BSSID_LEN 6
  74. #define WLAN_BSS_TS_LEN 8
  75. #define WLAN_HDR_A3_LEN 24
  76. #define WLAN_HDR_A4_LEN 30
  77. #define WLAN_SSID_MAXLEN 32
  78. #define WLAN_DATA_MAXLEN 2312
  79. #define WLAN_A3FR_MAXLEN (WLAN_HDR_A3_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
  80. #define WLAN_A4FR_MAXLEN (WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
  81. #define WLAN_BEACON_FR_MAXLEN (WLAN_HDR_A3_LEN + 334)
  82. #define WLAN_ATIM_FR_MAXLEN (WLAN_HDR_A3_LEN + 0)
  83. #define WLAN_DISASSOC_FR_MAXLEN (WLAN_HDR_A3_LEN + 2)
  84. #define WLAN_ASSOCREQ_FR_MAXLEN (WLAN_HDR_A3_LEN + 48)
  85. #define WLAN_ASSOCRESP_FR_MAXLEN (WLAN_HDR_A3_LEN + 16)
  86. #define WLAN_REASSOCREQ_FR_MAXLEN (WLAN_HDR_A3_LEN + 54)
  87. #define WLAN_REASSOCRESP_FR_MAXLEN (WLAN_HDR_A3_LEN + 16)
  88. #define WLAN_PROBEREQ_FR_MAXLEN (WLAN_HDR_A3_LEN + 44)
  89. #define WLAN_PROBERESP_FR_MAXLEN (WLAN_HDR_A3_LEN + 78)
  90. #define WLAN_AUTHEN_FR_MAXLEN (WLAN_HDR_A3_LEN + 261)
  91. #define WLAN_DEAUTHEN_FR_MAXLEN (WLAN_HDR_A3_LEN + 2)
  92. #define WLAN_WEP_NKEYS 4
  93. #define WLAN_WEP_MAXKEYLEN 13
  94. #define WLAN_CHALLENGE_IE_LEN 130
  95. #define WLAN_CHALLENGE_LEN 128
  96. #define WLAN_WEP_IV_LEN 4
  97. #define WLAN_WEP_ICV_LEN 4
  98. /*--- Frame Control Field -------------------------------------*/
  99. /* Frame Types */
  100. #define WLAN_FTYPE_MGMT 0x00
  101. #define WLAN_FTYPE_CTL 0x01
  102. #define WLAN_FTYPE_DATA 0x02
  103. /* Frame subtypes */
  104. /* Management */
  105. #define WLAN_FSTYPE_ASSOCREQ 0x00
  106. #define WLAN_FSTYPE_ASSOCRESP 0x01
  107. #define WLAN_FSTYPE_REASSOCREQ 0x02
  108. #define WLAN_FSTYPE_REASSOCRESP 0x03
  109. #define WLAN_FSTYPE_PROBEREQ 0x04
  110. #define WLAN_FSTYPE_PROBERESP 0x05
  111. #define WLAN_FSTYPE_BEACON 0x08
  112. #define WLAN_FSTYPE_ATIM 0x09
  113. #define WLAN_FSTYPE_DISASSOC 0x0a
  114. #define WLAN_FSTYPE_AUTHEN 0x0b
  115. #define WLAN_FSTYPE_DEAUTHEN 0x0c
  116. /* Control */
  117. #define WLAN_FSTYPE_BLOCKACKREQ 0x8
  118. #define WLAN_FSTYPE_BLOCKACK 0x9
  119. #define WLAN_FSTYPE_PSPOLL 0x0a
  120. #define WLAN_FSTYPE_RTS 0x0b
  121. #define WLAN_FSTYPE_CTS 0x0c
  122. #define WLAN_FSTYPE_ACK 0x0d
  123. #define WLAN_FSTYPE_CFEND 0x0e
  124. #define WLAN_FSTYPE_CFENDCFACK 0x0f
  125. /* Data */
  126. #define WLAN_FSTYPE_DATAONLY 0x00
  127. #define WLAN_FSTYPE_DATA_CFACK 0x01
  128. #define WLAN_FSTYPE_DATA_CFPOLL 0x02
  129. #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
  130. #define WLAN_FSTYPE_NULL 0x04
  131. #define WLAN_FSTYPE_CFACK 0x05
  132. #define WLAN_FSTYPE_CFPOLL 0x06
  133. #define WLAN_FSTYPE_CFACK_CFPOLL 0x07
  134. /*================================================================*/
  135. /* Macros */
  136. /*--- FC Macros ----------------------------------------------*/
  137. /* Macros to get/set the bitfields of the Frame Control Field */
  138. /* GET_FC_??? - takes the host byte-order value of an FC */
  139. /* and retrieves the value of one of the */
  140. /* bitfields and moves that value so its lsb is */
  141. /* in bit 0. */
  142. /* SET_FC_??? - takes a host order value for one of the FC */
  143. /* bitfields and moves it to the proper bit */
  144. /* location for ORing into a host order FC. */
  145. /* To send the FC produced from SET_FC_???, */
  146. /* one must put the bytes in IEEE order. */
  147. /* e.g. */
  148. /* printf("the frame subtype is %x", */
  149. /* GET_FC_FTYPE( ieee2host( rx.fc ))) */
  150. /* */
  151. /* tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) | */
  152. /* SET_FC_FSTYPE(WLAN_FSTYPE_RTS) ); */
  153. /*------------------------------------------------------------*/
  154. #define WLAN_GET_FC_PVER(n) (((UINT16)(n)) & (BIT0 | BIT1))
  155. #define WLAN_GET_FC_FTYPE(n) ((((UINT16)(n)) & (BIT2 | BIT3)) >> 2)
  156. #define WLAN_GET_FC_FSTYPE(n) ((((UINT16)(n)) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
  157. #define WLAN_GET_FC_TODS(n) ((((UINT16)(n)) & (BIT8)) >> 8)
  158. #define WLAN_GET_FC_FROMDS(n) ((((UINT16)(n)) & (BIT9)) >> 9)
  159. #define WLAN_GET_FC_MOREFRAG(n) ((((UINT16)(n)) & (BIT10)) >> 10)
  160. #define WLAN_GET_FC_RETRY(n) ((((UINT16)(n)) & (BIT11)) >> 11)
  161. #define WLAN_GET_FC_PWRMGT(n) ((((UINT16)(n)) & (BIT12)) >> 12)
  162. #define WLAN_GET_FC_MOREDATA(n) ((((UINT16)(n)) & (BIT13)) >> 13)
  163. #define WLAN_GET_FC_ISWEP(n) ((((UINT16)(n)) & (BIT14)) >> 14)
  164. #define WLAN_GET_FC_ORDER(n) ((((UINT16)(n)) & (BIT15)) >> 15)
  165. #define WLAN_SET_FC_PVER(n) ((UINT16)(n))
  166. #define WLAN_SET_FC_FTYPE(n) (((UINT16)(n)) << 2)
  167. #define WLAN_SET_FC_FSTYPE(n) (((UINT16)(n)) << 4)
  168. #define WLAN_SET_FC_TODS(n) (((UINT16)(n)) << 8)
  169. #define WLAN_SET_FC_FROMDS(n) (((UINT16)(n)) << 9)
  170. #define WLAN_SET_FC_MOREFRAG(n) (((UINT16)(n)) << 10)
  171. #define WLAN_SET_FC_RETRY(n) (((UINT16)(n)) << 11)
  172. #define WLAN_SET_FC_PWRMGT(n) (((UINT16)(n)) << 12)
  173. #define WLAN_SET_FC_MOREDATA(n) (((UINT16)(n)) << 13)
  174. #define WLAN_SET_FC_ISWEP(n) (((UINT16)(n)) << 14)
  175. #define WLAN_SET_FC_ORDER(n) (((UINT16)(n)) << 15)
  176. /*--- Duration Macros ----------------------------------------*/
  177. /* Macros to get/set the bitfields of the Duration Field */
  178. /* - the duration value is only valid when bit15 is zero */
  179. /* - the firmware handles these values, so I'm not going */
  180. /* these macros right now. */
  181. /*------------------------------------------------------------*/
  182. /*--- Sequence Control Macros -------------------------------*/
  183. /* Macros to get/set the bitfields of the Sequence Control */
  184. /* Field. */
  185. /*------------------------------------------------------------*/
  186. #define WLAN_GET_SEQ_FRGNUM(n) (((UINT16)(n)) & (BIT0|BIT1|BIT2|BIT3))
  187. #define WLAN_GET_SEQ_SEQNUM(n) ((((UINT16)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
  188. /*--- Data ptr macro -----------------------------------------*/
  189. /* Creates a UINT8* to the data portion of a frame */
  190. /* Assumes you're passing in a ptr to the beginning of the hdr*/
  191. /*------------------------------------------------------------*/
  192. #define WLAN_HDR_A3_DATAP(p) (((UINT8*)(p)) + WLAN_HDR_A3_LEN)
  193. #define WLAN_HDR_A4_DATAP(p) (((UINT8*)(p)) + WLAN_HDR_A4_LEN)
  194. #define DOT11_RATE5_ISBASIC_GET(r) (((UINT8)(r)) & BIT7)
  195. /*================================================================*/
  196. /* Types */
  197. /* BSS Timestamp */
  198. typedef UINT8 wlan_bss_ts_t[WLAN_BSS_TS_LEN];
  199. /* Generic 802.11 Header types */
  200. typedef struct p80211_hdr_a3
  201. {
  202. UINT16 fc;
  203. UINT16 dur;
  204. UINT8 a1[WLAN_ADDR_LEN];
  205. UINT8 a2[WLAN_ADDR_LEN];
  206. UINT8 a3[WLAN_ADDR_LEN];
  207. UINT16 seq;
  208. } __WLAN_ATTRIB_PACK__ p80211_hdr_a3_t;
  209. typedef struct p80211_hdr_a4
  210. {
  211. UINT16 fc;
  212. UINT16 dur;
  213. UINT8 a1[WLAN_ADDR_LEN];
  214. UINT8 a2[WLAN_ADDR_LEN];
  215. UINT8 a3[WLAN_ADDR_LEN];
  216. UINT16 seq;
  217. UINT8 a4[WLAN_ADDR_LEN];
  218. } __WLAN_ATTRIB_PACK__ p80211_hdr_a4_t;
  219. typedef union p80211_hdr
  220. {
  221. p80211_hdr_a3_t a3;
  222. p80211_hdr_a4_t a4;
  223. } __WLAN_ATTRIB_PACK__ p80211_hdr_t;
  224. /*================================================================*/
  225. /* Extern Declarations */
  226. /*================================================================*/
  227. /* Function Declarations */
  228. /* Frame and header lenght macros */
  229. #define WLAN_CTL_FRAMELEN(fstype) (\
  230. (fstype) == WLAN_FSTYPE_BLOCKACKREQ ? 24 : \
  231. (fstype) == WLAN_FSTYPE_BLOCKACK ? 152 : \
  232. (fstype) == WLAN_FSTYPE_PSPOLL ? 20 : \
  233. (fstype) == WLAN_FSTYPE_RTS ? 20 : \
  234. (fstype) == WLAN_FSTYPE_CTS ? 14 : \
  235. (fstype) == WLAN_FSTYPE_ACK ? 14 : \
  236. (fstype) == WLAN_FSTYPE_CFEND ? 20 : \
  237. (fstype) == WLAN_FSTYPE_CFENDCFACK ? 20 : 4)
  238. #define WLAN_FCS_LEN 4
  239. /* ftcl in HOST order */
  240. inline static UINT16 p80211_headerlen(UINT16 fctl)
  241. {
  242. UINT16 hdrlen = 0;
  243. switch ( WLAN_GET_FC_FTYPE(fctl) ) {
  244. case WLAN_FTYPE_MGMT:
  245. hdrlen = WLAN_HDR_A3_LEN;
  246. break;
  247. case WLAN_FTYPE_DATA:
  248. hdrlen = WLAN_HDR_A3_LEN;
  249. if ( WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl) ) {
  250. hdrlen += WLAN_ADDR_LEN;
  251. }
  252. break;
  253. case WLAN_FTYPE_CTL:
  254. hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) -
  255. WLAN_FCS_LEN;
  256. break;
  257. default:
  258. hdrlen = WLAN_HDR_A3_LEN;
  259. }
  260. return hdrlen;
  261. }
  262. #endif /* _P80211HDR_H */