2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 #include "opt_inet6.h"
34 #include <sys/param.h>
35 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/endian.h>
40 #include <sys/socket.h>
43 #include <net/ethernet.h>
45 #include <net/if_llc.h>
46 #include <net/if_media.h>
47 #include <net/if_vlan_var.h>
49 #include <net80211/ieee80211_var.h>
50 #include <net80211/ieee80211_regdomain.h>
51 #ifdef IEEE80211_SUPPORT_SUPERG
52 #include <net80211/ieee80211_superg.h>
54 #ifdef IEEE80211_SUPPORT_TDMA
55 #include <net80211/ieee80211_tdma.h>
57 #include <net80211/ieee80211_wds.h>
58 #include <net80211/ieee80211_mesh.h>
60 #if defined(INET) || defined(INET6)
61 #include <netinet/in.h>
65 #include <netinet/if_ether.h>
66 #include <netinet/in_systm.h>
67 #include <netinet/ip.h>
70 #include <netinet/ip6.h>
73 #include <security/mac/mac_framework.h>
75 #define ETHER_HEADER_COPY(dst, src) \
76 memcpy(dst, src, sizeof(struct ether_header))
78 /* unalligned little endian access */
79 #define LE_WRITE_2(p, v) do { \
80 ((uint8_t *)(p))[0] = (v) & 0xff; \
81 ((uint8_t *)(p))[1] = ((v) >> 8) & 0xff; \
83 #define LE_WRITE_4(p, v) do { \
84 ((uint8_t *)(p))[0] = (v) & 0xff; \
85 ((uint8_t *)(p))[1] = ((v) >> 8) & 0xff; \
86 ((uint8_t *)(p))[2] = ((v) >> 16) & 0xff; \
87 ((uint8_t *)(p))[3] = ((v) >> 24) & 0xff; \
90 static int ieee80211_fragment(struct ieee80211vap *, struct mbuf *,
91 u_int hdrsize, u_int ciphdrsize, u_int mtu);
92 static void ieee80211_tx_mgt_cb(struct ieee80211_node *, void *, int);
94 #ifdef IEEE80211_DEBUG
96 * Decide if an outbound management frame should be
97 * printed when debugging is enabled. This filters some
98 * of the less interesting frames that come frequently
102 doprint(struct ieee80211vap *vap, int subtype)
105 case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
106 return (vap->iv_opmode == IEEE80211_M_IBSS);
113 * Start method for vap's. All packets from the stack come
114 * through here. We handle common processing of the packets
115 * before dispatching them to the underlying device.
118 ieee80211_start(struct ifnet *ifp)
120 #define IS_DWDS(vap) \
121 (vap->iv_opmode == IEEE80211_M_WDS && \
122 (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY) == 0)
123 struct ieee80211vap *vap = ifp->if_softc;
124 struct ieee80211com *ic = vap->iv_ic;
125 struct ifnet *parent = ic->ic_ifp;
126 struct ieee80211_node *ni;
128 struct ether_header *eh;
131 /* NB: parent must be up and running */
132 if (!IFNET_IS_UP_RUNNING(parent)) {
133 IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
134 "%s: ignore queue, parent %s not up+running\n",
135 __func__, parent->if_xname);
139 if (vap->iv_state == IEEE80211_S_SLEEP) {
141 * In power save, wakeup device for transmit.
143 ieee80211_new_state(vap, IEEE80211_S_RUN, 0);
147 * No data frames go out unless we're running.
148 * Note in particular this covers CAC and CSA
149 * states (though maybe we should check muting
152 if (vap->iv_state != IEEE80211_S_RUN) {
154 /* re-check under the com lock to avoid races */
155 if (vap->iv_state != IEEE80211_S_RUN) {
156 IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
157 "%s: ignore queue, in %s state\n",
158 __func__, ieee80211_state_name[vap->iv_state]);
159 vap->iv_stats.is_tx_badstate++;
160 IEEE80211_UNLOCK(ic);
161 IFQ_LOCK(&ifp->if_snd);
162 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
163 IFQ_UNLOCK(&ifp->if_snd);
166 IEEE80211_UNLOCK(ic);
169 IFQ_DEQUEUE(&ifp->if_snd, m);
173 * Sanitize mbuf flags for net80211 use. We cannot
174 * clear M_PWR_SAV or M_MORE_DATA because these may
175 * be set for frames that are re-submitted from the
178 * NB: This must be done before ieee80211_classify as
179 * it marks EAPOL in frames with M_EAPOL.
181 m->m_flags &= ~(M_80211_TX - M_PWR_SAV - M_MORE_DATA);
183 * Cancel any background scan.
185 if (ic->ic_flags & IEEE80211_F_SCAN)
186 ieee80211_cancel_anyscan(vap);
188 * Find the node for the destination so we can do
189 * things like power save and fast frames aggregation.
191 * NB: past this point various code assumes the first
192 * mbuf has the 802.3 header present (and contiguous).
195 if (m->m_len < sizeof(struct ether_header) &&
196 (m = m_pullup(m, sizeof(struct ether_header))) == NULL) {
197 IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
198 "discard frame, %s\n", "m_pullup failed");
199 vap->iv_stats.is_tx_nobuf++; /* XXX */
203 eh = mtod(m, struct ether_header *);
204 if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
207 * Only unicast frames from the above go out
208 * DWDS vaps; multicast frames are handled by
209 * dispatching the frame as it comes through
210 * the AP vap (see below).
212 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_WDS,
213 eh->ether_dhost, "mcast", "%s", "on DWDS");
214 vap->iv_stats.is_dwds_mcast++;
218 if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
220 * Spam DWDS vap's w/ multicast traffic.
222 /* XXX only if dwds in use? */
223 ieee80211_dwds_mcast(vap, m);
226 #ifdef IEEE80211_SUPPORT_MESH
227 if (vap->iv_opmode != IEEE80211_M_MBSS) {
229 ni = ieee80211_find_txnode(vap, eh->ether_dhost);
231 /* NB: ieee80211_find_txnode does stat+msg */
236 if (ni->ni_associd == 0 &&
237 (ni->ni_flags & IEEE80211_NODE_ASSOCID)) {
238 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_OUTPUT,
239 eh->ether_dhost, NULL,
240 "sta not associated (type 0x%04x)",
241 htons(eh->ether_type));
242 vap->iv_stats.is_tx_notassoc++;
245 ieee80211_free_node(ni);
248 #ifdef IEEE80211_SUPPORT_MESH
250 if (!IEEE80211_ADDR_EQ(eh->ether_shost, vap->iv_myaddr)) {
252 * Proxy station only if configured.
254 if (!ieee80211_mesh_isproxyena(vap)) {
255 IEEE80211_DISCARD_MAC(vap,
256 IEEE80211_MSG_OUTPUT |
258 eh->ether_dhost, NULL,
259 "%s", "proxy not enabled");
260 vap->iv_stats.is_mesh_notproxy++;
265 ieee80211_mesh_proxy_check(vap, eh->ether_shost);
267 ni = ieee80211_mesh_discover(vap, eh->ether_dhost, m);
270 * NB: ieee80211_mesh_discover holds/disposes
271 * frame (e.g. queueing on path discovery).
278 if ((ni->ni_flags & IEEE80211_NODE_PWR_MGT) &&
279 (m->m_flags & M_PWR_SAV) == 0) {
281 * Station in power save mode; pass the frame
282 * to the 802.11 layer and continue. We'll get
283 * the frame back when the time is right.
284 * XXX lose WDS vap linkage?
286 (void) ieee80211_pwrsave(ni, m);
287 ieee80211_free_node(ni);
290 /* calculate priority so drivers can find the tx queue */
291 if (ieee80211_classify(ni, m)) {
292 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_OUTPUT,
293 eh->ether_dhost, NULL,
294 "%s", "classification failure");
295 vap->iv_stats.is_tx_classify++;
298 ieee80211_free_node(ni);
302 * Stash the node pointer. Note that we do this after
303 * any call to ieee80211_dwds_mcast because that code
304 * uses any existing value for rcvif to identify the
305 * interface it (might have been) received on.
307 m->m_pkthdr.rcvif = (void *)ni;
309 BPF_MTAP(ifp, m); /* 802.3 tx */
312 * Check if A-MPDU tx aggregation is setup or if we
313 * should try to enable it. The sta must be associated
314 * with HT and A-MPDU enabled for use. When the policy
315 * routine decides we should enable A-MPDU we issue an
316 * ADDBA request and wait for a reply. The frame being
317 * encapsulated will go out w/o using A-MPDU, or possibly
318 * it might be collected by the driver and held/retransmit.
319 * The default ic_ampdu_enable routine handles staggering
320 * ADDBA requests in case the receiver NAK's us or we are
321 * otherwise unable to establish a BA stream.
323 if ((ni->ni_flags & IEEE80211_NODE_AMPDU_TX) &&
324 (vap->iv_flags_ht & IEEE80211_FHT_AMPDU_TX) &&
325 (m->m_flags & M_EAPOL) == 0) {
326 const int ac = M_WME_GETAC(m);
327 struct ieee80211_tx_ampdu *tap = &ni->ni_tx_ampdu[ac];
329 ieee80211_txampdu_count_packet(tap);
330 if (IEEE80211_AMPDU_RUNNING(tap)) {
332 * Operational, mark frame for aggregation.
334 * XXX do tx aggregation here
336 m->m_flags |= M_AMPDU_MPDU;
337 } else if (!IEEE80211_AMPDU_REQUESTED(tap) &&
338 ic->ic_ampdu_enable(ni, tap)) {
340 * Not negotiated yet, request service.
342 ieee80211_ampdu_request(ni, tap);
343 /* XXX hold frame for reply? */
346 #ifdef IEEE80211_SUPPORT_SUPERG
347 else if (IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_FF)) {
348 m = ieee80211_ff_check(ni, m);
350 /* NB: any ni ref held on stageq */
354 #endif /* IEEE80211_SUPPORT_SUPERG */
355 if (__predict_true((vap->iv_caps & IEEE80211_C_8023ENCAP) == 0)) {
357 * Encapsulate the packet in prep for transmission.
359 m = ieee80211_encap(vap, ni, m);
361 /* NB: stat+msg handled in ieee80211_encap */
362 ieee80211_free_node(ni);
367 error = parent->if_transmit(parent, m);
369 /* NB: IFQ_HANDOFF reclaims mbuf */
370 ieee80211_free_node(ni);
374 ic->ic_lastdata = ticks;
380 * 802.11 output routine. This is (currently) used only to
381 * connect bpf write calls to the 802.11 layer for injecting
385 ieee80211_output(struct ifnet *ifp, struct mbuf *m,
386 struct sockaddr *dst, struct route *ro)
388 #define senderr(e) do { error = (e); goto bad;} while (0)
389 struct ieee80211_node *ni = NULL;
390 struct ieee80211vap *vap;
391 struct ieee80211_frame *wh;
394 IFQ_LOCK(&ifp->if_snd);
395 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
396 IFQ_UNLOCK(&ifp->if_snd);
398 * Short-circuit requests if the vap is marked OACTIVE
399 * as this can happen because a packet came down through
400 * ieee80211_start before the vap entered RUN state in
401 * which case it's ok to just drop the frame. This
402 * should not be necessary but callers of if_output don't
407 IFQ_UNLOCK(&ifp->if_snd);
410 * Hand to the 802.3 code if not tagged as
411 * a raw 802.11 frame.
413 if (dst->sa_family != AF_IEEE80211)
414 return vap->iv_output(ifp, m, dst, ro);
416 error = mac_ifnet_check_transmit(ifp, m);
420 if (ifp->if_flags & IFF_MONITOR)
422 if (!IFNET_IS_UP_RUNNING(ifp))
424 if (vap->iv_state == IEEE80211_S_CAC) {
425 IEEE80211_DPRINTF(vap,
426 IEEE80211_MSG_OUTPUT | IEEE80211_MSG_DOTH,
427 "block %s frame in CAC state\n", "raw data");
428 vap->iv_stats.is_tx_badstate++;
429 senderr(EIO); /* XXX */
430 } else if (vap->iv_state == IEEE80211_S_SCAN)
432 /* XXX bypass bridge, pfil, carp, etc. */
434 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame_ack))
435 senderr(EIO); /* XXX */
436 wh = mtod(m, struct ieee80211_frame *);
437 if ((wh->i_fc[0] & IEEE80211_FC0_VERSION_MASK) !=
438 IEEE80211_FC0_VERSION_0)
439 senderr(EIO); /* XXX */
441 /* locate destination node */
442 switch (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) {
443 case IEEE80211_FC1_DIR_NODS:
444 case IEEE80211_FC1_DIR_FROMDS:
445 ni = ieee80211_find_txnode(vap, wh->i_addr1);
447 case IEEE80211_FC1_DIR_TODS:
448 case IEEE80211_FC1_DIR_DSTODS:
449 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame))
450 senderr(EIO); /* XXX */
451 ni = ieee80211_find_txnode(vap, wh->i_addr3);
454 senderr(EIO); /* XXX */
458 * Permit packets w/ bpf params through regardless
459 * (see below about sa_len).
461 if (dst->sa_len == 0)
462 senderr(EHOSTUNREACH);
463 ni = ieee80211_ref_node(vap->iv_bss);
467 * Sanitize mbuf for net80211 flags leaked from above.
469 * NB: This must be done before ieee80211_classify as
470 * it marks EAPOL in frames with M_EAPOL.
472 m->m_flags &= ~M_80211_TX;
474 /* calculate priority so drivers can find the tx queue */
475 /* XXX assumes an 802.3 frame */
476 if (ieee80211_classify(ni, m))
477 senderr(EIO); /* XXX */
480 IEEE80211_NODE_STAT(ni, tx_data);
481 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
482 IEEE80211_NODE_STAT(ni, tx_mcast);
483 m->m_flags |= M_MCAST;
485 IEEE80211_NODE_STAT(ni, tx_ucast);
486 /* NB: ieee80211_encap does not include 802.11 header */
487 IEEE80211_NODE_STAT_ADD(ni, tx_bytes, m->m_pkthdr.len);
490 * NB: DLT_IEEE802_11_RADIO identifies the parameters are
491 * present by setting the sa_len field of the sockaddr (yes,
493 * NB: we assume sa_data is suitably aligned to cast.
495 return vap->iv_ic->ic_raw_xmit(ni, m,
496 (const struct ieee80211_bpf_params *)(dst->sa_len ?
497 dst->sa_data : NULL));
502 ieee80211_free_node(ni);
509 * Set the direction field and address fields of an outgoing
510 * frame. Note this should be called early on in constructing
511 * a frame as it sets i_fc[1]; other bits can then be or'd in.
514 ieee80211_send_setup(
515 struct ieee80211_node *ni,
518 const uint8_t sa[IEEE80211_ADDR_LEN],
519 const uint8_t da[IEEE80211_ADDR_LEN],
520 const uint8_t bssid[IEEE80211_ADDR_LEN])
522 #define WH4(wh) ((struct ieee80211_frame_addr4 *)wh)
523 struct ieee80211vap *vap = ni->ni_vap;
524 struct ieee80211_tx_ampdu *tap;
525 struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
528 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | type;
529 if ((type & IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_DATA) {
530 switch (vap->iv_opmode) {
531 case IEEE80211_M_STA:
532 wh->i_fc[1] = IEEE80211_FC1_DIR_TODS;
533 IEEE80211_ADDR_COPY(wh->i_addr1, bssid);
534 IEEE80211_ADDR_COPY(wh->i_addr2, sa);
535 IEEE80211_ADDR_COPY(wh->i_addr3, da);
537 case IEEE80211_M_IBSS:
538 case IEEE80211_M_AHDEMO:
539 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
540 IEEE80211_ADDR_COPY(wh->i_addr1, da);
541 IEEE80211_ADDR_COPY(wh->i_addr2, sa);
542 IEEE80211_ADDR_COPY(wh->i_addr3, bssid);
544 case IEEE80211_M_HOSTAP:
545 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
546 IEEE80211_ADDR_COPY(wh->i_addr1, da);
547 IEEE80211_ADDR_COPY(wh->i_addr2, bssid);
548 IEEE80211_ADDR_COPY(wh->i_addr3, sa);
550 case IEEE80211_M_WDS:
551 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
552 IEEE80211_ADDR_COPY(wh->i_addr1, da);
553 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
554 IEEE80211_ADDR_COPY(wh->i_addr3, da);
555 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, sa);
557 case IEEE80211_M_MBSS:
558 #ifdef IEEE80211_SUPPORT_MESH
559 /* XXX add support for proxied addresses */
560 if (IEEE80211_IS_MULTICAST(da)) {
561 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
563 IEEE80211_ADDR_COPY(wh->i_addr1, da);
564 IEEE80211_ADDR_COPY(wh->i_addr2,
567 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
568 IEEE80211_ADDR_COPY(wh->i_addr1, da);
569 IEEE80211_ADDR_COPY(wh->i_addr2,
571 IEEE80211_ADDR_COPY(wh->i_addr3, da);
572 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, sa);
576 case IEEE80211_M_MONITOR: /* NB: to quiet compiler */
580 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
581 IEEE80211_ADDR_COPY(wh->i_addr1, da);
582 IEEE80211_ADDR_COPY(wh->i_addr2, sa);
583 #ifdef IEEE80211_SUPPORT_MESH
584 if (vap->iv_opmode == IEEE80211_M_MBSS)
585 IEEE80211_ADDR_COPY(wh->i_addr3, sa);
588 IEEE80211_ADDR_COPY(wh->i_addr3, bssid);
590 *(uint16_t *)&wh->i_dur[0] = 0;
592 tap = &ni->ni_tx_ampdu[TID_TO_WME_AC(tid)];
593 if (tid != IEEE80211_NONQOS_TID && IEEE80211_AMPDU_RUNNING(tap))
594 m->m_flags |= M_AMPDU_MPDU;
596 seqno = ni->ni_txseqs[tid]++;
597 *(uint16_t *)&wh->i_seq[0] =
598 htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT);
599 M_SEQNO_SET(m, seqno);
602 if (IEEE80211_IS_MULTICAST(wh->i_addr1))
603 m->m_flags |= M_MCAST;
608 * Send a management frame to the specified node. The node pointer
609 * must have a reference as the pointer will be passed to the driver
610 * and potentially held for a long time. If the frame is successfully
611 * dispatched to the driver, then it is responsible for freeing the
612 * reference (and potentially free'ing up any associated storage);
613 * otherwise deal with reclaiming any reference (on error).
616 ieee80211_mgmt_output(struct ieee80211_node *ni, struct mbuf *m, int type,
617 struct ieee80211_bpf_params *params)
619 struct ieee80211vap *vap = ni->ni_vap;
620 struct ieee80211com *ic = ni->ni_ic;
621 struct ieee80211_frame *wh;
623 KASSERT(ni != NULL, ("null node"));
625 if (vap->iv_state == IEEE80211_S_CAC) {
626 IEEE80211_NOTE(vap, IEEE80211_MSG_OUTPUT | IEEE80211_MSG_DOTH,
627 ni, "block %s frame in CAC state",
628 ieee80211_mgt_subtype_name[
629 (type & IEEE80211_FC0_SUBTYPE_MASK) >>
630 IEEE80211_FC0_SUBTYPE_SHIFT]);
631 vap->iv_stats.is_tx_badstate++;
632 ieee80211_free_node(ni);
634 return EIO; /* XXX */
637 M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT);
639 ieee80211_free_node(ni);
643 wh = mtod(m, struct ieee80211_frame *);
644 ieee80211_send_setup(ni, m,
645 IEEE80211_FC0_TYPE_MGT | type, IEEE80211_NONQOS_TID,
646 vap->iv_myaddr, ni->ni_macaddr, ni->ni_bssid);
647 if (params->ibp_flags & IEEE80211_BPF_CRYPTO) {
648 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_AUTH, wh->i_addr1,
649 "encrypting frame (%s)", __func__);
650 wh->i_fc[1] |= IEEE80211_FC1_WEP;
652 m->m_flags |= M_ENCAP; /* mark encapsulated */
654 KASSERT(type != IEEE80211_FC0_SUBTYPE_PROBE_RESP, ("probe response?"));
655 M_WME_SETAC(m, params->ibp_pri);
657 #ifdef IEEE80211_DEBUG
658 /* avoid printing too many frames */
659 if ((ieee80211_msg_debug(vap) && doprint(vap, type)) ||
660 ieee80211_msg_dumppkts(vap)) {
661 printf("[%s] send %s on channel %u\n",
662 ether_sprintf(wh->i_addr1),
663 ieee80211_mgt_subtype_name[
664 (type & IEEE80211_FC0_SUBTYPE_MASK) >>
665 IEEE80211_FC0_SUBTYPE_SHIFT],
666 ieee80211_chan2ieee(ic, ic->ic_curchan));
669 IEEE80211_NODE_STAT(ni, tx_mgmt);
671 return ic->ic_raw_xmit(ni, m, params);
675 * Send a null data frame to the specified node. If the station
676 * is setup for QoS then a QoS Null Data frame is constructed.
677 * If this is a WDS station then a 4-address frame is constructed.
679 * NB: the caller is assumed to have setup a node reference
680 * for use; this is necessary to deal with a race condition
681 * when probing for inactive stations. Like ieee80211_mgmt_output
682 * we must cleanup any node reference on error; however we
683 * can safely just unref it as we know it will never be the
684 * last reference to the node.
687 ieee80211_send_nulldata(struct ieee80211_node *ni)
689 struct ieee80211vap *vap = ni->ni_vap;
690 struct ieee80211com *ic = ni->ni_ic;
692 struct ieee80211_frame *wh;
696 if (vap->iv_state == IEEE80211_S_CAC) {
697 IEEE80211_NOTE(vap, IEEE80211_MSG_OUTPUT | IEEE80211_MSG_DOTH,
698 ni, "block %s frame in CAC state", "null data");
699 ieee80211_unref_node(&ni);
700 vap->iv_stats.is_tx_badstate++;
701 return EIO; /* XXX */
704 if (ni->ni_flags & (IEEE80211_NODE_QOS|IEEE80211_NODE_HT))
705 hdrlen = sizeof(struct ieee80211_qosframe);
707 hdrlen = sizeof(struct ieee80211_frame);
708 /* NB: only WDS vap's get 4-address frames */
709 if (vap->iv_opmode == IEEE80211_M_WDS)
710 hdrlen += IEEE80211_ADDR_LEN;
711 if (ic->ic_flags & IEEE80211_F_DATAPAD)
712 hdrlen = roundup(hdrlen, sizeof(uint32_t));
714 m = ieee80211_getmgtframe(&frm, ic->ic_headroom + hdrlen, 0);
717 ieee80211_unref_node(&ni);
718 vap->iv_stats.is_tx_nobuf++;
721 KASSERT(M_LEADINGSPACE(m) >= hdrlen,
722 ("leading space %zd", M_LEADINGSPACE(m)));
723 M_PREPEND(m, hdrlen, M_DONTWAIT);
725 /* NB: cannot happen */
726 ieee80211_free_node(ni);
730 wh = mtod(m, struct ieee80211_frame *); /* NB: a little lie */
731 if (ni->ni_flags & IEEE80211_NODE_QOS) {
732 const int tid = WME_AC_TO_TID(WME_AC_BE);
735 ieee80211_send_setup(ni, m,
736 IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS_NULL,
737 tid, vap->iv_myaddr, ni->ni_macaddr, ni->ni_bssid);
739 if (vap->iv_opmode == IEEE80211_M_WDS)
740 qos = ((struct ieee80211_qosframe_addr4 *) wh)->i_qos;
742 qos = ((struct ieee80211_qosframe *) wh)->i_qos;
743 qos[0] = tid & IEEE80211_QOS_TID;
744 if (ic->ic_wme.wme_wmeChanParams.cap_wmeParams[WME_AC_BE].wmep_noackPolicy)
745 qos[0] |= IEEE80211_QOS_ACKPOLICY_NOACK;
748 ieee80211_send_setup(ni, m,
749 IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_NODATA,
750 IEEE80211_NONQOS_TID,
751 vap->iv_myaddr, ni->ni_macaddr, ni->ni_bssid);
753 if (vap->iv_opmode != IEEE80211_M_WDS) {
754 /* NB: power management bit is never sent by an AP */
755 if ((ni->ni_flags & IEEE80211_NODE_PWR_MGT) &&
756 vap->iv_opmode != IEEE80211_M_HOSTAP)
757 wh->i_fc[1] |= IEEE80211_FC1_PWR_MGT;
759 m->m_len = m->m_pkthdr.len = hdrlen;
760 m->m_flags |= M_ENCAP; /* mark encapsulated */
762 M_WME_SETAC(m, WME_AC_BE);
764 IEEE80211_NODE_STAT(ni, tx_data);
766 IEEE80211_NOTE(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_DUMPPKTS, ni,
767 "send %snull data frame on channel %u, pwr mgt %s",
768 ni->ni_flags & IEEE80211_NODE_QOS ? "QoS " : "",
769 ieee80211_chan2ieee(ic, ic->ic_curchan),
770 wh->i_fc[1] & IEEE80211_FC1_PWR_MGT ? "ena" : "dis");
772 return ic->ic_raw_xmit(ni, m, NULL);
776 * Assign priority to a frame based on any vlan tag assigned
777 * to the station and/or any Diffserv setting in an IP header.
778 * Finally, if an ACM policy is setup (in station mode) it's
782 ieee80211_classify(struct ieee80211_node *ni, struct mbuf *m)
784 const struct ether_header *eh = mtod(m, struct ether_header *);
785 int v_wme_ac, d_wme_ac, ac;
788 * Always promote PAE/EAPOL frames to high priority.
790 if (eh->ether_type == htons(ETHERTYPE_PAE)) {
791 /* NB: mark so others don't need to check header */
792 m->m_flags |= M_EAPOL;
797 * Non-qos traffic goes to BE.
799 if ((ni->ni_flags & IEEE80211_NODE_QOS) == 0) {
805 * If node has a vlan tag then all traffic
806 * to it must have a matching tag.
809 if (ni->ni_vlan != 0) {
810 if ((m->m_flags & M_VLANTAG) == 0) {
811 IEEE80211_NODE_STAT(ni, tx_novlantag);
814 if (EVL_VLANOFTAG(m->m_pkthdr.ether_vtag) !=
815 EVL_VLANOFTAG(ni->ni_vlan)) {
816 IEEE80211_NODE_STAT(ni, tx_vlanmismatch);
819 /* map vlan priority to AC */
820 v_wme_ac = TID_TO_WME_AC(EVL_PRIOFTAG(ni->ni_vlan));
823 /* XXX m_copydata may be too slow for fast path */
825 if (eh->ether_type == htons(ETHERTYPE_IP)) {
828 * IP frame, map the DSCP bits from the TOS field.
830 /* NB: ip header may not be in first mbuf */
831 m_copydata(m, sizeof(struct ether_header) +
832 offsetof(struct ip, ip_tos), sizeof(tos), &tos);
833 tos >>= 5; /* NB: ECN + low 3 bits of DSCP */
834 d_wme_ac = TID_TO_WME_AC(tos);
838 if (eh->ether_type == htons(ETHERTYPE_IPV6)) {
842 * IPv6 frame, map the DSCP bits from the traffic class field.
844 m_copydata(m, sizeof(struct ether_header) +
845 offsetof(struct ip6_hdr, ip6_flow), sizeof(flow),
847 tos = (uint8_t)(ntohl(flow) >> 20);
848 tos >>= 5; /* NB: ECN + low 3 bits of DSCP */
849 d_wme_ac = TID_TO_WME_AC(tos);
852 d_wme_ac = WME_AC_BE;
860 * Use highest priority AC.
862 if (v_wme_ac > d_wme_ac)
870 if (ni->ni_vap->iv_opmode == IEEE80211_M_STA) {
871 static const int acmap[4] = {
872 WME_AC_BK, /* WME_AC_BE */
873 WME_AC_BK, /* WME_AC_BK */
874 WME_AC_BE, /* WME_AC_VI */
875 WME_AC_VI, /* WME_AC_VO */
877 struct ieee80211com *ic = ni->ni_ic;
879 while (ac != WME_AC_BK &&
880 ic->ic_wme.wme_wmeBssChanParams.cap_wmeParams[ac].wmep_acm)
889 * Insure there is sufficient contiguous space to encapsulate the
890 * 802.11 data frame. If room isn't already there, arrange for it.
891 * Drivers and cipher modules assume we have done the necessary work
892 * and fail rudely if they don't find the space they need.
895 ieee80211_mbuf_adjust(struct ieee80211vap *vap, int hdrsize,
896 struct ieee80211_key *key, struct mbuf *m)
898 #define TO_BE_RECLAIMED (sizeof(struct ether_header) - sizeof(struct llc))
899 int needed_space = vap->iv_ic->ic_headroom + hdrsize;
902 /* XXX belongs in crypto code? */
903 needed_space += key->wk_cipher->ic_header;
906 * When crypto is being done in the host we must insure
907 * the data are writable for the cipher routines; clone
908 * a writable mbuf chain.
909 * XXX handle SWMIC specially
911 if (key->wk_flags & (IEEE80211_KEY_SWENCRYPT|IEEE80211_KEY_SWENMIC)) {
912 m = m_unshare(m, M_NOWAIT);
914 IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
915 "%s: cannot get writable mbuf\n", __func__);
916 vap->iv_stats.is_tx_nobuf++; /* XXX new stat */
922 * We know we are called just before stripping an Ethernet
923 * header and prepending an LLC header. This means we know
925 * sizeof(struct ether_header) - sizeof(struct llc)
926 * bytes recovered to which we need additional space for the
927 * 802.11 header and any crypto header.
929 /* XXX check trailing space and copy instead? */
930 if (M_LEADINGSPACE(m) < needed_space - TO_BE_RECLAIMED) {
931 struct mbuf *n = m_gethdr(M_NOWAIT, m->m_type);
933 IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
934 "%s: cannot expand storage\n", __func__);
935 vap->iv_stats.is_tx_nobuf++;
939 KASSERT(needed_space <= MHLEN,
940 ("not enough room, need %u got %zu\n", needed_space, MHLEN));
942 * Setup new mbuf to have leading space to prepend the
943 * 802.11 header and any crypto header bits that are
944 * required (the latter are added when the driver calls
945 * back to ieee80211_crypto_encap to do crypto encapsulation).
947 /* NB: must be first 'cuz it clobbers m_data */
949 n->m_len = 0; /* NB: m_gethdr does not set */
950 n->m_data += needed_space;
952 * Pull up Ethernet header to create the expected layout.
953 * We could use m_pullup but that's overkill (i.e. we don't
954 * need the actual data) and it cannot fail so do it inline
957 /* NB: struct ether_header is known to be contiguous */
958 n->m_len += sizeof(struct ether_header);
959 m->m_len -= sizeof(struct ether_header);
960 m->m_data += sizeof(struct ether_header);
962 * Replace the head of the chain.
968 #undef TO_BE_RECLAIMED
972 * Return the transmit key to use in sending a unicast frame.
973 * If a unicast key is set we use that. When no unicast key is set
974 * we fall back to the default transmit key.
976 static __inline struct ieee80211_key *
977 ieee80211_crypto_getucastkey(struct ieee80211vap *vap,
978 struct ieee80211_node *ni)
980 if (IEEE80211_KEY_UNDEFINED(&ni->ni_ucastkey)) {
981 if (vap->iv_def_txkey == IEEE80211_KEYIX_NONE ||
982 IEEE80211_KEY_UNDEFINED(&vap->iv_nw_keys[vap->iv_def_txkey]))
984 return &vap->iv_nw_keys[vap->iv_def_txkey];
986 return &ni->ni_ucastkey;
991 * Return the transmit key to use in sending a multicast frame.
992 * Multicast traffic always uses the group key which is installed as
993 * the default tx key.
995 static __inline struct ieee80211_key *
996 ieee80211_crypto_getmcastkey(struct ieee80211vap *vap,
997 struct ieee80211_node *ni)
999 if (vap->iv_def_txkey == IEEE80211_KEYIX_NONE ||
1000 IEEE80211_KEY_UNDEFINED(&vap->iv_nw_keys[vap->iv_def_txkey]))
1002 return &vap->iv_nw_keys[vap->iv_def_txkey];
1006 * Encapsulate an outbound data frame. The mbuf chain is updated.
1007 * If an error is encountered NULL is returned. The caller is required
1008 * to provide a node reference and pullup the ethernet header in the
1011 * NB: Packet is assumed to be processed by ieee80211_classify which
1012 * marked EAPOL frames w/ M_EAPOL.
1015 ieee80211_encap(struct ieee80211vap *vap, struct ieee80211_node *ni,
1018 #define WH4(wh) ((struct ieee80211_frame_addr4 *)(wh))
1019 struct ieee80211com *ic = ni->ni_ic;
1020 #ifdef IEEE80211_SUPPORT_MESH
1021 struct ieee80211_mesh_state *ms = vap->iv_mesh;
1022 struct ieee80211_meshcntl_ae10 *mc;
1024 struct ether_header eh;
1025 struct ieee80211_frame *wh;
1026 struct ieee80211_key *key;
1028 int hdrsize, hdrspace, datalen, addqos, txfrag, is4addr;
1029 ieee80211_seq seqno;
1030 int meshhdrsize, meshae;
1034 * Copy existing Ethernet header to a safe place. The
1035 * rest of the code assumes it's ok to strip it when
1036 * reorganizing state for the final encapsulation.
1038 KASSERT(m->m_len >= sizeof(eh), ("no ethernet header!"));
1039 ETHER_HEADER_COPY(&eh, mtod(m, caddr_t));
1042 * Insure space for additional headers. First identify
1043 * transmit key to use in calculating any buffer adjustments
1044 * required. This is also used below to do privacy
1045 * encapsulation work. Then calculate the 802.11 header
1046 * size and any padding required by the driver.
1048 * Note key may be NULL if we fall back to the default
1049 * transmit key and that is not set. In that case the
1050 * buffer may not be expanded as needed by the cipher
1051 * routines, but they will/should discard it.
1053 if (vap->iv_flags & IEEE80211_F_PRIVACY) {
1054 if (vap->iv_opmode == IEEE80211_M_STA ||
1055 !IEEE80211_IS_MULTICAST(eh.ether_dhost) ||
1056 (vap->iv_opmode == IEEE80211_M_WDS &&
1057 (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY)))
1058 key = ieee80211_crypto_getucastkey(vap, ni);
1060 key = ieee80211_crypto_getmcastkey(vap, ni);
1061 if (key == NULL && (m->m_flags & M_EAPOL) == 0) {
1062 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO,
1064 "no default transmit key (%s) deftxkey %u",
1065 __func__, vap->iv_def_txkey);
1066 vap->iv_stats.is_tx_nodefkey++;
1072 * XXX Some ap's don't handle QoS-encapsulated EAPOL
1073 * frames so suppress use. This may be an issue if other
1074 * ap's require all data frames to be QoS-encapsulated
1075 * once negotiated in which case we'll need to make this
1077 * NB: mesh data frames are QoS.
1079 addqos = ((ni->ni_flags & (IEEE80211_NODE_QOS|IEEE80211_NODE_HT)) ||
1080 (vap->iv_opmode == IEEE80211_M_MBSS)) &&
1081 (m->m_flags & M_EAPOL) == 0;
1083 hdrsize = sizeof(struct ieee80211_qosframe);
1085 hdrsize = sizeof(struct ieee80211_frame);
1086 #ifdef IEEE80211_SUPPORT_MESH
1087 if (vap->iv_opmode == IEEE80211_M_MBSS) {
1089 * Mesh data frames are encapsulated according to the
1090 * rules of Section 11B.8.5 (p.139 of D3.0 spec).
1091 * o Group Addressed data (aka multicast) originating
1092 * at the local sta are sent w/ 3-address format and
1093 * address extension mode 00
1094 * o Individually Addressed data (aka unicast) originating
1095 * at the local sta are sent w/ 4-address format and
1096 * address extension mode 00
1097 * o Group Addressed data forwarded from a non-mesh sta are
1098 * sent w/ 3-address format and address extension mode 01
1099 * o Individually Address data from another sta are sent
1100 * w/ 4-address format and address extension mode 10
1102 is4addr = 0; /* NB: don't use, disable */
1103 if (!IEEE80211_IS_MULTICAST(eh.ether_dhost))
1104 hdrsize += IEEE80211_ADDR_LEN; /* unicast are 4-addr */
1105 meshhdrsize = sizeof(struct ieee80211_meshcntl);
1106 /* XXX defines for AE modes */
1107 if (IEEE80211_ADDR_EQ(eh.ether_shost, vap->iv_myaddr)) {
1108 if (!IEEE80211_IS_MULTICAST(eh.ether_dhost))
1111 meshae = 4; /* NB: pseudo */
1112 } else if (IEEE80211_IS_MULTICAST(eh.ether_dhost)) {
1114 meshhdrsize += 1*IEEE80211_ADDR_LEN;
1117 meshhdrsize += 2*IEEE80211_ADDR_LEN;
1122 * 4-address frames need to be generated for:
1123 * o packets sent through a WDS vap (IEEE80211_M_WDS)
1124 * o packets sent through a vap marked for relaying
1125 * (e.g. a station operating with dynamic WDS)
1127 is4addr = vap->iv_opmode == IEEE80211_M_WDS ||
1128 ((vap->iv_flags_ext & IEEE80211_FEXT_4ADDR) &&
1129 !IEEE80211_ADDR_EQ(eh.ether_shost, vap->iv_myaddr));
1131 hdrsize += IEEE80211_ADDR_LEN;
1132 meshhdrsize = meshae = 0;
1133 #ifdef IEEE80211_SUPPORT_MESH
1137 * Honor driver DATAPAD requirement.
1139 if (ic->ic_flags & IEEE80211_F_DATAPAD)
1140 hdrspace = roundup(hdrsize, sizeof(uint32_t));
1144 if (__predict_true((m->m_flags & M_FF) == 0)) {
1148 m = ieee80211_mbuf_adjust(vap, hdrspace + meshhdrsize, key, m);
1150 /* NB: ieee80211_mbuf_adjust handles msgs+statistics */
1153 /* NB: this could be optimized 'cuz of ieee80211_mbuf_adjust */
1154 m_adj(m, sizeof(struct ether_header) - sizeof(struct llc));
1155 llc = mtod(m, struct llc *);
1156 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
1157 llc->llc_control = LLC_UI;
1158 llc->llc_snap.org_code[0] = 0;
1159 llc->llc_snap.org_code[1] = 0;
1160 llc->llc_snap.org_code[2] = 0;
1161 llc->llc_snap.ether_type = eh.ether_type;
1163 #ifdef IEEE80211_SUPPORT_SUPERG
1167 m = ieee80211_ff_encap(vap, m, hdrspace + meshhdrsize, key);
1172 datalen = m->m_pkthdr.len; /* NB: w/o 802.11 header */
1174 M_PREPEND(m, hdrspace + meshhdrsize, M_DONTWAIT);
1176 vap->iv_stats.is_tx_nobuf++;
1179 wh = mtod(m, struct ieee80211_frame *);
1180 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_DATA;
1181 *(uint16_t *)wh->i_dur = 0;
1182 qos = NULL; /* NB: quiet compiler */
1184 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
1185 IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr);
1186 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1187 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
1188 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, eh.ether_shost);
1189 } else switch (vap->iv_opmode) {
1190 case IEEE80211_M_STA:
1191 wh->i_fc[1] = IEEE80211_FC1_DIR_TODS;
1192 IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_bssid);
1193 IEEE80211_ADDR_COPY(wh->i_addr2, eh.ether_shost);
1194 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
1196 case IEEE80211_M_IBSS:
1197 case IEEE80211_M_AHDEMO:
1198 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
1199 IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost);
1200 IEEE80211_ADDR_COPY(wh->i_addr2, eh.ether_shost);
1202 * NB: always use the bssid from iv_bss as the
1203 * neighbor's may be stale after an ibss merge
1205 IEEE80211_ADDR_COPY(wh->i_addr3, vap->iv_bss->ni_bssid);
1207 case IEEE80211_M_HOSTAP:
1208 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
1209 IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost);
1210 IEEE80211_ADDR_COPY(wh->i_addr2, ni->ni_bssid);
1211 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_shost);
1213 #ifdef IEEE80211_SUPPORT_MESH
1214 case IEEE80211_M_MBSS:
1215 /* NB: offset by hdrspace to deal with DATAPAD */
1216 mc = (struct ieee80211_meshcntl_ae10 *)
1217 (mtod(m, uint8_t *) + hdrspace);
1219 case 0: /* ucast, no proxy */
1220 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
1221 IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr);
1222 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1223 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
1224 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, eh.ether_shost);
1226 qos = ((struct ieee80211_qosframe_addr4 *) wh)->i_qos;
1228 case 4: /* mcast, no proxy */
1229 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
1230 IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost);
1231 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1232 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_shost);
1233 mc->mc_flags = 0; /* NB: AE is really 0 */
1234 qos = ((struct ieee80211_qosframe *) wh)->i_qos;
1236 case 1: /* mcast, proxy */
1237 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
1238 IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost);
1239 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1240 IEEE80211_ADDR_COPY(wh->i_addr3, vap->iv_myaddr);
1242 IEEE80211_ADDR_COPY(mc->mc_addr4, eh.ether_shost);
1243 qos = ((struct ieee80211_qosframe *) wh)->i_qos;
1245 case 2: /* ucast, proxy */
1246 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
1247 IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr);
1248 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1249 /* XXX not right, need MeshDA */
1250 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
1251 /* XXX assume are MeshSA */
1252 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, vap->iv_myaddr);
1254 IEEE80211_ADDR_COPY(mc->mc_addr4, eh.ether_dhost);
1255 IEEE80211_ADDR_COPY(mc->mc_addr5, eh.ether_shost);
1256 qos = ((struct ieee80211_qosframe_addr4 *) wh)->i_qos;
1259 KASSERT(0, ("meshae %d", meshae));
1262 mc->mc_ttl = ms->ms_ttl;
1264 LE_WRITE_4(mc->mc_seq, ms->ms_seq);
1267 case IEEE80211_M_WDS: /* NB: is4addr should always be true */
1271 if (m->m_flags & M_MORE_DATA)
1272 wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA;
1277 qos = ((struct ieee80211_qosframe_addr4 *) wh)->i_qos;
1278 /* NB: mesh case handled earlier */
1279 } else if (vap->iv_opmode != IEEE80211_M_MBSS)
1280 qos = ((struct ieee80211_qosframe *) wh)->i_qos;
1281 ac = M_WME_GETAC(m);
1282 /* map from access class/queue to 11e header priorty value */
1283 tid = WME_AC_TO_TID(ac);
1284 qos[0] = tid & IEEE80211_QOS_TID;
1285 if (ic->ic_wme.wme_wmeChanParams.cap_wmeParams[ac].wmep_noackPolicy)
1286 qos[0] |= IEEE80211_QOS_ACKPOLICY_NOACK;
1287 #ifdef IEEE80211_SUPPORT_MESH
1288 if (vap->iv_opmode == IEEE80211_M_MBSS) {
1289 qos[1] |= IEEE80211_QOS_MC;
1293 wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_QOS;
1295 if ((m->m_flags & M_AMPDU_MPDU) == 0) {
1297 * NB: don't assign a sequence # to potential
1298 * aggregates; we expect this happens at the
1299 * point the frame comes off any aggregation q
1300 * as otherwise we may introduce holes in the
1301 * BA sequence space and/or make window accouting
1304 * XXX may want to control this with a driver
1305 * capability; this may also change when we pull
1306 * aggregation up into net80211
1308 seqno = ni->ni_txseqs[tid]++;
1309 *(uint16_t *)wh->i_seq =
1310 htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT);
1311 M_SEQNO_SET(m, seqno);
1314 seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]++;
1315 *(uint16_t *)wh->i_seq =
1316 htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT);
1317 M_SEQNO_SET(m, seqno);
1321 /* check if xmit fragmentation is required */
1322 txfrag = (m->m_pkthdr.len > vap->iv_fragthreshold &&
1323 !IEEE80211_IS_MULTICAST(wh->i_addr1) &&
1324 (vap->iv_caps & IEEE80211_C_TXFRAG) &&
1325 (m->m_flags & (M_FF | M_AMPDU_MPDU)) == 0);
1328 * IEEE 802.1X: send EAPOL frames always in the clear.
1329 * WPA/WPA2: encrypt EAPOL keys when pairwise keys are set.
1331 if ((m->m_flags & M_EAPOL) == 0 ||
1332 ((vap->iv_flags & IEEE80211_F_WPA) &&
1333 (vap->iv_opmode == IEEE80211_M_STA ?
1334 !IEEE80211_KEY_UNDEFINED(key) :
1335 !IEEE80211_KEY_UNDEFINED(&ni->ni_ucastkey)))) {
1336 wh->i_fc[1] |= IEEE80211_FC1_WEP;
1337 if (!ieee80211_crypto_enmic(vap, key, m, txfrag)) {
1338 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_OUTPUT,
1340 "%s", "enmic failed, discard frame");
1341 vap->iv_stats.is_crypto_enmicfail++;
1346 if (txfrag && !ieee80211_fragment(vap, m, hdrsize,
1347 key != NULL ? key->wk_cipher->ic_header : 0, vap->iv_fragthreshold))
1350 m->m_flags |= M_ENCAP; /* mark encapsulated */
1352 IEEE80211_NODE_STAT(ni, tx_data);
1353 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
1354 IEEE80211_NODE_STAT(ni, tx_mcast);
1355 m->m_flags |= M_MCAST;
1357 IEEE80211_NODE_STAT(ni, tx_ucast);
1358 IEEE80211_NODE_STAT_ADD(ni, tx_bytes, datalen);
1369 * Fragment the frame according to the specified mtu.
1370 * The size of the 802.11 header (w/o padding) is provided
1371 * so we don't need to recalculate it. We create a new
1372 * mbuf for each fragment and chain it through m_nextpkt;
1373 * we might be able to optimize this by reusing the original
1374 * packet's mbufs but that is significantly more complicated.
1377 ieee80211_fragment(struct ieee80211vap *vap, struct mbuf *m0,
1378 u_int hdrsize, u_int ciphdrsize, u_int mtu)
1380 struct ieee80211_frame *wh, *whf;
1381 struct mbuf *m, *prev, *next;
1382 u_int totalhdrsize, fragno, fragsize, off, remainder, payload;
1384 KASSERT(m0->m_nextpkt == NULL, ("mbuf already chained?"));
1385 KASSERT(m0->m_pkthdr.len > mtu,
1386 ("pktlen %u mtu %u", m0->m_pkthdr.len, mtu));
1388 wh = mtod(m0, struct ieee80211_frame *);
1389 /* NB: mark the first frag; it will be propagated below */
1390 wh->i_fc[1] |= IEEE80211_FC1_MORE_FRAG;
1391 totalhdrsize = hdrsize + ciphdrsize;
1393 off = mtu - ciphdrsize;
1394 remainder = m0->m_pkthdr.len - off;
1397 fragsize = totalhdrsize + remainder;
1400 /* XXX fragsize can be >2048! */
1401 KASSERT(fragsize < MCLBYTES,
1402 ("fragment size %u too big!", fragsize));
1403 if (fragsize > MHLEN)
1404 m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
1406 m = m_gethdr(M_DONTWAIT, MT_DATA);
1409 /* leave room to prepend any cipher header */
1410 m_align(m, fragsize - ciphdrsize);
1413 * Form the header in the fragment. Note that since
1414 * we mark the first fragment with the MORE_FRAG bit
1415 * it automatically is propagated to each fragment; we
1416 * need only clear it on the last fragment (done below).
1417 * NB: frag 1+ dont have Mesh Control field present.
1419 whf = mtod(m, struct ieee80211_frame *);
1420 memcpy(whf, wh, hdrsize);
1421 #ifdef IEEE80211_SUPPORT_MESH
1422 if (vap->iv_opmode == IEEE80211_M_MBSS) {
1423 if (IEEE80211_IS_DSTODS(wh))
1424 ((struct ieee80211_qosframe_addr4 *)
1425 whf)->i_qos[1] &= ~IEEE80211_QOS_MC;
1427 ((struct ieee80211_qosframe *)
1428 whf)->i_qos[1] &= ~IEEE80211_QOS_MC;
1431 *(uint16_t *)&whf->i_seq[0] |= htole16(
1432 (fragno & IEEE80211_SEQ_FRAG_MASK) <<
1433 IEEE80211_SEQ_FRAG_SHIFT);
1436 payload = fragsize - totalhdrsize;
1437 /* NB: destination is known to be contiguous */
1438 m_copydata(m0, off, payload, mtod(m, uint8_t *) + hdrsize);
1439 m->m_len = hdrsize + payload;
1440 m->m_pkthdr.len = hdrsize + payload;
1441 m->m_flags |= M_FRAG;
1443 /* chain up the fragment */
1444 prev->m_nextpkt = m;
1447 /* deduct fragment just formed */
1448 remainder -= payload;
1450 } while (remainder != 0);
1452 /* set the last fragment */
1453 m->m_flags |= M_LASTFRAG;
1454 whf->i_fc[1] &= ~IEEE80211_FC1_MORE_FRAG;
1456 /* strip first mbuf now that everything has been copied */
1457 m_adj(m0, -(m0->m_pkthdr.len - (mtu - ciphdrsize)));
1458 m0->m_flags |= M_FIRSTFRAG | M_FRAG;
1460 vap->iv_stats.is_tx_fragframes++;
1461 vap->iv_stats.is_tx_frags += fragno-1;
1465 /* reclaim fragments but leave original frame for caller to free */
1466 for (m = m0->m_nextpkt; m != NULL; m = next) {
1467 next = m->m_nextpkt;
1468 m->m_nextpkt = NULL; /* XXX paranoid */
1471 m0->m_nextpkt = NULL;
1476 * Add a supported rates element id to a frame.
1479 ieee80211_add_rates(uint8_t *frm, const struct ieee80211_rateset *rs)
1483 *frm++ = IEEE80211_ELEMID_RATES;
1484 nrates = rs->rs_nrates;
1485 if (nrates > IEEE80211_RATE_SIZE)
1486 nrates = IEEE80211_RATE_SIZE;
1488 memcpy(frm, rs->rs_rates, nrates);
1489 return frm + nrates;
1493 * Add an extended supported rates element id to a frame.
1496 ieee80211_add_xrates(uint8_t *frm, const struct ieee80211_rateset *rs)
1499 * Add an extended supported rates element if operating in 11g mode.
1501 if (rs->rs_nrates > IEEE80211_RATE_SIZE) {
1502 int nrates = rs->rs_nrates - IEEE80211_RATE_SIZE;
1503 *frm++ = IEEE80211_ELEMID_XRATES;
1505 memcpy(frm, rs->rs_rates + IEEE80211_RATE_SIZE, nrates);
1512 * Add an ssid element to a frame.
1515 ieee80211_add_ssid(uint8_t *frm, const uint8_t *ssid, u_int len)
1517 *frm++ = IEEE80211_ELEMID_SSID;
1519 memcpy(frm, ssid, len);
1524 * Add an erp element to a frame.
1527 ieee80211_add_erp(uint8_t *frm, struct ieee80211com *ic)
1531 *frm++ = IEEE80211_ELEMID_ERP;
1534 if (ic->ic_nonerpsta != 0)
1535 erp |= IEEE80211_ERP_NON_ERP_PRESENT;
1536 if (ic->ic_flags & IEEE80211_F_USEPROT)
1537 erp |= IEEE80211_ERP_USE_PROTECTION;
1538 if (ic->ic_flags & IEEE80211_F_USEBARKER)
1539 erp |= IEEE80211_ERP_LONG_PREAMBLE;
1545 * Add a CFParams element to a frame.
1548 ieee80211_add_cfparms(uint8_t *frm, struct ieee80211com *ic)
1550 #define ADDSHORT(frm, v) do { \
1551 LE_WRITE_2(frm, v); \
1554 *frm++ = IEEE80211_ELEMID_CFPARMS;
1556 *frm++ = 0; /* CFP count */
1557 *frm++ = 2; /* CFP period */
1558 ADDSHORT(frm, 0); /* CFP MaxDuration (TU) */
1559 ADDSHORT(frm, 0); /* CFP CurRemaining (TU) */
1564 static __inline uint8_t *
1565 add_appie(uint8_t *frm, const struct ieee80211_appie *ie)
1567 memcpy(frm, ie->ie_data, ie->ie_len);
1568 return frm + ie->ie_len;
1571 static __inline uint8_t *
1572 add_ie(uint8_t *frm, const uint8_t *ie)
1574 memcpy(frm, ie, 2 + ie[1]);
1575 return frm + 2 + ie[1];
1578 #define WME_OUI_BYTES 0x00, 0x50, 0xf2
1580 * Add a WME information element to a frame.
1583 ieee80211_add_wme_info(uint8_t *frm, struct ieee80211_wme_state *wme)
1585 static const struct ieee80211_wme_info info = {
1586 .wme_id = IEEE80211_ELEMID_VENDOR,
1587 .wme_len = sizeof(struct ieee80211_wme_info) - 2,
1588 .wme_oui = { WME_OUI_BYTES },
1589 .wme_type = WME_OUI_TYPE,
1590 .wme_subtype = WME_INFO_OUI_SUBTYPE,
1591 .wme_version = WME_VERSION,
1594 memcpy(frm, &info, sizeof(info));
1595 return frm + sizeof(info);
1599 * Add a WME parameters element to a frame.
1602 ieee80211_add_wme_param(uint8_t *frm, struct ieee80211_wme_state *wme)
1604 #define SM(_v, _f) (((_v) << _f##_S) & _f)
1605 #define ADDSHORT(frm, v) do { \
1606 LE_WRITE_2(frm, v); \
1609 /* NB: this works 'cuz a param has an info at the front */
1610 static const struct ieee80211_wme_info param = {
1611 .wme_id = IEEE80211_ELEMID_VENDOR,
1612 .wme_len = sizeof(struct ieee80211_wme_param) - 2,
1613 .wme_oui = { WME_OUI_BYTES },
1614 .wme_type = WME_OUI_TYPE,
1615 .wme_subtype = WME_PARAM_OUI_SUBTYPE,
1616 .wme_version = WME_VERSION,
1620 memcpy(frm, ¶m, sizeof(param));
1621 frm += __offsetof(struct ieee80211_wme_info, wme_info);
1622 *frm++ = wme->wme_bssChanParams.cap_info; /* AC info */
1623 *frm++ = 0; /* reserved field */
1624 for (i = 0; i < WME_NUM_AC; i++) {
1625 const struct wmeParams *ac =
1626 &wme->wme_bssChanParams.cap_wmeParams[i];
1627 *frm++ = SM(i, WME_PARAM_ACI)
1628 | SM(ac->wmep_acm, WME_PARAM_ACM)
1629 | SM(ac->wmep_aifsn, WME_PARAM_AIFSN)
1631 *frm++ = SM(ac->wmep_logcwmax, WME_PARAM_LOGCWMAX)
1632 | SM(ac->wmep_logcwmin, WME_PARAM_LOGCWMIN)
1634 ADDSHORT(frm, ac->wmep_txopLimit);
1640 #undef WME_OUI_BYTES
1643 * Add an 11h Power Constraint element to a frame.
1646 ieee80211_add_powerconstraint(uint8_t *frm, struct ieee80211vap *vap)
1648 const struct ieee80211_channel *c = vap->iv_bss->ni_chan;
1649 /* XXX per-vap tx power limit? */
1650 int8_t limit = vap->iv_ic->ic_txpowlimit / 2;
1652 frm[0] = IEEE80211_ELEMID_PWRCNSTR;
1654 frm[2] = c->ic_maxregpower > limit ? c->ic_maxregpower - limit : 0;
1659 * Add an 11h Power Capability element to a frame.
1662 ieee80211_add_powercapability(uint8_t *frm, const struct ieee80211_channel *c)
1664 frm[0] = IEEE80211_ELEMID_PWRCAP;
1666 frm[2] = c->ic_minpower;
1667 frm[3] = c->ic_maxpower;
1672 * Add an 11h Supported Channels element to a frame.
1675 ieee80211_add_supportedchannels(uint8_t *frm, struct ieee80211com *ic)
1677 static const int ielen = 26;
1679 frm[0] = IEEE80211_ELEMID_SUPPCHAN;
1681 /* XXX not correct */
1682 memcpy(frm+2, ic->ic_chan_avail, ielen);
1683 return frm + 2 + ielen;
1687 * Add an 11h Quiet time element to a frame.
1690 ieee80211_add_quiet(uint8_t *frm, struct ieee80211vap *vap)
1692 struct ieee80211_quiet_ie *quiet = (struct ieee80211_quiet_ie *) frm;
1694 quiet->quiet_ie = IEEE80211_ELEMID_QUIET;
1696 if (vap->iv_quiet_count_value == 1)
1697 vap->iv_quiet_count_value = vap->iv_quiet_count;
1698 else if (vap->iv_quiet_count_value > 1)
1699 vap->iv_quiet_count_value--;
1701 if (vap->iv_quiet_count_value == 0) {
1702 /* value 0 is reserved as per 802.11h standerd */
1703 vap->iv_quiet_count_value = 1;
1706 quiet->tbttcount = vap->iv_quiet_count_value;
1707 quiet->period = vap->iv_quiet_period;
1708 quiet->duration = htole16(vap->iv_quiet_duration);
1709 quiet->offset = htole16(vap->iv_quiet_offset);
1710 return frm + sizeof(*quiet);
1714 * Add an 11h Channel Switch Announcement element to a frame.
1715 * Note that we use the per-vap CSA count to adjust the global
1716 * counter so we can use this routine to form probe response
1717 * frames and get the current count.
1720 ieee80211_add_csa(uint8_t *frm, struct ieee80211vap *vap)
1722 struct ieee80211com *ic = vap->iv_ic;
1723 struct ieee80211_csa_ie *csa = (struct ieee80211_csa_ie *) frm;
1725 csa->csa_ie = IEEE80211_ELEMID_CSA;
1727 csa->csa_mode = 1; /* XXX force quiet on channel */
1728 csa->csa_newchan = ieee80211_chan2ieee(ic, ic->ic_csa_newchan);
1729 csa->csa_count = ic->ic_csa_count - vap->iv_csa_count;
1730 return frm + sizeof(*csa);
1734 * Add an 11h country information element to a frame.
1737 ieee80211_add_countryie(uint8_t *frm, struct ieee80211com *ic)
1740 if (ic->ic_countryie == NULL ||
1741 ic->ic_countryie_chan != ic->ic_bsschan) {
1743 * Handle lazy construction of ie. This is done on
1744 * first use and after a channel change that requires
1747 if (ic->ic_countryie != NULL)
1748 free(ic->ic_countryie, M_80211_NODE_IE);
1749 ic->ic_countryie = ieee80211_alloc_countryie(ic);
1750 if (ic->ic_countryie == NULL)
1752 ic->ic_countryie_chan = ic->ic_bsschan;
1754 return add_appie(frm, ic->ic_countryie);
1758 * Send a probe request frame with the specified ssid
1759 * and any optional information element data.
1762 ieee80211_send_probereq(struct ieee80211_node *ni,
1763 const uint8_t sa[IEEE80211_ADDR_LEN],
1764 const uint8_t da[IEEE80211_ADDR_LEN],
1765 const uint8_t bssid[IEEE80211_ADDR_LEN],
1766 const uint8_t *ssid, size_t ssidlen)
1768 struct ieee80211vap *vap = ni->ni_vap;
1769 struct ieee80211com *ic = ni->ni_ic;
1770 const struct ieee80211_txparam *tp;
1771 struct ieee80211_bpf_params params;
1772 struct ieee80211_frame *wh;
1773 const struct ieee80211_rateset *rs;
1777 if (vap->iv_state == IEEE80211_S_CAC) {
1778 IEEE80211_NOTE(vap, IEEE80211_MSG_OUTPUT, ni,
1779 "block %s frame in CAC state", "probe request");
1780 vap->iv_stats.is_tx_badstate++;
1781 return EIO; /* XXX */
1785 * Hold a reference on the node so it doesn't go away until after
1786 * the xmit is complete all the way in the driver. On error we
1787 * will remove our reference.
1789 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1790 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n",
1792 ni, ether_sprintf(ni->ni_macaddr),
1793 ieee80211_node_refcnt(ni)+1);
1794 ieee80211_ref_node(ni);
1797 * prreq frame format
1799 * [tlv] supported rates
1800 * [tlv] RSN (optional)
1801 * [tlv] extended supported rates
1802 * [tlv] WPA (optional)
1803 * [tlv] user-specified ie's
1805 m = ieee80211_getmgtframe(&frm,
1806 ic->ic_headroom + sizeof(struct ieee80211_frame),
1807 2 + IEEE80211_NWID_LEN
1808 + 2 + IEEE80211_RATE_SIZE
1809 + sizeof(struct ieee80211_ie_wpa)
1810 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
1811 + sizeof(struct ieee80211_ie_wpa)
1812 + (vap->iv_appie_probereq != NULL ?
1813 vap->iv_appie_probereq->ie_len : 0)
1816 vap->iv_stats.is_tx_nobuf++;
1817 ieee80211_free_node(ni);
1821 frm = ieee80211_add_ssid(frm, ssid, ssidlen);
1822 rs = ieee80211_get_suprates(ic, ic->ic_curchan);
1823 frm = ieee80211_add_rates(frm, rs);
1824 if (vap->iv_flags & IEEE80211_F_WPA2) {
1825 if (vap->iv_rsn_ie != NULL)
1826 frm = add_ie(frm, vap->iv_rsn_ie);
1827 /* XXX else complain? */
1829 frm = ieee80211_add_xrates(frm, rs);
1830 if (vap->iv_flags & IEEE80211_F_WPA1) {
1831 if (vap->iv_wpa_ie != NULL)
1832 frm = add_ie(frm, vap->iv_wpa_ie);
1833 /* XXX else complain? */
1835 if (vap->iv_appie_probereq != NULL)
1836 frm = add_appie(frm, vap->iv_appie_probereq);
1837 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
1839 KASSERT(M_LEADINGSPACE(m) >= sizeof(struct ieee80211_frame),
1840 ("leading space %zd", M_LEADINGSPACE(m)));
1841 M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT);
1843 /* NB: cannot happen */
1844 ieee80211_free_node(ni);
1848 wh = mtod(m, struct ieee80211_frame *);
1849 ieee80211_send_setup(ni, m,
1850 IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_REQ,
1851 IEEE80211_NONQOS_TID, sa, da, bssid);
1852 /* XXX power management? */
1853 m->m_flags |= M_ENCAP; /* mark encapsulated */
1855 M_WME_SETAC(m, WME_AC_BE);
1857 IEEE80211_NODE_STAT(ni, tx_probereq);
1858 IEEE80211_NODE_STAT(ni, tx_mgmt);
1860 IEEE80211_DPRINTF(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_DUMPPKTS,
1861 "send probe req on channel %u bssid %s ssid \"%.*s\"\n",
1862 ieee80211_chan2ieee(ic, ic->ic_curchan), ether_sprintf(bssid),
1865 memset(¶ms, 0, sizeof(params));
1866 params.ibp_pri = M_WME_GETAC(m);
1867 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)];
1868 params.ibp_rate0 = tp->mgmtrate;
1869 if (IEEE80211_IS_MULTICAST(da)) {
1870 params.ibp_flags |= IEEE80211_BPF_NOACK;
1871 params.ibp_try0 = 1;
1873 params.ibp_try0 = tp->maxretry;
1874 params.ibp_power = ni->ni_txpower;
1875 return ic->ic_raw_xmit(ni, m, ¶ms);
1879 * Calculate capability information for mgt frames.
1882 ieee80211_getcapinfo(struct ieee80211vap *vap, struct ieee80211_channel *chan)
1884 struct ieee80211com *ic = vap->iv_ic;
1887 KASSERT(vap->iv_opmode != IEEE80211_M_STA, ("station mode"));
1889 if (vap->iv_opmode == IEEE80211_M_HOSTAP)
1890 capinfo = IEEE80211_CAPINFO_ESS;
1891 else if (vap->iv_opmode == IEEE80211_M_IBSS)
1892 capinfo = IEEE80211_CAPINFO_IBSS;
1895 if (vap->iv_flags & IEEE80211_F_PRIVACY)
1896 capinfo |= IEEE80211_CAPINFO_PRIVACY;
1897 if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) &&
1898 IEEE80211_IS_CHAN_2GHZ(chan))
1899 capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE;
1900 if (ic->ic_flags & IEEE80211_F_SHSLOT)
1901 capinfo |= IEEE80211_CAPINFO_SHORT_SLOTTIME;
1902 if (IEEE80211_IS_CHAN_5GHZ(chan) && (vap->iv_flags & IEEE80211_F_DOTH))
1903 capinfo |= IEEE80211_CAPINFO_SPECTRUM_MGMT;
1908 * Send a management frame. The node is for the destination (or ic_bss
1909 * when in station mode). Nodes other than ic_bss have their reference
1910 * count bumped to reflect our use for an indeterminant time.
1913 ieee80211_send_mgmt(struct ieee80211_node *ni, int type, int arg)
1915 #define HTFLAGS (IEEE80211_NODE_HT | IEEE80211_NODE_HTCOMPAT)
1916 #define senderr(_x, _v) do { vap->iv_stats._v++; ret = _x; goto bad; } while (0)
1917 struct ieee80211vap *vap = ni->ni_vap;
1918 struct ieee80211com *ic = ni->ni_ic;
1919 struct ieee80211_node *bss = vap->iv_bss;
1920 struct ieee80211_bpf_params params;
1924 int has_challenge, is_shared_key, ret, status;
1926 KASSERT(ni != NULL, ("null node"));
1929 * Hold a reference on the node so it doesn't go away until after
1930 * the xmit is complete all the way in the driver. On error we
1931 * will remove our reference.
1933 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1934 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n",
1936 ni, ether_sprintf(ni->ni_macaddr),
1937 ieee80211_node_refcnt(ni)+1);
1938 ieee80211_ref_node(ni);
1940 memset(¶ms, 0, sizeof(params));
1943 case IEEE80211_FC0_SUBTYPE_AUTH:
1946 has_challenge = ((arg == IEEE80211_AUTH_SHARED_CHALLENGE ||
1947 arg == IEEE80211_AUTH_SHARED_RESPONSE) &&
1948 ni->ni_challenge != NULL);
1951 * Deduce whether we're doing open authentication or
1952 * shared key authentication. We do the latter if
1953 * we're in the middle of a shared key authentication
1954 * handshake or if we're initiating an authentication
1955 * request and configured to use shared key.
1957 is_shared_key = has_challenge ||
1958 arg >= IEEE80211_AUTH_SHARED_RESPONSE ||
1959 (arg == IEEE80211_AUTH_SHARED_REQUEST &&
1960 bss->ni_authmode == IEEE80211_AUTH_SHARED);
1962 m = ieee80211_getmgtframe(&frm,
1963 ic->ic_headroom + sizeof(struct ieee80211_frame),
1964 3 * sizeof(uint16_t)
1965 + (has_challenge && status == IEEE80211_STATUS_SUCCESS ?
1966 sizeof(uint16_t)+IEEE80211_CHALLENGE_LEN : 0)
1969 senderr(ENOMEM, is_tx_nobuf);
1971 ((uint16_t *)frm)[0] =
1972 (is_shared_key) ? htole16(IEEE80211_AUTH_ALG_SHARED)
1973 : htole16(IEEE80211_AUTH_ALG_OPEN);
1974 ((uint16_t *)frm)[1] = htole16(arg); /* sequence number */
1975 ((uint16_t *)frm)[2] = htole16(status);/* status */
1977 if (has_challenge && status == IEEE80211_STATUS_SUCCESS) {
1978 ((uint16_t *)frm)[3] =
1979 htole16((IEEE80211_CHALLENGE_LEN << 8) |
1980 IEEE80211_ELEMID_CHALLENGE);
1981 memcpy(&((uint16_t *)frm)[4], ni->ni_challenge,
1982 IEEE80211_CHALLENGE_LEN);
1983 m->m_pkthdr.len = m->m_len =
1984 4 * sizeof(uint16_t) + IEEE80211_CHALLENGE_LEN;
1985 if (arg == IEEE80211_AUTH_SHARED_RESPONSE) {
1986 IEEE80211_NOTE(vap, IEEE80211_MSG_AUTH, ni,
1987 "request encrypt frame (%s)", __func__);
1988 /* mark frame for encryption */
1989 params.ibp_flags |= IEEE80211_BPF_CRYPTO;
1992 m->m_pkthdr.len = m->m_len = 3 * sizeof(uint16_t);
1994 /* XXX not right for shared key */
1995 if (status == IEEE80211_STATUS_SUCCESS)
1996 IEEE80211_NODE_STAT(ni, tx_auth);
1998 IEEE80211_NODE_STAT(ni, tx_auth_fail);
2000 if (vap->iv_opmode == IEEE80211_M_STA)
2001 ieee80211_add_callback(m, ieee80211_tx_mgt_cb,
2002 (void *) vap->iv_state);
2005 case IEEE80211_FC0_SUBTYPE_DEAUTH:
2006 IEEE80211_NOTE(vap, IEEE80211_MSG_AUTH, ni,
2007 "send station deauthenticate (reason %d)", arg);
2008 m = ieee80211_getmgtframe(&frm,
2009 ic->ic_headroom + sizeof(struct ieee80211_frame),
2012 senderr(ENOMEM, is_tx_nobuf);
2013 *(uint16_t *)frm = htole16(arg); /* reason */
2014 m->m_pkthdr.len = m->m_len = sizeof(uint16_t);
2016 IEEE80211_NODE_STAT(ni, tx_deauth);
2017 IEEE80211_NODE_STAT_SET(ni, tx_deauth_code, arg);
2019 ieee80211_node_unauthorize(ni); /* port closed */
2022 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
2023 case IEEE80211_FC0_SUBTYPE_REASSOC_REQ:
2025 * asreq frame format
2026 * [2] capability information
2027 * [2] listen interval
2028 * [6*] current AP address (reassoc only)
2030 * [tlv] supported rates
2031 * [tlv] extended supported rates
2032 * [4] power capability (optional)
2033 * [28] supported channels (optional)
2034 * [tlv] HT capabilities
2035 * [tlv] WME (optional)
2036 * [tlv] Vendor OUI HT capabilities (optional)
2037 * [tlv] Atheros capabilities (if negotiated)
2038 * [tlv] AppIE's (optional)
2040 m = ieee80211_getmgtframe(&frm,
2041 ic->ic_headroom + sizeof(struct ieee80211_frame),
2044 + IEEE80211_ADDR_LEN
2045 + 2 + IEEE80211_NWID_LEN
2046 + 2 + IEEE80211_RATE_SIZE
2047 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
2050 + sizeof(struct ieee80211_wme_info)
2051 + sizeof(struct ieee80211_ie_htcap)
2052 + 4 + sizeof(struct ieee80211_ie_htcap)
2053 #ifdef IEEE80211_SUPPORT_SUPERG
2054 + sizeof(struct ieee80211_ath_ie)
2056 + (vap->iv_appie_wpa != NULL ?
2057 vap->iv_appie_wpa->ie_len : 0)
2058 + (vap->iv_appie_assocreq != NULL ?
2059 vap->iv_appie_assocreq->ie_len : 0)
2062 senderr(ENOMEM, is_tx_nobuf);
2064 KASSERT(vap->iv_opmode == IEEE80211_M_STA,
2065 ("wrong mode %u", vap->iv_opmode));
2066 capinfo = IEEE80211_CAPINFO_ESS;
2067 if (vap->iv_flags & IEEE80211_F_PRIVACY)
2068 capinfo |= IEEE80211_CAPINFO_PRIVACY;
2070 * NB: Some 11a AP's reject the request when
2071 * short premable is set.
2073 if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) &&
2074 IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan))
2075 capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE;
2076 if (IEEE80211_IS_CHAN_ANYG(ic->ic_curchan) &&
2077 (ic->ic_caps & IEEE80211_C_SHSLOT))
2078 capinfo |= IEEE80211_CAPINFO_SHORT_SLOTTIME;
2079 if ((ni->ni_capinfo & IEEE80211_CAPINFO_SPECTRUM_MGMT) &&
2080 (vap->iv_flags & IEEE80211_F_DOTH))
2081 capinfo |= IEEE80211_CAPINFO_SPECTRUM_MGMT;
2082 *(uint16_t *)frm = htole16(capinfo);
2085 KASSERT(bss->ni_intval != 0, ("beacon interval is zero!"));
2086 *(uint16_t *)frm = htole16(howmany(ic->ic_lintval,
2090 if (type == IEEE80211_FC0_SUBTYPE_REASSOC_REQ) {
2091 IEEE80211_ADDR_COPY(frm, bss->ni_bssid);
2092 frm += IEEE80211_ADDR_LEN;
2095 frm = ieee80211_add_ssid(frm, ni->ni_essid, ni->ni_esslen);
2096 frm = ieee80211_add_rates(frm, &ni->ni_rates);
2097 if (vap->iv_flags & IEEE80211_F_WPA2) {
2098 if (vap->iv_rsn_ie != NULL)
2099 frm = add_ie(frm, vap->iv_rsn_ie);
2100 /* XXX else complain? */
2102 frm = ieee80211_add_xrates(frm, &ni->ni_rates);
2103 if (capinfo & IEEE80211_CAPINFO_SPECTRUM_MGMT) {
2104 frm = ieee80211_add_powercapability(frm,
2106 frm = ieee80211_add_supportedchannels(frm, ic);
2108 if ((vap->iv_flags_ht & IEEE80211_FHT_HT) &&
2109 ni->ni_ies.htcap_ie != NULL &&
2110 ni->ni_ies.htcap_ie[0] == IEEE80211_ELEMID_HTCAP)
2111 frm = ieee80211_add_htcap(frm, ni);
2112 if (vap->iv_flags & IEEE80211_F_WPA1) {
2113 if (vap->iv_wpa_ie != NULL)
2114 frm = add_ie(frm, vap->iv_wpa_ie);
2115 /* XXX else complain */
2117 if ((ic->ic_flags & IEEE80211_F_WME) &&
2118 ni->ni_ies.wme_ie != NULL)
2119 frm = ieee80211_add_wme_info(frm, &ic->ic_wme);
2120 if ((vap->iv_flags_ht & IEEE80211_FHT_HT) &&
2121 ni->ni_ies.htcap_ie != NULL &&
2122 ni->ni_ies.htcap_ie[0] == IEEE80211_ELEMID_VENDOR)
2123 frm = ieee80211_add_htcap_vendor(frm, ni);
2124 #ifdef IEEE80211_SUPPORT_SUPERG
2125 if (IEEE80211_ATH_CAP(vap, ni, IEEE80211_F_ATHEROS)) {
2126 frm = ieee80211_add_ath(frm,
2127 IEEE80211_ATH_CAP(vap, ni, IEEE80211_F_ATHEROS),
2128 ((vap->iv_flags & IEEE80211_F_WPA) == 0 &&
2129 ni->ni_authmode != IEEE80211_AUTH_8021X) ?
2130 vap->iv_def_txkey : IEEE80211_KEYIX_NONE);
2132 #endif /* IEEE80211_SUPPORT_SUPERG */
2133 if (vap->iv_appie_assocreq != NULL)
2134 frm = add_appie(frm, vap->iv_appie_assocreq);
2135 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2137 ieee80211_add_callback(m, ieee80211_tx_mgt_cb,
2138 (void *) vap->iv_state);
2141 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
2142 case IEEE80211_FC0_SUBTYPE_REASSOC_RESP:
2144 * asresp frame format
2145 * [2] capability information
2147 * [2] association ID
2148 * [tlv] supported rates
2149 * [tlv] extended supported rates
2150 * [tlv] HT capabilities (standard, if STA enabled)
2151 * [tlv] HT information (standard, if STA enabled)
2152 * [tlv] WME (if configured and STA enabled)
2153 * [tlv] HT capabilities (vendor OUI, if STA enabled)
2154 * [tlv] HT information (vendor OUI, if STA enabled)
2155 * [tlv] Atheros capabilities (if STA enabled)
2156 * [tlv] AppIE's (optional)
2158 m = ieee80211_getmgtframe(&frm,
2159 ic->ic_headroom + sizeof(struct ieee80211_frame),
2163 + 2 + IEEE80211_RATE_SIZE
2164 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
2165 + sizeof(struct ieee80211_ie_htcap) + 4
2166 + sizeof(struct ieee80211_ie_htinfo) + 4
2167 + sizeof(struct ieee80211_wme_param)
2168 #ifdef IEEE80211_SUPPORT_SUPERG
2169 + sizeof(struct ieee80211_ath_ie)
2171 + (vap->iv_appie_assocresp != NULL ?
2172 vap->iv_appie_assocresp->ie_len : 0)
2175 senderr(ENOMEM, is_tx_nobuf);
2177 capinfo = ieee80211_getcapinfo(vap, bss->ni_chan);
2178 *(uint16_t *)frm = htole16(capinfo);
2181 *(uint16_t *)frm = htole16(arg); /* status */
2184 if (arg == IEEE80211_STATUS_SUCCESS) {
2185 *(uint16_t *)frm = htole16(ni->ni_associd);
2186 IEEE80211_NODE_STAT(ni, tx_assoc);
2188 IEEE80211_NODE_STAT(ni, tx_assoc_fail);
2191 frm = ieee80211_add_rates(frm, &ni->ni_rates);
2192 frm = ieee80211_add_xrates(frm, &ni->ni_rates);
2193 /* NB: respond according to what we received */
2194 if ((ni->ni_flags & HTFLAGS) == IEEE80211_NODE_HT) {
2195 frm = ieee80211_add_htcap(frm, ni);
2196 frm = ieee80211_add_htinfo(frm, ni);
2198 if ((vap->iv_flags & IEEE80211_F_WME) &&
2199 ni->ni_ies.wme_ie != NULL)
2200 frm = ieee80211_add_wme_param(frm, &ic->ic_wme);
2201 if ((ni->ni_flags & HTFLAGS) == HTFLAGS) {
2202 frm = ieee80211_add_htcap_vendor(frm, ni);
2203 frm = ieee80211_add_htinfo_vendor(frm, ni);
2205 #ifdef IEEE80211_SUPPORT_SUPERG
2206 if (IEEE80211_ATH_CAP(vap, ni, IEEE80211_F_ATHEROS))
2207 frm = ieee80211_add_ath(frm,
2208 IEEE80211_ATH_CAP(vap, ni, IEEE80211_F_ATHEROS),
2209 ((vap->iv_flags & IEEE80211_F_WPA) == 0 &&
2210 ni->ni_authmode != IEEE80211_AUTH_8021X) ?
2211 vap->iv_def_txkey : IEEE80211_KEYIX_NONE);
2212 #endif /* IEEE80211_SUPPORT_SUPERG */
2213 if (vap->iv_appie_assocresp != NULL)
2214 frm = add_appie(frm, vap->iv_appie_assocresp);
2215 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2218 case IEEE80211_FC0_SUBTYPE_DISASSOC:
2219 IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC, ni,
2220 "send station disassociate (reason %d)", arg);
2221 m = ieee80211_getmgtframe(&frm,
2222 ic->ic_headroom + sizeof(struct ieee80211_frame),
2225 senderr(ENOMEM, is_tx_nobuf);
2226 *(uint16_t *)frm = htole16(arg); /* reason */
2227 m->m_pkthdr.len = m->m_len = sizeof(uint16_t);
2229 IEEE80211_NODE_STAT(ni, tx_disassoc);
2230 IEEE80211_NODE_STAT_SET(ni, tx_disassoc_code, arg);
2234 IEEE80211_NOTE(vap, IEEE80211_MSG_ANY, ni,
2235 "invalid mgmt frame type %u", type);
2236 senderr(EINVAL, is_tx_unknownmgt);
2240 /* NB: force non-ProbeResp frames to the highest queue */
2241 params.ibp_pri = WME_AC_VO;
2242 params.ibp_rate0 = bss->ni_txparms->mgmtrate;
2243 /* NB: we know all frames are unicast */
2244 params.ibp_try0 = bss->ni_txparms->maxretry;
2245 params.ibp_power = bss->ni_txpower;
2246 return ieee80211_mgmt_output(ni, m, type, ¶ms);
2248 ieee80211_free_node(ni);
2255 * Return an mbuf with a probe response frame in it.
2256 * Space is left to prepend and 802.11 header at the
2257 * front but it's left to the caller to fill in.
2260 ieee80211_alloc_proberesp(struct ieee80211_node *bss, int legacy)
2262 struct ieee80211vap *vap = bss->ni_vap;
2263 struct ieee80211com *ic = bss->ni_ic;
2264 const struct ieee80211_rateset *rs;
2270 * probe response frame format
2272 * [2] beacon interval
2273 * [2] cabability information
2275 * [tlv] supported rates
2276 * [tlv] parameter set (FH/DS)
2277 * [tlv] parameter set (IBSS)
2278 * [tlv] country (optional)
2279 * [3] power control (optional)
2280 * [5] channel switch announcement (CSA) (optional)
2281 * [tlv] extended rate phy (ERP)
2282 * [tlv] extended supported rates
2283 * [tlv] RSN (optional)
2284 * [tlv] HT capabilities
2285 * [tlv] HT information
2286 * [tlv] WPA (optional)
2287 * [tlv] WME (optional)
2288 * [tlv] Vendor OUI HT capabilities (optional)
2289 * [tlv] Vendor OUI HT information (optional)
2290 * [tlv] Atheros capabilities
2291 * [tlv] AppIE's (optional)
2292 * [tlv] Mesh ID (MBSS)
2293 * [tlv] Mesh Conf (MBSS)
2295 m = ieee80211_getmgtframe(&frm,
2296 ic->ic_headroom + sizeof(struct ieee80211_frame),
2300 + 2 + IEEE80211_NWID_LEN
2301 + 2 + IEEE80211_RATE_SIZE
2303 + IEEE80211_COUNTRY_MAX_SIZE
2305 + sizeof(struct ieee80211_csa_ie)
2306 + sizeof(struct ieee80211_quiet_ie)
2308 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
2309 + sizeof(struct ieee80211_ie_wpa)
2310 + sizeof(struct ieee80211_ie_htcap)
2311 + sizeof(struct ieee80211_ie_htinfo)
2312 + sizeof(struct ieee80211_ie_wpa)
2313 + sizeof(struct ieee80211_wme_param)
2314 + 4 + sizeof(struct ieee80211_ie_htcap)
2315 + 4 + sizeof(struct ieee80211_ie_htinfo)
2316 #ifdef IEEE80211_SUPPORT_SUPERG
2317 + sizeof(struct ieee80211_ath_ie)
2319 #ifdef IEEE80211_SUPPORT_MESH
2320 + 2 + IEEE80211_MESHID_LEN
2321 + sizeof(struct ieee80211_meshconf_ie)
2323 + (vap->iv_appie_proberesp != NULL ?
2324 vap->iv_appie_proberesp->ie_len : 0)
2327 vap->iv_stats.is_tx_nobuf++;
2331 memset(frm, 0, 8); /* timestamp should be filled later */
2333 *(uint16_t *)frm = htole16(bss->ni_intval);
2335 capinfo = ieee80211_getcapinfo(vap, bss->ni_chan);
2336 *(uint16_t *)frm = htole16(capinfo);
2339 frm = ieee80211_add_ssid(frm, bss->ni_essid, bss->ni_esslen);
2340 rs = ieee80211_get_suprates(ic, bss->ni_chan);
2341 frm = ieee80211_add_rates(frm, rs);
2343 if (IEEE80211_IS_CHAN_FHSS(bss->ni_chan)) {
2344 *frm++ = IEEE80211_ELEMID_FHPARMS;
2346 *frm++ = bss->ni_fhdwell & 0x00ff;
2347 *frm++ = (bss->ni_fhdwell >> 8) & 0x00ff;
2348 *frm++ = IEEE80211_FH_CHANSET(
2349 ieee80211_chan2ieee(ic, bss->ni_chan));
2350 *frm++ = IEEE80211_FH_CHANPAT(
2351 ieee80211_chan2ieee(ic, bss->ni_chan));
2352 *frm++ = bss->ni_fhindex;
2354 *frm++ = IEEE80211_ELEMID_DSPARMS;
2356 *frm++ = ieee80211_chan2ieee(ic, bss->ni_chan);
2359 if (vap->iv_opmode == IEEE80211_M_IBSS) {
2360 *frm++ = IEEE80211_ELEMID_IBSSPARMS;
2362 *frm++ = 0; *frm++ = 0; /* TODO: ATIM window */
2364 if ((vap->iv_flags & IEEE80211_F_DOTH) ||
2365 (vap->iv_flags_ext & IEEE80211_FEXT_DOTD))
2366 frm = ieee80211_add_countryie(frm, ic);
2367 if (vap->iv_flags & IEEE80211_F_DOTH) {
2368 if (IEEE80211_IS_CHAN_5GHZ(bss->ni_chan))
2369 frm = ieee80211_add_powerconstraint(frm, vap);
2370 if (ic->ic_flags & IEEE80211_F_CSAPENDING)
2371 frm = ieee80211_add_csa(frm, vap);
2373 if (vap->iv_flags & IEEE80211_F_DOTH) {
2374 if (IEEE80211_IS_CHAN_DFS(ic->ic_bsschan) &&
2375 (vap->iv_flags_ext & IEEE80211_FEXT_DFS)) {
2377 frm = ieee80211_add_quiet(frm, vap);
2380 if (IEEE80211_IS_CHAN_ANYG(bss->ni_chan))
2381 frm = ieee80211_add_erp(frm, ic);
2382 frm = ieee80211_add_xrates(frm, rs);
2383 if (vap->iv_flags & IEEE80211_F_WPA2) {
2384 if (vap->iv_rsn_ie != NULL)
2385 frm = add_ie(frm, vap->iv_rsn_ie);
2386 /* XXX else complain? */
2389 * NB: legacy 11b clients do not get certain ie's.
2390 * The caller identifies such clients by passing
2391 * a token in legacy to us. Could expand this to be
2392 * any legacy client for stuff like HT ie's.
2394 if (IEEE80211_IS_CHAN_HT(bss->ni_chan) &&
2395 legacy != IEEE80211_SEND_LEGACY_11B) {
2396 frm = ieee80211_add_htcap(frm, bss);
2397 frm = ieee80211_add_htinfo(frm, bss);
2399 if (vap->iv_flags & IEEE80211_F_WPA1) {
2400 if (vap->iv_wpa_ie != NULL)
2401 frm = add_ie(frm, vap->iv_wpa_ie);
2402 /* XXX else complain? */
2404 if (vap->iv_flags & IEEE80211_F_WME)
2405 frm = ieee80211_add_wme_param(frm, &ic->ic_wme);
2406 if (IEEE80211_IS_CHAN_HT(bss->ni_chan) &&
2407 (vap->iv_flags_ht & IEEE80211_FHT_HTCOMPAT) &&
2408 legacy != IEEE80211_SEND_LEGACY_11B) {
2409 frm = ieee80211_add_htcap_vendor(frm, bss);
2410 frm = ieee80211_add_htinfo_vendor(frm, bss);
2412 #ifdef IEEE80211_SUPPORT_SUPERG
2413 if ((vap->iv_flags & IEEE80211_F_ATHEROS) &&
2414 legacy != IEEE80211_SEND_LEGACY_11B)
2415 frm = ieee80211_add_athcaps(frm, bss);
2417 if (vap->iv_appie_proberesp != NULL)
2418 frm = add_appie(frm, vap->iv_appie_proberesp);
2419 #ifdef IEEE80211_SUPPORT_MESH
2420 if (vap->iv_opmode == IEEE80211_M_MBSS) {
2421 frm = ieee80211_add_meshid(frm, vap);
2422 frm = ieee80211_add_meshconf(frm, vap);
2425 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2431 * Send a probe response frame to the specified mac address.
2432 * This does not go through the normal mgt frame api so we
2433 * can specify the destination address and re-use the bss node
2434 * for the sta reference.
2437 ieee80211_send_proberesp(struct ieee80211vap *vap,
2438 const uint8_t da[IEEE80211_ADDR_LEN], int legacy)
2440 struct ieee80211_node *bss = vap->iv_bss;
2441 struct ieee80211com *ic = vap->iv_ic;
2442 struct ieee80211_frame *wh;
2445 if (vap->iv_state == IEEE80211_S_CAC) {
2446 IEEE80211_NOTE(vap, IEEE80211_MSG_OUTPUT, bss,
2447 "block %s frame in CAC state", "probe response");
2448 vap->iv_stats.is_tx_badstate++;
2449 return EIO; /* XXX */
2453 * Hold a reference on the node so it doesn't go away until after
2454 * the xmit is complete all the way in the driver. On error we
2455 * will remove our reference.
2457 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2458 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n",
2459 __func__, __LINE__, bss, ether_sprintf(bss->ni_macaddr),
2460 ieee80211_node_refcnt(bss)+1);
2461 ieee80211_ref_node(bss);
2463 m = ieee80211_alloc_proberesp(bss, legacy);
2465 ieee80211_free_node(bss);
2469 M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT);
2470 KASSERT(m != NULL, ("no room for header"));
2472 wh = mtod(m, struct ieee80211_frame *);
2473 ieee80211_send_setup(bss, m,
2474 IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_RESP,
2475 IEEE80211_NONQOS_TID, vap->iv_myaddr, da, bss->ni_bssid);
2476 /* XXX power management? */
2477 m->m_flags |= M_ENCAP; /* mark encapsulated */
2479 M_WME_SETAC(m, WME_AC_BE);
2481 IEEE80211_DPRINTF(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_DUMPPKTS,
2482 "send probe resp on channel %u to %s%s\n",
2483 ieee80211_chan2ieee(ic, ic->ic_curchan), ether_sprintf(da),
2484 legacy ? " <legacy>" : "");
2485 IEEE80211_NODE_STAT(bss, tx_mgmt);
2487 return ic->ic_raw_xmit(bss, m, NULL);
2491 * Allocate and build a RTS (Request To Send) control frame.
2494 ieee80211_alloc_rts(struct ieee80211com *ic,
2495 const uint8_t ra[IEEE80211_ADDR_LEN],
2496 const uint8_t ta[IEEE80211_ADDR_LEN],
2499 struct ieee80211_frame_rts *rts;
2502 /* XXX honor ic_headroom */
2503 m = m_gethdr(M_DONTWAIT, MT_DATA);
2505 rts = mtod(m, struct ieee80211_frame_rts *);
2506 rts->i_fc[0] = IEEE80211_FC0_VERSION_0 |
2507 IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_RTS;
2508 rts->i_fc[1] = IEEE80211_FC1_DIR_NODS;
2509 *(u_int16_t *)rts->i_dur = htole16(dur);
2510 IEEE80211_ADDR_COPY(rts->i_ra, ra);
2511 IEEE80211_ADDR_COPY(rts->i_ta, ta);
2513 m->m_pkthdr.len = m->m_len = sizeof(struct ieee80211_frame_rts);
2519 * Allocate and build a CTS (Clear To Send) control frame.
2522 ieee80211_alloc_cts(struct ieee80211com *ic,
2523 const uint8_t ra[IEEE80211_ADDR_LEN], uint16_t dur)
2525 struct ieee80211_frame_cts *cts;
2528 /* XXX honor ic_headroom */
2529 m = m_gethdr(M_DONTWAIT, MT_DATA);
2531 cts = mtod(m, struct ieee80211_frame_cts *);
2532 cts->i_fc[0] = IEEE80211_FC0_VERSION_0 |
2533 IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_CTS;
2534 cts->i_fc[1] = IEEE80211_FC1_DIR_NODS;
2535 *(u_int16_t *)cts->i_dur = htole16(dur);
2536 IEEE80211_ADDR_COPY(cts->i_ra, ra);
2538 m->m_pkthdr.len = m->m_len = sizeof(struct ieee80211_frame_cts);
2544 ieee80211_tx_mgt_timeout(void *arg)
2546 struct ieee80211_node *ni = arg;
2547 struct ieee80211vap *vap = ni->ni_vap;
2549 if (vap->iv_state != IEEE80211_S_INIT &&
2550 (vap->iv_ic->ic_flags & IEEE80211_F_SCAN) == 0) {
2552 * NB: it's safe to specify a timeout as the reason here;
2553 * it'll only be used in the right state.
2555 ieee80211_new_state(vap, IEEE80211_S_SCAN,
2556 IEEE80211_SCAN_FAIL_TIMEOUT);
2561 ieee80211_tx_mgt_cb(struct ieee80211_node *ni, void *arg, int status)
2563 struct ieee80211vap *vap = ni->ni_vap;
2564 enum ieee80211_state ostate = (enum ieee80211_state) arg;
2567 * Frame transmit completed; arrange timer callback. If
2568 * transmit was successfuly we wait for response. Otherwise
2569 * we arrange an immediate callback instead of doing the
2570 * callback directly since we don't know what state the driver
2571 * is in (e.g. what locks it is holding). This work should
2572 * not be too time-critical and not happen too often so the
2573 * added overhead is acceptable.
2575 * XXX what happens if !acked but response shows up before callback?
2577 if (vap->iv_state == ostate)
2578 callout_reset(&vap->iv_mgtsend,
2579 status == 0 ? IEEE80211_TRANS_WAIT*hz : 0,
2580 ieee80211_tx_mgt_timeout, ni);
2584 ieee80211_beacon_construct(struct mbuf *m, uint8_t *frm,
2585 struct ieee80211_beacon_offsets *bo, struct ieee80211_node *ni)
2587 struct ieee80211vap *vap = ni->ni_vap;
2588 struct ieee80211com *ic = ni->ni_ic;
2589 struct ieee80211_rateset *rs = &ni->ni_rates;
2593 * beacon frame format
2595 * [2] beacon interval
2596 * [2] cabability information
2598 * [tlv] supported rates
2599 * [3] parameter set (DS)
2600 * [8] CF parameter set (optional)
2601 * [tlv] parameter set (IBSS/TIM)
2602 * [tlv] country (optional)
2603 * [3] power control (optional)
2604 * [5] channel switch announcement (CSA) (optional)
2605 * [tlv] extended rate phy (ERP)
2606 * [tlv] extended supported rates
2607 * [tlv] RSN parameters
2608 * [tlv] HT capabilities
2609 * [tlv] HT information
2610 * XXX Vendor-specific OIDs (e.g. Atheros)
2611 * [tlv] WPA parameters
2612 * [tlv] WME parameters
2613 * [tlv] Vendor OUI HT capabilities (optional)
2614 * [tlv] Vendor OUI HT information (optional)
2615 * [tlv] Atheros capabilities (optional)
2616 * [tlv] TDMA parameters (optional)
2617 * [tlv] Mesh ID (MBSS)
2618 * [tlv] Mesh Conf (MBSS)
2619 * [tlv] application data (optional)
2622 memset(bo, 0, sizeof(*bo));
2624 memset(frm, 0, 8); /* XXX timestamp is set by hardware/driver */
2626 *(uint16_t *)frm = htole16(ni->ni_intval);
2628 capinfo = ieee80211_getcapinfo(vap, ni->ni_chan);
2629 bo->bo_caps = (uint16_t *)frm;
2630 *(uint16_t *)frm = htole16(capinfo);
2632 *frm++ = IEEE80211_ELEMID_SSID;
2633 if ((vap->iv_flags & IEEE80211_F_HIDESSID) == 0) {
2634 *frm++ = ni->ni_esslen;
2635 memcpy(frm, ni->ni_essid, ni->ni_esslen);
2636 frm += ni->ni_esslen;
2639 frm = ieee80211_add_rates(frm, rs);
2640 if (!IEEE80211_IS_CHAN_FHSS(ni->ni_chan)) {
2641 *frm++ = IEEE80211_ELEMID_DSPARMS;
2643 *frm++ = ieee80211_chan2ieee(ic, ni->ni_chan);
2645 if (ic->ic_flags & IEEE80211_F_PCF) {
2647 frm = ieee80211_add_cfparms(frm, ic);
2650 if (vap->iv_opmode == IEEE80211_M_IBSS) {
2651 *frm++ = IEEE80211_ELEMID_IBSSPARMS;
2653 *frm++ = 0; *frm++ = 0; /* TODO: ATIM window */
2655 } else if (vap->iv_opmode == IEEE80211_M_HOSTAP ||
2656 vap->iv_opmode == IEEE80211_M_MBSS) {
2657 /* TIM IE is the same for Mesh and Hostap */
2658 struct ieee80211_tim_ie *tie = (struct ieee80211_tim_ie *) frm;
2660 tie->tim_ie = IEEE80211_ELEMID_TIM;
2661 tie->tim_len = 4; /* length */
2662 tie->tim_count = 0; /* DTIM count */
2663 tie->tim_period = vap->iv_dtim_period; /* DTIM period */
2664 tie->tim_bitctl = 0; /* bitmap control */
2665 tie->tim_bitmap[0] = 0; /* Partial Virtual Bitmap */
2666 frm += sizeof(struct ieee80211_tim_ie);
2669 bo->bo_tim_trailer = frm;
2670 if ((vap->iv_flags & IEEE80211_F_DOTH) ||
2671 (vap->iv_flags_ext & IEEE80211_FEXT_DOTD))
2672 frm = ieee80211_add_countryie(frm, ic);
2673 if (vap->iv_flags & IEEE80211_F_DOTH) {
2674 if (IEEE80211_IS_CHAN_5GHZ(ni->ni_chan))
2675 frm = ieee80211_add_powerconstraint(frm, vap);
2677 if (ic->ic_flags & IEEE80211_F_CSAPENDING)
2678 frm = ieee80211_add_csa(frm, vap);
2682 if (vap->iv_flags & IEEE80211_F_DOTH) {
2684 if (IEEE80211_IS_CHAN_DFS(ic->ic_bsschan) &&
2685 (vap->iv_flags_ext & IEEE80211_FEXT_DFS)) {
2687 frm = ieee80211_add_quiet(frm,vap);
2692 if (IEEE80211_IS_CHAN_ANYG(ni->ni_chan)) {
2694 frm = ieee80211_add_erp(frm, ic);
2696 frm = ieee80211_add_xrates(frm, rs);
2697 if (vap->iv_flags & IEEE80211_F_WPA2) {
2698 if (vap->iv_rsn_ie != NULL)
2699 frm = add_ie(frm, vap->iv_rsn_ie);
2700 /* XXX else complain */
2702 if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) {
2703 frm = ieee80211_add_htcap(frm, ni);
2704 bo->bo_htinfo = frm;
2705 frm = ieee80211_add_htinfo(frm, ni);
2707 if (vap->iv_flags & IEEE80211_F_WPA1) {
2708 if (vap->iv_wpa_ie != NULL)
2709 frm = add_ie(frm, vap->iv_wpa_ie);
2710 /* XXX else complain */
2712 if (vap->iv_flags & IEEE80211_F_WME) {
2714 frm = ieee80211_add_wme_param(frm, &ic->ic_wme);
2716 if (IEEE80211_IS_CHAN_HT(ni->ni_chan) &&
2717 (vap->iv_flags_ht & IEEE80211_FHT_HTCOMPAT)) {
2718 frm = ieee80211_add_htcap_vendor(frm, ni);
2719 frm = ieee80211_add_htinfo_vendor(frm, ni);
2721 #ifdef IEEE80211_SUPPORT_SUPERG
2722 if (vap->iv_flags & IEEE80211_F_ATHEROS) {
2724 frm = ieee80211_add_athcaps(frm, ni);
2727 #ifdef IEEE80211_SUPPORT_TDMA
2728 if (vap->iv_caps & IEEE80211_C_TDMA) {
2730 frm = ieee80211_add_tdma(frm, vap);
2733 if (vap->iv_appie_beacon != NULL) {
2735 bo->bo_appie_len = vap->iv_appie_beacon->ie_len;
2736 frm = add_appie(frm, vap->iv_appie_beacon);
2738 #ifdef IEEE80211_SUPPORT_MESH
2739 if (vap->iv_opmode == IEEE80211_M_MBSS) {
2740 frm = ieee80211_add_meshid(frm, vap);
2741 bo->bo_meshconf = frm;
2742 frm = ieee80211_add_meshconf(frm, vap);
2745 bo->bo_tim_trailer_len = frm - bo->bo_tim_trailer;
2746 bo->bo_csa_trailer_len = frm - bo->bo_csa;
2747 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2751 * Allocate a beacon frame and fillin the appropriate bits.
2754 ieee80211_beacon_alloc(struct ieee80211_node *ni,
2755 struct ieee80211_beacon_offsets *bo)
2757 struct ieee80211vap *vap = ni->ni_vap;
2758 struct ieee80211com *ic = ni->ni_ic;
2759 struct ifnet *ifp = vap->iv_ifp;
2760 struct ieee80211_frame *wh;
2766 * beacon frame format
2768 * [2] beacon interval
2769 * [2] cabability information
2771 * [tlv] supported rates
2772 * [3] parameter set (DS)
2773 * [8] CF parameter set (optional)
2774 * [tlv] parameter set (IBSS/TIM)
2775 * [tlv] country (optional)
2776 * [3] power control (optional)
2777 * [5] channel switch announcement (CSA) (optional)
2778 * [tlv] extended rate phy (ERP)
2779 * [tlv] extended supported rates
2780 * [tlv] RSN parameters
2781 * [tlv] HT capabilities
2782 * [tlv] HT information
2783 * [tlv] Vendor OUI HT capabilities (optional)
2784 * [tlv] Vendor OUI HT information (optional)
2785 * XXX Vendor-specific OIDs (e.g. Atheros)
2786 * [tlv] WPA parameters
2787 * [tlv] WME parameters
2788 * [tlv] TDMA parameters (optional)
2789 * [tlv] Mesh ID (MBSS)
2790 * [tlv] Mesh Conf (MBSS)
2791 * [tlv] application data (optional)
2792 * NB: we allocate the max space required for the TIM bitmap.
2793 * XXX how big is this?
2795 pktlen = 8 /* time stamp */
2796 + sizeof(uint16_t) /* beacon interval */
2797 + sizeof(uint16_t) /* capabilities */
2798 + 2 + ni->ni_esslen /* ssid */
2799 + 2 + IEEE80211_RATE_SIZE /* supported rates */
2800 + 2 + 1 /* DS parameters */
2801 + 2 + 6 /* CF parameters */
2802 + 2 + 4 + vap->iv_tim_len /* DTIM/IBSSPARMS */
2803 + IEEE80211_COUNTRY_MAX_SIZE /* country */
2804 + 2 + 1 /* power control */
2805 + sizeof(struct ieee80211_csa_ie) /* CSA */
2806 + sizeof(struct ieee80211_quiet_ie) /* Quiet */
2808 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
2809 + (vap->iv_caps & IEEE80211_C_WPA ? /* WPA 1+2 */
2810 2*sizeof(struct ieee80211_ie_wpa) : 0)
2811 /* XXX conditional? */
2812 + 4+2*sizeof(struct ieee80211_ie_htcap)/* HT caps */
2813 + 4+2*sizeof(struct ieee80211_ie_htinfo)/* HT info */
2814 + (vap->iv_caps & IEEE80211_C_WME ? /* WME */
2815 sizeof(struct ieee80211_wme_param) : 0)
2816 #ifdef IEEE80211_SUPPORT_SUPERG
2817 + sizeof(struct ieee80211_ath_ie) /* ATH */
2819 #ifdef IEEE80211_SUPPORT_TDMA
2820 + (vap->iv_caps & IEEE80211_C_TDMA ? /* TDMA */
2821 sizeof(struct ieee80211_tdma_param) : 0)
2823 #ifdef IEEE80211_SUPPORT_MESH
2824 + 2 + ni->ni_meshidlen
2825 + sizeof(struct ieee80211_meshconf_ie)
2827 + IEEE80211_MAX_APPIE
2829 m = ieee80211_getmgtframe(&frm,
2830 ic->ic_headroom + sizeof(struct ieee80211_frame), pktlen);
2832 IEEE80211_DPRINTF(vap, IEEE80211_MSG_ANY,
2833 "%s: cannot get buf; size %u\n", __func__, pktlen);
2834 vap->iv_stats.is_tx_nobuf++;
2837 ieee80211_beacon_construct(m, frm, bo, ni);
2839 M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT);
2840 KASSERT(m != NULL, ("no space for 802.11 header?"));
2841 wh = mtod(m, struct ieee80211_frame *);
2842 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT |
2843 IEEE80211_FC0_SUBTYPE_BEACON;
2844 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
2845 *(uint16_t *)wh->i_dur = 0;
2846 IEEE80211_ADDR_COPY(wh->i_addr1, ifp->if_broadcastaddr);
2847 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
2848 IEEE80211_ADDR_COPY(wh->i_addr3, ni->ni_bssid);
2849 *(uint16_t *)wh->i_seq = 0;
2855 * Update the dynamic parts of a beacon frame based on the current state.
2858 ieee80211_beacon_update(struct ieee80211_node *ni,
2859 struct ieee80211_beacon_offsets *bo, struct mbuf *m, int mcast)
2861 struct ieee80211vap *vap = ni->ni_vap;
2862 struct ieee80211com *ic = ni->ni_ic;
2863 int len_changed = 0;
2865 struct ieee80211_frame *wh;
2866 ieee80211_seq seqno;
2870 * Handle 11h channel change when we've reached the count.
2871 * We must recalculate the beacon frame contents to account
2872 * for the new channel. Note we do this only for the first
2873 * vap that reaches this point; subsequent vaps just update
2874 * their beacon state to reflect the recalculated channel.
2876 if (isset(bo->bo_flags, IEEE80211_BEACON_CSA) &&
2877 vap->iv_csa_count == ic->ic_csa_count) {
2878 vap->iv_csa_count = 0;
2880 * Effect channel change before reconstructing the beacon
2881 * frame contents as many places reference ni_chan.
2883 if (ic->ic_csa_newchan != NULL)
2884 ieee80211_csa_completeswitch(ic);
2886 * NB: ieee80211_beacon_construct clears all pending
2887 * updates in bo_flags so we don't need to explicitly
2888 * clear IEEE80211_BEACON_CSA.
2890 ieee80211_beacon_construct(m,
2891 mtod(m, uint8_t*) + sizeof(struct ieee80211_frame), bo, ni);
2893 /* XXX do WME aggressive mode processing? */
2894 IEEE80211_UNLOCK(ic);
2895 return 1; /* just assume length changed */
2898 wh = mtod(m, struct ieee80211_frame *);
2899 seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]++;
2900 *(uint16_t *)&wh->i_seq[0] =
2901 htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT);
2902 M_SEQNO_SET(m, seqno);
2904 /* XXX faster to recalculate entirely or just changes? */
2905 capinfo = ieee80211_getcapinfo(vap, ni->ni_chan);
2906 *bo->bo_caps = htole16(capinfo);
2908 if (vap->iv_flags & IEEE80211_F_WME) {
2909 struct ieee80211_wme_state *wme = &ic->ic_wme;
2912 * Check for agressive mode change. When there is
2913 * significant high priority traffic in the BSS
2914 * throttle back BE traffic by using conservative
2915 * parameters. Otherwise BE uses agressive params
2916 * to optimize performance of legacy/non-QoS traffic.
2918 if (wme->wme_flags & WME_F_AGGRMODE) {
2919 if (wme->wme_hipri_traffic >
2920 wme->wme_hipri_switch_thresh) {
2921 IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME,
2922 "%s: traffic %u, disable aggressive mode\n",
2923 __func__, wme->wme_hipri_traffic);
2924 wme->wme_flags &= ~WME_F_AGGRMODE;
2925 ieee80211_wme_updateparams_locked(vap);
2926 wme->wme_hipri_traffic =
2927 wme->wme_hipri_switch_hysteresis;
2929 wme->wme_hipri_traffic = 0;
2931 if (wme->wme_hipri_traffic <=
2932 wme->wme_hipri_switch_thresh) {
2933 IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME,
2934 "%s: traffic %u, enable aggressive mode\n",
2935 __func__, wme->wme_hipri_traffic);
2936 wme->wme_flags |= WME_F_AGGRMODE;
2937 ieee80211_wme_updateparams_locked(vap);
2938 wme->wme_hipri_traffic = 0;
2940 wme->wme_hipri_traffic =
2941 wme->wme_hipri_switch_hysteresis;
2943 if (isset(bo->bo_flags, IEEE80211_BEACON_WME)) {
2944 (void) ieee80211_add_wme_param(bo->bo_wme, wme);
2945 clrbit(bo->bo_flags, IEEE80211_BEACON_WME);
2949 if (isset(bo->bo_flags, IEEE80211_BEACON_HTINFO)) {
2950 ieee80211_ht_update_beacon(vap, bo);
2951 clrbit(bo->bo_flags, IEEE80211_BEACON_HTINFO);
2953 #ifdef IEEE80211_SUPPORT_TDMA
2954 if (vap->iv_caps & IEEE80211_C_TDMA) {
2956 * NB: the beacon is potentially updated every TBTT.
2958 ieee80211_tdma_update_beacon(vap, bo);
2961 #ifdef IEEE80211_SUPPORT_MESH
2962 if (vap->iv_opmode == IEEE80211_M_MBSS)
2963 ieee80211_mesh_update_beacon(vap, bo);
2966 if (vap->iv_opmode == IEEE80211_M_HOSTAP ||
2967 vap->iv_opmode == IEEE80211_M_MBSS) { /* NB: no IBSS support*/
2968 struct ieee80211_tim_ie *tie =
2969 (struct ieee80211_tim_ie *) bo->bo_tim;
2970 if (isset(bo->bo_flags, IEEE80211_BEACON_TIM)) {
2971 u_int timlen, timoff, i;
2973 * ATIM/DTIM needs updating. If it fits in the
2974 * current space allocated then just copy in the
2975 * new bits. Otherwise we need to move any trailing
2976 * data to make room. Note that we know there is
2977 * contiguous space because ieee80211_beacon_allocate
2978 * insures there is space in the mbuf to write a
2979 * maximal-size virtual bitmap (based on iv_max_aid).
2982 * Calculate the bitmap size and offset, copy any
2983 * trailer out of the way, and then copy in the
2984 * new bitmap and update the information element.
2985 * Note that the tim bitmap must contain at least
2986 * one byte and any offset must be even.
2988 if (vap->iv_ps_pending != 0) {
2989 timoff = 128; /* impossibly large */
2990 for (i = 0; i < vap->iv_tim_len; i++)
2991 if (vap->iv_tim_bitmap[i]) {
2995 KASSERT(timoff != 128, ("tim bitmap empty!"));
2996 for (i = vap->iv_tim_len-1; i >= timoff; i--)
2997 if (vap->iv_tim_bitmap[i])
2999 timlen = 1 + (i - timoff);
3004 if (timlen != bo->bo_tim_len) {
3005 /* copy up/down trailer */
3006 int adjust = tie->tim_bitmap+timlen
3007 - bo->bo_tim_trailer;
3008 ovbcopy(bo->bo_tim_trailer,
3009 bo->bo_tim_trailer+adjust,
3010 bo->bo_tim_trailer_len);
3011 bo->bo_tim_trailer += adjust;
3012 bo->bo_erp += adjust;
3013 bo->bo_htinfo += adjust;
3014 #ifdef IEEE80211_SUPPORT_SUPERG
3015 bo->bo_ath += adjust;
3017 #ifdef IEEE80211_SUPPORT_TDMA
3018 bo->bo_tdma += adjust;
3020 #ifdef IEEE80211_SUPPORT_MESH
3021 bo->bo_meshconf += adjust;
3023 bo->bo_appie += adjust;
3024 bo->bo_wme += adjust;
3025 bo->bo_csa += adjust;
3026 bo->bo_quiet += adjust;
3027 bo->bo_tim_len = timlen;
3029 /* update information element */
3030 tie->tim_len = 3 + timlen;
3031 tie->tim_bitctl = timoff;
3034 memcpy(tie->tim_bitmap, vap->iv_tim_bitmap + timoff,
3037 clrbit(bo->bo_flags, IEEE80211_BEACON_TIM);
3039 IEEE80211_DPRINTF(vap, IEEE80211_MSG_POWER,
3040 "%s: TIM updated, pending %u, off %u, len %u\n",
3041 __func__, vap->iv_ps_pending, timoff, timlen);
3043 /* count down DTIM period */
3044 if (tie->tim_count == 0)
3045 tie->tim_count = tie->tim_period - 1;
3048 /* update state for buffered multicast frames on DTIM */
3049 if (mcast && tie->tim_count == 0)
3050 tie->tim_bitctl |= 1;
3052 tie->tim_bitctl &= ~1;
3053 if (isset(bo->bo_flags, IEEE80211_BEACON_CSA)) {
3054 struct ieee80211_csa_ie *csa =
3055 (struct ieee80211_csa_ie *) bo->bo_csa;
3058 * Insert or update CSA ie. If we're just starting
3059 * to count down to the channel switch then we need
3060 * to insert the CSA ie. Otherwise we just need to
3061 * drop the count. The actual change happens above
3062 * when the vap's count reaches the target count.
3064 if (vap->iv_csa_count == 0) {
3065 memmove(&csa[1], csa, bo->bo_csa_trailer_len);
3066 bo->bo_erp += sizeof(*csa);
3067 bo->bo_htinfo += sizeof(*csa);
3068 bo->bo_wme += sizeof(*csa);
3069 #ifdef IEEE80211_SUPPORT_SUPERG
3070 bo->bo_ath += sizeof(*csa);
3072 #ifdef IEEE80211_SUPPORT_TDMA
3073 bo->bo_tdma += sizeof(*csa);
3075 #ifdef IEEE80211_SUPPORT_MESH
3076 bo->bo_meshconf += sizeof(*csa);
3078 bo->bo_appie += sizeof(*csa);
3079 bo->bo_csa_trailer_len += sizeof(*csa);
3080 bo->bo_quiet += sizeof(*csa);
3081 bo->bo_tim_trailer_len += sizeof(*csa);
3082 m->m_len += sizeof(*csa);
3083 m->m_pkthdr.len += sizeof(*csa);
3085 ieee80211_add_csa(bo->bo_csa, vap);
3088 vap->iv_csa_count++;
3089 /* NB: don't clear IEEE80211_BEACON_CSA */
3091 if (IEEE80211_IS_CHAN_DFS(ic->ic_bsschan) &&
3092 (vap->iv_flags_ext & IEEE80211_FEXT_DFS) ){
3094 ieee80211_add_quiet(bo->bo_quiet, vap);
3096 if (isset(bo->bo_flags, IEEE80211_BEACON_ERP)) {
3098 * ERP element needs updating.
3100 (void) ieee80211_add_erp(bo->bo_erp, ic);
3101 clrbit(bo->bo_flags, IEEE80211_BEACON_ERP);
3103 #ifdef IEEE80211_SUPPORT_SUPERG
3104 if (isset(bo->bo_flags, IEEE80211_BEACON_ATH)) {
3105 ieee80211_add_athcaps(bo->bo_ath, ni);
3106 clrbit(bo->bo_flags, IEEE80211_BEACON_ATH);
3110 if (isset(bo->bo_flags, IEEE80211_BEACON_APPIE)) {
3111 const struct ieee80211_appie *aie = vap->iv_appie_beacon;
3117 aielen += aie->ie_len;
3118 if (aielen != bo->bo_appie_len) {
3119 /* copy up/down trailer */
3120 int adjust = aielen - bo->bo_appie_len;
3121 ovbcopy(bo->bo_tim_trailer, bo->bo_tim_trailer+adjust,
3122 bo->bo_tim_trailer_len);
3123 bo->bo_tim_trailer += adjust;
3124 bo->bo_appie += adjust;
3125 bo->bo_appie_len = aielen;
3131 frm = add_appie(frm, aie);
3132 clrbit(bo->bo_flags, IEEE80211_BEACON_APPIE);
3134 IEEE80211_UNLOCK(ic);