home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / src / linux-headers-2.6.17-6 / include / wlan / p80211hdr.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-08-11  |  11.0 KB  |  300 lines

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