您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

p80211hdr.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. FILE_LICENCE ( GPL2_ONLY );
  60. #ifndef _P80211HDR_H
  61. #define _P80211HDR_H
  62. /*================================================================*/
  63. /* System Includes */
  64. /*================================================================*/
  65. /* Project Includes */
  66. #ifndef _WLAN_COMPAT_H
  67. #include <wlan/wlan_compat.h>
  68. #endif
  69. /*================================================================*/
  70. /* Constants */
  71. /*--- Sizes -----------------------------------------------*/
  72. #define WLAN_ADDR_LEN 6
  73. #define WLAN_CRC_LEN 4
  74. #define WLAN_BSSID_LEN 6
  75. #define WLAN_BSS_TS_LEN 8
  76. #define WLAN_HDR_A3_LEN 24
  77. #define WLAN_HDR_A4_LEN 30
  78. #define WLAN_SSID_MAXLEN 32
  79. #define WLAN_DATA_MAXLEN 2312
  80. #define WLAN_A3FR_MAXLEN (WLAN_HDR_A3_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
  81. #define WLAN_A4FR_MAXLEN (WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
  82. #define WLAN_BEACON_FR_MAXLEN (WLAN_HDR_A3_LEN + 334)
  83. #define WLAN_ATIM_FR_MAXLEN (WLAN_HDR_A3_LEN + 0)
  84. #define WLAN_DISASSOC_FR_MAXLEN (WLAN_HDR_A3_LEN + 2)
  85. #define WLAN_ASSOCREQ_FR_MAXLEN (WLAN_HDR_A3_LEN + 48)
  86. #define WLAN_ASSOCRESP_FR_MAXLEN (WLAN_HDR_A3_LEN + 16)
  87. #define WLAN_REASSOCREQ_FR_MAXLEN (WLAN_HDR_A3_LEN + 54)
  88. #define WLAN_REASSOCRESP_FR_MAXLEN (WLAN_HDR_A3_LEN + 16)
  89. #define WLAN_PROBEREQ_FR_MAXLEN (WLAN_HDR_A3_LEN + 44)
  90. #define WLAN_PROBERESP_FR_MAXLEN (WLAN_HDR_A3_LEN + 78)
  91. #define WLAN_AUTHEN_FR_MAXLEN (WLAN_HDR_A3_LEN + 261)
  92. #define WLAN_DEAUTHEN_FR_MAXLEN (WLAN_HDR_A3_LEN + 2)
  93. #define WLAN_WEP_NKEYS 4
  94. #define WLAN_WEP_MAXKEYLEN 13
  95. #define WLAN_CHALLENGE_IE_LEN 130
  96. #define WLAN_CHALLENGE_LEN 128
  97. #define WLAN_WEP_IV_LEN 4
  98. #define WLAN_WEP_ICV_LEN 4
  99. /*--- Frame Control Field -------------------------------------*/
  100. /* Frame Types */
  101. #define WLAN_FTYPE_MGMT 0x00
  102. #define WLAN_FTYPE_CTL 0x01
  103. #define WLAN_FTYPE_DATA 0x02
  104. /* Frame subtypes */
  105. /* Management */
  106. #define WLAN_FSTYPE_ASSOCREQ 0x00
  107. #define WLAN_FSTYPE_ASSOCRESP 0x01
  108. #define WLAN_FSTYPE_REASSOCREQ 0x02
  109. #define WLAN_FSTYPE_REASSOCRESP 0x03
  110. #define WLAN_FSTYPE_PROBEREQ 0x04
  111. #define WLAN_FSTYPE_PROBERESP 0x05
  112. #define WLAN_FSTYPE_BEACON 0x08
  113. #define WLAN_FSTYPE_ATIM 0x09
  114. #define WLAN_FSTYPE_DISASSOC 0x0a
  115. #define WLAN_FSTYPE_AUTHEN 0x0b
  116. #define WLAN_FSTYPE_DEAUTHEN 0x0c
  117. /* Control */
  118. #define WLAN_FSTYPE_BLOCKACKREQ 0x8
  119. #define WLAN_FSTYPE_BLOCKACK 0x9
  120. #define WLAN_FSTYPE_PSPOLL 0x0a
  121. #define WLAN_FSTYPE_RTS 0x0b
  122. #define WLAN_FSTYPE_CTS 0x0c
  123. #define WLAN_FSTYPE_ACK 0x0d
  124. #define WLAN_FSTYPE_CFEND 0x0e
  125. #define WLAN_FSTYPE_CFENDCFACK 0x0f
  126. /* Data */
  127. #define WLAN_FSTYPE_DATAONLY 0x00
  128. #define WLAN_FSTYPE_DATA_CFACK 0x01
  129. #define WLAN_FSTYPE_DATA_CFPOLL 0x02
  130. #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
  131. #define WLAN_FSTYPE_NULL 0x04
  132. #define WLAN_FSTYPE_CFACK 0x05
  133. #define WLAN_FSTYPE_CFPOLL 0x06
  134. #define WLAN_FSTYPE_CFACK_CFPOLL 0x07
  135. /*================================================================*/
  136. /* Macros */
  137. /*--- FC Macros ----------------------------------------------*/
  138. /* Macros to get/set the bitfields of the Frame Control Field */
  139. /* GET_FC_??? - takes the host byte-order value of an FC */
  140. /* and retrieves the value of one of the */
  141. /* bitfields and moves that value so its lsb is */
  142. /* in bit 0. */
  143. /* SET_FC_??? - takes a host order value for one of the FC */
  144. /* bitfields and moves it to the proper bit */
  145. /* location for ORing into a host order FC. */
  146. /* To send the FC produced from SET_FC_???, */
  147. /* one must put the bytes in IEEE order. */
  148. /* e.g. */
  149. /* printf("the frame subtype is %x", */
  150. /* GET_FC_FTYPE( ieee2host( rx.fc ))) */
  151. /* */
  152. /* tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) | */
  153. /* SET_FC_FSTYPE(WLAN_FSTYPE_RTS) ); */
  154. /*------------------------------------------------------------*/
  155. #define WLAN_GET_FC_PVER(n) (((uint16_t)(n)) & (BIT0 | BIT1))
  156. #define WLAN_GET_FC_FTYPE(n) ((((uint16_t)(n)) & (BIT2 | BIT3)) >> 2)
  157. #define WLAN_GET_FC_FSTYPE(n) ((((uint16_t)(n)) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
  158. #define WLAN_GET_FC_TODS(n) ((((uint16_t)(n)) & (BIT8)) >> 8)
  159. #define WLAN_GET_FC_FROMDS(n) ((((uint16_t)(n)) & (BIT9)) >> 9)
  160. #define WLAN_GET_FC_MOREFRAG(n) ((((uint16_t)(n)) & (BIT10)) >> 10)
  161. #define WLAN_GET_FC_RETRY(n) ((((uint16_t)(n)) & (BIT11)) >> 11)
  162. #define WLAN_GET_FC_PWRMGT(n) ((((uint16_t)(n)) & (BIT12)) >> 12)
  163. #define WLAN_GET_FC_MOREDATA(n) ((((uint16_t)(n)) & (BIT13)) >> 13)
  164. #define WLAN_GET_FC_ISWEP(n) ((((uint16_t)(n)) & (BIT14)) >> 14)
  165. #define WLAN_GET_FC_ORDER(n) ((((uint16_t)(n)) & (BIT15)) >> 15)
  166. #define WLAN_SET_FC_PVER(n) ((uint16_t)(n))
  167. #define WLAN_SET_FC_FTYPE(n) (((uint16_t)(n)) << 2)
  168. #define WLAN_SET_FC_FSTYPE(n) (((uint16_t)(n)) << 4)
  169. #define WLAN_SET_FC_TODS(n) (((uint16_t)(n)) << 8)
  170. #define WLAN_SET_FC_FROMDS(n) (((uint16_t)(n)) << 9)
  171. #define WLAN_SET_FC_MOREFRAG(n) (((uint16_t)(n)) << 10)
  172. #define WLAN_SET_FC_RETRY(n) (((uint16_t)(n)) << 11)
  173. #define WLAN_SET_FC_PWRMGT(n) (((uint16_t)(n)) << 12)
  174. #define WLAN_SET_FC_MOREDATA(n) (((uint16_t)(n)) << 13)
  175. #define WLAN_SET_FC_ISWEP(n) (((uint16_t)(n)) << 14)
  176. #define WLAN_SET_FC_ORDER(n) (((uint16_t)(n)) << 15)
  177. /*--- Duration Macros ----------------------------------------*/
  178. /* Macros to get/set the bitfields of the Duration Field */
  179. /* - the duration value is only valid when bit15 is zero */
  180. /* - the firmware handles these values, so I'm not going */
  181. /* these macros right now. */
  182. /*------------------------------------------------------------*/
  183. /*--- Sequence Control Macros -------------------------------*/
  184. /* Macros to get/set the bitfields of the Sequence Control */
  185. /* Field. */
  186. /*------------------------------------------------------------*/
  187. #define WLAN_GET_SEQ_FRGNUM(n) (((uint16_t)(n)) & (BIT0|BIT1|BIT2|BIT3))
  188. #define WLAN_GET_SEQ_SEQNUM(n) ((((uint16_t)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
  189. /*--- Data ptr macro -----------------------------------------*/
  190. /* Creates a uint8_t* to the data portion of a frame */
  191. /* Assumes you're passing in a ptr to the beginning of the hdr*/
  192. /*------------------------------------------------------------*/
  193. #define WLAN_HDR_A3_DATAP(p) (((uint8_t*)(p)) + WLAN_HDR_A3_LEN)
  194. #define WLAN_HDR_A4_DATAP(p) (((uint8_t*)(p)) + WLAN_HDR_A4_LEN)
  195. #define DOT11_RATE5_ISBASIC_GET(r) (((uint8_t)(r)) & BIT7)
  196. /*================================================================*/
  197. /* Types */
  198. /* BSS Timestamp */
  199. typedef uint8_t wlan_bss_ts_t[WLAN_BSS_TS_LEN];
  200. /* Generic 802.11 Header types */
  201. typedef struct p80211_hdr_a3
  202. {
  203. uint16_t fc;
  204. uint16_t dur;
  205. uint8_t a1[WLAN_ADDR_LEN];
  206. uint8_t a2[WLAN_ADDR_LEN];
  207. uint8_t a3[WLAN_ADDR_LEN];
  208. uint16_t seq;
  209. } __WLAN_ATTRIB_PACK__ p80211_hdr_a3_t;
  210. typedef struct p80211_hdr_a4
  211. {
  212. uint16_t fc;
  213. uint16_t dur;
  214. uint8_t a1[WLAN_ADDR_LEN];
  215. uint8_t a2[WLAN_ADDR_LEN];
  216. uint8_t a3[WLAN_ADDR_LEN];
  217. uint16_t seq;
  218. uint8_t a4[WLAN_ADDR_LEN];
  219. } __WLAN_ATTRIB_PACK__ p80211_hdr_a4_t;
  220. typedef union p80211_hdr
  221. {
  222. p80211_hdr_a3_t a3;
  223. p80211_hdr_a4_t a4;
  224. } __WLAN_ATTRIB_PACK__ p80211_hdr_t;
  225. /*================================================================*/
  226. /* Extern Declarations */
  227. /*================================================================*/
  228. /* Function Declarations */
  229. /* Frame and header length macros */
  230. #define WLAN_CTL_FRAMELEN(fstype) (\
  231. (fstype) == WLAN_FSTYPE_BLOCKACKREQ ? 24 : \
  232. (fstype) == WLAN_FSTYPE_BLOCKACK ? 152 : \
  233. (fstype) == WLAN_FSTYPE_PSPOLL ? 20 : \
  234. (fstype) == WLAN_FSTYPE_RTS ? 20 : \
  235. (fstype) == WLAN_FSTYPE_CTS ? 14 : \
  236. (fstype) == WLAN_FSTYPE_ACK ? 14 : \
  237. (fstype) == WLAN_FSTYPE_CFEND ? 20 : \
  238. (fstype) == WLAN_FSTYPE_CFENDCFACK ? 20 : 4)
  239. #define WLAN_FCS_LEN 4
  240. /* ftcl in HOST order */
  241. inline static uint16_t p80211_headerlen(uint16_t fctl)
  242. {
  243. uint16_t hdrlen = 0;
  244. switch ( WLAN_GET_FC_FTYPE(fctl) ) {
  245. case WLAN_FTYPE_MGMT:
  246. hdrlen = WLAN_HDR_A3_LEN;
  247. break;
  248. case WLAN_FTYPE_DATA:
  249. hdrlen = WLAN_HDR_A3_LEN;
  250. if ( WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl) ) {
  251. hdrlen += WLAN_ADDR_LEN;
  252. }
  253. break;
  254. case WLAN_FTYPE_CTL:
  255. hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) -
  256. WLAN_FCS_LEN;
  257. break;
  258. default:
  259. hdrlen = WLAN_HDR_A3_LEN;
  260. }
  261. return hdrlen;
  262. }
  263. #endif /* _P80211HDR_H */