Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */
0002 /*
0003  *
0004  * Macros, types, and functions for handling 802.11 MAC headers
0005  *
0006  * Copyright (C) 1999 AbsoluteValue Systems, Inc.  All Rights Reserved.
0007  * --------------------------------------------------------------------
0008  *
0009  * linux-wlan
0010  *
0011  *   The contents of this file are subject to the Mozilla Public
0012  *   License Version 1.1 (the "License"); you may not use this file
0013  *   except in compliance with the License. You may obtain a copy of
0014  *   the License at http://www.mozilla.org/MPL/
0015  *
0016  *   Software distributed under the License is distributed on an "AS
0017  *   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
0018  *   implied. See the License for the specific language governing
0019  *   rights and limitations under the License.
0020  *
0021  *   Alternatively, the contents of this file may be used under the
0022  *   terms of the GNU Public License version 2 (the "GPL"), in which
0023  *   case the provisions of the GPL are applicable instead of the
0024  *   above.  If you wish to allow the use of your version of this file
0025  *   only under the terms of the GPL and not to allow others to use
0026  *   your version of this file under the MPL, indicate your decision
0027  *   by deleting the provisions above and replace them with the notice
0028  *   and other provisions required by the GPL.  If you do not delete
0029  *   the provisions above, a recipient may use your version of this
0030  *   file under either the MPL or the GPL.
0031  *
0032  * --------------------------------------------------------------------
0033  *
0034  * Inquiries regarding the linux-wlan Open Source project can be
0035  * made directly to:
0036  *
0037  * AbsoluteValue Systems Inc.
0038  * info@linux-wlan.com
0039  * http://www.linux-wlan.com
0040  *
0041  * --------------------------------------------------------------------
0042  *
0043  * Portions of the development of this software were funded by
0044  * Intersil Corporation as part of PRISM(R) chipset product development.
0045  *
0046  * --------------------------------------------------------------------
0047  *
0048  * This file declares the constants and types used in the interface
0049  * between a wlan driver and the user mode utilities.
0050  *
0051  * Note:
0052  *  - Constant values are always in HOST byte order.  To assign
0053  *    values to multi-byte fields they _must_ be converted to
0054  *    ieee byte order.  To retrieve multi-byte values from incoming
0055  *    frames, they must be converted to host order.
0056  *
0057  * All functions declared here are implemented in p80211.c
0058  * --------------------------------------------------------------------
0059  */
0060 
0061 #ifndef _P80211HDR_H
0062 #define _P80211HDR_H
0063 
0064 #include <linux/if_ether.h>
0065 
0066 /*--- Sizes -----------------------------------------------*/
0067 #define WLAN_CRC_LEN            4
0068 #define WLAN_BSSID_LEN          6
0069 #define WLAN_HDR_A3_LEN         24
0070 #define WLAN_HDR_A4_LEN         30
0071 #define WLAN_SSID_MAXLEN        32
0072 #define WLAN_DATA_MAXLEN        2312
0073 #define WLAN_WEP_IV_LEN         4
0074 #define WLAN_WEP_ICV_LEN        4
0075 
0076 /*--- Frame Control Field -------------------------------------*/
0077 /* Frame Types */
0078 #define WLAN_FTYPE_MGMT         0x00
0079 #define WLAN_FTYPE_CTL          0x01
0080 #define WLAN_FTYPE_DATA         0x02
0081 
0082 /* Frame subtypes */
0083 /* Management */
0084 #define WLAN_FSTYPE_ASSOCREQ        0x00
0085 #define WLAN_FSTYPE_ASSOCRESP       0x01
0086 #define WLAN_FSTYPE_REASSOCREQ      0x02
0087 #define WLAN_FSTYPE_REASSOCRESP     0x03
0088 #define WLAN_FSTYPE_PROBEREQ        0x04
0089 #define WLAN_FSTYPE_PROBERESP       0x05
0090 #define WLAN_FSTYPE_BEACON      0x08
0091 #define WLAN_FSTYPE_ATIM        0x09
0092 #define WLAN_FSTYPE_DISASSOC        0x0a
0093 #define WLAN_FSTYPE_AUTHEN      0x0b
0094 #define WLAN_FSTYPE_DEAUTHEN        0x0c
0095 
0096 /* Control */
0097 #define WLAN_FSTYPE_BLOCKACKREQ     0x8
0098 #define WLAN_FSTYPE_BLOCKACK        0x9
0099 #define WLAN_FSTYPE_PSPOLL      0x0a
0100 #define WLAN_FSTYPE_RTS         0x0b
0101 #define WLAN_FSTYPE_CTS         0x0c
0102 #define WLAN_FSTYPE_ACK         0x0d
0103 #define WLAN_FSTYPE_CFEND       0x0e
0104 #define WLAN_FSTYPE_CFENDCFACK      0x0f
0105 
0106 /* Data */
0107 #define WLAN_FSTYPE_DATAONLY        0x00
0108 #define WLAN_FSTYPE_DATA_CFACK      0x01
0109 #define WLAN_FSTYPE_DATA_CFPOLL     0x02
0110 #define WLAN_FSTYPE_DATA_CFACK_CFPOLL   0x03
0111 #define WLAN_FSTYPE_NULL        0x04
0112 #define WLAN_FSTYPE_CFACK       0x05
0113 #define WLAN_FSTYPE_CFPOLL      0x06
0114 #define WLAN_FSTYPE_CFACK_CFPOLL    0x07
0115 
0116 /*--- FC Macros ----------------------------------------------*/
0117 /* Macros to get/set the bitfields of the Frame Control Field */
0118 /*  GET_FC_??? - takes the host byte-order value of an FC     */
0119 /*               and retrieves the value of one of the        */
0120 /*               bitfields and moves that value so its lsb is */
0121 /*               in bit 0.                                    */
0122 /*  SET_FC_??? - takes a host order value for one of the FC   */
0123 /*               bitfields and moves it to the proper bit     */
0124 /*               location for ORing into a host order FC.     */
0125 /*               To send the FC produced from SET_FC_???,     */
0126 /*               one must put the bytes in IEEE order.        */
0127 /*  e.g.                                                      */
0128 /*     printf("the frame subtype is %x",                      */
0129 /*                 GET_FC_FTYPE( ieee2host( rx.fc )))         */
0130 /*                                                            */
0131 /*     tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) |       */
0132 /*                        SET_FC_FSTYPE(WLAN_FSTYPE_RTS) );   */
0133 /*------------------------------------------------------------*/
0134 
0135 #define WLAN_GET_FC_FTYPE(n)    ((((u16)(n)) & GENMASK(3, 2)) >> 2)
0136 #define WLAN_GET_FC_FSTYPE(n)   ((((u16)(n)) & GENMASK(7, 4)) >> 4)
0137 #define WLAN_GET_FC_TODS(n) ((((u16)(n)) & (BIT(8))) >> 8)
0138 #define WLAN_GET_FC_FROMDS(n)   ((((u16)(n)) & (BIT(9))) >> 9)
0139 #define WLAN_GET_FC_ISWEP(n)    ((((u16)(n)) & (BIT(14))) >> 14)
0140 
0141 #define WLAN_SET_FC_FTYPE(n)    (((u16)(n)) << 2)
0142 #define WLAN_SET_FC_FSTYPE(n)   (((u16)(n)) << 4)
0143 #define WLAN_SET_FC_TODS(n) (((u16)(n)) << 8)
0144 #define WLAN_SET_FC_FROMDS(n)   (((u16)(n)) << 9)
0145 #define WLAN_SET_FC_ISWEP(n)    (((u16)(n)) << 14)
0146 
0147 #define DOT11_RATE5_ISBASIC_GET(r)     (((u8)(r)) & BIT(7))
0148 
0149 /* Generic 802.11 Header types */
0150 
0151 struct p80211_hdr {
0152     __le16  frame_control;
0153     u16 duration_id;
0154     u8  address1[ETH_ALEN];
0155     u8  address2[ETH_ALEN];
0156     u8  address3[ETH_ALEN];
0157     u16 sequence_control;
0158     u8  address4[ETH_ALEN];
0159 } __packed;
0160 
0161 /* Frame and header length macros */
0162 
0163 static inline u16 wlan_ctl_framelen(u16 fstype)
0164 {
0165     switch (fstype) {
0166     case WLAN_FSTYPE_BLOCKACKREQ:
0167         return 24;
0168     case WLAN_FSTYPE_BLOCKACK:
0169         return 152;
0170     case WLAN_FSTYPE_PSPOLL:
0171     case WLAN_FSTYPE_RTS:
0172     case WLAN_FSTYPE_CFEND:
0173     case WLAN_FSTYPE_CFENDCFACK:
0174         return 20;
0175     case WLAN_FSTYPE_CTS:
0176     case WLAN_FSTYPE_ACK:
0177         return 14;
0178     default:
0179         return 4;
0180     }
0181 }
0182 
0183 #define WLAN_FCS_LEN            4
0184 
0185 /* ftcl in HOST order */
0186 static inline u16 p80211_headerlen(u16 fctl)
0187 {
0188     u16 hdrlen = 0;
0189 
0190     switch (WLAN_GET_FC_FTYPE(fctl)) {
0191     case WLAN_FTYPE_MGMT:
0192         hdrlen = WLAN_HDR_A3_LEN;
0193         break;
0194     case WLAN_FTYPE_DATA:
0195         hdrlen = WLAN_HDR_A3_LEN;
0196         if (WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl))
0197             hdrlen += ETH_ALEN;
0198         break;
0199     case WLAN_FTYPE_CTL:
0200         hdrlen = wlan_ctl_framelen(WLAN_GET_FC_FSTYPE(fctl)) -
0201             WLAN_FCS_LEN;
0202         break;
0203     default:
0204         hdrlen = WLAN_HDR_A3_LEN;
0205     }
0206 
0207     return hdrlen;
0208 }
0209 
0210 #endif /* _P80211HDR_H */