p80211hdr.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */
  2. /* p80211hdr.h
  3. *
  4. * Macros, types, and functions for handling 802.11 MAC headers
  5. *
  6. * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
  7. * --------------------------------------------------------------------
  8. *
  9. * linux-wlan
  10. *
  11. * The contents of this file are subject to the Mozilla Public
  12. * License Version 1.1 (the "License"); you may not use this file
  13. * except in compliance with the License. You may obtain a copy of
  14. * the License at http://www.mozilla.org/MPL/
  15. *
  16. * Software distributed under the License is distributed on an "AS
  17. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  18. * implied. See the License for the specific language governing
  19. * rights and limitations under the License.
  20. *
  21. * Alternatively, the contents of this file may be used under the
  22. * terms of the GNU Public License version 2 (the "GPL"), in which
  23. * case the provisions of the GPL are applicable instead of the
  24. * above. If you wish to allow the use of your version of this file
  25. * only under the terms of the GPL and not to allow others to use
  26. * your version of this file under the MPL, indicate your decision
  27. * by deleting the provisions above and replace them with the notice
  28. * and other provisions required by the GPL. If you do not delete
  29. * the provisions above, a recipient may use your version of this
  30. * file under either the MPL or the GPL.
  31. *
  32. * --------------------------------------------------------------------
  33. *
  34. * Inquiries regarding the linux-wlan Open Source project can be
  35. * made directly to:
  36. *
  37. * AbsoluteValue Systems Inc.
  38. * info@linux-wlan.com
  39. * http://www.linux-wlan.com
  40. *
  41. * --------------------------------------------------------------------
  42. *
  43. * Portions of the development of this software were funded by
  44. * Intersil Corporation as part of PRISM(R) chipset product development.
  45. *
  46. * --------------------------------------------------------------------
  47. *
  48. * This file declares the constants and types used in the interface
  49. * between a wlan driver and the user mode utilities.
  50. *
  51. * Note:
  52. * - Constant values are always in HOST byte order. To assign
  53. * values to multi-byte fields they _must_ be converted to
  54. * ieee byte order. To retrieve multi-byte values from incoming
  55. * frames, they must be converted to host order.
  56. *
  57. * All functions declared here are implemented in p80211.c
  58. * --------------------------------------------------------------------
  59. */
  60. #ifndef _P80211HDR_H
  61. #define _P80211HDR_H
  62. #include <linux/if_ether.h>
  63. /*--- Sizes -----------------------------------------------*/
  64. #define WLAN_CRC_LEN 4
  65. #define WLAN_BSSID_LEN 6
  66. #define WLAN_HDR_A3_LEN 24
  67. #define WLAN_HDR_A4_LEN 30
  68. #define WLAN_SSID_MAXLEN 32
  69. #define WLAN_DATA_MAXLEN 2312
  70. #define WLAN_WEP_IV_LEN 4
  71. #define WLAN_WEP_ICV_LEN 4
  72. /*--- Frame Control Field -------------------------------------*/
  73. /* Frame Types */
  74. #define WLAN_FTYPE_MGMT 0x00
  75. #define WLAN_FTYPE_CTL 0x01
  76. #define WLAN_FTYPE_DATA 0x02
  77. /* Frame subtypes */
  78. /* Management */
  79. #define WLAN_FSTYPE_ASSOCREQ 0x00
  80. #define WLAN_FSTYPE_ASSOCRESP 0x01
  81. #define WLAN_FSTYPE_REASSOCREQ 0x02
  82. #define WLAN_FSTYPE_REASSOCRESP 0x03
  83. #define WLAN_FSTYPE_PROBEREQ 0x04
  84. #define WLAN_FSTYPE_PROBERESP 0x05
  85. #define WLAN_FSTYPE_BEACON 0x08
  86. #define WLAN_FSTYPE_ATIM 0x09
  87. #define WLAN_FSTYPE_DISASSOC 0x0a
  88. #define WLAN_FSTYPE_AUTHEN 0x0b
  89. #define WLAN_FSTYPE_DEAUTHEN 0x0c
  90. /* Control */
  91. #define WLAN_FSTYPE_BLOCKACKREQ 0x8
  92. #define WLAN_FSTYPE_BLOCKACK 0x9
  93. #define WLAN_FSTYPE_PSPOLL 0x0a
  94. #define WLAN_FSTYPE_RTS 0x0b
  95. #define WLAN_FSTYPE_CTS 0x0c
  96. #define WLAN_FSTYPE_ACK 0x0d
  97. #define WLAN_FSTYPE_CFEND 0x0e
  98. #define WLAN_FSTYPE_CFENDCFACK 0x0f
  99. /* Data */
  100. #define WLAN_FSTYPE_DATAONLY 0x00
  101. #define WLAN_FSTYPE_DATA_CFACK 0x01
  102. #define WLAN_FSTYPE_DATA_CFPOLL 0x02
  103. #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
  104. #define WLAN_FSTYPE_NULL 0x04
  105. #define WLAN_FSTYPE_CFACK 0x05
  106. #define WLAN_FSTYPE_CFPOLL 0x06
  107. #define WLAN_FSTYPE_CFACK_CFPOLL 0x07
  108. /*--- FC Macros ----------------------------------------------*/
  109. /* Macros to get/set the bitfields of the Frame Control Field */
  110. /* GET_FC_??? - takes the host byte-order value of an FC */
  111. /* and retrieves the value of one of the */
  112. /* bitfields and moves that value so its lsb is */
  113. /* in bit 0. */
  114. /* SET_FC_??? - takes a host order value for one of the FC */
  115. /* bitfields and moves it to the proper bit */
  116. /* location for ORing into a host order FC. */
  117. /* To send the FC produced from SET_FC_???, */
  118. /* one must put the bytes in IEEE order. */
  119. /* e.g. */
  120. /* printf("the frame subtype is %x", */
  121. /* GET_FC_FTYPE( ieee2host( rx.fc ))) */
  122. /* */
  123. /* tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) | */
  124. /* SET_FC_FSTYPE(WLAN_FSTYPE_RTS) ); */
  125. /*------------------------------------------------------------*/
  126. #define WLAN_GET_FC_FTYPE(n) ((((u16)(n)) & GENMASK(3, 2)) >> 2)
  127. #define WLAN_GET_FC_FSTYPE(n) ((((u16)(n)) & GENMASK(7, 4)) >> 4)
  128. #define WLAN_GET_FC_TODS(n) ((((u16)(n)) & (BIT(8))) >> 8)
  129. #define WLAN_GET_FC_FROMDS(n) ((((u16)(n)) & (BIT(9))) >> 9)
  130. #define WLAN_GET_FC_ISWEP(n) ((((u16)(n)) & (BIT(14))) >> 14)
  131. #define WLAN_SET_FC_FTYPE(n) (((u16)(n)) << 2)
  132. #define WLAN_SET_FC_FSTYPE(n) (((u16)(n)) << 4)
  133. #define WLAN_SET_FC_TODS(n) (((u16)(n)) << 8)
  134. #define WLAN_SET_FC_FROMDS(n) (((u16)(n)) << 9)
  135. #define WLAN_SET_FC_ISWEP(n) (((u16)(n)) << 14)
  136. #define DOT11_RATE5_ISBASIC_GET(r) (((u8)(r)) & BIT(7))
  137. /* Generic 802.11 Header types */
  138. struct p80211_hdr_a3 {
  139. __le16 fc;
  140. u16 dur;
  141. u8 a1[ETH_ALEN];
  142. u8 a2[ETH_ALEN];
  143. u8 a3[ETH_ALEN];
  144. u16 seq;
  145. } __packed;
  146. struct p80211_hdr_a4 {
  147. u16 fc;
  148. u16 dur;
  149. u8 a1[ETH_ALEN];
  150. u8 a2[ETH_ALEN];
  151. u8 a3[ETH_ALEN];
  152. u16 seq;
  153. u8 a4[ETH_ALEN];
  154. } __packed;
  155. union p80211_hdr {
  156. struct p80211_hdr_a3 a3;
  157. struct p80211_hdr_a4 a4;
  158. } __packed;
  159. /* Frame and header length macros */
  160. static inline u16 wlan_ctl_framelen(u16 fstype)
  161. {
  162. switch (fstype) {
  163. case WLAN_FSTYPE_BLOCKACKREQ:
  164. return 24;
  165. case WLAN_FSTYPE_BLOCKACK:
  166. return 152;
  167. case WLAN_FSTYPE_PSPOLL:
  168. case WLAN_FSTYPE_RTS:
  169. case WLAN_FSTYPE_CFEND:
  170. case WLAN_FSTYPE_CFENDCFACK:
  171. return 20;
  172. case WLAN_FSTYPE_CTS:
  173. case WLAN_FSTYPE_ACK:
  174. return 14;
  175. default:
  176. return 4;
  177. }
  178. }
  179. #define WLAN_FCS_LEN 4
  180. /* ftcl in HOST order */
  181. static inline u16 p80211_headerlen(u16 fctl)
  182. {
  183. u16 hdrlen = 0;
  184. switch (WLAN_GET_FC_FTYPE(fctl)) {
  185. case WLAN_FTYPE_MGMT:
  186. hdrlen = WLAN_HDR_A3_LEN;
  187. break;
  188. case WLAN_FTYPE_DATA:
  189. hdrlen = WLAN_HDR_A3_LEN;
  190. if (WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl))
  191. hdrlen += ETH_ALEN;
  192. break;
  193. case WLAN_FTYPE_CTL:
  194. hdrlen = wlan_ctl_framelen(WLAN_GET_FC_FSTYPE(fctl)) -
  195. WLAN_FCS_LEN;
  196. break;
  197. default:
  198. hdrlen = WLAN_HDR_A3_LEN;
  199. }
  200. return hdrlen;
  201. }
  202. #endif /* _P80211HDR_H */