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.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the NetBSD
49 * Foundation, Inc. and its contributors.
50 * 4. Neither the name of The NetBSD Foundation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
55 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
56 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
58 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64 * POSSIBILITY OF SUCH DAMAGE.
67 #include <sys/param.h>
68 #include <sys/ioctl.h>
69 #include <sys/socket.h>
70 #include <sys/sysctl.h>
73 #include <net/ethernet.h>
75 #include <net/if_dl.h>
76 #include <net/if_types.h>
77 #include <net/if_media.h>
78 #include <net/route.h>
80 #include <net80211/ieee80211_ioctl.h>
92 #include <stddef.h> /* NB: for offsetof */
95 #include "regdomain.h"
97 #ifndef IEEE80211_FIXED_RATE_NONE
98 #define IEEE80211_FIXED_RATE_NONE 0xff
101 #define REQ_ECM 0x01000000 /* enable if ECM set */
102 #define REQ_OUTDOOR 0x02000000 /* enable for outdoor operation */
103 #define REQ_FLAGS 0xff000000 /* private flags, don't pass to os */
105 /* XXX need these publicly defined or similar */
106 #ifndef IEEE80211_NODE_AUTH
107 #define IEEE80211_NODE_AUTH 0x0001 /* authorized for data */
108 #define IEEE80211_NODE_QOS 0x0002 /* QoS enabled */
109 #define IEEE80211_NODE_ERP 0x0004 /* ERP enabled */
110 #define IEEE80211_NODE_PWR_MGT 0x0010 /* power save mode enabled */
111 #define IEEE80211_NODE_HT 0x0040 /* HT enabled */
112 #define IEEE80211_NODE_HTCOMPAT 0x0080 /* HT setup w/ vendor OUI's */
113 #define IEEE80211_NODE_WPS 0x0100 /* WPS association */
114 #define IEEE80211_NODE_TSN 0x0200 /* TSN association */
115 #define IEEE80211_NODE_AMPDU_RX 0x0400 /* AMPDU rx enabled */
116 #define IEEE80211_NODE_AMPDU_TX 0x0800 /* AMPDU tx enabled */
117 #define IEEE80211_NODE_MIMO_PS 0x1000 /* MIMO power save enabled */
118 #define IEEE80211_NODE_MIMO_RTS 0x2000 /* send RTS in MIMO PS */
119 #define IEEE80211_NODE_RIFS 0x4000 /* RIFS enabled */
126 static void LINE_INIT(char c);
127 static void LINE_BREAK(void);
128 static void LINE_CHECK(const char *fmt, ...);
130 static const char *modename[] = {
131 "auto", "11a", "11b", "11g", "fh", "turboA", "turboG",
132 "sturbo", "11na", "11ng"
135 static void set80211(int s, int type, int val, int len, void *data);
136 static int get80211(int s, int type, void *data, int len);
137 static int get80211len(int s, int type, void *data, int len, int *plen);
138 static int get80211val(int s, int type, int *val);
139 static const char *get_string(const char *val, const char *sep,
140 u_int8_t *buf, int *lenp);
141 static void print_string(const u_int8_t *buf, int len);
142 static void print_regdomain(const struct ieee80211_regdomain *, int);
143 static void print_channels(int, const struct ieee80211req_chaninfo *,
144 int allchans, int verbose);
145 static void regdomain_makechannels(struct ieee80211_regdomain_req *,
146 const struct ieee80211_devcaps_req *);
148 static struct ieee80211req_chaninfo chaninfo;
149 static struct ieee80211_regdomain regdomain;
150 static int gotregdomain = 0;
151 static struct ieee80211_roamparams_req roamparams;
152 static int gotroam = 0;
153 static struct ieee80211_txparams_req txparams;
154 static int gottxparams = 0;
155 static struct ieee80211_channel curchan;
156 static int gotcurchan = 0;
157 static struct ifmediareq *ifmr;
158 static int htconf = 0;
159 static int gothtconf = 0;
166 if (get80211val(s, IEEE80211_IOC_HTCONF, &htconf) < 0)
167 warn("unable to get HT configuration information");
172 * Collect channel info from the kernel. We use this (mostly)
173 * to handle mapping between frequency and IEEE channel number.
178 if (chaninfo.ic_nchans != 0)
180 if (get80211(s, IEEE80211_IOC_CHANINFO, &chaninfo, sizeof(chaninfo)) < 0)
181 errx(1, "unable to get channel information");
182 ifmr = ifmedia_getstate(s);
186 static struct regdata *
189 static struct regdata *rdp = NULL;
191 rdp = lib80211_alloc_regdata();
193 errx(-1, "missing or corrupted regdomain database");
199 * Given the channel at index i with attributes from,
200 * check if there is a channel with attributes to in
201 * the channel table. With suitable attributes this
202 * allows the caller to look for promotion; e.g. from
206 canpromote(int i, int from, int to)
208 const struct ieee80211_channel *fc = &chaninfo.ic_chans[i];
211 if ((fc->ic_flags & from) != from)
213 /* NB: quick check exploiting ordering of chans w/ same frequency */
214 if (i+1 < chaninfo.ic_nchans &&
215 chaninfo.ic_chans[i+1].ic_freq == fc->ic_freq &&
216 (chaninfo.ic_chans[i+1].ic_flags & to) == to)
218 /* brute force search in case channel list is not ordered */
219 for (j = 0; j < chaninfo.ic_nchans; j++) {
220 const struct ieee80211_channel *tc = &chaninfo.ic_chans[j];
222 tc->ic_freq == fc->ic_freq && (tc->ic_flags & to) == to)
229 * Handle channel promotion. When a channel is specified with
230 * only a frequency we want to promote it to the ``best'' channel
231 * available. The channel list has separate entries for 11b, 11g,
232 * 11a, and 11n[ga] channels so specifying a frequency w/o any
233 * attributes requires we upgrade, e.g. from 11b -> 11g. This
234 * gets complicated when the channel is specified on the same
235 * command line with a media request that constrains the available
236 * channe list (e.g. mode 11a); we want to honor that to avoid
237 * confusing behaviour.
243 * Query the current mode of the interface in case it's
244 * constrained (e.g. to 11a). We must do this carefully
245 * as there may be a pending ifmedia request in which case
246 * asking the kernel will give us the wrong answer. This
247 * is an unfortunate side-effect of the way ifconfig is
248 * structure for modularity (yech).
250 * NB: ifmr is actually setup in getchaninfo (above); we
251 * assume it's called coincident with to this call so
252 * we have a ``current setting''; otherwise we must pass
253 * the socket descriptor down to here so we can make
254 * the ifmedia_getstate call ourselves.
256 int chanmode = ifmr != NULL ? IFM_MODE(ifmr->ifm_current) : IFM_AUTO;
258 /* when ambiguous promote to ``best'' */
259 /* NB: we abitrarily pick HT40+ over HT40- */
260 if (chanmode != IFM_IEEE80211_11B)
261 i = canpromote(i, IEEE80211_CHAN_B, IEEE80211_CHAN_G);
262 if (chanmode != IFM_IEEE80211_11G && (htconf & 1)) {
263 i = canpromote(i, IEEE80211_CHAN_G,
264 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20);
266 i = canpromote(i, IEEE80211_CHAN_G,
267 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D);
268 i = canpromote(i, IEEE80211_CHAN_G,
269 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U);
272 if (chanmode != IFM_IEEE80211_11A && (htconf & 1)) {
273 i = canpromote(i, IEEE80211_CHAN_A,
274 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20);
276 i = canpromote(i, IEEE80211_CHAN_A,
277 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D);
278 i = canpromote(i, IEEE80211_CHAN_A,
279 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U);
286 mapfreq(struct ieee80211_channel *chan, int freq, int flags)
290 for (i = 0; i < chaninfo.ic_nchans; i++) {
291 const struct ieee80211_channel *c = &chaninfo.ic_chans[i];
293 if (c->ic_freq == freq && (c->ic_flags & flags) == flags) {
295 /* when ambiguous promote to ``best'' */
296 c = &chaninfo.ic_chans[promote(i)];
302 errx(1, "unknown/undefined frequency %u/0x%x", freq, flags);
306 mapchan(struct ieee80211_channel *chan, int ieee, int flags)
310 for (i = 0; i < chaninfo.ic_nchans; i++) {
311 const struct ieee80211_channel *c = &chaninfo.ic_chans[i];
313 if (c->ic_ieee == ieee && (c->ic_flags & flags) == flags) {
315 /* when ambiguous promote to ``best'' */
316 c = &chaninfo.ic_chans[promote(i)];
322 errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags);
325 static const struct ieee80211_channel *
330 if (get80211(s, IEEE80211_IOC_CURCHAN, &curchan, sizeof(curchan)) < 0) {
332 /* fall back to legacy ioctl */
333 if (get80211val(s, IEEE80211_IOC_CHANNEL, &val) < 0)
334 errx(-1, "cannot figure out current channel");
336 mapchan(&curchan, val, 0);
342 static enum ieee80211_phymode
343 chan2mode(const struct ieee80211_channel *c)
345 if (IEEE80211_IS_CHAN_HTA(c))
346 return IEEE80211_MODE_11NA;
347 if (IEEE80211_IS_CHAN_HTG(c))
348 return IEEE80211_MODE_11NG;
349 if (IEEE80211_IS_CHAN_108A(c))
350 return IEEE80211_MODE_TURBO_A;
351 if (IEEE80211_IS_CHAN_108G(c))
352 return IEEE80211_MODE_TURBO_G;
353 if (IEEE80211_IS_CHAN_ST(c))
354 return IEEE80211_MODE_STURBO_A;
355 if (IEEE80211_IS_CHAN_FHSS(c))
356 return IEEE80211_MODE_FH;
357 if (IEEE80211_IS_CHAN_A(c))
358 return IEEE80211_MODE_11A;
359 if (IEEE80211_IS_CHAN_ANYG(c))
360 return IEEE80211_MODE_11G;
361 if (IEEE80211_IS_CHAN_B(c))
362 return IEEE80211_MODE_11B;
363 return IEEE80211_MODE_AUTO;
371 if (get80211(s, IEEE80211_IOC_ROAM,
372 &roamparams, sizeof(roamparams)) < 0)
373 errx(1, "unable to get roaming parameters");
378 setroam_cb(int s, void *arg)
380 struct ieee80211_roamparams_req *roam = arg;
381 set80211(s, IEEE80211_IOC_ROAM, 0, sizeof(*roam), roam);
389 if (get80211(s, IEEE80211_IOC_TXPARAMS,
390 &txparams, sizeof(txparams)) < 0)
391 errx(1, "unable to get transmit parameters");
396 settxparams_cb(int s, void *arg)
398 struct ieee80211_txparams_req *txp = arg;
399 set80211(s, IEEE80211_IOC_TXPARAMS, 0, sizeof(*txp), txp);
407 if (get80211(s, IEEE80211_IOC_REGDOMAIN,
408 ®domain, sizeof(regdomain)) < 0)
409 errx(1, "unable to get regulatory domain info");
414 getdevcaps(int s, struct ieee80211_devcaps_req *dc)
416 if (get80211(s, IEEE80211_IOC_DEVCAPS, dc, sizeof(*dc)) < 0)
417 errx(1, "unable to get device capabilities");
421 setregdomain_cb(int s, void *arg)
423 struct ieee80211_regdomain_req req;
424 struct ieee80211_regdomain *rd = arg;
425 struct ieee80211_devcaps_req dc;
426 struct regdata *rdp = getregdata();
428 if (rd->country != 0) {
429 const struct country *cc;
431 * Check current country seting to make sure it's
432 * compatible with the new regdomain. If not, then
433 * override it with any default country for this
434 * SKU. If we cannot arrange a match, then abort.
436 cc = lib80211_country_findbycc(rdp, rd->country);
438 errx(1, "unknown ISO country code %d", rd->country);
439 if (cc->rd->sku != rd->regdomain) {
440 const struct regdomain *rp;
442 * Check if country is incompatible with regdomain.
443 * To enable multiple regdomains for a country code
444 * we permit a mismatch between the regdomain and
445 * the country's associated regdomain when the
446 * regdomain is setup w/o a default country. For
447 * example, US is bound to the FCC regdomain but
448 * we allow US to be combined with FCC3 because FCC3
449 * has not default country. This allows bogus
450 * combinations like FCC3+DK which are resolved when
451 * constructing the channel list by deferring to the
452 * regdomain to construct the channel list.
454 rp = lib80211_regdomain_findbysku(rdp, rd->regdomain);
456 errx(1, "country %s (%s) is not usable with "
457 "regdomain %d", cc->isoname, cc->name,
459 else if (rp->cc != 0 && rp->cc != cc)
460 errx(1, "country %s (%s) is not usable with "
461 "regdomain %s", cc->isoname, cc->name,
467 * Fetch the device capabilities and calculate the
468 * full set of netbands for which we request a new
469 * channel list be constructed. Once that's done we
470 * push the regdomain info + channel list to the kernel.
475 printf("drivercaps: 0x%x\n", dc.dc_drivercaps);
476 printf("cryptocaps: 0x%x\n", dc.dc_cryptocaps);
477 printf("htcaps : 0x%x\n", dc.dc_htcaps);
478 memcpy(&chaninfo, &dc.dc_chaninfo, sizeof(chaninfo));
479 print_channels(s, &dc.dc_chaninfo, 1/*allchans*/, 1/*verbose*/);
482 regdomain_makechannels(&req, &dc);
485 print_regdomain(rd, 1/*verbose*/);
487 memcpy(&chaninfo, &req.chaninfo, sizeof(chaninfo));
488 print_channels(s, &req.chaninfo, 1/*allchans*/, 1/*verbose*/);
490 if (req.chaninfo.ic_nchans == 0)
491 errx(1, "no channels calculated");
492 set80211(s, IEEE80211_IOC_REGDOMAIN, 0, sizeof(req), &req);
496 ieee80211_mhz2ieee(int freq, int flags)
498 struct ieee80211_channel chan;
499 mapfreq(&chan, freq, flags);
504 isanyarg(const char *arg)
506 return (strncmp(arg, "-", 1) == 0 ||
507 strncasecmp(arg, "any", 3) == 0 || strncasecmp(arg, "off", 3) == 0);
511 set80211ssid(const char *val, int d, int s, const struct afswtch *rafp)
515 u_int8_t data[IEEE80211_NWID_LEN];
519 if (len > 2 && isdigit((int)val[0]) && val[1] == ':') {
524 bzero(data, sizeof(data));
526 if (get_string(val, NULL, data, &len) == NULL)
529 set80211(s, IEEE80211_IOC_SSID, ssid, len, data);
533 set80211stationname(const char *val, int d, int s, const struct afswtch *rafp)
538 bzero(data, sizeof(data));
540 get_string(val, NULL, data, &len);
542 set80211(s, IEEE80211_IOC_STATIONNAME, 0, len, data);
546 * Parse a channel specification for attributes/flags.
548 * freq/xx channel width (5,10,20,40,40+,40-)
549 * freq:mode channel mode (a,b,g,h,n,t,s,d)
551 * These can be combined in either order; e.g. 2437:ng/40.
552 * Modes are case insensitive.
554 * The result is not validated here; it's assumed to be
555 * checked against the channel table fetched from the kernel.
558 getchannelflags(const char *val, int freq)
560 #define _CHAN_HT 0x80000000
566 cp = strchr(val, ':');
568 for (cp++; isalpha((int) *cp); cp++) {
569 /* accept mixed case */
574 case 'a': /* 802.11a */
575 flags |= IEEE80211_CHAN_A;
577 case 'b': /* 802.11b */
578 flags |= IEEE80211_CHAN_B;
580 case 'g': /* 802.11g */
581 flags |= IEEE80211_CHAN_G;
583 case 'h': /* ht = 802.11n */
584 case 'n': /* 802.11n */
585 flags |= _CHAN_HT; /* NB: private */
587 case 'd': /* dt = Atheros Dynamic Turbo */
588 flags |= IEEE80211_CHAN_TURBO;
590 case 't': /* ht, dt, st, t */
591 /* dt and unadorned t specify Dynamic Turbo */
592 if ((flags & (IEEE80211_CHAN_STURBO|_CHAN_HT)) == 0)
593 flags |= IEEE80211_CHAN_TURBO;
595 case 's': /* st = Atheros Static Turbo */
596 flags |= IEEE80211_CHAN_STURBO;
599 errx(-1, "%s: Invalid channel attribute %c\n",
604 cp = strchr(val, '/');
607 u_long cw = strtoul(cp+1, &ep, 10);
611 flags |= IEEE80211_CHAN_QUARTER;
614 flags |= IEEE80211_CHAN_HALF;
617 /* NB: this may be removed below */
618 flags |= IEEE80211_CHAN_HT20;
621 if (ep != NULL && *ep == '+')
622 flags |= IEEE80211_CHAN_HT40U;
623 else if (ep != NULL && *ep == '-')
624 flags |= IEEE80211_CHAN_HT40D;
627 errx(-1, "%s: Invalid channel width\n", val);
631 * Cleanup specifications.
633 if ((flags & _CHAN_HT) == 0) {
635 * If user specified freq/20 or freq/40 quietly remove
636 * HT cw attributes depending on channel use. To give
637 * an explicit 20/40 width for an HT channel you must
638 * indicate it is an HT channel since all HT channels
639 * are also usable for legacy operation; e.g. freq:n/40.
641 flags &= ~IEEE80211_CHAN_HT;
644 * Remove private indicator that this is an HT channel
645 * and if no explicit channel width has been given
646 * provide the default settings.
649 if ((flags & IEEE80211_CHAN_HT) == 0) {
650 struct ieee80211_channel chan;
652 * Consult the channel list to see if we can use
653 * HT40+ or HT40- (if both the map routines choose).
656 mapfreq(&chan, freq, 0);
658 mapchan(&chan, freq, 0);
659 flags |= (chan.ic_flags & IEEE80211_CHAN_HT);
667 set80211channel(const char *val, int d, int s, const struct afswtch *rafp)
669 struct ieee80211_channel chan;
671 memset(&chan, 0, sizeof(chan));
672 if (!isanyarg(val)) {
677 v = strtol(val, &ep, 10);
678 if (val[0] == '\0' || val == ep || errno == ERANGE ||
679 /* channel may be suffixed with nothing, :flag, or /width */
680 (ep[0] != '\0' && ep[0] != ':' && ep[0] != '/'))
681 errx(1, "invalid channel specification");
682 flags = getchannelflags(val, v);
683 if (v > 255) { /* treat as frequency */
684 mapfreq(&chan, v, flags);
686 mapchan(&chan, v, flags);
689 chan.ic_freq = IEEE80211_CHAN_ANY;
691 set80211(s, IEEE80211_IOC_CURCHAN, 0, sizeof(chan), &chan);
695 set80211chanswitch(const char *val, int d, int s, const struct afswtch *rafp)
697 struct ieee80211_chanswitch_req csr;
700 memset(&csr, 0, sizeof(csr));
703 flags = getchannelflags(val, v);
704 if (v > 255) { /* treat as frequency */
705 mapfreq(&csr.csa_chan, v, flags);
707 mapchan(&csr.csa_chan, v, flags);
711 set80211(s, IEEE80211_IOC_CHANSWITCH, 0, sizeof(csr), &csr);
715 set80211authmode(const char *val, int d, int s, const struct afswtch *rafp)
719 if (strcasecmp(val, "none") == 0) {
720 mode = IEEE80211_AUTH_NONE;
721 } else if (strcasecmp(val, "open") == 0) {
722 mode = IEEE80211_AUTH_OPEN;
723 } else if (strcasecmp(val, "shared") == 0) {
724 mode = IEEE80211_AUTH_SHARED;
725 } else if (strcasecmp(val, "8021x") == 0) {
726 mode = IEEE80211_AUTH_8021X;
727 } else if (strcasecmp(val, "wpa") == 0) {
728 mode = IEEE80211_AUTH_WPA;
730 errx(1, "unknown authmode");
733 set80211(s, IEEE80211_IOC_AUTHMODE, mode, 0, NULL);
737 set80211powersavemode(const char *val, int d, int s, const struct afswtch *rafp)
741 if (strcasecmp(val, "off") == 0) {
742 mode = IEEE80211_POWERSAVE_OFF;
743 } else if (strcasecmp(val, "on") == 0) {
744 mode = IEEE80211_POWERSAVE_ON;
745 } else if (strcasecmp(val, "cam") == 0) {
746 mode = IEEE80211_POWERSAVE_CAM;
747 } else if (strcasecmp(val, "psp") == 0) {
748 mode = IEEE80211_POWERSAVE_PSP;
749 } else if (strcasecmp(val, "psp-cam") == 0) {
750 mode = IEEE80211_POWERSAVE_PSP_CAM;
752 errx(1, "unknown powersavemode");
755 set80211(s, IEEE80211_IOC_POWERSAVE, mode, 0, NULL);
759 set80211powersave(const char *val, int d, int s, const struct afswtch *rafp)
762 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_OFF,
765 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_ON,
770 set80211powersavesleep(const char *val, int d, int s, const struct afswtch *rafp)
772 set80211(s, IEEE80211_IOC_POWERSAVESLEEP, atoi(val), 0, NULL);
776 set80211wepmode(const char *val, int d, int s, const struct afswtch *rafp)
780 if (strcasecmp(val, "off") == 0) {
781 mode = IEEE80211_WEP_OFF;
782 } else if (strcasecmp(val, "on") == 0) {
783 mode = IEEE80211_WEP_ON;
784 } else if (strcasecmp(val, "mixed") == 0) {
785 mode = IEEE80211_WEP_MIXED;
787 errx(1, "unknown wep mode");
790 set80211(s, IEEE80211_IOC_WEP, mode, 0, NULL);
794 set80211wep(const char *val, int d, int s, const struct afswtch *rafp)
796 set80211(s, IEEE80211_IOC_WEP, d, 0, NULL);
800 isundefarg(const char *arg)
802 return (strcmp(arg, "-") == 0 || strncasecmp(arg, "undef", 5) == 0);
806 set80211weptxkey(const char *val, int d, int s, const struct afswtch *rafp)
809 set80211(s, IEEE80211_IOC_WEPTXKEY, IEEE80211_KEYIX_NONE, 0, NULL);
811 set80211(s, IEEE80211_IOC_WEPTXKEY, atoi(val)-1, 0, NULL);
815 set80211wepkey(const char *val, int d, int s, const struct afswtch *rafp)
819 u_int8_t data[IEEE80211_KEYBUF_SIZE];
821 if (isdigit((int)val[0]) && val[1] == ':') {
826 bzero(data, sizeof(data));
828 get_string(val, NULL, data, &len);
830 set80211(s, IEEE80211_IOC_WEPKEY, key, len, data);
834 * This function is purely a NetBSD compatability interface. The NetBSD
835 * interface is too inflexible, but it's there so we'll support it since
836 * it's not all that hard.
839 set80211nwkey(const char *val, int d, int s, const struct afswtch *rafp)
843 u_int8_t data[IEEE80211_KEYBUF_SIZE];
845 set80211(s, IEEE80211_IOC_WEP, IEEE80211_WEP_ON, 0, NULL);
847 if (isdigit((int)val[0]) && val[1] == ':') {
848 txkey = val[0]-'0'-1;
851 for (i = 0; i < 4; i++) {
852 bzero(data, sizeof(data));
854 val = get_string(val, ",", data, &len);
858 set80211(s, IEEE80211_IOC_WEPKEY, i, len, data);
861 bzero(data, sizeof(data));
863 get_string(val, NULL, data, &len);
866 set80211(s, IEEE80211_IOC_WEPKEY, 0, len, data);
868 bzero(data, sizeof(data));
869 for (i = 1; i < 4; i++)
870 set80211(s, IEEE80211_IOC_WEPKEY, i, 0, data);
873 set80211(s, IEEE80211_IOC_WEPTXKEY, txkey, 0, NULL);
877 set80211rtsthreshold(const char *val, int d, int s, const struct afswtch *rafp)
879 set80211(s, IEEE80211_IOC_RTSTHRESHOLD,
880 isundefarg(val) ? IEEE80211_RTS_MAX : atoi(val), 0, NULL);
884 set80211protmode(const char *val, int d, int s, const struct afswtch *rafp)
888 if (strcasecmp(val, "off") == 0) {
889 mode = IEEE80211_PROTMODE_OFF;
890 } else if (strcasecmp(val, "cts") == 0) {
891 mode = IEEE80211_PROTMODE_CTS;
892 } else if (strncasecmp(val, "rtscts", 3) == 0) {
893 mode = IEEE80211_PROTMODE_RTSCTS;
895 errx(1, "unknown protection mode");
898 set80211(s, IEEE80211_IOC_PROTMODE, mode, 0, NULL);
902 set80211htprotmode(const char *val, int d, int s, const struct afswtch *rafp)
906 if (strcasecmp(val, "off") == 0) {
907 mode = IEEE80211_PROTMODE_OFF;
908 } else if (strncasecmp(val, "rts", 3) == 0) {
909 mode = IEEE80211_PROTMODE_RTSCTS;
911 errx(1, "unknown protection mode");
914 set80211(s, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL);
918 set80211txpower(const char *val, int d, int s, const struct afswtch *rafp)
920 double v = atof(val);
925 errx(-1, "invalid tx power (must be .5 dBm units)");
926 set80211(s, IEEE80211_IOC_TXPOWER, txpow, 0, NULL);
929 #define IEEE80211_ROAMING_DEVICE 0
930 #define IEEE80211_ROAMING_AUTO 1
931 #define IEEE80211_ROAMING_MANUAL 2
934 set80211roaming(const char *val, int d, int s, const struct afswtch *rafp)
938 if (strcasecmp(val, "device") == 0) {
939 mode = IEEE80211_ROAMING_DEVICE;
940 } else if (strcasecmp(val, "auto") == 0) {
941 mode = IEEE80211_ROAMING_AUTO;
942 } else if (strcasecmp(val, "manual") == 0) {
943 mode = IEEE80211_ROAMING_MANUAL;
945 errx(1, "unknown roaming mode");
947 set80211(s, IEEE80211_IOC_ROAMING, mode, 0, NULL);
951 set80211wme(const char *val, int d, int s, const struct afswtch *rafp)
953 set80211(s, IEEE80211_IOC_WME, d, 0, NULL);
957 set80211hidessid(const char *val, int d, int s, const struct afswtch *rafp)
959 set80211(s, IEEE80211_IOC_HIDESSID, d, 0, NULL);
963 set80211apbridge(const char *val, int d, int s, const struct afswtch *rafp)
965 set80211(s, IEEE80211_IOC_APBRIDGE, d, 0, NULL);
969 set80211fastframes(const char *val, int d, int s, const struct afswtch *rafp)
971 set80211(s, IEEE80211_IOC_FF, d, 0, NULL);
975 set80211dturbo(const char *val, int d, int s, const struct afswtch *rafp)
977 set80211(s, IEEE80211_IOC_TURBOP, d, 0, NULL);
981 set80211chanlist(const char *val, int d, int s, const struct afswtch *rafp)
983 struct ieee80211req_chanlist chanlist;
984 #define MAXCHAN (sizeof(chanlist.ic_channels)*NBBY)
985 char *temp, *cp, *tp;
987 temp = malloc(strlen(val) + 1);
989 errx(1, "malloc failed");
991 memset(&chanlist, 0, sizeof(chanlist));
994 int first, last, f, c;
996 tp = strchr(cp, ',');
999 switch (sscanf(cp, "%u-%u", &first, &last)) {
1001 if (first > MAXCHAN)
1002 errx(-1, "channel %u out of range, max %zu",
1004 setbit(chanlist.ic_channels, first);
1007 if (first > MAXCHAN)
1008 errx(-1, "channel %u out of range, max %zu",
1011 errx(-1, "channel %u out of range, max %zu",
1014 errx(-1, "void channel range, %u > %u",
1016 for (f = first; f <= last; f++)
1017 setbit(chanlist.ic_channels, f);
1029 set80211(s, IEEE80211_IOC_CHANLIST, 0, sizeof(chanlist), &chanlist);
1034 set80211bssid(const char *val, int d, int s, const struct afswtch *rafp)
1037 if (!isanyarg(val)) {
1039 struct sockaddr_dl sdl;
1041 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1043 errx(1, "malloc failed");
1045 strcpy(temp + 1, val);
1046 sdl.sdl_len = sizeof(sdl);
1047 link_addr(temp, &sdl);
1049 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1050 errx(1, "malformed link-level address");
1051 set80211(s, IEEE80211_IOC_BSSID, 0,
1052 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1054 uint8_t zerobssid[IEEE80211_ADDR_LEN];
1055 memset(zerobssid, 0, sizeof(zerobssid));
1056 set80211(s, IEEE80211_IOC_BSSID, 0,
1057 IEEE80211_ADDR_LEN, zerobssid);
1062 getac(const char *ac)
1064 if (strcasecmp(ac, "ac_be") == 0 || strcasecmp(ac, "be") == 0)
1066 if (strcasecmp(ac, "ac_bk") == 0 || strcasecmp(ac, "bk") == 0)
1068 if (strcasecmp(ac, "ac_vi") == 0 || strcasecmp(ac, "vi") == 0)
1070 if (strcasecmp(ac, "ac_vo") == 0 || strcasecmp(ac, "vo") == 0)
1072 errx(1, "unknown wme access class %s", ac);
1076 DECL_CMD_FUNC2(set80211cwmin, ac, val)
1078 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac), NULL);
1082 DECL_CMD_FUNC2(set80211cwmax, ac, val)
1084 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac), NULL);
1088 DECL_CMD_FUNC2(set80211aifs, ac, val)
1090 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac), NULL);
1094 DECL_CMD_FUNC2(set80211txoplimit, ac, val)
1096 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac), NULL);
1100 DECL_CMD_FUNC(set80211acm, ac, d)
1102 set80211(s, IEEE80211_IOC_WME_ACM, 1, getac(ac), NULL);
1105 DECL_CMD_FUNC(set80211noacm, ac, d)
1107 set80211(s, IEEE80211_IOC_WME_ACM, 0, getac(ac), NULL);
1111 DECL_CMD_FUNC(set80211ackpolicy, ac, d)
1113 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 1, getac(ac), NULL);
1116 DECL_CMD_FUNC(set80211noackpolicy, ac, d)
1118 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 0, getac(ac), NULL);
1122 DECL_CMD_FUNC2(set80211bsscwmin, ac, val)
1124 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val),
1125 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1129 DECL_CMD_FUNC2(set80211bsscwmax, ac, val)
1131 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val),
1132 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1136 DECL_CMD_FUNC2(set80211bssaifs, ac, val)
1138 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val),
1139 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1143 DECL_CMD_FUNC2(set80211bsstxoplimit, ac, val)
1145 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val),
1146 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1150 DECL_CMD_FUNC(set80211dtimperiod, val, d)
1152 set80211(s, IEEE80211_IOC_DTIM_PERIOD, atoi(val), 0, NULL);
1156 DECL_CMD_FUNC(set80211bintval, val, d)
1158 set80211(s, IEEE80211_IOC_BEACON_INTERVAL, atoi(val), 0, NULL);
1162 set80211macmac(int s, int op, const char *val)
1165 struct sockaddr_dl sdl;
1167 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1169 errx(1, "malloc failed");
1171 strcpy(temp + 1, val);
1172 sdl.sdl_len = sizeof(sdl);
1173 link_addr(temp, &sdl);
1175 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1176 errx(1, "malformed link-level address");
1177 set80211(s, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl));
1181 DECL_CMD_FUNC(set80211addmac, val, d)
1183 set80211macmac(s, IEEE80211_IOC_ADDMAC, val);
1187 DECL_CMD_FUNC(set80211delmac, val, d)
1189 set80211macmac(s, IEEE80211_IOC_DELMAC, val);
1193 DECL_CMD_FUNC(set80211kickmac, val, d)
1196 struct sockaddr_dl sdl;
1197 struct ieee80211req_mlme mlme;
1199 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1201 errx(1, "malloc failed");
1203 strcpy(temp + 1, val);
1204 sdl.sdl_len = sizeof(sdl);
1205 link_addr(temp, &sdl);
1207 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1208 errx(1, "malformed link-level address");
1209 memset(&mlme, 0, sizeof(mlme));
1210 mlme.im_op = IEEE80211_MLME_DEAUTH;
1211 mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE;
1212 memcpy(mlme.im_macaddr, LLADDR(&sdl), IEEE80211_ADDR_LEN);
1213 set80211(s, IEEE80211_IOC_MLME, 0, sizeof(mlme), &mlme);
1217 DECL_CMD_FUNC(set80211maccmd, val, d)
1219 set80211(s, IEEE80211_IOC_MACCMD, d, 0, NULL);
1223 set80211pureg(const char *val, int d, int s, const struct afswtch *rafp)
1225 set80211(s, IEEE80211_IOC_PUREG, d, 0, NULL);
1229 set80211bgscan(const char *val, int d, int s, const struct afswtch *rafp)
1231 set80211(s, IEEE80211_IOC_BGSCAN, d, 0, NULL);
1235 DECL_CMD_FUNC(set80211bgscanidle, val, d)
1237 set80211(s, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL);
1241 DECL_CMD_FUNC(set80211bgscanintvl, val, d)
1243 set80211(s, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL);
1247 DECL_CMD_FUNC(set80211scanvalid, val, d)
1249 set80211(s, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL);
1253 * Parse an optional trailing specification of which netbands
1254 * to apply a parameter to. This is basically the same syntax
1255 * as used for channels but you can concatenate to specify
1256 * multiple. For example:
1257 * 14:abg apply to 11a, 11b, and 11g
1258 * 6:ht apply to 11na and 11ng
1259 * We don't make a big effort to catch silly things; this is
1260 * really a convenience mechanism.
1263 getmodeflags(const char *val)
1270 cp = strchr(val, ':');
1272 for (cp++; isalpha((int) *cp); cp++) {
1273 /* accept mixed case */
1278 case 'a': /* 802.11a */
1279 flags |= IEEE80211_CHAN_A;
1281 case 'b': /* 802.11b */
1282 flags |= IEEE80211_CHAN_B;
1284 case 'g': /* 802.11g */
1285 flags |= IEEE80211_CHAN_G;
1287 case 'h': /* ht = 802.11n */
1288 case 'n': /* 802.11n */
1289 flags |= IEEE80211_CHAN_HT;
1291 case 'd': /* dt = Atheros Dynamic Turbo */
1292 flags |= IEEE80211_CHAN_TURBO;
1294 case 't': /* ht, dt, st, t */
1295 /* dt and unadorned t specify Dynamic Turbo */
1296 if ((flags & (IEEE80211_CHAN_STURBO|IEEE80211_CHAN_HT)) == 0)
1297 flags |= IEEE80211_CHAN_TURBO;
1299 case 's': /* st = Atheros Static Turbo */
1300 flags |= IEEE80211_CHAN_STURBO;
1303 errx(-1, "%s: Invalid mode attribute %c\n",
1311 #define IEEE80211_CHAN_HTA (IEEE80211_CHAN_HT|IEEE80211_CHAN_5GHZ)
1312 #define IEEE80211_CHAN_HTG (IEEE80211_CHAN_HT|IEEE80211_CHAN_2GHZ)
1314 #define _APPLY(_flags, _base, _param, _v) do { \
1315 if (_flags & IEEE80211_CHAN_HT) { \
1316 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1317 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1318 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1319 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1320 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1322 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1324 if (_flags & IEEE80211_CHAN_TURBO) { \
1325 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1326 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1327 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1328 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1329 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1331 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1333 if (_flags & IEEE80211_CHAN_STURBO) \
1334 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1335 if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1336 _base.params[IEEE80211_MODE_11A]._param = _v; \
1337 if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1338 _base.params[IEEE80211_MODE_11G]._param = _v; \
1339 if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1340 _base.params[IEEE80211_MODE_11B]._param = _v; \
1342 #define _APPLY1(_flags, _base, _param, _v) do { \
1343 if (_flags & IEEE80211_CHAN_HT) { \
1344 if (_flags & IEEE80211_CHAN_5GHZ) \
1345 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1347 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1348 } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \
1349 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1350 else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \
1351 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1352 else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \
1353 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1354 else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1355 _base.params[IEEE80211_MODE_11A]._param = _v; \
1356 else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1357 _base.params[IEEE80211_MODE_11G]._param = _v; \
1358 else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1359 _base.params[IEEE80211_MODE_11B]._param = _v; \
1361 #define _APPLY_RATE(_flags, _base, _param, _v) do { \
1362 if (_flags & IEEE80211_CHAN_HT) { \
1363 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1364 _base.params[IEEE80211_MODE_11NA]._param = _v|0x80; \
1365 _base.params[IEEE80211_MODE_11NG]._param = _v|0x80; \
1366 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1367 _base.params[IEEE80211_MODE_11NA]._param = _v|0x80; \
1369 _base.params[IEEE80211_MODE_11NG]._param = _v|0x80; \
1371 if (_flags & IEEE80211_CHAN_TURBO) { \
1372 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1373 _base.params[IEEE80211_MODE_TURBO_A]._param = 2*_v; \
1374 _base.params[IEEE80211_MODE_TURBO_G]._param = 2*_v; \
1375 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1376 _base.params[IEEE80211_MODE_TURBO_A]._param = 2*_v; \
1378 _base.params[IEEE80211_MODE_TURBO_G]._param = 2*_v; \
1380 if (_flags & IEEE80211_CHAN_STURBO) \
1381 _base.params[IEEE80211_MODE_STURBO_A]._param = 2*_v; \
1382 if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1383 _base.params[IEEE80211_MODE_11A]._param = 2*_v; \
1384 if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1385 _base.params[IEEE80211_MODE_11G]._param = (_v == 5 ? 11 : 2*_v);\
1386 if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1387 _base.params[IEEE80211_MODE_11B]._param = (_v == 5 ? 11 : 2*_v);\
1389 #define _APPLY_RATE1(_flags, _base, _param, _v) do { \
1390 if (_flags & IEEE80211_CHAN_HT) { \
1391 if (_flags & IEEE80211_CHAN_5GHZ) \
1392 _base.params[IEEE80211_MODE_11NA]._param = _v|0x80; \
1394 _base.params[IEEE80211_MODE_11NG]._param = _v|0x80; \
1395 } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \
1396 _base.params[IEEE80211_MODE_TURBO_A]._param = 2*_v; \
1397 else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \
1398 _base.params[IEEE80211_MODE_TURBO_G]._param = 2*_v; \
1399 else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \
1400 _base.params[IEEE80211_MODE_STURBO_A]._param = 2*_v; \
1401 else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1402 _base.params[IEEE80211_MODE_11A]._param = 2*_v; \
1403 else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1404 _base.params[IEEE80211_MODE_11G]._param = (_v == 5 ? 11 : 2*_v);\
1405 else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1406 _base.params[IEEE80211_MODE_11B]._param = (_v == 5 ? 11 : 2*_v);\
1410 DECL_CMD_FUNC(set80211roamrssi, val, d)
1412 double v = atof(val);
1417 errx(-1, "invalid rssi (must be .5 dBm units)");
1418 flags = getmodeflags(val);
1420 if (flags == 0) { /* NB: no flags => current channel */
1421 flags = getcurchan(s)->ic_flags;
1422 _APPLY1(flags, roamparams, rssi, rssi);
1424 _APPLY(flags, roamparams, rssi, rssi);
1425 callback_register(setroam_cb, &roamparams);
1429 DECL_CMD_FUNC(set80211roamrate, val, d)
1431 int v = atoi(val), flags;
1433 flags = getmodeflags(val);
1435 if (flags == 0) { /* NB: no flags => current channel */
1436 flags = getcurchan(s)->ic_flags;
1437 _APPLY_RATE1(flags, roamparams, rate, v);
1439 _APPLY_RATE(flags, roamparams, rate, v);
1440 callback_register(setroam_cb, &roamparams);
1444 DECL_CMD_FUNC(set80211mcastrate, val, d)
1446 int v = atoi(val), flags;
1448 flags = getmodeflags(val);
1450 if (flags == 0) { /* NB: no flags => current channel */
1451 flags = getcurchan(s)->ic_flags;
1452 _APPLY_RATE1(flags, txparams, mcastrate, v);
1454 _APPLY_RATE(flags, txparams, mcastrate, v);
1455 callback_register(settxparams_cb, &txparams);
1459 DECL_CMD_FUNC(set80211mgtrate, val, d)
1461 int v = atoi(val), flags;
1463 flags = getmodeflags(val);
1465 if (flags == 0) { /* NB: no flags => current channel */
1466 flags = getcurchan(s)->ic_flags;
1467 _APPLY_RATE1(flags, txparams, mgmtrate, v);
1469 _APPLY_RATE(flags, txparams, mgmtrate, v);
1470 callback_register(settxparams_cb, &txparams);
1474 DECL_CMD_FUNC(set80211ucastrate, val, d)
1479 flags = getmodeflags(val);
1480 if (isanyarg(val)) {
1481 if (flags == 0) { /* NB: no flags => current channel */
1482 flags = getcurchan(s)->ic_flags;
1483 _APPLY1(flags, txparams, ucastrate,
1484 IEEE80211_FIXED_RATE_NONE);
1486 _APPLY(flags, txparams, ucastrate,
1487 IEEE80211_FIXED_RATE_NONE);
1490 if (flags == 0) { /* NB: no flags => current channel */
1491 flags = getcurchan(s)->ic_flags;
1492 _APPLY_RATE1(flags, txparams, ucastrate, v);
1494 _APPLY_RATE(flags, txparams, ucastrate, v);
1496 callback_register(settxparams_cb, &txparams);
1500 DECL_CMD_FUNC(set80211maxretry, val, d)
1502 int v = atoi(val), flags;
1504 flags = getmodeflags(val);
1506 if (flags == 0) { /* NB: no flags => current channel */
1507 flags = getcurchan(s)->ic_flags;
1508 _APPLY1(flags, txparams, maxretry, v);
1510 _APPLY(flags, txparams, maxretry, v);
1511 callback_register(settxparams_cb, &txparams);
1515 #undef IEEE80211_CHAN_HTA
1516 #undef IEEE80211_CHAN_HTG
1519 DECL_CMD_FUNC(set80211fragthreshold, val, d)
1521 set80211(s, IEEE80211_IOC_FRAGTHRESHOLD,
1522 isundefarg(val) ? IEEE80211_FRAG_MAX : atoi(val), 0, NULL);
1526 DECL_CMD_FUNC(set80211bmissthreshold, val, d)
1528 set80211(s, IEEE80211_IOC_BMISSTHRESHOLD,
1529 isundefarg(val) ? IEEE80211_HWBMISS_MAX : atoi(val), 0, NULL);
1533 set80211burst(const char *val, int d, int s, const struct afswtch *rafp)
1535 set80211(s, IEEE80211_IOC_BURST, d, 0, NULL);
1539 set80211doth(const char *val, int d, int s, const struct afswtch *rafp)
1541 set80211(s, IEEE80211_IOC_DOTH, d, 0, NULL);
1545 set80211dfs(const char *val, int d, int s, const struct afswtch *rafp)
1547 set80211(s, IEEE80211_IOC_DFS, d, 0, NULL);
1551 set80211shortgi(const char *val, int d, int s, const struct afswtch *rafp)
1553 set80211(s, IEEE80211_IOC_SHORTGI,
1554 d ? (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) : 0,
1559 set80211ampdu(const char *val, int d, int s, const struct afswtch *rafp)
1563 if (get80211val(s, IEEE80211_IOC_AMPDU, &du) < 0)
1564 errx(-1, "cannot get AMPDU setting");
1570 set80211(s, IEEE80211_IOC_AMPDU, ampdu, 0, NULL);
1574 DECL_CMD_FUNC(set80211ampdulimit, val, d)
1578 switch (atoi(val)) {
1581 v = IEEE80211_HTCAP_MAXRXAMPDU_8K;
1585 v = IEEE80211_HTCAP_MAXRXAMPDU_16K;
1589 v = IEEE80211_HTCAP_MAXRXAMPDU_32K;
1593 v = IEEE80211_HTCAP_MAXRXAMPDU_64K;
1596 errx(-1, "invalid A-MPDU limit %s", val);
1598 set80211(s, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL);
1602 DECL_CMD_FUNC(set80211ampdudensity, val, d)
1606 if (isanyarg(val) || strcasecmp(val, "na") == 0)
1607 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1608 else switch ((int)(atof(val)*4)) {
1610 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1613 v = IEEE80211_HTCAP_MPDUDENSITY_025;
1616 v = IEEE80211_HTCAP_MPDUDENSITY_05;
1619 v = IEEE80211_HTCAP_MPDUDENSITY_1;
1622 v = IEEE80211_HTCAP_MPDUDENSITY_2;
1625 v = IEEE80211_HTCAP_MPDUDENSITY_4;
1628 v = IEEE80211_HTCAP_MPDUDENSITY_8;
1631 v = IEEE80211_HTCAP_MPDUDENSITY_16;
1634 errx(-1, "invalid A-MPDU density %s", val);
1636 set80211(s, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL);
1640 set80211amsdu(const char *val, int d, int s, const struct afswtch *rafp)
1644 if (get80211val(s, IEEE80211_IOC_AMSDU, &amsdu) < 0)
1645 errx(-1, "cannot get AMSDU setting");
1651 set80211(s, IEEE80211_IOC_AMSDU, amsdu, 0, NULL);
1655 DECL_CMD_FUNC(set80211amsdulimit, val, d)
1657 set80211(s, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL);
1661 set80211puren(const char *val, int d, int s, const struct afswtch *rafp)
1663 set80211(s, IEEE80211_IOC_PUREN, d, 0, NULL);
1667 set80211htcompat(const char *val, int d, int s, const struct afswtch *rafp)
1669 set80211(s, IEEE80211_IOC_HTCOMPAT, d, 0, NULL);
1673 set80211htconf(const char *val, int d, int s, const struct afswtch *rafp)
1675 set80211(s, IEEE80211_IOC_HTCONF, d, 0, NULL);
1680 set80211dwds(const char *val, int d, int s, const struct afswtch *rafp)
1682 set80211(s, IEEE80211_IOC_DWDS, d, 0, NULL);
1686 set80211inact(const char *val, int d, int s, const struct afswtch *rafp)
1688 set80211(s, IEEE80211_IOC_INACTIVITY, d, 0, NULL);
1692 set80211tsn(const char *val, int d, int s, const struct afswtch *rafp)
1694 set80211(s, IEEE80211_IOC_TSN, d, 0, NULL);
1698 set80211dotd(const char *val, int d, int s, const struct afswtch *rafp)
1700 set80211(s, IEEE80211_IOC_DOTD, d, 0, NULL);
1704 set80211smps(const char *val, int d, int s, const struct afswtch *rafp)
1706 set80211(s, IEEE80211_IOC_SMPS, d, 0, NULL);
1710 set80211rifs(const char *val, int d, int s, const struct afswtch *rafp)
1712 set80211(s, IEEE80211_IOC_RIFS, d, 0, NULL);
1716 regdomain_sort(const void *a, const void *b)
1719 (IEEE80211_CHAN_ALLTURBO|IEEE80211_CHAN_HALF|IEEE80211_CHAN_QUARTER)
1720 const struct ieee80211_channel *ca = a;
1721 const struct ieee80211_channel *cb = b;
1723 return ca->ic_freq == cb->ic_freq ?
1724 (ca->ic_flags & CHAN_ALL) - (cb->ic_flags & CHAN_ALL) :
1725 ca->ic_freq - cb->ic_freq;
1729 static const struct ieee80211_channel *
1730 chanlookup(const struct ieee80211_channel chans[], int nchans,
1731 int freq, int flags)
1735 flags &= IEEE80211_CHAN_ALLTURBO;
1736 for (i = 0; i < nchans; i++) {
1737 const struct ieee80211_channel *c = &chans[i];
1738 if (c->ic_freq == freq &&
1739 (c->ic_flags & IEEE80211_CHAN_ALLTURBO) == flags)
1746 regdomain_addchans(struct ieee80211req_chaninfo *ci,
1747 const netband_head *bands,
1748 const struct ieee80211_regdomain *reg,
1750 const struct ieee80211req_chaninfo *avail)
1752 const struct netband *nb;
1753 const struct freqband *b;
1754 struct ieee80211_channel *c, *prev;
1755 int freq, channelSep;
1757 channelSep = (chanFlags & IEEE80211_CHAN_2GHZ) ? 0 : 40;
1758 LIST_FOREACH(nb, bands, next) {
1761 printf("%s: chanFlags 0x%x b %p\n",
1762 __func__, chanFlags, b);
1764 for (freq = b->freqStart; freq <= b->freqEnd; freq += b->chanSep) {
1765 uint32_t flags = nb->flags | b->flags;
1767 /* check if device can operate on this frequency */
1768 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, chanFlags) == NULL) {
1770 printf("%u: skip, flags 0x%x not available\n", freq, chanFlags);
1773 if ((flags & IEEE80211_CHAN_HALF) &&
1774 (chanFlags & IEEE80211_CHAN_HALF) == 0) {
1776 printf("%u: skip, device does not support half-rate channels\n", freq);
1779 if ((flags & IEEE80211_CHAN_QUARTER) &&
1780 (chanFlags & IEEE80211_CHAN_QUARTER) == 0) {
1782 printf("%u: skip, device does not support quarter-rate channels\n", freq);
1785 if ((flags & IEEE80211_CHAN_HT20) &&
1786 (chanFlags & IEEE80211_CHAN_HT20) == 0) {
1788 printf("%u: skip, device does not support HT20 operation\n", freq);
1791 if ((flags & IEEE80211_CHAN_HT40) &&
1792 (chanFlags & IEEE80211_CHAN_HT40) == 0) {
1794 printf("%u: skip, device does not support HT40 operation\n", freq);
1797 if ((flags & REQ_ECM) && !reg->ecm) {
1799 printf("%u: skip, ECM channel\n", freq);
1802 if ((flags & REQ_OUTDOOR) && reg->location == 'I') {
1804 printf("%u: skip, outdoor channel\n", freq);
1807 if ((flags & IEEE80211_CHAN_HT40) &&
1808 prev != NULL && (freq - prev->ic_freq) < channelSep) {
1810 printf("%u: skip, only %u channel "
1811 "separation, need %d\n", freq,
1812 freq - prev->ic_freq, channelSep);
1815 if (ci->ic_nchans == IEEE80211_CHAN_MAX) {
1817 printf("%u: skip, channel table full\n", freq);
1820 c = &ci->ic_chans[ci->ic_nchans++];
1822 c->ic_flags = chanFlags |
1823 (flags &~ (REQ_FLAGS | IEEE80211_CHAN_HT40));
1824 if (c->ic_flags & IEEE80211_CHAN_DFS)
1825 c->ic_maxregpower = nb->maxPowerDFS;
1827 c->ic_maxregpower = nb->maxPower;
1829 printf("[%3d] add freq %u flags 0x%x power %u\n",
1830 ci->ic_nchans-1, c->ic_freq, c->ic_flags,
1832 /* NB: kernel fills in other fields */
1839 regdomain_makechannels(
1840 struct ieee80211_regdomain_req *req,
1841 const struct ieee80211_devcaps_req *dc)
1843 struct regdata *rdp = getregdata();
1844 const struct country *cc;
1845 const struct ieee80211_regdomain *reg = &req->rd;
1846 struct ieee80211req_chaninfo *ci = &req->chaninfo;
1847 const struct regdomain *rd;
1850 * Locate construction table for new channel list. We treat
1851 * the regdomain/SKU as definitive so a country can be in
1852 * multiple with different properties (e.g. US in FCC+FCC3).
1853 * If no regdomain is specified then we fallback on the country
1854 * code to find the associated regdomain since countries always
1855 * belong to at least one regdomain.
1857 if (reg->regdomain == 0) {
1858 cc = lib80211_country_findbycc(rdp, reg->country);
1860 errx(1, "internal error, country %d not found",
1864 rd = lib80211_regdomain_findbysku(rdp, reg->regdomain);
1866 errx(1, "internal error, regdomain %d not found",
1868 if (rd->sku != SKU_DEBUG) {
1869 memset(ci, 0, sizeof(*ci));
1870 if (!LIST_EMPTY(&rd->bands_11b))
1871 regdomain_addchans(ci, &rd->bands_11b, reg,
1872 IEEE80211_CHAN_B, &dc->dc_chaninfo);
1873 if (!LIST_EMPTY(&rd->bands_11g))
1874 regdomain_addchans(ci, &rd->bands_11g, reg,
1875 IEEE80211_CHAN_G, &dc->dc_chaninfo);
1876 if (!LIST_EMPTY(&rd->bands_11a))
1877 regdomain_addchans(ci, &rd->bands_11a, reg,
1878 IEEE80211_CHAN_A, &dc->dc_chaninfo);
1879 if (!LIST_EMPTY(&rd->bands_11na)) {
1880 regdomain_addchans(ci, &rd->bands_11na, reg,
1881 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20,
1883 regdomain_addchans(ci, &rd->bands_11na, reg,
1884 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U,
1886 regdomain_addchans(ci, &rd->bands_11na, reg,
1887 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D,
1890 if (!LIST_EMPTY(&rd->bands_11ng)) {
1891 regdomain_addchans(ci, &rd->bands_11ng, reg,
1892 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20,
1894 regdomain_addchans(ci, &rd->bands_11ng, reg,
1895 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U,
1897 regdomain_addchans(ci, &rd->bands_11ng, reg,
1898 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D,
1901 qsort(ci->ic_chans, ci->ic_nchans, sizeof(ci->ic_chans[0]),
1904 *ci = dc->dc_chaninfo;
1908 list_countries(void)
1910 struct regdata *rdp = getregdata();
1911 const struct country *cp;
1912 const struct regdomain *dp;
1916 printf("\nCountry codes:\n");
1917 LIST_FOREACH(cp, &rdp->countries, next) {
1918 printf("%2s %-15.15s%s", cp->isoname,
1919 cp->name, ((i+1)%4) == 0 ? "\n" : " ");
1923 printf("\nRegulatory domains:\n");
1924 LIST_FOREACH(dp, &rdp->domains, next) {
1925 printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " ");
1932 defaultcountry(const struct regdomain *rd)
1934 struct regdata *rdp = getregdata();
1935 const struct country *cc;
1937 cc = lib80211_country_findbycc(rdp, rd->cc->code);
1939 errx(1, "internal error, ISO country code %d not "
1940 "defined for regdomain %s", rd->cc->code, rd->name);
1941 regdomain.country = cc->code;
1942 regdomain.isocc[0] = cc->isoname[0];
1943 regdomain.isocc[1] = cc->isoname[1];
1947 DECL_CMD_FUNC(set80211regdomain, val, d)
1949 struct regdata *rdp = getregdata();
1950 const struct regdomain *rd;
1952 rd = lib80211_regdomain_findbyname(rdp, val);
1954 rd = lib80211_regdomain_findbysku(rdp, atoi(val));
1956 errx(1, "unknown regdomain %s", val);
1959 regdomain.regdomain = rd->sku;
1960 if (regdomain.country == 0 && rd->cc != NULL) {
1962 * No country code setup and there's a default
1963 * one for this regdomain fill it in.
1967 callback_register(setregdomain_cb, ®domain);
1971 DECL_CMD_FUNC(set80211country, val, d)
1973 struct regdata *rdp = getregdata();
1974 const struct country *cc;
1976 cc = lib80211_country_findbyname(rdp, val);
1978 cc = lib80211_country_findbycc(rdp, atoi(val));
1980 errx(1, "unknown ISO country code %s", val);
1983 regdomain.regdomain = cc->rd->sku;
1984 regdomain.country = cc->code;
1985 regdomain.isocc[0] = cc->isoname[0];
1986 regdomain.isocc[1] = cc->isoname[1];
1987 callback_register(setregdomain_cb, ®domain);
1991 set80211location(const char *val, int d, int s, const struct afswtch *rafp)
1994 regdomain.location = d;
1995 callback_register(setregdomain_cb, ®domain);
1999 set80211ecm(const char *val, int d, int s, const struct afswtch *rafp)
2003 callback_register(setregdomain_cb, ®domain);
2019 if (spacer != '\t') {
2023 col = 8; /* 8-col tab */
2027 LINE_CHECK(const char *fmt, ...)
2034 n = vsnprintf(buf+1, sizeof(buf)-1, fmt, ap);
2047 getmaxrate(const uint8_t rates[15], uint8_t nrates)
2049 int i, maxrate = -1;
2051 for (i = 0; i < nrates; i++) {
2052 int rate = rates[i] & IEEE80211_RATE_VAL;
2060 getcaps(int capinfo)
2062 static char capstring[32];
2063 char *cp = capstring;
2065 if (capinfo & IEEE80211_CAPINFO_ESS)
2067 if (capinfo & IEEE80211_CAPINFO_IBSS)
2069 if (capinfo & IEEE80211_CAPINFO_CF_POLLABLE)
2071 if (capinfo & IEEE80211_CAPINFO_CF_POLLREQ)
2073 if (capinfo & IEEE80211_CAPINFO_PRIVACY)
2075 if (capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)
2077 if (capinfo & IEEE80211_CAPINFO_PBCC)
2079 if (capinfo & IEEE80211_CAPINFO_CHNL_AGILITY)
2081 if (capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME)
2083 if (capinfo & IEEE80211_CAPINFO_RSN)
2085 if (capinfo & IEEE80211_CAPINFO_DSSSOFDM)
2094 static char flagstring[32];
2095 char *cp = flagstring;
2097 if (flags & IEEE80211_NODE_AUTH)
2099 if (flags & IEEE80211_NODE_QOS)
2101 if (flags & IEEE80211_NODE_ERP)
2103 if (flags & IEEE80211_NODE_PWR_MGT)
2105 if (flags & IEEE80211_NODE_HT) {
2107 if (flags & IEEE80211_NODE_HTCOMPAT)
2110 if (flags & IEEE80211_NODE_WPS)
2112 if (flags & IEEE80211_NODE_TSN)
2114 if (flags & IEEE80211_NODE_AMPDU_TX)
2116 if (flags & IEEE80211_NODE_AMPDU_RX)
2118 if (flags & IEEE80211_NODE_MIMO_PS) {
2120 if (flags & IEEE80211_NODE_MIMO_RTS)
2123 if (flags & IEEE80211_NODE_RIFS)
2130 printie(const char* tag, const uint8_t *ie, size_t ielen, int maxlen)
2134 maxlen -= strlen(tag)+2;
2135 if (2*ielen > maxlen)
2138 for (; ielen > 0; ie++, ielen--) {
2141 printf("%02x", *ie);
2149 #define LE_READ_2(p) \
2151 ((((const u_int8_t *)(p))[0] ) | \
2152 (((const u_int8_t *)(p))[1] << 8)))
2153 #define LE_READ_4(p) \
2155 ((((const u_int8_t *)(p))[0] ) | \
2156 (((const u_int8_t *)(p))[1] << 8) | \
2157 (((const u_int8_t *)(p))[2] << 16) | \
2158 (((const u_int8_t *)(p))[3] << 24)))
2161 * NB: The decoding routines assume a properly formatted ie
2162 * which should be safe as the kernel only retains them
2167 printwmeparam(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2169 #define MS(_v, _f) (((_v) & _f) >> _f##_S)
2170 static const char *acnames[] = { "BE", "BK", "VO", "VI" };
2171 const struct ieee80211_wme_param *wme =
2172 (const struct ieee80211_wme_param *) ie;
2178 printf("<qosinfo 0x%x", wme->param_qosInfo);
2179 ie += offsetof(struct ieee80211_wme_param, params_acParams);
2180 for (i = 0; i < WME_NUM_AC; i++) {
2181 const struct ieee80211_wme_acparams *ac =
2182 &wme->params_acParams[i];
2184 printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]"
2186 , MS(ac->acp_aci_aifsn, WME_PARAM_ACM) ? "acm " : ""
2187 , MS(ac->acp_aci_aifsn, WME_PARAM_AIFSN)
2188 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMIN)
2189 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMAX)
2190 , LE_READ_2(&ac->acp_txop)
2198 printwmeinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2202 const struct ieee80211_wme_info *wme =
2203 (const struct ieee80211_wme_info *) ie;
2204 printf("<version 0x%x info 0x%x>",
2205 wme->wme_version, wme->wme_info);
2210 printhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2214 const struct ieee80211_ie_htcap *htcap =
2215 (const struct ieee80211_ie_htcap *) ie;
2219 printf("<cap 0x%x param 0x%x",
2220 LE_READ_2(&htcap->hc_cap), htcap->hc_param);
2223 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2224 if (isset(htcap->hc_mcsset, i)) {
2225 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2226 if (isclr(htcap->hc_mcsset, j))
2230 printf("%s%u", sep, i);
2232 printf("%s%u-%u", sep, i, j);
2236 printf("] extcap 0x%x txbf 0x%x antenna 0x%x>",
2237 LE_READ_2(&htcap->hc_extcap),
2238 LE_READ_4(&htcap->hc_txbf),
2244 printhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2248 const struct ieee80211_ie_htinfo *htinfo =
2249 (const struct ieee80211_ie_htinfo *) ie;
2253 printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel,
2254 htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3,
2255 LE_READ_2(&htinfo->hi_byte45));
2256 printf(" basicmcs[");
2258 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2259 if (isset(htinfo->hi_basicmcsset, i)) {
2260 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2261 if (isclr(htinfo->hi_basicmcsset, j))
2265 printf("%s%u", sep, i);
2267 printf("%s%u-%u", sep, i, j);
2276 printathie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2281 const struct ieee80211_ath_ie *ath =
2282 (const struct ieee80211_ath_ie *)ie;
2285 if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME)
2287 if (ath->ath_capability & ATHEROS_CAP_COMPRESSION)
2289 if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME)
2291 if (ath->ath_capability & ATHEROS_CAP_XR)
2293 if (ath->ath_capability & ATHEROS_CAP_AR)
2295 if (ath->ath_capability & ATHEROS_CAP_BURST)
2297 if (ath->ath_capability & ATHEROS_CAP_WME)
2299 if (ath->ath_capability & ATHEROS_CAP_BOOST)
2301 printf("0x%x>", LE_READ_2(ath->ath_defkeyix));
2306 wpa_cipher(const u_int8_t *sel)
2308 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2309 u_int32_t w = LE_READ_4(sel);
2312 case WPA_SEL(WPA_CSE_NULL):
2314 case WPA_SEL(WPA_CSE_WEP40):
2316 case WPA_SEL(WPA_CSE_WEP104):
2318 case WPA_SEL(WPA_CSE_TKIP):
2320 case WPA_SEL(WPA_CSE_CCMP):
2323 return "?"; /* NB: so 1<< is discarded */
2328 wpa_keymgmt(const u_int8_t *sel)
2330 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2331 u_int32_t w = LE_READ_4(sel);
2334 case WPA_SEL(WPA_ASE_8021X_UNSPEC):
2335 return "8021X-UNSPEC";
2336 case WPA_SEL(WPA_ASE_8021X_PSK):
2338 case WPA_SEL(WPA_ASE_NONE):
2346 printwpaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2348 u_int8_t len = ie[1];
2355 ie += 6, len -= 4; /* NB: len is payload only */
2357 printf("<v%u", LE_READ_2(ie));
2360 printf(" mc:%s", wpa_cipher(ie));
2363 /* unicast ciphers */
2367 for (; n > 0; n--) {
2368 printf("%s%s", sep, wpa_cipher(ie));
2373 /* key management algorithms */
2377 for (; n > 0; n--) {
2378 printf("%s%s", sep, wpa_keymgmt(ie));
2383 if (len > 2) /* optional capabilities */
2384 printf(", caps 0x%x", LE_READ_2(ie));
2390 rsn_cipher(const u_int8_t *sel)
2392 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
2393 u_int32_t w = LE_READ_4(sel);
2396 case RSN_SEL(RSN_CSE_NULL):
2398 case RSN_SEL(RSN_CSE_WEP40):
2400 case RSN_SEL(RSN_CSE_WEP104):
2402 case RSN_SEL(RSN_CSE_TKIP):
2404 case RSN_SEL(RSN_CSE_CCMP):
2406 case RSN_SEL(RSN_CSE_WRAP):
2414 rsn_keymgmt(const u_int8_t *sel)
2416 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
2417 u_int32_t w = LE_READ_4(sel);
2420 case RSN_SEL(RSN_ASE_8021X_UNSPEC):
2421 return "8021X-UNSPEC";
2422 case RSN_SEL(RSN_ASE_8021X_PSK):
2424 case RSN_SEL(RSN_ASE_NONE):
2432 printrsnie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2439 ie += 2, ielen -= 2;
2441 printf("<v%u", LE_READ_2(ie));
2442 ie += 2, ielen -= 2;
2444 printf(" mc:%s", rsn_cipher(ie));
2445 ie += 4, ielen -= 4;
2447 /* unicast ciphers */
2449 ie += 2, ielen -= 2;
2451 for (; n > 0; n--) {
2452 printf("%s%s", sep, rsn_cipher(ie));
2453 ie += 4, ielen -= 4;
2457 /* key management algorithms */
2459 ie += 2, ielen -= 2;
2461 for (; n > 0; n--) {
2462 printf("%s%s", sep, rsn_keymgmt(ie));
2463 ie += 4, ielen -= 4;
2467 if (ielen > 2) /* optional capabilities */
2468 printf(", caps 0x%x", LE_READ_2(ie));
2474 /* XXX move to a public include file */
2475 #define IEEE80211_WPS_DEV_PASS_ID 0x1012
2476 #define IEEE80211_WPS_SELECTED_REG 0x1041
2477 #define IEEE80211_WPS_SETUP_STATE 0x1044
2478 #define IEEE80211_WPS_UUID_E 0x1047
2479 #define IEEE80211_WPS_VERSION 0x104a
2481 #define BE_READ_2(p) \
2483 ((((const u_int8_t *)(p))[1] ) | \
2484 (((const u_int8_t *)(p))[0] << 8)))
2487 printwpsie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2489 #define N(a) (sizeof(a) / sizeof(a[0]))
2490 u_int8_t len = ie[1];
2494 static const char *dev_pass_id[] = {
2495 "D", /* Default (PIN) */
2496 "U", /* User-specified */
2497 "M", /* Machine-specified */
2499 "P", /* PushButton */
2500 "R" /* Registrar-specified */
2504 ie +=6, len -= 4; /* NB: len is payload only */
2506 /* WPS IE in Beacon and Probe Resp frames have different fields */
2509 uint16_t tlv_type = BE_READ_2(ie);
2510 uint16_t tlv_len = BE_READ_2(ie + 2);
2515 case IEEE80211_WPS_VERSION:
2516 printf("v:%d.%d", *ie >> 4, *ie & 0xf);
2518 case IEEE80211_WPS_SETUP_STATE:
2519 /* Only 1 and 2 are valid */
2520 if (*ie == 0 || *ie >= 3)
2523 printf(" st:%s", *ie == 1 ? "N" : "C");
2525 case IEEE80211_WPS_SELECTED_REG:
2526 printf(" sel:%s", *ie ? "T" : "F");
2528 case IEEE80211_WPS_DEV_PASS_ID:
2530 if (n < N(dev_pass_id))
2531 printf(" dpi:%s", dev_pass_id[n]);
2533 case IEEE80211_WPS_UUID_E:
2535 for (n = 0; n < (tlv_len - 1); n++)
2536 printf("%02x-", ie[n]);
2537 printf("%02x", ie[n]);
2540 ie += tlv_len, len -= tlv_len;
2548 * Copy the ssid string contents into buf, truncating to fit. If the
2549 * ssid is entirely printable then just copy intact. Otherwise convert
2550 * to hexadecimal. If the result is truncated then replace the last
2551 * three characters with "...".
2554 copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len)
2560 if (essid_len > bufsize)
2564 /* determine printable or not */
2565 for (i = 0, p = essid; i < maxlen; i++, p++) {
2566 if (*p < ' ' || *p > 0x7e)
2569 if (i != maxlen) { /* not printable, print as hex */
2572 strlcpy(buf, "0x", bufsize);
2575 for (i = 0; i < maxlen && bufsize >= 2; i++) {
2576 sprintf(&buf[2+2*i], "%02x", p[i]);
2580 memcpy(&buf[2+2*i-3], "...", 3);
2581 } else { /* printable, truncate as needed */
2582 memcpy(buf, essid, maxlen);
2583 if (maxlen != essid_len)
2584 memcpy(&buf[maxlen-3], "...", 3);
2590 printssid(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2592 char ssid[2*IEEE80211_NWID_LEN+1];
2594 printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid);
2598 printrates(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2605 for (i = 2; i < ielen; i++) {
2606 printf("%s%s%d", sep,
2607 ie[i] & IEEE80211_RATE_BASIC ? "B" : "",
2608 ie[i] & IEEE80211_RATE_VAL);
2615 printcountry(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2617 const struct ieee80211_country_ie *cie =
2618 (const struct ieee80211_country_ie *) ie;
2619 int i, nbands, schan, nchan;
2621 printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]);
2622 nbands = (cie->len - 3) / sizeof(cie->band[0]);
2623 for (i = 0; i < nbands; i++) {
2624 schan = cie->band[i].schan;
2625 nchan = cie->band[i].nchan;
2627 printf(" %u-%u,%u", schan, schan + nchan-1,
2628 cie->band[i].maxtxpwr);
2630 printf(" %u,%u", schan, cie->band[i].maxtxpwr);
2635 /* unaligned little endian access */
2636 #define LE_READ_4(p) \
2638 ((((const u_int8_t *)(p))[0] ) | \
2639 (((const u_int8_t *)(p))[1] << 8) | \
2640 (((const u_int8_t *)(p))[2] << 16) | \
2641 (((const u_int8_t *)(p))[3] << 24)))
2644 iswpaoui(const u_int8_t *frm)
2646 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI);
2650 iswmeinfo(const u_int8_t *frm)
2652 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
2653 frm[6] == WME_INFO_OUI_SUBTYPE;
2657 iswmeparam(const u_int8_t *frm)
2659 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
2660 frm[6] == WME_PARAM_OUI_SUBTYPE;
2664 isatherosoui(const u_int8_t *frm)
2666 return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI);
2670 iswpsoui(const uint8_t *frm)
2672 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPS_OUI_TYPE<<24)|WPA_OUI);
2679 case IEEE80211_ELEMID_FHPARMS: return " FHPARMS";
2680 case IEEE80211_ELEMID_CFPARMS: return " CFPARMS";
2681 case IEEE80211_ELEMID_TIM: return " TIM";
2682 case IEEE80211_ELEMID_IBSSPARMS:return " IBSSPARMS";
2683 case IEEE80211_ELEMID_CHALLENGE:return " CHALLENGE";
2684 case IEEE80211_ELEMID_PWRCNSTR: return " PWRCNSTR";
2685 case IEEE80211_ELEMID_PWRCAP: return " PWRCAP";
2686 case IEEE80211_ELEMID_TPCREQ: return " TPCREQ";
2687 case IEEE80211_ELEMID_TPCREP: return " TPCREP";
2688 case IEEE80211_ELEMID_SUPPCHAN: return " SUPPCHAN";
2689 case IEEE80211_ELEMID_CHANSWITCHANN:return " CSA";
2690 case IEEE80211_ELEMID_MEASREQ: return " MEASREQ";
2691 case IEEE80211_ELEMID_MEASREP: return " MEASREP";
2692 case IEEE80211_ELEMID_QUIET: return " QUIET";
2693 case IEEE80211_ELEMID_IBSSDFS: return " IBSSDFS";
2694 case IEEE80211_ELEMID_TPC: return " TPC";
2695 case IEEE80211_ELEMID_CCKM: return " CCKM";
2701 printies(const u_int8_t *vp, int ielen, int maxcols)
2705 case IEEE80211_ELEMID_SSID:
2707 printssid(" SSID", vp, 2+vp[1], maxcols);
2709 case IEEE80211_ELEMID_RATES:
2710 case IEEE80211_ELEMID_XRATES:
2712 printrates(vp[0] == IEEE80211_ELEMID_RATES ?
2713 " RATES" : " XRATES", vp, 2+vp[1], maxcols);
2715 case IEEE80211_ELEMID_DSPARMS:
2717 printf(" DSPARMS<%u>", vp[2]);
2719 case IEEE80211_ELEMID_COUNTRY:
2721 printcountry(" COUNTRY", vp, 2+vp[1], maxcols);
2723 case IEEE80211_ELEMID_ERP:
2725 printf(" ERP<0x%x>", vp[2]);
2727 case IEEE80211_ELEMID_VENDOR:
2729 printwpaie(" WPA", vp, 2+vp[1], maxcols);
2730 else if (iswmeinfo(vp))
2731 printwmeinfo(" WME", vp, 2+vp[1], maxcols);
2732 else if (iswmeparam(vp))
2733 printwmeparam(" WME", vp, 2+vp[1], maxcols);
2734 else if (isatherosoui(vp))
2735 printathie(" ATH", vp, 2+vp[1], maxcols);
2736 else if (iswpsoui(vp))
2737 printwpsie(" WPS", vp, 2+vp[1], maxcols);
2739 printie(" VEN", vp, 2+vp[1], maxcols);
2741 case IEEE80211_ELEMID_RSN:
2742 printrsnie(" RSN", vp, 2+vp[1], maxcols);
2744 case IEEE80211_ELEMID_HTCAP:
2745 printhtcap(" HTCAP", vp, 2+vp[1], maxcols);
2747 case IEEE80211_ELEMID_HTINFO:
2749 printhtinfo(" HTINFO", vp, 2+vp[1], maxcols);
2753 printie(iename(vp[0]), vp, 2+vp[1], maxcols);
2762 printmimo(const struct ieee80211_mimo_info *mi)
2764 /* NB: don't muddy display unless there's something to show */
2765 if (mi->rssi[0] != 0 || mi->rssi[1] != 0 || mi->rssi[2] != 0) {
2766 /* XXX ignore EVM for now */
2767 printf(" (rssi %d:%d:%d nf %d:%d:%d)",
2768 mi->rssi[0], mi->rssi[1], mi->rssi[2],
2769 mi->noise[0], mi->noise[1], mi->noise[2]);
2776 uint8_t buf[24*1024];
2777 char ssid[IEEE80211_NWID_LEN+1];
2781 if (get80211len(s, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0)
2782 errx(1, "unable to get scan results");
2783 if (len < sizeof(struct ieee80211req_scan_result))
2788 ssidmax = verbose ? IEEE80211_NWID_LEN : 14;
2789 printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n"
2790 , ssidmax, ssidmax, "SSID"
2800 const struct ieee80211req_scan_result *sr;
2803 sr = (const struct ieee80211req_scan_result *) cp;
2804 vp = cp + sr->isr_ie_off;
2805 printf("%-*.*s %s %3d %3dM %3d:%-3d %3d %-4.4s"
2807 , copy_essid(ssid, ssidmax, vp, sr->isr_ssid_len)
2809 , ether_ntoa((const struct ether_addr *) sr->isr_bssid)
2810 , ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags)
2811 , getmaxrate(sr->isr_rates, sr->isr_nrates)
2812 , (sr->isr_rssi/2)+sr->isr_noise, sr->isr_noise
2814 , getcaps(sr->isr_capinfo)
2816 printies(vp + sr->isr_ssid_len, sr->isr_ie_len, 24);
2818 cp += sr->isr_len, len -= sr->isr_len;
2819 } while (len >= sizeof(struct ieee80211req_scan_result));
2823 #include <net80211/ieee80211_freebsd.h>
2826 #include <net80211/ieee80211_netbsd.h>
2830 scan_and_wait(int s)
2832 struct ieee80211_scan_req sr;
2833 struct ieee80211req ireq;
2836 sroute = socket(PF_ROUTE, SOCK_RAW, 0);
2838 perror("socket(PF_ROUTE,SOCK_RAW)");
2841 (void) memset(&ireq, 0, sizeof(ireq));
2842 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
2843 ireq.i_type = IEEE80211_IOC_SCAN_REQ;
2845 memset(&sr, 0, sizeof(sr));
2846 sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE
2847 | IEEE80211_IOC_SCAN_NOPICK
2848 | IEEE80211_IOC_SCAN_ONCE;
2849 sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER;
2853 ireq.i_len = sizeof(sr);
2854 /* NB: only root can trigger a scan so ignore errors */
2855 if (ioctl(s, SIOCS80211, &ireq) >= 0) {
2857 struct if_announcemsghdr *ifan;
2858 struct rt_msghdr *rtm;
2861 if (read(sroute, buf, sizeof(buf)) < 0) {
2862 perror("read(PF_ROUTE)");
2865 rtm = (struct rt_msghdr *) buf;
2866 if (rtm->rtm_version != RTM_VERSION)
2868 ifan = (struct if_announcemsghdr *) rtm;
2869 } while (rtm->rtm_type != RTM_IEEE80211 ||
2870 ifan->ifan_what != RTM_IEEE80211_SCAN);
2876 DECL_CMD_FUNC(set80211scan, val, d)
2882 static enum ieee80211_opmode get80211opmode(int s);
2885 gettxseq(const struct ieee80211req_sta_info *si)
2887 #define IEEE80211_NODE_QOS 0x0002 /* QoS enabled */
2891 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
2892 return si->isi_txseqs[0];
2893 /* XXX not right but usually what folks want */
2895 for (i = 0; i < IEEE80211_TID_SIZE; i++)
2896 if (si->isi_txseqs[i] > txseq)
2897 txseq = si->isi_txseqs[i];
2899 #undef IEEE80211_NODE_QOS
2903 getrxseq(const struct ieee80211req_sta_info *si)
2905 #define IEEE80211_NODE_QOS 0x0002 /* QoS enabled */
2909 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
2910 return si->isi_rxseqs[0];
2911 /* XXX not right but usually what folks want */
2913 for (i = 0; i < IEEE80211_TID_SIZE; i++)
2914 if (si->isi_rxseqs[i] > rxseq)
2915 rxseq = si->isi_rxseqs[i];
2917 #undef IEEE80211_NODE_QOS
2921 list_stations(int s)
2924 struct ieee80211req_sta_req req;
2925 uint8_t buf[24*1024];
2927 enum ieee80211_opmode opmode = get80211opmode(s);
2931 /* broadcast address =>'s get all stations */
2932 (void) memset(u.req.is_u.macaddr, 0xff, IEEE80211_ADDR_LEN);
2933 if (opmode == IEEE80211_M_STA) {
2935 * Get information about the associated AP.
2937 (void) get80211(s, IEEE80211_IOC_BSSID,
2938 u.req.is_u.macaddr, IEEE80211_ADDR_LEN);
2940 if (get80211len(s, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0)
2941 errx(1, "unable to get station information");
2942 if (len < sizeof(struct ieee80211req_sta_info))
2947 printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %4s\n"
2959 cp = (const uint8_t *) u.req.info;
2961 const struct ieee80211req_sta_info *si;
2963 si = (const struct ieee80211req_sta_info *) cp;
2964 if (si->isi_len < sizeof(*si))
2966 printf("%s %4u %4d %3dM %3.1f %4d %6d %6d %-4.4s %-4.4s"
2967 , ether_ntoa((const struct ether_addr*) si->isi_macaddr)
2968 , IEEE80211_AID(si->isi_associd)
2969 , ieee80211_mhz2ieee(si->isi_freq, si->isi_flags)
2975 , getcaps(si->isi_capinfo)
2976 , getflags(si->isi_state)
2978 printies(cp + si->isi_ie_off, si->isi_ie_len, 24);
2979 printmimo(&si->isi_mimo);
2981 cp += si->isi_len, len -= si->isi_len;
2982 } while (len >= sizeof(struct ieee80211req_sta_info));
2986 get_chaninfo(const struct ieee80211_channel *c, int precise,
2987 char buf[], size_t bsize)
2990 if (IEEE80211_IS_CHAN_FHSS(c))
2991 strlcat(buf, " FHSS", bsize);
2992 if (IEEE80211_IS_CHAN_A(c)) {
2993 if (IEEE80211_IS_CHAN_HALF(c))
2994 strlcat(buf, " 11a/10Mhz", bsize);
2995 else if (IEEE80211_IS_CHAN_QUARTER(c))
2996 strlcat(buf, " 11a/5Mhz", bsize);
2998 strlcat(buf, " 11a", bsize);
3000 if (IEEE80211_IS_CHAN_ANYG(c)) {
3001 if (IEEE80211_IS_CHAN_HALF(c))
3002 strlcat(buf, " 11g/10Mhz", bsize);
3003 else if (IEEE80211_IS_CHAN_QUARTER(c))
3004 strlcat(buf, " 11g/5Mhz", bsize);
3006 strlcat(buf, " 11g", bsize);
3007 } else if (IEEE80211_IS_CHAN_B(c))
3008 strlcat(buf, " 11b", bsize);
3009 if (IEEE80211_IS_CHAN_TURBO(c))
3010 strlcat(buf, " Turbo", bsize);
3012 if (IEEE80211_IS_CHAN_HT20(c))
3013 strlcat(buf, " ht/20", bsize);
3014 else if (IEEE80211_IS_CHAN_HT40D(c))
3015 strlcat(buf, " ht/40-", bsize);
3016 else if (IEEE80211_IS_CHAN_HT40U(c))
3017 strlcat(buf, " ht/40+", bsize);
3019 if (IEEE80211_IS_CHAN_HT(c))
3020 strlcat(buf, " ht", bsize);
3026 print_chaninfo(const struct ieee80211_channel *c, int verb)
3030 printf("Channel %3u : %u%c Mhz%-14.14s",
3031 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
3032 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
3033 get_chaninfo(c, verb, buf, sizeof(buf)));
3037 print_channels(int s, const struct ieee80211req_chaninfo *chans,
3038 int allchans, int verb)
3040 struct ieee80211req_chaninfo achans;
3041 uint8_t reported[IEEE80211_CHAN_BYTES];
3042 const struct ieee80211_channel *c;
3045 memset(&achans, 0, sizeof(achans));
3046 memset(reported, 0, sizeof(reported));
3048 struct ieee80211req_chanlist active;
3050 if (get80211(s, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0)
3051 errx(1, "unable to get active channel list");
3052 memset(&achans, 0, sizeof(achans));
3053 for (i = 0; i < chans->ic_nchans; i++) {
3054 c = &chans->ic_chans[i];
3055 if (!isset(active.ic_channels, c->ic_ieee))
3058 * Suppress compatible duplicates unless
3059 * verbose. The kernel gives us it's
3060 * complete channel list which has separate
3061 * entries for 11g/11b and 11a/turbo.
3063 if (isset(reported, c->ic_ieee) && !verb) {
3064 /* XXX we assume duplicates are adjacent */
3065 achans.ic_chans[achans.ic_nchans-1] = *c;
3067 achans.ic_chans[achans.ic_nchans++] = *c;
3068 setbit(reported, c->ic_ieee);
3072 for (i = 0; i < chans->ic_nchans; i++) {
3073 c = &chans->ic_chans[i];
3074 /* suppress duplicates as above */
3075 if (isset(reported, c->ic_ieee) && !verb) {
3076 /* XXX we assume duplicates are adjacent */
3077 achans.ic_chans[achans.ic_nchans-1] = *c;
3079 achans.ic_chans[achans.ic_nchans++] = *c;
3080 setbit(reported, c->ic_ieee);
3084 half = achans.ic_nchans / 2;
3085 if (achans.ic_nchans % 2)
3088 for (i = 0; i < achans.ic_nchans / 2; i++) {
3089 print_chaninfo(&achans.ic_chans[i], verb);
3090 print_chaninfo(&achans.ic_chans[half+i], verb);
3093 if (achans.ic_nchans % 2) {
3094 print_chaninfo(&achans.ic_chans[i], verb);
3100 list_channels(int s, int allchans)
3103 print_channels(s, &chaninfo, allchans, verbose);
3107 print_txpow(const struct ieee80211_channel *c)
3109 printf("Channel %3u : %u Mhz %3.1f reg %2d ",
3110 c->ic_ieee, c->ic_freq,
3111 c->ic_maxpower/2., c->ic_maxregpower);
3115 print_txpow_verbose(const struct ieee80211_channel *c)
3117 print_chaninfo(c, 1);
3118 printf("min %4.1f dBm max %3.1f dBm reg %2d dBm",
3119 c->ic_minpower/2., c->ic_maxpower/2., c->ic_maxregpower);
3120 /* indicate where regulatory cap limits power use */
3121 if (c->ic_maxpower > 2*c->ic_maxregpower)
3128 struct ieee80211req_chaninfo achans;
3129 uint8_t reported[IEEE80211_CHAN_BYTES];
3130 struct ieee80211_channel *c, *prev;
3134 memset(&achans, 0, sizeof(achans));
3135 memset(reported, 0, sizeof(reported));
3136 for (i = 0; i < chaninfo.ic_nchans; i++) {
3137 c = &chaninfo.ic_chans[i];
3138 /* suppress duplicates as above */
3139 if (isset(reported, c->ic_ieee) && !verbose) {
3140 /* XXX we assume duplicates are adjacent */
3141 prev = &achans.ic_chans[achans.ic_nchans-1];
3142 /* display highest power on channel */
3143 if (c->ic_maxpower > prev->ic_maxpower)
3146 achans.ic_chans[achans.ic_nchans++] = *c;
3147 setbit(reported, c->ic_ieee);
3151 half = achans.ic_nchans / 2;
3152 if (achans.ic_nchans % 2)
3155 for (i = 0; i < achans.ic_nchans / 2; i++) {
3156 print_txpow(&achans.ic_chans[i]);
3157 print_txpow(&achans.ic_chans[half+i]);
3160 if (achans.ic_nchans % 2) {
3161 print_txpow(&achans.ic_chans[i]);
3165 for (i = 0; i < achans.ic_nchans; i++) {
3166 print_txpow_verbose(&achans.ic_chans[i]);
3177 #define IEEE80211_C_BITS \
3178 "\20\1STA\7FF\10TURBOP\11IBSS\12PMGT" \
3179 "\13HOSTAP\14AHDEMO\15SWRETRY\16TXPMGT\17SHSLOT\20SHPREAMBLE" \
3180 "\21MONITOR\22DFS\30WPA1\31WPA2\32BURST\33WME\34WDS\36BGSCAN" \
3183 #define IEEE80211_CRYPTO_BITS \
3184 "\20\1WEP\2TKIP\3AES\4AES_CCM\5TKIPMIC\6CKIP\12PMGT"
3186 #define IEEE80211_HTCAP_BITS \
3187 "\20\1LDPC\2CHWIDTH40\5GREENFIELD\6SHORTGI20\7SHORTGI40\10TXSTBC" \
3188 "\21AMPDU\22AMSDU\23HT"
3191 list_capabilities(int s)
3193 struct ieee80211_devcaps_req dc;
3196 printb("drivercaps", dc.dc_drivercaps, IEEE80211_C_BITS);
3197 if (dc.dc_cryptocaps != 0 || verbose) {
3199 printb("cryptocaps", dc.dc_cryptocaps, IEEE80211_CRYPTO_BITS);
3201 if (dc.dc_htcaps != 0 || verbose) {
3203 printb("htcaps", dc.dc_htcaps, IEEE80211_HTCAP_BITS);
3209 get80211wme(int s, int param, int ac, int *val)
3211 struct ieee80211req ireq;
3213 (void) memset(&ireq, 0, sizeof(ireq));
3214 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
3215 ireq.i_type = param;
3217 if (ioctl(s, SIOCG80211, &ireq) < 0) {
3218 warn("cannot get WME parameter %d, ac %d%s",
3219 param, ac & IEEE80211_WMEPARAM_VAL,
3220 ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : "");
3228 list_wme_aci(int s, const char *tag, int ac)
3232 printf("\t%s", tag);
3234 /* show WME BSS parameters */
3235 if (get80211wme(s, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1)
3236 printf(" cwmin %2u", val);
3237 if (get80211wme(s, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1)
3238 printf(" cwmax %2u", val);
3239 if (get80211wme(s, IEEE80211_IOC_WME_AIFS, ac, &val) != -1)
3240 printf(" aifs %2u", val);
3241 if (get80211wme(s, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1)
3242 printf(" txopLimit %3u", val);
3243 if (get80211wme(s, IEEE80211_IOC_WME_ACM, ac, &val) != -1) {
3250 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
3251 if (get80211wme(s, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) {
3264 static const char *acnames[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
3268 /* display both BSS and local settings */
3269 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) {
3271 if (ac & IEEE80211_WMEPARAM_BSS)
3272 list_wme_aci(s, " ", ac);
3274 list_wme_aci(s, acnames[ac], ac);
3275 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
3276 ac |= IEEE80211_WMEPARAM_BSS;
3279 ac &= ~IEEE80211_WMEPARAM_BSS;
3282 /* display only channel settings */
3283 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++)
3284 list_wme_aci(s, acnames[ac], ac);
3291 const struct ieee80211_roamparam *rp;
3295 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_11NA; mode++) {
3296 rp = &roamparams.params[mode];
3297 if (rp->rssi == 0 && rp->rate == 0)
3300 LINE_CHECK("roam:%-6.6s rssi %2u.5dBm rate %2u Mb/s",
3301 modename[mode], rp->rssi/2, rp->rate/2);
3303 LINE_CHECK("roam:%-6.6s rssi %4udBm rate %2u Mb/s",
3304 modename[mode], rp->rssi/2, rp->rate/2);
3306 for (; mode < IEEE80211_MODE_MAX; mode++) {
3307 rp = &roamparams.params[mode];
3308 if (rp->rssi == 0 && rp->rate == 0)
3311 LINE_CHECK("roam:%-6.6s rssi %2u.5dBm MCS %2u ",
3312 modename[mode], rp->rssi/2, rp->rate &~ 0x80);
3314 LINE_CHECK("roam:%-6.6s rssi %4udBm MCS %2u ",
3315 modename[mode], rp->rssi/2, rp->rate &~ 0x80);
3320 list_txparams(int s)
3322 const struct ieee80211_txparam *tp;
3326 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_11NA; mode++) {
3327 tp = &txparams.params[mode];
3328 if (tp->mgmtrate == 0 && tp->mcastrate == 0)
3330 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
3331 LINE_CHECK("%-6.6s ucast NONE mgmt %2u Mb/s "
3332 "mcast %2u Mb/s maxretry %u",
3333 modename[mode], tp->mgmtrate/2,
3334 tp->mcastrate/2, tp->maxretry);
3336 LINE_CHECK("%-6.6s ucast %2u Mb/s mgmt %2u Mb/s "
3337 "mcast %2u Mb/s maxretry %u",
3338 modename[mode], tp->ucastrate/2, tp->mgmtrate/2,
3339 tp->mcastrate/2, tp->maxretry);
3341 for (; mode < IEEE80211_MODE_MAX; mode++) {
3342 tp = &txparams.params[mode];
3343 if (tp->mgmtrate == 0 && tp->mcastrate == 0)
3345 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
3346 LINE_CHECK("%-6.6s ucast NONE mgmt %2u MCS "
3347 "mcast %2u MCS maxretry %u",
3348 modename[mode], tp->mgmtrate &~ 0x80,
3349 tp->mcastrate &~ 0x80, tp->maxretry);
3351 LINE_CHECK("%-6.6s ucast %2u MCS mgmt %2u MCS "
3352 "mcast %2u MCS maxretry %u",
3353 modename[mode], tp->ucastrate &~ 0x80,
3354 tp->mgmtrate &~ 0x80,
3355 tp->mcastrate &~ 0x80, tp->maxretry);
3360 printpolicy(int policy)
3363 case IEEE80211_MACCMD_POLICY_OPEN:
3364 printf("policy: open\n");
3366 case IEEE80211_MACCMD_POLICY_ALLOW:
3367 printf("policy: allow\n");
3369 case IEEE80211_MACCMD_POLICY_DENY:
3370 printf("policy: deny\n");
3372 case IEEE80211_MACCMD_POLICY_RADIUS:
3373 printf("policy: radius\n");
3376 printf("policy: unknown (%u)\n", policy);
3384 struct ieee80211req ireq;
3385 struct ieee80211req_maclist *acllist;
3386 int i, nacls, policy, len;
3390 (void) memset(&ireq, 0, sizeof(ireq));
3391 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); /* XXX ?? */
3392 ireq.i_type = IEEE80211_IOC_MACCMD;
3393 ireq.i_val = IEEE80211_MACCMD_POLICY;
3394 if (ioctl(s, SIOCG80211, &ireq) < 0) {
3395 if (errno == EINVAL) {
3396 printf("No acl policy loaded\n");
3399 err(1, "unable to get mac policy");
3401 policy = ireq.i_val;
3402 if (policy == IEEE80211_MACCMD_POLICY_OPEN) {
3404 } else if (policy == IEEE80211_MACCMD_POLICY_ALLOW) {
3406 } else if (policy == IEEE80211_MACCMD_POLICY_DENY) {
3408 } else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) {
3409 c = 'r'; /* NB: should never have entries */
3411 printf("policy: unknown (%u)\n", policy);
3414 if (verbose || c == '?')
3415 printpolicy(policy);
3417 ireq.i_val = IEEE80211_MACCMD_LIST;
3419 if (ioctl(s, SIOCG80211, &ireq) < 0)
3420 err(1, "unable to get mac acl list size");
3421 if (ireq.i_len == 0) { /* NB: no acls */
3422 if (!(verbose || c == '?'))
3423 printpolicy(policy);
3430 err(1, "out of memory for acl list");
3433 if (ioctl(s, SIOCG80211, &ireq) < 0)
3434 err(1, "unable to get mac acl list");
3435 nacls = len / sizeof(*acllist);
3436 acllist = (struct ieee80211req_maclist *) data;
3437 for (i = 0; i < nacls; i++)
3438 printf("%c%s\n", c, ether_ntoa(
3439 (const struct ether_addr *) acllist[i].ml_macaddr));
3444 print_regdomain(const struct ieee80211_regdomain *reg, int verb)
3446 if ((reg->regdomain != 0 &&
3447 reg->regdomain != reg->country) || verb) {
3448 const struct regdomain *rd =
3449 lib80211_regdomain_findbysku(getregdata(), reg->regdomain);
3451 LINE_CHECK("regdomain %d", reg->regdomain);
3453 LINE_CHECK("regdomain %s", rd->name);
3455 if (reg->country != 0 || verb) {
3456 const struct country *cc =
3457 lib80211_country_findbycc(getregdata(), reg->country);
3459 LINE_CHECK("country %d", reg->country);
3461 LINE_CHECK("country %s", cc->isoname);
3463 if (reg->location == 'I')
3464 LINE_CHECK("indoor");
3465 else if (reg->location == 'O')
3466 LINE_CHECK("outdoor");
3468 LINE_CHECK("anywhere");
3476 list_regdomain(int s, int channelsalso)
3482 print_regdomain(®domain, 1);
3484 print_channels(s, &chaninfo, 1/*allchans*/, 1/*verbose*/);
3486 print_regdomain(®domain, verbose);
3490 DECL_CMD_FUNC(set80211list, arg, d)
3492 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
3496 if (iseq(arg, "sta"))
3498 else if (iseq(arg, "scan") || iseq(arg, "ap"))
3500 else if (iseq(arg, "chan") || iseq(arg, "freq"))
3501 list_channels(s, 1);
3502 else if (iseq(arg, "active"))
3503 list_channels(s, 0);
3504 else if (iseq(arg, "keys"))
3506 else if (iseq(arg, "caps"))
3507 list_capabilities(s);
3508 else if (iseq(arg, "wme") || iseq(arg, "wmm"))
3510 else if (iseq(arg, "mac"))
3512 else if (iseq(arg, "txpow"))
3514 else if (iseq(arg, "roam"))
3516 else if (iseq(arg, "txparam") || iseq(arg, "txparm"))
3518 else if (iseq(arg, "regdomain"))
3519 list_regdomain(s, 1);
3520 else if (iseq(arg, "countries"))
3523 errx(1, "Don't know how to list %s for %s", arg, name);
3528 static enum ieee80211_opmode
3529 get80211opmode(int s)
3531 struct ifmediareq ifmr;
3533 (void) memset(&ifmr, 0, sizeof(ifmr));
3534 (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
3536 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) {
3537 if (ifmr.ifm_current & IFM_IEEE80211_ADHOC)
3538 return IEEE80211_M_IBSS; /* XXX ahdemo */
3539 if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP)
3540 return IEEE80211_M_HOSTAP;
3541 if (ifmr.ifm_current & IFM_IEEE80211_MONITOR)
3542 return IEEE80211_M_MONITOR;
3544 return IEEE80211_M_STA;
3549 printcipher(int s, struct ieee80211req *ireq, int keylenop)
3551 switch (ireq->i_val) {
3552 case IEEE80211_CIPHER_WEP:
3553 ireq->i_type = keylenop;
3554 if (ioctl(s, SIOCG80211, ireq) != -1)
3556 ireq->i_len <= 5 ? "40" :
3557 ireq->i_len <= 13 ? "104" : "128");
3561 case IEEE80211_CIPHER_TKIP:
3564 case IEEE80211_CIPHER_AES_OCB:
3567 case IEEE80211_CIPHER_AES_CCM:
3570 case IEEE80211_CIPHER_CKIP:
3573 case IEEE80211_CIPHER_NONE:
3577 printf("UNKNOWN (0x%x)", ireq->i_val);
3584 printkey(const struct ieee80211req_key *ik)
3586 static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
3587 int keylen = ik->ik_keylen;
3590 printcontents = printkeys &&
3591 (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose);
3594 switch (ik->ik_type) {
3595 case IEEE80211_CIPHER_WEP:
3597 LINE_CHECK("wepkey %u:%s", ik->ik_keyix+1,
3598 keylen <= 5 ? "40-bit" :
3599 keylen <= 13 ? "104-bit" : "128-bit");
3601 case IEEE80211_CIPHER_TKIP:
3603 keylen -= 128/8; /* ignore MIC for now */
3604 LINE_CHECK("TKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
3606 case IEEE80211_CIPHER_AES_OCB:
3607 LINE_CHECK("AES-OCB %u:%u-bit", ik->ik_keyix+1, 8*keylen);
3609 case IEEE80211_CIPHER_AES_CCM:
3610 LINE_CHECK("AES-CCM %u:%u-bit", ik->ik_keyix+1, 8*keylen);
3612 case IEEE80211_CIPHER_CKIP:
3613 LINE_CHECK("CKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
3615 case IEEE80211_CIPHER_NONE:
3616 LINE_CHECK("NULL %u:%u-bit", ik->ik_keyix+1, 8*keylen);
3619 LINE_CHECK("UNKNOWN (0x%x) %u:%u-bit",
3620 ik->ik_type, ik->ik_keyix+1, 8*keylen);
3623 if (printcontents) {
3627 for (i = 0; i < keylen; i++)
3628 printf("%02x", ik->ik_keydata[i]);
3630 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
3631 (ik->ik_keyrsc != 0 || verbose))
3632 printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc);
3633 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
3634 (ik->ik_keytsc != 0 || verbose))
3635 printf(" tsc %ju", (uintmax_t)ik->ik_keytsc);
3636 if (ik->ik_flags != 0 && verbose) {
3637 const char *sep = " ";
3639 if (ik->ik_flags & IEEE80211_KEY_XMIT)
3640 printf("%stx", sep), sep = "+";
3641 if (ik->ik_flags & IEEE80211_KEY_RECV)
3642 printf("%srx", sep), sep = "+";
3643 if (ik->ik_flags & IEEE80211_KEY_DEFAULT)
3644 printf("%sdef", sep), sep = "+";
3651 printrate(const char *tag, int v, int defrate, int defmcs)
3654 LINE_CHECK("%s 5.5", tag);
3655 else if (v & 0x80) {
3657 LINE_CHECK("%s %d", tag, v &~ 0x80);
3660 LINE_CHECK("%s %d", tag, v/2);
3665 getssid(int s, int ix, void *data, size_t len, int *plen)
3667 struct ieee80211req ireq;
3669 (void) memset(&ireq, 0, sizeof(ireq));
3670 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
3671 ireq.i_type = IEEE80211_IOC_SSID;
3675 if (ioctl(s, SIOCG80211, &ireq) < 0)
3682 ieee80211_status(int s)
3684 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
3685 enum ieee80211_opmode opmode = get80211opmode(s);
3686 int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode;
3688 const struct ieee80211_channel *c;
3689 const struct ieee80211_roamparam *rp;
3690 const struct ieee80211_txparam *tp;
3692 if (getssid(s, -1, data, sizeof(data), &len) < 0) {
3693 /* If we can't get the SSID, this isn't an 802.11 device. */
3698 * Invalidate cached state so printing status for multiple
3699 * if's doesn't reuse the first interfaces' cached state.
3707 if (get80211val(s, IEEE80211_IOC_NUMSSIDS, &num) < 0)
3711 for (i = 0; i < num; i++) {
3712 if (getssid(s, i, data, sizeof(data), &len) >= 0 && len > 0) {
3713 printf(" %d:", i + 1);
3714 print_string(data, len);
3718 print_string(data, len);
3721 if (c->ic_freq != IEEE80211_CHAN_ANY) {
3723 printf(" channel %d (%u Mhz%s)", c->ic_ieee, c->ic_freq,
3724 get_chaninfo(c, 1, buf, sizeof(buf)));
3726 printf(" channel UNDEF");
3728 if (get80211(s, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 &&
3729 (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose))
3730 printf(" bssid %s", ether_ntoa((struct ether_addr *)data));
3732 if (get80211len(s, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) {
3733 printf("\n\tstationname ");
3734 print_string(data, len);
3737 spacer = ' '; /* force first break */
3740 list_regdomain(s, 0);
3743 if (get80211val(s, IEEE80211_IOC_AUTHMODE, &val) != -1) {
3745 case IEEE80211_AUTH_NONE:
3746 LINE_CHECK("authmode NONE");
3748 case IEEE80211_AUTH_OPEN:
3749 LINE_CHECK("authmode OPEN");
3751 case IEEE80211_AUTH_SHARED:
3752 LINE_CHECK("authmode SHARED");
3754 case IEEE80211_AUTH_8021X:
3755 LINE_CHECK("authmode 802.1x");
3757 case IEEE80211_AUTH_WPA:
3758 if (get80211val(s, IEEE80211_IOC_WPA, &wpa) < 0)
3759 wpa = 1; /* default to WPA1 */
3762 LINE_CHECK("authmode WPA2/802.11i");
3765 LINE_CHECK("authmode WPA1+WPA2/802.11i");
3768 LINE_CHECK("authmode WPA");
3772 case IEEE80211_AUTH_AUTO:
3773 LINE_CHECK("authmode AUTO");
3776 LINE_CHECK("authmode UNKNOWN (0x%x)", val);
3781 if (wpa || verbose) {
3782 if (get80211val(s, IEEE80211_IOC_WPS, &val) != -1) {
3788 if (get80211val(s, IEEE80211_IOC_TSN, &val) != -1) {
3794 if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) {
3796 LINE_CHECK("countermeasures");
3798 LINE_CHECK("-countermeasures");
3801 /* XXX not interesting with WPA done in user space */
3802 ireq.i_type = IEEE80211_IOC_KEYMGTALGS;
3803 if (ioctl(s, SIOCG80211, &ireq) != -1) {
3806 ireq.i_type = IEEE80211_IOC_MCASTCIPHER;
3807 if (ioctl(s, SIOCG80211, &ireq) != -1) {
3808 LINE_CHECK("mcastcipher ");
3809 printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN);
3813 ireq.i_type = IEEE80211_IOC_UCASTCIPHER;
3814 if (ioctl(s, SIOCG80211, &ireq) != -1) {
3815 LINE_CHECK("ucastcipher ");
3816 printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN);
3820 ireq.i_type = IEEE80211_IOC_RSNCAPS;
3821 if (ioctl(s, SIOCG80211, &ireq) != -1) {
3822 LINE_CHECK("RSN caps 0x%x", ireq.i_val);
3827 ireq.i_type = IEEE80211_IOC_UCASTCIPHERS;
3828 if (ioctl(s, SIOCG80211, &ireq) != -1) {
3833 if (get80211val(s, IEEE80211_IOC_WEP, &wepmode) != -1 &&
3834 wepmode != IEEE80211_WEP_NOSUP) {
3838 case IEEE80211_WEP_OFF:
3839 LINE_CHECK("privacy OFF");
3841 case IEEE80211_WEP_ON:
3842 LINE_CHECK("privacy ON");
3844 case IEEE80211_WEP_MIXED:
3845 LINE_CHECK("privacy MIXED");
3848 LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode);
3853 * If we get here then we've got WEP support so we need
3854 * to print WEP status.
3857 if (get80211val(s, IEEE80211_IOC_WEPTXKEY, &val) < 0) {
3858 warn("WEP support, but no tx key!");
3862 LINE_CHECK("deftxkey %d", val+1);
3863 else if (wepmode != IEEE80211_WEP_OFF || verbose)
3864 LINE_CHECK("deftxkey UNDEF");
3866 if (get80211val(s, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) {
3867 warn("WEP support, but no NUMWEPKEYS support!");
3872 for (i = 0; i < num; i++) {
3873 struct ieee80211req_key ik;
3875 memset(&ik, 0, sizeof(ik));
3877 if (get80211(s, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) {
3878 warn("WEP support, but can get keys!");
3881 if (ik.ik_keylen != 0) {
3892 if (get80211val(s, IEEE80211_IOC_POWERSAVE, &val) != -1 &&
3893 val != IEEE80211_POWERSAVE_NOSUP ) {
3894 if (val != IEEE80211_POWERSAVE_OFF || verbose) {
3896 case IEEE80211_POWERSAVE_OFF:
3897 LINE_CHECK("powersavemode OFF");
3899 case IEEE80211_POWERSAVE_CAM:
3900 LINE_CHECK("powersavemode CAM");
3902 case IEEE80211_POWERSAVE_PSP:
3903 LINE_CHECK("powersavemode PSP");
3905 case IEEE80211_POWERSAVE_PSP_CAM:
3906 LINE_CHECK("powersavemode PSP-CAM");
3909 if (get80211val(s, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1)
3910 LINE_CHECK("powersavesleep %d", val);
3914 if (get80211val(s, IEEE80211_IOC_TXPOWER, &val) != -1) {
3916 LINE_CHECK("txpower %d.5", val/2);
3918 LINE_CHECK("txpower %d", val/2);
3921 if (get80211val(s, IEEE80211_IOC_TXPOWMAX, &val) != -1)
3922 LINE_CHECK("txpowmax %.1f", val/2.);
3925 if (get80211val(s, IEEE80211_IOC_DOTD, &val) != -1) {
3929 LINE_CHECK("-dotd");
3932 if (get80211val(s, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) {
3933 if (val != IEEE80211_RTS_MAX || verbose)
3934 LINE_CHECK("rtsthreshold %d", val);
3937 if (get80211val(s, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) {
3938 if (val != IEEE80211_FRAG_MAX || verbose)
3939 LINE_CHECK("fragthreshold %d", val);
3941 if (opmode == IEEE80211_M_STA || verbose) {
3942 if (get80211val(s, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) {
3943 if (val != IEEE80211_HWBMISS_MAX || verbose)
3944 LINE_CHECK("bmiss %d", val);
3950 tp = &txparams.params[chan2mode(c)];
3951 printrate("ucastrate", tp->ucastrate,
3952 IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE);
3953 printrate("mcastrate", tp->mcastrate, 2*1, 0x80|0);
3954 printrate("mgmtrate", tp->mgmtrate, 2*1, 0x80|0);
3955 if (tp->maxretry != 6) /* XXX */
3956 LINE_CHECK("maxretry %d", tp->maxretry);
3962 bgscaninterval = -1;
3963 (void) get80211val(s, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval);
3965 if (get80211val(s, IEEE80211_IOC_SCANVALID, &val) != -1) {
3966 if (val != bgscaninterval || verbose)
3967 LINE_CHECK("scanvalid %u", val);
3971 if (get80211val(s, IEEE80211_IOC_BGSCAN, &bgscan) != -1) {
3973 LINE_CHECK("bgscan");
3975 LINE_CHECK("-bgscan");
3977 if (bgscan || verbose) {
3978 if (bgscaninterval != -1)
3979 LINE_CHECK("bgscanintvl %u", bgscaninterval);
3980 if (get80211val(s, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1)
3981 LINE_CHECK("bgscanidle %u", val);
3984 rp = &roamparams.params[chan2mode(c)];
3986 LINE_CHECK("roam:rssi %u.5", rp->rssi/2);
3988 LINE_CHECK("roam:rssi %u", rp->rssi/2);
3989 LINE_CHECK("roam:rate %u", rp->rate/2);
3996 if (IEEE80211_IS_CHAN_ANYG(c) || verbose) {
3997 if (get80211val(s, IEEE80211_IOC_PUREG, &val) != -1) {
3999 LINE_CHECK("pureg");
4001 LINE_CHECK("-pureg");
4003 if (get80211val(s, IEEE80211_IOC_PROTMODE, &val) != -1) {
4005 case IEEE80211_PROTMODE_OFF:
4006 LINE_CHECK("protmode OFF");
4008 case IEEE80211_PROTMODE_CTS:
4009 LINE_CHECK("protmode CTS");
4011 case IEEE80211_PROTMODE_RTSCTS:
4012 LINE_CHECK("protmode RTSCTS");
4015 LINE_CHECK("protmode UNKNOWN (0x%x)", val);
4021 if (IEEE80211_IS_CHAN_HT(c) || verbose) {
4023 switch (htconf & 3) {
4036 if (get80211val(s, IEEE80211_IOC_HTCOMPAT, &val) != -1) {
4038 LINE_CHECK("-htcompat");
4040 LINE_CHECK("htcompat");
4042 if (get80211val(s, IEEE80211_IOC_AMPDU, &val) != -1) {
4045 LINE_CHECK("-ampdu");
4048 LINE_CHECK("ampdutx -ampdurx");
4051 LINE_CHECK("-ampdutx ampdurx");
4055 LINE_CHECK("ampdu");
4059 if (get80211val(s, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) {
4061 case IEEE80211_HTCAP_MAXRXAMPDU_8K:
4062 LINE_CHECK("ampdulimit 8k");
4064 case IEEE80211_HTCAP_MAXRXAMPDU_16K:
4065 LINE_CHECK("ampdulimit 16k");
4067 case IEEE80211_HTCAP_MAXRXAMPDU_32K:
4068 LINE_CHECK("ampdulimit 32k");
4070 case IEEE80211_HTCAP_MAXRXAMPDU_64K:
4071 LINE_CHECK("ampdulimit 64k");
4075 if (get80211val(s, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) {
4077 case IEEE80211_HTCAP_MPDUDENSITY_NA:
4079 LINE_CHECK("ampdudensity NA");
4081 case IEEE80211_HTCAP_MPDUDENSITY_025:
4082 LINE_CHECK("ampdudensity .25");
4084 case IEEE80211_HTCAP_MPDUDENSITY_05:
4085 LINE_CHECK("ampdudensity .5");
4087 case IEEE80211_HTCAP_MPDUDENSITY_1:
4088 LINE_CHECK("ampdudensity 1");
4090 case IEEE80211_HTCAP_MPDUDENSITY_2:
4091 LINE_CHECK("ampdudensity 2");
4093 case IEEE80211_HTCAP_MPDUDENSITY_4:
4094 LINE_CHECK("ampdudensity 4");
4096 case IEEE80211_HTCAP_MPDUDENSITY_8:
4097 LINE_CHECK("ampdudensity 8");
4099 case IEEE80211_HTCAP_MPDUDENSITY_16:
4100 LINE_CHECK("ampdudensity 16");
4104 if (get80211val(s, IEEE80211_IOC_AMSDU, &val) != -1) {
4107 LINE_CHECK("-amsdu");
4110 LINE_CHECK("amsdutx -amsdurx");
4113 LINE_CHECK("-amsdutx amsdurx");
4117 LINE_CHECK("amsdu");
4121 /* XXX amsdu limit */
4122 if (get80211val(s, IEEE80211_IOC_SHORTGI, &val) != -1) {
4124 LINE_CHECK("shortgi");
4126 LINE_CHECK("-shortgi");
4128 if (get80211val(s, IEEE80211_IOC_HTPROTMODE, &val) != -1) {
4129 if (val == IEEE80211_PROTMODE_OFF)
4130 LINE_CHECK("htprotmode OFF");
4131 else if (val != IEEE80211_PROTMODE_RTSCTS)
4132 LINE_CHECK("htprotmode UNKNOWN (0x%x)", val);
4134 LINE_CHECK("htprotmode RTSCTS");
4136 if (get80211val(s, IEEE80211_IOC_PUREN, &val) != -1) {
4138 LINE_CHECK("puren");
4140 LINE_CHECK("-puren");
4142 if (get80211val(s, IEEE80211_IOC_SMPS, &val) != -1) {
4143 if (val == IEEE80211_HTCAP_SMPS_DYNAMIC)
4144 LINE_CHECK("smpsdyn");
4145 else if (val == IEEE80211_HTCAP_SMPS_ENA)
4148 LINE_CHECK("-smps");
4150 if (get80211val(s, IEEE80211_IOC_RIFS, &val) != -1) {
4154 LINE_CHECK("-rifs");
4158 if (get80211val(s, IEEE80211_IOC_WME, &wme) != -1) {
4166 if (get80211val(s, IEEE80211_IOC_BURST, &val) != -1) {
4168 LINE_CHECK("burst");
4170 LINE_CHECK("-burst");
4173 if (get80211val(s, IEEE80211_IOC_FF, &val) != -1) {
4179 if (get80211val(s, IEEE80211_IOC_TURBOP, &val) != -1) {
4181 LINE_CHECK("dturbo");
4183 LINE_CHECK("-dturbo");
4185 if (get80211val(s, IEEE80211_IOC_DWDS, &val) != -1) {
4189 LINE_CHECK("-dwds");
4192 if (opmode == IEEE80211_M_HOSTAP) {
4193 if (get80211val(s, IEEE80211_IOC_HIDESSID, &val) != -1) {
4195 LINE_CHECK("hidessid");
4197 LINE_CHECK("-hidessid");
4199 if (get80211val(s, IEEE80211_IOC_APBRIDGE, &val) != -1) {
4201 LINE_CHECK("-apbridge");
4203 LINE_CHECK("apbridge");
4205 if (get80211val(s, IEEE80211_IOC_DTIM_PERIOD, &val) != -1)
4206 LINE_CHECK("dtimperiod %u", val);
4208 if (get80211val(s, IEEE80211_IOC_DOTH, &val) != -1) {
4210 LINE_CHECK("-doth");
4214 if (get80211val(s, IEEE80211_IOC_DFS, &val) != -1) {
4220 if (get80211val(s, IEEE80211_IOC_INACTIVITY, &val) != -1) {
4222 LINE_CHECK("-inact");
4224 LINE_CHECK("inact");
4227 if (get80211val(s, IEEE80211_IOC_ROAMING, &val) != -1) {
4228 if (val != IEEE80211_ROAMING_AUTO || verbose) {
4230 case IEEE80211_ROAMING_DEVICE:
4231 LINE_CHECK("roaming DEVICE");
4233 case IEEE80211_ROAMING_AUTO:
4234 LINE_CHECK("roaming AUTO");
4236 case IEEE80211_ROAMING_MANUAL:
4237 LINE_CHECK("roaming MANUAL");
4240 LINE_CHECK("roaming UNKNOWN (0x%x)",
4247 if (get80211val(s, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) {
4248 /* XXX default define not visible */
4249 if (val != 100 || verbose)
4250 LINE_CHECK("bintval %u", val);
4253 if (wme && verbose) {
4261 get80211(int s, int type, void *data, int len)
4263 struct ieee80211req ireq;
4265 (void) memset(&ireq, 0, sizeof(ireq));
4266 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
4270 return ioctl(s, SIOCG80211, &ireq);
4274 get80211len(int s, int type, void *data, int len, int *plen)
4276 struct ieee80211req ireq;
4278 (void) memset(&ireq, 0, sizeof(ireq));
4279 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
4283 if (ioctl(s, SIOCG80211, &ireq) < 0)
4290 get80211val(int s, int type, int *val)
4292 struct ieee80211req ireq;
4294 (void) memset(&ireq, 0, sizeof(ireq));
4295 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
4297 if (ioctl(s, SIOCG80211, &ireq) < 0)
4304 set80211(int s, int type, int val, int len, void *data)
4306 struct ieee80211req ireq;
4308 (void) memset(&ireq, 0, sizeof(ireq));
4309 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
4314 if (ioctl(s, SIOCS80211, &ireq) < 0)
4315 err(1, "SIOCS80211");
4319 get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
4327 hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x');
4333 if (sep != NULL && strchr(sep, *val) != NULL) {
4338 if (!isxdigit((u_char)val[0])) {
4339 warnx("bad hexadecimal digits");
4342 if (!isxdigit((u_char)val[1])) {
4343 warnx("odd count hexadecimal digits");
4347 if (p >= buf + len) {
4349 warnx("hexadecimal digits too long");
4351 warnx("string too long");
4355 #define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
4356 *p++ = (tohex((u_char)val[0]) << 4) |
4357 tohex((u_char)val[1]);
4364 /* The string "-" is treated as the empty string. */
4365 if (!hexstr && len == 1 && buf[0] == '-') {
4367 memset(buf, 0, *lenp);
4368 } else if (len < *lenp)
4369 memset(p, 0, *lenp - len);
4375 print_string(const u_int8_t *buf, int len)
4382 for (; i < len; i++) {
4383 if (!isprint(buf[i]) && buf[i] != '\0')
4385 if (isspace(buf[i]))
4389 if (hasspc || len == 0 || buf[0] == '\0')
4390 printf("\"%.*s\"", len, buf);
4392 printf("%.*s", len, buf);
4395 for (i = 0; i < len; i++)
4396 printf("%02x", buf[i]);
4401 * Virtual AP cloning support.
4403 static struct ieee80211_clone_params params = {
4404 .icp_opmode = IEEE80211_M_STA, /* default to station mode */
4408 wlan_create(int s, struct ifreq *ifr)
4410 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
4412 if (params.icp_parent[0] == '\0')
4413 errx(1, "must specify a parent when creating a wlan device");
4414 if (params.icp_opmode == IEEE80211_M_WDS &&
4415 memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0)
4416 errx(1, "no bssid specified for WDS (use wlanbssid)");
4417 ifr->ifr_data = (caddr_t) ¶ms;
4418 if (ioctl(s, SIOCIFCREATE2, ifr) < 0)
4419 err(1, "SIOCIFCREATE2");
4423 DECL_CMD_FUNC(set80211clone_wlandev, arg, d)
4425 strlcpy(params.icp_parent, arg, IFNAMSIZ);
4426 clone_setcallback(wlan_create);
4430 DECL_CMD_FUNC(set80211clone_wlanbssid, arg, d)
4432 const struct ether_addr *ea;
4434 ea = ether_aton(arg);
4436 errx(1, "%s: cannot parse bssid", arg);
4437 memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN);
4438 clone_setcallback(wlan_create);
4442 DECL_CMD_FUNC(set80211clone_wlanaddr, arg, d)
4444 const struct ether_addr *ea;
4446 ea = ether_aton(arg);
4448 errx(1, "%s: cannot parse addres", arg);
4449 memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN);
4450 params.icp_flags |= IEEE80211_CLONE_MACADDR;
4451 clone_setcallback(wlan_create);
4455 DECL_CMD_FUNC(set80211clone_wlanmode, arg, d)
4457 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
4458 if (iseq(arg, "sta"))
4459 params.icp_opmode = IEEE80211_M_STA;
4460 else if (iseq(arg, "ahdemo") || iseq(arg, "adhoc-demo"))
4461 params.icp_opmode = IEEE80211_M_AHDEMO;
4462 else if (iseq(arg, "ibss") || iseq(arg, "adhoc"))
4463 params.icp_opmode = IEEE80211_M_IBSS;
4464 else if (iseq(arg, "ap") || iseq(arg, "host"))
4465 params.icp_opmode = IEEE80211_M_HOSTAP;
4466 else if (iseq(arg, "wds"))
4467 params.icp_opmode = IEEE80211_M_WDS;
4468 else if (iseq(arg, "monitor"))
4469 params.icp_opmode = IEEE80211_M_MONITOR;
4471 errx(1, "Don't know to create %s for %s", arg, name);
4472 clone_setcallback(wlan_create);
4477 set80211clone_beacons(const char *val, int d, int s, const struct afswtch *rafp)
4479 /* NB: inverted sense */
4481 params.icp_flags &= ~IEEE80211_CLONE_NOBEACONS;
4483 params.icp_flags |= IEEE80211_CLONE_NOBEACONS;
4484 clone_setcallback(wlan_create);
4488 set80211clone_bssid(const char *val, int d, int s, const struct afswtch *rafp)
4491 params.icp_flags |= IEEE80211_CLONE_BSSID;
4493 params.icp_flags &= ~IEEE80211_CLONE_BSSID;
4494 clone_setcallback(wlan_create);
4498 set80211clone_wdslegacy(const char *val, int d, int s, const struct afswtch *rafp)
4501 params.icp_flags |= IEEE80211_CLONE_WDSLEGACY;
4503 params.icp_flags &= ~IEEE80211_CLONE_WDSLEGACY;
4504 clone_setcallback(wlan_create);
4507 static struct cmd ieee80211_cmds[] = {
4508 DEF_CMD_ARG("ssid", set80211ssid),
4509 DEF_CMD_ARG("nwid", set80211ssid),
4510 DEF_CMD_ARG("stationname", set80211stationname),
4511 DEF_CMD_ARG("station", set80211stationname), /* BSD/OS */
4512 DEF_CMD_ARG("channel", set80211channel),
4513 DEF_CMD_ARG("authmode", set80211authmode),
4514 DEF_CMD_ARG("powersavemode", set80211powersavemode),
4515 DEF_CMD("powersave", 1, set80211powersave),
4516 DEF_CMD("-powersave", 0, set80211powersave),
4517 DEF_CMD_ARG("powersavesleep", set80211powersavesleep),
4518 DEF_CMD_ARG("wepmode", set80211wepmode),
4519 DEF_CMD("wep", 1, set80211wep),
4520 DEF_CMD("-wep", 0, set80211wep),
4521 DEF_CMD_ARG("deftxkey", set80211weptxkey),
4522 DEF_CMD_ARG("weptxkey", set80211weptxkey),
4523 DEF_CMD_ARG("wepkey", set80211wepkey),
4524 DEF_CMD_ARG("nwkey", set80211nwkey), /* NetBSD */
4525 DEF_CMD("-nwkey", 0, set80211wep), /* NetBSD */
4526 DEF_CMD_ARG("rtsthreshold", set80211rtsthreshold),
4527 DEF_CMD_ARG("protmode", set80211protmode),
4528 DEF_CMD_ARG("txpower", set80211txpower),
4529 DEF_CMD_ARG("roaming", set80211roaming),
4530 DEF_CMD("wme", 1, set80211wme),
4531 DEF_CMD("-wme", 0, set80211wme),
4532 DEF_CMD("wmm", 1, set80211wme),
4533 DEF_CMD("-wmm", 0, set80211wme),
4534 DEF_CMD("hidessid", 1, set80211hidessid),
4535 DEF_CMD("-hidessid", 0, set80211hidessid),
4536 DEF_CMD("apbridge", 1, set80211apbridge),
4537 DEF_CMD("-apbridge", 0, set80211apbridge),
4538 DEF_CMD_ARG("chanlist", set80211chanlist),
4539 DEF_CMD_ARG("bssid", set80211bssid),
4540 DEF_CMD_ARG("ap", set80211bssid),
4541 DEF_CMD("scan", 0, set80211scan),
4542 DEF_CMD_ARG("list", set80211list),
4543 DEF_CMD_ARG2("cwmin", set80211cwmin),
4544 DEF_CMD_ARG2("cwmax", set80211cwmax),
4545 DEF_CMD_ARG2("aifs", set80211aifs),
4546 DEF_CMD_ARG2("txoplimit", set80211txoplimit),
4547 DEF_CMD_ARG("acm", set80211acm),
4548 DEF_CMD_ARG("-acm", set80211noacm),
4549 DEF_CMD_ARG("ack", set80211ackpolicy),
4550 DEF_CMD_ARG("-ack", set80211noackpolicy),
4551 DEF_CMD_ARG2("bss:cwmin", set80211bsscwmin),
4552 DEF_CMD_ARG2("bss:cwmax", set80211bsscwmax),
4553 DEF_CMD_ARG2("bss:aifs", set80211bssaifs),
4554 DEF_CMD_ARG2("bss:txoplimit", set80211bsstxoplimit),
4555 DEF_CMD_ARG("dtimperiod", set80211dtimperiod),
4556 DEF_CMD_ARG("bintval", set80211bintval),
4557 DEF_CMD("mac:open", IEEE80211_MACCMD_POLICY_OPEN, set80211maccmd),
4558 DEF_CMD("mac:allow", IEEE80211_MACCMD_POLICY_ALLOW, set80211maccmd),
4559 DEF_CMD("mac:deny", IEEE80211_MACCMD_POLICY_DENY, set80211maccmd),
4560 DEF_CMD("mac:radius", IEEE80211_MACCMD_POLICY_RADIUS, set80211maccmd),
4561 DEF_CMD("mac:flush", IEEE80211_MACCMD_FLUSH, set80211maccmd),
4562 DEF_CMD("mac:detach", IEEE80211_MACCMD_DETACH, set80211maccmd),
4563 DEF_CMD_ARG("mac:add", set80211addmac),
4564 DEF_CMD_ARG("mac:del", set80211delmac),
4565 DEF_CMD_ARG("mac:kick", set80211kickmac),
4566 DEF_CMD("pureg", 1, set80211pureg),
4567 DEF_CMD("-pureg", 0, set80211pureg),
4568 DEF_CMD("ff", 1, set80211fastframes),
4569 DEF_CMD("-ff", 0, set80211fastframes),
4570 DEF_CMD("dturbo", 1, set80211dturbo),
4571 DEF_CMD("-dturbo", 0, set80211dturbo),
4572 DEF_CMD("bgscan", 1, set80211bgscan),
4573 DEF_CMD("-bgscan", 0, set80211bgscan),
4574 DEF_CMD_ARG("bgscanidle", set80211bgscanidle),
4575 DEF_CMD_ARG("bgscanintvl", set80211bgscanintvl),
4576 DEF_CMD_ARG("scanvalid", set80211scanvalid),
4577 DEF_CMD_ARG("roam:rssi", set80211roamrssi),
4578 DEF_CMD_ARG("roam:rate", set80211roamrate),
4579 DEF_CMD_ARG("mcastrate", set80211mcastrate),
4580 DEF_CMD_ARG("ucastrate", set80211ucastrate),
4581 DEF_CMD_ARG("mgtrate", set80211mgtrate),
4582 DEF_CMD_ARG("mgmtrate", set80211mgtrate),
4583 DEF_CMD_ARG("maxretry", set80211maxretry),
4584 DEF_CMD_ARG("fragthreshold", set80211fragthreshold),
4585 DEF_CMD("burst", 1, set80211burst),
4586 DEF_CMD("-burst", 0, set80211burst),
4587 DEF_CMD_ARG("bmiss", set80211bmissthreshold),
4588 DEF_CMD_ARG("bmissthreshold", set80211bmissthreshold),
4589 DEF_CMD("shortgi", 1, set80211shortgi),
4590 DEF_CMD("-shortgi", 0, set80211shortgi),
4591 DEF_CMD("ampdurx", 2, set80211ampdu),
4592 DEF_CMD("-ampdurx", -2, set80211ampdu),
4593 DEF_CMD("ampdutx", 1, set80211ampdu),
4594 DEF_CMD("-ampdutx", -1, set80211ampdu),
4595 DEF_CMD("ampdu", 3, set80211ampdu), /* NB: tx+rx */
4596 DEF_CMD("-ampdu", -3, set80211ampdu),
4597 DEF_CMD_ARG("ampdulimit", set80211ampdulimit),
4598 DEF_CMD_ARG("ampdudensity", set80211ampdudensity),
4599 DEF_CMD("amsdurx", 2, set80211amsdu),
4600 DEF_CMD("-amsdurx", -2, set80211amsdu),
4601 DEF_CMD("amsdutx", 1, set80211amsdu),
4602 DEF_CMD("-amsdutx", -1, set80211amsdu),
4603 DEF_CMD("amsdu", 3, set80211amsdu), /* NB: tx+rx */
4604 DEF_CMD("-amsdu", -3, set80211amsdu),
4605 DEF_CMD_ARG("amsdulimit", set80211amsdulimit),
4606 DEF_CMD("puren", 1, set80211puren),
4607 DEF_CMD("-puren", 0, set80211puren),
4608 DEF_CMD("doth", 1, set80211doth),
4609 DEF_CMD("-doth", 0, set80211doth),
4610 DEF_CMD("dfs", 1, set80211dfs),
4611 DEF_CMD("-dfs", 0, set80211dfs),
4612 DEF_CMD("htcompat", 1, set80211htcompat),
4613 DEF_CMD("-htcompat", 0, set80211htcompat),
4614 DEF_CMD("dwds", 1, set80211dwds),
4615 DEF_CMD("-dwds", 0, set80211dwds),
4616 DEF_CMD("inact", 1, set80211inact),
4617 DEF_CMD("-inact", 0, set80211inact),
4618 DEF_CMD("tsn", 1, set80211tsn),
4619 DEF_CMD("-tsn", 0, set80211tsn),
4620 DEF_CMD_ARG("regdomain", set80211regdomain),
4621 DEF_CMD_ARG("country", set80211country),
4622 DEF_CMD("indoor", 'I', set80211location),
4623 DEF_CMD("-indoor", 'O', set80211location),
4624 DEF_CMD("outdoor", 'O', set80211location),
4625 DEF_CMD("-outdoor", 'I', set80211location),
4626 DEF_CMD("anywhere", ' ', set80211location),
4627 DEF_CMD("ecm", 1, set80211ecm),
4628 DEF_CMD("-ecm", 0, set80211ecm),
4629 DEF_CMD("dotd", 1, set80211dotd),
4630 DEF_CMD("-dotd", 0, set80211dotd),
4631 DEF_CMD_ARG("htprotmode", set80211htprotmode),
4632 DEF_CMD("ht20", 1, set80211htconf),
4633 DEF_CMD("-ht20", 0, set80211htconf),
4634 DEF_CMD("ht40", 3, set80211htconf), /* NB: 20+40 */
4635 DEF_CMD("-ht40", 0, set80211htconf),
4636 DEF_CMD("ht", 3, set80211htconf), /* NB: 20+40 */
4637 DEF_CMD("-ht", 0, set80211htconf),
4638 DEF_CMD("rifs", 1, set80211rifs),
4639 DEF_CMD("-rifs", 0, set80211rifs),
4640 DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA, set80211smps),
4641 DEF_CMD("smpsdyn", IEEE80211_HTCAP_SMPS_DYNAMIC, set80211smps),
4642 DEF_CMD("-smps", IEEE80211_HTCAP_SMPS_OFF, set80211smps),
4643 /* XXX for testing */
4644 DEF_CMD_ARG("chanswitch", set80211chanswitch),
4646 /* vap cloning support */
4647 DEF_CLONE_CMD_ARG("wlanaddr", set80211clone_wlanaddr),
4648 DEF_CLONE_CMD_ARG("wlanbssid", set80211clone_wlanbssid),
4649 DEF_CLONE_CMD_ARG("wlandev", set80211clone_wlandev),
4650 DEF_CLONE_CMD_ARG("wlanmode", set80211clone_wlanmode),
4651 DEF_CLONE_CMD("beacons", 1, set80211clone_beacons),
4652 DEF_CLONE_CMD("-beacons", 0, set80211clone_beacons),
4653 DEF_CLONE_CMD("bssid", 1, set80211clone_bssid),
4654 DEF_CLONE_CMD("-bssid", 0, set80211clone_bssid),
4655 DEF_CLONE_CMD("wdslegacy", 1, set80211clone_wdslegacy),
4656 DEF_CLONE_CMD("-wdslegacy", 0, set80211clone_wdslegacy),
4658 static struct afswtch af_ieee80211 = {
4659 .af_name = "af_ieee80211",
4661 .af_other_status = ieee80211_status,
4664 static __constructor void
4665 ieee80211_ctor(void)
4667 #define N(a) (sizeof(a) / sizeof(a[0]))
4670 for (i = 0; i < N(ieee80211_cmds); i++)
4671 cmd_register(&ieee80211_cmds[i]);
4672 af_register(&af_ieee80211);