ieee80211_proto.h revision 167442
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 167442 2007-03-11 07:22:21Z 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); 64148936Ssamvoid ieee80211_saveie(u_int8_t **, const u_int8_t *); 65144618Ssamvoid ieee80211_recv_mgmt(struct ieee80211com *, struct mbuf *, 66119150Ssam struct ieee80211_node *, int, int, u_int32_t); 67160690Ssamstruct ieee80211_bpf_params; 68160690Ssamint ieee80211_raw_xmit(struct ieee80211_node *, struct mbuf *, 69160690Ssam const struct ieee80211_bpf_params *); 70160690Ssamint ieee80211_output(struct ifnet *, struct mbuf *, 71160690Ssam struct sockaddr *, struct rtentry *); 72148301Ssamint ieee80211_send_nulldata(struct ieee80211_node *); 73148315Ssamint ieee80211_send_probereq(struct ieee80211_node *ni, 74148315Ssam const u_int8_t sa[IEEE80211_ADDR_LEN], 75148315Ssam const u_int8_t da[IEEE80211_ADDR_LEN], 76148315Ssam const u_int8_t bssid[IEEE80211_ADDR_LEN], 77148315Ssam const u_int8_t *ssid, size_t ssidlen, 78148315Ssam const void *optie, size_t optielen); 79144618Ssamint ieee80211_send_mgmt(struct ieee80211com *, struct ieee80211_node *, 80116742Ssam int, int); 81144618Ssamint ieee80211_classify(struct ieee80211com *, struct mbuf *, 82138568Ssam struct ieee80211_node *); 83144618Ssamstruct mbuf *ieee80211_encap(struct ieee80211com *, struct mbuf *, 84138568Ssam struct ieee80211_node *); 85144618Ssamvoid ieee80211_pwrsave(struct ieee80211com *, struct ieee80211_node *, 86138568Ssam struct mbuf *); 87138568Ssam 88144618Ssamvoid ieee80211_reset_erp(struct ieee80211com *); 89144618Ssamvoid ieee80211_set_shortslottime(struct ieee80211com *, int onoff); 90144618Ssamint ieee80211_iserp_rateset(struct ieee80211com *, 91138568Ssam struct ieee80211_rateset *); 92144618Ssamvoid ieee80211_set11gbasicrates(struct ieee80211_rateset *, 93138568Ssam enum ieee80211_phymode); 94138568Ssam 95138568Ssam/* 96138568Ssam * Return the size of the 802.11 header for a management or data frame. 97138568Ssam */ 98139525Ssamstatic __inline int 99138568Ssamieee80211_hdrsize(const void *data) 100138568Ssam{ 101138568Ssam const struct ieee80211_frame *wh = data; 102138568Ssam int size = sizeof(struct ieee80211_frame); 103138568Ssam 104138568Ssam /* NB: we don't handle control frames */ 105138568Ssam KASSERT((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL, 106138568Ssam ("%s: control frame", __func__)); 107138568Ssam if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS) 108138568Ssam size += IEEE80211_ADDR_LEN; 109138568Ssam if (IEEE80211_QOS_HAS_SEQ(wh)) 110138568Ssam size += sizeof(u_int16_t); 111138568Ssam return size; 112138568Ssam} 113138568Ssam 114138568Ssam/* 115138568Ssam * Return the size of the 802.11 header; handles any type of frame. 116138568Ssam */ 117139525Ssamstatic __inline int 118138568Ssamieee80211_anyhdrsize(const void *data) 119138568Ssam{ 120138568Ssam const struct ieee80211_frame *wh = data; 121138568Ssam 122138568Ssam if ((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL) { 123138568Ssam switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) { 124138568Ssam case IEEE80211_FC0_SUBTYPE_CTS: 125138568Ssam case IEEE80211_FC0_SUBTYPE_ACK: 126138568Ssam return sizeof(struct ieee80211_frame_ack); 127138568Ssam } 128138568Ssam return sizeof(struct ieee80211_frame_min); 129138568Ssam } else 130138568Ssam return ieee80211_hdrsize(data); 131138568Ssam} 132138568Ssam 133138568Ssam/* 134138568Ssam * Template for an in-kernel authenticator. Authenticators 135138568Ssam * register with the protocol code and are typically loaded 136138568Ssam * as separate modules as needed. 137138568Ssam */ 138138568Ssamstruct ieee80211_authenticator { 139138568Ssam const char *ia_name; /* printable name */ 140138568Ssam int (*ia_attach)(struct ieee80211com *); 141138568Ssam void (*ia_detach)(struct ieee80211com *); 142138568Ssam void (*ia_node_join)(struct ieee80211com *, 143138568Ssam struct ieee80211_node *); 144138568Ssam void (*ia_node_leave)(struct ieee80211com *, 145138568Ssam struct ieee80211_node *); 146138568Ssam}; 147144618Ssamvoid ieee80211_authenticator_register(int type, 148138568Ssam const struct ieee80211_authenticator *); 149144618Ssamvoid ieee80211_authenticator_unregister(int type); 150144618Ssamconst struct ieee80211_authenticator *ieee80211_authenticator_get(int auth); 151138568Ssam 152149028Ssamstruct ieee80211req; 153138568Ssam/* 154138568Ssam * Template for an MAC ACL policy module. Such modules 155138568Ssam * register with the protocol code and are passed the sender's 156138568Ssam * address of each received frame for validation. 157138568Ssam */ 158138568Ssamstruct ieee80211_aclator { 159138568Ssam const char *iac_name; /* printable name */ 160138568Ssam int (*iac_attach)(struct ieee80211com *); 161138568Ssam void (*iac_detach)(struct ieee80211com *); 162138568Ssam int (*iac_check)(struct ieee80211com *, 163138568Ssam const u_int8_t mac[IEEE80211_ADDR_LEN]); 164138568Ssam int (*iac_add)(struct ieee80211com *, 165138568Ssam const u_int8_t mac[IEEE80211_ADDR_LEN]); 166138568Ssam int (*iac_remove)(struct ieee80211com *, 167138568Ssam const u_int8_t mac[IEEE80211_ADDR_LEN]); 168138568Ssam int (*iac_flush)(struct ieee80211com *); 169138568Ssam int (*iac_setpolicy)(struct ieee80211com *, int); 170138568Ssam int (*iac_getpolicy)(struct ieee80211com *); 171149028Ssam int (*iac_setioctl)(struct ieee80211com *, struct ieee80211req *); 172149028Ssam int (*iac_getioctl)(struct ieee80211com *, struct ieee80211req *); 173138568Ssam}; 174144618Ssamvoid ieee80211_aclator_register(const struct ieee80211_aclator *); 175144618Ssamvoid ieee80211_aclator_unregister(const struct ieee80211_aclator *); 176144618Ssamconst struct ieee80211_aclator *ieee80211_aclator_get(const char *name); 177138568Ssam 178138568Ssam/* flags for ieee80211_fix_rate() */ 179138568Ssam#define IEEE80211_F_DOSORT 0x00000001 /* sort rate list */ 180138568Ssam#define IEEE80211_F_DOFRATE 0x00000002 /* use fixed rate */ 181138568Ssam#define IEEE80211_F_DONEGO 0x00000004 /* calc negotiated rate */ 182138568Ssam#define IEEE80211_F_DODEL 0x00000008 /* delete ignore rate */ 183165887Ssam#define IEEE80211_F_JOIN 0x00000010 /* sta joining our bss */ 184167442Ssamint ieee80211_fix_rate(struct ieee80211_node *, 185167442Ssam struct ieee80211_rateset *, int); 186138568Ssam 187138568Ssam/* 188138568Ssam * WME/WMM support. 189138568Ssam */ 190138568Ssamstruct wmeParams { 191138568Ssam u_int8_t wmep_acm; 192138568Ssam u_int8_t wmep_aifsn; 193138568Ssam u_int8_t wmep_logcwmin; /* log2(cwmin) */ 194138568Ssam u_int8_t wmep_logcwmax; /* log2(cwmax) */ 195138568Ssam u_int8_t wmep_txopLimit; 196138568Ssam u_int8_t wmep_noackPolicy; /* 0 (ack), 1 (no ack) */ 197138568Ssam}; 198140762Ssam#define IEEE80211_TXOP_TO_US(_txop) ((_txop)<<5) 199140762Ssam#define IEEE80211_US_TO_TXOP(_us) ((_us)>>5) 200138568Ssam 201138568Ssamstruct chanAccParams { 202138568Ssam u_int8_t cap_info; /* version of the current set */ 203138568Ssam struct wmeParams cap_wmeParams[WME_NUM_AC]; 204138568Ssam}; 205138568Ssam 206138568Ssamstruct ieee80211_wme_state { 207138568Ssam u_int wme_flags; 208138568Ssam#define WME_F_AGGRMODE 0x00000001 /* STATUS: WME agressive mode */ 209138568Ssam u_int wme_hipri_traffic; /* VI/VO frames in beacon interval */ 210138568Ssam u_int wme_hipri_switch_thresh;/* agressive mode switch thresh */ 211138568Ssam u_int wme_hipri_switch_hysteresis;/* agressive mode switch hysteresis */ 212138568Ssam 213138568Ssam struct wmeParams wme_params[4]; /* from assoc resp for each AC*/ 214138568Ssam struct chanAccParams wme_wmeChanParams; /* WME params applied to self */ 215138568Ssam struct chanAccParams wme_wmeBssChanParams;/* WME params bcast to stations */ 216138568Ssam struct chanAccParams wme_chanParams; /* params applied to self */ 217138568Ssam struct chanAccParams wme_bssChanParams; /* params bcast to stations */ 218138568Ssam 219138568Ssam int (*wme_update)(struct ieee80211com *); 220138568Ssam}; 221138568Ssam 222144618Ssamvoid ieee80211_wme_initparams(struct ieee80211com *); 223144618Ssamvoid ieee80211_wme_updateparams(struct ieee80211com *); 224144618Ssamvoid ieee80211_wme_updateparams_locked(struct ieee80211com *); 225138568Ssam 226117811Ssam#define ieee80211_new_state(_ic, _nstate, _arg) \ 227117811Ssam (((_ic)->ic_newstate)((_ic), (_nstate), (_arg))) 228153349Ssamvoid ieee80211_beacon_miss(struct ieee80211com *); 229144618Ssamvoid ieee80211_print_essid(const u_int8_t *, int); 230144618Ssamvoid ieee80211_dump_pkt(const u_int8_t *, int, int, int); 231117811Ssam 232167283Ssamextern const char *ieee80211_opmode_name[]; 233117811Ssamextern const char *ieee80211_state_name[IEEE80211_S_MAX]; 234138568Ssamextern const char *ieee80211_wme_acnames[]; 235138568Ssam 236138568Ssam/* 237138568Ssam * Beacon frames constructed by ieee80211_beacon_alloc 238138568Ssam * have the following structure filled in so drivers 239138568Ssam * can update the frame later w/ minimal overhead. 240138568Ssam */ 241138568Ssamstruct ieee80211_beacon_offsets { 242138568Ssam u_int16_t *bo_caps; /* capabilities */ 243138568Ssam u_int8_t *bo_tim; /* start of atim/dtim */ 244138568Ssam u_int8_t *bo_wme; /* start of WME parameters */ 245138568Ssam u_int8_t *bo_trailer; /* start of fixed-size trailer */ 246138568Ssam u_int16_t bo_tim_len; /* atim/dtim length in bytes */ 247138568Ssam u_int16_t bo_trailer_len; /* trailer length in bytes */ 248153973Ssam u_int8_t *bo_erp; /* start of ERP element */ 249138568Ssam}; 250144618Ssamstruct mbuf *ieee80211_beacon_alloc(struct ieee80211com *, 251138568Ssam struct ieee80211_node *, struct ieee80211_beacon_offsets *); 252144618Ssamint ieee80211_beacon_update(struct ieee80211com *, 253138568Ssam struct ieee80211_node *, struct ieee80211_beacon_offsets *, 254138568Ssam struct mbuf *, int broadcast); 255138568Ssam 256138568Ssam/* 257138568Ssam * Notification methods called from the 802.11 state machine. 258138568Ssam * Note that while these are defined here, their implementation 259138568Ssam * is OS-specific. 260138568Ssam */ 261144618Ssamvoid ieee80211_notify_node_join(struct ieee80211com *, 262138568Ssam struct ieee80211_node *, int newassoc); 263144618Ssamvoid ieee80211_notify_node_leave(struct ieee80211com *, 264138568Ssam struct ieee80211_node *); 265144618Ssamvoid ieee80211_notify_scan_done(struct ieee80211com *); 266116742Ssam#endif /* _NET80211_IEEE80211_PROTO_H_ */ 267