Lines Matching +full:timeout +full:- +full:pwr +full:- +full:ms
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
5 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
98 return (vap->iv_opmode == IEEE80211_M_IBSS);
111 * A-MPDU state stuff, fast-frames state stuff, encapsulation
124 struct ieee80211com *ic = vap->iv_ic;
125 struct ifnet *ifp = vap->iv_ifp;
135 if ((ni->ni_flags & IEEE80211_NODE_PWR_MGT) &&
136 (m->m_flags & M_PWR_SAV) == 0) {
156 ni->ni_macaddr, NULL,
158 vap->iv_stats.is_tx_classify++;
172 MPASS((m->m_pkthdr.csum_flags & CSUM_SND_TAG) == 0);
173 m->m_pkthdr.rcvif = (void *)ni;
174 mcast = (m->m_flags & (M_MCAST | M_BCAST)) ? 1: 0;
179 * Figure out if we can do A-MPDU, A-MSDU or FF.
181 * A-MPDU depends upon vap/node config.
182 * A-MSDU depends upon vap/node config.
189 do_ampdu = ((ni->ni_flags & IEEE80211_NODE_AMPDU_TX) &&
190 (vap->iv_flags_ht & IEEE80211_FHT_AMPDU_TX));
192 do_amsdu = ((ni->ni_flags & IEEE80211_NODE_AMSDU_TX) &&
193 (vap->iv_flags_ht & IEEE80211_FHT_AMSDU_TX));
195 ((ni->ni_flags & IEEE80211_NODE_HT) == 0) &&
196 ((ni->ni_flags & IEEE80211_NODE_VHT) == 0) &&
201 * Check if A-MPDU tx aggregation is setup or if we
203 * with HT and A-MPDU enabled for use. When the policy
204 * routine decides we should enable A-MPDU we issue an
206 * encapsulated will go out w/o using A-MPDU, or possibly
212 * Don't treat group-addressed frames as candidates for aggregation;
213 * net80211 doesn't support 802.11aa-2012 and so group addressed
218 if ((m->m_flags & M_EAPOL) == 0 && (! mcast)) {
220 struct ieee80211_tx_ampdu *tap = &ni->ni_tx_ampdu[tid];
229 m->m_flags |= M_AMPDU_MPDU;
231 ic->ic_ampdu_enable(ni, tap)) {
239 * Now update the no-ampdu flag. A-MPDU may have been
243 * This will let us know whether we should be doing A-MSDU
244 * at this point. We only do A-MSDU if we're either not
245 * doing A-MPDU, or A-MPDU is NACKed, or A-MPDU + A-MSDU
248 * Whilst here, update the amsdu-ampdu flag. The above may
249 * have also set or cleared the amsdu-in-ampdu txa_flags
250 * combination so we can correctly do A-MPDU + A-MSDU.
265 * A-MSDU encapsulation for 802.3 drivers. Now, we
268 * to really need to. For A-MSDU we'd have to set the
269 * A-MSDU QoS bit in the wifi header, so we just plain
272 if (__predict_true((vap->iv_caps & IEEE80211_C_8023ENCAP) == 0)) {
298 * Grab the TX lock - serialise the TX process from this
306 * so things like the FF (and later A-MSDU) path can just call
309 if (__predict_true((vap->iv_caps & IEEE80211_C_8023ENCAP) == 0)) {
325 * Unlock at this point - no need to hold it across
329 ic->ic_lastdata = ticks;
341 * does (eg CAC timeout, interface wakeup) - the caller must
348 (vap->iv_opmode == IEEE80211_M_WDS && \
349 (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY) == 0)
350 struct ieee80211com *ic = vap->iv_ic;
351 struct ifnet *ifp = vap->iv_ifp;
358 if (ic->ic_flags & IEEE80211_F_SCAN)
368 if (m->m_len < sizeof(struct ether_header) &&
372 vap->iv_stats.is_tx_nobuf++; /* XXX */
377 if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
386 eh->ether_dhost, "mcast", "%s", "on DWDS");
387 vap->iv_stats.is_dwds_mcast++;
393 if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
402 if (vap->iv_opmode != IEEE80211_M_MBSS) {
404 ni = ieee80211_find_txnode(vap, eh->ether_dhost);
412 if (ni->ni_associd == 0 &&
413 (ni->ni_flags & IEEE80211_NODE_ASSOCID)) {
415 eh->ether_dhost, NULL,
417 htons(eh->ether_type));
418 vap->iv_stats.is_tx_notassoc++;
427 if (!IEEE80211_ADDR_EQ(eh->ether_shost, vap->iv_myaddr)) {
435 eh->ether_dhost, NULL,
437 vap->iv_stats.is_mesh_notproxy++;
445 eh->ether_shost, ":",
446 eh->ether_dhost, ":");
447 ieee80211_mesh_proxy_check(vap, eh->ether_shost);
449 ni = ieee80211_mesh_discover(vap, eh->ether_dhost, m);
466 if (vap->iv_state == IEEE80211_S_SLEEP) {
471 ic->ic_lastdata = ticks;
496 struct ieee80211vap *vap = ifp->if_softc;
497 struct ieee80211com *ic = vap->iv_ic;
505 if (vap->iv_state != IEEE80211_S_RUN &&
506 vap->iv_state != IEEE80211_S_SLEEP) {
508 /* re-check under the com lock to avoid races */
509 if (vap->iv_state != IEEE80211_S_RUN &&
510 vap->iv_state != IEEE80211_S_SLEEP) {
513 __func__, ieee80211_state_name[vap->iv_state]);
514 vap->iv_stats.is_tx_badstate++;
516 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
527 * be set for frames that are re-submitted from the
533 m->m_flags &= ~(M_80211_TX - M_PWR_SAV - M_MORE_DATA);
553 * XXX keep the pwr mgmt bit set if it decides to call into the
563 struct ieee80211com *ic = vap->iv_ic;
567 * Set node - the caller has taken a reference, so ensure
571 MPASS((m->m_pkthdr.csum_flags & CSUM_SND_TAG) == 0);
572 m->m_pkthdr.rcvif = (void *)ni;
581 * they'll have to be added - so fail the transmit if
587 error = ic->ic_raw_xmit(ni, m, params);
589 if_inc_counter(vap->iv_ifp, IFCOUNTER_OERRORS, 1);
602 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame_ack))
609 type = wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
611 if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) !=
616 (wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG) != 0)
622 if ((params && (params->ibp_flags & IEEE80211_BPF_CRYPTO) != 0) ||
626 subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
629 * See IEEE Std 802.11-2012,
638 wh->i_fc[1] |= IEEE80211_FC1_PROTECTED;
641 if (m->m_pkthdr.len < ieee80211_anyhdrsize(wh))
650 struct ieee80211com *ic = ni->ni_ic;
653 if ((ic->ic_htcaps & IEEE80211_HTC_HT) == 0)
658 if (rate > ic->ic_txstream * 8 - 1)
665 if ((ic->ic_htcaps & IEEE80211_HTC_TXMCS32) == 0)
671 if ((ic->ic_htcaps & IEEE80211_HTC_TXUNEQUAL) == 0)
674 switch (ic->ic_txstream) {
697 if (!ieee80211_isratevalid(ic->ic_rt, rate))
713 if (params->ibp_rate0 != 0) {
714 error = ieee80211_validate_rate(ni, params->ibp_rate0);
718 /* XXX pre-setup some default (e.g., mgmt / mcast) rate */
723 if (params->ibp_rate1 != 0 &&
724 (error = ieee80211_validate_rate(ni, params->ibp_rate1)) != 0)
727 if (params->ibp_rate2 != 0 &&
728 (error = ieee80211_validate_rate(ni, params->ibp_rate2)) != 0)
731 if (params->ibp_rate3 != 0 &&
732 (error = ieee80211_validate_rate(ni, params->ibp_rate3)) != 0)
756 if (ifp->if_drv_flags & IFF_DRV_OACTIVE) {
758 * Short-circuit requests if the vap is marked OACTIVE
767 vap = ifp->if_softc;
768 ic = vap->iv_ic;
773 if (dst->sa_family != AF_IEEE80211)
774 return vap->iv_output(ifp, m, dst, ro);
780 if (ifp->if_flags & IFF_MONITOR)
784 if (vap->iv_state == IEEE80211_S_CAC) {
788 vap->iv_stats.is_tx_badstate++;
790 } else if (vap->iv_state == IEEE80211_S_SCAN)
800 if (dst->sa_len != 0)
801 params = (const struct ieee80211_bpf_params *)dst->sa_data;
810 switch (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) {
813 ni = ieee80211_find_txnode(vap, wh->i_addr1);
817 ni = ieee80211_find_txnode(vap, wh->i_addr3);
827 if (dst->sa_len == 0)
829 ni = ieee80211_ref_node(vap->iv_bss);
838 m->m_flags &= ~M_80211_TX;
839 m->m_flags |= M_ENCAP; /* mark encapsulated */
848 m->m_pkthdr.len - ieee80211_hdrsize(wh));
857 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
859 m->m_flags |= M_MCAST;
892 struct ieee80211vap *vap = ni->ni_vap;
897 IEEE80211_TX_LOCK_ASSERT(ni->ni_ic);
899 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | type;
901 switch (vap->iv_opmode) {
903 wh->i_fc[1] = IEEE80211_FC1_DIR_TODS;
904 IEEE80211_ADDR_COPY(wh->i_addr1, bssid);
905 IEEE80211_ADDR_COPY(wh->i_addr2, sa);
906 IEEE80211_ADDR_COPY(wh->i_addr3, da);
910 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
911 IEEE80211_ADDR_COPY(wh->i_addr1, da);
912 IEEE80211_ADDR_COPY(wh->i_addr2, sa);
913 IEEE80211_ADDR_COPY(wh->i_addr3, bssid);
916 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
917 IEEE80211_ADDR_COPY(wh->i_addr1, da);
918 IEEE80211_ADDR_COPY(wh->i_addr2, bssid);
919 IEEE80211_ADDR_COPY(wh->i_addr3, sa);
922 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
923 IEEE80211_ADDR_COPY(wh->i_addr1, da);
924 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
925 IEEE80211_ADDR_COPY(wh->i_addr3, da);
926 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, sa);
931 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
933 IEEE80211_ADDR_COPY(wh->i_addr1, da);
934 IEEE80211_ADDR_COPY(wh->i_addr2,
935 vap->iv_myaddr);
937 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
938 IEEE80211_ADDR_COPY(wh->i_addr1, da);
939 IEEE80211_ADDR_COPY(wh->i_addr2,
940 vap->iv_myaddr);
941 IEEE80211_ADDR_COPY(wh->i_addr3, da);
942 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, sa);
950 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
951 IEEE80211_ADDR_COPY(wh->i_addr1, da);
952 IEEE80211_ADDR_COPY(wh->i_addr2, sa);
954 if (vap->iv_opmode == IEEE80211_M_MBSS)
955 IEEE80211_ADDR_COPY(wh->i_addr3, sa);
958 IEEE80211_ADDR_COPY(wh->i_addr3, bssid);
960 *(uint16_t *)&wh->i_dur[0] = 0;
965 * need to be in lock-step with what the driver is doing
972 tap = &ni->ni_tx_ampdu[tid];
974 m->m_flags |= M_AMPDU_MPDU;
977 *(uint16_t *)&wh->i_seq[0] = 0;
982 * 802.11-2012 9.3.2.10 - QoS multicast frames
985 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
986 seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]++;
988 seqno = ni->ni_txseqs[tid]++;
993 *(uint16_t *)&wh->i_seq[0] =
998 if (IEEE80211_IS_MULTICAST(wh->i_addr1))
999 m->m_flags |= M_MCAST;
1015 struct ieee80211vap *vap = ni->ni_vap;
1016 struct ieee80211com *ic = ni->ni_ic;
1022 if (vap->iv_state == IEEE80211_S_CAC) {
1026 vap->iv_stats.is_tx_badstate++;
1043 vap->iv_myaddr, ni->ni_macaddr, ni->ni_bssid);
1044 if (params->ibp_flags & IEEE80211_BPF_CRYPTO) {
1045 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_AUTH, wh->i_addr1,
1047 wh->i_fc[1] |= IEEE80211_FC1_PROTECTED;
1049 m->m_flags |= M_ENCAP; /* mark encapsulated */
1052 M_WME_SETAC(m, params->ibp_pri);
1059 ether_sprintf(wh->i_addr1),
1061 ieee80211_chan2ieee(ic, ic->ic_curchan));
1075 struct ieee80211vap *vap = ni->ni_vap;
1083 * If this is a WDS station then a 4-address frame is constructed.
1095 struct ieee80211vap *vap = ni->ni_vap;
1096 struct ieee80211com *ic = ni->ni_ic;
1103 if (vap->iv_state == IEEE80211_S_CAC) {
1107 vap->iv_stats.is_tx_badstate++;
1111 if (ni->ni_flags & (IEEE80211_NODE_QOS|IEEE80211_NODE_HT))
1115 /* NB: only WDS vap's get 4-address frames */
1116 if (vap->iv_opmode == IEEE80211_M_WDS)
1118 if (ic->ic_flags & IEEE80211_F_DATAPAD)
1121 m = ieee80211_getmgtframe(&frm, ic->ic_headroom + hdrlen, 0);
1125 vap->iv_stats.is_tx_nobuf++;
1140 if (ni->ni_flags & IEEE80211_NODE_QOS) {
1146 tid, vap->iv_myaddr, ni->ni_macaddr, ni->ni_bssid);
1148 if (vap->iv_opmode == IEEE80211_M_WDS)
1149 qos = ((struct ieee80211_qosframe_addr4 *) wh)->i_qos;
1151 qos = ((struct ieee80211_qosframe *) wh)->i_qos;
1153 if (ic->ic_wme.wme_wmeChanParams.cap_wmeParams[WME_AC_BE].wmep_noackPolicy)
1160 vap->iv_myaddr, ni->ni_macaddr, ni->ni_bssid);
1162 if (vap->iv_opmode != IEEE80211_M_WDS) {
1164 if ((ni->ni_flags & IEEE80211_NODE_PWR_MGT) &&
1165 vap->iv_opmode != IEEE80211_M_HOSTAP)
1166 wh->i_fc[1] |= IEEE80211_FC1_PWR_MGT;
1168 if ((ic->ic_flags & IEEE80211_F_SCAN) &&
1169 (ni->ni_flags & IEEE80211_NODE_PWR_MGT)) {
1173 m->m_len = m->m_pkthdr.len = hdrlen;
1174 m->m_flags |= M_ENCAP; /* mark encapsulated */
1181 "send %snull data frame on channel %u, pwr mgt %s",
1182 ni->ni_flags & IEEE80211_NODE_QOS ? "QoS " : "",
1183 ieee80211_chan2ieee(ic, ic->ic_curchan),
1184 wh->i_fc[1] & IEEE80211_FC1_PWR_MGT ? "ena" : "dis");
1204 if (__predict_false(m->m_flags & M_ENCAP)) {
1209 subtype = wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
1216 if (m->m_pkthdr.len < hdrlen + sizeof(*llc))
1220 if (llc->llc_dsap != LLC_SNAP_LSAP ||
1221 llc->llc_ssap != LLC_SNAP_LSAP ||
1222 llc->llc_control != LLC_UI ||
1223 llc->llc_snap.org_code[0] != 0 ||
1224 llc->llc_snap.org_code[1] != 0 ||
1225 llc->llc_snap.org_code[2] != 0)
1228 ether_type = llc->llc_snap.ether_type;
1231 ether_type = eh->ether_type;
1239 m->m_flags |= M_EAPOL;
1244 * Non-qos traffic goes to BE.
1246 if ((ni->ni_flags & IEEE80211_NODE_QOS) == 0) {
1256 if (ni->ni_vlan != 0) {
1257 if ((m->m_flags & M_VLANTAG) == 0) {
1261 if (EVL_VLANOFTAG(m->m_pkthdr.ether_vtag) !=
1262 EVL_VLANOFTAG(ni->ni_vlan)) {
1267 v_wme_ac = TID_TO_WME_AC(EVL_PRIOFTAG(ni->ni_vlan));
1274 switch (ntohs(eh->ether_type)) {
1324 if (ni->ni_vap->iv_opmode == IEEE80211_M_STA) {
1331 struct ieee80211com *ic = ni->ni_ic;
1334 ic->ic_wme.wme_wmeBssChanParams.cap_wmeParams[ac].wmep_acm)
1352 #define TO_BE_RECLAIMED (sizeof(struct ether_header) - sizeof(struct llc))
1353 int needed_space = vap->iv_ic->ic_headroom + hdrsize;
1357 needed_space += key->wk_cipher->ic_header;
1365 if (key->wk_flags & (IEEE80211_KEY_SWENCRYPT|IEEE80211_KEY_SWENMIC)) {
1370 vap->iv_stats.is_tx_nobuf++; /* XXX new stat */
1379 * sizeof(struct ether_header) - sizeof(struct llc)
1384 if (M_LEADINGSPACE(m) < needed_space - TO_BE_RECLAIMED) {
1385 struct mbuf *n = m_gethdr(IEEE80211_M_NOWAIT, m->m_type);
1389 vap->iv_stats.is_tx_nobuf++;
1403 n->m_len = 0; /* NB: m_gethdr does not set */
1404 n->m_data += needed_space;
1412 n->m_len += sizeof(struct ether_header);
1413 m->m_len -= sizeof(struct ether_header);
1414 m->m_data += sizeof(struct ether_header);
1418 n->m_next = m;
1434 if (IEEE80211_KEY_UNDEFINED(&ni->ni_ucastkey)) {
1435 if (vap->iv_def_txkey == IEEE80211_KEYIX_NONE ||
1436 IEEE80211_KEY_UNDEFINED(&vap->iv_nw_keys[vap->iv_def_txkey]))
1438 return &vap->iv_nw_keys[vap->iv_def_txkey];
1440 return &ni->ni_ucastkey;
1453 if (vap->iv_def_txkey == IEEE80211_KEYIX_NONE ||
1454 IEEE80211_KEY_UNDEFINED(&vap->iv_nw_keys[vap->iv_def_txkey]))
1456 return &vap->iv_nw_keys[vap->iv_def_txkey];
1474 struct ieee80211com *ic = ni->ni_ic;
1476 struct ieee80211_mesh_state *ms = vap->iv_mesh;
1479 int dir = -1;
1493 is_mcast = !! (m->m_flags & (M_MCAST | M_BCAST));
1500 KASSERT(m->m_len >= sizeof(eh), ("no ethernet header!"));
1515 if (vap->iv_flags & IEEE80211_F_PRIVACY) {
1516 if (vap->iv_opmode == IEEE80211_M_STA ||
1518 (vap->iv_opmode == IEEE80211_M_WDS &&
1519 (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY))) {
1521 } else if ((vap->iv_opmode == IEEE80211_M_WDS) &&
1522 (! (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY))) {
1533 * AP VAP, the dynamically created per-STA WDS node)
1540 if (key == NULL && (m->m_flags & M_EAPOL) == 0) {
1544 __func__, vap->iv_def_txkey);
1545 vap->iv_stats.is_tx_nodefkey++;
1551 * XXX Some ap's don't handle QoS-encapsulated EAPOL
1553 * ap's require all data frames to be QoS-encapsulated
1564 (((is_mcast == 0) && (ni->ni_flags &
1566 (vap->iv_opmode == IEEE80211_M_MBSS)) &&
1567 (m->m_flags & M_EAPOL) == 0;
1574 if (vap->iv_opmode == IEEE80211_M_MBSS) {
1579 * at the local sta are sent w/ 3-address format and
1582 * at the local sta are sent w/ 4-address format and
1584 * o Group Addressed data forwarded from a non-mesh sta are
1585 * sent w/ 3-address format and address extension mode 01
1587 * w/ 4-address format and address extension mode 10
1595 if (rt->rt_flags & IEEE80211_MESHRT_FLAGS_PROXY) {
1596 if (IEEE80211_ADDR_EQ(rt->rt_mesh_gate,
1597 vap->iv_myaddr)) {
1614 if (!IEEE80211_ADDR_EQ(eh.ether_shost, vap->iv_myaddr)) {
1628 * 4-address frames need to be generated for:
1633 is4addr = vap->iv_opmode == IEEE80211_M_WDS ||
1634 ((vap->iv_flags_ext & IEEE80211_FEXT_4ADDR) &&
1635 !IEEE80211_ADDR_EQ(eh.ether_shost, vap->iv_myaddr));
1645 if (ic->ic_flags & IEEE80211_F_DATAPAD)
1650 if (__predict_true((m->m_flags & M_FF) == 0)) {
1660 m_adj(m, sizeof(struct ether_header) - sizeof(struct llc));
1662 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
1663 llc->llc_control = LLC_UI;
1664 llc->llc_snap.org_code[0] = 0;
1665 llc->llc_snap.org_code[1] = 0;
1666 llc->llc_snap.org_code[2] = 0;
1667 llc->llc_snap.ether_type = eh.ether_type;
1688 datalen = m->m_pkthdr.len; /* NB: w/o 802.11 header */
1692 vap->iv_stats.is_tx_nobuf++;
1696 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_DATA;
1697 *(uint16_t *)wh->i_dur = 0;
1700 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
1701 IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr);
1702 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1703 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
1704 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, eh.ether_shost);
1705 } else switch (vap->iv_opmode) {
1707 wh->i_fc[1] = IEEE80211_FC1_DIR_TODS;
1708 IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_bssid);
1709 IEEE80211_ADDR_COPY(wh->i_addr2, eh.ether_shost);
1710 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
1714 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
1715 IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost);
1716 IEEE80211_ADDR_COPY(wh->i_addr2, eh.ether_shost);
1721 IEEE80211_ADDR_COPY(wh->i_addr3, vap->iv_bss->ni_bssid);
1724 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
1725 IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost);
1726 IEEE80211_ADDR_COPY(wh->i_addr2, ni->ni_bssid);
1727 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_shost);
1734 wh->i_fc[1] = dir;
1737 mc->mc_flags = 0;
1739 IEEE80211_ADDR_COPY(wh->i_addr1,
1740 ni->ni_macaddr);
1741 IEEE80211_ADDR_COPY(wh->i_addr2,
1742 vap->iv_myaddr);
1743 IEEE80211_ADDR_COPY(wh->i_addr3,
1745 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4,
1748 wh)->i_qos;
1751 IEEE80211_ADDR_COPY(wh->i_addr1,
1753 IEEE80211_ADDR_COPY(wh->i_addr2,
1754 vap->iv_myaddr);
1755 IEEE80211_ADDR_COPY(wh->i_addr3,
1758 wh)->i_qos;
1762 wh->i_fc[1] = IEEE80211_FC1_DIR_FROMDS;
1763 IEEE80211_ADDR_COPY(wh->i_addr1, eh.ether_dhost);
1764 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1765 IEEE80211_ADDR_COPY(wh->i_addr3, vap->iv_myaddr);
1766 mc->mc_flags = 1;
1767 IEEE80211_ADDR_COPY(MC01(mc)->mc_addr4,
1769 qos = ((struct ieee80211_qosframe *) wh)->i_qos;
1773 IEEE80211_ADDR_COPY(wh->i_addr1, rt->rt_nexthop);
1774 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1775 IEEE80211_ADDR_COPY(wh->i_addr3, rt->rt_mesh_gate);
1776 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, vap->iv_myaddr);
1777 mc->mc_flags = IEEE80211_MESH_AE_10;
1778 IEEE80211_ADDR_COPY(mc->mc_addr5, eh.ether_dhost);
1779 IEEE80211_ADDR_COPY(mc->mc_addr6, eh.ether_shost);
1780 qos = ((struct ieee80211_qosframe_addr4 *) wh)->i_qos;
1786 mc->mc_ttl = ms->ms_ttl;
1787 ms->ms_seq++;
1788 le32enc(mc->mc_seq, ms->ms_seq);
1795 if (m->m_flags & M_MORE_DATA)
1796 wh->i_fc[1] |= IEEE80211_FC1_MORE_DATA;
1801 qos = ((struct ieee80211_qosframe_addr4 *) wh)->i_qos;
1803 } else if (vap->iv_opmode != IEEE80211_M_MBSS)
1804 qos = ((struct ieee80211_qosframe *) wh)->i_qos;
1809 if (ic->ic_wme.wme_wmeChanParams.cap_wmeParams[ac].wmep_noackPolicy)
1812 if (vap->iv_opmode == IEEE80211_M_MBSS)
1817 wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_QOS_DATA;
1820 * If this is an A-MSDU then ensure we set the
1831 if ((m->m_flags & M_AMPDU_MPDU) == 0) {
1833 * 802.11-2012 9.3.2.10 -
1843 if (IEEE80211_IS_MULTICAST(wh->i_addr1))
1844 seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]++;
1846 seqno = ni->ni_txseqs[tid]++;
1860 *(uint16_t *)wh->i_seq =
1865 *(uint16_t *)wh->i_seq = 0;
1873 seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]++;
1874 *(uint16_t *)wh->i_seq =
1880 * be forced to be non-QoS traffic to be A-MSDU encapsulated.
1896 txfrag = (m->m_pkthdr.len > vap->iv_fragthreshold &&
1897 !IEEE80211_IS_MULTICAST(wh->i_addr1) &&
1898 (vap->iv_caps & IEEE80211_C_TXFRAG) &&
1899 (m->m_flags & (M_FF | M_AMPDU_MPDU)) == 0);
1906 if ((m->m_flags & M_EAPOL) == 0 ||
1907 ((vap->iv_flags & IEEE80211_F_WPA) &&
1908 (vap->iv_opmode == IEEE80211_M_STA ?
1910 !IEEE80211_KEY_UNDEFINED(&ni->ni_ucastkey)))) {
1911 wh->i_fc[1] |= IEEE80211_FC1_PROTECTED;
1916 vap->iv_stats.is_crypto_enmicfail++;
1922 key != NULL ? key->wk_cipher->ic_header : 0, vap->iv_fragthreshold))
1925 m->m_flags |= M_ENCAP; /* mark encapsulated */
1928 if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
1930 m->m_flags |= M_MCAST;
1953 next = m->m_nextpkt;
1954 m->m_nextpkt = NULL;
1971 struct ieee80211com *ic = vap->iv_ic;
1977 KASSERT(m0->m_nextpkt == NULL, ("mbuf already chained?"));
1978 KASSERT(m0->m_pkthdr.len > mtu,
1979 ("pktlen %u mtu %u", m0->m_pkthdr.len, mtu));
1984 if (ic->ic_flags & IEEE80211_F_DATAPAD)
1991 wh->i_fc[1] |= IEEE80211_FC1_MORE_FRAG;
1994 off = mtu - ciphdrsize;
1995 remainder = m0->m_pkthdr.len - off;
2003 m_align(m, fragsize - ciphdrsize);
2015 if (vap->iv_opmode == IEEE80211_M_MBSS)
2018 *(uint16_t *)&whf->i_seq[0] |= htole16(
2023 payload = fragsize - totalhdrsize;
2027 m->m_len = hdrspace + payload;
2028 m->m_pkthdr.len = hdrspace + payload;
2029 m->m_flags |= M_FRAG;
2032 prev->m_nextpkt = m;
2036 remainder -= payload;
2041 m->m_flags |= M_LASTFRAG;
2042 whf->i_fc[1] &= ~IEEE80211_FC1_MORE_FRAG;
2045 m_adj(m0, -(m0->m_pkthdr.len - (mtu - ciphdrsize)));
2046 m0->m_flags |= M_FIRSTFRAG | M_FRAG;
2048 vap->iv_stats.is_tx_fragframes++;
2049 vap->iv_stats.is_tx_frags += fragno-1;
2054 ieee80211_free_mbuf(m0->m_nextpkt);
2055 m0->m_nextpkt = NULL;
2068 nrates = rs->rs_nrates;
2072 memcpy(frm, rs->rs_rates, nrates);
2085 if (rs->rs_nrates > IEEE80211_RATE_SIZE) {
2086 int nrates = rs->rs_nrates - IEEE80211_RATE_SIZE;
2089 memcpy(frm, rs->rs_rates + IEEE80211_RATE_SIZE, nrates);
2113 struct ieee80211com *ic = vap->iv_ic;
2122 * the per-VAP flags are fine for per-VAP, but don't
2131 if (ic->ic_flags_ext & IEEE80211_FEXT_NONERP_PR)
2137 * of per-VAP and channels.
2139 if (ic->ic_flags & IEEE80211_F_USEPROT)
2141 if (ic->ic_flags & IEEE80211_F_USEBARKER)
2170 memcpy(frm, ie->ie_data, ie->ie_len);
2171 return frm + ie->ie_len;
2190 struct ieee80211vap *vap = ni->ni_vap;
2193 *frm++ = sizeof(struct ieee80211_wme_info) - 2;
2200 switch (vap->iv_opmode) {
2202 *frm = wme->wme_bssChanParams.cap_info;
2203 if (vap->iv_flags_ext & IEEE80211_FEXT_UAPSD)
2212 *frm++ = vap->iv_uapsdinfo;
2236 .wme_len = sizeof(struct ieee80211_wme_param) - 2,
2246 *frm = wme->wme_bssChanParams.cap_info; /* AC info */
2251 /* XXX TODO - U-APSD bits - SP, flags below */
2254 &wme->wme_bssChanParams.cap_wmeParams[i];
2256 | _IEEE80211_SHIFTMASK(ac->wmep_acm, WME_PARAM_ACM)
2257 | _IEEE80211_SHIFTMASK(ac->wmep_aifsn, WME_PARAM_AIFSN)
2259 *frm++ = _IEEE80211_SHIFTMASK(ac->wmep_logcwmax,
2261 | _IEEE80211_SHIFTMASK(ac->wmep_logcwmin,
2264 ADDSHORT(frm, ac->wmep_txopLimit);
2277 const struct ieee80211_channel *c = vap->iv_bss->ni_chan;
2278 /* XXX per-vap tx power limit? */
2279 int8_t limit = vap->iv_ic->ic_txpowlimit / 2;
2283 frm[2] = c->ic_maxregpower > limit ? c->ic_maxregpower - limit : 0;
2295 frm[2] = c->ic_minpower;
2296 frm[3] = c->ic_maxpower;
2311 memcpy(frm+2, ic->ic_chan_avail, ielen);
2323 quiet->quiet_ie = IEEE80211_ELEMID_QUIET;
2324 quiet->len = 6;
2327 * Only update every beacon interval - otherwise probe responses
2331 if (vap->iv_quiet_count_value == 1)
2332 vap->iv_quiet_count_value = vap->iv_quiet_count;
2333 else if (vap->iv_quiet_count_value > 1)
2334 vap->iv_quiet_count_value--;
2337 if (vap->iv_quiet_count_value == 0) {
2339 vap->iv_quiet_count_value = 1;
2342 quiet->tbttcount = vap->iv_quiet_count_value;
2343 quiet->period = vap->iv_quiet_period;
2344 quiet->duration = htole16(vap->iv_quiet_duration);
2345 quiet->offset = htole16(vap->iv_quiet_offset);
2351 * Note that we use the per-vap CSA count to adjust the global
2358 struct ieee80211com *ic = vap->iv_ic;
2361 csa->csa_ie = IEEE80211_ELEMID_CSA;
2362 csa->csa_len = 3;
2363 csa->csa_mode = 1; /* XXX force quiet on channel */
2364 csa->csa_newchan = ieee80211_chan2ieee(ic, ic->ic_csa_newchan);
2365 csa->csa_count = ic->ic_csa_count - vap->iv_csa_count;
2376 if (ic->ic_countryie == NULL ||
2377 ic->ic_countryie_chan != ic->ic_bsschan) {
2381 * re-calculation.
2383 if (ic->ic_countryie != NULL)
2384 IEEE80211_FREE(ic->ic_countryie, M_80211_NODE_IE);
2385 ic->ic_countryie = ieee80211_alloc_countryie(ic);
2386 if (ic->ic_countryie == NULL)
2388 ic->ic_countryie_chan = ic->ic_bsschan;
2390 return add_appie(frm, ic->ic_countryie);
2396 if (vap->iv_flags & IEEE80211_F_WPA1 && vap->iv_wpa_ie != NULL)
2397 return (add_ie(frm, vap->iv_wpa_ie));
2407 if (vap->iv_flags & IEEE80211_F_WPA2 && vap->iv_rsn_ie != NULL)
2408 return (add_ie(frm, vap->iv_rsn_ie));
2418 if (ni->ni_flags & IEEE80211_NODE_QOS) {
2437 rs = ieee80211_get_suprates(ic, ic->ic_curchan);
2447 * [tlv] user-specified ie's
2451 + ((rs->rs_nrates > IEEE80211_RATE_SIZE) ?
2452 2 + (rs->rs_nrates - IEEE80211_RATE_SIZE) : 0)
2453 + (((vap->iv_opmode == IEEE80211_M_IBSS) &&
2454 (vap->iv_flags_ht & IEEE80211_FHT_HT)) ?
2460 + ((vap->iv_flags & IEEE80211_F_WPA1 && vap->iv_wpa_ie != NULL) ?
2461 vap->iv_wpa_ie[1] : 0)
2462 + (vap->iv_appie_probereq != NULL ?
2463 vap->iv_appie_probereq->ie_len : 0)
2484 if (ssidlen == -1)
2485 len -= (2 + IEEE80211_NWID_LEN);
2495 if (ssidlen != -1)
2497 rs = ieee80211_get_suprates(ic, ic->ic_curchan);
2508 if ((vap->iv_opmode == IEEE80211_M_IBSS) &&
2509 (vap->iv_flags_ht & IEEE80211_FHT_HT)) {
2516 c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan,
2517 vap->iv_flags_ht);
2526 if (vap->iv_vht_flags & IEEE80211_FVHT_VHT) {
2529 c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan,
2530 vap->iv_flags_ht);
2531 c = ieee80211_vht_adjust_channel(ic, c, vap->iv_vht_flags);
2537 if (vap->iv_appie_probereq != NULL)
2538 frm = add_appie(frm, vap->iv_appie_probereq);
2555 struct ieee80211vap *vap = ni->ni_vap;
2556 struct ieee80211com *ic = ni->ni_ic;
2565 bss = ieee80211_ref_node(vap->iv_bss);
2567 if (vap->iv_state == IEEE80211_S_CAC) {
2570 vap->iv_stats.is_tx_badstate++;
2583 ni, ether_sprintf(ni->ni_macaddr),
2590 ic->ic_headroom + sizeof(struct ieee80211_frame), frmlen);
2592 vap->iv_stats.is_tx_nobuf++;
2603 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2619 m->m_flags |= M_ENCAP; /* mark encapsulated */
2628 ieee80211_chan2ieee(ic, ic->ic_curchan),
2636 tp = &vap->iv_txparms[ieee80211_chan2mode(ic->ic_curchan)];
2637 params.ibp_rate0 = tp->mgmtrate;
2642 params.ibp_try0 = tp->maxretry;
2643 params.ibp_power = ni->ni_txpower;
2658 KASSERT(vap->iv_opmode != IEEE80211_M_STA, ("station mode"));
2660 if (vap->iv_opmode == IEEE80211_M_HOSTAP)
2662 else if (vap->iv_opmode == IEEE80211_M_IBSS)
2666 if (vap->iv_flags & IEEE80211_F_PRIVACY)
2668 if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) &&
2671 if (vap->iv_flags & IEEE80211_F_SHSLOT)
2673 if (IEEE80211_IS_CHAN_5GHZ(chan) && (vap->iv_flags & IEEE80211_F_DOTH))
2687 #define senderr(_x, _v) do { vap->iv_stats._v++; ret = _x; goto bad; } while (0)
2688 struct ieee80211vap *vap = ni->ni_vap;
2689 struct ieee80211com *ic = ni->ni_ic;
2690 struct ieee80211_node *bss = vap->iv_bss;
2707 ni, ether_sprintf(ni->ni_macaddr),
2718 ni->ni_challenge != NULL);
2730 bss->ni_authmode == IEEE80211_AUTH_SHARED);
2733 ic->ic_headroom + sizeof(struct ieee80211_frame),
2750 memcpy(&((uint16_t *)frm)[4], ni->ni_challenge,
2752 m->m_pkthdr.len = m->m_len =
2761 m->m_pkthdr.len = m->m_len = 3 * sizeof(uint16_t);
2769 if (vap->iv_opmode == IEEE80211_M_STA)
2771 (void *) vap->iv_state);
2779 ic->ic_headroom + sizeof(struct ieee80211_frame),
2784 m->m_pkthdr.len = m->m_len = sizeof(uint16_t);
2812 ic->ic_headroom + sizeof(struct ieee80211_frame),
2818 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
2828 + (vap->iv_appie_wpa != NULL ?
2829 vap->iv_appie_wpa->ie_len : 0)
2830 + (vap->iv_appie_assocreq != NULL ?
2831 vap->iv_appie_assocreq->ie_len : 0)
2836 KASSERT(vap->iv_opmode == IEEE80211_M_STA,
2837 ("wrong mode %u", vap->iv_opmode));
2839 if (vap->iv_flags & IEEE80211_F_PRIVACY)
2845 if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) &&
2846 IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan))
2848 if (IEEE80211_IS_CHAN_ANYG(ic->ic_curchan) &&
2849 (ic->ic_caps & IEEE80211_C_SHSLOT))
2851 if ((ni->ni_capinfo & IEEE80211_CAPINFO_SPECTRUM_MGMT) &&
2852 (vap->iv_flags & IEEE80211_F_DOTH))
2857 KASSERT(bss->ni_intval != 0, ("beacon interval is zero!"));
2858 *(uint16_t *)frm = htole16(howmany(ic->ic_lintval,
2859 bss->ni_intval));
2863 IEEE80211_ADDR_COPY(frm, bss->ni_bssid);
2867 frm = ieee80211_add_ssid(frm, ni->ni_essid, ni->ni_esslen);
2868 frm = ieee80211_add_rates(frm, &ni->ni_rates);
2870 frm = ieee80211_add_xrates(frm, &ni->ni_rates);
2873 ic->ic_curchan);
2878 * Check the channel - we may be using an 11n NIC with an
2882 if ((vap->iv_flags_ht & IEEE80211_FHT_HT) &&
2883 IEEE80211_IS_CHAN_HT(ni->ni_chan) &&
2884 ni->ni_ies.htcap_ie != NULL &&
2885 ni->ni_ies.htcap_ie[0] == IEEE80211_ELEMID_HTCAP) {
2889 if ((vap->iv_vht_flags & IEEE80211_FVHT_VHT) &&
2890 IEEE80211_IS_CHAN_VHT(ni->ni_chan) &&
2891 ni->ni_ies.vhtcap_ie != NULL &&
2892 ni->ni_ies.vhtcap_ie[0] == IEEE80211_ELEMID_VHT_CAP) {
2897 if ((vap->iv_flags & IEEE80211_F_WME) &&
2898 ni->ni_ies.wme_ie != NULL)
2899 frm = ieee80211_add_wme_info(frm, &ic->ic_wme, ni);
2902 * Same deal - only send HT info if we're on an 11n
2905 if ((vap->iv_flags_ht & IEEE80211_FHT_HT) &&
2906 IEEE80211_IS_CHAN_HT(ni->ni_chan) &&
2907 ni->ni_ies.htcap_ie != NULL &&
2908 ni->ni_ies.htcap_ie[0] == IEEE80211_ELEMID_VENDOR) {
2915 ((vap->iv_flags & IEEE80211_F_WPA) == 0 &&
2916 ni->ni_authmode != IEEE80211_AUTH_8021X) ?
2917 vap->iv_def_txkey : IEEE80211_KEYIX_NONE);
2920 if (vap->iv_appie_assocreq != NULL)
2921 frm = add_appie(frm, vap->iv_appie_assocreq);
2922 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
2925 (void *) vap->iv_state);
2948 ic->ic_headroom + sizeof(struct ieee80211_frame),
2953 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
2962 + (vap->iv_appie_assocresp != NULL ?
2963 vap->iv_appie_assocresp->ie_len : 0)
2968 capinfo = ieee80211_getcapinfo(vap, bss->ni_chan);
2976 *(uint16_t *)frm = htole16(ni->ni_associd);
2982 frm = ieee80211_add_rates(frm, &ni->ni_rates);
2983 frm = ieee80211_add_xrates(frm, &ni->ni_rates);
2985 if ((ni->ni_flags & HTFLAGS) == IEEE80211_NODE_HT) {
2989 if ((vap->iv_flags & IEEE80211_F_WME) &&
2990 ni->ni_ies.wme_ie != NULL)
2991 frm = ieee80211_add_wme_param(frm, &ic->ic_wme,
2992 !! (vap->iv_flags_ext & IEEE80211_FEXT_UAPSD));
2993 if ((ni->ni_flags & HTFLAGS) == HTFLAGS) {
2997 if (ni->ni_flags & IEEE80211_NODE_VHT) {
3005 ((vap->iv_flags & IEEE80211_F_WPA) == 0 &&
3006 ni->ni_authmode != IEEE80211_AUTH_8021X) ?
3007 vap->iv_def_txkey : IEEE80211_KEYIX_NONE);
3009 if (vap->iv_appie_assocresp != NULL)
3010 frm = add_appie(frm, vap->iv_appie_assocresp);
3011 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
3019 ic->ic_headroom + sizeof(struct ieee80211_frame),
3024 m->m_pkthdr.len = m->m_len = sizeof(uint16_t);
3037 /* NB: force non-ProbeResp frames to the highest queue */
3039 params.ibp_rate0 = bss->ni_txparms->mgmtrate;
3041 params.ibp_try0 = bss->ni_txparms->maxretry;
3042 params.ibp_power = bss->ni_txpower;
3059 struct ieee80211vap *vap = bss->ni_vap;
3060 struct ieee80211com *ic = bss->ni_ic;
3095 ic->ic_headroom + sizeof(struct ieee80211_frame),
3107 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
3124 + (vap->iv_appie_proberesp != NULL ?
3125 vap->iv_appie_proberesp->ie_len : 0)
3128 vap->iv_stats.is_tx_nobuf++;
3134 *(uint16_t *)frm = htole16(bss->ni_intval);
3136 capinfo = ieee80211_getcapinfo(vap, bss->ni_chan);
3140 frm = ieee80211_add_ssid(frm, bss->ni_essid, bss->ni_esslen);
3141 rs = ieee80211_get_suprates(ic, bss->ni_chan);
3144 if (IEEE80211_IS_CHAN_FHSS(bss->ni_chan)) {
3147 *frm++ = bss->ni_fhdwell & 0x00ff;
3148 *frm++ = (bss->ni_fhdwell >> 8) & 0x00ff;
3150 ieee80211_chan2ieee(ic, bss->ni_chan));
3152 ieee80211_chan2ieee(ic, bss->ni_chan));
3153 *frm++ = bss->ni_fhindex;
3157 *frm++ = ieee80211_chan2ieee(ic, bss->ni_chan);
3160 if (vap->iv_opmode == IEEE80211_M_IBSS) {
3165 if ((vap->iv_flags & IEEE80211_F_DOTH) ||
3166 (vap->iv_flags_ext & IEEE80211_FEXT_DOTD))
3168 if (vap->iv_flags & IEEE80211_F_DOTH) {
3169 if (IEEE80211_IS_CHAN_5GHZ(bss->ni_chan))
3171 if (ic->ic_flags & IEEE80211_F_CSAPENDING)
3174 if (vap->iv_flags & IEEE80211_F_DOTH) {
3175 if (IEEE80211_IS_CHAN_DFS(ic->ic_bsschan) &&
3176 (vap->iv_flags_ext & IEEE80211_FEXT_DFS)) {
3177 if (vap->iv_quiet)
3181 if (IEEE80211_IS_CHAN_ANYG(bss->ni_chan))
3191 if (IEEE80211_IS_CHAN_HT(bss->ni_chan) &&
3196 if (IEEE80211_IS_CHAN_VHT(bss->ni_chan) &&
3202 if (vap->iv_flags & IEEE80211_F_WME)
3203 frm = ieee80211_add_wme_param(frm, &ic->ic_wme,
3204 !! (vap->iv_flags_ext & IEEE80211_FEXT_UAPSD));
3205 if (IEEE80211_IS_CHAN_HT(bss->ni_chan) &&
3206 (vap->iv_flags_ht & IEEE80211_FHT_HTCOMPAT) &&
3212 if ((vap->iv_flags & IEEE80211_F_ATHEROS) &&
3216 if (vap->iv_appie_proberesp != NULL)
3217 frm = add_appie(frm, vap->iv_appie_proberesp);
3219 if (vap->iv_opmode == IEEE80211_M_MBSS) {
3224 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
3232 * can specify the destination address and re-use the bss node
3239 struct ieee80211_node *bss = vap->iv_bss;
3240 struct ieee80211com *ic = vap->iv_ic;
3244 if (vap->iv_state == IEEE80211_S_CAC) {
3247 vap->iv_stats.is_tx_badstate++;
3258 __func__, __LINE__, bss, ether_sprintf(bss->ni_macaddr),
3274 IEEE80211_NONQOS_TID, vap->iv_myaddr, da, bss->ni_bssid);
3276 m->m_flags |= M_ENCAP; /* mark encapsulated */
3282 ieee80211_chan2ieee(ic, ic->ic_curchan), ether_sprintf(da),
3307 rts->i_fc[0] = IEEE80211_FC0_VERSION_0 |
3309 rts->i_fc[1] = IEEE80211_FC1_DIR_NODS;
3310 *(u_int16_t *)rts->i_dur = htole16(dur);
3311 IEEE80211_ADDR_COPY(rts->i_ra, ra);
3312 IEEE80211_ADDR_COPY(rts->i_ta, ta);
3314 m->m_pkthdr.len = m->m_len = sizeof(struct ieee80211_frame_rts);
3333 cts->i_fc[0] = IEEE80211_FC0_VERSION_0 |
3335 cts->i_fc[1] = IEEE80211_FC1_DIR_NODS;
3336 *(u_int16_t *)cts->i_dur = htole16(dur);
3337 IEEE80211_ADDR_COPY(cts->i_ra, ra);
3339 m->m_pkthdr.len = m->m_len = sizeof(struct ieee80211_frame_cts);
3351 struct ieee80211com *ic = ni->ni_ic;
3352 struct ieee80211vap *vap = ni->ni_vap;
3363 pktlen = m->m_pkthdr.len + IEEE80211_CRC_LEN;
3364 isshort = (vap->iv_flags & IEEE80211_F_SHPREAMBLE) != 0;
3365 dur = ieee80211_compute_duration(ic->ic_rt, pktlen, rate, isshort)
3366 + ieee80211_ack_duration(ic->ic_rt, rate, isshort);
3370 dur += ieee80211_ack_duration(ic->ic_rt, rate, isshort);
3371 mprot = ieee80211_alloc_rts(ic, wh->i_addr1, wh->i_addr2, dur);
3373 mprot = ieee80211_alloc_cts(ic, vap->iv_myaddr, dur);
3385 ieee80211_opmode_name[vap->iv_opmode],
3386 ieee80211_state_name[vap->iv_state],
3387 vap->iv_ic->ic_flags, IEEE80211_F_SCAN);
3389 IEEE80211_LOCK(vap->iv_ic);
3390 if (vap->iv_state != IEEE80211_S_INIT &&
3391 (vap->iv_ic->ic_flags & IEEE80211_F_SCAN) == 0) {
3393 * NB: it's safe to specify a timeout as the reason here;
3399 IEEE80211_UNLOCK(vap->iv_ic);
3403 * This is the callback set on net80211-sourced transmitted
3419 struct ieee80211vap *vap = ni->ni_vap;
3428 * not be too time-critical and not happen too often so the
3433 if (vap->iv_state == ostate) {
3436 ieee80211_opmode_name[vap->iv_opmode],
3437 ieee80211_state_name[vap->iv_state], arg, status);
3439 callout_reset(&vap->iv_mgtsend,
3449 struct ieee80211vap *vap = ni->ni_vap;
3450 struct ieee80211_beacon_offsets *bo = &vap->iv_bcn_off;
3451 struct ieee80211com *ic = ni->ni_ic;
3452 struct ieee80211_rateset *rs = &ni->ni_rates;
3458 * TODO: update to 802.11-2012; a lot of stuff has changed;
3500 * XXX Vendor-specific OIDs (e.g. Atheros)
3516 *(uint16_t *)frm = htole16(ni->ni_intval);
3518 capinfo = ieee80211_getcapinfo(vap, ni->ni_chan);
3519 bo->bo_caps = (uint16_t *)frm;
3523 if ((vap->iv_flags & IEEE80211_F_HIDESSID) == 0) {
3524 *frm++ = ni->ni_esslen;
3525 memcpy(frm, ni->ni_essid, ni->ni_esslen);
3526 frm += ni->ni_esslen;
3530 if (!IEEE80211_IS_CHAN_FHSS(ni->ni_chan)) {
3533 *frm++ = ieee80211_chan2ieee(ic, ni->ni_chan);
3535 if (ic->ic_flags & IEEE80211_F_PCF) {
3536 bo->bo_cfp = frm;
3539 bo->bo_tim = frm;
3540 if (vap->iv_opmode == IEEE80211_M_IBSS) {
3544 bo->bo_tim_len = 0;
3545 } else if (vap->iv_opmode == IEEE80211_M_HOSTAP ||
3546 vap->iv_opmode == IEEE80211_M_MBSS) {
3550 tie->tim_ie = IEEE80211_ELEMID_TIM;
3551 tie->tim_len = 4; /* length */
3552 tie->tim_count = 0; /* DTIM count */
3553 tie->tim_period = vap->iv_dtim_period; /* DTIM period */
3554 tie->tim_bitctl = 0; /* bitmap control */
3555 tie->tim_bitmap[0] = 0; /* Partial Virtual Bitmap */
3557 bo->bo_tim_len = 1;
3559 bo->bo_tim_trailer = frm;
3560 if ((vap->iv_flags & IEEE80211_F_DOTH) ||
3561 (vap->iv_flags_ext & IEEE80211_FEXT_DOTD))
3563 if (vap->iv_flags & IEEE80211_F_DOTH) {
3564 if (IEEE80211_IS_CHAN_5GHZ(ni->ni_chan))
3566 bo->bo_csa = frm;
3567 if (ic->ic_flags & IEEE80211_F_CSAPENDING)
3570 bo->bo_csa = frm;
3572 bo->bo_quiet = NULL;
3573 if (vap->iv_flags & IEEE80211_F_DOTH) {
3574 if (IEEE80211_IS_CHAN_DFS(ic->ic_bsschan) &&
3575 (vap->iv_flags_ext & IEEE80211_FEXT_DFS) &&
3576 (vap->iv_quiet == 1)) {
3583 if (vap->iv_quiet) {
3584 bo->bo_quiet = frm;
3590 if (IEEE80211_IS_CHAN_ANYG(ni->ni_chan)) {
3591 bo->bo_erp = frm;
3596 if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) {
3598 bo->bo_htinfo = frm;
3602 if (IEEE80211_IS_CHAN_VHT(ni->ni_chan)) {
3604 bo->bo_vhtinfo = frm;
3612 if (vap->iv_flags & IEEE80211_F_WME) {
3613 bo->bo_wme = frm;
3614 frm = ieee80211_add_wme_param(frm, &ic->ic_wme,
3615 !! (vap->iv_flags_ext & IEEE80211_FEXT_UAPSD));
3617 if (IEEE80211_IS_CHAN_HT(ni->ni_chan) &&
3618 (vap->iv_flags_ht & IEEE80211_FHT_HTCOMPAT)) {
3624 if (vap->iv_flags & IEEE80211_F_ATHEROS) {
3625 bo->bo_ath = frm;
3630 if (vap->iv_caps & IEEE80211_C_TDMA) {
3631 bo->bo_tdma = frm;
3635 if (vap->iv_appie_beacon != NULL) {
3636 bo->bo_appie = frm;
3637 bo->bo_appie_len = vap->iv_appie_beacon->ie_len;
3638 frm = add_appie(frm, vap->iv_appie_beacon);
3643 if (vap->iv_opmode == IEEE80211_M_MBSS) {
3645 bo->bo_meshconf = frm;
3649 bo->bo_tim_trailer_len = frm - bo->bo_tim_trailer;
3650 bo->bo_csa_trailer_len = frm - bo->bo_csa;
3651 m->m_pkthdr.len = m->m_len = frm - mtod(m, uint8_t *);
3660 struct ieee80211vap *vap = ni->ni_vap;
3661 struct ieee80211com *ic = ni->ni_ic;
3662 struct ifnet *ifp = vap->iv_ifp;
3671 if (vap->iv_quiet == 1)
3672 vap->iv_flags_ext |= IEEE80211_FEXT_QUIET_IE;
3673 else if (vap->iv_quiet == 0)
3674 vap->iv_flags_ext &= ~IEEE80211_FEXT_QUIET_IE;
3679 * Note: This needs updating for 802.11-2012.
3701 * XXX Vendor-specific OIDs (e.g. Atheros)
3714 + 2 + ni->ni_esslen /* ssid */
3718 + 2 + 4 + vap->iv_tim_len /* DTIM/IBSSPARMS */
3724 + 2 + (IEEE80211_RATE_MAXSIZE - IEEE80211_RATE_SIZE)
3725 + (vap->iv_caps & IEEE80211_C_WPA ? /* WPA 1+2 */
3732 + (vap->iv_caps & IEEE80211_C_WME ? /* WME */
3738 + (vap->iv_caps & IEEE80211_C_TDMA ? /* TDMA */
3742 + 2 + ni->ni_meshidlen
3748 ic->ic_headroom + sizeof(struct ieee80211_frame), pktlen);
3752 vap->iv_stats.is_tx_nobuf++;
3760 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT |
3762 wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
3763 *(uint16_t *)wh->i_dur = 0;
3764 IEEE80211_ADDR_COPY(wh->i_addr1, ifp->if_broadcastaddr);
3765 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
3766 IEEE80211_ADDR_COPY(wh->i_addr3, ni->ni_bssid);
3767 *(uint16_t *)wh->i_seq = 0;
3778 struct ieee80211vap *vap = ni->ni_vap;
3779 struct ieee80211_beacon_offsets *bo = &vap->iv_bcn_off;
3780 struct ieee80211com *ic = ni->ni_ic;
3794 if (isset(bo->bo_flags, IEEE80211_BEACON_CSA) &&
3795 vap->iv_csa_count == ic->ic_csa_count) {
3796 vap->iv_csa_count = 0;
3801 if (ic->ic_csa_newchan != NULL)
3819 * beacon - that way the gap is provided as appropriate.
3824 if ((vap->iv_flags_ext & IEEE80211_FEXT_QUIET_IE) &&
3825 (vap->iv_quiet == 0)) {
3830 vap->iv_flags_ext &= ~IEEE80211_FEXT_QUIET_IE;
3838 if (((vap->iv_flags_ext & IEEE80211_FEXT_QUIET_IE) == 0) &&
3839 (vap->iv_quiet == 1)) {
3844 vap->iv_flags_ext |= IEEE80211_FEXT_QUIET_IE;
3856 * lock held so as to serialise access to the non-qos TID sequence
3862 seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]++;
3863 *(uint16_t *)&wh->i_seq[0] =
3868 capinfo = ieee80211_getcapinfo(vap, ni->ni_chan);
3869 *bo->bo_caps = htole16(capinfo);
3871 if (vap->iv_flags & IEEE80211_F_WME) {
3872 struct ieee80211_wme_state *wme = &ic->ic_wme;
3879 * to optimize performance of legacy/non-QoS traffic.
3881 if (wme->wme_flags & WME_F_AGGRMODE) {
3882 if (wme->wme_hipri_traffic >
3883 wme->wme_hipri_switch_thresh) {
3886 __func__, wme->wme_hipri_traffic);
3887 wme->wme_flags &= ~WME_F_AGGRMODE;
3889 wme->wme_hipri_traffic =
3890 wme->wme_hipri_switch_hysteresis;
3892 wme->wme_hipri_traffic = 0;
3894 if (wme->wme_hipri_traffic <=
3895 wme->wme_hipri_switch_thresh) {
3898 __func__, wme->wme_hipri_traffic);
3899 wme->wme_flags |= WME_F_AGGRMODE;
3901 wme->wme_hipri_traffic = 0;
3903 wme->wme_hipri_traffic =
3904 wme->wme_hipri_switch_hysteresis;
3906 if (isset(bo->bo_flags, IEEE80211_BEACON_WME)) {
3907 (void) ieee80211_add_wme_param(bo->bo_wme, wme,
3908 vap->iv_flags_ext & IEEE80211_FEXT_UAPSD);
3909 clrbit(bo->bo_flags, IEEE80211_BEACON_WME);
3913 if (isset(bo->bo_flags, IEEE80211_BEACON_HTINFO)) {
3915 clrbit(bo->bo_flags, IEEE80211_BEACON_HTINFO);
3918 if (vap->iv_caps & IEEE80211_C_TDMA) {
3926 if (vap->iv_opmode == IEEE80211_M_MBSS)
3930 if (vap->iv_opmode == IEEE80211_M_HOSTAP ||
3931 vap->iv_opmode == IEEE80211_M_MBSS) { /* NB: no IBSS support*/
3933 (struct ieee80211_tim_ie *) bo->bo_tim;
3934 if (isset(bo->bo_flags, IEEE80211_BEACON_TIM)) {
3943 * maximal-size virtual bitmap (based on iv_max_aid).
3952 if (vap->iv_ps_pending != 0) {
3954 for (i = 0; i < vap->iv_tim_len; i++)
3955 if (vap->iv_tim_bitmap[i]) {
3960 for (i = vap->iv_tim_len-1; i >= timoff; i--)
3961 if (vap->iv_tim_bitmap[i])
3963 timlen = 1 + (i - timoff);
3972 if (timlen != bo->bo_tim_len) {
3974 int adjust = tie->tim_bitmap+timlen
3975 - bo->bo_tim_trailer;
3976 ovbcopy(bo->bo_tim_trailer,
3977 bo->bo_tim_trailer+adjust,
3978 bo->bo_tim_trailer_len);
3979 bo->bo_tim_trailer += adjust;
3980 bo->bo_erp += adjust;
3981 bo->bo_htinfo += adjust;
3982 bo->bo_vhtinfo += adjust;
3984 bo->bo_ath += adjust;
3987 bo->bo_tdma += adjust;
3990 bo->bo_meshconf += adjust;
3992 bo->bo_appie += adjust;
3993 bo->bo_wme += adjust;
3994 bo->bo_csa += adjust;
3995 bo->bo_quiet += adjust;
3996 bo->bo_tim_len = timlen;
3999 tie->tim_len = 3 + timlen;
4000 tie->tim_bitctl = timoff;
4003 memcpy(tie->tim_bitmap, vap->iv_tim_bitmap + timoff,
4004 bo->bo_tim_len);
4006 clrbit(bo->bo_flags, IEEE80211_BEACON_TIM);
4010 __func__, vap->iv_ps_pending, timoff, timlen);
4013 if (tie->tim_count == 0)
4014 tie->tim_count = tie->tim_period - 1;
4016 tie->tim_count--;
4018 if (mcast && tie->tim_count == 0)
4019 tie->tim_bitctl |= 1;
4021 tie->tim_bitctl &= ~1;
4022 if (isset(bo->bo_flags, IEEE80211_BEACON_CSA)) {
4024 (struct ieee80211_csa_ie *) bo->bo_csa;
4033 if (vap->iv_csa_count == 0) {
4034 memmove(&csa[1], csa, bo->bo_csa_trailer_len);
4035 bo->bo_erp += sizeof(*csa);
4036 bo->bo_htinfo += sizeof(*csa);
4037 bo->bo_vhtinfo += sizeof(*csa);
4038 bo->bo_wme += sizeof(*csa);
4040 bo->bo_ath += sizeof(*csa);
4043 bo->bo_tdma += sizeof(*csa);
4046 bo->bo_meshconf += sizeof(*csa);
4048 bo->bo_appie += sizeof(*csa);
4049 bo->bo_csa_trailer_len += sizeof(*csa);
4050 bo->bo_quiet += sizeof(*csa);
4051 bo->bo_tim_trailer_len += sizeof(*csa);
4052 m->m_len += sizeof(*csa);
4053 m->m_pkthdr.len += sizeof(*csa);
4055 ieee80211_add_csa(bo->bo_csa, vap);
4057 csa->csa_count--;
4058 vap->iv_csa_count++;
4066 if (IEEE80211_IS_CHAN_DFS(ic->ic_bsschan) &&
4067 (vap->iv_flags_ext & IEEE80211_FEXT_DFS)) {
4068 if (vap->iv_quiet &&
4069 (vap->iv_flags_ext & IEEE80211_FEXT_QUIET_IE)) {
4070 ieee80211_add_quiet(bo->bo_quiet, vap, 1);
4073 if (isset(bo->bo_flags, IEEE80211_BEACON_ERP)) {
4077 (void) ieee80211_add_erp(bo->bo_erp, vap);
4078 clrbit(bo->bo_flags, IEEE80211_BEACON_ERP);
4081 if (isset(bo->bo_flags, IEEE80211_BEACON_ATH)) {
4082 ieee80211_add_athcaps(bo->bo_ath, ni);
4083 clrbit(bo->bo_flags, IEEE80211_BEACON_ATH);
4087 if (isset(bo->bo_flags, IEEE80211_BEACON_APPIE)) {
4088 const struct ieee80211_appie *aie = vap->iv_appie_beacon;
4094 aielen += aie->ie_len;
4095 if (aielen != bo->bo_appie_len) {
4097 int adjust = aielen - bo->bo_appie_len;
4098 ovbcopy(bo->bo_tim_trailer, bo->bo_tim_trailer+adjust,
4099 bo->bo_tim_trailer_len);
4100 bo->bo_tim_trailer += adjust;
4101 bo->bo_appie += adjust;
4102 bo->bo_appie_len = aielen;
4106 frm = bo->bo_appie;
4109 clrbit(bo->bo_flags, IEEE80211_BEACON_APPIE);
4117 * Do Ethernet-LLC encapsulation for each payload in a fast frame
4131 m_adj(m, sizeof(struct ether_header) - sizeof(struct llc));
4133 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
4134 llc->llc_control = LLC_UI;
4135 llc->llc_snap.org_code[0] = 0;
4136 llc->llc_snap.org_code[1] = 0;
4137 llc->llc_snap.org_code[2] = 0;
4138 llc->llc_snap.ether_type = eh->ether_type;
4139 payload = m->m_pkthdr.len; /* NB: w/o Ethernet header */
4145 vap->iv_stats.is_tx_nobuf++;
4149 mtod(m, struct ether_header *)->ether_type = htons(payload);
4162 * and already transmitted, it may end up doing A-MPDU retransmission,
4177 struct ifnet *ifp = ni->ni_vap->iv_ifp;
4180 if_inc_counter(ifp, IFCOUNTER_OBYTES, m->m_pkthdr.len);
4182 if (m->m_flags & M_MCAST)
4186 if (m->m_flags & M_TXCB) {
4187 IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG,
4188 "ni %p vap %p mode %s state %s m %p status %d\n", ni, ni->ni_vap,
4189 ieee80211_opmode_name[ni->ni_vap->iv_opmode],
4190 ieee80211_state_name[ni->ni_vap->iv_state], m, status);