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.
26 * $FreeBSD: head/sys/net80211/ieee80211_output.c 198384 2009-10-23 11:13:08Z rpaulo $
30 #include "opt_inet6.h"
33 #include <sys/param.h>
34 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/endian.h>
39 #include <sys/socket.h>
42 #include <net/ethernet.h>
43 #include <net/route.h>
45 #include <net/if_llc.h>
46 #include <net/if_media.h>
47 #include <net/ifq_var.h>
49 #include <netproto/802_11/ieee80211_var.h>
50 #include <netproto/802_11/ieee80211_regdomain.h>
51 #ifdef IEEE80211_SUPPORT_SUPERG
52 #include <netproto/802_11/ieee80211_superg.h>
54 #ifdef IEEE80211_SUPPORT_TDMA
55 #include <netproto/802_11/ieee80211_tdma.h>
57 #include <netproto/802_11/ieee80211_wds.h>
58 #include <netproto/802_11/ieee80211_mesh.h>
61 #include <netinet/in.h>
62 #include <netinet/if_ether.h>
63 #include <netinet/in_systm.h>
64 #include <netinet/ip.h>
67 #include <netinet/ip6.h>
70 #define ETHER_HEADER_COPY(dst, src) \
71 memcpy(dst, src, sizeof(struct ether_header))
73 /* unalligned little endian access */
74 #define LE_WRITE_2(p, v) do { \
75 ((uint8_t *)(p))[0] = (v) & 0xff; \
76 ((uint8_t *)(p))[1] = ((v) >> 8) & 0xff; \
78 #define LE_WRITE_4(p, v) do { \
79 ((uint8_t *)(p))[0] = (v) & 0xff; \
80 ((uint8_t *)(p))[1] = ((v) >> 8) & 0xff; \
81 ((uint8_t *)(p))[2] = ((v) >> 16) & 0xff; \
82 ((uint8_t *)(p))[3] = ((v) >> 24) & 0xff; \
85 static int ieee80211_fragment(struct ieee80211vap *, struct mbuf *,
86 u_int hdrsize, u_int ciphdrsize, u_int mtu);
87 static void ieee80211_tx_mgt_cb(struct ieee80211_node *, void *, int);
89 #ifdef IEEE80211_DEBUG
91 * Decide if an outbound management frame should be
92 * printed when debugging is enabled. This filters some
93 * of the less interesting frames that come frequently
97 doprint(struct ieee80211vap *vap, int subtype)
100 case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
101 return (vap->iv_opmode == IEEE80211_M_IBSS);
108 * Start method for vap's. All packets from the stack come
109 * through here. We handle common processing of the packets
110 * before dispatching them to the underlying device.
113 ieee80211_start(struct ifnet *ifp, struct ifaltq_subque *ifsq)
115 #define IS_DWDS(vap) \
116 (vap->iv_opmode == IEEE80211_M_WDS && \
117 (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY) == 0)
118 struct ieee80211vap *vap = ifp->if_softc;
119 struct ieee80211com *ic = vap->iv_ic;
120 struct ifnet *parent = ic->ic_ifp;
121 struct ieee80211_node *ni;
122 struct mbuf *m = NULL;
123 struct ether_header *eh;
126 wlan_assert_serialized();
127 ASSERT_ALTQ_SQ_DEFAULT(ifp, ifsq);
129 /* NB: parent must be up and running */
130 if (!IFNET_IS_UP_RUNNING(parent)) {
131 IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
132 "%s: ignore queue, parent %s not up+running\n",
133 __func__, parent->if_xname);
139 * No data frames go out unless we're running.
140 * Note in particular this covers CAC and CSA
141 * states (though maybe we should check muting
144 if (vap->iv_state != IEEE80211_S_RUN &&
145 vap->iv_state != IEEE80211_S_SLEEP) {
146 /* re-check under the com lock to avoid races */
147 if (vap->iv_state != IEEE80211_S_RUN &&
148 vap->iv_state != IEEE80211_S_SLEEP) {
149 IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
150 "%s: ignore queue, in %s state\n",
151 __func__, ieee80211_state_name[vap->iv_state]);
152 vap->iv_stats.is_tx_badstate++;
153 ifsq_set_oactive(ifsq);
158 m = ifsq_dequeue(ifsq);
162 * Sanitize mbuf flags for net80211 use. We cannot
163 * clear M_PWR_SAV or M_MORE_DATA because these may
164 * be set for frames that are re-submitted from the
167 * NB: This must be done before ieee80211_classify as
168 * it marks EAPOL in frames with M_EAPOL.
170 m->m_flags &= ~(M_80211_TX - M_PWR_SAV - M_MORE_DATA);
172 * Cancel any background scan.
174 if (ic->ic_flags & IEEE80211_F_SCAN)
175 ieee80211_cancel_anyscan(vap);
177 * Find the node for the destination so we can do
178 * things like power save and fast frames aggregation.
180 * NB: past this point various code assumes the first
181 * mbuf has the 802.3 header present (and contiguous).
184 if (m->m_len < sizeof(struct ether_header) &&
185 (m = m_pullup(m, sizeof(struct ether_header))) == NULL) {
186 IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
187 "discard frame, %s\n", "m_pullup failed");
188 vap->iv_stats.is_tx_nobuf++; /* XXX */
189 IFNET_STAT_INC(ifp, oerrors, 1);
192 eh = mtod(m, struct ether_header *);
193 if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
196 * Only unicast frames from the above go out
197 * DWDS vaps; multicast frames are handled by
198 * dispatching the frame as it comes through
199 * the AP vap (see below).
201 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_WDS,
202 eh->ether_dhost, "mcast", "%s", "on DWDS");
203 vap->iv_stats.is_dwds_mcast++;
207 if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
209 * Spam DWDS vap's w/ multicast traffic.
211 /* XXX only if dwds in use? */
212 ieee80211_dwds_mcast(vap, m);
215 #ifdef IEEE80211_SUPPORT_MESH
216 if (vap->iv_opmode != IEEE80211_M_MBSS) {
218 ni = ieee80211_find_txnode(vap, eh->ether_dhost);
220 /* NB: ieee80211_find_txnode does stat+msg */
221 IFNET_STAT_INC(ifp, oerrors, 1);
225 if (ni->ni_associd == 0 &&
226 (ni->ni_flags & IEEE80211_NODE_ASSOCID)) {
227 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_OUTPUT,
228 eh->ether_dhost, NULL,
229 "sta not associated (type 0x%04x)",
230 htons(eh->ether_type));
231 vap->iv_stats.is_tx_notassoc++;
232 IFNET_STAT_INC(ifp, oerrors, 1);
234 ieee80211_free_node(ni);
237 #ifdef IEEE80211_SUPPORT_MESH
239 if (!IEEE80211_ADDR_EQ(eh->ether_shost, vap->iv_myaddr)) {
241 * Proxy station only if configured.
243 if (!ieee80211_mesh_isproxyena(vap)) {
244 IEEE80211_DISCARD_MAC(vap,
245 IEEE80211_MSG_OUTPUT |
247 eh->ether_dhost, NULL,
248 "%s", "proxy not enabled");
249 vap->iv_stats.is_mesh_notproxy++;
250 IFNET_STAT_INC(ifp, oerrors, 1);
254 ieee80211_mesh_proxy_check(vap, eh->ether_shost);
256 ni = ieee80211_mesh_discover(vap, eh->ether_dhost, m);
259 * NB: ieee80211_mesh_discover holds/disposes
260 * frame (e.g. queueing on path discovery).
262 IFNET_STAT_INC(ifp, oerrors, 1);
268 * We've resolved the sender, so attempt to transmit it.
270 if (vap->iv_state == IEEE80211_S_SLEEP) {
272 * In power save; queue frame and then wakeup device
275 ic->ic_lastdata = ticks;
276 (void) ieee80211_pwrsave(ni, m);
277 ieee80211_free_node(ni);
278 ieee80211_new_state(vap, IEEE80211_S_RUN, 0);
282 if ((ni->ni_flags & IEEE80211_NODE_PWR_MGT) &&
283 (m->m_flags & M_PWR_SAV) == 0) {
285 * Station in power save mode; pass the frame
286 * to the 802.11 layer and continue. We'll get
287 * the frame back when the time is right.
288 * XXX lose WDS vap linkage?
290 (void) ieee80211_pwrsave(ni, m);
291 ieee80211_free_node(ni);
294 /* calculate priority so drivers can find the tx queue */
295 if (ieee80211_classify(ni, m)) {
296 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_OUTPUT,
297 eh->ether_dhost, NULL,
298 "%s", "classification failure");
299 vap->iv_stats.is_tx_classify++;
300 IFNET_STAT_INC(ifp, oerrors, 1);
302 ieee80211_free_node(ni);
306 * Stash the node pointer. Note that we do this after
307 * any call to ieee80211_dwds_mcast because that code
308 * uses any existing value for rcvif to identify the
309 * interface it (might have been) received on.
311 m->m_pkthdr.rcvif = (void *)ni;
313 BPF_MTAP(ifp, m); /* 802.3 tx */
316 * Check if A-MPDU tx aggregation is setup or if we
317 * should try to enable it. The sta must be associated
318 * with HT and A-MPDU enabled for use. When the policy
319 * routine decides we should enable A-MPDU we issue an
320 * ADDBA request and wait for a reply. The frame being
321 * encapsulated will go out w/o using A-MPDU, or possibly
322 * it might be collected by the driver and held/retransmit.
323 * The default ic_ampdu_enable routine handles staggering
324 * ADDBA requests in case the receiver NAK's us or we are
325 * otherwise unable to establish a BA stream.
327 if ((ni->ni_flags & IEEE80211_NODE_AMPDU_TX) &&
328 (vap->iv_flags_ht & IEEE80211_FHT_AMPDU_TX) &&
329 (m->m_flags & M_EAPOL) == 0) {
330 const int ac = M_WME_GETAC(m);
331 struct ieee80211_tx_ampdu *tap = &ni->ni_tx_ampdu[ac];
333 ieee80211_txampdu_count_packet(tap);
334 if (IEEE80211_AMPDU_RUNNING(tap)) {
336 * Operational, mark frame for aggregation.
338 * XXX do tx aggregation here
340 m->m_flags |= M_AMPDU_MPDU;
341 } else if (!IEEE80211_AMPDU_REQUESTED(tap) &&
342 ic->ic_ampdu_enable(ni, tap)) {
344 * Not negotiated yet, request service.
346 ieee80211_ampdu_request(ni, tap);
347 /* XXX hold frame for reply? */
350 #ifdef IEEE80211_SUPPORT_SUPERG
351 else if (IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_FF)) {
352 m = ieee80211_ff_check(ni, m);
354 /* NB: any ni ref held on stageq */
358 #endif /* IEEE80211_SUPPORT_SUPERG */
359 if (__predict_true((vap->iv_caps & IEEE80211_C_8023ENCAP) == 0)) {
361 * Encapsulate the packet in prep for transmission.
363 m = ieee80211_encap(vap, ni, m);
365 /* NB: stat+msg handled in ieee80211_encap */
366 ieee80211_free_node(ni);
371 error = ieee80211_handoff(parent, m);
373 /* NB: IFQ_HANDOFF reclaims mbuf */
374 ieee80211_free_node(ni);
376 IFNET_STAT_INC(ifp, opackets, 1);
378 ic->ic_lastdata = ticks;
385 * 802.11 output routine. This is (currently) used only to
386 * connect bpf write calls to the 802.11 layer for injecting
390 ieee80211_output(struct ifnet *ifp, struct mbuf *m,
391 struct sockaddr *dst, struct rtentry *rt)
393 #define senderr(e) do { error = (e); goto bad;} while (0)
394 struct ieee80211_node *ni = NULL;
395 struct ieee80211vap *vap;
396 struct ieee80211_frame *wh;
397 struct ifaltq_subque *ifsq;
400 ifsq = ifq_get_subq_default(&ifp->if_snd);
401 if (ifsq_is_oactive(ifsq)) {
403 * Short-circuit requests if the vap is marked OACTIVE
404 * as this can happen because a packet came down through
405 * ieee80211_start before the vap entered RUN state in
406 * which case it's ok to just drop the frame. This
407 * should not be necessary but callers of if_output don't
414 * Hand to the 802.3 code if not tagged as
415 * a raw 802.11 frame.
417 if (dst->sa_family != AF_IEEE80211)
418 return vap->iv_output(ifp, m, dst, rt);
420 error = mac_ifnet_check_transmit(ifp, m);
424 if (ifp->if_flags & IFF_MONITOR)
426 if (!IFNET_IS_UP_RUNNING(ifp))
428 if (vap->iv_state == IEEE80211_S_CAC) {
429 IEEE80211_DPRINTF(vap,
430 IEEE80211_MSG_OUTPUT | IEEE80211_MSG_DOTH,
431 "block %s frame in CAC state\n", "raw data");
432 vap->iv_stats.is_tx_badstate++;
433 senderr(EIO); /* XXX */
435 /* XXX bypass bridge, pfil, carp, etc. */
437 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame_ack))
438 senderr(EIO); /* XXX */
439 wh = mtod(m, struct ieee80211_frame *);
440 if ((wh->i_fc[0] & IEEE80211_FC0_VERSION_MASK) !=
441 IEEE80211_FC0_VERSION_0)
442 senderr(EIO); /* XXX */
444 /* locate destination node */
445 switch (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) {
446 case IEEE80211_FC1_DIR_NODS:
447 case IEEE80211_FC1_DIR_FROMDS:
448 ni = ieee80211_find_txnode(vap, wh->i_addr1);
450 case IEEE80211_FC1_DIR_TODS:
451 case IEEE80211_FC1_DIR_DSTODS:
452 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame))
453 senderr(EIO); /* XXX */
454 ni = ieee80211_find_txnode(vap, wh->i_addr3);
457 senderr(EIO); /* XXX */
461 * Permit packets w/ bpf params through regardless
462 * (see below about sa_len).
464 if (dst->sa_len == 0)
465 senderr(EHOSTUNREACH);
466 ni = ieee80211_ref_node(vap->iv_bss);
470 * Sanitize mbuf for net80211 flags leaked from above.
472 * NB: This must be done before ieee80211_classify as
473 * it marks EAPOL in frames with M_EAPOL.
475 m->m_flags &= ~M_80211_TX;
477 /* calculate priority so drivers can find the tx queue */
478 /* XXX assumes an 802.3 frame */
479 if (ieee80211_classify(ni, m))
480 senderr(EIO); /* XXX */
482 IFNET_STAT_INC(ifp, opackets, 1);
483 IEEE80211_NODE_STAT(ni, tx_data);
484 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
485 IEEE80211_NODE_STAT(ni, tx_mcast);
486 m->m_flags |= M_MCAST;
488 IEEE80211_NODE_STAT(ni, tx_ucast);
489 /* NB: ieee80211_encap does not include 802.11 header */
490 IEEE80211_NODE_STAT_ADD(ni, tx_bytes, m->m_pkthdr.len);
493 * NB: DLT_IEEE802_11_RADIO identifies the parameters are
494 * present by setting the sa_len field of the sockaddr (yes,
496 * NB: we assume sa_data is suitably aligned to cast.
498 return vap->iv_ic->ic_raw_xmit(ni, m,
499 (const struct ieee80211_bpf_params *)(dst->sa_len ?
500 dst->sa_data : NULL));
505 ieee80211_free_node(ni);
506 IFNET_STAT_INC(ifp, oerrors, 1);
512 * Set the direction field and address fields of an outgoing
513 * frame. Note this should be called early on in constructing
514 * a frame as it sets i_fc[1]; other bits can then be or'd in.
517 ieee80211_send_setup(
518 struct ieee80211_node *ni,
521 const uint8_t sa[IEEE80211_ADDR_LEN],
522 const uint8_t da[IEEE80211_ADDR_LEN],
523 const uint8_t bssid[IEEE80211_ADDR_LEN])
525 #define WH4(wh) ((struct ieee80211_frame_addr4 *)wh)
526 struct ieee80211vap *vap = ni->ni_vap;
527 struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
530 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | type;
531 if ((type & IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_DATA) {
532 switch (vap->iv_opmode) {
533 case IEEE80211_M_STA:
534 wh->i_fc[1] = IEEE80211_FC1_DIR_TODS;
535 IEEE80211_ADDR_COPY(wh->i_addr1, bssid);
536 IEEE80211_ADDR_COPY(wh->i_addr2, sa);
537 IEEE80211_ADDR_COPY(wh->i_addr3, da);
539 case IEEE80211_M_IBSS:
540 case IEEE80211_M_AHDEMO:
541 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
542 IEEE80211_ADDR_COPY(wh->i_addr1, da);
543 IEEE80211_ADDR_COPY(wh->i_addr2, sa);
544 IEEE80211_ADDR_COPY(wh->i_addr3, bssid);
546 case IEEE80211_M_HOSTAP:
547 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
548 IEEE80211_ADDR_COPY(wh->i_addr1, da);
549 IEEE80211_ADDR_COPY(wh->i_addr2, bssid);
550 IEEE80211_ADDR_COPY(wh->i_addr3, sa);
552 case IEEE80211_M_WDS:
553 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
554 IEEE80211_ADDR_COPY(wh->i_addr1, da);
555 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
556 IEEE80211_ADDR_COPY(wh->i_addr3, da);
557 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, sa);
559 case IEEE80211_M_MBSS:
560 #ifdef IEEE80211_SUPPORT_MESH
561 /* XXX add support for proxied addresses */
562 if (IEEE80211_IS_MULTICAST(da)) {
563 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
565 IEEE80211_ADDR_COPY(wh->i_addr1, da);
566 IEEE80211_ADDR_COPY(wh->i_addr2,
569 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
570 IEEE80211_ADDR_COPY(wh->i_addr1, da);
571 IEEE80211_ADDR_COPY(wh->i_addr2,
573 IEEE80211_ADDR_COPY(wh->i_addr3, da);
574 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, sa);
578 case IEEE80211_M_MONITOR: /* NB: to quiet compiler */
582 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
583 IEEE80211_ADDR_COPY(wh->i_addr1, da);
584 IEEE80211_ADDR_COPY(wh->i_addr2, sa);
585 #ifdef IEEE80211_SUPPORT_MESH
586 if (vap->iv_opmode == IEEE80211_M_MBSS)
587 IEEE80211_ADDR_COPY(wh->i_addr3, sa);
590 IEEE80211_ADDR_COPY(wh->i_addr3, bssid);
592 *(uint16_t *)&wh->i_dur[0] = 0;
594 seqno = ni->ni_txseqs[tid]++;
595 *(uint16_t *)&wh->i_seq[0] = htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT);
596 M_SEQNO_SET(m, seqno);
598 if (IEEE80211_IS_MULTICAST(wh->i_addr1))
599 m->m_flags |= M_MCAST;
604 * Send a management frame to the specified node. The node pointer
605 * must have a reference as the pointer will be passed to the driver
606 * and potentially held for a long time. If the frame is successfully
607 * dispatched to the driver, then it is responsible for freeing the
608 * reference (and potentially free'ing up any associated storage);
609 * otherwise deal with reclaiming any reference (on error).
612 ieee80211_mgmt_output(struct ieee80211_node *ni, struct mbuf *m, int type,
613 struct ieee80211_bpf_params *params)
615 struct ieee80211vap *vap = ni->ni_vap;
616 struct ieee80211com *ic = ni->ni_ic;
617 struct ieee80211_frame *wh;
618 #ifdef IEEE80211_DEBUG
619 char ethstr[ETHER_ADDRSTRLEN + 1];
621 KASSERT(ni != NULL, ("null node"));
623 if (vap->iv_state == IEEE80211_S_CAC) {
624 IEEE80211_NOTE(vap, IEEE80211_MSG_OUTPUT | IEEE80211_MSG_DOTH,
625 ni, "block %s frame in CAC state",
626 ieee80211_mgt_subtype_name[
627 (type & IEEE80211_FC0_SUBTYPE_MASK) >>
628 IEEE80211_FC0_SUBTYPE_SHIFT]);
629 vap->iv_stats.is_tx_badstate++;
630 ieee80211_free_node(ni);
632 return EIO; /* XXX */
635 M_PREPEND(m, sizeof(struct ieee80211_frame), MB_DONTWAIT);
637 ieee80211_free_node(ni);
641 wh = mtod(m, struct ieee80211_frame *);
642 ieee80211_send_setup(ni, m,
643 IEEE80211_FC0_TYPE_MGT | type, IEEE80211_NONQOS_TID,
644 vap->iv_myaddr, ni->ni_macaddr, ni->ni_bssid);
645 if (params->ibp_flags & IEEE80211_BPF_CRYPTO) {
646 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_AUTH, wh->i_addr1,
647 "encrypting frame (%s)", __func__);
648 wh->i_fc[1] |= IEEE80211_FC1_WEP;
650 m->m_flags |= M_ENCAP; /* mark encapsulated */
652 KASSERT(type != IEEE80211_FC0_SUBTYPE_PROBE_RESP, ("probe response?"));
653 M_WME_SETAC(m, params->ibp_pri);
655 #ifdef IEEE80211_DEBUG
656 /* avoid printing too many frames */
657 if ((ieee80211_msg_debug(vap) && doprint(vap, type)) ||
658 ieee80211_msg_dumppkts(vap)) {
659 kprintf("[%s] send %s on channel %u\n",
660 kether_ntoa(wh->i_addr1, ethstr),
661 ieee80211_mgt_subtype_name[
662 (type & IEEE80211_FC0_SUBTYPE_MASK) >>
663 IEEE80211_FC0_SUBTYPE_SHIFT],
664 ieee80211_chan2ieee(ic, ic->ic_curchan));
667 IEEE80211_NODE_STAT(ni, tx_mgmt);
669 return ic->ic_raw_xmit(ni, m, params);
673 * Send a null data frame to the specified node. If the station
674 * is setup for QoS then a QoS Null Data frame is constructed.
675 * If this is a WDS station then a 4-address frame is constructed.
677 * NB: the caller is assumed to have setup a node reference
678 * for use; this is necessary to deal with a race condition
679 * when probing for inactive stations. Like ieee80211_mgmt_output
680 * we must cleanup any node reference on error; however we
681 * can safely just unref it as we know it will never be the
682 * last reference to the node.
685 ieee80211_send_nulldata(struct ieee80211_node *ni)
687 struct ieee80211vap *vap = ni->ni_vap;
688 struct ieee80211com *ic = ni->ni_ic;
690 struct ieee80211_frame *wh;
694 if (vap->iv_state == IEEE80211_S_CAC) {
695 IEEE80211_NOTE(vap, IEEE80211_MSG_OUTPUT | IEEE80211_MSG_DOTH,
696 ni, "block %s frame in CAC state", "null data");
697 ieee80211_unref_node(&ni);
698 vap->iv_stats.is_tx_badstate++;
699 return EIO; /* XXX */
702 if (ni->ni_flags & (IEEE80211_NODE_QOS|IEEE80211_NODE_HT))
703 hdrlen = sizeof(struct ieee80211_qosframe);
705 hdrlen = sizeof(struct ieee80211_frame);
706 /* NB: only WDS vap's get 4-address frames */
707 if (vap->iv_opmode == IEEE80211_M_WDS)
708 hdrlen += IEEE80211_ADDR_LEN;
709 if (ic->ic_flags & IEEE80211_F_DATAPAD)
710 hdrlen = roundup(hdrlen, sizeof(uint32_t));
712 m = ieee80211_getmgtframe(&frm, ic->ic_headroom + hdrlen, 0);
715 ieee80211_unref_node(&ni);
716 vap->iv_stats.is_tx_nobuf++;
719 KASSERT(M_LEADINGSPACE(m) >= hdrlen,
720 ("leading space %zd", M_LEADINGSPACE(m)));
721 M_PREPEND(m, hdrlen, MB_DONTWAIT);
723 /* NB: cannot happen */
724 ieee80211_free_node(ni);
728 wh = mtod(m, struct ieee80211_frame *); /* NB: a little lie */
729 if (ni->ni_flags & IEEE80211_NODE_QOS) {
730 const int tid = WME_AC_TO_TID(WME_AC_BE);
733 ieee80211_send_setup(ni, m,
734 IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS_NULL,
735 tid, vap->iv_myaddr, ni->ni_macaddr, ni->ni_bssid);
737 if (vap->iv_opmode == IEEE80211_M_WDS)
738 qos = ((struct ieee80211_qosframe_addr4 *) wh)->i_qos;
740 qos = ((struct ieee80211_qosframe *) wh)->i_qos;
741 qos[0] = tid & IEEE80211_QOS_TID;
742 if (ic->ic_wme.wme_wmeChanParams.cap_wmeParams[WME_AC_BE].wmep_noackPolicy)
743 qos[0] |= IEEE80211_QOS_ACKPOLICY_NOACK;
746 ieee80211_send_setup(ni, m,
747 IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_NODATA,
748 IEEE80211_NONQOS_TID,
749 vap->iv_myaddr, ni->ni_macaddr, ni->ni_bssid);
751 if (vap->iv_opmode != IEEE80211_M_WDS) {
752 /* NB: power management bit is never sent by an AP */
753 if ((ni->ni_flags & IEEE80211_NODE_PWR_MGT) &&
754 vap->iv_opmode != IEEE80211_M_HOSTAP)
755 wh->i_fc[1] |= IEEE80211_FC1_PWR_MGT;
757 m->m_len = m->m_pkthdr.len = hdrlen;
758 m->m_flags |= M_ENCAP; /* mark encapsulated */
760 M_WME_SETAC(m, WME_AC_BE);
762 IEEE80211_NODE_STAT(ni, tx_data);
764 IEEE80211_NOTE(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_DUMPPKTS, ni,
765 "send %snull data frame on channel %u, pwr mgt %s",
766 ni->ni_flags & IEEE80211_NODE_QOS ? "QoS " : "",
767 ieee80211_chan2ieee(ic, ic->ic_curchan),
768 wh->i_fc[1] & IEEE80211_FC1_PWR_MGT ? "ena" : "dis");
770 return ic->ic_raw_xmit(ni, m, NULL);
774 * Assign priority to a frame based on any vlan tag assigned
775 * to the station and/or any Diffserv setting in an IP header.
776 * Finally, if an ACM policy is setup (in station mode) it's
780 ieee80211_classify(struct ieee80211_node *ni, struct mbuf *m)
782 const struct ether_header *eh = mtod(m, struct ether_header *);
783 int v_wme_ac, d_wme_ac, ac;
786 * Always promote PAE/EAPOL frames to high priority.
788 if (eh->ether_type == htons(ETHERTYPE_PAE)) {
789 /* NB: mark so others don't need to check header */
790 m->m_flags |= M_EAPOL;
795 * Non-qos traffic goes to BE.
797 if ((ni->ni_flags & IEEE80211_NODE_QOS) == 0) {
803 * If node has a vlan tag then all traffic
804 * to it must have a matching tag.
807 if (ni->ni_vlan != 0) {
808 if ((m->m_flags & M_VLANTAG) == 0) {
809 IEEE80211_NODE_STAT(ni, tx_novlantag);
813 if (EVL_VLANOFTAG(m->m_pkthdr.ether_vlantag) !=
814 EVL_VLANOFTAG(ni->ni_vlan)) {
815 IEEE80211_NODE_STAT(ni, tx_vlanmismatch);
818 /* map vlan priority to AC */
819 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 TOS 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 struct mbuf *mnew = NULL;
900 int needed_space = vap->iv_ic->ic_headroom + hdrsize;
903 /* XXX belongs in crypto code? */
904 needed_space += key->wk_cipher->ic_header;
907 * When crypto is being done in the host we must insure
908 * the data are writable for the cipher routines; clone
909 * a writable mbuf chain.
910 * XXX handle SWMIC specially
912 if (key->wk_flags & (IEEE80211_KEY_SWENCRYPT|IEEE80211_KEY_SWENMIC)) {
913 mnew = m_dup(m, MB_DONTWAIT);
915 IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
916 "%s: cannot get writable mbuf\n", __func__);
917 vap->iv_stats.is_tx_nobuf++; /* XXX new stat */
925 * We know we are called just before stripping an Ethernet
926 * header and prepending an LLC header. This means we know
928 * sizeof(struct ether_header) - sizeof(struct llc)
929 * bytes recovered to which we need additional space for the
930 * 802.11 header and any crypto header.
932 /* XXX check trailing space and copy instead? */
933 if (M_LEADINGSPACE(m) < needed_space - TO_BE_RECLAIMED) {
934 struct mbuf *n = m_gethdr(MB_DONTWAIT, m->m_type);
936 IEEE80211_DPRINTF(vap, IEEE80211_MSG_OUTPUT,
937 "%s: cannot expand storage\n", __func__);
938 vap->iv_stats.is_tx_nobuf++;
942 KASSERT(needed_space <= MHLEN,
943 ("not enough room, need %u got %zu", needed_space, MHLEN));
945 * Setup new mbuf to have leading space to prepend the
946 * 802.11 header and any crypto header bits that are
947 * required (the latter are added when the driver calls
948 * back to ieee80211_crypto_encap to do crypto encapsulation).
950 /* NB: must be first 'cuz it clobbers m_data */
952 n->m_len = 0; /* NB: m_gethdr does not set */
953 n->m_data += needed_space;
955 * Pull up Ethernet header to create the expected layout.
956 * We could use m_pullup but that's overkill (i.e. we don't
957 * need the actual data) and it cannot fail so do it inline
960 /* NB: struct ether_header is known to be contiguous */
961 n->m_len += sizeof(struct ether_header);
962 m->m_len -= sizeof(struct ether_header);
963 m->m_data += sizeof(struct ether_header);
965 * Replace the head of the chain.
971 #undef TO_BE_RECLAIMED
975 * Return the transmit key to use in sending a unicast frame.
976 * If a unicast key is set we use that. When no unicast key is set
977 * we fall back to the default transmit key.
979 static __inline struct ieee80211_key *
980 ieee80211_crypto_getucastkey(struct ieee80211vap *vap,
981 struct ieee80211_node *ni)
983 if (IEEE80211_KEY_UNDEFINED(&ni->ni_ucastkey)) {
984 if (vap->iv_def_txkey == IEEE80211_KEYIX_NONE ||
985 IEEE80211_KEY_UNDEFINED(&vap->iv_nw_keys[vap->iv_def_txkey]))
987 return &vap->iv_nw_keys[vap->iv_def_txkey];
989 return &ni->ni_ucastkey;
994 * Return the transmit key to use in sending a multicast frame.
995 * Multicast traffic always uses the group key which is installed as
996 * the default tx key.
998 static __inline struct ieee80211_key *
999 ieee80211_crypto_getmcastkey(struct ieee80211vap *vap,
1000 struct ieee80211_node *ni)
1002 if (vap->iv_def_txkey == IEEE80211_KEYIX_NONE ||
1003 IEEE80211_KEY_UNDEFINED(&vap->iv_nw_keys[vap->iv_def_txkey]))
1005 return &vap->iv_nw_keys[vap->iv_def_txkey];
1009 * Encapsulate an outbound data frame. The mbuf chain is updated.
1010 * If an error is encountered NULL is returned. The caller is required
1011 * to provide a node reference and pullup the ethernet header in the
1014 * NB: Packet is assumed to be processed by ieee80211_classify which
1015 * marked EAPOL frames w/ M_EAPOL.
1018 ieee80211_encap(struct ieee80211vap *vap, struct ieee80211_node *ni,
1021 #define WH4(wh) ((struct ieee80211_frame_addr4 *)(wh))
1022 struct ieee80211com *ic = ni->ni_ic;
1023 #ifdef IEEE80211_SUPPORT_MESH
1024 struct ieee80211_mesh_state *ms = vap->iv_mesh;
1025 struct ieee80211_meshcntl_ae10 *mc;
1027 struct ether_header eh;
1028 struct ieee80211_frame *wh;
1029 struct ieee80211_key *key;
1031 int hdrsize, hdrspace, datalen, addqos, txfrag, is4addr;
1032 ieee80211_seq seqno;
1033 int meshhdrsize, meshae;
1037 * Copy existing Ethernet header to a safe place. The
1038 * rest of the code assumes it's ok to strip it when
1039 * reorganizing state for the final encapsulation.
1041 KASSERT(m->m_len >= sizeof(eh), ("no ethernet header!"));
1042 ETHER_HEADER_COPY(&eh, mtod(m, caddr_t));
1045 * Insure space for additional headers. First identify
1046 * transmit key to use in calculating any buffer adjustments
1047 * required. This is also used below to do privacy
1048 * encapsulation work. Then calculate the 802.11 header
1049 * size and any padding required by the driver.
1051 * Note key may be NULL if we fall back to the default
1052 * transmit key and that is not set. In that case the
1053 * buffer may not be expanded as needed by the cipher
1054 * routines, but they will/should discard it.
1056 if (vap->iv_flags & IEEE80211_F_PRIVACY) {
1057 if (vap->iv_opmode == IEEE80211_M_STA ||
1058 !IEEE80211_IS_MULTICAST(eh.ether_dhost) ||
1059 (vap->iv_opmode == IEEE80211_M_WDS &&
1060 (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY)))
1061 key = ieee80211_crypto_getucastkey(vap, ni);
1063 key = ieee80211_crypto_getmcastkey(vap, ni);
1064 if (key == NULL && (m->m_flags & M_EAPOL) == 0) {
1065 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO,
1067 "no default transmit key (%s) deftxkey %u",
1068 __func__, vap->iv_def_txkey);
1069 vap->iv_stats.is_tx_nodefkey++;
1075 * XXX Some ap's don't handle QoS-encapsulated EAPOL
1076 * frames so suppress use. This may be an issue if other
1077 * ap's require all data frames to be QoS-encapsulated
1078 * once negotiated in which case we'll need to make this
1081 addqos = (ni->ni_flags & (IEEE80211_NODE_QOS|IEEE80211_NODE_HT)) &&
1082 (m->m_flags & M_EAPOL) == 0;
1084 hdrsize = sizeof(struct ieee80211_qosframe);
1086 hdrsize = sizeof(struct ieee80211_frame);
1087 #ifdef IEEE80211_SUPPORT_MESH
1088 if (vap->iv_opmode == IEEE80211_M_MBSS) {
1090 * Mesh data frames are encapsulated according to the
1091 * rules of Section 11B.8.5 (p.139 of D3.0 spec).
1092 * o Group Addressed data (aka multicast) originating
1093 * at the local sta are sent w/ 3-address format and
1094 * address extension mode 00
1095 * o Individually Addressed data (aka unicast) originating
1096 * at the local sta are sent w/ 4-address format and
1097 * address extension mode 00
1098 * o Group Addressed data forwarded from a non-mesh sta are
1099 * sent w/ 3-address format and address extension mode 01
1100 * o Individually Address data from another sta are sent
1101 * w/ 4-address format and address extension mode 10
1103 is4addr = 0; /* NB: don't use, disable */
1104 if (!IEEE80211_IS_MULTICAST(eh.ether_dhost))
1105 hdrsize += IEEE80211_ADDR_LEN; /* unicast are 4-addr */
1106 meshhdrsize = sizeof(struct ieee80211_meshcntl);
1107 /* XXX defines for AE modes */
1108 if (IEEE80211_ADDR_EQ(eh.ether_shost, vap->iv_myaddr)) {
1109 if (!IEEE80211_IS_MULTICAST(eh.ether_dhost))
1112 meshae = 4; /* NB: pseudo */
1113 } else if (IEEE80211_IS_MULTICAST(eh.ether_dhost)) {
1115 meshhdrsize += 1*IEEE80211_ADDR_LEN;
1118 meshhdrsize += 2*IEEE80211_ADDR_LEN;
1123 * 4-address frames need to be generated for:
1124 * o packets sent through a WDS vap (IEEE80211_M_WDS)
1125 * o packets sent through a vap marked for relaying
1126 * (e.g. a station operating with dynamic WDS)
1128 is4addr = vap->iv_opmode == IEEE80211_M_WDS ||
1129 ((vap->iv_flags_ext & IEEE80211_FEXT_4ADDR) &&
1130 !IEEE80211_ADDR_EQ(eh.ether_shost, vap->iv_myaddr));
1132 hdrsize += IEEE80211_ADDR_LEN;
1133 meshhdrsize = meshae = 0;
1134 #ifdef IEEE80211_SUPPORT_MESH
1138 * Honor driver DATAPAD requirement.
1140 if (ic->ic_flags & IEEE80211_F_DATAPAD)
1141 hdrspace = roundup(hdrsize, sizeof(uint32_t));
1145 if (__predict_true((m->m_flags & M_FF) == 0)) {
1149 m = ieee80211_mbuf_adjust(vap, hdrspace + meshhdrsize, key, m);
1151 /* NB: ieee80211_mbuf_adjust handles msgs+statistics */
1154 /* NB: this could be optimized 'cuz of ieee80211_mbuf_adjust */
1155 m_adj(m, sizeof(struct ether_header) - sizeof(struct llc));
1156 llc = mtod(m, struct llc *);
1157 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
1158 llc->llc_control = LLC_UI;
1159 llc->llc_snap.org_code[0] = 0;
1160 llc->llc_snap.org_code[1] = 0;
1161 llc->llc_snap.org_code[2] = 0;
1162 llc->llc_snap.ether_type = eh.ether_type;
1164 #ifdef IEEE80211_SUPPORT_SUPERG
1168 m = ieee80211_ff_encap(vap, m, hdrspace + meshhdrsize, key);
1173 datalen = m->m_pkthdr.len; /* NB: w/o 802.11 header */
1175 M_PREPEND(m, hdrspace + meshhdrsize, MB_DONTWAIT);
1177 vap->iv_stats.is_tx_nobuf++;
1180 wh = mtod(m, struct ieee80211_frame *);
1181 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_DATA;
1182 *(uint16_t *)wh->i_dur = 0;
1183 qos = NULL; /* NB: quiet compiler */
1185 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
1186 IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr);
1187 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1188 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
1189 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, eh.ether_shost);
1190 } else switch (vap->iv_opmode) {
1191 case IEEE80211_M_STA:
1192 wh->i_fc[1] = IEEE80211_FC1_DIR_TODS;
1193 IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_bssid);
1194 IEEE80211_ADDR_COPY(wh->i_addr2, eh.ether_shost);
1195 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
1197 case IEEE80211_M_IBSS:
1198 case IEEE80211_M_AHDEMO:
1199 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
1200 IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost);
1201 IEEE80211_ADDR_COPY(wh->i_addr2, eh.ether_shost);
1203 * NB: always use the bssid from iv_bss as the
1204 * neighbor's may be stale after an ibss merge
1206 IEEE80211_ADDR_COPY(wh->i_addr3, vap->iv_bss->ni_bssid);
1208 case IEEE80211_M_HOSTAP:
1209 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
1210 IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost);
1211 IEEE80211_ADDR_COPY(wh->i_addr2, ni->ni_bssid);
1212 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_shost);
1214 #ifdef IEEE80211_SUPPORT_MESH
1215 case IEEE80211_M_MBSS:
1216 /* NB: offset by hdrspace to deal with DATAPAD */
1217 mc = (struct ieee80211_meshcntl_ae10 *)
1218 (mtod(m, uint8_t *) + hdrspace);
1220 case 0: /* ucast, no proxy */
1221 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
1222 IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr);
1223 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1224 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
1225 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, eh.ether_shost);
1227 qos = ((struct ieee80211_qosframe_addr4 *) wh)->i_qos;
1229 case 4: /* mcast, no proxy */
1230 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
1231 IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost);
1232 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1233 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_shost);
1234 mc->mc_flags = 0; /* NB: AE is really 0 */
1235 qos = ((struct ieee80211_qosframe *) wh)->i_qos;
1237 case 1: /* mcast, proxy */
1238 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
1239 IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost);
1240 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1241 IEEE80211_ADDR_COPY(wh->i_addr3, vap->iv_myaddr);
1243 IEEE80211_ADDR_COPY(mc->mc_addr4, eh.ether_shost);
1244 qos = ((struct ieee80211_qosframe *) wh)->i_qos;
1246 case 2: /* ucast, proxy */
1247 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
1248 IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr);
1249 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1250 /* XXX not right, need MeshDA */
1251 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
1252 /* XXX assume are MeshSA */
1253 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, vap->iv_myaddr);
1255 IEEE80211_ADDR_COPY(mc->mc_addr4, eh.ether_dhost);
1256 IEEE80211_ADDR_COPY(mc->mc_addr5, eh.ether_shost);
1257 qos = ((struct ieee80211_qosframe_addr4 *) wh)->i_qos;
1260 KASSERT(0, ("meshae %d", meshae));
1263 mc->mc_ttl = ms->ms_ttl;
1265 LE_WRITE_4(mc->mc_seq, ms->ms_seq);
1268 case IEEE80211_M_WDS: /* NB: is4addr should always be true */
1272 if (m->m_flags & M_MORE_DATA)
1273 wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA;
1278 qos = ((struct ieee80211_qosframe_addr4 *) wh)->i_qos;
1279 /* NB: mesh case handled earlier */
1280 } else if (vap->iv_opmode != IEEE80211_M_MBSS)
1281 qos = ((struct ieee80211_qosframe *) wh)->i_qos;
1282 ac = M_WME_GETAC(m);
1283 /* map from access class/queue to 11e header priorty value */
1284 tid = WME_AC_TO_TID(ac);
1285 qos[0] = tid & IEEE80211_QOS_TID;
1286 if (ic->ic_wme.wme_wmeChanParams.cap_wmeParams[ac].wmep_noackPolicy)
1287 qos[0] |= IEEE80211_QOS_ACKPOLICY_NOACK;
1289 wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_QOS;
1291 if ((m->m_flags & M_AMPDU_MPDU) == 0) {
1293 * NB: don't assign a sequence # to potential
1294 * aggregates; we expect this happens at the
1295 * point the frame comes off any aggregation q
1296 * as otherwise we may introduce holes in the
1297 * BA sequence space and/or make window accouting
1300 * XXX may want to control this with a driver
1301 * capability; this may also change when we pull
1302 * aggregation up into net80211
1304 seqno = ni->ni_txseqs[tid]++;
1305 *(uint16_t *)wh->i_seq =
1306 htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT);
1307 M_SEQNO_SET(m, seqno);
1310 seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]++;
1311 *(uint16_t *)wh->i_seq =
1312 htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT);
1313 M_SEQNO_SET(m, seqno);
1317 /* check if xmit fragmentation is required */
1318 txfrag = (m->m_pkthdr.len > vap->iv_fragthreshold &&
1319 !IEEE80211_IS_MULTICAST(wh->i_addr1) &&
1320 (vap->iv_caps & IEEE80211_C_TXFRAG) &&
1321 (m->m_flags & (M_FF | M_AMPDU_MPDU)) == 0);
1324 * IEEE 802.1X: send EAPOL frames always in the clear.
1325 * WPA/WPA2: encrypt EAPOL keys when pairwise keys are set.
1327 if ((m->m_flags & M_EAPOL) == 0 ||
1328 ((vap->iv_flags & IEEE80211_F_WPA) &&
1329 (vap->iv_opmode == IEEE80211_M_STA ?
1330 !IEEE80211_KEY_UNDEFINED(key) :
1331 !IEEE80211_KEY_UNDEFINED(&ni->ni_ucastkey)))) {
1332 wh->i_fc[1] |= IEEE80211_FC1_WEP;
1333 if (!ieee80211_crypto_enmic(vap, key, m, txfrag)) {
1334 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_OUTPUT,
1336 "%s", "enmic failed, discard frame");
1337 vap->iv_stats.is_crypto_enmicfail++;
1342 if (txfrag && !ieee80211_fragment(vap, m, hdrsize,
1343 key != NULL ? key->wk_cipher->ic_header : 0, vap->iv_fragthreshold))
1346 m->m_flags |= M_ENCAP; /* mark encapsulated */
1348 IEEE80211_NODE_STAT(ni, tx_data);
1349 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
1350 IEEE80211_NODE_STAT(ni, tx_mcast);
1351 m->m_flags |= M_MCAST;
1353 IEEE80211_NODE_STAT(ni, tx_ucast);
1354 IEEE80211_NODE_STAT_ADD(ni, tx_bytes, datalen);
1365 * Fragment the frame according to the specified mtu.
1366 * The size of the 802.11 header (w/o padding) is provided
1367 * so we don't need to recalculate it. We create a new
1368 * mbuf for each fragment and chain it through m_nextpkt;
1369 * we might be able to optimize this by reusing the original
1370 * packet's mbufs but that is significantly more complicated.
1373 ieee80211_fragment(struct ieee80211vap *vap, struct mbuf *m0,
1374 u_int hdrsize, u_int ciphdrsize, u_int mtu)
1376 struct ieee80211_frame *wh, *whf;
1377 struct mbuf *m, *prev, *next;
1378 u_int totalhdrsize, fragno, fragsize, off, remainder, payload;
1380 KASSERT(m0->m_nextpkt == NULL, ("mbuf already chained?"));
1381 KASSERT(m0->m_pkthdr.len > mtu,
1382 ("pktlen %u mtu %u", m0->m_pkthdr.len, mtu));
1384 wh = mtod(m0, struct ieee80211_frame *);
1385 /* NB: mark the first frag; it will be propagated below */
1386 wh->i_fc[1] |= IEEE80211_FC1_MORE_FRAG;
1387 totalhdrsize = hdrsize + ciphdrsize;
1389 off = mtu - ciphdrsize;
1390 remainder = m0->m_pkthdr.len - off;
1393 fragsize = totalhdrsize + remainder;
1396 /* XXX fragsize can be >2048! */
1397 KASSERT(fragsize < MCLBYTES,
1398 ("fragment size %u too big!", fragsize));
1399 if (fragsize > MHLEN)
1400 m = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
1402 m = m_gethdr(MB_DONTWAIT, MT_DATA);
1405 /* leave room to prepend any cipher header */
1406 m_align(m, fragsize - ciphdrsize);
1409 * Form the header in the fragment. Note that since
1410 * we mark the first fragment with the MORE_FRAG bit
1411 * it automatically is propagated to each fragment; we
1412 * need only clear it on the last fragment (done below).
1414 whf = mtod(m, struct ieee80211_frame *);
1415 memcpy(whf, wh, hdrsize);
1416 *(uint16_t *)&whf->i_seq[0] |= htole16(
1417 (fragno & IEEE80211_SEQ_FRAG_MASK) <<
1418 IEEE80211_SEQ_FRAG_SHIFT);
1421 payload = fragsize - totalhdrsize;
1422 /* NB: destination is known to be contiguous */
1423 m_copydata(m0, off, payload, mtod(m, uint8_t *) + hdrsize);
1424 m->m_len = hdrsize + payload;
1425 m->m_pkthdr.len = hdrsize + payload;
1426 m->m_flags |= M_FRAG;
1427 m->m_pkthdr.rcvif = m0->m_pkthdr.rcvif;
1429 /* chain up the fragment */
1430 prev->m_nextpkt = m;
1433 /* deduct fragment just formed */
1434 remainder -= payload;
1436 } while (remainder != 0);
1438 /* set the last fragment */
1439 m->m_flags |= M_LASTFRAG;
1440 whf->i_fc[1] &= ~IEEE80211_FC1_MORE_FRAG;
1442 /* strip first mbuf now that everything has been copied */
1443 m_adj(m0, -(m0->m_pkthdr.len - (mtu - ciphdrsize)));
1444 m0->m_flags |= M_FIRSTFRAG | M_FRAG;
1446 vap->iv_stats.is_tx_fragframes++;
1447 vap->iv_stats.is_tx_frags += fragno-1;
1451 /* reclaim fragments but leave original frame for caller to free */
1452 for (m = m0->m_nextpkt; m != NULL; m = next) {
1453 next = m->m_nextpkt;
1454 m->m_nextpkt = NULL; /* XXX paranoid */
1457 m0->m_nextpkt = NULL;
1462 * Add a supported rates element id to a frame.
1465 ieee80211_add_rates(uint8_t *frm, const struct ieee80211_rateset *rs)
1469 *frm++ = IEEE80211_ELEMID_RATES;
1470 nrates = rs->rs_nrates;
1471 if (nrates > IEEE80211_RATE_SIZE)
1472 nrates = IEEE80211_RATE_SIZE;
1474 memcpy(frm, rs->rs_rates, nrates);
1475 return frm + nrates;
1479 * Add an extended supported rates element id to a frame.
1482 ieee80211_add_xrates(uint8_t *frm, const struct ieee80211_rateset *rs)
1485 * Add an extended supported rates element if operating in 11g mode.
1487 if (rs->rs_nrates > IEEE80211_RATE_SIZE) {
1488 int nrates = rs->rs_nrates - IEEE80211_RATE_SIZE;
1489 *frm++ = IEEE80211_ELEMID_XRATES;
1491 memcpy(frm, rs->rs_rates + IEEE80211_RATE_SIZE, nrates);
1498 * Add an ssid element to a frame.
1501 ieee80211_add_ssid(uint8_t *frm, const uint8_t *ssid, u_int len)
1503 *frm++ = IEEE80211_ELEMID_SSID;
1505 memcpy(frm, ssid, len);
1510 * Add an erp element to a frame.
1513 ieee80211_add_erp(uint8_t *frm, struct ieee80211com *ic)
1517 *frm++ = IEEE80211_ELEMID_ERP;
1520 if (ic->ic_nonerpsta != 0)
1521 erp |= IEEE80211_ERP_NON_ERP_PRESENT;
1522 if (ic->ic_flags & IEEE80211_F_USEPROT)
1523 erp |= IEEE80211_ERP_USE_PROTECTION;
1524 if (ic->ic_flags & IEEE80211_F_USEBARKER)
1525 erp |= IEEE80211_ERP_LONG_PREAMBLE;
1531 * Add a CFParams element to a frame.
1534 ieee80211_add_cfparms(uint8_t *frm, struct ieee80211com *ic)
1536 #define ADDSHORT(frm, v) do { \
1537 LE_WRITE_2(frm, v); \
1540 *frm++ = IEEE80211_ELEMID_CFPARMS;
1542 *frm++ = 0; /* CFP count */
1543 *frm++ = 2; /* CFP period */
1544 ADDSHORT(frm, 0); /* CFP MaxDuration (TU) */
1545 ADDSHORT(frm, 0); /* CFP CurRemaining (TU) */
1550 static __inline uint8_t *
1551 add_appie(uint8_t *frm, const struct ieee80211_appie *ie)
1553 memcpy(frm, ie->ie_data, ie->ie_len);
1554 return frm + ie->ie_len;
1557 static __inline uint8_t *
1558 add_ie(uint8_t *frm, const uint8_t *ie)
1560 memcpy(frm, ie, 2 + ie[1]);
1561 return frm + 2 + ie[1];
1564 #define WME_OUI_BYTES 0x00, 0x50, 0xf2
1566 * Add a WME information element to a frame.
1569 ieee80211_add_wme_info(uint8_t *frm, struct ieee80211_wme_state *wme)
1571 static const struct ieee80211_wme_info info = {
1572 .wme_id = IEEE80211_ELEMID_VENDOR,
1573 .wme_len = sizeof(struct ieee80211_wme_info) - 2,
1574 .wme_oui = { WME_OUI_BYTES },
1575 .wme_type = WME_OUI_TYPE,
1576 .wme_subtype = WME_INFO_OUI_SUBTYPE,
1577 .wme_version = WME_VERSION,
1580 memcpy(frm, &info, sizeof(info));
1581 return frm + sizeof(info);
1585 * Add a WME parameters element to a frame.
1588 ieee80211_add_wme_param(uint8_t *frm, struct ieee80211_wme_state *wme)
1590 #define SM(_v, _f) (((_v) << _f##_S) & _f)
1591 #define ADDSHORT(frm, v) do { \
1592 LE_WRITE_2(frm, v); \
1595 /* NB: this works 'cuz a param has an info at the front */
1596 static const struct ieee80211_wme_info param = {
1597 .wme_id = IEEE80211_ELEMID_VENDOR,
1598 .wme_len = sizeof(struct ieee80211_wme_param) - 2,
1599 .wme_oui = { WME_OUI_BYTES },
1600 .wme_type = WME_OUI_TYPE,
1601 .wme_subtype = WME_PARAM_OUI_SUBTYPE,
1602 .wme_version = WME_VERSION,
1606 memcpy(frm, ¶m, sizeof(param));
1607 frm += __offsetof(struct ieee80211_wme_info, wme_info);
1608 *frm++ = wme->wme_bssChanParams.cap_info; /* AC info */
1609 *frm++ = 0; /* reserved field */
1610 for (i = 0; i < WME_NUM_AC; i++) {
1611 const struct wmeParams *ac =
1612 &wme->wme_bssChanParams.cap_wmeParams[i];
1613 *frm++ = SM(i, WME_PARAM_ACI)
1614 | SM(ac->wmep_acm, WME_PARAM_ACM)
1615 | SM(ac->wmep_aifsn, WME_PARAM_AIFSN)
1617 *frm++ = SM(ac->wmep_logcwmax, WME_PARAM_LOGCWMAX)
1618 | SM(ac->wmep_logcwmin, WME_PARAM_LOGCWMIN)
1620 ADDSHORT(frm, ac->wmep_txopLimit);
1626 #undef WME_OUI_BYTES
1629 * Add an 11h Power Constraint element to a frame.
1632 ieee80211_add_powerconstraint(uint8_t *frm, struct ieee80211vap *vap)
1634 const struct ieee80211_channel *c = vap->iv_bss->ni_chan;
1635 /* XXX per-vap tx power limit? */
1636 int8_t limit = vap->iv_ic->ic_txpowlimit / 2;
1638 frm[0] = IEEE80211_ELEMID_PWRCNSTR;
1640 frm[2] = c->ic_maxregpower > limit ? c->ic_maxregpower - limit : 0;
1645 * Add an 11h Power Capability element to a frame.
1648 ieee80211_add_powercapability(uint8_t *frm, const struct ieee80211_channel *c)
1650 frm[0] = IEEE80211_ELEMID_PWRCAP;
1652 frm[2] = c->ic_minpower;
1653 frm[3] = c->ic_maxpower;
1658 * Add an 11h Supported Channels element to a frame.
1661 ieee80211_add_supportedchannels(uint8_t *frm, struct ieee80211com *ic)
1663 static const int ielen = 26;
1665 frm[0] = IEEE80211_ELEMID_SUPPCHAN;
1667 /* XXX not correct */
1668 memcpy(frm+2, ic->ic_chan_avail, ielen);
1669 return frm + 2 + ielen;
1673 * Add an 11h Channel Switch Announcement element to a frame.
1674 * Note that we use the per-vap CSA count to adjust the global
1675 * counter so we can use this routine to form probe response
1676 * frames and get the current count.
1679 ieee80211_add_csa(uint8_t *frm, struct ieee80211vap *vap)
1681 struct ieee80211com *ic = vap->iv_ic;
1682 struct ieee80211_csa_ie *csa = (struct ieee80211_csa_ie *) frm;
1684 csa->csa_ie = IEEE80211_ELEMID_CSA;
1686 csa->csa_mode = 1; /* XXX force quiet on channel */
1687 csa->csa_newchan = ieee80211_chan2ieee(ic, ic->ic_csa_newchan);
1688 csa->csa_count = ic->ic_csa_count - vap->iv_csa_count;
1689 return frm + sizeof(*csa);
1693 * Add an 11h country information element to a frame.
1696 ieee80211_add_countryie(uint8_t *frm, struct ieee80211com *ic)
1699 if (ic->ic_countryie == NULL ||
1700 ic->ic_countryie_chan != ic->ic_bsschan) {
1702 * Handle lazy construction of ie. This is done on
1703 * first use and after a channel change that requires
1706 if (ic->ic_countryie != NULL)
1707 kfree(ic->ic_countryie, M_80211_NODE_IE);
1708 ic->ic_countryie = ieee80211_alloc_countryie(ic);
1709 if (ic->ic_countryie == NULL)
1711 ic->ic_countryie_chan = ic->ic_bsschan;
1713 return add_appie(frm, ic->ic_countryie);
1717 * Send a probe request frame with the specified ssid
1718 * and any optional information element data.
1721 ieee80211_send_probereq(struct ieee80211_node *ni,
1722 const uint8_t sa[IEEE80211_ADDR_LEN],
1723 const uint8_t da[IEEE80211_ADDR_LEN],
1724 const uint8_t bssid[IEEE80211_ADDR_LEN],
1725 const uint8_t *ssid, size_t ssidlen)
1727 struct ieee80211vap *vap = ni->ni_vap;
1728 struct ieee80211com *ic = ni->ni_ic;
1729 const struct ieee80211_txparam *tp;
1730 struct ieee80211_bpf_params params;
1731 const struct ieee80211_rateset *rs;
1734 #ifdef IEEE80211_DEBUG
1735 char ethstr[ETHER_ADDRSTRLEN + 1];
1738 if (vap->iv_state == IEEE80211_S_CAC) {
1739 IEEE80211_NOTE(vap, IEEE80211_MSG_OUTPUT, ni,
1740 "block %s frame in CAC state", "probe request");
1741 vap->iv_stats.is_tx_badstate++;
1742 return EIO; /* XXX */
1746 * Hold a reference on the node so it doesn't go away until after
1747 * the xmit is complete all the way in the driver. On error we
1748 * will remove our reference.
1750 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1751 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n",
1753 ni, kether_ntoa(ni->ni_macaddr, ethstr),
1754 ieee80211_node_refcnt(ni)+1);
1755 ieee80211_ref_node(ni);
1758 * prreq frame format
1760 * [tlv] supported rates
1761 * [tlv] RSN (optional)
1762 * [tlv] extended supported rates
1763 * [tlv] WPA (optional)
1764 * [tlv] user-specified ie's
1766 m = ieee80211_getmgtframe(&frm,
1767 ic->ic_headroom + sizeof(struct ieee80211_frame),
1768 2 + IEEE80211_NWID_LEN
1769 + 2 + IEEE80211_RATE_SIZE
1770 + sizeof(struct ieee80211_ie_wpa)
1771 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
1772 + sizeof(struct ieee80211_ie_wpa)
1773 + (vap->iv_appie_probereq != NULL ?
1774 vap->iv_appie_probereq->ie_len : 0)
1777 vap->iv_stats.is_tx_nobuf++;
1778 ieee80211_free_node(ni);
1782 frm = ieee80211_add_ssid(frm, ssid, ssidlen);
1783 rs = ieee80211_get_suprates(ic, ic->ic_curchan);
1784 frm = ieee80211_add_rates(frm, rs);
1785 if (vap->iv_flags & IEEE80211_F_WPA2) {
1786 if (vap->iv_rsn_ie != NULL)
1787 frm = add_ie(frm, vap->iv_rsn_ie);
1788 /* XXX else complain? */
1790 frm = ieee80211_add_xrates(frm, rs);
1791 if (vap->iv_flags & IEEE80211_F_WPA1) {
1792 if (vap->iv_wpa_ie != NULL)
1793 frm = add_ie(frm, vap->iv_wpa_ie);
1794 /* XXX else complain? */
1796 if (vap->iv_appie_probereq != NULL)
1797 frm = add_appie(frm, vap->iv_appie_probereq);
1798 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
1800 KASSERT(M_LEADINGSPACE(m) >= sizeof(struct ieee80211_frame),
1801 ("leading space %zd", M_LEADINGSPACE(m)));
1802 M_PREPEND(m, sizeof(struct ieee80211_frame), MB_DONTWAIT);
1804 /* NB: cannot happen */
1805 ieee80211_free_node(ni);
1809 ieee80211_send_setup(ni, m,
1810 IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_REQ,
1811 IEEE80211_NONQOS_TID, sa, da, bssid);
1812 /* XXX power management? */
1813 m->m_flags |= M_ENCAP; /* mark encapsulated */
1815 M_WME_SETAC(m, WME_AC_BE);
1817 IEEE80211_NODE_STAT(ni, tx_probereq);
1818 IEEE80211_NODE_STAT(ni, tx_mgmt);
1820 IEEE80211_DPRINTF(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_DUMPPKTS,
1821 "send probe req on channel %u bssid %s ssid \"%.*s\"\n",
1822 ieee80211_chan2ieee(ic, ic->ic_curchan), kether_ntoa(bssid, ethstr),
1823 (int)ssidlen, ssid);
1825 memset(¶ms, 0, sizeof(params));
1826 params.ibp_pri = M_WME_GETAC(m);
1827 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)];
1828 params.ibp_rate0 = tp->mgmtrate;
1829 if (IEEE80211_IS_MULTICAST(da)) {
1830 params.ibp_flags |= IEEE80211_BPF_NOACK;
1831 params.ibp_try0 = 1;
1833 params.ibp_try0 = tp->maxretry;
1834 params.ibp_power = ni->ni_txpower;
1835 return ic->ic_raw_xmit(ni, m, ¶ms);
1839 * Calculate capability information for mgt frames.
1842 ieee80211_getcapinfo(struct ieee80211vap *vap, struct ieee80211_channel *chan)
1844 struct ieee80211com *ic = vap->iv_ic;
1847 KASSERT(vap->iv_opmode != IEEE80211_M_STA, ("station mode"));
1849 if (vap->iv_opmode == IEEE80211_M_HOSTAP)
1850 capinfo = IEEE80211_CAPINFO_ESS;
1851 else if (vap->iv_opmode == IEEE80211_M_IBSS)
1852 capinfo = IEEE80211_CAPINFO_IBSS;
1855 if (vap->iv_flags & IEEE80211_F_PRIVACY)
1856 capinfo |= IEEE80211_CAPINFO_PRIVACY;
1857 if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) &&
1858 IEEE80211_IS_CHAN_2GHZ(chan))
1859 capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE;
1860 if (ic->ic_flags & IEEE80211_F_SHSLOT)
1861 capinfo |= IEEE80211_CAPINFO_SHORT_SLOTTIME;
1862 if (IEEE80211_IS_CHAN_5GHZ(chan) && (vap->iv_flags & IEEE80211_F_DOTH))
1863 capinfo |= IEEE80211_CAPINFO_SPECTRUM_MGMT;
1868 * Send a management frame. The node is for the destination (or ic_bss
1869 * when in station mode). Nodes other than ic_bss have their reference
1870 * count bumped to reflect our use for an indeterminant time.
1873 ieee80211_send_mgmt(struct ieee80211_node *ni, int type, int arg)
1875 #define HTFLAGS (IEEE80211_NODE_HT | IEEE80211_NODE_HTCOMPAT)
1876 #define senderr(_x, _v) do { vap->iv_stats._v++; ret = _x; goto bad; } while (0)
1877 struct ieee80211vap *vap = ni->ni_vap;
1878 struct ieee80211com *ic = ni->ni_ic;
1879 struct ieee80211_node *bss = vap->iv_bss;
1880 struct ieee80211_bpf_params params;
1884 int has_challenge, is_shared_key, ret, status;
1885 #ifdef IEEE80211_DEBUG
1886 char ethstr[ETHER_ADDRSTRLEN + 1];
1889 KASSERT(ni != NULL, ("null node"));
1892 * Hold a reference on the node so it doesn't go away until after
1893 * the xmit is complete all the way in the driver. On error we
1894 * will remove our reference.
1896 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
1897 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n",
1899 ni, kether_ntoa(ni->ni_macaddr, ethstr),
1900 ieee80211_node_refcnt(ni)+1);
1901 ieee80211_ref_node(ni);
1903 memset(¶ms, 0, sizeof(params));
1906 case IEEE80211_FC0_SUBTYPE_AUTH:
1909 has_challenge = ((arg == IEEE80211_AUTH_SHARED_CHALLENGE ||
1910 arg == IEEE80211_AUTH_SHARED_RESPONSE) &&
1911 ni->ni_challenge != NULL);
1914 * Deduce whether we're doing open authentication or
1915 * shared key authentication. We do the latter if
1916 * we're in the middle of a shared key authentication
1917 * handshake or if we're initiating an authentication
1918 * request and configured to use shared key.
1920 is_shared_key = has_challenge ||
1921 arg >= IEEE80211_AUTH_SHARED_RESPONSE ||
1922 (arg == IEEE80211_AUTH_SHARED_REQUEST &&
1923 bss->ni_authmode == IEEE80211_AUTH_SHARED);
1925 m = ieee80211_getmgtframe(&frm,
1926 ic->ic_headroom + sizeof(struct ieee80211_frame),
1927 3 * sizeof(uint16_t)
1928 + (has_challenge && status == IEEE80211_STATUS_SUCCESS ?
1929 sizeof(uint16_t)+IEEE80211_CHALLENGE_LEN : 0)
1932 senderr(ENOMEM, is_tx_nobuf);
1934 ((uint16_t *)frm)[0] =
1935 (is_shared_key) ? htole16(IEEE80211_AUTH_ALG_SHARED)
1936 : htole16(IEEE80211_AUTH_ALG_OPEN);
1937 ((uint16_t *)frm)[1] = htole16(arg); /* sequence number */
1938 ((uint16_t *)frm)[2] = htole16(status);/* status */
1940 if (has_challenge && status == IEEE80211_STATUS_SUCCESS) {
1941 ((uint16_t *)frm)[3] =
1942 htole16((IEEE80211_CHALLENGE_LEN << 8) |
1943 IEEE80211_ELEMID_CHALLENGE);
1944 memcpy(&((uint16_t *)frm)[4], ni->ni_challenge,
1945 IEEE80211_CHALLENGE_LEN);
1946 m->m_pkthdr.len = m->m_len =
1947 4 * sizeof(uint16_t) + IEEE80211_CHALLENGE_LEN;
1948 if (arg == IEEE80211_AUTH_SHARED_RESPONSE) {
1949 IEEE80211_NOTE(vap, IEEE80211_MSG_AUTH, ni,
1950 "request encrypt frame (%s)", __func__);
1951 /* mark frame for encryption */
1952 params.ibp_flags |= IEEE80211_BPF_CRYPTO;
1955 m->m_pkthdr.len = m->m_len = 3 * sizeof(uint16_t);
1957 /* XXX not right for shared key */
1958 if (status == IEEE80211_STATUS_SUCCESS)
1959 IEEE80211_NODE_STAT(ni, tx_auth);
1961 IEEE80211_NODE_STAT(ni, tx_auth_fail);
1963 if (vap->iv_opmode == IEEE80211_M_STA)
1964 ieee80211_add_callback(m, ieee80211_tx_mgt_cb,
1965 (void *) vap->iv_state);
1968 case IEEE80211_FC0_SUBTYPE_DEAUTH:
1969 IEEE80211_NOTE(vap, IEEE80211_MSG_AUTH, ni,
1970 "send station deauthenticate (reason %d)", arg);
1971 m = ieee80211_getmgtframe(&frm,
1972 ic->ic_headroom + sizeof(struct ieee80211_frame),
1975 senderr(ENOMEM, is_tx_nobuf);
1976 *(uint16_t *)frm = htole16(arg); /* reason */
1977 m->m_pkthdr.len = m->m_len = sizeof(uint16_t);
1979 IEEE80211_NODE_STAT(ni, tx_deauth);
1980 IEEE80211_NODE_STAT_SET(ni, tx_deauth_code, arg);
1982 ieee80211_node_unauthorize(ni); /* port closed */
1985 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
1986 case IEEE80211_FC0_SUBTYPE_REASSOC_REQ:
1988 * asreq frame format
1989 * [2] capability information
1990 * [2] listen interval
1991 * [6*] current AP address (reassoc only)
1993 * [tlv] supported rates
1994 * [tlv] extended supported rates
1995 * [4] power capability (optional)
1996 * [28] supported channels (optional)
1997 * [tlv] HT capabilities
1998 * [tlv] WME (optional)
1999 * [tlv] Vendor OUI HT capabilities (optional)
2000 * [tlv] Atheros capabilities (if negotiated)
2001 * [tlv] AppIE's (optional)
2003 m = ieee80211_getmgtframe(&frm,
2004 ic->ic_headroom + sizeof(struct ieee80211_frame),
2007 + IEEE80211_ADDR_LEN
2008 + 2 + IEEE80211_NWID_LEN
2009 + 2 + IEEE80211_RATE_SIZE
2010 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
2013 + sizeof(struct ieee80211_wme_info)
2014 + sizeof(struct ieee80211_ie_htcap)
2015 + 4 + sizeof(struct ieee80211_ie_htcap)
2016 #ifdef IEEE80211_SUPPORT_SUPERG
2017 + sizeof(struct ieee80211_ath_ie)
2019 + (vap->iv_appie_wpa != NULL ?
2020 vap->iv_appie_wpa->ie_len : 0)
2021 + (vap->iv_appie_assocreq != NULL ?
2022 vap->iv_appie_assocreq->ie_len : 0)
2025 senderr(ENOMEM, is_tx_nobuf);
2027 KASSERT(vap->iv_opmode == IEEE80211_M_STA,
2028 ("wrong mode %u", vap->iv_opmode));
2029 capinfo = IEEE80211_CAPINFO_ESS;
2030 if (vap->iv_flags & IEEE80211_F_PRIVACY)
2031 capinfo |= IEEE80211_CAPINFO_PRIVACY;
2033 * NB: Some 11a AP's reject the request when
2034 * short premable is set.
2036 if ((ic->ic_flags & IEEE80211_F_SHPREAMBLE) &&
2037 IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan))
2038 capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE;
2039 if (IEEE80211_IS_CHAN_ANYG(ic->ic_curchan) &&
2040 (ic->ic_caps & IEEE80211_C_SHSLOT))
2041 capinfo |= IEEE80211_CAPINFO_SHORT_SLOTTIME;
2042 if ((ni->ni_capinfo & IEEE80211_CAPINFO_SPECTRUM_MGMT) &&
2043 (vap->iv_flags & IEEE80211_F_DOTH))
2044 capinfo |= IEEE80211_CAPINFO_SPECTRUM_MGMT;
2045 *(uint16_t *)frm = htole16(capinfo);
2048 KASSERT(bss->ni_intval != 0, ("beacon interval is zero!"));
2049 *(uint16_t *)frm = htole16(howmany(ic->ic_lintval,
2053 if (type == IEEE80211_FC0_SUBTYPE_REASSOC_REQ) {
2054 IEEE80211_ADDR_COPY(frm, bss->ni_bssid);
2055 frm += IEEE80211_ADDR_LEN;
2058 frm = ieee80211_add_ssid(frm, ni->ni_essid, ni->ni_esslen);
2059 frm = ieee80211_add_rates(frm, &ni->ni_rates);
2060 if (vap->iv_flags & IEEE80211_F_WPA2) {
2061 if (vap->iv_rsn_ie != NULL)
2062 frm = add_ie(frm, vap->iv_rsn_ie);
2063 /* XXX else complain? */
2065 frm = ieee80211_add_xrates(frm, &ni->ni_rates);
2066 if (capinfo & IEEE80211_CAPINFO_SPECTRUM_MGMT) {
2067 frm = ieee80211_add_powercapability(frm,
2069 frm = ieee80211_add_supportedchannels(frm, ic);
2071 if ((vap->iv_flags_ht & IEEE80211_FHT_HT) &&
2072 ni->ni_ies.htcap_ie != NULL &&
2073 ni->ni_ies.htcap_ie[0] == IEEE80211_ELEMID_HTCAP)
2074 frm = ieee80211_add_htcap(frm, ni);
2075 if (vap->iv_flags & IEEE80211_F_WPA1) {
2076 if (vap->iv_wpa_ie != NULL)
2077 frm = add_ie(frm, vap->iv_wpa_ie);
2078 /* XXX else complain */
2080 if ((ic->ic_flags & IEEE80211_F_WME) &&
2081 ni->ni_ies.wme_ie != NULL)
2082 frm = ieee80211_add_wme_info(frm, &ic->ic_wme);
2083 if ((vap->iv_flags_ht & IEEE80211_FHT_HT) &&
2084 ni->ni_ies.htcap_ie != NULL &&
2085 ni->ni_ies.htcap_ie[0] == IEEE80211_ELEMID_VENDOR)
2086 frm = ieee80211_add_htcap_vendor(frm, ni);
2087 #ifdef IEEE80211_SUPPORT_SUPERG
2088 if (IEEE80211_ATH_CAP(vap, ni, IEEE80211_F_ATHEROS)) {
2089 frm = ieee80211_add_ath(frm,
2090 IEEE80211_ATH_CAP(vap, ni, IEEE80211_F_ATHEROS),
2091 ((vap->iv_flags & IEEE80211_F_WPA) == 0 &&
2092 ni->ni_authmode != IEEE80211_AUTH_8021X) ?
2093 vap->iv_def_txkey : IEEE80211_KEYIX_NONE);
2095 #endif /* IEEE80211_SUPPORT_SUPERG */
2096 if (vap->iv_appie_assocreq != NULL)
2097 frm = add_appie(frm, vap->iv_appie_assocreq);
2098 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2100 ieee80211_add_callback(m, ieee80211_tx_mgt_cb,
2101 (void *) vap->iv_state);
2104 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
2105 case IEEE80211_FC0_SUBTYPE_REASSOC_RESP:
2107 * asresp frame format
2108 * [2] capability information
2110 * [2] association ID
2111 * [tlv] supported rates
2112 * [tlv] extended supported rates
2113 * [tlv] HT capabilities (standard, if STA enabled)
2114 * [tlv] HT information (standard, if STA enabled)
2115 * [tlv] WME (if configured and STA enabled)
2116 * [tlv] HT capabilities (vendor OUI, if STA enabled)
2117 * [tlv] HT information (vendor OUI, if STA enabled)
2118 * [tlv] Atheros capabilities (if STA enabled)
2119 * [tlv] AppIE's (optional)
2121 m = ieee80211_getmgtframe(&frm,
2122 ic->ic_headroom + sizeof(struct ieee80211_frame),
2126 + 2 + IEEE80211_RATE_SIZE
2127 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
2128 + sizeof(struct ieee80211_ie_htcap) + 4
2129 + sizeof(struct ieee80211_ie_htinfo) + 4
2130 + sizeof(struct ieee80211_wme_param)
2131 #ifdef IEEE80211_SUPPORT_SUPERG
2132 + sizeof(struct ieee80211_ath_ie)
2134 + (vap->iv_appie_assocresp != NULL ?
2135 vap->iv_appie_assocresp->ie_len : 0)
2138 senderr(ENOMEM, is_tx_nobuf);
2140 capinfo = ieee80211_getcapinfo(vap, bss->ni_chan);
2141 *(uint16_t *)frm = htole16(capinfo);
2144 *(uint16_t *)frm = htole16(arg); /* status */
2147 if (arg == IEEE80211_STATUS_SUCCESS) {
2148 *(uint16_t *)frm = htole16(ni->ni_associd);
2149 IEEE80211_NODE_STAT(ni, tx_assoc);
2151 IEEE80211_NODE_STAT(ni, tx_assoc_fail);
2154 frm = ieee80211_add_rates(frm, &ni->ni_rates);
2155 frm = ieee80211_add_xrates(frm, &ni->ni_rates);
2156 /* NB: respond according to what we received */
2157 if ((ni->ni_flags & HTFLAGS) == IEEE80211_NODE_HT) {
2158 frm = ieee80211_add_htcap(frm, ni);
2159 frm = ieee80211_add_htinfo(frm, ni);
2161 if ((vap->iv_flags & IEEE80211_F_WME) &&
2162 ni->ni_ies.wme_ie != NULL)
2163 frm = ieee80211_add_wme_param(frm, &ic->ic_wme);
2164 if ((ni->ni_flags & HTFLAGS) == HTFLAGS) {
2165 frm = ieee80211_add_htcap_vendor(frm, ni);
2166 frm = ieee80211_add_htinfo_vendor(frm, ni);
2168 #ifdef IEEE80211_SUPPORT_SUPERG
2169 if (IEEE80211_ATH_CAP(vap, ni, IEEE80211_F_ATHEROS))
2170 frm = ieee80211_add_ath(frm,
2171 IEEE80211_ATH_CAP(vap, ni, IEEE80211_F_ATHEROS),
2172 ((vap->iv_flags & IEEE80211_F_WPA) == 0 &&
2173 ni->ni_authmode != IEEE80211_AUTH_8021X) ?
2174 vap->iv_def_txkey : IEEE80211_KEYIX_NONE);
2175 #endif /* IEEE80211_SUPPORT_SUPERG */
2176 if (vap->iv_appie_assocresp != NULL)
2177 frm = add_appie(frm, vap->iv_appie_assocresp);
2178 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2181 case IEEE80211_FC0_SUBTYPE_DISASSOC:
2182 IEEE80211_NOTE(vap, IEEE80211_MSG_ASSOC, ni,
2183 "send station disassociate (reason %d)", arg);
2184 m = ieee80211_getmgtframe(&frm,
2185 ic->ic_headroom + sizeof(struct ieee80211_frame),
2188 senderr(ENOMEM, is_tx_nobuf);
2189 *(uint16_t *)frm = htole16(arg); /* reason */
2190 m->m_pkthdr.len = m->m_len = sizeof(uint16_t);
2192 IEEE80211_NODE_STAT(ni, tx_disassoc);
2193 IEEE80211_NODE_STAT_SET(ni, tx_disassoc_code, arg);
2197 IEEE80211_NOTE(vap, IEEE80211_MSG_ANY, ni,
2198 "invalid mgmt frame type %u", type);
2199 senderr(EINVAL, is_tx_unknownmgt);
2203 /* NB: force non-ProbeResp frames to the highest queue */
2204 params.ibp_pri = WME_AC_VO;
2205 params.ibp_rate0 = bss->ni_txparms->mgmtrate;
2206 /* NB: we know all frames are unicast */
2207 params.ibp_try0 = bss->ni_txparms->maxretry;
2208 params.ibp_power = bss->ni_txpower;
2209 return ieee80211_mgmt_output(ni, m, type, ¶ms);
2211 ieee80211_free_node(ni);
2218 * Return an mbuf with a probe response frame in it.
2219 * Space is left to prepend and 802.11 header at the
2220 * front but it's left to the caller to fill in.
2223 ieee80211_alloc_proberesp(struct ieee80211_node *bss, int legacy)
2225 struct ieee80211vap *vap = bss->ni_vap;
2226 struct ieee80211com *ic = bss->ni_ic;
2227 const struct ieee80211_rateset *rs;
2233 * probe response frame format
2235 * [2] beacon interval
2236 * [2] cabability information
2238 * [tlv] supported rates
2239 * [tlv] parameter set (FH/DS)
2240 * [tlv] parameter set (IBSS)
2241 * [tlv] country (optional)
2242 * [3] power control (optional)
2243 * [5] channel switch announcement (CSA) (optional)
2244 * [tlv] extended rate phy (ERP)
2245 * [tlv] extended supported rates
2246 * [tlv] RSN (optional)
2247 * [tlv] HT capabilities
2248 * [tlv] HT information
2249 * [tlv] WPA (optional)
2250 * [tlv] WME (optional)
2251 * [tlv] Vendor OUI HT capabilities (optional)
2252 * [tlv] Vendor OUI HT information (optional)
2253 * [tlv] Atheros capabilities
2254 * [tlv] AppIE's (optional)
2255 * [tlv] Mesh ID (MBSS)
2256 * [tlv] Mesh Conf (MBSS)
2258 m = ieee80211_getmgtframe(&frm,
2259 ic->ic_headroom + sizeof(struct ieee80211_frame),
2263 + 2 + IEEE80211_NWID_LEN
2264 + 2 + IEEE80211_RATE_SIZE
2266 + IEEE80211_COUNTRY_MAX_SIZE
2268 + sizeof(struct ieee80211_csa_ie)
2270 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
2271 + sizeof(struct ieee80211_ie_wpa)
2272 + sizeof(struct ieee80211_ie_htcap)
2273 + sizeof(struct ieee80211_ie_htinfo)
2274 + sizeof(struct ieee80211_ie_wpa)
2275 + sizeof(struct ieee80211_wme_param)
2276 + 4 + sizeof(struct ieee80211_ie_htcap)
2277 + 4 + sizeof(struct ieee80211_ie_htinfo)
2278 #ifdef IEEE80211_SUPPORT_SUPERG
2279 + sizeof(struct ieee80211_ath_ie)
2281 #ifdef IEEE80211_SUPPORT_MESH
2282 + 2 + IEEE80211_MESHID_LEN
2283 + sizeof(struct ieee80211_meshconf_ie)
2285 + (vap->iv_appie_proberesp != NULL ?
2286 vap->iv_appie_proberesp->ie_len : 0)
2289 vap->iv_stats.is_tx_nobuf++;
2293 memset(frm, 0, 8); /* timestamp should be filled later */
2295 *(uint16_t *)frm = htole16(bss->ni_intval);
2297 capinfo = ieee80211_getcapinfo(vap, bss->ni_chan);
2298 *(uint16_t *)frm = htole16(capinfo);
2301 frm = ieee80211_add_ssid(frm, bss->ni_essid, bss->ni_esslen);
2302 rs = ieee80211_get_suprates(ic, bss->ni_chan);
2303 frm = ieee80211_add_rates(frm, rs);
2305 if (IEEE80211_IS_CHAN_FHSS(bss->ni_chan)) {
2306 *frm++ = IEEE80211_ELEMID_FHPARMS;
2308 *frm++ = bss->ni_fhdwell & 0x00ff;
2309 *frm++ = (bss->ni_fhdwell >> 8) & 0x00ff;
2310 *frm++ = IEEE80211_FH_CHANSET(
2311 ieee80211_chan2ieee(ic, bss->ni_chan));
2312 *frm++ = IEEE80211_FH_CHANPAT(
2313 ieee80211_chan2ieee(ic, bss->ni_chan));
2314 *frm++ = bss->ni_fhindex;
2316 *frm++ = IEEE80211_ELEMID_DSPARMS;
2318 *frm++ = ieee80211_chan2ieee(ic, bss->ni_chan);
2321 if (vap->iv_opmode == IEEE80211_M_IBSS) {
2322 *frm++ = IEEE80211_ELEMID_IBSSPARMS;
2324 *frm++ = 0; *frm++ = 0; /* TODO: ATIM window */
2326 if ((vap->iv_flags & IEEE80211_F_DOTH) ||
2327 (vap->iv_flags_ext & IEEE80211_FEXT_DOTD))
2328 frm = ieee80211_add_countryie(frm, ic);
2329 if (vap->iv_flags & IEEE80211_F_DOTH) {
2330 if (IEEE80211_IS_CHAN_5GHZ(bss->ni_chan))
2331 frm = ieee80211_add_powerconstraint(frm, vap);
2332 if (ic->ic_flags & IEEE80211_F_CSAPENDING)
2333 frm = ieee80211_add_csa(frm, vap);
2335 if (IEEE80211_IS_CHAN_ANYG(bss->ni_chan))
2336 frm = ieee80211_add_erp(frm, ic);
2337 frm = ieee80211_add_xrates(frm, rs);
2338 if (vap->iv_flags & IEEE80211_F_WPA2) {
2339 if (vap->iv_rsn_ie != NULL)
2340 frm = add_ie(frm, vap->iv_rsn_ie);
2341 /* XXX else complain? */
2344 * NB: legacy 11b clients do not get certain ie's.
2345 * The caller identifies such clients by passing
2346 * a token in legacy to us. Could expand this to be
2347 * any legacy client for stuff like HT ie's.
2349 if (IEEE80211_IS_CHAN_HT(bss->ni_chan) &&
2350 legacy != IEEE80211_SEND_LEGACY_11B) {
2351 frm = ieee80211_add_htcap(frm, bss);
2352 frm = ieee80211_add_htinfo(frm, bss);
2354 if (vap->iv_flags & IEEE80211_F_WPA1) {
2355 if (vap->iv_wpa_ie != NULL)
2356 frm = add_ie(frm, vap->iv_wpa_ie);
2357 /* XXX else complain? */
2359 if (vap->iv_flags & IEEE80211_F_WME)
2360 frm = ieee80211_add_wme_param(frm, &ic->ic_wme);
2361 if (IEEE80211_IS_CHAN_HT(bss->ni_chan) &&
2362 (vap->iv_flags_ht & IEEE80211_FHT_HTCOMPAT) &&
2363 legacy != IEEE80211_SEND_LEGACY_11B) {
2364 frm = ieee80211_add_htcap_vendor(frm, bss);
2365 frm = ieee80211_add_htinfo_vendor(frm, bss);
2367 #ifdef IEEE80211_SUPPORT_SUPERG
2368 if ((vap->iv_flags & IEEE80211_F_ATHEROS) &&
2369 legacy != IEEE80211_SEND_LEGACY_11B)
2370 frm = ieee80211_add_athcaps(frm, bss);
2372 if (vap->iv_appie_proberesp != NULL)
2373 frm = add_appie(frm, vap->iv_appie_proberesp);
2374 #ifdef IEEE80211_SUPPORT_MESH
2375 if (vap->iv_opmode == IEEE80211_M_MBSS) {
2376 frm = ieee80211_add_meshid(frm, vap);
2377 frm = ieee80211_add_meshconf(frm, vap);
2380 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2386 * Send a probe response frame to the specified mac address.
2387 * This does not go through the normal mgt frame api so we
2388 * can specify the destination address and re-use the bss node
2389 * for the sta reference.
2392 ieee80211_send_proberesp(struct ieee80211vap *vap,
2393 const uint8_t da[IEEE80211_ADDR_LEN], int legacy)
2395 struct ieee80211_node *bss = vap->iv_bss;
2396 struct ieee80211com *ic = vap->iv_ic;
2398 #ifdef IEEE80211_DEBUG
2399 char ethstr[ETHER_ADDRSTRLEN + 1];
2402 if (vap->iv_state == IEEE80211_S_CAC) {
2403 IEEE80211_NOTE(vap, IEEE80211_MSG_OUTPUT, bss,
2404 "block %s frame in CAC state", "probe response");
2405 vap->iv_stats.is_tx_badstate++;
2406 return EIO; /* XXX */
2410 * Hold a reference on the node so it doesn't go away until after
2411 * the xmit is complete all the way in the driver. On error we
2412 * will remove our reference.
2414 IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
2415 "ieee80211_ref_node (%s:%u) %p<%s> refcnt %d\n",
2416 __func__, __LINE__, bss, kether_ntoa(bss->ni_macaddr, ethstr),
2417 ieee80211_node_refcnt(bss)+1);
2418 ieee80211_ref_node(bss);
2420 m = ieee80211_alloc_proberesp(bss, legacy);
2422 ieee80211_free_node(bss);
2426 M_PREPEND(m, sizeof(struct ieee80211_frame), MB_DONTWAIT);
2427 KASSERT(m != NULL, ("no room for header"));
2429 ieee80211_send_setup(bss, m,
2430 IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_RESP,
2431 IEEE80211_NONQOS_TID, vap->iv_myaddr, da, bss->ni_bssid);
2432 /* XXX power management? */
2433 m->m_flags |= M_ENCAP; /* mark encapsulated */
2435 M_WME_SETAC(m, WME_AC_BE);
2437 IEEE80211_DPRINTF(vap, IEEE80211_MSG_DEBUG | IEEE80211_MSG_DUMPPKTS,
2438 "send probe resp on channel %u to %s%s\n",
2439 ieee80211_chan2ieee(ic, ic->ic_curchan), kether_ntoa(da, ethstr),
2440 legacy ? " <legacy>" : "");
2441 IEEE80211_NODE_STAT(bss, tx_mgmt);
2443 return ic->ic_raw_xmit(bss, m, NULL);
2447 * Allocate and build a RTS (Request To Send) control frame.
2450 ieee80211_alloc_rts(struct ieee80211com *ic,
2451 const uint8_t ra[IEEE80211_ADDR_LEN],
2452 const uint8_t ta[IEEE80211_ADDR_LEN],
2455 struct ieee80211_frame_rts *rts;
2458 /* XXX honor ic_headroom */
2459 m = m_gethdr(MB_DONTWAIT, MT_DATA);
2461 rts = mtod(m, struct ieee80211_frame_rts *);
2462 rts->i_fc[0] = IEEE80211_FC0_VERSION_0 |
2463 IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_RTS;
2464 rts->i_fc[1] = IEEE80211_FC1_DIR_NODS;
2465 *(u_int16_t *)rts->i_dur = htole16(dur);
2466 IEEE80211_ADDR_COPY(rts->i_ra, ra);
2467 IEEE80211_ADDR_COPY(rts->i_ta, ta);
2469 m->m_pkthdr.len = m->m_len = sizeof(struct ieee80211_frame_rts);
2475 * Allocate and build a CTS (Clear To Send) control frame.
2478 ieee80211_alloc_cts(struct ieee80211com *ic,
2479 const uint8_t ra[IEEE80211_ADDR_LEN], uint16_t dur)
2481 struct ieee80211_frame_cts *cts;
2484 /* XXX honor ic_headroom */
2485 m = m_gethdr(MB_DONTWAIT, MT_DATA);
2487 cts = mtod(m, struct ieee80211_frame_cts *);
2488 cts->i_fc[0] = IEEE80211_FC0_VERSION_0 |
2489 IEEE80211_FC0_TYPE_CTL | IEEE80211_FC0_SUBTYPE_CTS;
2490 cts->i_fc[1] = IEEE80211_FC1_DIR_NODS;
2491 *(u_int16_t *)cts->i_dur = htole16(dur);
2492 IEEE80211_ADDR_COPY(cts->i_ra, ra);
2494 m->m_pkthdr.len = m->m_len = sizeof(struct ieee80211_frame_cts);
2500 ieee80211_tx_mgt_timeout_callout(void *arg)
2502 struct ieee80211_node *ni = arg;
2503 struct ieee80211vap *vap;
2505 wlan_serialize_enter();
2507 if (vap->iv_state != IEEE80211_S_INIT &&
2508 (vap->iv_ic->ic_flags & IEEE80211_F_SCAN) == 0) {
2510 * NB: it's safe to specify a timeout as the reason here;
2511 * it'll only be used in the right state.
2513 ieee80211_new_state(vap, IEEE80211_S_SCAN,
2514 IEEE80211_SCAN_FAIL_TIMEOUT);
2516 wlan_serialize_exit();
2520 ieee80211_tx_mgt_cb(struct ieee80211_node *ni, void *arg, int status)
2522 struct ieee80211vap *vap = ni->ni_vap;
2523 enum ieee80211_state ostate = (enum ieee80211_state) arg;
2526 * Frame transmit completed; arrange timer callback. If
2527 * transmit was successfuly we wait for response. Otherwise
2528 * we arrange an immediate callback instead of doing the
2529 * callback directly since we don't know what state the driver
2530 * is in (e.g. what locks it is holding). This work should
2531 * not be too time-critical and not happen too often so the
2532 * added overhead is acceptable.
2534 * XXX what happens if !acked but response shows up before callback?
2536 if (vap->iv_state == ostate)
2537 callout_reset(&vap->iv_mgtsend,
2538 status == 0 ? IEEE80211_TRANS_WAIT*hz : 0,
2539 ieee80211_tx_mgt_timeout_callout, ni);
2543 ieee80211_beacon_construct(struct mbuf *m, uint8_t *frm,
2544 struct ieee80211_beacon_offsets *bo, struct ieee80211_node *ni)
2546 struct ieee80211vap *vap = ni->ni_vap;
2547 struct ieee80211com *ic = ni->ni_ic;
2548 struct ieee80211_rateset *rs = &ni->ni_rates;
2552 * beacon frame format
2554 * [2] beacon interval
2555 * [2] cabability information
2557 * [tlv] supported rates
2558 * [3] parameter set (DS)
2559 * [8] CF parameter set (optional)
2560 * [tlv] parameter set (IBSS/TIM)
2561 * [tlv] country (optional)
2562 * [3] power control (optional)
2563 * [5] channel switch announcement (CSA) (optional)
2564 * [tlv] extended rate phy (ERP)
2565 * [tlv] extended supported rates
2566 * [tlv] RSN parameters
2567 * [tlv] HT capabilities
2568 * [tlv] HT information
2569 * XXX Vendor-specific OIDs (e.g. Atheros)
2570 * [tlv] WPA parameters
2571 * [tlv] WME parameters
2572 * [tlv] Vendor OUI HT capabilities (optional)
2573 * [tlv] Vendor OUI HT information (optional)
2574 * [tlv] Atheros capabilities (optional)
2575 * [tlv] TDMA parameters (optional)
2576 * [tlv] Mesh ID (MBSS)
2577 * [tlv] Mesh Conf (MBSS)
2578 * [tlv] application data (optional)
2581 memset(bo, 0, sizeof(*bo));
2583 memset(frm, 0, 8); /* XXX timestamp is set by hardware/driver */
2585 *(uint16_t *)frm = htole16(ni->ni_intval);
2587 capinfo = ieee80211_getcapinfo(vap, ni->ni_chan);
2588 bo->bo_caps = (uint16_t *)frm;
2589 *(uint16_t *)frm = htole16(capinfo);
2591 *frm++ = IEEE80211_ELEMID_SSID;
2592 if ((vap->iv_flags & IEEE80211_F_HIDESSID) == 0) {
2593 *frm++ = ni->ni_esslen;
2594 memcpy(frm, ni->ni_essid, ni->ni_esslen);
2595 frm += ni->ni_esslen;
2598 frm = ieee80211_add_rates(frm, rs);
2599 if (!IEEE80211_IS_CHAN_FHSS(ni->ni_chan)) {
2600 *frm++ = IEEE80211_ELEMID_DSPARMS;
2602 *frm++ = ieee80211_chan2ieee(ic, ni->ni_chan);
2604 if (ic->ic_flags & IEEE80211_F_PCF) {
2606 frm = ieee80211_add_cfparms(frm, ic);
2609 if (vap->iv_opmode == IEEE80211_M_IBSS) {
2610 *frm++ = IEEE80211_ELEMID_IBSSPARMS;
2612 *frm++ = 0; *frm++ = 0; /* TODO: ATIM window */
2614 } else if (vap->iv_opmode == IEEE80211_M_HOSTAP ||
2615 vap->iv_opmode == IEEE80211_M_MBSS) {
2616 /* TIM IE is the same for Mesh and Hostap */
2617 struct ieee80211_tim_ie *tie = (struct ieee80211_tim_ie *) frm;
2619 tie->tim_ie = IEEE80211_ELEMID_TIM;
2620 tie->tim_len = 4; /* length */
2621 tie->tim_count = 0; /* DTIM count */
2622 tie->tim_period = vap->iv_dtim_period; /* DTIM period */
2623 tie->tim_bitctl = 0; /* bitmap control */
2624 tie->tim_bitmap[0] = 0; /* Partial Virtual Bitmap */
2625 frm += sizeof(struct ieee80211_tim_ie);
2628 bo->bo_tim_trailer = frm;
2629 if ((vap->iv_flags & IEEE80211_F_DOTH) ||
2630 (vap->iv_flags_ext & IEEE80211_FEXT_DOTD))
2631 frm = ieee80211_add_countryie(frm, ic);
2632 if (vap->iv_flags & IEEE80211_F_DOTH) {
2633 if (IEEE80211_IS_CHAN_5GHZ(ni->ni_chan))
2634 frm = ieee80211_add_powerconstraint(frm, vap);
2636 if (ic->ic_flags & IEEE80211_F_CSAPENDING)
2637 frm = ieee80211_add_csa(frm, vap);
2640 if (IEEE80211_IS_CHAN_ANYG(ni->ni_chan)) {
2642 frm = ieee80211_add_erp(frm, ic);
2644 frm = ieee80211_add_xrates(frm, rs);
2645 if (vap->iv_flags & IEEE80211_F_WPA2) {
2646 if (vap->iv_rsn_ie != NULL)
2647 frm = add_ie(frm, vap->iv_rsn_ie);
2648 /* XXX else complain */
2650 if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) {
2651 frm = ieee80211_add_htcap(frm, ni);
2652 bo->bo_htinfo = frm;
2653 frm = ieee80211_add_htinfo(frm, ni);
2655 if (vap->iv_flags & IEEE80211_F_WPA1) {
2656 if (vap->iv_wpa_ie != NULL)
2657 frm = add_ie(frm, vap->iv_wpa_ie);
2658 /* XXX else complain */
2660 if (vap->iv_flags & IEEE80211_F_WME) {
2662 frm = ieee80211_add_wme_param(frm, &ic->ic_wme);
2664 if (IEEE80211_IS_CHAN_HT(ni->ni_chan) &&
2665 (vap->iv_flags_ht & IEEE80211_FHT_HTCOMPAT)) {
2666 frm = ieee80211_add_htcap_vendor(frm, ni);
2667 frm = ieee80211_add_htinfo_vendor(frm, ni);
2669 #ifdef IEEE80211_SUPPORT_SUPERG
2670 if (vap->iv_flags & IEEE80211_F_ATHEROS) {
2672 frm = ieee80211_add_athcaps(frm, ni);
2675 #ifdef IEEE80211_SUPPORT_TDMA
2676 if (vap->iv_caps & IEEE80211_C_TDMA) {
2678 frm = ieee80211_add_tdma(frm, vap);
2681 if (vap->iv_appie_beacon != NULL) {
2683 bo->bo_appie_len = vap->iv_appie_beacon->ie_len;
2684 frm = add_appie(frm, vap->iv_appie_beacon);
2686 #ifdef IEEE80211_SUPPORT_MESH
2687 if (vap->iv_opmode == IEEE80211_M_MBSS) {
2688 frm = ieee80211_add_meshid(frm, vap);
2689 bo->bo_meshconf = frm;
2690 frm = ieee80211_add_meshconf(frm, vap);
2693 bo->bo_tim_trailer_len = frm - bo->bo_tim_trailer;
2694 bo->bo_csa_trailer_len = frm - bo->bo_csa;
2695 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2699 * Allocate a beacon frame and fillin the appropriate bits.
2702 ieee80211_beacon_alloc(struct ieee80211_node *ni,
2703 struct ieee80211_beacon_offsets *bo)
2705 struct ieee80211vap *vap = ni->ni_vap;
2706 struct ieee80211com *ic = ni->ni_ic;
2707 struct ifnet *ifp = vap->iv_ifp;
2708 struct ieee80211_frame *wh;
2714 * beacon frame format
2716 * [2] beacon interval
2717 * [2] cabability information
2719 * [tlv] supported rates
2720 * [3] parameter set (DS)
2721 * [8] CF parameter set (optional)
2722 * [tlv] parameter set (IBSS/TIM)
2723 * [tlv] country (optional)
2724 * [3] power control (optional)
2725 * [5] channel switch announcement (CSA) (optional)
2726 * [tlv] extended rate phy (ERP)
2727 * [tlv] extended supported rates
2728 * [tlv] RSN parameters
2729 * [tlv] HT capabilities
2730 * [tlv] HT information
2731 * [tlv] Vendor OUI HT capabilities (optional)
2732 * [tlv] Vendor OUI HT information (optional)
2733 * XXX Vendor-specific OIDs (e.g. Atheros)
2734 * [tlv] WPA parameters
2735 * [tlv] WME parameters
2736 * [tlv] TDMA parameters (optional)
2737 * [tlv] Mesh ID (MBSS)
2738 * [tlv] Mesh Conf (MBSS)
2739 * [tlv] application data (optional)
2740 * NB: we allocate the max space required for the TIM bitmap.
2741 * XXX how big is this?
2743 pktlen = 8 /* time stamp */
2744 + sizeof(uint16_t) /* beacon interval */
2745 + sizeof(uint16_t) /* capabilities */
2746 + 2 + ni->ni_esslen /* ssid */
2747 + 2 + IEEE80211_RATE_SIZE /* supported rates */
2748 + 2 + 1 /* DS parameters */
2749 + 2 + 6 /* CF parameters */
2750 + 2 + 4 + vap->iv_tim_len /* DTIM/IBSSPARMS */
2751 + IEEE80211_COUNTRY_MAX_SIZE /* country */
2752 + 2 + 1 /* power control */
2753 + sizeof(struct ieee80211_csa_ie) /* CSA */
2755 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
2756 + (vap->iv_caps & IEEE80211_C_WPA ? /* WPA 1+2 */
2757 2*sizeof(struct ieee80211_ie_wpa) : 0)
2758 /* XXX conditional? */
2759 + 4+2*sizeof(struct ieee80211_ie_htcap)/* HT caps */
2760 + 4+2*sizeof(struct ieee80211_ie_htinfo)/* HT info */
2761 + (vap->iv_caps & IEEE80211_C_WME ? /* WME */
2762 sizeof(struct ieee80211_wme_param) : 0)
2763 #ifdef IEEE80211_SUPPORT_SUPERG
2764 + sizeof(struct ieee80211_ath_ie) /* ATH */
2766 #ifdef IEEE80211_SUPPORT_TDMA
2767 + (vap->iv_caps & IEEE80211_C_TDMA ? /* TDMA */
2768 sizeof(struct ieee80211_tdma_param) : 0)
2770 #ifdef IEEE80211_SUPPORT_MESH
2771 + 2 + ni->ni_meshidlen
2772 + sizeof(struct ieee80211_meshconf_ie)
2774 + IEEE80211_MAX_APPIE
2776 m = ieee80211_getmgtframe(&frm,
2777 ic->ic_headroom + sizeof(struct ieee80211_frame), pktlen);
2779 IEEE80211_DPRINTF(vap, IEEE80211_MSG_ANY,
2780 "%s: cannot get buf; size %u\n", __func__, pktlen);
2781 vap->iv_stats.is_tx_nobuf++;
2784 ieee80211_beacon_construct(m, frm, bo, ni);
2786 M_PREPEND(m, sizeof(struct ieee80211_frame), MB_DONTWAIT);
2787 KASSERT(m != NULL, ("no space for 802.11 header?"));
2788 wh = mtod(m, struct ieee80211_frame *);
2789 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT |
2790 IEEE80211_FC0_SUBTYPE_BEACON;
2791 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
2792 *(uint16_t *)wh->i_dur = 0;
2793 IEEE80211_ADDR_COPY(wh->i_addr1, ifp->if_broadcastaddr);
2794 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
2795 IEEE80211_ADDR_COPY(wh->i_addr3, ni->ni_bssid);
2796 *(uint16_t *)wh->i_seq = 0;
2802 * Update the dynamic parts of a beacon frame based on the current state.
2805 ieee80211_beacon_update(struct ieee80211_node *ni,
2806 struct ieee80211_beacon_offsets *bo, struct mbuf *m, int mcast)
2808 struct ieee80211vap *vap = ni->ni_vap;
2809 struct ieee80211com *ic = ni->ni_ic;
2810 int len_changed = 0;
2814 * Handle 11h channel change when we've reached the count.
2815 * We must recalculate the beacon frame contents to account
2816 * for the new channel. Note we do this only for the first
2817 * vap that reaches this point; subsequent vaps just update
2818 * their beacon state to reflect the recalculated channel.
2820 if (isset(bo->bo_flags, IEEE80211_BEACON_CSA) &&
2821 vap->iv_csa_count == ic->ic_csa_count) {
2822 vap->iv_csa_count = 0;
2824 * Effect channel change before reconstructing the beacon
2825 * frame contents as many places reference ni_chan.
2827 if (ic->ic_csa_newchan != NULL)
2828 ieee80211_csa_completeswitch(ic);
2830 * NB: ieee80211_beacon_construct clears all pending
2831 * updates in bo_flags so we don't need to explicitly
2832 * clear IEEE80211_BEACON_CSA.
2834 ieee80211_beacon_construct(m,
2835 mtod(m, uint8_t*) + sizeof(struct ieee80211_frame), bo, ni);
2837 /* XXX do WME aggressive mode processing? */
2838 return 1; /* just assume length changed */
2841 /* XXX faster to recalculate entirely or just changes? */
2842 capinfo = ieee80211_getcapinfo(vap, ni->ni_chan);
2843 *bo->bo_caps = htole16(capinfo);
2845 if (vap->iv_flags & IEEE80211_F_WME) {
2846 struct ieee80211_wme_state *wme = &ic->ic_wme;
2849 * Check for agressive mode change. When there is
2850 * significant high priority traffic in the BSS
2851 * throttle back BE traffic by using conservative
2852 * parameters. Otherwise BE uses agressive params
2853 * to optimize performance of legacy/non-QoS traffic.
2855 if (wme->wme_flags & WME_F_AGGRMODE) {
2856 if (wme->wme_hipri_traffic >
2857 wme->wme_hipri_switch_thresh) {
2858 IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME,
2859 "%s: traffic %u, disable aggressive mode\n",
2860 __func__, wme->wme_hipri_traffic);
2861 wme->wme_flags &= ~WME_F_AGGRMODE;
2862 ieee80211_wme_updateparams_locked(vap);
2863 wme->wme_hipri_traffic =
2864 wme->wme_hipri_switch_hysteresis;
2866 wme->wme_hipri_traffic = 0;
2868 if (wme->wme_hipri_traffic <=
2869 wme->wme_hipri_switch_thresh) {
2870 IEEE80211_DPRINTF(vap, IEEE80211_MSG_WME,
2871 "%s: traffic %u, enable aggressive mode\n",
2872 __func__, wme->wme_hipri_traffic);
2873 wme->wme_flags |= WME_F_AGGRMODE;
2874 ieee80211_wme_updateparams_locked(vap);
2875 wme->wme_hipri_traffic = 0;
2877 wme->wme_hipri_traffic =
2878 wme->wme_hipri_switch_hysteresis;
2880 if (isset(bo->bo_flags, IEEE80211_BEACON_WME)) {
2881 (void) ieee80211_add_wme_param(bo->bo_wme, wme);
2882 clrbit(bo->bo_flags, IEEE80211_BEACON_WME);
2886 if (isset(bo->bo_flags, IEEE80211_BEACON_HTINFO)) {
2887 ieee80211_ht_update_beacon(vap, bo);
2888 clrbit(bo->bo_flags, IEEE80211_BEACON_HTINFO);
2890 #ifdef IEEE80211_SUPPORT_TDMA
2891 if (vap->iv_caps & IEEE80211_C_TDMA) {
2893 * NB: the beacon is potentially updated every TBTT.
2895 ieee80211_tdma_update_beacon(vap, bo);
2898 #ifdef IEEE80211_SUPPORT_MESH
2899 if (vap->iv_opmode == IEEE80211_M_MBSS)
2900 ieee80211_mesh_update_beacon(vap, bo);
2903 if (vap->iv_opmode == IEEE80211_M_HOSTAP ||
2904 vap->iv_opmode == IEEE80211_M_MBSS) { /* NB: no IBSS support*/
2905 struct ieee80211_tim_ie *tie =
2906 (struct ieee80211_tim_ie *) bo->bo_tim;
2907 if (isset(bo->bo_flags, IEEE80211_BEACON_TIM)) {
2908 u_int timlen, timoff, i;
2910 * ATIM/DTIM needs updating. If it fits in the
2911 * current space allocated then just copy in the
2912 * new bits. Otherwise we need to move any trailing
2913 * data to make room. Note that we know there is
2914 * contiguous space because ieee80211_beacon_allocate
2915 * insures there is space in the mbuf to write a
2916 * maximal-size virtual bitmap (based on iv_max_aid).
2919 * Calculate the bitmap size and offset, copy any
2920 * trailer out of the way, and then copy in the
2921 * new bitmap and update the information element.
2922 * Note that the tim bitmap must contain at least
2923 * one byte and any offset must be even.
2925 if (vap->iv_ps_pending != 0) {
2926 timoff = 128; /* impossibly large */
2927 for (i = 0; i < vap->iv_tim_len; i++)
2928 if (vap->iv_tim_bitmap[i]) {
2932 KASSERT(timoff != 128, ("tim bitmap empty!"));
2933 for (i = vap->iv_tim_len-1; i >= timoff; i--)
2934 if (vap->iv_tim_bitmap[i])
2936 timlen = 1 + (i - timoff);
2941 if (timlen != bo->bo_tim_len) {
2942 /* copy up/down trailer */
2943 int adjust = tie->tim_bitmap+timlen
2944 - bo->bo_tim_trailer;
2945 ovbcopy(bo->bo_tim_trailer,
2946 bo->bo_tim_trailer+adjust,
2947 bo->bo_tim_trailer_len);
2948 bo->bo_tim_trailer += adjust;
2949 bo->bo_erp += adjust;
2950 bo->bo_htinfo += adjust;
2951 #ifdef IEEE80211_SUPERG_SUPPORT
2952 bo->bo_ath += adjust;
2954 #ifdef IEEE80211_TDMA_SUPPORT
2955 bo->bo_tdma += adjust;
2957 #ifdef IEEE80211_MESH_SUPPORT
2958 bo->bo_meshconf += adjust;
2960 bo->bo_appie += adjust;
2961 bo->bo_wme += adjust;
2962 bo->bo_csa += adjust;
2963 bo->bo_tim_len = timlen;
2965 /* update information element */
2966 tie->tim_len = 3 + timlen;
2967 tie->tim_bitctl = timoff;
2970 memcpy(tie->tim_bitmap, vap->iv_tim_bitmap + timoff,
2973 clrbit(bo->bo_flags, IEEE80211_BEACON_TIM);
2975 IEEE80211_DPRINTF(vap, IEEE80211_MSG_POWER,
2976 "%s: TIM updated, pending %u, off %u, len %u\n",
2977 __func__, vap->iv_ps_pending, timoff, timlen);
2979 /* count down DTIM period */
2980 if (tie->tim_count == 0)
2981 tie->tim_count = tie->tim_period - 1;
2984 /* update state for buffered multicast frames on DTIM */
2985 if (mcast && tie->tim_count == 0)
2986 tie->tim_bitctl |= 1;
2988 tie->tim_bitctl &= ~1;
2989 if (isset(bo->bo_flags, IEEE80211_BEACON_CSA)) {
2990 struct ieee80211_csa_ie *csa =
2991 (struct ieee80211_csa_ie *) bo->bo_csa;
2994 * Insert or update CSA ie. If we're just starting
2995 * to count down to the channel switch then we need
2996 * to insert the CSA ie. Otherwise we just need to
2997 * drop the count. The actual change happens above
2998 * when the vap's count reaches the target count.
3000 if (vap->iv_csa_count == 0) {
3001 memmove(&csa[1], csa, bo->bo_csa_trailer_len);
3002 bo->bo_erp += sizeof(*csa);
3003 bo->bo_htinfo += sizeof(*csa);
3004 bo->bo_wme += sizeof(*csa);
3005 #ifdef IEEE80211_SUPERG_SUPPORT
3006 bo->bo_ath += sizeof(*csa);
3008 #ifdef IEEE80211_TDMA_SUPPORT
3009 bo->bo_tdma += sizeof(*csa);
3011 #ifdef IEEE80211_MESH_SUPPORT
3012 bo->bo_meshconf += sizeof(*csa);
3014 bo->bo_appie += sizeof(*csa);
3015 bo->bo_csa_trailer_len += sizeof(*csa);
3016 bo->bo_tim_trailer_len += sizeof(*csa);
3017 m->m_len += sizeof(*csa);
3018 m->m_pkthdr.len += sizeof(*csa);
3020 ieee80211_add_csa(bo->bo_csa, vap);
3023 vap->iv_csa_count++;
3024 /* NB: don't clear IEEE80211_BEACON_CSA */
3026 if (isset(bo->bo_flags, IEEE80211_BEACON_ERP)) {
3028 * ERP element needs updating.
3030 (void) ieee80211_add_erp(bo->bo_erp, ic);
3031 clrbit(bo->bo_flags, IEEE80211_BEACON_ERP);
3033 #ifdef IEEE80211_SUPPORT_SUPERG
3034 if (isset(bo->bo_flags, IEEE80211_BEACON_ATH)) {
3035 ieee80211_add_athcaps(bo->bo_ath, ni);
3036 clrbit(bo->bo_flags, IEEE80211_BEACON_ATH);
3040 if (isset(bo->bo_flags, IEEE80211_BEACON_APPIE)) {
3041 const struct ieee80211_appie *aie = vap->iv_appie_beacon;
3047 aielen += aie->ie_len;
3048 if (aielen != bo->bo_appie_len) {
3049 /* copy up/down trailer */
3050 int adjust = aielen - bo->bo_appie_len;
3051 ovbcopy(bo->bo_tim_trailer, bo->bo_tim_trailer+adjust,
3052 bo->bo_tim_trailer_len);
3053 bo->bo_tim_trailer += adjust;
3054 bo->bo_appie += adjust;
3055 bo->bo_appie_len = aielen;
3061 frm = add_appie(frm, aie);
3062 clrbit(bo->bo_flags, IEEE80211_BEACON_APPIE);