2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/malloc.h>
36 #include <sys/endian.h>
37 #include <sys/kernel.h>
39 #include <sys/socket.h>
41 #include <net/ethernet.h>
43 #include <net/if_var.h>
44 #include <net/if_llc.h>
45 #include <net/if_media.h>
46 #include <net/vlan/if_vlan_var.h>
48 #include <netproto/802_11/ieee80211_var.h>
49 #include <netproto/802_11/ieee80211_input.h>
50 #ifdef IEEE80211_SUPPORT_MESH
51 #include <netproto/802_11/ieee80211_mesh.h>
57 #include <netinet/in.h>
58 #include <net/ethernet.h>
62 ieee80211_process_mimo(struct ieee80211_node *ni, struct ieee80211_rx_stats *rx)
66 /* Verify the required MIMO bits are set */
67 if ((rx->r_flags & (IEEE80211_R_C_CHAIN | IEEE80211_R_C_NF | IEEE80211_R_C_RSSI)) !=
68 (IEEE80211_R_C_CHAIN | IEEE80211_R_C_NF | IEEE80211_R_C_RSSI))
71 /* XXX This assumes the MIMO radios have both ctl and ext chains */
72 for (i = 0; i < MIN(rx->c_chain, IEEE80211_MAX_CHAINS); i++) {
73 IEEE80211_RSSI_LPF(ni->ni_mimo_rssi_ctl[i], rx->c_rssi_ctl[i]);
74 IEEE80211_RSSI_LPF(ni->ni_mimo_rssi_ext[i], rx->c_rssi_ext[i]);
77 /* XXX This also assumes the MIMO radios have both ctl and ext chains */
78 for(i = 0; i < MIN(rx->c_chain, IEEE80211_MAX_CHAINS); i++) {
79 ni->ni_mimo_noise_ctl[i] = rx->c_nf_ctl[i];
80 ni->ni_mimo_noise_ext[i] = rx->c_nf_ext[i];
82 ni->ni_mimo_chains = rx->c_chain;
86 ieee80211_input_mimo(struct ieee80211_node *ni, struct mbuf *m,
87 struct ieee80211_rx_stats *rx)
89 /* XXX should assert IEEE80211_R_NF and IEEE80211_R_RSSI are set */
90 ieee80211_process_mimo(ni, rx);
91 //return ieee80211_input(ni, m, rx->rssi, rx->nf);
92 return ni->ni_vap->iv_input(ni, m, rx, rx->rssi, rx->nf);
96 ieee80211_input_all(struct ieee80211com *ic, struct mbuf *m, int rssi, int nf)
98 struct ieee80211_rx_stats rx;
100 rx.r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI;
103 return ieee80211_input_mimo_all(ic, m, &rx);
107 ieee80211_input_mimo_all(struct ieee80211com *ic, struct mbuf *m,
108 struct ieee80211_rx_stats *rx)
110 struct ieee80211vap *vap;
113 m->m_flags |= M_BCAST; /* NB: mark for bpf tap'ing */
116 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
117 struct ieee80211_node *ni;
120 /* NB: could check for IFF_UP but this is cheaper */
121 if (vap->iv_state == IEEE80211_S_INIT)
124 * WDS vap's only receive directed traffic from the
125 * station at the ``far end''. That traffic should
126 * be passed through the AP vap the station is associated
127 * to--so don't spam them with mcast frames.
129 if (vap->iv_opmode == IEEE80211_M_WDS)
131 if (TAILQ_NEXT(vap, iv_next) != NULL) {
133 * Packet contents are changed by ieee80211_decap
134 * so do a deep copy of the packet.
136 mcopy = m_dup(m, M_NOWAIT);
145 ni = ieee80211_ref_node(vap->iv_bss);
146 type = ieee80211_input_mimo(ni, mcopy, rx);
147 ieee80211_free_node(ni);
149 if (m != NULL) /* no vaps, reclaim mbuf */
155 * This function reassembles fragments.
157 * XXX should handle 3 concurrent reassemblies per-spec.
160 ieee80211_defrag(struct ieee80211_node *ni, struct mbuf *m, int hdrspace)
162 struct ieee80211vap *vap = ni->ni_vap;
163 struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
164 struct ieee80211_frame *lwh;
167 uint8_t more_frag = wh->i_fc[1] & IEEE80211_FC1_MORE_FRAG;
170 KASSERT(!IEEE80211_IS_MULTICAST(wh->i_addr1), ("multicast fragm?"));
172 rxseq = le16toh(*(uint16_t *)wh->i_seq);
173 fragno = rxseq & IEEE80211_SEQ_FRAG_MASK;
175 /* Quick way out, if there's nothing to defragment */
176 if (!more_frag && fragno == 0 && ni->ni_rxfrag[0] == NULL)
180 * Remove frag to insure it doesn't get reaped by timer.
182 if (ni->ni_table == NULL) {
184 * Should never happen. If the node is orphaned (not in
185 * the table) then input packets should not reach here.
186 * Otherwise, a concurrent request that yanks the table
187 * should be blocked by other interlocking and/or by first
188 * shutting the driver down. Regardless, be defensive
191 /* XXX need msg+stat */
195 IEEE80211_NODE_LOCK(ni->ni_table);
196 mfrag = ni->ni_rxfrag[0];
197 ni->ni_rxfrag[0] = NULL;
198 IEEE80211_NODE_UNLOCK(ni->ni_table);
201 * Validate new fragment is in order and
202 * related to the previous ones.
207 lwh = mtod(mfrag, struct ieee80211_frame *);
208 last_rxseq = le16toh(*(uint16_t *)lwh->i_seq);
209 /* NB: check seq # and frag together */
210 if (rxseq != last_rxseq+1 ||
211 !IEEE80211_ADDR_EQ(wh->i_addr1, lwh->i_addr1) ||
212 !IEEE80211_ADDR_EQ(wh->i_addr2, lwh->i_addr2)) {
214 * Unrelated fragment or no space for it,
215 * clear current fragments.
223 if (fragno != 0) { /* !first fragment, discard */
224 vap->iv_stats.is_rx_defrag++;
225 IEEE80211_NODE_STAT(ni, rx_defrag);
230 } else { /* concatenate */
231 m_adj(m, hdrspace); /* strip header */
233 /* NB: m_cat doesn't update the packet header */
234 mfrag->m_pkthdr.len += m->m_pkthdr.len;
235 /* track last seqnum and fragno */
236 lwh = mtod(mfrag, struct ieee80211_frame *);
237 *(uint16_t *) lwh->i_seq = *(uint16_t *) wh->i_seq;
239 if (more_frag) { /* more to come, save */
240 ni->ni_rxfragstamp = ticks;
241 ni->ni_rxfrag[0] = mfrag;
248 ieee80211_deliver_data(struct ieee80211vap *vap,
249 struct ieee80211_node *ni, struct mbuf *m)
251 struct ether_header *eh = mtod(m, struct ether_header *);
252 struct ifnet *ifp = vap->iv_ifp;
254 /* clear driver/net80211 flags before passing up */
255 m->m_flags &= ~(M_MCAST | M_BCAST);
256 #if !defined(__DragonFly__)
260 /* NB: see hostap_deliver_data, this path doesn't handle hostap */
261 KASSERT(vap->iv_opmode != IEEE80211_M_HOSTAP, ("gack, hostap"));
265 IFNET_STAT_INC(ifp, ipackets, 1);
266 IEEE80211_NODE_STAT(ni, rx_data);
267 IEEE80211_NODE_STAT_ADD(ni, rx_bytes, m->m_pkthdr.len);
268 if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
269 m->m_flags |= M_MCAST; /* XXX M_BCAST? */
270 IEEE80211_NODE_STAT(ni, rx_mcast);
272 IEEE80211_NODE_STAT(ni, rx_ucast);
273 m->m_pkthdr.rcvif = ifp;
275 if (ni->ni_vlan != 0) {
276 /* attach vlan tag */
277 #if defined(__DragonFly__)
278 m->m_pkthdr.ether_vlantag = ni->ni_vlan;
280 m->m_pkthdr.ether_vtag = ni->ni_vlan;
282 m->m_flags |= M_VLANTAG;
284 ifp->if_input(ifp, m, NULL, -1);
288 ieee80211_decap(struct ieee80211vap *vap, struct mbuf *m, int hdrlen)
290 struct ieee80211_qosframe_addr4 wh;
291 struct ether_header *eh;
294 KASSERT(hdrlen <= sizeof(wh),
295 ("hdrlen %d > max %zd", hdrlen, sizeof(wh)));
297 if (m->m_len < hdrlen + sizeof(*llc) &&
298 (m = m_pullup(m, hdrlen + sizeof(*llc))) == NULL) {
299 vap->iv_stats.is_rx_tooshort++;
303 memcpy(&wh, mtod(m, caddr_t), hdrlen);
304 llc = (struct llc *)(mtod(m, caddr_t) + hdrlen);
305 if (llc->llc_dsap == LLC_SNAP_LSAP && llc->llc_ssap == LLC_SNAP_LSAP &&
306 llc->llc_control == LLC_UI && llc->llc_snap.org_code[0] == 0 &&
307 llc->llc_snap.org_code[1] == 0 && llc->llc_snap.org_code[2] == 0 &&
308 /* NB: preserve AppleTalk frames that have a native SNAP hdr */
309 !(llc->llc_snap.ether_type == htons(ETHERTYPE_AARP) ||
310 llc->llc_snap.ether_type == htons(ETHERTYPE_IPX))) {
311 m_adj(m, hdrlen + sizeof(struct llc) - sizeof(*eh));
314 m_adj(m, hdrlen - sizeof(*eh));
316 eh = mtod(m, struct ether_header *);
317 switch (wh.i_fc[1] & IEEE80211_FC1_DIR_MASK) {
318 case IEEE80211_FC1_DIR_NODS:
319 IEEE80211_ADDR_COPY(eh->ether_dhost, wh.i_addr1);
320 IEEE80211_ADDR_COPY(eh->ether_shost, wh.i_addr2);
322 case IEEE80211_FC1_DIR_TODS:
323 IEEE80211_ADDR_COPY(eh->ether_dhost, wh.i_addr3);
324 IEEE80211_ADDR_COPY(eh->ether_shost, wh.i_addr2);
326 case IEEE80211_FC1_DIR_FROMDS:
327 IEEE80211_ADDR_COPY(eh->ether_dhost, wh.i_addr1);
328 IEEE80211_ADDR_COPY(eh->ether_shost, wh.i_addr3);
330 case IEEE80211_FC1_DIR_DSTODS:
331 IEEE80211_ADDR_COPY(eh->ether_dhost, wh.i_addr3);
332 IEEE80211_ADDR_COPY(eh->ether_shost, wh.i_addr4);
335 #ifndef __NO_STRICT_ALIGNMENT
336 if (!ALIGNED_POINTER(mtod(m, caddr_t) + sizeof(*eh), uint32_t)) {
337 m = ieee80211_realign(vap, m, sizeof(*eh));
341 #endif /* !__NO_STRICT_ALIGNMENT */
343 eh = mtod(m, struct ether_header *);
344 eh->ether_type = htons(m->m_pkthdr.len - sizeof(*eh));
350 * Decap a frame encapsulated in a fast-frame/A-MSDU.
353 ieee80211_decap1(struct mbuf *m, int *framelen)
355 #define FF_LLC_SIZE (sizeof(struct ether_header) + sizeof(struct llc))
356 struct ether_header *eh;
360 * The frame has an 802.3 header followed by an 802.2
361 * LLC header. The encapsulated frame length is in the
362 * first header type field; save that and overwrite it
363 * with the true type field found in the second. Then
364 * copy the 802.3 header up to where it belongs and
365 * adjust the mbuf contents to remove the void.
367 if (m->m_len < FF_LLC_SIZE && (m = m_pullup(m, FF_LLC_SIZE)) == NULL)
369 eh = mtod(m, struct ether_header *); /* 802.3 header is first */
370 llc = (struct llc *)&eh[1]; /* 802.2 header follows */
371 *framelen = ntohs(eh->ether_type) /* encap'd frame size */
372 + sizeof(struct ether_header) - sizeof(struct llc);
373 eh->ether_type = llc->llc_un.type_snap.ether_type;
374 ovbcopy(eh, mtod(m, uint8_t *) + sizeof(struct llc),
375 sizeof(struct ether_header));
376 m_adj(m, sizeof(struct llc));
382 * Install received rate set information in the node's state block.
385 ieee80211_setup_rates(struct ieee80211_node *ni,
386 const uint8_t *rates, const uint8_t *xrates, int flags)
388 struct ieee80211vap *vap = ni->ni_vap;
389 struct ieee80211_rateset *rs = &ni->ni_rates;
391 memset(rs, 0, sizeof(*rs));
392 rs->rs_nrates = rates[1];
393 memcpy(rs->rs_rates, rates + 2, rs->rs_nrates);
394 if (xrates != NULL) {
397 * Tack on 11g extended supported rate element.
400 if (rs->rs_nrates + nxrates > IEEE80211_RATE_MAXSIZE) {
401 nxrates = IEEE80211_RATE_MAXSIZE - rs->rs_nrates;
402 IEEE80211_NOTE(vap, IEEE80211_MSG_XRATE, ni,
403 "extended rate set too large; only using "
404 "%u of %u rates", nxrates, xrates[1]);
405 vap->iv_stats.is_rx_rstoobig++;
407 memcpy(rs->rs_rates + rs->rs_nrates, xrates+2, nxrates);
408 rs->rs_nrates += nxrates;
410 return ieee80211_fix_rate(ni, rs, flags);
414 * Send a management frame error response to the specified
415 * station. If ni is associated with the station then use
416 * it; otherwise allocate a temporary node suitable for
417 * transmitting the frame and then free the reference so
418 * it will go away as soon as the frame has been transmitted.
421 ieee80211_send_error(struct ieee80211_node *ni,
422 const uint8_t mac[IEEE80211_ADDR_LEN], int subtype, int arg)
424 struct ieee80211vap *vap = ni->ni_vap;
427 if (ni == vap->iv_bss) {
428 if (vap->iv_state != IEEE80211_S_RUN) {
430 * XXX hack until we get rid of this routine.
431 * We can be called prior to the vap reaching
432 * run state under certain conditions in which
433 * case iv_bss->ni_chan will not be setup.
434 * Check for this explicitly and and just ignore
439 ni = ieee80211_tmp_node(vap, mac);
447 IEEE80211_SEND_MGMT(ni, subtype, arg);
449 ieee80211_free_node(ni);
453 ieee80211_alloc_challenge(struct ieee80211_node *ni)
455 if (ni->ni_challenge == NULL)
456 ni->ni_challenge = (uint32_t *) kmalloc(IEEE80211_CHALLENGE_LEN,
457 M_80211_NODE, M_INTWAIT);
458 if (ni->ni_challenge == NULL) {
459 IEEE80211_NOTE(ni->ni_vap,
460 IEEE80211_MSG_DEBUG | IEEE80211_MSG_AUTH, ni,
461 "%s", "shared key challenge alloc failed");
464 return (ni->ni_challenge != NULL);
468 * Parse a Beacon or ProbeResponse frame and return the
469 * useful information in an ieee80211_scanparams structure.
470 * Status is set to 0 if no problems were found; otherwise
471 * a bitmask of IEEE80211_BPARSE_* items is returned that
472 * describes the problems detected.
475 ieee80211_parse_beacon(struct ieee80211_node *ni, struct mbuf *m,
476 struct ieee80211_channel *rxchan, struct ieee80211_scanparams *scan)
478 struct ieee80211vap *vap = ni->ni_vap;
479 struct ieee80211com *ic = ni->ni_ic;
480 struct ieee80211_frame *wh;
483 wh = mtod(m, struct ieee80211_frame *);
484 frm = (uint8_t *)&wh[1];
485 efrm = mtod(m, uint8_t *) + m->m_len;
488 * beacon/probe response frame format
490 * [2] beacon interval
491 * [2] capability information
493 * [tlv] supported rates
494 * [tlv] country information
495 * [tlv] channel switch announcement (CSA)
496 * [tlv] parameter set (FH/DS)
497 * [tlv] erp information
498 * [tlv] extended supported rates
501 * [tlv] HT capabilities
502 * [tlv] HT information
503 * [tlv] Atheros capabilities
505 * [tlv] Mesh Configuration
507 IEEE80211_VERIFY_LENGTH(efrm - frm, 12,
508 return (scan->status = IEEE80211_BPARSE_BADIELEN));
509 memset(scan, 0, sizeof(*scan));
510 scan->tstamp = frm; frm += 8;
511 scan->bintval = le16toh(*(uint16_t *)frm); frm += 2;
512 scan->capinfo = le16toh(*(uint16_t *)frm); frm += 2;
513 scan->bchan = ieee80211_chan2ieee(ic, rxchan);
514 scan->chan = scan->bchan;
516 scan->ies_len = efrm - frm;
518 while (efrm - frm > 1) {
519 IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2,
520 return (scan->status = IEEE80211_BPARSE_BADIELEN));
522 case IEEE80211_ELEMID_SSID:
525 case IEEE80211_ELEMID_RATES:
528 case IEEE80211_ELEMID_COUNTRY:
531 case IEEE80211_ELEMID_CSA:
534 case IEEE80211_ELEMID_QUIET:
537 case IEEE80211_ELEMID_FHPARMS:
538 if (ic->ic_phytype == IEEE80211_T_FH) {
539 scan->fhdwell = LE_READ_2(&frm[2]);
540 scan->chan = IEEE80211_FH_CHAN(frm[4], frm[5]);
541 scan->fhindex = frm[6];
544 case IEEE80211_ELEMID_DSPARMS:
546 * XXX hack this since depending on phytype
547 * is problematic for multi-mode devices.
549 if (ic->ic_phytype != IEEE80211_T_FH)
552 case IEEE80211_ELEMID_TIM:
555 scan->timoff = frm - mtod(m, uint8_t *);
557 case IEEE80211_ELEMID_IBSSPARMS:
558 case IEEE80211_ELEMID_CFPARMS:
559 case IEEE80211_ELEMID_PWRCNSTR:
560 /* NB: avoid debugging complaints */
562 case IEEE80211_ELEMID_XRATES:
565 case IEEE80211_ELEMID_ERP:
567 IEEE80211_DISCARD_IE(vap,
568 IEEE80211_MSG_ELEMID, wh, "ERP",
569 "bad len %u", frm[1]);
570 vap->iv_stats.is_rx_elem_toobig++;
573 scan->erp = frm[2] | 0x100;
575 case IEEE80211_ELEMID_HTCAP:
578 case IEEE80211_ELEMID_RSN:
581 case IEEE80211_ELEMID_HTINFO:
584 #ifdef IEEE80211_SUPPORT_MESH
585 case IEEE80211_ELEMID_MESHID:
588 case IEEE80211_ELEMID_MESHCONF:
589 scan->meshconf = frm;
592 case IEEE80211_ELEMID_VENDOR:
595 else if (iswmeparam(frm) || iswmeinfo(frm))
597 #ifdef IEEE80211_SUPPORT_SUPERG
598 else if (isatherosoui(frm))
601 #ifdef IEEE80211_SUPPORT_TDMA
602 else if (istdmaoui(frm))
605 else if (vap->iv_flags_ht & IEEE80211_FHT_HTCOMPAT) {
607 * Accept pre-draft HT ie's if the
608 * standard ones have not been seen.
610 if (ishtcapoui(frm)) {
611 if (scan->htcap == NULL)
613 } else if (ishtinfooui(frm)) {
614 if (scan->htinfo == NULL)
620 IEEE80211_DISCARD_IE(vap, IEEE80211_MSG_ELEMID,
622 "id %u, len %u", *frm, frm[1]);
623 vap->iv_stats.is_rx_elem_unknown++;
628 IEEE80211_VERIFY_ELEMENT(scan->rates, IEEE80211_RATE_MAXSIZE,
629 scan->status |= IEEE80211_BPARSE_RATES_INVALID);
630 if (scan->rates != NULL && scan->xrates != NULL) {
632 * NB: don't process XRATES if RATES is missing. This
633 * avoids a potential null ptr deref and should be ok
634 * as the return code will already note RATES is missing
635 * (so callers shouldn't otherwise process the frame).
637 IEEE80211_VERIFY_ELEMENT(scan->xrates,
638 IEEE80211_RATE_MAXSIZE - scan->rates[1],
639 scan->status |= IEEE80211_BPARSE_XRATES_INVALID);
641 IEEE80211_VERIFY_ELEMENT(scan->ssid, IEEE80211_NWID_LEN,
642 scan->status |= IEEE80211_BPARSE_SSID_INVALID);
643 if (scan->chan != scan->bchan && ic->ic_phytype != IEEE80211_T_FH) {
645 * Frame was received on a channel different from the
646 * one indicated in the DS params element id;
647 * silently discard it.
649 * NB: this can happen due to signal leakage.
650 * But we should take it for FH phy because
651 * the rssi value should be correct even for
652 * different hop pattern in FH.
654 IEEE80211_DISCARD(vap,
655 IEEE80211_MSG_ELEMID | IEEE80211_MSG_INPUT,
656 wh, NULL, "for off-channel %u (bchan=%u)",
657 scan->chan, scan->bchan);
658 vap->iv_stats.is_rx_chanmismatch++;
659 scan->status |= IEEE80211_BPARSE_OFFCHAN;
661 if (!(IEEE80211_BINTVAL_MIN <= scan->bintval &&
662 scan->bintval <= IEEE80211_BINTVAL_MAX)) {
663 IEEE80211_DISCARD(vap,
664 IEEE80211_MSG_ELEMID | IEEE80211_MSG_INPUT,
665 wh, NULL, "bogus beacon interval (%d TU)",
666 (int) scan->bintval);
667 vap->iv_stats.is_rx_badbintval++;
668 scan->status |= IEEE80211_BPARSE_BINTVAL_INVALID;
670 if (scan->country != NULL) {
672 * Validate we have at least enough data to extract
673 * the country code. Not sure if we should return an
674 * error instead of discarding the IE; consider this
675 * being lenient as we don't depend on the data for
678 IEEE80211_VERIFY_LENGTH(scan->country[1], 3 * sizeof(uint8_t),
679 scan->country = NULL);
681 if (scan->csa != NULL) {
683 * Validate Channel Switch Announcement; this must
684 * be the correct length or we toss the frame.
686 IEEE80211_VERIFY_LENGTH(scan->csa[1], 3 * sizeof(uint8_t),
687 scan->status |= IEEE80211_BPARSE_CSA_INVALID);
690 * Process HT ie's. This is complicated by our
691 * accepting both the standard ie's and the pre-draft
692 * vendor OUI ie's that some vendors still use/require.
694 if (scan->htcap != NULL) {
695 IEEE80211_VERIFY_LENGTH(scan->htcap[1],
696 scan->htcap[0] == IEEE80211_ELEMID_VENDOR ?
697 4 + sizeof(struct ieee80211_ie_htcap)-2 :
698 sizeof(struct ieee80211_ie_htcap)-2,
701 if (scan->htinfo != NULL) {
702 IEEE80211_VERIFY_LENGTH(scan->htinfo[1],
703 scan->htinfo[0] == IEEE80211_ELEMID_VENDOR ?
704 4 + sizeof(struct ieee80211_ie_htinfo)-2 :
705 sizeof(struct ieee80211_ie_htinfo)-2,
706 scan->htinfo = NULL);
712 * Parse an Action frame. Return 0 on success, non-zero on failure.
715 ieee80211_parse_action(struct ieee80211_node *ni, struct mbuf *m)
717 struct ieee80211vap *vap = ni->ni_vap;
718 const struct ieee80211_action *ia;
719 struct ieee80211_frame *wh;
723 * action frame format:
728 wh = mtod(m, struct ieee80211_frame *);
729 frm = (u_int8_t *)&wh[1];
730 efrm = mtod(m, u_int8_t *) + m->m_len;
731 IEEE80211_VERIFY_LENGTH(efrm - frm,
732 sizeof(struct ieee80211_action), return EINVAL);
733 ia = (const struct ieee80211_action *) frm;
735 vap->iv_stats.is_rx_action++;
736 IEEE80211_NODE_STAT(ni, rx_action);
738 /* verify frame payloads but defer processing */
739 switch (ia->ia_category) {
740 case IEEE80211_ACTION_CAT_BA:
741 switch (ia->ia_action) {
742 case IEEE80211_ACTION_BA_ADDBA_REQUEST:
743 IEEE80211_VERIFY_LENGTH(efrm - frm,
744 sizeof(struct ieee80211_action_ba_addbarequest),
747 case IEEE80211_ACTION_BA_ADDBA_RESPONSE:
748 IEEE80211_VERIFY_LENGTH(efrm - frm,
749 sizeof(struct ieee80211_action_ba_addbaresponse),
752 case IEEE80211_ACTION_BA_DELBA:
753 IEEE80211_VERIFY_LENGTH(efrm - frm,
754 sizeof(struct ieee80211_action_ba_delba),
759 case IEEE80211_ACTION_CAT_HT:
760 switch (ia->ia_action) {
761 case IEEE80211_ACTION_HT_TXCHWIDTH:
762 IEEE80211_VERIFY_LENGTH(efrm - frm,
763 sizeof(struct ieee80211_action_ht_txchwidth),
766 case IEEE80211_ACTION_HT_MIMOPWRSAVE:
767 IEEE80211_VERIFY_LENGTH(efrm - frm,
768 sizeof(struct ieee80211_action_ht_mimopowersave),
773 #ifdef IEEE80211_SUPPORT_MESH
774 case IEEE80211_ACTION_CAT_MESH:
775 switch (ia->ia_action) {
776 case IEEE80211_ACTION_MESH_LMETRIC:
778 * XXX: verification is true only if we are using
779 * Airtime link metric (default)
781 IEEE80211_VERIFY_LENGTH(efrm - frm,
782 sizeof(struct ieee80211_meshlmetric_ie),
785 case IEEE80211_ACTION_MESH_HWMP:
786 /* verify something */
788 case IEEE80211_ACTION_MESH_GANN:
789 IEEE80211_VERIFY_LENGTH(efrm - frm,
790 sizeof(struct ieee80211_meshgann_ie),
793 case IEEE80211_ACTION_MESH_CC:
794 case IEEE80211_ACTION_MESH_MCCA_SREQ:
795 case IEEE80211_ACTION_MESH_MCCA_SREP:
796 case IEEE80211_ACTION_MESH_MCCA_AREQ:
797 case IEEE80211_ACTION_MESH_MCCA_ADVER:
798 case IEEE80211_ACTION_MESH_MCCA_TRDOWN:
799 case IEEE80211_ACTION_MESH_TBTT_REQ:
800 case IEEE80211_ACTION_MESH_TBTT_RES:
801 /* reject these early on, not implemented */
802 IEEE80211_DISCARD(vap,
803 IEEE80211_MSG_ELEMID | IEEE80211_MSG_INPUT,
804 wh, NULL, "not implemented yet, act=0x%02X",
809 case IEEE80211_ACTION_CAT_SELF_PROT:
810 /* If TA or RA group address discard silently */
811 if (IEEE80211_IS_MULTICAST(wh->i_addr1) ||
812 IEEE80211_IS_MULTICAST(wh->i_addr2))
815 * XXX: Should we verify complete length now or it is
816 * to varying in sizes?
818 switch (ia->ia_action) {
819 case IEEE80211_ACTION_MESHPEERING_CONFIRM:
820 case IEEE80211_ACTION_MESHPEERING_CLOSE:
821 /* is not a peering candidate (yet) */
822 if (ni == vap->iv_bss)
832 #ifdef IEEE80211_DEBUG
837 ieee80211_ssid_mismatch(struct ieee80211vap *vap, const char *tag,
838 uint8_t mac[IEEE80211_ADDR_LEN], uint8_t *ssid)
840 kprintf("[%s] discard %s frame, ssid mismatch: ",
841 ether_sprintf(mac), tag);
842 ieee80211_print_essid(ssid + 2, ssid[1]);
847 * Return the bssid of a frame.
849 static const uint8_t *
850 ieee80211_getbssid(const struct ieee80211vap *vap,
851 const struct ieee80211_frame *wh)
853 if (vap->iv_opmode == IEEE80211_M_STA)
855 if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) != IEEE80211_FC1_DIR_NODS)
857 if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == IEEE80211_FC0_SUBTYPE_PS_POLL)
862 #include <machine/stdarg.h>
865 ieee80211_note(const struct ieee80211vap *vap, const char *fmt, ...)
867 char buf[128]; /* XXX */
870 osdep_va_start(ap, fmt);
871 kvsnprintf(buf, sizeof(buf), fmt, ap);
874 if_printf(vap->iv_ifp, "%s", buf); /* NB: no \n */
878 ieee80211_note_frame(const struct ieee80211vap *vap,
879 const struct ieee80211_frame *wh,
880 const char *fmt, ...)
882 char buf[128]; /* XXX */
885 osdep_va_start(ap, fmt);
886 kvsnprintf(buf, sizeof(buf), fmt, ap);
888 if_printf(vap->iv_ifp, "[%s] %s\n",
889 ether_sprintf(ieee80211_getbssid(vap, wh)), buf);
893 ieee80211_note_mac(const struct ieee80211vap *vap,
894 const uint8_t mac[IEEE80211_ADDR_LEN],
895 const char *fmt, ...)
897 char buf[128]; /* XXX */
900 osdep_va_start(ap, fmt);
901 kvsnprintf(buf, sizeof(buf), fmt, ap);
903 if_printf(vap->iv_ifp, "[%s] %s\n", ether_sprintf(mac), buf);
907 ieee80211_discard_frame(const struct ieee80211vap *vap,
908 const struct ieee80211_frame *wh,
909 const char *type, const char *fmt, ...)
913 if_printf(vap->iv_ifp, "[%s] discard ",
914 ether_sprintf(ieee80211_getbssid(vap, wh)));
916 kprintf("%s frame, ", ieee80211_mgt_subtype_name[
917 (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) >>
918 IEEE80211_FC0_SUBTYPE_SHIFT]);
920 kprintf("%s frame, ", type);
921 osdep_va_start(ap, fmt);
928 ieee80211_discard_ie(const struct ieee80211vap *vap,
929 const struct ieee80211_frame *wh,
930 const char *type, const char *fmt, ...)
934 if_printf(vap->iv_ifp, "[%s] discard ",
935 ether_sprintf(ieee80211_getbssid(vap, wh)));
937 kprintf("%s information element, ", type);
939 kprintf("information element, ");
940 osdep_va_start(ap, fmt);
947 ieee80211_discard_mac(const struct ieee80211vap *vap,
948 const uint8_t mac[IEEE80211_ADDR_LEN],
949 const char *type, const char *fmt, ...)
953 if_printf(vap->iv_ifp, "[%s] discard ", ether_sprintf(mac));
955 kprintf("%s frame, ", type);
958 osdep_va_start(ap, fmt);
963 #endif /* IEEE80211_DEBUG */