Index: head/sys/net80211/ieee80211_node.c =================================================================== --- head/sys/net80211/ieee80211_node.c (revision 153972) +++ head/sys/net80211/ieee80211_node.c (revision 153973) @@ -1,2357 +1,2360 @@ /*- * Copyright (c) 2001 Atsushi Onoe * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include /* * Association id's are managed with a bit vector. */ #define IEEE80211_AID_SET(b, w) \ ((w)[IEEE80211_AID(b) / 32] |= (1 << (IEEE80211_AID(b) % 32))) #define IEEE80211_AID_CLR(b, w) \ ((w)[IEEE80211_AID(b) / 32] &= ~(1 << (IEEE80211_AID(b) % 32))) #define IEEE80211_AID_ISSET(b, w) \ ((w)[IEEE80211_AID(b) / 32] & (1 << (IEEE80211_AID(b) % 32))) static struct ieee80211_node *node_alloc(struct ieee80211_node_table *); static void node_cleanup(struct ieee80211_node *); static void node_free(struct ieee80211_node *); static u_int8_t node_getrssi(const struct ieee80211_node *); static void ieee80211_setup_node(struct ieee80211_node_table *, struct ieee80211_node *, const u_int8_t *); static void _ieee80211_free_node(struct ieee80211_node *); static void ieee80211_free_allnodes(struct ieee80211_node_table *); static void ieee80211_timeout_scan_candidates(struct ieee80211_node_table *); static void ieee80211_timeout_stations(struct ieee80211_node_table *); static void ieee80211_set_tim(struct ieee80211_node *, int set); static void ieee80211_node_table_init(struct ieee80211com *ic, struct ieee80211_node_table *nt, const char *name, int inact, int keyixmax, void (*timeout)(struct ieee80211_node_table *)); static void ieee80211_node_table_cleanup(struct ieee80211_node_table *nt); MALLOC_DEFINE(M_80211_NODE, "80211node", "802.11 node state"); void ieee80211_node_attach(struct ieee80211com *ic) { ic->ic_node_alloc = node_alloc; ic->ic_node_free = node_free; ic->ic_node_cleanup = node_cleanup; ic->ic_node_getrssi = node_getrssi; /* default station inactivity timer setings */ ic->ic_inact_init = IEEE80211_INACT_INIT; ic->ic_inact_auth = IEEE80211_INACT_AUTH; ic->ic_inact_run = IEEE80211_INACT_RUN; ic->ic_inact_probe = IEEE80211_INACT_PROBE; /* NB: driver should override */ ic->ic_max_aid = IEEE80211_AID_DEF; ic->ic_set_tim = ieee80211_set_tim; } void ieee80211_node_lateattach(struct ieee80211com *ic) { struct ieee80211_rsnparms *rsn; if (ic->ic_max_aid > IEEE80211_AID_MAX) ic->ic_max_aid = IEEE80211_AID_MAX; MALLOC(ic->ic_aid_bitmap, u_int32_t *, howmany(ic->ic_max_aid, 32) * sizeof(u_int32_t), M_DEVBUF, M_NOWAIT | M_ZERO); if (ic->ic_aid_bitmap == NULL) { /* XXX no way to recover */ printf("%s: no memory for AID bitmap!\n", __func__); ic->ic_max_aid = 0; } /* XXX defer until using hostap/ibss mode */ ic->ic_tim_len = howmany(ic->ic_max_aid, 8) * sizeof(u_int8_t); MALLOC(ic->ic_tim_bitmap, u_int8_t *, ic->ic_tim_len, M_DEVBUF, M_NOWAIT | M_ZERO); if (ic->ic_tim_bitmap == NULL) { /* XXX no way to recover */ printf("%s: no memory for TIM bitmap!\n", __func__); } ieee80211_node_table_init(ic, &ic->ic_sta, "station", IEEE80211_INACT_INIT, ic->ic_crypto.cs_max_keyix, ieee80211_timeout_stations); ieee80211_node_table_init(ic, &ic->ic_scan, "scan", IEEE80211_INACT_SCAN, 0, ieee80211_timeout_scan_candidates); ieee80211_reset_bss(ic); /* * Setup "global settings" in the bss node so that * each new station automatically inherits them. */ rsn = &ic->ic_bss->ni_rsn; /* WEP, TKIP, and AES-CCM are always supported */ rsn->rsn_ucastcipherset |= 1<rsn_ucastcipherset |= 1<rsn_ucastcipherset |= 1<ic_caps & IEEE80211_C_AES) rsn->rsn_ucastcipherset |= 1<ic_caps & IEEE80211_C_CKIP) rsn->rsn_ucastcipherset |= 1<rsn_ucastcipher = IEEE80211_CIPHER_WEP; rsn->rsn_ucastkeylen = 104 / NBBY; /* * WPA says the multicast cipher is the lowest unicast * cipher supported. But we skip WEP which would * otherwise be used based on this criteria. */ rsn->rsn_mcastcipher = IEEE80211_CIPHER_TKIP; rsn->rsn_mcastkeylen = 128 / NBBY; /* * We support both WPA-PSK and 802.1x; the one used * is determined by the authentication mode and the * setting of the PSK state. */ rsn->rsn_keymgmtset = WPA_ASE_8021X_UNSPEC | WPA_ASE_8021X_PSK; rsn->rsn_keymgmt = WPA_ASE_8021X_PSK; ic->ic_auth = ieee80211_authenticator_get(ic->ic_bss->ni_authmode); } void ieee80211_node_detach(struct ieee80211com *ic) { if (ic->ic_bss != NULL) { ieee80211_free_node(ic->ic_bss); ic->ic_bss = NULL; } ieee80211_node_table_cleanup(&ic->ic_scan); ieee80211_node_table_cleanup(&ic->ic_sta); if (ic->ic_aid_bitmap != NULL) { FREE(ic->ic_aid_bitmap, M_DEVBUF); ic->ic_aid_bitmap = NULL; } if (ic->ic_tim_bitmap != NULL) { FREE(ic->ic_tim_bitmap, M_DEVBUF); ic->ic_tim_bitmap = NULL; } } /* * Port authorize/unauthorize interfaces for use by an authenticator. */ void ieee80211_node_authorize(struct ieee80211_node *ni) { struct ieee80211com *ic = ni->ni_ic; ni->ni_flags |= IEEE80211_NODE_AUTH; ni->ni_inact_reload = ic->ic_inact_run; } void ieee80211_node_unauthorize(struct ieee80211_node *ni) { ni->ni_flags &= ~IEEE80211_NODE_AUTH; } /* * Set/change the channel. The rate set is also updated as * to insure a consistent view by drivers. */ static void ieee80211_set_chan(struct ieee80211com *ic, struct ieee80211_node *ni, struct ieee80211_channel *chan) { if (chan == IEEE80211_CHAN_ANYC) /* XXX while scanning */ chan = ic->ic_curchan; ni->ni_chan = chan; ni->ni_rates = ic->ic_sup_rates[ieee80211_chan2mode(ic, chan)]; } /* * AP scanning support. */ #ifdef IEEE80211_DEBUG static void dump_chanlist(const u_char chans[]) { const char *sep; int i; sep = " "; for (i = 0; i < IEEE80211_CHAN_MAX; i++) if (isset(chans, i)) { printf("%s%u", sep, i); sep = ", "; } } #endif /* IEEE80211_DEBUG */ /* * Initialize the channel set to scan based on the * of available channels and the current PHY mode. */ static void ieee80211_reset_scan(struct ieee80211com *ic) { /* XXX ic_des_chan should be handled with ic_chan_active */ if (ic->ic_des_chan != IEEE80211_CHAN_ANYC) { memset(ic->ic_chan_scan, 0, sizeof(ic->ic_chan_scan)); setbit(ic->ic_chan_scan, ieee80211_chan2ieee(ic, ic->ic_des_chan)); } else memcpy(ic->ic_chan_scan, ic->ic_chan_active, sizeof(ic->ic_chan_active)); #ifdef IEEE80211_DEBUG if (ieee80211_msg_scan(ic)) { printf("%s: scan set:", __func__); dump_chanlist(ic->ic_chan_scan); printf(" start chan %u\n", ieee80211_chan2ieee(ic, ic->ic_curchan)); } #endif /* IEEE80211_DEBUG */ } /* * Begin an active scan. */ void ieee80211_begin_scan(struct ieee80211com *ic, int reset) { ic->ic_scan.nt_scangen++; /* * In all but hostap mode scanning starts off in * an active mode before switching to passive. */ if (ic->ic_opmode != IEEE80211_M_HOSTAP) { ic->ic_flags |= IEEE80211_F_ASCAN; ic->ic_stats.is_scan_active++; } else ic->ic_stats.is_scan_passive++; IEEE80211_DPRINTF(ic, IEEE80211_MSG_SCAN, "begin %s scan in %s mode, scangen %u\n", (ic->ic_flags & IEEE80211_F_ASCAN) ? "active" : "passive", ieee80211_phymode_name[ic->ic_curmode], ic->ic_scan.nt_scangen); /* * Clear scan state and flush any previously seen AP's. */ ieee80211_reset_scan(ic); if (reset) ieee80211_free_allnodes(&ic->ic_scan); ic->ic_flags |= IEEE80211_F_SCAN; /* Scan the next channel. */ ieee80211_next_scan(ic); } /* * Switch to the next channel marked for scanning. */ int ieee80211_next_scan(struct ieee80211com *ic) { struct ieee80211_channel *chan; /* * Insure any previous mgt frame timeouts don't fire. * This assumes the driver does the right thing in * flushing anything queued in the driver and below. */ ic->ic_mgt_timer = 0; chan = ic->ic_curchan; do { if (++chan > &ic->ic_channels[IEEE80211_CHAN_MAX]) chan = &ic->ic_channels[0]; if (isset(ic->ic_chan_scan, ieee80211_chan2ieee(ic, chan))) { clrbit(ic->ic_chan_scan, ieee80211_chan2ieee(ic, chan)); IEEE80211_DPRINTF(ic, IEEE80211_MSG_SCAN, "%s: chan %d->%d\n", __func__, ieee80211_chan2ieee(ic, ic->ic_curchan), ieee80211_chan2ieee(ic, chan)); ic->ic_curchan = chan; /* * XXX drivers should do this as needed, * XXX for now maintain compatibility */ ic->ic_bss->ni_rates = ic->ic_sup_rates[ieee80211_chan2mode(ic, chan)]; ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); return 1; } } while (chan != ic->ic_curchan); ieee80211_end_scan(ic); return 0; } static __inline void copy_bss(struct ieee80211_node *nbss, const struct ieee80211_node *obss) { /* propagate useful state */ nbss->ni_authmode = obss->ni_authmode; nbss->ni_txpower = obss->ni_txpower; nbss->ni_vlan = obss->ni_vlan; nbss->ni_rsn = obss->ni_rsn; /* XXX statistics? */ } void ieee80211_create_ibss(struct ieee80211com* ic, struct ieee80211_channel *chan) { struct ieee80211_node_table *nt; struct ieee80211_node *ni; IEEE80211_DPRINTF(ic, IEEE80211_MSG_SCAN, "%s: creating ibss\n", __func__); /* * Create the station/neighbor table. Note that for adhoc * mode we make the initial inactivity timer longer since * we create nodes only through discovery and they typically * are long-lived associations. */ nt = &ic->ic_sta; IEEE80211_NODE_LOCK(nt); if (ic->ic_opmode == IEEE80211_M_HOSTAP) { nt->nt_name = "station"; nt->nt_inact_init = ic->ic_inact_init; } else { nt->nt_name = "neighbor"; nt->nt_inact_init = ic->ic_inact_run; } IEEE80211_NODE_UNLOCK(nt); ni = ieee80211_alloc_node(&ic->ic_sta, ic->ic_myaddr); if (ni == NULL) { /* XXX recovery? */ return; } IEEE80211_ADDR_COPY(ni->ni_bssid, ic->ic_myaddr); ni->ni_esslen = ic->ic_des_esslen; memcpy(ni->ni_essid, ic->ic_des_essid, ni->ni_esslen); copy_bss(ni, ic->ic_bss); ni->ni_intval = ic->ic_bintval; if (ic->ic_flags & IEEE80211_F_PRIVACY) ni->ni_capinfo |= IEEE80211_CAPINFO_PRIVACY; if (ic->ic_phytype == IEEE80211_T_FH) { ni->ni_fhdwell = 200; /* XXX */ ni->ni_fhindex = 1; } if (ic->ic_opmode == IEEE80211_M_IBSS) { ic->ic_flags |= IEEE80211_F_SIBSS; ni->ni_capinfo |= IEEE80211_CAPINFO_IBSS; /* XXX */ if (ic->ic_flags & IEEE80211_F_DESBSSID) IEEE80211_ADDR_COPY(ni->ni_bssid, ic->ic_des_bssid); else ni->ni_bssid[0] |= 0x02; /* local bit for IBSS */ } else if (ic->ic_opmode == IEEE80211_M_AHDEMO) { if (ic->ic_flags & IEEE80211_F_DESBSSID) IEEE80211_ADDR_COPY(ni->ni_bssid, ic->ic_des_bssid); else memset(ni->ni_bssid, 0, IEEE80211_ADDR_LEN); } /* * Fix the channel and related attributes. */ ieee80211_set_chan(ic, ni, chan); ic->ic_curchan = chan; ic->ic_curmode = ieee80211_chan2mode(ic, chan); /* * Do mode-specific rate setup. */ if (ic->ic_curmode == IEEE80211_MODE_11G) { /* * Use a mixed 11b/11g rate set. */ ieee80211_set11gbasicrates(&ni->ni_rates, IEEE80211_MODE_11G); } else if (ic->ic_curmode == IEEE80211_MODE_11B) { /* * Force pure 11b rate set. */ ieee80211_set11gbasicrates(&ni->ni_rates, IEEE80211_MODE_11B); } (void) ieee80211_sta_join(ic, ieee80211_ref_node(ni)); } void ieee80211_reset_bss(struct ieee80211com *ic) { struct ieee80211_node *ni, *obss; ieee80211_node_table_reset(&ic->ic_scan); ieee80211_node_table_reset(&ic->ic_sta); ni = ieee80211_alloc_node(&ic->ic_scan, ic->ic_myaddr); KASSERT(ni != NULL, ("unable to setup inital BSS node")); obss = ic->ic_bss; ic->ic_bss = ieee80211_ref_node(ni); if (obss != NULL) { copy_bss(ni, obss); ni->ni_intval = ic->ic_bintval; ieee80211_free_node(obss); } } /* XXX tunable */ #define STA_FAILS_MAX 2 /* assoc failures before ignored */ static int ieee80211_match_bss(struct ieee80211com *ic, struct ieee80211_node *ni) { u_int8_t rate; int fail; fail = 0; if (isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, ni->ni_chan))) fail |= 0x01; if (ic->ic_des_chan != IEEE80211_CHAN_ANYC && ni->ni_chan != ic->ic_des_chan) fail |= 0x01; if (ic->ic_opmode == IEEE80211_M_IBSS) { if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0) fail |= 0x02; } else { if ((ni->ni_capinfo & IEEE80211_CAPINFO_ESS) == 0) fail |= 0x02; } if (ic->ic_flags & IEEE80211_F_PRIVACY) { if ((ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0) fail |= 0x04; } else { /* XXX does this mean privacy is supported or required? */ if (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) fail |= 0x04; } rate = ieee80211_fix_rate(ni, IEEE80211_F_DONEGO | IEEE80211_F_DOFRATE); if (rate & IEEE80211_RATE_BASIC) fail |= 0x08; if (ic->ic_des_esslen != 0 && (ni->ni_esslen != ic->ic_des_esslen || memcmp(ni->ni_essid, ic->ic_des_essid, ic->ic_des_esslen) != 0)) fail |= 0x10; if ((ic->ic_flags & IEEE80211_F_DESBSSID) && !IEEE80211_ADDR_EQ(ic->ic_des_bssid, ni->ni_bssid)) fail |= 0x20; if (ni->ni_fails >= STA_FAILS_MAX) fail |= 0x40; #ifdef IEEE80211_DEBUG if (ieee80211_msg_scan(ic)) { printf(" %c %s", fail & 0x40 ? '=' : fail & 0x80 ? '^' : fail ? '-' : '+', ether_sprintf(ni->ni_macaddr)); printf(" %s%c", ether_sprintf(ni->ni_bssid), fail & 0x20 ? '!' : ' '); printf(" %3d%c", ieee80211_chan2ieee(ic, ni->ni_chan), fail & 0x01 ? '!' : ' '); printf(" %+4d", ni->ni_rssi); printf(" %2dM%c", (rate & IEEE80211_RATE_VAL) / 2, fail & 0x08 ? '!' : ' '); printf(" %4s%c", (ni->ni_capinfo & IEEE80211_CAPINFO_ESS) ? "ess" : (ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) ? "ibss" : "????", fail & 0x02 ? '!' : ' '); printf(" %3s%c ", (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) ? "wep" : "no", fail & 0x04 ? '!' : ' '); ieee80211_print_essid(ni->ni_essid, ni->ni_esslen); printf("%s\n", fail & 0x10 ? "!" : ""); } #endif return fail; } static __inline u_int8_t maxrate(const struct ieee80211_node *ni) { const struct ieee80211_rateset *rs = &ni->ni_rates; /* NB: assumes rate set is sorted (happens on frame receive) */ return rs->rs_rates[rs->rs_nrates-1] & IEEE80211_RATE_VAL; } /* * Compare the capabilities of two nodes and decide which is * more desirable (return >0 if a is considered better). Note * that we assume compatibility/usability has already been checked * so we don't need to (e.g. validate whether privacy is supported). * Used to select the best scan candidate for association in a BSS. */ static int ieee80211_node_compare(struct ieee80211com *ic, const struct ieee80211_node *a, const struct ieee80211_node *b) { u_int8_t maxa, maxb; u_int8_t rssia, rssib; int weight; /* privacy support preferred */ if ((a->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) && (b->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0) return 1; if ((a->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0 && (b->ni_capinfo & IEEE80211_CAPINFO_PRIVACY)) return -1; /* compare count of previous failures */ weight = b->ni_fails - a->ni_fails; if (abs(weight) > 1) return weight; rssia = ic->ic_node_getrssi(a); rssib = ic->ic_node_getrssi(b); if (abs(rssib - rssia) < 5) { /* best/max rate preferred if signal level close enough XXX */ maxa = maxrate(a); maxb = maxrate(b); if (maxa != maxb) return maxa - maxb; /* XXX use freq for channel preference */ /* for now just prefer 5Ghz band to all other bands */ if (IEEE80211_IS_CHAN_5GHZ(a->ni_chan) && !IEEE80211_IS_CHAN_5GHZ(b->ni_chan)) return 1; if (!IEEE80211_IS_CHAN_5GHZ(a->ni_chan) && IEEE80211_IS_CHAN_5GHZ(b->ni_chan)) return -1; } /* all things being equal, use signal level */ return rssia - rssib; } /* * Mark an ongoing scan stopped. */ void ieee80211_cancel_scan(struct ieee80211com *ic) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_SCAN, "%s: end %s scan\n", __func__, (ic->ic_flags & IEEE80211_F_ASCAN) ? "active" : "passive"); ic->ic_flags &= ~(IEEE80211_F_SCAN | IEEE80211_F_ASCAN); } /* * Complete a scan of potential channels. */ void ieee80211_end_scan(struct ieee80211com *ic) { struct ieee80211_node_table *nt = &ic->ic_scan; struct ieee80211_node *ni, *selbs; ieee80211_cancel_scan(ic); ieee80211_notify_scan_done(ic); if (ic->ic_opmode == IEEE80211_M_HOSTAP) { u_int8_t maxrssi[IEEE80211_CHAN_MAX]; /* XXX off stack? */ int i, bestchan; u_int8_t rssi; /* * The passive scan to look for existing AP's completed, * select a channel to camp on. Identify the channels * that already have one or more AP's and try to locate * an unoccupied one. If that fails, pick a channel that * looks to be quietest. */ memset(maxrssi, 0, sizeof(maxrssi)); IEEE80211_NODE_LOCK(nt); TAILQ_FOREACH(ni, &nt->nt_node, ni_list) { rssi = ic->ic_node_getrssi(ni); i = ieee80211_chan2ieee(ic, ni->ni_chan); if (rssi > maxrssi[i]) maxrssi[i] = rssi; } IEEE80211_NODE_UNLOCK(nt); /* XXX select channel more intelligently */ bestchan = -1; for (i = 0; i < IEEE80211_CHAN_MAX; i++) if (isset(ic->ic_chan_active, i)) { /* * If the channel is unoccupied the max rssi * should be zero; just take it. Otherwise * track the channel with the lowest rssi and * use that when all channels appear occupied. */ if (maxrssi[i] == 0) { bestchan = i; break; } if (bestchan == -1 || maxrssi[i] < maxrssi[bestchan]) bestchan = i; } if (bestchan != -1) { ieee80211_create_ibss(ic, &ic->ic_channels[bestchan]); return; } /* no suitable channel, should not happen */ } /* * When manually sequencing the state machine; scan just once * regardless of whether we have a candidate or not. The * controlling application is expected to setup state and * initiate an association. */ if (ic->ic_roaming == IEEE80211_ROAMING_MANUAL) return; /* * Automatic sequencing; look for a candidate and * if found join the network. */ /* NB: unlocked read should be ok */ if (TAILQ_FIRST(&nt->nt_node) == NULL) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_SCAN, "%s: no scan candidate\n", __func__); notfound: if (ic->ic_opmode == IEEE80211_M_IBSS && (ic->ic_flags & IEEE80211_F_IBSSON) && ic->ic_des_esslen != 0) { ieee80211_create_ibss(ic, ic->ic_ibss_chan); return; } /* * Decrement the failure counts so entries will be * reconsidered the next time around. We really want * to do this only for sta's where we've previously * had some success. */ IEEE80211_NODE_LOCK(nt); TAILQ_FOREACH(ni, &nt->nt_node, ni_list) if (ni->ni_fails) ni->ni_fails--; IEEE80211_NODE_UNLOCK(nt); /* * Reset the list of channels to scan and start again. */ ieee80211_reset_scan(ic); ic->ic_flags |= IEEE80211_F_SCAN; ieee80211_next_scan(ic); return; } selbs = NULL; IEEE80211_DPRINTF(ic, IEEE80211_MSG_SCAN, "\t%s\n", "macaddr bssid chan rssi rate flag wep essid"); IEEE80211_NODE_LOCK(nt); TAILQ_FOREACH(ni, &nt->nt_node, ni_list) { if (ieee80211_match_bss(ic, ni) == 0) { if (selbs == NULL) selbs = ni; else if (ieee80211_node_compare(ic, ni, selbs) > 0) selbs = ni; } } if (selbs != NULL) /* NB: grab ref while dropping lock */ (void) ieee80211_ref_node(selbs); IEEE80211_NODE_UNLOCK(nt); if (selbs == NULL) goto notfound; if (!ieee80211_sta_join(ic, selbs)) { ieee80211_free_node(selbs); goto notfound; } } /* * Handle 802.11 ad hoc network merge. The * convention, set by the Wireless Ethernet Compatibility Alliance * (WECA), is that an 802.11 station will change its BSSID to match * the "oldest" 802.11 ad hoc network, on the same channel, that * has the station's desired SSID. The "oldest" 802.11 network * sends beacons with the greatest TSF timestamp. * * The caller is assumed to validate TSF's before attempting a merge. * * Return !0 if the BSSID changed, 0 otherwise. */ int ieee80211_ibss_merge(struct ieee80211_node *ni) { struct ieee80211com *ic = ni->ni_ic; if (ni == ic->ic_bss || IEEE80211_ADDR_EQ(ni->ni_bssid, ic->ic_bss->ni_bssid)) { /* unchanged, nothing to do */ return 0; } if (ieee80211_match_bss(ic, ni) != 0) { /* capabilities mismatch */ IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC, "%s: merge failed, capabilities mismatch\n", __func__); ic->ic_stats.is_ibss_capmismatch++; return 0; } IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC, "%s: new bssid %s: %s preamble, %s slot time%s\n", __func__, ether_sprintf(ni->ni_bssid), ic->ic_flags&IEEE80211_F_SHPREAMBLE ? "short" : "long", ic->ic_flags&IEEE80211_F_SHSLOT ? "short" : "long", ic->ic_flags&IEEE80211_F_USEPROT ? ", protection" : "" ); return ieee80211_sta_join(ic, ieee80211_ref_node(ni)); } /* * Join the specified IBSS/BSS network. The node is assumed to * be passed in with a held reference. */ int ieee80211_sta_join(struct ieee80211com *ic, struct ieee80211_node *selbs) { struct ieee80211_node *obss; if (ic->ic_opmode == IEEE80211_M_IBSS) { struct ieee80211_node_table *nt; /* * Delete unusable rates; we've already checked * that the negotiated rate set is acceptable. */ ieee80211_fix_rate(selbs, IEEE80211_F_DODEL); /* * Fillin the neighbor table; it will already * exist if we are simply switching mastership. * XXX ic_sta always setup so this is unnecessary? */ nt = &ic->ic_sta; IEEE80211_NODE_LOCK(nt); nt->nt_name = "neighbor"; nt->nt_inact_init = ic->ic_inact_run; IEEE80211_NODE_UNLOCK(nt); } /* * Committed to selbs, setup state. */ obss = ic->ic_bss; ic->ic_bss = selbs; /* NB: caller assumed to bump refcnt */ if (obss != NULL) { copy_bss(selbs, obss); ieee80211_free_node(obss); } /* * Set the erp state (mostly the slot time) to deal with * the auto-select case; this should be redundant if the * mode is locked. */ ic->ic_curmode = ieee80211_chan2mode(ic, selbs->ni_chan); ic->ic_curchan = selbs->ni_chan; ieee80211_reset_erp(ic); ieee80211_wme_initparams(ic); if (ic->ic_opmode == IEEE80211_M_STA) ieee80211_new_state(ic, IEEE80211_S_AUTH, -1); else ieee80211_new_state(ic, IEEE80211_S_RUN, -1); return 1; } /* * Leave the specified IBSS/BSS network. The node is assumed to * be passed in with a held reference. */ void ieee80211_sta_leave(struct ieee80211com *ic, struct ieee80211_node *ni) { ic->ic_node_cleanup(ni); ieee80211_notify_node_leave(ic, ni); } static struct ieee80211_node * node_alloc(struct ieee80211_node_table *nt) { struct ieee80211_node *ni; MALLOC(ni, struct ieee80211_node *, sizeof(struct ieee80211_node), M_80211_NODE, M_NOWAIT | M_ZERO); return ni; } /* * Reclaim any resources in a node and reset any critical * state. Typically nodes are free'd immediately after, * but in some cases the storage may be reused so we need * to insure consistent state (should probably fix that). */ static void node_cleanup(struct ieee80211_node *ni) { #define N(a) (sizeof(a)/sizeof(a[0])) struct ieee80211com *ic = ni->ni_ic; int i, qlen; /* NB: preserve ni_table */ if (ni->ni_flags & IEEE80211_NODE_PWR_MGT) { ic->ic_ps_sta--; ni->ni_flags &= ~IEEE80211_NODE_PWR_MGT; IEEE80211_DPRINTF(ic, IEEE80211_MSG_POWER, "[%s] power save mode off, %u sta's in ps mode\n", ether_sprintf(ni->ni_macaddr), ic->ic_ps_sta); } /* * Clear AREF flag that marks the authorization refcnt bump * has happened. This is probably not needed as the node * should always be removed from the table so not found but * do it just in case. */ ni->ni_flags &= ~IEEE80211_NODE_AREF; /* * Drain power save queue and, if needed, clear TIM. */ IEEE80211_NODE_SAVEQ_DRAIN(ni, qlen); if (qlen != 0 && ic->ic_set_tim != NULL) ic->ic_set_tim(ni, 0); ni->ni_associd = 0; if (ni->ni_challenge != NULL) { FREE(ni->ni_challenge, M_DEVBUF); ni->ni_challenge = NULL; } /* * Preserve SSID, WPA, and WME ie's so the bss node is * reusable during a re-auth/re-assoc state transition. * If we remove these data they will not be recreated * because they come from a probe-response or beacon frame * which cannot be expected prior to the association-response. * This should not be an issue when operating in other modes * as stations leaving always go through a full state transition * which will rebuild this state. * * XXX does this leave us open to inheriting old state? */ for (i = 0; i < N(ni->ni_rxfrag); i++) if (ni->ni_rxfrag[i] != NULL) { m_freem(ni->ni_rxfrag[i]); ni->ni_rxfrag[i] = NULL; } /* * Must be careful here to remove any key map entry w/o a LOR. */ ieee80211_node_delucastkey(ni); #undef N } static void node_free(struct ieee80211_node *ni) { struct ieee80211com *ic = ni->ni_ic; ic->ic_node_cleanup(ni); if (ni->ni_wpa_ie != NULL) FREE(ni->ni_wpa_ie, M_DEVBUF); if (ni->ni_wme_ie != NULL) FREE(ni->ni_wme_ie, M_DEVBUF); IEEE80211_NODE_SAVEQ_DESTROY(ni); FREE(ni, M_80211_NODE); } static u_int8_t node_getrssi(const struct ieee80211_node *ni) { return ni->ni_rssi; } static void ieee80211_setup_node(struct ieee80211_node_table *nt, struct ieee80211_node *ni, const u_int8_t *macaddr) { struct ieee80211com *ic = nt->nt_ic; int hash; IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, "%s %p<%s> in %s table\n", __func__, ni, ether_sprintf(macaddr), nt->nt_name); IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr); hash = IEEE80211_NODE_HASH(macaddr); ieee80211_node_initref(ni); /* mark referenced */ ni->ni_chan = IEEE80211_CHAN_ANYC; ni->ni_authmode = IEEE80211_AUTH_OPEN; ni->ni_txpower = ic->ic_txpowlimit; /* max power */ ieee80211_crypto_resetkey(ic, &ni->ni_ucastkey, IEEE80211_KEYIX_NONE); ni->ni_inact_reload = nt->nt_inact_init; ni->ni_inact = ni->ni_inact_reload; IEEE80211_NODE_SAVEQ_INIT(ni, "unknown"); IEEE80211_NODE_LOCK(nt); TAILQ_INSERT_TAIL(&nt->nt_node, ni, ni_list); LIST_INSERT_HEAD(&nt->nt_hash[hash], ni, ni_hash); ni->ni_table = nt; ni->ni_ic = ic; IEEE80211_NODE_UNLOCK(nt); } struct ieee80211_node * ieee80211_alloc_node(struct ieee80211_node_table *nt, const u_int8_t *macaddr) { struct ieee80211com *ic = nt->nt_ic; struct ieee80211_node *ni; ni = ic->ic_node_alloc(nt); if (ni != NULL) ieee80211_setup_node(nt, ni, macaddr); else ic->ic_stats.is_rx_nodealloc++; return ni; } /* * Craft a temporary node suitable for sending a management frame * to the specified station. We craft only as much state as we * need to do the work since the node will be immediately reclaimed * once the send completes. */ struct ieee80211_node * ieee80211_tmp_node(struct ieee80211com *ic, const u_int8_t *macaddr) { struct ieee80211_node *ni; ni = ic->ic_node_alloc(&ic->ic_sta); if (ni != NULL) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, "%s %p<%s>\n", __func__, ni, ether_sprintf(macaddr)); IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr); IEEE80211_ADDR_COPY(ni->ni_bssid, ic->ic_bss->ni_bssid); ieee80211_node_initref(ni); /* mark referenced */ ni->ni_txpower = ic->ic_bss->ni_txpower; /* NB: required by ieee80211_fix_rate */ ieee80211_set_chan(ic, ni, ic->ic_bss->ni_chan); ieee80211_crypto_resetkey(ic, &ni->ni_ucastkey, IEEE80211_KEYIX_NONE); /* XXX optimize away */ IEEE80211_NODE_SAVEQ_INIT(ni, "unknown"); ni->ni_table = NULL; /* NB: pedantic */ ni->ni_ic = ic; } else { /* XXX msg */ ic->ic_stats.is_rx_nodealloc++; } return ni; } struct ieee80211_node * ieee80211_dup_bss(struct ieee80211_node_table *nt, const u_int8_t *macaddr) { struct ieee80211com *ic = nt->nt_ic; struct ieee80211_node *ni; ni = ic->ic_node_alloc(nt); if (ni != NULL) { ieee80211_setup_node(nt, ni, macaddr); /* * Inherit from ic_bss. */ ni->ni_authmode = ic->ic_bss->ni_authmode; ni->ni_txpower = ic->ic_bss->ni_txpower; ni->ni_vlan = ic->ic_bss->ni_vlan; /* XXX?? */ IEEE80211_ADDR_COPY(ni->ni_bssid, ic->ic_bss->ni_bssid); ieee80211_set_chan(ic, ni, ic->ic_bss->ni_chan); ni->ni_rsn = ic->ic_bss->ni_rsn; } else ic->ic_stats.is_rx_nodealloc++; return ni; } static struct ieee80211_node * #ifdef IEEE80211_DEBUG_REFCNT _ieee80211_find_node_debug(struct ieee80211_node_table *nt, const u_int8_t *macaddr, const char *func, int line) #else _ieee80211_find_node(struct ieee80211_node_table *nt, const u_int8_t *macaddr) #endif { struct ieee80211_node *ni; int hash; IEEE80211_NODE_LOCK_ASSERT(nt); hash = IEEE80211_NODE_HASH(macaddr); LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) { if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) { ieee80211_ref_node(ni); /* mark referenced */ #ifdef IEEE80211_DEBUG_REFCNT IEEE80211_DPRINTF(nt->nt_ic, IEEE80211_MSG_NODE, "%s (%s:%u) %p<%s> refcnt %d\n", __func__, func, line, ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)); #endif return ni; } } return NULL; } #ifdef IEEE80211_DEBUG_REFCNT #define _ieee80211_find_node(nt, mac) \ _ieee80211_find_node_debug(nt, mac, func, line) #endif struct ieee80211_node * #ifdef IEEE80211_DEBUG_REFCNT ieee80211_find_node_debug(struct ieee80211_node_table *nt, const u_int8_t *macaddr, const char *func, int line) #else ieee80211_find_node(struct ieee80211_node_table *nt, const u_int8_t *macaddr) #endif { struct ieee80211_node *ni; IEEE80211_NODE_LOCK(nt); ni = _ieee80211_find_node(nt, macaddr); IEEE80211_NODE_UNLOCK(nt); return ni; } /* * Fake up a node; this handles node discovery in adhoc mode. * Note that for the driver's benefit we we treat this like * an association so the driver has an opportunity to setup * it's private state. */ struct ieee80211_node * ieee80211_fakeup_adhoc_node(struct ieee80211_node_table *nt, const u_int8_t macaddr[IEEE80211_ADDR_LEN]) { struct ieee80211com *ic = nt->nt_ic; struct ieee80211_node *ni; IEEE80211_DPRINTF(nt->nt_ic, IEEE80211_MSG_NODE, "%s: mac<%s>\n", __func__, ether_sprintf(macaddr)); ni = ieee80211_dup_bss(nt, macaddr); if (ni != NULL) { /* XXX no rate negotiation; just dup */ ni->ni_rates = ic->ic_bss->ni_rates; if (ic->ic_newassoc != NULL) ic->ic_newassoc(ni, 1); /* XXX not right for 802.1x/WPA */ ieee80211_node_authorize(ni); if (ic->ic_opmode == IEEE80211_M_AHDEMO) { /* * Blindly propagate capabilities based on the * local configuration. In particular this permits * us to use QoS to disable ACK's. */ if (ic->ic_flags & IEEE80211_F_WME) ni->ni_flags |= IEEE80211_NODE_QOS; } } return ni; } #ifdef IEEE80211_DEBUG static void dump_probe_beacon(u_int8_t subtype, int isnew, const u_int8_t mac[IEEE80211_ADDR_LEN], const struct ieee80211_scanparams *sp) { printf("[%s] %s%s on chan %u (bss chan %u) ", ether_sprintf(mac), isnew ? "new " : "", ieee80211_mgt_subtype_name[subtype >> IEEE80211_FC0_SUBTYPE_SHIFT], sp->chan, sp->bchan); ieee80211_print_essid(sp->ssid + 2, sp->ssid[1]); printf("\n"); if (isnew) { printf("[%s] caps 0x%x bintval %u erp 0x%x", ether_sprintf(mac), sp->capinfo, sp->bintval, sp->erp); if (sp->country != NULL) { #ifdef __FreeBSD__ printf(" country info %*D", sp->country[1], sp->country+2, " "); #else int i; printf(" country info"); for (i = 0; i < sp->country[1]; i++) printf(" %02x", sp->country[i+2]); #endif } printf("\n"); } } #endif /* IEEE80211_DEBUG */ static void saveie(u_int8_t **iep, const u_int8_t *ie) { if (ie == NULL) *iep = NULL; else ieee80211_saveie(iep, ie); } /* * Process a beacon or probe response frame. */ void ieee80211_add_scan(struct ieee80211com *ic, const struct ieee80211_scanparams *sp, const struct ieee80211_frame *wh, int subtype, int rssi, int rstamp) { #define ISPROBE(_st) ((_st) == IEEE80211_FC0_SUBTYPE_PROBE_RESP) struct ieee80211_node_table *nt = &ic->ic_scan; struct ieee80211_node *ni; int newnode = 0; ni = ieee80211_find_node(nt, wh->i_addr2); if (ni == NULL) { /* * Create a new entry. */ ni = ic->ic_node_alloc(nt); if (ni == NULL) { ic->ic_stats.is_rx_nodealloc++; return; } ieee80211_setup_node(nt, ni, wh->i_addr2); /* * XXX inherit from ic_bss. */ ni->ni_authmode = ic->ic_bss->ni_authmode; ni->ni_txpower = ic->ic_bss->ni_txpower; ni->ni_vlan = ic->ic_bss->ni_vlan; /* XXX?? */ ieee80211_set_chan(ic, ni, ic->ic_curchan); ni->ni_rsn = ic->ic_bss->ni_rsn; newnode = 1; } #ifdef IEEE80211_DEBUG if (ieee80211_msg_scan(ic) && (ic->ic_flags & IEEE80211_F_SCAN)) dump_probe_beacon(subtype, newnode, wh->i_addr2, sp); #endif /* XXX ap beaconing multiple ssid w/ same bssid */ if (sp->ssid[1] != 0 && (ISPROBE(subtype) || ni->ni_esslen == 0)) { ni->ni_esslen = sp->ssid[1]; memset(ni->ni_essid, 0, sizeof(ni->ni_essid)); memcpy(ni->ni_essid, sp->ssid + 2, sp->ssid[1]); } ni->ni_scangen = ic->ic_scan.nt_scangen; IEEE80211_ADDR_COPY(ni->ni_bssid, wh->i_addr3); ni->ni_rssi = rssi; ni->ni_rstamp = rstamp; memcpy(ni->ni_tstamp.data, sp->tstamp, sizeof(ni->ni_tstamp)); ni->ni_intval = sp->bintval; ni->ni_capinfo = sp->capinfo; ni->ni_chan = &ic->ic_channels[sp->chan]; ni->ni_fhdwell = sp->fhdwell; ni->ni_fhindex = sp->fhindex; ni->ni_erp = sp->erp; if (sp->tim != NULL) { struct ieee80211_tim_ie *ie = (struct ieee80211_tim_ie *) sp->tim; ni->ni_dtim_count = ie->tim_count; ni->ni_dtim_period = ie->tim_period; } /* * Record the byte offset from the mac header to * the start of the TIM information element for * use by hardware and/or to speedup software * processing of beacon frames. */ ni->ni_timoff = sp->timoff; /* * Record optional information elements that might be * used by applications or drivers. */ saveie(&ni->ni_wme_ie, sp->wme); saveie(&ni->ni_wpa_ie, sp->wpa); /* NB: must be after ni_chan is setup */ ieee80211_setup_rates(ni, sp->rates, sp->xrates, IEEE80211_F_DOSORT); if (!newnode) ieee80211_free_node(ni); #undef ISPROBE } void ieee80211_init_neighbor(struct ieee80211_node *ni, const struct ieee80211_frame *wh, const struct ieee80211_scanparams *sp) { IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_NODE, "%s: %p<%s>\n", __func__, ni, ether_sprintf(ni->ni_macaddr)); ni->ni_esslen = sp->ssid[1]; memcpy(ni->ni_essid, sp->ssid + 2, sp->ssid[1]); IEEE80211_ADDR_COPY(ni->ni_bssid, wh->i_addr3); memcpy(ni->ni_tstamp.data, sp->tstamp, sizeof(ni->ni_tstamp)); ni->ni_intval = sp->bintval; ni->ni_capinfo = sp->capinfo; ni->ni_chan = ni->ni_ic->ic_curchan; ni->ni_fhdwell = sp->fhdwell; ni->ni_fhindex = sp->fhindex; ni->ni_erp = sp->erp; ni->ni_timoff = sp->timoff; if (sp->wme != NULL) ieee80211_saveie(&ni->ni_wme_ie, sp->wme); if (sp->wpa != NULL) ieee80211_saveie(&ni->ni_wpa_ie, sp->wpa); /* NB: must be after ni_chan is setup */ ieee80211_setup_rates(ni, sp->rates, sp->xrates, IEEE80211_F_DOSORT); } /* * Do node discovery in adhoc mode on receipt of a beacon * or probe response frame. Note that for the driver's * benefit we we treat this like an association so the * driver has an opportunity to setup it's private state. */ struct ieee80211_node * ieee80211_add_neighbor(struct ieee80211com *ic, const struct ieee80211_frame *wh, const struct ieee80211_scanparams *sp) { struct ieee80211_node *ni; IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, "%s: mac<%s>\n", __func__, ether_sprintf(wh->i_addr2)); ni = ieee80211_dup_bss(&ic->ic_sta, wh->i_addr2);/* XXX alloc_node? */ if (ni != NULL) { ieee80211_init_neighbor(ni, wh, sp); if (ic->ic_newassoc != NULL) ic->ic_newassoc(ni, 1); /* XXX not right for 802.1x/WPA */ ieee80211_node_authorize(ni); } return ni; } #define IS_CTL(wh) \ ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL) #define IS_PSPOLL(wh) \ ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == IEEE80211_FC0_SUBTYPE_PS_POLL) /* * Locate the node for sender, track state, and then pass the * (referenced) node up to the 802.11 layer for its use. We * are required to pass some node so we fall back to ic_bss * when this frame is from an unknown sender. The 802.11 layer * knows this means the sender wasn't in the node table and * acts accordingly. */ struct ieee80211_node * #ifdef IEEE80211_DEBUG_REFCNT ieee80211_find_rxnode_debug(struct ieee80211com *ic, const struct ieee80211_frame_min *wh, const char *func, int line) #else ieee80211_find_rxnode(struct ieee80211com *ic, const struct ieee80211_frame_min *wh) #endif { struct ieee80211_node_table *nt; struct ieee80211_node *ni; /* XXX may want scanned nodes in the neighbor table for adhoc */ if (ic->ic_opmode == IEEE80211_M_STA || ic->ic_opmode == IEEE80211_M_MONITOR || (ic->ic_flags & IEEE80211_F_SCAN)) nt = &ic->ic_scan; else nt = &ic->ic_sta; /* XXX check ic_bss first in station mode */ /* XXX 4-address frames? */ IEEE80211_NODE_LOCK(nt); if (IS_CTL(wh) && !IS_PSPOLL(wh) /*&& !IS_RTS(ah)*/) ni = _ieee80211_find_node(nt, wh->i_addr1); else ni = _ieee80211_find_node(nt, wh->i_addr2); if (ni == NULL) ni = ieee80211_ref_node(ic->ic_bss); IEEE80211_NODE_UNLOCK(nt); return ni; } /* * Like ieee80211_find_rxnode but use the supplied h/w * key index as a hint to locate the node in the key * mapping table. If an entry is present at the key * index we return it; otherwise do a normal lookup and * update the mapping table if the station has a unicast * key assigned to it. */ struct ieee80211_node * #ifdef IEEE80211_DEBUG_REFCNT ieee80211_find_rxnode_withkey_debug(struct ieee80211com *ic, const struct ieee80211_frame_min *wh, ieee80211_keyix keyix, const char *func, int line) #else ieee80211_find_rxnode_withkey(struct ieee80211com *ic, const struct ieee80211_frame_min *wh, ieee80211_keyix keyix) #endif { struct ieee80211_node_table *nt; struct ieee80211_node *ni; if (ic->ic_opmode == IEEE80211_M_STA || ic->ic_opmode == IEEE80211_M_MONITOR || (ic->ic_flags & IEEE80211_F_SCAN)) nt = &ic->ic_scan; else nt = &ic->ic_sta; IEEE80211_NODE_LOCK(nt); if (nt->nt_keyixmap != NULL && keyix < nt->nt_keyixmax) ni = nt->nt_keyixmap[keyix]; else ni = NULL; if (ni == NULL) { if (IS_CTL(wh) && !IS_PSPOLL(wh) /*&& !IS_RTS(ah)*/) ni = _ieee80211_find_node(nt, wh->i_addr1); else ni = _ieee80211_find_node(nt, wh->i_addr2); if (ni == NULL) ni = ieee80211_ref_node(ic->ic_bss); if (nt->nt_keyixmap != NULL) { /* * If the station has a unicast key cache slot * assigned update the key->node mapping table. */ keyix = ni->ni_ucastkey.wk_rxkeyix; /* XXX can keyixmap[keyix] != NULL? */ if (keyix < nt->nt_keyixmax && nt->nt_keyixmap[keyix] == NULL) { IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_NODE, "%s: add key map entry %p<%s> refcnt %d\n", __func__, ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)+1); nt->nt_keyixmap[keyix] = ieee80211_ref_node(ni); } } } else { ieee80211_ref_node(ni); } IEEE80211_NODE_UNLOCK(nt); return ni; } #undef IS_PSPOLL #undef IS_CTL /* * Return a reference to the appropriate node for sending * a data frame. This handles node discovery in adhoc networks. */ struct ieee80211_node * #ifdef IEEE80211_DEBUG_REFCNT ieee80211_find_txnode_debug(struct ieee80211com *ic, const u_int8_t *macaddr, const char *func, int line) #else ieee80211_find_txnode(struct ieee80211com *ic, const u_int8_t *macaddr) #endif { struct ieee80211_node_table *nt = &ic->ic_sta; struct ieee80211_node *ni; /* * The destination address should be in the node table * unless this is a multicast/broadcast frame. We can * also optimize station mode operation, all frames go * to the bss node. */ /* XXX can't hold lock across dup_bss 'cuz of recursive locking */ IEEE80211_NODE_LOCK(nt); if (ic->ic_opmode == IEEE80211_M_STA || IEEE80211_IS_MULTICAST(macaddr)) ni = ieee80211_ref_node(ic->ic_bss); else ni = _ieee80211_find_node(nt, macaddr); IEEE80211_NODE_UNLOCK(nt); if (ni == NULL) { if (ic->ic_opmode == IEEE80211_M_IBSS || ic->ic_opmode == IEEE80211_M_AHDEMO) { /* * In adhoc mode cons up a node for the destination. * Note that we need an additional reference for the * caller to be consistent with _ieee80211_find_node. */ ni = ieee80211_fakeup_adhoc_node(nt, macaddr); if (ni != NULL) (void) ieee80211_ref_node(ni); } else { IEEE80211_DPRINTF(ic, IEEE80211_MSG_OUTPUT, "[%s] no node, discard frame (%s)\n", ether_sprintf(macaddr), __func__); ic->ic_stats.is_tx_nonode++; } } return ni; } /* * Like find but search based on the channel too. */ struct ieee80211_node * #ifdef IEEE80211_DEBUG_REFCNT ieee80211_find_node_with_channel_debug(struct ieee80211_node_table *nt, const u_int8_t *macaddr, struct ieee80211_channel *chan, const char *func, int line) #else ieee80211_find_node_with_channel(struct ieee80211_node_table *nt, const u_int8_t *macaddr, struct ieee80211_channel *chan) #endif { struct ieee80211_node *ni; int hash; hash = IEEE80211_NODE_HASH(macaddr); IEEE80211_NODE_LOCK(nt); LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) { if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && ni->ni_chan == chan) { ieee80211_ref_node(ni); /* mark referenced */ IEEE80211_DPRINTF(nt->nt_ic, IEEE80211_MSG_NODE, #ifdef IEEE80211_DEBUG_REFCNT "%s (%s:%u) %p<%s> refcnt %d\n", __func__, func, line, #else "%s %p<%s> refcnt %d\n", __func__, #endif ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)); break; } } IEEE80211_NODE_UNLOCK(nt); return ni; } /* * Like find but search based on the ssid too. */ struct ieee80211_node * #ifdef IEEE80211_DEBUG_REFCNT ieee80211_find_node_with_ssid_debug(struct ieee80211_node_table *nt, const u_int8_t *macaddr, u_int ssidlen, const u_int8_t *ssid, const char *func, int line) #else ieee80211_find_node_with_ssid(struct ieee80211_node_table *nt, const u_int8_t *macaddr, u_int ssidlen, const u_int8_t *ssid) #endif { #define MATCH_SSID(ni, ssid, ssidlen) \ (ni->ni_esslen == ssidlen && memcmp(ni->ni_essid, ssid, ssidlen) == 0) static const u_int8_t zeromac[IEEE80211_ADDR_LEN]; struct ieee80211com *ic = nt->nt_ic; struct ieee80211_node *ni; int hash; IEEE80211_NODE_LOCK(nt); /* * A mac address that is all zero means match only the ssid; * otherwise we must match both. */ if (IEEE80211_ADDR_EQ(macaddr, zeromac)) { TAILQ_FOREACH(ni, &nt->nt_node, ni_list) { if (MATCH_SSID(ni, ssid, ssidlen)) break; } } else { hash = IEEE80211_NODE_HASH(macaddr); LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) { if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && MATCH_SSID(ni, ssid, ssidlen)) break; } } if (ni != NULL) { ieee80211_ref_node(ni); /* mark referenced */ IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, #ifdef IEEE80211_DEBUG_REFCNT "%s (%s:%u) %p<%s> refcnt %d\n", __func__, func, line, #else "%s %p<%s> refcnt %d\n", __func__, #endif ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)); } IEEE80211_NODE_UNLOCK(nt); return ni; #undef MATCH_SSID } static void _ieee80211_free_node(struct ieee80211_node *ni) { struct ieee80211com *ic = ni->ni_ic; struct ieee80211_node_table *nt = ni->ni_table; IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, "%s %p<%s> in %s table\n", __func__, ni, ether_sprintf(ni->ni_macaddr), nt != NULL ? nt->nt_name : ""); IEEE80211_AID_CLR(ni->ni_associd, ic->ic_aid_bitmap); if (nt != NULL) { TAILQ_REMOVE(&nt->nt_node, ni, ni_list); LIST_REMOVE(ni, ni_hash); } ic->ic_node_free(ni); } void #ifdef IEEE80211_DEBUG_REFCNT ieee80211_free_node_debug(struct ieee80211_node *ni, const char *func, int line) #else ieee80211_free_node(struct ieee80211_node *ni) #endif { struct ieee80211_node_table *nt = ni->ni_table; #ifdef IEEE80211_DEBUG_REFCNT IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_NODE, "%s (%s:%u) %p<%s> refcnt %d\n", __func__, func, line, ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)-1); #endif if (nt != NULL) { IEEE80211_NODE_LOCK(nt); if (ieee80211_node_dectestref(ni)) { /* * Last reference, reclaim state. */ _ieee80211_free_node(ni); } else if (ieee80211_node_refcnt(ni) == 1 && nt->nt_keyixmap != NULL) { ieee80211_keyix keyix; /* * Check for a last reference in the key mapping table. */ keyix = ni->ni_ucastkey.wk_rxkeyix; if (keyix < nt->nt_keyixmax && nt->nt_keyixmap[keyix] == ni) { IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_NODE, "%s: %p<%s> clear key map entry", __func__, ni, ether_sprintf(ni->ni_macaddr)); nt->nt_keyixmap[keyix] = NULL; ieee80211_node_decref(ni); /* XXX needed? */ _ieee80211_free_node(ni); } } IEEE80211_NODE_UNLOCK(nt); } else { if (ieee80211_node_dectestref(ni)) _ieee80211_free_node(ni); } } /* * Reclaim a unicast key and clear any key cache state. */ int ieee80211_node_delucastkey(struct ieee80211_node *ni) { struct ieee80211com *ic = ni->ni_ic; struct ieee80211_node_table *nt = &ic->ic_sta; struct ieee80211_node *nikey; ieee80211_keyix keyix; int isowned, status; /* * NB: We must beware of LOR here; deleting the key * can cause the crypto layer to block traffic updates * which can generate a LOR against the node table lock; * grab it here and stash the key index for our use below. * * Must also beware of recursion on the node table lock. * When called from node_cleanup we may already have * the node table lock held. Unfortunately there's no * way to separate out this path so we must do this * conditionally. */ isowned = IEEE80211_NODE_IS_LOCKED(nt); if (!isowned) IEEE80211_NODE_LOCK(nt); keyix = ni->ni_ucastkey.wk_rxkeyix; status = ieee80211_crypto_delkey(ic, &ni->ni_ucastkey); if (nt->nt_keyixmap != NULL && keyix < nt->nt_keyixmax) { nikey = nt->nt_keyixmap[keyix]; nt->nt_keyixmap[keyix] = NULL;; } else nikey = NULL; if (!isowned) IEEE80211_NODE_UNLOCK(&ic->ic_sta); if (nikey != NULL) { KASSERT(nikey == ni, ("key map out of sync, ni %p nikey %p", ni, nikey)); IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_NODE, "%s: delete key map entry %p<%s> refcnt %d\n", __func__, ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)-1); ieee80211_free_node(ni); } return status; } /* * Reclaim a node. If this is the last reference count then * do the normal free work. Otherwise remove it from the node * table and mark it gone by clearing the back-reference. */ static void node_reclaim(struct ieee80211_node_table *nt, struct ieee80211_node *ni) { ieee80211_keyix keyix; IEEE80211_NODE_LOCK_ASSERT(nt); IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_NODE, "%s: remove %p<%s> from %s table, refcnt %d\n", __func__, ni, ether_sprintf(ni->ni_macaddr), nt->nt_name, ieee80211_node_refcnt(ni)-1); /* * Clear any entry in the unicast key mapping table. * We need to do it here so rx lookups don't find it * in the mapping table even if it's not in the hash * table. We cannot depend on the mapping table entry * being cleared because the node may not be free'd. */ keyix = ni->ni_ucastkey.wk_rxkeyix; if (nt->nt_keyixmap != NULL && keyix < nt->nt_keyixmax && nt->nt_keyixmap[keyix] == ni) { IEEE80211_DPRINTF(ni->ni_ic, IEEE80211_MSG_NODE, "%s: %p<%s> clear key map entry\n", __func__, ni, ether_sprintf(ni->ni_macaddr)); nt->nt_keyixmap[keyix] = NULL; ieee80211_node_decref(ni); /* NB: don't need free */ } if (!ieee80211_node_dectestref(ni)) { /* * Other references are present, just remove the * node from the table so it cannot be found. When * the references are dropped storage will be * reclaimed. */ TAILQ_REMOVE(&nt->nt_node, ni, ni_list); LIST_REMOVE(ni, ni_hash); ni->ni_table = NULL; /* clear reference */ } else _ieee80211_free_node(ni); } static void ieee80211_free_allnodes_locked(struct ieee80211_node_table *nt) { struct ieee80211com *ic = nt->nt_ic; struct ieee80211_node *ni; IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, "%s: free all nodes in %s table\n", __func__, nt->nt_name); while ((ni = TAILQ_FIRST(&nt->nt_node)) != NULL) { if (ni->ni_associd != 0) { if (ic->ic_auth->ia_node_leave != NULL) ic->ic_auth->ia_node_leave(ic, ni); IEEE80211_AID_CLR(ni->ni_associd, ic->ic_aid_bitmap); } node_reclaim(nt, ni); } ieee80211_reset_erp(ic); } static void ieee80211_free_allnodes(struct ieee80211_node_table *nt) { IEEE80211_NODE_LOCK(nt); ieee80211_free_allnodes_locked(nt); IEEE80211_NODE_UNLOCK(nt); } /* * Timeout entries in the scan cache. */ static void ieee80211_timeout_scan_candidates(struct ieee80211_node_table *nt) { struct ieee80211com *ic = nt->nt_ic; struct ieee80211_node *ni, *tni; IEEE80211_NODE_LOCK(nt); ni = ic->ic_bss; /* XXX belongs elsewhere */ if (ni->ni_rxfrag[0] != NULL && ticks > ni->ni_rxfragstamp + hz) { m_freem(ni->ni_rxfrag[0]); ni->ni_rxfrag[0] = NULL; } TAILQ_FOREACH_SAFE(ni, &nt->nt_node, ni_list, tni) { if (ni->ni_inact && --ni->ni_inact == 0) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, "[%s] scan candidate purged from cache " "(refcnt %u)\n", ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)); node_reclaim(nt, ni); } } IEEE80211_NODE_UNLOCK(nt); nt->nt_inact_timer = IEEE80211_INACT_WAIT; } /* * Timeout inactive stations and do related housekeeping. * Note that we cannot hold the node lock while sending a * frame as this would lead to a LOR. Instead we use a * generation number to mark nodes that we've scanned and * drop the lock and restart a scan if we have to time out * a node. Since we are single-threaded by virtue of * controlling the inactivity timer we can be sure this will * process each node only once. */ static void ieee80211_timeout_stations(struct ieee80211_node_table *nt) { struct ieee80211com *ic = nt->nt_ic; struct ieee80211_node *ni; u_int gen; int isadhoc; isadhoc = (ic->ic_opmode == IEEE80211_M_IBSS || ic->ic_opmode == IEEE80211_M_AHDEMO); IEEE80211_SCAN_LOCK(nt); gen = nt->nt_scangen++; IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, "%s: %s scangen %u\n", __func__, nt->nt_name, gen); restart: IEEE80211_NODE_LOCK(nt); TAILQ_FOREACH(ni, &nt->nt_node, ni_list) { if (ni->ni_scangen == gen) /* previously handled */ continue; ni->ni_scangen = gen; /* * Ignore entries for which have yet to receive an * authentication frame. These are transient and * will be reclaimed when the last reference to them * goes away (when frame xmits complete). */ if (ic->ic_opmode == IEEE80211_M_HOSTAP && (ni->ni_flags & IEEE80211_NODE_AREF) == 0) continue; /* * Free fragment if not needed anymore * (last fragment older than 1s). * XXX doesn't belong here */ if (ni->ni_rxfrag[0] != NULL && ticks > ni->ni_rxfragstamp + hz) { m_freem(ni->ni_rxfrag[0]); ni->ni_rxfrag[0] = NULL; } /* * Special case ourself; we may be idle for extended periods * of time and regardless reclaiming our state is wrong. */ if (ni == ic->ic_bss) continue; ni->ni_inact--; if (ni->ni_associd != 0 || isadhoc) { /* * Age frames on the power save queue. The * aging interval is 4 times the listen * interval specified by the station. This * number is factored into the age calculations * when the frame is placed on the queue. We * store ages as time differences we can check * and/or adjust only the head of the list. */ if (IEEE80211_NODE_SAVEQ_QLEN(ni) != 0) { struct mbuf *m; int discard = 0; IEEE80211_NODE_SAVEQ_LOCK(ni); while (IF_POLL(&ni->ni_savedq, m) != NULL && M_AGE_GET(m) < IEEE80211_INACT_WAIT) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_POWER, "[%s] discard frame, age %u\n", ether_sprintf(ni->ni_macaddr), M_AGE_GET(m));/*XXX*/ _IEEE80211_NODE_SAVEQ_DEQUEUE_HEAD(ni, m); m_freem(m); discard++; } if (m != NULL) M_AGE_SUB(m, IEEE80211_INACT_WAIT); IEEE80211_NODE_SAVEQ_UNLOCK(ni); if (discard != 0) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_POWER, "[%s] discard %u frames for age\n", ether_sprintf(ni->ni_macaddr), discard); IEEE80211_NODE_STAT_ADD(ni, ps_discard, discard); if (IEEE80211_NODE_SAVEQ_QLEN(ni) == 0) ic->ic_set_tim(ni, 0); } } /* * Probe the station before time it out. We * send a null data frame which may not be * universally supported by drivers (need it * for ps-poll support so it should be...). */ if (0 < ni->ni_inact && ni->ni_inact <= ic->ic_inact_probe) { IEEE80211_NOTE(ic, IEEE80211_MSG_INACT | IEEE80211_MSG_NODE, ni, "%s", "probe station due to inactivity"); /* * Grab a reference before unlocking the table * so the node cannot be reclaimed before we * send the frame. ieee80211_send_nulldata * understands we've done this and reclaims the * ref for us as needed. */ ieee80211_ref_node(ni); IEEE80211_NODE_UNLOCK(nt); ieee80211_send_nulldata(ni); /* XXX stat? */ goto restart; } } if (ni->ni_inact <= 0) { IEEE80211_NOTE(ic, IEEE80211_MSG_INACT | IEEE80211_MSG_NODE, ni, "station timed out due to inactivity " "(refcnt %u)", ieee80211_node_refcnt(ni)); /* * Send a deauthenticate frame and drop the station. * This is somewhat complicated due to reference counts * and locking. At this point a station will typically * have a reference count of 1. ieee80211_node_leave * will do a "free" of the node which will drop the * reference count. But in the meantime a reference * wil be held by the deauth frame. The actual reclaim * of the node will happen either after the tx is * completed or by ieee80211_node_leave. * * Separately we must drop the node lock before sending * in case the driver takes a lock, as this will result * in LOR between the node lock and the driver lock. */ IEEE80211_NODE_UNLOCK(nt); if (ni->ni_associd != 0) { IEEE80211_SEND_MGMT(ic, ni, IEEE80211_FC0_SUBTYPE_DEAUTH, IEEE80211_REASON_AUTH_EXPIRE); } ieee80211_node_leave(ic, ni); ic->ic_stats.is_node_timeout++; goto restart; } } IEEE80211_NODE_UNLOCK(nt); IEEE80211_SCAN_UNLOCK(nt); nt->nt_inact_timer = IEEE80211_INACT_WAIT; } void ieee80211_iterate_nodes(struct ieee80211_node_table *nt, ieee80211_iter_func *f, void *arg) { struct ieee80211_node *ni; u_int gen; IEEE80211_SCAN_LOCK(nt); gen = nt->nt_scangen++; restart: IEEE80211_NODE_LOCK(nt); TAILQ_FOREACH(ni, &nt->nt_node, ni_list) { if (ni->ni_scangen != gen) { ni->ni_scangen = gen; (void) ieee80211_ref_node(ni); IEEE80211_NODE_UNLOCK(nt); (*f)(arg, ni); ieee80211_free_node(ni); goto restart; } } IEEE80211_NODE_UNLOCK(nt); IEEE80211_SCAN_UNLOCK(nt); } void ieee80211_dump_node(struct ieee80211_node_table *nt, struct ieee80211_node *ni) { printf("0x%p: mac %s refcnt %d\n", ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)); printf("\tscangen %u authmode %u flags 0x%x\n", ni->ni_scangen, ni->ni_authmode, ni->ni_flags); printf("\tassocid 0x%x txpower %u vlan %u\n", ni->ni_associd, ni->ni_txpower, ni->ni_vlan); printf("\ttxseq %u rxseq %u fragno %u rxfragstamp %u\n", ni->ni_txseqs[0], ni->ni_rxseqs[0] >> IEEE80211_SEQ_SEQ_SHIFT, ni->ni_rxseqs[0] & IEEE80211_SEQ_FRAG_MASK, ni->ni_rxfragstamp); printf("\trstamp %u rssi %u intval %u capinfo 0x%x\n", ni->ni_rstamp, ni->ni_rssi, ni->ni_intval, ni->ni_capinfo); printf("\tbssid %s essid \"%.*s\" channel %u:0x%x\n", ether_sprintf(ni->ni_bssid), ni->ni_esslen, ni->ni_essid, ni->ni_chan->ic_freq, ni->ni_chan->ic_flags); printf("\tfails %u inact %u txrate %u\n", ni->ni_fails, ni->ni_inact, ni->ni_txrate); } void ieee80211_dump_nodes(struct ieee80211_node_table *nt) { ieee80211_iterate_nodes(nt, (ieee80211_iter_func *) ieee80211_dump_node, nt); } /* * Handle a station joining an 11g network. */ static void ieee80211_node_join_11g(struct ieee80211com *ic, struct ieee80211_node *ni) { /* * Station isn't capable of short slot time. Bump * the count of long slot time stations and disable * use of short slot time. Note that the actual switch * over to long slot time use may not occur until the * next beacon transmission (per sec. 7.3.1.4 of 11g). */ if ((ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME) == 0) { ic->ic_longslotsta++; IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC, "[%s] station needs long slot time, count %d\n", ether_sprintf(ni->ni_macaddr), ic->ic_longslotsta); /* XXX vap's w/ conflicting needs won't work */ ieee80211_set_shortslottime(ic, 0); } /* * If the new station is not an ERP station * then bump the counter and enable protection * if configured. */ if (!ieee80211_iserp_rateset(ic, &ni->ni_rates)) { ic->ic_nonerpsta++; IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC, "[%s] station is !ERP, %d non-ERP stations associated\n", ether_sprintf(ni->ni_macaddr), ic->ic_nonerpsta); /* * If protection is configured, enable it. */ if (ic->ic_protmode != IEEE80211_PROT_NONE) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC, "%s: enable use of protection\n", __func__); ic->ic_flags |= IEEE80211_F_USEPROT; } /* * If station does not support short preamble * then we must enable use of Barker preamble. */ if ((ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE) == 0) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC, "[%s] station needs long preamble\n", ether_sprintf(ni->ni_macaddr)); ic->ic_flags |= IEEE80211_F_USEBARKER; ic->ic_flags &= ~IEEE80211_F_SHPREAMBLE; } + if (ic->ic_nonerpsta == 1) + ic->ic_flags_ext |= IEEE80211_FEXT_ERPUPDATE; } else ni->ni_flags |= IEEE80211_NODE_ERP; } void ieee80211_node_join(struct ieee80211com *ic, struct ieee80211_node *ni, int resp) { int newassoc; if (ni->ni_associd == 0) { u_int16_t aid; /* * It would be good to search the bitmap * more efficiently, but this will do for now. */ for (aid = 1; aid < ic->ic_max_aid; aid++) { if (!IEEE80211_AID_ISSET(aid, ic->ic_aid_bitmap)) break; } if (aid >= ic->ic_max_aid) { IEEE80211_SEND_MGMT(ic, ni, resp, IEEE80211_REASON_ASSOC_TOOMANY); ieee80211_node_leave(ic, ni); return; } ni->ni_associd = aid | 0xc000; IEEE80211_AID_SET(ni->ni_associd, ic->ic_aid_bitmap); ic->ic_sta_assoc++; newassoc = 1; if (ic->ic_curmode == IEEE80211_MODE_11G) ieee80211_node_join_11g(ic, ni); } else newassoc = 0; IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC | IEEE80211_MSG_DEBUG, "[%s] station %sassociated at aid %d: %s preamble, %s slot time%s%s\n", ether_sprintf(ni->ni_macaddr), newassoc ? "" : "re", IEEE80211_NODE_AID(ni), ic->ic_flags & IEEE80211_F_SHPREAMBLE ? "short" : "long", ic->ic_flags & IEEE80211_F_SHSLOT ? "short" : "long", ic->ic_flags & IEEE80211_F_USEPROT ? ", protection" : "", ni->ni_flags & IEEE80211_NODE_QOS ? ", QoS" : "" ); /* give driver a chance to setup state like ni_txrate */ if (ic->ic_newassoc != NULL) ic->ic_newassoc(ni, newassoc); ni->ni_inact_reload = ic->ic_inact_auth; ni->ni_inact = ni->ni_inact_reload; IEEE80211_SEND_MGMT(ic, ni, resp, IEEE80211_STATUS_SUCCESS); /* tell the authenticator about new station */ if (ic->ic_auth->ia_node_join != NULL) ic->ic_auth->ia_node_join(ic, ni); ieee80211_notify_node_join(ic, ni, newassoc); } /* * Handle a station leaving an 11g network. */ static void ieee80211_node_leave_11g(struct ieee80211com *ic, struct ieee80211_node *ni) { KASSERT(ic->ic_curmode == IEEE80211_MODE_11G, ("not in 11g, bss %u:0x%x, curmode %u", ni->ni_chan->ic_freq, ni->ni_chan->ic_flags, ic->ic_curmode)); /* * If a long slot station do the slot time bookkeeping. */ if ((ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME) == 0) { KASSERT(ic->ic_longslotsta > 0, ("bogus long slot station count %d", ic->ic_longslotsta)); ic->ic_longslotsta--; IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC, "[%s] long slot time station leaves, count now %d\n", ether_sprintf(ni->ni_macaddr), ic->ic_longslotsta); if (ic->ic_longslotsta == 0) { /* * Re-enable use of short slot time if supported * and not operating in IBSS mode (per spec). */ if ((ic->ic_caps & IEEE80211_C_SHSLOT) && ic->ic_opmode != IEEE80211_M_IBSS) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC, "%s: re-enable use of short slot time\n", __func__); ieee80211_set_shortslottime(ic, 1); } } } /* * If a non-ERP station do the protection-related bookkeeping. */ if ((ni->ni_flags & IEEE80211_NODE_ERP) == 0) { KASSERT(ic->ic_nonerpsta > 0, ("bogus non-ERP station count %d", ic->ic_nonerpsta)); ic->ic_nonerpsta--; IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC, "[%s] non-ERP station leaves, count now %d\n", ether_sprintf(ni->ni_macaddr), ic->ic_nonerpsta); if (ic->ic_nonerpsta == 0) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC, "%s: disable use of protection\n", __func__); ic->ic_flags &= ~IEEE80211_F_USEPROT; /* XXX verify mode? */ if (ic->ic_caps & IEEE80211_C_SHPREAMBLE) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC, "%s: re-enable use of short preamble\n", __func__); ic->ic_flags |= IEEE80211_F_SHPREAMBLE; ic->ic_flags &= ~IEEE80211_F_USEBARKER; } + ic->ic_flags_ext |= IEEE80211_FEXT_ERPUPDATE; } } } /* * Handle bookkeeping for station deauthentication/disassociation * when operating as an ap. */ void ieee80211_node_leave(struct ieee80211com *ic, struct ieee80211_node *ni) { struct ieee80211_node_table *nt = ni->ni_table; IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC | IEEE80211_MSG_DEBUG, "[%s] station with aid %d leaves\n", ether_sprintf(ni->ni_macaddr), IEEE80211_NODE_AID(ni)); KASSERT(ic->ic_opmode == IEEE80211_M_HOSTAP || ic->ic_opmode == IEEE80211_M_IBSS || ic->ic_opmode == IEEE80211_M_AHDEMO, ("unexpected operating mode %u", ic->ic_opmode)); /* * If node wasn't previously associated all * we need to do is reclaim the reference. */ /* XXX ibss mode bypasses 11g and notification */ if (ni->ni_associd == 0) goto done; /* * Tell the authenticator the station is leaving. * Note that we must do this before yanking the * association id as the authenticator uses the * associd to locate it's state block. */ if (ic->ic_auth->ia_node_leave != NULL) ic->ic_auth->ia_node_leave(ic, ni); IEEE80211_AID_CLR(ni->ni_associd, ic->ic_aid_bitmap); ni->ni_associd = 0; ic->ic_sta_assoc--; if (ic->ic_curmode == IEEE80211_MODE_11G) ieee80211_node_leave_11g(ic, ni); /* * Cleanup station state. In particular clear various * state that might otherwise be reused if the node * is reused before the reference count goes to zero * (and memory is reclaimed). */ ieee80211_sta_leave(ic, ni); done: /* * Remove the node from any table it's recorded in and * drop the caller's reference. Removal from the table * is important to insure the node is not reprocessed * for inactivity. */ if (nt != NULL) { IEEE80211_NODE_LOCK(nt); node_reclaim(nt, ni); IEEE80211_NODE_UNLOCK(nt); } else ieee80211_free_node(ni); } u_int8_t ieee80211_getrssi(struct ieee80211com *ic) { #define NZ(x) ((x) == 0 ? 1 : (x)) struct ieee80211_node_table *nt = &ic->ic_sta; u_int32_t rssi_samples, rssi_total; struct ieee80211_node *ni; rssi_total = 0; rssi_samples = 0; switch (ic->ic_opmode) { case IEEE80211_M_IBSS: /* average of all ibss neighbors */ /* XXX locking */ TAILQ_FOREACH(ni, &nt->nt_node, ni_list) if (ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) { rssi_samples++; rssi_total += ic->ic_node_getrssi(ni); } break; case IEEE80211_M_AHDEMO: /* average of all neighbors */ /* XXX locking */ TAILQ_FOREACH(ni, &nt->nt_node, ni_list) { rssi_samples++; rssi_total += ic->ic_node_getrssi(ni); } break; case IEEE80211_M_HOSTAP: /* average of all associated stations */ /* XXX locking */ TAILQ_FOREACH(ni, &nt->nt_node, ni_list) if (IEEE80211_AID(ni->ni_associd) != 0) { rssi_samples++; rssi_total += ic->ic_node_getrssi(ni); } break; case IEEE80211_M_MONITOR: /* XXX */ case IEEE80211_M_STA: /* use stats from associated ap */ default: if (ic->ic_bss != NULL) rssi_total = ic->ic_node_getrssi(ic->ic_bss); rssi_samples = 1; break; } return rssi_total / NZ(rssi_samples); #undef NZ } /* * Indicate whether there are frames queued for a station in power-save mode. */ static void ieee80211_set_tim(struct ieee80211_node *ni, int set) { struct ieee80211com *ic = ni->ni_ic; u_int16_t aid; KASSERT(ic->ic_opmode == IEEE80211_M_HOSTAP || ic->ic_opmode == IEEE80211_M_IBSS, ("operating mode %u", ic->ic_opmode)); aid = IEEE80211_AID(ni->ni_associd); KASSERT(aid < ic->ic_max_aid, ("bogus aid %u, max %u", aid, ic->ic_max_aid)); IEEE80211_BEACON_LOCK(ic); if (set != (isset(ic->ic_tim_bitmap, aid) != 0)) { if (set) { setbit(ic->ic_tim_bitmap, aid); ic->ic_ps_pending++; } else { clrbit(ic->ic_tim_bitmap, aid); ic->ic_ps_pending--; } ic->ic_flags |= IEEE80211_F_TIMUPDATE; } IEEE80211_BEACON_UNLOCK(ic); } /* * Node table support. */ static void ieee80211_node_table_init(struct ieee80211com *ic, struct ieee80211_node_table *nt, const char *name, int inact, int keyixmax, void (*timeout)(struct ieee80211_node_table *)) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, "%s %s table, inact %u\n", __func__, name, inact); nt->nt_ic = ic; /* XXX need unit */ IEEE80211_NODE_LOCK_INIT(nt, ic->ic_ifp->if_xname); IEEE80211_SCAN_LOCK_INIT(nt, ic->ic_ifp->if_xname); TAILQ_INIT(&nt->nt_node); nt->nt_name = name; nt->nt_scangen = 1; nt->nt_inact_init = inact; nt->nt_timeout = timeout; nt->nt_keyixmax = keyixmax; if (nt->nt_keyixmax > 0) { MALLOC(nt->nt_keyixmap, struct ieee80211_node **, keyixmax * sizeof(struct ieee80211_node *), M_80211_NODE, M_NOWAIT | M_ZERO); if (nt->nt_keyixmap == NULL) if_printf(ic->ic_ifp, "Cannot allocate key index map with %u entries\n", keyixmax); } else nt->nt_keyixmap = NULL; } void ieee80211_node_table_reset(struct ieee80211_node_table *nt) { IEEE80211_DPRINTF(nt->nt_ic, IEEE80211_MSG_NODE, "%s %s table\n", __func__, nt->nt_name); IEEE80211_NODE_LOCK(nt); nt->nt_inact_timer = 0; ieee80211_free_allnodes_locked(nt); IEEE80211_NODE_UNLOCK(nt); } static void ieee80211_node_table_cleanup(struct ieee80211_node_table *nt) { IEEE80211_DPRINTF(nt->nt_ic, IEEE80211_MSG_NODE, "%s %s table\n", __func__, nt->nt_name); IEEE80211_NODE_LOCK(nt); ieee80211_free_allnodes_locked(nt); if (nt->nt_keyixmap != NULL) { /* XXX verify all entries are NULL */ int i; for (i = 0; i < nt->nt_keyixmax; i++) if (nt->nt_keyixmap[i] != NULL) printf("%s: %s[%u] still active\n", __func__, nt->nt_name, i); FREE(nt->nt_keyixmap, M_80211_NODE); nt->nt_keyixmap = NULL; } IEEE80211_SCAN_LOCK_DESTROY(nt); IEEE80211_NODE_LOCK_DESTROY(nt); } Index: head/sys/net80211/ieee80211_output.c =================================================================== --- head/sys/net80211/ieee80211_output.c (revision 153972) +++ head/sys/net80211/ieee80211_output.c (revision 153973) @@ -1,1699 +1,1711 @@ /*- * Copyright (c) 2001 Atsushi Onoe * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_inet.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef INET #include #include #include #include #endif #ifdef IEEE80211_DEBUG /* * Decide if an outbound management frame should be * printed when debugging is enabled. This filters some * of the less interesting frames that come frequently * (e.g. beacons). */ static __inline int doprint(struct ieee80211com *ic, int subtype) { switch (subtype) { case IEEE80211_FC0_SUBTYPE_PROBE_RESP: return (ic->ic_opmode == IEEE80211_M_IBSS); } return 1; } #endif /* * Set the direction field and address fields of an outgoing * non-QoS frame. Note this should be called early on in * constructing a frame as it sets i_fc[1]; other bits can * then be or'd in. */ static void ieee80211_send_setup(struct ieee80211com *ic, struct ieee80211_node *ni, struct ieee80211_frame *wh, int type, const u_int8_t sa[IEEE80211_ADDR_LEN], const u_int8_t da[IEEE80211_ADDR_LEN], const u_int8_t bssid[IEEE80211_ADDR_LEN]) { #define WH4(wh) ((struct ieee80211_frame_addr4 *)wh) wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | type; if ((type & IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_DATA) { switch (ic->ic_opmode) { case IEEE80211_M_STA: wh->i_fc[1] = IEEE80211_FC1_DIR_TODS; IEEE80211_ADDR_COPY(wh->i_addr1, bssid); IEEE80211_ADDR_COPY(wh->i_addr2, sa); IEEE80211_ADDR_COPY(wh->i_addr3, da); break; case IEEE80211_M_IBSS: case IEEE80211_M_AHDEMO: wh->i_fc[1] = IEEE80211_FC1_DIR_NODS; IEEE80211_ADDR_COPY(wh->i_addr1, da); IEEE80211_ADDR_COPY(wh->i_addr2, sa); IEEE80211_ADDR_COPY(wh->i_addr3, bssid); break; case IEEE80211_M_HOSTAP: wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS; IEEE80211_ADDR_COPY(wh->i_addr1, da); IEEE80211_ADDR_COPY(wh->i_addr2, bssid); IEEE80211_ADDR_COPY(wh->i_addr3, sa); break; case IEEE80211_M_MONITOR: /* NB: to quiet compiler */ break; } } else { wh->i_fc[1] = IEEE80211_FC1_DIR_NODS; IEEE80211_ADDR_COPY(wh->i_addr1, da); IEEE80211_ADDR_COPY(wh->i_addr2, sa); IEEE80211_ADDR_COPY(wh->i_addr3, bssid); } *(u_int16_t *)&wh->i_dur[0] = 0; /* NB: use non-QoS tid */ *(u_int16_t *)&wh->i_seq[0] = htole16(ni->ni_txseqs[0] << IEEE80211_SEQ_SEQ_SHIFT); ni->ni_txseqs[0]++; #undef WH4 } /* * Send a management frame to the specified node. The node pointer * must have a reference as the pointer will be passed to the driver * and potentially held for a long time. If the frame is successfully * dispatched to the driver, then it is responsible for freeing the * reference (and potentially free'ing up any associated storage). */ static int ieee80211_mgmt_output(struct ieee80211com *ic, struct ieee80211_node *ni, struct mbuf *m, int type) { struct ifnet *ifp = ic->ic_ifp; struct ieee80211_frame *wh; KASSERT(ni != NULL, ("null node")); /* * Yech, hack alert! We want to pass the node down to the * driver's start routine. If we don't do so then the start * routine must immediately look it up again and that can * cause a lock order reversal if, for example, this frame * is being sent because the station is being timedout and * the frame being sent is a DEAUTH message. We could stick * this in an m_tag and tack that on to the mbuf. However * that's rather expensive to do for every frame so instead * we stuff it in the rcvif field since outbound frames do * not (presently) use this. */ M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT); if (m == NULL) return ENOMEM; KASSERT(m->m_pkthdr.rcvif == NULL, ("rcvif not null")); m->m_pkthdr.rcvif = (void *)ni; wh = mtod(m, struct ieee80211_frame *); ieee80211_send_setup(ic, ni, wh, IEEE80211_FC0_TYPE_MGT | type, ic->ic_myaddr, ni->ni_macaddr, ni->ni_bssid); if ((m->m_flags & M_LINK0) != 0 && ni->ni_challenge != NULL) { m->m_flags &= ~M_LINK0; IEEE80211_DPRINTF(ic, IEEE80211_MSG_AUTH, "[%s] encrypting frame (%s)\n", ether_sprintf(wh->i_addr1), __func__); wh->i_fc[1] |= IEEE80211_FC1_WEP; } #ifdef IEEE80211_DEBUG /* avoid printing too many frames */ if ((ieee80211_msg_debug(ic) && doprint(ic, type)) || ieee80211_msg_dumppkts(ic)) { printf("[%s] send %s on channel %u\n", ether_sprintf(wh->i_addr1), ieee80211_mgt_subtype_name[ (type & IEEE80211_FC0_SUBTYPE_MASK) >> IEEE80211_FC0_SUBTYPE_SHIFT], ieee80211_chan2ieee(ic, ic->ic_curchan)); } #endif IEEE80211_NODE_STAT(ni, tx_mgmt); IF_ENQUEUE(&ic->ic_mgtq, m); ifp->if_timer = 1; if_start(ifp); return 0; } /* * Send a null data frame to the specified node. * * NB: the caller is assumed to have setup a node reference * for use; this is necessary to deal with a race condition * when probing for inactive stations. */ int ieee80211_send_nulldata(struct ieee80211_node *ni) { struct ieee80211com *ic = ni->ni_ic; struct ifnet *ifp = ic->ic_ifp; struct mbuf *m; struct ieee80211_frame *wh; MGETHDR(m, M_NOWAIT, MT_DATA); if (m == NULL) { /* XXX debug msg */ ic->ic_stats.is_tx_nobuf++; ieee80211_unref_node(&ni); return ENOMEM; } m->m_pkthdr.rcvif = (void *) ni; wh = mtod(m, struct ieee80211_frame *); ieee80211_send_setup(ic, ni, wh, IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_NODATA, ic->ic_myaddr, ni->ni_macaddr, ni->ni_bssid); /* NB: power management bit is never sent by an AP */ if ((ni->ni_flags & IEEE80211_NODE_PWR_MGT) && ic->ic_opmode != IEEE80211_M_HOSTAP) wh->i_fc[1] |= IEEE80211_FC1_PWR_MGT; m->m_len = m->m_pkthdr.len = sizeof(struct ieee80211_frame); IEEE80211_NODE_STAT(ni, tx_data); IEEE80211_DPRINTF(ic, IEEE80211_MSG_DEBUG | IEEE80211_MSG_DUMPPKTS, "[%s] send null data frame on channel %u, pwr mgt %s\n", ether_sprintf(ni->ni_macaddr), ieee80211_chan2ieee(ic, ic->ic_curchan), wh->i_fc[1] & IEEE80211_FC1_PWR_MGT ? "ena" : "dis"); IF_ENQUEUE(&ic->ic_mgtq, m); /* cheat */ if_start(ifp); return 0; } /* * Assign priority to a frame based on any vlan tag assigned * to the station and/or any Diffserv setting in an IP header. * Finally, if an ACM policy is setup (in station mode) it's * applied. */ int ieee80211_classify(struct ieee80211com *ic, struct mbuf *m, struct ieee80211_node *ni) { int v_wme_ac, d_wme_ac, ac; #ifdef INET struct ether_header *eh; #endif if ((ni->ni_flags & IEEE80211_NODE_QOS) == 0) { ac = WME_AC_BE; goto done; } /* * If node has a vlan tag then all traffic * to it must have a matching tag. */ v_wme_ac = 0; if (ni->ni_vlan != 0) { struct m_tag *mtag = VLAN_OUTPUT_TAG(ic->ic_ifp, m); if (mtag == NULL) { IEEE80211_NODE_STAT(ni, tx_novlantag); return 1; } if (EVL_VLANOFTAG(VLAN_TAG_VALUE(mtag)) != EVL_VLANOFTAG(ni->ni_vlan)) { IEEE80211_NODE_STAT(ni, tx_vlanmismatch); return 1; } /* map vlan priority to AC */ switch (EVL_PRIOFTAG(ni->ni_vlan)) { case 1: case 2: v_wme_ac = WME_AC_BK; break; case 0: case 3: v_wme_ac = WME_AC_BE; break; case 4: case 5: v_wme_ac = WME_AC_VI; break; case 6: case 7: v_wme_ac = WME_AC_VO; break; } } #ifdef INET eh = mtod(m, struct ether_header *); if (eh->ether_type == htons(ETHERTYPE_IP)) { const struct ip *ip = (struct ip *) (mtod(m, u_int8_t *) + sizeof (*eh)); /* * IP frame, map the TOS field. */ switch (ip->ip_tos) { case 0x08: case 0x20: d_wme_ac = WME_AC_BK; /* background */ break; case 0x28: case 0xa0: d_wme_ac = WME_AC_VI; /* video */ break; case 0x30: /* voice */ case 0xe0: case 0x88: /* XXX UPSD */ case 0xb8: d_wme_ac = WME_AC_VO; break; default: d_wme_ac = WME_AC_BE; break; } } else { #endif /* INET */ d_wme_ac = WME_AC_BE; #ifdef INET } #endif /* * Use highest priority AC. */ if (v_wme_ac > d_wme_ac) ac = v_wme_ac; else ac = d_wme_ac; /* * Apply ACM policy. */ if (ic->ic_opmode == IEEE80211_M_STA) { static const int acmap[4] = { WME_AC_BK, /* WME_AC_BE */ WME_AC_BK, /* WME_AC_BK */ WME_AC_BE, /* WME_AC_VI */ WME_AC_VI, /* WME_AC_VO */ }; while (ac != WME_AC_BK && ic->ic_wme.wme_wmeBssChanParams.cap_wmeParams[ac].wmep_acm) ac = acmap[ac]; } done: M_WME_SETAC(m, ac); return 0; } /* * Insure there is sufficient contiguous space to encapsulate the * 802.11 data frame. If room isn't already there, arrange for it. * Drivers and cipher modules assume we have done the necessary work * and fail rudely if they don't find the space they need. */ static struct mbuf * ieee80211_mbuf_adjust(struct ieee80211com *ic, int hdrsize, struct ieee80211_key *key, struct mbuf *m) { #define TO_BE_RECLAIMED (sizeof(struct ether_header) - sizeof(struct llc)) int needed_space = hdrsize; if (key != NULL) { /* XXX belongs in crypto code? */ needed_space += key->wk_cipher->ic_header; /* XXX frags */ } /* * We know we are called just before stripping an Ethernet * header and prepending an LLC header. This means we know * there will be * sizeof(struct ether_header) - sizeof(struct llc) * bytes recovered to which we need additional space for the * 802.11 header and any crypto header. */ /* XXX check trailing space and copy instead? */ if (M_LEADINGSPACE(m) < needed_space - TO_BE_RECLAIMED) { struct mbuf *n = m_gethdr(M_NOWAIT, m->m_type); if (n == NULL) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_OUTPUT, "%s: cannot expand storage\n", __func__); ic->ic_stats.is_tx_nobuf++; m_freem(m); return NULL; } KASSERT(needed_space <= MHLEN, ("not enough room, need %u got %zu\n", needed_space, MHLEN)); /* * Setup new mbuf to have leading space to prepend the * 802.11 header and any crypto header bits that are * required (the latter are added when the driver calls * back to ieee80211_crypto_encap to do crypto encapsulation). */ /* NB: must be first 'cuz it clobbers m_data */ m_move_pkthdr(n, m); n->m_len = 0; /* NB: m_gethdr does not set */ n->m_data += needed_space; /* * Pull up Ethernet header to create the expected layout. * We could use m_pullup but that's overkill (i.e. we don't * need the actual data) and it cannot fail so do it inline * for speed. */ /* NB: struct ether_header is known to be contiguous */ n->m_len += sizeof(struct ether_header); m->m_len -= sizeof(struct ether_header); m->m_data += sizeof(struct ether_header); /* * Replace the head of the chain. */ n->m_next = m; m = n; } return m; #undef TO_BE_RECLAIMED } #define KEY_UNDEFINED(k) ((k).wk_cipher == &ieee80211_cipher_none) /* * Return the transmit key to use in sending a unicast frame. * If a unicast key is set we use that. When no unicast key is set * we fall back to the default transmit key. */ static __inline struct ieee80211_key * ieee80211_crypto_getucastkey(struct ieee80211com *ic, struct ieee80211_node *ni) { if (KEY_UNDEFINED(ni->ni_ucastkey)) { if (ic->ic_def_txkey == IEEE80211_KEYIX_NONE || KEY_UNDEFINED(ic->ic_nw_keys[ic->ic_def_txkey])) return NULL; return &ic->ic_nw_keys[ic->ic_def_txkey]; } else { return &ni->ni_ucastkey; } } /* * Return the transmit key to use in sending a multicast frame. * Multicast traffic always uses the group key which is installed as * the default tx key. */ static __inline struct ieee80211_key * ieee80211_crypto_getmcastkey(struct ieee80211com *ic, struct ieee80211_node *ni) { if (ic->ic_def_txkey == IEEE80211_KEYIX_NONE || KEY_UNDEFINED(ic->ic_nw_keys[ic->ic_def_txkey])) return NULL; return &ic->ic_nw_keys[ic->ic_def_txkey]; } /* * Encapsulate an outbound data frame. The mbuf chain is updated. * If an error is encountered NULL is returned. The caller is required * to provide a node reference and pullup the ethernet header in the * first mbuf. */ struct mbuf * ieee80211_encap(struct ieee80211com *ic, struct mbuf *m, struct ieee80211_node *ni) { struct ether_header eh; struct ieee80211_frame *wh; struct ieee80211_key *key; struct llc *llc; int hdrsize, datalen, addqos; KASSERT(m->m_len >= sizeof(eh), ("no ethernet header!")); memcpy(&eh, mtod(m, caddr_t), sizeof(struct ether_header)); /* * Insure space for additional headers. First identify * transmit key to use in calculating any buffer adjustments * required. This is also used below to do privacy * encapsulation work. Then calculate the 802.11 header * size and any padding required by the driver. * * Note key may be NULL if we fall back to the default * transmit key and that is not set. In that case the * buffer may not be expanded as needed by the cipher * routines, but they will/should discard it. */ if (ic->ic_flags & IEEE80211_F_PRIVACY) { if (ic->ic_opmode == IEEE80211_M_STA || !IEEE80211_IS_MULTICAST(eh.ether_dhost)) key = ieee80211_crypto_getucastkey(ic, ni); else key = ieee80211_crypto_getmcastkey(ic, ni); if (key == NULL && eh.ether_type != htons(ETHERTYPE_PAE)) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO, "[%s] no default transmit key (%s) deftxkey %u\n", ether_sprintf(eh.ether_dhost), __func__, ic->ic_def_txkey); ic->ic_stats.is_tx_nodefkey++; } } else key = NULL; /* XXX 4-address format */ /* * XXX Some ap's don't handle QoS-encapsulated EAPOL * frames so suppress use. This may be an issue if other * ap's require all data frames to be QoS-encapsulated * once negotiated in which case we'll need to make this * configurable. */ addqos = (ni->ni_flags & IEEE80211_NODE_QOS) && eh.ether_type != htons(ETHERTYPE_PAE); if (addqos) hdrsize = sizeof(struct ieee80211_qosframe); else hdrsize = sizeof(struct ieee80211_frame); if (ic->ic_flags & IEEE80211_F_DATAPAD) hdrsize = roundup(hdrsize, sizeof(u_int32_t)); m = ieee80211_mbuf_adjust(ic, hdrsize, key, m); if (m == NULL) { /* NB: ieee80211_mbuf_adjust handles msgs+statistics */ goto bad; } /* NB: this could be optimized because of ieee80211_mbuf_adjust */ m_adj(m, sizeof(struct ether_header) - sizeof(struct llc)); llc = mtod(m, struct llc *); llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP; llc->llc_control = LLC_UI; llc->llc_snap.org_code[0] = 0; llc->llc_snap.org_code[1] = 0; llc->llc_snap.org_code[2] = 0; llc->llc_snap.ether_type = eh.ether_type; datalen = m->m_pkthdr.len; /* NB: w/o 802.11 header */ M_PREPEND(m, hdrsize, M_DONTWAIT); if (m == NULL) { ic->ic_stats.is_tx_nobuf++; goto bad; } wh = mtod(m, struct ieee80211_frame *); wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_DATA; *(u_int16_t *)wh->i_dur = 0; switch (ic->ic_opmode) { case IEEE80211_M_STA: wh->i_fc[1] = IEEE80211_FC1_DIR_TODS; IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_bssid); IEEE80211_ADDR_COPY(wh->i_addr2, eh.ether_shost); IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost); break; case IEEE80211_M_IBSS: case IEEE80211_M_AHDEMO: wh->i_fc[1] = IEEE80211_FC1_DIR_NODS; IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost); IEEE80211_ADDR_COPY(wh->i_addr2, eh.ether_shost); /* * NB: always use the bssid from ic_bss as the * neighbor's may be stale after an ibss merge */ IEEE80211_ADDR_COPY(wh->i_addr3, ic->ic_bss->ni_bssid); break; case IEEE80211_M_HOSTAP: wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS; IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost); IEEE80211_ADDR_COPY(wh->i_addr2, ni->ni_bssid); IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_shost); break; case IEEE80211_M_MONITOR: goto bad; } if (m->m_flags & M_MORE_DATA) wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA; if (addqos) { struct ieee80211_qosframe *qwh = (struct ieee80211_qosframe *) wh; int ac, tid; ac = M_WME_GETAC(m); /* map from access class/queue to 11e header priorty value */ tid = WME_AC_TO_TID(ac); qwh->i_qos[0] = tid & IEEE80211_QOS_TID; if (ic->ic_wme.wme_wmeChanParams.cap_wmeParams[ac].wmep_noackPolicy) qwh->i_qos[0] |= 1 << IEEE80211_QOS_ACKPOLICY_S; qwh->i_qos[1] = 0; qwh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_QOS; *(u_int16_t *)wh->i_seq = htole16(ni->ni_txseqs[tid] << IEEE80211_SEQ_SEQ_SHIFT); ni->ni_txseqs[tid]++; } else { *(u_int16_t *)wh->i_seq = htole16(ni->ni_txseqs[0] << IEEE80211_SEQ_SEQ_SHIFT); ni->ni_txseqs[0]++; } if (key != NULL) { /* * IEEE 802.1X: send EAPOL frames always in the clear. * WPA/WPA2: encrypt EAPOL keys when pairwise keys are set. */ if (eh.ether_type != htons(ETHERTYPE_PAE) || ((ic->ic_flags & IEEE80211_F_WPA) && (ic->ic_opmode == IEEE80211_M_STA ? !KEY_UNDEFINED(*key) : !KEY_UNDEFINED(ni->ni_ucastkey)))) { wh->i_fc[1] |= IEEE80211_FC1_WEP; /* XXX do fragmentation */ if (!ieee80211_crypto_enmic(ic, key, m, 0)) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_OUTPUT, "[%s] enmic failed, discard frame\n", ether_sprintf(eh.ether_dhost)); ic->ic_stats.is_crypto_enmicfail++; goto bad; } } } IEEE80211_NODE_STAT(ni, tx_data); IEEE80211_NODE_STAT_ADD(ni, tx_bytes, datalen); return m; bad: if (m != NULL) m_freem(m); return NULL; } /* * Add a supported rates element id to a frame. */ static u_int8_t * ieee80211_add_rates(u_int8_t *frm, const struct ieee80211_rateset *rs) { int nrates; *frm++ = IEEE80211_ELEMID_RATES; nrates = rs->rs_nrates; if (nrates > IEEE80211_RATE_SIZE) nrates = IEEE80211_RATE_SIZE; *frm++ = nrates; memcpy(frm, rs->rs_rates, nrates); return frm + nrates; } /* * Add an extended supported rates element id to a frame. */ static u_int8_t * ieee80211_add_xrates(u_int8_t *frm, const struct ieee80211_rateset *rs) { /* * Add an extended supported rates element if operating in 11g mode. */ if (rs->rs_nrates > IEEE80211_RATE_SIZE) { int nrates = rs->rs_nrates - IEEE80211_RATE_SIZE; *frm++ = IEEE80211_ELEMID_XRATES; *frm++ = nrates; memcpy(frm, rs->rs_rates + IEEE80211_RATE_SIZE, nrates); frm += nrates; } return frm; } /* * Add an ssid elemet to a frame. */ static u_int8_t * ieee80211_add_ssid(u_int8_t *frm, const u_int8_t *ssid, u_int len) { *frm++ = IEEE80211_ELEMID_SSID; *frm++ = len; memcpy(frm, ssid, len); return frm + len; } /* * Add an erp element to a frame. */ static u_int8_t * ieee80211_add_erp(u_int8_t *frm, struct ieee80211com *ic) { u_int8_t erp; *frm++ = IEEE80211_ELEMID_ERP; *frm++ = 1; erp = 0; if (ic->ic_nonerpsta != 0) erp |= IEEE80211_ERP_NON_ERP_PRESENT; if (ic->ic_flags & IEEE80211_F_USEPROT) erp |= IEEE80211_ERP_USE_PROTECTION; if (ic->ic_flags & IEEE80211_F_USEBARKER) erp |= IEEE80211_ERP_LONG_PREAMBLE; *frm++ = erp; return frm; } static u_int8_t * ieee80211_setup_wpa_ie(struct ieee80211com *ic, u_int8_t *ie) { #define WPA_OUI_BYTES 0x00, 0x50, 0xf2 #define ADDSHORT(frm, v) do { \ frm[0] = (v) & 0xff; \ frm[1] = (v) >> 8; \ frm += 2; \ } while (0) #define ADDSELECTOR(frm, sel) do { \ memcpy(frm, sel, 4); \ frm += 4; \ } while (0) static const u_int8_t oui[4] = { WPA_OUI_BYTES, WPA_OUI_TYPE }; static const u_int8_t cipher_suite[][4] = { { WPA_OUI_BYTES, WPA_CSE_WEP40 }, /* NB: 40-bit */ { WPA_OUI_BYTES, WPA_CSE_TKIP }, { 0x00, 0x00, 0x00, 0x00 }, /* XXX WRAP */ { WPA_OUI_BYTES, WPA_CSE_CCMP }, { 0x00, 0x00, 0x00, 0x00 }, /* XXX CKIP */ { WPA_OUI_BYTES, WPA_CSE_NULL }, }; static const u_int8_t wep104_suite[4] = { WPA_OUI_BYTES, WPA_CSE_WEP104 }; static const u_int8_t key_mgt_unspec[4] = { WPA_OUI_BYTES, WPA_ASE_8021X_UNSPEC }; static const u_int8_t key_mgt_psk[4] = { WPA_OUI_BYTES, WPA_ASE_8021X_PSK }; const struct ieee80211_rsnparms *rsn = &ic->ic_bss->ni_rsn; u_int8_t *frm = ie; u_int8_t *selcnt; *frm++ = IEEE80211_ELEMID_VENDOR; *frm++ = 0; /* length filled in below */ memcpy(frm, oui, sizeof(oui)); /* WPA OUI */ frm += sizeof(oui); ADDSHORT(frm, WPA_VERSION); /* XXX filter out CKIP */ /* multicast cipher */ if (rsn->rsn_mcastcipher == IEEE80211_CIPHER_WEP && rsn->rsn_mcastkeylen >= 13) ADDSELECTOR(frm, wep104_suite); else ADDSELECTOR(frm, cipher_suite[rsn->rsn_mcastcipher]); /* unicast cipher list */ selcnt = frm; ADDSHORT(frm, 0); /* selector count */ if (rsn->rsn_ucastcipherset & (1<rsn_ucastcipherset & (1<rsn_keymgmtset & WPA_ASE_8021X_UNSPEC) { selcnt[0]++; ADDSELECTOR(frm, key_mgt_unspec); } if (rsn->rsn_keymgmtset & WPA_ASE_8021X_PSK) { selcnt[0]++; ADDSELECTOR(frm, key_mgt_psk); } /* optional capabilities */ if (rsn->rsn_caps != 0 && rsn->rsn_caps != RSN_CAP_PREAUTH) ADDSHORT(frm, rsn->rsn_caps); /* calculate element length */ ie[1] = frm - ie - 2; KASSERT(ie[1]+2 <= sizeof(struct ieee80211_ie_wpa), ("WPA IE too big, %u > %zu", ie[1]+2, sizeof(struct ieee80211_ie_wpa))); return frm; #undef ADDSHORT #undef ADDSELECTOR #undef WPA_OUI_BYTES } static u_int8_t * ieee80211_setup_rsn_ie(struct ieee80211com *ic, u_int8_t *ie) { #define RSN_OUI_BYTES 0x00, 0x0f, 0xac #define ADDSHORT(frm, v) do { \ frm[0] = (v) & 0xff; \ frm[1] = (v) >> 8; \ frm += 2; \ } while (0) #define ADDSELECTOR(frm, sel) do { \ memcpy(frm, sel, 4); \ frm += 4; \ } while (0) static const u_int8_t cipher_suite[][4] = { { RSN_OUI_BYTES, RSN_CSE_WEP40 }, /* NB: 40-bit */ { RSN_OUI_BYTES, RSN_CSE_TKIP }, { RSN_OUI_BYTES, RSN_CSE_WRAP }, { RSN_OUI_BYTES, RSN_CSE_CCMP }, { 0x00, 0x00, 0x00, 0x00 }, /* XXX CKIP */ { RSN_OUI_BYTES, RSN_CSE_NULL }, }; static const u_int8_t wep104_suite[4] = { RSN_OUI_BYTES, RSN_CSE_WEP104 }; static const u_int8_t key_mgt_unspec[4] = { RSN_OUI_BYTES, RSN_ASE_8021X_UNSPEC }; static const u_int8_t key_mgt_psk[4] = { RSN_OUI_BYTES, RSN_ASE_8021X_PSK }; const struct ieee80211_rsnparms *rsn = &ic->ic_bss->ni_rsn; u_int8_t *frm = ie; u_int8_t *selcnt; *frm++ = IEEE80211_ELEMID_RSN; *frm++ = 0; /* length filled in below */ ADDSHORT(frm, RSN_VERSION); /* XXX filter out CKIP */ /* multicast cipher */ if (rsn->rsn_mcastcipher == IEEE80211_CIPHER_WEP && rsn->rsn_mcastkeylen >= 13) ADDSELECTOR(frm, wep104_suite); else ADDSELECTOR(frm, cipher_suite[rsn->rsn_mcastcipher]); /* unicast cipher list */ selcnt = frm; ADDSHORT(frm, 0); /* selector count */ if (rsn->rsn_ucastcipherset & (1<rsn_ucastcipherset & (1<rsn_keymgmtset & WPA_ASE_8021X_UNSPEC) { selcnt[0]++; ADDSELECTOR(frm, key_mgt_unspec); } if (rsn->rsn_keymgmtset & WPA_ASE_8021X_PSK) { selcnt[0]++; ADDSELECTOR(frm, key_mgt_psk); } /* optional capabilities */ ADDSHORT(frm, rsn->rsn_caps); /* XXX PMKID */ /* calculate element length */ ie[1] = frm - ie - 2; KASSERT(ie[1]+2 <= sizeof(struct ieee80211_ie_wpa), ("RSN IE too big, %u > %zu", ie[1]+2, sizeof(struct ieee80211_ie_wpa))); return frm; #undef ADDSELECTOR #undef ADDSHORT #undef RSN_OUI_BYTES } /* * Add a WPA/RSN element to a frame. */ static u_int8_t * ieee80211_add_wpa(u_int8_t *frm, struct ieee80211com *ic) { KASSERT(ic->ic_flags & IEEE80211_F_WPA, ("no WPA/RSN!")); if (ic->ic_flags & IEEE80211_F_WPA2) frm = ieee80211_setup_rsn_ie(ic, frm); if (ic->ic_flags & IEEE80211_F_WPA1) frm = ieee80211_setup_wpa_ie(ic, frm); return frm; } #define WME_OUI_BYTES 0x00, 0x50, 0xf2 /* * Add a WME information element to a frame. */ static u_int8_t * ieee80211_add_wme_info(u_int8_t *frm, struct ieee80211_wme_state *wme) { static const struct ieee80211_wme_info info = { .wme_id = IEEE80211_ELEMID_VENDOR, .wme_len = sizeof(struct ieee80211_wme_info) - 2, .wme_oui = { WME_OUI_BYTES }, .wme_type = WME_OUI_TYPE, .wme_subtype = WME_INFO_OUI_SUBTYPE, .wme_version = WME_VERSION, .wme_info = 0, }; memcpy(frm, &info, sizeof(info)); return frm + sizeof(info); } /* * Add a WME parameters element to a frame. */ static u_int8_t * ieee80211_add_wme_param(u_int8_t *frm, struct ieee80211_wme_state *wme) { #define SM(_v, _f) (((_v) << _f##_S) & _f) #define ADDSHORT(frm, v) do { \ frm[0] = (v) & 0xff; \ frm[1] = (v) >> 8; \ frm += 2; \ } while (0) /* NB: this works 'cuz a param has an info at the front */ static const struct ieee80211_wme_info param = { .wme_id = IEEE80211_ELEMID_VENDOR, .wme_len = sizeof(struct ieee80211_wme_param) - 2, .wme_oui = { WME_OUI_BYTES }, .wme_type = WME_OUI_TYPE, .wme_subtype = WME_PARAM_OUI_SUBTYPE, .wme_version = WME_VERSION, }; int i; memcpy(frm, ¶m, sizeof(param)); frm += __offsetof(struct ieee80211_wme_info, wme_info); *frm++ = wme->wme_bssChanParams.cap_info; /* AC info */ *frm++ = 0; /* reserved field */ for (i = 0; i < WME_NUM_AC; i++) { const struct wmeParams *ac = &wme->wme_bssChanParams.cap_wmeParams[i]; *frm++ = SM(i, WME_PARAM_ACI) | SM(ac->wmep_acm, WME_PARAM_ACM) | SM(ac->wmep_aifsn, WME_PARAM_AIFSN) ; *frm++ = SM(ac->wmep_logcwmax, WME_PARAM_LOGCWMAX) | SM(ac->wmep_logcwmin, WME_PARAM_LOGCWMIN) ; ADDSHORT(frm, ac->wmep_txopLimit); } return frm; #undef SM #undef ADDSHORT } #undef WME_OUI_BYTES /* * Send a probe request frame with the specified ssid * and any optional information element data. */ int ieee80211_send_probereq(struct ieee80211_node *ni, const u_int8_t sa[IEEE80211_ADDR_LEN], const u_int8_t da[IEEE80211_ADDR_LEN], const u_int8_t bssid[IEEE80211_ADDR_LEN], const u_int8_t *ssid, size_t ssidlen, const void *optie, size_t optielen) { struct ieee80211com *ic = ni->ni_ic; enum ieee80211_phymode mode; struct ieee80211_frame *wh; struct mbuf *m; u_int8_t *frm; /* * Hold a reference on the node so it doesn't go away until after * the xmit is complete all the way in the driver. On error we * will remove our reference. */ IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n", __func__, __LINE__, ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)+1); ieee80211_ref_node(ni); /* * prreq frame format * [tlv] ssid * [tlv] supported rates * [tlv] extended supported rates * [tlv] user-specified ie's */ m = ieee80211_getmgtframe(&frm, 2 + IEEE80211_NWID_LEN + 2 + IEEE80211_RATE_SIZE + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE) + (optie != NULL ? optielen : 0) ); if (m == NULL) { ic->ic_stats.is_tx_nobuf++; ieee80211_free_node(ni); return ENOMEM; } frm = ieee80211_add_ssid(frm, ssid, ssidlen); mode = ieee80211_chan2mode(ic, ic->ic_curchan); frm = ieee80211_add_rates(frm, &ic->ic_sup_rates[mode]); frm = ieee80211_add_xrates(frm, &ic->ic_sup_rates[mode]); if (optie != NULL) { memcpy(frm, optie, optielen); frm += optielen; } m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *); M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT); if (m == NULL) return ENOMEM; KASSERT(m->m_pkthdr.rcvif == NULL, ("rcvif not null")); m->m_pkthdr.rcvif = (void *)ni; wh = mtod(m, struct ieee80211_frame *); ieee80211_send_setup(ic, ni, wh, IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_REQ, sa, da, bssid); /* XXX power management? */ IEEE80211_NODE_STAT(ni, tx_probereq); IEEE80211_NODE_STAT(ni, tx_mgmt); IEEE80211_DPRINTF(ic, IEEE80211_MSG_DEBUG | IEEE80211_MSG_DUMPPKTS, "[%s] send probe req on channel %u\n", ether_sprintf(wh->i_addr1), ieee80211_chan2ieee(ic, ic->ic_curchan)); IF_ENQUEUE(&ic->ic_mgtq, m); if_start(ic->ic_ifp); return 0; } /* * Send a management frame. The node is for the destination (or ic_bss * when in station mode). Nodes other than ic_bss have their reference * count bumped to reflect our use for an indeterminant time. */ int ieee80211_send_mgmt(struct ieee80211com *ic, struct ieee80211_node *ni, int type, int arg) { #define senderr(_x, _v) do { ic->ic_stats._v++; ret = _x; goto bad; } while (0) struct mbuf *m; u_int8_t *frm; u_int16_t capinfo; int has_challenge, is_shared_key, ret, timer, status; KASSERT(ni != NULL, ("null node")); /* * Hold a reference on the node so it doesn't go away until after * the xmit is complete all the way in the driver. On error we * will remove our reference. */ IEEE80211_DPRINTF(ic, IEEE80211_MSG_NODE, "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n", __func__, __LINE__, ni, ether_sprintf(ni->ni_macaddr), ieee80211_node_refcnt(ni)+1); ieee80211_ref_node(ni); timer = 0; switch (type) { case IEEE80211_FC0_SUBTYPE_PROBE_RESP: /* * probe response frame format * [8] time stamp * [2] beacon interval * [2] cabability information * [tlv] ssid * [tlv] supported rates * [tlv] parameter set (FH/DS) * [tlv] parameter set (IBSS) * [tlv] extended rate phy (ERP) * [tlv] extended supported rates * [tlv] WPA * [tlv] WME (optional) */ m = ieee80211_getmgtframe(&frm, 8 + sizeof(u_int16_t) + sizeof(u_int16_t) + 2 + IEEE80211_NWID_LEN + 2 + IEEE80211_RATE_SIZE + 7 /* max(7,3) */ + 6 + 3 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE) /* XXX !WPA1+WPA2 fits w/o a cluster */ + (ic->ic_flags & IEEE80211_F_WPA ? 2*sizeof(struct ieee80211_ie_wpa) : 0) + sizeof(struct ieee80211_wme_param) ); if (m == NULL) senderr(ENOMEM, is_tx_nobuf); memset(frm, 0, 8); /* timestamp should be filled later */ frm += 8; *(u_int16_t *)frm = htole16(ic->ic_bss->ni_intval); frm += 2; if (ic->ic_opmode == IEEE80211_M_IBSS) capinfo = IEEE80211_CAPINFO_IBSS; else capinfo = IEEE80211_CAPINFO_ESS; if (ic->ic_flags & IEEE80211_F_PRIVACY) capinfo |= IEEE80211_CAPINFO_PRIVACY; if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) && IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan)) capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE; if (ic->ic_flags & IEEE80211_F_SHSLOT) capinfo |= IEEE80211_CAPINFO_SHORT_SLOTTIME; *(u_int16_t *)frm = htole16(capinfo); frm += 2; frm = ieee80211_add_ssid(frm, ic->ic_bss->ni_essid, ic->ic_bss->ni_esslen); frm = ieee80211_add_rates(frm, &ni->ni_rates); if (ic->ic_phytype == IEEE80211_T_FH) { *frm++ = IEEE80211_ELEMID_FHPARMS; *frm++ = 5; *frm++ = ni->ni_fhdwell & 0x00ff; *frm++ = (ni->ni_fhdwell >> 8) & 0x00ff; *frm++ = IEEE80211_FH_CHANSET( ieee80211_chan2ieee(ic, ic->ic_curchan)); *frm++ = IEEE80211_FH_CHANPAT( ieee80211_chan2ieee(ic, ic->ic_curchan)); *frm++ = ni->ni_fhindex; } else { *frm++ = IEEE80211_ELEMID_DSPARMS; *frm++ = 1; *frm++ = ieee80211_chan2ieee(ic, ic->ic_curchan); } if (ic->ic_opmode == IEEE80211_M_IBSS) { *frm++ = IEEE80211_ELEMID_IBSSPARMS; *frm++ = 2; *frm++ = 0; *frm++ = 0; /* TODO: ATIM window */ } if (ic->ic_flags & IEEE80211_F_WPA) frm = ieee80211_add_wpa(frm, ic); if (ic->ic_curmode == IEEE80211_MODE_11G) frm = ieee80211_add_erp(frm, ic); frm = ieee80211_add_xrates(frm, &ni->ni_rates); if (ic->ic_flags & IEEE80211_F_WME) frm = ieee80211_add_wme_param(frm, &ic->ic_wme); m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *); break; case IEEE80211_FC0_SUBTYPE_AUTH: status = arg >> 16; arg &= 0xffff; has_challenge = ((arg == IEEE80211_AUTH_SHARED_CHALLENGE || arg == IEEE80211_AUTH_SHARED_RESPONSE) && ni->ni_challenge != NULL); /* * Deduce whether we're doing open authentication or * shared key authentication. We do the latter if * we're in the middle of a shared key authentication * handshake or if we're initiating an authentication * request and configured to use shared key. */ is_shared_key = has_challenge || arg >= IEEE80211_AUTH_SHARED_RESPONSE || (arg == IEEE80211_AUTH_SHARED_REQUEST && ic->ic_bss->ni_authmode == IEEE80211_AUTH_SHARED); m = ieee80211_getmgtframe(&frm, 3 * sizeof(u_int16_t) + (has_challenge && status == IEEE80211_STATUS_SUCCESS ? sizeof(u_int16_t)+IEEE80211_CHALLENGE_LEN : 0) ); if (m == NULL) senderr(ENOMEM, is_tx_nobuf); ((u_int16_t *)frm)[0] = (is_shared_key) ? htole16(IEEE80211_AUTH_ALG_SHARED) : htole16(IEEE80211_AUTH_ALG_OPEN); ((u_int16_t *)frm)[1] = htole16(arg); /* sequence number */ ((u_int16_t *)frm)[2] = htole16(status);/* status */ if (has_challenge && status == IEEE80211_STATUS_SUCCESS) { ((u_int16_t *)frm)[3] = htole16((IEEE80211_CHALLENGE_LEN << 8) | IEEE80211_ELEMID_CHALLENGE); memcpy(&((u_int16_t *)frm)[4], ni->ni_challenge, IEEE80211_CHALLENGE_LEN); m->m_pkthdr.len = m->m_len = 4 * sizeof(u_int16_t) + IEEE80211_CHALLENGE_LEN; if (arg == IEEE80211_AUTH_SHARED_RESPONSE) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_AUTH, "[%s] request encrypt frame (%s)\n", ether_sprintf(ni->ni_macaddr), __func__); m->m_flags |= M_LINK0; /* WEP-encrypt, please */ } } else m->m_pkthdr.len = m->m_len = 3 * sizeof(u_int16_t); /* XXX not right for shared key */ if (status == IEEE80211_STATUS_SUCCESS) IEEE80211_NODE_STAT(ni, tx_auth); else IEEE80211_NODE_STAT(ni, tx_auth_fail); if (ic->ic_opmode == IEEE80211_M_STA) timer = IEEE80211_TRANS_WAIT; break; case IEEE80211_FC0_SUBTYPE_DEAUTH: IEEE80211_DPRINTF(ic, IEEE80211_MSG_AUTH, "[%s] send station deauthenticate (reason %d)\n", ether_sprintf(ni->ni_macaddr), arg); m = ieee80211_getmgtframe(&frm, sizeof(u_int16_t)); if (m == NULL) senderr(ENOMEM, is_tx_nobuf); *(u_int16_t *)frm = htole16(arg); /* reason */ m->m_pkthdr.len = m->m_len = sizeof(u_int16_t); IEEE80211_NODE_STAT(ni, tx_deauth); IEEE80211_NODE_STAT_SET(ni, tx_deauth_code, arg); ieee80211_node_unauthorize(ni); /* port closed */ break; case IEEE80211_FC0_SUBTYPE_ASSOC_REQ: case IEEE80211_FC0_SUBTYPE_REASSOC_REQ: /* * asreq frame format * [2] capability information * [2] listen interval * [6*] current AP address (reassoc only) * [tlv] ssid * [tlv] supported rates * [tlv] extended supported rates * [tlv] WME * [tlv] user-specified ie's */ m = ieee80211_getmgtframe(&frm, sizeof(u_int16_t) + sizeof(u_int16_t) + IEEE80211_ADDR_LEN + 2 + IEEE80211_NWID_LEN + 2 + IEEE80211_RATE_SIZE + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE) + sizeof(struct ieee80211_wme_info) + (ic->ic_opt_ie != NULL ? ic->ic_opt_ie_len : 0) ); if (m == NULL) senderr(ENOMEM, is_tx_nobuf); capinfo = 0; if (ic->ic_opmode == IEEE80211_M_IBSS) capinfo |= IEEE80211_CAPINFO_IBSS; else /* IEEE80211_M_STA */ capinfo |= IEEE80211_CAPINFO_ESS; if (ic->ic_flags & IEEE80211_F_PRIVACY) capinfo |= IEEE80211_CAPINFO_PRIVACY; /* * NB: Some 11a AP's reject the request when * short premable is set. */ if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) && IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan)) capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE; if ((ni->ni_capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME) && (ic->ic_caps & IEEE80211_C_SHSLOT)) capinfo |= IEEE80211_CAPINFO_SHORT_SLOTTIME; *(u_int16_t *)frm = htole16(capinfo); frm += 2; *(u_int16_t *)frm = htole16(ic->ic_lintval); frm += 2; if (type == IEEE80211_FC0_SUBTYPE_REASSOC_REQ) { IEEE80211_ADDR_COPY(frm, ic->ic_bss->ni_bssid); frm += IEEE80211_ADDR_LEN; } frm = ieee80211_add_ssid(frm, ni->ni_essid, ni->ni_esslen); frm = ieee80211_add_rates(frm, &ni->ni_rates); frm = ieee80211_add_xrates(frm, &ni->ni_rates); if ((ic->ic_flags & IEEE80211_F_WME) && ni->ni_wme_ie != NULL) frm = ieee80211_add_wme_info(frm, &ic->ic_wme); if (ic->ic_opt_ie != NULL) { memcpy(frm, ic->ic_opt_ie, ic->ic_opt_ie_len); frm += ic->ic_opt_ie_len; } m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *); timer = IEEE80211_TRANS_WAIT; break; case IEEE80211_FC0_SUBTYPE_ASSOC_RESP: case IEEE80211_FC0_SUBTYPE_REASSOC_RESP: /* * asreq frame format * [2] capability information * [2] status * [2] association ID * [tlv] supported rates * [tlv] extended supported rates * [tlv] WME (if enabled and STA enabled) */ m = ieee80211_getmgtframe(&frm, sizeof(u_int16_t) + sizeof(u_int16_t) + sizeof(u_int16_t) + 2 + IEEE80211_RATE_SIZE + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE) + sizeof(struct ieee80211_wme_param) ); if (m == NULL) senderr(ENOMEM, is_tx_nobuf); capinfo = IEEE80211_CAPINFO_ESS; if (ic->ic_flags & IEEE80211_F_PRIVACY) capinfo |= IEEE80211_CAPINFO_PRIVACY; if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) && IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan)) capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE; if (ic->ic_flags & IEEE80211_F_SHSLOT) capinfo |= IEEE80211_CAPINFO_SHORT_SLOTTIME; *(u_int16_t *)frm = htole16(capinfo); frm += 2; *(u_int16_t *)frm = htole16(arg); /* status */ frm += 2; if (arg == IEEE80211_STATUS_SUCCESS) { *(u_int16_t *)frm = htole16(ni->ni_associd); IEEE80211_NODE_STAT(ni, tx_assoc); } else IEEE80211_NODE_STAT(ni, tx_assoc_fail); frm += 2; frm = ieee80211_add_rates(frm, &ni->ni_rates); frm = ieee80211_add_xrates(frm, &ni->ni_rates); if ((ic->ic_flags & IEEE80211_F_WME) && ni->ni_wme_ie != NULL) frm = ieee80211_add_wme_param(frm, &ic->ic_wme); m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *); break; case IEEE80211_FC0_SUBTYPE_DISASSOC: IEEE80211_DPRINTF(ic, IEEE80211_MSG_ASSOC, "[%s] send station disassociate (reason %d)\n", ether_sprintf(ni->ni_macaddr), arg); m = ieee80211_getmgtframe(&frm, sizeof(u_int16_t)); if (m == NULL) senderr(ENOMEM, is_tx_nobuf); *(u_int16_t *)frm = htole16(arg); /* reason */ m->m_pkthdr.len = m->m_len = sizeof(u_int16_t); IEEE80211_NODE_STAT(ni, tx_disassoc); IEEE80211_NODE_STAT_SET(ni, tx_disassoc_code, arg); break; default: IEEE80211_DPRINTF(ic, IEEE80211_MSG_ANY, "[%s] invalid mgmt frame type %u\n", ether_sprintf(ni->ni_macaddr), type); senderr(EINVAL, is_tx_unknownmgt); /* NOTREACHED */ } ret = ieee80211_mgmt_output(ic, ni, m, type); if (ret == 0) { if (timer) ic->ic_mgt_timer = timer; } else { bad: ieee80211_free_node(ni); } return ret; #undef senderr } /* * Allocate a beacon frame and fillin the appropriate bits. */ struct mbuf * ieee80211_beacon_alloc(struct ieee80211com *ic, struct ieee80211_node *ni, struct ieee80211_beacon_offsets *bo) { struct ifnet *ifp = ic->ic_ifp; struct ieee80211_frame *wh; struct mbuf *m; int pktlen; u_int8_t *frm, *efrm; u_int16_t capinfo; struct ieee80211_rateset *rs; /* * beacon frame format * [8] time stamp * [2] beacon interval * [2] cabability information * [tlv] ssid * [tlv] supported rates * [3] parameter set (DS) * [tlv] parameter set (IBSS/TIM) * [tlv] extended rate phy (ERP) * [tlv] extended supported rates * [tlv] WME parameters * [tlv] WPA/RSN parameters * XXX Vendor-specific OIDs (e.g. Atheros) * NB: we allocate the max space required for the TIM bitmap. */ rs = &ni->ni_rates; pktlen = 8 /* time stamp */ + sizeof(u_int16_t) /* beacon interval */ + sizeof(u_int16_t) /* capabilities */ + 2 + ni->ni_esslen /* ssid */ + 2 + IEEE80211_RATE_SIZE /* supported rates */ + 2 + 1 /* DS parameters */ + 2 + 4 + ic->ic_tim_len /* DTIM/IBSSPARMS */ + 2 + 1 /* ERP */ + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE) + (ic->ic_caps & IEEE80211_C_WME ? /* WME */ sizeof(struct ieee80211_wme_param) : 0) + (ic->ic_caps & IEEE80211_C_WPA ? /* WPA 1+2 */ 2*sizeof(struct ieee80211_ie_wpa) : 0) ; m = ieee80211_getmgtframe(&frm, pktlen); if (m == NULL) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_ANY, "%s: cannot get buf; size %u\n", __func__, pktlen); ic->ic_stats.is_tx_nobuf++; return NULL; } memset(frm, 0, 8); /* XXX timestamp is set by hardware/driver */ frm += 8; *(u_int16_t *)frm = htole16(ni->ni_intval); frm += 2; if (ic->ic_opmode == IEEE80211_M_IBSS) capinfo = IEEE80211_CAPINFO_IBSS; else capinfo = IEEE80211_CAPINFO_ESS; if (ic->ic_flags & IEEE80211_F_PRIVACY) capinfo |= IEEE80211_CAPINFO_PRIVACY; if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) && IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE; if (ic->ic_flags & IEEE80211_F_SHSLOT) capinfo |= IEEE80211_CAPINFO_SHORT_SLOTTIME; bo->bo_caps = (u_int16_t *)frm; *(u_int16_t *)frm = htole16(capinfo); frm += 2; *frm++ = IEEE80211_ELEMID_SSID; if ((ic->ic_flags & IEEE80211_F_HIDESSID) == 0) { *frm++ = ni->ni_esslen; memcpy(frm, ni->ni_essid, ni->ni_esslen); frm += ni->ni_esslen; } else *frm++ = 0; frm = ieee80211_add_rates(frm, rs); if (ic->ic_curmode != IEEE80211_MODE_FH) { *frm++ = IEEE80211_ELEMID_DSPARMS; *frm++ = 1; *frm++ = ieee80211_chan2ieee(ic, ni->ni_chan); } bo->bo_tim = frm; if (ic->ic_opmode == IEEE80211_M_IBSS) { *frm++ = IEEE80211_ELEMID_IBSSPARMS; *frm++ = 2; *frm++ = 0; *frm++ = 0; /* TODO: ATIM window */ bo->bo_tim_len = 0; } else { struct ieee80211_tim_ie *tie = (struct ieee80211_tim_ie *) frm; tie->tim_ie = IEEE80211_ELEMID_TIM; tie->tim_len = 4; /* length */ tie->tim_count = 0; /* DTIM count */ tie->tim_period = ic->ic_dtim_period; /* DTIM period */ tie->tim_bitctl = 0; /* bitmap control */ tie->tim_bitmap[0] = 0; /* Partial Virtual Bitmap */ frm += sizeof(struct ieee80211_tim_ie); bo->bo_tim_len = 1; } bo->bo_trailer = frm; if (ic->ic_flags & IEEE80211_F_WME) { bo->bo_wme = frm; frm = ieee80211_add_wme_param(frm, &ic->ic_wme); ic->ic_flags &= ~IEEE80211_F_WMEUPDATE; } if (ic->ic_flags & IEEE80211_F_WPA) frm = ieee80211_add_wpa(frm, ic); - if (ic->ic_curmode == IEEE80211_MODE_11G) + if (ic->ic_curmode == IEEE80211_MODE_11G) { + bo->bo_erp = frm; frm = ieee80211_add_erp(frm, ic); + } efrm = ieee80211_add_xrates(frm, rs); bo->bo_trailer_len = efrm - bo->bo_trailer; m->m_pkthdr.len = m->m_len = efrm - mtod(m, u_int8_t *); M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT); KASSERT(m != NULL, ("no space for 802.11 header?")); wh = mtod(m, struct ieee80211_frame *); wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_BEACON; wh->i_fc[1] = IEEE80211_FC1_DIR_NODS; *(u_int16_t *)wh->i_dur = 0; IEEE80211_ADDR_COPY(wh->i_addr1, ifp->if_broadcastaddr); IEEE80211_ADDR_COPY(wh->i_addr2, ic->ic_myaddr); IEEE80211_ADDR_COPY(wh->i_addr3, ni->ni_bssid); *(u_int16_t *)wh->i_seq = 0; return m; } /* * Update the dynamic parts of a beacon frame based on the current state. */ int ieee80211_beacon_update(struct ieee80211com *ic, struct ieee80211_node *ni, struct ieee80211_beacon_offsets *bo, struct mbuf *m, int mcast) { int len_changed = 0; u_int16_t capinfo; IEEE80211_BEACON_LOCK(ic); /* XXX faster to recalculate entirely or just changes? */ if (ic->ic_opmode == IEEE80211_M_IBSS) capinfo = IEEE80211_CAPINFO_IBSS; else capinfo = IEEE80211_CAPINFO_ESS; if (ic->ic_flags & IEEE80211_F_PRIVACY) capinfo |= IEEE80211_CAPINFO_PRIVACY; if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) && IEEE80211_IS_CHAN_2GHZ(ni->ni_chan)) capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE; if (ic->ic_flags & IEEE80211_F_SHSLOT) capinfo |= IEEE80211_CAPINFO_SHORT_SLOTTIME; *bo->bo_caps = htole16(capinfo); if (ic->ic_flags & IEEE80211_F_WME) { struct ieee80211_wme_state *wme = &ic->ic_wme; /* * Check for agressive mode change. When there is * significant high priority traffic in the BSS * throttle back BE traffic by using conservative * parameters. Otherwise BE uses agressive params * to optimize performance of legacy/non-QoS traffic. */ if (wme->wme_flags & WME_F_AGGRMODE) { if (wme->wme_hipri_traffic > wme->wme_hipri_switch_thresh) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_WME, "%s: traffic %u, disable aggressive mode\n", __func__, wme->wme_hipri_traffic); wme->wme_flags &= ~WME_F_AGGRMODE; ieee80211_wme_updateparams_locked(ic); wme->wme_hipri_traffic = wme->wme_hipri_switch_hysteresis; } else wme->wme_hipri_traffic = 0; } else { if (wme->wme_hipri_traffic <= wme->wme_hipri_switch_thresh) { IEEE80211_DPRINTF(ic, IEEE80211_MSG_WME, "%s: traffic %u, enable aggressive mode\n", __func__, wme->wme_hipri_traffic); wme->wme_flags |= WME_F_AGGRMODE; ieee80211_wme_updateparams_locked(ic); wme->wme_hipri_traffic = 0; } else wme->wme_hipri_traffic = wme->wme_hipri_switch_hysteresis; } if (ic->ic_flags & IEEE80211_F_WMEUPDATE) { (void) ieee80211_add_wme_param(bo->bo_wme, wme); ic->ic_flags &= ~IEEE80211_F_WMEUPDATE; } } if (ic->ic_opmode == IEEE80211_M_HOSTAP) { /* NB: no IBSS support*/ struct ieee80211_tim_ie *tie = (struct ieee80211_tim_ie *) bo->bo_tim; if (ic->ic_flags & IEEE80211_F_TIMUPDATE) { u_int timlen, timoff, i; /* * ATIM/DTIM needs updating. If it fits in the * current space allocated then just copy in the * new bits. Otherwise we need to move any trailing * data to make room. Note that we know there is * contiguous space because ieee80211_beacon_allocate * insures there is space in the mbuf to write a * maximal-size virtual bitmap (based on ic_max_aid). */ /* * Calculate the bitmap size and offset, copy any * trailer out of the way, and then copy in the * new bitmap and update the information element. * Note that the tim bitmap must contain at least * one byte and any offset must be even. */ if (ic->ic_ps_pending != 0) { timoff = 128; /* impossibly large */ for (i = 0; i < ic->ic_tim_len; i++) if (ic->ic_tim_bitmap[i]) { timoff = i &~ 1; break; } KASSERT(timoff != 128, ("tim bitmap empty!")); for (i = ic->ic_tim_len-1; i >= timoff; i--) if (ic->ic_tim_bitmap[i]) break; timlen = 1 + (i - timoff); } else { timoff = 0; timlen = 1; } if (timlen != bo->bo_tim_len) { /* copy up/down trailer */ - ovbcopy(bo->bo_trailer, tie->tim_bitmap+timlen, + int adjust = tie->tim_bitmap+timlen + - bo->bo_trailer; + ovbcopy(bo->bo_trailer, bo->bo_trailer+adjust, bo->bo_trailer_len); - bo->bo_trailer = tie->tim_bitmap+timlen; - bo->bo_wme = bo->bo_trailer; + bo->bo_trailer += adjust; + bo->bo_wme += adjust; + bo->bo_erp += adjust; bo->bo_tim_len = timlen; /* update information element */ tie->tim_len = 3 + timlen; tie->tim_bitctl = timoff; len_changed = 1; } memcpy(tie->tim_bitmap, ic->ic_tim_bitmap + timoff, bo->bo_tim_len); ic->ic_flags &= ~IEEE80211_F_TIMUPDATE; IEEE80211_DPRINTF(ic, IEEE80211_MSG_POWER, "%s: TIM updated, pending %u, off %u, len %u\n", __func__, ic->ic_ps_pending, timoff, timlen); } /* count down DTIM period */ if (tie->tim_count == 0) tie->tim_count = tie->tim_period - 1; else tie->tim_count--; /* update state for buffered multicast frames on DTIM */ if (mcast && tie->tim_count == 0) tie->tim_bitctl |= 1; else tie->tim_bitctl &= ~1; + if (ic->ic_flags_ext & IEEE80211_FEXT_ERPUPDATE) { + /* + * ERP element needs updating. + */ + (void) ieee80211_add_erp(bo->bo_erp, ic); + ic->ic_flags_ext &= ~IEEE80211_FEXT_ERPUPDATE; + } } IEEE80211_BEACON_UNLOCK(ic); return len_changed; } /* * Save an outbound packet for a node in power-save sleep state. * The new packet is placed on the node's saved queue, and the TIM * is changed, if necessary. */ void ieee80211_pwrsave(struct ieee80211com *ic, struct ieee80211_node *ni, struct mbuf *m) { int qlen, age; IEEE80211_NODE_SAVEQ_LOCK(ni); if (_IF_QFULL(&ni->ni_savedq)) { _IF_DROP(&ni->ni_savedq); IEEE80211_NODE_SAVEQ_UNLOCK(ni); IEEE80211_DPRINTF(ic, IEEE80211_MSG_ANY, "[%s] pwr save q overflow, drops %d (size %d)\n", ether_sprintf(ni->ni_macaddr), ni->ni_savedq.ifq_drops, IEEE80211_PS_MAX_QUEUE); #ifdef IEEE80211_DEBUG if (ieee80211_msg_dumppkts(ic)) ieee80211_dump_pkt(mtod(m, caddr_t), m->m_len, -1, -1); #endif m_freem(m); return; } /* * Tag the frame with it's expiry time and insert * it in the queue. The aging interval is 4 times * the listen interval specified by the station. * Frames that sit around too long are reclaimed * using this information. */ /* XXX handle overflow? */ age = ((ni->ni_intval * ic->ic_bintval) << 2) / 1024; /* TU -> secs */ _IEEE80211_NODE_SAVEQ_ENQUEUE(ni, m, qlen, age); IEEE80211_NODE_SAVEQ_UNLOCK(ni); IEEE80211_DPRINTF(ic, IEEE80211_MSG_POWER, "[%s] save frame with age %d, %u now queued\n", ether_sprintf(ni->ni_macaddr), age, qlen); if (qlen == 1) ic->ic_set_tim(ni, 1); } Index: head/sys/net80211/ieee80211_proto.h =================================================================== --- head/sys/net80211/ieee80211_proto.h (revision 153972) +++ head/sys/net80211/ieee80211_proto.h (revision 153973) @@ -1,257 +1,258 @@ /*- * Copyright (c) 2001 Atsushi Onoe * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _NET80211_IEEE80211_PROTO_H_ #define _NET80211_IEEE80211_PROTO_H_ /* * 802.11 protocol implementation definitions. */ enum ieee80211_state { IEEE80211_S_INIT = 0, /* default state */ IEEE80211_S_SCAN = 1, /* scanning */ IEEE80211_S_AUTH = 2, /* try to authenticate */ IEEE80211_S_ASSOC = 3, /* try to assoc */ IEEE80211_S_RUN = 4, /* associated */ }; #define IEEE80211_S_MAX (IEEE80211_S_RUN+1) #define IEEE80211_SEND_MGMT(_ic,_ni,_type,_arg) \ ((*(_ic)->ic_send_mgmt)(_ic, _ni, _type, _arg)) extern const char *ieee80211_mgt_subtype_name[]; extern const char *ieee80211_phymode_name[]; void ieee80211_proto_attach(struct ieee80211com *); void ieee80211_proto_detach(struct ieee80211com *); struct ieee80211_node; int ieee80211_input(struct ieee80211com *, struct mbuf *, struct ieee80211_node *, int, u_int32_t); int ieee80211_setup_rates(struct ieee80211_node *ni, const u_int8_t *rates, const u_int8_t *xrates, int flags); void ieee80211_saveie(u_int8_t **, const u_int8_t *); void ieee80211_recv_mgmt(struct ieee80211com *, struct mbuf *, struct ieee80211_node *, int, int, u_int32_t); int ieee80211_send_nulldata(struct ieee80211_node *); int ieee80211_send_probereq(struct ieee80211_node *ni, const u_int8_t sa[IEEE80211_ADDR_LEN], const u_int8_t da[IEEE80211_ADDR_LEN], const u_int8_t bssid[IEEE80211_ADDR_LEN], const u_int8_t *ssid, size_t ssidlen, const void *optie, size_t optielen); int ieee80211_send_mgmt(struct ieee80211com *, struct ieee80211_node *, int, int); int ieee80211_classify(struct ieee80211com *, struct mbuf *, struct ieee80211_node *); struct mbuf *ieee80211_encap(struct ieee80211com *, struct mbuf *, struct ieee80211_node *); void ieee80211_pwrsave(struct ieee80211com *, struct ieee80211_node *, struct mbuf *); void ieee80211_reset_erp(struct ieee80211com *); void ieee80211_set_shortslottime(struct ieee80211com *, int onoff); int ieee80211_iserp_rateset(struct ieee80211com *, struct ieee80211_rateset *); void ieee80211_set11gbasicrates(struct ieee80211_rateset *, enum ieee80211_phymode); /* * Return the size of the 802.11 header for a management or data frame. */ static __inline int ieee80211_hdrsize(const void *data) { const struct ieee80211_frame *wh = data; int size = sizeof(struct ieee80211_frame); /* NB: we don't handle control frames */ KASSERT((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_CTL, ("%s: control frame", __func__)); if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS) size += IEEE80211_ADDR_LEN; if (IEEE80211_QOS_HAS_SEQ(wh)) size += sizeof(u_int16_t); return size; } /* * Return the size of the 802.11 header; handles any type of frame. */ static __inline int ieee80211_anyhdrsize(const void *data) { const struct ieee80211_frame *wh = data; if ((wh->i_fc[0]&IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL) { switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) { case IEEE80211_FC0_SUBTYPE_CTS: case IEEE80211_FC0_SUBTYPE_ACK: return sizeof(struct ieee80211_frame_ack); } return sizeof(struct ieee80211_frame_min); } else return ieee80211_hdrsize(data); } /* * Template for an in-kernel authenticator. Authenticators * register with the protocol code and are typically loaded * as separate modules as needed. */ struct ieee80211_authenticator { const char *ia_name; /* printable name */ int (*ia_attach)(struct ieee80211com *); void (*ia_detach)(struct ieee80211com *); void (*ia_node_join)(struct ieee80211com *, struct ieee80211_node *); void (*ia_node_leave)(struct ieee80211com *, struct ieee80211_node *); }; void ieee80211_authenticator_register(int type, const struct ieee80211_authenticator *); void ieee80211_authenticator_unregister(int type); const struct ieee80211_authenticator *ieee80211_authenticator_get(int auth); struct ieee80211req; /* * Template for an MAC ACL policy module. Such modules * register with the protocol code and are passed the sender's * address of each received frame for validation. */ struct ieee80211_aclator { const char *iac_name; /* printable name */ int (*iac_attach)(struct ieee80211com *); void (*iac_detach)(struct ieee80211com *); int (*iac_check)(struct ieee80211com *, const u_int8_t mac[IEEE80211_ADDR_LEN]); int (*iac_add)(struct ieee80211com *, const u_int8_t mac[IEEE80211_ADDR_LEN]); int (*iac_remove)(struct ieee80211com *, const u_int8_t mac[IEEE80211_ADDR_LEN]); int (*iac_flush)(struct ieee80211com *); int (*iac_setpolicy)(struct ieee80211com *, int); int (*iac_getpolicy)(struct ieee80211com *); int (*iac_setioctl)(struct ieee80211com *, struct ieee80211req *); int (*iac_getioctl)(struct ieee80211com *, struct ieee80211req *); }; void ieee80211_aclator_register(const struct ieee80211_aclator *); void ieee80211_aclator_unregister(const struct ieee80211_aclator *); const struct ieee80211_aclator *ieee80211_aclator_get(const char *name); /* flags for ieee80211_fix_rate() */ #define IEEE80211_F_DOSORT 0x00000001 /* sort rate list */ #define IEEE80211_F_DOFRATE 0x00000002 /* use fixed rate */ #define IEEE80211_F_DONEGO 0x00000004 /* calc negotiated rate */ #define IEEE80211_F_DODEL 0x00000008 /* delete ignore rate */ int ieee80211_fix_rate(struct ieee80211_node *, int); /* * WME/WMM support. */ struct wmeParams { u_int8_t wmep_acm; u_int8_t wmep_aifsn; u_int8_t wmep_logcwmin; /* log2(cwmin) */ u_int8_t wmep_logcwmax; /* log2(cwmax) */ u_int8_t wmep_txopLimit; u_int8_t wmep_noackPolicy; /* 0 (ack), 1 (no ack) */ }; #define IEEE80211_TXOP_TO_US(_txop) ((_txop)<<5) #define IEEE80211_US_TO_TXOP(_us) ((_us)>>5) struct chanAccParams { u_int8_t cap_info; /* version of the current set */ struct wmeParams cap_wmeParams[WME_NUM_AC]; }; struct ieee80211_wme_state { u_int wme_flags; #define WME_F_AGGRMODE 0x00000001 /* STATUS: WME agressive mode */ u_int wme_hipri_traffic; /* VI/VO frames in beacon interval */ u_int wme_hipri_switch_thresh;/* agressive mode switch thresh */ u_int wme_hipri_switch_hysteresis;/* agressive mode switch hysteresis */ struct wmeParams wme_params[4]; /* from assoc resp for each AC*/ struct chanAccParams wme_wmeChanParams; /* WME params applied to self */ struct chanAccParams wme_wmeBssChanParams;/* WME params bcast to stations */ struct chanAccParams wme_chanParams; /* params applied to self */ struct chanAccParams wme_bssChanParams; /* params bcast to stations */ int (*wme_update)(struct ieee80211com *); }; void ieee80211_wme_initparams(struct ieee80211com *); void ieee80211_wme_updateparams(struct ieee80211com *); void ieee80211_wme_updateparams_locked(struct ieee80211com *); #define ieee80211_new_state(_ic, _nstate, _arg) \ (((_ic)->ic_newstate)((_ic), (_nstate), (_arg))) void ieee80211_beacon_miss(struct ieee80211com *); void ieee80211_print_essid(const u_int8_t *, int); void ieee80211_dump_pkt(const u_int8_t *, int, int, int); extern const char *ieee80211_state_name[IEEE80211_S_MAX]; extern const char *ieee80211_wme_acnames[]; /* * Beacon frames constructed by ieee80211_beacon_alloc * have the following structure filled in so drivers * can update the frame later w/ minimal overhead. */ struct ieee80211_beacon_offsets { u_int16_t *bo_caps; /* capabilities */ u_int8_t *bo_tim; /* start of atim/dtim */ u_int8_t *bo_wme; /* start of WME parameters */ u_int8_t *bo_trailer; /* start of fixed-size trailer */ u_int16_t bo_tim_len; /* atim/dtim length in bytes */ u_int16_t bo_trailer_len; /* trailer length in bytes */ + u_int8_t *bo_erp; /* start of ERP element */ }; struct mbuf *ieee80211_beacon_alloc(struct ieee80211com *, struct ieee80211_node *, struct ieee80211_beacon_offsets *); int ieee80211_beacon_update(struct ieee80211com *, struct ieee80211_node *, struct ieee80211_beacon_offsets *, struct mbuf *, int broadcast); /* * Notification methods called from the 802.11 state machine. * Note that while these are defined here, their implementation * is OS-specific. */ void ieee80211_notify_node_join(struct ieee80211com *, struct ieee80211_node *, int newassoc); void ieee80211_notify_node_leave(struct ieee80211com *, struct ieee80211_node *); void ieee80211_notify_scan_done(struct ieee80211com *); #endif /* _NET80211_IEEE80211_PROTO_H_ */ Index: head/sys/net80211/ieee80211_var.h =================================================================== --- head/sys/net80211/ieee80211_var.h (revision 153972) +++ head/sys/net80211/ieee80211_var.h (revision 153973) @@ -1,422 +1,423 @@ /*- * Copyright (c) 2001 Atsushi Onoe * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _NET80211_IEEE80211_VAR_H_ #define _NET80211_IEEE80211_VAR_H_ /* * Definitions for IEEE 802.11 drivers. */ #define IEEE80211_DEBUG #undef IEEE80211_DEBUG_REFCNT /* node refcnt stuff */ /* NB: portability glue must go first */ #ifdef __NetBSD__ #include #elif __FreeBSD__ #include #elif __linux__ #include #else #error "No support for your operating system!" #endif #include #include #include #include /* for ieee80211_stats */ #include #include #define IEEE80211_TXPOWER_MAX 100 /* .5 dbM (XXX units?) */ #define IEEE80211_TXPOWER_MIN 0 /* kill radio */ #define IEEE80211_DTIM_MAX 15 /* max DTIM period */ #define IEEE80211_DTIM_MIN 1 /* min DTIM period */ #define IEEE80211_DTIM_DEFAULT 1 /* default DTIM period */ /* NB: min+max come from WiFi requirements */ #define IEEE80211_BINTVAL_MAX 1000 /* max beacon interval (TU's) */ #define IEEE80211_BINTVAL_MIN 25 /* min beacon interval (TU's) */ #define IEEE80211_BINTVAL_DEFAULT 100 /* default beacon interval (TU's) */ #define IEEE80211_BMISS_MAX 2 /* maximum consecutive bmiss allowed */ #define IEEE80211_PS_SLEEP 0x1 /* STA is in power saving mode */ #define IEEE80211_PS_MAX_QUEUE 50 /* maximum saved packets */ #define IEEE80211_FIXED_RATE_NONE -1 #define IEEE80211_MCAST_RATE_DEFAULT (2*1) /* default mcast rate (1M) */ #define IEEE80211_RTS_DEFAULT IEEE80211_RTS_MAX #define IEEE80211_FRAG_DEFAULT IEEE80211_FRAG_MAX #define IEEE80211_MS_TO_TU(x) (((x) * 1024) / 1000) #define IEEE80211_TU_TO_MS(x) (((x) * 1000) / 1024) struct ieee80211_aclator; struct sysctl_ctx_list; struct ieee80211com { SLIST_ENTRY(ieee80211com) ic_next; struct ifnet *ic_ifp; /* associated device */ struct ieee80211_stats ic_stats; /* statistics */ struct sysctl_ctx_list *ic_sysctl; /* dynamic sysctl context */ u_int32_t ic_debug; /* debug msg flags */ int ic_vap; /* virtual AP index */ ieee80211_beacon_lock_t ic_beaconlock; /* beacon update lock */ int (*ic_reset)(struct ifnet *); void (*ic_recv_mgmt)(struct ieee80211com *, struct mbuf *, struct ieee80211_node *, int, int, u_int32_t); int (*ic_send_mgmt)(struct ieee80211com *, struct ieee80211_node *, int, int); int (*ic_newstate)(struct ieee80211com *, enum ieee80211_state, int); void (*ic_newassoc)(struct ieee80211_node *, int); void (*ic_updateslot)(struct ifnet *); void (*ic_set_tim)(struct ieee80211_node *, int); u_int8_t ic_myaddr[IEEE80211_ADDR_LEN]; struct ieee80211_rateset ic_sup_rates[IEEE80211_MODE_MAX]; struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX+1]; u_int8_t ic_chan_avail[IEEE80211_CHAN_BYTES]; u_int8_t ic_chan_active[IEEE80211_CHAN_BYTES]; u_int8_t ic_chan_scan[IEEE80211_CHAN_BYTES]; struct ieee80211_node_table ic_scan; /* scan candidates */ struct ifqueue ic_mgtq; u_int32_t ic_flags; /* state flags */ u_int32_t ic_flags_ext; /* extended state flags */ u_int32_t ic_caps; /* capabilities */ u_int16_t ic_modecaps; /* set of mode capabilities */ u_int16_t ic_curmode; /* current mode */ enum ieee80211_phytype ic_phytype; /* XXX wrong for multi-mode */ enum ieee80211_opmode ic_opmode; /* operation mode */ enum ieee80211_state ic_state; /* 802.11 state */ enum ieee80211_protmode ic_protmode; /* 802.11g protection mode */ enum ieee80211_roamingmode ic_roaming; /* roaming mode */ struct ieee80211_node_table ic_sta; /* stations/neighbors */ u_int32_t *ic_aid_bitmap; /* association id map */ u_int16_t ic_max_aid; u_int16_t ic_sta_assoc; /* stations associated */ u_int16_t ic_ps_sta; /* stations in power save */ u_int16_t ic_ps_pending; /* ps sta's w/ pending frames */ u_int8_t *ic_tim_bitmap; /* power-save stations w/ data*/ u_int16_t ic_tim_len; /* ic_tim_bitmap size (bytes) */ u_int8_t ic_dtim_period; /* DTIM period */ u_int8_t ic_dtim_count; /* DTIM count for last bcn */ struct ifmedia ic_media; /* interface media config */ struct bpf_if *ic_rawbpf; /* packet filter structure */ struct ieee80211_node *ic_bss; /* information for this node */ struct ieee80211_channel *ic_ibss_chan; struct ieee80211_channel *ic_curchan; /* current channel */ int ic_fixed_rate; /* index to ic_sup_rates[] */ int ic_mcast_rate; /* rate for mcast frames */ u_int16_t ic_rtsthreshold; u_int16_t ic_fragthreshold; u_int8_t ic_bmiss_count; /* current beacon miss count */ int ic_bmiss_max; /* max bmiss before scan */ struct ieee80211_node *(*ic_node_alloc)(struct ieee80211_node_table*); void (*ic_node_free)(struct ieee80211_node *); void (*ic_node_cleanup)(struct ieee80211_node *); u_int8_t (*ic_node_getrssi)(const struct ieee80211_node*); u_int16_t ic_lintval; /* listen interval */ u_int16_t ic_bintval; /* beacon interval */ u_int16_t ic_holdover; /* PM hold over duration */ u_int16_t ic_txmin; /* min tx retry count */ u_int16_t ic_txmax; /* max tx retry count */ u_int16_t ic_txlifetime; /* tx lifetime */ u_int16_t ic_txpowlimit; /* global tx power limit */ u_int16_t ic_bmisstimeout;/* beacon miss threshold (ms) */ u_int16_t ic_nonerpsta; /* # non-ERP stations */ u_int16_t ic_longslotsta; /* # long slot time stations */ int ic_mgt_timer; /* mgmt timeout */ int ic_inact_timer; /* inactivity timer wait */ int ic_des_esslen; u_int8_t ic_des_essid[IEEE80211_NWID_LEN]; struct ieee80211_channel *ic_des_chan; /* desired channel */ u_int8_t ic_des_bssid[IEEE80211_ADDR_LEN]; void *ic_opt_ie; /* user-specified IE's */ u_int16_t ic_opt_ie_len; /* length of ni_opt_ie */ /* * Inactivity timer settings for nodes. */ int ic_inact_init; /* initial setting */ int ic_inact_auth; /* auth but not assoc setting */ int ic_inact_run; /* authorized setting */ int ic_inact_probe; /* inactive probe time */ /* * WME/WMM state. */ struct ieee80211_wme_state ic_wme; /* * Cipher state/configuration. */ struct ieee80211_crypto_state ic_crypto; #define ic_nw_keys ic_crypto.cs_nw_keys /* XXX compatibility */ #define ic_def_txkey ic_crypto.cs_def_txkey /* XXX compatibility */ /* * 802.1x glue. When an authenticator attaches it * fills in this section. We assume that when ic_ec * is setup that the methods are safe to call. */ const struct ieee80211_authenticator *ic_auth; struct eapolcom *ic_ec; /* * Access control glue. When a control agent attaches * it fills in this section. We assume that when ic_ac * is setup that the methods are safe to call. */ const struct ieee80211_aclator *ic_acl; void *ic_as; }; #define IEEE80211_ADDR_EQ(a1,a2) (memcmp(a1,a2,IEEE80211_ADDR_LEN) == 0) #define IEEE80211_ADDR_COPY(dst,src) memcpy(dst,src,IEEE80211_ADDR_LEN) /* ic_flags */ /* NB: bits 0x4c available */ #define IEEE80211_F_FF 0x00000001 /* CONF: ATH FF enabled */ #define IEEE80211_F_TURBOP 0x00000002 /* CONF: ATH Turbo enabled*/ #define IEEE80211_F_BURST 0x00000004 /* CONF: bursting enabled */ /* NB: this is intentionally setup to be IEEE80211_CAPINFO_PRIVACY */ #define IEEE80211_F_PRIVACY 0x00000010 /* CONF: privacy enabled */ #define IEEE80211_F_PUREG 0x00000020 /* CONF: 11g w/o 11b sta's */ #define IEEE80211_F_SCAN 0x00000080 /* STATUS: scanning */ #define IEEE80211_F_ASCAN 0x00000100 /* STATUS: active scan */ #define IEEE80211_F_SIBSS 0x00000200 /* STATUS: start IBSS */ /* NB: this is intentionally setup to be IEEE80211_CAPINFO_SHORT_SLOTTIME */ #define IEEE80211_F_SHSLOT 0x00000400 /* STATUS: use short slot time*/ #define IEEE80211_F_PMGTON 0x00000800 /* CONF: Power mgmt enable */ #define IEEE80211_F_DESBSSID 0x00001000 /* CONF: des_bssid is set */ #define IEEE80211_F_WME 0x00002000 /* CONF: enable WME use */ #define IEEE80211_F_BGSCAN 0x00004000 /* CONF: bg scan enabled (???)*/ #define IEEE80211_F_SWRETRY 0x00008000 /* CONF: sw tx retry enabled */ #define IEEE80211_F_TXPOW_FIXED 0x00010000 /* TX Power: fixed rate */ #define IEEE80211_F_IBSSON 0x00020000 /* CONF: IBSS creation enable */ #define IEEE80211_F_SHPREAMBLE 0x00040000 /* STATUS: use short preamble */ #define IEEE80211_F_DATAPAD 0x00080000 /* CONF: do alignment pad */ #define IEEE80211_F_USEPROT 0x00100000 /* STATUS: protection enabled */ #define IEEE80211_F_USEBARKER 0x00200000 /* STATUS: use barker preamble*/ #define IEEE80211_F_TIMUPDATE 0x00400000 /* STATUS: update beacon tim */ #define IEEE80211_F_WPA1 0x00800000 /* CONF: WPA enabled */ #define IEEE80211_F_WPA2 0x01000000 /* CONF: WPA2 enabled */ #define IEEE80211_F_WPA 0x01800000 /* CONF: WPA/WPA2 enabled */ #define IEEE80211_F_DROPUNENC 0x02000000 /* CONF: drop unencrypted */ #define IEEE80211_F_COUNTERM 0x04000000 /* CONF: TKIP countermeasures */ #define IEEE80211_F_HIDESSID 0x08000000 /* CONF: hide SSID in beacon */ #define IEEE80211_F_NOBRIDGE 0x10000000 /* CONF: dis. internal bridge */ #define IEEE80211_F_WMEUPDATE 0x20000000 /* STATUS: update beacon wme */ /* ic_flags_ext */ #define IEEE80211_FEXT_WDS 0x00000001 /* CONF: 4 addr allowed */ /* 0x00000006 reserved */ #define IEEE80211_FEXT_BGSCAN 0x00000008 /* STATUS: enable full bgscan completion */ +#define IEEE80211_FEXT_ERPUPDATE 0x00000200 /* STATUS: update ERP element */ /* ic_caps */ #define IEEE80211_C_WEP 0x00000001 /* CAPABILITY: WEP available */ #define IEEE80211_C_TKIP 0x00000002 /* CAPABILITY: TKIP available */ #define IEEE80211_C_AES 0x00000004 /* CAPABILITY: AES OCB avail */ #define IEEE80211_C_AES_CCM 0x00000008 /* CAPABILITY: AES CCM avail */ #define IEEE80211_C_CKIP 0x00000020 /* CAPABILITY: CKIP available */ #define IEEE80211_C_FF 0x00000040 /* CAPABILITY: ATH FF avail */ #define IEEE80211_C_TURBOP 0x00000080 /* CAPABILITY: ATH Turbo avail*/ #define IEEE80211_C_IBSS 0x00000100 /* CAPABILITY: IBSS available */ #define IEEE80211_C_PMGT 0x00000200 /* CAPABILITY: Power mgmt */ #define IEEE80211_C_HOSTAP 0x00000400 /* CAPABILITY: HOSTAP avail */ #define IEEE80211_C_AHDEMO 0x00000800 /* CAPABILITY: Old Adhoc Demo */ #define IEEE80211_C_SWRETRY 0x00001000 /* CAPABILITY: sw tx retry */ #define IEEE80211_C_TXPMGT 0x00002000 /* CAPABILITY: tx power mgmt */ #define IEEE80211_C_SHSLOT 0x00004000 /* CAPABILITY: short slottime */ #define IEEE80211_C_SHPREAMBLE 0x00008000 /* CAPABILITY: short preamble */ #define IEEE80211_C_MONITOR 0x00010000 /* CAPABILITY: monitor mode */ #define IEEE80211_C_TKIPMIC 0x00020000 /* CAPABILITY: TKIP MIC avail */ #define IEEE80211_C_WPA1 0x00800000 /* CAPABILITY: WPA1 avail */ #define IEEE80211_C_WPA2 0x01000000 /* CAPABILITY: WPA2 avail */ #define IEEE80211_C_WPA 0x01800000 /* CAPABILITY: WPA1+WPA2 avail*/ #define IEEE80211_C_BURST 0x02000000 /* CAPABILITY: frame bursting */ #define IEEE80211_C_WME 0x04000000 /* CAPABILITY: WME avail */ #define IEEE80211_C_WDS 0x08000000 /* CAPABILITY: 4-addr support */ /* 0x10000000 reserved */ #define IEEE80211_C_BGSCAN 0x20000000 /* CAPABILITY: bg scanning */ #define IEEE80211_C_TXFRAG 0x40000000 /* CAPABILITY: tx fragments */ /* XXX protection/barker? */ #define IEEE80211_C_CRYPTO 0x0000002f /* CAPABILITY: crypto alg's */ void ieee80211_ifattach(struct ieee80211com *); void ieee80211_ifdetach(struct ieee80211com *); void ieee80211_announce(struct ieee80211com *); void ieee80211_media_init(struct ieee80211com *, ifm_change_cb_t, ifm_stat_cb_t); struct ieee80211com *ieee80211_find_vap(const u_int8_t mac[IEEE80211_ADDR_LEN]); int ieee80211_media_change(struct ifnet *); void ieee80211_media_status(struct ifnet *, struct ifmediareq *); int ieee80211_ioctl(struct ieee80211com *, u_long, caddr_t); int ieee80211_cfgget(struct ieee80211com *, u_long, caddr_t); int ieee80211_cfgset(struct ieee80211com *, u_long, caddr_t); void ieee80211_watchdog(struct ieee80211com *); int ieee80211_rate2media(struct ieee80211com *, int, enum ieee80211_phymode); int ieee80211_media2rate(int); int ieee80211_mhz2ieee(u_int, u_int); int ieee80211_chan2ieee(struct ieee80211com *, struct ieee80211_channel *); u_int ieee80211_ieee2mhz(u_int, u_int); int ieee80211_setmode(struct ieee80211com *, enum ieee80211_phymode); enum ieee80211_phymode ieee80211_chan2mode(struct ieee80211com *, struct ieee80211_channel *); /* * Key update synchronization methods. XXX should not be visible. */ static __inline void ieee80211_key_update_begin(struct ieee80211com *ic) { ic->ic_crypto.cs_key_update_begin(ic); } static __inline void ieee80211_key_update_end(struct ieee80211com *ic) { ic->ic_crypto.cs_key_update_end(ic); } /* * XXX these need to be here for IEEE80211_F_DATAPAD */ /* * Return the space occupied by the 802.11 header and any * padding required by the driver. This works for a * management or data frame. */ static __inline int ieee80211_hdrspace(struct ieee80211com *ic, const void *data) { int size = ieee80211_hdrsize(data); if (ic->ic_flags & IEEE80211_F_DATAPAD) size = roundup(size, sizeof(u_int32_t)); return size; } /* * Like ieee80211_hdrspace, but handles any type of frame. */ static __inline int ieee80211_anyhdrspace(struct ieee80211com *ic, const void *data) { int size = ieee80211_anyhdrsize(data); if (ic->ic_flags & IEEE80211_F_DATAPAD) size = roundup(size, sizeof(u_int32_t)); return size; } #define IEEE80211_MSG_DEBUG 0x40000000 /* IFF_DEBUG equivalent */ #define IEEE80211_MSG_DUMPPKTS 0x20000000 /* IFF_LINK2 equivalant */ #define IEEE80211_MSG_CRYPTO 0x10000000 /* crypto work */ #define IEEE80211_MSG_INPUT 0x08000000 /* input handling */ #define IEEE80211_MSG_XRATE 0x04000000 /* rate set handling */ #define IEEE80211_MSG_ELEMID 0x02000000 /* element id parsing */ #define IEEE80211_MSG_NODE 0x01000000 /* node handling */ #define IEEE80211_MSG_ASSOC 0x00800000 /* association handling */ #define IEEE80211_MSG_AUTH 0x00400000 /* authentication handling */ #define IEEE80211_MSG_SCAN 0x00200000 /* scanning */ #define IEEE80211_MSG_OUTPUT 0x00100000 /* output handling */ #define IEEE80211_MSG_STATE 0x00080000 /* state machine */ #define IEEE80211_MSG_POWER 0x00040000 /* power save handling */ #define IEEE80211_MSG_DOT1X 0x00020000 /* 802.1x authenticator */ #define IEEE80211_MSG_DOT1XSM 0x00010000 /* 802.1x state machine */ #define IEEE80211_MSG_RADIUS 0x00008000 /* 802.1x radius client */ #define IEEE80211_MSG_RADDUMP 0x00004000 /* dump 802.1x radius packets */ #define IEEE80211_MSG_RADKEYS 0x00002000 /* dump 802.1x keys */ #define IEEE80211_MSG_WPA 0x00001000 /* WPA/RSN protocol */ #define IEEE80211_MSG_ACL 0x00000800 /* ACL handling */ #define IEEE80211_MSG_WME 0x00000400 /* WME protocol */ #define IEEE80211_MSG_SUPERG 0x00000200 /* Atheros SuperG protocol */ #define IEEE80211_MSG_DOTH 0x00000100 /* 802.11h support */ #define IEEE80211_MSG_INACT 0x00000080 /* inactivity handling */ #define IEEE80211_MSG_ROAM 0x00000040 /* sta-mode roaming */ #define IEEE80211_MSG_ANY 0xffffffff /* anything */ #ifdef IEEE80211_DEBUG #define ieee80211_msg(_ic, _m) ((_ic)->ic_debug & (_m)) #define IEEE80211_DPRINTF(_ic, _m, _fmt, ...) do { \ if (ieee80211_msg(_ic, _m)) \ ieee80211_note(_ic, _fmt, __VA_ARGS__); \ } while (0) #define IEEE80211_NOTE(_ic, _m, _ni, _fmt, ...) do { \ if (ieee80211_msg(_ic, _m)) \ ieee80211_note_mac(_ic, (_ni)->ni_macaddr, _fmt, __VA_ARGS__);\ } while (0) #define IEEE80211_NOTE_MAC(_ic, _m, _mac, _fmt, ...) do { \ if (ieee80211_msg(_ic, _m)) \ ieee80211_note_mac(_ic, _mac, _fmt, __VA_ARGS__); \ } while (0) #define IEEE80211_NOTE_FRAME(_ic, _m, _wh, _fmt, ...) do { \ if (ieee80211_msg(_ic, _m)) \ ieee80211_note_frame(_ic, _wh, _fmt, __VA_ARGS__); \ } while (0) void ieee80211_note(struct ieee80211com *ic, const char *fmt, ...); void ieee80211_note_mac(struct ieee80211com *ic, const u_int8_t mac[IEEE80211_ADDR_LEN], const char *fmt, ...); void ieee80211_note_frame(struct ieee80211com *ic, const struct ieee80211_frame *wh, const char *fmt, ...); #define ieee80211_msg_debug(_ic) \ ((_ic)->ic_debug & IEEE80211_MSG_DEBUG) #define ieee80211_msg_dumppkts(_ic) \ ((_ic)->ic_debug & IEEE80211_MSG_DUMPPKTS) #define ieee80211_msg_input(_ic) \ ((_ic)->ic_debug & IEEE80211_MSG_INPUT) #define ieee80211_msg_radius(_ic) \ ((_ic)->ic_debug & IEEE80211_MSG_RADIUS) #define ieee80211_msg_dumpradius(_ic) \ ((_ic)->ic_debug & IEEE80211_MSG_RADDUMP) #define ieee80211_msg_dumpradkeys(_ic) \ ((_ic)->ic_debug & IEEE80211_MSG_RADKEYS) #define ieee80211_msg_scan(_ic) \ ((_ic)->ic_debug & IEEE80211_MSG_SCAN) #define ieee80211_msg_assoc(_ic) \ ((_ic)->ic_debug & IEEE80211_MSG_ASSOC) #else #define IEEE80211_DPRINTF(_ic, _m, _fmt, ...) #define IEEE80211_NOTE_FRAME(_ic, _m, _wh, _fmt, ...) #define IEEE80211_NOTE_MAC(_ic, _m, _mac, _fmt, ...) #define ieee80211_msg_dumppkts(_ic) 0 #define ieee80211_msg(_ic, _m) 0 #endif #endif /* _NET80211_IEEE80211_VAR_H_ */