p80211hdr.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* 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. #include <linux/if_ether.h>
  62. /*--- Sizes -----------------------------------------------*/
  63. #define WLAN_CRC_LEN 4
  64. #define WLAN_BSSID_LEN 6
  65. #define WLAN_HDR_A3_LEN 24
  66. #define WLAN_HDR_A4_LEN 30
  67. #define WLAN_SSID_MAXLEN 32
  68. #define WLAN_DATA_MAXLEN 2312
  69. #define WLAN_WEP_IV_LEN 4
  70. #define WLAN_WEP_ICV_LEN 4
  71. /*--- Frame Control Field -------------------------------------*/
  72. /* Frame Types */
  73. #define WLAN_FTYPE_MGMT 0x00
  74. #define WLAN_FTYPE_CTL 0x01
  75. #define WLAN_FTYPE_DATA 0x02
  76. /* Frame subtypes */
  77. /* Management */
  78. #define WLAN_FSTYPE_ASSOCREQ 0x00
  79. #define WLAN_FSTYPE_ASSOCRESP 0x01
  80. #define WLAN_FSTYPE_REASSOCREQ 0x02
  81. #define WLAN_FSTYPE_REASSOCRESP 0x03
  82. #define WLAN_FSTYPE_PROBEREQ 0x04
  83. #define WLAN_FSTYPE_PROBERESP 0x05
  84. #define WLAN_FSTYPE_BEACON 0x08
  85. #define WLAN_FSTYPE_ATIM 0x09
  86. #define WLAN_FSTYPE_DISASSOC 0x0a
  87. #define WLAN_FSTYPE_AUTHEN 0x0b
  88. #define WLAN_FSTYPE_DEAUTHEN 0x0c
  89. /* Control */
  90. #define WLAN_FSTYPE_BLOCKACKREQ 0x8
  91. #define WLAN_FSTYPE_BLOCKACK 0x9
  92. #define WLAN_FSTYPE_PSPOLL 0x0a
  93. #define WLAN_FSTYPE_RTS 0x0b
  94. #define WLAN_FSTYPE_CTS 0x0c
  95. #define WLAN_FSTYPE_ACK 0x0d
  96. #define WLAN_FSTYPE_CFEND 0x0e
  97. #define WLAN_FSTYPE_CFENDCFACK 0x0f
  98. /* Data */
  99. #define WLAN_FSTYPE_DATAONLY 0x00
  100. #define WLAN_FSTYPE_DATA_CFACK 0x01
  101. #define WLAN_FSTYPE_DATA_CFPOLL 0x02
  102. #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
  103. #define WLAN_FSTYPE_NULL 0x04
  104. #define WLAN_FSTYPE_CFACK 0x05
  105. #define WLAN_FSTYPE_CFPOLL 0x06
  106. #define WLAN_FSTYPE_CFACK_CFPOLL 0x07
  107. /*--- FC Macros ----------------------------------------------*/
  108. /* Macros to get/set the bitfields of the Frame Control Field */
  109. /* GET_FC_??? - takes the host byte-order value of an FC */
  110. /* and retrieves the value of one of the */
  111. /* bitfields and moves that value so its lsb is */
  112. /* in bit 0. */
  113. /* SET_FC_??? - takes a host order value for one of the FC */
  114. /* bitfields and moves it to the proper bit */
  115. /* location for ORing into a host order FC. */
  116. /* To send the FC produced from SET_FC_???, */
  117. /* one must put the bytes in IEEE order. */
  118. /* e.g. */
  119. /* printf("the frame subtype is %x", */
  120. /* GET_FC_FTYPE( ieee2host( rx.fc ))) */
  121. /* */
  122. /* tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) | */
  123. /* SET_FC_FSTYPE(WLAN_FSTYPE_RTS) ); */
  124. /*------------------------------------------------------------*/
  125. #define WLAN_GET_FC_FTYPE(n) ((((u16)(n)) & (BIT(2) | BIT(3))) >> 2)
  126. #define WLAN_GET_FC_FSTYPE(n) ((((u16)(n)) & (BIT(4)|BIT(5)|BIT(6)|BIT(7))) >> 4)
  127. #define WLAN_GET_FC_TODS(n) ((((u16)(n)) & (BIT(8))) >> 8)
  128. #define WLAN_GET_FC_FROMDS(n) ((((u16)(n)) & (BIT(9))) >> 9)
  129. #define WLAN_GET_FC_ISWEP(n) ((((u16)(n)) & (BIT(14))) >> 14)
  130. #define WLAN_SET_FC_FTYPE(n) (((u16)(n)) << 2)
  131. #define WLAN_SET_FC_FSTYPE(n) (((u16)(n)) << 4)
  132. #define WLAN_SET_FC_TODS(n) (((u16)(n)) << 8)
  133. #define WLAN_SET_FC_FROMDS(n) (((u16)(n)) << 9)
  134. #define WLAN_SET_FC_ISWEP(n) (((u16)(n)) << 14)
  135. #define DOT11_RATE5_ISBASIC_GET(r) (((u8)(r)) & BIT(7))
  136. /* Generic 802.11 Header types */
  137. struct p80211_hdr_a3 {
  138. __le16 fc;
  139. u16 dur;
  140. u8 a1[ETH_ALEN];
  141. u8 a2[ETH_ALEN];
  142. u8 a3[ETH_ALEN];
  143. u16 seq;
  144. } __packed;
  145. struct p80211_hdr_a4 {
  146. u16 fc;
  147. u16 dur;
  148. u8 a1[ETH_ALEN];
  149. u8 a2[ETH_ALEN];
  150. u8 a3[ETH_ALEN];
  151. u16 seq;
  152. u8 a4[ETH_ALEN];
  153. } __packed;
  154. union p80211_hdr {
  155. struct p80211_hdr_a3 a3;
  156. struct p80211_hdr_a4 a4;
  157. } __packed;
  158. /* Frame and header length macros */
  159. #define WLAN_CTL_FRAMELEN(fstype) (\
  160. (fstype) == WLAN_FSTYPE_BLOCKACKREQ ? 24 : \
  161. (fstype) == WLAN_FSTYPE_BLOCKACK ? 152 : \
  162. (fstype) == WLAN_FSTYPE_PSPOLL ? 20 : \
  163. (fstype) == WLAN_FSTYPE_RTS ? 20 : \
  164. (fstype) == WLAN_FSTYPE_CTS ? 14 : \
  165. (fstype) == WLAN_FSTYPE_ACK ? 14 : \
  166. (fstype) == WLAN_FSTYPE_CFEND ? 20 : \
  167. (fstype) == WLAN_FSTYPE_CFENDCFACK ? 20 : 4)
  168. #define WLAN_FCS_LEN 4
  169. /* ftcl in HOST order */
  170. static inline u16 p80211_headerlen(u16 fctl)
  171. {
  172. u16 hdrlen = 0;
  173. switch (WLAN_GET_FC_FTYPE(fctl)) {
  174. case WLAN_FTYPE_MGMT:
  175. hdrlen = WLAN_HDR_A3_LEN;
  176. break;
  177. case WLAN_FTYPE_DATA:
  178. hdrlen = WLAN_HDR_A3_LEN;
  179. if (WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl))
  180. hdrlen += ETH_ALEN;
  181. break;
  182. case WLAN_FTYPE_CTL:
  183. hdrlen = WLAN_CTL_FRAMELEN(WLAN_GET_FC_FSTYPE(fctl)) -
  184. WLAN_FCS_LEN;
  185. break;
  186. default:
  187. hdrlen = WLAN_HDR_A3_LEN;
  188. }
  189. return hdrlen;
  190. }
  191. #endif /* _P80211HDR_H */