Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/drivers/net/ieee80211_standard.h need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 /*
0019  * IEEE 802.11 defines
0020  *
0021  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
0022  * <jkmaline@cc.hut.fi>
0023  * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
0024  * Copyright (c) 2005, Devicescape Software, Inc.
0025  * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
0026  *
0027  * This program is free software; you can redistribute it and/or modify
0028  * it under the terms of the GNU General Public License version 2 as
0029  * published by the Free Software Foundation.
0030  */
0031 
0032 #ifndef STANDARD_IEEE80211_H
0033 #define STANDARD_IEEE80211_H
0034 
0035 #include <types.h>
0036 
0037 /*
0038  * DS bit usage
0039  *
0040  * TA = transmitter address
0041  * RA = receiver address
0042  * DA = destination address
0043  * SA = source address
0044  *
0045  * ToDS    FromDS  A1(RA)  A2(TA)  A3      A4      Use
0046  * -----------------------------------------------------------------
0047  *  0       0       DA      SA      BSSID   -       IBSS/DLS
0048  *  0       1       DA      BSSID   SA      -       AP -> STA
0049  *  1       0       BSSID   SA      DA      -       AP <- STA
0050  *  1       1       RA      TA      DA      SA      unspecified (WDS)
0051  */
0052 
0053 #define FCS_LEN 4
0054 
0055 #define IEEE80211_FCTL_VERS             0x0003
0056 #define IEEE80211_FCTL_FTYPE            0x000c
0057 #define IEEE80211_FCTL_STYPE            0x00f0
0058 #define IEEE80211_FCTL_TODS             0x0100
0059 #define IEEE80211_FCTL_FROMDS           0x0200
0060 #define IEEE80211_FCTL_MOREFRAGS        0x0400
0061 #define IEEE80211_FCTL_RETRY            0x0800
0062 #define IEEE80211_FCTL_PM               0x1000
0063 #define IEEE80211_FCTL_MOREDATA         0x2000
0064 #define IEEE80211_FCTL_PROTECTED        0x4000
0065 #define IEEE80211_FCTL_ORDER            0x8000
0066 
0067 #define IEEE80211_SCTL_FRAG             0x000F
0068 #define IEEE80211_SCTL_SEQ              0xFFF0
0069 
0070 #define IEEE80211_FTYPE_MGMT            0x0000
0071 #define IEEE80211_FTYPE_CTL             0x0004
0072 #define IEEE80211_FTYPE_DATA            0x0008
0073 
0074 /* management */
0075 #define IEEE80211_STYPE_ASSOC_REQ       0x0000
0076 #define IEEE80211_STYPE_ASSOC_RESP      0x0010
0077 #define IEEE80211_STYPE_REASSOC_REQ     0x0020
0078 #define IEEE80211_STYPE_REASSOC_RESP    0x0030
0079 #define IEEE80211_STYPE_PROBE_REQ       0x0040
0080 #define IEEE80211_STYPE_PROBE_RESP      0x0050
0081 #define IEEE80211_STYPE_BEACON          0x0080
0082 #define IEEE80211_STYPE_ATIM            0x0090
0083 #define IEEE80211_STYPE_DISASSOC        0x00A0
0084 #define IEEE80211_STYPE_AUTH            0x00B0
0085 #define IEEE80211_STYPE_DEAUTH          0x00C0
0086 #define IEEE80211_STYPE_ACTION          0x00D0
0087 
0088 /* control */
0089 #define IEEE80211_STYPE_BACK_REQ        0x0080
0090 #define IEEE80211_STYPE_BACK            0x0090
0091 #define IEEE80211_STYPE_PSPOLL          0x00A0
0092 #define IEEE80211_STYPE_RTS             0x00B0
0093 #define IEEE80211_STYPE_CTS             0x00C0
0094 #define IEEE80211_STYPE_ACK             0x00D0
0095 #define IEEE80211_STYPE_CFEND           0x00E0
0096 #define IEEE80211_STYPE_CFENDACK        0x00F0
0097 
0098 /* data */
0099 #define IEEE80211_STYPE_DATA                    0x0000
0100 #define IEEE80211_STYPE_DATA_CFACK              0x0010
0101 #define IEEE80211_STYPE_DATA_CFPOLL             0x0020
0102 #define IEEE80211_STYPE_DATA_CFACKPOLL          0x0030
0103 #define IEEE80211_STYPE_NULLFUNC                0x0040
0104 #define IEEE80211_STYPE_CFACK                   0x0050
0105 #define IEEE80211_STYPE_CFPOLL                  0x0060
0106 #define IEEE80211_STYPE_CFACKPOLL               0x0070
0107 #define IEEE80211_STYPE_QOS_DATA                0x0080
0108 #define IEEE80211_STYPE_QOS_DATA_CFACK          0x0090
0109 #define IEEE80211_STYPE_QOS_DATA_CFPOLL         0x00A0
0110 #define IEEE80211_STYPE_QOS_DATA_CFACKPOLL      0x00B0
0111 #define IEEE80211_STYPE_QOS_NULLFUNC            0x00C0
0112 #define IEEE80211_STYPE_QOS_CFACK               0x00D0
0113 #define IEEE80211_STYPE_QOS_CFPOLL              0x00E0
0114 #define IEEE80211_STYPE_QOS_CFACKPOLL           0x00F0
0115 
0116 
0117 /* miscellaneous IEEE 802.11 constants */
0118 #define IEEE80211_MAX_FRAG_THRESHOLD    2352
0119 #define IEEE80211_MAX_RTS_THRESHOLD     2353
0120 #define IEEE80211_MAX_AID               2007
0121 #define IEEE80211_MAX_TIM_LEN           251
0122 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
0123    6.2.1.1.2.
0124 
0125    802.11e clarifies the figure in section 7.1.2. The frame body is
0126    up to 2304 octets long (maximum MSDU size) plus any crypt overhead. */
0127 #define IEEE80211_MAX_DATA_LEN          2304
0128 /* 30 byte 4 addr hdr, 2 byte QoS, 2304 byte MSDU, 12 byte crypt, 4 byte FCS */
0129 #define IEEE80211_MAX_FRAME_LEN         2352
0130 
0131 #define IEEE80211_MAX_SSID_LEN          32
0132 
0133 #define IEEE80211_MAX_MESH_ID_LEN       32
0134 #define IEEE80211_MESH_CONFIG_LEN       24
0135 
0136 #define IEEE80211_QOS_CTL_LEN           2
0137 #define IEEE80211_QOS_CTL_TID_MASK      0x000F
0138 #define IEEE80211_QOS_CTL_TAG1D_MASK    0x0007
0139 
0140 struct ieee80211_hdr {
0141   __le16 frame_control;
0142   __le16 duration_id;
0143   u8 addr1[6];
0144   u8 addr2[6];
0145   u8 addr3[6];
0146   __le16 seq_ctrl;
0147   u8 addr4[6];
0148 } __attribute__ ((packed));
0149 
0150 /**
0151  * ieee80211_has_tods - check if IEEE80211_FCTL_TODS is set
0152  * @fc: frame control bytes in little-endian byteorder
0153  */
0154 static inline int ieee80211_has_tods(__le16 fc)
0155 {
0156   return (fc & cpu_to_le16(IEEE80211_FCTL_TODS)) != 0;
0157 }
0158 
0159 /**
0160  * ieee80211_has_fromds - check if IEEE80211_FCTL_FROMDS is set
0161  * @fc: frame control bytes in little-endian byteorder
0162  */
0163 static inline int ieee80211_has_fromds(__le16 fc)
0164 {
0165   return (fc & cpu_to_le16(IEEE80211_FCTL_FROMDS)) != 0;
0166 }
0167 
0168 /**
0169  * ieee80211_has_a4 - check if IEEE80211_FCTL_TODS and IEEE80211_FCTL_FROMDS are set
0170  * @fc: frame control bytes in little-endian byteorder
0171  */
0172 static inline int ieee80211_has_a4(__le16 fc)
0173 {
0174   __le16 tmp = cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS);
0175   return (fc & tmp) == tmp;
0176 }
0177 
0178 /**
0179  * ieee80211_has_morefrags - check if IEEE80211_FCTL_MOREFRAGS is set
0180  * @fc: frame control bytes in little-endian byteorder
0181  */
0182 static inline int ieee80211_has_morefrags(__le16 fc)
0183 {
0184   return (fc & cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) != 0;
0185 }
0186 
0187 /**
0188  * ieee80211_has_retry - check if IEEE80211_FCTL_RETRY is set
0189  * @fc: frame control bytes in little-endian byteorder
0190  */
0191 static inline int ieee80211_has_retry(__le16 fc)
0192 {
0193   return (fc & cpu_to_le16(IEEE80211_FCTL_RETRY)) != 0;
0194 }
0195 
0196 /**
0197  * ieee80211_has_pm - check if IEEE80211_FCTL_PM is set
0198  * @fc: frame control bytes in little-endian byteorder
0199  */
0200 static inline int ieee80211_has_pm(__le16 fc)
0201 {
0202   return (fc & cpu_to_le16(IEEE80211_FCTL_PM)) != 0;
0203 }
0204 
0205 /**
0206  * ieee80211_has_moredata - check if IEEE80211_FCTL_MOREDATA is set
0207  * @fc: frame control bytes in little-endian byteorder
0208  */
0209 static inline int ieee80211_has_moredata(__le16 fc)
0210 {
0211   return (fc & cpu_to_le16(IEEE80211_FCTL_MOREDATA)) != 0;
0212 }
0213 
0214 /**
0215  * ieee80211_has_protected - check if IEEE80211_FCTL_PROTECTED is set
0216  * @fc: frame control bytes in little-endian byteorder
0217  */
0218 static inline int ieee80211_has_protected(__le16 fc)
0219 {
0220   return (fc & cpu_to_le16(IEEE80211_FCTL_PROTECTED)) != 0;
0221 }
0222 
0223 /**
0224  * ieee80211_has_order - check if IEEE80211_FCTL_ORDER is set
0225  * @fc: frame control bytes in little-endian byteorder
0226  */
0227 static inline int ieee80211_has_order(__le16 fc)
0228 {
0229   return (fc & cpu_to_le16(IEEE80211_FCTL_ORDER)) != 0;
0230 }
0231 
0232 /**
0233  * ieee80211_is_mgmt - check if type is IEEE80211_FTYPE_MGMT
0234  * @fc: frame control bytes in little-endian byteorder
0235  */
0236 static inline int ieee80211_is_mgmt(__le16 fc)
0237 {
0238   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
0239     cpu_to_le16(IEEE80211_FTYPE_MGMT);
0240 }
0241 
0242 /**
0243  * ieee80211_is_ctl - check if type is IEEE80211_FTYPE_CTL
0244  * @fc: frame control bytes in little-endian byteorder
0245  */
0246 static inline int ieee80211_is_ctl(__le16 fc)
0247 {
0248   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
0249     cpu_to_le16(IEEE80211_FTYPE_CTL);
0250 }
0251 
0252 /**
0253  * ieee80211_is_data - check if type is IEEE80211_FTYPE_DATA
0254  * @fc: frame control bytes in little-endian byteorder
0255  */
0256 static inline int ieee80211_is_data(__le16 fc)
0257 {
0258   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
0259     cpu_to_le16(IEEE80211_FTYPE_DATA);
0260 }
0261 
0262 /**
0263  * ieee80211_is_data_qos - check if type is IEEE80211_FTYPE_DATA and IEEE80211_STYPE_QOS_DATA is set
0264  * @fc: frame control bytes in little-endian byteorder
0265  */
0266 static inline int ieee80211_is_data_qos(__le16 fc)
0267 {
0268   /*
0269    * mask with QOS_DATA rather than IEEE80211_FCTL_STYPE as we just need
0270    * to check the one bit
0271    */
0272   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_STYPE_QOS_DATA)) ==
0273     cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA);
0274 }
0275 
0276 /**
0277  * ieee80211_is_data_present - check if type is IEEE80211_FTYPE_DATA and has data
0278  * @fc: frame control bytes in little-endian byteorder
0279  */
0280 static inline int ieee80211_is_data_present(__le16 fc)
0281 {
0282   /*
0283    * mask with 0x40 and test that that bit is clear to only return true
0284    * for the data-containing substypes.
0285    */
0286   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | 0x40)) ==
0287     cpu_to_le16(IEEE80211_FTYPE_DATA);
0288 }
0289 
0290 /**
0291  * ieee80211_is_assoc_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ASSOC_REQ
0292  * @fc: frame control bytes in little-endian byteorder
0293  */
0294 static inline int ieee80211_is_assoc_req(__le16 fc)
0295 {
0296   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0297     cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ASSOC_REQ);
0298 }
0299 
0300 /**
0301  * ieee80211_is_assoc_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ASSOC_RESP
0302  * @fc: frame control bytes in little-endian byteorder
0303  */
0304 static inline int ieee80211_is_assoc_resp(__le16 fc)
0305 {
0306   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0307     cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ASSOC_RESP);
0308 }
0309 
0310 /**
0311  * ieee80211_is_reassoc_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_REASSOC_REQ
0312  * @fc: frame control bytes in little-endian byteorder
0313  */
0314 static inline int ieee80211_is_reassoc_req(__le16 fc)
0315 {
0316   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0317     cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_REASSOC_REQ);
0318 }
0319 
0320 /**
0321  * ieee80211_is_reassoc_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_REASSOC_RESP
0322  * @fc: frame control bytes in little-endian byteorder
0323  */
0324 static inline int ieee80211_is_reassoc_resp(__le16 fc)
0325 {
0326   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0327     cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_REASSOC_RESP);
0328 }
0329 
0330 /**
0331  * ieee80211_is_probe_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_PROBE_REQ
0332  * @fc: frame control bytes in little-endian byteorder
0333  */
0334 static inline int ieee80211_is_probe_req(__le16 fc)
0335 {
0336   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0337     cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ);
0338 }
0339 
0340 /**
0341  * ieee80211_is_probe_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_PROBE_RESP
0342  * @fc: frame control bytes in little-endian byteorder
0343  */
0344 static inline int ieee80211_is_probe_resp(__le16 fc)
0345 {
0346   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0347     cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
0348 }
0349 
0350 /**
0351  * ieee80211_is_beacon - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_BEACON
0352  * @fc: frame control bytes in little-endian byteorder
0353  */
0354 static inline int ieee80211_is_beacon(__le16 fc)
0355 {
0356   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0357     cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
0358 }
0359 
0360 /**
0361  * ieee80211_is_atim - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ATIM
0362  * @fc: frame control bytes in little-endian byteorder
0363  */
0364 static inline int ieee80211_is_atim(__le16 fc)
0365 {
0366   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0367     cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ATIM);
0368 }
0369 
0370 /**
0371  * ieee80211_is_disassoc - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_DISASSOC
0372  * @fc: frame control bytes in little-endian byteorder
0373  */
0374 static inline int ieee80211_is_disassoc(__le16 fc)
0375 {
0376   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0377     cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DISASSOC);
0378 }
0379 
0380 /**
0381  * ieee80211_is_auth - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_AUTH
0382  * @fc: frame control bytes in little-endian byteorder
0383  */
0384 static inline int ieee80211_is_auth(__le16 fc)
0385 {
0386   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0387     cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH);
0388 }
0389 
0390 /**
0391  * ieee80211_is_deauth - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_DEAUTH
0392  * @fc: frame control bytes in little-endian byteorder
0393  */
0394 static inline int ieee80211_is_deauth(__le16 fc)
0395 {
0396   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0397     cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH);
0398 }
0399 
0400 /**
0401  * ieee80211_is_action - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ACTION
0402  * @fc: frame control bytes in little-endian byteorder
0403  */
0404 static inline int ieee80211_is_action(__le16 fc)
0405 {
0406   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0407     cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION);
0408 }
0409 
0410 /**
0411  * ieee80211_is_back_req - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_BACK_REQ
0412  * @fc: frame control bytes in little-endian byteorder
0413  */
0414 static inline int ieee80211_is_back_req(__le16 fc)
0415 {
0416   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0417     cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK_REQ);
0418 }
0419 
0420 /**
0421  * ieee80211_is_back - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_BACK
0422  * @fc: frame control bytes in little-endian byteorder
0423  */
0424 static inline int ieee80211_is_back(__le16 fc)
0425 {
0426   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0427     cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK);
0428 }
0429 
0430 /**
0431  * ieee80211_is_pspoll - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_PSPOLL
0432  * @fc: frame control bytes in little-endian byteorder
0433  */
0434 static inline int ieee80211_is_pspoll(__le16 fc)
0435 {
0436   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0437     cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
0438 }
0439 
0440 /**
0441  * ieee80211_is_rts - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_RTS
0442  * @fc: frame control bytes in little-endian byteorder
0443  */
0444 static inline int ieee80211_is_rts(__le16 fc)
0445 {
0446   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0447     cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
0448 }
0449 
0450 /**
0451  * ieee80211_is_cts - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CTS
0452  * @fc: frame control bytes in little-endian byteorder
0453  */
0454 static inline int ieee80211_is_cts(__le16 fc)
0455 {
0456   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0457     cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
0458 }
0459 
0460 /**
0461  * ieee80211_is_ack - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_ACK
0462  * @fc: frame control bytes in little-endian byteorder
0463  */
0464 static inline int ieee80211_is_ack(__le16 fc)
0465 {
0466   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0467     cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK);
0468 }
0469 
0470 /**
0471  * ieee80211_is_cfend - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CFEND
0472  * @fc: frame control bytes in little-endian byteorder
0473  */
0474 static inline int ieee80211_is_cfend(__le16 fc)
0475 {
0476   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0477     cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CFEND);
0478 }
0479 
0480 /**
0481  * ieee80211_is_cfendack - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CFENDACK
0482  * @fc: frame control bytes in little-endian byteorder
0483  */
0484 static inline int ieee80211_is_cfendack(__le16 fc)
0485 {
0486   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0487     cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CFENDACK);
0488 }
0489 
0490 /**
0491  * ieee80211_is_nullfunc - check if FTYPE=IEEE80211_FTYPE_DATA and STYPE=IEEE80211_STYPE_NULLFUNC
0492  * @fc: frame control bytes in little-endian byteorder
0493  */
0494 static inline int ieee80211_is_nullfunc(__le16 fc)
0495 {
0496   return (fc & cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
0497     cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC);
0498 }
0499 
0500 struct ieee80211s_hdr {
0501   u8 flags;
0502   u8 ttl;
0503   __le32 seqnum;
0504   u8 eaddr1[6];
0505   u8 eaddr2[6];
0506   u8 eaddr3[6];
0507 } __attribute__ ((packed));
0508 
0509 /* Mesh flags */
0510 #define MESH_FLAGS_AE_A4        0x1
0511 #define MESH_FLAGS_AE_A5_A6     0x2
0512 #define MESH_FLAGS_AE           0x3
0513 #define MESH_FLAGS_PS_DEEP      0x4
0514 
0515 /**
0516  * struct ieee80211_quiet_ie
0517  *
0518  * This structure refers to "Quiet information element"
0519  */
0520 struct ieee80211_quiet_ie {
0521   u8 count;
0522   u8 period;
0523   __le16 duration;
0524   __le16 offset;
0525 } __attribute__ ((packed));
0526 
0527 /**
0528  * struct ieee80211_msrment_ie
0529  *
0530  * This structure refers to "Measurement Request/Report information element"
0531  */
0532 struct ieee80211_msrment_ie {
0533   u8 token;
0534   u8 mode;
0535   u8 type;
0536   u8 request[0];
0537 } __attribute__ ((packed));
0538 
0539 /**
0540  * struct ieee80211_channel_sw_ie
0541  *
0542  * This structure refers to "Channel Switch Announcement information element"
0543  */
0544 struct ieee80211_channel_sw_ie {
0545   u8 mode;
0546   u8 new_ch_num;
0547   u8 count;
0548 } __attribute__ ((packed));
0549 
0550 /**
0551  * struct ieee80211_tim
0552  *
0553  * This structure refers to "Traffic Indication Map information element"
0554  */
0555 struct ieee80211_tim_ie {
0556   u8 dtim_count;
0557   u8 dtim_period;
0558   u8 bitmap_ctrl;
0559   /* variable size: 1 - 251 bytes */
0560   u8 virtual_map[1];
0561 } __attribute__ ((packed));
0562 
0563 #define WLAN_SA_QUERY_TR_ID_LEN 2
0564 
0565 struct ieee80211_mgmt {
0566   __le16 frame_control;
0567   __le16 duration;
0568   u8 da[6];
0569   u8 sa[6];
0570   u8 bssid[6];
0571   __le16 seq_ctrl;
0572   union {
0573     struct {
0574       __le16 auth_alg;
0575       __le16 auth_transaction;
0576       __le16 status_code;
0577       /* possibly followed by Challenge text */
0578       u8 variable[0];
0579     } __attribute__ ((packed)) auth;
0580     struct {
0581       __le16 reason_code;
0582     } __attribute__ ((packed)) deauth;
0583     struct {
0584       __le16 capab_info;
0585       __le16 listen_interval;
0586       /* followed by SSID and Supported rates */
0587       u8 variable[0];
0588     } __attribute__ ((packed)) assoc_req;
0589     struct {
0590       __le16 capab_info;
0591       __le16 status_code;
0592       __le16 aid;
0593       /* followed by Supported rates */
0594       u8 variable[0];
0595     } __attribute__ ((packed)) assoc_resp, reassoc_resp;
0596     struct {
0597       __le16 capab_info;
0598       __le16 listen_interval;
0599       u8 current_ap[6];
0600       /* followed by SSID and Supported rates */
0601       u8 variable[0];
0602     } __attribute__ ((packed)) reassoc_req;
0603     struct {
0604       __le16 reason_code;
0605     } __attribute__ ((packed)) disassoc;
0606     struct {
0607       __le64 timestamp;
0608       __le16 beacon_int;
0609       __le16 capab_info;
0610       /* followed by some of SSID, Supported rates,
0611        * FH Params, DS Params, CF Params, IBSS Params, TIM */
0612       u8 variable[0];
0613     } __attribute__ ((packed)) beacon;
0614     struct {
0615       /* only variable items: SSID, Supported rates */
0616       u8 variable[0];
0617     } __attribute__ ((packed)) probe_req;
0618     struct {
0619       __le64 timestamp;
0620       __le16 beacon_int;
0621       __le16 capab_info;
0622       /* followed by some of SSID, Supported rates,
0623        * FH Params, DS Params, CF Params, IBSS Params */
0624       u8 variable[0];
0625     } __attribute__ ((packed)) probe_resp;
0626     struct {
0627       u8 category;
0628       union {
0629         struct {
0630           u8 action_code;
0631           u8 dialog_token;
0632           u8 status_code;
0633           u8 variable[0];
0634         } __attribute__ ((packed)) wme_action;
0635         struct{
0636           u8 action_code;
0637           u8 element_id;
0638           u8 length;
0639           struct ieee80211_channel_sw_ie sw_elem;
0640         } __attribute__((packed)) chan_switch;
0641         struct{
0642           u8 action_code;
0643           u8 dialog_token;
0644           u8 element_id;
0645           u8 length;
0646           struct ieee80211_msrment_ie msr_elem;
0647         } __attribute__((packed)) measurement;
0648         struct{
0649           u8 action_code;
0650           u8 dialog_token;
0651           __le16 capab;
0652           __le16 timeout;
0653           __le16 start_seq_num;
0654         } __attribute__((packed)) addba_req;
0655         struct{
0656           u8 action_code;
0657           u8 dialog_token;
0658           __le16 status;
0659           __le16 capab;
0660           __le16 timeout;
0661         } __attribute__((packed)) addba_resp;
0662         struct{
0663           u8 action_code;
0664           __le16 params;
0665           __le16 reason_code;
0666         } __attribute__((packed)) delba;
0667         struct{
0668           u8 action_code;
0669           /* capab_info for open and confirm,
0670            * reason for close
0671            */
0672           __le16 aux;
0673           /* Followed in plink_confirm by status
0674            * code, AID and supported rates,
0675            * and directly by supported rates in
0676            * plink_open and plink_close
0677            */
0678           u8 variable[0];
0679         } __attribute__((packed)) plink_action;
0680         struct{
0681           u8 action_code;
0682           u8 variable[0];
0683         } __attribute__((packed)) mesh_action;
0684         struct {
0685           u8 action;
0686           u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];
0687         } __attribute__ ((packed)) sa_query;
0688       } u;
0689     } __attribute__ ((packed)) action;
0690   } u;
0691 } __attribute__ ((packed));
0692 
0693 /* mgmt header + 1 byte category code */
0694 #define IEEE80211_MIN_ACTION_SIZE offsetof(struct ieee80211_mgmt, u.action.u)
0695 
0696 
0697 /* Management MIC information element (IEEE 802.11w) */
0698 struct ieee80211_mmie {
0699   u8 element_id;
0700   u8 length;
0701   __le16 key_id;
0702   u8 sequence_number[6];
0703   u8 mic[8];
0704 } __attribute__ ((packed));
0705 
0706 /* Control frames */
0707 struct ieee80211_rts {
0708   __le16 frame_control;
0709   __le16 duration;
0710   u8 ra[6];
0711   u8 ta[6];
0712 } __attribute__ ((packed));
0713 
0714 struct ieee80211_cts {
0715   __le16 frame_control;
0716   __le16 duration;
0717   u8 ra[6];
0718 } __attribute__ ((packed));
0719 
0720 struct ieee80211_pspoll {
0721   __le16 frame_control;
0722   __le16 aid;
0723   u8 bssid[6];
0724   u8 ta[6];
0725 } __attribute__ ((packed));
0726 
0727 /**
0728  * struct ieee80211_bar - HT Block Ack Request
0729  *
0730  * This structure refers to "HT BlockAckReq" as
0731  * described in 802.11n draft section 7.2.1.7.1
0732  */
0733 struct ieee80211_bar {
0734   __le16 frame_control;
0735   __le16 duration;
0736   u8 ra[6];
0737   u8 ta[6];
0738   __le16 control;
0739   __le16 start_seq_num;
0740 } __attribute__((packed));
0741 
0742 /* 802.11 BAR control masks */
0743 #define IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL     0x0000
0744 #define IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA  0x0004
0745 
0746 
0747 #define IEEE80211_HT_MCS_MASK_LEN               10
0748 
0749 /**
0750  * struct ieee80211_mcs_info - MCS information
0751  * @rx_mask: RX mask
0752  * @rx_highest: highest supported RX rate
0753  * @tx_params: TX parameters
0754  */
0755 struct ieee80211_mcs_info {
0756   u8 rx_mask[IEEE80211_HT_MCS_MASK_LEN];
0757   __le16 rx_highest;
0758   u8 tx_params;
0759   u8 reserved[3];
0760 } __attribute__((packed));
0761 
0762 /* 802.11n HT capability MSC set */
0763 #define IEEE80211_HT_MCS_RX_HIGHEST_MASK        0x3ff
0764 #define IEEE80211_HT_MCS_TX_DEFINED             0x01
0765 #define IEEE80211_HT_MCS_TX_RX_DIFF             0x02
0766 /* value 0 == 1 stream etc */
0767 #define IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK    0x0C
0768 #define IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT   2
0769 #define         IEEE80211_HT_MCS_TX_MAX_STREAMS 4
0770 #define IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION  0x10
0771 
0772 /*
0773  * 802.11n D5.0 20.3.5 / 20.6 says:
0774  * - indices 0 to 7 and 32 are single spatial stream
0775  * - 8 to 31 are multiple spatial streams using equal modulation
0776  *   [8..15 for two streams, 16..23 for three and 24..31 for four]
0777  * - remainder are multiple spatial streams using unequal modulation
0778  */
0779 #define IEEE80211_HT_MCS_UNEQUAL_MODULATION_START 33
0780 #define IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE  \
0781   (IEEE80211_HT_MCS_UNEQUAL_MODULATION_START / 8)
0782 
0783 /**
0784  * struct ieee80211_ht_cap - HT capabilities
0785  *
0786  * This structure is the "HT capabilities element" as
0787  * described in 802.11n D5.0 7.3.2.57
0788  */
0789 struct ieee80211_ht_cap {
0790   __le16 cap_info;
0791   u8 ampdu_params_info;
0792 
0793   /* 16 bytes MCS information */
0794   struct ieee80211_mcs_info mcs;
0795 
0796   __le16 extended_ht_cap_info;
0797   __le32 tx_BF_cap_info;
0798   u8 antenna_selection_info;
0799 } __attribute__ ((packed));
0800 
0801 /* 802.11n HT capabilities masks (for cap_info) */
0802 #define IEEE80211_HT_CAP_LDPC_CODING            0x0001
0803 #define IEEE80211_HT_CAP_SUP_WIDTH_20_40        0x0002
0804 #define IEEE80211_HT_CAP_SM_PS                  0x000C
0805 #define IEEE80211_HT_CAP_GRN_FLD                0x0010
0806 #define IEEE80211_HT_CAP_SGI_20                 0x0020
0807 #define IEEE80211_HT_CAP_SGI_40                 0x0040
0808 #define IEEE80211_HT_CAP_TX_STBC                0x0080
0809 #define IEEE80211_HT_CAP_RX_STBC                0x0300
0810 #define IEEE80211_HT_CAP_DELAY_BA               0x0400
0811 #define IEEE80211_HT_CAP_MAX_AMSDU              0x0800
0812 #define IEEE80211_HT_CAP_DSSSCCK40              0x1000
0813 #define IEEE80211_HT_CAP_PSMP_SUPPORT           0x2000
0814 #define IEEE80211_HT_CAP_40MHZ_INTOLERANT       0x4000
0815 #define IEEE80211_HT_CAP_LSIG_TXOP_PROT         0x8000
0816 
0817 /* 802.11n HT capability AMPDU settings (for ampdu_params_info) */
0818 #define IEEE80211_HT_AMPDU_PARM_FACTOR          0x03
0819 #define IEEE80211_HT_AMPDU_PARM_DENSITY         0x1C
0820 
0821 /*
0822  * Maximum length of AMPDU that the STA can receive.
0823  * Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
0824  */
0825 enum ieee80211_max_ampdu_length_exp {
0826   IEEE80211_HT_MAX_AMPDU_8K = 0,
0827   IEEE80211_HT_MAX_AMPDU_16K = 1,
0828   IEEE80211_HT_MAX_AMPDU_32K = 2,
0829   IEEE80211_HT_MAX_AMPDU_64K = 3
0830 };
0831 
0832 #define IEEE80211_HT_MAX_AMPDU_FACTOR 13
0833 
0834 /* Minimum MPDU start spacing */
0835 enum ieee80211_min_mpdu_spacing {
0836   IEEE80211_HT_MPDU_DENSITY_NONE = 0,     /* No restriction */
0837   IEEE80211_HT_MPDU_DENSITY_0_25 = 1,     /* 1/4 usec */
0838   IEEE80211_HT_MPDU_DENSITY_0_5 = 2,      /* 1/2 usec */
0839   IEEE80211_HT_MPDU_DENSITY_1 = 3,        /* 1 usec */
0840   IEEE80211_HT_MPDU_DENSITY_2 = 4,        /* 2 usec */
0841   IEEE80211_HT_MPDU_DENSITY_4 = 5,        /* 4 usec */
0842   IEEE80211_HT_MPDU_DENSITY_8 = 6,        /* 8 usec */
0843   IEEE80211_HT_MPDU_DENSITY_16 = 7        /* 16 usec */
0844 };
0845 
0846 /**
0847  * struct ieee80211_ht_info - HT information
0848  *
0849  * This structure is the "HT information element" as
0850  * described in 802.11n D5.0 7.3.2.58
0851  */
0852 struct ieee80211_ht_info {
0853   u8 control_chan;
0854   u8 ht_param;
0855   __le16 operation_mode;
0856   __le16 stbc_param;
0857   u8 basic_set[16];
0858 } __attribute__ ((packed));
0859 
0860 /* for ht_param */
0861 #define IEEE80211_HT_PARAM_CHA_SEC_OFFSET               0x03
0862 #define         IEEE80211_HT_PARAM_CHA_SEC_NONE         0x00
0863 #define         IEEE80211_HT_PARAM_CHA_SEC_ABOVE        0x01
0864 #define         IEEE80211_HT_PARAM_CHA_SEC_BELOW        0x03
0865 #define IEEE80211_HT_PARAM_CHAN_WIDTH_ANY               0x04
0866 #define IEEE80211_HT_PARAM_RIFS_MODE                    0x08
0867 #define IEEE80211_HT_PARAM_SPSMP_SUPPORT                0x10
0868 #define IEEE80211_HT_PARAM_SERV_INTERVAL_GRAN           0xE0
0869 
0870 /* for operation_mode */
0871 #define IEEE80211_HT_OP_MODE_PROTECTION                 0x0003
0872 #define         IEEE80211_HT_OP_MODE_PROTECTION_NONE            0
0873 #define         IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER       1
0874 #define         IEEE80211_HT_OP_MODE_PROTECTION_20MHZ           2
0875 #define         IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED     3
0876 #define IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT           0x0004
0877 #define IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT           0x0010
0878 
0879 /* for stbc_param */
0880 #define IEEE80211_HT_STBC_PARAM_DUAL_BEACON             0x0040
0881 #define IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT           0x0080
0882 #define IEEE80211_HT_STBC_PARAM_STBC_BEACON             0x0100
0883 #define IEEE80211_HT_STBC_PARAM_LSIG_TXOP_FULLPROT      0x0200
0884 #define IEEE80211_HT_STBC_PARAM_PCO_ACTIVE              0x0400
0885 #define IEEE80211_HT_STBC_PARAM_PCO_PHASE               0x0800
0886 
0887 
0888 /* block-ack parameters */
0889 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
0890 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
0891 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
0892 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
0893 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
0894 
0895 /*
0896  * A-PMDU buffer sizes
0897  * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2)
0898  */
0899 #define IEEE80211_MIN_AMPDU_BUF 0x8
0900 #define IEEE80211_MAX_AMPDU_BUF 0x40
0901 
0902 
0903 /* Spatial Multiplexing Power Save Modes */
0904 #define WLAN_HT_CAP_SM_PS_STATIC        0
0905 #define WLAN_HT_CAP_SM_PS_DYNAMIC       1
0906 #define WLAN_HT_CAP_SM_PS_INVALID       2
0907 #define WLAN_HT_CAP_SM_PS_DISABLED      3
0908 
0909 /* Authentication algorithms */
0910 #define WLAN_AUTH_OPEN 0
0911 #define WLAN_AUTH_SHARED_KEY 1
0912 #define WLAN_AUTH_FT 2
0913 #define WLAN_AUTH_LEAP 128
0914 
0915 #define WLAN_AUTH_CHALLENGE_LEN 128
0916 
0917 #define WLAN_CAPABILITY_ESS             (1<<0)
0918 #define WLAN_CAPABILITY_IBSS            (1<<1)
0919 #define WLAN_CAPABILITY_CF_POLLABLE     (1<<2)
0920 #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
0921 #define WLAN_CAPABILITY_PRIVACY         (1<<4)
0922 #define WLAN_CAPABILITY_SHORT_PREAMBLE  (1<<5)
0923 #define WLAN_CAPABILITY_PBCC            (1<<6)
0924 #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
0925 
0926 /* 802.11h */
0927 #define WLAN_CAPABILITY_SPECTRUM_MGMT   (1<<8)
0928 #define WLAN_CAPABILITY_QOS             (1<<9)
0929 #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
0930 #define WLAN_CAPABILITY_DSSS_OFDM       (1<<13)
0931 /* measurement */
0932 #define IEEE80211_SPCT_MSR_RPRT_MODE_LATE       (1<<0)
0933 #define IEEE80211_SPCT_MSR_RPRT_MODE_INCAPABLE  (1<<1)
0934 #define IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED    (1<<2)
0935 
0936 #define IEEE80211_SPCT_MSR_RPRT_TYPE_BASIC      0
0937 #define IEEE80211_SPCT_MSR_RPRT_TYPE_CCA        1
0938 #define IEEE80211_SPCT_MSR_RPRT_TYPE_RPI        2
0939 
0940 
0941 /* 802.11g ERP information element */
0942 #define WLAN_ERP_NON_ERP_PRESENT (1<<0)
0943 #define WLAN_ERP_USE_PROTECTION (1<<1)
0944 #define WLAN_ERP_BARKER_PREAMBLE (1<<2)
0945 
0946 /* WLAN_ERP_BARKER_PREAMBLE values */
0947 enum {
0948   WLAN_ERP_PREAMBLE_SHORT = 0,
0949   WLAN_ERP_PREAMBLE_LONG = 1,
0950 };
0951 
0952 /* Status codes */
0953 enum ieee80211_statuscode {
0954   WLAN_STATUS_SUCCESS = 0,
0955   WLAN_STATUS_UNSPECIFIED_FAILURE = 1,
0956   WLAN_STATUS_CAPS_UNSUPPORTED = 10,
0957   WLAN_STATUS_REASSOC_NO_ASSOC = 11,
0958   WLAN_STATUS_ASSOC_DENIED_UNSPEC = 12,
0959   WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG = 13,
0960   WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION = 14,
0961   WLAN_STATUS_CHALLENGE_FAIL = 15,
0962   WLAN_STATUS_AUTH_TIMEOUT = 16,
0963   WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA = 17,
0964   WLAN_STATUS_ASSOC_DENIED_RATES = 18,
0965   /* 802.11b */
0966   WLAN_STATUS_ASSOC_DENIED_NOSHORTPREAMBLE = 19,
0967   WLAN_STATUS_ASSOC_DENIED_NOPBCC = 20,
0968   WLAN_STATUS_ASSOC_DENIED_NOAGILITY = 21,
0969   /* 802.11h */
0970   WLAN_STATUS_ASSOC_DENIED_NOSPECTRUM = 22,
0971   WLAN_STATUS_ASSOC_REJECTED_BAD_POWER = 23,
0972   WLAN_STATUS_ASSOC_REJECTED_BAD_SUPP_CHAN = 24,
0973   /* 802.11g */
0974   WLAN_STATUS_ASSOC_DENIED_NOSHORTTIME = 25,
0975   WLAN_STATUS_ASSOC_DENIED_NODSSSOFDM = 26,
0976   /* 802.11w */
0977   WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY = 30,
0978   WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION = 31,
0979   /* 802.11i */
0980   WLAN_STATUS_INVALID_IE = 40,
0981   WLAN_STATUS_INVALID_GROUP_CIPHER = 41,
0982   WLAN_STATUS_INVALID_PAIRWISE_CIPHER = 42,
0983   WLAN_STATUS_INVALID_AKMP = 43,
0984   WLAN_STATUS_UNSUPP_RSN_VERSION = 44,
0985   WLAN_STATUS_INVALID_RSN_IE_CAP = 45,
0986   WLAN_STATUS_CIPHER_SUITE_REJECTED = 46,
0987   /* 802.11e */
0988   WLAN_STATUS_UNSPECIFIED_QOS = 32,
0989   WLAN_STATUS_ASSOC_DENIED_NOBANDWIDTH = 33,
0990   WLAN_STATUS_ASSOC_DENIED_LOWACK = 34,
0991   WLAN_STATUS_ASSOC_DENIED_UNSUPP_QOS = 35,
0992   WLAN_STATUS_REQUEST_DECLINED = 37,
0993   WLAN_STATUS_INVALID_QOS_PARAM = 38,
0994   WLAN_STATUS_CHANGE_TSPEC = 39,
0995   WLAN_STATUS_WAIT_TS_DELAY = 47,
0996   WLAN_STATUS_NO_DIRECT_LINK = 48,
0997   WLAN_STATUS_STA_NOT_PRESENT = 49,
0998   WLAN_STATUS_STA_NOT_QSTA = 50,
0999 };
1000 
1001 
1002 /* Reason codes */
1003 enum ieee80211_reasoncode {
1004   WLAN_REASON_UNSPECIFIED = 1,
1005   WLAN_REASON_PREV_AUTH_NOT_VALID = 2,
1006   WLAN_REASON_DEAUTH_LEAVING = 3,
1007   WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY = 4,
1008   WLAN_REASON_DISASSOC_AP_BUSY = 5,
1009   WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA = 6,
1010   WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA = 7,
1011   WLAN_REASON_DISASSOC_STA_HAS_LEFT = 8,
1012   WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH = 9,
1013   /* 802.11h */
1014   WLAN_REASON_DISASSOC_BAD_POWER = 10,
1015   WLAN_REASON_DISASSOC_BAD_SUPP_CHAN = 11,
1016   /* 802.11i */
1017   WLAN_REASON_INVALID_IE = 13,
1018   WLAN_REASON_MIC_FAILURE = 14,
1019   WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
1020   WLAN_REASON_GROUP_KEY_HANDSHAKE_TIMEOUT = 16,
1021   WLAN_REASON_IE_DIFFERENT = 17,
1022   WLAN_REASON_INVALID_GROUP_CIPHER = 18,
1023   WLAN_REASON_INVALID_PAIRWISE_CIPHER = 19,
1024   WLAN_REASON_INVALID_AKMP = 20,
1025   WLAN_REASON_UNSUPP_RSN_VERSION = 21,
1026   WLAN_REASON_INVALID_RSN_IE_CAP = 22,
1027   WLAN_REASON_IEEE8021X_FAILED = 23,
1028   WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
1029   /* 802.11e */
1030   WLAN_REASON_DISASSOC_UNSPECIFIED_QOS = 32,
1031   WLAN_REASON_DISASSOC_QAP_NO_BANDWIDTH = 33,
1032   WLAN_REASON_DISASSOC_LOW_ACK = 34,
1033   WLAN_REASON_DISASSOC_QAP_EXCEED_TXOP = 35,
1034   WLAN_REASON_QSTA_LEAVE_QBSS = 36,
1035   WLAN_REASON_QSTA_NOT_USE = 37,
1036   WLAN_REASON_QSTA_REQUIRE_SETUP = 38,
1037   WLAN_REASON_QSTA_TIMEOUT = 39,
1038   WLAN_REASON_QSTA_CIPHER_NOT_SUPP = 45,
1039 };
1040 
1041 
1042 /* Information Element IDs */
1043 enum ieee80211_eid {
1044   WLAN_EID_SSID = 0,
1045   WLAN_EID_SUPP_RATES = 1,
1046   WLAN_EID_FH_PARAMS = 2,
1047   WLAN_EID_DS_PARAMS = 3,
1048   WLAN_EID_CF_PARAMS = 4,
1049   WLAN_EID_TIM = 5,
1050   WLAN_EID_IBSS_PARAMS = 6,
1051   WLAN_EID_CHALLENGE = 16,
1052   /* 802.11d */
1053   WLAN_EID_COUNTRY = 7,
1054   WLAN_EID_HP_PARAMS = 8,
1055   WLAN_EID_HP_TABLE = 9,
1056   WLAN_EID_REQUEST = 10,
1057   /* 802.11e */
1058   WLAN_EID_QBSS_LOAD = 11,
1059   WLAN_EID_EDCA_PARAM_SET = 12,
1060   WLAN_EID_TSPEC = 13,
1061   WLAN_EID_TCLAS = 14,
1062   WLAN_EID_SCHEDULE = 15,
1063   WLAN_EID_TS_DELAY = 43,
1064   WLAN_EID_TCLAS_PROCESSING = 44,
1065   WLAN_EID_QOS_CAPA = 46,
1066   /* 802.11s
1067    *
1068    * All mesh EID numbers are pending IEEE 802.11 ANA approval.
1069    * The numbers have been incremented from those suggested in
1070    * 802.11s/D2.0 so that MESH_CONFIG does not conflict with
1071    * EXT_SUPP_RATES.
1072    */
1073   WLAN_EID_MESH_CONFIG = 51,
1074   WLAN_EID_MESH_ID = 52,
1075   WLAN_EID_PEER_LINK = 55,
1076   WLAN_EID_PREQ = 68,
1077   WLAN_EID_PREP = 69,
1078   WLAN_EID_PERR = 70,
1079   /* 802.11h */
1080   WLAN_EID_PWR_CONSTRAINT = 32,
1081   WLAN_EID_PWR_CAPABILITY = 33,
1082   WLAN_EID_TPC_REQUEST = 34,
1083   WLAN_EID_TPC_REPORT = 35,
1084   WLAN_EID_SUPPORTED_CHANNELS = 36,
1085   WLAN_EID_CHANNEL_SWITCH = 37,
1086   WLAN_EID_MEASURE_REQUEST = 38,
1087   WLAN_EID_MEASURE_REPORT = 39,
1088   WLAN_EID_QUIET = 40,
1089   WLAN_EID_IBSS_DFS = 41,
1090   /* 802.11g */
1091   WLAN_EID_ERP_INFO = 42,
1092   WLAN_EID_EXT_SUPP_RATES = 50,
1093   /* 802.11n */
1094   WLAN_EID_HT_CAPABILITY = 45,
1095   WLAN_EID_HT_INFORMATION = 61,
1096   /* 802.11i */
1097   WLAN_EID_RSN = 48,
1098   WLAN_EID_TIMEOUT_INTERVAL = 56,
1099   WLAN_EID_MMIE = 76 /* 802.11w */,
1100   WLAN_EID_WPA = 221,
1101   WLAN_EID_GENERIC = 221,
1102   WLAN_EID_VENDOR_SPECIFIC = 221,
1103   WLAN_EID_QOS_PARAMETER = 222
1104 };
1105 
1106 /* Action category code */
1107 enum ieee80211_category {
1108   WLAN_CATEGORY_SPECTRUM_MGMT = 0,
1109   WLAN_CATEGORY_QOS = 1,
1110   WLAN_CATEGORY_DLS = 2,
1111   WLAN_CATEGORY_BACK = 3,
1112   WLAN_CATEGORY_PUBLIC = 4,
1113   WLAN_CATEGORY_HT = 7,
1114   WLAN_CATEGORY_SA_QUERY = 8,
1115   WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION = 9,
1116   WLAN_CATEGORY_WMM = 17,
1117   WLAN_CATEGORY_VENDOR_SPECIFIC_PROTECTED = 126,
1118   WLAN_CATEGORY_VENDOR_SPECIFIC = 127,
1119 };
1120 
1121 /* SPECTRUM_MGMT action code */
1122 enum ieee80211_spectrum_mgmt_actioncode {
1123   WLAN_ACTION_SPCT_MSR_REQ = 0,
1124   WLAN_ACTION_SPCT_MSR_RPRT = 1,
1125   WLAN_ACTION_SPCT_TPC_REQ = 2,
1126   WLAN_ACTION_SPCT_TPC_RPRT = 3,
1127   WLAN_ACTION_SPCT_CHL_SWITCH = 4,
1128 };
1129 
1130 /* Security key length */
1131 enum ieee80211_key_len {
1132   WLAN_KEY_LEN_WEP40 = 5,
1133   WLAN_KEY_LEN_WEP104 = 13,
1134   WLAN_KEY_LEN_CCMP = 16,
1135   WLAN_KEY_LEN_TKIP = 32,
1136   WLAN_KEY_LEN_AES_CMAC = 16,
1137 };
1138 
1139 /*
1140  * IEEE 802.11-2007 7.3.2.9 Country information element
1141  *
1142  * Minimum length is 8 octets, ie len must be evenly
1143  * divisible by 2
1144  */
1145 
1146 /* Although the spec says 8 I'm seeing 6 in practice */
1147 #define IEEE80211_COUNTRY_IE_MIN_LEN    6
1148 
1149 /*
1150  * For regulatory extension stuff see IEEE 802.11-2007
1151  * Annex I (page 1141) and Annex J (page 1147). Also
1152  * review 7.3.2.9.
1153  *
1154  * When dot11RegulatoryClassesRequired is true and the
1155  * first_channel/reg_extension_id is >= 201 then the IE
1156  * compromises of the 'ext' struct represented below:
1157  *
1158  *  - Regulatory extension ID - when generating IE this just needs
1159  *    to be monotonically increasing for each triplet passed in
1160  *    the IE
1161  *  - Regulatory class - index into set of rules
1162  *  - Coverage class - index into air propagation time (Table 7-27),
1163  *    in microseconds, you can compute the air propagation time from
1164  *    the index by multiplying by 3, so index 10 yields a propagation
1165  *    of 10 us. Valid values are 0-31, values 32-255 are not defined
1166  *    yet. A value of 0 inicates air propagation of <= 1 us.
1167  *
1168  *  See also Table I.2 for Emission limit sets and table
1169  *  I.3 for Behavior limit sets. Table J.1 indicates how to map
1170  *  a reg_class to an emission limit set and behavior limit set.
1171  */
1172 #define IEEE80211_COUNTRY_EXTENSION_ID 201
1173 
1174 /*
1175  *  Channels numbers in the IE must be monotonically increasing
1176  *  if dot11RegulatoryClassesRequired is not true.
1177  *
1178  *  If dot11RegulatoryClassesRequired is true consecutive
1179  *  subband triplets following a regulatory triplet shall
1180  *  have monotonically increasing first_channel number fields.
1181  *
1182  *  Channel numbers shall not overlap.
1183  *
1184  *  Note that max_power is signed.
1185  */
1186 struct ieee80211_country_ie_triplet {
1187   union {
1188     struct {
1189       u8 first_channel;
1190       u8 num_channels;
1191       s8 max_power;
1192     } __attribute__ ((packed)) chans;
1193     struct {
1194       u8 reg_extension_id;
1195       u8 reg_class;
1196       u8 coverage_class;
1197     } __attribute__ ((packed)) ext;
1198   };
1199 } __attribute__ ((packed));
1200 
1201 enum ieee80211_timeout_interval_type {
1202   WLAN_TIMEOUT_REASSOC_DEADLINE = 1 /* 802.11r */,
1203   WLAN_TIMEOUT_KEY_LIFETIME = 2 /* 802.11r */,
1204   WLAN_TIMEOUT_ASSOC_COMEBACK = 3 /* 802.11w */,
1205 };
1206 
1207 /* BACK action code */
1208 enum ieee80211_back_actioncode {
1209   WLAN_ACTION_ADDBA_REQ = 0,
1210   WLAN_ACTION_ADDBA_RESP = 1,
1211   WLAN_ACTION_DELBA = 2,
1212 };
1213 
1214 /* BACK (block-ack) parties */
1215 enum ieee80211_back_parties {
1216   WLAN_BACK_RECIPIENT = 0,
1217   WLAN_BACK_INITIATOR = 1,
1218   WLAN_BACK_TIMER = 2,
1219 };
1220 
1221 /* SA Query action */
1222 enum ieee80211_sa_query_action {
1223   WLAN_ACTION_SA_QUERY_REQUEST = 0,
1224   WLAN_ACTION_SA_QUERY_RESPONSE = 1,
1225 };
1226 
1227 
1228 /* A-MSDU 802.11n */
1229 #define IEEE80211_QOS_CONTROL_A_MSDU_PRESENT 0x0080
1230 
1231 /* cipher suite selectors */
1232 #define WLAN_CIPHER_SUITE_USE_GROUP     0x000FAC00
1233 #define WLAN_CIPHER_SUITE_WEP40         0x000FAC01
1234 #define WLAN_CIPHER_SUITE_TKIP          0x000FAC02
1235 /* reserved:                            0x000FAC03 */
1236 #define WLAN_CIPHER_SUITE_CCMP          0x000FAC04
1237 #define WLAN_CIPHER_SUITE_WEP104        0x000FAC05
1238 #define WLAN_CIPHER_SUITE_AES_CMAC      0x000FAC06
1239 
1240 /* AKM suite selectors */
1241 #define WLAN_AKM_SUITE_8021X            0x000FAC01
1242 #define WLAN_AKM_SUITE_PSK              0x000FAC02
1243 
1244 #define WLAN_MAX_KEY_LEN                32
1245 
1246 /**
1247  * ieee80211_get_qos_ctl - get pointer to qos control bytes
1248  * @hdr: the frame
1249  *
1250  * The qos ctrl bytes come after the frame_control, duration, seq_num
1251  * and 3 or 4 addresses of length ETH_ALEN.
1252  * 3 addr: 2 + 2 + 2 + 3*6 = 24
1253  * 4 addr: 2 + 2 + 2 + 4*6 = 30
1254  */
1255 static inline u8 *ieee80211_get_qos_ctl(struct ieee80211_hdr *hdr)
1256 {
1257   if (ieee80211_has_a4(hdr->frame_control))
1258     return (u8 *)hdr + 30;
1259   else
1260     return (u8 *)hdr + 24;
1261 }
1262 
1263 /**
1264  * ieee80211_get_SA - get pointer to SA
1265  * @hdr: the frame
1266  *
1267  * Given an 802.11 frame, this function returns the offset
1268  * to the source address (SA). It does not verify that the
1269  * header is long enough to contain the address, and the
1270  * header must be long enough to contain the frame control
1271  * field.
1272  */
1273 static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
1274 {
1275   if (ieee80211_has_a4(hdr->frame_control))
1276     return hdr->addr4;
1277   if (ieee80211_has_fromds(hdr->frame_control))
1278     return hdr->addr3;
1279   return hdr->addr2;
1280 }
1281 
1282 /**
1283  * ieee80211_get_DA - get pointer to DA
1284  * @hdr: the frame
1285  *
1286  * Given an 802.11 frame, this function returns the offset
1287  * to the destination address (DA). It does not verify that
1288  * the header is long enough to contain the address, and the
1289  * header must be long enough to contain the frame control
1290  * field.
1291  */
1292 static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
1293 {
1294   if (ieee80211_has_tods(hdr->frame_control))
1295     return hdr->addr3;
1296   else
1297     return hdr->addr1;
1298 }
1299 
1300 /**
1301  * ieee80211_is_robust_mgmt_frame - check if frame is a robust management frame
1302  * @hdr: the frame (buffer must include at least the first octet of payload)
1303  */
1304 static inline bool ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr)
1305 {
1306   if (ieee80211_is_disassoc(hdr->frame_control) ||
1307       ieee80211_is_deauth(hdr->frame_control))
1308     return TRUE;
1309 
1310   if (ieee80211_is_action(hdr->frame_control)) {
1311     u8 *category;
1312 
1313     /*
1314      * Action frames, excluding Public Action frames, are Robust
1315      * Management Frames. However, if we are looking at a Protected
1316      * frame, skip the check since the data may be encrypted and
1317      * the frame has already been found to be a Robust Management
1318      * Frame (by the other end).
1319      */
1320     if (ieee80211_has_protected(hdr->frame_control))
1321       return TRUE;
1322     category = ((u8 *) hdr) + 24;
1323     return *category != WLAN_CATEGORY_PUBLIC &&
1324       *category != WLAN_CATEGORY_HT &&
1325       *category != WLAN_CATEGORY_VENDOR_SPECIFIC;
1326   }
1327 
1328   return FALSE;
1329 }
1330 
1331 /**
1332  * ieee80211_fhss_chan_to_freq - get channel frequency
1333  * @channel: the FHSS channel
1334  *
1335  * Convert IEEE802.11 FHSS channel to frequency (MHz)
1336  * Ref IEEE 802.11-2007 section 14.6
1337  */
1338 static inline int ieee80211_fhss_chan_to_freq(int channel)
1339 {
1340   if ((channel > 1) && (channel < 96))
1341     return channel + 2400;
1342   else
1343     return -1;
1344 }
1345 
1346 /**
1347  * ieee80211_freq_to_fhss_chan - get channel
1348  * @freq: the channels frequency
1349  *
1350  * Convert frequency (MHz) to IEEE802.11 FHSS channel
1351  * Ref IEEE 802.11-2007 section 14.6
1352  */
1353 static inline int ieee80211_freq_to_fhss_chan(int freq)
1354 {
1355   if ((freq > 2401) && (freq < 2496))
1356     return freq - 2400;
1357   else
1358     return -1;
1359 }
1360 
1361 /**
1362  * ieee80211_dsss_chan_to_freq - get channel center frequency
1363  * @channel: the DSSS channel
1364  *
1365  * Convert IEEE802.11 DSSS channel to the center frequency (MHz).
1366  * Ref IEEE 802.11-2007 section 15.6
1367  */
1368 static inline int ieee80211_dsss_chan_to_freq(int channel)
1369 {
1370   if ((channel > 0) && (channel < 14))
1371     return 2407 + (channel * 5);
1372   else if (channel == 14)
1373     return 2484;
1374   else
1375     return -1;
1376 }
1377 
1378 /**
1379  * ieee80211_freq_to_dsss_chan - get channel
1380  * @freq: the frequency
1381  *
1382  * Convert frequency (MHz) to IEEE802.11 DSSS channel
1383  * Ref IEEE 802.11-2007 section 15.6
1384  *
1385  * This routine selects the channel with the closest center frequency.
1386  */
1387 static inline int ieee80211_freq_to_dsss_chan(int freq)
1388 {
1389   if ((freq >= 2410) && (freq < 2475))
1390     return (freq - 2405) / 5;
1391   else if ((freq >= 2482) && (freq < 2487))
1392     return 14;
1393   else
1394     return -1;
1395 }
1396 
1397 /* Convert IEEE802.11 HR DSSS channel to frequency (MHz) and back
1398  * Ref IEEE 802.11-2007 section 18.4.6.2
1399  *
1400  * The channels and frequencies are the same as those defined for DSSS
1401  */
1402 #define ieee80211_hr_chan_to_freq(chan) ieee80211_dsss_chan_to_freq(chan)
1403 #define ieee80211_freq_to_hr_chan(freq) ieee80211_freq_to_dsss_chan(freq)
1404 
1405 /* Convert IEEE802.11 ERP channel to frequency (MHz) and back
1406  * Ref IEEE 802.11-2007 section 19.4.2
1407  */
1408 #define ieee80211_erp_chan_to_freq(chan) ieee80211_hr_chan_to_freq(chan)
1409 #define ieee80211_freq_to_erp_chan(freq) ieee80211_freq_to_hr_chan(freq)
1410 
1411 /**
1412  * ieee80211_ofdm_chan_to_freq - get channel center frequency
1413  * @s_freq: starting frequency == (dotChannelStartingFactor/2) MHz
1414  * @channel: the OFDM channel
1415  *
1416  * Convert IEEE802.11 OFDM channel to center frequency (MHz)
1417  * Ref IEEE 802.11-2007 section 17.3.8.3.2
1418  */
1419 static inline int ieee80211_ofdm_chan_to_freq(int s_freq, int channel)
1420 {
1421   if ((channel > 0) && (channel <= 200) &&
1422       (s_freq >= 4000))
1423     return s_freq + (channel * 5);
1424   else
1425     return -1;
1426 }
1427 
1428 /**
1429  * ieee80211_freq_to_ofdm_channel - get channel
1430  * @s_freq: starting frequency == (dotChannelStartingFactor/2) MHz
1431  * @freq: the frequency
1432  *
1433  * Convert frequency (MHz) to IEEE802.11 OFDM channel
1434  * Ref IEEE 802.11-2007 section 17.3.8.3.2
1435  *
1436  * This routine selects the channel with the closest center frequency.
1437  */
1438 static inline int ieee80211_freq_to_ofdm_chan(int s_freq, int freq)
1439 {
1440   if ((freq > (s_freq + 2)) && (freq <= (s_freq + 1202)) &&
1441       (s_freq >= 4000))
1442     return (freq + 2 - s_freq) / 5;
1443   else
1444     return -1;
1445 }
1446 
1447 /**
1448  * ieee80211_tu_to_usec - convert time units (TU) to microseconds
1449  * @tu: the TUs
1450  */
1451 static inline unsigned long ieee80211_tu_to_usec(unsigned long tu)
1452 {
1453   return 1024 * tu;
1454 }
1455 
1456 /**
1457  * ieee80211_check_tim - check if AID bit is set in TIM
1458  * @tim: the TIM IE
1459  * @tim_len: length of the TIM IE
1460  * @aid: the AID to look for
1461  */
1462 static inline bool ieee80211_check_tim(struct ieee80211_tim_ie *tim,
1463                                        u8 tim_len, u16 aid)
1464 {
1465   u8 mask;
1466   u8 index, indexn1, indexn2;
1467 
1468   if (unlikely(!tim || tim_len < sizeof(*tim)))
1469     return FALSE;
1470 
1471   aid &= 0x3fff;
1472   index = aid / 8;
1473   mask  = 1 << (aid & 7);
1474 
1475   indexn1 = tim->bitmap_ctrl & 0xfe;
1476   indexn2 = tim_len + indexn1 - 4;
1477 
1478   if (index < indexn1 || index > indexn2)
1479     return FALSE;
1480 
1481   index -= indexn1;
1482 
1483   return !!(tim->virtual_map[index] & mask);
1484 }
1485 
1486 #endif /* STANDARD_IEEE80211_H */
1487 
1488 /*
1489  * Local Variables:
1490  * indent-tabs-mode: nil
1491  * mode: C
1492  * c-file-style: "gnu"
1493  * c-basic-offset: 2
1494  * End:
1495  */
1496 
1497 /* vi: set et sw=2 sts=2: */