ieee80211_proto.h revision 148315
1116742Ssam/*- 2116904Ssam * Copyright (c) 2001 Atsushi Onoe 3139530Ssam * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting 4116742Ssam * All rights reserved. 5116742Ssam * 6116742Ssam * Redistribution and use in source and binary forms, with or without 7116742Ssam * modification, are permitted provided that the following conditions 8116742Ssam * are met: 9116742Ssam * 1. Redistributions of source code must retain the above copyright 10116742Ssam * notice, this list of conditions and the following disclaimer. 11116742Ssam * 2. Redistributions in binary form must reproduce the above copyright 12116742Ssam * notice, this list of conditions and the following disclaimer in the 13116742Ssam * documentation and/or other materials provided with the distribution. 14116904Ssam * 3. The name of the author may not be used to endorse or promote products 15116904Ssam * derived from this software without specific prior written permission. 16116742Ssam * 17116904Ssam * Alternatively, this software may be distributed under the terms of the 18116904Ssam * GNU General Public License ("GPL") version 2 as published by the Free 19116904Ssam * Software Foundation. 20116742Ssam * 21116904Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22116904Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23116904Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24116904Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25116904Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26116904Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27116904Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28116904Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29116904Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30116904Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31116904Ssam * 32116742Ssam * $FreeBSD: head/sys/net80211/ieee80211_proto.h 148315 2005-07-22 21:11:26Z sam $ 33116742Ssam */ 34116742Ssam#ifndef _NET80211_IEEE80211_PROTO_H_ 35116742Ssam#define _NET80211_IEEE80211_PROTO_H_ 36116742Ssam 37116742Ssam/* 38116742Ssam * 802.11 protocol implementation definitions. 39116742Ssam */ 40116742Ssam 41116742Ssamenum ieee80211_state { 42117811Ssam IEEE80211_S_INIT = 0, /* default state */ 43117811Ssam IEEE80211_S_SCAN = 1, /* scanning */ 44117811Ssam IEEE80211_S_AUTH = 2, /* try to authenticate */ 45117811Ssam IEEE80211_S_ASSOC = 3, /* try to assoc */ 46117811Ssam IEEE80211_S_RUN = 4, /* associated */ 47116742Ssam}; 48117811Ssam#define IEEE80211_S_MAX (IEEE80211_S_RUN+1) 49116742Ssam 50116742Ssam#define IEEE80211_SEND_MGMT(_ic,_ni,_type,_arg) \ 51116742Ssam ((*(_ic)->ic_send_mgmt)(_ic, _ni, _type, _arg)) 52116742Ssam 53116742Ssamextern const char *ieee80211_mgt_subtype_name[]; 54139502Ssamextern const char *ieee80211_phymode_name[]; 55116742Ssam 56144618Ssamvoid ieee80211_proto_attach(struct ieee80211com *); 57144618Ssamvoid ieee80211_proto_detach(struct ieee80211com *); 58116742Ssam 59119150Ssamstruct ieee80211_node; 60144618Ssamint ieee80211_input(struct ieee80211com *, struct mbuf *, 61119150Ssam struct ieee80211_node *, int, u_int32_t); 62148299Ssamint ieee80211_setup_rates(struct ieee80211_node *ni, 63148299Ssam const u_int8_t *rates, const u_int8_t *xrates, int flags); 64144618Ssamvoid ieee80211_recv_mgmt(struct ieee80211com *, struct mbuf *, 65119150Ssam struct ieee80211_node *, int, int, u_int32_t); 66148301Ssamint ieee80211_send_nulldata(struct ieee80211_node *); 67148315Ssamint ieee80211_send_probereq(struct ieee80211_node *ni, 68148315Ssam const u_int8_t sa[IEEE80211_ADDR_LEN], 69148315Ssam const u_int8_t da[IEEE80211_ADDR_LEN], 70148315Ssam const u_int8_t bssid[IEEE80211_ADDR_LEN], 71148315Ssam const u_int8_t *ssid, size_t ssidlen, 72148315Ssam const void *optie, size_t optielen); 73144618Ssamint ieee80211_send_mgmt(struct ieee80211com *, struct ieee80211_node *, 74116742Ssam int, int); 75144618Ssamint ieee80211_classify(struct ieee80211com *, struct mbuf *, 76138568Ssam struct ieee80211_node *); 77144618Ssamstruct mbuf *ieee80211_encap(struct ieee80211com *, struct mbuf *, 78138568Ssam struct ieee80211_node *); 79144618Ssamvoid ieee80211_pwrsave(struct ieee80211com *, struct ieee80211_node *, 80138568Ssam struct mbuf *); 81138568Ssam 82144618Ssamvoid ieee80211_reset_erp(struct ieee80211com *); 83144618Ssamvoid ieee80211_set_shortslottime(struct ieee80211com *, int onoff); 84144618Ssamint ieee80211_iserp_rateset(struct ieee80211com *, 85138568Ssam struct ieee80211_rateset *); 86144618Ssamvoid ieee80211_set11gbasicrates(struct ieee80211_rateset *, 87138568Ssam enum ieee80211_phymode); 88138568Ssam 89138568Ssam/* 90138568Ssam * Return the size of the 802.11 header for a management or data frame. 91138568Ssam */ 92139525Ssamstatic __inline int 93138568Ssamieee80211_hdrsize(const void *data) 94138568Ssam{ 95138568Ssam const struct ieee80211_frame *wh = data; 96138568Ssam int size = sizeof(struct ieee80211_frame); 97138568Ssam 98138568Ssam /* NB: we don't handle control frames */ 99138568Ssam KASSERT((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL, 100138568Ssam ("%s: control frame", __func__)); 101138568Ssam if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS) 102138568Ssam size += IEEE80211_ADDR_LEN; 103138568Ssam if (IEEE80211_QOS_HAS_SEQ(wh)) 104138568Ssam size += sizeof(u_int16_t); 105138568Ssam return size; 106138568Ssam} 107138568Ssam 108138568Ssam/* 109138568Ssam * Return the size of the 802.11 header; handles any type of frame. 110138568Ssam */ 111139525Ssamstatic __inline int 112138568Ssamieee80211_anyhdrsize(const void *data) 113138568Ssam{ 114138568Ssam const struct ieee80211_frame *wh = data; 115138568Ssam 116138568Ssam if ((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL) { 117138568Ssam switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) { 118138568Ssam case IEEE80211_FC0_SUBTYPE_CTS: 119138568Ssam case IEEE80211_FC0_SUBTYPE_ACK: 120138568Ssam return sizeof(struct ieee80211_frame_ack); 121138568Ssam } 122138568Ssam return sizeof(struct ieee80211_frame_min); 123138568Ssam } else 124138568Ssam return ieee80211_hdrsize(data); 125138568Ssam} 126138568Ssam 127138568Ssam/* 128138568Ssam * Template for an in-kernel authenticator. Authenticators 129138568Ssam * register with the protocol code and are typically loaded 130138568Ssam * as separate modules as needed. 131138568Ssam */ 132138568Ssamstruct ieee80211_authenticator { 133138568Ssam const char *ia_name; /* printable name */ 134138568Ssam int (*ia_attach)(struct ieee80211com *); 135138568Ssam void (*ia_detach)(struct ieee80211com *); 136138568Ssam void (*ia_node_join)(struct ieee80211com *, 137138568Ssam struct ieee80211_node *); 138138568Ssam void (*ia_node_leave)(struct ieee80211com *, 139138568Ssam struct ieee80211_node *); 140138568Ssam}; 141144618Ssamvoid ieee80211_authenticator_register(int type, 142138568Ssam const struct ieee80211_authenticator *); 143144618Ssamvoid ieee80211_authenticator_unregister(int type); 144144618Ssamconst struct ieee80211_authenticator *ieee80211_authenticator_get(int auth); 145138568Ssam 146138568Ssam/* 147138568Ssam * Template for an MAC ACL policy module. Such modules 148138568Ssam * register with the protocol code and are passed the sender's 149138568Ssam * address of each received frame for validation. 150138568Ssam */ 151138568Ssamstruct ieee80211_aclator { 152138568Ssam const char *iac_name; /* printable name */ 153138568Ssam int (*iac_attach)(struct ieee80211com *); 154138568Ssam void (*iac_detach)(struct ieee80211com *); 155138568Ssam int (*iac_check)(struct ieee80211com *, 156138568Ssam const u_int8_t mac[IEEE80211_ADDR_LEN]); 157138568Ssam int (*iac_add)(struct ieee80211com *, 158138568Ssam const u_int8_t mac[IEEE80211_ADDR_LEN]); 159138568Ssam int (*iac_remove)(struct ieee80211com *, 160138568Ssam const u_int8_t mac[IEEE80211_ADDR_LEN]); 161138568Ssam int (*iac_flush)(struct ieee80211com *); 162138568Ssam int (*iac_setpolicy)(struct ieee80211com *, int); 163138568Ssam int (*iac_getpolicy)(struct ieee80211com *); 164138568Ssam}; 165144618Ssamvoid ieee80211_aclator_register(const struct ieee80211_aclator *); 166144618Ssamvoid ieee80211_aclator_unregister(const struct ieee80211_aclator *); 167144618Ssamconst struct ieee80211_aclator *ieee80211_aclator_get(const char *name); 168138568Ssam 169138568Ssam/* flags for ieee80211_fix_rate() */ 170138568Ssam#define IEEE80211_F_DOSORT 0x00000001 /* sort rate list */ 171138568Ssam#define IEEE80211_F_DOFRATE 0x00000002 /* use fixed rate */ 172138568Ssam#define IEEE80211_F_DONEGO 0x00000004 /* calc negotiated rate */ 173138568Ssam#define IEEE80211_F_DODEL 0x00000008 /* delete ignore rate */ 174148299Ssamint ieee80211_fix_rate(struct ieee80211_node *, int); 175138568Ssam 176138568Ssam/* 177138568Ssam * WME/WMM support. 178138568Ssam */ 179138568Ssamstruct wmeParams { 180138568Ssam u_int8_t wmep_acm; 181138568Ssam u_int8_t wmep_aifsn; 182138568Ssam u_int8_t wmep_logcwmin; /* log2(cwmin) */ 183138568Ssam u_int8_t wmep_logcwmax; /* log2(cwmax) */ 184138568Ssam u_int8_t wmep_txopLimit; 185138568Ssam u_int8_t wmep_noackPolicy; /* 0 (ack), 1 (no ack) */ 186138568Ssam}; 187140762Ssam#define IEEE80211_TXOP_TO_US(_txop) ((_txop)<<5) 188140762Ssam#define IEEE80211_US_TO_TXOP(_us) ((_us)>>5) 189138568Ssam 190138568Ssamstruct chanAccParams { 191138568Ssam u_int8_t cap_info; /* version of the current set */ 192138568Ssam struct wmeParams cap_wmeParams[WME_NUM_AC]; 193138568Ssam}; 194138568Ssam 195138568Ssamstruct ieee80211_wme_state { 196138568Ssam u_int wme_flags; 197138568Ssam#define WME_F_AGGRMODE 0x00000001 /* STATUS: WME agressive mode */ 198138568Ssam u_int wme_hipri_traffic; /* VI/VO frames in beacon interval */ 199138568Ssam u_int wme_hipri_switch_thresh;/* agressive mode switch thresh */ 200138568Ssam u_int wme_hipri_switch_hysteresis;/* agressive mode switch hysteresis */ 201138568Ssam 202138568Ssam struct wmeParams wme_params[4]; /* from assoc resp for each AC*/ 203138568Ssam struct chanAccParams wme_wmeChanParams; /* WME params applied to self */ 204138568Ssam struct chanAccParams wme_wmeBssChanParams;/* WME params bcast to stations */ 205138568Ssam struct chanAccParams wme_chanParams; /* params applied to self */ 206138568Ssam struct chanAccParams wme_bssChanParams; /* params bcast to stations */ 207138568Ssam 208138568Ssam int (*wme_update)(struct ieee80211com *); 209138568Ssam}; 210138568Ssam 211144618Ssamvoid ieee80211_wme_initparams(struct ieee80211com *); 212144618Ssamvoid ieee80211_wme_updateparams(struct ieee80211com *); 213144618Ssamvoid ieee80211_wme_updateparams_locked(struct ieee80211com *); 214138568Ssam 215117811Ssam#define ieee80211_new_state(_ic, _nstate, _arg) \ 216117811Ssam (((_ic)->ic_newstate)((_ic), (_nstate), (_arg))) 217144618Ssamvoid ieee80211_print_essid(const u_int8_t *, int); 218144618Ssamvoid ieee80211_dump_pkt(const u_int8_t *, int, int, int); 219117811Ssam 220117811Ssamextern const char *ieee80211_state_name[IEEE80211_S_MAX]; 221138568Ssamextern const char *ieee80211_wme_acnames[]; 222138568Ssam 223138568Ssam/* 224138568Ssam * Beacon frames constructed by ieee80211_beacon_alloc 225138568Ssam * have the following structure filled in so drivers 226138568Ssam * can update the frame later w/ minimal overhead. 227138568Ssam */ 228138568Ssamstruct ieee80211_beacon_offsets { 229138568Ssam u_int16_t *bo_caps; /* capabilities */ 230138568Ssam u_int8_t *bo_tim; /* start of atim/dtim */ 231138568Ssam u_int8_t *bo_wme; /* start of WME parameters */ 232138568Ssam u_int8_t *bo_trailer; /* start of fixed-size trailer */ 233138568Ssam u_int16_t bo_tim_len; /* atim/dtim length in bytes */ 234138568Ssam u_int16_t bo_trailer_len; /* trailer length in bytes */ 235138568Ssam}; 236144618Ssamstruct mbuf *ieee80211_beacon_alloc(struct ieee80211com *, 237138568Ssam struct ieee80211_node *, struct ieee80211_beacon_offsets *); 238144618Ssamint ieee80211_beacon_update(struct ieee80211com *, 239138568Ssam struct ieee80211_node *, struct ieee80211_beacon_offsets *, 240138568Ssam struct mbuf *, int broadcast); 241138568Ssam 242138568Ssam/* 243138568Ssam * Notification methods called from the 802.11 state machine. 244138568Ssam * Note that while these are defined here, their implementation 245138568Ssam * is OS-specific. 246138568Ssam */ 247144618Ssamvoid ieee80211_notify_node_join(struct ieee80211com *, 248138568Ssam struct ieee80211_node *, int newassoc); 249144618Ssamvoid ieee80211_notify_node_leave(struct ieee80211com *, 250138568Ssam struct ieee80211_node *); 251144618Ssamvoid ieee80211_notify_scan_done(struct ieee80211com *); 252116742Ssam#endif /* _NET80211_IEEE80211_PROTO_H_ */ 253