Tim Collier | 3fb28ae | 2018-05-04 09:51:52 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 2 | /* p80211hdr.h |
Sergio Paracuellos | ed2e0f8 | 2016-10-09 17:51:27 +0200 | [diff] [blame] | 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 | */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 60 | |
| 61 | #ifndef _P80211HDR_H |
| 62 | #define _P80211HDR_H |
| 63 | |
Moritz Muehlenhoff | 28b17a4 | 2009-01-21 22:00:41 +0100 | [diff] [blame] | 64 | #include <linux/if_ether.h> |
| 65 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 66 | /*--- Sizes -----------------------------------------------*/ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 67 | #define WLAN_CRC_LEN 4 |
| 68 | #define WLAN_BSSID_LEN 6 |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 69 | #define WLAN_HDR_A3_LEN 24 |
| 70 | #define WLAN_HDR_A4_LEN 30 |
| 71 | #define WLAN_SSID_MAXLEN 32 |
| 72 | #define WLAN_DATA_MAXLEN 2312 |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 73 | #define WLAN_WEP_IV_LEN 4 |
| 74 | #define WLAN_WEP_ICV_LEN 4 |
| 75 | |
| 76 | /*--- Frame Control Field -------------------------------------*/ |
| 77 | /* Frame Types */ |
| 78 | #define WLAN_FTYPE_MGMT 0x00 |
| 79 | #define WLAN_FTYPE_CTL 0x01 |
| 80 | #define WLAN_FTYPE_DATA 0x02 |
| 81 | |
| 82 | /* Frame subtypes */ |
| 83 | /* Management */ |
| 84 | #define WLAN_FSTYPE_ASSOCREQ 0x00 |
| 85 | #define WLAN_FSTYPE_ASSOCRESP 0x01 |
| 86 | #define WLAN_FSTYPE_REASSOCREQ 0x02 |
| 87 | #define WLAN_FSTYPE_REASSOCRESP 0x03 |
| 88 | #define WLAN_FSTYPE_PROBEREQ 0x04 |
| 89 | #define WLAN_FSTYPE_PROBERESP 0x05 |
| 90 | #define WLAN_FSTYPE_BEACON 0x08 |
| 91 | #define WLAN_FSTYPE_ATIM 0x09 |
| 92 | #define WLAN_FSTYPE_DISASSOC 0x0a |
| 93 | #define WLAN_FSTYPE_AUTHEN 0x0b |
| 94 | #define WLAN_FSTYPE_DEAUTHEN 0x0c |
| 95 | |
| 96 | /* Control */ |
| 97 | #define WLAN_FSTYPE_BLOCKACKREQ 0x8 |
Edgardo Hames | 93df38e | 2010-07-30 22:51:55 -0300 | [diff] [blame] | 98 | #define WLAN_FSTYPE_BLOCKACK 0x9 |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 99 | #define WLAN_FSTYPE_PSPOLL 0x0a |
| 100 | #define WLAN_FSTYPE_RTS 0x0b |
| 101 | #define WLAN_FSTYPE_CTS 0x0c |
| 102 | #define WLAN_FSTYPE_ACK 0x0d |
| 103 | #define WLAN_FSTYPE_CFEND 0x0e |
| 104 | #define WLAN_FSTYPE_CFENDCFACK 0x0f |
| 105 | |
| 106 | /* Data */ |
| 107 | #define WLAN_FSTYPE_DATAONLY 0x00 |
| 108 | #define WLAN_FSTYPE_DATA_CFACK 0x01 |
| 109 | #define WLAN_FSTYPE_DATA_CFPOLL 0x02 |
| 110 | #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03 |
| 111 | #define WLAN_FSTYPE_NULL 0x04 |
| 112 | #define WLAN_FSTYPE_CFACK 0x05 |
| 113 | #define WLAN_FSTYPE_CFPOLL 0x06 |
| 114 | #define WLAN_FSTYPE_CFACK_CFPOLL 0x07 |
| 115 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 116 | /*--- FC Macros ----------------------------------------------*/ |
| 117 | /* Macros to get/set the bitfields of the Frame Control Field */ |
| 118 | /* GET_FC_??? - takes the host byte-order value of an FC */ |
| 119 | /* and retrieves the value of one of the */ |
| 120 | /* bitfields and moves that value so its lsb is */ |
| 121 | /* in bit 0. */ |
| 122 | /* SET_FC_??? - takes a host order value for one of the FC */ |
| 123 | /* bitfields and moves it to the proper bit */ |
| 124 | /* location for ORing into a host order FC. */ |
| 125 | /* To send the FC produced from SET_FC_???, */ |
| 126 | /* one must put the bytes in IEEE order. */ |
| 127 | /* e.g. */ |
| 128 | /* printf("the frame subtype is %x", */ |
| 129 | /* GET_FC_FTYPE( ieee2host( rx.fc ))) */ |
| 130 | /* */ |
| 131 | /* tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) | */ |
| 132 | /* SET_FC_FSTYPE(WLAN_FSTYPE_RTS) ); */ |
| 133 | /*------------------------------------------------------------*/ |
| 134 | |
Sergio Paracuellos | 408fec3f | 2016-11-10 19:16:40 +0100 | [diff] [blame] | 135 | #define WLAN_GET_FC_FTYPE(n) ((((u16)(n)) & GENMASK(3, 2)) >> 2) |
| 136 | #define WLAN_GET_FC_FSTYPE(n) ((((u16)(n)) & GENMASK(7, 4)) >> 4) |
Edgardo Hames | 93df38e | 2010-07-30 22:51:55 -0300 | [diff] [blame] | 137 | #define WLAN_GET_FC_TODS(n) ((((u16)(n)) & (BIT(8))) >> 8) |
Moritz Muehlenhoff | 7f6e0e4 | 2009-01-25 21:54:55 +0100 | [diff] [blame] | 138 | #define WLAN_GET_FC_FROMDS(n) ((((u16)(n)) & (BIT(9))) >> 9) |
Moritz Muehlenhoff | 7f6e0e4 | 2009-01-25 21:54:55 +0100 | [diff] [blame] | 139 | #define WLAN_GET_FC_ISWEP(n) ((((u16)(n)) & (BIT(14))) >> 14) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 140 | |
Solomon Peachy | aaad430 | 2008-10-29 10:42:53 -0400 | [diff] [blame] | 141 | #define WLAN_SET_FC_FTYPE(n) (((u16)(n)) << 2) |
| 142 | #define WLAN_SET_FC_FSTYPE(n) (((u16)(n)) << 4) |
Edgardo Hames | 93df38e | 2010-07-30 22:51:55 -0300 | [diff] [blame] | 143 | #define WLAN_SET_FC_TODS(n) (((u16)(n)) << 8) |
Solomon Peachy | aaad430 | 2008-10-29 10:42:53 -0400 | [diff] [blame] | 144 | #define WLAN_SET_FC_FROMDS(n) (((u16)(n)) << 9) |
Solomon Peachy | aaad430 | 2008-10-29 10:42:53 -0400 | [diff] [blame] | 145 | #define WLAN_SET_FC_ISWEP(n) (((u16)(n)) << 14) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 146 | |
Moritz Muehlenhoff | 7f6e0e4 | 2009-01-25 21:54:55 +0100 | [diff] [blame] | 147 | #define DOT11_RATE5_ISBASIC_GET(r) (((u8)(r)) & BIT(7)) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 148 | |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 149 | /* Generic 802.11 Header types */ |
| 150 | |
Edgardo Hames | 93df38e | 2010-07-30 22:51:55 -0300 | [diff] [blame] | 151 | struct p80211_hdr_a3 { |
Ebru Akagunduz | f474f5e | 2014-10-25 13:16:42 +0300 | [diff] [blame] | 152 | __le16 fc; |
Moritz Muehlenhoff | d6c82d9 | 2009-02-08 02:20:54 +0100 | [diff] [blame] | 153 | u16 dur; |
| 154 | u8 a1[ETH_ALEN]; |
| 155 | u8 a2[ETH_ALEN]; |
| 156 | u8 a3[ETH_ALEN]; |
| 157 | u16 seq; |
Bas van den Berg | 7d3864d | 2011-02-03 21:37:16 +0100 | [diff] [blame] | 158 | } __packed; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 159 | |
Edgardo Hames | 93df38e | 2010-07-30 22:51:55 -0300 | [diff] [blame] | 160 | struct p80211_hdr_a4 { |
Moritz Muehlenhoff | d6c82d9 | 2009-02-08 02:20:54 +0100 | [diff] [blame] | 161 | u16 fc; |
| 162 | u16 dur; |
| 163 | u8 a1[ETH_ALEN]; |
| 164 | u8 a2[ETH_ALEN]; |
| 165 | u8 a3[ETH_ALEN]; |
| 166 | u16 seq; |
| 167 | u8 a4[ETH_ALEN]; |
Bas van den Berg | 7d3864d | 2011-02-03 21:37:16 +0100 | [diff] [blame] | 168 | } __packed; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 169 | |
Edgardo Hames | 93df38e | 2010-07-30 22:51:55 -0300 | [diff] [blame] | 170 | union p80211_hdr { |
| 171 | struct p80211_hdr_a3 a3; |
| 172 | struct p80211_hdr_a4 a4; |
Bas van den Berg | 7d3864d | 2011-02-03 21:37:16 +0100 | [diff] [blame] | 173 | } __packed; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 174 | |
Moritz Muehlenhoff | d6c82d9 | 2009-02-08 02:20:54 +0100 | [diff] [blame] | 175 | /* Frame and header length macros */ |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 176 | |
Tim Collier | 9e5ffff | 2018-06-22 20:39:32 +0100 | [diff] [blame] | 177 | static inline u16 wlan_ctl_framelen(u16 fstype) |
| 178 | { |
| 179 | switch (fstype) { |
| 180 | case WLAN_FSTYPE_BLOCKACKREQ: |
| 181 | return 24; |
| 182 | case WLAN_FSTYPE_BLOCKACK: |
| 183 | return 152; |
| 184 | case WLAN_FSTYPE_PSPOLL: |
| 185 | case WLAN_FSTYPE_RTS: |
| 186 | case WLAN_FSTYPE_CFEND: |
| 187 | case WLAN_FSTYPE_CFENDCFACK: |
| 188 | return 20; |
| 189 | case WLAN_FSTYPE_CTS: |
| 190 | case WLAN_FSTYPE_ACK: |
| 191 | return 14; |
| 192 | default: |
| 193 | return 4; |
| 194 | } |
| 195 | } |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 196 | |
| 197 | #define WLAN_FCS_LEN 4 |
| 198 | |
| 199 | /* ftcl in HOST order */ |
Moritz Muehlenhoff | d6c82d9 | 2009-02-08 02:20:54 +0100 | [diff] [blame] | 200 | static inline u16 p80211_headerlen(u16 fctl) |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 201 | { |
Solomon Peachy | aaad430 | 2008-10-29 10:42:53 -0400 | [diff] [blame] | 202 | u16 hdrlen = 0; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 203 | |
Moritz Muehlenhoff | d6c82d9 | 2009-02-08 02:20:54 +0100 | [diff] [blame] | 204 | switch (WLAN_GET_FC_FTYPE(fctl)) { |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 205 | case WLAN_FTYPE_MGMT: |
| 206 | hdrlen = WLAN_HDR_A3_LEN; |
| 207 | break; |
| 208 | case WLAN_FTYPE_DATA: |
| 209 | hdrlen = WLAN_HDR_A3_LEN; |
Moritz Muehlenhoff | d6c82d9 | 2009-02-08 02:20:54 +0100 | [diff] [blame] | 210 | if (WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl)) |
Moritz Muehlenhoff | 28b17a4 | 2009-01-21 22:00:41 +0100 | [diff] [blame] | 211 | hdrlen += ETH_ALEN; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 212 | break; |
| 213 | case WLAN_FTYPE_CTL: |
Tim Collier | 9e5ffff | 2018-06-22 20:39:32 +0100 | [diff] [blame] | 214 | hdrlen = wlan_ctl_framelen(WLAN_GET_FC_FSTYPE(fctl)) - |
Moritz Muehlenhoff | d6c82d9 | 2009-02-08 02:20:54 +0100 | [diff] [blame] | 215 | WLAN_FCS_LEN; |
Greg Kroah-Hartman | 00b3ed1 | 2008-10-02 11:29:28 -0700 | [diff] [blame] | 216 | break; |
| 217 | default: |
| 218 | hdrlen = WLAN_HDR_A3_LEN; |
| 219 | } |
| 220 | |
| 221 | return hdrlen; |
| 222 | } |
| 223 | |
| 224 | #endif /* _P80211HDR_H */ |