Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */
0002 /*
0003  *
0004  * Macros, types, and functions to handle 802.11 mgmt frames
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  * Notes:
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  *  - The len member of the frame structure does NOT!!! include
0058  *    the MAC CRC.  Therefore, the len field on rx'd frames should
0059  *    have 4 subtracted from it.
0060  *
0061  * All functions declared here are implemented in p80211.c
0062  *
0063  * The types, macros, and functions defined here are primarily
0064  * used for encoding and decoding management frames.  They are
0065  * designed to follow these patterns of use:
0066  *
0067  * DECODE:
0068  * 1) a frame of length len is received into buffer b
0069  * 2) using the hdr structure and macros, we determine the type
0070  * 3) an appropriate mgmt frame structure, mf, is allocated and zeroed
0071  * 4) mf.hdr = b
0072  *    mf.buf = b
0073  *    mf.len = len
0074  * 5) call mgmt_decode( mf )
0075  * 6) the frame field pointers in mf are now set.  Note that any
0076  *    multi-byte frame field values accessed using the frame field
0077  *    pointers are in ieee byte order and will have to be converted
0078  *    to host order.
0079  *
0080  * ENCODE:
0081  * 1) Library client allocates buffer space for maximum length
0082  *    frame of the desired type
0083  * 2) Library client allocates a mgmt frame structure, called mf,
0084  *    of the desired type
0085  * 3) Set the following:
0086  *    mf.type = <desired type>
0087  *    mf.buf = <allocated buffer address>
0088  * 4) call mgmt_encode( mf )
0089  * 5) all of the fixed field pointers and fixed length information element
0090  *    pointers in mf are now set to their respective locations in the
0091  *    allocated space (fortunately, all variable length information elements
0092  *    fall at the end of their respective frames).
0093  * 5a) The length field is set to include the last of the fixed and fixed
0094  *     length fields.  It may have to be updated for optional or variable
0095  *  length information elements.
0096  * 6) Optional and variable length information elements are special cases
0097  *    and must be handled individually by the client code.
0098  * --------------------------------------------------------------------
0099  */
0100 
0101 #ifndef _P80211MGMT_H
0102 #define _P80211MGMT_H
0103 
0104 #ifndef _P80211HDR_H
0105 #include "p80211hdr.h"
0106 #endif
0107 
0108 /*-- Information Element IDs --------------------*/
0109 #define WLAN_EID_SSID       0
0110 #define WLAN_EID_SUPP_RATES 1
0111 #define WLAN_EID_FH_PARMS   2
0112 #define WLAN_EID_DS_PARMS   3
0113 #define WLAN_EID_CF_PARMS   4
0114 #define WLAN_EID_TIM        5
0115 #define WLAN_EID_IBSS_PARMS 6
0116 /*-- values 7-15 reserved --*/
0117 #define WLAN_EID_CHALLENGE  16
0118 /*-- values 17-31 reserved for challenge text extension --*/
0119 /*-- values 32-255 reserved --*/
0120 
0121 /*-- Reason Codes -------------------------------*/
0122 #define WLAN_MGMT_REASON_RSVD           0
0123 #define WLAN_MGMT_REASON_UNSPEC         1
0124 #define WLAN_MGMT_REASON_PRIOR_AUTH_INVALID 2
0125 #define WLAN_MGMT_REASON_DEAUTH_LEAVING     3
0126 #define WLAN_MGMT_REASON_DISASSOC_INACTIVE  4
0127 #define WLAN_MGMT_REASON_DISASSOC_AP_BUSY   5
0128 #define WLAN_MGMT_REASON_CLASS2_NONAUTH     6
0129 #define WLAN_MGMT_REASON_CLASS3_NONASSOC    7
0130 #define WLAN_MGMT_REASON_DISASSOC_STA_HASLEFT   8
0131 #define WLAN_MGMT_REASON_CANT_ASSOC_NONAUTH 9
0132 
0133 /*-- Status Codes -------------------------------*/
0134 #define WLAN_MGMT_STATUS_SUCCESS        0
0135 #define WLAN_MGMT_STATUS_UNSPEC_FAILURE     1
0136 #define WLAN_MGMT_STATUS_CAPS_UNSUPPORTED   10
0137 #define WLAN_MGMT_STATUS_REASSOC_NO_ASSOC   11
0138 #define WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC    12
0139 #define WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG    13
0140 #define WLAN_MGMT_STATUS_RX_AUTH_NOSEQ      14
0141 #define WLAN_MGMT_STATUS_CHALLENGE_FAIL     15
0142 #define WLAN_MGMT_STATUS_AUTH_TIMEOUT       16
0143 #define WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY  17
0144 #define WLAN_MGMT_STATUS_ASSOC_DENIED_RATES 18
0145   /* p80211b additions */
0146 #define WLAN_MGMT_STATUS_ASSOC_DENIED_NOSHORT   19
0147 #define WLAN_MGMT_STATUS_ASSOC_DENIED_NOPBCC    20
0148 #define WLAN_MGMT_STATUS_ASSOC_DENIED_NOAGILITY 21
0149 
0150 /*-- Auth Algorithm Field ---------------------------*/
0151 #define WLAN_AUTH_ALG_OPENSYSTEM        0
0152 #define WLAN_AUTH_ALG_SHAREDKEY         1
0153 
0154 /*-- Management Frame Field Offsets -------------*/
0155 /* Note: Not all fields are listed because of variable lengths,   */
0156 /*       see the code in p80211.c to see how we search for fields */
0157 /* Note: These offsets are from the start of the frame data       */
0158 
0159 #define WLAN_BEACON_OFF_TS          0
0160 #define WLAN_BEACON_OFF_BCN_int         8
0161 #define WLAN_BEACON_OFF_CAPINFO         10
0162 #define WLAN_BEACON_OFF_SSID            12
0163 
0164 #define WLAN_DISASSOC_OFF_REASON        0
0165 
0166 #define WLAN_ASSOCREQ_OFF_CAP_INFO      0
0167 #define WLAN_ASSOCREQ_OFF_LISTEN_int        2
0168 #define WLAN_ASSOCREQ_OFF_SSID          4
0169 
0170 #define WLAN_ASSOCRESP_OFF_CAP_INFO     0
0171 #define WLAN_ASSOCRESP_OFF_STATUS       2
0172 #define WLAN_ASSOCRESP_OFF_AID          4
0173 #define WLAN_ASSOCRESP_OFF_SUPP_RATES       6
0174 
0175 #define WLAN_REASSOCREQ_OFF_CAP_INFO        0
0176 #define WLAN_REASSOCREQ_OFF_LISTEN_int      2
0177 #define WLAN_REASSOCREQ_OFF_CURR_AP     4
0178 #define WLAN_REASSOCREQ_OFF_SSID        10
0179 
0180 #define WLAN_REASSOCRESP_OFF_CAP_INFO       0
0181 #define WLAN_REASSOCRESP_OFF_STATUS     2
0182 #define WLAN_REASSOCRESP_OFF_AID        4
0183 #define WLAN_REASSOCRESP_OFF_SUPP_RATES     6
0184 
0185 #define WLAN_PROBEREQ_OFF_SSID          0
0186 
0187 #define WLAN_PROBERESP_OFF_TS           0
0188 #define WLAN_PROBERESP_OFF_BCN_int      8
0189 #define WLAN_PROBERESP_OFF_CAP_INFO     10
0190 #define WLAN_PROBERESP_OFF_SSID         12
0191 
0192 #define WLAN_AUTHEN_OFF_AUTH_ALG        0
0193 #define WLAN_AUTHEN_OFF_AUTH_SEQ        2
0194 #define WLAN_AUTHEN_OFF_STATUS          4
0195 #define WLAN_AUTHEN_OFF_CHALLENGE       6
0196 
0197 #define WLAN_DEAUTHEN_OFF_REASON        0
0198 
0199 /*-- Capability Field ---------------------------*/
0200 #define WLAN_GET_MGMT_CAP_INFO_ESS(n)       ((n) & BIT(0))
0201 #define WLAN_GET_MGMT_CAP_INFO_IBSS(n)      (((n) & BIT(1)) >> 1)
0202 #define WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(n)    (((n) & BIT(2)) >> 2)
0203 #define WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(n) (((n) & BIT(3)) >> 3)
0204 #define WLAN_GET_MGMT_CAP_INFO_PRIVACY(n)   (((n) & BIT(4)) >> 4)
0205   /* p80211b additions */
0206 #define WLAN_GET_MGMT_CAP_INFO_SHORT(n)     (((n) & BIT(5)) >> 5)
0207 #define WLAN_GET_MGMT_CAP_INFO_PBCC(n)      (((n) & BIT(6)) >> 6)
0208 #define WLAN_GET_MGMT_CAP_INFO_AGILITY(n)   (((n) & BIT(7)) >> 7)
0209 
0210 #define WLAN_SET_MGMT_CAP_INFO_ESS(n)       (n)
0211 #define WLAN_SET_MGMT_CAP_INFO_IBSS(n)      ((n) << 1)
0212 #define WLAN_SET_MGMT_CAP_INFO_CFPOLLABLE(n)    ((n) << 2)
0213 #define WLAN_SET_MGMT_CAP_INFO_CFPOLLREQ(n) ((n) << 3)
0214 #define WLAN_SET_MGMT_CAP_INFO_PRIVACY(n)   ((n) << 4)
0215   /* p80211b additions */
0216 #define WLAN_SET_MGMT_CAP_INFO_SHORT(n)     ((n) << 5)
0217 #define WLAN_SET_MGMT_CAP_INFO_PBCC(n)      ((n) << 6)
0218 #define WLAN_SET_MGMT_CAP_INFO_AGILITY(n)   ((n) << 7)
0219 
0220 /*-- Information Element Types --------------------*/
0221 /* prototype structure, all IEs start with these members */
0222 
0223 struct wlan_ie {
0224     u8 eid;
0225     u8 len;
0226 } __packed;
0227 
0228 /*-- Service Set Identity (SSID)  -----------------*/
0229 struct wlan_ie_ssid {
0230     u8 eid;
0231     u8 len;
0232     u8 ssid[1];     /* may be zero, ptrs may overlap */
0233 } __packed;
0234 
0235 /*-- Supported Rates  -----------------------------*/
0236 struct wlan_ie_supp_rates {
0237     u8 eid;
0238     u8 len;
0239     u8 rates[1];        /* had better be at LEAST one! */
0240 } __packed;
0241 
0242 /*-- FH Parameter Set  ----------------------------*/
0243 struct wlan_ie_fh_parms {
0244     u8 eid;
0245     u8 len;
0246     u16 dwell;
0247     u8 hopset;
0248     u8 hoppattern;
0249     u8 hopindex;
0250 } __packed;
0251 
0252 /*-- DS Parameter Set  ----------------------------*/
0253 struct wlan_ie_ds_parms {
0254     u8 eid;
0255     u8 len;
0256     u8 curr_ch;
0257 } __packed;
0258 
0259 /*-- CF Parameter Set  ----------------------------*/
0260 
0261 struct wlan_ie_cf_parms {
0262     u8 eid;
0263     u8 len;
0264     u8 cfp_cnt;
0265     u8 cfp_period;
0266     u16 cfp_maxdur;
0267     u16 cfp_durremaining;
0268 } __packed;
0269 
0270 /*-- TIM ------------------------------------------*/
0271 struct wlan_ie_tim {
0272     u8 eid;
0273     u8 len;
0274     u8 dtim_cnt;
0275     u8 dtim_period;
0276     u8 bitmap_ctl;
0277     u8 virt_bm[1];
0278 } __packed;
0279 
0280 /*-- IBSS Parameter Set ---------------------------*/
0281 struct wlan_ie_ibss_parms {
0282     u8 eid;
0283     u8 len;
0284     u16 atim_win;
0285 } __packed;
0286 
0287 /*-- Challenge Text  ------------------------------*/
0288 struct wlan_ie_challenge {
0289     u8 eid;
0290     u8 len;
0291     u8 challenge[1];
0292 } __packed;
0293 
0294 /*-------------------------------------------------*/
0295 /*  Frame Types  */
0296 
0297 /* prototype structure, all mgmt frame types will start with these members */
0298 struct wlan_fr_mgmt {
0299     u16 type;
0300     u16 len;        /* DOES NOT include CRC !!!! */
0301     u8 *buf;
0302     struct p80211_hdr *hdr;
0303     /* used for target specific data, skb in Linux */
0304     void *priv;
0305     /*-- fixed fields -----------*/
0306     /*-- info elements ----------*/
0307 };
0308 
0309 /*-- Beacon ---------------------------------------*/
0310 struct wlan_fr_beacon {
0311     u16 type;
0312     u16 len;
0313     u8 *buf;
0314     struct p80211_hdr *hdr;
0315     /* used for target specific data, skb in Linux */
0316     void *priv;
0317     /*-- fixed fields -----------*/
0318     u64 *ts;
0319     u16 *bcn_int;
0320     u16 *cap_info;
0321     /*-- info elements ----------*/
0322     struct wlan_ie_ssid *ssid;
0323     struct wlan_ie_supp_rates *supp_rates;
0324     struct wlan_ie_fh_parms *fh_parms;
0325     struct wlan_ie_ds_parms *ds_parms;
0326     struct wlan_ie_cf_parms *cf_parms;
0327     struct wlan_ie_ibss_parms *ibss_parms;
0328     struct wlan_ie_tim *tim;
0329 
0330 };
0331 
0332 /*-- IBSS ATIM ------------------------------------*/
0333 struct wlan_fr_ibssatim {
0334     u16 type;
0335     u16 len;
0336     u8 *buf;
0337     struct p80211_hdr *hdr;
0338     /* used for target specific data, skb in Linux */
0339     void *priv;
0340 
0341     /*-- fixed fields -----------*/
0342     /*-- info elements ----------*/
0343 
0344     /* this frame type has a null body */
0345 
0346 };
0347 
0348 /*-- Disassociation -------------------------------*/
0349 struct wlan_fr_disassoc {
0350     u16 type;
0351     u16 len;
0352     u8 *buf;
0353     struct p80211_hdr *hdr;
0354     /* used for target specific data, skb in Linux */
0355     void *priv;
0356     /*-- fixed fields -----------*/
0357     u16 *reason;
0358 
0359     /*-- info elements ----------*/
0360 
0361 };
0362 
0363 /*-- Association Request --------------------------*/
0364 struct wlan_fr_assocreq {
0365     u16 type;
0366     u16 len;
0367     u8 *buf;
0368     struct p80211_hdr *hdr;
0369     /* used for target specific data, skb in Linux */
0370     void *priv;
0371     /*-- fixed fields -----------*/
0372     u16 *cap_info;
0373     u16 *listen_int;
0374     /*-- info elements ----------*/
0375     struct wlan_ie_ssid *ssid;
0376     struct wlan_ie_supp_rates *supp_rates;
0377 
0378 };
0379 
0380 /*-- Association Response -------------------------*/
0381 struct wlan_fr_assocresp {
0382     u16 type;
0383     u16 len;
0384     u8 *buf;
0385     struct p80211_hdr *hdr;
0386     /* used for target specific data, skb in Linux */
0387     void *priv;
0388     /*-- fixed fields -----------*/
0389     u16 *cap_info;
0390     u16 *status;
0391     u16 *aid;
0392     /*-- info elements ----------*/
0393     struct wlan_ie_supp_rates *supp_rates;
0394 
0395 };
0396 
0397 /*-- Reassociation Request ------------------------*/
0398 struct wlan_fr_reassocreq {
0399     u16 type;
0400     u16 len;
0401     u8 *buf;
0402     struct p80211_hdr *hdr;
0403     /* used for target specific data, skb in Linux */
0404     void *priv;
0405     /*-- fixed fields -----------*/
0406     u16 *cap_info;
0407     u16 *listen_int;
0408     u8 *curr_ap;
0409     /*-- info elements ----------*/
0410     struct wlan_ie_ssid *ssid;
0411     struct wlan_ie_supp_rates *supp_rates;
0412 
0413 };
0414 
0415 /*-- Reassociation Response -----------------------*/
0416 struct wlan_fr_reassocresp {
0417     u16 type;
0418     u16 len;
0419     u8 *buf;
0420     struct p80211_hdr *hdr;
0421     /* used for target specific data, skb in Linux */
0422     void *priv;
0423     /*-- fixed fields -----------*/
0424     u16 *cap_info;
0425     u16 *status;
0426     u16 *aid;
0427     /*-- info elements ----------*/
0428     struct wlan_ie_supp_rates *supp_rates;
0429 
0430 };
0431 
0432 /*-- Probe Request --------------------------------*/
0433 struct wlan_fr_probereq {
0434     u16 type;
0435     u16 len;
0436     u8 *buf;
0437     struct p80211_hdr *hdr;
0438     /* used for target specific data, skb in Linux */
0439     void *priv;
0440     /*-- fixed fields -----------*/
0441     /*-- info elements ----------*/
0442     struct wlan_ie_ssid *ssid;
0443     struct wlan_ie_supp_rates *supp_rates;
0444 
0445 };
0446 
0447 /*-- Probe Response -------------------------------*/
0448 struct wlan_fr_proberesp {
0449     u16 type;
0450     u16 len;
0451     u8 *buf;
0452     struct p80211_hdr *hdr;
0453     /* used for target specific data, skb in Linux */
0454     void *priv;
0455     /*-- fixed fields -----------*/
0456     u64 *ts;
0457     u16 *bcn_int;
0458     u16 *cap_info;
0459     /*-- info elements ----------*/
0460     struct wlan_ie_ssid *ssid;
0461     struct wlan_ie_supp_rates *supp_rates;
0462     struct wlan_ie_fh_parms *fh_parms;
0463     struct wlan_ie_ds_parms *ds_parms;
0464     struct wlan_ie_cf_parms *cf_parms;
0465     struct wlan_ie_ibss_parms *ibss_parms;
0466 };
0467 
0468 /*-- Authentication -------------------------------*/
0469 struct wlan_fr_authen {
0470     u16 type;
0471     u16 len;
0472     u8 *buf;
0473     struct p80211_hdr *hdr;
0474     /* used for target specific data, skb in Linux */
0475     void *priv;
0476     /*-- fixed fields -----------*/
0477     u16 *auth_alg;
0478     u16 *auth_seq;
0479     u16 *status;
0480     /*-- info elements ----------*/
0481     struct wlan_ie_challenge *challenge;
0482 
0483 };
0484 
0485 /*-- Deauthenication -----------------------------*/
0486 struct wlan_fr_deauthen {
0487     u16 type;
0488     u16 len;
0489     u8 *buf;
0490     struct p80211_hdr *hdr;
0491     /* used for target specific data, skb in Linux */
0492     void *priv;
0493     /*-- fixed fields -----------*/
0494     u16 *reason;
0495 
0496     /*-- info elements ----------*/
0497 
0498 };
0499 
0500 void wlan_mgmt_encode_beacon(struct wlan_fr_beacon *f);
0501 void wlan_mgmt_decode_beacon(struct wlan_fr_beacon *f);
0502 void wlan_mgmt_encode_disassoc(struct wlan_fr_disassoc *f);
0503 void wlan_mgmt_decode_disassoc(struct wlan_fr_disassoc *f);
0504 void wlan_mgmt_encode_assocreq(struct wlan_fr_assocreq *f);
0505 void wlan_mgmt_decode_assocreq(struct wlan_fr_assocreq *f);
0506 void wlan_mgmt_encode_assocresp(struct wlan_fr_assocresp *f);
0507 void wlan_mgmt_decode_assocresp(struct wlan_fr_assocresp *f);
0508 void wlan_mgmt_encode_reassocreq(struct wlan_fr_reassocreq *f);
0509 void wlan_mgmt_decode_reassocreq(struct wlan_fr_reassocreq *f);
0510 void wlan_mgmt_encode_reassocresp(struct wlan_fr_reassocresp *f);
0511 void wlan_mgmt_decode_reassocresp(struct wlan_fr_reassocresp *f);
0512 void wlan_mgmt_encode_probereq(struct wlan_fr_probereq *f);
0513 void wlan_mgmt_decode_probereq(struct wlan_fr_probereq *f);
0514 void wlan_mgmt_encode_proberesp(struct wlan_fr_proberesp *f);
0515 void wlan_mgmt_decode_proberesp(struct wlan_fr_proberesp *f);
0516 void wlan_mgmt_encode_authen(struct wlan_fr_authen *f);
0517 void wlan_mgmt_decode_authen(struct wlan_fr_authen *f);
0518 void wlan_mgmt_encode_deauthen(struct wlan_fr_deauthen *f);
0519 void wlan_mgmt_decode_deauthen(struct wlan_fr_deauthen *f);
0520 
0521 #endif /* _P80211MGMT_H */