2 * Copyright 2001 The Aerospace Corporation. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of The Aerospace Corporation may not be used to endorse or
13 * promote products derived from this software.
15 * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
32 * All rights reserved.
34 * This code is derived from software contributed to The NetBSD Foundation
35 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
36 * NASA Ames Research Center.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
47 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
48 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
49 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
51 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57 * POSSIBILITY OF SUCH DAMAGE.
60 #include <sys/param.h>
61 #include <sys/ioctl.h>
62 #include <sys/socket.h>
63 #include <sys/sysctl.h>
66 #include <net/ethernet.h>
68 #include <net/if_dl.h>
69 #include <net/if_types.h>
70 #include <net/if_media.h>
71 #include <net/route.h>
73 #include <net80211/ieee80211_ioctl.h>
74 #include <net80211/ieee80211_freebsd.h>
75 #include <net80211/ieee80211_superg.h>
76 #include <net80211/ieee80211_tdma.h>
77 #include <net80211/ieee80211_mesh.h>
90 #include <stddef.h> /* NB: for offsetof */
94 #include <lib80211/lib80211_regdomain.h>
95 #include <lib80211/lib80211_ioctl.h>
97 #ifndef IEEE80211_FIXED_RATE_NONE
98 #define IEEE80211_FIXED_RATE_NONE 0xff
101 /* XXX need these publicly defined or similar */
102 #ifndef IEEE80211_NODE_AUTH
103 #define IEEE80211_NODE_AUTH 0x000001 /* authorized for data */
104 #define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */
105 #define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */
106 #define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */
107 #define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */
108 #define IEEE80211_NODE_HT 0x000040 /* HT enabled */
109 #define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */
110 #define IEEE80211_NODE_WPS 0x000100 /* WPS association */
111 #define IEEE80211_NODE_TSN 0x000200 /* TSN association */
112 #define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */
113 #define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */
114 #define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */
115 #define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */
116 #define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */
117 #define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */
118 #define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */
119 #define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */
120 #define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */
121 #define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */
124 #define MAXCHAN 1536 /* max 1.5K channels */
130 static void LINE_INIT(char c);
131 static void LINE_BREAK(void);
132 static void LINE_CHECK(const char *fmt, ...);
134 static const char *modename[IEEE80211_MODE_MAX] = {
135 [IEEE80211_MODE_AUTO] = "auto",
136 [IEEE80211_MODE_11A] = "11a",
137 [IEEE80211_MODE_11B] = "11b",
138 [IEEE80211_MODE_11G] = "11g",
139 [IEEE80211_MODE_FH] = "fh",
140 [IEEE80211_MODE_TURBO_A] = "turboA",
141 [IEEE80211_MODE_TURBO_G] = "turboG",
142 [IEEE80211_MODE_STURBO_A] = "sturbo",
143 [IEEE80211_MODE_11NA] = "11na",
144 [IEEE80211_MODE_11NG] = "11ng",
145 [IEEE80211_MODE_HALF] = "half",
146 [IEEE80211_MODE_QUARTER] = "quarter"
149 static void set80211(int s, int type, int val, int len, void *data);
150 static int get80211(int s, int type, void *data, int len);
151 static int get80211len(int s, int type, void *data, int len, int *plen);
152 static int get80211val(int s, int type, int *val);
153 static const char *get_string(const char *val, const char *sep,
154 u_int8_t *buf, int *lenp);
155 static void print_string(const u_int8_t *buf, int len);
156 static void print_regdomain(const struct ieee80211_regdomain *, int);
157 static void print_channels(int, const struct ieee80211req_chaninfo *,
158 int allchans, int verbose);
159 static void regdomain_makechannels(struct ieee80211_regdomain_req *,
160 const struct ieee80211_devcaps_req *);
161 static const char *mesh_linkstate_string(uint8_t state);
163 static struct ieee80211req_chaninfo *chaninfo;
164 static struct ieee80211_regdomain regdomain;
165 static int gotregdomain = 0;
166 static struct ieee80211_roamparams_req roamparams;
167 static int gotroam = 0;
168 static struct ieee80211_txparams_req txparams;
169 static int gottxparams = 0;
170 static struct ieee80211_channel curchan;
171 static int gotcurchan = 0;
172 static struct ifmediareq *ifmr;
173 static int htconf = 0;
174 static int gothtconf = 0;
181 if (get80211val(s, IEEE80211_IOC_HTCONF, &htconf) < 0)
182 warn("unable to get HT configuration information");
187 * Collect channel info from the kernel. We use this (mostly)
188 * to handle mapping between frequency and IEEE channel number.
193 if (chaninfo != NULL)
195 chaninfo = malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN));
196 if (chaninfo == NULL)
197 errx(1, "no space for channel list");
198 if (get80211(s, IEEE80211_IOC_CHANINFO, chaninfo,
199 IEEE80211_CHANINFO_SIZE(MAXCHAN)) < 0)
200 err(1, "unable to get channel information");
201 ifmr = ifmedia_getstate(s);
205 static struct regdata *
208 static struct regdata *rdp = NULL;
210 rdp = lib80211_alloc_regdata();
212 errx(-1, "missing or corrupted regdomain database");
218 * Given the channel at index i with attributes from,
219 * check if there is a channel with attributes to in
220 * the channel table. With suitable attributes this
221 * allows the caller to look for promotion; e.g. from
225 canpromote(int i, int from, int to)
227 const struct ieee80211_channel *fc = &chaninfo->ic_chans[i];
230 if ((fc->ic_flags & from) != from)
232 /* NB: quick check exploiting ordering of chans w/ same frequency */
233 if (i+1 < chaninfo->ic_nchans &&
234 chaninfo->ic_chans[i+1].ic_freq == fc->ic_freq &&
235 (chaninfo->ic_chans[i+1].ic_flags & to) == to)
237 /* brute force search in case channel list is not ordered */
238 for (j = 0; j < chaninfo->ic_nchans; j++) {
239 const struct ieee80211_channel *tc = &chaninfo->ic_chans[j];
241 tc->ic_freq == fc->ic_freq && (tc->ic_flags & to) == to)
248 * Handle channel promotion. When a channel is specified with
249 * only a frequency we want to promote it to the ``best'' channel
250 * available. The channel list has separate entries for 11b, 11g,
251 * 11a, and 11n[ga] channels so specifying a frequency w/o any
252 * attributes requires we upgrade, e.g. from 11b -> 11g. This
253 * gets complicated when the channel is specified on the same
254 * command line with a media request that constrains the available
255 * channe list (e.g. mode 11a); we want to honor that to avoid
256 * confusing behaviour.
262 * Query the current mode of the interface in case it's
263 * constrained (e.g. to 11a). We must do this carefully
264 * as there may be a pending ifmedia request in which case
265 * asking the kernel will give us the wrong answer. This
266 * is an unfortunate side-effect of the way ifconfig is
267 * structure for modularity (yech).
269 * NB: ifmr is actually setup in getchaninfo (above); we
270 * assume it's called coincident with to this call so
271 * we have a ``current setting''; otherwise we must pass
272 * the socket descriptor down to here so we can make
273 * the ifmedia_getstate call ourselves.
275 int chanmode = ifmr != NULL ? IFM_MODE(ifmr->ifm_current) : IFM_AUTO;
277 /* when ambiguous promote to ``best'' */
278 /* NB: we abitrarily pick HT40+ over HT40- */
279 if (chanmode != IFM_IEEE80211_11B)
280 i = canpromote(i, IEEE80211_CHAN_B, IEEE80211_CHAN_G);
281 if (chanmode != IFM_IEEE80211_11G && (htconf & 1)) {
282 i = canpromote(i, IEEE80211_CHAN_G,
283 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20);
285 i = canpromote(i, IEEE80211_CHAN_G,
286 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D);
287 i = canpromote(i, IEEE80211_CHAN_G,
288 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U);
291 if (chanmode != IFM_IEEE80211_11A && (htconf & 1)) {
292 i = canpromote(i, IEEE80211_CHAN_A,
293 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20);
295 i = canpromote(i, IEEE80211_CHAN_A,
296 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D);
297 i = canpromote(i, IEEE80211_CHAN_A,
298 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U);
305 mapfreq(struct ieee80211_channel *chan, int freq, int flags)
309 for (i = 0; i < chaninfo->ic_nchans; i++) {
310 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
312 if (c->ic_freq == freq && (c->ic_flags & flags) == flags) {
314 /* when ambiguous promote to ``best'' */
315 c = &chaninfo->ic_chans[promote(i)];
321 errx(1, "unknown/undefined frequency %u/0x%x", freq, flags);
325 mapchan(struct ieee80211_channel *chan, int ieee, int flags)
329 for (i = 0; i < chaninfo->ic_nchans; i++) {
330 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
332 if (c->ic_ieee == ieee && (c->ic_flags & flags) == flags) {
334 /* when ambiguous promote to ``best'' */
335 c = &chaninfo->ic_chans[promote(i)];
341 errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags);
344 static const struct ieee80211_channel *
349 if (get80211(s, IEEE80211_IOC_CURCHAN, &curchan, sizeof(curchan)) < 0) {
351 /* fall back to legacy ioctl */
352 if (get80211val(s, IEEE80211_IOC_CHANNEL, &val) < 0)
353 err(-1, "cannot figure out current channel");
355 mapchan(&curchan, val, 0);
361 static enum ieee80211_phymode
362 chan2mode(const struct ieee80211_channel *c)
364 if (IEEE80211_IS_CHAN_HTA(c))
365 return IEEE80211_MODE_11NA;
366 if (IEEE80211_IS_CHAN_HTG(c))
367 return IEEE80211_MODE_11NG;
368 if (IEEE80211_IS_CHAN_108A(c))
369 return IEEE80211_MODE_TURBO_A;
370 if (IEEE80211_IS_CHAN_108G(c))
371 return IEEE80211_MODE_TURBO_G;
372 if (IEEE80211_IS_CHAN_ST(c))
373 return IEEE80211_MODE_STURBO_A;
374 if (IEEE80211_IS_CHAN_FHSS(c))
375 return IEEE80211_MODE_FH;
376 if (IEEE80211_IS_CHAN_HALF(c))
377 return IEEE80211_MODE_HALF;
378 if (IEEE80211_IS_CHAN_QUARTER(c))
379 return IEEE80211_MODE_QUARTER;
380 if (IEEE80211_IS_CHAN_A(c))
381 return IEEE80211_MODE_11A;
382 if (IEEE80211_IS_CHAN_ANYG(c))
383 return IEEE80211_MODE_11G;
384 if (IEEE80211_IS_CHAN_B(c))
385 return IEEE80211_MODE_11B;
386 return IEEE80211_MODE_AUTO;
394 if (get80211(s, IEEE80211_IOC_ROAM,
395 &roamparams, sizeof(roamparams)) < 0)
396 err(1, "unable to get roaming parameters");
401 setroam_cb(int s, void *arg)
403 struct ieee80211_roamparams_req *roam = arg;
404 set80211(s, IEEE80211_IOC_ROAM, 0, sizeof(*roam), roam);
412 if (get80211(s, IEEE80211_IOC_TXPARAMS,
413 &txparams, sizeof(txparams)) < 0)
414 err(1, "unable to get transmit parameters");
419 settxparams_cb(int s, void *arg)
421 struct ieee80211_txparams_req *txp = arg;
422 set80211(s, IEEE80211_IOC_TXPARAMS, 0, sizeof(*txp), txp);
430 if (get80211(s, IEEE80211_IOC_REGDOMAIN,
431 ®domain, sizeof(regdomain)) < 0)
432 err(1, "unable to get regulatory domain info");
437 getdevcaps(int s, struct ieee80211_devcaps_req *dc)
439 if (get80211(s, IEEE80211_IOC_DEVCAPS, dc,
440 IEEE80211_DEVCAPS_SPACE(dc)) < 0)
441 err(1, "unable to get device capabilities");
445 setregdomain_cb(int s, void *arg)
447 struct ieee80211_regdomain_req *req;
448 struct ieee80211_regdomain *rd = arg;
449 struct ieee80211_devcaps_req *dc;
450 struct regdata *rdp = getregdata();
452 if (rd->country != NO_COUNTRY) {
453 const struct country *cc;
455 * Check current country seting to make sure it's
456 * compatible with the new regdomain. If not, then
457 * override it with any default country for this
458 * SKU. If we cannot arrange a match, then abort.
460 cc = lib80211_country_findbycc(rdp, rd->country);
462 errx(1, "unknown ISO country code %d", rd->country);
463 if (cc->rd->sku != rd->regdomain) {
464 const struct regdomain *rp;
466 * Check if country is incompatible with regdomain.
467 * To enable multiple regdomains for a country code
468 * we permit a mismatch between the regdomain and
469 * the country's associated regdomain when the
470 * regdomain is setup w/o a default country. For
471 * example, US is bound to the FCC regdomain but
472 * we allow US to be combined with FCC3 because FCC3
473 * has not default country. This allows bogus
474 * combinations like FCC3+DK which are resolved when
475 * constructing the channel list by deferring to the
476 * regdomain to construct the channel list.
478 rp = lib80211_regdomain_findbysku(rdp, rd->regdomain);
480 errx(1, "country %s (%s) is not usable with "
481 "regdomain %d", cc->isoname, cc->name,
483 else if (rp->cc != NULL && rp->cc != cc)
484 errx(1, "country %s (%s) is not usable with "
485 "regdomain %s", cc->isoname, cc->name,
490 * Fetch the device capabilities and calculate the
491 * full set of netbands for which we request a new
492 * channel list be constructed. Once that's done we
493 * push the regdomain info + channel list to the kernel.
495 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
497 errx(1, "no space for device capabilities");
498 dc->dc_chaninfo.ic_nchans = MAXCHAN;
502 printf("drivercaps: 0x%x\n", dc->dc_drivercaps);
503 printf("cryptocaps: 0x%x\n", dc->dc_cryptocaps);
504 printf("htcaps : 0x%x\n", dc->dc_htcaps);
505 memcpy(chaninfo, &dc->dc_chaninfo,
506 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
507 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, 1/*verbose*/);
510 req = malloc(IEEE80211_REGDOMAIN_SIZE(dc->dc_chaninfo.ic_nchans));
512 errx(1, "no space for regdomain request");
514 regdomain_makechannels(req, dc);
517 print_regdomain(rd, 1/*verbose*/);
519 /* blech, reallocate channel list for new data */
520 if (chaninfo != NULL)
522 chaninfo = malloc(IEEE80211_CHANINFO_SPACE(&req->chaninfo));
523 if (chaninfo == NULL)
524 errx(1, "no space for channel list");
525 memcpy(chaninfo, &req->chaninfo,
526 IEEE80211_CHANINFO_SPACE(&req->chaninfo));
527 print_channels(s, &req->chaninfo, 1/*allchans*/, 1/*verbose*/);
529 if (req->chaninfo.ic_nchans == 0)
530 errx(1, "no channels calculated");
531 set80211(s, IEEE80211_IOC_REGDOMAIN, 0,
532 IEEE80211_REGDOMAIN_SPACE(req), req);
538 ieee80211_mhz2ieee(int freq, int flags)
540 struct ieee80211_channel chan;
541 mapfreq(&chan, freq, flags);
546 isanyarg(const char *arg)
548 return (strncmp(arg, "-", 1) == 0 ||
549 strncasecmp(arg, "any", 3) == 0 || strncasecmp(arg, "off", 3) == 0);
553 set80211ssid(const char *val, int d, int s, const struct afswtch *rafp)
557 u_int8_t data[IEEE80211_NWID_LEN];
561 if (len > 2 && isdigit((int)val[0]) && val[1] == ':') {
566 bzero(data, sizeof(data));
568 if (get_string(val, NULL, data, &len) == NULL)
571 set80211(s, IEEE80211_IOC_SSID, ssid, len, data);
575 set80211meshid(const char *val, int d, int s, const struct afswtch *rafp)
578 u_int8_t data[IEEE80211_NWID_LEN];
580 memset(data, 0, sizeof(data));
582 if (get_string(val, NULL, data, &len) == NULL)
585 set80211(s, IEEE80211_IOC_MESH_ID, 0, len, data);
589 set80211stationname(const char *val, int d, int s, const struct afswtch *rafp)
594 bzero(data, sizeof(data));
596 get_string(val, NULL, data, &len);
598 set80211(s, IEEE80211_IOC_STATIONNAME, 0, len, data);
602 * Parse a channel specification for attributes/flags.
604 * freq/xx channel width (5,10,20,40,40+,40-)
605 * freq:mode channel mode (a,b,g,h,n,t,s,d)
607 * These can be combined in either order; e.g. 2437:ng/40.
608 * Modes are case insensitive.
610 * The result is not validated here; it's assumed to be
611 * checked against the channel table fetched from the kernel.
614 getchannelflags(const char *val, int freq)
616 #define _CHAN_HT 0x80000000
622 cp = strchr(val, ':');
624 for (cp++; isalpha((int) *cp); cp++) {
625 /* accept mixed case */
630 case 'a': /* 802.11a */
631 flags |= IEEE80211_CHAN_A;
633 case 'b': /* 802.11b */
634 flags |= IEEE80211_CHAN_B;
636 case 'g': /* 802.11g */
637 flags |= IEEE80211_CHAN_G;
639 case 'h': /* ht = 802.11n */
640 case 'n': /* 802.11n */
641 flags |= _CHAN_HT; /* NB: private */
643 case 'd': /* dt = Atheros Dynamic Turbo */
644 flags |= IEEE80211_CHAN_TURBO;
646 case 't': /* ht, dt, st, t */
647 /* dt and unadorned t specify Dynamic Turbo */
648 if ((flags & (IEEE80211_CHAN_STURBO|_CHAN_HT)) == 0)
649 flags |= IEEE80211_CHAN_TURBO;
651 case 's': /* st = Atheros Static Turbo */
652 flags |= IEEE80211_CHAN_STURBO;
655 errx(-1, "%s: Invalid channel attribute %c\n",
660 cp = strchr(val, '/');
663 u_long cw = strtoul(cp+1, &ep, 10);
667 flags |= IEEE80211_CHAN_QUARTER;
670 flags |= IEEE80211_CHAN_HALF;
673 /* NB: this may be removed below */
674 flags |= IEEE80211_CHAN_HT20;
677 if (ep != NULL && *ep == '+')
678 flags |= IEEE80211_CHAN_HT40U;
679 else if (ep != NULL && *ep == '-')
680 flags |= IEEE80211_CHAN_HT40D;
683 errx(-1, "%s: Invalid channel width\n", val);
687 * Cleanup specifications.
689 if ((flags & _CHAN_HT) == 0) {
691 * If user specified freq/20 or freq/40 quietly remove
692 * HT cw attributes depending on channel use. To give
693 * an explicit 20/40 width for an HT channel you must
694 * indicate it is an HT channel since all HT channels
695 * are also usable for legacy operation; e.g. freq:n/40.
697 flags &= ~IEEE80211_CHAN_HT;
700 * Remove private indicator that this is an HT channel
701 * and if no explicit channel width has been given
702 * provide the default settings.
705 if ((flags & IEEE80211_CHAN_HT) == 0) {
706 struct ieee80211_channel chan;
708 * Consult the channel list to see if we can use
709 * HT40+ or HT40- (if both the map routines choose).
712 mapfreq(&chan, freq, 0);
714 mapchan(&chan, freq, 0);
715 flags |= (chan.ic_flags & IEEE80211_CHAN_HT);
723 getchannel(int s, struct ieee80211_channel *chan, const char *val)
728 memset(chan, 0, sizeof(*chan));
730 chan->ic_freq = IEEE80211_CHAN_ANY;
735 v = strtol(val, &eptr, 10);
736 if (val[0] == '\0' || val == eptr || errno == ERANGE ||
737 /* channel may be suffixed with nothing, :flag, or /width */
738 (eptr[0] != '\0' && eptr[0] != ':' && eptr[0] != '/'))
739 errx(1, "invalid channel specification%s",
740 errno == ERANGE ? " (out of range)" : "");
741 flags = getchannelflags(val, v);
742 if (v > 255) { /* treat as frequency */
743 mapfreq(chan, v, flags);
745 mapchan(chan, v, flags);
750 set80211channel(const char *val, int d, int s, const struct afswtch *rafp)
752 struct ieee80211_channel chan;
754 getchannel(s, &chan, val);
755 set80211(s, IEEE80211_IOC_CURCHAN, 0, sizeof(chan), &chan);
759 set80211chanswitch(const char *val, int d, int s, const struct afswtch *rafp)
761 struct ieee80211_chanswitch_req csr;
763 getchannel(s, &csr.csa_chan, val);
766 set80211(s, IEEE80211_IOC_CHANSWITCH, 0, sizeof(csr), &csr);
770 set80211authmode(const char *val, int d, int s, const struct afswtch *rafp)
774 if (strcasecmp(val, "none") == 0) {
775 mode = IEEE80211_AUTH_NONE;
776 } else if (strcasecmp(val, "open") == 0) {
777 mode = IEEE80211_AUTH_OPEN;
778 } else if (strcasecmp(val, "shared") == 0) {
779 mode = IEEE80211_AUTH_SHARED;
780 } else if (strcasecmp(val, "8021x") == 0) {
781 mode = IEEE80211_AUTH_8021X;
782 } else if (strcasecmp(val, "wpa") == 0) {
783 mode = IEEE80211_AUTH_WPA;
785 errx(1, "unknown authmode");
788 set80211(s, IEEE80211_IOC_AUTHMODE, mode, 0, NULL);
792 set80211powersavemode(const char *val, int d, int s, const struct afswtch *rafp)
796 if (strcasecmp(val, "off") == 0) {
797 mode = IEEE80211_POWERSAVE_OFF;
798 } else if (strcasecmp(val, "on") == 0) {
799 mode = IEEE80211_POWERSAVE_ON;
800 } else if (strcasecmp(val, "cam") == 0) {
801 mode = IEEE80211_POWERSAVE_CAM;
802 } else if (strcasecmp(val, "psp") == 0) {
803 mode = IEEE80211_POWERSAVE_PSP;
804 } else if (strcasecmp(val, "psp-cam") == 0) {
805 mode = IEEE80211_POWERSAVE_PSP_CAM;
807 errx(1, "unknown powersavemode");
810 set80211(s, IEEE80211_IOC_POWERSAVE, mode, 0, NULL);
814 set80211powersave(const char *val, int d, int s, const struct afswtch *rafp)
817 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_OFF,
820 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_ON,
825 set80211powersavesleep(const char *val, int d, int s, const struct afswtch *rafp)
827 set80211(s, IEEE80211_IOC_POWERSAVESLEEP, atoi(val), 0, NULL);
831 set80211wepmode(const char *val, int d, int s, const struct afswtch *rafp)
835 if (strcasecmp(val, "off") == 0) {
836 mode = IEEE80211_WEP_OFF;
837 } else if (strcasecmp(val, "on") == 0) {
838 mode = IEEE80211_WEP_ON;
839 } else if (strcasecmp(val, "mixed") == 0) {
840 mode = IEEE80211_WEP_MIXED;
842 errx(1, "unknown wep mode");
845 set80211(s, IEEE80211_IOC_WEP, mode, 0, NULL);
849 set80211wep(const char *val, int d, int s, const struct afswtch *rafp)
851 set80211(s, IEEE80211_IOC_WEP, d, 0, NULL);
855 isundefarg(const char *arg)
857 return (strcmp(arg, "-") == 0 || strncasecmp(arg, "undef", 5) == 0);
861 set80211weptxkey(const char *val, int d, int s, const struct afswtch *rafp)
864 set80211(s, IEEE80211_IOC_WEPTXKEY, IEEE80211_KEYIX_NONE, 0, NULL);
866 set80211(s, IEEE80211_IOC_WEPTXKEY, atoi(val)-1, 0, NULL);
870 set80211wepkey(const char *val, int d, int s, const struct afswtch *rafp)
874 u_int8_t data[IEEE80211_KEYBUF_SIZE];
876 if (isdigit((int)val[0]) && val[1] == ':') {
881 bzero(data, sizeof(data));
883 get_string(val, NULL, data, &len);
885 set80211(s, IEEE80211_IOC_WEPKEY, key, len, data);
889 * This function is purely a NetBSD compatibility interface. The NetBSD
890 * interface is too inflexible, but it's there so we'll support it since
891 * it's not all that hard.
894 set80211nwkey(const char *val, int d, int s, const struct afswtch *rafp)
898 u_int8_t data[IEEE80211_KEYBUF_SIZE];
900 set80211(s, IEEE80211_IOC_WEP, IEEE80211_WEP_ON, 0, NULL);
902 if (isdigit((int)val[0]) && val[1] == ':') {
903 txkey = val[0]-'0'-1;
906 for (i = 0; i < 4; i++) {
907 bzero(data, sizeof(data));
909 val = get_string(val, ",", data, &len);
913 set80211(s, IEEE80211_IOC_WEPKEY, i, len, data);
916 bzero(data, sizeof(data));
918 get_string(val, NULL, data, &len);
921 set80211(s, IEEE80211_IOC_WEPKEY, 0, len, data);
923 bzero(data, sizeof(data));
924 for (i = 1; i < 4; i++)
925 set80211(s, IEEE80211_IOC_WEPKEY, i, 0, data);
928 set80211(s, IEEE80211_IOC_WEPTXKEY, txkey, 0, NULL);
932 set80211rtsthreshold(const char *val, int d, int s, const struct afswtch *rafp)
934 set80211(s, IEEE80211_IOC_RTSTHRESHOLD,
935 isundefarg(val) ? IEEE80211_RTS_MAX : atoi(val), 0, NULL);
939 set80211protmode(const char *val, int d, int s, const struct afswtch *rafp)
943 if (strcasecmp(val, "off") == 0) {
944 mode = IEEE80211_PROTMODE_OFF;
945 } else if (strcasecmp(val, "cts") == 0) {
946 mode = IEEE80211_PROTMODE_CTS;
947 } else if (strncasecmp(val, "rtscts", 3) == 0) {
948 mode = IEEE80211_PROTMODE_RTSCTS;
950 errx(1, "unknown protection mode");
953 set80211(s, IEEE80211_IOC_PROTMODE, mode, 0, NULL);
957 set80211htprotmode(const char *val, int d, int s, const struct afswtch *rafp)
961 if (strcasecmp(val, "off") == 0) {
962 mode = IEEE80211_PROTMODE_OFF;
963 } else if (strncasecmp(val, "rts", 3) == 0) {
964 mode = IEEE80211_PROTMODE_RTSCTS;
966 errx(1, "unknown protection mode");
969 set80211(s, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL);
973 set80211txpower(const char *val, int d, int s, const struct afswtch *rafp)
975 double v = atof(val);
980 errx(-1, "invalid tx power (must be .5 dBm units)");
981 set80211(s, IEEE80211_IOC_TXPOWER, txpow, 0, NULL);
984 #define IEEE80211_ROAMING_DEVICE 0
985 #define IEEE80211_ROAMING_AUTO 1
986 #define IEEE80211_ROAMING_MANUAL 2
989 set80211roaming(const char *val, int d, int s, const struct afswtch *rafp)
993 if (strcasecmp(val, "device") == 0) {
994 mode = IEEE80211_ROAMING_DEVICE;
995 } else if (strcasecmp(val, "auto") == 0) {
996 mode = IEEE80211_ROAMING_AUTO;
997 } else if (strcasecmp(val, "manual") == 0) {
998 mode = IEEE80211_ROAMING_MANUAL;
1000 errx(1, "unknown roaming mode");
1002 set80211(s, IEEE80211_IOC_ROAMING, mode, 0, NULL);
1006 set80211wme(const char *val, int d, int s, const struct afswtch *rafp)
1008 set80211(s, IEEE80211_IOC_WME, d, 0, NULL);
1012 set80211hidessid(const char *val, int d, int s, const struct afswtch *rafp)
1014 set80211(s, IEEE80211_IOC_HIDESSID, d, 0, NULL);
1018 set80211apbridge(const char *val, int d, int s, const struct afswtch *rafp)
1020 set80211(s, IEEE80211_IOC_APBRIDGE, d, 0, NULL);
1024 set80211fastframes(const char *val, int d, int s, const struct afswtch *rafp)
1026 set80211(s, IEEE80211_IOC_FF, d, 0, NULL);
1030 set80211dturbo(const char *val, int d, int s, const struct afswtch *rafp)
1032 set80211(s, IEEE80211_IOC_TURBOP, d, 0, NULL);
1036 set80211chanlist(const char *val, int d, int s, const struct afswtch *rafp)
1038 struct ieee80211req_chanlist chanlist;
1039 char *temp, *cp, *tp;
1041 temp = malloc(strlen(val) + 1);
1043 errx(1, "malloc failed");
1045 memset(&chanlist, 0, sizeof(chanlist));
1048 int first, last, f, c;
1050 tp = strchr(cp, ',');
1053 switch (sscanf(cp, "%u-%u", &first, &last)) {
1055 if (first > IEEE80211_CHAN_MAX)
1056 errx(-1, "channel %u out of range, max %u",
1057 first, IEEE80211_CHAN_MAX);
1058 setbit(chanlist.ic_channels, first);
1061 if (first > IEEE80211_CHAN_MAX)
1062 errx(-1, "channel %u out of range, max %u",
1063 first, IEEE80211_CHAN_MAX);
1064 if (last > IEEE80211_CHAN_MAX)
1065 errx(-1, "channel %u out of range, max %u",
1066 last, IEEE80211_CHAN_MAX);
1068 errx(-1, "void channel range, %u > %u",
1070 for (f = first; f <= last; f++)
1071 setbit(chanlist.ic_channels, f);
1083 set80211(s, IEEE80211_IOC_CHANLIST, 0, sizeof(chanlist), &chanlist);
1087 set80211bssid(const char *val, int d, int s, const struct afswtch *rafp)
1090 if (!isanyarg(val)) {
1092 struct sockaddr_dl sdl;
1094 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1096 errx(1, "malloc failed");
1098 strcpy(temp + 1, val);
1099 sdl.sdl_len = sizeof(sdl);
1100 link_addr(temp, &sdl);
1102 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1103 errx(1, "malformed link-level address");
1104 set80211(s, IEEE80211_IOC_BSSID, 0,
1105 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1107 uint8_t zerobssid[IEEE80211_ADDR_LEN];
1108 memset(zerobssid, 0, sizeof(zerobssid));
1109 set80211(s, IEEE80211_IOC_BSSID, 0,
1110 IEEE80211_ADDR_LEN, zerobssid);
1115 getac(const char *ac)
1117 if (strcasecmp(ac, "ac_be") == 0 || strcasecmp(ac, "be") == 0)
1119 if (strcasecmp(ac, "ac_bk") == 0 || strcasecmp(ac, "bk") == 0)
1121 if (strcasecmp(ac, "ac_vi") == 0 || strcasecmp(ac, "vi") == 0)
1123 if (strcasecmp(ac, "ac_vo") == 0 || strcasecmp(ac, "vo") == 0)
1125 errx(1, "unknown wme access class %s", ac);
1129 DECL_CMD_FUNC2(set80211cwmin, ac, val)
1131 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac), NULL);
1135 DECL_CMD_FUNC2(set80211cwmax, ac, val)
1137 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac), NULL);
1141 DECL_CMD_FUNC2(set80211aifs, ac, val)
1143 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac), NULL);
1147 DECL_CMD_FUNC2(set80211txoplimit, ac, val)
1149 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac), NULL);
1153 DECL_CMD_FUNC(set80211acm, ac, d)
1155 set80211(s, IEEE80211_IOC_WME_ACM, 1, getac(ac), NULL);
1158 DECL_CMD_FUNC(set80211noacm, ac, d)
1160 set80211(s, IEEE80211_IOC_WME_ACM, 0, getac(ac), NULL);
1164 DECL_CMD_FUNC(set80211ackpolicy, ac, d)
1166 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 1, getac(ac), NULL);
1169 DECL_CMD_FUNC(set80211noackpolicy, ac, d)
1171 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 0, getac(ac), NULL);
1175 DECL_CMD_FUNC2(set80211bsscwmin, ac, val)
1177 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val),
1178 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1182 DECL_CMD_FUNC2(set80211bsscwmax, ac, val)
1184 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val),
1185 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1189 DECL_CMD_FUNC2(set80211bssaifs, ac, val)
1191 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val),
1192 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1196 DECL_CMD_FUNC2(set80211bsstxoplimit, ac, val)
1198 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val),
1199 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1203 DECL_CMD_FUNC(set80211dtimperiod, val, d)
1205 set80211(s, IEEE80211_IOC_DTIM_PERIOD, atoi(val), 0, NULL);
1209 DECL_CMD_FUNC(set80211bintval, val, d)
1211 set80211(s, IEEE80211_IOC_BEACON_INTERVAL, atoi(val), 0, NULL);
1215 set80211macmac(int s, int op, const char *val)
1218 struct sockaddr_dl sdl;
1220 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1222 errx(1, "malloc failed");
1224 strcpy(temp + 1, val);
1225 sdl.sdl_len = sizeof(sdl);
1226 link_addr(temp, &sdl);
1228 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1229 errx(1, "malformed link-level address");
1230 set80211(s, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl));
1234 DECL_CMD_FUNC(set80211addmac, val, d)
1236 set80211macmac(s, IEEE80211_IOC_ADDMAC, val);
1240 DECL_CMD_FUNC(set80211delmac, val, d)
1242 set80211macmac(s, IEEE80211_IOC_DELMAC, val);
1246 DECL_CMD_FUNC(set80211kickmac, val, d)
1249 struct sockaddr_dl sdl;
1250 struct ieee80211req_mlme mlme;
1252 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1254 errx(1, "malloc failed");
1256 strcpy(temp + 1, val);
1257 sdl.sdl_len = sizeof(sdl);
1258 link_addr(temp, &sdl);
1260 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1261 errx(1, "malformed link-level address");
1262 memset(&mlme, 0, sizeof(mlme));
1263 mlme.im_op = IEEE80211_MLME_DEAUTH;
1264 mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE;
1265 memcpy(mlme.im_macaddr, LLADDR(&sdl), IEEE80211_ADDR_LEN);
1266 set80211(s, IEEE80211_IOC_MLME, 0, sizeof(mlme), &mlme);
1270 DECL_CMD_FUNC(set80211maccmd, val, d)
1272 set80211(s, IEEE80211_IOC_MACCMD, d, 0, NULL);
1276 set80211meshrtmac(int s, int req, const char *val)
1279 struct sockaddr_dl sdl;
1281 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1283 errx(1, "malloc failed");
1285 strcpy(temp + 1, val);
1286 sdl.sdl_len = sizeof(sdl);
1287 link_addr(temp, &sdl);
1289 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1290 errx(1, "malformed link-level address");
1291 set80211(s, IEEE80211_IOC_MESH_RTCMD, req,
1292 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1296 DECL_CMD_FUNC(set80211addmeshrt, val, d)
1298 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_ADD, val);
1302 DECL_CMD_FUNC(set80211delmeshrt, val, d)
1304 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_DELETE, val);
1308 DECL_CMD_FUNC(set80211meshrtcmd, val, d)
1310 set80211(s, IEEE80211_IOC_MESH_RTCMD, d, 0, NULL);
1314 DECL_CMD_FUNC(set80211hwmprootmode, val, d)
1318 if (strcasecmp(val, "normal") == 0)
1319 mode = IEEE80211_HWMP_ROOTMODE_NORMAL;
1320 else if (strcasecmp(val, "proactive") == 0)
1321 mode = IEEE80211_HWMP_ROOTMODE_PROACTIVE;
1322 else if (strcasecmp(val, "rann") == 0)
1323 mode = IEEE80211_HWMP_ROOTMODE_RANN;
1325 mode = IEEE80211_HWMP_ROOTMODE_DISABLED;
1326 set80211(s, IEEE80211_IOC_HWMP_ROOTMODE, mode, 0, NULL);
1330 DECL_CMD_FUNC(set80211hwmpmaxhops, val, d)
1332 set80211(s, IEEE80211_IOC_HWMP_MAXHOPS, atoi(val), 0, NULL);
1336 set80211pureg(const char *val, int d, int s, const struct afswtch *rafp)
1338 set80211(s, IEEE80211_IOC_PUREG, d, 0, NULL);
1342 set80211quiet(const char *val, int d, int s, const struct afswtch *rafp)
1344 set80211(s, IEEE80211_IOC_QUIET, d, 0, NULL);
1348 DECL_CMD_FUNC(set80211quietperiod, val, d)
1350 set80211(s, IEEE80211_IOC_QUIET_PERIOD, atoi(val), 0, NULL);
1354 DECL_CMD_FUNC(set80211quietcount, val, d)
1356 set80211(s, IEEE80211_IOC_QUIET_COUNT, atoi(val), 0, NULL);
1360 DECL_CMD_FUNC(set80211quietduration, val, d)
1362 set80211(s, IEEE80211_IOC_QUIET_DUR, atoi(val), 0, NULL);
1366 DECL_CMD_FUNC(set80211quietoffset, val, d)
1368 set80211(s, IEEE80211_IOC_QUIET_OFFSET, atoi(val), 0, NULL);
1372 set80211bgscan(const char *val, int d, int s, const struct afswtch *rafp)
1374 set80211(s, IEEE80211_IOC_BGSCAN, d, 0, NULL);
1378 DECL_CMD_FUNC(set80211bgscanidle, val, d)
1380 set80211(s, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL);
1384 DECL_CMD_FUNC(set80211bgscanintvl, val, d)
1386 set80211(s, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL);
1390 DECL_CMD_FUNC(set80211scanvalid, val, d)
1392 set80211(s, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL);
1396 * Parse an optional trailing specification of which netbands
1397 * to apply a parameter to. This is basically the same syntax
1398 * as used for channels but you can concatenate to specify
1399 * multiple. For example:
1400 * 14:abg apply to 11a, 11b, and 11g
1401 * 6:ht apply to 11na and 11ng
1402 * We don't make a big effort to catch silly things; this is
1403 * really a convenience mechanism.
1406 getmodeflags(const char *val)
1413 cp = strchr(val, ':');
1415 for (cp++; isalpha((int) *cp); cp++) {
1416 /* accept mixed case */
1421 case 'a': /* 802.11a */
1422 flags |= IEEE80211_CHAN_A;
1424 case 'b': /* 802.11b */
1425 flags |= IEEE80211_CHAN_B;
1427 case 'g': /* 802.11g */
1428 flags |= IEEE80211_CHAN_G;
1430 case 'n': /* 802.11n */
1431 flags |= IEEE80211_CHAN_HT;
1433 case 'd': /* dt = Atheros Dynamic Turbo */
1434 flags |= IEEE80211_CHAN_TURBO;
1436 case 't': /* ht, dt, st, t */
1437 /* dt and unadorned t specify Dynamic Turbo */
1438 if ((flags & (IEEE80211_CHAN_STURBO|IEEE80211_CHAN_HT)) == 0)
1439 flags |= IEEE80211_CHAN_TURBO;
1441 case 's': /* st = Atheros Static Turbo */
1442 flags |= IEEE80211_CHAN_STURBO;
1444 case 'h': /* 1/2-width channels */
1445 flags |= IEEE80211_CHAN_HALF;
1447 case 'q': /* 1/4-width channels */
1448 flags |= IEEE80211_CHAN_QUARTER;
1451 errx(-1, "%s: Invalid mode attribute %c\n",
1459 #define IEEE80211_CHAN_HTA (IEEE80211_CHAN_HT|IEEE80211_CHAN_5GHZ)
1460 #define IEEE80211_CHAN_HTG (IEEE80211_CHAN_HT|IEEE80211_CHAN_2GHZ)
1462 #define _APPLY(_flags, _base, _param, _v) do { \
1463 if (_flags & IEEE80211_CHAN_HT) { \
1464 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1465 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1466 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1467 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1468 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1470 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1472 if (_flags & IEEE80211_CHAN_TURBO) { \
1473 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1474 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1475 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1476 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1477 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1479 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1481 if (_flags & IEEE80211_CHAN_STURBO) \
1482 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1483 if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1484 _base.params[IEEE80211_MODE_11A]._param = _v; \
1485 if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1486 _base.params[IEEE80211_MODE_11G]._param = _v; \
1487 if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1488 _base.params[IEEE80211_MODE_11B]._param = _v; \
1489 if (_flags & IEEE80211_CHAN_HALF) \
1490 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1491 if (_flags & IEEE80211_CHAN_QUARTER) \
1492 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1494 #define _APPLY1(_flags, _base, _param, _v) do { \
1495 if (_flags & IEEE80211_CHAN_HT) { \
1496 if (_flags & IEEE80211_CHAN_5GHZ) \
1497 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1499 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1500 } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \
1501 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1502 else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \
1503 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1504 else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \
1505 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1506 else if (_flags & IEEE80211_CHAN_HALF) \
1507 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1508 else if (_flags & IEEE80211_CHAN_QUARTER) \
1509 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1510 else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1511 _base.params[IEEE80211_MODE_11A]._param = _v; \
1512 else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1513 _base.params[IEEE80211_MODE_11G]._param = _v; \
1514 else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1515 _base.params[IEEE80211_MODE_11B]._param = _v; \
1517 #define _APPLY_RATE(_flags, _base, _param, _v) do { \
1518 if (_flags & IEEE80211_CHAN_HT) { \
1519 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1521 _APPLY(_flags, _base, _param, _v); \
1523 #define _APPLY_RATE1(_flags, _base, _param, _v) do { \
1524 if (_flags & IEEE80211_CHAN_HT) { \
1525 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1527 _APPLY1(_flags, _base, _param, _v); \
1531 DECL_CMD_FUNC(set80211roamrssi, val, d)
1533 double v = atof(val);
1538 errx(-1, "invalid rssi (must be .5 dBm units)");
1539 flags = getmodeflags(val);
1541 if (flags == 0) { /* NB: no flags => current channel */
1542 flags = getcurchan(s)->ic_flags;
1543 _APPLY1(flags, roamparams, rssi, rssi);
1545 _APPLY(flags, roamparams, rssi, rssi);
1546 callback_register(setroam_cb, &roamparams);
1550 getrate(const char *val, const char *tag)
1552 double v = atof(val);
1557 errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag);
1558 return rate; /* NB: returns 2x the specified value */
1562 DECL_CMD_FUNC(set80211roamrate, val, d)
1566 rate = getrate(val, "roam");
1567 flags = getmodeflags(val);
1569 if (flags == 0) { /* NB: no flags => current channel */
1570 flags = getcurchan(s)->ic_flags;
1571 _APPLY_RATE1(flags, roamparams, rate, rate);
1573 _APPLY_RATE(flags, roamparams, rate, rate);
1574 callback_register(setroam_cb, &roamparams);
1578 DECL_CMD_FUNC(set80211mcastrate, val, d)
1582 rate = getrate(val, "mcast");
1583 flags = getmodeflags(val);
1585 if (flags == 0) { /* NB: no flags => current channel */
1586 flags = getcurchan(s)->ic_flags;
1587 _APPLY_RATE1(flags, txparams, mcastrate, rate);
1589 _APPLY_RATE(flags, txparams, mcastrate, rate);
1590 callback_register(settxparams_cb, &txparams);
1594 DECL_CMD_FUNC(set80211mgtrate, val, d)
1598 rate = getrate(val, "mgmt");
1599 flags = getmodeflags(val);
1601 if (flags == 0) { /* NB: no flags => current channel */
1602 flags = getcurchan(s)->ic_flags;
1603 _APPLY_RATE1(flags, txparams, mgmtrate, rate);
1605 _APPLY_RATE(flags, txparams, mgmtrate, rate);
1606 callback_register(settxparams_cb, &txparams);
1610 DECL_CMD_FUNC(set80211ucastrate, val, d)
1615 flags = getmodeflags(val);
1616 if (isanyarg(val)) {
1617 if (flags == 0) { /* NB: no flags => current channel */
1618 flags = getcurchan(s)->ic_flags;
1619 _APPLY1(flags, txparams, ucastrate,
1620 IEEE80211_FIXED_RATE_NONE);
1622 _APPLY(flags, txparams, ucastrate,
1623 IEEE80211_FIXED_RATE_NONE);
1625 int rate = getrate(val, "ucast");
1626 if (flags == 0) { /* NB: no flags => current channel */
1627 flags = getcurchan(s)->ic_flags;
1628 _APPLY_RATE1(flags, txparams, ucastrate, rate);
1630 _APPLY_RATE(flags, txparams, ucastrate, rate);
1632 callback_register(settxparams_cb, &txparams);
1636 DECL_CMD_FUNC(set80211maxretry, val, d)
1638 int v = atoi(val), flags;
1640 flags = getmodeflags(val);
1642 if (flags == 0) { /* NB: no flags => current channel */
1643 flags = getcurchan(s)->ic_flags;
1644 _APPLY1(flags, txparams, maxretry, v);
1646 _APPLY(flags, txparams, maxretry, v);
1647 callback_register(settxparams_cb, &txparams);
1651 #undef IEEE80211_CHAN_HTA
1652 #undef IEEE80211_CHAN_HTG
1655 DECL_CMD_FUNC(set80211fragthreshold, val, d)
1657 set80211(s, IEEE80211_IOC_FRAGTHRESHOLD,
1658 isundefarg(val) ? IEEE80211_FRAG_MAX : atoi(val), 0, NULL);
1662 DECL_CMD_FUNC(set80211bmissthreshold, val, d)
1664 set80211(s, IEEE80211_IOC_BMISSTHRESHOLD,
1665 isundefarg(val) ? IEEE80211_HWBMISS_MAX : atoi(val), 0, NULL);
1669 set80211burst(const char *val, int d, int s, const struct afswtch *rafp)
1671 set80211(s, IEEE80211_IOC_BURST, d, 0, NULL);
1675 set80211doth(const char *val, int d, int s, const struct afswtch *rafp)
1677 set80211(s, IEEE80211_IOC_DOTH, d, 0, NULL);
1681 set80211dfs(const char *val, int d, int s, const struct afswtch *rafp)
1683 set80211(s, IEEE80211_IOC_DFS, d, 0, NULL);
1687 set80211shortgi(const char *val, int d, int s, const struct afswtch *rafp)
1689 set80211(s, IEEE80211_IOC_SHORTGI,
1690 d ? (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) : 0,
1695 set80211ampdu(const char *val, int d, int s, const struct afswtch *rafp)
1699 if (get80211val(s, IEEE80211_IOC_AMPDU, &du) < 0)
1700 errx(-1, "cannot set AMPDU setting");
1706 set80211(s, IEEE80211_IOC_AMPDU, ampdu, 0, NULL);
1710 set80211stbc(const char *val, int d, int s, const struct afswtch *rafp)
1714 if (get80211val(s, IEEE80211_IOC_STBC, &stbc) < 0)
1715 errx(-1, "cannot set STBC setting");
1721 set80211(s, IEEE80211_IOC_STBC, stbc, 0, NULL);
1725 DECL_CMD_FUNC(set80211ampdulimit, val, d)
1729 switch (atoi(val)) {
1732 v = IEEE80211_HTCAP_MAXRXAMPDU_8K;
1736 v = IEEE80211_HTCAP_MAXRXAMPDU_16K;
1740 v = IEEE80211_HTCAP_MAXRXAMPDU_32K;
1744 v = IEEE80211_HTCAP_MAXRXAMPDU_64K;
1747 errx(-1, "invalid A-MPDU limit %s", val);
1749 set80211(s, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL);
1753 DECL_CMD_FUNC(set80211ampdudensity, val, d)
1757 if (isanyarg(val) || strcasecmp(val, "na") == 0)
1758 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1759 else switch ((int)(atof(val)*4)) {
1761 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1764 v = IEEE80211_HTCAP_MPDUDENSITY_025;
1767 v = IEEE80211_HTCAP_MPDUDENSITY_05;
1770 v = IEEE80211_HTCAP_MPDUDENSITY_1;
1773 v = IEEE80211_HTCAP_MPDUDENSITY_2;
1776 v = IEEE80211_HTCAP_MPDUDENSITY_4;
1779 v = IEEE80211_HTCAP_MPDUDENSITY_8;
1782 v = IEEE80211_HTCAP_MPDUDENSITY_16;
1785 errx(-1, "invalid A-MPDU density %s", val);
1787 set80211(s, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL);
1791 set80211amsdu(const char *val, int d, int s, const struct afswtch *rafp)
1795 if (get80211val(s, IEEE80211_IOC_AMSDU, &amsdu) < 0)
1796 err(-1, "cannot get AMSDU setting");
1802 set80211(s, IEEE80211_IOC_AMSDU, amsdu, 0, NULL);
1806 DECL_CMD_FUNC(set80211amsdulimit, val, d)
1808 set80211(s, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL);
1812 set80211puren(const char *val, int d, int s, const struct afswtch *rafp)
1814 set80211(s, IEEE80211_IOC_PUREN, d, 0, NULL);
1818 set80211htcompat(const char *val, int d, int s, const struct afswtch *rafp)
1820 set80211(s, IEEE80211_IOC_HTCOMPAT, d, 0, NULL);
1824 set80211htconf(const char *val, int d, int s, const struct afswtch *rafp)
1826 set80211(s, IEEE80211_IOC_HTCONF, d, 0, NULL);
1831 set80211dwds(const char *val, int d, int s, const struct afswtch *rafp)
1833 set80211(s, IEEE80211_IOC_DWDS, d, 0, NULL);
1837 set80211inact(const char *val, int d, int s, const struct afswtch *rafp)
1839 set80211(s, IEEE80211_IOC_INACTIVITY, d, 0, NULL);
1843 set80211tsn(const char *val, int d, int s, const struct afswtch *rafp)
1845 set80211(s, IEEE80211_IOC_TSN, d, 0, NULL);
1849 set80211dotd(const char *val, int d, int s, const struct afswtch *rafp)
1851 set80211(s, IEEE80211_IOC_DOTD, d, 0, NULL);
1855 set80211smps(const char *val, int d, int s, const struct afswtch *rafp)
1857 set80211(s, IEEE80211_IOC_SMPS, d, 0, NULL);
1861 set80211rifs(const char *val, int d, int s, const struct afswtch *rafp)
1863 set80211(s, IEEE80211_IOC_RIFS, d, 0, NULL);
1867 DECL_CMD_FUNC(set80211tdmaslot, val, d)
1869 set80211(s, IEEE80211_IOC_TDMA_SLOT, atoi(val), 0, NULL);
1873 DECL_CMD_FUNC(set80211tdmaslotcnt, val, d)
1875 set80211(s, IEEE80211_IOC_TDMA_SLOTCNT, atoi(val), 0, NULL);
1879 DECL_CMD_FUNC(set80211tdmaslotlen, val, d)
1881 set80211(s, IEEE80211_IOC_TDMA_SLOTLEN, atoi(val), 0, NULL);
1885 DECL_CMD_FUNC(set80211tdmabintval, val, d)
1887 set80211(s, IEEE80211_IOC_TDMA_BINTERVAL, atoi(val), 0, NULL);
1891 DECL_CMD_FUNC(set80211meshttl, val, d)
1893 set80211(s, IEEE80211_IOC_MESH_TTL, atoi(val), 0, NULL);
1897 DECL_CMD_FUNC(set80211meshforward, val, d)
1899 set80211(s, IEEE80211_IOC_MESH_FWRD, d, 0, NULL);
1903 DECL_CMD_FUNC(set80211meshgate, val, d)
1905 set80211(s, IEEE80211_IOC_MESH_GATE, d, 0, NULL);
1909 DECL_CMD_FUNC(set80211meshpeering, val, d)
1911 set80211(s, IEEE80211_IOC_MESH_AP, d, 0, NULL);
1915 DECL_CMD_FUNC(set80211meshmetric, val, d)
1919 memcpy(v, val, sizeof(v));
1920 set80211(s, IEEE80211_IOC_MESH_PR_METRIC, 0, 0, v);
1924 DECL_CMD_FUNC(set80211meshpath, val, d)
1928 memcpy(v, val, sizeof(v));
1929 set80211(s, IEEE80211_IOC_MESH_PR_PATH, 0, 0, v);
1933 regdomain_sort(const void *a, const void *b)
1936 (IEEE80211_CHAN_ALLTURBO|IEEE80211_CHAN_HALF|IEEE80211_CHAN_QUARTER)
1937 const struct ieee80211_channel *ca = a;
1938 const struct ieee80211_channel *cb = b;
1940 return ca->ic_freq == cb->ic_freq ?
1941 (ca->ic_flags & CHAN_ALL) - (cb->ic_flags & CHAN_ALL) :
1942 ca->ic_freq - cb->ic_freq;
1946 static const struct ieee80211_channel *
1947 chanlookup(const struct ieee80211_channel chans[], int nchans,
1948 int freq, int flags)
1952 flags &= IEEE80211_CHAN_ALLTURBO;
1953 for (i = 0; i < nchans; i++) {
1954 const struct ieee80211_channel *c = &chans[i];
1955 if (c->ic_freq == freq &&
1956 (c->ic_flags & IEEE80211_CHAN_ALLTURBO) == flags)
1963 chanfind(const struct ieee80211_channel chans[], int nchans, int flags)
1967 for (i = 0; i < nchans; i++) {
1968 const struct ieee80211_channel *c = &chans[i];
1969 if ((c->ic_flags & flags) == flags)
1976 * Check channel compatibility.
1979 checkchan(const struct ieee80211req_chaninfo *avail, int freq, int flags)
1981 flags &= ~REQ_FLAGS;
1983 * Check if exact channel is in the calibration table;
1984 * everything below is to deal with channels that we
1985 * want to include but that are not explicitly listed.
1987 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, flags) != NULL)
1989 if (flags & IEEE80211_CHAN_GSM) {
1991 * XXX GSM frequency mapping is handled in the kernel
1992 * so we cannot find them in the calibration table;
1993 * just accept the channel and the kernel will reject
1994 * the channel list if it's wrong.
1999 * If this is a 1/2 or 1/4 width channel allow it if a full
2000 * width channel is present for this frequency, and the device
2001 * supports fractional channels on this band. This is a hack
2002 * that avoids bloating the calibration table; it may be better
2003 * by per-band attributes though (we are effectively calculating
2004 * this attribute by scanning the channel list ourself).
2006 if ((flags & (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == 0)
2008 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq,
2009 flags &~ (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == NULL)
2011 if (flags & IEEE80211_CHAN_HALF) {
2012 return chanfind(avail->ic_chans, avail->ic_nchans,
2013 IEEE80211_CHAN_HALF |
2014 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2016 return chanfind(avail->ic_chans, avail->ic_nchans,
2017 IEEE80211_CHAN_QUARTER |
2018 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2023 regdomain_addchans(struct ieee80211req_chaninfo *ci,
2024 const netband_head *bands,
2025 const struct ieee80211_regdomain *reg,
2027 const struct ieee80211req_chaninfo *avail)
2029 const struct netband *nb;
2030 const struct freqband *b;
2031 struct ieee80211_channel *c, *prev;
2032 int freq, hi_adj, lo_adj, channelSep;
2035 hi_adj = (chanFlags & IEEE80211_CHAN_HT40U) ? -20 : 0;
2036 lo_adj = (chanFlags & IEEE80211_CHAN_HT40D) ? 20 : 0;
2037 channelSep = (chanFlags & IEEE80211_CHAN_2GHZ) ? 0 : 40;
2038 LIST_FOREACH(nb, bands, next) {
2041 printf("%s:", __func__);
2042 printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS);
2043 printb(" bandFlags", nb->flags | b->flags,
2044 IEEE80211_CHAN_BITS);
2048 for (freq = b->freqStart + lo_adj;
2049 freq <= b->freqEnd + hi_adj; freq += b->chanSep) {
2051 * Construct flags for the new channel. We take
2052 * the attributes from the band descriptions except
2053 * for HT40 which is enabled generically (i.e. +/-
2054 * extension channel) in the band description and
2055 * then constrained according by channel separation.
2057 flags = nb->flags | b->flags;
2058 if (flags & IEEE80211_CHAN_HT) {
2060 * HT channels are generated specially; we're
2061 * called to add HT20, HT40+, and HT40- chan's
2062 * so we need to expand only band specs for
2063 * the HT channel type being added.
2065 if ((chanFlags & IEEE80211_CHAN_HT20) &&
2066 (flags & IEEE80211_CHAN_HT20) == 0) {
2068 printf("%u: skip, not an "
2069 "HT20 channel\n", freq);
2072 if ((chanFlags & IEEE80211_CHAN_HT40) &&
2073 (flags & IEEE80211_CHAN_HT40) == 0) {
2075 printf("%u: skip, not an "
2076 "HT40 channel\n", freq);
2079 /* NB: HT attribute comes from caller */
2080 flags &= ~IEEE80211_CHAN_HT;
2081 flags |= chanFlags & IEEE80211_CHAN_HT;
2084 * Check if device can operate on this frequency.
2086 if (!checkchan(avail, freq, flags)) {
2088 printf("%u: skip, ", freq);
2089 printb("flags", flags,
2090 IEEE80211_CHAN_BITS);
2091 printf(" not available\n");
2095 if ((flags & REQ_ECM) && !reg->ecm) {
2097 printf("%u: skip, ECM channel\n", freq);
2100 if ((flags & REQ_INDOOR) && reg->location == 'O') {
2102 printf("%u: skip, indoor channel\n",
2106 if ((flags & REQ_OUTDOOR) && reg->location == 'I') {
2108 printf("%u: skip, outdoor channel\n",
2112 if ((flags & IEEE80211_CHAN_HT40) &&
2113 prev != NULL && (freq - prev->ic_freq) < channelSep) {
2115 printf("%u: skip, only %u channel "
2116 "separation, need %d\n", freq,
2117 freq - prev->ic_freq, channelSep);
2120 if (ci->ic_nchans == IEEE80211_CHAN_MAX) {
2122 printf("%u: skip, channel table full\n",
2126 c = &ci->ic_chans[ci->ic_nchans++];
2127 memset(c, 0, sizeof(*c));
2129 c->ic_flags = flags;
2130 if (c->ic_flags & IEEE80211_CHAN_DFS)
2131 c->ic_maxregpower = nb->maxPowerDFS;
2133 c->ic_maxregpower = nb->maxPower;
2135 printf("[%3d] add freq %u ",
2136 ci->ic_nchans-1, c->ic_freq);
2137 printb("flags", c->ic_flags, IEEE80211_CHAN_BITS);
2138 printf(" power %u\n", c->ic_maxregpower);
2140 /* NB: kernel fills in other fields */
2147 regdomain_makechannels(
2148 struct ieee80211_regdomain_req *req,
2149 const struct ieee80211_devcaps_req *dc)
2151 struct regdata *rdp = getregdata();
2152 const struct country *cc;
2153 const struct ieee80211_regdomain *reg = &req->rd;
2154 struct ieee80211req_chaninfo *ci = &req->chaninfo;
2155 const struct regdomain *rd;
2158 * Locate construction table for new channel list. We treat
2159 * the regdomain/SKU as definitive so a country can be in
2160 * multiple with different properties (e.g. US in FCC+FCC3).
2161 * If no regdomain is specified then we fallback on the country
2162 * code to find the associated regdomain since countries always
2163 * belong to at least one regdomain.
2165 if (reg->regdomain == 0) {
2166 cc = lib80211_country_findbycc(rdp, reg->country);
2168 errx(1, "internal error, country %d not found",
2172 rd = lib80211_regdomain_findbysku(rdp, reg->regdomain);
2174 errx(1, "internal error, regdomain %d not found",
2176 if (rd->sku != SKU_DEBUG) {
2178 * regdomain_addchans incrememnts the channel count for
2179 * each channel it adds so initialize ic_nchans to zero.
2180 * Note that we know we have enough space to hold all possible
2181 * channels because the devcaps list size was used to
2182 * allocate our request.
2185 if (!LIST_EMPTY(&rd->bands_11b))
2186 regdomain_addchans(ci, &rd->bands_11b, reg,
2187 IEEE80211_CHAN_B, &dc->dc_chaninfo);
2188 if (!LIST_EMPTY(&rd->bands_11g))
2189 regdomain_addchans(ci, &rd->bands_11g, reg,
2190 IEEE80211_CHAN_G, &dc->dc_chaninfo);
2191 if (!LIST_EMPTY(&rd->bands_11a))
2192 regdomain_addchans(ci, &rd->bands_11a, reg,
2193 IEEE80211_CHAN_A, &dc->dc_chaninfo);
2194 if (!LIST_EMPTY(&rd->bands_11na) && dc->dc_htcaps != 0) {
2195 regdomain_addchans(ci, &rd->bands_11na, reg,
2196 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20,
2198 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2199 regdomain_addchans(ci, &rd->bands_11na, reg,
2200 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U,
2202 regdomain_addchans(ci, &rd->bands_11na, reg,
2203 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D,
2207 if (!LIST_EMPTY(&rd->bands_11ng) && dc->dc_htcaps != 0) {
2208 regdomain_addchans(ci, &rd->bands_11ng, reg,
2209 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20,
2211 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2212 regdomain_addchans(ci, &rd->bands_11ng, reg,
2213 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U,
2215 regdomain_addchans(ci, &rd->bands_11ng, reg,
2216 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D,
2220 qsort(ci->ic_chans, ci->ic_nchans, sizeof(ci->ic_chans[0]),
2223 memcpy(ci, &dc->dc_chaninfo,
2224 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
2228 list_countries(void)
2230 struct regdata *rdp = getregdata();
2231 const struct country *cp;
2232 const struct regdomain *dp;
2236 printf("\nCountry codes:\n");
2237 LIST_FOREACH(cp, &rdp->countries, next) {
2238 printf("%2s %-15.15s%s", cp->isoname,
2239 cp->name, ((i+1)%4) == 0 ? "\n" : " ");
2243 printf("\nRegulatory domains:\n");
2244 LIST_FOREACH(dp, &rdp->domains, next) {
2245 printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " ");
2252 defaultcountry(const struct regdomain *rd)
2254 struct regdata *rdp = getregdata();
2255 const struct country *cc;
2257 cc = lib80211_country_findbycc(rdp, rd->cc->code);
2259 errx(1, "internal error, ISO country code %d not "
2260 "defined for regdomain %s", rd->cc->code, rd->name);
2261 regdomain.country = cc->code;
2262 regdomain.isocc[0] = cc->isoname[0];
2263 regdomain.isocc[1] = cc->isoname[1];
2267 DECL_CMD_FUNC(set80211regdomain, val, d)
2269 struct regdata *rdp = getregdata();
2270 const struct regdomain *rd;
2272 rd = lib80211_regdomain_findbyname(rdp, val);
2275 long sku = strtol(val, &eptr, 0);
2278 rd = lib80211_regdomain_findbysku(rdp, sku);
2279 if (eptr == val || rd == NULL)
2280 errx(1, "unknown regdomain %s", val);
2283 regdomain.regdomain = rd->sku;
2284 if (regdomain.country == 0 && rd->cc != NULL) {
2286 * No country code setup and there's a default
2287 * one for this regdomain fill it in.
2291 callback_register(setregdomain_cb, ®domain);
2295 DECL_CMD_FUNC(set80211country, val, d)
2297 struct regdata *rdp = getregdata();
2298 const struct country *cc;
2300 cc = lib80211_country_findbyname(rdp, val);
2303 long code = strtol(val, &eptr, 0);
2306 cc = lib80211_country_findbycc(rdp, code);
2307 if (eptr == val || cc == NULL)
2308 errx(1, "unknown ISO country code %s", val);
2311 regdomain.regdomain = cc->rd->sku;
2312 regdomain.country = cc->code;
2313 regdomain.isocc[0] = cc->isoname[0];
2314 regdomain.isocc[1] = cc->isoname[1];
2315 callback_register(setregdomain_cb, ®domain);
2319 set80211location(const char *val, int d, int s, const struct afswtch *rafp)
2322 regdomain.location = d;
2323 callback_register(setregdomain_cb, ®domain);
2327 set80211ecm(const char *val, int d, int s, const struct afswtch *rafp)
2331 callback_register(setregdomain_cb, ®domain);
2347 if (spacer != '\t') {
2351 col = 8; /* 8-col tab */
2355 LINE_CHECK(const char *fmt, ...)
2362 n = vsnprintf(buf+1, sizeof(buf)-1, fmt, ap);
2375 getmaxrate(const uint8_t rates[15], uint8_t nrates)
2377 int i, maxrate = -1;
2379 for (i = 0; i < nrates; i++) {
2380 int rate = rates[i] & IEEE80211_RATE_VAL;
2388 getcaps(int capinfo)
2390 static char capstring[32];
2391 char *cp = capstring;
2393 if (capinfo & IEEE80211_CAPINFO_ESS)
2395 if (capinfo & IEEE80211_CAPINFO_IBSS)
2397 if (capinfo & IEEE80211_CAPINFO_CF_POLLABLE)
2399 if (capinfo & IEEE80211_CAPINFO_CF_POLLREQ)
2401 if (capinfo & IEEE80211_CAPINFO_PRIVACY)
2403 if (capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)
2405 if (capinfo & IEEE80211_CAPINFO_PBCC)
2407 if (capinfo & IEEE80211_CAPINFO_CHNL_AGILITY)
2409 if (capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME)
2411 if (capinfo & IEEE80211_CAPINFO_RSN)
2413 if (capinfo & IEEE80211_CAPINFO_DSSSOFDM)
2422 static char flagstring[32];
2423 char *cp = flagstring;
2425 if (flags & IEEE80211_NODE_AUTH)
2427 if (flags & IEEE80211_NODE_QOS)
2429 if (flags & IEEE80211_NODE_ERP)
2431 if (flags & IEEE80211_NODE_PWR_MGT)
2433 if (flags & IEEE80211_NODE_HT) {
2435 if (flags & IEEE80211_NODE_HTCOMPAT)
2438 if (flags & IEEE80211_NODE_WPS)
2440 if (flags & IEEE80211_NODE_TSN)
2442 if (flags & IEEE80211_NODE_AMPDU_TX)
2444 if (flags & IEEE80211_NODE_AMPDU_RX)
2446 if (flags & IEEE80211_NODE_MIMO_PS) {
2448 if (flags & IEEE80211_NODE_MIMO_RTS)
2451 if (flags & IEEE80211_NODE_RIFS)
2453 if (flags & IEEE80211_NODE_SGI40) {
2455 if (flags & IEEE80211_NODE_SGI20)
2457 } else if (flags & IEEE80211_NODE_SGI20)
2459 if (flags & IEEE80211_NODE_AMSDU_TX)
2461 if (flags & IEEE80211_NODE_AMSDU_RX)
2468 printie(const char* tag, const uint8_t *ie, size_t ielen, int maxlen)
2472 maxlen -= strlen(tag)+2;
2473 if (2*ielen > maxlen)
2476 for (; ielen > 0; ie++, ielen--) {
2479 printf("%02x", *ie);
2487 #define LE_READ_2(p) \
2489 ((((const u_int8_t *)(p))[0] ) | \
2490 (((const u_int8_t *)(p))[1] << 8)))
2491 #define LE_READ_4(p) \
2493 ((((const u_int8_t *)(p))[0] ) | \
2494 (((const u_int8_t *)(p))[1] << 8) | \
2495 (((const u_int8_t *)(p))[2] << 16) | \
2496 (((const u_int8_t *)(p))[3] << 24)))
2499 * NB: The decoding routines assume a properly formatted ie
2500 * which should be safe as the kernel only retains them
2505 printwmeparam(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2507 #define MS(_v, _f) (((_v) & _f) >> _f##_S)
2508 static const char *acnames[] = { "BE", "BK", "VO", "VI" };
2509 const struct ieee80211_wme_param *wme =
2510 (const struct ieee80211_wme_param *) ie;
2516 printf("<qosinfo 0x%x", wme->param_qosInfo);
2517 ie += offsetof(struct ieee80211_wme_param, params_acParams);
2518 for (i = 0; i < WME_NUM_AC; i++) {
2519 const struct ieee80211_wme_acparams *ac =
2520 &wme->params_acParams[i];
2522 printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]"
2524 , MS(ac->acp_aci_aifsn, WME_PARAM_ACM) ? "acm " : ""
2525 , MS(ac->acp_aci_aifsn, WME_PARAM_AIFSN)
2526 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMIN)
2527 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMAX)
2528 , LE_READ_2(&ac->acp_txop)
2536 printwmeinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2540 const struct ieee80211_wme_info *wme =
2541 (const struct ieee80211_wme_info *) ie;
2542 printf("<version 0x%x info 0x%x>",
2543 wme->wme_version, wme->wme_info);
2548 printvhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2552 const struct ieee80211_ie_vhtcap *vhtcap =
2553 (const struct ieee80211_ie_vhtcap *) ie;
2554 uint32_t vhtcap_info = LE_READ_4(&vhtcap->vht_cap_info);
2556 printf("<cap 0x%08x", vhtcap_info);
2557 printf(" rx_mcs_map 0x%x",
2558 LE_READ_2(&vhtcap->supp_mcs.rx_mcs_map));
2559 printf(" rx_highest %d",
2560 LE_READ_2(&vhtcap->supp_mcs.rx_highest) & 0x1fff);
2561 printf(" tx_mcs_map 0x%x",
2562 LE_READ_2(&vhtcap->supp_mcs.tx_mcs_map));
2563 printf(" tx_highest %d",
2564 LE_READ_2(&vhtcap->supp_mcs.tx_highest) & 0x1fff);
2571 printvhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2575 const struct ieee80211_ie_vht_operation *vhtinfo =
2576 (const struct ieee80211_ie_vht_operation *) ie;
2578 printf("<chw %d freq1_idx %d freq2_idx %d basic_mcs_set 0x%04x>",
2579 vhtinfo->chan_width,
2580 vhtinfo->center_freq_seg1_idx,
2581 vhtinfo->center_freq_seg2_idx,
2582 LE_READ_2(&vhtinfo->basic_mcs_set));
2587 printvhtpwrenv(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2590 static const char *txpwrmap[] = {
2597 const struct ieee80211_ie_vht_txpwrenv *vhtpwr =
2598 (const struct ieee80211_ie_vht_txpwrenv *) ie;
2600 const char *sep = "";
2602 /* Get count; trim at ielen */
2603 n = (vhtpwr->tx_info &
2604 IEEE80211_VHT_TXPWRENV_INFO_COUNT_MASK) + 1;
2608 printf("<tx_info 0x%02x pwr:[", vhtpwr->tx_info);
2609 for (i = 0; i < n; i++) {
2610 printf("%s%s:%.2f", sep, txpwrmap[i],
2611 ((float) ((int8_t) ie[i+3])) / 2.0);
2620 printhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2624 const struct ieee80211_ie_htcap *htcap =
2625 (const struct ieee80211_ie_htcap *) ie;
2629 printf("<cap 0x%x param 0x%x",
2630 LE_READ_2(&htcap->hc_cap), htcap->hc_param);
2633 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2634 if (isset(htcap->hc_mcsset, i)) {
2635 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2636 if (isclr(htcap->hc_mcsset, j))
2640 printf("%s%u", sep, i);
2642 printf("%s%u-%u", sep, i, j);
2646 printf("] extcap 0x%x txbf 0x%x antenna 0x%x>",
2647 LE_READ_2(&htcap->hc_extcap),
2648 LE_READ_4(&htcap->hc_txbf),
2654 printhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2658 const struct ieee80211_ie_htinfo *htinfo =
2659 (const struct ieee80211_ie_htinfo *) ie;
2663 printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel,
2664 htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3,
2665 LE_READ_2(&htinfo->hi_byte45));
2666 printf(" basicmcs[");
2668 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2669 if (isset(htinfo->hi_basicmcsset, i)) {
2670 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2671 if (isclr(htinfo->hi_basicmcsset, j))
2675 printf("%s%u", sep, i);
2677 printf("%s%u-%u", sep, i, j);
2686 printathie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2691 const struct ieee80211_ath_ie *ath =
2692 (const struct ieee80211_ath_ie *)ie;
2695 if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME)
2697 if (ath->ath_capability & ATHEROS_CAP_COMPRESSION)
2699 if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME)
2701 if (ath->ath_capability & ATHEROS_CAP_XR)
2703 if (ath->ath_capability & ATHEROS_CAP_AR)
2705 if (ath->ath_capability & ATHEROS_CAP_BURST)
2707 if (ath->ath_capability & ATHEROS_CAP_WME)
2709 if (ath->ath_capability & ATHEROS_CAP_BOOST)
2711 printf("0x%x>", LE_READ_2(ath->ath_defkeyix));
2717 printmeshconf(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2719 #define MATCHOUI(field, oui, string) \
2721 if (memcmp(field, oui, 4) == 0) \
2722 printf("%s", string); \
2727 const struct ieee80211_meshconf_ie *mconf =
2728 (const struct ieee80211_meshconf_ie *)ie;
2730 if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP)
2735 if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME)
2739 printf(" CONGESTION:");
2740 if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED)
2745 if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF)
2750 if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED)
2754 printf(" FORM:0x%x CAPS:0x%x>", mconf->conf_form,
2761 printbssload(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2765 const struct ieee80211_bss_load_ie *bssload =
2766 (const struct ieee80211_bss_load_ie *) ie;
2767 printf("<sta count %d, chan load %d, aac %d>",
2768 LE_READ_2(&bssload->sta_count),
2775 printapchanrep(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2779 const struct ieee80211_ap_chan_report_ie *ap =
2780 (const struct ieee80211_ap_chan_report_ie *) ie;
2781 const char *sep = "";
2784 printf("<class %u, chan:[", ap->i_class);
2786 for (i = 3; i < ielen; i++) {
2787 printf("%s%u", sep, ie[i]);
2795 wpa_cipher(const u_int8_t *sel)
2797 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2798 u_int32_t w = LE_READ_4(sel);
2801 case WPA_SEL(WPA_CSE_NULL):
2803 case WPA_SEL(WPA_CSE_WEP40):
2805 case WPA_SEL(WPA_CSE_WEP104):
2807 case WPA_SEL(WPA_CSE_TKIP):
2809 case WPA_SEL(WPA_CSE_CCMP):
2812 return "?"; /* NB: so 1<< is discarded */
2817 wpa_keymgmt(const u_int8_t *sel)
2819 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2820 u_int32_t w = LE_READ_4(sel);
2823 case WPA_SEL(WPA_ASE_8021X_UNSPEC):
2824 return "8021X-UNSPEC";
2825 case WPA_SEL(WPA_ASE_8021X_PSK):
2827 case WPA_SEL(WPA_ASE_NONE):
2835 printwpaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2837 u_int8_t len = ie[1];
2844 ie += 6, len -= 4; /* NB: len is payload only */
2846 printf("<v%u", LE_READ_2(ie));
2849 printf(" mc:%s", wpa_cipher(ie));
2852 /* unicast ciphers */
2856 for (; n > 0; n--) {
2857 printf("%s%s", sep, wpa_cipher(ie));
2862 /* key management algorithms */
2866 for (; n > 0; n--) {
2867 printf("%s%s", sep, wpa_keymgmt(ie));
2872 if (len > 2) /* optional capabilities */
2873 printf(", caps 0x%x", LE_READ_2(ie));
2879 rsn_cipher(const u_int8_t *sel)
2881 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
2882 u_int32_t w = LE_READ_4(sel);
2885 case RSN_SEL(RSN_CSE_NULL):
2887 case RSN_SEL(RSN_CSE_WEP40):
2889 case RSN_SEL(RSN_CSE_WEP104):
2891 case RSN_SEL(RSN_CSE_TKIP):
2893 case RSN_SEL(RSN_CSE_CCMP):
2895 case RSN_SEL(RSN_CSE_WRAP):
2903 rsn_keymgmt(const u_int8_t *sel)
2905 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
2906 u_int32_t w = LE_READ_4(sel);
2909 case RSN_SEL(RSN_ASE_8021X_UNSPEC):
2910 return "8021X-UNSPEC";
2911 case RSN_SEL(RSN_ASE_8021X_PSK):
2913 case RSN_SEL(RSN_ASE_NONE):
2921 printrsnie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2928 ie += 2, ielen -= 2;
2930 printf("<v%u", LE_READ_2(ie));
2931 ie += 2, ielen -= 2;
2933 printf(" mc:%s", rsn_cipher(ie));
2934 ie += 4, ielen -= 4;
2936 /* unicast ciphers */
2938 ie += 2, ielen -= 2;
2940 for (; n > 0; n--) {
2941 printf("%s%s", sep, rsn_cipher(ie));
2942 ie += 4, ielen -= 4;
2946 /* key management algorithms */
2948 ie += 2, ielen -= 2;
2950 for (; n > 0; n--) {
2951 printf("%s%s", sep, rsn_keymgmt(ie));
2952 ie += 4, ielen -= 4;
2956 if (ielen > 2) /* optional capabilities */
2957 printf(", caps 0x%x", LE_READ_2(ie));
2963 /* XXX move to a public include file */
2964 #define IEEE80211_WPS_DEV_PASS_ID 0x1012
2965 #define IEEE80211_WPS_SELECTED_REG 0x1041
2966 #define IEEE80211_WPS_SETUP_STATE 0x1044
2967 #define IEEE80211_WPS_UUID_E 0x1047
2968 #define IEEE80211_WPS_VERSION 0x104a
2970 #define BE_READ_2(p) \
2972 ((((const u_int8_t *)(p))[1] ) | \
2973 (((const u_int8_t *)(p))[0] << 8)))
2976 printwpsie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2978 u_int8_t len = ie[1];
2982 static const char *dev_pass_id[] = {
2983 "D", /* Default (PIN) */
2984 "U", /* User-specified */
2985 "M", /* Machine-specified */
2987 "P", /* PushButton */
2988 "R" /* Registrar-specified */
2992 ie +=6, len -= 4; /* NB: len is payload only */
2994 /* WPS IE in Beacon and Probe Resp frames have different fields */
2997 uint16_t tlv_type = BE_READ_2(ie);
2998 uint16_t tlv_len = BE_READ_2(ie + 2);
3003 case IEEE80211_WPS_VERSION:
3004 printf("v:%d.%d", *ie >> 4, *ie & 0xf);
3006 case IEEE80211_WPS_SETUP_STATE:
3007 /* Only 1 and 2 are valid */
3008 if (*ie == 0 || *ie >= 3)
3011 printf(" st:%s", *ie == 1 ? "N" : "C");
3013 case IEEE80211_WPS_SELECTED_REG:
3014 printf(" sel:%s", *ie ? "T" : "F");
3016 case IEEE80211_WPS_DEV_PASS_ID:
3018 if (n < nitems(dev_pass_id))
3019 printf(" dpi:%s", dev_pass_id[n]);
3021 case IEEE80211_WPS_UUID_E:
3023 for (n = 0; n < (tlv_len - 1); n++)
3024 printf("%02x-", ie[n]);
3025 printf("%02x", ie[n]);
3028 ie += tlv_len, len -= tlv_len;
3035 printtdmaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3038 if (verbose && ielen >= sizeof(struct ieee80211_tdma_param)) {
3039 const struct ieee80211_tdma_param *tdma =
3040 (const struct ieee80211_tdma_param *) ie;
3043 printf("<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>",
3044 tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt,
3045 LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval,
3046 tdma->tdma_inuse[0]);
3051 * Copy the ssid string contents into buf, truncating to fit. If the
3052 * ssid is entirely printable then just copy intact. Otherwise convert
3053 * to hexadecimal. If the result is truncated then replace the last
3054 * three characters with "...".
3057 copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len)
3063 if (essid_len > bufsize)
3067 /* determine printable or not */
3068 for (i = 0, p = essid; i < maxlen; i++, p++) {
3069 if (*p < ' ' || *p > 0x7e)
3072 if (i != maxlen) { /* not printable, print as hex */
3075 strlcpy(buf, "0x", bufsize);
3078 for (i = 0; i < maxlen && bufsize >= 2; i++) {
3079 sprintf(&buf[2+2*i], "%02x", p[i]);
3083 memcpy(&buf[2+2*i-3], "...", 3);
3084 } else { /* printable, truncate as needed */
3085 memcpy(buf, essid, maxlen);
3086 if (maxlen != essid_len)
3087 memcpy(&buf[maxlen-3], "...", 3);
3093 printssid(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3095 char ssid[2*IEEE80211_NWID_LEN+1];
3097 printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid);
3101 printrates(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3108 for (i = 2; i < ielen; i++) {
3109 printf("%s%s%d", sep,
3110 ie[i] & IEEE80211_RATE_BASIC ? "B" : "",
3111 ie[i] & IEEE80211_RATE_VAL);
3118 printcountry(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3120 const struct ieee80211_country_ie *cie =
3121 (const struct ieee80211_country_ie *) ie;
3122 int i, nbands, schan, nchan;
3124 printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]);
3125 nbands = (cie->len - 3) / sizeof(cie->band[0]);
3126 for (i = 0; i < nbands; i++) {
3127 schan = cie->band[i].schan;
3128 nchan = cie->band[i].nchan;
3130 printf(" %u-%u,%u", schan, schan + nchan-1,
3131 cie->band[i].maxtxpwr);
3133 printf(" %u,%u", schan, cie->band[i].maxtxpwr);
3139 iswpaoui(const u_int8_t *frm)
3141 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI);
3145 iswmeinfo(const u_int8_t *frm)
3147 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3148 frm[6] == WME_INFO_OUI_SUBTYPE;
3152 iswmeparam(const u_int8_t *frm)
3154 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3155 frm[6] == WME_PARAM_OUI_SUBTYPE;
3159 isatherosoui(const u_int8_t *frm)
3161 return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI);
3165 istdmaoui(const uint8_t *frm)
3167 return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI);
3171 iswpsoui(const uint8_t *frm)
3173 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPS_OUI_TYPE<<24)|WPA_OUI);
3180 case IEEE80211_ELEMID_FHPARMS: return " FHPARMS";
3181 case IEEE80211_ELEMID_CFPARMS: return " CFPARMS";
3182 case IEEE80211_ELEMID_TIM: return " TIM";
3183 case IEEE80211_ELEMID_IBSSPARMS:return " IBSSPARMS";
3184 case IEEE80211_ELEMID_BSSLOAD: return " BSSLOAD";
3185 case IEEE80211_ELEMID_CHALLENGE:return " CHALLENGE";
3186 case IEEE80211_ELEMID_PWRCNSTR: return " PWRCNSTR";
3187 case IEEE80211_ELEMID_PWRCAP: return " PWRCAP";
3188 case IEEE80211_ELEMID_TPCREQ: return " TPCREQ";
3189 case IEEE80211_ELEMID_TPCREP: return " TPCREP";
3190 case IEEE80211_ELEMID_SUPPCHAN: return " SUPPCHAN";
3191 case IEEE80211_ELEMID_CSA: return " CSA";
3192 case IEEE80211_ELEMID_MEASREQ: return " MEASREQ";
3193 case IEEE80211_ELEMID_MEASREP: return " MEASREP";
3194 case IEEE80211_ELEMID_QUIET: return " QUIET";
3195 case IEEE80211_ELEMID_IBSSDFS: return " IBSSDFS";
3196 case IEEE80211_ELEMID_TPC: return " TPC";
3197 case IEEE80211_ELEMID_CCKM: return " CCKM";
3203 printies(const u_int8_t *vp, int ielen, int maxcols)
3207 case IEEE80211_ELEMID_SSID:
3209 printssid(" SSID", vp, 2+vp[1], maxcols);
3211 case IEEE80211_ELEMID_RATES:
3212 case IEEE80211_ELEMID_XRATES:
3214 printrates(vp[0] == IEEE80211_ELEMID_RATES ?
3215 " RATES" : " XRATES", vp, 2+vp[1], maxcols);
3217 case IEEE80211_ELEMID_DSPARMS:
3219 printf(" DSPARMS<%u>", vp[2]);
3221 case IEEE80211_ELEMID_COUNTRY:
3223 printcountry(" COUNTRY", vp, 2+vp[1], maxcols);
3225 case IEEE80211_ELEMID_ERP:
3227 printf(" ERP<0x%x>", vp[2]);
3229 case IEEE80211_ELEMID_VENDOR:
3231 printwpaie(" WPA", vp, 2+vp[1], maxcols);
3232 else if (iswmeinfo(vp))
3233 printwmeinfo(" WME", vp, 2+vp[1], maxcols);
3234 else if (iswmeparam(vp))
3235 printwmeparam(" WME", vp, 2+vp[1], maxcols);
3236 else if (isatherosoui(vp))
3237 printathie(" ATH", vp, 2+vp[1], maxcols);
3238 else if (iswpsoui(vp))
3239 printwpsie(" WPS", vp, 2+vp[1], maxcols);
3240 else if (istdmaoui(vp))
3241 printtdmaie(" TDMA", vp, 2+vp[1], maxcols);
3243 printie(" VEN", vp, 2+vp[1], maxcols);
3245 case IEEE80211_ELEMID_RSN:
3246 printrsnie(" RSN", vp, 2+vp[1], maxcols);
3248 case IEEE80211_ELEMID_HTCAP:
3249 printhtcap(" HTCAP", vp, 2+vp[1], maxcols);
3251 case IEEE80211_ELEMID_HTINFO:
3253 printhtinfo(" HTINFO", vp, 2+vp[1], maxcols);
3255 case IEEE80211_ELEMID_MESHID:
3257 printssid(" MESHID", vp, 2+vp[1], maxcols);
3259 case IEEE80211_ELEMID_MESHCONF:
3260 printmeshconf(" MESHCONF", vp, 2+vp[1], maxcols);
3262 case IEEE80211_ELEMID_VHT_CAP:
3263 printvhtcap(" VHTCAP", vp, 2+vp[1], maxcols);
3265 case IEEE80211_ELEMID_VHT_OPMODE:
3266 printvhtinfo(" VHTOPMODE", vp, 2+vp[1], maxcols);
3268 case IEEE80211_ELEMID_VHT_PWR_ENV:
3269 printvhtpwrenv(" VHTPWRENV", vp, 2+vp[1], maxcols);
3271 case IEEE80211_ELEMID_BSSLOAD:
3272 printbssload(" BSSLOAD", vp, 2+vp[1], maxcols);
3274 case IEEE80211_ELEMID_APCHANREP:
3275 printapchanrep(" APCHANREP", vp, 2+vp[1], maxcols);
3279 printie(iename(vp[0]), vp, 2+vp[1], maxcols);
3288 printmimo(const struct ieee80211_mimo_info *mi)
3290 /* NB: don't muddy display unless there's something to show */
3291 if (mi->rssi[0] != 0 || mi->rssi[1] != 0 || mi->rssi[2] != 0) {
3292 /* XXX ignore EVM for now */
3293 printf(" (rssi %.1f:%.1f:%.1f nf %d:%d:%d)",
3294 mi->rssi[0] / 2.0, mi->rssi[1] / 2.0, mi->rssi[2] / 2.0,
3295 mi->noise[0], mi->noise[1], mi->noise[2]);
3302 uint8_t buf[24*1024];
3303 char ssid[IEEE80211_NWID_LEN+1];
3305 int len, ssidmax, idlen;
3307 if (get80211len(s, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0)
3308 errx(1, "unable to get scan results");
3309 if (len < sizeof(struct ieee80211req_scan_result))
3314 ssidmax = verbose ? IEEE80211_NWID_LEN - 1 : 14;
3315 printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n"
3316 , ssidmax, ssidmax, "SSID/MESH ID"
3326 const struct ieee80211req_scan_result *sr;
3327 const uint8_t *vp, *idp;
3329 sr = (const struct ieee80211req_scan_result *) cp;
3330 vp = cp + sr->isr_ie_off;
3331 if (sr->isr_meshid_len) {
3332 idp = vp + sr->isr_ssid_len;
3333 idlen = sr->isr_meshid_len;
3336 idlen = sr->isr_ssid_len;
3338 printf("%-*.*s %s %3d %3dM %4d:%-4d %4d %-4.4s"
3340 , copy_essid(ssid, ssidmax, idp, idlen)
3342 , ether_ntoa((const struct ether_addr *) sr->isr_bssid)
3343 , ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags)
3344 , getmaxrate(sr->isr_rates, sr->isr_nrates)
3345 , (sr->isr_rssi/2)+sr->isr_noise, sr->isr_noise
3347 , getcaps(sr->isr_capinfo)
3349 printies(vp + sr->isr_ssid_len + sr->isr_meshid_len,
3350 sr->isr_ie_len, 24);
3352 cp += sr->isr_len, len -= sr->isr_len;
3353 } while (len >= sizeof(struct ieee80211req_scan_result));
3357 scan_and_wait(int s)
3359 struct ieee80211_scan_req sr;
3360 struct ieee80211req ireq;
3363 sroute = socket(PF_ROUTE, SOCK_RAW, 0);
3365 perror("socket(PF_ROUTE,SOCK_RAW)");
3368 (void) memset(&ireq, 0, sizeof(ireq));
3369 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
3370 ireq.i_type = IEEE80211_IOC_SCAN_REQ;
3372 memset(&sr, 0, sizeof(sr));
3373 sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE
3374 | IEEE80211_IOC_SCAN_BGSCAN
3375 | IEEE80211_IOC_SCAN_NOPICK
3376 | IEEE80211_IOC_SCAN_ONCE;
3377 sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER;
3381 ireq.i_len = sizeof(sr);
3383 * NB: only root can trigger a scan so ignore errors. Also ignore
3384 * possible errors from net80211, even if no new scan could be
3385 * started there might still be a valid scan cache.
3387 if (ioctl(s, SIOCS80211, &ireq) == 0) {
3389 struct if_announcemsghdr *ifan;
3390 struct rt_msghdr *rtm;
3393 if (read(sroute, buf, sizeof(buf)) < 0) {
3394 perror("read(PF_ROUTE)");
3397 rtm = (struct rt_msghdr *) buf;
3398 if (rtm->rtm_version != RTM_VERSION)
3400 ifan = (struct if_announcemsghdr *) rtm;
3401 } while (rtm->rtm_type != RTM_IEEE80211 ||
3402 ifan->ifan_what != RTM_IEEE80211_SCAN);
3408 DECL_CMD_FUNC(set80211scan, val, d)
3414 static enum ieee80211_opmode get80211opmode(int s);
3417 gettxseq(const struct ieee80211req_sta_info *si)
3421 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3422 return si->isi_txseqs[0];
3423 /* XXX not right but usually what folks want */
3425 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3426 if (si->isi_txseqs[i] > txseq)
3427 txseq = si->isi_txseqs[i];
3432 getrxseq(const struct ieee80211req_sta_info *si)
3436 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3437 return si->isi_rxseqs[0];
3438 /* XXX not right but usually what folks want */
3440 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3441 if (si->isi_rxseqs[i] > rxseq)
3442 rxseq = si->isi_rxseqs[i];
3447 list_stations(int s)
3450 struct ieee80211req_sta_req req;
3451 uint8_t buf[24*1024];
3453 enum ieee80211_opmode opmode = get80211opmode(s);
3457 /* broadcast address =>'s get all stations */
3458 (void) memset(u.req.is_u.macaddr, 0xff, IEEE80211_ADDR_LEN);
3459 if (opmode == IEEE80211_M_STA) {
3461 * Get information about the associated AP.
3463 (void) get80211(s, IEEE80211_IOC_BSSID,
3464 u.req.is_u.macaddr, IEEE80211_ADDR_LEN);
3466 if (get80211len(s, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0)
3467 errx(1, "unable to get station information");
3468 if (len < sizeof(struct ieee80211req_sta_info))
3473 if (opmode == IEEE80211_M_MBSS)
3474 printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n"
3487 printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-7s\n"
3499 cp = (const uint8_t *) u.req.info;
3501 const struct ieee80211req_sta_info *si;
3503 si = (const struct ieee80211req_sta_info *) cp;
3504 if (si->isi_len < sizeof(*si))
3506 if (opmode == IEEE80211_M_MBSS)
3507 printf("%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d"
3508 , ether_ntoa((const struct ether_addr*)
3510 , ieee80211_mhz2ieee(si->isi_freq,
3514 , mesh_linkstate_string(si->isi_peerstate)
3522 printf("%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-7.7s"
3523 , ether_ntoa((const struct ether_addr*)
3525 , IEEE80211_AID(si->isi_associd)
3526 , ieee80211_mhz2ieee(si->isi_freq,
3533 , getcaps(si->isi_capinfo)
3534 , getflags(si->isi_state)
3536 printies(cp + si->isi_ie_off, si->isi_ie_len, 24);
3537 printmimo(&si->isi_mimo);
3539 cp += si->isi_len, len -= si->isi_len;
3540 } while (len >= sizeof(struct ieee80211req_sta_info));
3544 mesh_linkstate_string(uint8_t state)
3546 static const char *state_names[] = {
3555 if (state >= nitems(state_names)) {
3556 static char buf[10];
3557 snprintf(buf, sizeof(buf), "#%u", state);
3560 return state_names[state];
3564 get_chaninfo(const struct ieee80211_channel *c, int precise,
3565 char buf[], size_t bsize)
3568 if (IEEE80211_IS_CHAN_FHSS(c))
3569 strlcat(buf, " FHSS", bsize);
3570 if (IEEE80211_IS_CHAN_A(c))
3571 strlcat(buf, " 11a", bsize);
3572 else if (IEEE80211_IS_CHAN_ANYG(c))
3573 strlcat(buf, " 11g", bsize);
3574 else if (IEEE80211_IS_CHAN_B(c))
3575 strlcat(buf, " 11b", bsize);
3576 if (IEEE80211_IS_CHAN_HALF(c))
3577 strlcat(buf, "/10MHz", bsize);
3578 if (IEEE80211_IS_CHAN_QUARTER(c))
3579 strlcat(buf, "/5MHz", bsize);
3580 if (IEEE80211_IS_CHAN_TURBO(c))
3581 strlcat(buf, " Turbo", bsize);
3583 if (IEEE80211_IS_CHAN_HT20(c))
3584 strlcat(buf, " ht/20", bsize);
3585 else if (IEEE80211_IS_CHAN_HT40D(c))
3586 strlcat(buf, " ht/40-", bsize);
3587 else if (IEEE80211_IS_CHAN_HT40U(c))
3588 strlcat(buf, " ht/40+", bsize);
3590 if (IEEE80211_IS_CHAN_HT(c))
3591 strlcat(buf, " ht", bsize);
3597 print_chaninfo(const struct ieee80211_channel *c, int verb)
3602 printf("Channel %3u : %u%c%c%c%c%c MHz%-14.14s",
3603 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
3604 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
3605 IEEE80211_IS_CHAN_DFS(c) ? 'D' : ' ',
3606 IEEE80211_IS_CHAN_RADAR(c) ? 'R' : ' ',
3607 IEEE80211_IS_CHAN_CWINT(c) ? 'I' : ' ',
3608 IEEE80211_IS_CHAN_CACDONE(c) ? 'C' : ' ',
3609 get_chaninfo(c, verb, buf, sizeof(buf)));
3611 printf("Channel %3u : %u%c MHz%-14.14s",
3612 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
3613 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
3614 get_chaninfo(c, verb, buf, sizeof(buf)));
3619 chanpref(const struct ieee80211_channel *c)
3621 if (IEEE80211_IS_CHAN_HT40(c))
3623 if (IEEE80211_IS_CHAN_HT20(c))
3625 if (IEEE80211_IS_CHAN_HALF(c))
3627 if (IEEE80211_IS_CHAN_QUARTER(c))
3629 if (IEEE80211_IS_CHAN_TURBO(c))
3631 if (IEEE80211_IS_CHAN_A(c))
3633 if (IEEE80211_IS_CHAN_G(c))
3635 if (IEEE80211_IS_CHAN_B(c))
3637 if (IEEE80211_IS_CHAN_PUREG(c))
3643 print_channels(int s, const struct ieee80211req_chaninfo *chans,
3644 int allchans, int verb)
3646 struct ieee80211req_chaninfo *achans;
3647 uint8_t reported[IEEE80211_CHAN_BYTES];
3648 const struct ieee80211_channel *c;
3651 achans = malloc(IEEE80211_CHANINFO_SPACE(chans));
3653 errx(1, "no space for active channel list");
3654 achans->ic_nchans = 0;
3655 memset(reported, 0, sizeof(reported));
3657 struct ieee80211req_chanlist active;
3659 if (get80211(s, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0)
3660 errx(1, "unable to get active channel list");
3661 for (i = 0; i < chans->ic_nchans; i++) {
3662 c = &chans->ic_chans[i];
3663 if (!isset(active.ic_channels, c->ic_ieee))
3666 * Suppress compatible duplicates unless
3667 * verbose. The kernel gives us it's
3668 * complete channel list which has separate
3669 * entries for 11g/11b and 11a/turbo.
3671 if (isset(reported, c->ic_ieee) && !verb) {
3672 /* XXX we assume duplicates are adjacent */
3673 achans->ic_chans[achans->ic_nchans-1] = *c;
3675 achans->ic_chans[achans->ic_nchans++] = *c;
3676 setbit(reported, c->ic_ieee);
3680 for (i = 0; i < chans->ic_nchans; i++) {
3681 c = &chans->ic_chans[i];
3682 /* suppress duplicates as above */
3683 if (isset(reported, c->ic_ieee) && !verb) {
3684 /* XXX we assume duplicates are adjacent */
3685 struct ieee80211_channel *a =
3686 &achans->ic_chans[achans->ic_nchans-1];
3687 if (chanpref(c) > chanpref(a))
3690 achans->ic_chans[achans->ic_nchans++] = *c;
3691 setbit(reported, c->ic_ieee);
3695 half = achans->ic_nchans / 2;
3696 if (achans->ic_nchans % 2)
3699 for (i = 0; i < achans->ic_nchans / 2; i++) {
3700 print_chaninfo(&achans->ic_chans[i], verb);
3701 print_chaninfo(&achans->ic_chans[half+i], verb);
3704 if (achans->ic_nchans % 2) {
3705 print_chaninfo(&achans->ic_chans[i], verb);
3712 list_channels(int s, int allchans)
3715 print_channels(s, chaninfo, allchans, verbose);
3719 print_txpow(const struct ieee80211_channel *c)
3721 printf("Channel %3u : %u MHz %3.1f reg %2d ",
3722 c->ic_ieee, c->ic_freq,
3723 c->ic_maxpower/2., c->ic_maxregpower);
3727 print_txpow_verbose(const struct ieee80211_channel *c)
3729 print_chaninfo(c, 1);
3730 printf("min %4.1f dBm max %3.1f dBm reg %2d dBm",
3731 c->ic_minpower/2., c->ic_maxpower/2., c->ic_maxregpower);
3732 /* indicate where regulatory cap limits power use */
3733 if (c->ic_maxpower > 2*c->ic_maxregpower)
3740 struct ieee80211req_chaninfo *achans;
3741 uint8_t reported[IEEE80211_CHAN_BYTES];
3742 struct ieee80211_channel *c, *prev;
3746 achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo));
3748 errx(1, "no space for active channel list");
3749 achans->ic_nchans = 0;
3750 memset(reported, 0, sizeof(reported));
3751 for (i = 0; i < chaninfo->ic_nchans; i++) {
3752 c = &chaninfo->ic_chans[i];
3753 /* suppress duplicates as above */
3754 if (isset(reported, c->ic_ieee) && !verbose) {
3755 /* XXX we assume duplicates are adjacent */
3756 assert(achans->ic_nchans > 0);
3757 prev = &achans->ic_chans[achans->ic_nchans-1];
3758 /* display highest power on channel */
3759 if (c->ic_maxpower > prev->ic_maxpower)
3762 achans->ic_chans[achans->ic_nchans++] = *c;
3763 setbit(reported, c->ic_ieee);
3767 half = achans->ic_nchans / 2;
3768 if (achans->ic_nchans % 2)
3771 for (i = 0; i < achans->ic_nchans / 2; i++) {
3772 print_txpow(&achans->ic_chans[i]);
3773 print_txpow(&achans->ic_chans[half+i]);
3776 if (achans->ic_nchans % 2) {
3777 print_txpow(&achans->ic_chans[i]);
3781 for (i = 0; i < achans->ic_nchans; i++) {
3782 print_txpow_verbose(&achans->ic_chans[i]);
3794 #define IEEE80211_C_BITS \
3795 "\20\1STA\002803ENCAP\7FF\10TURBOP\11IBSS\12PMGT" \
3796 "\13HOSTAP\14AHDEMO\15SWRETRY\16TXPMGT\17SHSLOT\20SHPREAMBLE" \
3797 "\21MONITOR\22DFS\23MBSS\30WPA1\31WPA2\32BURST\33WME\34WDS\36BGSCAN" \
3801 list_capabilities(int s)
3803 struct ieee80211_devcaps_req *dc;
3806 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
3808 dc = malloc(IEEE80211_DEVCAPS_SIZE(1));
3810 errx(1, "no space for device capabilities");
3811 dc->dc_chaninfo.ic_nchans = verbose ? MAXCHAN : 1;
3813 printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS);
3814 if (dc->dc_cryptocaps != 0 || verbose) {
3816 printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS);
3818 if (dc->dc_htcaps != 0 || verbose) {
3820 printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS);
3824 chaninfo = &dc->dc_chaninfo; /* XXX */
3825 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, verbose);
3831 get80211wme(int s, int param, int ac, int *val)
3833 struct ieee80211req ireq;
3835 (void) memset(&ireq, 0, sizeof(ireq));
3836 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
3837 ireq.i_type = param;
3839 if (ioctl(s, SIOCG80211, &ireq) < 0) {
3840 warn("cannot get WME parameter %d, ac %d%s",
3841 param, ac & IEEE80211_WMEPARAM_VAL,
3842 ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : "");
3850 list_wme_aci(int s, const char *tag, int ac)
3854 printf("\t%s", tag);
3856 /* show WME BSS parameters */
3857 if (get80211wme(s, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1)
3858 printf(" cwmin %2u", val);
3859 if (get80211wme(s, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1)
3860 printf(" cwmax %2u", val);
3861 if (get80211wme(s, IEEE80211_IOC_WME_AIFS, ac, &val) != -1)
3862 printf(" aifs %2u", val);
3863 if (get80211wme(s, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1)
3864 printf(" txopLimit %3u", val);
3865 if (get80211wme(s, IEEE80211_IOC_WME_ACM, ac, &val) != -1) {
3872 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
3873 if (get80211wme(s, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) {
3886 static const char *acnames[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
3890 /* display both BSS and local settings */
3891 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) {
3893 if (ac & IEEE80211_WMEPARAM_BSS)
3894 list_wme_aci(s, " ", ac);
3896 list_wme_aci(s, acnames[ac], ac);
3897 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
3898 ac |= IEEE80211_WMEPARAM_BSS;
3901 ac &= ~IEEE80211_WMEPARAM_BSS;
3904 /* display only channel settings */
3905 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++)
3906 list_wme_aci(s, acnames[ac], ac);
3913 const struct ieee80211_roamparam *rp;
3917 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
3918 rp = &roamparams.params[mode];
3919 if (rp->rssi == 0 && rp->rate == 0)
3921 if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) {
3923 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm MCS %2u ",
3924 modename[mode], rp->rssi/2,
3925 rp->rate &~ IEEE80211_RATE_MCS);
3927 LINE_CHECK("roam:%-7.7s rssi %4udBm MCS %2u ",
3928 modename[mode], rp->rssi/2,
3929 rp->rate &~ IEEE80211_RATE_MCS);
3932 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s",
3933 modename[mode], rp->rssi/2, rp->rate/2);
3935 LINE_CHECK("roam:%-7.7s rssi %4udBm rate %2u Mb/s",
3936 modename[mode], rp->rssi/2, rp->rate/2);
3942 list_txparams(int s)
3944 const struct ieee80211_txparam *tp;
3948 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
3949 tp = &txparams.params[mode];
3950 if (tp->mgmtrate == 0 && tp->mcastrate == 0)
3952 if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) {
3953 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
3954 LINE_CHECK("%-7.7s ucast NONE mgmt %2u MCS "
3955 "mcast %2u MCS maxretry %u",
3957 tp->mgmtrate &~ IEEE80211_RATE_MCS,
3958 tp->mcastrate &~ IEEE80211_RATE_MCS,
3961 LINE_CHECK("%-7.7s ucast %2u MCS mgmt %2u MCS "
3962 "mcast %2u MCS maxretry %u",
3964 tp->ucastrate &~ IEEE80211_RATE_MCS,
3965 tp->mgmtrate &~ IEEE80211_RATE_MCS,
3966 tp->mcastrate &~ IEEE80211_RATE_MCS,
3969 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
3970 LINE_CHECK("%-7.7s ucast NONE mgmt %2u Mb/s "
3971 "mcast %2u Mb/s maxretry %u",
3974 tp->mcastrate/2, tp->maxretry);
3976 LINE_CHECK("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s "
3977 "mcast %2u Mb/s maxretry %u",
3979 tp->ucastrate/2, tp->mgmtrate/2,
3980 tp->mcastrate/2, tp->maxretry);
3986 printpolicy(int policy)
3989 case IEEE80211_MACCMD_POLICY_OPEN:
3990 printf("policy: open\n");
3992 case IEEE80211_MACCMD_POLICY_ALLOW:
3993 printf("policy: allow\n");
3995 case IEEE80211_MACCMD_POLICY_DENY:
3996 printf("policy: deny\n");
3998 case IEEE80211_MACCMD_POLICY_RADIUS:
3999 printf("policy: radius\n");
4002 printf("policy: unknown (%u)\n", policy);
4010 struct ieee80211req ireq;
4011 struct ieee80211req_maclist *acllist;
4012 int i, nacls, policy, len;
4016 (void) memset(&ireq, 0, sizeof(ireq));
4017 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name)); /* XXX ?? */
4018 ireq.i_type = IEEE80211_IOC_MACCMD;
4019 ireq.i_val = IEEE80211_MACCMD_POLICY;
4020 if (ioctl(s, SIOCG80211, &ireq) < 0) {
4021 if (errno == EINVAL) {
4022 printf("No acl policy loaded\n");
4025 err(1, "unable to get mac policy");
4027 policy = ireq.i_val;
4028 if (policy == IEEE80211_MACCMD_POLICY_OPEN) {
4030 } else if (policy == IEEE80211_MACCMD_POLICY_ALLOW) {
4032 } else if (policy == IEEE80211_MACCMD_POLICY_DENY) {
4034 } else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) {
4035 c = 'r'; /* NB: should never have entries */
4037 printf("policy: unknown (%u)\n", policy);
4040 if (verbose || c == '?')
4041 printpolicy(policy);
4043 ireq.i_val = IEEE80211_MACCMD_LIST;
4045 if (ioctl(s, SIOCG80211, &ireq) < 0)
4046 err(1, "unable to get mac acl list size");
4047 if (ireq.i_len == 0) { /* NB: no acls */
4048 if (!(verbose || c == '?'))
4049 printpolicy(policy);
4056 err(1, "out of memory for acl list");
4059 if (ioctl(s, SIOCG80211, &ireq) < 0)
4060 err(1, "unable to get mac acl list");
4061 nacls = len / sizeof(*acllist);
4062 acllist = (struct ieee80211req_maclist *) data;
4063 for (i = 0; i < nacls; i++)
4064 printf("%c%s\n", c, ether_ntoa(
4065 (const struct ether_addr *) acllist[i].ml_macaddr));
4070 print_regdomain(const struct ieee80211_regdomain *reg, int verb)
4072 if ((reg->regdomain != 0 &&
4073 reg->regdomain != reg->country) || verb) {
4074 const struct regdomain *rd =
4075 lib80211_regdomain_findbysku(getregdata(), reg->regdomain);
4077 LINE_CHECK("regdomain %d", reg->regdomain);
4079 LINE_CHECK("regdomain %s", rd->name);
4081 if (reg->country != 0 || verb) {
4082 const struct country *cc =
4083 lib80211_country_findbycc(getregdata(), reg->country);
4085 LINE_CHECK("country %d", reg->country);
4087 LINE_CHECK("country %s", cc->isoname);
4089 if (reg->location == 'I')
4090 LINE_CHECK("indoor");
4091 else if (reg->location == 'O')
4092 LINE_CHECK("outdoor");
4094 LINE_CHECK("anywhere");
4102 list_regdomain(int s, int channelsalso)
4108 print_regdomain(®domain, 1);
4110 print_channels(s, chaninfo, 1/*allchans*/, 1/*verbose*/);
4112 print_regdomain(®domain, verbose);
4118 struct ieee80211req ireq;
4119 struct ieee80211req_mesh_route routes[128];
4120 struct ieee80211req_mesh_route *rt;
4122 (void) memset(&ireq, 0, sizeof(ireq));
4123 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4124 ireq.i_type = IEEE80211_IOC_MESH_RTCMD;
4125 ireq.i_val = IEEE80211_MESH_RTCMD_LIST;
4126 ireq.i_data = &routes;
4127 ireq.i_len = sizeof(routes);
4128 if (ioctl(s, SIOCG80211, &ireq) < 0)
4129 err(1, "unable to get the Mesh routing table");
4131 printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n"
4140 for (rt = &routes[0]; rt - &routes[0] < ireq.i_len / sizeof(*rt); rt++){
4142 ether_ntoa((const struct ether_addr *)rt->imr_dest));
4143 printf("%s %4u %4u %6u %6u %c%c\n",
4144 ether_ntoa((const struct ether_addr *)rt->imr_nexthop),
4145 rt->imr_nhops, rt->imr_metric, rt->imr_lifetime,
4147 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_DISCOVER) ?
4149 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_VALID) ?
4151 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ?
4153 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_GATE) ?
4159 DECL_CMD_FUNC(set80211list, arg, d)
4161 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
4165 if (iseq(arg, "sta"))
4167 else if (iseq(arg, "scan") || iseq(arg, "ap"))
4169 else if (iseq(arg, "chan") || iseq(arg, "freq"))
4170 list_channels(s, 1);
4171 else if (iseq(arg, "active"))
4172 list_channels(s, 0);
4173 else if (iseq(arg, "keys"))
4175 else if (iseq(arg, "caps"))
4176 list_capabilities(s);
4177 else if (iseq(arg, "wme") || iseq(arg, "wmm"))
4179 else if (iseq(arg, "mac"))
4181 else if (iseq(arg, "txpow"))
4183 else if (iseq(arg, "roam"))
4185 else if (iseq(arg, "txparam") || iseq(arg, "txparm"))
4187 else if (iseq(arg, "regdomain"))
4188 list_regdomain(s, 1);
4189 else if (iseq(arg, "countries"))
4191 else if (iseq(arg, "mesh"))
4194 errx(1, "Don't know how to list %s for %s", arg, name);
4199 static enum ieee80211_opmode
4200 get80211opmode(int s)
4202 struct ifmediareq ifmr;
4204 (void) memset(&ifmr, 0, sizeof(ifmr));
4205 (void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
4207 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) {
4208 if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) {
4209 if (ifmr.ifm_current & IFM_FLAG0)
4210 return IEEE80211_M_AHDEMO;
4212 return IEEE80211_M_IBSS;
4214 if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP)
4215 return IEEE80211_M_HOSTAP;
4216 if (ifmr.ifm_current & IFM_IEEE80211_IBSS)
4217 return IEEE80211_M_IBSS;
4218 if (ifmr.ifm_current & IFM_IEEE80211_MONITOR)
4219 return IEEE80211_M_MONITOR;
4220 if (ifmr.ifm_current & IFM_IEEE80211_MBSS)
4221 return IEEE80211_M_MBSS;
4223 return IEEE80211_M_STA;
4228 printcipher(int s, struct ieee80211req *ireq, int keylenop)
4230 switch (ireq->i_val) {
4231 case IEEE80211_CIPHER_WEP:
4232 ireq->i_type = keylenop;
4233 if (ioctl(s, SIOCG80211, ireq) != -1)
4235 ireq->i_len <= 5 ? "40" :
4236 ireq->i_len <= 13 ? "104" : "128");
4240 case IEEE80211_CIPHER_TKIP:
4243 case IEEE80211_CIPHER_AES_OCB:
4246 case IEEE80211_CIPHER_AES_CCM:
4249 case IEEE80211_CIPHER_CKIP:
4252 case IEEE80211_CIPHER_NONE:
4256 printf("UNKNOWN (0x%x)", ireq->i_val);
4263 printkey(const struct ieee80211req_key *ik)
4265 static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
4266 u_int keylen = ik->ik_keylen;
4269 printcontents = printkeys &&
4270 (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose);
4273 switch (ik->ik_type) {
4274 case IEEE80211_CIPHER_WEP:
4276 LINE_CHECK("wepkey %u:%s", ik->ik_keyix+1,
4277 keylen <= 5 ? "40-bit" :
4278 keylen <= 13 ? "104-bit" : "128-bit");
4280 case IEEE80211_CIPHER_TKIP:
4282 keylen -= 128/8; /* ignore MIC for now */
4283 LINE_CHECK("TKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4285 case IEEE80211_CIPHER_AES_OCB:
4286 LINE_CHECK("AES-OCB %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4288 case IEEE80211_CIPHER_AES_CCM:
4289 LINE_CHECK("AES-CCM %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4291 case IEEE80211_CIPHER_CKIP:
4292 LINE_CHECK("CKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4294 case IEEE80211_CIPHER_NONE:
4295 LINE_CHECK("NULL %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4298 LINE_CHECK("UNKNOWN (0x%x) %u:%u-bit",
4299 ik->ik_type, ik->ik_keyix+1, 8*keylen);
4302 if (printcontents) {
4306 for (i = 0; i < keylen; i++)
4307 printf("%02x", ik->ik_keydata[i]);
4309 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4310 (ik->ik_keyrsc != 0 || verbose))
4311 printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc);
4312 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4313 (ik->ik_keytsc != 0 || verbose))
4314 printf(" tsc %ju", (uintmax_t)ik->ik_keytsc);
4315 if (ik->ik_flags != 0 && verbose) {
4316 const char *sep = " ";
4318 if (ik->ik_flags & IEEE80211_KEY_XMIT)
4319 printf("%stx", sep), sep = "+";
4320 if (ik->ik_flags & IEEE80211_KEY_RECV)
4321 printf("%srx", sep), sep = "+";
4322 if (ik->ik_flags & IEEE80211_KEY_DEFAULT)
4323 printf("%sdef", sep), sep = "+";
4330 printrate(const char *tag, int v, int defrate, int defmcs)
4332 if ((v & IEEE80211_RATE_MCS) == 0) {
4335 LINE_CHECK("%s %d.5", tag, v/2);
4337 LINE_CHECK("%s %d", tag, v/2);
4341 LINE_CHECK("%s %d", tag, v &~ 0x80);
4346 getid(int s, int ix, void *data, size_t len, int *plen, int mesh)
4348 struct ieee80211req ireq;
4350 (void) memset(&ireq, 0, sizeof(ireq));
4351 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4352 ireq.i_type = (!mesh) ? IEEE80211_IOC_SSID : IEEE80211_IOC_MESH_ID;
4356 if (ioctl(s, SIOCG80211, &ireq) < 0)
4363 ieee80211_status(int s)
4365 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
4366 enum ieee80211_opmode opmode = get80211opmode(s);
4367 int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode;
4369 const struct ieee80211_channel *c;
4370 const struct ieee80211_roamparam *rp;
4371 const struct ieee80211_txparam *tp;
4373 if (getid(s, -1, data, sizeof(data), &len, 0) < 0) {
4374 /* If we can't get the SSID, this isn't an 802.11 device. */
4379 * Invalidate cached state so printing status for multiple
4380 * if's doesn't reuse the first interfaces' cached state.
4389 if (opmode == IEEE80211_M_MBSS) {
4391 getid(s, 0, data, sizeof(data), &len, 1);
4392 print_string(data, len);
4394 if (get80211val(s, IEEE80211_IOC_NUMSSIDS, &num) < 0)
4398 for (i = 0; i < num; i++) {
4399 if (getid(s, i, data, sizeof(data), &len, 0) >= 0 && len > 0) {
4400 printf(" %d:", i + 1);
4401 print_string(data, len);
4405 print_string(data, len);
4408 if (c->ic_freq != IEEE80211_CHAN_ANY) {
4410 printf(" channel %d (%u MHz%s)", c->ic_ieee, c->ic_freq,
4411 get_chaninfo(c, 1, buf, sizeof(buf)));
4413 printf(" channel UNDEF");
4415 if (get80211(s, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 &&
4416 (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose))
4417 printf(" bssid %s", ether_ntoa((struct ether_addr *)data));
4419 if (get80211len(s, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) {
4420 printf("\n\tstationname ");
4421 print_string(data, len);
4424 spacer = ' '; /* force first break */
4427 list_regdomain(s, 0);
4430 if (get80211val(s, IEEE80211_IOC_AUTHMODE, &val) != -1) {
4432 case IEEE80211_AUTH_NONE:
4433 LINE_CHECK("authmode NONE");
4435 case IEEE80211_AUTH_OPEN:
4436 LINE_CHECK("authmode OPEN");
4438 case IEEE80211_AUTH_SHARED:
4439 LINE_CHECK("authmode SHARED");
4441 case IEEE80211_AUTH_8021X:
4442 LINE_CHECK("authmode 802.1x");
4444 case IEEE80211_AUTH_WPA:
4445 if (get80211val(s, IEEE80211_IOC_WPA, &wpa) < 0)
4446 wpa = 1; /* default to WPA1 */
4449 LINE_CHECK("authmode WPA2/802.11i");
4452 LINE_CHECK("authmode WPA1+WPA2/802.11i");
4455 LINE_CHECK("authmode WPA");
4459 case IEEE80211_AUTH_AUTO:
4460 LINE_CHECK("authmode AUTO");
4463 LINE_CHECK("authmode UNKNOWN (0x%x)", val);
4468 if (wpa || verbose) {
4469 if (get80211val(s, IEEE80211_IOC_WPS, &val) != -1) {
4475 if (get80211val(s, IEEE80211_IOC_TSN, &val) != -1) {
4481 if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) {
4483 LINE_CHECK("countermeasures");
4485 LINE_CHECK("-countermeasures");
4488 /* XXX not interesting with WPA done in user space */
4489 ireq.i_type = IEEE80211_IOC_KEYMGTALGS;
4490 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4493 ireq.i_type = IEEE80211_IOC_MCASTCIPHER;
4494 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4495 LINE_CHECK("mcastcipher ");
4496 printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN);
4500 ireq.i_type = IEEE80211_IOC_UCASTCIPHER;
4501 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4502 LINE_CHECK("ucastcipher ");
4503 printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN);
4507 ireq.i_type = IEEE80211_IOC_RSNCAPS;
4508 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4509 LINE_CHECK("RSN caps 0x%x", ireq.i_val);
4514 ireq.i_type = IEEE80211_IOC_UCASTCIPHERS;
4515 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4520 if (get80211val(s, IEEE80211_IOC_WEP, &wepmode) != -1 &&
4521 wepmode != IEEE80211_WEP_NOSUP) {
4524 case IEEE80211_WEP_OFF:
4525 LINE_CHECK("privacy OFF");
4527 case IEEE80211_WEP_ON:
4528 LINE_CHECK("privacy ON");
4530 case IEEE80211_WEP_MIXED:
4531 LINE_CHECK("privacy MIXED");
4534 LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode);
4539 * If we get here then we've got WEP support so we need
4540 * to print WEP status.
4543 if (get80211val(s, IEEE80211_IOC_WEPTXKEY, &val) < 0) {
4544 warn("WEP support, but no tx key!");
4548 LINE_CHECK("deftxkey %d", val+1);
4549 else if (wepmode != IEEE80211_WEP_OFF || verbose)
4550 LINE_CHECK("deftxkey UNDEF");
4552 if (get80211val(s, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) {
4553 warn("WEP support, but no NUMWEPKEYS support!");
4557 for (i = 0; i < num; i++) {
4558 struct ieee80211req_key ik;
4560 memset(&ik, 0, sizeof(ik));
4562 if (get80211(s, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) {
4563 warn("WEP support, but can get keys!");
4566 if (ik.ik_keylen != 0) {
4576 if (get80211val(s, IEEE80211_IOC_POWERSAVE, &val) != -1 &&
4577 val != IEEE80211_POWERSAVE_NOSUP ) {
4578 if (val != IEEE80211_POWERSAVE_OFF || verbose) {
4580 case IEEE80211_POWERSAVE_OFF:
4581 LINE_CHECK("powersavemode OFF");
4583 case IEEE80211_POWERSAVE_CAM:
4584 LINE_CHECK("powersavemode CAM");
4586 case IEEE80211_POWERSAVE_PSP:
4587 LINE_CHECK("powersavemode PSP");
4589 case IEEE80211_POWERSAVE_PSP_CAM:
4590 LINE_CHECK("powersavemode PSP-CAM");
4593 if (get80211val(s, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1)
4594 LINE_CHECK("powersavesleep %d", val);
4598 if (get80211val(s, IEEE80211_IOC_TXPOWER, &val) != -1) {
4600 LINE_CHECK("txpower %d.5", val/2);
4602 LINE_CHECK("txpower %d", val/2);
4605 if (get80211val(s, IEEE80211_IOC_TXPOWMAX, &val) != -1)
4606 LINE_CHECK("txpowmax %.1f", val/2.);
4609 if (get80211val(s, IEEE80211_IOC_DOTD, &val) != -1) {
4613 LINE_CHECK("-dotd");
4616 if (get80211val(s, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) {
4617 if (val != IEEE80211_RTS_MAX || verbose)
4618 LINE_CHECK("rtsthreshold %d", val);
4621 if (get80211val(s, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) {
4622 if (val != IEEE80211_FRAG_MAX || verbose)
4623 LINE_CHECK("fragthreshold %d", val);
4625 if (opmode == IEEE80211_M_STA || verbose) {
4626 if (get80211val(s, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) {
4627 if (val != IEEE80211_HWBMISS_MAX || verbose)
4628 LINE_CHECK("bmiss %d", val);
4634 tp = &txparams.params[chan2mode(c)];
4635 printrate("ucastrate", tp->ucastrate,
4636 IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE);
4637 printrate("mcastrate", tp->mcastrate, 2*1,
4638 IEEE80211_RATE_MCS|0);
4639 printrate("mgmtrate", tp->mgmtrate, 2*1,
4640 IEEE80211_RATE_MCS|0);
4641 if (tp->maxretry != 6) /* XXX */
4642 LINE_CHECK("maxretry %d", tp->maxretry);
4648 bgscaninterval = -1;
4649 (void) get80211val(s, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval);
4651 if (get80211val(s, IEEE80211_IOC_SCANVALID, &val) != -1) {
4652 if (val != bgscaninterval || verbose)
4653 LINE_CHECK("scanvalid %u", val);
4657 if (get80211val(s, IEEE80211_IOC_BGSCAN, &bgscan) != -1) {
4659 LINE_CHECK("bgscan");
4661 LINE_CHECK("-bgscan");
4663 if (bgscan || verbose) {
4664 if (bgscaninterval != -1)
4665 LINE_CHECK("bgscanintvl %u", bgscaninterval);
4666 if (get80211val(s, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1)
4667 LINE_CHECK("bgscanidle %u", val);
4670 rp = &roamparams.params[chan2mode(c)];
4672 LINE_CHECK("roam:rssi %u.5", rp->rssi/2);
4674 LINE_CHECK("roam:rssi %u", rp->rssi/2);
4675 LINE_CHECK("roam:rate %u", rp->rate/2);
4683 if (IEEE80211_IS_CHAN_ANYG(c) || verbose) {
4684 if (get80211val(s, IEEE80211_IOC_PUREG, &val) != -1) {
4686 LINE_CHECK("pureg");
4688 LINE_CHECK("-pureg");
4690 if (get80211val(s, IEEE80211_IOC_PROTMODE, &val) != -1) {
4692 case IEEE80211_PROTMODE_OFF:
4693 LINE_CHECK("protmode OFF");
4695 case IEEE80211_PROTMODE_CTS:
4696 LINE_CHECK("protmode CTS");
4698 case IEEE80211_PROTMODE_RTSCTS:
4699 LINE_CHECK("protmode RTSCTS");
4702 LINE_CHECK("protmode UNKNOWN (0x%x)", val);
4708 if (IEEE80211_IS_CHAN_HT(c) || verbose) {
4710 switch (htconf & 3) {
4723 if (get80211val(s, IEEE80211_IOC_HTCOMPAT, &val) != -1) {
4725 LINE_CHECK("-htcompat");
4727 LINE_CHECK("htcompat");
4729 if (get80211val(s, IEEE80211_IOC_AMPDU, &val) != -1) {
4732 LINE_CHECK("-ampdu");
4735 LINE_CHECK("ampdutx -ampdurx");
4738 LINE_CHECK("-ampdutx ampdurx");
4742 LINE_CHECK("ampdu");
4746 if (get80211val(s, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) {
4748 case IEEE80211_HTCAP_MAXRXAMPDU_8K:
4749 LINE_CHECK("ampdulimit 8k");
4751 case IEEE80211_HTCAP_MAXRXAMPDU_16K:
4752 LINE_CHECK("ampdulimit 16k");
4754 case IEEE80211_HTCAP_MAXRXAMPDU_32K:
4755 LINE_CHECK("ampdulimit 32k");
4757 case IEEE80211_HTCAP_MAXRXAMPDU_64K:
4758 LINE_CHECK("ampdulimit 64k");
4762 if (get80211val(s, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) {
4764 case IEEE80211_HTCAP_MPDUDENSITY_NA:
4766 LINE_CHECK("ampdudensity NA");
4768 case IEEE80211_HTCAP_MPDUDENSITY_025:
4769 LINE_CHECK("ampdudensity .25");
4771 case IEEE80211_HTCAP_MPDUDENSITY_05:
4772 LINE_CHECK("ampdudensity .5");
4774 case IEEE80211_HTCAP_MPDUDENSITY_1:
4775 LINE_CHECK("ampdudensity 1");
4777 case IEEE80211_HTCAP_MPDUDENSITY_2:
4778 LINE_CHECK("ampdudensity 2");
4780 case IEEE80211_HTCAP_MPDUDENSITY_4:
4781 LINE_CHECK("ampdudensity 4");
4783 case IEEE80211_HTCAP_MPDUDENSITY_8:
4784 LINE_CHECK("ampdudensity 8");
4786 case IEEE80211_HTCAP_MPDUDENSITY_16:
4787 LINE_CHECK("ampdudensity 16");
4791 if (get80211val(s, IEEE80211_IOC_AMSDU, &val) != -1) {
4794 LINE_CHECK("-amsdu");
4797 LINE_CHECK("amsdutx -amsdurx");
4800 LINE_CHECK("-amsdutx amsdurx");
4804 LINE_CHECK("amsdu");
4808 /* XXX amsdu limit */
4809 if (get80211val(s, IEEE80211_IOC_SHORTGI, &val) != -1) {
4811 LINE_CHECK("shortgi");
4813 LINE_CHECK("-shortgi");
4815 if (get80211val(s, IEEE80211_IOC_HTPROTMODE, &val) != -1) {
4816 if (val == IEEE80211_PROTMODE_OFF)
4817 LINE_CHECK("htprotmode OFF");
4818 else if (val != IEEE80211_PROTMODE_RTSCTS)
4819 LINE_CHECK("htprotmode UNKNOWN (0x%x)", val);
4821 LINE_CHECK("htprotmode RTSCTS");
4823 if (get80211val(s, IEEE80211_IOC_PUREN, &val) != -1) {
4825 LINE_CHECK("puren");
4827 LINE_CHECK("-puren");
4829 if (get80211val(s, IEEE80211_IOC_SMPS, &val) != -1) {
4830 if (val == IEEE80211_HTCAP_SMPS_DYNAMIC)
4831 LINE_CHECK("smpsdyn");
4832 else if (val == IEEE80211_HTCAP_SMPS_ENA)
4835 LINE_CHECK("-smps");
4837 if (get80211val(s, IEEE80211_IOC_RIFS, &val) != -1) {
4841 LINE_CHECK("-rifs");
4843 if (get80211val(s, IEEE80211_IOC_STBC, &val) != -1) {
4846 LINE_CHECK("-stbc");
4849 LINE_CHECK("stbctx -stbcrx");
4852 LINE_CHECK("-stbctx stbcrx");
4862 if (get80211val(s, IEEE80211_IOC_WME, &wme) != -1) {
4870 if (get80211val(s, IEEE80211_IOC_BURST, &val) != -1) {
4872 LINE_CHECK("burst");
4874 LINE_CHECK("-burst");
4877 if (get80211val(s, IEEE80211_IOC_FF, &val) != -1) {
4883 if (get80211val(s, IEEE80211_IOC_TURBOP, &val) != -1) {
4885 LINE_CHECK("dturbo");
4887 LINE_CHECK("-dturbo");
4889 if (get80211val(s, IEEE80211_IOC_DWDS, &val) != -1) {
4893 LINE_CHECK("-dwds");
4896 if (opmode == IEEE80211_M_HOSTAP) {
4897 if (get80211val(s, IEEE80211_IOC_HIDESSID, &val) != -1) {
4899 LINE_CHECK("hidessid");
4901 LINE_CHECK("-hidessid");
4903 if (get80211val(s, IEEE80211_IOC_APBRIDGE, &val) != -1) {
4905 LINE_CHECK("-apbridge");
4907 LINE_CHECK("apbridge");
4909 if (get80211val(s, IEEE80211_IOC_DTIM_PERIOD, &val) != -1)
4910 LINE_CHECK("dtimperiod %u", val);
4912 if (get80211val(s, IEEE80211_IOC_DOTH, &val) != -1) {
4914 LINE_CHECK("-doth");
4918 if (get80211val(s, IEEE80211_IOC_DFS, &val) != -1) {
4924 if (get80211val(s, IEEE80211_IOC_INACTIVITY, &val) != -1) {
4926 LINE_CHECK("-inact");
4928 LINE_CHECK("inact");
4931 if (get80211val(s, IEEE80211_IOC_ROAMING, &val) != -1) {
4932 if (val != IEEE80211_ROAMING_AUTO || verbose) {
4934 case IEEE80211_ROAMING_DEVICE:
4935 LINE_CHECK("roaming DEVICE");
4937 case IEEE80211_ROAMING_AUTO:
4938 LINE_CHECK("roaming AUTO");
4940 case IEEE80211_ROAMING_MANUAL:
4941 LINE_CHECK("roaming MANUAL");
4944 LINE_CHECK("roaming UNKNOWN (0x%x)",
4952 if (opmode == IEEE80211_M_AHDEMO) {
4953 if (get80211val(s, IEEE80211_IOC_TDMA_SLOT, &val) != -1)
4954 LINE_CHECK("tdmaslot %u", val);
4955 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1)
4956 LINE_CHECK("tdmaslotcnt %u", val);
4957 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1)
4958 LINE_CHECK("tdmaslotlen %u", val);
4959 if (get80211val(s, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1)
4960 LINE_CHECK("tdmabintval %u", val);
4961 } else if (get80211val(s, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) {
4962 /* XXX default define not visible */
4963 if (val != 100 || verbose)
4964 LINE_CHECK("bintval %u", val);
4967 if (wme && verbose) {
4972 if (opmode == IEEE80211_M_MBSS) {
4973 if (get80211val(s, IEEE80211_IOC_MESH_TTL, &val) != -1) {
4974 LINE_CHECK("meshttl %u", val);
4976 if (get80211val(s, IEEE80211_IOC_MESH_AP, &val) != -1) {
4978 LINE_CHECK("meshpeering");
4980 LINE_CHECK("-meshpeering");
4982 if (get80211val(s, IEEE80211_IOC_MESH_FWRD, &val) != -1) {
4984 LINE_CHECK("meshforward");
4986 LINE_CHECK("-meshforward");
4988 if (get80211val(s, IEEE80211_IOC_MESH_GATE, &val) != -1) {
4990 LINE_CHECK("meshgate");
4992 LINE_CHECK("-meshgate");
4994 if (get80211len(s, IEEE80211_IOC_MESH_PR_METRIC, data, 12,
4997 LINE_CHECK("meshmetric %s", data);
4999 if (get80211len(s, IEEE80211_IOC_MESH_PR_PATH, data, 12,
5002 LINE_CHECK("meshpath %s", data);
5004 if (get80211val(s, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) {
5006 case IEEE80211_HWMP_ROOTMODE_DISABLED:
5007 LINE_CHECK("hwmprootmode DISABLED");
5009 case IEEE80211_HWMP_ROOTMODE_NORMAL:
5010 LINE_CHECK("hwmprootmode NORMAL");
5012 case IEEE80211_HWMP_ROOTMODE_PROACTIVE:
5013 LINE_CHECK("hwmprootmode PROACTIVE");
5015 case IEEE80211_HWMP_ROOTMODE_RANN:
5016 LINE_CHECK("hwmprootmode RANN");
5019 LINE_CHECK("hwmprootmode UNKNOWN(%d)", val);
5023 if (get80211val(s, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) {
5024 LINE_CHECK("hwmpmaxhops %u", val);
5032 get80211(int s, int type, void *data, int len)
5035 return (lib80211_get80211(s, name, type, data, len));
5039 get80211len(int s, int type, void *data, int len, int *plen)
5042 return (lib80211_get80211len(s, name, type, data, len, plen));
5046 get80211val(int s, int type, int *val)
5049 return (lib80211_get80211val(s, name, type, val));
5053 set80211(int s, int type, int val, int len, void *data)
5057 ret = lib80211_set80211(s, name, type, val, len, data);
5059 err(1, "SIOCS80211");
5063 get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
5071 hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x');
5077 if (sep != NULL && strchr(sep, *val) != NULL) {
5082 if (!isxdigit((u_char)val[0])) {
5083 warnx("bad hexadecimal digits");
5086 if (!isxdigit((u_char)val[1])) {
5087 warnx("odd count hexadecimal digits");
5091 if (p >= buf + len) {
5093 warnx("hexadecimal digits too long");
5095 warnx("string too long");
5099 #define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
5100 *p++ = (tohex((u_char)val[0]) << 4) |
5101 tohex((u_char)val[1]);
5108 /* The string "-" is treated as the empty string. */
5109 if (!hexstr && len == 1 && buf[0] == '-') {
5111 memset(buf, 0, *lenp);
5112 } else if (len < *lenp)
5113 memset(p, 0, *lenp - len);
5119 print_string(const u_int8_t *buf, int len)
5126 for (; i < len; i++) {
5127 if (!isprint(buf[i]) && buf[i] != '\0')
5129 if (isspace(buf[i]))
5133 if (hasspc || len == 0 || buf[0] == '\0')
5134 printf("\"%.*s\"", len, buf);
5136 printf("%.*s", len, buf);
5139 for (i = 0; i < len; i++)
5140 printf("%02x", buf[i]);
5145 setdefregdomain(int s)
5147 struct regdata *rdp = getregdata();
5148 const struct regdomain *rd;
5150 /* Check if regdomain/country was already set by a previous call. */
5151 /* XXX is it possible? */
5152 if (regdomain.regdomain != 0 ||
5153 regdomain.country != CTRY_DEFAULT)
5158 /* Check if it was already set by the driver. */
5159 if (regdomain.regdomain != 0 ||
5160 regdomain.country != CTRY_DEFAULT)
5163 /* Set FCC/US as default. */
5164 rd = lib80211_regdomain_findbysku(rdp, SKU_FCC);
5166 errx(1, "FCC regdomain was not found");
5168 regdomain.regdomain = rd->sku;
5172 /* Send changes to net80211. */
5173 setregdomain_cb(s, ®domain);
5175 /* Cleanup (so it can be overriden by subsequent parameters). */
5176 regdomain.regdomain = 0;
5177 regdomain.country = CTRY_DEFAULT;
5178 regdomain.isocc[0] = 0;
5179 regdomain.isocc[1] = 0;
5183 * Virtual AP cloning support.
5185 static struct ieee80211_clone_params params = {
5186 .icp_opmode = IEEE80211_M_STA, /* default to station mode */
5190 wlan_create(int s, struct ifreq *ifr)
5192 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
5193 char orig_name[IFNAMSIZ];
5195 if (params.icp_parent[0] == '\0')
5196 errx(1, "must specify a parent device (wlandev) when creating "
5198 if (params.icp_opmode == IEEE80211_M_WDS &&
5199 memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0)
5200 errx(1, "no bssid specified for WDS (use wlanbssid)");
5201 ifr->ifr_data = (caddr_t) ¶ms;
5202 if (ioctl(s, SIOCIFCREATE2, ifr) < 0)
5203 err(1, "SIOCIFCREATE2");
5205 /* XXX preserve original name for ifclonecreate(). */
5206 strlcpy(orig_name, name, sizeof(orig_name));
5207 strlcpy(name, ifr->ifr_name, sizeof(name));
5211 strlcpy(name, orig_name, sizeof(name));
5215 DECL_CMD_FUNC(set80211clone_wlandev, arg, d)
5217 strlcpy(params.icp_parent, arg, IFNAMSIZ);
5221 DECL_CMD_FUNC(set80211clone_wlanbssid, arg, d)
5223 const struct ether_addr *ea;
5225 ea = ether_aton(arg);
5227 errx(1, "%s: cannot parse bssid", arg);
5228 memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN);
5232 DECL_CMD_FUNC(set80211clone_wlanaddr, arg, d)
5234 const struct ether_addr *ea;
5236 ea = ether_aton(arg);
5238 errx(1, "%s: cannot parse address", arg);
5239 memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN);
5240 params.icp_flags |= IEEE80211_CLONE_MACADDR;
5244 DECL_CMD_FUNC(set80211clone_wlanmode, arg, d)
5246 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
5247 if (iseq(arg, "sta"))
5248 params.icp_opmode = IEEE80211_M_STA;
5249 else if (iseq(arg, "ahdemo") || iseq(arg, "adhoc-demo"))
5250 params.icp_opmode = IEEE80211_M_AHDEMO;
5251 else if (iseq(arg, "ibss") || iseq(arg, "adhoc"))
5252 params.icp_opmode = IEEE80211_M_IBSS;
5253 else if (iseq(arg, "ap") || iseq(arg, "host"))
5254 params.icp_opmode = IEEE80211_M_HOSTAP;
5255 else if (iseq(arg, "wds"))
5256 params.icp_opmode = IEEE80211_M_WDS;
5257 else if (iseq(arg, "monitor"))
5258 params.icp_opmode = IEEE80211_M_MONITOR;
5259 else if (iseq(arg, "tdma")) {
5260 params.icp_opmode = IEEE80211_M_AHDEMO;
5261 params.icp_flags |= IEEE80211_CLONE_TDMA;
5262 } else if (iseq(arg, "mesh") || iseq(arg, "mp")) /* mesh point */
5263 params.icp_opmode = IEEE80211_M_MBSS;
5265 errx(1, "Don't know to create %s for %s", arg, name);
5270 set80211clone_beacons(const char *val, int d, int s, const struct afswtch *rafp)
5272 /* NB: inverted sense */
5274 params.icp_flags &= ~IEEE80211_CLONE_NOBEACONS;
5276 params.icp_flags |= IEEE80211_CLONE_NOBEACONS;
5280 set80211clone_bssid(const char *val, int d, int s, const struct afswtch *rafp)
5283 params.icp_flags |= IEEE80211_CLONE_BSSID;
5285 params.icp_flags &= ~IEEE80211_CLONE_BSSID;
5289 set80211clone_wdslegacy(const char *val, int d, int s, const struct afswtch *rafp)
5292 params.icp_flags |= IEEE80211_CLONE_WDSLEGACY;
5294 params.icp_flags &= ~IEEE80211_CLONE_WDSLEGACY;
5297 static struct cmd ieee80211_cmds[] = {
5298 DEF_CMD_ARG("ssid", set80211ssid),
5299 DEF_CMD_ARG("nwid", set80211ssid),
5300 DEF_CMD_ARG("meshid", set80211meshid),
5301 DEF_CMD_ARG("stationname", set80211stationname),
5302 DEF_CMD_ARG("station", set80211stationname), /* BSD/OS */
5303 DEF_CMD_ARG("channel", set80211channel),
5304 DEF_CMD_ARG("authmode", set80211authmode),
5305 DEF_CMD_ARG("powersavemode", set80211powersavemode),
5306 DEF_CMD("powersave", 1, set80211powersave),
5307 DEF_CMD("-powersave", 0, set80211powersave),
5308 DEF_CMD_ARG("powersavesleep", set80211powersavesleep),
5309 DEF_CMD_ARG("wepmode", set80211wepmode),
5310 DEF_CMD("wep", 1, set80211wep),
5311 DEF_CMD("-wep", 0, set80211wep),
5312 DEF_CMD_ARG("deftxkey", set80211weptxkey),
5313 DEF_CMD_ARG("weptxkey", set80211weptxkey),
5314 DEF_CMD_ARG("wepkey", set80211wepkey),
5315 DEF_CMD_ARG("nwkey", set80211nwkey), /* NetBSD */
5316 DEF_CMD("-nwkey", 0, set80211wep), /* NetBSD */
5317 DEF_CMD_ARG("rtsthreshold", set80211rtsthreshold),
5318 DEF_CMD_ARG("protmode", set80211protmode),
5319 DEF_CMD_ARG("txpower", set80211txpower),
5320 DEF_CMD_ARG("roaming", set80211roaming),
5321 DEF_CMD("wme", 1, set80211wme),
5322 DEF_CMD("-wme", 0, set80211wme),
5323 DEF_CMD("wmm", 1, set80211wme),
5324 DEF_CMD("-wmm", 0, set80211wme),
5325 DEF_CMD("hidessid", 1, set80211hidessid),
5326 DEF_CMD("-hidessid", 0, set80211hidessid),
5327 DEF_CMD("apbridge", 1, set80211apbridge),
5328 DEF_CMD("-apbridge", 0, set80211apbridge),
5329 DEF_CMD_ARG("chanlist", set80211chanlist),
5330 DEF_CMD_ARG("bssid", set80211bssid),
5331 DEF_CMD_ARG("ap", set80211bssid),
5332 DEF_CMD("scan", 0, set80211scan),
5333 DEF_CMD_ARG("list", set80211list),
5334 DEF_CMD_ARG2("cwmin", set80211cwmin),
5335 DEF_CMD_ARG2("cwmax", set80211cwmax),
5336 DEF_CMD_ARG2("aifs", set80211aifs),
5337 DEF_CMD_ARG2("txoplimit", set80211txoplimit),
5338 DEF_CMD_ARG("acm", set80211acm),
5339 DEF_CMD_ARG("-acm", set80211noacm),
5340 DEF_CMD_ARG("ack", set80211ackpolicy),
5341 DEF_CMD_ARG("-ack", set80211noackpolicy),
5342 DEF_CMD_ARG2("bss:cwmin", set80211bsscwmin),
5343 DEF_CMD_ARG2("bss:cwmax", set80211bsscwmax),
5344 DEF_CMD_ARG2("bss:aifs", set80211bssaifs),
5345 DEF_CMD_ARG2("bss:txoplimit", set80211bsstxoplimit),
5346 DEF_CMD_ARG("dtimperiod", set80211dtimperiod),
5347 DEF_CMD_ARG("bintval", set80211bintval),
5348 DEF_CMD("mac:open", IEEE80211_MACCMD_POLICY_OPEN, set80211maccmd),
5349 DEF_CMD("mac:allow", IEEE80211_MACCMD_POLICY_ALLOW, set80211maccmd),
5350 DEF_CMD("mac:deny", IEEE80211_MACCMD_POLICY_DENY, set80211maccmd),
5351 DEF_CMD("mac:radius", IEEE80211_MACCMD_POLICY_RADIUS, set80211maccmd),
5352 DEF_CMD("mac:flush", IEEE80211_MACCMD_FLUSH, set80211maccmd),
5353 DEF_CMD("mac:detach", IEEE80211_MACCMD_DETACH, set80211maccmd),
5354 DEF_CMD_ARG("mac:add", set80211addmac),
5355 DEF_CMD_ARG("mac:del", set80211delmac),
5356 DEF_CMD_ARG("mac:kick", set80211kickmac),
5357 DEF_CMD("pureg", 1, set80211pureg),
5358 DEF_CMD("-pureg", 0, set80211pureg),
5359 DEF_CMD("ff", 1, set80211fastframes),
5360 DEF_CMD("-ff", 0, set80211fastframes),
5361 DEF_CMD("dturbo", 1, set80211dturbo),
5362 DEF_CMD("-dturbo", 0, set80211dturbo),
5363 DEF_CMD("bgscan", 1, set80211bgscan),
5364 DEF_CMD("-bgscan", 0, set80211bgscan),
5365 DEF_CMD_ARG("bgscanidle", set80211bgscanidle),
5366 DEF_CMD_ARG("bgscanintvl", set80211bgscanintvl),
5367 DEF_CMD_ARG("scanvalid", set80211scanvalid),
5368 DEF_CMD("quiet", 1, set80211quiet),
5369 DEF_CMD("-quiet", 0, set80211quiet),
5370 DEF_CMD_ARG("quiet_count", set80211quietcount),
5371 DEF_CMD_ARG("quiet_period", set80211quietperiod),
5372 DEF_CMD_ARG("quiet_dur", set80211quietduration),
5373 DEF_CMD_ARG("quiet_offset", set80211quietoffset),
5374 DEF_CMD_ARG("roam:rssi", set80211roamrssi),
5375 DEF_CMD_ARG("roam:rate", set80211roamrate),
5376 DEF_CMD_ARG("mcastrate", set80211mcastrate),
5377 DEF_CMD_ARG("ucastrate", set80211ucastrate),
5378 DEF_CMD_ARG("mgtrate", set80211mgtrate),
5379 DEF_CMD_ARG("mgmtrate", set80211mgtrate),
5380 DEF_CMD_ARG("maxretry", set80211maxretry),
5381 DEF_CMD_ARG("fragthreshold", set80211fragthreshold),
5382 DEF_CMD("burst", 1, set80211burst),
5383 DEF_CMD("-burst", 0, set80211burst),
5384 DEF_CMD_ARG("bmiss", set80211bmissthreshold),
5385 DEF_CMD_ARG("bmissthreshold", set80211bmissthreshold),
5386 DEF_CMD("shortgi", 1, set80211shortgi),
5387 DEF_CMD("-shortgi", 0, set80211shortgi),
5388 DEF_CMD("ampdurx", 2, set80211ampdu),
5389 DEF_CMD("-ampdurx", -2, set80211ampdu),
5390 DEF_CMD("ampdutx", 1, set80211ampdu),
5391 DEF_CMD("-ampdutx", -1, set80211ampdu),
5392 DEF_CMD("ampdu", 3, set80211ampdu), /* NB: tx+rx */
5393 DEF_CMD("-ampdu", -3, set80211ampdu),
5394 DEF_CMD_ARG("ampdulimit", set80211ampdulimit),
5395 DEF_CMD_ARG("ampdudensity", set80211ampdudensity),
5396 DEF_CMD("amsdurx", 2, set80211amsdu),
5397 DEF_CMD("-amsdurx", -2, set80211amsdu),
5398 DEF_CMD("amsdutx", 1, set80211amsdu),
5399 DEF_CMD("-amsdutx", -1, set80211amsdu),
5400 DEF_CMD("amsdu", 3, set80211amsdu), /* NB: tx+rx */
5401 DEF_CMD("-amsdu", -3, set80211amsdu),
5402 DEF_CMD_ARG("amsdulimit", set80211amsdulimit),
5403 DEF_CMD("stbcrx", 2, set80211stbc),
5404 DEF_CMD("-stbcrx", -2, set80211stbc),
5405 DEF_CMD("stbctx", 1, set80211stbc),
5406 DEF_CMD("-stbctx", -1, set80211stbc),
5407 DEF_CMD("stbc", 3, set80211stbc), /* NB: tx+rx */
5408 DEF_CMD("-ampdu", -3, set80211stbc),
5409 DEF_CMD("puren", 1, set80211puren),
5410 DEF_CMD("-puren", 0, set80211puren),
5411 DEF_CMD("doth", 1, set80211doth),
5412 DEF_CMD("-doth", 0, set80211doth),
5413 DEF_CMD("dfs", 1, set80211dfs),
5414 DEF_CMD("-dfs", 0, set80211dfs),
5415 DEF_CMD("htcompat", 1, set80211htcompat),
5416 DEF_CMD("-htcompat", 0, set80211htcompat),
5417 DEF_CMD("dwds", 1, set80211dwds),
5418 DEF_CMD("-dwds", 0, set80211dwds),
5419 DEF_CMD("inact", 1, set80211inact),
5420 DEF_CMD("-inact", 0, set80211inact),
5421 DEF_CMD("tsn", 1, set80211tsn),
5422 DEF_CMD("-tsn", 0, set80211tsn),
5423 DEF_CMD_ARG("regdomain", set80211regdomain),
5424 DEF_CMD_ARG("country", set80211country),
5425 DEF_CMD("indoor", 'I', set80211location),
5426 DEF_CMD("-indoor", 'O', set80211location),
5427 DEF_CMD("outdoor", 'O', set80211location),
5428 DEF_CMD("-outdoor", 'I', set80211location),
5429 DEF_CMD("anywhere", ' ', set80211location),
5430 DEF_CMD("ecm", 1, set80211ecm),
5431 DEF_CMD("-ecm", 0, set80211ecm),
5432 DEF_CMD("dotd", 1, set80211dotd),
5433 DEF_CMD("-dotd", 0, set80211dotd),
5434 DEF_CMD_ARG("htprotmode", set80211htprotmode),
5435 DEF_CMD("ht20", 1, set80211htconf),
5436 DEF_CMD("-ht20", 0, set80211htconf),
5437 DEF_CMD("ht40", 3, set80211htconf), /* NB: 20+40 */
5438 DEF_CMD("-ht40", 0, set80211htconf),
5439 DEF_CMD("ht", 3, set80211htconf), /* NB: 20+40 */
5440 DEF_CMD("-ht", 0, set80211htconf),
5441 DEF_CMD("rifs", 1, set80211rifs),
5442 DEF_CMD("-rifs", 0, set80211rifs),
5443 DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA, set80211smps),
5444 DEF_CMD("smpsdyn", IEEE80211_HTCAP_SMPS_DYNAMIC, set80211smps),
5445 DEF_CMD("-smps", IEEE80211_HTCAP_SMPS_OFF, set80211smps),
5446 /* XXX for testing */
5447 DEF_CMD_ARG("chanswitch", set80211chanswitch),
5449 DEF_CMD_ARG("tdmaslot", set80211tdmaslot),
5450 DEF_CMD_ARG("tdmaslotcnt", set80211tdmaslotcnt),
5451 DEF_CMD_ARG("tdmaslotlen", set80211tdmaslotlen),
5452 DEF_CMD_ARG("tdmabintval", set80211tdmabintval),
5454 DEF_CMD_ARG("meshttl", set80211meshttl),
5455 DEF_CMD("meshforward", 1, set80211meshforward),
5456 DEF_CMD("-meshforward", 0, set80211meshforward),
5457 DEF_CMD("meshgate", 1, set80211meshgate),
5458 DEF_CMD("-meshgate", 0, set80211meshgate),
5459 DEF_CMD("meshpeering", 1, set80211meshpeering),
5460 DEF_CMD("-meshpeering", 0, set80211meshpeering),
5461 DEF_CMD_ARG("meshmetric", set80211meshmetric),
5462 DEF_CMD_ARG("meshpath", set80211meshpath),
5463 DEF_CMD("meshrt:flush", IEEE80211_MESH_RTCMD_FLUSH, set80211meshrtcmd),
5464 DEF_CMD_ARG("meshrt:add", set80211addmeshrt),
5465 DEF_CMD_ARG("meshrt:del", set80211delmeshrt),
5466 DEF_CMD_ARG("hwmprootmode", set80211hwmprootmode),
5467 DEF_CMD_ARG("hwmpmaxhops", set80211hwmpmaxhops),
5469 /* vap cloning support */
5470 DEF_CLONE_CMD_ARG("wlanaddr", set80211clone_wlanaddr),
5471 DEF_CLONE_CMD_ARG("wlanbssid", set80211clone_wlanbssid),
5472 DEF_CLONE_CMD_ARG("wlandev", set80211clone_wlandev),
5473 DEF_CLONE_CMD_ARG("wlanmode", set80211clone_wlanmode),
5474 DEF_CLONE_CMD("beacons", 1, set80211clone_beacons),
5475 DEF_CLONE_CMD("-beacons", 0, set80211clone_beacons),
5476 DEF_CLONE_CMD("bssid", 1, set80211clone_bssid),
5477 DEF_CLONE_CMD("-bssid", 0, set80211clone_bssid),
5478 DEF_CLONE_CMD("wdslegacy", 1, set80211clone_wdslegacy),
5479 DEF_CLONE_CMD("-wdslegacy", 0, set80211clone_wdslegacy),
5481 static struct afswtch af_ieee80211 = {
5482 .af_name = "af_ieee80211",
5484 .af_other_status = ieee80211_status,
5487 static __constructor void
5488 ieee80211_ctor(void)
5492 for (i = 0; i < nitems(ieee80211_cmds); i++)
5493 cmd_register(&ieee80211_cmds[i]);
5494 af_register(&af_ieee80211);
5495 clone_setdefcallback("wlan", wlan_create);