2 * Copyright 2001 The Aerospace Corporation. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of The Aerospace Corporation may not be used to endorse or
13 * promote products derived from this software.
15 * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
32 * All rights reserved.
34 * This code is derived from software contributed to The NetBSD Foundation
35 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
36 * NASA Ames Research Center.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
47 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
48 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
49 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
51 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57 * POSSIBILITY OF SUCH DAMAGE.
60 #include <sys/param.h>
61 #include <sys/ioctl.h>
62 #include <sys/socket.h>
63 #include <sys/sysctl.h>
66 #include <net/ethernet.h>
68 #include <net/if_dl.h>
69 #include <net/if_types.h>
70 #include <net/if_media.h>
71 #include <net/route.h>
73 #include <net80211/ieee80211_ioctl.h>
74 #include <net80211/ieee80211_freebsd.h>
75 #include <net80211/ieee80211_superg.h>
76 #include <net80211/ieee80211_tdma.h>
77 #include <net80211/ieee80211_mesh.h>
90 #include <stddef.h> /* NB: for offsetof */
94 #include <lib80211/lib80211_regdomain.h>
95 #include <lib80211/lib80211_ioctl.h>
97 #ifndef IEEE80211_FIXED_RATE_NONE
98 #define IEEE80211_FIXED_RATE_NONE 0xff
101 /* XXX need these publicly defined or similar */
102 #ifndef IEEE80211_NODE_AUTH
103 #define IEEE80211_NODE_AUTH 0x000001 /* authorized for data */
104 #define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */
105 #define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */
106 #define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */
107 #define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */
108 #define IEEE80211_NODE_HT 0x000040 /* HT enabled */
109 #define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */
110 #define IEEE80211_NODE_WPS 0x000100 /* WPS association */
111 #define IEEE80211_NODE_TSN 0x000200 /* TSN association */
112 #define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */
113 #define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */
114 #define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */
115 #define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */
116 #define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */
117 #define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */
118 #define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */
119 #define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */
120 #define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */
121 #define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */
122 #define IEEE80211_NODE_VHT 0x100000 /* VHT enabled */
125 #define MAXCHAN 1536 /* max 1.5K channels */
131 static void LINE_INIT(char c);
132 static void LINE_BREAK(void);
133 static void LINE_CHECK(const char *fmt, ...);
135 static const char *modename[IEEE80211_MODE_MAX] = {
136 [IEEE80211_MODE_AUTO] = "auto",
137 [IEEE80211_MODE_11A] = "11a",
138 [IEEE80211_MODE_11B] = "11b",
139 [IEEE80211_MODE_11G] = "11g",
140 [IEEE80211_MODE_FH] = "fh",
141 [IEEE80211_MODE_TURBO_A] = "turboA",
142 [IEEE80211_MODE_TURBO_G] = "turboG",
143 [IEEE80211_MODE_STURBO_A] = "sturbo",
144 [IEEE80211_MODE_11NA] = "11na",
145 [IEEE80211_MODE_11NG] = "11ng",
146 [IEEE80211_MODE_HALF] = "half",
147 [IEEE80211_MODE_QUARTER] = "quarter",
148 [IEEE80211_MODE_VHT_2GHZ] = "11acg",
149 [IEEE80211_MODE_VHT_5GHZ] = "11ac",
152 static void set80211(int s, int type, int val, int len, void *data);
153 static int get80211(int s, int type, void *data, int len);
154 static int get80211len(int s, int type, void *data, int len, int *plen);
155 static int get80211val(int s, int type, int *val);
156 static const char *get_string(const char *val, const char *sep,
157 u_int8_t *buf, int *lenp);
158 static void print_string(const u_int8_t *buf, int len);
159 static void print_regdomain(const struct ieee80211_regdomain *, int);
160 static void print_channels(int, const struct ieee80211req_chaninfo *,
161 int allchans, int verbose);
162 static void regdomain_makechannels(struct ieee80211_regdomain_req *,
163 const struct ieee80211_devcaps_req *);
164 static const char *mesh_linkstate_string(uint8_t state);
166 static struct ieee80211req_chaninfo *chaninfo;
167 static struct ieee80211_regdomain regdomain;
168 static int gotregdomain = 0;
169 static struct ieee80211_roamparams_req roamparams;
170 static int gotroam = 0;
171 static struct ieee80211_txparams_req txparams;
172 static int gottxparams = 0;
173 static struct ieee80211_channel curchan;
174 static int gotcurchan = 0;
175 static struct ifmediareq *ifmr;
176 static int htconf = 0;
177 static int gothtconf = 0;
184 if (get80211val(s, IEEE80211_IOC_HTCONF, &htconf) < 0)
185 warn("unable to get HT configuration information");
190 static int vhtconf = 0;
191 static int gotvhtconf = 0;
198 if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
199 warn("unable to get VHT configuration information");
204 * Collect channel info from the kernel. We use this (mostly)
205 * to handle mapping between frequency and IEEE channel number.
210 if (chaninfo != NULL)
212 chaninfo = malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN));
213 if (chaninfo == NULL)
214 errx(1, "no space for channel list");
215 if (get80211(s, IEEE80211_IOC_CHANINFO, chaninfo,
216 IEEE80211_CHANINFO_SIZE(MAXCHAN)) < 0)
217 err(1, "unable to get channel information");
218 ifmr = ifmedia_getstate(s);
223 static struct regdata *
226 static struct regdata *rdp = NULL;
228 rdp = lib80211_alloc_regdata();
230 errx(-1, "missing or corrupted regdomain database");
236 * Given the channel at index i with attributes from,
237 * check if there is a channel with attributes to in
238 * the channel table. With suitable attributes this
239 * allows the caller to look for promotion; e.g. from
243 canpromote(int i, int from, int to)
245 const struct ieee80211_channel *fc = &chaninfo->ic_chans[i];
248 if ((fc->ic_flags & from) != from)
250 /* NB: quick check exploiting ordering of chans w/ same frequency */
251 if (i+1 < chaninfo->ic_nchans &&
252 chaninfo->ic_chans[i+1].ic_freq == fc->ic_freq &&
253 (chaninfo->ic_chans[i+1].ic_flags & to) == to)
255 /* brute force search in case channel list is not ordered */
256 for (j = 0; j < chaninfo->ic_nchans; j++) {
257 const struct ieee80211_channel *tc = &chaninfo->ic_chans[j];
259 tc->ic_freq == fc->ic_freq && (tc->ic_flags & to) == to)
266 * Handle channel promotion. When a channel is specified with
267 * only a frequency we want to promote it to the ``best'' channel
268 * available. The channel list has separate entries for 11b, 11g,
269 * 11a, and 11n[ga] channels so specifying a frequency w/o any
270 * attributes requires we upgrade, e.g. from 11b -> 11g. This
271 * gets complicated when the channel is specified on the same
272 * command line with a media request that constrains the available
273 * channe list (e.g. mode 11a); we want to honor that to avoid
274 * confusing behaviour.
283 * Query the current mode of the interface in case it's
284 * constrained (e.g. to 11a). We must do this carefully
285 * as there may be a pending ifmedia request in which case
286 * asking the kernel will give us the wrong answer. This
287 * is an unfortunate side-effect of the way ifconfig is
288 * structure for modularity (yech).
290 * NB: ifmr is actually setup in getchaninfo (above); we
291 * assume it's called coincident with to this call so
292 * we have a ``current setting''; otherwise we must pass
293 * the socket descriptor down to here so we can make
294 * the ifmedia_getstate call ourselves.
296 int chanmode = ifmr != NULL ? IFM_MODE(ifmr->ifm_current) : IFM_AUTO;
298 /* when ambiguous promote to ``best'' */
299 /* NB: we abitrarily pick HT40+ over HT40- */
300 if (chanmode != IFM_IEEE80211_11B)
301 i = canpromote(i, IEEE80211_CHAN_B, IEEE80211_CHAN_G);
302 if (chanmode != IFM_IEEE80211_11G && (htconf & 1)) {
303 i = canpromote(i, IEEE80211_CHAN_G,
304 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20);
306 i = canpromote(i, IEEE80211_CHAN_G,
307 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D);
308 i = canpromote(i, IEEE80211_CHAN_G,
309 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U);
312 if (chanmode != IFM_IEEE80211_11A && (htconf & 1)) {
313 i = canpromote(i, IEEE80211_CHAN_A,
314 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20);
316 i = canpromote(i, IEEE80211_CHAN_A,
317 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D);
318 i = canpromote(i, IEEE80211_CHAN_A,
319 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U);
326 mapfreq(struct ieee80211_channel *chan, int freq, int flags)
330 for (i = 0; i < chaninfo->ic_nchans; i++) {
331 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
333 if (c->ic_freq == freq && (c->ic_flags & flags) == flags) {
335 /* when ambiguous promote to ``best'' */
336 c = &chaninfo->ic_chans[promote(i)];
342 errx(1, "unknown/undefined frequency %u/0x%x", freq, flags);
346 mapchan(struct ieee80211_channel *chan, int ieee, int flags)
350 for (i = 0; i < chaninfo->ic_nchans; i++) {
351 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
353 if (c->ic_ieee == ieee && (c->ic_flags & flags) == flags) {
355 /* when ambiguous promote to ``best'' */
356 c = &chaninfo->ic_chans[promote(i)];
362 errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags);
365 static const struct ieee80211_channel *
370 if (get80211(s, IEEE80211_IOC_CURCHAN, &curchan, sizeof(curchan)) < 0) {
372 /* fall back to legacy ioctl */
373 if (get80211val(s, IEEE80211_IOC_CHANNEL, &val) < 0)
374 err(-1, "cannot figure out current channel");
376 mapchan(&curchan, val, 0);
382 static enum ieee80211_phymode
383 chan2mode(const struct ieee80211_channel *c)
385 if (IEEE80211_IS_CHAN_VHTA(c))
386 return IEEE80211_MODE_VHT_5GHZ;
387 if (IEEE80211_IS_CHAN_VHTG(c))
388 return IEEE80211_MODE_VHT_2GHZ;
389 if (IEEE80211_IS_CHAN_HTA(c))
390 return IEEE80211_MODE_11NA;
391 if (IEEE80211_IS_CHAN_HTG(c))
392 return IEEE80211_MODE_11NG;
393 if (IEEE80211_IS_CHAN_108A(c))
394 return IEEE80211_MODE_TURBO_A;
395 if (IEEE80211_IS_CHAN_108G(c))
396 return IEEE80211_MODE_TURBO_G;
397 if (IEEE80211_IS_CHAN_ST(c))
398 return IEEE80211_MODE_STURBO_A;
399 if (IEEE80211_IS_CHAN_FHSS(c))
400 return IEEE80211_MODE_FH;
401 if (IEEE80211_IS_CHAN_HALF(c))
402 return IEEE80211_MODE_HALF;
403 if (IEEE80211_IS_CHAN_QUARTER(c))
404 return IEEE80211_MODE_QUARTER;
405 if (IEEE80211_IS_CHAN_A(c))
406 return IEEE80211_MODE_11A;
407 if (IEEE80211_IS_CHAN_ANYG(c))
408 return IEEE80211_MODE_11G;
409 if (IEEE80211_IS_CHAN_B(c))
410 return IEEE80211_MODE_11B;
411 return IEEE80211_MODE_AUTO;
419 if (get80211(s, IEEE80211_IOC_ROAM,
420 &roamparams, sizeof(roamparams)) < 0)
421 err(1, "unable to get roaming parameters");
426 setroam_cb(int s, void *arg)
428 struct ieee80211_roamparams_req *roam = arg;
429 set80211(s, IEEE80211_IOC_ROAM, 0, sizeof(*roam), roam);
437 if (get80211(s, IEEE80211_IOC_TXPARAMS,
438 &txparams, sizeof(txparams)) < 0)
439 err(1, "unable to get transmit parameters");
444 settxparams_cb(int s, void *arg)
446 struct ieee80211_txparams_req *txp = arg;
447 set80211(s, IEEE80211_IOC_TXPARAMS, 0, sizeof(*txp), txp);
455 if (get80211(s, IEEE80211_IOC_REGDOMAIN,
456 ®domain, sizeof(regdomain)) < 0)
457 err(1, "unable to get regulatory domain info");
462 getdevcaps(int s, struct ieee80211_devcaps_req *dc)
464 if (get80211(s, IEEE80211_IOC_DEVCAPS, dc,
465 IEEE80211_DEVCAPS_SPACE(dc)) < 0)
466 err(1, "unable to get device capabilities");
470 setregdomain_cb(int s, void *arg)
472 struct ieee80211_regdomain_req *req;
473 struct ieee80211_regdomain *rd = arg;
474 struct ieee80211_devcaps_req *dc;
475 struct regdata *rdp = getregdata();
477 if (rd->country != NO_COUNTRY) {
478 const struct country *cc;
480 * Check current country seting to make sure it's
481 * compatible with the new regdomain. If not, then
482 * override it with any default country for this
483 * SKU. If we cannot arrange a match, then abort.
485 cc = lib80211_country_findbycc(rdp, rd->country);
487 errx(1, "unknown ISO country code %d", rd->country);
488 if (cc->rd->sku != rd->regdomain) {
489 const struct regdomain *rp;
491 * Check if country is incompatible with regdomain.
492 * To enable multiple regdomains for a country code
493 * we permit a mismatch between the regdomain and
494 * the country's associated regdomain when the
495 * regdomain is setup w/o a default country. For
496 * example, US is bound to the FCC regdomain but
497 * we allow US to be combined with FCC3 because FCC3
498 * has not default country. This allows bogus
499 * combinations like FCC3+DK which are resolved when
500 * constructing the channel list by deferring to the
501 * regdomain to construct the channel list.
503 rp = lib80211_regdomain_findbysku(rdp, rd->regdomain);
505 errx(1, "country %s (%s) is not usable with "
506 "regdomain %d", cc->isoname, cc->name,
508 else if (rp->cc != NULL && rp->cc != cc)
509 errx(1, "country %s (%s) is not usable with "
510 "regdomain %s", cc->isoname, cc->name,
515 * Fetch the device capabilities and calculate the
516 * full set of netbands for which we request a new
517 * channel list be constructed. Once that's done we
518 * push the regdomain info + channel list to the kernel.
520 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
522 errx(1, "no space for device capabilities");
523 dc->dc_chaninfo.ic_nchans = MAXCHAN;
527 printf("drivercaps: 0x%x\n", dc->dc_drivercaps);
528 printf("cryptocaps: 0x%x\n", dc->dc_cryptocaps);
529 printf("htcaps : 0x%x\n", dc->dc_htcaps);
530 printf("vhtcaps : 0x%x\n", dc->dc_vhtcaps);
532 memcpy(chaninfo, &dc->dc_chaninfo,
533 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
534 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, 1/*verbose*/);
538 req = malloc(IEEE80211_REGDOMAIN_SIZE(dc->dc_chaninfo.ic_nchans));
540 errx(1, "no space for regdomain request");
542 regdomain_makechannels(req, dc);
545 print_regdomain(rd, 1/*verbose*/);
547 /* blech, reallocate channel list for new data */
548 if (chaninfo != NULL)
550 chaninfo = malloc(IEEE80211_CHANINFO_SPACE(&req->chaninfo));
551 if (chaninfo == NULL)
552 errx(1, "no space for channel list");
553 memcpy(chaninfo, &req->chaninfo,
554 IEEE80211_CHANINFO_SPACE(&req->chaninfo));
555 print_channels(s, &req->chaninfo, 1/*allchans*/, 1/*verbose*/);
557 if (req->chaninfo.ic_nchans == 0)
558 errx(1, "no channels calculated");
559 set80211(s, IEEE80211_IOC_REGDOMAIN, 0,
560 IEEE80211_REGDOMAIN_SPACE(req), req);
566 ieee80211_mhz2ieee(int freq, int flags)
568 struct ieee80211_channel chan;
569 mapfreq(&chan, freq, flags);
574 isanyarg(const char *arg)
576 return (strncmp(arg, "-", 1) == 0 ||
577 strncasecmp(arg, "any", 3) == 0 || strncasecmp(arg, "off", 3) == 0);
581 set80211ssid(const char *val, int d, int s, const struct afswtch *rafp)
585 u_int8_t data[IEEE80211_NWID_LEN];
589 if (len > 2 && isdigit((int)val[0]) && val[1] == ':') {
594 bzero(data, sizeof(data));
596 if (get_string(val, NULL, data, &len) == NULL)
599 set80211(s, IEEE80211_IOC_SSID, ssid, len, data);
603 set80211meshid(const char *val, int d, int s, const struct afswtch *rafp)
606 u_int8_t data[IEEE80211_NWID_LEN];
608 memset(data, 0, sizeof(data));
610 if (get_string(val, NULL, data, &len) == NULL)
613 set80211(s, IEEE80211_IOC_MESH_ID, 0, len, data);
617 set80211stationname(const char *val, int d, int s, const struct afswtch *rafp)
622 bzero(data, sizeof(data));
624 get_string(val, NULL, data, &len);
626 set80211(s, IEEE80211_IOC_STATIONNAME, 0, len, data);
630 * Parse a channel specification for attributes/flags.
632 * freq/xx channel width (5,10,20,40,40+,40-)
633 * freq:mode channel mode (a,b,g,h,n,t,s,d)
635 * These can be combined in either order; e.g. 2437:ng/40.
636 * Modes are case insensitive.
638 * The result is not validated here; it's assumed to be
639 * checked against the channel table fetched from the kernel.
642 getchannelflags(const char *val, int freq)
644 #define _CHAN_HT 0x80000000
651 cp = strchr(val, ':');
653 for (cp++; isalpha((int) *cp); cp++) {
654 /* accept mixed case */
659 case 'a': /* 802.11a */
660 flags |= IEEE80211_CHAN_A;
662 case 'b': /* 802.11b */
663 flags |= IEEE80211_CHAN_B;
665 case 'g': /* 802.11g */
666 flags |= IEEE80211_CHAN_G;
668 case 'v': /* vht: 802.11ac */
671 case 'h': /* ht = 802.11n */
672 case 'n': /* 802.11n */
673 flags |= _CHAN_HT; /* NB: private */
675 case 'd': /* dt = Atheros Dynamic Turbo */
676 flags |= IEEE80211_CHAN_TURBO;
678 case 't': /* ht, dt, st, t */
679 /* dt and unadorned t specify Dynamic Turbo */
680 if ((flags & (IEEE80211_CHAN_STURBO|_CHAN_HT)) == 0)
681 flags |= IEEE80211_CHAN_TURBO;
683 case 's': /* st = Atheros Static Turbo */
684 flags |= IEEE80211_CHAN_STURBO;
687 errx(-1, "%s: Invalid channel attribute %c\n",
692 cp = strchr(val, '/');
695 u_long cw = strtoul(cp+1, &ep, 10);
699 flags |= IEEE80211_CHAN_QUARTER;
702 flags |= IEEE80211_CHAN_HALF;
705 /* NB: this may be removed below */
706 flags |= IEEE80211_CHAN_HT20;
711 /* Handle the 80/160 VHT flag */
713 flags |= IEEE80211_CHAN_VHT80;
715 flags |= IEEE80211_CHAN_VHT160;
718 if (ep != NULL && *ep == '+')
719 flags |= IEEE80211_CHAN_HT40U;
720 else if (ep != NULL && *ep == '-')
721 flags |= IEEE80211_CHAN_HT40D;
724 errx(-1, "%s: Invalid channel width\n", val);
729 * Cleanup specifications.
731 if ((flags & _CHAN_HT) == 0) {
733 * If user specified freq/20 or freq/40 quietly remove
734 * HT cw attributes depending on channel use. To give
735 * an explicit 20/40 width for an HT channel you must
736 * indicate it is an HT channel since all HT channels
737 * are also usable for legacy operation; e.g. freq:n/40.
739 flags &= ~IEEE80211_CHAN_HT;
740 flags &= ~IEEE80211_CHAN_VHT;
743 * Remove private indicator that this is an HT channel
744 * and if no explicit channel width has been given
745 * provide the default settings.
748 if ((flags & IEEE80211_CHAN_HT) == 0) {
749 struct ieee80211_channel chan;
751 * Consult the channel list to see if we can use
752 * HT40+ or HT40- (if both the map routines choose).
755 mapfreq(&chan, freq, 0);
757 mapchan(&chan, freq, 0);
758 flags |= (chan.ic_flags & IEEE80211_CHAN_HT);
762 * If VHT is enabled, then also set the VHT flag and the
763 * relevant channel up/down.
765 if (is_vht && (flags & IEEE80211_CHAN_HT)) {
767 * XXX yes, maybe we should just have VHT, and reuse
770 if (flags & IEEE80211_CHAN_VHT80)
772 else if (flags & IEEE80211_CHAN_HT20)
773 flags |= IEEE80211_CHAN_VHT20;
774 else if (flags & IEEE80211_CHAN_HT40U)
775 flags |= IEEE80211_CHAN_VHT40U;
776 else if (flags & IEEE80211_CHAN_HT40D)
777 flags |= IEEE80211_CHAN_VHT40D;
785 getchannel(int s, struct ieee80211_channel *chan, const char *val)
790 memset(chan, 0, sizeof(*chan));
792 chan->ic_freq = IEEE80211_CHAN_ANY;
797 v = strtol(val, &eptr, 10);
798 if (val[0] == '\0' || val == eptr || errno == ERANGE ||
799 /* channel may be suffixed with nothing, :flag, or /width */
800 (eptr[0] != '\0' && eptr[0] != ':' && eptr[0] != '/'))
801 errx(1, "invalid channel specification%s",
802 errno == ERANGE ? " (out of range)" : "");
803 flags = getchannelflags(val, v);
804 if (v > 255) { /* treat as frequency */
805 mapfreq(chan, v, flags);
807 mapchan(chan, v, flags);
812 set80211channel(const char *val, int d, int s, const struct afswtch *rafp)
814 struct ieee80211_channel chan;
816 getchannel(s, &chan, val);
817 set80211(s, IEEE80211_IOC_CURCHAN, 0, sizeof(chan), &chan);
821 set80211chanswitch(const char *val, int d, int s, const struct afswtch *rafp)
823 struct ieee80211_chanswitch_req csr;
825 getchannel(s, &csr.csa_chan, val);
828 set80211(s, IEEE80211_IOC_CHANSWITCH, 0, sizeof(csr), &csr);
832 set80211authmode(const char *val, int d, int s, const struct afswtch *rafp)
836 if (strcasecmp(val, "none") == 0) {
837 mode = IEEE80211_AUTH_NONE;
838 } else if (strcasecmp(val, "open") == 0) {
839 mode = IEEE80211_AUTH_OPEN;
840 } else if (strcasecmp(val, "shared") == 0) {
841 mode = IEEE80211_AUTH_SHARED;
842 } else if (strcasecmp(val, "8021x") == 0) {
843 mode = IEEE80211_AUTH_8021X;
844 } else if (strcasecmp(val, "wpa") == 0) {
845 mode = IEEE80211_AUTH_WPA;
847 errx(1, "unknown authmode");
850 set80211(s, IEEE80211_IOC_AUTHMODE, mode, 0, NULL);
854 set80211powersavemode(const char *val, int d, int s, const struct afswtch *rafp)
858 if (strcasecmp(val, "off") == 0) {
859 mode = IEEE80211_POWERSAVE_OFF;
860 } else if (strcasecmp(val, "on") == 0) {
861 mode = IEEE80211_POWERSAVE_ON;
862 } else if (strcasecmp(val, "cam") == 0) {
863 mode = IEEE80211_POWERSAVE_CAM;
864 } else if (strcasecmp(val, "psp") == 0) {
865 mode = IEEE80211_POWERSAVE_PSP;
866 } else if (strcasecmp(val, "psp-cam") == 0) {
867 mode = IEEE80211_POWERSAVE_PSP_CAM;
869 errx(1, "unknown powersavemode");
872 set80211(s, IEEE80211_IOC_POWERSAVE, mode, 0, NULL);
876 set80211powersave(const char *val, int d, int s, const struct afswtch *rafp)
879 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_OFF,
882 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_ON,
887 set80211powersavesleep(const char *val, int d, int s, const struct afswtch *rafp)
889 set80211(s, IEEE80211_IOC_POWERSAVESLEEP, atoi(val), 0, NULL);
893 set80211wepmode(const char *val, int d, int s, const struct afswtch *rafp)
897 if (strcasecmp(val, "off") == 0) {
898 mode = IEEE80211_WEP_OFF;
899 } else if (strcasecmp(val, "on") == 0) {
900 mode = IEEE80211_WEP_ON;
901 } else if (strcasecmp(val, "mixed") == 0) {
902 mode = IEEE80211_WEP_MIXED;
904 errx(1, "unknown wep mode");
907 set80211(s, IEEE80211_IOC_WEP, mode, 0, NULL);
911 set80211wep(const char *val, int d, int s, const struct afswtch *rafp)
913 set80211(s, IEEE80211_IOC_WEP, d, 0, NULL);
917 isundefarg(const char *arg)
919 return (strcmp(arg, "-") == 0 || strncasecmp(arg, "undef", 5) == 0);
923 set80211weptxkey(const char *val, int d, int s, const struct afswtch *rafp)
926 set80211(s, IEEE80211_IOC_WEPTXKEY, IEEE80211_KEYIX_NONE, 0, NULL);
928 set80211(s, IEEE80211_IOC_WEPTXKEY, atoi(val)-1, 0, NULL);
932 set80211wepkey(const char *val, int d, int s, const struct afswtch *rafp)
936 u_int8_t data[IEEE80211_KEYBUF_SIZE];
938 if (isdigit((int)val[0]) && val[1] == ':') {
943 bzero(data, sizeof(data));
945 get_string(val, NULL, data, &len);
947 set80211(s, IEEE80211_IOC_WEPKEY, key, len, data);
951 * This function is purely a NetBSD compatibility interface. The NetBSD
952 * interface is too inflexible, but it's there so we'll support it since
953 * it's not all that hard.
956 set80211nwkey(const char *val, int d, int s, const struct afswtch *rafp)
960 u_int8_t data[IEEE80211_KEYBUF_SIZE];
962 set80211(s, IEEE80211_IOC_WEP, IEEE80211_WEP_ON, 0, NULL);
964 if (isdigit((int)val[0]) && val[1] == ':') {
965 txkey = val[0]-'0'-1;
968 for (i = 0; i < 4; i++) {
969 bzero(data, sizeof(data));
971 val = get_string(val, ",", data, &len);
975 set80211(s, IEEE80211_IOC_WEPKEY, i, len, data);
978 bzero(data, sizeof(data));
980 get_string(val, NULL, data, &len);
983 set80211(s, IEEE80211_IOC_WEPKEY, 0, len, data);
985 bzero(data, sizeof(data));
986 for (i = 1; i < 4; i++)
987 set80211(s, IEEE80211_IOC_WEPKEY, i, 0, data);
990 set80211(s, IEEE80211_IOC_WEPTXKEY, txkey, 0, NULL);
994 set80211rtsthreshold(const char *val, int d, int s, const struct afswtch *rafp)
996 set80211(s, IEEE80211_IOC_RTSTHRESHOLD,
997 isundefarg(val) ? IEEE80211_RTS_MAX : atoi(val), 0, NULL);
1001 set80211protmode(const char *val, int d, int s, const struct afswtch *rafp)
1005 if (strcasecmp(val, "off") == 0) {
1006 mode = IEEE80211_PROTMODE_OFF;
1007 } else if (strcasecmp(val, "cts") == 0) {
1008 mode = IEEE80211_PROTMODE_CTS;
1009 } else if (strncasecmp(val, "rtscts", 3) == 0) {
1010 mode = IEEE80211_PROTMODE_RTSCTS;
1012 errx(1, "unknown protection mode");
1015 set80211(s, IEEE80211_IOC_PROTMODE, mode, 0, NULL);
1019 set80211htprotmode(const char *val, int d, int s, const struct afswtch *rafp)
1023 if (strcasecmp(val, "off") == 0) {
1024 mode = IEEE80211_PROTMODE_OFF;
1025 } else if (strncasecmp(val, "rts", 3) == 0) {
1026 mode = IEEE80211_PROTMODE_RTSCTS;
1028 errx(1, "unknown protection mode");
1031 set80211(s, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL);
1035 set80211txpower(const char *val, int d, int s, const struct afswtch *rafp)
1037 double v = atof(val);
1040 txpow = (int) (2*v);
1042 errx(-1, "invalid tx power (must be .5 dBm units)");
1043 set80211(s, IEEE80211_IOC_TXPOWER, txpow, 0, NULL);
1046 #define IEEE80211_ROAMING_DEVICE 0
1047 #define IEEE80211_ROAMING_AUTO 1
1048 #define IEEE80211_ROAMING_MANUAL 2
1051 set80211roaming(const char *val, int d, int s, const struct afswtch *rafp)
1055 if (strcasecmp(val, "device") == 0) {
1056 mode = IEEE80211_ROAMING_DEVICE;
1057 } else if (strcasecmp(val, "auto") == 0) {
1058 mode = IEEE80211_ROAMING_AUTO;
1059 } else if (strcasecmp(val, "manual") == 0) {
1060 mode = IEEE80211_ROAMING_MANUAL;
1062 errx(1, "unknown roaming mode");
1064 set80211(s, IEEE80211_IOC_ROAMING, mode, 0, NULL);
1068 set80211wme(const char *val, int d, int s, const struct afswtch *rafp)
1070 set80211(s, IEEE80211_IOC_WME, d, 0, NULL);
1074 set80211hidessid(const char *val, int d, int s, const struct afswtch *rafp)
1076 set80211(s, IEEE80211_IOC_HIDESSID, d, 0, NULL);
1080 set80211apbridge(const char *val, int d, int s, const struct afswtch *rafp)
1082 set80211(s, IEEE80211_IOC_APBRIDGE, d, 0, NULL);
1086 set80211fastframes(const char *val, int d, int s, const struct afswtch *rafp)
1088 set80211(s, IEEE80211_IOC_FF, d, 0, NULL);
1092 set80211dturbo(const char *val, int d, int s, const struct afswtch *rafp)
1094 set80211(s, IEEE80211_IOC_TURBOP, d, 0, NULL);
1098 set80211chanlist(const char *val, int d, int s, const struct afswtch *rafp)
1100 struct ieee80211req_chanlist chanlist;
1101 char *temp, *cp, *tp;
1103 temp = malloc(strlen(val) + 1);
1105 errx(1, "malloc failed");
1107 memset(&chanlist, 0, sizeof(chanlist));
1110 int first, last, f, c;
1112 tp = strchr(cp, ',');
1115 switch (sscanf(cp, "%u-%u", &first, &last)) {
1117 if (first > IEEE80211_CHAN_MAX)
1118 errx(-1, "channel %u out of range, max %u",
1119 first, IEEE80211_CHAN_MAX);
1120 setbit(chanlist.ic_channels, first);
1123 if (first > IEEE80211_CHAN_MAX)
1124 errx(-1, "channel %u out of range, max %u",
1125 first, IEEE80211_CHAN_MAX);
1126 if (last > IEEE80211_CHAN_MAX)
1127 errx(-1, "channel %u out of range, max %u",
1128 last, IEEE80211_CHAN_MAX);
1130 errx(-1, "void channel range, %u > %u",
1132 for (f = first; f <= last; f++)
1133 setbit(chanlist.ic_channels, f);
1145 set80211(s, IEEE80211_IOC_CHANLIST, 0, sizeof(chanlist), &chanlist);
1149 set80211bssid(const char *val, int d, int s, const struct afswtch *rafp)
1152 if (!isanyarg(val)) {
1154 struct sockaddr_dl sdl;
1156 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1158 errx(1, "malloc failed");
1160 strcpy(temp + 1, val);
1161 sdl.sdl_len = sizeof(sdl);
1162 link_addr(temp, &sdl);
1164 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1165 errx(1, "malformed link-level address");
1166 set80211(s, IEEE80211_IOC_BSSID, 0,
1167 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1169 uint8_t zerobssid[IEEE80211_ADDR_LEN];
1170 memset(zerobssid, 0, sizeof(zerobssid));
1171 set80211(s, IEEE80211_IOC_BSSID, 0,
1172 IEEE80211_ADDR_LEN, zerobssid);
1177 getac(const char *ac)
1179 if (strcasecmp(ac, "ac_be") == 0 || strcasecmp(ac, "be") == 0)
1181 if (strcasecmp(ac, "ac_bk") == 0 || strcasecmp(ac, "bk") == 0)
1183 if (strcasecmp(ac, "ac_vi") == 0 || strcasecmp(ac, "vi") == 0)
1185 if (strcasecmp(ac, "ac_vo") == 0 || strcasecmp(ac, "vo") == 0)
1187 errx(1, "unknown wme access class %s", ac);
1191 DECL_CMD_FUNC2(set80211cwmin, ac, val)
1193 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac), NULL);
1197 DECL_CMD_FUNC2(set80211cwmax, ac, val)
1199 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac), NULL);
1203 DECL_CMD_FUNC2(set80211aifs, ac, val)
1205 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac), NULL);
1209 DECL_CMD_FUNC2(set80211txoplimit, ac, val)
1211 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac), NULL);
1215 DECL_CMD_FUNC(set80211acm, ac, d)
1217 set80211(s, IEEE80211_IOC_WME_ACM, 1, getac(ac), NULL);
1220 DECL_CMD_FUNC(set80211noacm, ac, d)
1222 set80211(s, IEEE80211_IOC_WME_ACM, 0, getac(ac), NULL);
1226 DECL_CMD_FUNC(set80211ackpolicy, ac, d)
1228 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 1, getac(ac), NULL);
1231 DECL_CMD_FUNC(set80211noackpolicy, ac, d)
1233 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 0, getac(ac), NULL);
1237 DECL_CMD_FUNC2(set80211bsscwmin, ac, val)
1239 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val),
1240 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1244 DECL_CMD_FUNC2(set80211bsscwmax, ac, val)
1246 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val),
1247 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1251 DECL_CMD_FUNC2(set80211bssaifs, ac, val)
1253 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val),
1254 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1258 DECL_CMD_FUNC2(set80211bsstxoplimit, ac, val)
1260 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val),
1261 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1265 DECL_CMD_FUNC(set80211dtimperiod, val, d)
1267 set80211(s, IEEE80211_IOC_DTIM_PERIOD, atoi(val), 0, NULL);
1271 DECL_CMD_FUNC(set80211bintval, val, d)
1273 set80211(s, IEEE80211_IOC_BEACON_INTERVAL, atoi(val), 0, NULL);
1277 set80211macmac(int s, int op, const char *val)
1280 struct sockaddr_dl sdl;
1282 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1284 errx(1, "malloc failed");
1286 strcpy(temp + 1, val);
1287 sdl.sdl_len = sizeof(sdl);
1288 link_addr(temp, &sdl);
1290 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1291 errx(1, "malformed link-level address");
1292 set80211(s, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl));
1296 DECL_CMD_FUNC(set80211addmac, val, d)
1298 set80211macmac(s, IEEE80211_IOC_ADDMAC, val);
1302 DECL_CMD_FUNC(set80211delmac, val, d)
1304 set80211macmac(s, IEEE80211_IOC_DELMAC, val);
1308 DECL_CMD_FUNC(set80211kickmac, val, d)
1311 struct sockaddr_dl sdl;
1312 struct ieee80211req_mlme mlme;
1314 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1316 errx(1, "malloc failed");
1318 strcpy(temp + 1, val);
1319 sdl.sdl_len = sizeof(sdl);
1320 link_addr(temp, &sdl);
1322 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1323 errx(1, "malformed link-level address");
1324 memset(&mlme, 0, sizeof(mlme));
1325 mlme.im_op = IEEE80211_MLME_DEAUTH;
1326 mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE;
1327 memcpy(mlme.im_macaddr, LLADDR(&sdl), IEEE80211_ADDR_LEN);
1328 set80211(s, IEEE80211_IOC_MLME, 0, sizeof(mlme), &mlme);
1332 DECL_CMD_FUNC(set80211maccmd, val, d)
1334 set80211(s, IEEE80211_IOC_MACCMD, d, 0, NULL);
1338 set80211meshrtmac(int s, int req, const char *val)
1341 struct sockaddr_dl sdl;
1343 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1345 errx(1, "malloc failed");
1347 strcpy(temp + 1, val);
1348 sdl.sdl_len = sizeof(sdl);
1349 link_addr(temp, &sdl);
1351 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1352 errx(1, "malformed link-level address");
1353 set80211(s, IEEE80211_IOC_MESH_RTCMD, req,
1354 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1358 DECL_CMD_FUNC(set80211addmeshrt, val, d)
1360 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_ADD, val);
1364 DECL_CMD_FUNC(set80211delmeshrt, val, d)
1366 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_DELETE, val);
1370 DECL_CMD_FUNC(set80211meshrtcmd, val, d)
1372 set80211(s, IEEE80211_IOC_MESH_RTCMD, d, 0, NULL);
1376 DECL_CMD_FUNC(set80211hwmprootmode, val, d)
1380 if (strcasecmp(val, "normal") == 0)
1381 mode = IEEE80211_HWMP_ROOTMODE_NORMAL;
1382 else if (strcasecmp(val, "proactive") == 0)
1383 mode = IEEE80211_HWMP_ROOTMODE_PROACTIVE;
1384 else if (strcasecmp(val, "rann") == 0)
1385 mode = IEEE80211_HWMP_ROOTMODE_RANN;
1387 mode = IEEE80211_HWMP_ROOTMODE_DISABLED;
1388 set80211(s, IEEE80211_IOC_HWMP_ROOTMODE, mode, 0, NULL);
1392 DECL_CMD_FUNC(set80211hwmpmaxhops, val, d)
1394 set80211(s, IEEE80211_IOC_HWMP_MAXHOPS, atoi(val), 0, NULL);
1398 set80211pureg(const char *val, int d, int s, const struct afswtch *rafp)
1400 set80211(s, IEEE80211_IOC_PUREG, d, 0, NULL);
1404 set80211quiet(const char *val, int d, int s, const struct afswtch *rafp)
1406 set80211(s, IEEE80211_IOC_QUIET, d, 0, NULL);
1410 DECL_CMD_FUNC(set80211quietperiod, val, d)
1412 set80211(s, IEEE80211_IOC_QUIET_PERIOD, atoi(val), 0, NULL);
1416 DECL_CMD_FUNC(set80211quietcount, val, d)
1418 set80211(s, IEEE80211_IOC_QUIET_COUNT, atoi(val), 0, NULL);
1422 DECL_CMD_FUNC(set80211quietduration, val, d)
1424 set80211(s, IEEE80211_IOC_QUIET_DUR, atoi(val), 0, NULL);
1428 DECL_CMD_FUNC(set80211quietoffset, val, d)
1430 set80211(s, IEEE80211_IOC_QUIET_OFFSET, atoi(val), 0, NULL);
1434 set80211bgscan(const char *val, int d, int s, const struct afswtch *rafp)
1436 set80211(s, IEEE80211_IOC_BGSCAN, d, 0, NULL);
1440 DECL_CMD_FUNC(set80211bgscanidle, val, d)
1442 set80211(s, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL);
1446 DECL_CMD_FUNC(set80211bgscanintvl, val, d)
1448 set80211(s, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL);
1452 DECL_CMD_FUNC(set80211scanvalid, val, d)
1454 set80211(s, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL);
1458 * Parse an optional trailing specification of which netbands
1459 * to apply a parameter to. This is basically the same syntax
1460 * as used for channels but you can concatenate to specify
1461 * multiple. For example:
1462 * 14:abg apply to 11a, 11b, and 11g
1463 * 6:ht apply to 11na and 11ng
1464 * We don't make a big effort to catch silly things; this is
1465 * really a convenience mechanism.
1468 getmodeflags(const char *val)
1475 cp = strchr(val, ':');
1477 for (cp++; isalpha((int) *cp); cp++) {
1478 /* accept mixed case */
1483 case 'a': /* 802.11a */
1484 flags |= IEEE80211_CHAN_A;
1486 case 'b': /* 802.11b */
1487 flags |= IEEE80211_CHAN_B;
1489 case 'g': /* 802.11g */
1490 flags |= IEEE80211_CHAN_G;
1492 case 'n': /* 802.11n */
1493 flags |= IEEE80211_CHAN_HT;
1495 case 'd': /* dt = Atheros Dynamic Turbo */
1496 flags |= IEEE80211_CHAN_TURBO;
1498 case 't': /* ht, dt, st, t */
1499 /* dt and unadorned t specify Dynamic Turbo */
1500 if ((flags & (IEEE80211_CHAN_STURBO|IEEE80211_CHAN_HT)) == 0)
1501 flags |= IEEE80211_CHAN_TURBO;
1503 case 's': /* st = Atheros Static Turbo */
1504 flags |= IEEE80211_CHAN_STURBO;
1506 case 'h': /* 1/2-width channels */
1507 flags |= IEEE80211_CHAN_HALF;
1509 case 'q': /* 1/4-width channels */
1510 flags |= IEEE80211_CHAN_QUARTER;
1513 /* XXX set HT too? */
1514 flags |= IEEE80211_CHAN_VHT;
1517 errx(-1, "%s: Invalid mode attribute %c\n",
1525 #define IEEE80211_CHAN_HTA (IEEE80211_CHAN_HT|IEEE80211_CHAN_5GHZ)
1526 #define IEEE80211_CHAN_HTG (IEEE80211_CHAN_HT|IEEE80211_CHAN_2GHZ)
1528 #define _APPLY(_flags, _base, _param, _v) do { \
1529 if (_flags & IEEE80211_CHAN_HT) { \
1530 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1531 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1532 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1533 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1534 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1536 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1538 if (_flags & IEEE80211_CHAN_TURBO) { \
1539 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1540 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1541 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1542 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1543 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1545 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1547 if (_flags & IEEE80211_CHAN_STURBO) \
1548 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1549 if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1550 _base.params[IEEE80211_MODE_11A]._param = _v; \
1551 if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1552 _base.params[IEEE80211_MODE_11G]._param = _v; \
1553 if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1554 _base.params[IEEE80211_MODE_11B]._param = _v; \
1555 if (_flags & IEEE80211_CHAN_HALF) \
1556 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1557 if (_flags & IEEE80211_CHAN_QUARTER) \
1558 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1560 #define _APPLY1(_flags, _base, _param, _v) do { \
1561 if (_flags & IEEE80211_CHAN_HT) { \
1562 if (_flags & IEEE80211_CHAN_5GHZ) \
1563 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1565 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1566 } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \
1567 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1568 else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \
1569 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1570 else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \
1571 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1572 else if (_flags & IEEE80211_CHAN_HALF) \
1573 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1574 else if (_flags & IEEE80211_CHAN_QUARTER) \
1575 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1576 else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1577 _base.params[IEEE80211_MODE_11A]._param = _v; \
1578 else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1579 _base.params[IEEE80211_MODE_11G]._param = _v; \
1580 else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1581 _base.params[IEEE80211_MODE_11B]._param = _v; \
1583 #define _APPLY_RATE(_flags, _base, _param, _v) do { \
1584 if (_flags & IEEE80211_CHAN_HT) { \
1585 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1587 _APPLY(_flags, _base, _param, _v); \
1589 #define _APPLY_RATE1(_flags, _base, _param, _v) do { \
1590 if (_flags & IEEE80211_CHAN_HT) { \
1591 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1593 _APPLY1(_flags, _base, _param, _v); \
1597 DECL_CMD_FUNC(set80211roamrssi, val, d)
1599 double v = atof(val);
1604 errx(-1, "invalid rssi (must be .5 dBm units)");
1605 flags = getmodeflags(val);
1607 if (flags == 0) { /* NB: no flags => current channel */
1608 flags = getcurchan(s)->ic_flags;
1609 _APPLY1(flags, roamparams, rssi, rssi);
1611 _APPLY(flags, roamparams, rssi, rssi);
1612 callback_register(setroam_cb, &roamparams);
1616 getrate(const char *val, const char *tag)
1618 double v = atof(val);
1623 errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag);
1624 return rate; /* NB: returns 2x the specified value */
1628 DECL_CMD_FUNC(set80211roamrate, val, d)
1632 rate = getrate(val, "roam");
1633 flags = getmodeflags(val);
1635 if (flags == 0) { /* NB: no flags => current channel */
1636 flags = getcurchan(s)->ic_flags;
1637 _APPLY_RATE1(flags, roamparams, rate, rate);
1639 _APPLY_RATE(flags, roamparams, rate, rate);
1640 callback_register(setroam_cb, &roamparams);
1644 DECL_CMD_FUNC(set80211mcastrate, val, d)
1648 rate = getrate(val, "mcast");
1649 flags = getmodeflags(val);
1651 if (flags == 0) { /* NB: no flags => current channel */
1652 flags = getcurchan(s)->ic_flags;
1653 _APPLY_RATE1(flags, txparams, mcastrate, rate);
1655 _APPLY_RATE(flags, txparams, mcastrate, rate);
1656 callback_register(settxparams_cb, &txparams);
1660 DECL_CMD_FUNC(set80211mgtrate, val, d)
1664 rate = getrate(val, "mgmt");
1665 flags = getmodeflags(val);
1667 if (flags == 0) { /* NB: no flags => current channel */
1668 flags = getcurchan(s)->ic_flags;
1669 _APPLY_RATE1(flags, txparams, mgmtrate, rate);
1671 _APPLY_RATE(flags, txparams, mgmtrate, rate);
1672 callback_register(settxparams_cb, &txparams);
1676 DECL_CMD_FUNC(set80211ucastrate, val, d)
1681 flags = getmodeflags(val);
1682 if (isanyarg(val)) {
1683 if (flags == 0) { /* NB: no flags => current channel */
1684 flags = getcurchan(s)->ic_flags;
1685 _APPLY1(flags, txparams, ucastrate,
1686 IEEE80211_FIXED_RATE_NONE);
1688 _APPLY(flags, txparams, ucastrate,
1689 IEEE80211_FIXED_RATE_NONE);
1691 int rate = getrate(val, "ucast");
1692 if (flags == 0) { /* NB: no flags => current channel */
1693 flags = getcurchan(s)->ic_flags;
1694 _APPLY_RATE1(flags, txparams, ucastrate, rate);
1696 _APPLY_RATE(flags, txparams, ucastrate, rate);
1698 callback_register(settxparams_cb, &txparams);
1702 DECL_CMD_FUNC(set80211maxretry, val, d)
1704 int v = atoi(val), flags;
1706 flags = getmodeflags(val);
1708 if (flags == 0) { /* NB: no flags => current channel */
1709 flags = getcurchan(s)->ic_flags;
1710 _APPLY1(flags, txparams, maxretry, v);
1712 _APPLY(flags, txparams, maxretry, v);
1713 callback_register(settxparams_cb, &txparams);
1717 #undef IEEE80211_CHAN_HTA
1718 #undef IEEE80211_CHAN_HTG
1721 DECL_CMD_FUNC(set80211fragthreshold, val, d)
1723 set80211(s, IEEE80211_IOC_FRAGTHRESHOLD,
1724 isundefarg(val) ? IEEE80211_FRAG_MAX : atoi(val), 0, NULL);
1728 DECL_CMD_FUNC(set80211bmissthreshold, val, d)
1730 set80211(s, IEEE80211_IOC_BMISSTHRESHOLD,
1731 isundefarg(val) ? IEEE80211_HWBMISS_MAX : atoi(val), 0, NULL);
1735 set80211burst(const char *val, int d, int s, const struct afswtch *rafp)
1737 set80211(s, IEEE80211_IOC_BURST, d, 0, NULL);
1741 set80211doth(const char *val, int d, int s, const struct afswtch *rafp)
1743 set80211(s, IEEE80211_IOC_DOTH, d, 0, NULL);
1747 set80211dfs(const char *val, int d, int s, const struct afswtch *rafp)
1749 set80211(s, IEEE80211_IOC_DFS, d, 0, NULL);
1753 set80211shortgi(const char *val, int d, int s, const struct afswtch *rafp)
1755 set80211(s, IEEE80211_IOC_SHORTGI,
1756 d ? (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) : 0,
1761 set80211ampdu(const char *val, int d, int s, const struct afswtch *rafp)
1765 if (get80211val(s, IEEE80211_IOC_AMPDU, &du) < 0)
1766 errx(-1, "cannot set AMPDU setting");
1772 set80211(s, IEEE80211_IOC_AMPDU, ampdu, 0, NULL);
1776 set80211stbc(const char *val, int d, int s, const struct afswtch *rafp)
1780 if (get80211val(s, IEEE80211_IOC_STBC, &stbc) < 0)
1781 errx(-1, "cannot set STBC setting");
1787 set80211(s, IEEE80211_IOC_STBC, stbc, 0, NULL);
1791 set80211ldpc(const char *val, int d, int s, const struct afswtch *rafp)
1795 if (get80211val(s, IEEE80211_IOC_LDPC, &ldpc) < 0)
1796 errx(-1, "cannot set LDPC setting");
1802 set80211(s, IEEE80211_IOC_LDPC, ldpc, 0, NULL);
1806 DECL_CMD_FUNC(set80211ampdulimit, val, d)
1810 switch (atoi(val)) {
1813 v = IEEE80211_HTCAP_MAXRXAMPDU_8K;
1817 v = IEEE80211_HTCAP_MAXRXAMPDU_16K;
1821 v = IEEE80211_HTCAP_MAXRXAMPDU_32K;
1825 v = IEEE80211_HTCAP_MAXRXAMPDU_64K;
1828 errx(-1, "invalid A-MPDU limit %s", val);
1830 set80211(s, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL);
1834 DECL_CMD_FUNC(set80211ampdudensity, val, d)
1838 if (isanyarg(val) || strcasecmp(val, "na") == 0)
1839 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1840 else switch ((int)(atof(val)*4)) {
1842 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1845 v = IEEE80211_HTCAP_MPDUDENSITY_025;
1848 v = IEEE80211_HTCAP_MPDUDENSITY_05;
1851 v = IEEE80211_HTCAP_MPDUDENSITY_1;
1854 v = IEEE80211_HTCAP_MPDUDENSITY_2;
1857 v = IEEE80211_HTCAP_MPDUDENSITY_4;
1860 v = IEEE80211_HTCAP_MPDUDENSITY_8;
1863 v = IEEE80211_HTCAP_MPDUDENSITY_16;
1866 errx(-1, "invalid A-MPDU density %s", val);
1868 set80211(s, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL);
1872 set80211amsdu(const char *val, int d, int s, const struct afswtch *rafp)
1876 if (get80211val(s, IEEE80211_IOC_AMSDU, &amsdu) < 0)
1877 err(-1, "cannot get AMSDU setting");
1883 set80211(s, IEEE80211_IOC_AMSDU, amsdu, 0, NULL);
1887 DECL_CMD_FUNC(set80211amsdulimit, val, d)
1889 set80211(s, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL);
1893 set80211puren(const char *val, int d, int s, const struct afswtch *rafp)
1895 set80211(s, IEEE80211_IOC_PUREN, d, 0, NULL);
1899 set80211htcompat(const char *val, int d, int s, const struct afswtch *rafp)
1901 set80211(s, IEEE80211_IOC_HTCOMPAT, d, 0, NULL);
1905 set80211htconf(const char *val, int d, int s, const struct afswtch *rafp)
1907 set80211(s, IEEE80211_IOC_HTCONF, d, 0, NULL);
1912 set80211dwds(const char *val, int d, int s, const struct afswtch *rafp)
1914 set80211(s, IEEE80211_IOC_DWDS, d, 0, NULL);
1918 set80211inact(const char *val, int d, int s, const struct afswtch *rafp)
1920 set80211(s, IEEE80211_IOC_INACTIVITY, d, 0, NULL);
1924 set80211tsn(const char *val, int d, int s, const struct afswtch *rafp)
1926 set80211(s, IEEE80211_IOC_TSN, d, 0, NULL);
1930 set80211dotd(const char *val, int d, int s, const struct afswtch *rafp)
1932 set80211(s, IEEE80211_IOC_DOTD, d, 0, NULL);
1936 set80211smps(const char *val, int d, int s, const struct afswtch *rafp)
1938 set80211(s, IEEE80211_IOC_SMPS, d, 0, NULL);
1942 set80211rifs(const char *val, int d, int s, const struct afswtch *rafp)
1944 set80211(s, IEEE80211_IOC_RIFS, d, 0, NULL);
1948 set80211vhtconf(const char *val, int d, int s, const struct afswtch *rafp)
1950 if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
1951 errx(-1, "cannot set VHT setting");
1952 printf("%s: vhtconf=0x%08x, d=%d\n", __func__, vhtconf, d);
1958 printf("%s: vhtconf is now 0x%08x\n", __func__, vhtconf);
1959 set80211(s, IEEE80211_IOC_VHTCONF, vhtconf, 0, NULL);
1963 DECL_CMD_FUNC(set80211tdmaslot, val, d)
1965 set80211(s, IEEE80211_IOC_TDMA_SLOT, atoi(val), 0, NULL);
1969 DECL_CMD_FUNC(set80211tdmaslotcnt, val, d)
1971 set80211(s, IEEE80211_IOC_TDMA_SLOTCNT, atoi(val), 0, NULL);
1975 DECL_CMD_FUNC(set80211tdmaslotlen, val, d)
1977 set80211(s, IEEE80211_IOC_TDMA_SLOTLEN, atoi(val), 0, NULL);
1981 DECL_CMD_FUNC(set80211tdmabintval, val, d)
1983 set80211(s, IEEE80211_IOC_TDMA_BINTERVAL, atoi(val), 0, NULL);
1987 DECL_CMD_FUNC(set80211meshttl, val, d)
1989 set80211(s, IEEE80211_IOC_MESH_TTL, atoi(val), 0, NULL);
1993 DECL_CMD_FUNC(set80211meshforward, val, d)
1995 set80211(s, IEEE80211_IOC_MESH_FWRD, d, 0, NULL);
1999 DECL_CMD_FUNC(set80211meshgate, val, d)
2001 set80211(s, IEEE80211_IOC_MESH_GATE, d, 0, NULL);
2005 DECL_CMD_FUNC(set80211meshpeering, val, d)
2007 set80211(s, IEEE80211_IOC_MESH_AP, d, 0, NULL);
2011 DECL_CMD_FUNC(set80211meshmetric, val, d)
2015 memcpy(v, val, sizeof(v));
2016 set80211(s, IEEE80211_IOC_MESH_PR_METRIC, 0, 0, v);
2020 DECL_CMD_FUNC(set80211meshpath, val, d)
2024 memcpy(v, val, sizeof(v));
2025 set80211(s, IEEE80211_IOC_MESH_PR_PATH, 0, 0, v);
2029 regdomain_sort(const void *a, const void *b)
2032 (IEEE80211_CHAN_ALLTURBO|IEEE80211_CHAN_HALF|IEEE80211_CHAN_QUARTER)
2033 const struct ieee80211_channel *ca = a;
2034 const struct ieee80211_channel *cb = b;
2036 return ca->ic_freq == cb->ic_freq ?
2037 (ca->ic_flags & CHAN_ALL) - (cb->ic_flags & CHAN_ALL) :
2038 ca->ic_freq - cb->ic_freq;
2042 static const struct ieee80211_channel *
2043 chanlookup(const struct ieee80211_channel chans[], int nchans,
2044 int freq, int flags)
2048 flags &= IEEE80211_CHAN_ALLTURBO;
2049 for (i = 0; i < nchans; i++) {
2050 const struct ieee80211_channel *c = &chans[i];
2051 if (c->ic_freq == freq &&
2052 (c->ic_flags & IEEE80211_CHAN_ALLTURBO) == flags)
2059 chanfind(const struct ieee80211_channel chans[], int nchans, int flags)
2063 for (i = 0; i < nchans; i++) {
2064 const struct ieee80211_channel *c = &chans[i];
2065 if ((c->ic_flags & flags) == flags)
2072 * Check channel compatibility.
2075 checkchan(const struct ieee80211req_chaninfo *avail, int freq, int flags)
2077 flags &= ~REQ_FLAGS;
2079 * Check if exact channel is in the calibration table;
2080 * everything below is to deal with channels that we
2081 * want to include but that are not explicitly listed.
2083 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, flags) != NULL)
2085 if (flags & IEEE80211_CHAN_GSM) {
2087 * XXX GSM frequency mapping is handled in the kernel
2088 * so we cannot find them in the calibration table;
2089 * just accept the channel and the kernel will reject
2090 * the channel list if it's wrong.
2095 * If this is a 1/2 or 1/4 width channel allow it if a full
2096 * width channel is present for this frequency, and the device
2097 * supports fractional channels on this band. This is a hack
2098 * that avoids bloating the calibration table; it may be better
2099 * by per-band attributes though (we are effectively calculating
2100 * this attribute by scanning the channel list ourself).
2102 if ((flags & (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == 0)
2104 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq,
2105 flags &~ (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == NULL)
2107 if (flags & IEEE80211_CHAN_HALF) {
2108 return chanfind(avail->ic_chans, avail->ic_nchans,
2109 IEEE80211_CHAN_HALF |
2110 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2112 return chanfind(avail->ic_chans, avail->ic_nchans,
2113 IEEE80211_CHAN_QUARTER |
2114 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2119 regdomain_addchans(struct ieee80211req_chaninfo *ci,
2120 const netband_head *bands,
2121 const struct ieee80211_regdomain *reg,
2123 const struct ieee80211req_chaninfo *avail)
2125 const struct netband *nb;
2126 const struct freqband *b;
2127 struct ieee80211_channel *c, *prev;
2128 int freq, hi_adj, lo_adj, channelSep;
2131 hi_adj = (chanFlags & IEEE80211_CHAN_HT40U) ? -20 : 0;
2132 lo_adj = (chanFlags & IEEE80211_CHAN_HT40D) ? 20 : 0;
2133 channelSep = (chanFlags & IEEE80211_CHAN_2GHZ) ? 0 : 40;
2135 LIST_FOREACH(nb, bands, next) {
2138 printf("%s:", __func__);
2139 printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS);
2140 printb(" bandFlags", nb->flags | b->flags,
2141 IEEE80211_CHAN_BITS);
2146 for (freq = b->freqStart + lo_adj;
2147 freq <= b->freqEnd + hi_adj; freq += b->chanSep) {
2149 * Construct flags for the new channel. We take
2150 * the attributes from the band descriptions except
2151 * for HT40 which is enabled generically (i.e. +/-
2152 * extension channel) in the band description and
2153 * then constrained according by channel separation.
2155 flags = nb->flags | b->flags;
2158 * VHT first - HT is a subset.
2160 * XXX TODO: VHT80p80, VHT160 is not yet done.
2162 if (flags & IEEE80211_CHAN_VHT) {
2163 if ((chanFlags & IEEE80211_CHAN_VHT20) &&
2164 (flags & IEEE80211_CHAN_VHT20) == 0) {
2166 printf("%u: skip, not a "
2167 "VHT20 channel\n", freq);
2170 if ((chanFlags & IEEE80211_CHAN_VHT40) &&
2171 (flags & IEEE80211_CHAN_VHT40) == 0) {
2173 printf("%u: skip, not a "
2174 "VHT40 channel\n", freq);
2177 if ((chanFlags & IEEE80211_CHAN_VHT80) &&
2178 (flags & IEEE80211_CHAN_VHT80) == 0) {
2180 printf("%u: skip, not a "
2181 "VHT80 channel\n", freq);
2185 flags &= ~IEEE80211_CHAN_VHT;
2186 flags |= chanFlags & IEEE80211_CHAN_VHT;
2189 /* Now, constrain HT */
2190 if (flags & IEEE80211_CHAN_HT) {
2192 * HT channels are generated specially; we're
2193 * called to add HT20, HT40+, and HT40- chan's
2194 * so we need to expand only band specs for
2195 * the HT channel type being added.
2197 if ((chanFlags & IEEE80211_CHAN_HT20) &&
2198 (flags & IEEE80211_CHAN_HT20) == 0) {
2200 printf("%u: skip, not an "
2201 "HT20 channel\n", freq);
2204 if ((chanFlags & IEEE80211_CHAN_HT40) &&
2205 (flags & IEEE80211_CHAN_HT40) == 0) {
2207 printf("%u: skip, not an "
2208 "HT40 channel\n", freq);
2211 /* NB: HT attribute comes from caller */
2212 flags &= ~IEEE80211_CHAN_HT;
2213 flags |= chanFlags & IEEE80211_CHAN_HT;
2216 * Check if device can operate on this frequency.
2218 if (!checkchan(avail, freq, flags)) {
2220 printf("%u: skip, ", freq);
2221 printb("flags", flags,
2222 IEEE80211_CHAN_BITS);
2223 printf(" not available\n");
2227 if ((flags & REQ_ECM) && !reg->ecm) {
2229 printf("%u: skip, ECM channel\n", freq);
2232 if ((flags & REQ_INDOOR) && reg->location == 'O') {
2234 printf("%u: skip, indoor channel\n",
2238 if ((flags & REQ_OUTDOOR) && reg->location == 'I') {
2240 printf("%u: skip, outdoor channel\n",
2244 if ((flags & IEEE80211_CHAN_HT40) &&
2245 prev != NULL && (freq - prev->ic_freq) < channelSep) {
2247 printf("%u: skip, only %u channel "
2248 "separation, need %d\n", freq,
2249 freq - prev->ic_freq, channelSep);
2252 if (ci->ic_nchans == IEEE80211_CHAN_MAX) {
2254 printf("%u: skip, channel table full\n",
2258 c = &ci->ic_chans[ci->ic_nchans++];
2259 memset(c, 0, sizeof(*c));
2261 c->ic_flags = flags;
2262 if (c->ic_flags & IEEE80211_CHAN_DFS)
2263 c->ic_maxregpower = nb->maxPowerDFS;
2265 c->ic_maxregpower = nb->maxPower;
2267 printf("[%3d] add freq %u ",
2268 ci->ic_nchans-1, c->ic_freq);
2269 printb("flags", c->ic_flags, IEEE80211_CHAN_BITS);
2270 printf(" power %u\n", c->ic_maxregpower);
2272 /* NB: kernel fills in other fields */
2279 regdomain_makechannels(
2280 struct ieee80211_regdomain_req *req,
2281 const struct ieee80211_devcaps_req *dc)
2283 struct regdata *rdp = getregdata();
2284 const struct country *cc;
2285 const struct ieee80211_regdomain *reg = &req->rd;
2286 struct ieee80211req_chaninfo *ci = &req->chaninfo;
2287 const struct regdomain *rd;
2290 * Locate construction table for new channel list. We treat
2291 * the regdomain/SKU as definitive so a country can be in
2292 * multiple with different properties (e.g. US in FCC+FCC3).
2293 * If no regdomain is specified then we fallback on the country
2294 * code to find the associated regdomain since countries always
2295 * belong to at least one regdomain.
2297 if (reg->regdomain == 0) {
2298 cc = lib80211_country_findbycc(rdp, reg->country);
2300 errx(1, "internal error, country %d not found",
2304 rd = lib80211_regdomain_findbysku(rdp, reg->regdomain);
2306 errx(1, "internal error, regdomain %d not found",
2308 if (rd->sku != SKU_DEBUG) {
2310 * regdomain_addchans incrememnts the channel count for
2311 * each channel it adds so initialize ic_nchans to zero.
2312 * Note that we know we have enough space to hold all possible
2313 * channels because the devcaps list size was used to
2314 * allocate our request.
2317 if (!LIST_EMPTY(&rd->bands_11b))
2318 regdomain_addchans(ci, &rd->bands_11b, reg,
2319 IEEE80211_CHAN_B, &dc->dc_chaninfo);
2320 if (!LIST_EMPTY(&rd->bands_11g))
2321 regdomain_addchans(ci, &rd->bands_11g, reg,
2322 IEEE80211_CHAN_G, &dc->dc_chaninfo);
2323 if (!LIST_EMPTY(&rd->bands_11a))
2324 regdomain_addchans(ci, &rd->bands_11a, reg,
2325 IEEE80211_CHAN_A, &dc->dc_chaninfo);
2326 if (!LIST_EMPTY(&rd->bands_11na) && dc->dc_htcaps != 0) {
2327 regdomain_addchans(ci, &rd->bands_11na, reg,
2328 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20,
2330 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2331 regdomain_addchans(ci, &rd->bands_11na, reg,
2332 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U,
2334 regdomain_addchans(ci, &rd->bands_11na, reg,
2335 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D,
2339 if (!LIST_EMPTY(&rd->bands_11ac) && dc->dc_vhtcaps != 0) {
2340 regdomain_addchans(ci, &rd->bands_11ac, reg,
2341 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20 |
2342 IEEE80211_CHAN_VHT20,
2345 /* VHT40 is a function of HT40.. */
2346 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2347 regdomain_addchans(ci, &rd->bands_11ac, reg,
2348 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U |
2349 IEEE80211_CHAN_VHT40U,
2351 regdomain_addchans(ci, &rd->bands_11ac, reg,
2352 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D |
2353 IEEE80211_CHAN_VHT40D,
2358 /* XXX dc_vhtcap? */
2360 regdomain_addchans(ci, &rd->bands_11ac, reg,
2361 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U |
2362 IEEE80211_CHAN_VHT80,
2364 regdomain_addchans(ci, &rd->bands_11ac, reg,
2365 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D |
2366 IEEE80211_CHAN_VHT80,
2370 /* XXX TODO: VHT80_80, VHT160 */
2373 if (!LIST_EMPTY(&rd->bands_11ng) && dc->dc_htcaps != 0) {
2374 regdomain_addchans(ci, &rd->bands_11ng, reg,
2375 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20,
2377 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2378 regdomain_addchans(ci, &rd->bands_11ng, reg,
2379 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U,
2381 regdomain_addchans(ci, &rd->bands_11ng, reg,
2382 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D,
2386 qsort(ci->ic_chans, ci->ic_nchans, sizeof(ci->ic_chans[0]),
2389 memcpy(ci, &dc->dc_chaninfo,
2390 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
2394 list_countries(void)
2396 struct regdata *rdp = getregdata();
2397 const struct country *cp;
2398 const struct regdomain *dp;
2402 printf("\nCountry codes:\n");
2403 LIST_FOREACH(cp, &rdp->countries, next) {
2404 printf("%2s %-15.15s%s", cp->isoname,
2405 cp->name, ((i+1)%4) == 0 ? "\n" : " ");
2409 printf("\nRegulatory domains:\n");
2410 LIST_FOREACH(dp, &rdp->domains, next) {
2411 printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " ");
2418 defaultcountry(const struct regdomain *rd)
2420 struct regdata *rdp = getregdata();
2421 const struct country *cc;
2423 cc = lib80211_country_findbycc(rdp, rd->cc->code);
2425 errx(1, "internal error, ISO country code %d not "
2426 "defined for regdomain %s", rd->cc->code, rd->name);
2427 regdomain.country = cc->code;
2428 regdomain.isocc[0] = cc->isoname[0];
2429 regdomain.isocc[1] = cc->isoname[1];
2433 DECL_CMD_FUNC(set80211regdomain, val, d)
2435 struct regdata *rdp = getregdata();
2436 const struct regdomain *rd;
2438 rd = lib80211_regdomain_findbyname(rdp, val);
2441 long sku = strtol(val, &eptr, 0);
2444 rd = lib80211_regdomain_findbysku(rdp, sku);
2445 if (eptr == val || rd == NULL)
2446 errx(1, "unknown regdomain %s", val);
2449 regdomain.regdomain = rd->sku;
2450 if (regdomain.country == 0 && rd->cc != NULL) {
2452 * No country code setup and there's a default
2453 * one for this regdomain fill it in.
2457 callback_register(setregdomain_cb, ®domain);
2461 DECL_CMD_FUNC(set80211country, val, d)
2463 struct regdata *rdp = getregdata();
2464 const struct country *cc;
2466 cc = lib80211_country_findbyname(rdp, val);
2469 long code = strtol(val, &eptr, 0);
2472 cc = lib80211_country_findbycc(rdp, code);
2473 if (eptr == val || cc == NULL)
2474 errx(1, "unknown ISO country code %s", val);
2477 regdomain.regdomain = cc->rd->sku;
2478 regdomain.country = cc->code;
2479 regdomain.isocc[0] = cc->isoname[0];
2480 regdomain.isocc[1] = cc->isoname[1];
2481 callback_register(setregdomain_cb, ®domain);
2485 set80211location(const char *val, int d, int s, const struct afswtch *rafp)
2488 regdomain.location = d;
2489 callback_register(setregdomain_cb, ®domain);
2493 set80211ecm(const char *val, int d, int s, const struct afswtch *rafp)
2497 callback_register(setregdomain_cb, ®domain);
2513 if (spacer != '\t') {
2517 col = 8; /* 8-col tab */
2521 LINE_CHECK(const char *fmt, ...)
2528 n = vsnprintf(buf+1, sizeof(buf)-1, fmt, ap);
2541 getmaxrate(const uint8_t rates[15], uint8_t nrates)
2543 int i, maxrate = -1;
2545 for (i = 0; i < nrates; i++) {
2546 int rate = rates[i] & IEEE80211_RATE_VAL;
2554 getcaps(int capinfo)
2556 static char capstring[32];
2557 char *cp = capstring;
2559 if (capinfo & IEEE80211_CAPINFO_ESS)
2561 if (capinfo & IEEE80211_CAPINFO_IBSS)
2563 if (capinfo & IEEE80211_CAPINFO_CF_POLLABLE)
2565 if (capinfo & IEEE80211_CAPINFO_CF_POLLREQ)
2567 if (capinfo & IEEE80211_CAPINFO_PRIVACY)
2569 if (capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)
2571 if (capinfo & IEEE80211_CAPINFO_PBCC)
2573 if (capinfo & IEEE80211_CAPINFO_CHNL_AGILITY)
2575 if (capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME)
2577 if (capinfo & IEEE80211_CAPINFO_RSN)
2579 if (capinfo & IEEE80211_CAPINFO_DSSSOFDM)
2588 static char flagstring[32];
2589 char *cp = flagstring;
2591 if (flags & IEEE80211_NODE_AUTH)
2593 if (flags & IEEE80211_NODE_QOS)
2595 if (flags & IEEE80211_NODE_ERP)
2597 if (flags & IEEE80211_NODE_PWR_MGT)
2599 if (flags & IEEE80211_NODE_HT) {
2601 if (flags & IEEE80211_NODE_HTCOMPAT)
2604 if (flags & IEEE80211_NODE_VHT)
2606 if (flags & IEEE80211_NODE_WPS)
2608 if (flags & IEEE80211_NODE_TSN)
2610 if (flags & IEEE80211_NODE_AMPDU_TX)
2612 if (flags & IEEE80211_NODE_AMPDU_RX)
2614 if (flags & IEEE80211_NODE_MIMO_PS) {
2616 if (flags & IEEE80211_NODE_MIMO_RTS)
2619 if (flags & IEEE80211_NODE_RIFS)
2621 if (flags & IEEE80211_NODE_SGI40) {
2623 if (flags & IEEE80211_NODE_SGI20)
2625 } else if (flags & IEEE80211_NODE_SGI20)
2627 if (flags & IEEE80211_NODE_AMSDU_TX)
2629 if (flags & IEEE80211_NODE_AMSDU_RX)
2636 printie(const char* tag, const uint8_t *ie, size_t ielen, int maxlen)
2640 maxlen -= strlen(tag)+2;
2641 if (2*ielen > maxlen)
2644 for (; ielen > 0; ie++, ielen--) {
2647 printf("%02x", *ie);
2655 #define LE_READ_2(p) \
2657 ((((const u_int8_t *)(p))[0] ) | \
2658 (((const u_int8_t *)(p))[1] << 8)))
2659 #define LE_READ_4(p) \
2661 ((((const u_int8_t *)(p))[0] ) | \
2662 (((const u_int8_t *)(p))[1] << 8) | \
2663 (((const u_int8_t *)(p))[2] << 16) | \
2664 (((const u_int8_t *)(p))[3] << 24)))
2667 * NB: The decoding routines assume a properly formatted ie
2668 * which should be safe as the kernel only retains them
2673 printwmeparam(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2675 #define MS(_v, _f) (((_v) & _f) >> _f##_S)
2676 static const char *acnames[] = { "BE", "BK", "VO", "VI" };
2677 const struct ieee80211_wme_param *wme =
2678 (const struct ieee80211_wme_param *) ie;
2684 printf("<qosinfo 0x%x", wme->param_qosInfo);
2685 ie += offsetof(struct ieee80211_wme_param, params_acParams);
2686 for (i = 0; i < WME_NUM_AC; i++) {
2687 const struct ieee80211_wme_acparams *ac =
2688 &wme->params_acParams[i];
2690 printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]"
2692 , MS(ac->acp_aci_aifsn, WME_PARAM_ACM) ? "acm " : ""
2693 , MS(ac->acp_aci_aifsn, WME_PARAM_AIFSN)
2694 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMIN)
2695 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMAX)
2696 , LE_READ_2(&ac->acp_txop)
2704 printwmeinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2708 const struct ieee80211_wme_info *wme =
2709 (const struct ieee80211_wme_info *) ie;
2710 printf("<version 0x%x info 0x%x>",
2711 wme->wme_version, wme->wme_info);
2716 printvhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2720 const struct ieee80211_ie_vhtcap *vhtcap =
2721 (const struct ieee80211_ie_vhtcap *) ie;
2722 uint32_t vhtcap_info = LE_READ_4(&vhtcap->vht_cap_info);
2724 printf("<cap 0x%08x", vhtcap_info);
2725 printf(" rx_mcs_map 0x%x",
2726 LE_READ_2(&vhtcap->supp_mcs.rx_mcs_map));
2727 printf(" rx_highest %d",
2728 LE_READ_2(&vhtcap->supp_mcs.rx_highest) & 0x1fff);
2729 printf(" tx_mcs_map 0x%x",
2730 LE_READ_2(&vhtcap->supp_mcs.tx_mcs_map));
2731 printf(" tx_highest %d",
2732 LE_READ_2(&vhtcap->supp_mcs.tx_highest) & 0x1fff);
2739 printvhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2743 const struct ieee80211_ie_vht_operation *vhtinfo =
2744 (const struct ieee80211_ie_vht_operation *) ie;
2746 printf("<chw %d freq1_idx %d freq2_idx %d basic_mcs_set 0x%04x>",
2747 vhtinfo->chan_width,
2748 vhtinfo->center_freq_seg1_idx,
2749 vhtinfo->center_freq_seg2_idx,
2750 LE_READ_2(&vhtinfo->basic_mcs_set));
2755 printvhtpwrenv(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2758 static const char *txpwrmap[] = {
2765 const struct ieee80211_ie_vht_txpwrenv *vhtpwr =
2766 (const struct ieee80211_ie_vht_txpwrenv *) ie;
2768 const char *sep = "";
2770 /* Get count; trim at ielen */
2771 n = (vhtpwr->tx_info &
2772 IEEE80211_VHT_TXPWRENV_INFO_COUNT_MASK) + 1;
2776 printf("<tx_info 0x%02x pwr:[", vhtpwr->tx_info);
2777 for (i = 0; i < n; i++) {
2778 printf("%s%s:%.2f", sep, txpwrmap[i],
2779 ((float) ((int8_t) ie[i+3])) / 2.0);
2788 printhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2792 const struct ieee80211_ie_htcap *htcap =
2793 (const struct ieee80211_ie_htcap *) ie;
2797 printf("<cap 0x%x param 0x%x",
2798 LE_READ_2(&htcap->hc_cap), htcap->hc_param);
2801 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2802 if (isset(htcap->hc_mcsset, i)) {
2803 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2804 if (isclr(htcap->hc_mcsset, j))
2808 printf("%s%u", sep, i);
2810 printf("%s%u-%u", sep, i, j);
2814 printf("] extcap 0x%x txbf 0x%x antenna 0x%x>",
2815 LE_READ_2(&htcap->hc_extcap),
2816 LE_READ_4(&htcap->hc_txbf),
2822 printhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2826 const struct ieee80211_ie_htinfo *htinfo =
2827 (const struct ieee80211_ie_htinfo *) ie;
2831 printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel,
2832 htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3,
2833 LE_READ_2(&htinfo->hi_byte45));
2834 printf(" basicmcs[");
2836 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2837 if (isset(htinfo->hi_basicmcsset, i)) {
2838 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2839 if (isclr(htinfo->hi_basicmcsset, j))
2843 printf("%s%u", sep, i);
2845 printf("%s%u-%u", sep, i, j);
2854 printathie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2859 const struct ieee80211_ath_ie *ath =
2860 (const struct ieee80211_ath_ie *)ie;
2863 if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME)
2865 if (ath->ath_capability & ATHEROS_CAP_COMPRESSION)
2867 if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME)
2869 if (ath->ath_capability & ATHEROS_CAP_XR)
2871 if (ath->ath_capability & ATHEROS_CAP_AR)
2873 if (ath->ath_capability & ATHEROS_CAP_BURST)
2875 if (ath->ath_capability & ATHEROS_CAP_WME)
2877 if (ath->ath_capability & ATHEROS_CAP_BOOST)
2879 printf("0x%x>", LE_READ_2(ath->ath_defkeyix));
2885 printmeshconf(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2890 const struct ieee80211_meshconf_ie *mconf =
2891 (const struct ieee80211_meshconf_ie *)ie;
2893 if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP)
2898 if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME)
2902 printf(" CONGESTION:");
2903 if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED)
2908 if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF)
2913 if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED)
2917 printf(" FORM:0x%x CAPS:0x%x>", mconf->conf_form,
2923 printbssload(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2927 const struct ieee80211_bss_load_ie *bssload =
2928 (const struct ieee80211_bss_load_ie *) ie;
2929 printf("<sta count %d, chan load %d, aac %d>",
2930 LE_READ_2(&bssload->sta_count),
2937 printapchanrep(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2941 const struct ieee80211_ap_chan_report_ie *ap =
2942 (const struct ieee80211_ap_chan_report_ie *) ie;
2943 const char *sep = "";
2946 printf("<class %u, chan:[", ap->i_class);
2948 for (i = 3; i < ielen; i++) {
2949 printf("%s%u", sep, ie[i]);
2957 wpa_cipher(const u_int8_t *sel)
2959 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2960 u_int32_t w = LE_READ_4(sel);
2963 case WPA_SEL(WPA_CSE_NULL):
2965 case WPA_SEL(WPA_CSE_WEP40):
2967 case WPA_SEL(WPA_CSE_WEP104):
2969 case WPA_SEL(WPA_CSE_TKIP):
2971 case WPA_SEL(WPA_CSE_CCMP):
2974 return "?"; /* NB: so 1<< is discarded */
2979 wpa_keymgmt(const u_int8_t *sel)
2981 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2982 u_int32_t w = LE_READ_4(sel);
2985 case WPA_SEL(WPA_ASE_8021X_UNSPEC):
2986 return "8021X-UNSPEC";
2987 case WPA_SEL(WPA_ASE_8021X_PSK):
2989 case WPA_SEL(WPA_ASE_NONE):
2997 printwpaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2999 u_int8_t len = ie[1];
3006 ie += 6, len -= 4; /* NB: len is payload only */
3008 printf("<v%u", LE_READ_2(ie));
3011 printf(" mc:%s", wpa_cipher(ie));
3014 /* unicast ciphers */
3018 for (; n > 0; n--) {
3019 printf("%s%s", sep, wpa_cipher(ie));
3024 /* key management algorithms */
3028 for (; n > 0; n--) {
3029 printf("%s%s", sep, wpa_keymgmt(ie));
3034 if (len > 2) /* optional capabilities */
3035 printf(", caps 0x%x", LE_READ_2(ie));
3041 rsn_cipher(const u_int8_t *sel)
3043 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
3044 u_int32_t w = LE_READ_4(sel);
3047 case RSN_SEL(RSN_CSE_NULL):
3049 case RSN_SEL(RSN_CSE_WEP40):
3051 case RSN_SEL(RSN_CSE_WEP104):
3053 case RSN_SEL(RSN_CSE_TKIP):
3055 case RSN_SEL(RSN_CSE_CCMP):
3057 case RSN_SEL(RSN_CSE_WRAP):
3065 rsn_keymgmt(const u_int8_t *sel)
3067 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
3068 u_int32_t w = LE_READ_4(sel);
3071 case RSN_SEL(RSN_ASE_8021X_UNSPEC):
3072 return "8021X-UNSPEC";
3073 case RSN_SEL(RSN_ASE_8021X_PSK):
3075 case RSN_SEL(RSN_ASE_NONE):
3083 printrsnie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3090 ie += 2, ielen -= 2;
3092 printf("<v%u", LE_READ_2(ie));
3093 ie += 2, ielen -= 2;
3095 printf(" mc:%s", rsn_cipher(ie));
3096 ie += 4, ielen -= 4;
3098 /* unicast ciphers */
3100 ie += 2, ielen -= 2;
3102 for (; n > 0; n--) {
3103 printf("%s%s", sep, rsn_cipher(ie));
3104 ie += 4, ielen -= 4;
3108 /* key management algorithms */
3110 ie += 2, ielen -= 2;
3112 for (; n > 0; n--) {
3113 printf("%s%s", sep, rsn_keymgmt(ie));
3114 ie += 4, ielen -= 4;
3118 if (ielen > 2) /* optional capabilities */
3119 printf(", caps 0x%x", LE_READ_2(ie));
3125 /* XXX move to a public include file */
3126 #define IEEE80211_WPS_DEV_PASS_ID 0x1012
3127 #define IEEE80211_WPS_SELECTED_REG 0x1041
3128 #define IEEE80211_WPS_SETUP_STATE 0x1044
3129 #define IEEE80211_WPS_UUID_E 0x1047
3130 #define IEEE80211_WPS_VERSION 0x104a
3132 #define BE_READ_2(p) \
3134 ((((const u_int8_t *)(p))[1] ) | \
3135 (((const u_int8_t *)(p))[0] << 8)))
3138 printwpsie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3140 u_int8_t len = ie[1];
3144 static const char *dev_pass_id[] = {
3145 "D", /* Default (PIN) */
3146 "U", /* User-specified */
3147 "M", /* Machine-specified */
3149 "P", /* PushButton */
3150 "R" /* Registrar-specified */
3154 ie +=6, len -= 4; /* NB: len is payload only */
3156 /* WPS IE in Beacon and Probe Resp frames have different fields */
3159 uint16_t tlv_type = BE_READ_2(ie);
3160 uint16_t tlv_len = BE_READ_2(ie + 2);
3165 case IEEE80211_WPS_VERSION:
3166 printf("v:%d.%d", *ie >> 4, *ie & 0xf);
3168 case IEEE80211_WPS_SETUP_STATE:
3169 /* Only 1 and 2 are valid */
3170 if (*ie == 0 || *ie >= 3)
3173 printf(" st:%s", *ie == 1 ? "N" : "C");
3175 case IEEE80211_WPS_SELECTED_REG:
3176 printf(" sel:%s", *ie ? "T" : "F");
3178 case IEEE80211_WPS_DEV_PASS_ID:
3180 if (n < nitems(dev_pass_id))
3181 printf(" dpi:%s", dev_pass_id[n]);
3183 case IEEE80211_WPS_UUID_E:
3185 for (n = 0; n < (tlv_len - 1); n++)
3186 printf("%02x-", ie[n]);
3187 printf("%02x", ie[n]);
3190 ie += tlv_len, len -= tlv_len;
3197 printtdmaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3200 if (verbose && ielen >= sizeof(struct ieee80211_tdma_param)) {
3201 const struct ieee80211_tdma_param *tdma =
3202 (const struct ieee80211_tdma_param *) ie;
3205 printf("<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>",
3206 tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt,
3207 LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval,
3208 tdma->tdma_inuse[0]);
3213 * Copy the ssid string contents into buf, truncating to fit. If the
3214 * ssid is entirely printable then just copy intact. Otherwise convert
3215 * to hexadecimal. If the result is truncated then replace the last
3216 * three characters with "...".
3219 copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len)
3225 if (essid_len > bufsize)
3229 /* determine printable or not */
3230 for (i = 0, p = essid; i < maxlen; i++, p++) {
3231 if (*p < ' ' || *p > 0x7e)
3234 if (i != maxlen) { /* not printable, print as hex */
3237 strlcpy(buf, "0x", bufsize);
3240 for (i = 0; i < maxlen && bufsize >= 2; i++) {
3241 sprintf(&buf[2+2*i], "%02x", p[i]);
3245 memcpy(&buf[2+2*i-3], "...", 3);
3246 } else { /* printable, truncate as needed */
3247 memcpy(buf, essid, maxlen);
3248 if (maxlen != essid_len)
3249 memcpy(&buf[maxlen-3], "...", 3);
3255 printssid(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3257 char ssid[2*IEEE80211_NWID_LEN+1];
3259 printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid);
3263 printrates(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3270 for (i = 2; i < ielen; i++) {
3271 printf("%s%s%d", sep,
3272 ie[i] & IEEE80211_RATE_BASIC ? "B" : "",
3273 ie[i] & IEEE80211_RATE_VAL);
3280 printcountry(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3282 const struct ieee80211_country_ie *cie =
3283 (const struct ieee80211_country_ie *) ie;
3284 int i, nbands, schan, nchan;
3286 printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]);
3287 nbands = (cie->len - 3) / sizeof(cie->band[0]);
3288 for (i = 0; i < nbands; i++) {
3289 schan = cie->band[i].schan;
3290 nchan = cie->band[i].nchan;
3292 printf(" %u-%u,%u", schan, schan + nchan-1,
3293 cie->band[i].maxtxpwr);
3295 printf(" %u,%u", schan, cie->band[i].maxtxpwr);
3301 iswpaoui(const u_int8_t *frm)
3303 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI);
3307 iswmeinfo(const u_int8_t *frm)
3309 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3310 frm[6] == WME_INFO_OUI_SUBTYPE;
3314 iswmeparam(const u_int8_t *frm)
3316 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3317 frm[6] == WME_PARAM_OUI_SUBTYPE;
3321 isatherosoui(const u_int8_t *frm)
3323 return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI);
3327 istdmaoui(const uint8_t *frm)
3329 return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI);
3333 iswpsoui(const uint8_t *frm)
3335 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPS_OUI_TYPE<<24)|WPA_OUI);
3342 case IEEE80211_ELEMID_FHPARMS: return " FHPARMS";
3343 case IEEE80211_ELEMID_CFPARMS: return " CFPARMS";
3344 case IEEE80211_ELEMID_TIM: return " TIM";
3345 case IEEE80211_ELEMID_IBSSPARMS:return " IBSSPARMS";
3346 case IEEE80211_ELEMID_BSSLOAD: return " BSSLOAD";
3347 case IEEE80211_ELEMID_CHALLENGE:return " CHALLENGE";
3348 case IEEE80211_ELEMID_PWRCNSTR: return " PWRCNSTR";
3349 case IEEE80211_ELEMID_PWRCAP: return " PWRCAP";
3350 case IEEE80211_ELEMID_TPCREQ: return " TPCREQ";
3351 case IEEE80211_ELEMID_TPCREP: return " TPCREP";
3352 case IEEE80211_ELEMID_SUPPCHAN: return " SUPPCHAN";
3353 case IEEE80211_ELEMID_CSA: return " CSA";
3354 case IEEE80211_ELEMID_MEASREQ: return " MEASREQ";
3355 case IEEE80211_ELEMID_MEASREP: return " MEASREP";
3356 case IEEE80211_ELEMID_QUIET: return " QUIET";
3357 case IEEE80211_ELEMID_IBSSDFS: return " IBSSDFS";
3358 case IEEE80211_ELEMID_TPC: return " TPC";
3359 case IEEE80211_ELEMID_CCKM: return " CCKM";
3365 printies(const u_int8_t *vp, int ielen, int maxcols)
3369 case IEEE80211_ELEMID_SSID:
3371 printssid(" SSID", vp, 2+vp[1], maxcols);
3373 case IEEE80211_ELEMID_RATES:
3374 case IEEE80211_ELEMID_XRATES:
3376 printrates(vp[0] == IEEE80211_ELEMID_RATES ?
3377 " RATES" : " XRATES", vp, 2+vp[1], maxcols);
3379 case IEEE80211_ELEMID_DSPARMS:
3381 printf(" DSPARMS<%u>", vp[2]);
3383 case IEEE80211_ELEMID_COUNTRY:
3385 printcountry(" COUNTRY", vp, 2+vp[1], maxcols);
3387 case IEEE80211_ELEMID_ERP:
3389 printf(" ERP<0x%x>", vp[2]);
3391 case IEEE80211_ELEMID_VENDOR:
3393 printwpaie(" WPA", vp, 2+vp[1], maxcols);
3394 else if (iswmeinfo(vp))
3395 printwmeinfo(" WME", vp, 2+vp[1], maxcols);
3396 else if (iswmeparam(vp))
3397 printwmeparam(" WME", vp, 2+vp[1], maxcols);
3398 else if (isatherosoui(vp))
3399 printathie(" ATH", vp, 2+vp[1], maxcols);
3400 else if (iswpsoui(vp))
3401 printwpsie(" WPS", vp, 2+vp[1], maxcols);
3402 else if (istdmaoui(vp))
3403 printtdmaie(" TDMA", vp, 2+vp[1], maxcols);
3405 printie(" VEN", vp, 2+vp[1], maxcols);
3407 case IEEE80211_ELEMID_RSN:
3408 printrsnie(" RSN", vp, 2+vp[1], maxcols);
3410 case IEEE80211_ELEMID_HTCAP:
3411 printhtcap(" HTCAP", vp, 2+vp[1], maxcols);
3413 case IEEE80211_ELEMID_HTINFO:
3415 printhtinfo(" HTINFO", vp, 2+vp[1], maxcols);
3417 case IEEE80211_ELEMID_MESHID:
3419 printssid(" MESHID", vp, 2+vp[1], maxcols);
3421 case IEEE80211_ELEMID_MESHCONF:
3422 printmeshconf(" MESHCONF", vp, 2+vp[1], maxcols);
3424 case IEEE80211_ELEMID_VHT_CAP:
3425 printvhtcap(" VHTCAP", vp, 2+vp[1], maxcols);
3427 case IEEE80211_ELEMID_VHT_OPMODE:
3428 printvhtinfo(" VHTOPMODE", vp, 2+vp[1], maxcols);
3430 case IEEE80211_ELEMID_VHT_PWR_ENV:
3431 printvhtpwrenv(" VHTPWRENV", vp, 2+vp[1], maxcols);
3433 case IEEE80211_ELEMID_BSSLOAD:
3434 printbssload(" BSSLOAD", vp, 2+vp[1], maxcols);
3436 case IEEE80211_ELEMID_APCHANREP:
3437 printapchanrep(" APCHANREP", vp, 2+vp[1], maxcols);
3441 printie(iename(vp[0]), vp, 2+vp[1], maxcols);
3450 printmimo(const struct ieee80211_mimo_info *mi)
3452 /* NB: don't muddy display unless there's something to show */
3453 if (mi->rssi[0] != 0 || mi->rssi[1] != 0 || mi->rssi[2] != 0) {
3454 /* XXX ignore EVM for now */
3455 printf(" (rssi %.1f:%.1f:%.1f nf %d:%d:%d)",
3456 mi->rssi[0] / 2.0, mi->rssi[1] / 2.0, mi->rssi[2] / 2.0,
3457 mi->noise[0], mi->noise[1], mi->noise[2]);
3464 uint8_t buf[24*1024];
3465 char ssid[IEEE80211_NWID_LEN+1];
3467 int len, ssidmax, idlen;
3469 if (get80211len(s, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0)
3470 errx(1, "unable to get scan results");
3471 if (len < sizeof(struct ieee80211req_scan_result))
3476 ssidmax = verbose ? IEEE80211_NWID_LEN : 14;
3477 printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n"
3478 , ssidmax, ssidmax, "SSID/MESH ID"
3488 const struct ieee80211req_scan_result *sr;
3489 const uint8_t *vp, *idp;
3491 sr = (const struct ieee80211req_scan_result *) cp;
3492 vp = cp + sr->isr_ie_off;
3493 if (sr->isr_meshid_len) {
3494 idp = vp + sr->isr_ssid_len;
3495 idlen = sr->isr_meshid_len;
3498 idlen = sr->isr_ssid_len;
3500 printf("%-*.*s %s %3d %3dM %4d:%-4d %4d %-4.4s"
3502 , copy_essid(ssid, ssidmax, idp, idlen)
3504 , ether_ntoa((const struct ether_addr *) sr->isr_bssid)
3505 , ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags)
3506 , getmaxrate(sr->isr_rates, sr->isr_nrates)
3507 , (sr->isr_rssi/2)+sr->isr_noise, sr->isr_noise
3509 , getcaps(sr->isr_capinfo)
3511 printies(vp + sr->isr_ssid_len + sr->isr_meshid_len,
3512 sr->isr_ie_len, 24);
3514 cp += sr->isr_len, len -= sr->isr_len;
3515 } while (len >= sizeof(struct ieee80211req_scan_result));
3519 scan_and_wait(int s)
3521 struct ieee80211_scan_req sr;
3522 struct ieee80211req ireq;
3525 sroute = socket(PF_ROUTE, SOCK_RAW, 0);
3527 perror("socket(PF_ROUTE,SOCK_RAW)");
3530 (void) memset(&ireq, 0, sizeof(ireq));
3531 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
3532 ireq.i_type = IEEE80211_IOC_SCAN_REQ;
3534 memset(&sr, 0, sizeof(sr));
3535 sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE
3536 | IEEE80211_IOC_SCAN_BGSCAN
3537 | IEEE80211_IOC_SCAN_NOPICK
3538 | IEEE80211_IOC_SCAN_ONCE;
3539 sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER;
3543 ireq.i_len = sizeof(sr);
3545 * NB: only root can trigger a scan so ignore errors. Also ignore
3546 * possible errors from net80211, even if no new scan could be
3547 * started there might still be a valid scan cache.
3549 if (ioctl(s, SIOCS80211, &ireq) == 0) {
3551 struct if_announcemsghdr *ifan;
3552 struct rt_msghdr *rtm;
3555 if (read(sroute, buf, sizeof(buf)) < 0) {
3556 perror("read(PF_ROUTE)");
3559 rtm = (struct rt_msghdr *) buf;
3560 if (rtm->rtm_version != RTM_VERSION)
3562 ifan = (struct if_announcemsghdr *) rtm;
3563 } while (rtm->rtm_type != RTM_IEEE80211 ||
3564 ifan->ifan_what != RTM_IEEE80211_SCAN);
3570 DECL_CMD_FUNC(set80211scan, val, d)
3576 static enum ieee80211_opmode get80211opmode(int s);
3579 gettxseq(const struct ieee80211req_sta_info *si)
3583 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3584 return si->isi_txseqs[0];
3585 /* XXX not right but usually what folks want */
3587 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3588 if (si->isi_txseqs[i] > txseq)
3589 txseq = si->isi_txseqs[i];
3594 getrxseq(const struct ieee80211req_sta_info *si)
3598 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3599 return si->isi_rxseqs[0];
3600 /* XXX not right but usually what folks want */
3602 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3603 if (si->isi_rxseqs[i] > rxseq)
3604 rxseq = si->isi_rxseqs[i];
3609 list_stations(int s)
3612 struct ieee80211req_sta_req req;
3613 uint8_t buf[24*1024];
3615 enum ieee80211_opmode opmode = get80211opmode(s);
3619 /* broadcast address =>'s get all stations */
3620 (void) memset(u.req.is_u.macaddr, 0xff, IEEE80211_ADDR_LEN);
3621 if (opmode == IEEE80211_M_STA) {
3623 * Get information about the associated AP.
3625 (void) get80211(s, IEEE80211_IOC_BSSID,
3626 u.req.is_u.macaddr, IEEE80211_ADDR_LEN);
3628 if (get80211len(s, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0)
3629 errx(1, "unable to get station information");
3630 if (len < sizeof(struct ieee80211req_sta_info))
3635 if (opmode == IEEE80211_M_MBSS)
3636 printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n"
3649 printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-7s\n"
3661 cp = (const uint8_t *) u.req.info;
3663 const struct ieee80211req_sta_info *si;
3665 si = (const struct ieee80211req_sta_info *) cp;
3666 if (si->isi_len < sizeof(*si))
3668 if (opmode == IEEE80211_M_MBSS)
3669 printf("%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d"
3670 , ether_ntoa((const struct ether_addr*)
3672 , ieee80211_mhz2ieee(si->isi_freq,
3676 , mesh_linkstate_string(si->isi_peerstate)
3684 printf("%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-7.7s"
3685 , ether_ntoa((const struct ether_addr*)
3687 , IEEE80211_AID(si->isi_associd)
3688 , ieee80211_mhz2ieee(si->isi_freq,
3695 , getcaps(si->isi_capinfo)
3696 , getflags(si->isi_state)
3698 printies(cp + si->isi_ie_off, si->isi_ie_len, 24);
3699 printmimo(&si->isi_mimo);
3701 cp += si->isi_len, len -= si->isi_len;
3702 } while (len >= sizeof(struct ieee80211req_sta_info));
3706 mesh_linkstate_string(uint8_t state)
3708 static const char *state_names[] = {
3717 if (state >= nitems(state_names)) {
3718 static char buf[10];
3719 snprintf(buf, sizeof(buf), "#%u", state);
3722 return state_names[state];
3726 get_chaninfo(const struct ieee80211_channel *c, int precise,
3727 char buf[], size_t bsize)
3730 if (IEEE80211_IS_CHAN_FHSS(c))
3731 strlcat(buf, " FHSS", bsize);
3732 if (IEEE80211_IS_CHAN_A(c))
3733 strlcat(buf, " 11a", bsize);
3734 else if (IEEE80211_IS_CHAN_ANYG(c))
3735 strlcat(buf, " 11g", bsize);
3736 else if (IEEE80211_IS_CHAN_B(c))
3737 strlcat(buf, " 11b", bsize);
3738 if (IEEE80211_IS_CHAN_HALF(c))
3739 strlcat(buf, "/10MHz", bsize);
3740 if (IEEE80211_IS_CHAN_QUARTER(c))
3741 strlcat(buf, "/5MHz", bsize);
3742 if (IEEE80211_IS_CHAN_TURBO(c))
3743 strlcat(buf, " Turbo", bsize);
3745 /* XXX should make VHT80U, VHT80D */
3746 if (IEEE80211_IS_CHAN_VHT80(c) &&
3747 IEEE80211_IS_CHAN_HT40D(c))
3748 strlcat(buf, " vht/80-", bsize);
3749 else if (IEEE80211_IS_CHAN_VHT80(c) &&
3750 IEEE80211_IS_CHAN_HT40U(c))
3751 strlcat(buf, " vht/80+", bsize);
3752 else if (IEEE80211_IS_CHAN_VHT80(c))
3753 strlcat(buf, " vht/80", bsize);
3754 else if (IEEE80211_IS_CHAN_VHT40D(c))
3755 strlcat(buf, " vht/40-", bsize);
3756 else if (IEEE80211_IS_CHAN_VHT40U(c))
3757 strlcat(buf, " vht/40+", bsize);
3758 else if (IEEE80211_IS_CHAN_VHT20(c))
3759 strlcat(buf, " vht/20", bsize);
3760 else if (IEEE80211_IS_CHAN_HT20(c))
3761 strlcat(buf, " ht/20", bsize);
3762 else if (IEEE80211_IS_CHAN_HT40D(c))
3763 strlcat(buf, " ht/40-", bsize);
3764 else if (IEEE80211_IS_CHAN_HT40U(c))
3765 strlcat(buf, " ht/40+", bsize);
3767 if (IEEE80211_IS_CHAN_VHT(c))
3768 strlcat(buf, " vht", bsize);
3769 else if (IEEE80211_IS_CHAN_HT(c))
3770 strlcat(buf, " ht", bsize);
3776 print_chaninfo(const struct ieee80211_channel *c, int verb)
3781 printf("Channel %3u : %u%c%c%c%c%c MHz%-14.14s",
3782 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
3783 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
3784 IEEE80211_IS_CHAN_DFS(c) ? 'D' : ' ',
3785 IEEE80211_IS_CHAN_RADAR(c) ? 'R' : ' ',
3786 IEEE80211_IS_CHAN_CWINT(c) ? 'I' : ' ',
3787 IEEE80211_IS_CHAN_CACDONE(c) ? 'C' : ' ',
3788 get_chaninfo(c, verb, buf, sizeof(buf)));
3790 printf("Channel %3u : %u%c MHz%-14.14s",
3791 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
3792 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
3793 get_chaninfo(c, verb, buf, sizeof(buf)));
3798 chanpref(const struct ieee80211_channel *c)
3800 if (IEEE80211_IS_CHAN_VHT160(c))
3802 if (IEEE80211_IS_CHAN_VHT80_80(c))
3804 if (IEEE80211_IS_CHAN_VHT80(c))
3806 if (IEEE80211_IS_CHAN_VHT40(c))
3808 if (IEEE80211_IS_CHAN_VHT20(c))
3810 if (IEEE80211_IS_CHAN_HT40(c))
3812 if (IEEE80211_IS_CHAN_HT20(c))
3814 if (IEEE80211_IS_CHAN_HALF(c))
3816 if (IEEE80211_IS_CHAN_QUARTER(c))
3818 if (IEEE80211_IS_CHAN_TURBO(c))
3820 if (IEEE80211_IS_CHAN_A(c))
3822 if (IEEE80211_IS_CHAN_G(c))
3824 if (IEEE80211_IS_CHAN_B(c))
3826 if (IEEE80211_IS_CHAN_PUREG(c))
3832 print_channels(int s, const struct ieee80211req_chaninfo *chans,
3833 int allchans, int verb)
3835 struct ieee80211req_chaninfo *achans;
3836 uint8_t reported[IEEE80211_CHAN_BYTES];
3837 const struct ieee80211_channel *c;
3840 achans = malloc(IEEE80211_CHANINFO_SPACE(chans));
3842 errx(1, "no space for active channel list");
3843 achans->ic_nchans = 0;
3844 memset(reported, 0, sizeof(reported));
3846 struct ieee80211req_chanlist active;
3848 if (get80211(s, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0)
3849 errx(1, "unable to get active channel list");
3850 for (i = 0; i < chans->ic_nchans; i++) {
3851 c = &chans->ic_chans[i];
3852 if (!isset(active.ic_channels, c->ic_ieee))
3855 * Suppress compatible duplicates unless
3856 * verbose. The kernel gives us it's
3857 * complete channel list which has separate
3858 * entries for 11g/11b and 11a/turbo.
3860 if (isset(reported, c->ic_ieee) && !verb) {
3861 /* XXX we assume duplicates are adjacent */
3862 achans->ic_chans[achans->ic_nchans-1] = *c;
3864 achans->ic_chans[achans->ic_nchans++] = *c;
3865 setbit(reported, c->ic_ieee);
3869 for (i = 0; i < chans->ic_nchans; i++) {
3870 c = &chans->ic_chans[i];
3871 /* suppress duplicates as above */
3872 if (isset(reported, c->ic_ieee) && !verb) {
3873 /* XXX we assume duplicates are adjacent */
3874 struct ieee80211_channel *a =
3875 &achans->ic_chans[achans->ic_nchans-1];
3876 if (chanpref(c) > chanpref(a))
3879 achans->ic_chans[achans->ic_nchans++] = *c;
3880 setbit(reported, c->ic_ieee);
3884 half = achans->ic_nchans / 2;
3885 if (achans->ic_nchans % 2)
3888 for (i = 0; i < achans->ic_nchans / 2; i++) {
3889 print_chaninfo(&achans->ic_chans[i], verb);
3890 print_chaninfo(&achans->ic_chans[half+i], verb);
3893 if (achans->ic_nchans % 2) {
3894 print_chaninfo(&achans->ic_chans[i], verb);
3901 list_channels(int s, int allchans)
3904 print_channels(s, chaninfo, allchans, verbose);
3908 print_txpow(const struct ieee80211_channel *c)
3910 printf("Channel %3u : %u MHz %3.1f reg %2d ",
3911 c->ic_ieee, c->ic_freq,
3912 c->ic_maxpower/2., c->ic_maxregpower);
3916 print_txpow_verbose(const struct ieee80211_channel *c)
3918 print_chaninfo(c, 1);
3919 printf("min %4.1f dBm max %3.1f dBm reg %2d dBm",
3920 c->ic_minpower/2., c->ic_maxpower/2., c->ic_maxregpower);
3921 /* indicate where regulatory cap limits power use */
3922 if (c->ic_maxpower > 2*c->ic_maxregpower)
3929 struct ieee80211req_chaninfo *achans;
3930 uint8_t reported[IEEE80211_CHAN_BYTES];
3931 struct ieee80211_channel *c, *prev;
3935 achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo));
3937 errx(1, "no space for active channel list");
3938 achans->ic_nchans = 0;
3939 memset(reported, 0, sizeof(reported));
3940 for (i = 0; i < chaninfo->ic_nchans; i++) {
3941 c = &chaninfo->ic_chans[i];
3942 /* suppress duplicates as above */
3943 if (isset(reported, c->ic_ieee) && !verbose) {
3944 /* XXX we assume duplicates are adjacent */
3945 assert(achans->ic_nchans > 0);
3946 prev = &achans->ic_chans[achans->ic_nchans-1];
3947 /* display highest power on channel */
3948 if (c->ic_maxpower > prev->ic_maxpower)
3951 achans->ic_chans[achans->ic_nchans++] = *c;
3952 setbit(reported, c->ic_ieee);
3956 half = achans->ic_nchans / 2;
3957 if (achans->ic_nchans % 2)
3960 for (i = 0; i < achans->ic_nchans / 2; i++) {
3961 print_txpow(&achans->ic_chans[i]);
3962 print_txpow(&achans->ic_chans[half+i]);
3965 if (achans->ic_nchans % 2) {
3966 print_txpow(&achans->ic_chans[i]);
3970 for (i = 0; i < achans->ic_nchans; i++) {
3971 print_txpow_verbose(&achans->ic_chans[i]);
3984 list_capabilities(int s)
3986 struct ieee80211_devcaps_req *dc;
3989 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
3991 dc = malloc(IEEE80211_DEVCAPS_SIZE(1));
3993 errx(1, "no space for device capabilities");
3994 dc->dc_chaninfo.ic_nchans = verbose ? MAXCHAN : 1;
3996 printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS);
3997 if (dc->dc_cryptocaps != 0 || verbose) {
3999 printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS);
4001 if (dc->dc_htcaps != 0 || verbose) {
4003 printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS);
4005 if (dc->dc_vhtcaps != 0 || verbose) {
4007 printb("vhtcaps", dc->dc_vhtcaps, IEEE80211_VHTCAP_BITS);
4012 chaninfo = &dc->dc_chaninfo; /* XXX */
4013 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, verbose);
4019 get80211wme(int s, int param, int ac, int *val)
4021 struct ieee80211req ireq;
4023 (void) memset(&ireq, 0, sizeof(ireq));
4024 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4025 ireq.i_type = param;
4027 if (ioctl(s, SIOCG80211, &ireq) < 0) {
4028 warn("cannot get WME parameter %d, ac %d%s",
4029 param, ac & IEEE80211_WMEPARAM_VAL,
4030 ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : "");
4038 list_wme_aci(int s, const char *tag, int ac)
4042 printf("\t%s", tag);
4044 /* show WME BSS parameters */
4045 if (get80211wme(s, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1)
4046 printf(" cwmin %2u", val);
4047 if (get80211wme(s, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1)
4048 printf(" cwmax %2u", val);
4049 if (get80211wme(s, IEEE80211_IOC_WME_AIFS, ac, &val) != -1)
4050 printf(" aifs %2u", val);
4051 if (get80211wme(s, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1)
4052 printf(" txopLimit %3u", val);
4053 if (get80211wme(s, IEEE80211_IOC_WME_ACM, ac, &val) != -1) {
4060 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
4061 if (get80211wme(s, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) {
4074 static const char *acnames[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
4078 /* display both BSS and local settings */
4079 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) {
4081 if (ac & IEEE80211_WMEPARAM_BSS)
4082 list_wme_aci(s, " ", ac);
4084 list_wme_aci(s, acnames[ac], ac);
4085 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
4086 ac |= IEEE80211_WMEPARAM_BSS;
4089 ac &= ~IEEE80211_WMEPARAM_BSS;
4092 /* display only channel settings */
4093 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++)
4094 list_wme_aci(s, acnames[ac], ac);
4101 const struct ieee80211_roamparam *rp;
4105 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
4106 rp = &roamparams.params[mode];
4107 if (rp->rssi == 0 && rp->rate == 0)
4109 if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) {
4111 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm MCS %2u ",
4112 modename[mode], rp->rssi/2,
4113 rp->rate &~ IEEE80211_RATE_MCS);
4115 LINE_CHECK("roam:%-7.7s rssi %4udBm MCS %2u ",
4116 modename[mode], rp->rssi/2,
4117 rp->rate &~ IEEE80211_RATE_MCS);
4120 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s",
4121 modename[mode], rp->rssi/2, rp->rate/2);
4123 LINE_CHECK("roam:%-7.7s rssi %4udBm rate %2u Mb/s",
4124 modename[mode], rp->rssi/2, rp->rate/2);
4130 list_txparams(int s)
4132 const struct ieee80211_txparam *tp;
4136 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
4137 tp = &txparams.params[mode];
4138 if (tp->mgmtrate == 0 && tp->mcastrate == 0)
4140 if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) {
4141 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
4142 LINE_CHECK("%-7.7s ucast NONE mgmt %2u MCS "
4143 "mcast %2u MCS maxretry %u",
4145 tp->mgmtrate &~ IEEE80211_RATE_MCS,
4146 tp->mcastrate &~ IEEE80211_RATE_MCS,
4149 LINE_CHECK("%-7.7s ucast %2u MCS mgmt %2u MCS "
4150 "mcast %2u MCS maxretry %u",
4152 tp->ucastrate &~ IEEE80211_RATE_MCS,
4153 tp->mgmtrate &~ IEEE80211_RATE_MCS,
4154 tp->mcastrate &~ IEEE80211_RATE_MCS,
4157 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
4158 LINE_CHECK("%-7.7s ucast NONE mgmt %2u Mb/s "
4159 "mcast %2u Mb/s maxretry %u",
4162 tp->mcastrate/2, tp->maxretry);
4164 LINE_CHECK("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s "
4165 "mcast %2u Mb/s maxretry %u",
4167 tp->ucastrate/2, tp->mgmtrate/2,
4168 tp->mcastrate/2, tp->maxretry);
4174 printpolicy(int policy)
4177 case IEEE80211_MACCMD_POLICY_OPEN:
4178 printf("policy: open\n");
4180 case IEEE80211_MACCMD_POLICY_ALLOW:
4181 printf("policy: allow\n");
4183 case IEEE80211_MACCMD_POLICY_DENY:
4184 printf("policy: deny\n");
4186 case IEEE80211_MACCMD_POLICY_RADIUS:
4187 printf("policy: radius\n");
4190 printf("policy: unknown (%u)\n", policy);
4198 struct ieee80211req ireq;
4199 struct ieee80211req_maclist *acllist;
4200 int i, nacls, policy, len;
4204 (void) memset(&ireq, 0, sizeof(ireq));
4205 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name)); /* XXX ?? */
4206 ireq.i_type = IEEE80211_IOC_MACCMD;
4207 ireq.i_val = IEEE80211_MACCMD_POLICY;
4208 if (ioctl(s, SIOCG80211, &ireq) < 0) {
4209 if (errno == EINVAL) {
4210 printf("No acl policy loaded\n");
4213 err(1, "unable to get mac policy");
4215 policy = ireq.i_val;
4216 if (policy == IEEE80211_MACCMD_POLICY_OPEN) {
4218 } else if (policy == IEEE80211_MACCMD_POLICY_ALLOW) {
4220 } else if (policy == IEEE80211_MACCMD_POLICY_DENY) {
4222 } else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) {
4223 c = 'r'; /* NB: should never have entries */
4225 printf("policy: unknown (%u)\n", policy);
4228 if (verbose || c == '?')
4229 printpolicy(policy);
4231 ireq.i_val = IEEE80211_MACCMD_LIST;
4233 if (ioctl(s, SIOCG80211, &ireq) < 0)
4234 err(1, "unable to get mac acl list size");
4235 if (ireq.i_len == 0) { /* NB: no acls */
4236 if (!(verbose || c == '?'))
4237 printpolicy(policy);
4244 err(1, "out of memory for acl list");
4247 if (ioctl(s, SIOCG80211, &ireq) < 0)
4248 err(1, "unable to get mac acl list");
4249 nacls = len / sizeof(*acllist);
4250 acllist = (struct ieee80211req_maclist *) data;
4251 for (i = 0; i < nacls; i++)
4252 printf("%c%s\n", c, ether_ntoa(
4253 (const struct ether_addr *) acllist[i].ml_macaddr));
4258 print_regdomain(const struct ieee80211_regdomain *reg, int verb)
4260 if ((reg->regdomain != 0 &&
4261 reg->regdomain != reg->country) || verb) {
4262 const struct regdomain *rd =
4263 lib80211_regdomain_findbysku(getregdata(), reg->regdomain);
4265 LINE_CHECK("regdomain %d", reg->regdomain);
4267 LINE_CHECK("regdomain %s", rd->name);
4269 if (reg->country != 0 || verb) {
4270 const struct country *cc =
4271 lib80211_country_findbycc(getregdata(), reg->country);
4273 LINE_CHECK("country %d", reg->country);
4275 LINE_CHECK("country %s", cc->isoname);
4277 if (reg->location == 'I')
4278 LINE_CHECK("indoor");
4279 else if (reg->location == 'O')
4280 LINE_CHECK("outdoor");
4282 LINE_CHECK("anywhere");
4290 list_regdomain(int s, int channelsalso)
4296 print_regdomain(®domain, 1);
4298 print_channels(s, chaninfo, 1/*allchans*/, 1/*verbose*/);
4300 print_regdomain(®domain, verbose);
4306 struct ieee80211req ireq;
4307 struct ieee80211req_mesh_route routes[128];
4308 struct ieee80211req_mesh_route *rt;
4310 (void) memset(&ireq, 0, sizeof(ireq));
4311 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4312 ireq.i_type = IEEE80211_IOC_MESH_RTCMD;
4313 ireq.i_val = IEEE80211_MESH_RTCMD_LIST;
4314 ireq.i_data = &routes;
4315 ireq.i_len = sizeof(routes);
4316 if (ioctl(s, SIOCG80211, &ireq) < 0)
4317 err(1, "unable to get the Mesh routing table");
4319 printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n"
4328 for (rt = &routes[0]; rt - &routes[0] < ireq.i_len / sizeof(*rt); rt++){
4330 ether_ntoa((const struct ether_addr *)rt->imr_dest));
4331 printf("%s %4u %4u %6u %6u %c%c\n",
4332 ether_ntoa((const struct ether_addr *)rt->imr_nexthop),
4333 rt->imr_nhops, rt->imr_metric, rt->imr_lifetime,
4335 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_DISCOVER) ?
4337 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_VALID) ?
4339 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ?
4341 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_GATE) ?
4347 DECL_CMD_FUNC(set80211list, arg, d)
4349 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
4353 if (iseq(arg, "sta"))
4355 else if (iseq(arg, "scan") || iseq(arg, "ap"))
4357 else if (iseq(arg, "chan") || iseq(arg, "freq"))
4358 list_channels(s, 1);
4359 else if (iseq(arg, "active"))
4360 list_channels(s, 0);
4361 else if (iseq(arg, "keys"))
4363 else if (iseq(arg, "caps"))
4364 list_capabilities(s);
4365 else if (iseq(arg, "wme") || iseq(arg, "wmm"))
4367 else if (iseq(arg, "mac"))
4369 else if (iseq(arg, "txpow"))
4371 else if (iseq(arg, "roam"))
4373 else if (iseq(arg, "txparam") || iseq(arg, "txparm"))
4375 else if (iseq(arg, "regdomain"))
4376 list_regdomain(s, 1);
4377 else if (iseq(arg, "countries"))
4379 else if (iseq(arg, "mesh"))
4382 errx(1, "Don't know how to list %s for %s", arg, name);
4387 static enum ieee80211_opmode
4388 get80211opmode(int s)
4390 struct ifmediareq ifmr;
4392 (void) memset(&ifmr, 0, sizeof(ifmr));
4393 (void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
4395 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) {
4396 if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) {
4397 if (ifmr.ifm_current & IFM_FLAG0)
4398 return IEEE80211_M_AHDEMO;
4400 return IEEE80211_M_IBSS;
4402 if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP)
4403 return IEEE80211_M_HOSTAP;
4404 if (ifmr.ifm_current & IFM_IEEE80211_IBSS)
4405 return IEEE80211_M_IBSS;
4406 if (ifmr.ifm_current & IFM_IEEE80211_MONITOR)
4407 return IEEE80211_M_MONITOR;
4408 if (ifmr.ifm_current & IFM_IEEE80211_MBSS)
4409 return IEEE80211_M_MBSS;
4411 return IEEE80211_M_STA;
4416 printcipher(int s, struct ieee80211req *ireq, int keylenop)
4418 switch (ireq->i_val) {
4419 case IEEE80211_CIPHER_WEP:
4420 ireq->i_type = keylenop;
4421 if (ioctl(s, SIOCG80211, ireq) != -1)
4423 ireq->i_len <= 5 ? "40" :
4424 ireq->i_len <= 13 ? "104" : "128");
4428 case IEEE80211_CIPHER_TKIP:
4431 case IEEE80211_CIPHER_AES_OCB:
4434 case IEEE80211_CIPHER_AES_CCM:
4437 case IEEE80211_CIPHER_CKIP:
4440 case IEEE80211_CIPHER_NONE:
4444 printf("UNKNOWN (0x%x)", ireq->i_val);
4451 printkey(const struct ieee80211req_key *ik)
4453 static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
4454 u_int keylen = ik->ik_keylen;
4457 printcontents = printkeys &&
4458 (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose);
4461 switch (ik->ik_type) {
4462 case IEEE80211_CIPHER_WEP:
4464 LINE_CHECK("wepkey %u:%s", ik->ik_keyix+1,
4465 keylen <= 5 ? "40-bit" :
4466 keylen <= 13 ? "104-bit" : "128-bit");
4468 case IEEE80211_CIPHER_TKIP:
4470 keylen -= 128/8; /* ignore MIC for now */
4471 LINE_CHECK("TKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4473 case IEEE80211_CIPHER_AES_OCB:
4474 LINE_CHECK("AES-OCB %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4476 case IEEE80211_CIPHER_AES_CCM:
4477 LINE_CHECK("AES-CCM %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4479 case IEEE80211_CIPHER_CKIP:
4480 LINE_CHECK("CKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4482 case IEEE80211_CIPHER_NONE:
4483 LINE_CHECK("NULL %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4486 LINE_CHECK("UNKNOWN (0x%x) %u:%u-bit",
4487 ik->ik_type, ik->ik_keyix+1, 8*keylen);
4490 if (printcontents) {
4494 for (i = 0; i < keylen; i++)
4495 printf("%02x", ik->ik_keydata[i]);
4497 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4498 (ik->ik_keyrsc != 0 || verbose))
4499 printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc);
4500 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4501 (ik->ik_keytsc != 0 || verbose))
4502 printf(" tsc %ju", (uintmax_t)ik->ik_keytsc);
4503 if (ik->ik_flags != 0 && verbose) {
4504 const char *sep = " ";
4506 if (ik->ik_flags & IEEE80211_KEY_XMIT)
4507 printf("%stx", sep), sep = "+";
4508 if (ik->ik_flags & IEEE80211_KEY_RECV)
4509 printf("%srx", sep), sep = "+";
4510 if (ik->ik_flags & IEEE80211_KEY_DEFAULT)
4511 printf("%sdef", sep), sep = "+";
4518 printrate(const char *tag, int v, int defrate, int defmcs)
4520 if ((v & IEEE80211_RATE_MCS) == 0) {
4523 LINE_CHECK("%s %d.5", tag, v/2);
4525 LINE_CHECK("%s %d", tag, v/2);
4529 LINE_CHECK("%s %d", tag, v &~ 0x80);
4534 getid(int s, int ix, void *data, size_t len, int *plen, int mesh)
4536 struct ieee80211req ireq;
4538 (void) memset(&ireq, 0, sizeof(ireq));
4539 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4540 ireq.i_type = (!mesh) ? IEEE80211_IOC_SSID : IEEE80211_IOC_MESH_ID;
4544 if (ioctl(s, SIOCG80211, &ireq) < 0)
4551 ieee80211_status(int s)
4553 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
4554 enum ieee80211_opmode opmode = get80211opmode(s);
4555 int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode;
4557 const struct ieee80211_channel *c;
4558 const struct ieee80211_roamparam *rp;
4559 const struct ieee80211_txparam *tp;
4561 if (getid(s, -1, data, sizeof(data), &len, 0) < 0) {
4562 /* If we can't get the SSID, this isn't an 802.11 device. */
4567 * Invalidate cached state so printing status for multiple
4568 * if's doesn't reuse the first interfaces' cached state.
4577 if (opmode == IEEE80211_M_MBSS) {
4579 getid(s, 0, data, sizeof(data), &len, 1);
4580 print_string(data, len);
4582 if (get80211val(s, IEEE80211_IOC_NUMSSIDS, &num) < 0)
4586 for (i = 0; i < num; i++) {
4587 if (getid(s, i, data, sizeof(data), &len, 0) >= 0 && len > 0) {
4588 printf(" %d:", i + 1);
4589 print_string(data, len);
4593 print_string(data, len);
4596 if (c->ic_freq != IEEE80211_CHAN_ANY) {
4598 printf(" channel %d (%u MHz%s)", c->ic_ieee, c->ic_freq,
4599 get_chaninfo(c, 1, buf, sizeof(buf)));
4601 printf(" channel UNDEF");
4603 if (get80211(s, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 &&
4604 (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose))
4605 printf(" bssid %s", ether_ntoa((struct ether_addr *)data));
4607 if (get80211len(s, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) {
4608 printf("\n\tstationname ");
4609 print_string(data, len);
4612 spacer = ' '; /* force first break */
4615 list_regdomain(s, 0);
4618 if (get80211val(s, IEEE80211_IOC_AUTHMODE, &val) != -1) {
4620 case IEEE80211_AUTH_NONE:
4621 LINE_CHECK("authmode NONE");
4623 case IEEE80211_AUTH_OPEN:
4624 LINE_CHECK("authmode OPEN");
4626 case IEEE80211_AUTH_SHARED:
4627 LINE_CHECK("authmode SHARED");
4629 case IEEE80211_AUTH_8021X:
4630 LINE_CHECK("authmode 802.1x");
4632 case IEEE80211_AUTH_WPA:
4633 if (get80211val(s, IEEE80211_IOC_WPA, &wpa) < 0)
4634 wpa = 1; /* default to WPA1 */
4637 LINE_CHECK("authmode WPA2/802.11i");
4640 LINE_CHECK("authmode WPA1+WPA2/802.11i");
4643 LINE_CHECK("authmode WPA");
4647 case IEEE80211_AUTH_AUTO:
4648 LINE_CHECK("authmode AUTO");
4651 LINE_CHECK("authmode UNKNOWN (0x%x)", val);
4656 if (wpa || verbose) {
4657 if (get80211val(s, IEEE80211_IOC_WPS, &val) != -1) {
4663 if (get80211val(s, IEEE80211_IOC_TSN, &val) != -1) {
4669 if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) {
4671 LINE_CHECK("countermeasures");
4673 LINE_CHECK("-countermeasures");
4676 /* XXX not interesting with WPA done in user space */
4677 ireq.i_type = IEEE80211_IOC_KEYMGTALGS;
4678 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4681 ireq.i_type = IEEE80211_IOC_MCASTCIPHER;
4682 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4683 LINE_CHECK("mcastcipher ");
4684 printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN);
4688 ireq.i_type = IEEE80211_IOC_UCASTCIPHER;
4689 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4690 LINE_CHECK("ucastcipher ");
4691 printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN);
4695 ireq.i_type = IEEE80211_IOC_RSNCAPS;
4696 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4697 LINE_CHECK("RSN caps 0x%x", ireq.i_val);
4702 ireq.i_type = IEEE80211_IOC_UCASTCIPHERS;
4703 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4708 if (get80211val(s, IEEE80211_IOC_WEP, &wepmode) != -1 &&
4709 wepmode != IEEE80211_WEP_NOSUP) {
4712 case IEEE80211_WEP_OFF:
4713 LINE_CHECK("privacy OFF");
4715 case IEEE80211_WEP_ON:
4716 LINE_CHECK("privacy ON");
4718 case IEEE80211_WEP_MIXED:
4719 LINE_CHECK("privacy MIXED");
4722 LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode);
4727 * If we get here then we've got WEP support so we need
4728 * to print WEP status.
4731 if (get80211val(s, IEEE80211_IOC_WEPTXKEY, &val) < 0) {
4732 warn("WEP support, but no tx key!");
4736 LINE_CHECK("deftxkey %d", val+1);
4737 else if (wepmode != IEEE80211_WEP_OFF || verbose)
4738 LINE_CHECK("deftxkey UNDEF");
4740 if (get80211val(s, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) {
4741 warn("WEP support, but no NUMWEPKEYS support!");
4745 for (i = 0; i < num; i++) {
4746 struct ieee80211req_key ik;
4748 memset(&ik, 0, sizeof(ik));
4750 if (get80211(s, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) {
4751 warn("WEP support, but can get keys!");
4754 if (ik.ik_keylen != 0) {
4764 if (get80211val(s, IEEE80211_IOC_POWERSAVE, &val) != -1 &&
4765 val != IEEE80211_POWERSAVE_NOSUP ) {
4766 if (val != IEEE80211_POWERSAVE_OFF || verbose) {
4768 case IEEE80211_POWERSAVE_OFF:
4769 LINE_CHECK("powersavemode OFF");
4771 case IEEE80211_POWERSAVE_CAM:
4772 LINE_CHECK("powersavemode CAM");
4774 case IEEE80211_POWERSAVE_PSP:
4775 LINE_CHECK("powersavemode PSP");
4777 case IEEE80211_POWERSAVE_PSP_CAM:
4778 LINE_CHECK("powersavemode PSP-CAM");
4781 if (get80211val(s, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1)
4782 LINE_CHECK("powersavesleep %d", val);
4786 if (get80211val(s, IEEE80211_IOC_TXPOWER, &val) != -1) {
4788 LINE_CHECK("txpower %d.5", val/2);
4790 LINE_CHECK("txpower %d", val/2);
4793 if (get80211val(s, IEEE80211_IOC_TXPOWMAX, &val) != -1)
4794 LINE_CHECK("txpowmax %.1f", val/2.);
4797 if (get80211val(s, IEEE80211_IOC_DOTD, &val) != -1) {
4801 LINE_CHECK("-dotd");
4804 if (get80211val(s, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) {
4805 if (val != IEEE80211_RTS_MAX || verbose)
4806 LINE_CHECK("rtsthreshold %d", val);
4809 if (get80211val(s, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) {
4810 if (val != IEEE80211_FRAG_MAX || verbose)
4811 LINE_CHECK("fragthreshold %d", val);
4813 if (opmode == IEEE80211_M_STA || verbose) {
4814 if (get80211val(s, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) {
4815 if (val != IEEE80211_HWBMISS_MAX || verbose)
4816 LINE_CHECK("bmiss %d", val);
4822 tp = &txparams.params[chan2mode(c)];
4823 printrate("ucastrate", tp->ucastrate,
4824 IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE);
4825 printrate("mcastrate", tp->mcastrate, 2*1,
4826 IEEE80211_RATE_MCS|0);
4827 printrate("mgmtrate", tp->mgmtrate, 2*1,
4828 IEEE80211_RATE_MCS|0);
4829 if (tp->maxretry != 6) /* XXX */
4830 LINE_CHECK("maxretry %d", tp->maxretry);
4836 bgscaninterval = -1;
4837 (void) get80211val(s, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval);
4839 if (get80211val(s, IEEE80211_IOC_SCANVALID, &val) != -1) {
4840 if (val != bgscaninterval || verbose)
4841 LINE_CHECK("scanvalid %u", val);
4845 if (get80211val(s, IEEE80211_IOC_BGSCAN, &bgscan) != -1) {
4847 LINE_CHECK("bgscan");
4849 LINE_CHECK("-bgscan");
4851 if (bgscan || verbose) {
4852 if (bgscaninterval != -1)
4853 LINE_CHECK("bgscanintvl %u", bgscaninterval);
4854 if (get80211val(s, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1)
4855 LINE_CHECK("bgscanidle %u", val);
4858 rp = &roamparams.params[chan2mode(c)];
4860 LINE_CHECK("roam:rssi %u.5", rp->rssi/2);
4862 LINE_CHECK("roam:rssi %u", rp->rssi/2);
4863 LINE_CHECK("roam:rate %u", rp->rate/2);
4871 if (IEEE80211_IS_CHAN_ANYG(c) || verbose) {
4872 if (get80211val(s, IEEE80211_IOC_PUREG, &val) != -1) {
4874 LINE_CHECK("pureg");
4876 LINE_CHECK("-pureg");
4878 if (get80211val(s, IEEE80211_IOC_PROTMODE, &val) != -1) {
4880 case IEEE80211_PROTMODE_OFF:
4881 LINE_CHECK("protmode OFF");
4883 case IEEE80211_PROTMODE_CTS:
4884 LINE_CHECK("protmode CTS");
4886 case IEEE80211_PROTMODE_RTSCTS:
4887 LINE_CHECK("protmode RTSCTS");
4890 LINE_CHECK("protmode UNKNOWN (0x%x)", val);
4896 if (IEEE80211_IS_CHAN_HT(c) || verbose) {
4898 switch (htconf & 3) {
4911 if (get80211val(s, IEEE80211_IOC_HTCOMPAT, &val) != -1) {
4913 LINE_CHECK("-htcompat");
4915 LINE_CHECK("htcompat");
4917 if (get80211val(s, IEEE80211_IOC_AMPDU, &val) != -1) {
4920 LINE_CHECK("-ampdu");
4923 LINE_CHECK("ampdutx -ampdurx");
4926 LINE_CHECK("-ampdutx ampdurx");
4930 LINE_CHECK("ampdu");
4934 if (get80211val(s, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) {
4936 case IEEE80211_HTCAP_MAXRXAMPDU_8K:
4937 LINE_CHECK("ampdulimit 8k");
4939 case IEEE80211_HTCAP_MAXRXAMPDU_16K:
4940 LINE_CHECK("ampdulimit 16k");
4942 case IEEE80211_HTCAP_MAXRXAMPDU_32K:
4943 LINE_CHECK("ampdulimit 32k");
4945 case IEEE80211_HTCAP_MAXRXAMPDU_64K:
4946 LINE_CHECK("ampdulimit 64k");
4950 if (get80211val(s, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) {
4952 case IEEE80211_HTCAP_MPDUDENSITY_NA:
4954 LINE_CHECK("ampdudensity NA");
4956 case IEEE80211_HTCAP_MPDUDENSITY_025:
4957 LINE_CHECK("ampdudensity .25");
4959 case IEEE80211_HTCAP_MPDUDENSITY_05:
4960 LINE_CHECK("ampdudensity .5");
4962 case IEEE80211_HTCAP_MPDUDENSITY_1:
4963 LINE_CHECK("ampdudensity 1");
4965 case IEEE80211_HTCAP_MPDUDENSITY_2:
4966 LINE_CHECK("ampdudensity 2");
4968 case IEEE80211_HTCAP_MPDUDENSITY_4:
4969 LINE_CHECK("ampdudensity 4");
4971 case IEEE80211_HTCAP_MPDUDENSITY_8:
4972 LINE_CHECK("ampdudensity 8");
4974 case IEEE80211_HTCAP_MPDUDENSITY_16:
4975 LINE_CHECK("ampdudensity 16");
4979 if (get80211val(s, IEEE80211_IOC_AMSDU, &val) != -1) {
4982 LINE_CHECK("-amsdu");
4985 LINE_CHECK("amsdutx -amsdurx");
4988 LINE_CHECK("-amsdutx amsdurx");
4992 LINE_CHECK("amsdu");
4996 /* XXX amsdu limit */
4997 if (get80211val(s, IEEE80211_IOC_SHORTGI, &val) != -1) {
4999 LINE_CHECK("shortgi");
5001 LINE_CHECK("-shortgi");
5003 if (get80211val(s, IEEE80211_IOC_HTPROTMODE, &val) != -1) {
5004 if (val == IEEE80211_PROTMODE_OFF)
5005 LINE_CHECK("htprotmode OFF");
5006 else if (val != IEEE80211_PROTMODE_RTSCTS)
5007 LINE_CHECK("htprotmode UNKNOWN (0x%x)", val);
5009 LINE_CHECK("htprotmode RTSCTS");
5011 if (get80211val(s, IEEE80211_IOC_PUREN, &val) != -1) {
5013 LINE_CHECK("puren");
5015 LINE_CHECK("-puren");
5017 if (get80211val(s, IEEE80211_IOC_SMPS, &val) != -1) {
5018 if (val == IEEE80211_HTCAP_SMPS_DYNAMIC)
5019 LINE_CHECK("smpsdyn");
5020 else if (val == IEEE80211_HTCAP_SMPS_ENA)
5023 LINE_CHECK("-smps");
5025 if (get80211val(s, IEEE80211_IOC_RIFS, &val) != -1) {
5029 LINE_CHECK("-rifs");
5031 if (get80211val(s, IEEE80211_IOC_STBC, &val) != -1) {
5034 LINE_CHECK("-stbc");
5037 LINE_CHECK("stbctx -stbcrx");
5040 LINE_CHECK("-stbctx stbcrx");
5048 if (get80211val(s, IEEE80211_IOC_LDPC, &val) != -1) {
5051 LINE_CHECK("-ldpc");
5054 LINE_CHECK("ldpctx -ldpcrx");
5057 LINE_CHECK("-ldpctx ldpcrx");
5067 if (IEEE80211_IS_CHAN_VHT(c) || verbose) {
5074 LINE_CHECK("vht40");
5076 LINE_CHECK("-vht40");
5078 LINE_CHECK("vht80");
5080 LINE_CHECK("-vht80");
5082 LINE_CHECK("vht80p80");
5084 LINE_CHECK("-vht80p80");
5086 LINE_CHECK("vht160");
5088 LINE_CHECK("-vht160");
5091 if (get80211val(s, IEEE80211_IOC_WME, &wme) != -1) {
5099 if (get80211val(s, IEEE80211_IOC_BURST, &val) != -1) {
5101 LINE_CHECK("burst");
5103 LINE_CHECK("-burst");
5106 if (get80211val(s, IEEE80211_IOC_FF, &val) != -1) {
5112 if (get80211val(s, IEEE80211_IOC_TURBOP, &val) != -1) {
5114 LINE_CHECK("dturbo");
5116 LINE_CHECK("-dturbo");
5118 if (get80211val(s, IEEE80211_IOC_DWDS, &val) != -1) {
5122 LINE_CHECK("-dwds");
5125 if (opmode == IEEE80211_M_HOSTAP) {
5126 if (get80211val(s, IEEE80211_IOC_HIDESSID, &val) != -1) {
5128 LINE_CHECK("hidessid");
5130 LINE_CHECK("-hidessid");
5132 if (get80211val(s, IEEE80211_IOC_APBRIDGE, &val) != -1) {
5134 LINE_CHECK("-apbridge");
5136 LINE_CHECK("apbridge");
5138 if (get80211val(s, IEEE80211_IOC_DTIM_PERIOD, &val) != -1)
5139 LINE_CHECK("dtimperiod %u", val);
5141 if (get80211val(s, IEEE80211_IOC_DOTH, &val) != -1) {
5143 LINE_CHECK("-doth");
5147 if (get80211val(s, IEEE80211_IOC_DFS, &val) != -1) {
5153 if (get80211val(s, IEEE80211_IOC_INACTIVITY, &val) != -1) {
5155 LINE_CHECK("-inact");
5157 LINE_CHECK("inact");
5160 if (get80211val(s, IEEE80211_IOC_ROAMING, &val) != -1) {
5161 if (val != IEEE80211_ROAMING_AUTO || verbose) {
5163 case IEEE80211_ROAMING_DEVICE:
5164 LINE_CHECK("roaming DEVICE");
5166 case IEEE80211_ROAMING_AUTO:
5167 LINE_CHECK("roaming AUTO");
5169 case IEEE80211_ROAMING_MANUAL:
5170 LINE_CHECK("roaming MANUAL");
5173 LINE_CHECK("roaming UNKNOWN (0x%x)",
5181 if (opmode == IEEE80211_M_AHDEMO) {
5182 if (get80211val(s, IEEE80211_IOC_TDMA_SLOT, &val) != -1)
5183 LINE_CHECK("tdmaslot %u", val);
5184 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1)
5185 LINE_CHECK("tdmaslotcnt %u", val);
5186 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1)
5187 LINE_CHECK("tdmaslotlen %u", val);
5188 if (get80211val(s, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1)
5189 LINE_CHECK("tdmabintval %u", val);
5190 } else if (get80211val(s, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) {
5191 /* XXX default define not visible */
5192 if (val != 100 || verbose)
5193 LINE_CHECK("bintval %u", val);
5196 if (wme && verbose) {
5201 if (opmode == IEEE80211_M_MBSS) {
5202 if (get80211val(s, IEEE80211_IOC_MESH_TTL, &val) != -1) {
5203 LINE_CHECK("meshttl %u", val);
5205 if (get80211val(s, IEEE80211_IOC_MESH_AP, &val) != -1) {
5207 LINE_CHECK("meshpeering");
5209 LINE_CHECK("-meshpeering");
5211 if (get80211val(s, IEEE80211_IOC_MESH_FWRD, &val) != -1) {
5213 LINE_CHECK("meshforward");
5215 LINE_CHECK("-meshforward");
5217 if (get80211val(s, IEEE80211_IOC_MESH_GATE, &val) != -1) {
5219 LINE_CHECK("meshgate");
5221 LINE_CHECK("-meshgate");
5223 if (get80211len(s, IEEE80211_IOC_MESH_PR_METRIC, data, 12,
5226 LINE_CHECK("meshmetric %s", data);
5228 if (get80211len(s, IEEE80211_IOC_MESH_PR_PATH, data, 12,
5231 LINE_CHECK("meshpath %s", data);
5233 if (get80211val(s, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) {
5235 case IEEE80211_HWMP_ROOTMODE_DISABLED:
5236 LINE_CHECK("hwmprootmode DISABLED");
5238 case IEEE80211_HWMP_ROOTMODE_NORMAL:
5239 LINE_CHECK("hwmprootmode NORMAL");
5241 case IEEE80211_HWMP_ROOTMODE_PROACTIVE:
5242 LINE_CHECK("hwmprootmode PROACTIVE");
5244 case IEEE80211_HWMP_ROOTMODE_RANN:
5245 LINE_CHECK("hwmprootmode RANN");
5248 LINE_CHECK("hwmprootmode UNKNOWN(%d)", val);
5252 if (get80211val(s, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) {
5253 LINE_CHECK("hwmpmaxhops %u", val);
5261 get80211(int s, int type, void *data, int len)
5264 return (lib80211_get80211(s, name, type, data, len));
5268 get80211len(int s, int type, void *data, int len, int *plen)
5271 return (lib80211_get80211len(s, name, type, data, len, plen));
5275 get80211val(int s, int type, int *val)
5278 return (lib80211_get80211val(s, name, type, val));
5282 set80211(int s, int type, int val, int len, void *data)
5286 ret = lib80211_set80211(s, name, type, val, len, data);
5288 err(1, "SIOCS80211");
5292 get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
5300 hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x');
5306 if (sep != NULL && strchr(sep, *val) != NULL) {
5311 if (!isxdigit((u_char)val[0])) {
5312 warnx("bad hexadecimal digits");
5315 if (!isxdigit((u_char)val[1])) {
5316 warnx("odd count hexadecimal digits");
5320 if (p >= buf + len) {
5322 warnx("hexadecimal digits too long");
5324 warnx("string too long");
5328 #define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
5329 *p++ = (tohex((u_char)val[0]) << 4) |
5330 tohex((u_char)val[1]);
5337 /* The string "-" is treated as the empty string. */
5338 if (!hexstr && len == 1 && buf[0] == '-') {
5340 memset(buf, 0, *lenp);
5341 } else if (len < *lenp)
5342 memset(p, 0, *lenp - len);
5348 print_string(const u_int8_t *buf, int len)
5355 for (; i < len; i++) {
5356 if (!isprint(buf[i]) && buf[i] != '\0')
5358 if (isspace(buf[i]))
5362 if (hasspc || len == 0 || buf[0] == '\0')
5363 printf("\"%.*s\"", len, buf);
5365 printf("%.*s", len, buf);
5368 for (i = 0; i < len; i++)
5369 printf("%02x", buf[i]);
5374 setdefregdomain(int s)
5376 struct regdata *rdp = getregdata();
5377 const struct regdomain *rd;
5379 /* Check if regdomain/country was already set by a previous call. */
5380 /* XXX is it possible? */
5381 if (regdomain.regdomain != 0 ||
5382 regdomain.country != CTRY_DEFAULT)
5387 /* Check if it was already set by the driver. */
5388 if (regdomain.regdomain != 0 ||
5389 regdomain.country != CTRY_DEFAULT)
5392 /* Set FCC/US as default. */
5393 rd = lib80211_regdomain_findbysku(rdp, SKU_FCC);
5395 errx(1, "FCC regdomain was not found");
5397 regdomain.regdomain = rd->sku;
5401 /* Send changes to net80211. */
5402 setregdomain_cb(s, ®domain);
5404 /* Cleanup (so it can be overriden by subsequent parameters). */
5405 regdomain.regdomain = 0;
5406 regdomain.country = CTRY_DEFAULT;
5407 regdomain.isocc[0] = 0;
5408 regdomain.isocc[1] = 0;
5412 * Virtual AP cloning support.
5414 static struct ieee80211_clone_params params = {
5415 .icp_opmode = IEEE80211_M_STA, /* default to station mode */
5419 wlan_create(int s, struct ifreq *ifr)
5421 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
5422 char orig_name[IFNAMSIZ];
5424 if (params.icp_parent[0] == '\0')
5425 errx(1, "must specify a parent device (wlandev) when creating "
5427 if (params.icp_opmode == IEEE80211_M_WDS &&
5428 memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0)
5429 errx(1, "no bssid specified for WDS (use wlanbssid)");
5430 ifr->ifr_data = (caddr_t) ¶ms;
5431 if (ioctl(s, SIOCIFCREATE2, ifr) < 0)
5432 err(1, "SIOCIFCREATE2");
5434 /* XXX preserve original name for ifclonecreate(). */
5435 strlcpy(orig_name, name, sizeof(orig_name));
5436 strlcpy(name, ifr->ifr_name, sizeof(name));
5440 strlcpy(name, orig_name, sizeof(name));
5444 DECL_CMD_FUNC(set80211clone_wlandev, arg, d)
5446 strlcpy(params.icp_parent, arg, IFNAMSIZ);
5450 DECL_CMD_FUNC(set80211clone_wlanbssid, arg, d)
5452 const struct ether_addr *ea;
5454 ea = ether_aton(arg);
5456 errx(1, "%s: cannot parse bssid", arg);
5457 memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN);
5461 DECL_CMD_FUNC(set80211clone_wlanaddr, arg, d)
5463 const struct ether_addr *ea;
5465 ea = ether_aton(arg);
5467 errx(1, "%s: cannot parse address", arg);
5468 memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN);
5469 params.icp_flags |= IEEE80211_CLONE_MACADDR;
5473 DECL_CMD_FUNC(set80211clone_wlanmode, arg, d)
5475 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
5476 if (iseq(arg, "sta"))
5477 params.icp_opmode = IEEE80211_M_STA;
5478 else if (iseq(arg, "ahdemo") || iseq(arg, "adhoc-demo"))
5479 params.icp_opmode = IEEE80211_M_AHDEMO;
5480 else if (iseq(arg, "ibss") || iseq(arg, "adhoc"))
5481 params.icp_opmode = IEEE80211_M_IBSS;
5482 else if (iseq(arg, "ap") || iseq(arg, "host"))
5483 params.icp_opmode = IEEE80211_M_HOSTAP;
5484 else if (iseq(arg, "wds"))
5485 params.icp_opmode = IEEE80211_M_WDS;
5486 else if (iseq(arg, "monitor"))
5487 params.icp_opmode = IEEE80211_M_MONITOR;
5488 else if (iseq(arg, "tdma")) {
5489 params.icp_opmode = IEEE80211_M_AHDEMO;
5490 params.icp_flags |= IEEE80211_CLONE_TDMA;
5491 } else if (iseq(arg, "mesh") || iseq(arg, "mp")) /* mesh point */
5492 params.icp_opmode = IEEE80211_M_MBSS;
5494 errx(1, "Don't know to create %s for %s", arg, name);
5499 set80211clone_beacons(const char *val, int d, int s, const struct afswtch *rafp)
5501 /* NB: inverted sense */
5503 params.icp_flags &= ~IEEE80211_CLONE_NOBEACONS;
5505 params.icp_flags |= IEEE80211_CLONE_NOBEACONS;
5509 set80211clone_bssid(const char *val, int d, int s, const struct afswtch *rafp)
5512 params.icp_flags |= IEEE80211_CLONE_BSSID;
5514 params.icp_flags &= ~IEEE80211_CLONE_BSSID;
5518 set80211clone_wdslegacy(const char *val, int d, int s, const struct afswtch *rafp)
5521 params.icp_flags |= IEEE80211_CLONE_WDSLEGACY;
5523 params.icp_flags &= ~IEEE80211_CLONE_WDSLEGACY;
5526 static struct cmd ieee80211_cmds[] = {
5527 DEF_CMD_ARG("ssid", set80211ssid),
5528 DEF_CMD_ARG("nwid", set80211ssid),
5529 DEF_CMD_ARG("meshid", set80211meshid),
5530 DEF_CMD_ARG("stationname", set80211stationname),
5531 DEF_CMD_ARG("station", set80211stationname), /* BSD/OS */
5532 DEF_CMD_ARG("channel", set80211channel),
5533 DEF_CMD_ARG("authmode", set80211authmode),
5534 DEF_CMD_ARG("powersavemode", set80211powersavemode),
5535 DEF_CMD("powersave", 1, set80211powersave),
5536 DEF_CMD("-powersave", 0, set80211powersave),
5537 DEF_CMD_ARG("powersavesleep", set80211powersavesleep),
5538 DEF_CMD_ARG("wepmode", set80211wepmode),
5539 DEF_CMD("wep", 1, set80211wep),
5540 DEF_CMD("-wep", 0, set80211wep),
5541 DEF_CMD_ARG("deftxkey", set80211weptxkey),
5542 DEF_CMD_ARG("weptxkey", set80211weptxkey),
5543 DEF_CMD_ARG("wepkey", set80211wepkey),
5544 DEF_CMD_ARG("nwkey", set80211nwkey), /* NetBSD */
5545 DEF_CMD("-nwkey", 0, set80211wep), /* NetBSD */
5546 DEF_CMD_ARG("rtsthreshold", set80211rtsthreshold),
5547 DEF_CMD_ARG("protmode", set80211protmode),
5548 DEF_CMD_ARG("txpower", set80211txpower),
5549 DEF_CMD_ARG("roaming", set80211roaming),
5550 DEF_CMD("wme", 1, set80211wme),
5551 DEF_CMD("-wme", 0, set80211wme),
5552 DEF_CMD("wmm", 1, set80211wme),
5553 DEF_CMD("-wmm", 0, set80211wme),
5554 DEF_CMD("hidessid", 1, set80211hidessid),
5555 DEF_CMD("-hidessid", 0, set80211hidessid),
5556 DEF_CMD("apbridge", 1, set80211apbridge),
5557 DEF_CMD("-apbridge", 0, set80211apbridge),
5558 DEF_CMD_ARG("chanlist", set80211chanlist),
5559 DEF_CMD_ARG("bssid", set80211bssid),
5560 DEF_CMD_ARG("ap", set80211bssid),
5561 DEF_CMD("scan", 0, set80211scan),
5562 DEF_CMD_ARG("list", set80211list),
5563 DEF_CMD_ARG2("cwmin", set80211cwmin),
5564 DEF_CMD_ARG2("cwmax", set80211cwmax),
5565 DEF_CMD_ARG2("aifs", set80211aifs),
5566 DEF_CMD_ARG2("txoplimit", set80211txoplimit),
5567 DEF_CMD_ARG("acm", set80211acm),
5568 DEF_CMD_ARG("-acm", set80211noacm),
5569 DEF_CMD_ARG("ack", set80211ackpolicy),
5570 DEF_CMD_ARG("-ack", set80211noackpolicy),
5571 DEF_CMD_ARG2("bss:cwmin", set80211bsscwmin),
5572 DEF_CMD_ARG2("bss:cwmax", set80211bsscwmax),
5573 DEF_CMD_ARG2("bss:aifs", set80211bssaifs),
5574 DEF_CMD_ARG2("bss:txoplimit", set80211bsstxoplimit),
5575 DEF_CMD_ARG("dtimperiod", set80211dtimperiod),
5576 DEF_CMD_ARG("bintval", set80211bintval),
5577 DEF_CMD("mac:open", IEEE80211_MACCMD_POLICY_OPEN, set80211maccmd),
5578 DEF_CMD("mac:allow", IEEE80211_MACCMD_POLICY_ALLOW, set80211maccmd),
5579 DEF_CMD("mac:deny", IEEE80211_MACCMD_POLICY_DENY, set80211maccmd),
5580 DEF_CMD("mac:radius", IEEE80211_MACCMD_POLICY_RADIUS, set80211maccmd),
5581 DEF_CMD("mac:flush", IEEE80211_MACCMD_FLUSH, set80211maccmd),
5582 DEF_CMD("mac:detach", IEEE80211_MACCMD_DETACH, set80211maccmd),
5583 DEF_CMD_ARG("mac:add", set80211addmac),
5584 DEF_CMD_ARG("mac:del", set80211delmac),
5585 DEF_CMD_ARG("mac:kick", set80211kickmac),
5586 DEF_CMD("pureg", 1, set80211pureg),
5587 DEF_CMD("-pureg", 0, set80211pureg),
5588 DEF_CMD("ff", 1, set80211fastframes),
5589 DEF_CMD("-ff", 0, set80211fastframes),
5590 DEF_CMD("dturbo", 1, set80211dturbo),
5591 DEF_CMD("-dturbo", 0, set80211dturbo),
5592 DEF_CMD("bgscan", 1, set80211bgscan),
5593 DEF_CMD("-bgscan", 0, set80211bgscan),
5594 DEF_CMD_ARG("bgscanidle", set80211bgscanidle),
5595 DEF_CMD_ARG("bgscanintvl", set80211bgscanintvl),
5596 DEF_CMD_ARG("scanvalid", set80211scanvalid),
5597 DEF_CMD("quiet", 1, set80211quiet),
5598 DEF_CMD("-quiet", 0, set80211quiet),
5599 DEF_CMD_ARG("quiet_count", set80211quietcount),
5600 DEF_CMD_ARG("quiet_period", set80211quietperiod),
5601 DEF_CMD_ARG("quiet_dur", set80211quietduration),
5602 DEF_CMD_ARG("quiet_offset", set80211quietoffset),
5603 DEF_CMD_ARG("roam:rssi", set80211roamrssi),
5604 DEF_CMD_ARG("roam:rate", set80211roamrate),
5605 DEF_CMD_ARG("mcastrate", set80211mcastrate),
5606 DEF_CMD_ARG("ucastrate", set80211ucastrate),
5607 DEF_CMD_ARG("mgtrate", set80211mgtrate),
5608 DEF_CMD_ARG("mgmtrate", set80211mgtrate),
5609 DEF_CMD_ARG("maxretry", set80211maxretry),
5610 DEF_CMD_ARG("fragthreshold", set80211fragthreshold),
5611 DEF_CMD("burst", 1, set80211burst),
5612 DEF_CMD("-burst", 0, set80211burst),
5613 DEF_CMD_ARG("bmiss", set80211bmissthreshold),
5614 DEF_CMD_ARG("bmissthreshold", set80211bmissthreshold),
5615 DEF_CMD("shortgi", 1, set80211shortgi),
5616 DEF_CMD("-shortgi", 0, set80211shortgi),
5617 DEF_CMD("ampdurx", 2, set80211ampdu),
5618 DEF_CMD("-ampdurx", -2, set80211ampdu),
5619 DEF_CMD("ampdutx", 1, set80211ampdu),
5620 DEF_CMD("-ampdutx", -1, set80211ampdu),
5621 DEF_CMD("ampdu", 3, set80211ampdu), /* NB: tx+rx */
5622 DEF_CMD("-ampdu", -3, set80211ampdu),
5623 DEF_CMD_ARG("ampdulimit", set80211ampdulimit),
5624 DEF_CMD_ARG("ampdudensity", set80211ampdudensity),
5625 DEF_CMD("amsdurx", 2, set80211amsdu),
5626 DEF_CMD("-amsdurx", -2, set80211amsdu),
5627 DEF_CMD("amsdutx", 1, set80211amsdu),
5628 DEF_CMD("-amsdutx", -1, set80211amsdu),
5629 DEF_CMD("amsdu", 3, set80211amsdu), /* NB: tx+rx */
5630 DEF_CMD("-amsdu", -3, set80211amsdu),
5631 DEF_CMD_ARG("amsdulimit", set80211amsdulimit),
5632 DEF_CMD("stbcrx", 2, set80211stbc),
5633 DEF_CMD("-stbcrx", -2, set80211stbc),
5634 DEF_CMD("stbctx", 1, set80211stbc),
5635 DEF_CMD("-stbctx", -1, set80211stbc),
5636 DEF_CMD("stbc", 3, set80211stbc), /* NB: tx+rx */
5637 DEF_CMD("-stbc", -3, set80211stbc),
5638 DEF_CMD("ldpcrx", 2, set80211ldpc),
5639 DEF_CMD("-ldpcrx", -2, set80211ldpc),
5640 DEF_CMD("ldpctx", 1, set80211ldpc),
5641 DEF_CMD("-ldpctx", -1, set80211ldpc),
5642 DEF_CMD("ldpc", 3, set80211ldpc), /* NB: tx+rx */
5643 DEF_CMD("-ldpc", -3, set80211ldpc),
5644 DEF_CMD("puren", 1, set80211puren),
5645 DEF_CMD("-puren", 0, set80211puren),
5646 DEF_CMD("doth", 1, set80211doth),
5647 DEF_CMD("-doth", 0, set80211doth),
5648 DEF_CMD("dfs", 1, set80211dfs),
5649 DEF_CMD("-dfs", 0, set80211dfs),
5650 DEF_CMD("htcompat", 1, set80211htcompat),
5651 DEF_CMD("-htcompat", 0, set80211htcompat),
5652 DEF_CMD("dwds", 1, set80211dwds),
5653 DEF_CMD("-dwds", 0, set80211dwds),
5654 DEF_CMD("inact", 1, set80211inact),
5655 DEF_CMD("-inact", 0, set80211inact),
5656 DEF_CMD("tsn", 1, set80211tsn),
5657 DEF_CMD("-tsn", 0, set80211tsn),
5658 DEF_CMD_ARG("regdomain", set80211regdomain),
5659 DEF_CMD_ARG("country", set80211country),
5660 DEF_CMD("indoor", 'I', set80211location),
5661 DEF_CMD("-indoor", 'O', set80211location),
5662 DEF_CMD("outdoor", 'O', set80211location),
5663 DEF_CMD("-outdoor", 'I', set80211location),
5664 DEF_CMD("anywhere", ' ', set80211location),
5665 DEF_CMD("ecm", 1, set80211ecm),
5666 DEF_CMD("-ecm", 0, set80211ecm),
5667 DEF_CMD("dotd", 1, set80211dotd),
5668 DEF_CMD("-dotd", 0, set80211dotd),
5669 DEF_CMD_ARG("htprotmode", set80211htprotmode),
5670 DEF_CMD("ht20", 1, set80211htconf),
5671 DEF_CMD("-ht20", 0, set80211htconf),
5672 DEF_CMD("ht40", 3, set80211htconf), /* NB: 20+40 */
5673 DEF_CMD("-ht40", 0, set80211htconf),
5674 DEF_CMD("ht", 3, set80211htconf), /* NB: 20+40 */
5675 DEF_CMD("-ht", 0, set80211htconf),
5676 DEF_CMD("vht", 1, set80211vhtconf),
5677 DEF_CMD("-vht", 0, set80211vhtconf),
5678 DEF_CMD("vht40", 2, set80211vhtconf),
5679 DEF_CMD("-vht40", -2, set80211vhtconf),
5680 DEF_CMD("vht80", 4, set80211vhtconf),
5681 DEF_CMD("-vht80", -4, set80211vhtconf),
5682 DEF_CMD("vht80p80", 8, set80211vhtconf),
5683 DEF_CMD("-vht80p80", -8, set80211vhtconf),
5684 DEF_CMD("vht160", 16, set80211vhtconf),
5685 DEF_CMD("-vht160", -16, set80211vhtconf),
5686 DEF_CMD("rifs", 1, set80211rifs),
5687 DEF_CMD("-rifs", 0, set80211rifs),
5688 DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA, set80211smps),
5689 DEF_CMD("smpsdyn", IEEE80211_HTCAP_SMPS_DYNAMIC, set80211smps),
5690 DEF_CMD("-smps", IEEE80211_HTCAP_SMPS_OFF, set80211smps),
5691 /* XXX for testing */
5692 DEF_CMD_ARG("chanswitch", set80211chanswitch),
5694 DEF_CMD_ARG("tdmaslot", set80211tdmaslot),
5695 DEF_CMD_ARG("tdmaslotcnt", set80211tdmaslotcnt),
5696 DEF_CMD_ARG("tdmaslotlen", set80211tdmaslotlen),
5697 DEF_CMD_ARG("tdmabintval", set80211tdmabintval),
5699 DEF_CMD_ARG("meshttl", set80211meshttl),
5700 DEF_CMD("meshforward", 1, set80211meshforward),
5701 DEF_CMD("-meshforward", 0, set80211meshforward),
5702 DEF_CMD("meshgate", 1, set80211meshgate),
5703 DEF_CMD("-meshgate", 0, set80211meshgate),
5704 DEF_CMD("meshpeering", 1, set80211meshpeering),
5705 DEF_CMD("-meshpeering", 0, set80211meshpeering),
5706 DEF_CMD_ARG("meshmetric", set80211meshmetric),
5707 DEF_CMD_ARG("meshpath", set80211meshpath),
5708 DEF_CMD("meshrt:flush", IEEE80211_MESH_RTCMD_FLUSH, set80211meshrtcmd),
5709 DEF_CMD_ARG("meshrt:add", set80211addmeshrt),
5710 DEF_CMD_ARG("meshrt:del", set80211delmeshrt),
5711 DEF_CMD_ARG("hwmprootmode", set80211hwmprootmode),
5712 DEF_CMD_ARG("hwmpmaxhops", set80211hwmpmaxhops),
5714 /* vap cloning support */
5715 DEF_CLONE_CMD_ARG("wlanaddr", set80211clone_wlanaddr),
5716 DEF_CLONE_CMD_ARG("wlanbssid", set80211clone_wlanbssid),
5717 DEF_CLONE_CMD_ARG("wlandev", set80211clone_wlandev),
5718 DEF_CLONE_CMD_ARG("wlanmode", set80211clone_wlanmode),
5719 DEF_CLONE_CMD("beacons", 1, set80211clone_beacons),
5720 DEF_CLONE_CMD("-beacons", 0, set80211clone_beacons),
5721 DEF_CLONE_CMD("bssid", 1, set80211clone_bssid),
5722 DEF_CLONE_CMD("-bssid", 0, set80211clone_bssid),
5723 DEF_CLONE_CMD("wdslegacy", 1, set80211clone_wdslegacy),
5724 DEF_CLONE_CMD("-wdslegacy", 0, set80211clone_wdslegacy),
5726 static struct afswtch af_ieee80211 = {
5727 .af_name = "af_ieee80211",
5729 .af_other_status = ieee80211_status,
5732 static __constructor void
5733 ieee80211_ctor(void)
5737 for (i = 0; i < nitems(ieee80211_cmds); i++)
5738 cmd_register(&ieee80211_cmds[i]);
5739 af_register(&af_ieee80211);
5740 clone_setdefcallback("wlan", wlan_create);