2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright 2001 The Aerospace Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of The Aerospace Corporation may not be used to endorse or
15 * promote products derived from this software.
17 * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
34 * All rights reserved.
36 * This code is derived from software contributed to The NetBSD Foundation
37 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
38 * NASA Ames Research Center.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
49 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
50 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
51 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
53 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
54 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
55 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
56 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
57 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
58 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 * POSSIBILITY OF SUCH DAMAGE.
62 #include <sys/param.h>
63 #include <sys/ioctl.h>
64 #include <sys/socket.h>
65 #include <sys/sysctl.h>
68 #include <net/ethernet.h>
70 #include <net/if_dl.h>
71 #include <net/if_types.h>
72 #include <net/if_media.h>
73 #include <net/route.h>
75 #include <net80211/ieee80211_ioctl.h>
76 #include <net80211/ieee80211_freebsd.h>
77 #include <net80211/ieee80211_superg.h>
78 #include <net80211/ieee80211_tdma.h>
79 #include <net80211/ieee80211_mesh.h>
92 #include <stddef.h> /* NB: for offsetof */
96 #include <lib80211/lib80211_regdomain.h>
97 #include <lib80211/lib80211_ioctl.h>
99 #ifndef IEEE80211_FIXED_RATE_NONE
100 #define IEEE80211_FIXED_RATE_NONE 0xff
103 /* XXX need these publicly defined or similar */
104 #ifndef IEEE80211_NODE_AUTH
105 #define IEEE80211_NODE_AUTH 0x000001 /* authorized for data */
106 #define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */
107 #define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */
108 #define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */
109 #define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */
110 #define IEEE80211_NODE_HT 0x000040 /* HT enabled */
111 #define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */
112 #define IEEE80211_NODE_WPS 0x000100 /* WPS association */
113 #define IEEE80211_NODE_TSN 0x000200 /* TSN association */
114 #define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */
115 #define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */
116 #define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */
117 #define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */
118 #define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */
119 #define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */
120 #define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */
121 #define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */
122 #define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */
123 #define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */
126 #define MAXCHAN 1536 /* max 1.5K channels */
132 static void LINE_INIT(char c);
133 static void LINE_BREAK(void);
134 static void LINE_CHECK(const char *fmt, ...);
136 static const char *modename[IEEE80211_MODE_MAX] = {
137 [IEEE80211_MODE_AUTO] = "auto",
138 [IEEE80211_MODE_11A] = "11a",
139 [IEEE80211_MODE_11B] = "11b",
140 [IEEE80211_MODE_11G] = "11g",
141 [IEEE80211_MODE_FH] = "fh",
142 [IEEE80211_MODE_TURBO_A] = "turboA",
143 [IEEE80211_MODE_TURBO_G] = "turboG",
144 [IEEE80211_MODE_STURBO_A] = "sturbo",
145 [IEEE80211_MODE_11NA] = "11na",
146 [IEEE80211_MODE_11NG] = "11ng",
147 [IEEE80211_MODE_HALF] = "half",
148 [IEEE80211_MODE_QUARTER] = "quarter"
151 static void set80211(int s, int type, int val, int len, void *data);
152 static int get80211(int s, int type, void *data, int len);
153 static int get80211len(int s, int type, void *data, int len, int *plen);
154 static int get80211val(int s, int type, int *val);
155 static const char *get_string(const char *val, const char *sep,
156 u_int8_t *buf, int *lenp);
157 static void print_string(const u_int8_t *buf, int len);
158 static void print_regdomain(const struct ieee80211_regdomain *, int);
159 static void print_channels(int, const struct ieee80211req_chaninfo *,
160 int allchans, int verbose);
161 static void regdomain_makechannels(struct ieee80211_regdomain_req *,
162 const struct ieee80211_devcaps_req *);
163 static const char *mesh_linkstate_string(uint8_t state);
165 static struct ieee80211req_chaninfo *chaninfo;
166 static struct ieee80211_regdomain regdomain;
167 static int gotregdomain = 0;
168 static struct ieee80211_roamparams_req roamparams;
169 static int gotroam = 0;
170 static struct ieee80211_txparams_req txparams;
171 static int gottxparams = 0;
172 static struct ieee80211_channel curchan;
173 static int gotcurchan = 0;
174 static struct ifmediareq *ifmr;
175 static int htconf = 0;
176 static int gothtconf = 0;
183 if (get80211val(s, IEEE80211_IOC_HTCONF, &htconf) < 0)
184 warn("unable to get HT configuration information");
189 * Collect channel info from the kernel. We use this (mostly)
190 * to handle mapping between frequency and IEEE channel number.
195 if (chaninfo != NULL)
197 chaninfo = malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN));
198 if (chaninfo == NULL)
199 errx(1, "no space for channel list");
200 if (get80211(s, IEEE80211_IOC_CHANINFO, chaninfo,
201 IEEE80211_CHANINFO_SIZE(MAXCHAN)) < 0)
202 err(1, "unable to get channel information");
203 ifmr = ifmedia_getstate(s);
207 static struct regdata *
210 static struct regdata *rdp = NULL;
212 rdp = lib80211_alloc_regdata();
214 errx(-1, "missing or corrupted regdomain database");
220 * Given the channel at index i with attributes from,
221 * check if there is a channel with attributes to in
222 * the channel table. With suitable attributes this
223 * allows the caller to look for promotion; e.g. from
227 canpromote(int i, int from, int to)
229 const struct ieee80211_channel *fc = &chaninfo->ic_chans[i];
232 if ((fc->ic_flags & from) != from)
234 /* NB: quick check exploiting ordering of chans w/ same frequency */
235 if (i+1 < chaninfo->ic_nchans &&
236 chaninfo->ic_chans[i+1].ic_freq == fc->ic_freq &&
237 (chaninfo->ic_chans[i+1].ic_flags & to) == to)
239 /* brute force search in case channel list is not ordered */
240 for (j = 0; j < chaninfo->ic_nchans; j++) {
241 const struct ieee80211_channel *tc = &chaninfo->ic_chans[j];
243 tc->ic_freq == fc->ic_freq && (tc->ic_flags & to) == to)
250 * Handle channel promotion. When a channel is specified with
251 * only a frequency we want to promote it to the ``best'' channel
252 * available. The channel list has separate entries for 11b, 11g,
253 * 11a, and 11n[ga] channels so specifying a frequency w/o any
254 * attributes requires we upgrade, e.g. from 11b -> 11g. This
255 * gets complicated when the channel is specified on the same
256 * command line with a media request that constrains the available
257 * channe list (e.g. mode 11a); we want to honor that to avoid
258 * confusing behaviour.
264 * Query the current mode of the interface in case it's
265 * constrained (e.g. to 11a). We must do this carefully
266 * as there may be a pending ifmedia request in which case
267 * asking the kernel will give us the wrong answer. This
268 * is an unfortunate side-effect of the way ifconfig is
269 * structure for modularity (yech).
271 * NB: ifmr is actually setup in getchaninfo (above); we
272 * assume it's called coincident with to this call so
273 * we have a ``current setting''; otherwise we must pass
274 * the socket descriptor down to here so we can make
275 * the ifmedia_getstate call ourselves.
277 int chanmode = ifmr != NULL ? IFM_MODE(ifmr->ifm_current) : IFM_AUTO;
279 /* when ambiguous promote to ``best'' */
280 /* NB: we abitrarily pick HT40+ over HT40- */
281 if (chanmode != IFM_IEEE80211_11B)
282 i = canpromote(i, IEEE80211_CHAN_B, IEEE80211_CHAN_G);
283 if (chanmode != IFM_IEEE80211_11G && (htconf & 1)) {
284 i = canpromote(i, IEEE80211_CHAN_G,
285 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20);
287 i = canpromote(i, IEEE80211_CHAN_G,
288 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D);
289 i = canpromote(i, IEEE80211_CHAN_G,
290 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U);
293 if (chanmode != IFM_IEEE80211_11A && (htconf & 1)) {
294 i = canpromote(i, IEEE80211_CHAN_A,
295 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20);
297 i = canpromote(i, IEEE80211_CHAN_A,
298 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D);
299 i = canpromote(i, IEEE80211_CHAN_A,
300 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U);
307 mapfreq(struct ieee80211_channel *chan, int freq, int flags)
311 for (i = 0; i < chaninfo->ic_nchans; i++) {
312 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
314 if (c->ic_freq == freq && (c->ic_flags & flags) == flags) {
316 /* when ambiguous promote to ``best'' */
317 c = &chaninfo->ic_chans[promote(i)];
323 errx(1, "unknown/undefined frequency %u/0x%x", freq, flags);
327 mapchan(struct ieee80211_channel *chan, int ieee, int flags)
331 for (i = 0; i < chaninfo->ic_nchans; i++) {
332 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
334 if (c->ic_ieee == ieee && (c->ic_flags & flags) == flags) {
336 /* when ambiguous promote to ``best'' */
337 c = &chaninfo->ic_chans[promote(i)];
343 errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags);
346 static const struct ieee80211_channel *
351 if (get80211(s, IEEE80211_IOC_CURCHAN, &curchan, sizeof(curchan)) < 0) {
353 /* fall back to legacy ioctl */
354 if (get80211val(s, IEEE80211_IOC_CHANNEL, &val) < 0)
355 err(-1, "cannot figure out current channel");
357 mapchan(&curchan, val, 0);
363 static enum ieee80211_phymode
364 chan2mode(const struct ieee80211_channel *c)
366 if (IEEE80211_IS_CHAN_HTA(c))
367 return IEEE80211_MODE_11NA;
368 if (IEEE80211_IS_CHAN_HTG(c))
369 return IEEE80211_MODE_11NG;
370 if (IEEE80211_IS_CHAN_108A(c))
371 return IEEE80211_MODE_TURBO_A;
372 if (IEEE80211_IS_CHAN_108G(c))
373 return IEEE80211_MODE_TURBO_G;
374 if (IEEE80211_IS_CHAN_ST(c))
375 return IEEE80211_MODE_STURBO_A;
376 if (IEEE80211_IS_CHAN_FHSS(c))
377 return IEEE80211_MODE_FH;
378 if (IEEE80211_IS_CHAN_HALF(c))
379 return IEEE80211_MODE_HALF;
380 if (IEEE80211_IS_CHAN_QUARTER(c))
381 return IEEE80211_MODE_QUARTER;
382 if (IEEE80211_IS_CHAN_A(c))
383 return IEEE80211_MODE_11A;
384 if (IEEE80211_IS_CHAN_ANYG(c))
385 return IEEE80211_MODE_11G;
386 if (IEEE80211_IS_CHAN_B(c))
387 return IEEE80211_MODE_11B;
388 return IEEE80211_MODE_AUTO;
396 if (get80211(s, IEEE80211_IOC_ROAM,
397 &roamparams, sizeof(roamparams)) < 0)
398 err(1, "unable to get roaming parameters");
403 setroam_cb(int s, void *arg)
405 struct ieee80211_roamparams_req *roam = arg;
406 set80211(s, IEEE80211_IOC_ROAM, 0, sizeof(*roam), roam);
414 if (get80211(s, IEEE80211_IOC_TXPARAMS,
415 &txparams, sizeof(txparams)) < 0)
416 err(1, "unable to get transmit parameters");
421 settxparams_cb(int s, void *arg)
423 struct ieee80211_txparams_req *txp = arg;
424 set80211(s, IEEE80211_IOC_TXPARAMS, 0, sizeof(*txp), txp);
432 if (get80211(s, IEEE80211_IOC_REGDOMAIN,
433 ®domain, sizeof(regdomain)) < 0)
434 err(1, "unable to get regulatory domain info");
439 getdevcaps(int s, struct ieee80211_devcaps_req *dc)
441 if (get80211(s, IEEE80211_IOC_DEVCAPS, dc,
442 IEEE80211_DEVCAPS_SPACE(dc)) < 0)
443 err(1, "unable to get device capabilities");
447 setregdomain_cb(int s, void *arg)
449 struct ieee80211_regdomain_req *req;
450 struct ieee80211_regdomain *rd = arg;
451 struct ieee80211_devcaps_req *dc;
452 struct regdata *rdp = getregdata();
454 if (rd->country != NO_COUNTRY) {
455 const struct country *cc;
457 * Check current country seting to make sure it's
458 * compatible with the new regdomain. If not, then
459 * override it with any default country for this
460 * SKU. If we cannot arrange a match, then abort.
462 cc = lib80211_country_findbycc(rdp, rd->country);
464 errx(1, "unknown ISO country code %d", rd->country);
465 if (cc->rd->sku != rd->regdomain) {
466 const struct regdomain *rp;
468 * Check if country is incompatible with regdomain.
469 * To enable multiple regdomains for a country code
470 * we permit a mismatch between the regdomain and
471 * the country's associated regdomain when the
472 * regdomain is setup w/o a default country. For
473 * example, US is bound to the FCC regdomain but
474 * we allow US to be combined with FCC3 because FCC3
475 * has not default country. This allows bogus
476 * combinations like FCC3+DK which are resolved when
477 * constructing the channel list by deferring to the
478 * regdomain to construct the channel list.
480 rp = lib80211_regdomain_findbysku(rdp, rd->regdomain);
482 errx(1, "country %s (%s) is not usable with "
483 "regdomain %d", cc->isoname, cc->name,
485 else if (rp->cc != NULL && rp->cc != cc)
486 errx(1, "country %s (%s) is not usable with "
487 "regdomain %s", cc->isoname, cc->name,
492 * Fetch the device capabilities and calculate the
493 * full set of netbands for which we request a new
494 * channel list be constructed. Once that's done we
495 * push the regdomain info + channel list to the kernel.
497 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
499 errx(1, "no space for device capabilities");
500 dc->dc_chaninfo.ic_nchans = MAXCHAN;
504 printf("drivercaps: 0x%x\n", dc->dc_drivercaps);
505 printf("cryptocaps: 0x%x\n", dc->dc_cryptocaps);
506 printf("htcaps : 0x%x\n", dc->dc_htcaps);
507 memcpy(chaninfo, &dc->dc_chaninfo,
508 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
509 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, 1/*verbose*/);
512 req = malloc(IEEE80211_REGDOMAIN_SIZE(dc->dc_chaninfo.ic_nchans));
514 errx(1, "no space for regdomain request");
516 regdomain_makechannels(req, dc);
519 print_regdomain(rd, 1/*verbose*/);
521 /* blech, reallocate channel list for new data */
522 if (chaninfo != NULL)
524 chaninfo = malloc(IEEE80211_CHANINFO_SPACE(&req->chaninfo));
525 if (chaninfo == NULL)
526 errx(1, "no space for channel list");
527 memcpy(chaninfo, &req->chaninfo,
528 IEEE80211_CHANINFO_SPACE(&req->chaninfo));
529 print_channels(s, &req->chaninfo, 1/*allchans*/, 1/*verbose*/);
531 if (req->chaninfo.ic_nchans == 0)
532 errx(1, "no channels calculated");
533 set80211(s, IEEE80211_IOC_REGDOMAIN, 0,
534 IEEE80211_REGDOMAIN_SPACE(req), req);
540 ieee80211_mhz2ieee(int freq, int flags)
542 struct ieee80211_channel chan;
543 mapfreq(&chan, freq, flags);
548 isanyarg(const char *arg)
550 return (strncmp(arg, "-", 1) == 0 ||
551 strncasecmp(arg, "any", 3) == 0 || strncasecmp(arg, "off", 3) == 0);
555 set80211ssid(const char *val, int d, int s, const struct afswtch *rafp)
559 u_int8_t data[IEEE80211_NWID_LEN];
563 if (len > 2 && isdigit((int)val[0]) && val[1] == ':') {
568 bzero(data, sizeof(data));
570 if (get_string(val, NULL, data, &len) == NULL)
573 set80211(s, IEEE80211_IOC_SSID, ssid, len, data);
577 set80211meshid(const char *val, int d, int s, const struct afswtch *rafp)
580 u_int8_t data[IEEE80211_NWID_LEN];
582 memset(data, 0, sizeof(data));
584 if (get_string(val, NULL, data, &len) == NULL)
587 set80211(s, IEEE80211_IOC_MESH_ID, 0, len, data);
591 set80211stationname(const char *val, int d, int s, const struct afswtch *rafp)
596 bzero(data, sizeof(data));
598 get_string(val, NULL, data, &len);
600 set80211(s, IEEE80211_IOC_STATIONNAME, 0, len, data);
604 * Parse a channel specification for attributes/flags.
606 * freq/xx channel width (5,10,20,40,40+,40-)
607 * freq:mode channel mode (a,b,g,h,n,t,s,d)
609 * These can be combined in either order; e.g. 2437:ng/40.
610 * Modes are case insensitive.
612 * The result is not validated here; it's assumed to be
613 * checked against the channel table fetched from the kernel.
616 getchannelflags(const char *val, int freq)
618 #define _CHAN_HT 0x80000000
624 cp = strchr(val, ':');
626 for (cp++; isalpha((int) *cp); cp++) {
627 /* accept mixed case */
632 case 'a': /* 802.11a */
633 flags |= IEEE80211_CHAN_A;
635 case 'b': /* 802.11b */
636 flags |= IEEE80211_CHAN_B;
638 case 'g': /* 802.11g */
639 flags |= IEEE80211_CHAN_G;
641 case 'h': /* ht = 802.11n */
642 case 'n': /* 802.11n */
643 flags |= _CHAN_HT; /* NB: private */
645 case 'd': /* dt = Atheros Dynamic Turbo */
646 flags |= IEEE80211_CHAN_TURBO;
648 case 't': /* ht, dt, st, t */
649 /* dt and unadorned t specify Dynamic Turbo */
650 if ((flags & (IEEE80211_CHAN_STURBO|_CHAN_HT)) == 0)
651 flags |= IEEE80211_CHAN_TURBO;
653 case 's': /* st = Atheros Static Turbo */
654 flags |= IEEE80211_CHAN_STURBO;
657 errx(-1, "%s: Invalid channel attribute %c\n",
662 cp = strchr(val, '/');
665 u_long cw = strtoul(cp+1, &ep, 10);
669 flags |= IEEE80211_CHAN_QUARTER;
672 flags |= IEEE80211_CHAN_HALF;
675 /* NB: this may be removed below */
676 flags |= IEEE80211_CHAN_HT20;
679 if (ep != NULL && *ep == '+')
680 flags |= IEEE80211_CHAN_HT40U;
681 else if (ep != NULL && *ep == '-')
682 flags |= IEEE80211_CHAN_HT40D;
685 errx(-1, "%s: Invalid channel width\n", val);
689 * Cleanup specifications.
691 if ((flags & _CHAN_HT) == 0) {
693 * If user specified freq/20 or freq/40 quietly remove
694 * HT cw attributes depending on channel use. To give
695 * an explicit 20/40 width for an HT channel you must
696 * indicate it is an HT channel since all HT channels
697 * are also usable for legacy operation; e.g. freq:n/40.
699 flags &= ~IEEE80211_CHAN_HT;
702 * Remove private indicator that this is an HT channel
703 * and if no explicit channel width has been given
704 * provide the default settings.
707 if ((flags & IEEE80211_CHAN_HT) == 0) {
708 struct ieee80211_channel chan;
710 * Consult the channel list to see if we can use
711 * HT40+ or HT40- (if both the map routines choose).
714 mapfreq(&chan, freq, 0);
716 mapchan(&chan, freq, 0);
717 flags |= (chan.ic_flags & IEEE80211_CHAN_HT);
725 getchannel(int s, struct ieee80211_channel *chan, const char *val)
730 memset(chan, 0, sizeof(*chan));
732 chan->ic_freq = IEEE80211_CHAN_ANY;
737 v = strtol(val, &eptr, 10);
738 if (val[0] == '\0' || val == eptr || errno == ERANGE ||
739 /* channel may be suffixed with nothing, :flag, or /width */
740 (eptr[0] != '\0' && eptr[0] != ':' && eptr[0] != '/'))
741 errx(1, "invalid channel specification%s",
742 errno == ERANGE ? " (out of range)" : "");
743 flags = getchannelflags(val, v);
744 if (v > 255) { /* treat as frequency */
745 mapfreq(chan, v, flags);
747 mapchan(chan, v, flags);
752 set80211channel(const char *val, int d, int s, const struct afswtch *rafp)
754 struct ieee80211_channel chan;
756 getchannel(s, &chan, val);
757 set80211(s, IEEE80211_IOC_CURCHAN, 0, sizeof(chan), &chan);
761 set80211chanswitch(const char *val, int d, int s, const struct afswtch *rafp)
763 struct ieee80211_chanswitch_req csr;
765 getchannel(s, &csr.csa_chan, val);
768 set80211(s, IEEE80211_IOC_CHANSWITCH, 0, sizeof(csr), &csr);
772 set80211authmode(const char *val, int d, int s, const struct afswtch *rafp)
776 if (strcasecmp(val, "none") == 0) {
777 mode = IEEE80211_AUTH_NONE;
778 } else if (strcasecmp(val, "open") == 0) {
779 mode = IEEE80211_AUTH_OPEN;
780 } else if (strcasecmp(val, "shared") == 0) {
781 mode = IEEE80211_AUTH_SHARED;
782 } else if (strcasecmp(val, "8021x") == 0) {
783 mode = IEEE80211_AUTH_8021X;
784 } else if (strcasecmp(val, "wpa") == 0) {
785 mode = IEEE80211_AUTH_WPA;
787 errx(1, "unknown authmode");
790 set80211(s, IEEE80211_IOC_AUTHMODE, mode, 0, NULL);
794 set80211powersavemode(const char *val, int d, int s, const struct afswtch *rafp)
798 if (strcasecmp(val, "off") == 0) {
799 mode = IEEE80211_POWERSAVE_OFF;
800 } else if (strcasecmp(val, "on") == 0) {
801 mode = IEEE80211_POWERSAVE_ON;
802 } else if (strcasecmp(val, "cam") == 0) {
803 mode = IEEE80211_POWERSAVE_CAM;
804 } else if (strcasecmp(val, "psp") == 0) {
805 mode = IEEE80211_POWERSAVE_PSP;
806 } else if (strcasecmp(val, "psp-cam") == 0) {
807 mode = IEEE80211_POWERSAVE_PSP_CAM;
809 errx(1, "unknown powersavemode");
812 set80211(s, IEEE80211_IOC_POWERSAVE, mode, 0, NULL);
816 set80211powersave(const char *val, int d, int s, const struct afswtch *rafp)
819 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_OFF,
822 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_ON,
827 set80211powersavesleep(const char *val, int d, int s, const struct afswtch *rafp)
829 set80211(s, IEEE80211_IOC_POWERSAVESLEEP, atoi(val), 0, NULL);
833 set80211wepmode(const char *val, int d, int s, const struct afswtch *rafp)
837 if (strcasecmp(val, "off") == 0) {
838 mode = IEEE80211_WEP_OFF;
839 } else if (strcasecmp(val, "on") == 0) {
840 mode = IEEE80211_WEP_ON;
841 } else if (strcasecmp(val, "mixed") == 0) {
842 mode = IEEE80211_WEP_MIXED;
844 errx(1, "unknown wep mode");
847 set80211(s, IEEE80211_IOC_WEP, mode, 0, NULL);
851 set80211wep(const char *val, int d, int s, const struct afswtch *rafp)
853 set80211(s, IEEE80211_IOC_WEP, d, 0, NULL);
857 isundefarg(const char *arg)
859 return (strcmp(arg, "-") == 0 || strncasecmp(arg, "undef", 5) == 0);
863 set80211weptxkey(const char *val, int d, int s, const struct afswtch *rafp)
866 set80211(s, IEEE80211_IOC_WEPTXKEY, IEEE80211_KEYIX_NONE, 0, NULL);
868 set80211(s, IEEE80211_IOC_WEPTXKEY, atoi(val)-1, 0, NULL);
872 set80211wepkey(const char *val, int d, int s, const struct afswtch *rafp)
876 u_int8_t data[IEEE80211_KEYBUF_SIZE];
878 if (isdigit((int)val[0]) && val[1] == ':') {
883 bzero(data, sizeof(data));
885 get_string(val, NULL, data, &len);
887 set80211(s, IEEE80211_IOC_WEPKEY, key, len, data);
891 * This function is purely a NetBSD compatibility interface. The NetBSD
892 * interface is too inflexible, but it's there so we'll support it since
893 * it's not all that hard.
896 set80211nwkey(const char *val, int d, int s, const struct afswtch *rafp)
900 u_int8_t data[IEEE80211_KEYBUF_SIZE];
902 set80211(s, IEEE80211_IOC_WEP, IEEE80211_WEP_ON, 0, NULL);
904 if (isdigit((int)val[0]) && val[1] == ':') {
905 txkey = val[0]-'0'-1;
908 for (i = 0; i < 4; i++) {
909 bzero(data, sizeof(data));
911 val = get_string(val, ",", data, &len);
915 set80211(s, IEEE80211_IOC_WEPKEY, i, len, data);
918 bzero(data, sizeof(data));
920 get_string(val, NULL, data, &len);
923 set80211(s, IEEE80211_IOC_WEPKEY, 0, len, data);
925 bzero(data, sizeof(data));
926 for (i = 1; i < 4; i++)
927 set80211(s, IEEE80211_IOC_WEPKEY, i, 0, data);
930 set80211(s, IEEE80211_IOC_WEPTXKEY, txkey, 0, NULL);
934 set80211rtsthreshold(const char *val, int d, int s, const struct afswtch *rafp)
936 set80211(s, IEEE80211_IOC_RTSTHRESHOLD,
937 isundefarg(val) ? IEEE80211_RTS_MAX : atoi(val), 0, NULL);
941 set80211protmode(const char *val, int d, int s, const struct afswtch *rafp)
945 if (strcasecmp(val, "off") == 0) {
946 mode = IEEE80211_PROTMODE_OFF;
947 } else if (strcasecmp(val, "cts") == 0) {
948 mode = IEEE80211_PROTMODE_CTS;
949 } else if (strncasecmp(val, "rtscts", 3) == 0) {
950 mode = IEEE80211_PROTMODE_RTSCTS;
952 errx(1, "unknown protection mode");
955 set80211(s, IEEE80211_IOC_PROTMODE, mode, 0, NULL);
959 set80211htprotmode(const char *val, int d, int s, const struct afswtch *rafp)
963 if (strcasecmp(val, "off") == 0) {
964 mode = IEEE80211_PROTMODE_OFF;
965 } else if (strncasecmp(val, "rts", 3) == 0) {
966 mode = IEEE80211_PROTMODE_RTSCTS;
968 errx(1, "unknown protection mode");
971 set80211(s, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL);
975 set80211txpower(const char *val, int d, int s, const struct afswtch *rafp)
977 double v = atof(val);
982 errx(-1, "invalid tx power (must be .5 dBm units)");
983 set80211(s, IEEE80211_IOC_TXPOWER, txpow, 0, NULL);
986 #define IEEE80211_ROAMING_DEVICE 0
987 #define IEEE80211_ROAMING_AUTO 1
988 #define IEEE80211_ROAMING_MANUAL 2
991 set80211roaming(const char *val, int d, int s, const struct afswtch *rafp)
995 if (strcasecmp(val, "device") == 0) {
996 mode = IEEE80211_ROAMING_DEVICE;
997 } else if (strcasecmp(val, "auto") == 0) {
998 mode = IEEE80211_ROAMING_AUTO;
999 } else if (strcasecmp(val, "manual") == 0) {
1000 mode = IEEE80211_ROAMING_MANUAL;
1002 errx(1, "unknown roaming mode");
1004 set80211(s, IEEE80211_IOC_ROAMING, mode, 0, NULL);
1008 set80211wme(const char *val, int d, int s, const struct afswtch *rafp)
1010 set80211(s, IEEE80211_IOC_WME, d, 0, NULL);
1014 set80211hidessid(const char *val, int d, int s, const struct afswtch *rafp)
1016 set80211(s, IEEE80211_IOC_HIDESSID, d, 0, NULL);
1020 set80211apbridge(const char *val, int d, int s, const struct afswtch *rafp)
1022 set80211(s, IEEE80211_IOC_APBRIDGE, d, 0, NULL);
1026 set80211fastframes(const char *val, int d, int s, const struct afswtch *rafp)
1028 set80211(s, IEEE80211_IOC_FF, d, 0, NULL);
1032 set80211dturbo(const char *val, int d, int s, const struct afswtch *rafp)
1034 set80211(s, IEEE80211_IOC_TURBOP, d, 0, NULL);
1038 set80211chanlist(const char *val, int d, int s, const struct afswtch *rafp)
1040 struct ieee80211req_chanlist chanlist;
1041 char *temp, *cp, *tp;
1043 temp = malloc(strlen(val) + 1);
1045 errx(1, "malloc failed");
1047 memset(&chanlist, 0, sizeof(chanlist));
1050 int first, last, f, c;
1052 tp = strchr(cp, ',');
1055 switch (sscanf(cp, "%u-%u", &first, &last)) {
1057 if (first > IEEE80211_CHAN_MAX)
1058 errx(-1, "channel %u out of range, max %u",
1059 first, IEEE80211_CHAN_MAX);
1060 setbit(chanlist.ic_channels, first);
1063 if (first > IEEE80211_CHAN_MAX)
1064 errx(-1, "channel %u out of range, max %u",
1065 first, IEEE80211_CHAN_MAX);
1066 if (last > IEEE80211_CHAN_MAX)
1067 errx(-1, "channel %u out of range, max %u",
1068 last, IEEE80211_CHAN_MAX);
1070 errx(-1, "void channel range, %u > %u",
1072 for (f = first; f <= last; f++)
1073 setbit(chanlist.ic_channels, f);
1085 set80211(s, IEEE80211_IOC_CHANLIST, 0, sizeof(chanlist), &chanlist);
1089 set80211bssid(const char *val, int d, int s, const struct afswtch *rafp)
1092 if (!isanyarg(val)) {
1094 struct sockaddr_dl sdl;
1096 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1098 errx(1, "malloc failed");
1100 strcpy(temp + 1, val);
1101 sdl.sdl_len = sizeof(sdl);
1102 link_addr(temp, &sdl);
1104 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1105 errx(1, "malformed link-level address");
1106 set80211(s, IEEE80211_IOC_BSSID, 0,
1107 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1109 uint8_t zerobssid[IEEE80211_ADDR_LEN];
1110 memset(zerobssid, 0, sizeof(zerobssid));
1111 set80211(s, IEEE80211_IOC_BSSID, 0,
1112 IEEE80211_ADDR_LEN, zerobssid);
1117 getac(const char *ac)
1119 if (strcasecmp(ac, "ac_be") == 0 || strcasecmp(ac, "be") == 0)
1121 if (strcasecmp(ac, "ac_bk") == 0 || strcasecmp(ac, "bk") == 0)
1123 if (strcasecmp(ac, "ac_vi") == 0 || strcasecmp(ac, "vi") == 0)
1125 if (strcasecmp(ac, "ac_vo") == 0 || strcasecmp(ac, "vo") == 0)
1127 errx(1, "unknown wme access class %s", ac);
1131 DECL_CMD_FUNC2(set80211cwmin, ac, val)
1133 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac), NULL);
1137 DECL_CMD_FUNC2(set80211cwmax, ac, val)
1139 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac), NULL);
1143 DECL_CMD_FUNC2(set80211aifs, ac, val)
1145 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac), NULL);
1149 DECL_CMD_FUNC2(set80211txoplimit, ac, val)
1151 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac), NULL);
1155 DECL_CMD_FUNC(set80211acm, ac, d)
1157 set80211(s, IEEE80211_IOC_WME_ACM, 1, getac(ac), NULL);
1160 DECL_CMD_FUNC(set80211noacm, ac, d)
1162 set80211(s, IEEE80211_IOC_WME_ACM, 0, getac(ac), NULL);
1166 DECL_CMD_FUNC(set80211ackpolicy, ac, d)
1168 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 1, getac(ac), NULL);
1171 DECL_CMD_FUNC(set80211noackpolicy, ac, d)
1173 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 0, getac(ac), NULL);
1177 DECL_CMD_FUNC2(set80211bsscwmin, ac, val)
1179 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val),
1180 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1184 DECL_CMD_FUNC2(set80211bsscwmax, ac, val)
1186 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val),
1187 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1191 DECL_CMD_FUNC2(set80211bssaifs, ac, val)
1193 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val),
1194 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1198 DECL_CMD_FUNC2(set80211bsstxoplimit, ac, val)
1200 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val),
1201 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1205 DECL_CMD_FUNC(set80211dtimperiod, val, d)
1207 set80211(s, IEEE80211_IOC_DTIM_PERIOD, atoi(val), 0, NULL);
1211 DECL_CMD_FUNC(set80211bintval, val, d)
1213 set80211(s, IEEE80211_IOC_BEACON_INTERVAL, atoi(val), 0, NULL);
1217 set80211macmac(int s, int op, const char *val)
1220 struct sockaddr_dl sdl;
1222 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1224 errx(1, "malloc failed");
1226 strcpy(temp + 1, val);
1227 sdl.sdl_len = sizeof(sdl);
1228 link_addr(temp, &sdl);
1230 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1231 errx(1, "malformed link-level address");
1232 set80211(s, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl));
1236 DECL_CMD_FUNC(set80211addmac, val, d)
1238 set80211macmac(s, IEEE80211_IOC_ADDMAC, val);
1242 DECL_CMD_FUNC(set80211delmac, val, d)
1244 set80211macmac(s, IEEE80211_IOC_DELMAC, val);
1248 DECL_CMD_FUNC(set80211kickmac, val, d)
1251 struct sockaddr_dl sdl;
1252 struct ieee80211req_mlme mlme;
1254 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1256 errx(1, "malloc failed");
1258 strcpy(temp + 1, val);
1259 sdl.sdl_len = sizeof(sdl);
1260 link_addr(temp, &sdl);
1262 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1263 errx(1, "malformed link-level address");
1264 memset(&mlme, 0, sizeof(mlme));
1265 mlme.im_op = IEEE80211_MLME_DEAUTH;
1266 mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE;
1267 memcpy(mlme.im_macaddr, LLADDR(&sdl), IEEE80211_ADDR_LEN);
1268 set80211(s, IEEE80211_IOC_MLME, 0, sizeof(mlme), &mlme);
1272 DECL_CMD_FUNC(set80211maccmd, val, d)
1274 set80211(s, IEEE80211_IOC_MACCMD, d, 0, NULL);
1278 set80211meshrtmac(int s, int req, const char *val)
1281 struct sockaddr_dl sdl;
1283 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1285 errx(1, "malloc failed");
1287 strcpy(temp + 1, val);
1288 sdl.sdl_len = sizeof(sdl);
1289 link_addr(temp, &sdl);
1291 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1292 errx(1, "malformed link-level address");
1293 set80211(s, IEEE80211_IOC_MESH_RTCMD, req,
1294 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1298 DECL_CMD_FUNC(set80211addmeshrt, val, d)
1300 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_ADD, val);
1304 DECL_CMD_FUNC(set80211delmeshrt, val, d)
1306 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_DELETE, val);
1310 DECL_CMD_FUNC(set80211meshrtcmd, val, d)
1312 set80211(s, IEEE80211_IOC_MESH_RTCMD, d, 0, NULL);
1316 DECL_CMD_FUNC(set80211hwmprootmode, val, d)
1320 if (strcasecmp(val, "normal") == 0)
1321 mode = IEEE80211_HWMP_ROOTMODE_NORMAL;
1322 else if (strcasecmp(val, "proactive") == 0)
1323 mode = IEEE80211_HWMP_ROOTMODE_PROACTIVE;
1324 else if (strcasecmp(val, "rann") == 0)
1325 mode = IEEE80211_HWMP_ROOTMODE_RANN;
1327 mode = IEEE80211_HWMP_ROOTMODE_DISABLED;
1328 set80211(s, IEEE80211_IOC_HWMP_ROOTMODE, mode, 0, NULL);
1332 DECL_CMD_FUNC(set80211hwmpmaxhops, val, d)
1334 set80211(s, IEEE80211_IOC_HWMP_MAXHOPS, atoi(val), 0, NULL);
1338 set80211pureg(const char *val, int d, int s, const struct afswtch *rafp)
1340 set80211(s, IEEE80211_IOC_PUREG, d, 0, NULL);
1344 set80211quiet(const char *val, int d, int s, const struct afswtch *rafp)
1346 set80211(s, IEEE80211_IOC_QUIET, d, 0, NULL);
1350 DECL_CMD_FUNC(set80211quietperiod, val, d)
1352 set80211(s, IEEE80211_IOC_QUIET_PERIOD, atoi(val), 0, NULL);
1356 DECL_CMD_FUNC(set80211quietcount, val, d)
1358 set80211(s, IEEE80211_IOC_QUIET_COUNT, atoi(val), 0, NULL);
1362 DECL_CMD_FUNC(set80211quietduration, val, d)
1364 set80211(s, IEEE80211_IOC_QUIET_DUR, atoi(val), 0, NULL);
1368 DECL_CMD_FUNC(set80211quietoffset, val, d)
1370 set80211(s, IEEE80211_IOC_QUIET_OFFSET, atoi(val), 0, NULL);
1374 set80211bgscan(const char *val, int d, int s, const struct afswtch *rafp)
1376 set80211(s, IEEE80211_IOC_BGSCAN, d, 0, NULL);
1380 DECL_CMD_FUNC(set80211bgscanidle, val, d)
1382 set80211(s, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL);
1386 DECL_CMD_FUNC(set80211bgscanintvl, val, d)
1388 set80211(s, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL);
1392 DECL_CMD_FUNC(set80211scanvalid, val, d)
1394 set80211(s, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL);
1398 * Parse an optional trailing specification of which netbands
1399 * to apply a parameter to. This is basically the same syntax
1400 * as used for channels but you can concatenate to specify
1401 * multiple. For example:
1402 * 14:abg apply to 11a, 11b, and 11g
1403 * 6:ht apply to 11na and 11ng
1404 * We don't make a big effort to catch silly things; this is
1405 * really a convenience mechanism.
1408 getmodeflags(const char *val)
1415 cp = strchr(val, ':');
1417 for (cp++; isalpha((int) *cp); cp++) {
1418 /* accept mixed case */
1423 case 'a': /* 802.11a */
1424 flags |= IEEE80211_CHAN_A;
1426 case 'b': /* 802.11b */
1427 flags |= IEEE80211_CHAN_B;
1429 case 'g': /* 802.11g */
1430 flags |= IEEE80211_CHAN_G;
1432 case 'n': /* 802.11n */
1433 flags |= IEEE80211_CHAN_HT;
1435 case 'd': /* dt = Atheros Dynamic Turbo */
1436 flags |= IEEE80211_CHAN_TURBO;
1438 case 't': /* ht, dt, st, t */
1439 /* dt and unadorned t specify Dynamic Turbo */
1440 if ((flags & (IEEE80211_CHAN_STURBO|IEEE80211_CHAN_HT)) == 0)
1441 flags |= IEEE80211_CHAN_TURBO;
1443 case 's': /* st = Atheros Static Turbo */
1444 flags |= IEEE80211_CHAN_STURBO;
1446 case 'h': /* 1/2-width channels */
1447 flags |= IEEE80211_CHAN_HALF;
1449 case 'q': /* 1/4-width channels */
1450 flags |= IEEE80211_CHAN_QUARTER;
1453 errx(-1, "%s: Invalid mode attribute %c\n",
1461 #define IEEE80211_CHAN_HTA (IEEE80211_CHAN_HT|IEEE80211_CHAN_5GHZ)
1462 #define IEEE80211_CHAN_HTG (IEEE80211_CHAN_HT|IEEE80211_CHAN_2GHZ)
1464 #define _APPLY(_flags, _base, _param, _v) do { \
1465 if (_flags & IEEE80211_CHAN_HT) { \
1466 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1467 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1468 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1469 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1470 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1472 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1474 if (_flags & IEEE80211_CHAN_TURBO) { \
1475 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1476 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1477 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1478 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1479 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1481 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1483 if (_flags & IEEE80211_CHAN_STURBO) \
1484 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1485 if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1486 _base.params[IEEE80211_MODE_11A]._param = _v; \
1487 if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1488 _base.params[IEEE80211_MODE_11G]._param = _v; \
1489 if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1490 _base.params[IEEE80211_MODE_11B]._param = _v; \
1491 if (_flags & IEEE80211_CHAN_HALF) \
1492 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1493 if (_flags & IEEE80211_CHAN_QUARTER) \
1494 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1496 #define _APPLY1(_flags, _base, _param, _v) do { \
1497 if (_flags & IEEE80211_CHAN_HT) { \
1498 if (_flags & IEEE80211_CHAN_5GHZ) \
1499 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1501 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1502 } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \
1503 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1504 else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \
1505 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1506 else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \
1507 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1508 else if (_flags & IEEE80211_CHAN_HALF) \
1509 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1510 else if (_flags & IEEE80211_CHAN_QUARTER) \
1511 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1512 else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1513 _base.params[IEEE80211_MODE_11A]._param = _v; \
1514 else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1515 _base.params[IEEE80211_MODE_11G]._param = _v; \
1516 else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1517 _base.params[IEEE80211_MODE_11B]._param = _v; \
1519 #define _APPLY_RATE(_flags, _base, _param, _v) do { \
1520 if (_flags & IEEE80211_CHAN_HT) { \
1521 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1523 _APPLY(_flags, _base, _param, _v); \
1525 #define _APPLY_RATE1(_flags, _base, _param, _v) do { \
1526 if (_flags & IEEE80211_CHAN_HT) { \
1527 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1529 _APPLY1(_flags, _base, _param, _v); \
1533 DECL_CMD_FUNC(set80211roamrssi, val, d)
1535 double v = atof(val);
1540 errx(-1, "invalid rssi (must be .5 dBm units)");
1541 flags = getmodeflags(val);
1543 if (flags == 0) { /* NB: no flags => current channel */
1544 flags = getcurchan(s)->ic_flags;
1545 _APPLY1(flags, roamparams, rssi, rssi);
1547 _APPLY(flags, roamparams, rssi, rssi);
1548 callback_register(setroam_cb, &roamparams);
1552 getrate(const char *val, const char *tag)
1554 double v = atof(val);
1559 errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag);
1560 return rate; /* NB: returns 2x the specified value */
1564 DECL_CMD_FUNC(set80211roamrate, val, d)
1568 rate = getrate(val, "roam");
1569 flags = getmodeflags(val);
1571 if (flags == 0) { /* NB: no flags => current channel */
1572 flags = getcurchan(s)->ic_flags;
1573 _APPLY_RATE1(flags, roamparams, rate, rate);
1575 _APPLY_RATE(flags, roamparams, rate, rate);
1576 callback_register(setroam_cb, &roamparams);
1580 DECL_CMD_FUNC(set80211mcastrate, val, d)
1584 rate = getrate(val, "mcast");
1585 flags = getmodeflags(val);
1587 if (flags == 0) { /* NB: no flags => current channel */
1588 flags = getcurchan(s)->ic_flags;
1589 _APPLY_RATE1(flags, txparams, mcastrate, rate);
1591 _APPLY_RATE(flags, txparams, mcastrate, rate);
1592 callback_register(settxparams_cb, &txparams);
1596 DECL_CMD_FUNC(set80211mgtrate, val, d)
1600 rate = getrate(val, "mgmt");
1601 flags = getmodeflags(val);
1603 if (flags == 0) { /* NB: no flags => current channel */
1604 flags = getcurchan(s)->ic_flags;
1605 _APPLY_RATE1(flags, txparams, mgmtrate, rate);
1607 _APPLY_RATE(flags, txparams, mgmtrate, rate);
1608 callback_register(settxparams_cb, &txparams);
1612 DECL_CMD_FUNC(set80211ucastrate, val, d)
1617 flags = getmodeflags(val);
1618 if (isanyarg(val)) {
1619 if (flags == 0) { /* NB: no flags => current channel */
1620 flags = getcurchan(s)->ic_flags;
1621 _APPLY1(flags, txparams, ucastrate,
1622 IEEE80211_FIXED_RATE_NONE);
1624 _APPLY(flags, txparams, ucastrate,
1625 IEEE80211_FIXED_RATE_NONE);
1627 int rate = getrate(val, "ucast");
1628 if (flags == 0) { /* NB: no flags => current channel */
1629 flags = getcurchan(s)->ic_flags;
1630 _APPLY_RATE1(flags, txparams, ucastrate, rate);
1632 _APPLY_RATE(flags, txparams, ucastrate, rate);
1634 callback_register(settxparams_cb, &txparams);
1638 DECL_CMD_FUNC(set80211maxretry, val, d)
1640 int v = atoi(val), flags;
1642 flags = getmodeflags(val);
1644 if (flags == 0) { /* NB: no flags => current channel */
1645 flags = getcurchan(s)->ic_flags;
1646 _APPLY1(flags, txparams, maxretry, v);
1648 _APPLY(flags, txparams, maxretry, v);
1649 callback_register(settxparams_cb, &txparams);
1653 #undef IEEE80211_CHAN_HTA
1654 #undef IEEE80211_CHAN_HTG
1657 DECL_CMD_FUNC(set80211fragthreshold, val, d)
1659 set80211(s, IEEE80211_IOC_FRAGTHRESHOLD,
1660 isundefarg(val) ? IEEE80211_FRAG_MAX : atoi(val), 0, NULL);
1664 DECL_CMD_FUNC(set80211bmissthreshold, val, d)
1666 set80211(s, IEEE80211_IOC_BMISSTHRESHOLD,
1667 isundefarg(val) ? IEEE80211_HWBMISS_MAX : atoi(val), 0, NULL);
1671 set80211burst(const char *val, int d, int s, const struct afswtch *rafp)
1673 set80211(s, IEEE80211_IOC_BURST, d, 0, NULL);
1677 set80211doth(const char *val, int d, int s, const struct afswtch *rafp)
1679 set80211(s, IEEE80211_IOC_DOTH, d, 0, NULL);
1683 set80211dfs(const char *val, int d, int s, const struct afswtch *rafp)
1685 set80211(s, IEEE80211_IOC_DFS, d, 0, NULL);
1689 set80211shortgi(const char *val, int d, int s, const struct afswtch *rafp)
1691 set80211(s, IEEE80211_IOC_SHORTGI,
1692 d ? (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) : 0,
1697 set80211ampdu(const char *val, int d, int s, const struct afswtch *rafp)
1701 if (get80211val(s, IEEE80211_IOC_AMPDU, &du) < 0)
1702 errx(-1, "cannot set AMPDU setting");
1708 set80211(s, IEEE80211_IOC_AMPDU, ampdu, 0, NULL);
1712 set80211stbc(const char *val, int d, int s, const struct afswtch *rafp)
1716 if (get80211val(s, IEEE80211_IOC_STBC, &stbc) < 0)
1717 errx(-1, "cannot set STBC setting");
1723 set80211(s, IEEE80211_IOC_STBC, stbc, 0, NULL);
1727 DECL_CMD_FUNC(set80211ampdulimit, val, d)
1731 switch (atoi(val)) {
1734 v = IEEE80211_HTCAP_MAXRXAMPDU_8K;
1738 v = IEEE80211_HTCAP_MAXRXAMPDU_16K;
1742 v = IEEE80211_HTCAP_MAXRXAMPDU_32K;
1746 v = IEEE80211_HTCAP_MAXRXAMPDU_64K;
1749 errx(-1, "invalid A-MPDU limit %s", val);
1751 set80211(s, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL);
1755 DECL_CMD_FUNC(set80211ampdudensity, val, d)
1759 if (isanyarg(val) || strcasecmp(val, "na") == 0)
1760 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1761 else switch ((int)(atof(val)*4)) {
1763 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1766 v = IEEE80211_HTCAP_MPDUDENSITY_025;
1769 v = IEEE80211_HTCAP_MPDUDENSITY_05;
1772 v = IEEE80211_HTCAP_MPDUDENSITY_1;
1775 v = IEEE80211_HTCAP_MPDUDENSITY_2;
1778 v = IEEE80211_HTCAP_MPDUDENSITY_4;
1781 v = IEEE80211_HTCAP_MPDUDENSITY_8;
1784 v = IEEE80211_HTCAP_MPDUDENSITY_16;
1787 errx(-1, "invalid A-MPDU density %s", val);
1789 set80211(s, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL);
1793 set80211amsdu(const char *val, int d, int s, const struct afswtch *rafp)
1797 if (get80211val(s, IEEE80211_IOC_AMSDU, &amsdu) < 0)
1798 err(-1, "cannot get AMSDU setting");
1804 set80211(s, IEEE80211_IOC_AMSDU, amsdu, 0, NULL);
1808 DECL_CMD_FUNC(set80211amsdulimit, val, d)
1810 set80211(s, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL);
1814 set80211puren(const char *val, int d, int s, const struct afswtch *rafp)
1816 set80211(s, IEEE80211_IOC_PUREN, d, 0, NULL);
1820 set80211htcompat(const char *val, int d, int s, const struct afswtch *rafp)
1822 set80211(s, IEEE80211_IOC_HTCOMPAT, d, 0, NULL);
1826 set80211htconf(const char *val, int d, int s, const struct afswtch *rafp)
1828 set80211(s, IEEE80211_IOC_HTCONF, d, 0, NULL);
1833 set80211dwds(const char *val, int d, int s, const struct afswtch *rafp)
1835 set80211(s, IEEE80211_IOC_DWDS, d, 0, NULL);
1839 set80211inact(const char *val, int d, int s, const struct afswtch *rafp)
1841 set80211(s, IEEE80211_IOC_INACTIVITY, d, 0, NULL);
1845 set80211tsn(const char *val, int d, int s, const struct afswtch *rafp)
1847 set80211(s, IEEE80211_IOC_TSN, d, 0, NULL);
1851 set80211dotd(const char *val, int d, int s, const struct afswtch *rafp)
1853 set80211(s, IEEE80211_IOC_DOTD, d, 0, NULL);
1857 set80211smps(const char *val, int d, int s, const struct afswtch *rafp)
1859 set80211(s, IEEE80211_IOC_SMPS, d, 0, NULL);
1863 set80211rifs(const char *val, int d, int s, const struct afswtch *rafp)
1865 set80211(s, IEEE80211_IOC_RIFS, d, 0, NULL);
1869 DECL_CMD_FUNC(set80211tdmaslot, val, d)
1871 set80211(s, IEEE80211_IOC_TDMA_SLOT, atoi(val), 0, NULL);
1875 DECL_CMD_FUNC(set80211tdmaslotcnt, val, d)
1877 set80211(s, IEEE80211_IOC_TDMA_SLOTCNT, atoi(val), 0, NULL);
1881 DECL_CMD_FUNC(set80211tdmaslotlen, val, d)
1883 set80211(s, IEEE80211_IOC_TDMA_SLOTLEN, atoi(val), 0, NULL);
1887 DECL_CMD_FUNC(set80211tdmabintval, val, d)
1889 set80211(s, IEEE80211_IOC_TDMA_BINTERVAL, atoi(val), 0, NULL);
1893 DECL_CMD_FUNC(set80211meshttl, val, d)
1895 set80211(s, IEEE80211_IOC_MESH_TTL, atoi(val), 0, NULL);
1899 DECL_CMD_FUNC(set80211meshforward, val, d)
1901 set80211(s, IEEE80211_IOC_MESH_FWRD, d, 0, NULL);
1905 DECL_CMD_FUNC(set80211meshgate, val, d)
1907 set80211(s, IEEE80211_IOC_MESH_GATE, d, 0, NULL);
1911 DECL_CMD_FUNC(set80211meshpeering, val, d)
1913 set80211(s, IEEE80211_IOC_MESH_AP, d, 0, NULL);
1917 DECL_CMD_FUNC(set80211meshmetric, val, d)
1921 memcpy(v, val, sizeof(v));
1922 set80211(s, IEEE80211_IOC_MESH_PR_METRIC, 0, 0, v);
1926 DECL_CMD_FUNC(set80211meshpath, val, d)
1930 memcpy(v, val, sizeof(v));
1931 set80211(s, IEEE80211_IOC_MESH_PR_PATH, 0, 0, v);
1935 regdomain_sort(const void *a, const void *b)
1938 (IEEE80211_CHAN_ALLTURBO|IEEE80211_CHAN_HALF|IEEE80211_CHAN_QUARTER)
1939 const struct ieee80211_channel *ca = a;
1940 const struct ieee80211_channel *cb = b;
1942 return ca->ic_freq == cb->ic_freq ?
1943 (ca->ic_flags & CHAN_ALL) - (cb->ic_flags & CHAN_ALL) :
1944 ca->ic_freq - cb->ic_freq;
1948 static const struct ieee80211_channel *
1949 chanlookup(const struct ieee80211_channel chans[], int nchans,
1950 int freq, int flags)
1954 flags &= IEEE80211_CHAN_ALLTURBO;
1955 for (i = 0; i < nchans; i++) {
1956 const struct ieee80211_channel *c = &chans[i];
1957 if (c->ic_freq == freq &&
1958 (c->ic_flags & IEEE80211_CHAN_ALLTURBO) == flags)
1965 chanfind(const struct ieee80211_channel chans[], int nchans, int flags)
1969 for (i = 0; i < nchans; i++) {
1970 const struct ieee80211_channel *c = &chans[i];
1971 if ((c->ic_flags & flags) == flags)
1978 * Check channel compatibility.
1981 checkchan(const struct ieee80211req_chaninfo *avail, int freq, int flags)
1983 flags &= ~REQ_FLAGS;
1985 * Check if exact channel is in the calibration table;
1986 * everything below is to deal with channels that we
1987 * want to include but that are not explicitly listed.
1989 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, flags) != NULL)
1991 if (flags & IEEE80211_CHAN_GSM) {
1993 * XXX GSM frequency mapping is handled in the kernel
1994 * so we cannot find them in the calibration table;
1995 * just accept the channel and the kernel will reject
1996 * the channel list if it's wrong.
2001 * If this is a 1/2 or 1/4 width channel allow it if a full
2002 * width channel is present for this frequency, and the device
2003 * supports fractional channels on this band. This is a hack
2004 * that avoids bloating the calibration table; it may be better
2005 * by per-band attributes though (we are effectively calculating
2006 * this attribute by scanning the channel list ourself).
2008 if ((flags & (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == 0)
2010 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq,
2011 flags &~ (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == NULL)
2013 if (flags & IEEE80211_CHAN_HALF) {
2014 return chanfind(avail->ic_chans, avail->ic_nchans,
2015 IEEE80211_CHAN_HALF |
2016 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2018 return chanfind(avail->ic_chans, avail->ic_nchans,
2019 IEEE80211_CHAN_QUARTER |
2020 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2025 regdomain_addchans(struct ieee80211req_chaninfo *ci,
2026 const netband_head *bands,
2027 const struct ieee80211_regdomain *reg,
2029 const struct ieee80211req_chaninfo *avail)
2031 const struct netband *nb;
2032 const struct freqband *b;
2033 struct ieee80211_channel *c, *prev;
2034 int freq, hi_adj, lo_adj, channelSep;
2037 hi_adj = (chanFlags & IEEE80211_CHAN_HT40U) ? -20 : 0;
2038 lo_adj = (chanFlags & IEEE80211_CHAN_HT40D) ? 20 : 0;
2039 channelSep = (chanFlags & IEEE80211_CHAN_2GHZ) ? 0 : 40;
2040 LIST_FOREACH(nb, bands, next) {
2043 printf("%s:", __func__);
2044 printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS);
2045 printb(" bandFlags", nb->flags | b->flags,
2046 IEEE80211_CHAN_BITS);
2050 for (freq = b->freqStart + lo_adj;
2051 freq <= b->freqEnd + hi_adj; freq += b->chanSep) {
2053 * Construct flags for the new channel. We take
2054 * the attributes from the band descriptions except
2055 * for HT40 which is enabled generically (i.e. +/-
2056 * extension channel) in the band description and
2057 * then constrained according by channel separation.
2059 flags = nb->flags | b->flags;
2060 if (flags & IEEE80211_CHAN_HT) {
2062 * HT channels are generated specially; we're
2063 * called to add HT20, HT40+, and HT40- chan's
2064 * so we need to expand only band specs for
2065 * the HT channel type being added.
2067 if ((chanFlags & IEEE80211_CHAN_HT20) &&
2068 (flags & IEEE80211_CHAN_HT20) == 0) {
2070 printf("%u: skip, not an "
2071 "HT20 channel\n", freq);
2074 if ((chanFlags & IEEE80211_CHAN_HT40) &&
2075 (flags & IEEE80211_CHAN_HT40) == 0) {
2077 printf("%u: skip, not an "
2078 "HT40 channel\n", freq);
2081 /* NB: HT attribute comes from caller */
2082 flags &= ~IEEE80211_CHAN_HT;
2083 flags |= chanFlags & IEEE80211_CHAN_HT;
2086 * Check if device can operate on this frequency.
2088 if (!checkchan(avail, freq, flags)) {
2090 printf("%u: skip, ", freq);
2091 printb("flags", flags,
2092 IEEE80211_CHAN_BITS);
2093 printf(" not available\n");
2097 if ((flags & REQ_ECM) && !reg->ecm) {
2099 printf("%u: skip, ECM channel\n", freq);
2102 if ((flags & REQ_INDOOR) && reg->location == 'O') {
2104 printf("%u: skip, indoor channel\n",
2108 if ((flags & REQ_OUTDOOR) && reg->location == 'I') {
2110 printf("%u: skip, outdoor channel\n",
2114 if ((flags & IEEE80211_CHAN_HT40) &&
2115 prev != NULL && (freq - prev->ic_freq) < channelSep) {
2117 printf("%u: skip, only %u channel "
2118 "separation, need %d\n", freq,
2119 freq - prev->ic_freq, channelSep);
2122 if (ci->ic_nchans == IEEE80211_CHAN_MAX) {
2124 printf("%u: skip, channel table full\n",
2128 c = &ci->ic_chans[ci->ic_nchans++];
2129 memset(c, 0, sizeof(*c));
2131 c->ic_flags = flags;
2132 if (c->ic_flags & IEEE80211_CHAN_DFS)
2133 c->ic_maxregpower = nb->maxPowerDFS;
2135 c->ic_maxregpower = nb->maxPower;
2137 printf("[%3d] add freq %u ",
2138 ci->ic_nchans-1, c->ic_freq);
2139 printb("flags", c->ic_flags, IEEE80211_CHAN_BITS);
2140 printf(" power %u\n", c->ic_maxregpower);
2142 /* NB: kernel fills in other fields */
2149 regdomain_makechannels(
2150 struct ieee80211_regdomain_req *req,
2151 const struct ieee80211_devcaps_req *dc)
2153 struct regdata *rdp = getregdata();
2154 const struct country *cc;
2155 const struct ieee80211_regdomain *reg = &req->rd;
2156 struct ieee80211req_chaninfo *ci = &req->chaninfo;
2157 const struct regdomain *rd;
2160 * Locate construction table for new channel list. We treat
2161 * the regdomain/SKU as definitive so a country can be in
2162 * multiple with different properties (e.g. US in FCC+FCC3).
2163 * If no regdomain is specified then we fallback on the country
2164 * code to find the associated regdomain since countries always
2165 * belong to at least one regdomain.
2167 if (reg->regdomain == 0) {
2168 cc = lib80211_country_findbycc(rdp, reg->country);
2170 errx(1, "internal error, country %d not found",
2174 rd = lib80211_regdomain_findbysku(rdp, reg->regdomain);
2176 errx(1, "internal error, regdomain %d not found",
2178 if (rd->sku != SKU_DEBUG) {
2180 * regdomain_addchans incrememnts the channel count for
2181 * each channel it adds so initialize ic_nchans to zero.
2182 * Note that we know we have enough space to hold all possible
2183 * channels because the devcaps list size was used to
2184 * allocate our request.
2187 if (!LIST_EMPTY(&rd->bands_11b))
2188 regdomain_addchans(ci, &rd->bands_11b, reg,
2189 IEEE80211_CHAN_B, &dc->dc_chaninfo);
2190 if (!LIST_EMPTY(&rd->bands_11g))
2191 regdomain_addchans(ci, &rd->bands_11g, reg,
2192 IEEE80211_CHAN_G, &dc->dc_chaninfo);
2193 if (!LIST_EMPTY(&rd->bands_11a))
2194 regdomain_addchans(ci, &rd->bands_11a, reg,
2195 IEEE80211_CHAN_A, &dc->dc_chaninfo);
2196 if (!LIST_EMPTY(&rd->bands_11na) && dc->dc_htcaps != 0) {
2197 regdomain_addchans(ci, &rd->bands_11na, reg,
2198 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20,
2200 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2201 regdomain_addchans(ci, &rd->bands_11na, reg,
2202 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U,
2204 regdomain_addchans(ci, &rd->bands_11na, reg,
2205 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D,
2209 if (!LIST_EMPTY(&rd->bands_11ng) && dc->dc_htcaps != 0) {
2210 regdomain_addchans(ci, &rd->bands_11ng, reg,
2211 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20,
2213 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2214 regdomain_addchans(ci, &rd->bands_11ng, reg,
2215 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U,
2217 regdomain_addchans(ci, &rd->bands_11ng, reg,
2218 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D,
2222 qsort(ci->ic_chans, ci->ic_nchans, sizeof(ci->ic_chans[0]),
2225 memcpy(ci, &dc->dc_chaninfo,
2226 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
2230 list_countries(void)
2232 struct regdata *rdp = getregdata();
2233 const struct country *cp;
2234 const struct regdomain *dp;
2238 printf("\nCountry codes:\n");
2239 LIST_FOREACH(cp, &rdp->countries, next) {
2240 printf("%2s %-15.15s%s", cp->isoname,
2241 cp->name, ((i+1)%4) == 0 ? "\n" : " ");
2245 printf("\nRegulatory domains:\n");
2246 LIST_FOREACH(dp, &rdp->domains, next) {
2247 printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " ");
2254 defaultcountry(const struct regdomain *rd)
2256 struct regdata *rdp = getregdata();
2257 const struct country *cc;
2259 cc = lib80211_country_findbycc(rdp, rd->cc->code);
2261 errx(1, "internal error, ISO country code %d not "
2262 "defined for regdomain %s", rd->cc->code, rd->name);
2263 regdomain.country = cc->code;
2264 regdomain.isocc[0] = cc->isoname[0];
2265 regdomain.isocc[1] = cc->isoname[1];
2269 DECL_CMD_FUNC(set80211regdomain, val, d)
2271 struct regdata *rdp = getregdata();
2272 const struct regdomain *rd;
2274 rd = lib80211_regdomain_findbyname(rdp, val);
2277 long sku = strtol(val, &eptr, 0);
2280 rd = lib80211_regdomain_findbysku(rdp, sku);
2281 if (eptr == val || rd == NULL)
2282 errx(1, "unknown regdomain %s", val);
2285 regdomain.regdomain = rd->sku;
2286 if (regdomain.country == 0 && rd->cc != NULL) {
2288 * No country code setup and there's a default
2289 * one for this regdomain fill it in.
2293 callback_register(setregdomain_cb, ®domain);
2297 DECL_CMD_FUNC(set80211country, val, d)
2299 struct regdata *rdp = getregdata();
2300 const struct country *cc;
2302 cc = lib80211_country_findbyname(rdp, val);
2305 long code = strtol(val, &eptr, 0);
2308 cc = lib80211_country_findbycc(rdp, code);
2309 if (eptr == val || cc == NULL)
2310 errx(1, "unknown ISO country code %s", val);
2313 regdomain.regdomain = cc->rd->sku;
2314 regdomain.country = cc->code;
2315 regdomain.isocc[0] = cc->isoname[0];
2316 regdomain.isocc[1] = cc->isoname[1];
2317 callback_register(setregdomain_cb, ®domain);
2321 set80211location(const char *val, int d, int s, const struct afswtch *rafp)
2324 regdomain.location = d;
2325 callback_register(setregdomain_cb, ®domain);
2329 set80211ecm(const char *val, int d, int s, const struct afswtch *rafp)
2333 callback_register(setregdomain_cb, ®domain);
2349 if (spacer != '\t') {
2353 col = 8; /* 8-col tab */
2357 LINE_CHECK(const char *fmt, ...)
2364 n = vsnprintf(buf+1, sizeof(buf)-1, fmt, ap);
2377 getmaxrate(const uint8_t rates[15], uint8_t nrates)
2379 int i, maxrate = -1;
2381 for (i = 0; i < nrates; i++) {
2382 int rate = rates[i] & IEEE80211_RATE_VAL;
2390 getcaps(int capinfo)
2392 static char capstring[32];
2393 char *cp = capstring;
2395 if (capinfo & IEEE80211_CAPINFO_ESS)
2397 if (capinfo & IEEE80211_CAPINFO_IBSS)
2399 if (capinfo & IEEE80211_CAPINFO_CF_POLLABLE)
2401 if (capinfo & IEEE80211_CAPINFO_CF_POLLREQ)
2403 if (capinfo & IEEE80211_CAPINFO_PRIVACY)
2405 if (capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)
2407 if (capinfo & IEEE80211_CAPINFO_PBCC)
2409 if (capinfo & IEEE80211_CAPINFO_CHNL_AGILITY)
2411 if (capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME)
2413 if (capinfo & IEEE80211_CAPINFO_RSN)
2415 if (capinfo & IEEE80211_CAPINFO_DSSSOFDM)
2424 static char flagstring[32];
2425 char *cp = flagstring;
2427 if (flags & IEEE80211_NODE_AUTH)
2429 if (flags & IEEE80211_NODE_QOS)
2431 if (flags & IEEE80211_NODE_ERP)
2433 if (flags & IEEE80211_NODE_PWR_MGT)
2435 if (flags & IEEE80211_NODE_HT) {
2437 if (flags & IEEE80211_NODE_HTCOMPAT)
2440 if (flags & IEEE80211_NODE_WPS)
2442 if (flags & IEEE80211_NODE_TSN)
2444 if (flags & IEEE80211_NODE_AMPDU_TX)
2446 if (flags & IEEE80211_NODE_AMPDU_RX)
2448 if (flags & IEEE80211_NODE_MIMO_PS) {
2450 if (flags & IEEE80211_NODE_MIMO_RTS)
2453 if (flags & IEEE80211_NODE_RIFS)
2455 if (flags & IEEE80211_NODE_SGI40) {
2457 if (flags & IEEE80211_NODE_SGI20)
2459 } else if (flags & IEEE80211_NODE_SGI20)
2461 if (flags & IEEE80211_NODE_AMSDU_TX)
2463 if (flags & IEEE80211_NODE_AMSDU_RX)
2470 printie(const char* tag, const uint8_t *ie, size_t ielen, int maxlen)
2474 maxlen -= strlen(tag)+2;
2475 if (2*ielen > maxlen)
2478 for (; ielen > 0; ie++, ielen--) {
2481 printf("%02x", *ie);
2489 #define LE_READ_2(p) \
2491 ((((const u_int8_t *)(p))[0] ) | \
2492 (((const u_int8_t *)(p))[1] << 8)))
2493 #define LE_READ_4(p) \
2495 ((((const u_int8_t *)(p))[0] ) | \
2496 (((const u_int8_t *)(p))[1] << 8) | \
2497 (((const u_int8_t *)(p))[2] << 16) | \
2498 (((const u_int8_t *)(p))[3] << 24)))
2501 * NB: The decoding routines assume a properly formatted ie
2502 * which should be safe as the kernel only retains them
2507 printwmeparam(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2509 #define MS(_v, _f) (((_v) & _f) >> _f##_S)
2510 static const char *acnames[] = { "BE", "BK", "VO", "VI" };
2511 const struct ieee80211_wme_param *wme =
2512 (const struct ieee80211_wme_param *) ie;
2518 printf("<qosinfo 0x%x", wme->param_qosInfo);
2519 ie += offsetof(struct ieee80211_wme_param, params_acParams);
2520 for (i = 0; i < WME_NUM_AC; i++) {
2521 const struct ieee80211_wme_acparams *ac =
2522 &wme->params_acParams[i];
2524 printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]"
2526 , MS(ac->acp_aci_aifsn, WME_PARAM_ACM) ? "acm " : ""
2527 , MS(ac->acp_aci_aifsn, WME_PARAM_AIFSN)
2528 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMIN)
2529 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMAX)
2530 , LE_READ_2(&ac->acp_txop)
2538 printwmeinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2542 const struct ieee80211_wme_info *wme =
2543 (const struct ieee80211_wme_info *) ie;
2544 printf("<version 0x%x info 0x%x>",
2545 wme->wme_version, wme->wme_info);
2550 printvhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2554 const struct ieee80211_ie_vhtcap *vhtcap =
2555 (const struct ieee80211_ie_vhtcap *) ie;
2556 uint32_t vhtcap_info = LE_READ_4(&vhtcap->vht_cap_info);
2558 printf("<cap 0x%08x", vhtcap_info);
2559 printf(" rx_mcs_map 0x%x",
2560 LE_READ_2(&vhtcap->supp_mcs.rx_mcs_map));
2561 printf(" rx_highest %d",
2562 LE_READ_2(&vhtcap->supp_mcs.rx_highest) & 0x1fff);
2563 printf(" tx_mcs_map 0x%x",
2564 LE_READ_2(&vhtcap->supp_mcs.tx_mcs_map));
2565 printf(" tx_highest %d",
2566 LE_READ_2(&vhtcap->supp_mcs.tx_highest) & 0x1fff);
2573 printvhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2577 const struct ieee80211_ie_vht_operation *vhtinfo =
2578 (const struct ieee80211_ie_vht_operation *) ie;
2580 printf("<chw %d freq1_idx %d freq2_idx %d basic_mcs_set 0x%04x>",
2581 vhtinfo->chan_width,
2582 vhtinfo->center_freq_seg1_idx,
2583 vhtinfo->center_freq_seg2_idx,
2584 LE_READ_2(&vhtinfo->basic_mcs_set));
2589 printvhtpwrenv(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2592 static const char *txpwrmap[] = {
2599 const struct ieee80211_ie_vht_txpwrenv *vhtpwr =
2600 (const struct ieee80211_ie_vht_txpwrenv *) ie;
2602 const char *sep = "";
2604 /* Get count; trim at ielen */
2605 n = (vhtpwr->tx_info &
2606 IEEE80211_VHT_TXPWRENV_INFO_COUNT_MASK) + 1;
2610 printf("<tx_info 0x%02x pwr:[", vhtpwr->tx_info);
2611 for (i = 0; i < n; i++) {
2612 printf("%s%s:%.2f", sep, txpwrmap[i],
2613 ((float) ((int8_t) ie[i+3])) / 2.0);
2622 printhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2626 const struct ieee80211_ie_htcap *htcap =
2627 (const struct ieee80211_ie_htcap *) ie;
2631 printf("<cap 0x%x param 0x%x",
2632 LE_READ_2(&htcap->hc_cap), htcap->hc_param);
2635 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2636 if (isset(htcap->hc_mcsset, i)) {
2637 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2638 if (isclr(htcap->hc_mcsset, j))
2642 printf("%s%u", sep, i);
2644 printf("%s%u-%u", sep, i, j);
2648 printf("] extcap 0x%x txbf 0x%x antenna 0x%x>",
2649 LE_READ_2(&htcap->hc_extcap),
2650 LE_READ_4(&htcap->hc_txbf),
2656 printhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2660 const struct ieee80211_ie_htinfo *htinfo =
2661 (const struct ieee80211_ie_htinfo *) ie;
2665 printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel,
2666 htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3,
2667 LE_READ_2(&htinfo->hi_byte45));
2668 printf(" basicmcs[");
2670 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2671 if (isset(htinfo->hi_basicmcsset, i)) {
2672 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2673 if (isclr(htinfo->hi_basicmcsset, j))
2677 printf("%s%u", sep, i);
2679 printf("%s%u-%u", sep, i, j);
2688 printathie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2693 const struct ieee80211_ath_ie *ath =
2694 (const struct ieee80211_ath_ie *)ie;
2697 if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME)
2699 if (ath->ath_capability & ATHEROS_CAP_COMPRESSION)
2701 if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME)
2703 if (ath->ath_capability & ATHEROS_CAP_XR)
2705 if (ath->ath_capability & ATHEROS_CAP_AR)
2707 if (ath->ath_capability & ATHEROS_CAP_BURST)
2709 if (ath->ath_capability & ATHEROS_CAP_WME)
2711 if (ath->ath_capability & ATHEROS_CAP_BOOST)
2713 printf("0x%x>", LE_READ_2(ath->ath_defkeyix));
2719 printmeshconf(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2721 #define MATCHOUI(field, oui, string) \
2723 if (memcmp(field, oui, 4) == 0) \
2724 printf("%s", string); \
2729 const struct ieee80211_meshconf_ie *mconf =
2730 (const struct ieee80211_meshconf_ie *)ie;
2732 if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP)
2737 if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME)
2741 printf(" CONGESTION:");
2742 if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED)
2747 if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF)
2752 if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED)
2756 printf(" FORM:0x%x CAPS:0x%x>", mconf->conf_form,
2763 printbssload(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2767 const struct ieee80211_bss_load_ie *bssload =
2768 (const struct ieee80211_bss_load_ie *) ie;
2769 printf("<sta count %d, chan load %d, aac %d>",
2770 LE_READ_2(&bssload->sta_count),
2777 printapchanrep(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2781 const struct ieee80211_ap_chan_report_ie *ap =
2782 (const struct ieee80211_ap_chan_report_ie *) ie;
2783 const char *sep = "";
2786 printf("<class %u, chan:[", ap->i_class);
2788 for (i = 3; i < ielen; i++) {
2789 printf("%s%u", sep, ie[i]);
2797 wpa_cipher(const u_int8_t *sel)
2799 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2800 u_int32_t w = LE_READ_4(sel);
2803 case WPA_SEL(WPA_CSE_NULL):
2805 case WPA_SEL(WPA_CSE_WEP40):
2807 case WPA_SEL(WPA_CSE_WEP104):
2809 case WPA_SEL(WPA_CSE_TKIP):
2811 case WPA_SEL(WPA_CSE_CCMP):
2814 return "?"; /* NB: so 1<< is discarded */
2819 wpa_keymgmt(const u_int8_t *sel)
2821 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2822 u_int32_t w = LE_READ_4(sel);
2825 case WPA_SEL(WPA_ASE_8021X_UNSPEC):
2826 return "8021X-UNSPEC";
2827 case WPA_SEL(WPA_ASE_8021X_PSK):
2829 case WPA_SEL(WPA_ASE_NONE):
2837 printwpaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2839 u_int8_t len = ie[1];
2846 ie += 6, len -= 4; /* NB: len is payload only */
2848 printf("<v%u", LE_READ_2(ie));
2851 printf(" mc:%s", wpa_cipher(ie));
2854 /* unicast ciphers */
2858 for (; n > 0; n--) {
2859 printf("%s%s", sep, wpa_cipher(ie));
2864 /* key management algorithms */
2868 for (; n > 0; n--) {
2869 printf("%s%s", sep, wpa_keymgmt(ie));
2874 if (len > 2) /* optional capabilities */
2875 printf(", caps 0x%x", LE_READ_2(ie));
2881 rsn_cipher(const u_int8_t *sel)
2883 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
2884 u_int32_t w = LE_READ_4(sel);
2887 case RSN_SEL(RSN_CSE_NULL):
2889 case RSN_SEL(RSN_CSE_WEP40):
2891 case RSN_SEL(RSN_CSE_WEP104):
2893 case RSN_SEL(RSN_CSE_TKIP):
2895 case RSN_SEL(RSN_CSE_CCMP):
2897 case RSN_SEL(RSN_CSE_WRAP):
2905 rsn_keymgmt(const u_int8_t *sel)
2907 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
2908 u_int32_t w = LE_READ_4(sel);
2911 case RSN_SEL(RSN_ASE_8021X_UNSPEC):
2912 return "8021X-UNSPEC";
2913 case RSN_SEL(RSN_ASE_8021X_PSK):
2915 case RSN_SEL(RSN_ASE_NONE):
2923 printrsnie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2930 ie += 2, ielen -= 2;
2932 printf("<v%u", LE_READ_2(ie));
2933 ie += 2, ielen -= 2;
2935 printf(" mc:%s", rsn_cipher(ie));
2936 ie += 4, ielen -= 4;
2938 /* unicast ciphers */
2940 ie += 2, ielen -= 2;
2942 for (; n > 0; n--) {
2943 printf("%s%s", sep, rsn_cipher(ie));
2944 ie += 4, ielen -= 4;
2948 /* key management algorithms */
2950 ie += 2, ielen -= 2;
2952 for (; n > 0; n--) {
2953 printf("%s%s", sep, rsn_keymgmt(ie));
2954 ie += 4, ielen -= 4;
2958 if (ielen > 2) /* optional capabilities */
2959 printf(", caps 0x%x", LE_READ_2(ie));
2965 /* XXX move to a public include file */
2966 #define IEEE80211_WPS_DEV_PASS_ID 0x1012
2967 #define IEEE80211_WPS_SELECTED_REG 0x1041
2968 #define IEEE80211_WPS_SETUP_STATE 0x1044
2969 #define IEEE80211_WPS_UUID_E 0x1047
2970 #define IEEE80211_WPS_VERSION 0x104a
2972 #define BE_READ_2(p) \
2974 ((((const u_int8_t *)(p))[1] ) | \
2975 (((const u_int8_t *)(p))[0] << 8)))
2978 printwpsie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2980 u_int8_t len = ie[1];
2984 static const char *dev_pass_id[] = {
2985 "D", /* Default (PIN) */
2986 "U", /* User-specified */
2987 "M", /* Machine-specified */
2989 "P", /* PushButton */
2990 "R" /* Registrar-specified */
2994 ie +=6, len -= 4; /* NB: len is payload only */
2996 /* WPS IE in Beacon and Probe Resp frames have different fields */
2999 uint16_t tlv_type = BE_READ_2(ie);
3000 uint16_t tlv_len = BE_READ_2(ie + 2);
3002 /* some devices broadcast invalid WPS frames */
3003 if (tlv_len > len) {
3004 printf("bad frame length tlv_type=0x%02x "
3005 "tlv_len=%d len=%d", tlv_type, tlv_len,
3013 case IEEE80211_WPS_VERSION:
3014 printf("v:%d.%d", *ie >> 4, *ie & 0xf);
3016 case IEEE80211_WPS_SETUP_STATE:
3017 /* Only 1 and 2 are valid */
3018 if (*ie == 0 || *ie >= 3)
3021 printf(" st:%s", *ie == 1 ? "N" : "C");
3023 case IEEE80211_WPS_SELECTED_REG:
3024 printf(" sel:%s", *ie ? "T" : "F");
3026 case IEEE80211_WPS_DEV_PASS_ID:
3028 if (n < nitems(dev_pass_id))
3029 printf(" dpi:%s", dev_pass_id[n]);
3031 case IEEE80211_WPS_UUID_E:
3033 for (n = 0; n < (tlv_len - 1); n++)
3034 printf("%02x-", ie[n]);
3035 printf("%02x", ie[n]);
3038 ie += tlv_len, len -= tlv_len;
3045 printtdmaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3048 if (verbose && ielen >= sizeof(struct ieee80211_tdma_param)) {
3049 const struct ieee80211_tdma_param *tdma =
3050 (const struct ieee80211_tdma_param *) ie;
3053 printf("<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>",
3054 tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt,
3055 LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval,
3056 tdma->tdma_inuse[0]);
3061 * Copy the ssid string contents into buf, truncating to fit. If the
3062 * ssid is entirely printable then just copy intact. Otherwise convert
3063 * to hexadecimal. If the result is truncated then replace the last
3064 * three characters with "...".
3067 copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len)
3073 if (essid_len > bufsize)
3077 /* determine printable or not */
3078 for (i = 0, p = essid; i < maxlen; i++, p++) {
3079 if (*p < ' ' || *p > 0x7e)
3082 if (i != maxlen) { /* not printable, print as hex */
3085 strlcpy(buf, "0x", bufsize);
3088 for (i = 0; i < maxlen && bufsize >= 2; i++) {
3089 sprintf(&buf[2+2*i], "%02x", p[i]);
3093 memcpy(&buf[2+2*i-3], "...", 3);
3094 } else { /* printable, truncate as needed */
3095 memcpy(buf, essid, maxlen);
3096 if (maxlen != essid_len)
3097 memcpy(&buf[maxlen-3], "...", 3);
3103 printssid(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3105 char ssid[2*IEEE80211_NWID_LEN+1];
3107 printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid);
3111 printrates(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3118 for (i = 2; i < ielen; i++) {
3119 printf("%s%s%d", sep,
3120 ie[i] & IEEE80211_RATE_BASIC ? "B" : "",
3121 ie[i] & IEEE80211_RATE_VAL);
3128 printcountry(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3130 const struct ieee80211_country_ie *cie =
3131 (const struct ieee80211_country_ie *) ie;
3132 int i, nbands, schan, nchan;
3134 printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]);
3135 nbands = (cie->len - 3) / sizeof(cie->band[0]);
3136 for (i = 0; i < nbands; i++) {
3137 schan = cie->band[i].schan;
3138 nchan = cie->band[i].nchan;
3140 printf(" %u-%u,%u", schan, schan + nchan-1,
3141 cie->band[i].maxtxpwr);
3143 printf(" %u,%u", schan, cie->band[i].maxtxpwr);
3149 iswpaoui(const u_int8_t *frm)
3151 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI);
3155 iswmeinfo(const u_int8_t *frm)
3157 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3158 frm[6] == WME_INFO_OUI_SUBTYPE;
3162 iswmeparam(const u_int8_t *frm)
3164 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3165 frm[6] == WME_PARAM_OUI_SUBTYPE;
3169 isatherosoui(const u_int8_t *frm)
3171 return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI);
3175 istdmaoui(const uint8_t *frm)
3177 return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI);
3181 iswpsoui(const uint8_t *frm)
3183 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPS_OUI_TYPE<<24)|WPA_OUI);
3190 case IEEE80211_ELEMID_FHPARMS: return " FHPARMS";
3191 case IEEE80211_ELEMID_CFPARMS: return " CFPARMS";
3192 case IEEE80211_ELEMID_TIM: return " TIM";
3193 case IEEE80211_ELEMID_IBSSPARMS:return " IBSSPARMS";
3194 case IEEE80211_ELEMID_BSSLOAD: return " BSSLOAD";
3195 case IEEE80211_ELEMID_CHALLENGE:return " CHALLENGE";
3196 case IEEE80211_ELEMID_PWRCNSTR: return " PWRCNSTR";
3197 case IEEE80211_ELEMID_PWRCAP: return " PWRCAP";
3198 case IEEE80211_ELEMID_TPCREQ: return " TPCREQ";
3199 case IEEE80211_ELEMID_TPCREP: return " TPCREP";
3200 case IEEE80211_ELEMID_SUPPCHAN: return " SUPPCHAN";
3201 case IEEE80211_ELEMID_CSA: return " CSA";
3202 case IEEE80211_ELEMID_MEASREQ: return " MEASREQ";
3203 case IEEE80211_ELEMID_MEASREP: return " MEASREP";
3204 case IEEE80211_ELEMID_QUIET: return " QUIET";
3205 case IEEE80211_ELEMID_IBSSDFS: return " IBSSDFS";
3206 case IEEE80211_ELEMID_TPC: return " TPC";
3207 case IEEE80211_ELEMID_CCKM: return " CCKM";
3213 printies(const u_int8_t *vp, int ielen, int maxcols)
3217 case IEEE80211_ELEMID_SSID:
3219 printssid(" SSID", vp, 2+vp[1], maxcols);
3221 case IEEE80211_ELEMID_RATES:
3222 case IEEE80211_ELEMID_XRATES:
3224 printrates(vp[0] == IEEE80211_ELEMID_RATES ?
3225 " RATES" : " XRATES", vp, 2+vp[1], maxcols);
3227 case IEEE80211_ELEMID_DSPARMS:
3229 printf(" DSPARMS<%u>", vp[2]);
3231 case IEEE80211_ELEMID_COUNTRY:
3233 printcountry(" COUNTRY", vp, 2+vp[1], maxcols);
3235 case IEEE80211_ELEMID_ERP:
3237 printf(" ERP<0x%x>", vp[2]);
3239 case IEEE80211_ELEMID_VENDOR:
3241 printwpaie(" WPA", vp, 2+vp[1], maxcols);
3242 else if (iswmeinfo(vp))
3243 printwmeinfo(" WME", vp, 2+vp[1], maxcols);
3244 else if (iswmeparam(vp))
3245 printwmeparam(" WME", vp, 2+vp[1], maxcols);
3246 else if (isatherosoui(vp))
3247 printathie(" ATH", vp, 2+vp[1], maxcols);
3248 else if (iswpsoui(vp))
3249 printwpsie(" WPS", vp, 2+vp[1], maxcols);
3250 else if (istdmaoui(vp))
3251 printtdmaie(" TDMA", vp, 2+vp[1], maxcols);
3253 printie(" VEN", vp, 2+vp[1], maxcols);
3255 case IEEE80211_ELEMID_RSN:
3256 printrsnie(" RSN", vp, 2+vp[1], maxcols);
3258 case IEEE80211_ELEMID_HTCAP:
3259 printhtcap(" HTCAP", vp, 2+vp[1], maxcols);
3261 case IEEE80211_ELEMID_HTINFO:
3263 printhtinfo(" HTINFO", vp, 2+vp[1], maxcols);
3265 case IEEE80211_ELEMID_MESHID:
3267 printssid(" MESHID", vp, 2+vp[1], maxcols);
3269 case IEEE80211_ELEMID_MESHCONF:
3270 printmeshconf(" MESHCONF", vp, 2+vp[1], maxcols);
3272 case IEEE80211_ELEMID_VHT_CAP:
3273 printvhtcap(" VHTCAP", vp, 2+vp[1], maxcols);
3275 case IEEE80211_ELEMID_VHT_OPMODE:
3276 printvhtinfo(" VHTOPMODE", vp, 2+vp[1], maxcols);
3278 case IEEE80211_ELEMID_VHT_PWR_ENV:
3279 printvhtpwrenv(" VHTPWRENV", vp, 2+vp[1], maxcols);
3281 case IEEE80211_ELEMID_BSSLOAD:
3282 printbssload(" BSSLOAD", vp, 2+vp[1], maxcols);
3284 case IEEE80211_ELEMID_APCHANREP:
3285 printapchanrep(" APCHANREP", vp, 2+vp[1], maxcols);
3289 printie(iename(vp[0]), vp, 2+vp[1], maxcols);
3298 printmimo(const struct ieee80211_mimo_info *mi)
3300 /* NB: don't muddy display unless there's something to show */
3301 if (mi->rssi[0] != 0 || mi->rssi[1] != 0 || mi->rssi[2] != 0) {
3302 /* XXX ignore EVM for now */
3303 printf(" (rssi %d:%d:%d nf %d:%d:%d)",
3304 mi->rssi[0], mi->rssi[1], mi->rssi[2],
3305 mi->noise[0], mi->noise[1], mi->noise[2]);
3312 uint8_t buf[24*1024];
3313 char ssid[IEEE80211_NWID_LEN+1];
3315 int len, ssidmax, idlen;
3317 if (get80211len(s, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0)
3318 errx(1, "unable to get scan results");
3319 if (len < sizeof(struct ieee80211req_scan_result))
3324 ssidmax = verbose ? IEEE80211_NWID_LEN : 14;
3325 printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n"
3326 , ssidmax, ssidmax, "SSID/MESH ID"
3336 const struct ieee80211req_scan_result *sr;
3337 const uint8_t *vp, *idp;
3339 sr = (const struct ieee80211req_scan_result *) cp;
3340 vp = cp + sr->isr_ie_off;
3341 if (sr->isr_meshid_len) {
3342 idp = vp + sr->isr_ssid_len;
3343 idlen = sr->isr_meshid_len;
3346 idlen = sr->isr_ssid_len;
3348 printf("%-*.*s %s %3d %3dM %4d:%-4d %4d %-4.4s"
3350 , copy_essid(ssid, ssidmax, idp, idlen)
3352 , ether_ntoa((const struct ether_addr *) sr->isr_bssid)
3353 , ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags)
3354 , getmaxrate(sr->isr_rates, sr->isr_nrates)
3355 , (sr->isr_rssi/2)+sr->isr_noise, sr->isr_noise
3357 , getcaps(sr->isr_capinfo)
3359 printies(vp + sr->isr_ssid_len + sr->isr_meshid_len,
3360 sr->isr_ie_len, 24);
3362 cp += sr->isr_len, len -= sr->isr_len;
3363 } while (len >= sizeof(struct ieee80211req_scan_result));
3367 scan_and_wait(int s)
3369 struct ieee80211_scan_req sr;
3370 struct ieee80211req ireq;
3373 sroute = socket(PF_ROUTE, SOCK_RAW, 0);
3375 perror("socket(PF_ROUTE,SOCK_RAW)");
3378 (void) memset(&ireq, 0, sizeof(ireq));
3379 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
3380 ireq.i_type = IEEE80211_IOC_SCAN_REQ;
3382 memset(&sr, 0, sizeof(sr));
3383 sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE
3384 | IEEE80211_IOC_SCAN_BGSCAN
3385 | IEEE80211_IOC_SCAN_NOPICK
3386 | IEEE80211_IOC_SCAN_ONCE;
3387 sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER;
3391 ireq.i_len = sizeof(sr);
3393 * NB: only root can trigger a scan so ignore errors. Also ignore
3394 * possible errors from net80211, even if no new scan could be
3395 * started there might still be a valid scan cache.
3397 if (ioctl(s, SIOCS80211, &ireq) == 0) {
3399 struct if_announcemsghdr *ifan;
3400 struct rt_msghdr *rtm;
3403 if (read(sroute, buf, sizeof(buf)) < 0) {
3404 perror("read(PF_ROUTE)");
3407 rtm = (struct rt_msghdr *) buf;
3408 if (rtm->rtm_version != RTM_VERSION)
3410 ifan = (struct if_announcemsghdr *) rtm;
3411 } while (rtm->rtm_type != RTM_IEEE80211 ||
3412 ifan->ifan_what != RTM_IEEE80211_SCAN);
3418 DECL_CMD_FUNC(set80211scan, val, d)
3424 static enum ieee80211_opmode get80211opmode(int s);
3427 gettxseq(const struct ieee80211req_sta_info *si)
3431 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3432 return si->isi_txseqs[0];
3433 /* XXX not right but usually what folks want */
3435 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3436 if (si->isi_txseqs[i] > txseq)
3437 txseq = si->isi_txseqs[i];
3442 getrxseq(const struct ieee80211req_sta_info *si)
3446 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3447 return si->isi_rxseqs[0];
3448 /* XXX not right but usually what folks want */
3450 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3451 if (si->isi_rxseqs[i] > rxseq)
3452 rxseq = si->isi_rxseqs[i];
3457 list_stations(int s)
3460 struct ieee80211req_sta_req req;
3461 uint8_t buf[24*1024];
3463 enum ieee80211_opmode opmode = get80211opmode(s);
3467 /* broadcast address =>'s get all stations */
3468 (void) memset(u.req.is_u.macaddr, 0xff, IEEE80211_ADDR_LEN);
3469 if (opmode == IEEE80211_M_STA) {
3471 * Get information about the associated AP.
3473 (void) get80211(s, IEEE80211_IOC_BSSID,
3474 u.req.is_u.macaddr, IEEE80211_ADDR_LEN);
3476 if (get80211len(s, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0)
3477 errx(1, "unable to get station information");
3478 if (len < sizeof(struct ieee80211req_sta_info))
3483 if (opmode == IEEE80211_M_MBSS)
3484 printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n"
3497 printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-7s\n"
3509 cp = (const uint8_t *) u.req.info;
3511 const struct ieee80211req_sta_info *si;
3513 si = (const struct ieee80211req_sta_info *) cp;
3514 if (si->isi_len < sizeof(*si))
3516 if (opmode == IEEE80211_M_MBSS)
3517 printf("%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d"
3518 , ether_ntoa((const struct ether_addr*)
3520 , ieee80211_mhz2ieee(si->isi_freq,
3524 , mesh_linkstate_string(si->isi_peerstate)
3532 printf("%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-7.7s"
3533 , ether_ntoa((const struct ether_addr*)
3535 , IEEE80211_AID(si->isi_associd)
3536 , ieee80211_mhz2ieee(si->isi_freq,
3543 , getcaps(si->isi_capinfo)
3544 , getflags(si->isi_state)
3546 printies(cp + si->isi_ie_off, si->isi_ie_len, 24);
3547 printmimo(&si->isi_mimo);
3549 cp += si->isi_len, len -= si->isi_len;
3550 } while (len >= sizeof(struct ieee80211req_sta_info));
3554 mesh_linkstate_string(uint8_t state)
3556 static const char *state_names[] = {
3565 if (state >= nitems(state_names)) {
3566 static char buf[10];
3567 snprintf(buf, sizeof(buf), "#%u", state);
3570 return state_names[state];
3574 get_chaninfo(const struct ieee80211_channel *c, int precise,
3575 char buf[], size_t bsize)
3578 if (IEEE80211_IS_CHAN_FHSS(c))
3579 strlcat(buf, " FHSS", bsize);
3580 if (IEEE80211_IS_CHAN_A(c))
3581 strlcat(buf, " 11a", bsize);
3582 else if (IEEE80211_IS_CHAN_ANYG(c))
3583 strlcat(buf, " 11g", bsize);
3584 else if (IEEE80211_IS_CHAN_B(c))
3585 strlcat(buf, " 11b", bsize);
3586 if (IEEE80211_IS_CHAN_HALF(c))
3587 strlcat(buf, "/10MHz", bsize);
3588 if (IEEE80211_IS_CHAN_QUARTER(c))
3589 strlcat(buf, "/5MHz", bsize);
3590 if (IEEE80211_IS_CHAN_TURBO(c))
3591 strlcat(buf, " Turbo", bsize);
3593 if (IEEE80211_IS_CHAN_HT20(c))
3594 strlcat(buf, " ht/20", bsize);
3595 else if (IEEE80211_IS_CHAN_HT40D(c))
3596 strlcat(buf, " ht/40-", bsize);
3597 else if (IEEE80211_IS_CHAN_HT40U(c))
3598 strlcat(buf, " ht/40+", bsize);
3600 if (IEEE80211_IS_CHAN_HT(c))
3601 strlcat(buf, " ht", bsize);
3607 print_chaninfo(const struct ieee80211_channel *c, int verb)
3612 printf("Channel %3u : %u%c%c%c%c%c MHz%-14.14s",
3613 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
3614 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
3615 IEEE80211_IS_CHAN_DFS(c) ? 'D' : ' ',
3616 IEEE80211_IS_CHAN_RADAR(c) ? 'R' : ' ',
3617 IEEE80211_IS_CHAN_CWINT(c) ? 'I' : ' ',
3618 IEEE80211_IS_CHAN_CACDONE(c) ? 'C' : ' ',
3619 get_chaninfo(c, verb, buf, sizeof(buf)));
3621 printf("Channel %3u : %u%c MHz%-14.14s",
3622 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
3623 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
3624 get_chaninfo(c, verb, buf, sizeof(buf)));
3629 chanpref(const struct ieee80211_channel *c)
3631 if (IEEE80211_IS_CHAN_HT40(c))
3633 if (IEEE80211_IS_CHAN_HT20(c))
3635 if (IEEE80211_IS_CHAN_HALF(c))
3637 if (IEEE80211_IS_CHAN_QUARTER(c))
3639 if (IEEE80211_IS_CHAN_TURBO(c))
3641 if (IEEE80211_IS_CHAN_A(c))
3643 if (IEEE80211_IS_CHAN_G(c))
3645 if (IEEE80211_IS_CHAN_B(c))
3647 if (IEEE80211_IS_CHAN_PUREG(c))
3653 print_channels(int s, const struct ieee80211req_chaninfo *chans,
3654 int allchans, int verb)
3656 struct ieee80211req_chaninfo *achans;
3657 uint8_t reported[IEEE80211_CHAN_BYTES];
3658 const struct ieee80211_channel *c;
3661 achans = malloc(IEEE80211_CHANINFO_SPACE(chans));
3663 errx(1, "no space for active channel list");
3664 achans->ic_nchans = 0;
3665 memset(reported, 0, sizeof(reported));
3667 struct ieee80211req_chanlist active;
3669 if (get80211(s, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0)
3670 errx(1, "unable to get active channel list");
3671 for (i = 0; i < chans->ic_nchans; i++) {
3672 c = &chans->ic_chans[i];
3673 if (!isset(active.ic_channels, c->ic_ieee))
3676 * Suppress compatible duplicates unless
3677 * verbose. The kernel gives us it's
3678 * complete channel list which has separate
3679 * entries for 11g/11b and 11a/turbo.
3681 if (isset(reported, c->ic_ieee) && !verb) {
3682 /* XXX we assume duplicates are adjacent */
3683 achans->ic_chans[achans->ic_nchans-1] = *c;
3685 achans->ic_chans[achans->ic_nchans++] = *c;
3686 setbit(reported, c->ic_ieee);
3690 for (i = 0; i < chans->ic_nchans; i++) {
3691 c = &chans->ic_chans[i];
3692 /* suppress duplicates as above */
3693 if (isset(reported, c->ic_ieee) && !verb) {
3694 /* XXX we assume duplicates are adjacent */
3695 struct ieee80211_channel *a =
3696 &achans->ic_chans[achans->ic_nchans-1];
3697 if (chanpref(c) > chanpref(a))
3700 achans->ic_chans[achans->ic_nchans++] = *c;
3701 setbit(reported, c->ic_ieee);
3705 half = achans->ic_nchans / 2;
3706 if (achans->ic_nchans % 2)
3709 for (i = 0; i < achans->ic_nchans / 2; i++) {
3710 print_chaninfo(&achans->ic_chans[i], verb);
3711 print_chaninfo(&achans->ic_chans[half+i], verb);
3714 if (achans->ic_nchans % 2) {
3715 print_chaninfo(&achans->ic_chans[i], verb);
3722 list_channels(int s, int allchans)
3725 print_channels(s, chaninfo, allchans, verbose);
3729 print_txpow(const struct ieee80211_channel *c)
3731 printf("Channel %3u : %u MHz %3.1f reg %2d ",
3732 c->ic_ieee, c->ic_freq,
3733 c->ic_maxpower/2., c->ic_maxregpower);
3737 print_txpow_verbose(const struct ieee80211_channel *c)
3739 print_chaninfo(c, 1);
3740 printf("min %4.1f dBm max %3.1f dBm reg %2d dBm",
3741 c->ic_minpower/2., c->ic_maxpower/2., c->ic_maxregpower);
3742 /* indicate where regulatory cap limits power use */
3743 if (c->ic_maxpower > 2*c->ic_maxregpower)
3750 struct ieee80211req_chaninfo *achans;
3751 uint8_t reported[IEEE80211_CHAN_BYTES];
3752 struct ieee80211_channel *c, *prev;
3756 achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo));
3758 errx(1, "no space for active channel list");
3759 achans->ic_nchans = 0;
3760 memset(reported, 0, sizeof(reported));
3761 for (i = 0; i < chaninfo->ic_nchans; i++) {
3762 c = &chaninfo->ic_chans[i];
3763 /* suppress duplicates as above */
3764 if (isset(reported, c->ic_ieee) && !verbose) {
3765 /* XXX we assume duplicates are adjacent */
3766 assert(achans->ic_nchans > 0);
3767 prev = &achans->ic_chans[achans->ic_nchans-1];
3768 /* display highest power on channel */
3769 if (c->ic_maxpower > prev->ic_maxpower)
3772 achans->ic_chans[achans->ic_nchans++] = *c;
3773 setbit(reported, c->ic_ieee);
3777 half = achans->ic_nchans / 2;
3778 if (achans->ic_nchans % 2)
3781 for (i = 0; i < achans->ic_nchans / 2; i++) {
3782 print_txpow(&achans->ic_chans[i]);
3783 print_txpow(&achans->ic_chans[half+i]);
3786 if (achans->ic_nchans % 2) {
3787 print_txpow(&achans->ic_chans[i]);
3791 for (i = 0; i < achans->ic_nchans; i++) {
3792 print_txpow_verbose(&achans->ic_chans[i]);
3804 #define IEEE80211_C_BITS \
3805 "\20\1STA\002803ENCAP\7FF\10TURBOP\11IBSS\12PMGT" \
3806 "\13HOSTAP\14AHDEMO\15SWRETRY\16TXPMGT\17SHSLOT\20SHPREAMBLE" \
3807 "\21MONITOR\22DFS\23MBSS\30WPA1\31WPA2\32BURST\33WME\34WDS\36BGSCAN" \
3811 list_capabilities(int s)
3813 struct ieee80211_devcaps_req *dc;
3816 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
3818 dc = malloc(IEEE80211_DEVCAPS_SIZE(1));
3820 errx(1, "no space for device capabilities");
3821 dc->dc_chaninfo.ic_nchans = verbose ? MAXCHAN : 1;
3823 printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS);
3824 if (dc->dc_cryptocaps != 0 || verbose) {
3826 printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS);
3828 if (dc->dc_htcaps != 0 || verbose) {
3830 printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS);
3834 chaninfo = &dc->dc_chaninfo; /* XXX */
3835 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, verbose);
3841 get80211wme(int s, int param, int ac, int *val)
3843 struct ieee80211req ireq;
3845 (void) memset(&ireq, 0, sizeof(ireq));
3846 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
3847 ireq.i_type = param;
3849 if (ioctl(s, SIOCG80211, &ireq) < 0) {
3850 warn("cannot get WME parameter %d, ac %d%s",
3851 param, ac & IEEE80211_WMEPARAM_VAL,
3852 ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : "");
3860 list_wme_aci(int s, const char *tag, int ac)
3864 printf("\t%s", tag);
3866 /* show WME BSS parameters */
3867 if (get80211wme(s, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1)
3868 printf(" cwmin %2u", val);
3869 if (get80211wme(s, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1)
3870 printf(" cwmax %2u", val);
3871 if (get80211wme(s, IEEE80211_IOC_WME_AIFS, ac, &val) != -1)
3872 printf(" aifs %2u", val);
3873 if (get80211wme(s, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1)
3874 printf(" txopLimit %3u", val);
3875 if (get80211wme(s, IEEE80211_IOC_WME_ACM, ac, &val) != -1) {
3882 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
3883 if (get80211wme(s, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) {
3896 static const char *acnames[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
3900 /* display both BSS and local settings */
3901 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) {
3903 if (ac & IEEE80211_WMEPARAM_BSS)
3904 list_wme_aci(s, " ", ac);
3906 list_wme_aci(s, acnames[ac], ac);
3907 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
3908 ac |= IEEE80211_WMEPARAM_BSS;
3911 ac &= ~IEEE80211_WMEPARAM_BSS;
3914 /* display only channel settings */
3915 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++)
3916 list_wme_aci(s, acnames[ac], ac);
3923 const struct ieee80211_roamparam *rp;
3927 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
3928 rp = &roamparams.params[mode];
3929 if (rp->rssi == 0 && rp->rate == 0)
3931 if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) {
3933 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm MCS %2u ",
3934 modename[mode], rp->rssi/2,
3935 rp->rate &~ IEEE80211_RATE_MCS);
3937 LINE_CHECK("roam:%-7.7s rssi %4udBm MCS %2u ",
3938 modename[mode], rp->rssi/2,
3939 rp->rate &~ IEEE80211_RATE_MCS);
3942 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s",
3943 modename[mode], rp->rssi/2, rp->rate/2);
3945 LINE_CHECK("roam:%-7.7s rssi %4udBm rate %2u Mb/s",
3946 modename[mode], rp->rssi/2, rp->rate/2);
3952 list_txparams(int s)
3954 const struct ieee80211_txparam *tp;
3958 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
3959 tp = &txparams.params[mode];
3960 if (tp->mgmtrate == 0 && tp->mcastrate == 0)
3962 if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) {
3963 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
3964 LINE_CHECK("%-7.7s ucast NONE mgmt %2u MCS "
3965 "mcast %2u MCS maxretry %u",
3967 tp->mgmtrate &~ IEEE80211_RATE_MCS,
3968 tp->mcastrate &~ IEEE80211_RATE_MCS,
3971 LINE_CHECK("%-7.7s ucast %2u MCS mgmt %2u MCS "
3972 "mcast %2u MCS maxretry %u",
3974 tp->ucastrate &~ IEEE80211_RATE_MCS,
3975 tp->mgmtrate &~ IEEE80211_RATE_MCS,
3976 tp->mcastrate &~ IEEE80211_RATE_MCS,
3979 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
3980 LINE_CHECK("%-7.7s ucast NONE mgmt %2u Mb/s "
3981 "mcast %2u Mb/s maxretry %u",
3984 tp->mcastrate/2, tp->maxretry);
3986 LINE_CHECK("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s "
3987 "mcast %2u Mb/s maxretry %u",
3989 tp->ucastrate/2, tp->mgmtrate/2,
3990 tp->mcastrate/2, tp->maxretry);
3996 printpolicy(int policy)
3999 case IEEE80211_MACCMD_POLICY_OPEN:
4000 printf("policy: open\n");
4002 case IEEE80211_MACCMD_POLICY_ALLOW:
4003 printf("policy: allow\n");
4005 case IEEE80211_MACCMD_POLICY_DENY:
4006 printf("policy: deny\n");
4008 case IEEE80211_MACCMD_POLICY_RADIUS:
4009 printf("policy: radius\n");
4012 printf("policy: unknown (%u)\n", policy);
4020 struct ieee80211req ireq;
4021 struct ieee80211req_maclist *acllist;
4022 int i, nacls, policy, len;
4026 (void) memset(&ireq, 0, sizeof(ireq));
4027 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name)); /* XXX ?? */
4028 ireq.i_type = IEEE80211_IOC_MACCMD;
4029 ireq.i_val = IEEE80211_MACCMD_POLICY;
4030 if (ioctl(s, SIOCG80211, &ireq) < 0) {
4031 if (errno == EINVAL) {
4032 printf("No acl policy loaded\n");
4035 err(1, "unable to get mac policy");
4037 policy = ireq.i_val;
4038 if (policy == IEEE80211_MACCMD_POLICY_OPEN) {
4040 } else if (policy == IEEE80211_MACCMD_POLICY_ALLOW) {
4042 } else if (policy == IEEE80211_MACCMD_POLICY_DENY) {
4044 } else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) {
4045 c = 'r'; /* NB: should never have entries */
4047 printf("policy: unknown (%u)\n", policy);
4050 if (verbose || c == '?')
4051 printpolicy(policy);
4053 ireq.i_val = IEEE80211_MACCMD_LIST;
4055 if (ioctl(s, SIOCG80211, &ireq) < 0)
4056 err(1, "unable to get mac acl list size");
4057 if (ireq.i_len == 0) { /* NB: no acls */
4058 if (!(verbose || c == '?'))
4059 printpolicy(policy);
4066 err(1, "out of memory for acl list");
4069 if (ioctl(s, SIOCG80211, &ireq) < 0)
4070 err(1, "unable to get mac acl list");
4071 nacls = len / sizeof(*acllist);
4072 acllist = (struct ieee80211req_maclist *) data;
4073 for (i = 0; i < nacls; i++)
4074 printf("%c%s\n", c, ether_ntoa(
4075 (const struct ether_addr *) acllist[i].ml_macaddr));
4080 print_regdomain(const struct ieee80211_regdomain *reg, int verb)
4082 if ((reg->regdomain != 0 &&
4083 reg->regdomain != reg->country) || verb) {
4084 const struct regdomain *rd =
4085 lib80211_regdomain_findbysku(getregdata(), reg->regdomain);
4087 LINE_CHECK("regdomain %d", reg->regdomain);
4089 LINE_CHECK("regdomain %s", rd->name);
4091 if (reg->country != 0 || verb) {
4092 const struct country *cc =
4093 lib80211_country_findbycc(getregdata(), reg->country);
4095 LINE_CHECK("country %d", reg->country);
4097 LINE_CHECK("country %s", cc->isoname);
4099 if (reg->location == 'I')
4100 LINE_CHECK("indoor");
4101 else if (reg->location == 'O')
4102 LINE_CHECK("outdoor");
4104 LINE_CHECK("anywhere");
4112 list_regdomain(int s, int channelsalso)
4118 print_regdomain(®domain, 1);
4120 print_channels(s, chaninfo, 1/*allchans*/, 1/*verbose*/);
4122 print_regdomain(®domain, verbose);
4128 struct ieee80211req ireq;
4129 struct ieee80211req_mesh_route routes[128];
4130 struct ieee80211req_mesh_route *rt;
4132 (void) memset(&ireq, 0, sizeof(ireq));
4133 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4134 ireq.i_type = IEEE80211_IOC_MESH_RTCMD;
4135 ireq.i_val = IEEE80211_MESH_RTCMD_LIST;
4136 ireq.i_data = &routes;
4137 ireq.i_len = sizeof(routes);
4138 if (ioctl(s, SIOCG80211, &ireq) < 0)
4139 err(1, "unable to get the Mesh routing table");
4141 printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n"
4150 for (rt = &routes[0]; rt - &routes[0] < ireq.i_len / sizeof(*rt); rt++){
4152 ether_ntoa((const struct ether_addr *)rt->imr_dest));
4153 printf("%s %4u %4u %6u %6u %c%c\n",
4154 ether_ntoa((const struct ether_addr *)rt->imr_nexthop),
4155 rt->imr_nhops, rt->imr_metric, rt->imr_lifetime,
4157 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_DISCOVER) ?
4159 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_VALID) ?
4161 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ?
4163 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_GATE) ?
4169 DECL_CMD_FUNC(set80211list, arg, d)
4171 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
4175 if (iseq(arg, "sta"))
4177 else if (iseq(arg, "scan") || iseq(arg, "ap"))
4179 else if (iseq(arg, "chan") || iseq(arg, "freq"))
4180 list_channels(s, 1);
4181 else if (iseq(arg, "active"))
4182 list_channels(s, 0);
4183 else if (iseq(arg, "keys"))
4185 else if (iseq(arg, "caps"))
4186 list_capabilities(s);
4187 else if (iseq(arg, "wme") || iseq(arg, "wmm"))
4189 else if (iseq(arg, "mac"))
4191 else if (iseq(arg, "txpow"))
4193 else if (iseq(arg, "roam"))
4195 else if (iseq(arg, "txparam") || iseq(arg, "txparm"))
4197 else if (iseq(arg, "regdomain"))
4198 list_regdomain(s, 1);
4199 else if (iseq(arg, "countries"))
4201 else if (iseq(arg, "mesh"))
4204 errx(1, "Don't know how to list %s for %s", arg, name);
4209 static enum ieee80211_opmode
4210 get80211opmode(int s)
4212 struct ifmediareq ifmr;
4214 (void) memset(&ifmr, 0, sizeof(ifmr));
4215 (void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
4217 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) {
4218 if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) {
4219 if (ifmr.ifm_current & IFM_FLAG0)
4220 return IEEE80211_M_AHDEMO;
4222 return IEEE80211_M_IBSS;
4224 if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP)
4225 return IEEE80211_M_HOSTAP;
4226 if (ifmr.ifm_current & IFM_IEEE80211_IBSS)
4227 return IEEE80211_M_IBSS;
4228 if (ifmr.ifm_current & IFM_IEEE80211_MONITOR)
4229 return IEEE80211_M_MONITOR;
4230 if (ifmr.ifm_current & IFM_IEEE80211_MBSS)
4231 return IEEE80211_M_MBSS;
4233 return IEEE80211_M_STA;
4238 printcipher(int s, struct ieee80211req *ireq, int keylenop)
4240 switch (ireq->i_val) {
4241 case IEEE80211_CIPHER_WEP:
4242 ireq->i_type = keylenop;
4243 if (ioctl(s, SIOCG80211, ireq) != -1)
4245 ireq->i_len <= 5 ? "40" :
4246 ireq->i_len <= 13 ? "104" : "128");
4250 case IEEE80211_CIPHER_TKIP:
4253 case IEEE80211_CIPHER_AES_OCB:
4256 case IEEE80211_CIPHER_AES_CCM:
4259 case IEEE80211_CIPHER_CKIP:
4262 case IEEE80211_CIPHER_NONE:
4266 printf("UNKNOWN (0x%x)", ireq->i_val);
4273 printkey(const struct ieee80211req_key *ik)
4275 static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
4276 u_int keylen = ik->ik_keylen;
4279 printcontents = printkeys &&
4280 (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose);
4283 switch (ik->ik_type) {
4284 case IEEE80211_CIPHER_WEP:
4286 LINE_CHECK("wepkey %u:%s", ik->ik_keyix+1,
4287 keylen <= 5 ? "40-bit" :
4288 keylen <= 13 ? "104-bit" : "128-bit");
4290 case IEEE80211_CIPHER_TKIP:
4292 keylen -= 128/8; /* ignore MIC for now */
4293 LINE_CHECK("TKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4295 case IEEE80211_CIPHER_AES_OCB:
4296 LINE_CHECK("AES-OCB %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4298 case IEEE80211_CIPHER_AES_CCM:
4299 LINE_CHECK("AES-CCM %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4301 case IEEE80211_CIPHER_CKIP:
4302 LINE_CHECK("CKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4304 case IEEE80211_CIPHER_NONE:
4305 LINE_CHECK("NULL %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4308 LINE_CHECK("UNKNOWN (0x%x) %u:%u-bit",
4309 ik->ik_type, ik->ik_keyix+1, 8*keylen);
4312 if (printcontents) {
4316 for (i = 0; i < keylen; i++)
4317 printf("%02x", ik->ik_keydata[i]);
4319 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4320 (ik->ik_keyrsc != 0 || verbose))
4321 printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc);
4322 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4323 (ik->ik_keytsc != 0 || verbose))
4324 printf(" tsc %ju", (uintmax_t)ik->ik_keytsc);
4325 if (ik->ik_flags != 0 && verbose) {
4326 const char *sep = " ";
4328 if (ik->ik_flags & IEEE80211_KEY_XMIT)
4329 printf("%stx", sep), sep = "+";
4330 if (ik->ik_flags & IEEE80211_KEY_RECV)
4331 printf("%srx", sep), sep = "+";
4332 if (ik->ik_flags & IEEE80211_KEY_DEFAULT)
4333 printf("%sdef", sep), sep = "+";
4340 printrate(const char *tag, int v, int defrate, int defmcs)
4342 if ((v & IEEE80211_RATE_MCS) == 0) {
4345 LINE_CHECK("%s %d.5", tag, v/2);
4347 LINE_CHECK("%s %d", tag, v/2);
4351 LINE_CHECK("%s %d", tag, v &~ 0x80);
4356 getid(int s, int ix, void *data, size_t len, int *plen, int mesh)
4358 struct ieee80211req ireq;
4360 (void) memset(&ireq, 0, sizeof(ireq));
4361 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4362 ireq.i_type = (!mesh) ? IEEE80211_IOC_SSID : IEEE80211_IOC_MESH_ID;
4366 if (ioctl(s, SIOCG80211, &ireq) < 0)
4373 ieee80211_status(int s)
4375 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
4376 enum ieee80211_opmode opmode = get80211opmode(s);
4377 int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode;
4379 const struct ieee80211_channel *c;
4380 const struct ieee80211_roamparam *rp;
4381 const struct ieee80211_txparam *tp;
4383 if (getid(s, -1, data, sizeof(data), &len, 0) < 0) {
4384 /* If we can't get the SSID, this isn't an 802.11 device. */
4389 * Invalidate cached state so printing status for multiple
4390 * if's doesn't reuse the first interfaces' cached state.
4399 if (opmode == IEEE80211_M_MBSS) {
4401 getid(s, 0, data, sizeof(data), &len, 1);
4402 print_string(data, len);
4404 if (get80211val(s, IEEE80211_IOC_NUMSSIDS, &num) < 0)
4408 for (i = 0; i < num; i++) {
4409 if (getid(s, i, data, sizeof(data), &len, 0) >= 0 && len > 0) {
4410 printf(" %d:", i + 1);
4411 print_string(data, len);
4415 print_string(data, len);
4418 if (c->ic_freq != IEEE80211_CHAN_ANY) {
4420 printf(" channel %d (%u MHz%s)", c->ic_ieee, c->ic_freq,
4421 get_chaninfo(c, 1, buf, sizeof(buf)));
4423 printf(" channel UNDEF");
4425 if (get80211(s, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 &&
4426 (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose))
4427 printf(" bssid %s", ether_ntoa((struct ether_addr *)data));
4429 if (get80211len(s, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) {
4430 printf("\n\tstationname ");
4431 print_string(data, len);
4434 spacer = ' '; /* force first break */
4437 list_regdomain(s, 0);
4440 if (get80211val(s, IEEE80211_IOC_AUTHMODE, &val) != -1) {
4442 case IEEE80211_AUTH_NONE:
4443 LINE_CHECK("authmode NONE");
4445 case IEEE80211_AUTH_OPEN:
4446 LINE_CHECK("authmode OPEN");
4448 case IEEE80211_AUTH_SHARED:
4449 LINE_CHECK("authmode SHARED");
4451 case IEEE80211_AUTH_8021X:
4452 LINE_CHECK("authmode 802.1x");
4454 case IEEE80211_AUTH_WPA:
4455 if (get80211val(s, IEEE80211_IOC_WPA, &wpa) < 0)
4456 wpa = 1; /* default to WPA1 */
4459 LINE_CHECK("authmode WPA2/802.11i");
4462 LINE_CHECK("authmode WPA1+WPA2/802.11i");
4465 LINE_CHECK("authmode WPA");
4469 case IEEE80211_AUTH_AUTO:
4470 LINE_CHECK("authmode AUTO");
4473 LINE_CHECK("authmode UNKNOWN (0x%x)", val);
4478 if (wpa || verbose) {
4479 if (get80211val(s, IEEE80211_IOC_WPS, &val) != -1) {
4485 if (get80211val(s, IEEE80211_IOC_TSN, &val) != -1) {
4491 if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) {
4493 LINE_CHECK("countermeasures");
4495 LINE_CHECK("-countermeasures");
4498 /* XXX not interesting with WPA done in user space */
4499 ireq.i_type = IEEE80211_IOC_KEYMGTALGS;
4500 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4503 ireq.i_type = IEEE80211_IOC_MCASTCIPHER;
4504 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4505 LINE_CHECK("mcastcipher ");
4506 printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN);
4510 ireq.i_type = IEEE80211_IOC_UCASTCIPHER;
4511 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4512 LINE_CHECK("ucastcipher ");
4513 printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN);
4517 ireq.i_type = IEEE80211_IOC_RSNCAPS;
4518 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4519 LINE_CHECK("RSN caps 0x%x", ireq.i_val);
4524 ireq.i_type = IEEE80211_IOC_UCASTCIPHERS;
4525 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4530 if (get80211val(s, IEEE80211_IOC_WEP, &wepmode) != -1 &&
4531 wepmode != IEEE80211_WEP_NOSUP) {
4534 case IEEE80211_WEP_OFF:
4535 LINE_CHECK("privacy OFF");
4537 case IEEE80211_WEP_ON:
4538 LINE_CHECK("privacy ON");
4540 case IEEE80211_WEP_MIXED:
4541 LINE_CHECK("privacy MIXED");
4544 LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode);
4549 * If we get here then we've got WEP support so we need
4550 * to print WEP status.
4553 if (get80211val(s, IEEE80211_IOC_WEPTXKEY, &val) < 0) {
4554 warn("WEP support, but no tx key!");
4558 LINE_CHECK("deftxkey %d", val+1);
4559 else if (wepmode != IEEE80211_WEP_OFF || verbose)
4560 LINE_CHECK("deftxkey UNDEF");
4562 if (get80211val(s, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) {
4563 warn("WEP support, but no NUMWEPKEYS support!");
4567 for (i = 0; i < num; i++) {
4568 struct ieee80211req_key ik;
4570 memset(&ik, 0, sizeof(ik));
4572 if (get80211(s, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) {
4573 warn("WEP support, but can get keys!");
4576 if (ik.ik_keylen != 0) {
4586 if (get80211val(s, IEEE80211_IOC_POWERSAVE, &val) != -1 &&
4587 val != IEEE80211_POWERSAVE_NOSUP ) {
4588 if (val != IEEE80211_POWERSAVE_OFF || verbose) {
4590 case IEEE80211_POWERSAVE_OFF:
4591 LINE_CHECK("powersavemode OFF");
4593 case IEEE80211_POWERSAVE_CAM:
4594 LINE_CHECK("powersavemode CAM");
4596 case IEEE80211_POWERSAVE_PSP:
4597 LINE_CHECK("powersavemode PSP");
4599 case IEEE80211_POWERSAVE_PSP_CAM:
4600 LINE_CHECK("powersavemode PSP-CAM");
4603 if (get80211val(s, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1)
4604 LINE_CHECK("powersavesleep %d", val);
4608 if (get80211val(s, IEEE80211_IOC_TXPOWER, &val) != -1) {
4610 LINE_CHECK("txpower %d.5", val/2);
4612 LINE_CHECK("txpower %d", val/2);
4615 if (get80211val(s, IEEE80211_IOC_TXPOWMAX, &val) != -1)
4616 LINE_CHECK("txpowmax %.1f", val/2.);
4619 if (get80211val(s, IEEE80211_IOC_DOTD, &val) != -1) {
4623 LINE_CHECK("-dotd");
4626 if (get80211val(s, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) {
4627 if (val != IEEE80211_RTS_MAX || verbose)
4628 LINE_CHECK("rtsthreshold %d", val);
4631 if (get80211val(s, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) {
4632 if (val != IEEE80211_FRAG_MAX || verbose)
4633 LINE_CHECK("fragthreshold %d", val);
4635 if (opmode == IEEE80211_M_STA || verbose) {
4636 if (get80211val(s, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) {
4637 if (val != IEEE80211_HWBMISS_MAX || verbose)
4638 LINE_CHECK("bmiss %d", val);
4644 tp = &txparams.params[chan2mode(c)];
4645 printrate("ucastrate", tp->ucastrate,
4646 IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE);
4647 printrate("mcastrate", tp->mcastrate, 2*1,
4648 IEEE80211_RATE_MCS|0);
4649 printrate("mgmtrate", tp->mgmtrate, 2*1,
4650 IEEE80211_RATE_MCS|0);
4651 if (tp->maxretry != 6) /* XXX */
4652 LINE_CHECK("maxretry %d", tp->maxretry);
4658 bgscaninterval = -1;
4659 (void) get80211val(s, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval);
4661 if (get80211val(s, IEEE80211_IOC_SCANVALID, &val) != -1) {
4662 if (val != bgscaninterval || verbose)
4663 LINE_CHECK("scanvalid %u", val);
4667 if (get80211val(s, IEEE80211_IOC_BGSCAN, &bgscan) != -1) {
4669 LINE_CHECK("bgscan");
4671 LINE_CHECK("-bgscan");
4673 if (bgscan || verbose) {
4674 if (bgscaninterval != -1)
4675 LINE_CHECK("bgscanintvl %u", bgscaninterval);
4676 if (get80211val(s, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1)
4677 LINE_CHECK("bgscanidle %u", val);
4680 rp = &roamparams.params[chan2mode(c)];
4682 LINE_CHECK("roam:rssi %u.5", rp->rssi/2);
4684 LINE_CHECK("roam:rssi %u", rp->rssi/2);
4685 LINE_CHECK("roam:rate %u", rp->rate/2);
4693 if (IEEE80211_IS_CHAN_ANYG(c) || verbose) {
4694 if (get80211val(s, IEEE80211_IOC_PUREG, &val) != -1) {
4696 LINE_CHECK("pureg");
4698 LINE_CHECK("-pureg");
4700 if (get80211val(s, IEEE80211_IOC_PROTMODE, &val) != -1) {
4702 case IEEE80211_PROTMODE_OFF:
4703 LINE_CHECK("protmode OFF");
4705 case IEEE80211_PROTMODE_CTS:
4706 LINE_CHECK("protmode CTS");
4708 case IEEE80211_PROTMODE_RTSCTS:
4709 LINE_CHECK("protmode RTSCTS");
4712 LINE_CHECK("protmode UNKNOWN (0x%x)", val);
4718 if (IEEE80211_IS_CHAN_HT(c) || verbose) {
4720 switch (htconf & 3) {
4733 if (get80211val(s, IEEE80211_IOC_HTCOMPAT, &val) != -1) {
4735 LINE_CHECK("-htcompat");
4737 LINE_CHECK("htcompat");
4739 if (get80211val(s, IEEE80211_IOC_AMPDU, &val) != -1) {
4742 LINE_CHECK("-ampdu");
4745 LINE_CHECK("ampdutx -ampdurx");
4748 LINE_CHECK("-ampdutx ampdurx");
4752 LINE_CHECK("ampdu");
4756 if (get80211val(s, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) {
4758 case IEEE80211_HTCAP_MAXRXAMPDU_8K:
4759 LINE_CHECK("ampdulimit 8k");
4761 case IEEE80211_HTCAP_MAXRXAMPDU_16K:
4762 LINE_CHECK("ampdulimit 16k");
4764 case IEEE80211_HTCAP_MAXRXAMPDU_32K:
4765 LINE_CHECK("ampdulimit 32k");
4767 case IEEE80211_HTCAP_MAXRXAMPDU_64K:
4768 LINE_CHECK("ampdulimit 64k");
4772 if (get80211val(s, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) {
4774 case IEEE80211_HTCAP_MPDUDENSITY_NA:
4776 LINE_CHECK("ampdudensity NA");
4778 case IEEE80211_HTCAP_MPDUDENSITY_025:
4779 LINE_CHECK("ampdudensity .25");
4781 case IEEE80211_HTCAP_MPDUDENSITY_05:
4782 LINE_CHECK("ampdudensity .5");
4784 case IEEE80211_HTCAP_MPDUDENSITY_1:
4785 LINE_CHECK("ampdudensity 1");
4787 case IEEE80211_HTCAP_MPDUDENSITY_2:
4788 LINE_CHECK("ampdudensity 2");
4790 case IEEE80211_HTCAP_MPDUDENSITY_4:
4791 LINE_CHECK("ampdudensity 4");
4793 case IEEE80211_HTCAP_MPDUDENSITY_8:
4794 LINE_CHECK("ampdudensity 8");
4796 case IEEE80211_HTCAP_MPDUDENSITY_16:
4797 LINE_CHECK("ampdudensity 16");
4801 if (get80211val(s, IEEE80211_IOC_AMSDU, &val) != -1) {
4804 LINE_CHECK("-amsdu");
4807 LINE_CHECK("amsdutx -amsdurx");
4810 LINE_CHECK("-amsdutx amsdurx");
4814 LINE_CHECK("amsdu");
4818 /* XXX amsdu limit */
4819 if (get80211val(s, IEEE80211_IOC_SHORTGI, &val) != -1) {
4821 LINE_CHECK("shortgi");
4823 LINE_CHECK("-shortgi");
4825 if (get80211val(s, IEEE80211_IOC_HTPROTMODE, &val) != -1) {
4826 if (val == IEEE80211_PROTMODE_OFF)
4827 LINE_CHECK("htprotmode OFF");
4828 else if (val != IEEE80211_PROTMODE_RTSCTS)
4829 LINE_CHECK("htprotmode UNKNOWN (0x%x)", val);
4831 LINE_CHECK("htprotmode RTSCTS");
4833 if (get80211val(s, IEEE80211_IOC_PUREN, &val) != -1) {
4835 LINE_CHECK("puren");
4837 LINE_CHECK("-puren");
4839 if (get80211val(s, IEEE80211_IOC_SMPS, &val) != -1) {
4840 if (val == IEEE80211_HTCAP_SMPS_DYNAMIC)
4841 LINE_CHECK("smpsdyn");
4842 else if (val == IEEE80211_HTCAP_SMPS_ENA)
4845 LINE_CHECK("-smps");
4847 if (get80211val(s, IEEE80211_IOC_RIFS, &val) != -1) {
4851 LINE_CHECK("-rifs");
4853 if (get80211val(s, IEEE80211_IOC_STBC, &val) != -1) {
4856 LINE_CHECK("-stbc");
4859 LINE_CHECK("stbctx -stbcrx");
4862 LINE_CHECK("-stbctx stbcrx");
4872 if (get80211val(s, IEEE80211_IOC_WME, &wme) != -1) {
4880 if (get80211val(s, IEEE80211_IOC_BURST, &val) != -1) {
4882 LINE_CHECK("burst");
4884 LINE_CHECK("-burst");
4887 if (get80211val(s, IEEE80211_IOC_FF, &val) != -1) {
4893 if (get80211val(s, IEEE80211_IOC_TURBOP, &val) != -1) {
4895 LINE_CHECK("dturbo");
4897 LINE_CHECK("-dturbo");
4899 if (get80211val(s, IEEE80211_IOC_DWDS, &val) != -1) {
4903 LINE_CHECK("-dwds");
4906 if (opmode == IEEE80211_M_HOSTAP) {
4907 if (get80211val(s, IEEE80211_IOC_HIDESSID, &val) != -1) {
4909 LINE_CHECK("hidessid");
4911 LINE_CHECK("-hidessid");
4913 if (get80211val(s, IEEE80211_IOC_APBRIDGE, &val) != -1) {
4915 LINE_CHECK("-apbridge");
4917 LINE_CHECK("apbridge");
4919 if (get80211val(s, IEEE80211_IOC_DTIM_PERIOD, &val) != -1)
4920 LINE_CHECK("dtimperiod %u", val);
4922 if (get80211val(s, IEEE80211_IOC_DOTH, &val) != -1) {
4924 LINE_CHECK("-doth");
4928 if (get80211val(s, IEEE80211_IOC_DFS, &val) != -1) {
4934 if (get80211val(s, IEEE80211_IOC_INACTIVITY, &val) != -1) {
4936 LINE_CHECK("-inact");
4938 LINE_CHECK("inact");
4941 if (get80211val(s, IEEE80211_IOC_ROAMING, &val) != -1) {
4942 if (val != IEEE80211_ROAMING_AUTO || verbose) {
4944 case IEEE80211_ROAMING_DEVICE:
4945 LINE_CHECK("roaming DEVICE");
4947 case IEEE80211_ROAMING_AUTO:
4948 LINE_CHECK("roaming AUTO");
4950 case IEEE80211_ROAMING_MANUAL:
4951 LINE_CHECK("roaming MANUAL");
4954 LINE_CHECK("roaming UNKNOWN (0x%x)",
4962 if (opmode == IEEE80211_M_AHDEMO) {
4963 if (get80211val(s, IEEE80211_IOC_TDMA_SLOT, &val) != -1)
4964 LINE_CHECK("tdmaslot %u", val);
4965 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1)
4966 LINE_CHECK("tdmaslotcnt %u", val);
4967 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1)
4968 LINE_CHECK("tdmaslotlen %u", val);
4969 if (get80211val(s, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1)
4970 LINE_CHECK("tdmabintval %u", val);
4971 } else if (get80211val(s, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) {
4972 /* XXX default define not visible */
4973 if (val != 100 || verbose)
4974 LINE_CHECK("bintval %u", val);
4977 if (wme && verbose) {
4982 if (opmode == IEEE80211_M_MBSS) {
4983 if (get80211val(s, IEEE80211_IOC_MESH_TTL, &val) != -1) {
4984 LINE_CHECK("meshttl %u", val);
4986 if (get80211val(s, IEEE80211_IOC_MESH_AP, &val) != -1) {
4988 LINE_CHECK("meshpeering");
4990 LINE_CHECK("-meshpeering");
4992 if (get80211val(s, IEEE80211_IOC_MESH_FWRD, &val) != -1) {
4994 LINE_CHECK("meshforward");
4996 LINE_CHECK("-meshforward");
4998 if (get80211val(s, IEEE80211_IOC_MESH_GATE, &val) != -1) {
5000 LINE_CHECK("meshgate");
5002 LINE_CHECK("-meshgate");
5004 if (get80211len(s, IEEE80211_IOC_MESH_PR_METRIC, data, 12,
5007 LINE_CHECK("meshmetric %s", data);
5009 if (get80211len(s, IEEE80211_IOC_MESH_PR_PATH, data, 12,
5012 LINE_CHECK("meshpath %s", data);
5014 if (get80211val(s, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) {
5016 case IEEE80211_HWMP_ROOTMODE_DISABLED:
5017 LINE_CHECK("hwmprootmode DISABLED");
5019 case IEEE80211_HWMP_ROOTMODE_NORMAL:
5020 LINE_CHECK("hwmprootmode NORMAL");
5022 case IEEE80211_HWMP_ROOTMODE_PROACTIVE:
5023 LINE_CHECK("hwmprootmode PROACTIVE");
5025 case IEEE80211_HWMP_ROOTMODE_RANN:
5026 LINE_CHECK("hwmprootmode RANN");
5029 LINE_CHECK("hwmprootmode UNKNOWN(%d)", val);
5033 if (get80211val(s, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) {
5034 LINE_CHECK("hwmpmaxhops %u", val);
5042 get80211(int s, int type, void *data, int len)
5045 return (lib80211_get80211(s, name, type, data, len));
5049 get80211len(int s, int type, void *data, int len, int *plen)
5052 return (lib80211_get80211len(s, name, type, data, len, plen));
5056 get80211val(int s, int type, int *val)
5059 return (lib80211_get80211val(s, name, type, val));
5063 set80211(int s, int type, int val, int len, void *data)
5067 ret = lib80211_set80211(s, name, type, val, len, data);
5069 err(1, "SIOCS80211");
5073 get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
5081 hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x');
5087 if (sep != NULL && strchr(sep, *val) != NULL) {
5092 if (!isxdigit((u_char)val[0])) {
5093 warnx("bad hexadecimal digits");
5096 if (!isxdigit((u_char)val[1])) {
5097 warnx("odd count hexadecimal digits");
5101 if (p >= buf + len) {
5103 warnx("hexadecimal digits too long");
5105 warnx("string too long");
5109 #define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
5110 *p++ = (tohex((u_char)val[0]) << 4) |
5111 tohex((u_char)val[1]);
5118 /* The string "-" is treated as the empty string. */
5119 if (!hexstr && len == 1 && buf[0] == '-') {
5121 memset(buf, 0, *lenp);
5122 } else if (len < *lenp)
5123 memset(p, 0, *lenp - len);
5129 print_string(const u_int8_t *buf, int len)
5136 for (; i < len; i++) {
5137 if (!isprint(buf[i]) && buf[i] != '\0')
5139 if (isspace(buf[i]))
5143 if (hasspc || len == 0 || buf[0] == '\0')
5144 printf("\"%.*s\"", len, buf);
5146 printf("%.*s", len, buf);
5149 for (i = 0; i < len; i++)
5150 printf("%02x", buf[i]);
5155 setdefregdomain(int s)
5157 struct regdata *rdp = getregdata();
5158 const struct regdomain *rd;
5160 /* Check if regdomain/country was already set by a previous call. */
5161 /* XXX is it possible? */
5162 if (regdomain.regdomain != 0 ||
5163 regdomain.country != CTRY_DEFAULT)
5168 /* Check if it was already set by the driver. */
5169 if (regdomain.regdomain != 0 ||
5170 regdomain.country != CTRY_DEFAULT)
5173 /* Set FCC/US as default. */
5174 rd = lib80211_regdomain_findbysku(rdp, SKU_FCC);
5176 errx(1, "FCC regdomain was not found");
5178 regdomain.regdomain = rd->sku;
5182 /* Send changes to net80211. */
5183 setregdomain_cb(s, ®domain);
5185 /* Cleanup (so it can be overriden by subsequent parameters). */
5186 regdomain.regdomain = 0;
5187 regdomain.country = CTRY_DEFAULT;
5188 regdomain.isocc[0] = 0;
5189 regdomain.isocc[1] = 0;
5193 * Virtual AP cloning support.
5195 static struct ieee80211_clone_params params = {
5196 .icp_opmode = IEEE80211_M_STA, /* default to station mode */
5200 wlan_create(int s, struct ifreq *ifr)
5202 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
5203 char orig_name[IFNAMSIZ];
5205 if (params.icp_parent[0] == '\0')
5206 errx(1, "must specify a parent device (wlandev) when creating "
5208 if (params.icp_opmode == IEEE80211_M_WDS &&
5209 memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0)
5210 errx(1, "no bssid specified for WDS (use wlanbssid)");
5211 ifr->ifr_data = (caddr_t) ¶ms;
5212 if (ioctl(s, SIOCIFCREATE2, ifr) < 0)
5213 err(1, "SIOCIFCREATE2");
5215 /* XXX preserve original name for ifclonecreate(). */
5216 strlcpy(orig_name, name, sizeof(orig_name));
5217 strlcpy(name, ifr->ifr_name, sizeof(name));
5221 strlcpy(name, orig_name, sizeof(name));
5225 DECL_CMD_FUNC(set80211clone_wlandev, arg, d)
5227 strlcpy(params.icp_parent, arg, IFNAMSIZ);
5231 DECL_CMD_FUNC(set80211clone_wlanbssid, arg, d)
5233 const struct ether_addr *ea;
5235 ea = ether_aton(arg);
5237 errx(1, "%s: cannot parse bssid", arg);
5238 memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN);
5242 DECL_CMD_FUNC(set80211clone_wlanaddr, arg, d)
5244 const struct ether_addr *ea;
5246 ea = ether_aton(arg);
5248 errx(1, "%s: cannot parse address", arg);
5249 memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN);
5250 params.icp_flags |= IEEE80211_CLONE_MACADDR;
5254 DECL_CMD_FUNC(set80211clone_wlanmode, arg, d)
5256 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
5257 if (iseq(arg, "sta"))
5258 params.icp_opmode = IEEE80211_M_STA;
5259 else if (iseq(arg, "ahdemo") || iseq(arg, "adhoc-demo"))
5260 params.icp_opmode = IEEE80211_M_AHDEMO;
5261 else if (iseq(arg, "ibss") || iseq(arg, "adhoc"))
5262 params.icp_opmode = IEEE80211_M_IBSS;
5263 else if (iseq(arg, "ap") || iseq(arg, "host"))
5264 params.icp_opmode = IEEE80211_M_HOSTAP;
5265 else if (iseq(arg, "wds"))
5266 params.icp_opmode = IEEE80211_M_WDS;
5267 else if (iseq(arg, "monitor"))
5268 params.icp_opmode = IEEE80211_M_MONITOR;
5269 else if (iseq(arg, "tdma")) {
5270 params.icp_opmode = IEEE80211_M_AHDEMO;
5271 params.icp_flags |= IEEE80211_CLONE_TDMA;
5272 } else if (iseq(arg, "mesh") || iseq(arg, "mp")) /* mesh point */
5273 params.icp_opmode = IEEE80211_M_MBSS;
5275 errx(1, "Don't know to create %s for %s", arg, name);
5280 set80211clone_beacons(const char *val, int d, int s, const struct afswtch *rafp)
5282 /* NB: inverted sense */
5284 params.icp_flags &= ~IEEE80211_CLONE_NOBEACONS;
5286 params.icp_flags |= IEEE80211_CLONE_NOBEACONS;
5290 set80211clone_bssid(const char *val, int d, int s, const struct afswtch *rafp)
5293 params.icp_flags |= IEEE80211_CLONE_BSSID;
5295 params.icp_flags &= ~IEEE80211_CLONE_BSSID;
5299 set80211clone_wdslegacy(const char *val, int d, int s, const struct afswtch *rafp)
5302 params.icp_flags |= IEEE80211_CLONE_WDSLEGACY;
5304 params.icp_flags &= ~IEEE80211_CLONE_WDSLEGACY;
5307 static struct cmd ieee80211_cmds[] = {
5308 DEF_CMD_ARG("ssid", set80211ssid),
5309 DEF_CMD_ARG("nwid", set80211ssid),
5310 DEF_CMD_ARG("meshid", set80211meshid),
5311 DEF_CMD_ARG("stationname", set80211stationname),
5312 DEF_CMD_ARG("station", set80211stationname), /* BSD/OS */
5313 DEF_CMD_ARG("channel", set80211channel),
5314 DEF_CMD_ARG("authmode", set80211authmode),
5315 DEF_CMD_ARG("powersavemode", set80211powersavemode),
5316 DEF_CMD("powersave", 1, set80211powersave),
5317 DEF_CMD("-powersave", 0, set80211powersave),
5318 DEF_CMD_ARG("powersavesleep", set80211powersavesleep),
5319 DEF_CMD_ARG("wepmode", set80211wepmode),
5320 DEF_CMD("wep", 1, set80211wep),
5321 DEF_CMD("-wep", 0, set80211wep),
5322 DEF_CMD_ARG("deftxkey", set80211weptxkey),
5323 DEF_CMD_ARG("weptxkey", set80211weptxkey),
5324 DEF_CMD_ARG("wepkey", set80211wepkey),
5325 DEF_CMD_ARG("nwkey", set80211nwkey), /* NetBSD */
5326 DEF_CMD("-nwkey", 0, set80211wep), /* NetBSD */
5327 DEF_CMD_ARG("rtsthreshold", set80211rtsthreshold),
5328 DEF_CMD_ARG("protmode", set80211protmode),
5329 DEF_CMD_ARG("txpower", set80211txpower),
5330 DEF_CMD_ARG("roaming", set80211roaming),
5331 DEF_CMD("wme", 1, set80211wme),
5332 DEF_CMD("-wme", 0, set80211wme),
5333 DEF_CMD("wmm", 1, set80211wme),
5334 DEF_CMD("-wmm", 0, set80211wme),
5335 DEF_CMD("hidessid", 1, set80211hidessid),
5336 DEF_CMD("-hidessid", 0, set80211hidessid),
5337 DEF_CMD("apbridge", 1, set80211apbridge),
5338 DEF_CMD("-apbridge", 0, set80211apbridge),
5339 DEF_CMD_ARG("chanlist", set80211chanlist),
5340 DEF_CMD_ARG("bssid", set80211bssid),
5341 DEF_CMD_ARG("ap", set80211bssid),
5342 DEF_CMD("scan", 0, set80211scan),
5343 DEF_CMD_ARG("list", set80211list),
5344 DEF_CMD_ARG2("cwmin", set80211cwmin),
5345 DEF_CMD_ARG2("cwmax", set80211cwmax),
5346 DEF_CMD_ARG2("aifs", set80211aifs),
5347 DEF_CMD_ARG2("txoplimit", set80211txoplimit),
5348 DEF_CMD_ARG("acm", set80211acm),
5349 DEF_CMD_ARG("-acm", set80211noacm),
5350 DEF_CMD_ARG("ack", set80211ackpolicy),
5351 DEF_CMD_ARG("-ack", set80211noackpolicy),
5352 DEF_CMD_ARG2("bss:cwmin", set80211bsscwmin),
5353 DEF_CMD_ARG2("bss:cwmax", set80211bsscwmax),
5354 DEF_CMD_ARG2("bss:aifs", set80211bssaifs),
5355 DEF_CMD_ARG2("bss:txoplimit", set80211bsstxoplimit),
5356 DEF_CMD_ARG("dtimperiod", set80211dtimperiod),
5357 DEF_CMD_ARG("bintval", set80211bintval),
5358 DEF_CMD("mac:open", IEEE80211_MACCMD_POLICY_OPEN, set80211maccmd),
5359 DEF_CMD("mac:allow", IEEE80211_MACCMD_POLICY_ALLOW, set80211maccmd),
5360 DEF_CMD("mac:deny", IEEE80211_MACCMD_POLICY_DENY, set80211maccmd),
5361 DEF_CMD("mac:radius", IEEE80211_MACCMD_POLICY_RADIUS, set80211maccmd),
5362 DEF_CMD("mac:flush", IEEE80211_MACCMD_FLUSH, set80211maccmd),
5363 DEF_CMD("mac:detach", IEEE80211_MACCMD_DETACH, set80211maccmd),
5364 DEF_CMD_ARG("mac:add", set80211addmac),
5365 DEF_CMD_ARG("mac:del", set80211delmac),
5366 DEF_CMD_ARG("mac:kick", set80211kickmac),
5367 DEF_CMD("pureg", 1, set80211pureg),
5368 DEF_CMD("-pureg", 0, set80211pureg),
5369 DEF_CMD("ff", 1, set80211fastframes),
5370 DEF_CMD("-ff", 0, set80211fastframes),
5371 DEF_CMD("dturbo", 1, set80211dturbo),
5372 DEF_CMD("-dturbo", 0, set80211dturbo),
5373 DEF_CMD("bgscan", 1, set80211bgscan),
5374 DEF_CMD("-bgscan", 0, set80211bgscan),
5375 DEF_CMD_ARG("bgscanidle", set80211bgscanidle),
5376 DEF_CMD_ARG("bgscanintvl", set80211bgscanintvl),
5377 DEF_CMD_ARG("scanvalid", set80211scanvalid),
5378 DEF_CMD("quiet", 1, set80211quiet),
5379 DEF_CMD("-quiet", 0, set80211quiet),
5380 DEF_CMD_ARG("quiet_count", set80211quietcount),
5381 DEF_CMD_ARG("quiet_period", set80211quietperiod),
5382 DEF_CMD_ARG("quiet_dur", set80211quietduration),
5383 DEF_CMD_ARG("quiet_offset", set80211quietoffset),
5384 DEF_CMD_ARG("roam:rssi", set80211roamrssi),
5385 DEF_CMD_ARG("roam:rate", set80211roamrate),
5386 DEF_CMD_ARG("mcastrate", set80211mcastrate),
5387 DEF_CMD_ARG("ucastrate", set80211ucastrate),
5388 DEF_CMD_ARG("mgtrate", set80211mgtrate),
5389 DEF_CMD_ARG("mgmtrate", set80211mgtrate),
5390 DEF_CMD_ARG("maxretry", set80211maxretry),
5391 DEF_CMD_ARG("fragthreshold", set80211fragthreshold),
5392 DEF_CMD("burst", 1, set80211burst),
5393 DEF_CMD("-burst", 0, set80211burst),
5394 DEF_CMD_ARG("bmiss", set80211bmissthreshold),
5395 DEF_CMD_ARG("bmissthreshold", set80211bmissthreshold),
5396 DEF_CMD("shortgi", 1, set80211shortgi),
5397 DEF_CMD("-shortgi", 0, set80211shortgi),
5398 DEF_CMD("ampdurx", 2, set80211ampdu),
5399 DEF_CMD("-ampdurx", -2, set80211ampdu),
5400 DEF_CMD("ampdutx", 1, set80211ampdu),
5401 DEF_CMD("-ampdutx", -1, set80211ampdu),
5402 DEF_CMD("ampdu", 3, set80211ampdu), /* NB: tx+rx */
5403 DEF_CMD("-ampdu", -3, set80211ampdu),
5404 DEF_CMD_ARG("ampdulimit", set80211ampdulimit),
5405 DEF_CMD_ARG("ampdudensity", set80211ampdudensity),
5406 DEF_CMD("amsdurx", 2, set80211amsdu),
5407 DEF_CMD("-amsdurx", -2, set80211amsdu),
5408 DEF_CMD("amsdutx", 1, set80211amsdu),
5409 DEF_CMD("-amsdutx", -1, set80211amsdu),
5410 DEF_CMD("amsdu", 3, set80211amsdu), /* NB: tx+rx */
5411 DEF_CMD("-amsdu", -3, set80211amsdu),
5412 DEF_CMD_ARG("amsdulimit", set80211amsdulimit),
5413 DEF_CMD("stbcrx", 2, set80211stbc),
5414 DEF_CMD("-stbcrx", -2, set80211stbc),
5415 DEF_CMD("stbctx", 1, set80211stbc),
5416 DEF_CMD("-stbctx", -1, set80211stbc),
5417 DEF_CMD("stbc", 3, set80211stbc), /* NB: tx+rx */
5418 DEF_CMD("-stbc", -3, set80211stbc),
5419 DEF_CMD("puren", 1, set80211puren),
5420 DEF_CMD("-puren", 0, set80211puren),
5421 DEF_CMD("doth", 1, set80211doth),
5422 DEF_CMD("-doth", 0, set80211doth),
5423 DEF_CMD("dfs", 1, set80211dfs),
5424 DEF_CMD("-dfs", 0, set80211dfs),
5425 DEF_CMD("htcompat", 1, set80211htcompat),
5426 DEF_CMD("-htcompat", 0, set80211htcompat),
5427 DEF_CMD("dwds", 1, set80211dwds),
5428 DEF_CMD("-dwds", 0, set80211dwds),
5429 DEF_CMD("inact", 1, set80211inact),
5430 DEF_CMD("-inact", 0, set80211inact),
5431 DEF_CMD("tsn", 1, set80211tsn),
5432 DEF_CMD("-tsn", 0, set80211tsn),
5433 DEF_CMD_ARG("regdomain", set80211regdomain),
5434 DEF_CMD_ARG("country", set80211country),
5435 DEF_CMD("indoor", 'I', set80211location),
5436 DEF_CMD("-indoor", 'O', set80211location),
5437 DEF_CMD("outdoor", 'O', set80211location),
5438 DEF_CMD("-outdoor", 'I', set80211location),
5439 DEF_CMD("anywhere", ' ', set80211location),
5440 DEF_CMD("ecm", 1, set80211ecm),
5441 DEF_CMD("-ecm", 0, set80211ecm),
5442 DEF_CMD("dotd", 1, set80211dotd),
5443 DEF_CMD("-dotd", 0, set80211dotd),
5444 DEF_CMD_ARG("htprotmode", set80211htprotmode),
5445 DEF_CMD("ht20", 1, set80211htconf),
5446 DEF_CMD("-ht20", 0, set80211htconf),
5447 DEF_CMD("ht40", 3, set80211htconf), /* NB: 20+40 */
5448 DEF_CMD("-ht40", 0, set80211htconf),
5449 DEF_CMD("ht", 3, set80211htconf), /* NB: 20+40 */
5450 DEF_CMD("-ht", 0, set80211htconf),
5451 DEF_CMD("rifs", 1, set80211rifs),
5452 DEF_CMD("-rifs", 0, set80211rifs),
5453 DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA, set80211smps),
5454 DEF_CMD("smpsdyn", IEEE80211_HTCAP_SMPS_DYNAMIC, set80211smps),
5455 DEF_CMD("-smps", IEEE80211_HTCAP_SMPS_OFF, set80211smps),
5456 /* XXX for testing */
5457 DEF_CMD_ARG("chanswitch", set80211chanswitch),
5459 DEF_CMD_ARG("tdmaslot", set80211tdmaslot),
5460 DEF_CMD_ARG("tdmaslotcnt", set80211tdmaslotcnt),
5461 DEF_CMD_ARG("tdmaslotlen", set80211tdmaslotlen),
5462 DEF_CMD_ARG("tdmabintval", set80211tdmabintval),
5464 DEF_CMD_ARG("meshttl", set80211meshttl),
5465 DEF_CMD("meshforward", 1, set80211meshforward),
5466 DEF_CMD("-meshforward", 0, set80211meshforward),
5467 DEF_CMD("meshgate", 1, set80211meshgate),
5468 DEF_CMD("-meshgate", 0, set80211meshgate),
5469 DEF_CMD("meshpeering", 1, set80211meshpeering),
5470 DEF_CMD("-meshpeering", 0, set80211meshpeering),
5471 DEF_CMD_ARG("meshmetric", set80211meshmetric),
5472 DEF_CMD_ARG("meshpath", set80211meshpath),
5473 DEF_CMD("meshrt:flush", IEEE80211_MESH_RTCMD_FLUSH, set80211meshrtcmd),
5474 DEF_CMD_ARG("meshrt:add", set80211addmeshrt),
5475 DEF_CMD_ARG("meshrt:del", set80211delmeshrt),
5476 DEF_CMD_ARG("hwmprootmode", set80211hwmprootmode),
5477 DEF_CMD_ARG("hwmpmaxhops", set80211hwmpmaxhops),
5479 /* vap cloning support */
5480 DEF_CLONE_CMD_ARG("wlanaddr", set80211clone_wlanaddr),
5481 DEF_CLONE_CMD_ARG("wlanbssid", set80211clone_wlanbssid),
5482 DEF_CLONE_CMD_ARG("wlandev", set80211clone_wlandev),
5483 DEF_CLONE_CMD_ARG("wlanmode", set80211clone_wlanmode),
5484 DEF_CLONE_CMD("beacons", 1, set80211clone_beacons),
5485 DEF_CLONE_CMD("-beacons", 0, set80211clone_beacons),
5486 DEF_CLONE_CMD("bssid", 1, set80211clone_bssid),
5487 DEF_CLONE_CMD("-bssid", 0, set80211clone_bssid),
5488 DEF_CLONE_CMD("wdslegacy", 1, set80211clone_wdslegacy),
5489 DEF_CLONE_CMD("-wdslegacy", 0, set80211clone_wdslegacy),
5491 static struct afswtch af_ieee80211 = {
5492 .af_name = "af_ieee80211",
5494 .af_other_status = ieee80211_status,
5497 static __constructor void
5498 ieee80211_ctor(void)
5502 for (i = 0; i < nitems(ieee80211_cmds); i++)
5503 cmd_register(&ieee80211_cmds[i]);
5504 af_register(&af_ieee80211);
5505 clone_setdefcallback("wlan", wlan_create);