2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright 2001 The Aerospace Corporation. All rights reserved.
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.
14 * 3. The name of The Aerospace Corporation may not be used to endorse or
15 * promote products derived from this software.
17 * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
34 * All rights reserved.
36 * This code is derived from software contributed to The NetBSD Foundation
37 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
38 * NASA Ames Research Center.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
49 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
50 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
51 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
53 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
54 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
55 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
56 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
57 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
58 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 * POSSIBILITY OF SUCH DAMAGE.
62 #include <sys/param.h>
63 #include <sys/ioctl.h>
64 #include <sys/socket.h>
65 #include <sys/sysctl.h>
68 #include <net/ethernet.h>
70 #include <net/if_dl.h>
71 #include <net/if_types.h>
72 #include <net/if_media.h>
73 #include <net/route.h>
75 #include <net80211/ieee80211_ioctl.h>
76 #include <net80211/ieee80211_freebsd.h>
77 #include <net80211/ieee80211_superg.h>
78 #include <net80211/ieee80211_tdma.h>
79 #include <net80211/ieee80211_mesh.h>
92 #include <stddef.h> /* NB: for offsetof */
98 #include <lib80211/lib80211_regdomain.h>
99 #include <lib80211/lib80211_ioctl.h>
101 #ifndef IEEE80211_FIXED_RATE_NONE
102 #define IEEE80211_FIXED_RATE_NONE 0xff
105 /* XXX need these publicly defined or similar */
106 #ifndef IEEE80211_NODE_AUTH
107 #define IEEE80211_NODE_AUTH 0x000001 /* authorized for data */
108 #define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */
109 #define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */
110 #define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */
111 #define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */
112 #define IEEE80211_NODE_HT 0x000040 /* HT enabled */
113 #define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */
114 #define IEEE80211_NODE_WPS 0x000100 /* WPS association */
115 #define IEEE80211_NODE_TSN 0x000200 /* TSN association */
116 #define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */
117 #define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */
118 #define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */
119 #define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */
120 #define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */
121 #define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */
122 #define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */
123 #define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */
124 #define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */
125 #define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */
126 #define IEEE80211_NODE_VHT 0x100000 /* VHT enabled */
129 #define MAXCHAN 1536 /* max 1.5K channels */
135 static void LINE_INIT(char c);
136 static void LINE_BREAK(void);
137 static void LINE_CHECK(const char *fmt, ...);
139 static const char *modename[IEEE80211_MODE_MAX] = {
140 [IEEE80211_MODE_AUTO] = "auto",
141 [IEEE80211_MODE_11A] = "11a",
142 [IEEE80211_MODE_11B] = "11b",
143 [IEEE80211_MODE_11G] = "11g",
144 [IEEE80211_MODE_FH] = "fh",
145 [IEEE80211_MODE_TURBO_A] = "turboA",
146 [IEEE80211_MODE_TURBO_G] = "turboG",
147 [IEEE80211_MODE_STURBO_A] = "sturbo",
148 [IEEE80211_MODE_11NA] = "11na",
149 [IEEE80211_MODE_11NG] = "11ng",
150 [IEEE80211_MODE_HALF] = "half",
151 [IEEE80211_MODE_QUARTER] = "quarter",
152 [IEEE80211_MODE_VHT_2GHZ] = "11acg",
153 [IEEE80211_MODE_VHT_5GHZ] = "11ac",
156 static void set80211(int s, int type, int val, int len, void *data);
157 static int get80211(int s, int type, void *data, int len);
158 static int get80211len(int s, int type, void *data, int len, int *plen);
159 static int get80211val(int s, int type, int *val);
160 static const char *get_string(const char *val, const char *sep,
161 u_int8_t *buf, int *lenp);
162 static void print_string(const u_int8_t *buf, int len);
163 static void print_regdomain(const struct ieee80211_regdomain *, int);
164 static void print_channels(int, const struct ieee80211req_chaninfo *,
165 int allchans, int verbose);
166 static void regdomain_makechannels(struct ieee80211_regdomain_req *,
167 const struct ieee80211_devcaps_req *);
168 static const char *mesh_linkstate_string(uint8_t state);
170 static struct ieee80211req_chaninfo *chaninfo;
171 static struct ieee80211_regdomain regdomain;
172 static int gotregdomain = 0;
173 static struct ieee80211_roamparams_req roamparams;
174 static int gotroam = 0;
175 static struct ieee80211_txparams_req txparams;
176 static int gottxparams = 0;
177 static struct ieee80211_channel curchan;
178 static int gotcurchan = 0;
179 static struct ifmediareq *ifmr;
180 static int htconf = 0;
181 static int gothtconf = 0;
188 if (get80211val(s, IEEE80211_IOC_HTCONF, &htconf) < 0)
189 warn("unable to get HT configuration information");
194 static int vhtconf = 0;
195 static int gotvhtconf = 0;
202 if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
203 warn("unable to get VHT configuration information");
208 * Collect channel info from the kernel. We use this (mostly)
209 * to handle mapping between frequency and IEEE channel number.
214 if (chaninfo != NULL)
216 chaninfo = malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN));
217 if (chaninfo == NULL)
218 errx(1, "no space for channel list");
219 if (get80211(s, IEEE80211_IOC_CHANINFO, chaninfo,
220 IEEE80211_CHANINFO_SIZE(MAXCHAN)) < 0)
221 err(1, "unable to get channel information");
222 ifmr = ifmedia_getstate(s);
227 static struct regdata *
230 static struct regdata *rdp = NULL;
232 rdp = lib80211_alloc_regdata();
234 errx(-1, "missing or corrupted regdomain database");
240 * Given the channel at index i with attributes from,
241 * check if there is a channel with attributes to in
242 * the channel table. With suitable attributes this
243 * allows the caller to look for promotion; e.g. from
247 canpromote(int i, int from, int to)
249 const struct ieee80211_channel *fc = &chaninfo->ic_chans[i];
252 if ((fc->ic_flags & from) != from)
254 /* NB: quick check exploiting ordering of chans w/ same frequency */
255 if (i+1 < chaninfo->ic_nchans &&
256 chaninfo->ic_chans[i+1].ic_freq == fc->ic_freq &&
257 (chaninfo->ic_chans[i+1].ic_flags & to) == to)
259 /* brute force search in case channel list is not ordered */
260 for (j = 0; j < chaninfo->ic_nchans; j++) {
261 const struct ieee80211_channel *tc = &chaninfo->ic_chans[j];
263 tc->ic_freq == fc->ic_freq && (tc->ic_flags & to) == to)
270 * Handle channel promotion. When a channel is specified with
271 * only a frequency we want to promote it to the ``best'' channel
272 * available. The channel list has separate entries for 11b, 11g,
273 * 11a, and 11n[ga] channels so specifying a frequency w/o any
274 * attributes requires we upgrade, e.g. from 11b -> 11g. This
275 * gets complicated when the channel is specified on the same
276 * command line with a media request that constrains the available
277 * channe list (e.g. mode 11a); we want to honor that to avoid
278 * confusing behaviour.
287 * Query the current mode of the interface in case it's
288 * constrained (e.g. to 11a). We must do this carefully
289 * as there may be a pending ifmedia request in which case
290 * asking the kernel will give us the wrong answer. This
291 * is an unfortunate side-effect of the way ifconfig is
292 * structure for modularity (yech).
294 * NB: ifmr is actually setup in getchaninfo (above); we
295 * assume it's called coincident with to this call so
296 * we have a ``current setting''; otherwise we must pass
297 * the socket descriptor down to here so we can make
298 * the ifmedia_getstate call ourselves.
300 int chanmode = ifmr != NULL ? IFM_MODE(ifmr->ifm_current) : IFM_AUTO;
302 /* when ambiguous promote to ``best'' */
303 /* NB: we abitrarily pick HT40+ over HT40- */
304 if (chanmode != IFM_IEEE80211_11B)
305 i = canpromote(i, IEEE80211_CHAN_B, IEEE80211_CHAN_G);
306 if (chanmode != IFM_IEEE80211_11G && (htconf & 1)) {
307 i = canpromote(i, IEEE80211_CHAN_G,
308 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20);
310 i = canpromote(i, IEEE80211_CHAN_G,
311 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D);
312 i = canpromote(i, IEEE80211_CHAN_G,
313 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U);
316 if (chanmode != IFM_IEEE80211_11A && (htconf & 1)) {
317 i = canpromote(i, IEEE80211_CHAN_A,
318 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20);
320 i = canpromote(i, IEEE80211_CHAN_A,
321 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D);
322 i = canpromote(i, IEEE80211_CHAN_A,
323 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U);
330 mapfreq(struct ieee80211_channel *chan, int freq, int flags)
334 for (i = 0; i < chaninfo->ic_nchans; i++) {
335 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
337 if (c->ic_freq == freq && (c->ic_flags & flags) == flags) {
339 /* when ambiguous promote to ``best'' */
340 c = &chaninfo->ic_chans[promote(i)];
346 errx(1, "unknown/undefined frequency %u/0x%x", freq, flags);
350 mapchan(struct ieee80211_channel *chan, int ieee, int flags)
354 for (i = 0; i < chaninfo->ic_nchans; i++) {
355 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
357 if (c->ic_ieee == ieee && (c->ic_flags & flags) == flags) {
359 /* when ambiguous promote to ``best'' */
360 c = &chaninfo->ic_chans[promote(i)];
366 errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags);
369 static const struct ieee80211_channel *
374 if (get80211(s, IEEE80211_IOC_CURCHAN, &curchan, sizeof(curchan)) < 0) {
376 /* fall back to legacy ioctl */
377 if (get80211val(s, IEEE80211_IOC_CHANNEL, &val) < 0)
378 err(-1, "cannot figure out current channel");
380 mapchan(&curchan, val, 0);
386 static enum ieee80211_phymode
387 chan2mode(const struct ieee80211_channel *c)
389 if (IEEE80211_IS_CHAN_VHTA(c))
390 return IEEE80211_MODE_VHT_5GHZ;
391 if (IEEE80211_IS_CHAN_VHTG(c))
392 return IEEE80211_MODE_VHT_2GHZ;
393 if (IEEE80211_IS_CHAN_HTA(c))
394 return IEEE80211_MODE_11NA;
395 if (IEEE80211_IS_CHAN_HTG(c))
396 return IEEE80211_MODE_11NG;
397 if (IEEE80211_IS_CHAN_108A(c))
398 return IEEE80211_MODE_TURBO_A;
399 if (IEEE80211_IS_CHAN_108G(c))
400 return IEEE80211_MODE_TURBO_G;
401 if (IEEE80211_IS_CHAN_ST(c))
402 return IEEE80211_MODE_STURBO_A;
403 if (IEEE80211_IS_CHAN_FHSS(c))
404 return IEEE80211_MODE_FH;
405 if (IEEE80211_IS_CHAN_HALF(c))
406 return IEEE80211_MODE_HALF;
407 if (IEEE80211_IS_CHAN_QUARTER(c))
408 return IEEE80211_MODE_QUARTER;
409 if (IEEE80211_IS_CHAN_A(c))
410 return IEEE80211_MODE_11A;
411 if (IEEE80211_IS_CHAN_ANYG(c))
412 return IEEE80211_MODE_11G;
413 if (IEEE80211_IS_CHAN_B(c))
414 return IEEE80211_MODE_11B;
415 return IEEE80211_MODE_AUTO;
423 if (get80211(s, IEEE80211_IOC_ROAM,
424 &roamparams, sizeof(roamparams)) < 0)
425 err(1, "unable to get roaming parameters");
430 setroam_cb(int s, void *arg)
432 struct ieee80211_roamparams_req *roam = arg;
433 set80211(s, IEEE80211_IOC_ROAM, 0, sizeof(*roam), roam);
441 if (get80211(s, IEEE80211_IOC_TXPARAMS,
442 &txparams, sizeof(txparams)) < 0)
443 err(1, "unable to get transmit parameters");
448 settxparams_cb(int s, void *arg)
450 struct ieee80211_txparams_req *txp = arg;
451 set80211(s, IEEE80211_IOC_TXPARAMS, 0, sizeof(*txp), txp);
459 if (get80211(s, IEEE80211_IOC_REGDOMAIN,
460 ®domain, sizeof(regdomain)) < 0)
461 err(1, "unable to get regulatory domain info");
466 getdevcaps(int s, struct ieee80211_devcaps_req *dc)
468 if (get80211(s, IEEE80211_IOC_DEVCAPS, dc,
469 IEEE80211_DEVCAPS_SPACE(dc)) < 0)
470 err(1, "unable to get device capabilities");
474 setregdomain_cb(int s, void *arg)
476 struct ieee80211_regdomain_req *req;
477 struct ieee80211_regdomain *rd = arg;
478 struct ieee80211_devcaps_req *dc;
479 struct regdata *rdp = getregdata();
481 if (rd->country != NO_COUNTRY) {
482 const struct country *cc;
484 * Check current country seting to make sure it's
485 * compatible with the new regdomain. If not, then
486 * override it with any default country for this
487 * SKU. If we cannot arrange a match, then abort.
489 cc = lib80211_country_findbycc(rdp, rd->country);
491 errx(1, "unknown ISO country code %d", rd->country);
492 if (cc->rd->sku != rd->regdomain) {
493 const struct regdomain *rp;
495 * Check if country is incompatible with regdomain.
496 * To enable multiple regdomains for a country code
497 * we permit a mismatch between the regdomain and
498 * the country's associated regdomain when the
499 * regdomain is setup w/o a default country. For
500 * example, US is bound to the FCC regdomain but
501 * we allow US to be combined with FCC3 because FCC3
502 * has not default country. This allows bogus
503 * combinations like FCC3+DK which are resolved when
504 * constructing the channel list by deferring to the
505 * regdomain to construct the channel list.
507 rp = lib80211_regdomain_findbysku(rdp, rd->regdomain);
509 errx(1, "country %s (%s) is not usable with "
510 "regdomain %d", cc->isoname, cc->name,
512 else if (rp->cc != NULL && rp->cc != cc)
513 errx(1, "country %s (%s) is not usable with "
514 "regdomain %s", cc->isoname, cc->name,
519 * Fetch the device capabilities and calculate the
520 * full set of netbands for which we request a new
521 * channel list be constructed. Once that's done we
522 * push the regdomain info + channel list to the kernel.
524 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
526 errx(1, "no space for device capabilities");
527 dc->dc_chaninfo.ic_nchans = MAXCHAN;
531 printf("drivercaps: 0x%x\n", dc->dc_drivercaps);
532 printf("cryptocaps: 0x%x\n", dc->dc_cryptocaps);
533 printf("htcaps : 0x%x\n", dc->dc_htcaps);
534 printf("vhtcaps : 0x%x\n", dc->dc_vhtcaps);
536 memcpy(chaninfo, &dc->dc_chaninfo,
537 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
538 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, 1/*verbose*/);
542 req = malloc(IEEE80211_REGDOMAIN_SIZE(dc->dc_chaninfo.ic_nchans));
544 errx(1, "no space for regdomain request");
546 regdomain_makechannels(req, dc);
549 print_regdomain(rd, 1/*verbose*/);
551 /* blech, reallocate channel list for new data */
552 if (chaninfo != NULL)
554 chaninfo = malloc(IEEE80211_CHANINFO_SPACE(&req->chaninfo));
555 if (chaninfo == NULL)
556 errx(1, "no space for channel list");
557 memcpy(chaninfo, &req->chaninfo,
558 IEEE80211_CHANINFO_SPACE(&req->chaninfo));
559 print_channels(s, &req->chaninfo, 1/*allchans*/, 1/*verbose*/);
561 if (req->chaninfo.ic_nchans == 0)
562 errx(1, "no channels calculated");
563 set80211(s, IEEE80211_IOC_REGDOMAIN, 0,
564 IEEE80211_REGDOMAIN_SPACE(req), req);
570 ieee80211_mhz2ieee(int freq, int flags)
572 struct ieee80211_channel chan;
573 mapfreq(&chan, freq, flags);
578 isanyarg(const char *arg)
580 return (strncmp(arg, "-", 1) == 0 ||
581 strncasecmp(arg, "any", 3) == 0 || strncasecmp(arg, "off", 3) == 0);
585 set80211ssid(const char *val, int d, int s, const struct afswtch *rafp)
589 u_int8_t data[IEEE80211_NWID_LEN];
593 if (len > 2 && isdigit((int)val[0]) && val[1] == ':') {
598 bzero(data, sizeof(data));
600 if (get_string(val, NULL, data, &len) == NULL)
603 set80211(s, IEEE80211_IOC_SSID, ssid, len, data);
607 set80211meshid(const char *val, int d, int s, const struct afswtch *rafp)
610 u_int8_t data[IEEE80211_NWID_LEN];
612 memset(data, 0, sizeof(data));
614 if (get_string(val, NULL, data, &len) == NULL)
617 set80211(s, IEEE80211_IOC_MESH_ID, 0, len, data);
621 set80211stationname(const char *val, int d, int s, const struct afswtch *rafp)
626 bzero(data, sizeof(data));
628 get_string(val, NULL, data, &len);
630 set80211(s, IEEE80211_IOC_STATIONNAME, 0, len, data);
634 * Parse a channel specification for attributes/flags.
636 * freq/xx channel width (5,10,20,40,40+,40-)
637 * freq:mode channel mode (a,b,g,h,n,t,s,d)
639 * These can be combined in either order; e.g. 2437:ng/40.
640 * Modes are case insensitive.
642 * The result is not validated here; it's assumed to be
643 * checked against the channel table fetched from the kernel.
646 getchannelflags(const char *val, int freq)
648 #define _CHAN_HT 0x80000000
655 cp = strchr(val, ':');
657 for (cp++; isalpha((int) *cp); cp++) {
658 /* accept mixed case */
663 case 'a': /* 802.11a */
664 flags |= IEEE80211_CHAN_A;
666 case 'b': /* 802.11b */
667 flags |= IEEE80211_CHAN_B;
669 case 'g': /* 802.11g */
670 flags |= IEEE80211_CHAN_G;
672 case 'v': /* vht: 802.11ac */
675 case 'h': /* ht = 802.11n */
676 case 'n': /* 802.11n */
677 flags |= _CHAN_HT; /* NB: private */
679 case 'd': /* dt = Atheros Dynamic Turbo */
680 flags |= IEEE80211_CHAN_TURBO;
682 case 't': /* ht, dt, st, t */
683 /* dt and unadorned t specify Dynamic Turbo */
684 if ((flags & (IEEE80211_CHAN_STURBO|_CHAN_HT)) == 0)
685 flags |= IEEE80211_CHAN_TURBO;
687 case 's': /* st = Atheros Static Turbo */
688 flags |= IEEE80211_CHAN_STURBO;
691 errx(-1, "%s: Invalid channel attribute %c\n",
696 cp = strchr(val, '/');
699 u_long cw = strtoul(cp+1, &ep, 10);
703 flags |= IEEE80211_CHAN_QUARTER;
706 flags |= IEEE80211_CHAN_HALF;
709 /* NB: this may be removed below */
710 flags |= IEEE80211_CHAN_HT20;
715 /* Handle the 80/160 VHT flag */
717 flags |= IEEE80211_CHAN_VHT80;
719 flags |= IEEE80211_CHAN_VHT160;
722 if (ep != NULL && *ep == '+')
723 flags |= IEEE80211_CHAN_HT40U;
724 else if (ep != NULL && *ep == '-')
725 flags |= IEEE80211_CHAN_HT40D;
728 errx(-1, "%s: Invalid channel width\n", val);
733 * Cleanup specifications.
735 if ((flags & _CHAN_HT) == 0) {
737 * If user specified freq/20 or freq/40 quietly remove
738 * HT cw attributes depending on channel use. To give
739 * an explicit 20/40 width for an HT channel you must
740 * indicate it is an HT channel since all HT channels
741 * are also usable for legacy operation; e.g. freq:n/40.
743 flags &= ~IEEE80211_CHAN_HT;
744 flags &= ~IEEE80211_CHAN_VHT;
747 * Remove private indicator that this is an HT channel
748 * and if no explicit channel width has been given
749 * provide the default settings.
752 if ((flags & IEEE80211_CHAN_HT) == 0) {
753 struct ieee80211_channel chan;
755 * Consult the channel list to see if we can use
756 * HT40+ or HT40- (if both the map routines choose).
759 mapfreq(&chan, freq, 0);
761 mapchan(&chan, freq, 0);
762 flags |= (chan.ic_flags & IEEE80211_CHAN_HT);
766 * If VHT is enabled, then also set the VHT flag and the
767 * relevant channel up/down.
769 if (is_vht && (flags & IEEE80211_CHAN_HT)) {
771 * XXX yes, maybe we should just have VHT, and reuse
774 if (flags & IEEE80211_CHAN_VHT80)
776 else if (flags & IEEE80211_CHAN_HT20)
777 flags |= IEEE80211_CHAN_VHT20;
778 else if (flags & IEEE80211_CHAN_HT40U)
779 flags |= IEEE80211_CHAN_VHT40U;
780 else if (flags & IEEE80211_CHAN_HT40D)
781 flags |= IEEE80211_CHAN_VHT40D;
789 getchannel(int s, struct ieee80211_channel *chan, const char *val)
794 memset(chan, 0, sizeof(*chan));
796 chan->ic_freq = IEEE80211_CHAN_ANY;
801 v = strtol(val, &eptr, 10);
802 if (val[0] == '\0' || val == eptr || errno == ERANGE ||
803 /* channel may be suffixed with nothing, :flag, or /width */
804 (eptr[0] != '\0' && eptr[0] != ':' && eptr[0] != '/'))
805 errx(1, "invalid channel specification%s",
806 errno == ERANGE ? " (out of range)" : "");
807 flags = getchannelflags(val, v);
808 if (v > 255) { /* treat as frequency */
809 mapfreq(chan, v, flags);
811 mapchan(chan, v, flags);
816 set80211channel(const char *val, int d, int s, const struct afswtch *rafp)
818 struct ieee80211_channel chan;
820 getchannel(s, &chan, val);
821 set80211(s, IEEE80211_IOC_CURCHAN, 0, sizeof(chan), &chan);
825 set80211chanswitch(const char *val, int d, int s, const struct afswtch *rafp)
827 struct ieee80211_chanswitch_req csr;
829 getchannel(s, &csr.csa_chan, val);
832 set80211(s, IEEE80211_IOC_CHANSWITCH, 0, sizeof(csr), &csr);
836 set80211authmode(const char *val, int d, int s, const struct afswtch *rafp)
840 if (strcasecmp(val, "none") == 0) {
841 mode = IEEE80211_AUTH_NONE;
842 } else if (strcasecmp(val, "open") == 0) {
843 mode = IEEE80211_AUTH_OPEN;
844 } else if (strcasecmp(val, "shared") == 0) {
845 mode = IEEE80211_AUTH_SHARED;
846 } else if (strcasecmp(val, "8021x") == 0) {
847 mode = IEEE80211_AUTH_8021X;
848 } else if (strcasecmp(val, "wpa") == 0) {
849 mode = IEEE80211_AUTH_WPA;
851 errx(1, "unknown authmode");
854 set80211(s, IEEE80211_IOC_AUTHMODE, mode, 0, NULL);
858 set80211powersavemode(const char *val, int d, int s, const struct afswtch *rafp)
862 if (strcasecmp(val, "off") == 0) {
863 mode = IEEE80211_POWERSAVE_OFF;
864 } else if (strcasecmp(val, "on") == 0) {
865 mode = IEEE80211_POWERSAVE_ON;
866 } else if (strcasecmp(val, "cam") == 0) {
867 mode = IEEE80211_POWERSAVE_CAM;
868 } else if (strcasecmp(val, "psp") == 0) {
869 mode = IEEE80211_POWERSAVE_PSP;
870 } else if (strcasecmp(val, "psp-cam") == 0) {
871 mode = IEEE80211_POWERSAVE_PSP_CAM;
873 errx(1, "unknown powersavemode");
876 set80211(s, IEEE80211_IOC_POWERSAVE, mode, 0, NULL);
880 set80211powersave(const char *val, int d, int s, const struct afswtch *rafp)
883 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_OFF,
886 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_ON,
891 set80211powersavesleep(const char *val, int d, int s, const struct afswtch *rafp)
893 set80211(s, IEEE80211_IOC_POWERSAVESLEEP, atoi(val), 0, NULL);
897 set80211wepmode(const char *val, int d, int s, const struct afswtch *rafp)
901 if (strcasecmp(val, "off") == 0) {
902 mode = IEEE80211_WEP_OFF;
903 } else if (strcasecmp(val, "on") == 0) {
904 mode = IEEE80211_WEP_ON;
905 } else if (strcasecmp(val, "mixed") == 0) {
906 mode = IEEE80211_WEP_MIXED;
908 errx(1, "unknown wep mode");
911 set80211(s, IEEE80211_IOC_WEP, mode, 0, NULL);
915 set80211wep(const char *val, int d, int s, const struct afswtch *rafp)
917 set80211(s, IEEE80211_IOC_WEP, d, 0, NULL);
921 isundefarg(const char *arg)
923 return (strcmp(arg, "-") == 0 || strncasecmp(arg, "undef", 5) == 0);
927 set80211weptxkey(const char *val, int d, int s, const struct afswtch *rafp)
930 set80211(s, IEEE80211_IOC_WEPTXKEY, IEEE80211_KEYIX_NONE, 0, NULL);
932 set80211(s, IEEE80211_IOC_WEPTXKEY, atoi(val)-1, 0, NULL);
936 set80211wepkey(const char *val, int d, int s, const struct afswtch *rafp)
940 u_int8_t data[IEEE80211_KEYBUF_SIZE];
942 if (isdigit((int)val[0]) && val[1] == ':') {
947 bzero(data, sizeof(data));
949 get_string(val, NULL, data, &len);
951 set80211(s, IEEE80211_IOC_WEPKEY, key, len, data);
955 * This function is purely a NetBSD compatibility interface. The NetBSD
956 * interface is too inflexible, but it's there so we'll support it since
957 * it's not all that hard.
960 set80211nwkey(const char *val, int d, int s, const struct afswtch *rafp)
964 u_int8_t data[IEEE80211_KEYBUF_SIZE];
966 set80211(s, IEEE80211_IOC_WEP, IEEE80211_WEP_ON, 0, NULL);
968 if (isdigit((int)val[0]) && val[1] == ':') {
969 txkey = val[0]-'0'-1;
972 for (i = 0; i < 4; i++) {
973 bzero(data, sizeof(data));
975 val = get_string(val, ",", data, &len);
979 set80211(s, IEEE80211_IOC_WEPKEY, i, len, data);
982 bzero(data, sizeof(data));
984 get_string(val, NULL, data, &len);
987 set80211(s, IEEE80211_IOC_WEPKEY, 0, len, data);
989 bzero(data, sizeof(data));
990 for (i = 1; i < 4; i++)
991 set80211(s, IEEE80211_IOC_WEPKEY, i, 0, data);
994 set80211(s, IEEE80211_IOC_WEPTXKEY, txkey, 0, NULL);
998 set80211rtsthreshold(const char *val, int d, int s, const struct afswtch *rafp)
1000 set80211(s, IEEE80211_IOC_RTSTHRESHOLD,
1001 isundefarg(val) ? IEEE80211_RTS_MAX : atoi(val), 0, NULL);
1005 set80211protmode(const char *val, int d, int s, const struct afswtch *rafp)
1009 if (strcasecmp(val, "off") == 0) {
1010 mode = IEEE80211_PROTMODE_OFF;
1011 } else if (strcasecmp(val, "cts") == 0) {
1012 mode = IEEE80211_PROTMODE_CTS;
1013 } else if (strncasecmp(val, "rtscts", 3) == 0) {
1014 mode = IEEE80211_PROTMODE_RTSCTS;
1016 errx(1, "unknown protection mode");
1019 set80211(s, IEEE80211_IOC_PROTMODE, mode, 0, NULL);
1023 set80211htprotmode(const char *val, int d, int s, const struct afswtch *rafp)
1027 if (strcasecmp(val, "off") == 0) {
1028 mode = IEEE80211_PROTMODE_OFF;
1029 } else if (strncasecmp(val, "rts", 3) == 0) {
1030 mode = IEEE80211_PROTMODE_RTSCTS;
1032 errx(1, "unknown protection mode");
1035 set80211(s, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL);
1039 set80211txpower(const char *val, int d, int s, const struct afswtch *rafp)
1041 double v = atof(val);
1044 txpow = (int) (2*v);
1046 errx(-1, "invalid tx power (must be .5 dBm units)");
1047 set80211(s, IEEE80211_IOC_TXPOWER, txpow, 0, NULL);
1050 #define IEEE80211_ROAMING_DEVICE 0
1051 #define IEEE80211_ROAMING_AUTO 1
1052 #define IEEE80211_ROAMING_MANUAL 2
1055 set80211roaming(const char *val, int d, int s, const struct afswtch *rafp)
1059 if (strcasecmp(val, "device") == 0) {
1060 mode = IEEE80211_ROAMING_DEVICE;
1061 } else if (strcasecmp(val, "auto") == 0) {
1062 mode = IEEE80211_ROAMING_AUTO;
1063 } else if (strcasecmp(val, "manual") == 0) {
1064 mode = IEEE80211_ROAMING_MANUAL;
1066 errx(1, "unknown roaming mode");
1068 set80211(s, IEEE80211_IOC_ROAMING, mode, 0, NULL);
1072 set80211wme(const char *val, int d, int s, const struct afswtch *rafp)
1074 set80211(s, IEEE80211_IOC_WME, d, 0, NULL);
1078 set80211hidessid(const char *val, int d, int s, const struct afswtch *rafp)
1080 set80211(s, IEEE80211_IOC_HIDESSID, d, 0, NULL);
1084 set80211apbridge(const char *val, int d, int s, const struct afswtch *rafp)
1086 set80211(s, IEEE80211_IOC_APBRIDGE, d, 0, NULL);
1090 set80211fastframes(const char *val, int d, int s, const struct afswtch *rafp)
1092 set80211(s, IEEE80211_IOC_FF, d, 0, NULL);
1096 set80211dturbo(const char *val, int d, int s, const struct afswtch *rafp)
1098 set80211(s, IEEE80211_IOC_TURBOP, d, 0, NULL);
1102 set80211chanlist(const char *val, int d, int s, const struct afswtch *rafp)
1104 struct ieee80211req_chanlist chanlist;
1105 char *temp, *cp, *tp;
1107 temp = malloc(strlen(val) + 1);
1109 errx(1, "malloc failed");
1111 memset(&chanlist, 0, sizeof(chanlist));
1114 int first, last, f, c;
1116 tp = strchr(cp, ',');
1119 switch (sscanf(cp, "%u-%u", &first, &last)) {
1121 if (first > IEEE80211_CHAN_MAX)
1122 errx(-1, "channel %u out of range, max %u",
1123 first, IEEE80211_CHAN_MAX);
1124 setbit(chanlist.ic_channels, first);
1127 if (first > IEEE80211_CHAN_MAX)
1128 errx(-1, "channel %u out of range, max %u",
1129 first, IEEE80211_CHAN_MAX);
1130 if (last > IEEE80211_CHAN_MAX)
1131 errx(-1, "channel %u out of range, max %u",
1132 last, IEEE80211_CHAN_MAX);
1134 errx(-1, "void channel range, %u > %u",
1136 for (f = first; f <= last; f++)
1137 setbit(chanlist.ic_channels, f);
1149 set80211(s, IEEE80211_IOC_CHANLIST, 0, sizeof(chanlist), &chanlist);
1154 set80211bssid(const char *val, int d, int s, const struct afswtch *rafp)
1157 if (!isanyarg(val)) {
1159 struct sockaddr_dl sdl;
1161 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1163 errx(1, "malloc failed");
1165 strcpy(temp + 1, val);
1166 sdl.sdl_len = sizeof(sdl);
1167 link_addr(temp, &sdl);
1169 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1170 errx(1, "malformed link-level address");
1171 set80211(s, IEEE80211_IOC_BSSID, 0,
1172 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1174 uint8_t zerobssid[IEEE80211_ADDR_LEN];
1175 memset(zerobssid, 0, sizeof(zerobssid));
1176 set80211(s, IEEE80211_IOC_BSSID, 0,
1177 IEEE80211_ADDR_LEN, zerobssid);
1182 getac(const char *ac)
1184 if (strcasecmp(ac, "ac_be") == 0 || strcasecmp(ac, "be") == 0)
1186 if (strcasecmp(ac, "ac_bk") == 0 || strcasecmp(ac, "bk") == 0)
1188 if (strcasecmp(ac, "ac_vi") == 0 || strcasecmp(ac, "vi") == 0)
1190 if (strcasecmp(ac, "ac_vo") == 0 || strcasecmp(ac, "vo") == 0)
1192 errx(1, "unknown wme access class %s", ac);
1196 DECL_CMD_FUNC2(set80211cwmin, ac, val)
1198 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac), NULL);
1202 DECL_CMD_FUNC2(set80211cwmax, ac, val)
1204 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac), NULL);
1208 DECL_CMD_FUNC2(set80211aifs, ac, val)
1210 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac), NULL);
1214 DECL_CMD_FUNC2(set80211txoplimit, ac, val)
1216 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac), NULL);
1220 DECL_CMD_FUNC(set80211acm, ac, d)
1222 set80211(s, IEEE80211_IOC_WME_ACM, 1, getac(ac), NULL);
1225 DECL_CMD_FUNC(set80211noacm, ac, d)
1227 set80211(s, IEEE80211_IOC_WME_ACM, 0, getac(ac), NULL);
1231 DECL_CMD_FUNC(set80211ackpolicy, ac, d)
1233 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 1, getac(ac), NULL);
1236 DECL_CMD_FUNC(set80211noackpolicy, ac, d)
1238 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 0, getac(ac), NULL);
1242 DECL_CMD_FUNC2(set80211bsscwmin, ac, val)
1244 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val),
1245 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1249 DECL_CMD_FUNC2(set80211bsscwmax, ac, val)
1251 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val),
1252 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1256 DECL_CMD_FUNC2(set80211bssaifs, ac, val)
1258 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val),
1259 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1263 DECL_CMD_FUNC2(set80211bsstxoplimit, ac, val)
1265 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val),
1266 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1270 DECL_CMD_FUNC(set80211dtimperiod, val, d)
1272 set80211(s, IEEE80211_IOC_DTIM_PERIOD, atoi(val), 0, NULL);
1276 DECL_CMD_FUNC(set80211bintval, val, d)
1278 set80211(s, IEEE80211_IOC_BEACON_INTERVAL, atoi(val), 0, NULL);
1282 set80211macmac(int s, int op, const char *val)
1285 struct sockaddr_dl sdl;
1287 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1289 errx(1, "malloc failed");
1291 strcpy(temp + 1, val);
1292 sdl.sdl_len = sizeof(sdl);
1293 link_addr(temp, &sdl);
1295 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1296 errx(1, "malformed link-level address");
1297 set80211(s, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl));
1301 DECL_CMD_FUNC(set80211addmac, val, d)
1303 set80211macmac(s, IEEE80211_IOC_ADDMAC, val);
1307 DECL_CMD_FUNC(set80211delmac, val, d)
1309 set80211macmac(s, IEEE80211_IOC_DELMAC, val);
1313 DECL_CMD_FUNC(set80211kickmac, val, d)
1316 struct sockaddr_dl sdl;
1317 struct ieee80211req_mlme mlme;
1319 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1321 errx(1, "malloc failed");
1323 strcpy(temp + 1, val);
1324 sdl.sdl_len = sizeof(sdl);
1325 link_addr(temp, &sdl);
1327 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1328 errx(1, "malformed link-level address");
1329 memset(&mlme, 0, sizeof(mlme));
1330 mlme.im_op = IEEE80211_MLME_DEAUTH;
1331 mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE;
1332 memcpy(mlme.im_macaddr, LLADDR(&sdl), IEEE80211_ADDR_LEN);
1333 set80211(s, IEEE80211_IOC_MLME, 0, sizeof(mlme), &mlme);
1337 DECL_CMD_FUNC(set80211maccmd, val, d)
1339 set80211(s, IEEE80211_IOC_MACCMD, d, 0, NULL);
1343 set80211meshrtmac(int s, int req, const char *val)
1346 struct sockaddr_dl sdl;
1348 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1350 errx(1, "malloc failed");
1352 strcpy(temp + 1, val);
1353 sdl.sdl_len = sizeof(sdl);
1354 link_addr(temp, &sdl);
1356 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1357 errx(1, "malformed link-level address");
1358 set80211(s, IEEE80211_IOC_MESH_RTCMD, req,
1359 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1363 DECL_CMD_FUNC(set80211addmeshrt, val, d)
1365 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_ADD, val);
1369 DECL_CMD_FUNC(set80211delmeshrt, val, d)
1371 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_DELETE, val);
1375 DECL_CMD_FUNC(set80211meshrtcmd, val, d)
1377 set80211(s, IEEE80211_IOC_MESH_RTCMD, d, 0, NULL);
1381 DECL_CMD_FUNC(set80211hwmprootmode, val, d)
1385 if (strcasecmp(val, "normal") == 0)
1386 mode = IEEE80211_HWMP_ROOTMODE_NORMAL;
1387 else if (strcasecmp(val, "proactive") == 0)
1388 mode = IEEE80211_HWMP_ROOTMODE_PROACTIVE;
1389 else if (strcasecmp(val, "rann") == 0)
1390 mode = IEEE80211_HWMP_ROOTMODE_RANN;
1392 mode = IEEE80211_HWMP_ROOTMODE_DISABLED;
1393 set80211(s, IEEE80211_IOC_HWMP_ROOTMODE, mode, 0, NULL);
1397 DECL_CMD_FUNC(set80211hwmpmaxhops, val, d)
1399 set80211(s, IEEE80211_IOC_HWMP_MAXHOPS, atoi(val), 0, NULL);
1403 set80211pureg(const char *val, int d, int s, const struct afswtch *rafp)
1405 set80211(s, IEEE80211_IOC_PUREG, d, 0, NULL);
1409 set80211quiet(const char *val, int d, int s, const struct afswtch *rafp)
1411 set80211(s, IEEE80211_IOC_QUIET, d, 0, NULL);
1415 DECL_CMD_FUNC(set80211quietperiod, val, d)
1417 set80211(s, IEEE80211_IOC_QUIET_PERIOD, atoi(val), 0, NULL);
1421 DECL_CMD_FUNC(set80211quietcount, val, d)
1423 set80211(s, IEEE80211_IOC_QUIET_COUNT, atoi(val), 0, NULL);
1427 DECL_CMD_FUNC(set80211quietduration, val, d)
1429 set80211(s, IEEE80211_IOC_QUIET_DUR, atoi(val), 0, NULL);
1433 DECL_CMD_FUNC(set80211quietoffset, val, d)
1435 set80211(s, IEEE80211_IOC_QUIET_OFFSET, atoi(val), 0, NULL);
1439 set80211bgscan(const char *val, int d, int s, const struct afswtch *rafp)
1441 set80211(s, IEEE80211_IOC_BGSCAN, d, 0, NULL);
1445 DECL_CMD_FUNC(set80211bgscanidle, val, d)
1447 set80211(s, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL);
1451 DECL_CMD_FUNC(set80211bgscanintvl, val, d)
1453 set80211(s, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL);
1457 DECL_CMD_FUNC(set80211scanvalid, val, d)
1459 set80211(s, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL);
1463 * Parse an optional trailing specification of which netbands
1464 * to apply a parameter to. This is basically the same syntax
1465 * as used for channels but you can concatenate to specify
1466 * multiple. For example:
1467 * 14:abg apply to 11a, 11b, and 11g
1468 * 6:ht apply to 11na and 11ng
1469 * We don't make a big effort to catch silly things; this is
1470 * really a convenience mechanism.
1473 getmodeflags(const char *val)
1480 cp = strchr(val, ':');
1482 for (cp++; isalpha((int) *cp); cp++) {
1483 /* accept mixed case */
1488 case 'a': /* 802.11a */
1489 flags |= IEEE80211_CHAN_A;
1491 case 'b': /* 802.11b */
1492 flags |= IEEE80211_CHAN_B;
1494 case 'g': /* 802.11g */
1495 flags |= IEEE80211_CHAN_G;
1497 case 'n': /* 802.11n */
1498 flags |= IEEE80211_CHAN_HT;
1500 case 'd': /* dt = Atheros Dynamic Turbo */
1501 flags |= IEEE80211_CHAN_TURBO;
1503 case 't': /* ht, dt, st, t */
1504 /* dt and unadorned t specify Dynamic Turbo */
1505 if ((flags & (IEEE80211_CHAN_STURBO|IEEE80211_CHAN_HT)) == 0)
1506 flags |= IEEE80211_CHAN_TURBO;
1508 case 's': /* st = Atheros Static Turbo */
1509 flags |= IEEE80211_CHAN_STURBO;
1511 case 'h': /* 1/2-width channels */
1512 flags |= IEEE80211_CHAN_HALF;
1514 case 'q': /* 1/4-width channels */
1515 flags |= IEEE80211_CHAN_QUARTER;
1518 /* XXX set HT too? */
1519 flags |= IEEE80211_CHAN_VHT;
1522 errx(-1, "%s: Invalid mode attribute %c\n",
1530 #define IEEE80211_CHAN_HTA (IEEE80211_CHAN_HT|IEEE80211_CHAN_5GHZ)
1531 #define IEEE80211_CHAN_HTG (IEEE80211_CHAN_HT|IEEE80211_CHAN_2GHZ)
1533 #define _APPLY(_flags, _base, _param, _v) do { \
1534 if (_flags & IEEE80211_CHAN_HT) { \
1535 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1536 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1537 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1538 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1539 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1541 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1543 if (_flags & IEEE80211_CHAN_TURBO) { \
1544 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1545 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1546 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1547 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1548 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1550 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1552 if (_flags & IEEE80211_CHAN_STURBO) \
1553 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1554 if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1555 _base.params[IEEE80211_MODE_11A]._param = _v; \
1556 if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1557 _base.params[IEEE80211_MODE_11G]._param = _v; \
1558 if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1559 _base.params[IEEE80211_MODE_11B]._param = _v; \
1560 if (_flags & IEEE80211_CHAN_HALF) \
1561 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1562 if (_flags & IEEE80211_CHAN_QUARTER) \
1563 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1565 #define _APPLY1(_flags, _base, _param, _v) do { \
1566 if (_flags & IEEE80211_CHAN_HT) { \
1567 if (_flags & IEEE80211_CHAN_5GHZ) \
1568 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1570 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1571 } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \
1572 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1573 else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \
1574 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1575 else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \
1576 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1577 else if (_flags & IEEE80211_CHAN_HALF) \
1578 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1579 else if (_flags & IEEE80211_CHAN_QUARTER) \
1580 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1581 else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1582 _base.params[IEEE80211_MODE_11A]._param = _v; \
1583 else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1584 _base.params[IEEE80211_MODE_11G]._param = _v; \
1585 else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1586 _base.params[IEEE80211_MODE_11B]._param = _v; \
1588 #define _APPLY_RATE(_flags, _base, _param, _v) do { \
1589 if (_flags & IEEE80211_CHAN_HT) { \
1590 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1592 _APPLY(_flags, _base, _param, _v); \
1594 #define _APPLY_RATE1(_flags, _base, _param, _v) do { \
1595 if (_flags & IEEE80211_CHAN_HT) { \
1596 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1598 _APPLY1(_flags, _base, _param, _v); \
1602 DECL_CMD_FUNC(set80211roamrssi, val, d)
1604 double v = atof(val);
1609 errx(-1, "invalid rssi (must be .5 dBm units)");
1610 flags = getmodeflags(val);
1612 if (flags == 0) { /* NB: no flags => current channel */
1613 flags = getcurchan(s)->ic_flags;
1614 _APPLY1(flags, roamparams, rssi, rssi);
1616 _APPLY(flags, roamparams, rssi, rssi);
1617 callback_register(setroam_cb, &roamparams);
1621 getrate(const char *val, const char *tag)
1623 double v = atof(val);
1628 errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag);
1629 return rate; /* NB: returns 2x the specified value */
1633 DECL_CMD_FUNC(set80211roamrate, val, d)
1637 rate = getrate(val, "roam");
1638 flags = getmodeflags(val);
1640 if (flags == 0) { /* NB: no flags => current channel */
1641 flags = getcurchan(s)->ic_flags;
1642 _APPLY_RATE1(flags, roamparams, rate, rate);
1644 _APPLY_RATE(flags, roamparams, rate, rate);
1645 callback_register(setroam_cb, &roamparams);
1649 DECL_CMD_FUNC(set80211mcastrate, val, d)
1653 rate = getrate(val, "mcast");
1654 flags = getmodeflags(val);
1656 if (flags == 0) { /* NB: no flags => current channel */
1657 flags = getcurchan(s)->ic_flags;
1658 _APPLY_RATE1(flags, txparams, mcastrate, rate);
1660 _APPLY_RATE(flags, txparams, mcastrate, rate);
1661 callback_register(settxparams_cb, &txparams);
1665 DECL_CMD_FUNC(set80211mgtrate, val, d)
1669 rate = getrate(val, "mgmt");
1670 flags = getmodeflags(val);
1672 if (flags == 0) { /* NB: no flags => current channel */
1673 flags = getcurchan(s)->ic_flags;
1674 _APPLY_RATE1(flags, txparams, mgmtrate, rate);
1676 _APPLY_RATE(flags, txparams, mgmtrate, rate);
1677 callback_register(settxparams_cb, &txparams);
1681 DECL_CMD_FUNC(set80211ucastrate, val, d)
1686 flags = getmodeflags(val);
1687 if (isanyarg(val)) {
1688 if (flags == 0) { /* NB: no flags => current channel */
1689 flags = getcurchan(s)->ic_flags;
1690 _APPLY1(flags, txparams, ucastrate,
1691 IEEE80211_FIXED_RATE_NONE);
1693 _APPLY(flags, txparams, ucastrate,
1694 IEEE80211_FIXED_RATE_NONE);
1696 int rate = getrate(val, "ucast");
1697 if (flags == 0) { /* NB: no flags => current channel */
1698 flags = getcurchan(s)->ic_flags;
1699 _APPLY_RATE1(flags, txparams, ucastrate, rate);
1701 _APPLY_RATE(flags, txparams, ucastrate, rate);
1703 callback_register(settxparams_cb, &txparams);
1707 DECL_CMD_FUNC(set80211maxretry, val, d)
1709 int v = atoi(val), flags;
1711 flags = getmodeflags(val);
1713 if (flags == 0) { /* NB: no flags => current channel */
1714 flags = getcurchan(s)->ic_flags;
1715 _APPLY1(flags, txparams, maxretry, v);
1717 _APPLY(flags, txparams, maxretry, v);
1718 callback_register(settxparams_cb, &txparams);
1722 #undef IEEE80211_CHAN_HTA
1723 #undef IEEE80211_CHAN_HTG
1726 DECL_CMD_FUNC(set80211fragthreshold, val, d)
1728 set80211(s, IEEE80211_IOC_FRAGTHRESHOLD,
1729 isundefarg(val) ? IEEE80211_FRAG_MAX : atoi(val), 0, NULL);
1733 DECL_CMD_FUNC(set80211bmissthreshold, val, d)
1735 set80211(s, IEEE80211_IOC_BMISSTHRESHOLD,
1736 isundefarg(val) ? IEEE80211_HWBMISS_MAX : atoi(val), 0, NULL);
1740 set80211burst(const char *val, int d, int s, const struct afswtch *rafp)
1742 set80211(s, IEEE80211_IOC_BURST, d, 0, NULL);
1746 set80211doth(const char *val, int d, int s, const struct afswtch *rafp)
1748 set80211(s, IEEE80211_IOC_DOTH, d, 0, NULL);
1752 set80211dfs(const char *val, int d, int s, const struct afswtch *rafp)
1754 set80211(s, IEEE80211_IOC_DFS, d, 0, NULL);
1758 set80211shortgi(const char *val, int d, int s, const struct afswtch *rafp)
1760 set80211(s, IEEE80211_IOC_SHORTGI,
1761 d ? (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) : 0,
1765 /* XXX 11ac density/size is different */
1767 set80211ampdu(const char *val, int d, int s, const struct afswtch *rafp)
1771 if (get80211val(s, IEEE80211_IOC_AMPDU, &du) < 0)
1772 errx(-1, "cannot set AMPDU setting");
1778 set80211(s, IEEE80211_IOC_AMPDU, ampdu, 0, NULL);
1782 set80211stbc(const char *val, int d, int s, const struct afswtch *rafp)
1786 if (get80211val(s, IEEE80211_IOC_STBC, &stbc) < 0)
1787 errx(-1, "cannot set STBC setting");
1793 set80211(s, IEEE80211_IOC_STBC, stbc, 0, NULL);
1797 set80211ldpc(const char *val, int d, int s, const struct afswtch *rafp)
1801 if (get80211val(s, IEEE80211_IOC_LDPC, &ldpc) < 0)
1802 errx(-1, "cannot set LDPC setting");
1808 set80211(s, IEEE80211_IOC_LDPC, ldpc, 0, NULL);
1812 DECL_CMD_FUNC(set80211ampdulimit, val, d)
1816 switch (atoi(val)) {
1819 v = IEEE80211_HTCAP_MAXRXAMPDU_8K;
1823 v = IEEE80211_HTCAP_MAXRXAMPDU_16K;
1827 v = IEEE80211_HTCAP_MAXRXAMPDU_32K;
1831 v = IEEE80211_HTCAP_MAXRXAMPDU_64K;
1834 errx(-1, "invalid A-MPDU limit %s", val);
1836 set80211(s, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL);
1839 /* XXX 11ac density/size is different */
1841 DECL_CMD_FUNC(set80211ampdudensity, val, d)
1845 if (isanyarg(val) || strcasecmp(val, "na") == 0)
1846 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1847 else switch ((int)(atof(val)*4)) {
1849 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1852 v = IEEE80211_HTCAP_MPDUDENSITY_025;
1855 v = IEEE80211_HTCAP_MPDUDENSITY_05;
1858 v = IEEE80211_HTCAP_MPDUDENSITY_1;
1861 v = IEEE80211_HTCAP_MPDUDENSITY_2;
1864 v = IEEE80211_HTCAP_MPDUDENSITY_4;
1867 v = IEEE80211_HTCAP_MPDUDENSITY_8;
1870 v = IEEE80211_HTCAP_MPDUDENSITY_16;
1873 errx(-1, "invalid A-MPDU density %s", val);
1875 set80211(s, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL);
1879 set80211amsdu(const char *val, int d, int s, const struct afswtch *rafp)
1883 if (get80211val(s, IEEE80211_IOC_AMSDU, &amsdu) < 0)
1884 err(-1, "cannot get AMSDU setting");
1890 set80211(s, IEEE80211_IOC_AMSDU, amsdu, 0, NULL);
1894 DECL_CMD_FUNC(set80211amsdulimit, val, d)
1896 set80211(s, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL);
1900 set80211puren(const char *val, int d, int s, const struct afswtch *rafp)
1902 set80211(s, IEEE80211_IOC_PUREN, d, 0, NULL);
1906 set80211htcompat(const char *val, int d, int s, const struct afswtch *rafp)
1908 set80211(s, IEEE80211_IOC_HTCOMPAT, d, 0, NULL);
1912 set80211htconf(const char *val, int d, int s, const struct afswtch *rafp)
1914 set80211(s, IEEE80211_IOC_HTCONF, d, 0, NULL);
1919 set80211dwds(const char *val, int d, int s, const struct afswtch *rafp)
1921 set80211(s, IEEE80211_IOC_DWDS, d, 0, NULL);
1925 set80211inact(const char *val, int d, int s, const struct afswtch *rafp)
1927 set80211(s, IEEE80211_IOC_INACTIVITY, d, 0, NULL);
1931 set80211tsn(const char *val, int d, int s, const struct afswtch *rafp)
1933 set80211(s, IEEE80211_IOC_TSN, d, 0, NULL);
1937 set80211dotd(const char *val, int d, int s, const struct afswtch *rafp)
1939 set80211(s, IEEE80211_IOC_DOTD, d, 0, NULL);
1943 set80211smps(const char *val, int d, int s, const struct afswtch *rafp)
1945 set80211(s, IEEE80211_IOC_SMPS, d, 0, NULL);
1949 set80211rifs(const char *val, int d, int s, const struct afswtch *rafp)
1951 set80211(s, IEEE80211_IOC_RIFS, d, 0, NULL);
1955 set80211vhtconf(const char *val, int d, int s, const struct afswtch *rafp)
1957 if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
1958 errx(-1, "cannot set VHT setting");
1959 printf("%s: vhtconf=0x%08x, d=%d\n", __func__, vhtconf, d);
1965 printf("%s: vhtconf is now 0x%08x\n", __func__, vhtconf);
1966 set80211(s, IEEE80211_IOC_VHTCONF, vhtconf, 0, NULL);
1970 DECL_CMD_FUNC(set80211tdmaslot, val, d)
1972 set80211(s, IEEE80211_IOC_TDMA_SLOT, atoi(val), 0, NULL);
1976 DECL_CMD_FUNC(set80211tdmaslotcnt, val, d)
1978 set80211(s, IEEE80211_IOC_TDMA_SLOTCNT, atoi(val), 0, NULL);
1982 DECL_CMD_FUNC(set80211tdmaslotlen, val, d)
1984 set80211(s, IEEE80211_IOC_TDMA_SLOTLEN, atoi(val), 0, NULL);
1988 DECL_CMD_FUNC(set80211tdmabintval, val, d)
1990 set80211(s, IEEE80211_IOC_TDMA_BINTERVAL, atoi(val), 0, NULL);
1994 DECL_CMD_FUNC(set80211meshttl, val, d)
1996 set80211(s, IEEE80211_IOC_MESH_TTL, atoi(val), 0, NULL);
2000 DECL_CMD_FUNC(set80211meshforward, val, d)
2002 set80211(s, IEEE80211_IOC_MESH_FWRD, d, 0, NULL);
2006 DECL_CMD_FUNC(set80211meshgate, val, d)
2008 set80211(s, IEEE80211_IOC_MESH_GATE, d, 0, NULL);
2012 DECL_CMD_FUNC(set80211meshpeering, val, d)
2014 set80211(s, IEEE80211_IOC_MESH_AP, d, 0, NULL);
2018 DECL_CMD_FUNC(set80211meshmetric, val, d)
2022 memcpy(v, val, sizeof(v));
2023 set80211(s, IEEE80211_IOC_MESH_PR_METRIC, 0, 0, v);
2027 DECL_CMD_FUNC(set80211meshpath, val, d)
2031 memcpy(v, val, sizeof(v));
2032 set80211(s, IEEE80211_IOC_MESH_PR_PATH, 0, 0, v);
2036 regdomain_sort(const void *a, const void *b)
2039 (IEEE80211_CHAN_ALLTURBO|IEEE80211_CHAN_HALF|IEEE80211_CHAN_QUARTER)
2040 const struct ieee80211_channel *ca = a;
2041 const struct ieee80211_channel *cb = b;
2043 return ca->ic_freq == cb->ic_freq ?
2044 (ca->ic_flags & CHAN_ALL) - (cb->ic_flags & CHAN_ALL) :
2045 ca->ic_freq - cb->ic_freq;
2049 static const struct ieee80211_channel *
2050 chanlookup(const struct ieee80211_channel chans[], int nchans,
2051 int freq, int flags)
2055 flags &= IEEE80211_CHAN_ALLTURBO;
2056 for (i = 0; i < nchans; i++) {
2057 const struct ieee80211_channel *c = &chans[i];
2058 if (c->ic_freq == freq &&
2059 (c->ic_flags & IEEE80211_CHAN_ALLTURBO) == flags)
2066 chanfind(const struct ieee80211_channel chans[], int nchans, int flags)
2070 for (i = 0; i < nchans; i++) {
2071 const struct ieee80211_channel *c = &chans[i];
2072 if ((c->ic_flags & flags) == flags)
2079 * Check channel compatibility.
2082 checkchan(const struct ieee80211req_chaninfo *avail, int freq, int flags)
2084 flags &= ~REQ_FLAGS;
2086 * Check if exact channel is in the calibration table;
2087 * everything below is to deal with channels that we
2088 * want to include but that are not explicitly listed.
2090 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, flags) != NULL)
2092 if (flags & IEEE80211_CHAN_GSM) {
2094 * XXX GSM frequency mapping is handled in the kernel
2095 * so we cannot find them in the calibration table;
2096 * just accept the channel and the kernel will reject
2097 * the channel list if it's wrong.
2102 * If this is a 1/2 or 1/4 width channel allow it if a full
2103 * width channel is present for this frequency, and the device
2104 * supports fractional channels on this band. This is a hack
2105 * that avoids bloating the calibration table; it may be better
2106 * by per-band attributes though (we are effectively calculating
2107 * this attribute by scanning the channel list ourself).
2109 if ((flags & (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == 0)
2111 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq,
2112 flags &~ (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == NULL)
2114 if (flags & IEEE80211_CHAN_HALF) {
2115 return chanfind(avail->ic_chans, avail->ic_nchans,
2116 IEEE80211_CHAN_HALF |
2117 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2119 return chanfind(avail->ic_chans, avail->ic_nchans,
2120 IEEE80211_CHAN_QUARTER |
2121 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2126 regdomain_addchans(struct ieee80211req_chaninfo *ci,
2127 const netband_head *bands,
2128 const struct ieee80211_regdomain *reg,
2130 const struct ieee80211req_chaninfo *avail)
2132 const struct netband *nb;
2133 const struct freqband *b;
2134 struct ieee80211_channel *c, *prev;
2135 int freq, hi_adj, lo_adj, channelSep;
2138 hi_adj = (chanFlags & IEEE80211_CHAN_HT40U) ? -20 : 0;
2139 lo_adj = (chanFlags & IEEE80211_CHAN_HT40D) ? 20 : 0;
2140 channelSep = (chanFlags & IEEE80211_CHAN_2GHZ) ? 0 : 40;
2142 LIST_FOREACH(nb, bands, next) {
2145 printf("%s:", __func__);
2146 printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS);
2147 printb(" bandFlags", nb->flags | b->flags,
2148 IEEE80211_CHAN_BITS);
2153 for (freq = b->freqStart + lo_adj;
2154 freq <= b->freqEnd + hi_adj; freq += b->chanSep) {
2156 * Construct flags for the new channel. We take
2157 * the attributes from the band descriptions except
2158 * for HT40 which is enabled generically (i.e. +/-
2159 * extension channel) in the band description and
2160 * then constrained according by channel separation.
2162 flags = nb->flags | b->flags;
2165 * VHT first - HT is a subset.
2167 * XXX TODO: VHT80p80, VHT160 is not yet done.
2169 if (flags & IEEE80211_CHAN_VHT) {
2170 if ((chanFlags & IEEE80211_CHAN_VHT20) &&
2171 (flags & IEEE80211_CHAN_VHT20) == 0) {
2173 printf("%u: skip, not a "
2174 "VHT20 channel\n", freq);
2177 if ((chanFlags & IEEE80211_CHAN_VHT40) &&
2178 (flags & IEEE80211_CHAN_VHT40) == 0) {
2180 printf("%u: skip, not a "
2181 "VHT40 channel\n", freq);
2184 if ((chanFlags & IEEE80211_CHAN_VHT80) &&
2185 (flags & IEEE80211_CHAN_VHT80) == 0) {
2187 printf("%u: skip, not a "
2188 "VHT80 channel\n", freq);
2192 flags &= ~IEEE80211_CHAN_VHT;
2193 flags |= chanFlags & IEEE80211_CHAN_VHT;
2196 /* Now, constrain HT */
2197 if (flags & IEEE80211_CHAN_HT) {
2199 * HT channels are generated specially; we're
2200 * called to add HT20, HT40+, and HT40- chan's
2201 * so we need to expand only band specs for
2202 * the HT channel type being added.
2204 if ((chanFlags & IEEE80211_CHAN_HT20) &&
2205 (flags & IEEE80211_CHAN_HT20) == 0) {
2207 printf("%u: skip, not an "
2208 "HT20 channel\n", freq);
2211 if ((chanFlags & IEEE80211_CHAN_HT40) &&
2212 (flags & IEEE80211_CHAN_HT40) == 0) {
2214 printf("%u: skip, not an "
2215 "HT40 channel\n", freq);
2218 /* NB: HT attribute comes from caller */
2219 flags &= ~IEEE80211_CHAN_HT;
2220 flags |= chanFlags & IEEE80211_CHAN_HT;
2223 * Check if device can operate on this frequency.
2225 if (!checkchan(avail, freq, flags)) {
2227 printf("%u: skip, ", freq);
2228 printb("flags", flags,
2229 IEEE80211_CHAN_BITS);
2230 printf(" not available\n");
2234 if ((flags & REQ_ECM) && !reg->ecm) {
2236 printf("%u: skip, ECM channel\n", freq);
2239 if ((flags & REQ_INDOOR) && reg->location == 'O') {
2241 printf("%u: skip, indoor channel\n",
2245 if ((flags & REQ_OUTDOOR) && reg->location == 'I') {
2247 printf("%u: skip, outdoor channel\n",
2251 if ((flags & IEEE80211_CHAN_HT40) &&
2252 prev != NULL && (freq - prev->ic_freq) < channelSep) {
2254 printf("%u: skip, only %u channel "
2255 "separation, need %d\n", freq,
2256 freq - prev->ic_freq, channelSep);
2259 if (ci->ic_nchans == IEEE80211_CHAN_MAX) {
2261 printf("%u: skip, channel table full\n",
2265 c = &ci->ic_chans[ci->ic_nchans++];
2266 memset(c, 0, sizeof(*c));
2268 c->ic_flags = flags;
2269 if (c->ic_flags & IEEE80211_CHAN_DFS)
2270 c->ic_maxregpower = nb->maxPowerDFS;
2272 c->ic_maxregpower = nb->maxPower;
2274 printf("[%3d] add freq %u ",
2275 ci->ic_nchans-1, c->ic_freq);
2276 printb("flags", c->ic_flags, IEEE80211_CHAN_BITS);
2277 printf(" power %u\n", c->ic_maxregpower);
2279 /* NB: kernel fills in other fields */
2286 regdomain_makechannels(
2287 struct ieee80211_regdomain_req *req,
2288 const struct ieee80211_devcaps_req *dc)
2290 struct regdata *rdp = getregdata();
2291 const struct country *cc;
2292 const struct ieee80211_regdomain *reg = &req->rd;
2293 struct ieee80211req_chaninfo *ci = &req->chaninfo;
2294 const struct regdomain *rd;
2297 * Locate construction table for new channel list. We treat
2298 * the regdomain/SKU as definitive so a country can be in
2299 * multiple with different properties (e.g. US in FCC+FCC3).
2300 * If no regdomain is specified then we fallback on the country
2301 * code to find the associated regdomain since countries always
2302 * belong to at least one regdomain.
2304 if (reg->regdomain == 0) {
2305 cc = lib80211_country_findbycc(rdp, reg->country);
2307 errx(1, "internal error, country %d not found",
2311 rd = lib80211_regdomain_findbysku(rdp, reg->regdomain);
2313 errx(1, "internal error, regdomain %d not found",
2315 if (rd->sku != SKU_DEBUG) {
2317 * regdomain_addchans incrememnts the channel count for
2318 * each channel it adds so initialize ic_nchans to zero.
2319 * Note that we know we have enough space to hold all possible
2320 * channels because the devcaps list size was used to
2321 * allocate our request.
2324 if (!LIST_EMPTY(&rd->bands_11b))
2325 regdomain_addchans(ci, &rd->bands_11b, reg,
2326 IEEE80211_CHAN_B, &dc->dc_chaninfo);
2327 if (!LIST_EMPTY(&rd->bands_11g))
2328 regdomain_addchans(ci, &rd->bands_11g, reg,
2329 IEEE80211_CHAN_G, &dc->dc_chaninfo);
2330 if (!LIST_EMPTY(&rd->bands_11a))
2331 regdomain_addchans(ci, &rd->bands_11a, reg,
2332 IEEE80211_CHAN_A, &dc->dc_chaninfo);
2333 if (!LIST_EMPTY(&rd->bands_11na) && dc->dc_htcaps != 0) {
2334 regdomain_addchans(ci, &rd->bands_11na, reg,
2335 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20,
2337 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2338 regdomain_addchans(ci, &rd->bands_11na, reg,
2339 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U,
2341 regdomain_addchans(ci, &rd->bands_11na, reg,
2342 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D,
2346 if (!LIST_EMPTY(&rd->bands_11ac) && dc->dc_vhtcaps != 0) {
2347 regdomain_addchans(ci, &rd->bands_11ac, reg,
2348 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20 |
2349 IEEE80211_CHAN_VHT20,
2352 /* VHT40 is a function of HT40.. */
2353 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2354 regdomain_addchans(ci, &rd->bands_11ac, reg,
2355 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U |
2356 IEEE80211_CHAN_VHT40U,
2358 regdomain_addchans(ci, &rd->bands_11ac, reg,
2359 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D |
2360 IEEE80211_CHAN_VHT40D,
2365 /* XXX dc_vhtcap? */
2367 regdomain_addchans(ci, &rd->bands_11ac, reg,
2368 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U |
2369 IEEE80211_CHAN_VHT80,
2371 regdomain_addchans(ci, &rd->bands_11ac, reg,
2372 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D |
2373 IEEE80211_CHAN_VHT80,
2377 /* XXX TODO: VHT80_80, VHT160 */
2380 if (!LIST_EMPTY(&rd->bands_11ng) && dc->dc_htcaps != 0) {
2381 regdomain_addchans(ci, &rd->bands_11ng, reg,
2382 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20,
2384 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2385 regdomain_addchans(ci, &rd->bands_11ng, reg,
2386 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U,
2388 regdomain_addchans(ci, &rd->bands_11ng, reg,
2389 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D,
2393 qsort(ci->ic_chans, ci->ic_nchans, sizeof(ci->ic_chans[0]),
2396 memcpy(ci, &dc->dc_chaninfo,
2397 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
2401 list_countries(void)
2403 struct regdata *rdp = getregdata();
2404 const struct country *cp;
2405 const struct regdomain *dp;
2409 printf("\nCountry codes:\n");
2410 LIST_FOREACH(cp, &rdp->countries, next) {
2411 printf("%2s %-15.15s%s", cp->isoname,
2412 cp->name, ((i+1)%4) == 0 ? "\n" : " ");
2416 printf("\nRegulatory domains:\n");
2417 LIST_FOREACH(dp, &rdp->domains, next) {
2418 printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " ");
2425 defaultcountry(const struct regdomain *rd)
2427 struct regdata *rdp = getregdata();
2428 const struct country *cc;
2430 cc = lib80211_country_findbycc(rdp, rd->cc->code);
2432 errx(1, "internal error, ISO country code %d not "
2433 "defined for regdomain %s", rd->cc->code, rd->name);
2434 regdomain.country = cc->code;
2435 regdomain.isocc[0] = cc->isoname[0];
2436 regdomain.isocc[1] = cc->isoname[1];
2440 DECL_CMD_FUNC(set80211regdomain, val, d)
2442 struct regdata *rdp = getregdata();
2443 const struct regdomain *rd;
2445 rd = lib80211_regdomain_findbyname(rdp, val);
2448 long sku = strtol(val, &eptr, 0);
2451 rd = lib80211_regdomain_findbysku(rdp, sku);
2452 if (eptr == val || rd == NULL)
2453 errx(1, "unknown regdomain %s", val);
2456 regdomain.regdomain = rd->sku;
2457 if (regdomain.country == 0 && rd->cc != NULL) {
2459 * No country code setup and there's a default
2460 * one for this regdomain fill it in.
2464 callback_register(setregdomain_cb, ®domain);
2468 DECL_CMD_FUNC(set80211country, val, d)
2470 struct regdata *rdp = getregdata();
2471 const struct country *cc;
2473 cc = lib80211_country_findbyname(rdp, val);
2476 long code = strtol(val, &eptr, 0);
2479 cc = lib80211_country_findbycc(rdp, code);
2480 if (eptr == val || cc == NULL)
2481 errx(1, "unknown ISO country code %s", val);
2484 regdomain.regdomain = cc->rd->sku;
2485 regdomain.country = cc->code;
2486 regdomain.isocc[0] = cc->isoname[0];
2487 regdomain.isocc[1] = cc->isoname[1];
2488 callback_register(setregdomain_cb, ®domain);
2492 set80211location(const char *val, int d, int s, const struct afswtch *rafp)
2495 regdomain.location = d;
2496 callback_register(setregdomain_cb, ®domain);
2500 set80211ecm(const char *val, int d, int s, const struct afswtch *rafp)
2504 callback_register(setregdomain_cb, ®domain);
2520 if (spacer != '\t') {
2524 col = 8; /* 8-col tab */
2528 LINE_CHECK(const char *fmt, ...)
2535 n = vsnprintf(buf+1, sizeof(buf)-1, fmt, ap);
2548 getmaxrate(const uint8_t rates[15], uint8_t nrates)
2550 int i, maxrate = -1;
2552 for (i = 0; i < nrates; i++) {
2553 int rate = rates[i] & IEEE80211_RATE_VAL;
2561 getcaps(int capinfo)
2563 static char capstring[32];
2564 char *cp = capstring;
2566 if (capinfo & IEEE80211_CAPINFO_ESS)
2568 if (capinfo & IEEE80211_CAPINFO_IBSS)
2570 if (capinfo & IEEE80211_CAPINFO_CF_POLLABLE)
2572 if (capinfo & IEEE80211_CAPINFO_CF_POLLREQ)
2574 if (capinfo & IEEE80211_CAPINFO_PRIVACY)
2576 if (capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)
2578 if (capinfo & IEEE80211_CAPINFO_PBCC)
2580 if (capinfo & IEEE80211_CAPINFO_CHNL_AGILITY)
2582 if (capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME)
2584 if (capinfo & IEEE80211_CAPINFO_RSN)
2586 if (capinfo & IEEE80211_CAPINFO_DSSSOFDM)
2595 static char flagstring[32];
2596 char *cp = flagstring;
2598 if (flags & IEEE80211_NODE_AUTH)
2600 if (flags & IEEE80211_NODE_QOS)
2602 if (flags & IEEE80211_NODE_ERP)
2604 if (flags & IEEE80211_NODE_PWR_MGT)
2606 if (flags & IEEE80211_NODE_HT) {
2608 if (flags & IEEE80211_NODE_HTCOMPAT)
2611 if (flags & IEEE80211_NODE_VHT)
2613 if (flags & IEEE80211_NODE_WPS)
2615 if (flags & IEEE80211_NODE_TSN)
2617 if (flags & IEEE80211_NODE_AMPDU_TX)
2619 if (flags & IEEE80211_NODE_AMPDU_RX)
2621 if (flags & IEEE80211_NODE_MIMO_PS) {
2623 if (flags & IEEE80211_NODE_MIMO_RTS)
2626 if (flags & IEEE80211_NODE_RIFS)
2628 if (flags & IEEE80211_NODE_SGI40) {
2630 if (flags & IEEE80211_NODE_SGI20)
2632 } else if (flags & IEEE80211_NODE_SGI20)
2634 if (flags & IEEE80211_NODE_AMSDU_TX)
2636 if (flags & IEEE80211_NODE_AMSDU_RX)
2643 printie(const char* tag, const uint8_t *ie, size_t ielen, int maxlen)
2647 maxlen -= strlen(tag)+2;
2648 if (2*ielen > maxlen)
2651 for (; ielen > 0; ie++, ielen--) {
2654 printf("%02x", *ie);
2662 #define LE_READ_2(p) \
2664 ((((const u_int8_t *)(p))[0] ) | \
2665 (((const u_int8_t *)(p))[1] << 8)))
2666 #define LE_READ_4(p) \
2668 ((((const u_int8_t *)(p))[0] ) | \
2669 (((const u_int8_t *)(p))[1] << 8) | \
2670 (((const u_int8_t *)(p))[2] << 16) | \
2671 (((const u_int8_t *)(p))[3] << 24)))
2674 * NB: The decoding routines assume a properly formatted ie
2675 * which should be safe as the kernel only retains them
2680 printwmeparam(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2682 #define MS(_v, _f) (((_v) & _f) >> _f##_S)
2683 static const char *acnames[] = { "BE", "BK", "VO", "VI" };
2684 const struct ieee80211_wme_param *wme =
2685 (const struct ieee80211_wme_param *) ie;
2691 printf("<qosinfo 0x%x", wme->param_qosInfo);
2692 ie += offsetof(struct ieee80211_wme_param, params_acParams);
2693 for (i = 0; i < WME_NUM_AC; i++) {
2694 const struct ieee80211_wme_acparams *ac =
2695 &wme->params_acParams[i];
2697 printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]"
2699 , MS(ac->acp_aci_aifsn, WME_PARAM_ACM) ? "acm " : ""
2700 , MS(ac->acp_aci_aifsn, WME_PARAM_AIFSN)
2701 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMIN)
2702 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMAX)
2703 , LE_READ_2(&ac->acp_txop)
2711 printwmeinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2715 const struct ieee80211_wme_info *wme =
2716 (const struct ieee80211_wme_info *) ie;
2717 printf("<version 0x%x info 0x%x>",
2718 wme->wme_version, wme->wme_info);
2723 printvhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2727 const struct ieee80211_ie_vhtcap *vhtcap =
2728 (const struct ieee80211_ie_vhtcap *) ie;
2729 uint32_t vhtcap_info = LE_READ_4(&vhtcap->vht_cap_info);
2731 printf("<cap 0x%08x", vhtcap_info);
2732 printf(" rx_mcs_map 0x%x",
2733 LE_READ_2(&vhtcap->supp_mcs.rx_mcs_map));
2734 printf(" rx_highest %d",
2735 LE_READ_2(&vhtcap->supp_mcs.rx_highest) & 0x1fff);
2736 printf(" tx_mcs_map 0x%x",
2737 LE_READ_2(&vhtcap->supp_mcs.tx_mcs_map));
2738 printf(" tx_highest %d",
2739 LE_READ_2(&vhtcap->supp_mcs.tx_highest) & 0x1fff);
2746 printvhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2750 const struct ieee80211_ie_vht_operation *vhtinfo =
2751 (const struct ieee80211_ie_vht_operation *) ie;
2753 printf("<chw %d freq1_idx %d freq2_idx %d basic_mcs_set 0x%04x>",
2754 vhtinfo->chan_width,
2755 vhtinfo->center_freq_seg1_idx,
2756 vhtinfo->center_freq_seg2_idx,
2757 LE_READ_2(&vhtinfo->basic_mcs_set));
2762 printvhtpwrenv(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2765 static const char *txpwrmap[] = {
2772 const struct ieee80211_ie_vht_txpwrenv *vhtpwr =
2773 (const struct ieee80211_ie_vht_txpwrenv *) ie;
2775 const char *sep = "";
2777 /* Get count; trim at ielen */
2778 n = (vhtpwr->tx_info &
2779 IEEE80211_VHT_TXPWRENV_INFO_COUNT_MASK) + 1;
2783 printf("<tx_info 0x%02x pwr:[", vhtpwr->tx_info);
2784 for (i = 0; i < n; i++) {
2785 printf("%s%s:%.2f", sep, txpwrmap[i],
2786 ((float) ((int8_t) ie[i+3])) / 2.0);
2795 printhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2799 const struct ieee80211_ie_htcap *htcap =
2800 (const struct ieee80211_ie_htcap *) ie;
2804 printf("<cap 0x%x param 0x%x",
2805 LE_READ_2(&htcap->hc_cap), htcap->hc_param);
2808 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2809 if (isset(htcap->hc_mcsset, i)) {
2810 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2811 if (isclr(htcap->hc_mcsset, j))
2815 printf("%s%u", sep, i);
2817 printf("%s%u-%u", sep, i, j);
2821 printf("] extcap 0x%x txbf 0x%x antenna 0x%x>",
2822 LE_READ_2(&htcap->hc_extcap),
2823 LE_READ_4(&htcap->hc_txbf),
2829 printhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2833 const struct ieee80211_ie_htinfo *htinfo =
2834 (const struct ieee80211_ie_htinfo *) ie;
2838 printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel,
2839 htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3,
2840 LE_READ_2(&htinfo->hi_byte45));
2841 printf(" basicmcs[");
2843 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2844 if (isset(htinfo->hi_basicmcsset, i)) {
2845 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2846 if (isclr(htinfo->hi_basicmcsset, j))
2850 printf("%s%u", sep, i);
2852 printf("%s%u-%u", sep, i, j);
2861 printathie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2866 const struct ieee80211_ath_ie *ath =
2867 (const struct ieee80211_ath_ie *)ie;
2870 if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME)
2872 if (ath->ath_capability & ATHEROS_CAP_COMPRESSION)
2874 if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME)
2876 if (ath->ath_capability & ATHEROS_CAP_XR)
2878 if (ath->ath_capability & ATHEROS_CAP_AR)
2880 if (ath->ath_capability & ATHEROS_CAP_BURST)
2882 if (ath->ath_capability & ATHEROS_CAP_WME)
2884 if (ath->ath_capability & ATHEROS_CAP_BOOST)
2886 printf("0x%x>", LE_READ_2(ath->ath_defkeyix));
2892 printmeshconf(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2897 const struct ieee80211_meshconf_ie *mconf =
2898 (const struct ieee80211_meshconf_ie *)ie;
2900 if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP)
2905 if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME)
2909 printf(" CONGESTION:");
2910 if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED)
2915 if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF)
2920 if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED)
2924 printf(" FORM:0x%x CAPS:0x%x>", mconf->conf_form,
2930 printbssload(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2934 const struct ieee80211_bss_load_ie *bssload =
2935 (const struct ieee80211_bss_load_ie *) ie;
2936 printf("<sta count %d, chan load %d, aac %d>",
2937 LE_READ_2(&bssload->sta_count),
2944 printapchanrep(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2948 const struct ieee80211_ap_chan_report_ie *ap =
2949 (const struct ieee80211_ap_chan_report_ie *) ie;
2950 const char *sep = "";
2953 printf("<class %u, chan:[", ap->i_class);
2955 for (i = 3; i < ielen; i++) {
2956 printf("%s%u", sep, ie[i]);
2964 wpa_cipher(const u_int8_t *sel)
2966 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2967 u_int32_t w = LE_READ_4(sel);
2970 case WPA_SEL(WPA_CSE_NULL):
2972 case WPA_SEL(WPA_CSE_WEP40):
2974 case WPA_SEL(WPA_CSE_WEP104):
2976 case WPA_SEL(WPA_CSE_TKIP):
2978 case WPA_SEL(WPA_CSE_CCMP):
2981 return "?"; /* NB: so 1<< is discarded */
2986 wpa_keymgmt(const u_int8_t *sel)
2988 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2989 u_int32_t w = LE_READ_4(sel);
2992 case WPA_SEL(WPA_ASE_8021X_UNSPEC):
2993 return "8021X-UNSPEC";
2994 case WPA_SEL(WPA_ASE_8021X_PSK):
2996 case WPA_SEL(WPA_ASE_NONE):
3004 printwpaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3006 u_int8_t len = ie[1];
3013 ie += 6, len -= 4; /* NB: len is payload only */
3015 printf("<v%u", LE_READ_2(ie));
3018 printf(" mc:%s", wpa_cipher(ie));
3021 /* unicast ciphers */
3025 for (; n > 0; n--) {
3026 printf("%s%s", sep, wpa_cipher(ie));
3031 /* key management algorithms */
3035 for (; n > 0; n--) {
3036 printf("%s%s", sep, wpa_keymgmt(ie));
3041 if (len > 2) /* optional capabilities */
3042 printf(", caps 0x%x", LE_READ_2(ie));
3048 rsn_cipher(const u_int8_t *sel)
3050 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
3051 u_int32_t w = LE_READ_4(sel);
3054 case RSN_SEL(RSN_CSE_NULL):
3056 case RSN_SEL(RSN_CSE_WEP40):
3058 case RSN_SEL(RSN_CSE_WEP104):
3060 case RSN_SEL(RSN_CSE_TKIP):
3062 case RSN_SEL(RSN_CSE_CCMP):
3064 case RSN_SEL(RSN_CSE_WRAP):
3072 rsn_keymgmt(const u_int8_t *sel)
3074 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
3075 u_int32_t w = LE_READ_4(sel);
3078 case RSN_SEL(RSN_ASE_8021X_UNSPEC):
3079 return "8021X-UNSPEC";
3080 case RSN_SEL(RSN_ASE_8021X_PSK):
3082 case RSN_SEL(RSN_ASE_NONE):
3090 printrsnie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3097 ie += 2, ielen -= 2;
3099 printf("<v%u", LE_READ_2(ie));
3100 ie += 2, ielen -= 2;
3102 printf(" mc:%s", rsn_cipher(ie));
3103 ie += 4, ielen -= 4;
3105 /* unicast ciphers */
3107 ie += 2, ielen -= 2;
3109 for (; n > 0; n--) {
3110 printf("%s%s", sep, rsn_cipher(ie));
3111 ie += 4, ielen -= 4;
3115 /* key management algorithms */
3117 ie += 2, ielen -= 2;
3119 for (; n > 0; n--) {
3120 printf("%s%s", sep, rsn_keymgmt(ie));
3121 ie += 4, ielen -= 4;
3125 if (ielen > 2) /* optional capabilities */
3126 printf(", caps 0x%x", LE_READ_2(ie));
3132 /* XXX move to a public include file */
3133 #define IEEE80211_WPS_DEV_PASS_ID 0x1012
3134 #define IEEE80211_WPS_SELECTED_REG 0x1041
3135 #define IEEE80211_WPS_SETUP_STATE 0x1044
3136 #define IEEE80211_WPS_UUID_E 0x1047
3137 #define IEEE80211_WPS_VERSION 0x104a
3139 #define BE_READ_2(p) \
3141 ((((const u_int8_t *)(p))[1] ) | \
3142 (((const u_int8_t *)(p))[0] << 8)))
3145 printwpsie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3147 u_int8_t len = ie[1];
3151 static const char *dev_pass_id[] = {
3152 "D", /* Default (PIN) */
3153 "U", /* User-specified */
3154 "M", /* Machine-specified */
3156 "P", /* PushButton */
3157 "R" /* Registrar-specified */
3161 ie +=6, len -= 4; /* NB: len is payload only */
3163 /* WPS IE in Beacon and Probe Resp frames have different fields */
3166 uint16_t tlv_type = BE_READ_2(ie);
3167 uint16_t tlv_len = BE_READ_2(ie + 2);
3169 /* some devices broadcast invalid WPS frames */
3170 if (tlv_len > len) {
3171 printf("bad frame length tlv_type=0x%02x "
3172 "tlv_len=%d len=%d", tlv_type, tlv_len,
3180 case IEEE80211_WPS_VERSION:
3181 printf("v:%d.%d", *ie >> 4, *ie & 0xf);
3183 case IEEE80211_WPS_SETUP_STATE:
3184 /* Only 1 and 2 are valid */
3185 if (*ie == 0 || *ie >= 3)
3188 printf(" st:%s", *ie == 1 ? "N" : "C");
3190 case IEEE80211_WPS_SELECTED_REG:
3191 printf(" sel:%s", *ie ? "T" : "F");
3193 case IEEE80211_WPS_DEV_PASS_ID:
3195 if (n < nitems(dev_pass_id))
3196 printf(" dpi:%s", dev_pass_id[n]);
3198 case IEEE80211_WPS_UUID_E:
3200 for (n = 0; n < (tlv_len - 1); n++)
3201 printf("%02x-", ie[n]);
3202 printf("%02x", ie[n]);
3205 ie += tlv_len, len -= tlv_len;
3212 printtdmaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3215 if (verbose && ielen >= sizeof(struct ieee80211_tdma_param)) {
3216 const struct ieee80211_tdma_param *tdma =
3217 (const struct ieee80211_tdma_param *) ie;
3220 printf("<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>",
3221 tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt,
3222 LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval,
3223 tdma->tdma_inuse[0]);
3228 * Copy the ssid string contents into buf, truncating to fit. If the
3229 * ssid is entirely printable then just copy intact. Otherwise convert
3230 * to hexadecimal. If the result is truncated then replace the last
3231 * three characters with "...".
3234 copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len)
3240 if (essid_len > bufsize)
3244 /* determine printable or not */
3245 for (i = 0, p = essid; i < maxlen; i++, p++) {
3246 if (*p < ' ' || *p > 0x7e)
3249 if (i != maxlen) { /* not printable, print as hex */
3252 strlcpy(buf, "0x", bufsize);
3255 for (i = 0; i < maxlen && bufsize >= 2; i++) {
3256 sprintf(&buf[2+2*i], "%02x", p[i]);
3260 memcpy(&buf[2+2*i-3], "...", 3);
3261 } else { /* printable, truncate as needed */
3262 memcpy(buf, essid, maxlen);
3263 if (maxlen != essid_len)
3264 memcpy(&buf[maxlen-3], "...", 3);
3270 printssid(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3272 char ssid[2*IEEE80211_NWID_LEN+1];
3274 printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid);
3278 printrates(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3285 for (i = 2; i < ielen; i++) {
3286 printf("%s%s%d", sep,
3287 ie[i] & IEEE80211_RATE_BASIC ? "B" : "",
3288 ie[i] & IEEE80211_RATE_VAL);
3295 printcountry(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3297 const struct ieee80211_country_ie *cie =
3298 (const struct ieee80211_country_ie *) ie;
3299 int i, nbands, schan, nchan;
3301 printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]);
3302 nbands = (cie->len - 3) / sizeof(cie->band[0]);
3303 for (i = 0; i < nbands; i++) {
3304 schan = cie->band[i].schan;
3305 nchan = cie->band[i].nchan;
3307 printf(" %u-%u,%u", schan, schan + nchan-1,
3308 cie->band[i].maxtxpwr);
3310 printf(" %u,%u", schan, cie->band[i].maxtxpwr);
3316 iswpaoui(const u_int8_t *frm)
3318 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI);
3322 iswmeinfo(const u_int8_t *frm)
3324 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3325 frm[6] == WME_INFO_OUI_SUBTYPE;
3329 iswmeparam(const u_int8_t *frm)
3331 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3332 frm[6] == WME_PARAM_OUI_SUBTYPE;
3336 isatherosoui(const u_int8_t *frm)
3338 return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI);
3342 istdmaoui(const uint8_t *frm)
3344 return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI);
3348 iswpsoui(const uint8_t *frm)
3350 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPS_OUI_TYPE<<24)|WPA_OUI);
3357 case IEEE80211_ELEMID_FHPARMS: return " FHPARMS";
3358 case IEEE80211_ELEMID_CFPARMS: return " CFPARMS";
3359 case IEEE80211_ELEMID_TIM: return " TIM";
3360 case IEEE80211_ELEMID_IBSSPARMS:return " IBSSPARMS";
3361 case IEEE80211_ELEMID_BSSLOAD: return " BSSLOAD";
3362 case IEEE80211_ELEMID_CHALLENGE:return " CHALLENGE";
3363 case IEEE80211_ELEMID_PWRCNSTR: return " PWRCNSTR";
3364 case IEEE80211_ELEMID_PWRCAP: return " PWRCAP";
3365 case IEEE80211_ELEMID_TPCREQ: return " TPCREQ";
3366 case IEEE80211_ELEMID_TPCREP: return " TPCREP";
3367 case IEEE80211_ELEMID_SUPPCHAN: return " SUPPCHAN";
3368 case IEEE80211_ELEMID_CSA: return " CSA";
3369 case IEEE80211_ELEMID_MEASREQ: return " MEASREQ";
3370 case IEEE80211_ELEMID_MEASREP: return " MEASREP";
3371 case IEEE80211_ELEMID_QUIET: return " QUIET";
3372 case IEEE80211_ELEMID_IBSSDFS: return " IBSSDFS";
3373 case IEEE80211_ELEMID_TPC: return " TPC";
3374 case IEEE80211_ELEMID_CCKM: return " CCKM";
3380 printies(const u_int8_t *vp, int ielen, int maxcols)
3384 case IEEE80211_ELEMID_SSID:
3386 printssid(" SSID", vp, 2+vp[1], maxcols);
3388 case IEEE80211_ELEMID_RATES:
3389 case IEEE80211_ELEMID_XRATES:
3391 printrates(vp[0] == IEEE80211_ELEMID_RATES ?
3392 " RATES" : " XRATES", vp, 2+vp[1], maxcols);
3394 case IEEE80211_ELEMID_DSPARMS:
3396 printf(" DSPARMS<%u>", vp[2]);
3398 case IEEE80211_ELEMID_COUNTRY:
3400 printcountry(" COUNTRY", vp, 2+vp[1], maxcols);
3402 case IEEE80211_ELEMID_ERP:
3404 printf(" ERP<0x%x>", vp[2]);
3406 case IEEE80211_ELEMID_VENDOR:
3408 printwpaie(" WPA", vp, 2+vp[1], maxcols);
3409 else if (iswmeinfo(vp))
3410 printwmeinfo(" WME", vp, 2+vp[1], maxcols);
3411 else if (iswmeparam(vp))
3412 printwmeparam(" WME", vp, 2+vp[1], maxcols);
3413 else if (isatherosoui(vp))
3414 printathie(" ATH", vp, 2+vp[1], maxcols);
3415 else if (iswpsoui(vp))
3416 printwpsie(" WPS", vp, 2+vp[1], maxcols);
3417 else if (istdmaoui(vp))
3418 printtdmaie(" TDMA", vp, 2+vp[1], maxcols);
3420 printie(" VEN", vp, 2+vp[1], maxcols);
3422 case IEEE80211_ELEMID_RSN:
3423 printrsnie(" RSN", vp, 2+vp[1], maxcols);
3425 case IEEE80211_ELEMID_HTCAP:
3426 printhtcap(" HTCAP", vp, 2+vp[1], maxcols);
3428 case IEEE80211_ELEMID_HTINFO:
3430 printhtinfo(" HTINFO", vp, 2+vp[1], maxcols);
3432 case IEEE80211_ELEMID_MESHID:
3434 printssid(" MESHID", vp, 2+vp[1], maxcols);
3436 case IEEE80211_ELEMID_MESHCONF:
3437 printmeshconf(" MESHCONF", vp, 2+vp[1], maxcols);
3439 case IEEE80211_ELEMID_VHT_CAP:
3440 printvhtcap(" VHTCAP", vp, 2+vp[1], maxcols);
3442 case IEEE80211_ELEMID_VHT_OPMODE:
3443 printvhtinfo(" VHTOPMODE", vp, 2+vp[1], maxcols);
3445 case IEEE80211_ELEMID_VHT_PWR_ENV:
3446 printvhtpwrenv(" VHTPWRENV", vp, 2+vp[1], maxcols);
3448 case IEEE80211_ELEMID_BSSLOAD:
3449 printbssload(" BSSLOAD", vp, 2+vp[1], maxcols);
3451 case IEEE80211_ELEMID_APCHANREP:
3452 printapchanrep(" APCHANREP", vp, 2+vp[1], maxcols);
3456 printie(iename(vp[0]), vp, 2+vp[1], maxcols);
3465 printmimo(const struct ieee80211_mimo_info *mi)
3470 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3471 if (mi->ch[i].rssi != 0) {
3477 /* NB: don't muddy display unless there's something to show */
3481 /* XXX TODO: ignore EVM; secondary channels for now */
3482 printf(" (rssi %.1f:%.1f:%.1f:%.1f nf %d:%d:%d:%d)",
3483 mi->ch[0].rssi[0] / 2.0,
3484 mi->ch[1].rssi[0] / 2.0,
3485 mi->ch[2].rssi[0] / 2.0,
3486 mi->ch[3].rssi[0] / 2.0,
3490 mi->ch[3].noise[0]);
3496 uint8_t buf[24*1024];
3497 char ssid[IEEE80211_NWID_LEN+1];
3501 if (get80211len(s, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0)
3502 errx(1, "unable to get scan results");
3503 if (len < sizeof(struct ieee80211req_scan_result))
3508 printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n"
3509 , IEEE80211_NWID_LEN, IEEE80211_NWID_LEN, "SSID/MESH ID"
3519 const struct ieee80211req_scan_result *sr;
3520 const uint8_t *vp, *idp;
3522 sr = (const struct ieee80211req_scan_result *) cp;
3523 vp = cp + sr->isr_ie_off;
3524 if (sr->isr_meshid_len) {
3525 idp = vp + sr->isr_ssid_len;
3526 idlen = sr->isr_meshid_len;
3529 idlen = sr->isr_ssid_len;
3531 printf("%-*.*s %s %3d %3dM %4d:%-4d %4d %-4.4s"
3532 , IEEE80211_NWID_LEN
3533 , copy_essid(ssid, IEEE80211_NWID_LEN, idp, idlen)
3535 , ether_ntoa((const struct ether_addr *) sr->isr_bssid)
3536 , ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags)
3537 , getmaxrate(sr->isr_rates, sr->isr_nrates)
3538 , (sr->isr_rssi/2)+sr->isr_noise, sr->isr_noise
3540 , getcaps(sr->isr_capinfo)
3542 printies(vp + sr->isr_ssid_len + sr->isr_meshid_len,
3543 sr->isr_ie_len, 24);
3545 cp += sr->isr_len, len -= sr->isr_len;
3546 } while (len >= sizeof(struct ieee80211req_scan_result));
3550 scan_and_wait(int s)
3552 struct ieee80211_scan_req sr;
3553 struct ieee80211req ireq;
3556 sroute = socket(PF_ROUTE, SOCK_RAW, 0);
3558 perror("socket(PF_ROUTE,SOCK_RAW)");
3561 (void) memset(&ireq, 0, sizeof(ireq));
3562 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
3563 ireq.i_type = IEEE80211_IOC_SCAN_REQ;
3565 memset(&sr, 0, sizeof(sr));
3566 sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE
3567 | IEEE80211_IOC_SCAN_BGSCAN
3568 | IEEE80211_IOC_SCAN_NOPICK
3569 | IEEE80211_IOC_SCAN_ONCE;
3570 sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER;
3574 ireq.i_len = sizeof(sr);
3576 * NB: only root can trigger a scan so ignore errors. Also ignore
3577 * possible errors from net80211, even if no new scan could be
3578 * started there might still be a valid scan cache.
3580 if (ioctl(s, SIOCS80211, &ireq) == 0) {
3582 struct if_announcemsghdr *ifan;
3583 struct rt_msghdr *rtm;
3586 if (read(sroute, buf, sizeof(buf)) < 0) {
3587 perror("read(PF_ROUTE)");
3590 rtm = (struct rt_msghdr *) buf;
3591 if (rtm->rtm_version != RTM_VERSION)
3593 ifan = (struct if_announcemsghdr *) rtm;
3594 } while (rtm->rtm_type != RTM_IEEE80211 ||
3595 ifan->ifan_what != RTM_IEEE80211_SCAN);
3601 DECL_CMD_FUNC(set80211scan, val, d)
3607 static enum ieee80211_opmode get80211opmode(int s);
3610 gettxseq(const struct ieee80211req_sta_info *si)
3614 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3615 return si->isi_txseqs[0];
3616 /* XXX not right but usually what folks want */
3618 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3619 if (si->isi_txseqs[i] > txseq)
3620 txseq = si->isi_txseqs[i];
3625 getrxseq(const struct ieee80211req_sta_info *si)
3629 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3630 return si->isi_rxseqs[0];
3631 /* XXX not right but usually what folks want */
3633 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3634 if (si->isi_rxseqs[i] > rxseq)
3635 rxseq = si->isi_rxseqs[i];
3640 list_stations(int s)
3643 struct ieee80211req_sta_req req;
3644 uint8_t buf[24*1024];
3646 enum ieee80211_opmode opmode = get80211opmode(s);
3650 /* broadcast address =>'s get all stations */
3651 (void) memset(u.req.is_u.macaddr, 0xff, IEEE80211_ADDR_LEN);
3652 if (opmode == IEEE80211_M_STA) {
3654 * Get information about the associated AP.
3656 (void) get80211(s, IEEE80211_IOC_BSSID,
3657 u.req.is_u.macaddr, IEEE80211_ADDR_LEN);
3659 if (get80211len(s, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0)
3660 errx(1, "unable to get station information");
3661 if (len < sizeof(struct ieee80211req_sta_info))
3666 if (opmode == IEEE80211_M_MBSS)
3667 printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n"
3680 printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-7s\n"
3692 cp = (const uint8_t *) u.req.info;
3694 const struct ieee80211req_sta_info *si;
3696 si = (const struct ieee80211req_sta_info *) cp;
3697 if (si->isi_len < sizeof(*si))
3699 if (opmode == IEEE80211_M_MBSS)
3700 printf("%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d"
3701 , ether_ntoa((const struct ether_addr*)
3703 , ieee80211_mhz2ieee(si->isi_freq,
3707 , mesh_linkstate_string(si->isi_peerstate)
3715 printf("%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-7.7s"
3716 , ether_ntoa((const struct ether_addr*)
3718 , IEEE80211_AID(si->isi_associd)
3719 , ieee80211_mhz2ieee(si->isi_freq,
3726 , getcaps(si->isi_capinfo)
3727 , getflags(si->isi_state)
3729 printies(cp + si->isi_ie_off, si->isi_ie_len, 24);
3730 printmimo(&si->isi_mimo);
3732 cp += si->isi_len, len -= si->isi_len;
3733 } while (len >= sizeof(struct ieee80211req_sta_info));
3737 mesh_linkstate_string(uint8_t state)
3739 static const char *state_names[] = {
3748 if (state >= nitems(state_names)) {
3749 static char buf[10];
3750 snprintf(buf, sizeof(buf), "#%u", state);
3753 return state_names[state];
3757 get_chaninfo(const struct ieee80211_channel *c, int precise,
3758 char buf[], size_t bsize)
3761 if (IEEE80211_IS_CHAN_FHSS(c))
3762 strlcat(buf, " FHSS", bsize);
3763 if (IEEE80211_IS_CHAN_A(c))
3764 strlcat(buf, " 11a", bsize);
3765 else if (IEEE80211_IS_CHAN_ANYG(c))
3766 strlcat(buf, " 11g", bsize);
3767 else if (IEEE80211_IS_CHAN_B(c))
3768 strlcat(buf, " 11b", bsize);
3769 if (IEEE80211_IS_CHAN_HALF(c))
3770 strlcat(buf, "/10MHz", bsize);
3771 if (IEEE80211_IS_CHAN_QUARTER(c))
3772 strlcat(buf, "/5MHz", bsize);
3773 if (IEEE80211_IS_CHAN_TURBO(c))
3774 strlcat(buf, " Turbo", bsize);
3776 /* XXX should make VHT80U, VHT80D */
3777 if (IEEE80211_IS_CHAN_VHT80(c) &&
3778 IEEE80211_IS_CHAN_HT40D(c))
3779 strlcat(buf, " vht/80-", bsize);
3780 else if (IEEE80211_IS_CHAN_VHT80(c) &&
3781 IEEE80211_IS_CHAN_HT40U(c))
3782 strlcat(buf, " vht/80+", bsize);
3783 else if (IEEE80211_IS_CHAN_VHT80(c))
3784 strlcat(buf, " vht/80", bsize);
3785 else if (IEEE80211_IS_CHAN_VHT40D(c))
3786 strlcat(buf, " vht/40-", bsize);
3787 else if (IEEE80211_IS_CHAN_VHT40U(c))
3788 strlcat(buf, " vht/40+", bsize);
3789 else if (IEEE80211_IS_CHAN_VHT20(c))
3790 strlcat(buf, " vht/20", bsize);
3791 else if (IEEE80211_IS_CHAN_HT20(c))
3792 strlcat(buf, " ht/20", bsize);
3793 else if (IEEE80211_IS_CHAN_HT40D(c))
3794 strlcat(buf, " ht/40-", bsize);
3795 else if (IEEE80211_IS_CHAN_HT40U(c))
3796 strlcat(buf, " ht/40+", bsize);
3798 if (IEEE80211_IS_CHAN_VHT(c))
3799 strlcat(buf, " vht", bsize);
3800 else if (IEEE80211_IS_CHAN_HT(c))
3801 strlcat(buf, " ht", bsize);
3807 print_chaninfo(const struct ieee80211_channel *c, int verb)
3812 printf("Channel %3u : %u%c%c%c%c%c MHz%-14.14s",
3813 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
3814 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
3815 IEEE80211_IS_CHAN_DFS(c) ? 'D' : ' ',
3816 IEEE80211_IS_CHAN_RADAR(c) ? 'R' : ' ',
3817 IEEE80211_IS_CHAN_CWINT(c) ? 'I' : ' ',
3818 IEEE80211_IS_CHAN_CACDONE(c) ? 'C' : ' ',
3819 get_chaninfo(c, verb, buf, sizeof(buf)));
3821 printf("Channel %3u : %u%c MHz%-14.14s",
3822 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
3823 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
3824 get_chaninfo(c, verb, buf, sizeof(buf)));
3829 chanpref(const struct ieee80211_channel *c)
3831 if (IEEE80211_IS_CHAN_VHT160(c))
3833 if (IEEE80211_IS_CHAN_VHT80_80(c))
3835 if (IEEE80211_IS_CHAN_VHT80(c))
3837 if (IEEE80211_IS_CHAN_VHT40(c))
3839 if (IEEE80211_IS_CHAN_VHT20(c))
3841 if (IEEE80211_IS_CHAN_HT40(c))
3843 if (IEEE80211_IS_CHAN_HT20(c))
3845 if (IEEE80211_IS_CHAN_HALF(c))
3847 if (IEEE80211_IS_CHAN_QUARTER(c))
3849 if (IEEE80211_IS_CHAN_TURBO(c))
3851 if (IEEE80211_IS_CHAN_A(c))
3853 if (IEEE80211_IS_CHAN_G(c))
3855 if (IEEE80211_IS_CHAN_B(c))
3857 if (IEEE80211_IS_CHAN_PUREG(c))
3863 print_channels(int s, const struct ieee80211req_chaninfo *chans,
3864 int allchans, int verb)
3866 struct ieee80211req_chaninfo *achans;
3867 uint8_t reported[IEEE80211_CHAN_BYTES];
3868 const struct ieee80211_channel *c;
3871 achans = malloc(IEEE80211_CHANINFO_SPACE(chans));
3873 errx(1, "no space for active channel list");
3874 achans->ic_nchans = 0;
3875 memset(reported, 0, sizeof(reported));
3877 struct ieee80211req_chanlist active;
3879 if (get80211(s, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0)
3880 errx(1, "unable to get active channel list");
3881 for (i = 0; i < chans->ic_nchans; i++) {
3882 c = &chans->ic_chans[i];
3883 if (!isset(active.ic_channels, c->ic_ieee))
3886 * Suppress compatible duplicates unless
3887 * verbose. The kernel gives us it's
3888 * complete channel list which has separate
3889 * entries for 11g/11b and 11a/turbo.
3891 if (isset(reported, c->ic_ieee) && !verb) {
3892 /* XXX we assume duplicates are adjacent */
3893 achans->ic_chans[achans->ic_nchans-1] = *c;
3895 achans->ic_chans[achans->ic_nchans++] = *c;
3896 setbit(reported, c->ic_ieee);
3900 for (i = 0; i < chans->ic_nchans; i++) {
3901 c = &chans->ic_chans[i];
3902 /* suppress duplicates as above */
3903 if (isset(reported, c->ic_ieee) && !verb) {
3904 /* XXX we assume duplicates are adjacent */
3905 struct ieee80211_channel *a =
3906 &achans->ic_chans[achans->ic_nchans-1];
3907 if (chanpref(c) > chanpref(a))
3910 achans->ic_chans[achans->ic_nchans++] = *c;
3911 setbit(reported, c->ic_ieee);
3915 half = achans->ic_nchans / 2;
3916 if (achans->ic_nchans % 2)
3919 for (i = 0; i < achans->ic_nchans / 2; i++) {
3920 print_chaninfo(&achans->ic_chans[i], verb);
3921 print_chaninfo(&achans->ic_chans[half+i], verb);
3924 if (achans->ic_nchans % 2) {
3925 print_chaninfo(&achans->ic_chans[i], verb);
3932 list_channels(int s, int allchans)
3935 print_channels(s, chaninfo, allchans, verbose);
3939 print_txpow(const struct ieee80211_channel *c)
3941 printf("Channel %3u : %u MHz %3.1f reg %2d ",
3942 c->ic_ieee, c->ic_freq,
3943 c->ic_maxpower/2., c->ic_maxregpower);
3947 print_txpow_verbose(const struct ieee80211_channel *c)
3949 print_chaninfo(c, 1);
3950 printf("min %4.1f dBm max %3.1f dBm reg %2d dBm",
3951 c->ic_minpower/2., c->ic_maxpower/2., c->ic_maxregpower);
3952 /* indicate where regulatory cap limits power use */
3953 if (c->ic_maxpower > 2*c->ic_maxregpower)
3960 struct ieee80211req_chaninfo *achans;
3961 uint8_t reported[IEEE80211_CHAN_BYTES];
3962 struct ieee80211_channel *c, *prev;
3966 achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo));
3968 errx(1, "no space for active channel list");
3969 achans->ic_nchans = 0;
3970 memset(reported, 0, sizeof(reported));
3971 for (i = 0; i < chaninfo->ic_nchans; i++) {
3972 c = &chaninfo->ic_chans[i];
3973 /* suppress duplicates as above */
3974 if (isset(reported, c->ic_ieee) && !verbose) {
3975 /* XXX we assume duplicates are adjacent */
3976 assert(achans->ic_nchans > 0);
3977 prev = &achans->ic_chans[achans->ic_nchans-1];
3978 /* display highest power on channel */
3979 if (c->ic_maxpower > prev->ic_maxpower)
3982 achans->ic_chans[achans->ic_nchans++] = *c;
3983 setbit(reported, c->ic_ieee);
3987 half = achans->ic_nchans / 2;
3988 if (achans->ic_nchans % 2)
3991 for (i = 0; i < achans->ic_nchans / 2; i++) {
3992 print_txpow(&achans->ic_chans[i]);
3993 print_txpow(&achans->ic_chans[half+i]);
3996 if (achans->ic_nchans % 2) {
3997 print_txpow(&achans->ic_chans[i]);
4001 for (i = 0; i < achans->ic_nchans; i++) {
4002 print_txpow_verbose(&achans->ic_chans[i]);
4015 list_capabilities(int s)
4017 struct ieee80211_devcaps_req *dc;
4020 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
4022 dc = malloc(IEEE80211_DEVCAPS_SIZE(1));
4024 errx(1, "no space for device capabilities");
4025 dc->dc_chaninfo.ic_nchans = verbose ? MAXCHAN : 1;
4027 printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS);
4028 if (dc->dc_cryptocaps != 0 || verbose) {
4030 printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS);
4032 if (dc->dc_htcaps != 0 || verbose) {
4034 printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS);
4036 if (dc->dc_vhtcaps != 0 || verbose) {
4038 printb("vhtcaps", dc->dc_vhtcaps, IEEE80211_VHTCAP_BITS);
4043 chaninfo = &dc->dc_chaninfo; /* XXX */
4044 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, verbose);
4050 get80211wme(int s, int param, int ac, int *val)
4052 struct ieee80211req ireq;
4054 (void) memset(&ireq, 0, sizeof(ireq));
4055 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4056 ireq.i_type = param;
4058 if (ioctl(s, SIOCG80211, &ireq) < 0) {
4059 warn("cannot get WME parameter %d, ac %d%s",
4060 param, ac & IEEE80211_WMEPARAM_VAL,
4061 ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : "");
4069 list_wme_aci(int s, const char *tag, int ac)
4073 printf("\t%s", tag);
4075 /* show WME BSS parameters */
4076 if (get80211wme(s, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1)
4077 printf(" cwmin %2u", val);
4078 if (get80211wme(s, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1)
4079 printf(" cwmax %2u", val);
4080 if (get80211wme(s, IEEE80211_IOC_WME_AIFS, ac, &val) != -1)
4081 printf(" aifs %2u", val);
4082 if (get80211wme(s, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1)
4083 printf(" txopLimit %3u", val);
4084 if (get80211wme(s, IEEE80211_IOC_WME_ACM, ac, &val) != -1) {
4091 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
4092 if (get80211wme(s, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) {
4105 static const char *acnames[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
4109 /* display both BSS and local settings */
4110 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) {
4112 if (ac & IEEE80211_WMEPARAM_BSS)
4113 list_wme_aci(s, " ", ac);
4115 list_wme_aci(s, acnames[ac], ac);
4116 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
4117 ac |= IEEE80211_WMEPARAM_BSS;
4120 ac &= ~IEEE80211_WMEPARAM_BSS;
4123 /* display only channel settings */
4124 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++)
4125 list_wme_aci(s, acnames[ac], ac);
4132 const struct ieee80211_roamparam *rp;
4136 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
4137 rp = &roamparams.params[mode];
4138 if (rp->rssi == 0 && rp->rate == 0)
4140 if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) {
4142 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm MCS %2u ",
4143 modename[mode], rp->rssi/2,
4144 rp->rate &~ IEEE80211_RATE_MCS);
4146 LINE_CHECK("roam:%-7.7s rssi %4udBm MCS %2u ",
4147 modename[mode], rp->rssi/2,
4148 rp->rate &~ IEEE80211_RATE_MCS);
4151 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s",
4152 modename[mode], rp->rssi/2, rp->rate/2);
4154 LINE_CHECK("roam:%-7.7s rssi %4udBm rate %2u Mb/s",
4155 modename[mode], rp->rssi/2, rp->rate/2);
4161 list_txparams(int s)
4163 const struct ieee80211_txparam *tp;
4167 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
4168 tp = &txparams.params[mode];
4169 if (tp->mgmtrate == 0 && tp->mcastrate == 0)
4171 if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) {
4172 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
4173 LINE_CHECK("%-7.7s ucast NONE mgmt %2u MCS "
4174 "mcast %2u MCS maxretry %u",
4176 tp->mgmtrate &~ IEEE80211_RATE_MCS,
4177 tp->mcastrate &~ IEEE80211_RATE_MCS,
4180 LINE_CHECK("%-7.7s ucast %2u MCS mgmt %2u MCS "
4181 "mcast %2u MCS maxretry %u",
4183 tp->ucastrate &~ IEEE80211_RATE_MCS,
4184 tp->mgmtrate &~ IEEE80211_RATE_MCS,
4185 tp->mcastrate &~ IEEE80211_RATE_MCS,
4188 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
4189 LINE_CHECK("%-7.7s ucast NONE mgmt %2u Mb/s "
4190 "mcast %2u Mb/s maxretry %u",
4193 tp->mcastrate/2, tp->maxretry);
4195 LINE_CHECK("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s "
4196 "mcast %2u Mb/s maxretry %u",
4198 tp->ucastrate/2, tp->mgmtrate/2,
4199 tp->mcastrate/2, tp->maxretry);
4205 printpolicy(int policy)
4208 case IEEE80211_MACCMD_POLICY_OPEN:
4209 printf("policy: open\n");
4211 case IEEE80211_MACCMD_POLICY_ALLOW:
4212 printf("policy: allow\n");
4214 case IEEE80211_MACCMD_POLICY_DENY:
4215 printf("policy: deny\n");
4217 case IEEE80211_MACCMD_POLICY_RADIUS:
4218 printf("policy: radius\n");
4221 printf("policy: unknown (%u)\n", policy);
4229 struct ieee80211req ireq;
4230 struct ieee80211req_maclist *acllist;
4231 int i, nacls, policy, len;
4235 (void) memset(&ireq, 0, sizeof(ireq));
4236 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name)); /* XXX ?? */
4237 ireq.i_type = IEEE80211_IOC_MACCMD;
4238 ireq.i_val = IEEE80211_MACCMD_POLICY;
4239 if (ioctl(s, SIOCG80211, &ireq) < 0) {
4240 if (errno == EINVAL) {
4241 printf("No acl policy loaded\n");
4244 err(1, "unable to get mac policy");
4246 policy = ireq.i_val;
4247 if (policy == IEEE80211_MACCMD_POLICY_OPEN) {
4249 } else if (policy == IEEE80211_MACCMD_POLICY_ALLOW) {
4251 } else if (policy == IEEE80211_MACCMD_POLICY_DENY) {
4253 } else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) {
4254 c = 'r'; /* NB: should never have entries */
4256 printf("policy: unknown (%u)\n", policy);
4259 if (verbose || c == '?')
4260 printpolicy(policy);
4262 ireq.i_val = IEEE80211_MACCMD_LIST;
4264 if (ioctl(s, SIOCG80211, &ireq) < 0)
4265 err(1, "unable to get mac acl list size");
4266 if (ireq.i_len == 0) { /* NB: no acls */
4267 if (!(verbose || c == '?'))
4268 printpolicy(policy);
4275 err(1, "out of memory for acl list");
4278 if (ioctl(s, SIOCG80211, &ireq) < 0)
4279 err(1, "unable to get mac acl list");
4280 nacls = len / sizeof(*acllist);
4281 acllist = (struct ieee80211req_maclist *) data;
4282 for (i = 0; i < nacls; i++)
4283 printf("%c%s\n", c, ether_ntoa(
4284 (const struct ether_addr *) acllist[i].ml_macaddr));
4289 print_regdomain(const struct ieee80211_regdomain *reg, int verb)
4291 if ((reg->regdomain != 0 &&
4292 reg->regdomain != reg->country) || verb) {
4293 const struct regdomain *rd =
4294 lib80211_regdomain_findbysku(getregdata(), reg->regdomain);
4296 LINE_CHECK("regdomain %d", reg->regdomain);
4298 LINE_CHECK("regdomain %s", rd->name);
4300 if (reg->country != 0 || verb) {
4301 const struct country *cc =
4302 lib80211_country_findbycc(getregdata(), reg->country);
4304 LINE_CHECK("country %d", reg->country);
4306 LINE_CHECK("country %s", cc->isoname);
4308 if (reg->location == 'I')
4309 LINE_CHECK("indoor");
4310 else if (reg->location == 'O')
4311 LINE_CHECK("outdoor");
4313 LINE_CHECK("anywhere");
4321 list_regdomain(int s, int channelsalso)
4327 print_regdomain(®domain, 1);
4329 print_channels(s, chaninfo, 1/*allchans*/, 1/*verbose*/);
4331 print_regdomain(®domain, verbose);
4337 struct ieee80211req ireq;
4338 struct ieee80211req_mesh_route routes[128];
4339 struct ieee80211req_mesh_route *rt;
4341 (void) memset(&ireq, 0, sizeof(ireq));
4342 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4343 ireq.i_type = IEEE80211_IOC_MESH_RTCMD;
4344 ireq.i_val = IEEE80211_MESH_RTCMD_LIST;
4345 ireq.i_data = &routes;
4346 ireq.i_len = sizeof(routes);
4347 if (ioctl(s, SIOCG80211, &ireq) < 0)
4348 err(1, "unable to get the Mesh routing table");
4350 printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n"
4359 for (rt = &routes[0]; rt - &routes[0] < ireq.i_len / sizeof(*rt); rt++){
4361 ether_ntoa((const struct ether_addr *)rt->imr_dest));
4362 printf("%s %4u %4u %6u %6u %c%c\n",
4363 ether_ntoa((const struct ether_addr *)rt->imr_nexthop),
4364 rt->imr_nhops, rt->imr_metric, rt->imr_lifetime,
4366 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_DISCOVER) ?
4368 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_VALID) ?
4370 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ?
4372 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_GATE) ?
4378 DECL_CMD_FUNC(set80211list, arg, d)
4380 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
4384 if (iseq(arg, "sta"))
4386 else if (iseq(arg, "scan") || iseq(arg, "ap"))
4388 else if (iseq(arg, "chan") || iseq(arg, "freq"))
4389 list_channels(s, 1);
4390 else if (iseq(arg, "active"))
4391 list_channels(s, 0);
4392 else if (iseq(arg, "keys"))
4394 else if (iseq(arg, "caps"))
4395 list_capabilities(s);
4396 else if (iseq(arg, "wme") || iseq(arg, "wmm"))
4398 else if (iseq(arg, "mac"))
4400 else if (iseq(arg, "txpow"))
4402 else if (iseq(arg, "roam"))
4404 else if (iseq(arg, "txparam") || iseq(arg, "txparm"))
4406 else if (iseq(arg, "regdomain"))
4407 list_regdomain(s, 1);
4408 else if (iseq(arg, "countries"))
4410 else if (iseq(arg, "mesh"))
4413 errx(1, "Don't know how to list %s for %s", arg, name);
4418 static enum ieee80211_opmode
4419 get80211opmode(int s)
4421 struct ifmediareq ifmr;
4423 (void) memset(&ifmr, 0, sizeof(ifmr));
4424 (void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
4426 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) {
4427 if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) {
4428 if (ifmr.ifm_current & IFM_FLAG0)
4429 return IEEE80211_M_AHDEMO;
4431 return IEEE80211_M_IBSS;
4433 if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP)
4434 return IEEE80211_M_HOSTAP;
4435 if (ifmr.ifm_current & IFM_IEEE80211_IBSS)
4436 return IEEE80211_M_IBSS;
4437 if (ifmr.ifm_current & IFM_IEEE80211_MONITOR)
4438 return IEEE80211_M_MONITOR;
4439 if (ifmr.ifm_current & IFM_IEEE80211_MBSS)
4440 return IEEE80211_M_MBSS;
4442 return IEEE80211_M_STA;
4447 printcipher(int s, struct ieee80211req *ireq, int keylenop)
4449 switch (ireq->i_val) {
4450 case IEEE80211_CIPHER_WEP:
4451 ireq->i_type = keylenop;
4452 if (ioctl(s, SIOCG80211, ireq) != -1)
4454 ireq->i_len <= 5 ? "40" :
4455 ireq->i_len <= 13 ? "104" : "128");
4459 case IEEE80211_CIPHER_TKIP:
4462 case IEEE80211_CIPHER_AES_OCB:
4465 case IEEE80211_CIPHER_AES_CCM:
4468 case IEEE80211_CIPHER_CKIP:
4471 case IEEE80211_CIPHER_NONE:
4475 printf("UNKNOWN (0x%x)", ireq->i_val);
4482 printkey(const struct ieee80211req_key *ik)
4484 static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
4485 u_int keylen = ik->ik_keylen;
4488 printcontents = printkeys &&
4489 (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose);
4492 switch (ik->ik_type) {
4493 case IEEE80211_CIPHER_WEP:
4495 LINE_CHECK("wepkey %u:%s", ik->ik_keyix+1,
4496 keylen <= 5 ? "40-bit" :
4497 keylen <= 13 ? "104-bit" : "128-bit");
4499 case IEEE80211_CIPHER_TKIP:
4501 keylen -= 128/8; /* ignore MIC for now */
4502 LINE_CHECK("TKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4504 case IEEE80211_CIPHER_AES_OCB:
4505 LINE_CHECK("AES-OCB %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4507 case IEEE80211_CIPHER_AES_CCM:
4508 LINE_CHECK("AES-CCM %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4510 case IEEE80211_CIPHER_CKIP:
4511 LINE_CHECK("CKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4513 case IEEE80211_CIPHER_NONE:
4514 LINE_CHECK("NULL %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4517 LINE_CHECK("UNKNOWN (0x%x) %u:%u-bit",
4518 ik->ik_type, ik->ik_keyix+1, 8*keylen);
4521 if (printcontents) {
4525 for (i = 0; i < keylen; i++)
4526 printf("%02x", ik->ik_keydata[i]);
4528 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4529 (ik->ik_keyrsc != 0 || verbose))
4530 printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc);
4531 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4532 (ik->ik_keytsc != 0 || verbose))
4533 printf(" tsc %ju", (uintmax_t)ik->ik_keytsc);
4534 if (ik->ik_flags != 0 && verbose) {
4535 const char *sep = " ";
4537 if (ik->ik_flags & IEEE80211_KEY_XMIT)
4538 printf("%stx", sep), sep = "+";
4539 if (ik->ik_flags & IEEE80211_KEY_RECV)
4540 printf("%srx", sep), sep = "+";
4541 if (ik->ik_flags & IEEE80211_KEY_DEFAULT)
4542 printf("%sdef", sep), sep = "+";
4549 printrate(const char *tag, int v, int defrate, int defmcs)
4551 if ((v & IEEE80211_RATE_MCS) == 0) {
4554 LINE_CHECK("%s %d.5", tag, v/2);
4556 LINE_CHECK("%s %d", tag, v/2);
4560 LINE_CHECK("%s %d", tag, v &~ 0x80);
4565 getid(int s, int ix, void *data, size_t len, int *plen, int mesh)
4567 struct ieee80211req ireq;
4569 (void) memset(&ireq, 0, sizeof(ireq));
4570 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4571 ireq.i_type = (!mesh) ? IEEE80211_IOC_SSID : IEEE80211_IOC_MESH_ID;
4575 if (ioctl(s, SIOCG80211, &ireq) < 0)
4582 ieee80211_status(int s)
4584 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
4585 enum ieee80211_opmode opmode = get80211opmode(s);
4586 int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode;
4588 const struct ieee80211_channel *c;
4589 const struct ieee80211_roamparam *rp;
4590 const struct ieee80211_txparam *tp;
4592 if (getid(s, -1, data, sizeof(data), &len, 0) < 0) {
4593 /* If we can't get the SSID, this isn't an 802.11 device. */
4598 * Invalidate cached state so printing status for multiple
4599 * if's doesn't reuse the first interfaces' cached state.
4608 if (opmode == IEEE80211_M_MBSS) {
4610 getid(s, 0, data, sizeof(data), &len, 1);
4611 print_string(data, len);
4613 if (get80211val(s, IEEE80211_IOC_NUMSSIDS, &num) < 0)
4617 for (i = 0; i < num; i++) {
4618 if (getid(s, i, data, sizeof(data), &len, 0) >= 0 && len > 0) {
4619 printf(" %d:", i + 1);
4620 print_string(data, len);
4624 print_string(data, len);
4627 if (c->ic_freq != IEEE80211_CHAN_ANY) {
4629 printf(" channel %d (%u MHz%s)", c->ic_ieee, c->ic_freq,
4630 get_chaninfo(c, 1, buf, sizeof(buf)));
4632 printf(" channel UNDEF");
4634 if (get80211(s, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 &&
4635 (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose))
4636 printf(" bssid %s", ether_ntoa((struct ether_addr *)data));
4638 if (get80211len(s, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) {
4639 printf("\n\tstationname ");
4640 print_string(data, len);
4643 spacer = ' '; /* force first break */
4646 list_regdomain(s, 0);
4649 if (get80211val(s, IEEE80211_IOC_AUTHMODE, &val) != -1) {
4651 case IEEE80211_AUTH_NONE:
4652 LINE_CHECK("authmode NONE");
4654 case IEEE80211_AUTH_OPEN:
4655 LINE_CHECK("authmode OPEN");
4657 case IEEE80211_AUTH_SHARED:
4658 LINE_CHECK("authmode SHARED");
4660 case IEEE80211_AUTH_8021X:
4661 LINE_CHECK("authmode 802.1x");
4663 case IEEE80211_AUTH_WPA:
4664 if (get80211val(s, IEEE80211_IOC_WPA, &wpa) < 0)
4665 wpa = 1; /* default to WPA1 */
4668 LINE_CHECK("authmode WPA2/802.11i");
4671 LINE_CHECK("authmode WPA1+WPA2/802.11i");
4674 LINE_CHECK("authmode WPA");
4678 case IEEE80211_AUTH_AUTO:
4679 LINE_CHECK("authmode AUTO");
4682 LINE_CHECK("authmode UNKNOWN (0x%x)", val);
4687 if (wpa || verbose) {
4688 if (get80211val(s, IEEE80211_IOC_WPS, &val) != -1) {
4694 if (get80211val(s, IEEE80211_IOC_TSN, &val) != -1) {
4700 if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) {
4702 LINE_CHECK("countermeasures");
4704 LINE_CHECK("-countermeasures");
4707 /* XXX not interesting with WPA done in user space */
4708 ireq.i_type = IEEE80211_IOC_KEYMGTALGS;
4709 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4712 ireq.i_type = IEEE80211_IOC_MCASTCIPHER;
4713 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4714 LINE_CHECK("mcastcipher ");
4715 printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN);
4719 ireq.i_type = IEEE80211_IOC_UCASTCIPHER;
4720 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4721 LINE_CHECK("ucastcipher ");
4722 printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN);
4726 ireq.i_type = IEEE80211_IOC_RSNCAPS;
4727 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4728 LINE_CHECK("RSN caps 0x%x", ireq.i_val);
4733 ireq.i_type = IEEE80211_IOC_UCASTCIPHERS;
4734 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4739 if (get80211val(s, IEEE80211_IOC_WEP, &wepmode) != -1 &&
4740 wepmode != IEEE80211_WEP_NOSUP) {
4743 case IEEE80211_WEP_OFF:
4744 LINE_CHECK("privacy OFF");
4746 case IEEE80211_WEP_ON:
4747 LINE_CHECK("privacy ON");
4749 case IEEE80211_WEP_MIXED:
4750 LINE_CHECK("privacy MIXED");
4753 LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode);
4758 * If we get here then we've got WEP support so we need
4759 * to print WEP status.
4762 if (get80211val(s, IEEE80211_IOC_WEPTXKEY, &val) < 0) {
4763 warn("WEP support, but no tx key!");
4767 LINE_CHECK("deftxkey %d", val+1);
4768 else if (wepmode != IEEE80211_WEP_OFF || verbose)
4769 LINE_CHECK("deftxkey UNDEF");
4771 if (get80211val(s, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) {
4772 warn("WEP support, but no NUMWEPKEYS support!");
4776 for (i = 0; i < num; i++) {
4777 struct ieee80211req_key ik;
4779 memset(&ik, 0, sizeof(ik));
4781 if (get80211(s, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) {
4782 warn("WEP support, but can get keys!");
4785 if (ik.ik_keylen != 0) {
4795 if (get80211val(s, IEEE80211_IOC_POWERSAVE, &val) != -1 &&
4796 val != IEEE80211_POWERSAVE_NOSUP ) {
4797 if (val != IEEE80211_POWERSAVE_OFF || verbose) {
4799 case IEEE80211_POWERSAVE_OFF:
4800 LINE_CHECK("powersavemode OFF");
4802 case IEEE80211_POWERSAVE_CAM:
4803 LINE_CHECK("powersavemode CAM");
4805 case IEEE80211_POWERSAVE_PSP:
4806 LINE_CHECK("powersavemode PSP");
4808 case IEEE80211_POWERSAVE_PSP_CAM:
4809 LINE_CHECK("powersavemode PSP-CAM");
4812 if (get80211val(s, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1)
4813 LINE_CHECK("powersavesleep %d", val);
4817 if (get80211val(s, IEEE80211_IOC_TXPOWER, &val) != -1) {
4819 LINE_CHECK("txpower %d.5", val/2);
4821 LINE_CHECK("txpower %d", val/2);
4824 if (get80211val(s, IEEE80211_IOC_TXPOWMAX, &val) != -1)
4825 LINE_CHECK("txpowmax %.1f", val/2.);
4828 if (get80211val(s, IEEE80211_IOC_DOTD, &val) != -1) {
4832 LINE_CHECK("-dotd");
4835 if (get80211val(s, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) {
4836 if (val != IEEE80211_RTS_MAX || verbose)
4837 LINE_CHECK("rtsthreshold %d", val);
4840 if (get80211val(s, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) {
4841 if (val != IEEE80211_FRAG_MAX || verbose)
4842 LINE_CHECK("fragthreshold %d", val);
4844 if (opmode == IEEE80211_M_STA || verbose) {
4845 if (get80211val(s, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) {
4846 if (val != IEEE80211_HWBMISS_MAX || verbose)
4847 LINE_CHECK("bmiss %d", val);
4853 tp = &txparams.params[chan2mode(c)];
4854 printrate("ucastrate", tp->ucastrate,
4855 IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE);
4856 printrate("mcastrate", tp->mcastrate, 2*1,
4857 IEEE80211_RATE_MCS|0);
4858 printrate("mgmtrate", tp->mgmtrate, 2*1,
4859 IEEE80211_RATE_MCS|0);
4860 if (tp->maxretry != 6) /* XXX */
4861 LINE_CHECK("maxretry %d", tp->maxretry);
4867 bgscaninterval = -1;
4868 (void) get80211val(s, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval);
4870 if (get80211val(s, IEEE80211_IOC_SCANVALID, &val) != -1) {
4871 if (val != bgscaninterval || verbose)
4872 LINE_CHECK("scanvalid %u", val);
4876 if (get80211val(s, IEEE80211_IOC_BGSCAN, &bgscan) != -1) {
4878 LINE_CHECK("bgscan");
4880 LINE_CHECK("-bgscan");
4882 if (bgscan || verbose) {
4883 if (bgscaninterval != -1)
4884 LINE_CHECK("bgscanintvl %u", bgscaninterval);
4885 if (get80211val(s, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1)
4886 LINE_CHECK("bgscanidle %u", val);
4889 rp = &roamparams.params[chan2mode(c)];
4891 LINE_CHECK("roam:rssi %u.5", rp->rssi/2);
4893 LINE_CHECK("roam:rssi %u", rp->rssi/2);
4894 LINE_CHECK("roam:rate %u", rp->rate/2);
4902 if (IEEE80211_IS_CHAN_ANYG(c) || verbose) {
4903 if (get80211val(s, IEEE80211_IOC_PUREG, &val) != -1) {
4905 LINE_CHECK("pureg");
4907 LINE_CHECK("-pureg");
4909 if (get80211val(s, IEEE80211_IOC_PROTMODE, &val) != -1) {
4911 case IEEE80211_PROTMODE_OFF:
4912 LINE_CHECK("protmode OFF");
4914 case IEEE80211_PROTMODE_CTS:
4915 LINE_CHECK("protmode CTS");
4917 case IEEE80211_PROTMODE_RTSCTS:
4918 LINE_CHECK("protmode RTSCTS");
4921 LINE_CHECK("protmode UNKNOWN (0x%x)", val);
4927 if (IEEE80211_IS_CHAN_HT(c) || verbose) {
4929 switch (htconf & 3) {
4942 if (get80211val(s, IEEE80211_IOC_HTCOMPAT, &val) != -1) {
4944 LINE_CHECK("-htcompat");
4946 LINE_CHECK("htcompat");
4948 if (get80211val(s, IEEE80211_IOC_AMPDU, &val) != -1) {
4951 LINE_CHECK("-ampdu");
4954 LINE_CHECK("ampdutx -ampdurx");
4957 LINE_CHECK("-ampdutx ampdurx");
4961 LINE_CHECK("ampdu");
4965 /* XXX 11ac density/size is different */
4966 if (get80211val(s, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) {
4968 case IEEE80211_HTCAP_MAXRXAMPDU_8K:
4969 LINE_CHECK("ampdulimit 8k");
4971 case IEEE80211_HTCAP_MAXRXAMPDU_16K:
4972 LINE_CHECK("ampdulimit 16k");
4974 case IEEE80211_HTCAP_MAXRXAMPDU_32K:
4975 LINE_CHECK("ampdulimit 32k");
4977 case IEEE80211_HTCAP_MAXRXAMPDU_64K:
4978 LINE_CHECK("ampdulimit 64k");
4982 /* XXX 11ac density/size is different */
4983 if (get80211val(s, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) {
4985 case IEEE80211_HTCAP_MPDUDENSITY_NA:
4987 LINE_CHECK("ampdudensity NA");
4989 case IEEE80211_HTCAP_MPDUDENSITY_025:
4990 LINE_CHECK("ampdudensity .25");
4992 case IEEE80211_HTCAP_MPDUDENSITY_05:
4993 LINE_CHECK("ampdudensity .5");
4995 case IEEE80211_HTCAP_MPDUDENSITY_1:
4996 LINE_CHECK("ampdudensity 1");
4998 case IEEE80211_HTCAP_MPDUDENSITY_2:
4999 LINE_CHECK("ampdudensity 2");
5001 case IEEE80211_HTCAP_MPDUDENSITY_4:
5002 LINE_CHECK("ampdudensity 4");
5004 case IEEE80211_HTCAP_MPDUDENSITY_8:
5005 LINE_CHECK("ampdudensity 8");
5007 case IEEE80211_HTCAP_MPDUDENSITY_16:
5008 LINE_CHECK("ampdudensity 16");
5012 if (get80211val(s, IEEE80211_IOC_AMSDU, &val) != -1) {
5015 LINE_CHECK("-amsdu");
5018 LINE_CHECK("amsdutx -amsdurx");
5021 LINE_CHECK("-amsdutx amsdurx");
5025 LINE_CHECK("amsdu");
5029 /* XXX amsdu limit */
5030 if (get80211val(s, IEEE80211_IOC_SHORTGI, &val) != -1) {
5032 LINE_CHECK("shortgi");
5034 LINE_CHECK("-shortgi");
5036 if (get80211val(s, IEEE80211_IOC_HTPROTMODE, &val) != -1) {
5037 if (val == IEEE80211_PROTMODE_OFF)
5038 LINE_CHECK("htprotmode OFF");
5039 else if (val != IEEE80211_PROTMODE_RTSCTS)
5040 LINE_CHECK("htprotmode UNKNOWN (0x%x)", val);
5042 LINE_CHECK("htprotmode RTSCTS");
5044 if (get80211val(s, IEEE80211_IOC_PUREN, &val) != -1) {
5046 LINE_CHECK("puren");
5048 LINE_CHECK("-puren");
5050 if (get80211val(s, IEEE80211_IOC_SMPS, &val) != -1) {
5051 if (val == IEEE80211_HTCAP_SMPS_DYNAMIC)
5052 LINE_CHECK("smpsdyn");
5053 else if (val == IEEE80211_HTCAP_SMPS_ENA)
5056 LINE_CHECK("-smps");
5058 if (get80211val(s, IEEE80211_IOC_RIFS, &val) != -1) {
5062 LINE_CHECK("-rifs");
5066 if (get80211val(s, IEEE80211_IOC_STBC, &val) != -1) {
5069 LINE_CHECK("-stbc");
5072 LINE_CHECK("stbctx -stbcrx");
5075 LINE_CHECK("-stbctx stbcrx");
5083 if (get80211val(s, IEEE80211_IOC_LDPC, &val) != -1) {
5086 LINE_CHECK("-ldpc");
5089 LINE_CHECK("ldpctx -ldpcrx");
5092 LINE_CHECK("-ldpctx ldpcrx");
5102 if (IEEE80211_IS_CHAN_VHT(c) || verbose) {
5109 LINE_CHECK("vht40");
5111 LINE_CHECK("-vht40");
5113 LINE_CHECK("vht80");
5115 LINE_CHECK("-vht80");
5117 LINE_CHECK("vht80p80");
5119 LINE_CHECK("-vht80p80");
5121 LINE_CHECK("vht160");
5123 LINE_CHECK("-vht160");
5126 if (get80211val(s, IEEE80211_IOC_WME, &wme) != -1) {
5134 if (get80211val(s, IEEE80211_IOC_BURST, &val) != -1) {
5136 LINE_CHECK("burst");
5138 LINE_CHECK("-burst");
5141 if (get80211val(s, IEEE80211_IOC_FF, &val) != -1) {
5147 if (get80211val(s, IEEE80211_IOC_TURBOP, &val) != -1) {
5149 LINE_CHECK("dturbo");
5151 LINE_CHECK("-dturbo");
5153 if (get80211val(s, IEEE80211_IOC_DWDS, &val) != -1) {
5157 LINE_CHECK("-dwds");
5160 if (opmode == IEEE80211_M_HOSTAP) {
5161 if (get80211val(s, IEEE80211_IOC_HIDESSID, &val) != -1) {
5163 LINE_CHECK("hidessid");
5165 LINE_CHECK("-hidessid");
5167 if (get80211val(s, IEEE80211_IOC_APBRIDGE, &val) != -1) {
5169 LINE_CHECK("-apbridge");
5171 LINE_CHECK("apbridge");
5173 if (get80211val(s, IEEE80211_IOC_DTIM_PERIOD, &val) != -1)
5174 LINE_CHECK("dtimperiod %u", val);
5176 if (get80211val(s, IEEE80211_IOC_DOTH, &val) != -1) {
5178 LINE_CHECK("-doth");
5182 if (get80211val(s, IEEE80211_IOC_DFS, &val) != -1) {
5188 if (get80211val(s, IEEE80211_IOC_INACTIVITY, &val) != -1) {
5190 LINE_CHECK("-inact");
5192 LINE_CHECK("inact");
5195 if (get80211val(s, IEEE80211_IOC_ROAMING, &val) != -1) {
5196 if (val != IEEE80211_ROAMING_AUTO || verbose) {
5198 case IEEE80211_ROAMING_DEVICE:
5199 LINE_CHECK("roaming DEVICE");
5201 case IEEE80211_ROAMING_AUTO:
5202 LINE_CHECK("roaming AUTO");
5204 case IEEE80211_ROAMING_MANUAL:
5205 LINE_CHECK("roaming MANUAL");
5208 LINE_CHECK("roaming UNKNOWN (0x%x)",
5216 if (opmode == IEEE80211_M_AHDEMO) {
5217 if (get80211val(s, IEEE80211_IOC_TDMA_SLOT, &val) != -1)
5218 LINE_CHECK("tdmaslot %u", val);
5219 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1)
5220 LINE_CHECK("tdmaslotcnt %u", val);
5221 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1)
5222 LINE_CHECK("tdmaslotlen %u", val);
5223 if (get80211val(s, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1)
5224 LINE_CHECK("tdmabintval %u", val);
5225 } else if (get80211val(s, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) {
5226 /* XXX default define not visible */
5227 if (val != 100 || verbose)
5228 LINE_CHECK("bintval %u", val);
5231 if (wme && verbose) {
5236 if (opmode == IEEE80211_M_MBSS) {
5237 if (get80211val(s, IEEE80211_IOC_MESH_TTL, &val) != -1) {
5238 LINE_CHECK("meshttl %u", val);
5240 if (get80211val(s, IEEE80211_IOC_MESH_AP, &val) != -1) {
5242 LINE_CHECK("meshpeering");
5244 LINE_CHECK("-meshpeering");
5246 if (get80211val(s, IEEE80211_IOC_MESH_FWRD, &val) != -1) {
5248 LINE_CHECK("meshforward");
5250 LINE_CHECK("-meshforward");
5252 if (get80211val(s, IEEE80211_IOC_MESH_GATE, &val) != -1) {
5254 LINE_CHECK("meshgate");
5256 LINE_CHECK("-meshgate");
5258 if (get80211len(s, IEEE80211_IOC_MESH_PR_METRIC, data, 12,
5261 LINE_CHECK("meshmetric %s", data);
5263 if (get80211len(s, IEEE80211_IOC_MESH_PR_PATH, data, 12,
5266 LINE_CHECK("meshpath %s", data);
5268 if (get80211val(s, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) {
5270 case IEEE80211_HWMP_ROOTMODE_DISABLED:
5271 LINE_CHECK("hwmprootmode DISABLED");
5273 case IEEE80211_HWMP_ROOTMODE_NORMAL:
5274 LINE_CHECK("hwmprootmode NORMAL");
5276 case IEEE80211_HWMP_ROOTMODE_PROACTIVE:
5277 LINE_CHECK("hwmprootmode PROACTIVE");
5279 case IEEE80211_HWMP_ROOTMODE_RANN:
5280 LINE_CHECK("hwmprootmode RANN");
5283 LINE_CHECK("hwmprootmode UNKNOWN(%d)", val);
5287 if (get80211val(s, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) {
5288 LINE_CHECK("hwmpmaxhops %u", val);
5296 get80211(int s, int type, void *data, int len)
5299 return (lib80211_get80211(s, name, type, data, len));
5303 get80211len(int s, int type, void *data, int len, int *plen)
5306 return (lib80211_get80211len(s, name, type, data, len, plen));
5310 get80211val(int s, int type, int *val)
5313 return (lib80211_get80211val(s, name, type, val));
5317 set80211(int s, int type, int val, int len, void *data)
5321 ret = lib80211_set80211(s, name, type, val, len, data);
5323 err(1, "SIOCS80211");
5327 get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
5335 hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x');
5341 if (sep != NULL && strchr(sep, *val) != NULL) {
5346 if (!isxdigit((u_char)val[0])) {
5347 warnx("bad hexadecimal digits");
5350 if (!isxdigit((u_char)val[1])) {
5351 warnx("odd count hexadecimal digits");
5355 if (p >= buf + len) {
5357 warnx("hexadecimal digits too long");
5359 warnx("string too long");
5363 #define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
5364 *p++ = (tohex((u_char)val[0]) << 4) |
5365 tohex((u_char)val[1]);
5372 /* The string "-" is treated as the empty string. */
5373 if (!hexstr && len == 1 && buf[0] == '-') {
5375 memset(buf, 0, *lenp);
5376 } else if (len < *lenp)
5377 memset(p, 0, *lenp - len);
5383 print_string(const u_int8_t *buf, int len)
5392 setlocale(LC_CTYPE, "");
5393 utf8 = strncmp("UTF-8", nl_langinfo(CODESET), 5) == 0;
5395 for (; i < len; i++) {
5396 if (!isprint(buf[i]) && buf[i] != '\0' && !utf8)
5398 if (isspace(buf[i]))
5401 if (i == len || utf8) {
5402 if (hasspc || len == 0 || buf[0] == '\0')
5403 printf("\"%.*s\"", len, buf);
5405 printf("%.*s", len, buf);
5408 for (i = 0; i < len; i++)
5409 printf("%02x", buf[i]);
5414 setdefregdomain(int s)
5416 struct regdata *rdp = getregdata();
5417 const struct regdomain *rd;
5419 /* Check if regdomain/country was already set by a previous call. */
5420 /* XXX is it possible? */
5421 if (regdomain.regdomain != 0 ||
5422 regdomain.country != CTRY_DEFAULT)
5427 /* Check if it was already set by the driver. */
5428 if (regdomain.regdomain != 0 ||
5429 regdomain.country != CTRY_DEFAULT)
5432 /* Set FCC/US as default. */
5433 rd = lib80211_regdomain_findbysku(rdp, SKU_FCC);
5435 errx(1, "FCC regdomain was not found");
5437 regdomain.regdomain = rd->sku;
5441 /* Send changes to net80211. */
5442 setregdomain_cb(s, ®domain);
5444 /* Cleanup (so it can be overriden by subsequent parameters). */
5445 regdomain.regdomain = 0;
5446 regdomain.country = CTRY_DEFAULT;
5447 regdomain.isocc[0] = 0;
5448 regdomain.isocc[1] = 0;
5452 * Virtual AP cloning support.
5454 static struct ieee80211_clone_params params = {
5455 .icp_opmode = IEEE80211_M_STA, /* default to station mode */
5459 wlan_create(int s, struct ifreq *ifr)
5461 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
5462 char orig_name[IFNAMSIZ];
5464 if (params.icp_parent[0] == '\0')
5465 errx(1, "must specify a parent device (wlandev) when creating "
5467 if (params.icp_opmode == IEEE80211_M_WDS &&
5468 memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0)
5469 errx(1, "no bssid specified for WDS (use wlanbssid)");
5470 ifr->ifr_data = (caddr_t) ¶ms;
5471 if (ioctl(s, SIOCIFCREATE2, ifr) < 0)
5472 err(1, "SIOCIFCREATE2");
5474 /* XXX preserve original name for ifclonecreate(). */
5475 strlcpy(orig_name, name, sizeof(orig_name));
5476 strlcpy(name, ifr->ifr_name, sizeof(name));
5480 strlcpy(name, orig_name, sizeof(name));
5484 DECL_CMD_FUNC(set80211clone_wlandev, arg, d)
5486 strlcpy(params.icp_parent, arg, IFNAMSIZ);
5490 DECL_CMD_FUNC(set80211clone_wlanbssid, arg, d)
5492 const struct ether_addr *ea;
5494 ea = ether_aton(arg);
5496 errx(1, "%s: cannot parse bssid", arg);
5497 memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN);
5501 DECL_CMD_FUNC(set80211clone_wlanaddr, arg, d)
5503 const struct ether_addr *ea;
5505 ea = ether_aton(arg);
5507 errx(1, "%s: cannot parse address", arg);
5508 memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN);
5509 params.icp_flags |= IEEE80211_CLONE_MACADDR;
5513 DECL_CMD_FUNC(set80211clone_wlanmode, arg, d)
5515 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
5516 if (iseq(arg, "sta"))
5517 params.icp_opmode = IEEE80211_M_STA;
5518 else if (iseq(arg, "ahdemo") || iseq(arg, "adhoc-demo"))
5519 params.icp_opmode = IEEE80211_M_AHDEMO;
5520 else if (iseq(arg, "ibss") || iseq(arg, "adhoc"))
5521 params.icp_opmode = IEEE80211_M_IBSS;
5522 else if (iseq(arg, "ap") || iseq(arg, "host"))
5523 params.icp_opmode = IEEE80211_M_HOSTAP;
5524 else if (iseq(arg, "wds"))
5525 params.icp_opmode = IEEE80211_M_WDS;
5526 else if (iseq(arg, "monitor"))
5527 params.icp_opmode = IEEE80211_M_MONITOR;
5528 else if (iseq(arg, "tdma")) {
5529 params.icp_opmode = IEEE80211_M_AHDEMO;
5530 params.icp_flags |= IEEE80211_CLONE_TDMA;
5531 } else if (iseq(arg, "mesh") || iseq(arg, "mp")) /* mesh point */
5532 params.icp_opmode = IEEE80211_M_MBSS;
5534 errx(1, "Don't know to create %s for %s", arg, name);
5539 set80211clone_beacons(const char *val, int d, int s, const struct afswtch *rafp)
5541 /* NB: inverted sense */
5543 params.icp_flags &= ~IEEE80211_CLONE_NOBEACONS;
5545 params.icp_flags |= IEEE80211_CLONE_NOBEACONS;
5549 set80211clone_bssid(const char *val, int d, int s, const struct afswtch *rafp)
5552 params.icp_flags |= IEEE80211_CLONE_BSSID;
5554 params.icp_flags &= ~IEEE80211_CLONE_BSSID;
5558 set80211clone_wdslegacy(const char *val, int d, int s, const struct afswtch *rafp)
5561 params.icp_flags |= IEEE80211_CLONE_WDSLEGACY;
5563 params.icp_flags &= ~IEEE80211_CLONE_WDSLEGACY;
5566 static struct cmd ieee80211_cmds[] = {
5567 DEF_CMD_ARG("ssid", set80211ssid),
5568 DEF_CMD_ARG("nwid", set80211ssid),
5569 DEF_CMD_ARG("meshid", set80211meshid),
5570 DEF_CMD_ARG("stationname", set80211stationname),
5571 DEF_CMD_ARG("station", set80211stationname), /* BSD/OS */
5572 DEF_CMD_ARG("channel", set80211channel),
5573 DEF_CMD_ARG("authmode", set80211authmode),
5574 DEF_CMD_ARG("powersavemode", set80211powersavemode),
5575 DEF_CMD("powersave", 1, set80211powersave),
5576 DEF_CMD("-powersave", 0, set80211powersave),
5577 DEF_CMD_ARG("powersavesleep", set80211powersavesleep),
5578 DEF_CMD_ARG("wepmode", set80211wepmode),
5579 DEF_CMD("wep", 1, set80211wep),
5580 DEF_CMD("-wep", 0, set80211wep),
5581 DEF_CMD_ARG("deftxkey", set80211weptxkey),
5582 DEF_CMD_ARG("weptxkey", set80211weptxkey),
5583 DEF_CMD_ARG("wepkey", set80211wepkey),
5584 DEF_CMD_ARG("nwkey", set80211nwkey), /* NetBSD */
5585 DEF_CMD("-nwkey", 0, set80211wep), /* NetBSD */
5586 DEF_CMD_ARG("rtsthreshold", set80211rtsthreshold),
5587 DEF_CMD_ARG("protmode", set80211protmode),
5588 DEF_CMD_ARG("txpower", set80211txpower),
5589 DEF_CMD_ARG("roaming", set80211roaming),
5590 DEF_CMD("wme", 1, set80211wme),
5591 DEF_CMD("-wme", 0, set80211wme),
5592 DEF_CMD("wmm", 1, set80211wme),
5593 DEF_CMD("-wmm", 0, set80211wme),
5594 DEF_CMD("hidessid", 1, set80211hidessid),
5595 DEF_CMD("-hidessid", 0, set80211hidessid),
5596 DEF_CMD("apbridge", 1, set80211apbridge),
5597 DEF_CMD("-apbridge", 0, set80211apbridge),
5598 DEF_CMD_ARG("chanlist", set80211chanlist),
5599 DEF_CMD_ARG("bssid", set80211bssid),
5600 DEF_CMD_ARG("ap", set80211bssid),
5601 DEF_CMD("scan", 0, set80211scan),
5602 DEF_CMD_ARG("list", set80211list),
5603 DEF_CMD_ARG2("cwmin", set80211cwmin),
5604 DEF_CMD_ARG2("cwmax", set80211cwmax),
5605 DEF_CMD_ARG2("aifs", set80211aifs),
5606 DEF_CMD_ARG2("txoplimit", set80211txoplimit),
5607 DEF_CMD_ARG("acm", set80211acm),
5608 DEF_CMD_ARG("-acm", set80211noacm),
5609 DEF_CMD_ARG("ack", set80211ackpolicy),
5610 DEF_CMD_ARG("-ack", set80211noackpolicy),
5611 DEF_CMD_ARG2("bss:cwmin", set80211bsscwmin),
5612 DEF_CMD_ARG2("bss:cwmax", set80211bsscwmax),
5613 DEF_CMD_ARG2("bss:aifs", set80211bssaifs),
5614 DEF_CMD_ARG2("bss:txoplimit", set80211bsstxoplimit),
5615 DEF_CMD_ARG("dtimperiod", set80211dtimperiod),
5616 DEF_CMD_ARG("bintval", set80211bintval),
5617 DEF_CMD("mac:open", IEEE80211_MACCMD_POLICY_OPEN, set80211maccmd),
5618 DEF_CMD("mac:allow", IEEE80211_MACCMD_POLICY_ALLOW, set80211maccmd),
5619 DEF_CMD("mac:deny", IEEE80211_MACCMD_POLICY_DENY, set80211maccmd),
5620 DEF_CMD("mac:radius", IEEE80211_MACCMD_POLICY_RADIUS, set80211maccmd),
5621 DEF_CMD("mac:flush", IEEE80211_MACCMD_FLUSH, set80211maccmd),
5622 DEF_CMD("mac:detach", IEEE80211_MACCMD_DETACH, set80211maccmd),
5623 DEF_CMD_ARG("mac:add", set80211addmac),
5624 DEF_CMD_ARG("mac:del", set80211delmac),
5625 DEF_CMD_ARG("mac:kick", set80211kickmac),
5626 DEF_CMD("pureg", 1, set80211pureg),
5627 DEF_CMD("-pureg", 0, set80211pureg),
5628 DEF_CMD("ff", 1, set80211fastframes),
5629 DEF_CMD("-ff", 0, set80211fastframes),
5630 DEF_CMD("dturbo", 1, set80211dturbo),
5631 DEF_CMD("-dturbo", 0, set80211dturbo),
5632 DEF_CMD("bgscan", 1, set80211bgscan),
5633 DEF_CMD("-bgscan", 0, set80211bgscan),
5634 DEF_CMD_ARG("bgscanidle", set80211bgscanidle),
5635 DEF_CMD_ARG("bgscanintvl", set80211bgscanintvl),
5636 DEF_CMD_ARG("scanvalid", set80211scanvalid),
5637 DEF_CMD("quiet", 1, set80211quiet),
5638 DEF_CMD("-quiet", 0, set80211quiet),
5639 DEF_CMD_ARG("quiet_count", set80211quietcount),
5640 DEF_CMD_ARG("quiet_period", set80211quietperiod),
5641 DEF_CMD_ARG("quiet_duration", set80211quietduration),
5642 DEF_CMD_ARG("quiet_offset", set80211quietoffset),
5643 DEF_CMD_ARG("roam:rssi", set80211roamrssi),
5644 DEF_CMD_ARG("roam:rate", set80211roamrate),
5645 DEF_CMD_ARG("mcastrate", set80211mcastrate),
5646 DEF_CMD_ARG("ucastrate", set80211ucastrate),
5647 DEF_CMD_ARG("mgtrate", set80211mgtrate),
5648 DEF_CMD_ARG("mgmtrate", set80211mgtrate),
5649 DEF_CMD_ARG("maxretry", set80211maxretry),
5650 DEF_CMD_ARG("fragthreshold", set80211fragthreshold),
5651 DEF_CMD("burst", 1, set80211burst),
5652 DEF_CMD("-burst", 0, set80211burst),
5653 DEF_CMD_ARG("bmiss", set80211bmissthreshold),
5654 DEF_CMD_ARG("bmissthreshold", set80211bmissthreshold),
5655 DEF_CMD("shortgi", 1, set80211shortgi),
5656 DEF_CMD("-shortgi", 0, set80211shortgi),
5657 DEF_CMD("ampdurx", 2, set80211ampdu),
5658 DEF_CMD("-ampdurx", -2, set80211ampdu),
5659 DEF_CMD("ampdutx", 1, set80211ampdu),
5660 DEF_CMD("-ampdutx", -1, set80211ampdu),
5661 DEF_CMD("ampdu", 3, set80211ampdu), /* NB: tx+rx */
5662 DEF_CMD("-ampdu", -3, set80211ampdu),
5663 DEF_CMD_ARG("ampdulimit", set80211ampdulimit),
5664 DEF_CMD_ARG("ampdudensity", set80211ampdudensity),
5665 DEF_CMD("amsdurx", 2, set80211amsdu),
5666 DEF_CMD("-amsdurx", -2, set80211amsdu),
5667 DEF_CMD("amsdutx", 1, set80211amsdu),
5668 DEF_CMD("-amsdutx", -1, set80211amsdu),
5669 DEF_CMD("amsdu", 3, set80211amsdu), /* NB: tx+rx */
5670 DEF_CMD("-amsdu", -3, set80211amsdu),
5671 DEF_CMD_ARG("amsdulimit", set80211amsdulimit),
5672 DEF_CMD("stbcrx", 2, set80211stbc),
5673 DEF_CMD("-stbcrx", -2, set80211stbc),
5674 DEF_CMD("stbctx", 1, set80211stbc),
5675 DEF_CMD("-stbctx", -1, set80211stbc),
5676 DEF_CMD("stbc", 3, set80211stbc), /* NB: tx+rx */
5677 DEF_CMD("-stbc", -3, set80211stbc),
5678 DEF_CMD("ldpcrx", 2, set80211ldpc),
5679 DEF_CMD("-ldpcrx", -2, set80211ldpc),
5680 DEF_CMD("ldpctx", 1, set80211ldpc),
5681 DEF_CMD("-ldpctx", -1, set80211ldpc),
5682 DEF_CMD("ldpc", 3, set80211ldpc), /* NB: tx+rx */
5683 DEF_CMD("-ldpc", -3, set80211ldpc),
5684 DEF_CMD("puren", 1, set80211puren),
5685 DEF_CMD("-puren", 0, set80211puren),
5686 DEF_CMD("doth", 1, set80211doth),
5687 DEF_CMD("-doth", 0, set80211doth),
5688 DEF_CMD("dfs", 1, set80211dfs),
5689 DEF_CMD("-dfs", 0, set80211dfs),
5690 DEF_CMD("htcompat", 1, set80211htcompat),
5691 DEF_CMD("-htcompat", 0, set80211htcompat),
5692 DEF_CMD("dwds", 1, set80211dwds),
5693 DEF_CMD("-dwds", 0, set80211dwds),
5694 DEF_CMD("inact", 1, set80211inact),
5695 DEF_CMD("-inact", 0, set80211inact),
5696 DEF_CMD("tsn", 1, set80211tsn),
5697 DEF_CMD("-tsn", 0, set80211tsn),
5698 DEF_CMD_ARG("regdomain", set80211regdomain),
5699 DEF_CMD_ARG("country", set80211country),
5700 DEF_CMD("indoor", 'I', set80211location),
5701 DEF_CMD("-indoor", 'O', set80211location),
5702 DEF_CMD("outdoor", 'O', set80211location),
5703 DEF_CMD("-outdoor", 'I', set80211location),
5704 DEF_CMD("anywhere", ' ', set80211location),
5705 DEF_CMD("ecm", 1, set80211ecm),
5706 DEF_CMD("-ecm", 0, set80211ecm),
5707 DEF_CMD("dotd", 1, set80211dotd),
5708 DEF_CMD("-dotd", 0, set80211dotd),
5709 DEF_CMD_ARG("htprotmode", set80211htprotmode),
5710 DEF_CMD("ht20", 1, set80211htconf),
5711 DEF_CMD("-ht20", 0, set80211htconf),
5712 DEF_CMD("ht40", 3, set80211htconf), /* NB: 20+40 */
5713 DEF_CMD("-ht40", 0, set80211htconf),
5714 DEF_CMD("ht", 3, set80211htconf), /* NB: 20+40 */
5715 DEF_CMD("-ht", 0, set80211htconf),
5716 DEF_CMD("vht", 1, set80211vhtconf),
5717 DEF_CMD("-vht", 0, set80211vhtconf),
5718 DEF_CMD("vht40", 2, set80211vhtconf),
5719 DEF_CMD("-vht40", -2, set80211vhtconf),
5720 DEF_CMD("vht80", 4, set80211vhtconf),
5721 DEF_CMD("-vht80", -4, set80211vhtconf),
5722 DEF_CMD("vht80p80", 8, set80211vhtconf),
5723 DEF_CMD("-vht80p80", -8, set80211vhtconf),
5724 DEF_CMD("vht160", 16, set80211vhtconf),
5725 DEF_CMD("-vht160", -16, set80211vhtconf),
5726 DEF_CMD("rifs", 1, set80211rifs),
5727 DEF_CMD("-rifs", 0, set80211rifs),
5728 DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA, set80211smps),
5729 DEF_CMD("smpsdyn", IEEE80211_HTCAP_SMPS_DYNAMIC, set80211smps),
5730 DEF_CMD("-smps", IEEE80211_HTCAP_SMPS_OFF, set80211smps),
5731 /* XXX for testing */
5732 DEF_CMD_ARG("chanswitch", set80211chanswitch),
5734 DEF_CMD_ARG("tdmaslot", set80211tdmaslot),
5735 DEF_CMD_ARG("tdmaslotcnt", set80211tdmaslotcnt),
5736 DEF_CMD_ARG("tdmaslotlen", set80211tdmaslotlen),
5737 DEF_CMD_ARG("tdmabintval", set80211tdmabintval),
5739 DEF_CMD_ARG("meshttl", set80211meshttl),
5740 DEF_CMD("meshforward", 1, set80211meshforward),
5741 DEF_CMD("-meshforward", 0, set80211meshforward),
5742 DEF_CMD("meshgate", 1, set80211meshgate),
5743 DEF_CMD("-meshgate", 0, set80211meshgate),
5744 DEF_CMD("meshpeering", 1, set80211meshpeering),
5745 DEF_CMD("-meshpeering", 0, set80211meshpeering),
5746 DEF_CMD_ARG("meshmetric", set80211meshmetric),
5747 DEF_CMD_ARG("meshpath", set80211meshpath),
5748 DEF_CMD("meshrt:flush", IEEE80211_MESH_RTCMD_FLUSH, set80211meshrtcmd),
5749 DEF_CMD_ARG("meshrt:add", set80211addmeshrt),
5750 DEF_CMD_ARG("meshrt:del", set80211delmeshrt),
5751 DEF_CMD_ARG("hwmprootmode", set80211hwmprootmode),
5752 DEF_CMD_ARG("hwmpmaxhops", set80211hwmpmaxhops),
5754 /* vap cloning support */
5755 DEF_CLONE_CMD_ARG("wlanaddr", set80211clone_wlanaddr),
5756 DEF_CLONE_CMD_ARG("wlanbssid", set80211clone_wlanbssid),
5757 DEF_CLONE_CMD_ARG("wlandev", set80211clone_wlandev),
5758 DEF_CLONE_CMD_ARG("wlanmode", set80211clone_wlanmode),
5759 DEF_CLONE_CMD("beacons", 1, set80211clone_beacons),
5760 DEF_CLONE_CMD("-beacons", 0, set80211clone_beacons),
5761 DEF_CLONE_CMD("bssid", 1, set80211clone_bssid),
5762 DEF_CLONE_CMD("-bssid", 0, set80211clone_bssid),
5763 DEF_CLONE_CMD("wdslegacy", 1, set80211clone_wdslegacy),
5764 DEF_CLONE_CMD("-wdslegacy", 0, set80211clone_wdslegacy),
5766 static struct afswtch af_ieee80211 = {
5767 .af_name = "af_ieee80211",
5769 .af_other_status = ieee80211_status,
5772 static __constructor void
5773 ieee80211_ctor(void)
5777 for (i = 0; i < nitems(ieee80211_cmds); i++)
5778 cmd_register(&ieee80211_cmds[i]);
5779 af_register(&af_ieee80211);
5780 clone_setdefcallback("wlan", wlan_create);