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>
80 #include <net80211/ieee80211_wps.h>
93 #include <stddef.h> /* NB: for offsetof */
99 #include <lib80211/lib80211_regdomain.h>
100 #include <lib80211/lib80211_ioctl.h>
102 #ifndef IEEE80211_FIXED_RATE_NONE
103 #define IEEE80211_FIXED_RATE_NONE 0xff
106 /* XXX need these publicly defined or similar */
107 #ifndef IEEE80211_NODE_AUTH
108 #define IEEE80211_NODE_AUTH 0x000001 /* authorized for data */
109 #define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */
110 #define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */
111 #define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */
112 #define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */
113 #define IEEE80211_NODE_HT 0x000040 /* HT enabled */
114 #define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */
115 #define IEEE80211_NODE_WPS 0x000100 /* WPS association */
116 #define IEEE80211_NODE_TSN 0x000200 /* TSN association */
117 #define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */
118 #define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */
119 #define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */
120 #define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */
121 #define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */
122 #define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */
123 #define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */
124 #define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */
125 #define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */
126 #define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */
127 #define IEEE80211_NODE_VHT 0x100000 /* VHT enabled */
128 #define IEEE80211_NODE_LDPC 0x200000 /* LDPC enabled */
129 #define IEEE80211_NODE_UAPSD 0x400000 /* UAPSD enabled */
132 /* XXX should also figure out where to put these for k/u-space sharing. */
133 #ifndef IEEE80211_FVHT_VHT
134 #define IEEE80211_FVHT_VHT 0x000000001 /* CONF: VHT supported */
135 #define IEEE80211_FVHT_USEVHT40 0x000000002 /* CONF: Use VHT40 */
136 #define IEEE80211_FVHT_USEVHT80 0x000000004 /* CONF: Use VHT80 */
137 #define IEEE80211_FVHT_USEVHT160 0x000000008 /* CONF: Use VHT160 */
138 #define IEEE80211_FVHT_USEVHT80P80 0x000000010 /* CONF: Use VHT 80+80 */
141 #define MAXCHAN 1536 /* max 1.5K channels */
147 static void LINE_INIT(char c);
148 static void LINE_BREAK(void);
149 static void LINE_CHECK(const char *fmt, ...);
151 static const char *modename[IEEE80211_MODE_MAX] = {
152 [IEEE80211_MODE_AUTO] = "auto",
153 [IEEE80211_MODE_11A] = "11a",
154 [IEEE80211_MODE_11B] = "11b",
155 [IEEE80211_MODE_11G] = "11g",
156 [IEEE80211_MODE_FH] = "fh",
157 [IEEE80211_MODE_TURBO_A] = "turboA",
158 [IEEE80211_MODE_TURBO_G] = "turboG",
159 [IEEE80211_MODE_STURBO_A] = "sturbo",
160 [IEEE80211_MODE_11NA] = "11na",
161 [IEEE80211_MODE_11NG] = "11ng",
162 [IEEE80211_MODE_HALF] = "half",
163 [IEEE80211_MODE_QUARTER] = "quarter",
164 [IEEE80211_MODE_VHT_2GHZ] = "11acg",
165 [IEEE80211_MODE_VHT_5GHZ] = "11ac",
168 static void set80211(int s, int type, int val, int len, void *data);
169 static int get80211(int s, int type, void *data, int len);
170 static int get80211len(int s, int type, void *data, int len, int *plen);
171 static int get80211val(int s, int type, int *val);
172 static const char *get_string(const char *val, const char *sep,
173 u_int8_t *buf, int *lenp);
174 static void print_string(const u_int8_t *buf, int len);
175 static void print_regdomain(const struct ieee80211_regdomain *, int);
176 static void print_channels(int, const struct ieee80211req_chaninfo *,
177 int allchans, int verbose);
178 static void regdomain_makechannels(struct ieee80211_regdomain_req *,
179 const struct ieee80211_devcaps_req *);
180 static const char *mesh_linkstate_string(uint8_t state);
182 static struct ieee80211req_chaninfo *chaninfo;
183 static struct ieee80211_regdomain regdomain;
184 static int gotregdomain = 0;
185 static struct ieee80211_roamparams_req roamparams;
186 static int gotroam = 0;
187 static struct ieee80211_txparams_req txparams;
188 static int gottxparams = 0;
189 static struct ieee80211_channel curchan;
190 static int gotcurchan = 0;
191 static struct ifmediareq *ifmr;
192 static int htconf = 0;
193 static int gothtconf = 0;
200 if (get80211val(s, IEEE80211_IOC_HTCONF, &htconf) < 0)
201 warn("unable to get HT configuration information");
206 static int vhtconf = 0;
207 static int gotvhtconf = 0;
214 if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
215 warn("unable to get VHT configuration information");
220 * Collect channel info from the kernel. We use this (mostly)
221 * to handle mapping between frequency and IEEE channel number.
226 if (chaninfo != NULL)
228 chaninfo = malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN));
229 if (chaninfo == NULL)
230 errx(1, "no space for channel list");
231 if (get80211(s, IEEE80211_IOC_CHANINFO, chaninfo,
232 IEEE80211_CHANINFO_SIZE(MAXCHAN)) < 0)
233 err(1, "unable to get channel information");
234 ifmr = ifmedia_getstate(s);
239 static struct regdata *
242 static struct regdata *rdp = NULL;
244 rdp = lib80211_alloc_regdata();
246 errx(-1, "missing or corrupted regdomain database");
252 * Given the channel at index i with attributes from,
253 * check if there is a channel with attributes to in
254 * the channel table. With suitable attributes this
255 * allows the caller to look for promotion; e.g. from
259 canpromote(int i, int from, int to)
261 const struct ieee80211_channel *fc = &chaninfo->ic_chans[i];
264 if ((fc->ic_flags & from) != from)
266 /* NB: quick check exploiting ordering of chans w/ same frequency */
267 if (i+1 < chaninfo->ic_nchans &&
268 chaninfo->ic_chans[i+1].ic_freq == fc->ic_freq &&
269 (chaninfo->ic_chans[i+1].ic_flags & to) == to)
271 /* brute force search in case channel list is not ordered */
272 for (j = 0; j < chaninfo->ic_nchans; j++) {
273 const struct ieee80211_channel *tc = &chaninfo->ic_chans[j];
275 tc->ic_freq == fc->ic_freq && (tc->ic_flags & to) == to)
282 * Handle channel promotion. When a channel is specified with
283 * only a frequency we want to promote it to the ``best'' channel
284 * available. The channel list has separate entries for 11b, 11g,
285 * 11a, and 11n[ga] channels so specifying a frequency w/o any
286 * attributes requires we upgrade, e.g. from 11b -> 11g. This
287 * gets complicated when the channel is specified on the same
288 * command line with a media request that constrains the available
289 * channe list (e.g. mode 11a); we want to honor that to avoid
290 * confusing behaviour.
299 * Query the current mode of the interface in case it's
300 * constrained (e.g. to 11a). We must do this carefully
301 * as there may be a pending ifmedia request in which case
302 * asking the kernel will give us the wrong answer. This
303 * is an unfortunate side-effect of the way ifconfig is
304 * structure for modularity (yech).
306 * NB: ifmr is actually setup in getchaninfo (above); we
307 * assume it's called coincident with to this call so
308 * we have a ``current setting''; otherwise we must pass
309 * the socket descriptor down to here so we can make
310 * the ifmedia_getstate call ourselves.
312 int chanmode = ifmr != NULL ? IFM_MODE(ifmr->ifm_current) : IFM_AUTO;
314 /* when ambiguous promote to ``best'' */
315 /* NB: we abitrarily pick HT40+ over HT40- */
316 if (chanmode != IFM_IEEE80211_11B)
317 i = canpromote(i, IEEE80211_CHAN_B, IEEE80211_CHAN_G);
318 if (chanmode != IFM_IEEE80211_11G && (htconf & 1)) {
319 i = canpromote(i, IEEE80211_CHAN_G,
320 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20);
322 i = canpromote(i, IEEE80211_CHAN_G,
323 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D);
324 i = canpromote(i, IEEE80211_CHAN_G,
325 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U);
328 if (chanmode != IFM_IEEE80211_11A && (htconf & 1)) {
329 i = canpromote(i, IEEE80211_CHAN_A,
330 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20);
332 i = canpromote(i, IEEE80211_CHAN_A,
333 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D);
334 i = canpromote(i, IEEE80211_CHAN_A,
335 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U);
342 mapfreq(struct ieee80211_channel *chan, int freq, int flags)
346 for (i = 0; i < chaninfo->ic_nchans; i++) {
347 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
349 if (c->ic_freq == freq && (c->ic_flags & flags) == flags) {
351 /* when ambiguous promote to ``best'' */
352 c = &chaninfo->ic_chans[promote(i)];
358 errx(1, "unknown/undefined frequency %u/0x%x", freq, flags);
362 mapchan(struct ieee80211_channel *chan, int ieee, int flags)
366 for (i = 0; i < chaninfo->ic_nchans; i++) {
367 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
369 if (c->ic_ieee == ieee && (c->ic_flags & flags) == flags) {
371 /* when ambiguous promote to ``best'' */
372 c = &chaninfo->ic_chans[promote(i)];
378 errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags);
381 static const struct ieee80211_channel *
386 if (get80211(s, IEEE80211_IOC_CURCHAN, &curchan, sizeof(curchan)) < 0) {
388 /* fall back to legacy ioctl */
389 if (get80211val(s, IEEE80211_IOC_CHANNEL, &val) < 0)
390 err(-1, "cannot figure out current channel");
392 mapchan(&curchan, val, 0);
398 static enum ieee80211_phymode
399 chan2mode(const struct ieee80211_channel *c)
401 if (IEEE80211_IS_CHAN_VHTA(c))
402 return IEEE80211_MODE_VHT_5GHZ;
403 if (IEEE80211_IS_CHAN_VHTG(c))
404 return IEEE80211_MODE_VHT_2GHZ;
405 if (IEEE80211_IS_CHAN_HTA(c))
406 return IEEE80211_MODE_11NA;
407 if (IEEE80211_IS_CHAN_HTG(c))
408 return IEEE80211_MODE_11NG;
409 if (IEEE80211_IS_CHAN_108A(c))
410 return IEEE80211_MODE_TURBO_A;
411 if (IEEE80211_IS_CHAN_108G(c))
412 return IEEE80211_MODE_TURBO_G;
413 if (IEEE80211_IS_CHAN_ST(c))
414 return IEEE80211_MODE_STURBO_A;
415 if (IEEE80211_IS_CHAN_FHSS(c))
416 return IEEE80211_MODE_FH;
417 if (IEEE80211_IS_CHAN_HALF(c))
418 return IEEE80211_MODE_HALF;
419 if (IEEE80211_IS_CHAN_QUARTER(c))
420 return IEEE80211_MODE_QUARTER;
421 if (IEEE80211_IS_CHAN_A(c))
422 return IEEE80211_MODE_11A;
423 if (IEEE80211_IS_CHAN_ANYG(c))
424 return IEEE80211_MODE_11G;
425 if (IEEE80211_IS_CHAN_B(c))
426 return IEEE80211_MODE_11B;
427 return IEEE80211_MODE_AUTO;
435 if (get80211(s, IEEE80211_IOC_ROAM,
436 &roamparams, sizeof(roamparams)) < 0)
437 err(1, "unable to get roaming parameters");
442 setroam_cb(int s, void *arg)
444 struct ieee80211_roamparams_req *roam = arg;
445 set80211(s, IEEE80211_IOC_ROAM, 0, sizeof(*roam), roam);
453 if (get80211(s, IEEE80211_IOC_TXPARAMS,
454 &txparams, sizeof(txparams)) < 0)
455 err(1, "unable to get transmit parameters");
460 settxparams_cb(int s, void *arg)
462 struct ieee80211_txparams_req *txp = arg;
463 set80211(s, IEEE80211_IOC_TXPARAMS, 0, sizeof(*txp), txp);
471 if (get80211(s, IEEE80211_IOC_REGDOMAIN,
472 ®domain, sizeof(regdomain)) < 0)
473 err(1, "unable to get regulatory domain info");
478 getdevcaps(int s, struct ieee80211_devcaps_req *dc)
480 if (get80211(s, IEEE80211_IOC_DEVCAPS, dc,
481 IEEE80211_DEVCAPS_SPACE(dc)) < 0)
482 err(1, "unable to get device capabilities");
486 setregdomain_cb(int s, void *arg)
488 struct ieee80211_regdomain_req *req;
489 struct ieee80211_regdomain *rd = arg;
490 struct ieee80211_devcaps_req *dc;
491 struct regdata *rdp = getregdata();
493 if (rd->country != NO_COUNTRY) {
494 const struct country *cc;
496 * Check current country seting to make sure it's
497 * compatible with the new regdomain. If not, then
498 * override it with any default country for this
499 * SKU. If we cannot arrange a match, then abort.
501 cc = lib80211_country_findbycc(rdp, rd->country);
503 errx(1, "unknown ISO country code %d", rd->country);
504 if (cc->rd->sku != rd->regdomain) {
505 const struct regdomain *rp;
507 * Check if country is incompatible with regdomain.
508 * To enable multiple regdomains for a country code
509 * we permit a mismatch between the regdomain and
510 * the country's associated regdomain when the
511 * regdomain is setup w/o a default country. For
512 * example, US is bound to the FCC regdomain but
513 * we allow US to be combined with FCC3 because FCC3
514 * has not default country. This allows bogus
515 * combinations like FCC3+DK which are resolved when
516 * constructing the channel list by deferring to the
517 * regdomain to construct the channel list.
519 rp = lib80211_regdomain_findbysku(rdp, rd->regdomain);
521 errx(1, "country %s (%s) is not usable with "
522 "regdomain %d", cc->isoname, cc->name,
524 else if (rp->cc != NULL && rp->cc != cc)
525 errx(1, "country %s (%s) is not usable with "
526 "regdomain %s", cc->isoname, cc->name,
531 * Fetch the device capabilities and calculate the
532 * full set of netbands for which we request a new
533 * channel list be constructed. Once that's done we
534 * push the regdomain info + channel list to the kernel.
536 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
538 errx(1, "no space for device capabilities");
539 dc->dc_chaninfo.ic_nchans = MAXCHAN;
543 printf("drivercaps: 0x%x\n", dc->dc_drivercaps);
544 printf("cryptocaps: 0x%x\n", dc->dc_cryptocaps);
545 printf("htcaps : 0x%x\n", dc->dc_htcaps);
546 printf("vhtcaps : 0x%x\n", dc->dc_vhtcaps);
548 memcpy(chaninfo, &dc->dc_chaninfo,
549 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
550 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, 1/*verbose*/);
554 req = malloc(IEEE80211_REGDOMAIN_SIZE(dc->dc_chaninfo.ic_nchans));
556 errx(1, "no space for regdomain request");
558 regdomain_makechannels(req, dc);
561 print_regdomain(rd, 1/*verbose*/);
563 /* blech, reallocate channel list for new data */
564 if (chaninfo != NULL)
566 chaninfo = malloc(IEEE80211_CHANINFO_SPACE(&req->chaninfo));
567 if (chaninfo == NULL)
568 errx(1, "no space for channel list");
569 memcpy(chaninfo, &req->chaninfo,
570 IEEE80211_CHANINFO_SPACE(&req->chaninfo));
571 print_channels(s, &req->chaninfo, 1/*allchans*/, 1/*verbose*/);
573 if (req->chaninfo.ic_nchans == 0)
574 errx(1, "no channels calculated");
575 set80211(s, IEEE80211_IOC_REGDOMAIN, 0,
576 IEEE80211_REGDOMAIN_SPACE(req), req);
582 ieee80211_mhz2ieee(int freq, int flags)
584 struct ieee80211_channel chan;
585 mapfreq(&chan, freq, flags);
590 isanyarg(const char *arg)
592 return (strncmp(arg, "-", 1) == 0 ||
593 strncasecmp(arg, "any", 3) == 0 || strncasecmp(arg, "off", 3) == 0);
597 set80211ssid(const char *val, int d, int s, const struct afswtch *rafp)
601 u_int8_t data[IEEE80211_NWID_LEN];
605 if (len > 2 && isdigit((int)val[0]) && val[1] == ':') {
610 bzero(data, sizeof(data));
612 if (get_string(val, NULL, data, &len) == NULL)
615 set80211(s, IEEE80211_IOC_SSID, ssid, len, data);
619 set80211meshid(const char *val, int d, int s, const struct afswtch *rafp)
622 u_int8_t data[IEEE80211_NWID_LEN];
624 memset(data, 0, sizeof(data));
626 if (get_string(val, NULL, data, &len) == NULL)
629 set80211(s, IEEE80211_IOC_MESH_ID, 0, len, data);
633 set80211stationname(const char *val, int d, int s, const struct afswtch *rafp)
638 bzero(data, sizeof(data));
640 get_string(val, NULL, data, &len);
642 set80211(s, IEEE80211_IOC_STATIONNAME, 0, len, data);
646 * Parse a channel specification for attributes/flags.
648 * freq/xx channel width (5,10,20,40,40+,40-)
649 * freq:mode channel mode (a,b,g,h,n,t,s,d)
651 * These can be combined in either order; e.g. 2437:ng/40.
652 * Modes are case insensitive.
654 * The result is not validated here; it's assumed to be
655 * checked against the channel table fetched from the kernel.
658 getchannelflags(const char *val, int freq)
660 #define _CHAN_HT 0x80000000
667 cp = strchr(val, ':');
669 for (cp++; isalpha((int) *cp); cp++) {
670 /* accept mixed case */
675 case 'a': /* 802.11a */
676 flags |= IEEE80211_CHAN_A;
678 case 'b': /* 802.11b */
679 flags |= IEEE80211_CHAN_B;
681 case 'g': /* 802.11g */
682 flags |= IEEE80211_CHAN_G;
684 case 'v': /* vht: 802.11ac */
687 case 'h': /* ht = 802.11n */
688 case 'n': /* 802.11n */
689 flags |= _CHAN_HT; /* NB: private */
691 case 'd': /* dt = Atheros Dynamic Turbo */
692 flags |= IEEE80211_CHAN_TURBO;
694 case 't': /* ht, dt, st, t */
695 /* dt and unadorned t specify Dynamic Turbo */
696 if ((flags & (IEEE80211_CHAN_STURBO|_CHAN_HT)) == 0)
697 flags |= IEEE80211_CHAN_TURBO;
699 case 's': /* st = Atheros Static Turbo */
700 flags |= IEEE80211_CHAN_STURBO;
703 errx(-1, "%s: Invalid channel attribute %c\n",
708 cp = strchr(val, '/');
711 u_long cw = strtoul(cp+1, &ep, 10);
715 flags |= IEEE80211_CHAN_QUARTER;
718 flags |= IEEE80211_CHAN_HALF;
721 /* NB: this may be removed below */
722 flags |= IEEE80211_CHAN_HT20;
727 /* Handle the 80/160 VHT flag */
729 flags |= IEEE80211_CHAN_VHT80;
731 flags |= IEEE80211_CHAN_VHT160;
734 if (ep != NULL && *ep == '+')
735 flags |= IEEE80211_CHAN_HT40U;
736 else if (ep != NULL && *ep == '-')
737 flags |= IEEE80211_CHAN_HT40D;
740 errx(-1, "%s: Invalid channel width\n", val);
745 * Cleanup specifications.
747 if ((flags & _CHAN_HT) == 0) {
749 * If user specified freq/20 or freq/40 quietly remove
750 * HT cw attributes depending on channel use. To give
751 * an explicit 20/40 width for an HT channel you must
752 * indicate it is an HT channel since all HT channels
753 * are also usable for legacy operation; e.g. freq:n/40.
755 flags &= ~IEEE80211_CHAN_HT;
756 flags &= ~IEEE80211_CHAN_VHT;
759 * Remove private indicator that this is an HT channel
760 * and if no explicit channel width has been given
761 * provide the default settings.
764 if ((flags & IEEE80211_CHAN_HT) == 0) {
765 struct ieee80211_channel chan;
767 * Consult the channel list to see if we can use
768 * HT40+ or HT40- (if both the map routines choose).
771 mapfreq(&chan, freq, 0);
773 mapchan(&chan, freq, 0);
774 flags |= (chan.ic_flags & IEEE80211_CHAN_HT);
778 * If VHT is enabled, then also set the VHT flag and the
779 * relevant channel up/down.
781 if (is_vht && (flags & IEEE80211_CHAN_HT)) {
783 * XXX yes, maybe we should just have VHT, and reuse
786 if (flags & IEEE80211_CHAN_VHT80)
788 else if (flags & IEEE80211_CHAN_HT20)
789 flags |= IEEE80211_CHAN_VHT20;
790 else if (flags & IEEE80211_CHAN_HT40U)
791 flags |= IEEE80211_CHAN_VHT40U;
792 else if (flags & IEEE80211_CHAN_HT40D)
793 flags |= IEEE80211_CHAN_VHT40D;
801 getchannel(int s, struct ieee80211_channel *chan, const char *val)
806 memset(chan, 0, sizeof(*chan));
808 chan->ic_freq = IEEE80211_CHAN_ANY;
813 v = strtol(val, &eptr, 10);
814 if (val[0] == '\0' || val == eptr || errno == ERANGE ||
815 /* channel may be suffixed with nothing, :flag, or /width */
816 (eptr[0] != '\0' && eptr[0] != ':' && eptr[0] != '/'))
817 errx(1, "invalid channel specification%s",
818 errno == ERANGE ? " (out of range)" : "");
819 flags = getchannelflags(val, v);
820 if (v > 255) { /* treat as frequency */
821 mapfreq(chan, v, flags);
823 mapchan(chan, v, flags);
828 set80211channel(const char *val, int d, int s, const struct afswtch *rafp)
830 struct ieee80211_channel chan;
832 getchannel(s, &chan, val);
833 set80211(s, IEEE80211_IOC_CURCHAN, 0, sizeof(chan), &chan);
837 set80211chanswitch(const char *val, int d, int s, const struct afswtch *rafp)
839 struct ieee80211_chanswitch_req csr;
841 getchannel(s, &csr.csa_chan, val);
844 set80211(s, IEEE80211_IOC_CHANSWITCH, 0, sizeof(csr), &csr);
848 set80211authmode(const char *val, int d, int s, const struct afswtch *rafp)
852 if (strcasecmp(val, "none") == 0) {
853 mode = IEEE80211_AUTH_NONE;
854 } else if (strcasecmp(val, "open") == 0) {
855 mode = IEEE80211_AUTH_OPEN;
856 } else if (strcasecmp(val, "shared") == 0) {
857 mode = IEEE80211_AUTH_SHARED;
858 } else if (strcasecmp(val, "8021x") == 0) {
859 mode = IEEE80211_AUTH_8021X;
860 } else if (strcasecmp(val, "wpa") == 0) {
861 mode = IEEE80211_AUTH_WPA;
863 errx(1, "unknown authmode");
866 set80211(s, IEEE80211_IOC_AUTHMODE, mode, 0, NULL);
870 set80211powersavemode(const char *val, int d, int s, const struct afswtch *rafp)
874 if (strcasecmp(val, "off") == 0) {
875 mode = IEEE80211_POWERSAVE_OFF;
876 } else if (strcasecmp(val, "on") == 0) {
877 mode = IEEE80211_POWERSAVE_ON;
878 } else if (strcasecmp(val, "cam") == 0) {
879 mode = IEEE80211_POWERSAVE_CAM;
880 } else if (strcasecmp(val, "psp") == 0) {
881 mode = IEEE80211_POWERSAVE_PSP;
882 } else if (strcasecmp(val, "psp-cam") == 0) {
883 mode = IEEE80211_POWERSAVE_PSP_CAM;
885 errx(1, "unknown powersavemode");
888 set80211(s, IEEE80211_IOC_POWERSAVE, mode, 0, NULL);
892 set80211powersave(const char *val, int d, int s, const struct afswtch *rafp)
895 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_OFF,
898 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_ON,
903 set80211powersavesleep(const char *val, int d, int s, const struct afswtch *rafp)
905 set80211(s, IEEE80211_IOC_POWERSAVESLEEP, atoi(val), 0, NULL);
909 set80211wepmode(const char *val, int d, int s, const struct afswtch *rafp)
913 if (strcasecmp(val, "off") == 0) {
914 mode = IEEE80211_WEP_OFF;
915 } else if (strcasecmp(val, "on") == 0) {
916 mode = IEEE80211_WEP_ON;
917 } else if (strcasecmp(val, "mixed") == 0) {
918 mode = IEEE80211_WEP_MIXED;
920 errx(1, "unknown wep mode");
923 set80211(s, IEEE80211_IOC_WEP, mode, 0, NULL);
927 set80211wep(const char *val, int d, int s, const struct afswtch *rafp)
929 set80211(s, IEEE80211_IOC_WEP, d, 0, NULL);
933 isundefarg(const char *arg)
935 return (strcmp(arg, "-") == 0 || strncasecmp(arg, "undef", 5) == 0);
939 set80211weptxkey(const char *val, int d, int s, const struct afswtch *rafp)
942 set80211(s, IEEE80211_IOC_WEPTXKEY, IEEE80211_KEYIX_NONE, 0, NULL);
944 set80211(s, IEEE80211_IOC_WEPTXKEY, atoi(val)-1, 0, NULL);
948 set80211wepkey(const char *val, int d, int s, const struct afswtch *rafp)
952 u_int8_t data[IEEE80211_KEYBUF_SIZE];
954 if (isdigit((int)val[0]) && val[1] == ':') {
959 bzero(data, sizeof(data));
961 get_string(val, NULL, data, &len);
963 set80211(s, IEEE80211_IOC_WEPKEY, key, len, data);
967 * This function is purely a NetBSD compatibility interface. The NetBSD
968 * interface is too inflexible, but it's there so we'll support it since
969 * it's not all that hard.
972 set80211nwkey(const char *val, int d, int s, const struct afswtch *rafp)
976 u_int8_t data[IEEE80211_KEYBUF_SIZE];
978 set80211(s, IEEE80211_IOC_WEP, IEEE80211_WEP_ON, 0, NULL);
980 if (isdigit((int)val[0]) && val[1] == ':') {
981 txkey = val[0]-'0'-1;
984 for (i = 0; i < 4; i++) {
985 bzero(data, sizeof(data));
987 val = get_string(val, ",", data, &len);
991 set80211(s, IEEE80211_IOC_WEPKEY, i, len, data);
994 bzero(data, sizeof(data));
996 get_string(val, NULL, data, &len);
999 set80211(s, IEEE80211_IOC_WEPKEY, 0, len, data);
1001 bzero(data, sizeof(data));
1002 for (i = 1; i < 4; i++)
1003 set80211(s, IEEE80211_IOC_WEPKEY, i, 0, data);
1006 set80211(s, IEEE80211_IOC_WEPTXKEY, txkey, 0, NULL);
1010 set80211rtsthreshold(const char *val, int d, int s, const struct afswtch *rafp)
1012 set80211(s, IEEE80211_IOC_RTSTHRESHOLD,
1013 isundefarg(val) ? IEEE80211_RTS_MAX : atoi(val), 0, NULL);
1017 set80211protmode(const char *val, int d, int s, const struct afswtch *rafp)
1021 if (strcasecmp(val, "off") == 0) {
1022 mode = IEEE80211_PROTMODE_OFF;
1023 } else if (strcasecmp(val, "cts") == 0) {
1024 mode = IEEE80211_PROTMODE_CTS;
1025 } else if (strncasecmp(val, "rtscts", 3) == 0) {
1026 mode = IEEE80211_PROTMODE_RTSCTS;
1028 errx(1, "unknown protection mode");
1031 set80211(s, IEEE80211_IOC_PROTMODE, mode, 0, NULL);
1035 set80211htprotmode(const char *val, int d, int s, const struct afswtch *rafp)
1039 if (strcasecmp(val, "off") == 0) {
1040 mode = IEEE80211_PROTMODE_OFF;
1041 } else if (strncasecmp(val, "rts", 3) == 0) {
1042 mode = IEEE80211_PROTMODE_RTSCTS;
1044 errx(1, "unknown protection mode");
1047 set80211(s, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL);
1051 set80211txpower(const char *val, int d, int s, const struct afswtch *rafp)
1053 double v = atof(val);
1056 txpow = (int) (2*v);
1058 errx(-1, "invalid tx power (must be .5 dBm units)");
1059 set80211(s, IEEE80211_IOC_TXPOWER, txpow, 0, NULL);
1062 #define IEEE80211_ROAMING_DEVICE 0
1063 #define IEEE80211_ROAMING_AUTO 1
1064 #define IEEE80211_ROAMING_MANUAL 2
1067 set80211roaming(const char *val, int d, int s, const struct afswtch *rafp)
1071 if (strcasecmp(val, "device") == 0) {
1072 mode = IEEE80211_ROAMING_DEVICE;
1073 } else if (strcasecmp(val, "auto") == 0) {
1074 mode = IEEE80211_ROAMING_AUTO;
1075 } else if (strcasecmp(val, "manual") == 0) {
1076 mode = IEEE80211_ROAMING_MANUAL;
1078 errx(1, "unknown roaming mode");
1080 set80211(s, IEEE80211_IOC_ROAMING, mode, 0, NULL);
1084 set80211wme(const char *val, int d, int s, const struct afswtch *rafp)
1086 set80211(s, IEEE80211_IOC_WME, d, 0, NULL);
1090 set80211hidessid(const char *val, int d, int s, const struct afswtch *rafp)
1092 set80211(s, IEEE80211_IOC_HIDESSID, d, 0, NULL);
1096 set80211apbridge(const char *val, int d, int s, const struct afswtch *rafp)
1098 set80211(s, IEEE80211_IOC_APBRIDGE, d, 0, NULL);
1102 set80211fastframes(const char *val, int d, int s, const struct afswtch *rafp)
1104 set80211(s, IEEE80211_IOC_FF, d, 0, NULL);
1108 set80211dturbo(const char *val, int d, int s, const struct afswtch *rafp)
1110 set80211(s, IEEE80211_IOC_TURBOP, d, 0, NULL);
1114 set80211chanlist(const char *val, int d, int s, const struct afswtch *rafp)
1116 struct ieee80211req_chanlist chanlist;
1117 char *temp, *cp, *tp;
1119 temp = malloc(strlen(val) + 1);
1121 errx(1, "malloc failed");
1123 memset(&chanlist, 0, sizeof(chanlist));
1126 int first, last, f, c;
1128 tp = strchr(cp, ',');
1131 switch (sscanf(cp, "%u-%u", &first, &last)) {
1133 if (first > IEEE80211_CHAN_MAX)
1134 errx(-1, "channel %u out of range, max %u",
1135 first, IEEE80211_CHAN_MAX);
1136 setbit(chanlist.ic_channels, first);
1139 if (first > IEEE80211_CHAN_MAX)
1140 errx(-1, "channel %u out of range, max %u",
1141 first, IEEE80211_CHAN_MAX);
1142 if (last > IEEE80211_CHAN_MAX)
1143 errx(-1, "channel %u out of range, max %u",
1144 last, IEEE80211_CHAN_MAX);
1146 errx(-1, "void channel range, %u > %u",
1148 for (f = first; f <= last; f++)
1149 setbit(chanlist.ic_channels, f);
1161 set80211(s, IEEE80211_IOC_CHANLIST, 0, sizeof(chanlist), &chanlist);
1166 set80211bssid(const char *val, int d, int s, const struct afswtch *rafp)
1169 if (!isanyarg(val)) {
1171 struct sockaddr_dl sdl;
1173 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1175 errx(1, "malloc failed");
1177 strcpy(temp + 1, val);
1178 sdl.sdl_len = sizeof(sdl);
1179 link_addr(temp, &sdl);
1181 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1182 errx(1, "malformed link-level address");
1183 set80211(s, IEEE80211_IOC_BSSID, 0,
1184 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1186 uint8_t zerobssid[IEEE80211_ADDR_LEN];
1187 memset(zerobssid, 0, sizeof(zerobssid));
1188 set80211(s, IEEE80211_IOC_BSSID, 0,
1189 IEEE80211_ADDR_LEN, zerobssid);
1194 getac(const char *ac)
1196 if (strcasecmp(ac, "ac_be") == 0 || strcasecmp(ac, "be") == 0)
1198 if (strcasecmp(ac, "ac_bk") == 0 || strcasecmp(ac, "bk") == 0)
1200 if (strcasecmp(ac, "ac_vi") == 0 || strcasecmp(ac, "vi") == 0)
1202 if (strcasecmp(ac, "ac_vo") == 0 || strcasecmp(ac, "vo") == 0)
1204 errx(1, "unknown wme access class %s", ac);
1208 DECL_CMD_FUNC2(set80211cwmin, ac, val)
1210 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac), NULL);
1214 DECL_CMD_FUNC2(set80211cwmax, ac, val)
1216 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac), NULL);
1220 DECL_CMD_FUNC2(set80211aifs, ac, val)
1222 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac), NULL);
1226 DECL_CMD_FUNC2(set80211txoplimit, ac, val)
1228 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac), NULL);
1232 DECL_CMD_FUNC(set80211acm, ac, d)
1234 set80211(s, IEEE80211_IOC_WME_ACM, 1, getac(ac), NULL);
1237 DECL_CMD_FUNC(set80211noacm, ac, d)
1239 set80211(s, IEEE80211_IOC_WME_ACM, 0, getac(ac), NULL);
1243 DECL_CMD_FUNC(set80211ackpolicy, ac, d)
1245 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 1, getac(ac), NULL);
1248 DECL_CMD_FUNC(set80211noackpolicy, ac, d)
1250 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 0, getac(ac), NULL);
1254 DECL_CMD_FUNC2(set80211bsscwmin, ac, val)
1256 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val),
1257 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1261 DECL_CMD_FUNC2(set80211bsscwmax, ac, val)
1263 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val),
1264 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1268 DECL_CMD_FUNC2(set80211bssaifs, ac, val)
1270 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val),
1271 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1275 DECL_CMD_FUNC2(set80211bsstxoplimit, ac, val)
1277 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val),
1278 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1282 DECL_CMD_FUNC(set80211dtimperiod, val, d)
1284 set80211(s, IEEE80211_IOC_DTIM_PERIOD, atoi(val), 0, NULL);
1288 DECL_CMD_FUNC(set80211bintval, val, d)
1290 set80211(s, IEEE80211_IOC_BEACON_INTERVAL, atoi(val), 0, NULL);
1294 set80211macmac(int s, int op, const char *val)
1297 struct sockaddr_dl sdl;
1299 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1301 errx(1, "malloc failed");
1303 strcpy(temp + 1, val);
1304 sdl.sdl_len = sizeof(sdl);
1305 link_addr(temp, &sdl);
1307 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1308 errx(1, "malformed link-level address");
1309 set80211(s, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl));
1313 DECL_CMD_FUNC(set80211addmac, val, d)
1315 set80211macmac(s, IEEE80211_IOC_ADDMAC, val);
1319 DECL_CMD_FUNC(set80211delmac, val, d)
1321 set80211macmac(s, IEEE80211_IOC_DELMAC, val);
1325 DECL_CMD_FUNC(set80211kickmac, val, d)
1328 struct sockaddr_dl sdl;
1329 struct ieee80211req_mlme mlme;
1331 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1333 errx(1, "malloc failed");
1335 strcpy(temp + 1, val);
1336 sdl.sdl_len = sizeof(sdl);
1337 link_addr(temp, &sdl);
1339 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1340 errx(1, "malformed link-level address");
1341 memset(&mlme, 0, sizeof(mlme));
1342 mlme.im_op = IEEE80211_MLME_DEAUTH;
1343 mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE;
1344 memcpy(mlme.im_macaddr, LLADDR(&sdl), IEEE80211_ADDR_LEN);
1345 set80211(s, IEEE80211_IOC_MLME, 0, sizeof(mlme), &mlme);
1349 DECL_CMD_FUNC(set80211maccmd, val, d)
1351 set80211(s, IEEE80211_IOC_MACCMD, d, 0, NULL);
1355 set80211meshrtmac(int s, int req, const char *val)
1358 struct sockaddr_dl sdl;
1360 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1362 errx(1, "malloc failed");
1364 strcpy(temp + 1, val);
1365 sdl.sdl_len = sizeof(sdl);
1366 link_addr(temp, &sdl);
1368 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1369 errx(1, "malformed link-level address");
1370 set80211(s, IEEE80211_IOC_MESH_RTCMD, req,
1371 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1375 DECL_CMD_FUNC(set80211addmeshrt, val, d)
1377 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_ADD, val);
1381 DECL_CMD_FUNC(set80211delmeshrt, val, d)
1383 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_DELETE, val);
1387 DECL_CMD_FUNC(set80211meshrtcmd, val, d)
1389 set80211(s, IEEE80211_IOC_MESH_RTCMD, d, 0, NULL);
1393 DECL_CMD_FUNC(set80211hwmprootmode, val, d)
1397 if (strcasecmp(val, "normal") == 0)
1398 mode = IEEE80211_HWMP_ROOTMODE_NORMAL;
1399 else if (strcasecmp(val, "proactive") == 0)
1400 mode = IEEE80211_HWMP_ROOTMODE_PROACTIVE;
1401 else if (strcasecmp(val, "rann") == 0)
1402 mode = IEEE80211_HWMP_ROOTMODE_RANN;
1404 mode = IEEE80211_HWMP_ROOTMODE_DISABLED;
1405 set80211(s, IEEE80211_IOC_HWMP_ROOTMODE, mode, 0, NULL);
1409 DECL_CMD_FUNC(set80211hwmpmaxhops, val, d)
1411 set80211(s, IEEE80211_IOC_HWMP_MAXHOPS, atoi(val), 0, NULL);
1415 set80211pureg(const char *val, int d, int s, const struct afswtch *rafp)
1417 set80211(s, IEEE80211_IOC_PUREG, d, 0, NULL);
1421 set80211quiet(const char *val, int d, int s, const struct afswtch *rafp)
1423 set80211(s, IEEE80211_IOC_QUIET, d, 0, NULL);
1427 DECL_CMD_FUNC(set80211quietperiod, val, d)
1429 set80211(s, IEEE80211_IOC_QUIET_PERIOD, atoi(val), 0, NULL);
1433 DECL_CMD_FUNC(set80211quietcount, val, d)
1435 set80211(s, IEEE80211_IOC_QUIET_COUNT, atoi(val), 0, NULL);
1439 DECL_CMD_FUNC(set80211quietduration, val, d)
1441 set80211(s, IEEE80211_IOC_QUIET_DUR, atoi(val), 0, NULL);
1445 DECL_CMD_FUNC(set80211quietoffset, val, d)
1447 set80211(s, IEEE80211_IOC_QUIET_OFFSET, atoi(val), 0, NULL);
1451 set80211bgscan(const char *val, int d, int s, const struct afswtch *rafp)
1453 set80211(s, IEEE80211_IOC_BGSCAN, d, 0, NULL);
1457 DECL_CMD_FUNC(set80211bgscanidle, val, d)
1459 set80211(s, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL);
1463 DECL_CMD_FUNC(set80211bgscanintvl, val, d)
1465 set80211(s, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL);
1469 DECL_CMD_FUNC(set80211scanvalid, val, d)
1471 set80211(s, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL);
1475 * Parse an optional trailing specification of which netbands
1476 * to apply a parameter to. This is basically the same syntax
1477 * as used for channels but you can concatenate to specify
1478 * multiple. For example:
1479 * 14:abg apply to 11a, 11b, and 11g
1480 * 6:ht apply to 11na and 11ng
1481 * We don't make a big effort to catch silly things; this is
1482 * really a convenience mechanism.
1485 getmodeflags(const char *val)
1492 cp = strchr(val, ':');
1494 for (cp++; isalpha((int) *cp); cp++) {
1495 /* accept mixed case */
1500 case 'a': /* 802.11a */
1501 flags |= IEEE80211_CHAN_A;
1503 case 'b': /* 802.11b */
1504 flags |= IEEE80211_CHAN_B;
1506 case 'g': /* 802.11g */
1507 flags |= IEEE80211_CHAN_G;
1509 case 'n': /* 802.11n */
1510 flags |= IEEE80211_CHAN_HT;
1512 case 'd': /* dt = Atheros Dynamic Turbo */
1513 flags |= IEEE80211_CHAN_TURBO;
1515 case 't': /* ht, dt, st, t */
1516 /* dt and unadorned t specify Dynamic Turbo */
1517 if ((flags & (IEEE80211_CHAN_STURBO|IEEE80211_CHAN_HT)) == 0)
1518 flags |= IEEE80211_CHAN_TURBO;
1520 case 's': /* st = Atheros Static Turbo */
1521 flags |= IEEE80211_CHAN_STURBO;
1523 case 'h': /* 1/2-width channels */
1524 flags |= IEEE80211_CHAN_HALF;
1526 case 'q': /* 1/4-width channels */
1527 flags |= IEEE80211_CHAN_QUARTER;
1530 /* XXX set HT too? */
1531 flags |= IEEE80211_CHAN_VHT;
1534 errx(-1, "%s: Invalid mode attribute %c\n",
1542 #define _APPLY(_flags, _base, _param, _v) do { \
1543 if (_flags & IEEE80211_CHAN_HT) { \
1544 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1545 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1546 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1547 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1548 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1550 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1552 if (_flags & IEEE80211_CHAN_TURBO) { \
1553 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1554 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1555 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1556 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1557 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1559 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1561 if (_flags & IEEE80211_CHAN_STURBO) \
1562 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1563 if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1564 _base.params[IEEE80211_MODE_11A]._param = _v; \
1565 if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1566 _base.params[IEEE80211_MODE_11G]._param = _v; \
1567 if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1568 _base.params[IEEE80211_MODE_11B]._param = _v; \
1569 if (_flags & IEEE80211_CHAN_HALF) \
1570 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1571 if (_flags & IEEE80211_CHAN_QUARTER) \
1572 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1574 #define _APPLY1(_flags, _base, _param, _v) do { \
1575 if (_flags & IEEE80211_CHAN_HT) { \
1576 if (_flags & IEEE80211_CHAN_5GHZ) \
1577 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1579 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1580 } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \
1581 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1582 else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \
1583 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1584 else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \
1585 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1586 else if (_flags & IEEE80211_CHAN_HALF) \
1587 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1588 else if (_flags & IEEE80211_CHAN_QUARTER) \
1589 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1590 else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1591 _base.params[IEEE80211_MODE_11A]._param = _v; \
1592 else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1593 _base.params[IEEE80211_MODE_11G]._param = _v; \
1594 else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1595 _base.params[IEEE80211_MODE_11B]._param = _v; \
1597 #define _APPLY_RATE(_flags, _base, _param, _v) do { \
1598 if (_flags & IEEE80211_CHAN_HT) { \
1599 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1601 _APPLY(_flags, _base, _param, _v); \
1603 #define _APPLY_RATE1(_flags, _base, _param, _v) do { \
1604 if (_flags & IEEE80211_CHAN_HT) { \
1605 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1607 _APPLY1(_flags, _base, _param, _v); \
1611 DECL_CMD_FUNC(set80211roamrssi, val, d)
1613 double v = atof(val);
1618 errx(-1, "invalid rssi (must be .5 dBm units)");
1619 flags = getmodeflags(val);
1621 if (flags == 0) { /* NB: no flags => current channel */
1622 flags = getcurchan(s)->ic_flags;
1623 _APPLY1(flags, roamparams, rssi, rssi);
1625 _APPLY(flags, roamparams, rssi, rssi);
1626 callback_register(setroam_cb, &roamparams);
1630 getrate(const char *val, const char *tag)
1632 double v = atof(val);
1637 errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag);
1638 return rate; /* NB: returns 2x the specified value */
1642 DECL_CMD_FUNC(set80211roamrate, val, d)
1646 rate = getrate(val, "roam");
1647 flags = getmodeflags(val);
1649 if (flags == 0) { /* NB: no flags => current channel */
1650 flags = getcurchan(s)->ic_flags;
1651 _APPLY_RATE1(flags, roamparams, rate, rate);
1653 _APPLY_RATE(flags, roamparams, rate, rate);
1654 callback_register(setroam_cb, &roamparams);
1658 DECL_CMD_FUNC(set80211mcastrate, val, d)
1662 rate = getrate(val, "mcast");
1663 flags = getmodeflags(val);
1665 if (flags == 0) { /* NB: no flags => current channel */
1666 flags = getcurchan(s)->ic_flags;
1667 _APPLY_RATE1(flags, txparams, mcastrate, rate);
1669 _APPLY_RATE(flags, txparams, mcastrate, rate);
1670 callback_register(settxparams_cb, &txparams);
1674 DECL_CMD_FUNC(set80211mgtrate, val, d)
1678 rate = getrate(val, "mgmt");
1679 flags = getmodeflags(val);
1681 if (flags == 0) { /* NB: no flags => current channel */
1682 flags = getcurchan(s)->ic_flags;
1683 _APPLY_RATE1(flags, txparams, mgmtrate, rate);
1685 _APPLY_RATE(flags, txparams, mgmtrate, rate);
1686 callback_register(settxparams_cb, &txparams);
1690 DECL_CMD_FUNC(set80211ucastrate, val, d)
1695 flags = getmodeflags(val);
1696 if (isanyarg(val)) {
1697 if (flags == 0) { /* NB: no flags => current channel */
1698 flags = getcurchan(s)->ic_flags;
1699 _APPLY1(flags, txparams, ucastrate,
1700 IEEE80211_FIXED_RATE_NONE);
1702 _APPLY(flags, txparams, ucastrate,
1703 IEEE80211_FIXED_RATE_NONE);
1705 int rate = getrate(val, "ucast");
1706 if (flags == 0) { /* NB: no flags => current channel */
1707 flags = getcurchan(s)->ic_flags;
1708 _APPLY_RATE1(flags, txparams, ucastrate, rate);
1710 _APPLY_RATE(flags, txparams, ucastrate, rate);
1712 callback_register(settxparams_cb, &txparams);
1716 DECL_CMD_FUNC(set80211maxretry, val, d)
1718 int v = atoi(val), flags;
1720 flags = getmodeflags(val);
1722 if (flags == 0) { /* NB: no flags => current channel */
1723 flags = getcurchan(s)->ic_flags;
1724 _APPLY1(flags, txparams, maxretry, v);
1726 _APPLY(flags, txparams, maxretry, v);
1727 callback_register(settxparams_cb, &txparams);
1733 DECL_CMD_FUNC(set80211fragthreshold, val, d)
1735 set80211(s, IEEE80211_IOC_FRAGTHRESHOLD,
1736 isundefarg(val) ? IEEE80211_FRAG_MAX : atoi(val), 0, NULL);
1740 DECL_CMD_FUNC(set80211bmissthreshold, val, d)
1742 set80211(s, IEEE80211_IOC_BMISSTHRESHOLD,
1743 isundefarg(val) ? IEEE80211_HWBMISS_MAX : atoi(val), 0, NULL);
1747 set80211burst(const char *val, int d, int s, const struct afswtch *rafp)
1749 set80211(s, IEEE80211_IOC_BURST, d, 0, NULL);
1753 set80211doth(const char *val, int d, int s, const struct afswtch *rafp)
1755 set80211(s, IEEE80211_IOC_DOTH, d, 0, NULL);
1759 set80211dfs(const char *val, int d, int s, const struct afswtch *rafp)
1761 set80211(s, IEEE80211_IOC_DFS, d, 0, NULL);
1765 set80211shortgi(const char *val, int d, int s, const struct afswtch *rafp)
1767 set80211(s, IEEE80211_IOC_SHORTGI,
1768 d ? (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) : 0,
1772 /* XXX 11ac density/size is different */
1774 set80211ampdu(const char *val, int d, int s, const struct afswtch *rafp)
1778 if (get80211val(s, IEEE80211_IOC_AMPDU, &du) < 0)
1779 errx(-1, "cannot set AMPDU setting");
1785 set80211(s, IEEE80211_IOC_AMPDU, ampdu, 0, NULL);
1789 set80211stbc(const char *val, int d, int s, const struct afswtch *rafp)
1793 if (get80211val(s, IEEE80211_IOC_STBC, &stbc) < 0)
1794 errx(-1, "cannot set STBC setting");
1800 set80211(s, IEEE80211_IOC_STBC, stbc, 0, NULL);
1804 set80211ldpc(const char *val, int d, int s, const struct afswtch *rafp)
1808 if (get80211val(s, IEEE80211_IOC_LDPC, &ldpc) < 0)
1809 errx(-1, "cannot set LDPC setting");
1815 set80211(s, IEEE80211_IOC_LDPC, ldpc, 0, NULL);
1819 set80211uapsd(const char *val, int d, int s, const struct afswtch *rafp)
1821 set80211(s, IEEE80211_IOC_UAPSD, d, 0, NULL);
1825 DECL_CMD_FUNC(set80211ampdulimit, val, d)
1829 switch (atoi(val)) {
1832 v = IEEE80211_HTCAP_MAXRXAMPDU_8K;
1836 v = IEEE80211_HTCAP_MAXRXAMPDU_16K;
1840 v = IEEE80211_HTCAP_MAXRXAMPDU_32K;
1844 v = IEEE80211_HTCAP_MAXRXAMPDU_64K;
1847 errx(-1, "invalid A-MPDU limit %s", val);
1849 set80211(s, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL);
1852 /* XXX 11ac density/size is different */
1854 DECL_CMD_FUNC(set80211ampdudensity, val, d)
1858 if (isanyarg(val) || strcasecmp(val, "na") == 0)
1859 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1860 else switch ((int)(atof(val)*4)) {
1862 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1865 v = IEEE80211_HTCAP_MPDUDENSITY_025;
1868 v = IEEE80211_HTCAP_MPDUDENSITY_05;
1871 v = IEEE80211_HTCAP_MPDUDENSITY_1;
1874 v = IEEE80211_HTCAP_MPDUDENSITY_2;
1877 v = IEEE80211_HTCAP_MPDUDENSITY_4;
1880 v = IEEE80211_HTCAP_MPDUDENSITY_8;
1883 v = IEEE80211_HTCAP_MPDUDENSITY_16;
1886 errx(-1, "invalid A-MPDU density %s", val);
1888 set80211(s, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL);
1892 set80211amsdu(const char *val, int d, int s, const struct afswtch *rafp)
1896 if (get80211val(s, IEEE80211_IOC_AMSDU, &amsdu) < 0)
1897 err(-1, "cannot get AMSDU setting");
1903 set80211(s, IEEE80211_IOC_AMSDU, amsdu, 0, NULL);
1907 DECL_CMD_FUNC(set80211amsdulimit, val, d)
1909 set80211(s, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL);
1913 set80211puren(const char *val, int d, int s, const struct afswtch *rafp)
1915 set80211(s, IEEE80211_IOC_PUREN, d, 0, NULL);
1919 set80211htcompat(const char *val, int d, int s, const struct afswtch *rafp)
1921 set80211(s, IEEE80211_IOC_HTCOMPAT, d, 0, NULL);
1925 set80211htconf(const char *val, int d, int s, const struct afswtch *rafp)
1927 set80211(s, IEEE80211_IOC_HTCONF, d, 0, NULL);
1932 set80211dwds(const char *val, int d, int s, const struct afswtch *rafp)
1934 set80211(s, IEEE80211_IOC_DWDS, d, 0, NULL);
1938 set80211inact(const char *val, int d, int s, const struct afswtch *rafp)
1940 set80211(s, IEEE80211_IOC_INACTIVITY, d, 0, NULL);
1944 set80211tsn(const char *val, int d, int s, const struct afswtch *rafp)
1946 set80211(s, IEEE80211_IOC_TSN, d, 0, NULL);
1950 set80211dotd(const char *val, int d, int s, const struct afswtch *rafp)
1952 set80211(s, IEEE80211_IOC_DOTD, d, 0, NULL);
1956 set80211smps(const char *val, int d, int s, const struct afswtch *rafp)
1958 set80211(s, IEEE80211_IOC_SMPS, d, 0, NULL);
1962 set80211rifs(const char *val, int d, int s, const struct afswtch *rafp)
1964 set80211(s, IEEE80211_IOC_RIFS, d, 0, NULL);
1968 set80211vhtconf(const char *val, int d, int s, const struct afswtch *rafp)
1970 if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
1971 errx(-1, "cannot set VHT setting");
1972 printf("%s: vhtconf=0x%08x, d=%d\n", __func__, vhtconf, d);
1978 printf("%s: vhtconf is now 0x%08x\n", __func__, vhtconf);
1979 set80211(s, IEEE80211_IOC_VHTCONF, vhtconf, 0, NULL);
1983 DECL_CMD_FUNC(set80211tdmaslot, val, d)
1985 set80211(s, IEEE80211_IOC_TDMA_SLOT, atoi(val), 0, NULL);
1989 DECL_CMD_FUNC(set80211tdmaslotcnt, val, d)
1991 set80211(s, IEEE80211_IOC_TDMA_SLOTCNT, atoi(val), 0, NULL);
1995 DECL_CMD_FUNC(set80211tdmaslotlen, val, d)
1997 set80211(s, IEEE80211_IOC_TDMA_SLOTLEN, atoi(val), 0, NULL);
2001 DECL_CMD_FUNC(set80211tdmabintval, val, d)
2003 set80211(s, IEEE80211_IOC_TDMA_BINTERVAL, atoi(val), 0, NULL);
2007 DECL_CMD_FUNC(set80211meshttl, val, d)
2009 set80211(s, IEEE80211_IOC_MESH_TTL, atoi(val), 0, NULL);
2013 DECL_CMD_FUNC(set80211meshforward, val, d)
2015 set80211(s, IEEE80211_IOC_MESH_FWRD, d, 0, NULL);
2019 DECL_CMD_FUNC(set80211meshgate, val, d)
2021 set80211(s, IEEE80211_IOC_MESH_GATE, d, 0, NULL);
2025 DECL_CMD_FUNC(set80211meshpeering, val, d)
2027 set80211(s, IEEE80211_IOC_MESH_AP, d, 0, NULL);
2031 DECL_CMD_FUNC(set80211meshmetric, val, d)
2035 memcpy(v, val, sizeof(v));
2036 set80211(s, IEEE80211_IOC_MESH_PR_METRIC, 0, 0, v);
2040 DECL_CMD_FUNC(set80211meshpath, val, d)
2044 memcpy(v, val, sizeof(v));
2045 set80211(s, IEEE80211_IOC_MESH_PR_PATH, 0, 0, v);
2049 regdomain_sort(const void *a, const void *b)
2052 (IEEE80211_CHAN_ALLTURBO|IEEE80211_CHAN_HALF|IEEE80211_CHAN_QUARTER)
2053 const struct ieee80211_channel *ca = a;
2054 const struct ieee80211_channel *cb = b;
2056 return ca->ic_freq == cb->ic_freq ?
2057 (ca->ic_flags & CHAN_ALL) - (cb->ic_flags & CHAN_ALL) :
2058 ca->ic_freq - cb->ic_freq;
2062 static const struct ieee80211_channel *
2063 chanlookup(const struct ieee80211_channel chans[], int nchans,
2064 int freq, int flags)
2068 flags &= IEEE80211_CHAN_ALLTURBO;
2069 for (i = 0; i < nchans; i++) {
2070 const struct ieee80211_channel *c = &chans[i];
2071 if (c->ic_freq == freq &&
2072 (c->ic_flags & IEEE80211_CHAN_ALLTURBO) == flags)
2079 chanfind(const struct ieee80211_channel chans[], int nchans, int flags)
2083 for (i = 0; i < nchans; i++) {
2084 const struct ieee80211_channel *c = &chans[i];
2085 if ((c->ic_flags & flags) == flags)
2092 * Check channel compatibility.
2095 checkchan(const struct ieee80211req_chaninfo *avail, int freq, int flags)
2097 flags &= ~REQ_FLAGS;
2099 * Check if exact channel is in the calibration table;
2100 * everything below is to deal with channels that we
2101 * want to include but that are not explicitly listed.
2103 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, flags) != NULL)
2105 if (flags & IEEE80211_CHAN_GSM) {
2107 * XXX GSM frequency mapping is handled in the kernel
2108 * so we cannot find them in the calibration table;
2109 * just accept the channel and the kernel will reject
2110 * the channel list if it's wrong.
2115 * If this is a 1/2 or 1/4 width channel allow it if a full
2116 * width channel is present for this frequency, and the device
2117 * supports fractional channels on this band. This is a hack
2118 * that avoids bloating the calibration table; it may be better
2119 * by per-band attributes though (we are effectively calculating
2120 * this attribute by scanning the channel list ourself).
2122 if ((flags & (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == 0)
2124 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq,
2125 flags &~ (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == NULL)
2127 if (flags & IEEE80211_CHAN_HALF) {
2128 return chanfind(avail->ic_chans, avail->ic_nchans,
2129 IEEE80211_CHAN_HALF |
2130 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2132 return chanfind(avail->ic_chans, avail->ic_nchans,
2133 IEEE80211_CHAN_QUARTER |
2134 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2139 regdomain_addchans(struct ieee80211req_chaninfo *ci,
2140 const netband_head *bands,
2141 const struct ieee80211_regdomain *reg,
2143 const struct ieee80211req_chaninfo *avail)
2145 const struct netband *nb;
2146 const struct freqband *b;
2147 struct ieee80211_channel *c, *prev;
2148 int freq, hi_adj, lo_adj, channelSep;
2151 hi_adj = (chanFlags & IEEE80211_CHAN_HT40U) ? -20 : 0;
2152 lo_adj = (chanFlags & IEEE80211_CHAN_HT40D) ? 20 : 0;
2153 channelSep = (chanFlags & IEEE80211_CHAN_2GHZ) ? 0 : 40;
2155 LIST_FOREACH(nb, bands, next) {
2158 printf("%s:", __func__);
2159 printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS);
2160 printb(" bandFlags", nb->flags | b->flags,
2161 IEEE80211_CHAN_BITS);
2166 for (freq = b->freqStart + lo_adj;
2167 freq <= b->freqEnd + hi_adj; freq += b->chanSep) {
2169 * Construct flags for the new channel. We take
2170 * the attributes from the band descriptions except
2171 * for HT40 which is enabled generically (i.e. +/-
2172 * extension channel) in the band description and
2173 * then constrained according by channel separation.
2175 flags = nb->flags | b->flags;
2178 * VHT first - HT is a subset.
2180 if (flags & IEEE80211_CHAN_VHT) {
2181 if ((chanFlags & IEEE80211_CHAN_VHT20) &&
2182 (flags & IEEE80211_CHAN_VHT20) == 0) {
2184 printf("%u: skip, not a "
2185 "VHT20 channel\n", freq);
2188 if ((chanFlags & IEEE80211_CHAN_VHT40) &&
2189 (flags & IEEE80211_CHAN_VHT40) == 0) {
2191 printf("%u: skip, not a "
2192 "VHT40 channel\n", freq);
2195 if ((chanFlags & IEEE80211_CHAN_VHT80) &&
2196 (flags & IEEE80211_CHAN_VHT80) == 0) {
2198 printf("%u: skip, not a "
2199 "VHT80 channel\n", freq);
2202 if ((chanFlags & IEEE80211_CHAN_VHT160) &&
2203 (flags & IEEE80211_CHAN_VHT160) == 0) {
2205 printf("%u: skip, not a "
2206 "VHT160 channel\n", freq);
2209 if ((chanFlags & IEEE80211_CHAN_VHT80P80) &&
2210 (flags & IEEE80211_CHAN_VHT80P80) == 0) {
2212 printf("%u: skip, not a "
2213 "VHT80+80 channel\n", freq);
2216 flags &= ~IEEE80211_CHAN_VHT;
2217 flags |= chanFlags & IEEE80211_CHAN_VHT;
2220 /* Now, constrain HT */
2221 if (flags & IEEE80211_CHAN_HT) {
2223 * HT channels are generated specially; we're
2224 * called to add HT20, HT40+, and HT40- chan's
2225 * so we need to expand only band specs for
2226 * the HT channel type being added.
2228 if ((chanFlags & IEEE80211_CHAN_HT20) &&
2229 (flags & IEEE80211_CHAN_HT20) == 0) {
2231 printf("%u: skip, not an "
2232 "HT20 channel\n", freq);
2235 if ((chanFlags & IEEE80211_CHAN_HT40) &&
2236 (flags & IEEE80211_CHAN_HT40) == 0) {
2238 printf("%u: skip, not an "
2239 "HT40 channel\n", freq);
2242 /* NB: HT attribute comes from caller */
2243 flags &= ~IEEE80211_CHAN_HT;
2244 flags |= chanFlags & IEEE80211_CHAN_HT;
2247 * Check if device can operate on this frequency.
2249 if (!checkchan(avail, freq, flags)) {
2251 printf("%u: skip, ", freq);
2252 printb("flags", flags,
2253 IEEE80211_CHAN_BITS);
2254 printf(" not available\n");
2258 if ((flags & REQ_ECM) && !reg->ecm) {
2260 printf("%u: skip, ECM channel\n", freq);
2263 if ((flags & REQ_INDOOR) && reg->location == 'O') {
2265 printf("%u: skip, indoor channel\n",
2269 if ((flags & REQ_OUTDOOR) && reg->location == 'I') {
2271 printf("%u: skip, outdoor channel\n",
2275 if ((flags & IEEE80211_CHAN_HT40) &&
2276 prev != NULL && (freq - prev->ic_freq) < channelSep) {
2278 printf("%u: skip, only %u channel "
2279 "separation, need %d\n", freq,
2280 freq - prev->ic_freq, channelSep);
2283 if (ci->ic_nchans == IEEE80211_CHAN_MAX) {
2285 printf("%u: skip, channel table full\n",
2289 c = &ci->ic_chans[ci->ic_nchans++];
2290 memset(c, 0, sizeof(*c));
2292 c->ic_flags = flags;
2293 if (c->ic_flags & IEEE80211_CHAN_DFS)
2294 c->ic_maxregpower = nb->maxPowerDFS;
2296 c->ic_maxregpower = nb->maxPower;
2298 printf("[%3d] add freq %u ",
2299 ci->ic_nchans-1, c->ic_freq);
2300 printb("flags", c->ic_flags, IEEE80211_CHAN_BITS);
2301 printf(" power %u\n", c->ic_maxregpower);
2303 /* NB: kernel fills in other fields */
2310 regdomain_makechannels(
2311 struct ieee80211_regdomain_req *req,
2312 const struct ieee80211_devcaps_req *dc)
2314 struct regdata *rdp = getregdata();
2315 const struct country *cc;
2316 const struct ieee80211_regdomain *reg = &req->rd;
2317 struct ieee80211req_chaninfo *ci = &req->chaninfo;
2318 const struct regdomain *rd;
2321 * Locate construction table for new channel list. We treat
2322 * the regdomain/SKU as definitive so a country can be in
2323 * multiple with different properties (e.g. US in FCC+FCC3).
2324 * If no regdomain is specified then we fallback on the country
2325 * code to find the associated regdomain since countries always
2326 * belong to at least one regdomain.
2328 if (reg->regdomain == 0) {
2329 cc = lib80211_country_findbycc(rdp, reg->country);
2331 errx(1, "internal error, country %d not found",
2335 rd = lib80211_regdomain_findbysku(rdp, reg->regdomain);
2337 errx(1, "internal error, regdomain %d not found",
2339 if (rd->sku != SKU_DEBUG) {
2341 * regdomain_addchans incrememnts the channel count for
2342 * each channel it adds so initialize ic_nchans to zero.
2343 * Note that we know we have enough space to hold all possible
2344 * channels because the devcaps list size was used to
2345 * allocate our request.
2348 if (!LIST_EMPTY(&rd->bands_11b))
2349 regdomain_addchans(ci, &rd->bands_11b, reg,
2350 IEEE80211_CHAN_B, &dc->dc_chaninfo);
2351 if (!LIST_EMPTY(&rd->bands_11g))
2352 regdomain_addchans(ci, &rd->bands_11g, reg,
2353 IEEE80211_CHAN_G, &dc->dc_chaninfo);
2354 if (!LIST_EMPTY(&rd->bands_11a))
2355 regdomain_addchans(ci, &rd->bands_11a, reg,
2356 IEEE80211_CHAN_A, &dc->dc_chaninfo);
2357 if (!LIST_EMPTY(&rd->bands_11na) && dc->dc_htcaps != 0) {
2358 regdomain_addchans(ci, &rd->bands_11na, reg,
2359 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20,
2361 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2362 regdomain_addchans(ci, &rd->bands_11na, reg,
2363 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U,
2365 regdomain_addchans(ci, &rd->bands_11na, reg,
2366 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D,
2370 if (!LIST_EMPTY(&rd->bands_11ac) && dc->dc_vhtcaps != 0) {
2371 regdomain_addchans(ci, &rd->bands_11ac, reg,
2372 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20 |
2373 IEEE80211_CHAN_VHT20,
2376 /* VHT40 is a function of HT40.. */
2377 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2378 regdomain_addchans(ci, &rd->bands_11ac, reg,
2379 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U |
2380 IEEE80211_CHAN_VHT40U,
2382 regdomain_addchans(ci, &rd->bands_11ac, reg,
2383 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D |
2384 IEEE80211_CHAN_VHT40D,
2388 /* VHT80 is mandatory (and so should be VHT40 above). */
2390 regdomain_addchans(ci, &rd->bands_11ac, reg,
2391 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U |
2392 IEEE80211_CHAN_VHT80,
2394 regdomain_addchans(ci, &rd->bands_11ac, reg,
2395 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D |
2396 IEEE80211_CHAN_VHT80,
2400 /* XXX TODO: VHT80P80, VHT160 */
2403 if (!LIST_EMPTY(&rd->bands_11ng) && dc->dc_htcaps != 0) {
2404 regdomain_addchans(ci, &rd->bands_11ng, reg,
2405 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20,
2407 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2408 regdomain_addchans(ci, &rd->bands_11ng, reg,
2409 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U,
2411 regdomain_addchans(ci, &rd->bands_11ng, reg,
2412 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D,
2416 qsort(ci->ic_chans, ci->ic_nchans, sizeof(ci->ic_chans[0]),
2419 memcpy(ci, &dc->dc_chaninfo,
2420 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
2424 list_countries(void)
2426 struct regdata *rdp = getregdata();
2427 const struct country *cp;
2428 const struct regdomain *dp;
2432 printf("\nCountry codes:\n");
2433 LIST_FOREACH(cp, &rdp->countries, next) {
2434 printf("%2s %-15.15s%s", cp->isoname,
2435 cp->name, ((i+1)%4) == 0 ? "\n" : " ");
2439 printf("\nRegulatory domains:\n");
2440 LIST_FOREACH(dp, &rdp->domains, next) {
2441 printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " ");
2448 defaultcountry(const struct regdomain *rd)
2450 struct regdata *rdp = getregdata();
2451 const struct country *cc;
2453 cc = lib80211_country_findbycc(rdp, rd->cc->code);
2455 errx(1, "internal error, ISO country code %d not "
2456 "defined for regdomain %s", rd->cc->code, rd->name);
2457 regdomain.country = cc->code;
2458 regdomain.isocc[0] = cc->isoname[0];
2459 regdomain.isocc[1] = cc->isoname[1];
2463 DECL_CMD_FUNC(set80211regdomain, val, d)
2465 struct regdata *rdp = getregdata();
2466 const struct regdomain *rd;
2468 rd = lib80211_regdomain_findbyname(rdp, val);
2471 long sku = strtol(val, &eptr, 0);
2474 rd = lib80211_regdomain_findbysku(rdp, sku);
2475 if (eptr == val || rd == NULL)
2476 errx(1, "unknown regdomain %s", val);
2479 regdomain.regdomain = rd->sku;
2480 if (regdomain.country == 0 && rd->cc != NULL) {
2482 * No country code setup and there's a default
2483 * one for this regdomain fill it in.
2487 callback_register(setregdomain_cb, ®domain);
2491 DECL_CMD_FUNC(set80211country, val, d)
2493 struct regdata *rdp = getregdata();
2494 const struct country *cc;
2496 cc = lib80211_country_findbyname(rdp, val);
2499 long code = strtol(val, &eptr, 0);
2502 cc = lib80211_country_findbycc(rdp, code);
2503 if (eptr == val || cc == NULL)
2504 errx(1, "unknown ISO country code %s", val);
2507 regdomain.regdomain = cc->rd->sku;
2508 regdomain.country = cc->code;
2509 regdomain.isocc[0] = cc->isoname[0];
2510 regdomain.isocc[1] = cc->isoname[1];
2511 callback_register(setregdomain_cb, ®domain);
2515 set80211location(const char *val, int d, int s, const struct afswtch *rafp)
2518 regdomain.location = d;
2519 callback_register(setregdomain_cb, ®domain);
2523 set80211ecm(const char *val, int d, int s, const struct afswtch *rafp)
2527 callback_register(setregdomain_cb, ®domain);
2543 if (spacer != '\t') {
2547 col = 8; /* 8-col tab */
2551 LINE_CHECK(const char *fmt, ...)
2558 n = vsnprintf(buf+1, sizeof(buf)-1, fmt, ap);
2571 getmaxrate(const uint8_t rates[15], uint8_t nrates)
2573 int i, maxrate = -1;
2575 for (i = 0; i < nrates; i++) {
2576 int rate = rates[i] & IEEE80211_RATE_VAL;
2584 getcaps(int capinfo)
2586 static char capstring[32];
2587 char *cp = capstring;
2589 if (capinfo & IEEE80211_CAPINFO_ESS)
2591 if (capinfo & IEEE80211_CAPINFO_IBSS)
2593 if (capinfo & IEEE80211_CAPINFO_CF_POLLABLE)
2595 if (capinfo & IEEE80211_CAPINFO_CF_POLLREQ)
2597 if (capinfo & IEEE80211_CAPINFO_PRIVACY)
2599 if (capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)
2601 if (capinfo & IEEE80211_CAPINFO_PBCC)
2603 if (capinfo & IEEE80211_CAPINFO_CHNL_AGILITY)
2605 if (capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME)
2607 if (capinfo & IEEE80211_CAPINFO_RSN)
2609 if (capinfo & IEEE80211_CAPINFO_DSSSOFDM)
2618 static char flagstring[32];
2619 char *cp = flagstring;
2621 if (flags & IEEE80211_NODE_AUTH)
2623 if (flags & IEEE80211_NODE_QOS)
2625 if (flags & IEEE80211_NODE_ERP)
2627 if (flags & IEEE80211_NODE_PWR_MGT)
2629 if (flags & IEEE80211_NODE_HT) {
2631 if (flags & IEEE80211_NODE_HTCOMPAT)
2634 if (flags & IEEE80211_NODE_VHT)
2636 if (flags & IEEE80211_NODE_WPS)
2638 if (flags & IEEE80211_NODE_TSN)
2640 if (flags & IEEE80211_NODE_AMPDU_TX)
2642 if (flags & IEEE80211_NODE_AMPDU_RX)
2644 if (flags & IEEE80211_NODE_MIMO_PS) {
2646 if (flags & IEEE80211_NODE_MIMO_RTS)
2649 if (flags & IEEE80211_NODE_RIFS)
2651 if (flags & IEEE80211_NODE_SGI40) {
2653 if (flags & IEEE80211_NODE_SGI20)
2655 } else if (flags & IEEE80211_NODE_SGI20)
2657 if (flags & IEEE80211_NODE_AMSDU_TX)
2659 if (flags & IEEE80211_NODE_AMSDU_RX)
2661 if (flags & IEEE80211_NODE_UAPSD)
2663 if (flags & IEEE80211_NODE_LDPC)
2670 printie(const char* tag, const uint8_t *ie, size_t ielen, int maxlen)
2674 maxlen -= strlen(tag)+2;
2675 if (2*ielen > maxlen)
2678 for (; ielen > 0; ie++, ielen--) {
2681 printf("%02x", *ie);
2689 #define LE_READ_2(p) \
2691 ((((const u_int8_t *)(p))[0] ) | \
2692 (((const u_int8_t *)(p))[1] << 8)))
2693 #define LE_READ_4(p) \
2695 ((((const u_int8_t *)(p))[0] ) | \
2696 (((const u_int8_t *)(p))[1] << 8) | \
2697 (((const u_int8_t *)(p))[2] << 16) | \
2698 (((const u_int8_t *)(p))[3] << 24)))
2701 * NB: The decoding routines assume a properly formatted ie
2702 * which should be safe as the kernel only retains them
2707 printwmeparam(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2709 #define MS(_v, _f) (((_v) & _f) >> _f##_S)
2710 static const char *acnames[] = { "BE", "BK", "VO", "VI" };
2711 const struct ieee80211_wme_param *wme =
2712 (const struct ieee80211_wme_param *) ie;
2718 printf("<qosinfo 0x%x", wme->param_qosInfo);
2719 ie += offsetof(struct ieee80211_wme_param, params_acParams);
2720 for (i = 0; i < WME_NUM_AC; i++) {
2721 const struct ieee80211_wme_acparams *ac =
2722 &wme->params_acParams[i];
2724 printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]"
2726 , MS(ac->acp_aci_aifsn, WME_PARAM_ACM) ? "acm " : ""
2727 , MS(ac->acp_aci_aifsn, WME_PARAM_AIFSN)
2728 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMIN)
2729 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMAX)
2730 , LE_READ_2(&ac->acp_txop)
2738 printwmeinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2742 const struct ieee80211_wme_info *wme =
2743 (const struct ieee80211_wme_info *) ie;
2744 printf("<version 0x%x info 0x%x>",
2745 wme->wme_version, wme->wme_info);
2750 printvhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2754 const struct ieee80211_ie_vhtcap *vhtcap =
2755 (const struct ieee80211_ie_vhtcap *) ie;
2756 uint32_t vhtcap_info = LE_READ_4(&vhtcap->vht_cap_info);
2758 printf("<cap 0x%08x", vhtcap_info);
2759 printf(" rx_mcs_map 0x%x",
2760 LE_READ_2(&vhtcap->supp_mcs.rx_mcs_map));
2761 printf(" rx_highest %d",
2762 LE_READ_2(&vhtcap->supp_mcs.rx_highest) & 0x1fff);
2763 printf(" tx_mcs_map 0x%x",
2764 LE_READ_2(&vhtcap->supp_mcs.tx_mcs_map));
2765 printf(" tx_highest %d",
2766 LE_READ_2(&vhtcap->supp_mcs.tx_highest) & 0x1fff);
2773 printvhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2777 const struct ieee80211_ie_vht_operation *vhtinfo =
2778 (const struct ieee80211_ie_vht_operation *) ie;
2780 printf("<chw %d freq1_idx %d freq2_idx %d basic_mcs_set 0x%04x>",
2781 vhtinfo->chan_width,
2782 vhtinfo->center_freq_seg1_idx,
2783 vhtinfo->center_freq_seg2_idx,
2784 LE_READ_2(&vhtinfo->basic_mcs_set));
2789 printvhtpwrenv(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2792 static const char *txpwrmap[] = {
2799 const struct ieee80211_ie_vht_txpwrenv *vhtpwr =
2800 (const struct ieee80211_ie_vht_txpwrenv *) ie;
2802 const char *sep = "";
2804 /* Get count; trim at ielen */
2805 n = (vhtpwr->tx_info &
2806 IEEE80211_VHT_TXPWRENV_INFO_COUNT_MASK) + 1;
2810 printf("<tx_info 0x%02x pwr:[", vhtpwr->tx_info);
2811 for (i = 0; i < n; i++) {
2812 printf("%s%s:%.2f", sep, txpwrmap[i],
2813 ((float) ((int8_t) ie[i+3])) / 2.0);
2822 printhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2826 const struct ieee80211_ie_htcap *htcap =
2827 (const struct ieee80211_ie_htcap *) ie;
2831 printf("<cap 0x%x param 0x%x",
2832 LE_READ_2(&htcap->hc_cap), htcap->hc_param);
2835 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2836 if (isset(htcap->hc_mcsset, i)) {
2837 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2838 if (isclr(htcap->hc_mcsset, j))
2842 printf("%s%u", sep, i);
2844 printf("%s%u-%u", sep, i, j);
2848 printf("] extcap 0x%x txbf 0x%x antenna 0x%x>",
2849 LE_READ_2(&htcap->hc_extcap),
2850 LE_READ_4(&htcap->hc_txbf),
2856 printhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2860 const struct ieee80211_ie_htinfo *htinfo =
2861 (const struct ieee80211_ie_htinfo *) ie;
2865 printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel,
2866 htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3,
2867 LE_READ_2(&htinfo->hi_byte45));
2868 printf(" basicmcs[");
2870 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2871 if (isset(htinfo->hi_basicmcsset, i)) {
2872 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2873 if (isclr(htinfo->hi_basicmcsset, j))
2877 printf("%s%u", sep, i);
2879 printf("%s%u-%u", sep, i, j);
2888 printathie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2893 const struct ieee80211_ath_ie *ath =
2894 (const struct ieee80211_ath_ie *)ie;
2897 if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME)
2899 if (ath->ath_capability & ATHEROS_CAP_COMPRESSION)
2901 if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME)
2903 if (ath->ath_capability & ATHEROS_CAP_XR)
2905 if (ath->ath_capability & ATHEROS_CAP_AR)
2907 if (ath->ath_capability & ATHEROS_CAP_BURST)
2909 if (ath->ath_capability & ATHEROS_CAP_WME)
2911 if (ath->ath_capability & ATHEROS_CAP_BOOST)
2913 printf("0x%x>", LE_READ_2(ath->ath_defkeyix));
2919 printmeshconf(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2924 const struct ieee80211_meshconf_ie *mconf =
2925 (const struct ieee80211_meshconf_ie *)ie;
2927 if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP)
2932 if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME)
2936 printf(" CONGESTION:");
2937 if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED)
2942 if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF)
2947 if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED)
2951 printf(" FORM:0x%x CAPS:0x%x>", mconf->conf_form,
2957 printbssload(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2961 const struct ieee80211_bss_load_ie *bssload =
2962 (const struct ieee80211_bss_load_ie *) ie;
2963 printf("<sta count %d, chan load %d, aac %d>",
2964 LE_READ_2(&bssload->sta_count),
2971 printapchanrep(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2975 const struct ieee80211_ap_chan_report_ie *ap =
2976 (const struct ieee80211_ap_chan_report_ie *) ie;
2977 const char *sep = "";
2980 printf("<class %u, chan:[", ap->i_class);
2982 for (i = 3; i < ielen; i++) {
2983 printf("%s%u", sep, ie[i]);
2991 wpa_cipher(const u_int8_t *sel)
2993 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2994 u_int32_t w = LE_READ_4(sel);
2997 case WPA_SEL(WPA_CSE_NULL):
2999 case WPA_SEL(WPA_CSE_WEP40):
3001 case WPA_SEL(WPA_CSE_WEP104):
3003 case WPA_SEL(WPA_CSE_TKIP):
3005 case WPA_SEL(WPA_CSE_CCMP):
3008 return "?"; /* NB: so 1<< is discarded */
3013 wpa_keymgmt(const u_int8_t *sel)
3015 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
3016 u_int32_t w = LE_READ_4(sel);
3019 case WPA_SEL(WPA_ASE_8021X_UNSPEC):
3020 return "8021X-UNSPEC";
3021 case WPA_SEL(WPA_ASE_8021X_PSK):
3023 case WPA_SEL(WPA_ASE_NONE):
3031 printwpaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3033 u_int8_t len = ie[1];
3040 ie += 6, len -= 4; /* NB: len is payload only */
3042 printf("<v%u", LE_READ_2(ie));
3045 printf(" mc:%s", wpa_cipher(ie));
3048 /* unicast ciphers */
3052 for (; n > 0; n--) {
3053 printf("%s%s", sep, wpa_cipher(ie));
3058 /* key management algorithms */
3062 for (; n > 0; n--) {
3063 printf("%s%s", sep, wpa_keymgmt(ie));
3068 if (len > 2) /* optional capabilities */
3069 printf(", caps 0x%x", LE_READ_2(ie));
3075 rsn_cipher(const u_int8_t *sel)
3077 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
3078 u_int32_t w = LE_READ_4(sel);
3081 case RSN_SEL(RSN_CSE_NULL):
3083 case RSN_SEL(RSN_CSE_WEP40):
3085 case RSN_SEL(RSN_CSE_WEP104):
3087 case RSN_SEL(RSN_CSE_TKIP):
3089 case RSN_SEL(RSN_CSE_CCMP):
3091 case RSN_SEL(RSN_CSE_WRAP):
3099 rsn_keymgmt(const u_int8_t *sel)
3101 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
3102 u_int32_t w = LE_READ_4(sel);
3105 case RSN_SEL(RSN_ASE_8021X_UNSPEC):
3106 return "8021X-UNSPEC";
3107 case RSN_SEL(RSN_ASE_8021X_PSK):
3109 case RSN_SEL(RSN_ASE_NONE):
3117 printrsnie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3124 ie += 2, ielen -= 2;
3126 printf("<v%u", LE_READ_2(ie));
3127 ie += 2, ielen -= 2;
3129 printf(" mc:%s", rsn_cipher(ie));
3130 ie += 4, ielen -= 4;
3132 /* unicast ciphers */
3134 ie += 2, ielen -= 2;
3136 for (; n > 0; n--) {
3137 printf("%s%s", sep, rsn_cipher(ie));
3138 ie += 4, ielen -= 4;
3142 /* key management algorithms */
3144 ie += 2, ielen -= 2;
3146 for (; n > 0; n--) {
3147 printf("%s%s", sep, rsn_keymgmt(ie));
3148 ie += 4, ielen -= 4;
3152 if (ielen > 2) /* optional capabilities */
3153 printf(", caps 0x%x", LE_READ_2(ie));
3159 #define BE_READ_2(p) \
3161 ((((const u_int8_t *)(p))[1] ) | \
3162 (((const u_int8_t *)(p))[0] << 8)))
3165 printwpsie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3167 u_int8_t len = ie[1];
3171 static const char *dev_pass_id[] = {
3172 "D", /* Default (PIN) */
3173 "U", /* User-specified */
3174 "M", /* Machine-specified */
3176 "P", /* PushButton */
3177 "R" /* Registrar-specified */
3182 ie +=6, len -= 4; /* NB: len is payload only */
3184 /* WPS IE in Beacon and Probe Resp frames have different fields */
3187 uint16_t tlv_type = BE_READ_2(ie);
3188 uint16_t tlv_len = BE_READ_2(ie + 2);
3191 /* some devices broadcast invalid WPS frames */
3192 if (tlv_len > len) {
3193 printf("bad frame length tlv_type=0x%02x "
3194 "tlv_len=%d len=%d", tlv_type, tlv_len,
3202 case IEEE80211_WPS_ATTR_VERSION:
3203 printf("v:%d.%d", *ie >> 4, *ie & 0xf);
3205 case IEEE80211_WPS_ATTR_AP_SETUP_LOCKED:
3206 printf(" ap_setup:%s", *ie ? "locked" :
3209 case IEEE80211_WPS_ATTR_CONFIG_METHODS:
3210 case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS:
3211 if (tlv_type == IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS)
3212 printf(" sel_reg_cfg_mthd:");
3214 printf(" cfg_mthd:" );
3215 cfg_mthd = BE_READ_2(ie);
3217 for (n = 15; n >= 0; n--) {
3222 switch (cfg_mthd & (1 << n)) {
3225 case IEEE80211_WPS_CONFIG_USBA:
3229 case IEEE80211_WPS_CONFIG_ETHERNET:
3233 case IEEE80211_WPS_CONFIG_LABEL:
3237 case IEEE80211_WPS_CONFIG_DISPLAY:
3239 (IEEE80211_WPS_CONFIG_VIRT_DISPLAY |
3240 IEEE80211_WPS_CONFIG_PHY_DISPLAY)))
3246 case IEEE80211_WPS_CONFIG_EXT_NFC_TOKEN:
3247 printf("ext_nfc_tokenk");
3250 case IEEE80211_WPS_CONFIG_INT_NFC_TOKEN:
3251 printf("int_nfc_token");
3254 case IEEE80211_WPS_CONFIG_NFC_INTERFACE:
3255 printf("nfc_interface");
3258 case IEEE80211_WPS_CONFIG_PUSHBUTTON:
3260 (IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON |
3261 IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON))) {
3262 printf("push_button");
3266 case IEEE80211_WPS_CONFIG_KEYPAD:
3270 case IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON:
3271 printf("virtual_push_button");
3274 case IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON:
3275 printf("physical_push_button");
3278 case IEEE80211_WPS_CONFIG_P2PS:
3282 case IEEE80211_WPS_CONFIG_VIRT_DISPLAY:
3283 printf("virtual_display");
3286 case IEEE80211_WPS_CONFIG_PHY_DISPLAY:
3287 printf("physical_display");
3291 printf("unknown_wps_config<%04x>",
3292 cfg_mthd & (1 << n));
3298 case IEEE80211_WPS_ATTR_DEV_NAME:
3299 printf(" device_name:<%.*s>", tlv_len, ie);
3301 case IEEE80211_WPS_ATTR_DEV_PASSWORD_ID:
3303 if (n < nitems(dev_pass_id))
3304 printf(" dpi:%s", dev_pass_id[n]);
3306 case IEEE80211_WPS_ATTR_MANUFACTURER:
3307 printf(" manufacturer:<%.*s>", tlv_len, ie);
3309 case IEEE80211_WPS_ATTR_MODEL_NAME:
3310 printf(" model_name:<%.*s>", tlv_len, ie);
3312 case IEEE80211_WPS_ATTR_MODEL_NUMBER:
3313 printf(" model_number:<%.*s>", tlv_len, ie);
3315 case IEEE80211_WPS_ATTR_PRIMARY_DEV_TYPE:
3316 printf(" prim_dev:");
3317 for (n = 0; n < tlv_len; n++)
3318 printf("%02x", ie[n]);
3320 case IEEE80211_WPS_ATTR_RF_BANDS:
3323 for (n = 7; n >= 0; n--) {
3328 switch (*ie & (1 << n)) {
3331 case IEEE80211_WPS_RF_BAND_24GHZ:
3335 case IEEE80211_WPS_RF_BAND_50GHZ:
3339 case IEEE80211_WPS_RF_BAND_600GHZ:
3344 printf("unknown<%02x>",
3351 case IEEE80211_WPS_ATTR_RESPONSE_TYPE:
3352 printf(" resp_type:0x%02x", *ie);
3354 case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR:
3355 printf(" sel:%s", *ie ? "T" : "F");
3357 case IEEE80211_WPS_ATTR_SERIAL_NUMBER:
3358 printf(" serial_number:<%.*s>", tlv_len, ie);
3360 case IEEE80211_WPS_ATTR_UUID_E:
3362 for (n = 0; n < (tlv_len - 1); n++)
3363 printf("%02x-", ie[n]);
3364 printf("%02x", ie[n]);
3366 case IEEE80211_WPS_ATTR_VENDOR_EXT:
3368 for (n = 0; n < tlv_len; n++)
3369 printf("%02x", ie[n]);
3371 case IEEE80211_WPS_ATTR_WPS_STATE:
3373 case IEEE80211_WPS_STATE_NOT_CONFIGURED:
3376 case IEEE80211_WPS_STATE_CONFIGURED:
3380 printf(" state:B<%02x>", *ie);
3385 printf(" unknown_wps_attr:0x%x", tlv_type);
3388 ie += tlv_len, len -= tlv_len;
3395 printtdmaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3398 if (verbose && ielen >= sizeof(struct ieee80211_tdma_param)) {
3399 const struct ieee80211_tdma_param *tdma =
3400 (const struct ieee80211_tdma_param *) ie;
3403 printf("<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>",
3404 tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt,
3405 LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval,
3406 tdma->tdma_inuse[0]);
3411 * Copy the ssid string contents into buf, truncating to fit. If the
3412 * ssid is entirely printable then just copy intact. Otherwise convert
3413 * to hexadecimal. If the result is truncated then replace the last
3414 * three characters with "...".
3417 copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len)
3423 if (essid_len > bufsize)
3427 /* determine printable or not */
3428 for (i = 0, p = essid; i < maxlen; i++, p++) {
3429 if (*p < ' ' || *p > 0x7e)
3432 if (i != maxlen) { /* not printable, print as hex */
3435 strlcpy(buf, "0x", bufsize);
3438 for (i = 0; i < maxlen && bufsize >= 2; i++) {
3439 sprintf(&buf[2+2*i], "%02x", p[i]);
3443 memcpy(&buf[2+2*i-3], "...", 3);
3444 } else { /* printable, truncate as needed */
3445 memcpy(buf, essid, maxlen);
3446 if (maxlen != essid_len)
3447 memcpy(&buf[maxlen-3], "...", 3);
3453 printssid(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3455 char ssid[2*IEEE80211_NWID_LEN+1];
3457 printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid);
3461 printrates(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3468 for (i = 2; i < ielen; i++) {
3469 printf("%s%s%d", sep,
3470 ie[i] & IEEE80211_RATE_BASIC ? "B" : "",
3471 ie[i] & IEEE80211_RATE_VAL);
3478 printcountry(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3480 const struct ieee80211_country_ie *cie =
3481 (const struct ieee80211_country_ie *) ie;
3482 int i, nbands, schan, nchan;
3484 printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]);
3485 nbands = (cie->len - 3) / sizeof(cie->band[0]);
3486 for (i = 0; i < nbands; i++) {
3487 schan = cie->band[i].schan;
3488 nchan = cie->band[i].nchan;
3490 printf(" %u-%u,%u", schan, schan + nchan-1,
3491 cie->band[i].maxtxpwr);
3493 printf(" %u,%u", schan, cie->band[i].maxtxpwr);
3499 iswpaoui(const u_int8_t *frm)
3501 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI);
3505 iswmeinfo(const u_int8_t *frm)
3507 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3508 frm[6] == WME_INFO_OUI_SUBTYPE;
3512 iswmeparam(const u_int8_t *frm)
3514 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3515 frm[6] == WME_PARAM_OUI_SUBTYPE;
3519 isatherosoui(const u_int8_t *frm)
3521 return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI);
3525 istdmaoui(const uint8_t *frm)
3527 return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI);
3531 iswpsoui(const uint8_t *frm)
3533 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPS_OUI_TYPE<<24)|WPA_OUI);
3539 static char iename_buf[64];
3541 case IEEE80211_ELEMID_FHPARMS: return " FHPARMS";
3542 case IEEE80211_ELEMID_CFPARMS: return " CFPARMS";
3543 case IEEE80211_ELEMID_TIM: return " TIM";
3544 case IEEE80211_ELEMID_IBSSPARMS:return " IBSSPARMS";
3545 case IEEE80211_ELEMID_BSSLOAD: return " BSSLOAD";
3546 case IEEE80211_ELEMID_CHALLENGE:return " CHALLENGE";
3547 case IEEE80211_ELEMID_PWRCNSTR: return " PWRCNSTR";
3548 case IEEE80211_ELEMID_PWRCAP: return " PWRCAP";
3549 case IEEE80211_ELEMID_TPCREQ: return " TPCREQ";
3550 case IEEE80211_ELEMID_TPCREP: return " TPCREP";
3551 case IEEE80211_ELEMID_SUPPCHAN: return " SUPPCHAN";
3552 case IEEE80211_ELEMID_CSA: return " CSA";
3553 case IEEE80211_ELEMID_MEASREQ: return " MEASREQ";
3554 case IEEE80211_ELEMID_MEASREP: return " MEASREP";
3555 case IEEE80211_ELEMID_QUIET: return " QUIET";
3556 case IEEE80211_ELEMID_IBSSDFS: return " IBSSDFS";
3557 case IEEE80211_ELEMID_RESERVED_47:
3558 return " RESERVED_47";
3559 case IEEE80211_ELEMID_MOBILITY_DOMAIN:
3560 return " MOBILITY_DOMAIN";
3561 case IEEE80211_ELEMID_RRM_ENACAPS:
3562 return " RRM_ENCAPS";
3563 case IEEE80211_ELEMID_OVERLAP_BSS_SCAN_PARAM:
3564 return " OVERLAP_BSS";
3565 case IEEE80211_ELEMID_TPC: return " TPC";
3566 case IEEE80211_ELEMID_CCKM: return " CCKM";
3567 case IEEE80211_ELEMID_EXTCAP: return " EXTCAP";
3569 snprintf(iename_buf, sizeof(iename_buf), " UNKNOWN_ELEMID_%d",
3571 return (const char *) iename_buf;
3575 printies(const u_int8_t *vp, int ielen, int maxcols)
3579 case IEEE80211_ELEMID_SSID:
3581 printssid(" SSID", vp, 2+vp[1], maxcols);
3583 case IEEE80211_ELEMID_RATES:
3584 case IEEE80211_ELEMID_XRATES:
3586 printrates(vp[0] == IEEE80211_ELEMID_RATES ?
3587 " RATES" : " XRATES", vp, 2+vp[1], maxcols);
3589 case IEEE80211_ELEMID_DSPARMS:
3591 printf(" DSPARMS<%u>", vp[2]);
3593 case IEEE80211_ELEMID_COUNTRY:
3595 printcountry(" COUNTRY", vp, 2+vp[1], maxcols);
3597 case IEEE80211_ELEMID_ERP:
3599 printf(" ERP<0x%x>", vp[2]);
3601 case IEEE80211_ELEMID_VENDOR:
3603 printwpaie(" WPA", vp, 2+vp[1], maxcols);
3604 else if (iswmeinfo(vp))
3605 printwmeinfo(" WME", vp, 2+vp[1], maxcols);
3606 else if (iswmeparam(vp))
3607 printwmeparam(" WME", vp, 2+vp[1], maxcols);
3608 else if (isatherosoui(vp))
3609 printathie(" ATH", vp, 2+vp[1], maxcols);
3610 else if (iswpsoui(vp))
3611 printwpsie(" WPS", vp, 2+vp[1], maxcols);
3612 else if (istdmaoui(vp))
3613 printtdmaie(" TDMA", vp, 2+vp[1], maxcols);
3615 printie(" VEN", vp, 2+vp[1], maxcols);
3617 case IEEE80211_ELEMID_RSN:
3618 printrsnie(" RSN", vp, 2+vp[1], maxcols);
3620 case IEEE80211_ELEMID_HTCAP:
3621 printhtcap(" HTCAP", vp, 2+vp[1], maxcols);
3623 case IEEE80211_ELEMID_HTINFO:
3625 printhtinfo(" HTINFO", vp, 2+vp[1], maxcols);
3627 case IEEE80211_ELEMID_MESHID:
3629 printssid(" MESHID", vp, 2+vp[1], maxcols);
3631 case IEEE80211_ELEMID_MESHCONF:
3632 printmeshconf(" MESHCONF", vp, 2+vp[1], maxcols);
3634 case IEEE80211_ELEMID_VHT_CAP:
3635 printvhtcap(" VHTCAP", vp, 2+vp[1], maxcols);
3637 case IEEE80211_ELEMID_VHT_OPMODE:
3638 printvhtinfo(" VHTOPMODE", vp, 2+vp[1], maxcols);
3640 case IEEE80211_ELEMID_VHT_PWR_ENV:
3641 printvhtpwrenv(" VHTPWRENV", vp, 2+vp[1], maxcols);
3643 case IEEE80211_ELEMID_BSSLOAD:
3644 printbssload(" BSSLOAD", vp, 2+vp[1], maxcols);
3646 case IEEE80211_ELEMID_APCHANREP:
3647 printapchanrep(" APCHANREP", vp, 2+vp[1], maxcols);
3651 printie(iename(vp[0]), vp, 2+vp[1], maxcols);
3660 printmimo(const struct ieee80211_mimo_info *mi)
3665 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3666 if (mi->ch[i].rssi != 0) {
3672 /* NB: don't muddy display unless there's something to show */
3676 /* XXX TODO: ignore EVM; secondary channels for now */
3677 printf(" (rssi %.1f:%.1f:%.1f:%.1f nf %d:%d:%d:%d)",
3678 mi->ch[0].rssi[0] / 2.0,
3679 mi->ch[1].rssi[0] / 2.0,
3680 mi->ch[2].rssi[0] / 2.0,
3681 mi->ch[3].rssi[0] / 2.0,
3685 mi->ch[3].noise[0]);
3691 uint8_t buf[24*1024];
3692 char ssid[IEEE80211_NWID_LEN+1];
3696 if (get80211len(s, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0)
3697 errx(1, "unable to get scan results");
3698 if (len < sizeof(struct ieee80211req_scan_result))
3703 printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n"
3704 , IEEE80211_NWID_LEN, IEEE80211_NWID_LEN, "SSID/MESH ID"
3714 const struct ieee80211req_scan_result *sr;
3715 const uint8_t *vp, *idp;
3717 sr = (const struct ieee80211req_scan_result *) cp;
3718 vp = cp + sr->isr_ie_off;
3719 if (sr->isr_meshid_len) {
3720 idp = vp + sr->isr_ssid_len;
3721 idlen = sr->isr_meshid_len;
3724 idlen = sr->isr_ssid_len;
3726 printf("%-*.*s %s %3d %3dM %4d:%-4d %4d %-4.4s"
3727 , IEEE80211_NWID_LEN
3728 , copy_essid(ssid, IEEE80211_NWID_LEN, idp, idlen)
3730 , ether_ntoa((const struct ether_addr *) sr->isr_bssid)
3731 , ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags)
3732 , getmaxrate(sr->isr_rates, sr->isr_nrates)
3733 , (sr->isr_rssi/2)+sr->isr_noise, sr->isr_noise
3735 , getcaps(sr->isr_capinfo)
3737 printies(vp + sr->isr_ssid_len + sr->isr_meshid_len,
3738 sr->isr_ie_len, 24);
3740 cp += sr->isr_len, len -= sr->isr_len;
3741 } while (len >= sizeof(struct ieee80211req_scan_result));
3745 scan_and_wait(int s)
3747 struct ieee80211_scan_req sr;
3748 struct ieee80211req ireq;
3751 sroute = socket(PF_ROUTE, SOCK_RAW, 0);
3753 perror("socket(PF_ROUTE,SOCK_RAW)");
3756 (void) memset(&ireq, 0, sizeof(ireq));
3757 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
3758 ireq.i_type = IEEE80211_IOC_SCAN_REQ;
3760 memset(&sr, 0, sizeof(sr));
3761 sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE
3762 | IEEE80211_IOC_SCAN_BGSCAN
3763 | IEEE80211_IOC_SCAN_NOPICK
3764 | IEEE80211_IOC_SCAN_ONCE;
3765 sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER;
3769 ireq.i_len = sizeof(sr);
3771 * NB: only root can trigger a scan so ignore errors. Also ignore
3772 * possible errors from net80211, even if no new scan could be
3773 * started there might still be a valid scan cache.
3775 if (ioctl(s, SIOCS80211, &ireq) == 0) {
3777 struct if_announcemsghdr *ifan;
3778 struct rt_msghdr *rtm;
3781 if (read(sroute, buf, sizeof(buf)) < 0) {
3782 perror("read(PF_ROUTE)");
3785 rtm = (struct rt_msghdr *) buf;
3786 if (rtm->rtm_version != RTM_VERSION)
3788 ifan = (struct if_announcemsghdr *) rtm;
3789 } while (rtm->rtm_type != RTM_IEEE80211 ||
3790 ifan->ifan_what != RTM_IEEE80211_SCAN);
3796 DECL_CMD_FUNC(set80211scan, val, d)
3802 static enum ieee80211_opmode get80211opmode(int s);
3805 gettxseq(const struct ieee80211req_sta_info *si)
3809 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3810 return si->isi_txseqs[0];
3811 /* XXX not right but usually what folks want */
3813 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3814 if (si->isi_txseqs[i] > txseq)
3815 txseq = si->isi_txseqs[i];
3820 getrxseq(const struct ieee80211req_sta_info *si)
3824 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3825 return si->isi_rxseqs[0];
3826 /* XXX not right but usually what folks want */
3828 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3829 if (si->isi_rxseqs[i] > rxseq)
3830 rxseq = si->isi_rxseqs[i];
3835 list_stations(int s)
3838 struct ieee80211req_sta_req req;
3839 uint8_t buf[24*1024];
3841 enum ieee80211_opmode opmode = get80211opmode(s);
3845 /* broadcast address =>'s get all stations */
3846 (void) memset(u.req.is_u.macaddr, 0xff, IEEE80211_ADDR_LEN);
3847 if (opmode == IEEE80211_M_STA) {
3849 * Get information about the associated AP.
3851 (void) get80211(s, IEEE80211_IOC_BSSID,
3852 u.req.is_u.macaddr, IEEE80211_ADDR_LEN);
3854 if (get80211len(s, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0)
3855 errx(1, "unable to get station information");
3856 if (len < sizeof(struct ieee80211req_sta_info))
3861 if (opmode == IEEE80211_M_MBSS)
3862 printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n"
3875 printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-12s\n"
3887 cp = (const uint8_t *) u.req.info;
3889 const struct ieee80211req_sta_info *si;
3891 si = (const struct ieee80211req_sta_info *) cp;
3892 if (si->isi_len < sizeof(*si))
3894 if (opmode == IEEE80211_M_MBSS)
3895 printf("%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d"
3896 , ether_ntoa((const struct ether_addr*)
3898 , ieee80211_mhz2ieee(si->isi_freq,
3902 , mesh_linkstate_string(si->isi_peerstate)
3910 printf("%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-12.12s"
3911 , ether_ntoa((const struct ether_addr*)
3913 , IEEE80211_AID(si->isi_associd)
3914 , ieee80211_mhz2ieee(si->isi_freq,
3921 , getcaps(si->isi_capinfo)
3922 , getflags(si->isi_state)
3924 printies(cp + si->isi_ie_off, si->isi_ie_len, 24);
3925 printmimo(&si->isi_mimo);
3927 cp += si->isi_len, len -= si->isi_len;
3928 } while (len >= sizeof(struct ieee80211req_sta_info));
3932 mesh_linkstate_string(uint8_t state)
3934 static const char *state_names[] = {
3943 if (state >= nitems(state_names)) {
3944 static char buf[10];
3945 snprintf(buf, sizeof(buf), "#%u", state);
3948 return state_names[state];
3952 get_chaninfo(const struct ieee80211_channel *c, int precise,
3953 char buf[], size_t bsize)
3956 if (IEEE80211_IS_CHAN_FHSS(c))
3957 strlcat(buf, " FHSS", bsize);
3958 if (IEEE80211_IS_CHAN_A(c))
3959 strlcat(buf, " 11a", bsize);
3960 else if (IEEE80211_IS_CHAN_ANYG(c))
3961 strlcat(buf, " 11g", bsize);
3962 else if (IEEE80211_IS_CHAN_B(c))
3963 strlcat(buf, " 11b", bsize);
3964 if (IEEE80211_IS_CHAN_HALF(c))
3965 strlcat(buf, "/10MHz", bsize);
3966 if (IEEE80211_IS_CHAN_QUARTER(c))
3967 strlcat(buf, "/5MHz", bsize);
3968 if (IEEE80211_IS_CHAN_TURBO(c))
3969 strlcat(buf, " Turbo", bsize);
3971 if (IEEE80211_IS_CHAN_VHT80P80(c))
3972 strlcat(buf, " vht/80p80", bsize);
3973 else if (IEEE80211_IS_CHAN_VHT160(c))
3974 strlcat(buf, " vht/160", bsize);
3975 else if (IEEE80211_IS_CHAN_VHT80(c) &&
3976 IEEE80211_IS_CHAN_HT40D(c))
3977 strlcat(buf, " vht/80-", bsize);
3978 else if (IEEE80211_IS_CHAN_VHT80(c) &&
3979 IEEE80211_IS_CHAN_HT40U(c))
3980 strlcat(buf, " vht/80+", bsize);
3981 else if (IEEE80211_IS_CHAN_VHT80(c))
3982 strlcat(buf, " vht/80", bsize);
3983 else if (IEEE80211_IS_CHAN_VHT40D(c))
3984 strlcat(buf, " vht/40-", bsize);
3985 else if (IEEE80211_IS_CHAN_VHT40U(c))
3986 strlcat(buf, " vht/40+", bsize);
3987 else if (IEEE80211_IS_CHAN_VHT20(c))
3988 strlcat(buf, " vht/20", bsize);
3989 else if (IEEE80211_IS_CHAN_HT20(c))
3990 strlcat(buf, " ht/20", bsize);
3991 else if (IEEE80211_IS_CHAN_HT40D(c))
3992 strlcat(buf, " ht/40-", bsize);
3993 else if (IEEE80211_IS_CHAN_HT40U(c))
3994 strlcat(buf, " ht/40+", bsize);
3996 if (IEEE80211_IS_CHAN_VHT(c))
3997 strlcat(buf, " vht", bsize);
3998 else if (IEEE80211_IS_CHAN_HT(c))
3999 strlcat(buf, " ht", bsize);
4005 print_chaninfo(const struct ieee80211_channel *c, int verb)
4010 printf("Channel %3u : %u%c%c%c%c%c MHz%-14.14s",
4011 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
4012 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
4013 IEEE80211_IS_CHAN_DFS(c) ? 'D' : ' ',
4014 IEEE80211_IS_CHAN_RADAR(c) ? 'R' : ' ',
4015 IEEE80211_IS_CHAN_CWINT(c) ? 'I' : ' ',
4016 IEEE80211_IS_CHAN_CACDONE(c) ? 'C' : ' ',
4017 get_chaninfo(c, verb, buf, sizeof(buf)));
4019 printf("Channel %3u : %u%c MHz%-14.14s",
4020 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
4021 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
4022 get_chaninfo(c, verb, buf, sizeof(buf)));
4027 chanpref(const struct ieee80211_channel *c)
4030 if (IEEE80211_IS_CHAN_VHT80P80(c))
4032 if (IEEE80211_IS_CHAN_VHT160(c))
4034 if (IEEE80211_IS_CHAN_VHT80(c))
4036 if (IEEE80211_IS_CHAN_VHT40(c))
4038 if (IEEE80211_IS_CHAN_VHT20(c))
4040 if (IEEE80211_IS_CHAN_HT40(c))
4042 if (IEEE80211_IS_CHAN_HT20(c))
4044 if (IEEE80211_IS_CHAN_HALF(c))
4046 if (IEEE80211_IS_CHAN_QUARTER(c))
4048 if (IEEE80211_IS_CHAN_TURBO(c))
4050 if (IEEE80211_IS_CHAN_A(c))
4052 if (IEEE80211_IS_CHAN_G(c))
4054 if (IEEE80211_IS_CHAN_B(c))
4056 if (IEEE80211_IS_CHAN_PUREG(c))
4062 print_channels(int s, const struct ieee80211req_chaninfo *chans,
4063 int allchans, int verb)
4065 struct ieee80211req_chaninfo *achans;
4066 uint8_t reported[IEEE80211_CHAN_BYTES];
4067 const struct ieee80211_channel *c;
4070 achans = malloc(IEEE80211_CHANINFO_SPACE(chans));
4072 errx(1, "no space for active channel list");
4073 achans->ic_nchans = 0;
4074 memset(reported, 0, sizeof(reported));
4076 struct ieee80211req_chanlist active;
4078 if (get80211(s, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0)
4079 errx(1, "unable to get active channel list");
4080 for (i = 0; i < chans->ic_nchans; i++) {
4081 c = &chans->ic_chans[i];
4082 if (!isset(active.ic_channels, c->ic_ieee))
4085 * Suppress compatible duplicates unless
4086 * verbose. The kernel gives us it's
4087 * complete channel list which has separate
4088 * entries for 11g/11b and 11a/turbo.
4090 if (isset(reported, c->ic_ieee) && !verb) {
4091 /* XXX we assume duplicates are adjacent */
4092 achans->ic_chans[achans->ic_nchans-1] = *c;
4094 achans->ic_chans[achans->ic_nchans++] = *c;
4095 setbit(reported, c->ic_ieee);
4099 for (i = 0; i < chans->ic_nchans; i++) {
4100 c = &chans->ic_chans[i];
4101 /* suppress duplicates as above */
4102 if (isset(reported, c->ic_ieee) && !verb) {
4103 /* XXX we assume duplicates are adjacent */
4104 struct ieee80211_channel *a =
4105 &achans->ic_chans[achans->ic_nchans-1];
4106 if (chanpref(c) > chanpref(a))
4109 achans->ic_chans[achans->ic_nchans++] = *c;
4110 setbit(reported, c->ic_ieee);
4114 half = achans->ic_nchans / 2;
4115 if (achans->ic_nchans % 2)
4118 for (i = 0; i < achans->ic_nchans / 2; i++) {
4119 print_chaninfo(&achans->ic_chans[i], verb);
4120 print_chaninfo(&achans->ic_chans[half+i], verb);
4123 if (achans->ic_nchans % 2) {
4124 print_chaninfo(&achans->ic_chans[i], verb);
4131 list_channels(int s, int allchans)
4134 print_channels(s, chaninfo, allchans, verbose);
4138 print_txpow(const struct ieee80211_channel *c)
4140 printf("Channel %3u : %u MHz %3.1f reg %2d ",
4141 c->ic_ieee, c->ic_freq,
4142 c->ic_maxpower/2., c->ic_maxregpower);
4146 print_txpow_verbose(const struct ieee80211_channel *c)
4148 print_chaninfo(c, 1);
4149 printf("min %4.1f dBm max %3.1f dBm reg %2d dBm",
4150 c->ic_minpower/2., c->ic_maxpower/2., c->ic_maxregpower);
4151 /* indicate where regulatory cap limits power use */
4152 if (c->ic_maxpower > 2*c->ic_maxregpower)
4159 struct ieee80211req_chaninfo *achans;
4160 uint8_t reported[IEEE80211_CHAN_BYTES];
4161 struct ieee80211_channel *c, *prev;
4165 achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo));
4167 errx(1, "no space for active channel list");
4168 achans->ic_nchans = 0;
4169 memset(reported, 0, sizeof(reported));
4170 for (i = 0; i < chaninfo->ic_nchans; i++) {
4171 c = &chaninfo->ic_chans[i];
4172 /* suppress duplicates as above */
4173 if (isset(reported, c->ic_ieee) && !verbose) {
4174 /* XXX we assume duplicates are adjacent */
4175 assert(achans->ic_nchans > 0);
4176 prev = &achans->ic_chans[achans->ic_nchans-1];
4177 /* display highest power on channel */
4178 if (c->ic_maxpower > prev->ic_maxpower)
4181 achans->ic_chans[achans->ic_nchans++] = *c;
4182 setbit(reported, c->ic_ieee);
4186 half = achans->ic_nchans / 2;
4187 if (achans->ic_nchans % 2)
4190 for (i = 0; i < achans->ic_nchans / 2; i++) {
4191 print_txpow(&achans->ic_chans[i]);
4192 print_txpow(&achans->ic_chans[half+i]);
4195 if (achans->ic_nchans % 2) {
4196 print_txpow(&achans->ic_chans[i]);
4200 for (i = 0; i < achans->ic_nchans; i++) {
4201 print_txpow_verbose(&achans->ic_chans[i]);
4214 list_capabilities(int s)
4216 struct ieee80211_devcaps_req *dc;
4219 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
4221 dc = malloc(IEEE80211_DEVCAPS_SIZE(1));
4223 errx(1, "no space for device capabilities");
4224 dc->dc_chaninfo.ic_nchans = verbose ? MAXCHAN : 1;
4226 printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS);
4227 if (dc->dc_cryptocaps != 0 || verbose) {
4229 printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS);
4231 if (dc->dc_htcaps != 0 || verbose) {
4233 printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS);
4235 if (dc->dc_vhtcaps != 0 || verbose) {
4237 printb("vhtcaps", dc->dc_vhtcaps, IEEE80211_VHTCAP_BITS);
4242 chaninfo = &dc->dc_chaninfo; /* XXX */
4243 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, verbose);
4249 get80211wme(int s, int param, int ac, int *val)
4251 struct ieee80211req ireq;
4253 (void) memset(&ireq, 0, sizeof(ireq));
4254 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4255 ireq.i_type = param;
4257 if (ioctl(s, SIOCG80211, &ireq) < 0) {
4258 warn("cannot get WME parameter %d, ac %d%s",
4259 param, ac & IEEE80211_WMEPARAM_VAL,
4260 ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : "");
4268 list_wme_aci(int s, const char *tag, int ac)
4272 printf("\t%s", tag);
4274 /* show WME BSS parameters */
4275 if (get80211wme(s, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1)
4276 printf(" cwmin %2u", val);
4277 if (get80211wme(s, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1)
4278 printf(" cwmax %2u", val);
4279 if (get80211wme(s, IEEE80211_IOC_WME_AIFS, ac, &val) != -1)
4280 printf(" aifs %2u", val);
4281 if (get80211wme(s, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1)
4282 printf(" txopLimit %3u", val);
4283 if (get80211wme(s, IEEE80211_IOC_WME_ACM, ac, &val) != -1) {
4290 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
4291 if (get80211wme(s, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) {
4304 static const char *acnames[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
4308 /* display both BSS and local settings */
4309 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) {
4311 if (ac & IEEE80211_WMEPARAM_BSS)
4312 list_wme_aci(s, " ", ac);
4314 list_wme_aci(s, acnames[ac], ac);
4315 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
4316 ac |= IEEE80211_WMEPARAM_BSS;
4319 ac &= ~IEEE80211_WMEPARAM_BSS;
4322 /* display only channel settings */
4323 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++)
4324 list_wme_aci(s, acnames[ac], ac);
4331 const struct ieee80211_roamparam *rp;
4335 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
4336 rp = &roamparams.params[mode];
4337 if (rp->rssi == 0 && rp->rate == 0)
4339 if (mode == IEEE80211_MODE_11NA ||
4340 mode == IEEE80211_MODE_11NG ||
4341 mode == IEEE80211_MODE_VHT_2GHZ ||
4342 mode == IEEE80211_MODE_VHT_5GHZ) {
4344 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm MCS %2u ",
4345 modename[mode], rp->rssi/2,
4346 rp->rate &~ IEEE80211_RATE_MCS);
4348 LINE_CHECK("roam:%-7.7s rssi %4udBm MCS %2u ",
4349 modename[mode], rp->rssi/2,
4350 rp->rate &~ IEEE80211_RATE_MCS);
4353 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s",
4354 modename[mode], rp->rssi/2, rp->rate/2);
4356 LINE_CHECK("roam:%-7.7s rssi %4udBm rate %2u Mb/s",
4357 modename[mode], rp->rssi/2, rp->rate/2);
4362 /* XXX TODO: rate-to-string method... */
4364 get_mcs_mbs_rate_str(uint8_t rate)
4366 return (rate & IEEE80211_RATE_MCS) ? "MCS " : "Mb/s";
4370 get_rate_value(uint8_t rate)
4372 if (rate & IEEE80211_RATE_MCS)
4373 return (rate &~ IEEE80211_RATE_MCS);
4378 list_txparams(int s)
4380 const struct ieee80211_txparam *tp;
4384 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
4385 tp = &txparams.params[mode];
4386 if (tp->mgmtrate == 0 && tp->mcastrate == 0)
4388 if (mode == IEEE80211_MODE_11NA ||
4389 mode == IEEE80211_MODE_11NG ||
4390 mode == IEEE80211_MODE_VHT_2GHZ ||
4391 mode == IEEE80211_MODE_VHT_5GHZ) {
4392 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
4393 LINE_CHECK("%-7.7s ucast NONE mgmt %2u %s "
4394 "mcast %2u %s maxretry %u",
4396 get_rate_value(tp->mgmtrate),
4397 get_mcs_mbs_rate_str(tp->mgmtrate),
4398 get_rate_value(tp->mcastrate),
4399 get_mcs_mbs_rate_str(tp->mcastrate),
4402 LINE_CHECK("%-7.7s ucast %2u MCS mgmt %2u %s "
4403 "mcast %2u %s maxretry %u",
4405 tp->ucastrate &~ IEEE80211_RATE_MCS,
4406 get_rate_value(tp->mgmtrate),
4407 get_mcs_mbs_rate_str(tp->mgmtrate),
4408 get_rate_value(tp->mcastrate),
4409 get_mcs_mbs_rate_str(tp->mcastrate),
4412 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
4413 LINE_CHECK("%-7.7s ucast NONE mgmt %2u Mb/s "
4414 "mcast %2u Mb/s maxretry %u",
4417 tp->mcastrate/2, tp->maxretry);
4419 LINE_CHECK("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s "
4420 "mcast %2u Mb/s maxretry %u",
4422 tp->ucastrate/2, tp->mgmtrate/2,
4423 tp->mcastrate/2, tp->maxretry);
4429 printpolicy(int policy)
4432 case IEEE80211_MACCMD_POLICY_OPEN:
4433 printf("policy: open\n");
4435 case IEEE80211_MACCMD_POLICY_ALLOW:
4436 printf("policy: allow\n");
4438 case IEEE80211_MACCMD_POLICY_DENY:
4439 printf("policy: deny\n");
4441 case IEEE80211_MACCMD_POLICY_RADIUS:
4442 printf("policy: radius\n");
4445 printf("policy: unknown (%u)\n", policy);
4453 struct ieee80211req ireq;
4454 struct ieee80211req_maclist *acllist;
4455 int i, nacls, policy, len;
4459 (void) memset(&ireq, 0, sizeof(ireq));
4460 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name)); /* XXX ?? */
4461 ireq.i_type = IEEE80211_IOC_MACCMD;
4462 ireq.i_val = IEEE80211_MACCMD_POLICY;
4463 if (ioctl(s, SIOCG80211, &ireq) < 0) {
4464 if (errno == EINVAL) {
4465 printf("No acl policy loaded\n");
4468 err(1, "unable to get mac policy");
4470 policy = ireq.i_val;
4471 if (policy == IEEE80211_MACCMD_POLICY_OPEN) {
4473 } else if (policy == IEEE80211_MACCMD_POLICY_ALLOW) {
4475 } else if (policy == IEEE80211_MACCMD_POLICY_DENY) {
4477 } else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) {
4478 c = 'r'; /* NB: should never have entries */
4480 printf("policy: unknown (%u)\n", policy);
4483 if (verbose || c == '?')
4484 printpolicy(policy);
4486 ireq.i_val = IEEE80211_MACCMD_LIST;
4488 if (ioctl(s, SIOCG80211, &ireq) < 0)
4489 err(1, "unable to get mac acl list size");
4490 if (ireq.i_len == 0) { /* NB: no acls */
4491 if (!(verbose || c == '?'))
4492 printpolicy(policy);
4499 err(1, "out of memory for acl list");
4502 if (ioctl(s, SIOCG80211, &ireq) < 0)
4503 err(1, "unable to get mac acl list");
4504 nacls = len / sizeof(*acllist);
4505 acllist = (struct ieee80211req_maclist *) data;
4506 for (i = 0; i < nacls; i++)
4507 printf("%c%s\n", c, ether_ntoa(
4508 (const struct ether_addr *) acllist[i].ml_macaddr));
4513 print_regdomain(const struct ieee80211_regdomain *reg, int verb)
4515 if ((reg->regdomain != 0 &&
4516 reg->regdomain != reg->country) || verb) {
4517 const struct regdomain *rd =
4518 lib80211_regdomain_findbysku(getregdata(), reg->regdomain);
4520 LINE_CHECK("regdomain %d", reg->regdomain);
4522 LINE_CHECK("regdomain %s", rd->name);
4524 if (reg->country != 0 || verb) {
4525 const struct country *cc =
4526 lib80211_country_findbycc(getregdata(), reg->country);
4528 LINE_CHECK("country %d", reg->country);
4530 LINE_CHECK("country %s", cc->isoname);
4532 if (reg->location == 'I')
4533 LINE_CHECK("indoor");
4534 else if (reg->location == 'O')
4535 LINE_CHECK("outdoor");
4537 LINE_CHECK("anywhere");
4545 list_regdomain(int s, int channelsalso)
4551 print_regdomain(®domain, 1);
4553 print_channels(s, chaninfo, 1/*allchans*/, 1/*verbose*/);
4555 print_regdomain(®domain, verbose);
4561 struct ieee80211req ireq;
4562 struct ieee80211req_mesh_route routes[128];
4563 struct ieee80211req_mesh_route *rt;
4565 (void) memset(&ireq, 0, sizeof(ireq));
4566 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4567 ireq.i_type = IEEE80211_IOC_MESH_RTCMD;
4568 ireq.i_val = IEEE80211_MESH_RTCMD_LIST;
4569 ireq.i_data = &routes;
4570 ireq.i_len = sizeof(routes);
4571 if (ioctl(s, SIOCG80211, &ireq) < 0)
4572 err(1, "unable to get the Mesh routing table");
4574 printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n"
4583 for (rt = &routes[0]; rt - &routes[0] < ireq.i_len / sizeof(*rt); rt++){
4585 ether_ntoa((const struct ether_addr *)rt->imr_dest));
4586 printf("%s %4u %4u %6u %6u %c%c\n",
4587 ether_ntoa((const struct ether_addr *)rt->imr_nexthop),
4588 rt->imr_nhops, rt->imr_metric, rt->imr_lifetime,
4590 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_DISCOVER) ?
4592 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_VALID) ?
4594 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ?
4596 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_GATE) ?
4602 DECL_CMD_FUNC(set80211list, arg, d)
4604 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
4608 if (iseq(arg, "sta"))
4610 else if (iseq(arg, "scan") || iseq(arg, "ap"))
4612 else if (iseq(arg, "chan") || iseq(arg, "freq"))
4613 list_channels(s, 1);
4614 else if (iseq(arg, "active"))
4615 list_channels(s, 0);
4616 else if (iseq(arg, "keys"))
4618 else if (iseq(arg, "caps"))
4619 list_capabilities(s);
4620 else if (iseq(arg, "wme") || iseq(arg, "wmm"))
4622 else if (iseq(arg, "mac"))
4624 else if (iseq(arg, "txpow"))
4626 else if (iseq(arg, "roam"))
4628 else if (iseq(arg, "txparam") || iseq(arg, "txparm"))
4630 else if (iseq(arg, "regdomain"))
4631 list_regdomain(s, 1);
4632 else if (iseq(arg, "countries"))
4634 else if (iseq(arg, "mesh"))
4637 errx(1, "Don't know how to list %s for %s", arg, name);
4642 static enum ieee80211_opmode
4643 get80211opmode(int s)
4645 struct ifmediareq ifmr;
4647 (void) memset(&ifmr, 0, sizeof(ifmr));
4648 (void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
4650 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) {
4651 if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) {
4652 if (ifmr.ifm_current & IFM_FLAG0)
4653 return IEEE80211_M_AHDEMO;
4655 return IEEE80211_M_IBSS;
4657 if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP)
4658 return IEEE80211_M_HOSTAP;
4659 if (ifmr.ifm_current & IFM_IEEE80211_IBSS)
4660 return IEEE80211_M_IBSS;
4661 if (ifmr.ifm_current & IFM_IEEE80211_MONITOR)
4662 return IEEE80211_M_MONITOR;
4663 if (ifmr.ifm_current & IFM_IEEE80211_MBSS)
4664 return IEEE80211_M_MBSS;
4666 return IEEE80211_M_STA;
4671 printcipher(int s, struct ieee80211req *ireq, int keylenop)
4673 switch (ireq->i_val) {
4674 case IEEE80211_CIPHER_WEP:
4675 ireq->i_type = keylenop;
4676 if (ioctl(s, SIOCG80211, ireq) != -1)
4678 ireq->i_len <= 5 ? "40" :
4679 ireq->i_len <= 13 ? "104" : "128");
4683 case IEEE80211_CIPHER_TKIP:
4686 case IEEE80211_CIPHER_AES_OCB:
4689 case IEEE80211_CIPHER_AES_CCM:
4692 case IEEE80211_CIPHER_CKIP:
4695 case IEEE80211_CIPHER_NONE:
4699 printf("UNKNOWN (0x%x)", ireq->i_val);
4706 printkey(const struct ieee80211req_key *ik)
4708 static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
4709 u_int keylen = ik->ik_keylen;
4712 printcontents = printkeys &&
4713 (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose);
4716 switch (ik->ik_type) {
4717 case IEEE80211_CIPHER_WEP:
4719 LINE_CHECK("wepkey %u:%s", ik->ik_keyix+1,
4720 keylen <= 5 ? "40-bit" :
4721 keylen <= 13 ? "104-bit" : "128-bit");
4723 case IEEE80211_CIPHER_TKIP:
4725 keylen -= 128/8; /* ignore MIC for now */
4726 LINE_CHECK("TKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4728 case IEEE80211_CIPHER_AES_OCB:
4729 LINE_CHECK("AES-OCB %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4731 case IEEE80211_CIPHER_AES_CCM:
4732 LINE_CHECK("AES-CCM %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4734 case IEEE80211_CIPHER_CKIP:
4735 LINE_CHECK("CKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4737 case IEEE80211_CIPHER_NONE:
4738 LINE_CHECK("NULL %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4741 LINE_CHECK("UNKNOWN (0x%x) %u:%u-bit",
4742 ik->ik_type, ik->ik_keyix+1, 8*keylen);
4745 if (printcontents) {
4749 for (i = 0; i < keylen; i++)
4750 printf("%02x", ik->ik_keydata[i]);
4752 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4753 (ik->ik_keyrsc != 0 || verbose))
4754 printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc);
4755 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4756 (ik->ik_keytsc != 0 || verbose))
4757 printf(" tsc %ju", (uintmax_t)ik->ik_keytsc);
4758 if (ik->ik_flags != 0 && verbose) {
4759 const char *sep = " ";
4761 if (ik->ik_flags & IEEE80211_KEY_XMIT)
4762 printf("%stx", sep), sep = "+";
4763 if (ik->ik_flags & IEEE80211_KEY_RECV)
4764 printf("%srx", sep), sep = "+";
4765 if (ik->ik_flags & IEEE80211_KEY_DEFAULT)
4766 printf("%sdef", sep), sep = "+";
4773 printrate(const char *tag, int v, int defrate, int defmcs)
4775 if ((v & IEEE80211_RATE_MCS) == 0) {
4778 LINE_CHECK("%s %d.5", tag, v/2);
4780 LINE_CHECK("%s %d", tag, v/2);
4784 LINE_CHECK("%s %d", tag, v &~ 0x80);
4789 getid(int s, int ix, void *data, size_t len, int *plen, int mesh)
4791 struct ieee80211req ireq;
4793 (void) memset(&ireq, 0, sizeof(ireq));
4794 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4795 ireq.i_type = (!mesh) ? IEEE80211_IOC_SSID : IEEE80211_IOC_MESH_ID;
4799 if (ioctl(s, SIOCG80211, &ireq) < 0)
4806 getdevicename(int s, void *data, size_t len, int *plen)
4808 struct ieee80211req ireq;
4810 (void) memset(&ireq, 0, sizeof(ireq));
4811 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4812 ireq.i_type = IEEE80211_IOC_IC_NAME;
4816 if (ioctl(s, SIOCG80211, &ireq) < 0)
4823 ieee80211_status(int s)
4825 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
4826 enum ieee80211_opmode opmode = get80211opmode(s);
4827 int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode;
4829 const struct ieee80211_channel *c;
4830 const struct ieee80211_roamparam *rp;
4831 const struct ieee80211_txparam *tp;
4833 if (getid(s, -1, data, sizeof(data), &len, 0) < 0) {
4834 /* If we can't get the SSID, this isn't an 802.11 device. */
4839 * Invalidate cached state so printing status for multiple
4840 * if's doesn't reuse the first interfaces' cached state.
4849 if (opmode == IEEE80211_M_MBSS) {
4851 getid(s, 0, data, sizeof(data), &len, 1);
4852 print_string(data, len);
4854 if (get80211val(s, IEEE80211_IOC_NUMSSIDS, &num) < 0)
4858 for (i = 0; i < num; i++) {
4859 if (getid(s, i, data, sizeof(data), &len, 0) >= 0 && len > 0) {
4860 printf(" %d:", i + 1);
4861 print_string(data, len);
4865 print_string(data, len);
4868 if (c->ic_freq != IEEE80211_CHAN_ANY) {
4870 printf(" channel %d (%u MHz%s)", c->ic_ieee, c->ic_freq,
4871 get_chaninfo(c, 1, buf, sizeof(buf)));
4873 printf(" channel UNDEF");
4875 if (get80211(s, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 &&
4876 (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose))
4877 printf(" bssid %s", ether_ntoa((struct ether_addr *)data));
4879 if (get80211len(s, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) {
4880 printf("\n\tstationname ");
4881 print_string(data, len);
4884 spacer = ' '; /* force first break */
4887 list_regdomain(s, 0);
4890 if (get80211val(s, IEEE80211_IOC_AUTHMODE, &val) != -1) {
4892 case IEEE80211_AUTH_NONE:
4893 LINE_CHECK("authmode NONE");
4895 case IEEE80211_AUTH_OPEN:
4896 LINE_CHECK("authmode OPEN");
4898 case IEEE80211_AUTH_SHARED:
4899 LINE_CHECK("authmode SHARED");
4901 case IEEE80211_AUTH_8021X:
4902 LINE_CHECK("authmode 802.1x");
4904 case IEEE80211_AUTH_WPA:
4905 if (get80211val(s, IEEE80211_IOC_WPA, &wpa) < 0)
4906 wpa = 1; /* default to WPA1 */
4909 LINE_CHECK("authmode WPA2/802.11i");
4912 LINE_CHECK("authmode WPA1+WPA2/802.11i");
4915 LINE_CHECK("authmode WPA");
4919 case IEEE80211_AUTH_AUTO:
4920 LINE_CHECK("authmode AUTO");
4923 LINE_CHECK("authmode UNKNOWN (0x%x)", val);
4928 if (wpa || verbose) {
4929 if (get80211val(s, IEEE80211_IOC_WPS, &val) != -1) {
4935 if (get80211val(s, IEEE80211_IOC_TSN, &val) != -1) {
4941 if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) {
4943 LINE_CHECK("countermeasures");
4945 LINE_CHECK("-countermeasures");
4948 /* XXX not interesting with WPA done in user space */
4949 ireq.i_type = IEEE80211_IOC_KEYMGTALGS;
4950 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4953 ireq.i_type = IEEE80211_IOC_MCASTCIPHER;
4954 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4955 LINE_CHECK("mcastcipher ");
4956 printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN);
4960 ireq.i_type = IEEE80211_IOC_UCASTCIPHER;
4961 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4962 LINE_CHECK("ucastcipher ");
4963 printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN);
4967 ireq.i_type = IEEE80211_IOC_RSNCAPS;
4968 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4969 LINE_CHECK("RSN caps 0x%x", ireq.i_val);
4974 ireq.i_type = IEEE80211_IOC_UCASTCIPHERS;
4975 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4980 if (get80211val(s, IEEE80211_IOC_WEP, &wepmode) != -1 &&
4981 wepmode != IEEE80211_WEP_NOSUP) {
4984 case IEEE80211_WEP_OFF:
4985 LINE_CHECK("privacy OFF");
4987 case IEEE80211_WEP_ON:
4988 LINE_CHECK("privacy ON");
4990 case IEEE80211_WEP_MIXED:
4991 LINE_CHECK("privacy MIXED");
4994 LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode);
4999 * If we get here then we've got WEP support so we need
5000 * to print WEP status.
5003 if (get80211val(s, IEEE80211_IOC_WEPTXKEY, &val) < 0) {
5004 warn("WEP support, but no tx key!");
5008 LINE_CHECK("deftxkey %d", val+1);
5009 else if (wepmode != IEEE80211_WEP_OFF || verbose)
5010 LINE_CHECK("deftxkey UNDEF");
5012 if (get80211val(s, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) {
5013 warn("WEP support, but no NUMWEPKEYS support!");
5017 for (i = 0; i < num; i++) {
5018 struct ieee80211req_key ik;
5020 memset(&ik, 0, sizeof(ik));
5022 if (get80211(s, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) {
5023 warn("WEP support, but can get keys!");
5026 if (ik.ik_keylen != 0) {
5036 if (get80211val(s, IEEE80211_IOC_POWERSAVE, &val) != -1 &&
5037 val != IEEE80211_POWERSAVE_NOSUP ) {
5038 if (val != IEEE80211_POWERSAVE_OFF || verbose) {
5040 case IEEE80211_POWERSAVE_OFF:
5041 LINE_CHECK("powersavemode OFF");
5043 case IEEE80211_POWERSAVE_CAM:
5044 LINE_CHECK("powersavemode CAM");
5046 case IEEE80211_POWERSAVE_PSP:
5047 LINE_CHECK("powersavemode PSP");
5049 case IEEE80211_POWERSAVE_PSP_CAM:
5050 LINE_CHECK("powersavemode PSP-CAM");
5053 if (get80211val(s, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1)
5054 LINE_CHECK("powersavesleep %d", val);
5058 if (get80211val(s, IEEE80211_IOC_TXPOWER, &val) != -1) {
5060 LINE_CHECK("txpower %d.5", val/2);
5062 LINE_CHECK("txpower %d", val/2);
5065 if (get80211val(s, IEEE80211_IOC_TXPOWMAX, &val) != -1)
5066 LINE_CHECK("txpowmax %.1f", val/2.);
5069 if (get80211val(s, IEEE80211_IOC_DOTD, &val) != -1) {
5073 LINE_CHECK("-dotd");
5076 if (get80211val(s, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) {
5077 if (val != IEEE80211_RTS_MAX || verbose)
5078 LINE_CHECK("rtsthreshold %d", val);
5081 if (get80211val(s, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) {
5082 if (val != IEEE80211_FRAG_MAX || verbose)
5083 LINE_CHECK("fragthreshold %d", val);
5085 if (opmode == IEEE80211_M_STA || verbose) {
5086 if (get80211val(s, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) {
5087 if (val != IEEE80211_HWBMISS_MAX || verbose)
5088 LINE_CHECK("bmiss %d", val);
5094 tp = &txparams.params[chan2mode(c)];
5095 printrate("ucastrate", tp->ucastrate,
5096 IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE);
5097 printrate("mcastrate", tp->mcastrate, 2*1,
5098 IEEE80211_RATE_MCS|0);
5099 printrate("mgmtrate", tp->mgmtrate, 2*1,
5100 IEEE80211_RATE_MCS|0);
5101 if (tp->maxretry != 6) /* XXX */
5102 LINE_CHECK("maxretry %d", tp->maxretry);
5108 bgscaninterval = -1;
5109 (void) get80211val(s, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval);
5111 if (get80211val(s, IEEE80211_IOC_SCANVALID, &val) != -1) {
5112 if (val != bgscaninterval || verbose)
5113 LINE_CHECK("scanvalid %u", val);
5117 if (get80211val(s, IEEE80211_IOC_BGSCAN, &bgscan) != -1) {
5119 LINE_CHECK("bgscan");
5121 LINE_CHECK("-bgscan");
5123 if (bgscan || verbose) {
5124 if (bgscaninterval != -1)
5125 LINE_CHECK("bgscanintvl %u", bgscaninterval);
5126 if (get80211val(s, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1)
5127 LINE_CHECK("bgscanidle %u", val);
5130 rp = &roamparams.params[chan2mode(c)];
5132 LINE_CHECK("roam:rssi %u.5", rp->rssi/2);
5134 LINE_CHECK("roam:rssi %u", rp->rssi/2);
5135 LINE_CHECK("roam:rate %s%u",
5136 (rp->rate & IEEE80211_RATE_MCS) ? "MCS " : "",
5137 get_rate_value(rp->rate));
5145 if (IEEE80211_IS_CHAN_ANYG(c) || verbose) {
5146 if (get80211val(s, IEEE80211_IOC_PUREG, &val) != -1) {
5148 LINE_CHECK("pureg");
5150 LINE_CHECK("-pureg");
5152 if (get80211val(s, IEEE80211_IOC_PROTMODE, &val) != -1) {
5154 case IEEE80211_PROTMODE_OFF:
5155 LINE_CHECK("protmode OFF");
5157 case IEEE80211_PROTMODE_CTS:
5158 LINE_CHECK("protmode CTS");
5160 case IEEE80211_PROTMODE_RTSCTS:
5161 LINE_CHECK("protmode RTSCTS");
5164 LINE_CHECK("protmode UNKNOWN (0x%x)", val);
5170 if (IEEE80211_IS_CHAN_HT(c) || verbose) {
5172 switch (htconf & 3) {
5185 if (get80211val(s, IEEE80211_IOC_HTCOMPAT, &val) != -1) {
5187 LINE_CHECK("-htcompat");
5189 LINE_CHECK("htcompat");
5191 if (get80211val(s, IEEE80211_IOC_AMPDU, &val) != -1) {
5194 LINE_CHECK("-ampdu");
5197 LINE_CHECK("ampdutx -ampdurx");
5200 LINE_CHECK("-ampdutx ampdurx");
5204 LINE_CHECK("ampdu");
5208 /* XXX 11ac density/size is different */
5209 if (get80211val(s, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) {
5211 case IEEE80211_HTCAP_MAXRXAMPDU_8K:
5212 LINE_CHECK("ampdulimit 8k");
5214 case IEEE80211_HTCAP_MAXRXAMPDU_16K:
5215 LINE_CHECK("ampdulimit 16k");
5217 case IEEE80211_HTCAP_MAXRXAMPDU_32K:
5218 LINE_CHECK("ampdulimit 32k");
5220 case IEEE80211_HTCAP_MAXRXAMPDU_64K:
5221 LINE_CHECK("ampdulimit 64k");
5225 /* XXX 11ac density/size is different */
5226 if (get80211val(s, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) {
5228 case IEEE80211_HTCAP_MPDUDENSITY_NA:
5230 LINE_CHECK("ampdudensity NA");
5232 case IEEE80211_HTCAP_MPDUDENSITY_025:
5233 LINE_CHECK("ampdudensity .25");
5235 case IEEE80211_HTCAP_MPDUDENSITY_05:
5236 LINE_CHECK("ampdudensity .5");
5238 case IEEE80211_HTCAP_MPDUDENSITY_1:
5239 LINE_CHECK("ampdudensity 1");
5241 case IEEE80211_HTCAP_MPDUDENSITY_2:
5242 LINE_CHECK("ampdudensity 2");
5244 case IEEE80211_HTCAP_MPDUDENSITY_4:
5245 LINE_CHECK("ampdudensity 4");
5247 case IEEE80211_HTCAP_MPDUDENSITY_8:
5248 LINE_CHECK("ampdudensity 8");
5250 case IEEE80211_HTCAP_MPDUDENSITY_16:
5251 LINE_CHECK("ampdudensity 16");
5255 if (get80211val(s, IEEE80211_IOC_AMSDU, &val) != -1) {
5258 LINE_CHECK("-amsdu");
5261 LINE_CHECK("amsdutx -amsdurx");
5264 LINE_CHECK("-amsdutx amsdurx");
5268 LINE_CHECK("amsdu");
5272 /* XXX amsdu limit */
5273 if (get80211val(s, IEEE80211_IOC_SHORTGI, &val) != -1) {
5275 LINE_CHECK("shortgi");
5277 LINE_CHECK("-shortgi");
5279 if (get80211val(s, IEEE80211_IOC_HTPROTMODE, &val) != -1) {
5280 if (val == IEEE80211_PROTMODE_OFF)
5281 LINE_CHECK("htprotmode OFF");
5282 else if (val != IEEE80211_PROTMODE_RTSCTS)
5283 LINE_CHECK("htprotmode UNKNOWN (0x%x)", val);
5285 LINE_CHECK("htprotmode RTSCTS");
5287 if (get80211val(s, IEEE80211_IOC_PUREN, &val) != -1) {
5289 LINE_CHECK("puren");
5291 LINE_CHECK("-puren");
5293 if (get80211val(s, IEEE80211_IOC_SMPS, &val) != -1) {
5294 if (val == IEEE80211_HTCAP_SMPS_DYNAMIC)
5295 LINE_CHECK("smpsdyn");
5296 else if (val == IEEE80211_HTCAP_SMPS_ENA)
5299 LINE_CHECK("-smps");
5301 if (get80211val(s, IEEE80211_IOC_RIFS, &val) != -1) {
5305 LINE_CHECK("-rifs");
5309 if (get80211val(s, IEEE80211_IOC_STBC, &val) != -1) {
5312 LINE_CHECK("-stbc");
5315 LINE_CHECK("stbctx -stbcrx");
5318 LINE_CHECK("-stbctx stbcrx");
5326 if (get80211val(s, IEEE80211_IOC_LDPC, &val) != -1) {
5329 LINE_CHECK("-ldpc");
5332 LINE_CHECK("ldpctx -ldpcrx");
5335 LINE_CHECK("-ldpctx ldpcrx");
5343 if (get80211val(s, IEEE80211_IOC_UAPSD, &val) != -1) {
5346 LINE_CHECK("-uapsd");
5349 LINE_CHECK("uapsd");
5355 if (IEEE80211_IS_CHAN_VHT(c) || verbose) {
5357 if (vhtconf & IEEE80211_FVHT_VHT)
5361 if (vhtconf & IEEE80211_FVHT_USEVHT40)
5362 LINE_CHECK("vht40");
5364 LINE_CHECK("-vht40");
5365 if (vhtconf & IEEE80211_FVHT_USEVHT80)
5366 LINE_CHECK("vht80");
5368 LINE_CHECK("-vht80");
5369 if (vhtconf & IEEE80211_FVHT_USEVHT160)
5370 LINE_CHECK("vht160");
5372 LINE_CHECK("-vht160");
5373 if (vhtconf & IEEE80211_FVHT_USEVHT80P80)
5374 LINE_CHECK("vht80p80");
5376 LINE_CHECK("-vht80p80");
5379 if (get80211val(s, IEEE80211_IOC_WME, &wme) != -1) {
5387 if (get80211val(s, IEEE80211_IOC_BURST, &val) != -1) {
5389 LINE_CHECK("burst");
5391 LINE_CHECK("-burst");
5394 if (get80211val(s, IEEE80211_IOC_FF, &val) != -1) {
5400 if (get80211val(s, IEEE80211_IOC_TURBOP, &val) != -1) {
5402 LINE_CHECK("dturbo");
5404 LINE_CHECK("-dturbo");
5406 if (get80211val(s, IEEE80211_IOC_DWDS, &val) != -1) {
5410 LINE_CHECK("-dwds");
5413 if (opmode == IEEE80211_M_HOSTAP) {
5414 if (get80211val(s, IEEE80211_IOC_HIDESSID, &val) != -1) {
5416 LINE_CHECK("hidessid");
5418 LINE_CHECK("-hidessid");
5420 if (get80211val(s, IEEE80211_IOC_APBRIDGE, &val) != -1) {
5422 LINE_CHECK("-apbridge");
5424 LINE_CHECK("apbridge");
5426 if (get80211val(s, IEEE80211_IOC_DTIM_PERIOD, &val) != -1)
5427 LINE_CHECK("dtimperiod %u", val);
5429 if (get80211val(s, IEEE80211_IOC_DOTH, &val) != -1) {
5431 LINE_CHECK("-doth");
5435 if (get80211val(s, IEEE80211_IOC_DFS, &val) != -1) {
5441 if (get80211val(s, IEEE80211_IOC_INACTIVITY, &val) != -1) {
5443 LINE_CHECK("-inact");
5445 LINE_CHECK("inact");
5448 if (get80211val(s, IEEE80211_IOC_ROAMING, &val) != -1) {
5449 if (val != IEEE80211_ROAMING_AUTO || verbose) {
5451 case IEEE80211_ROAMING_DEVICE:
5452 LINE_CHECK("roaming DEVICE");
5454 case IEEE80211_ROAMING_AUTO:
5455 LINE_CHECK("roaming AUTO");
5457 case IEEE80211_ROAMING_MANUAL:
5458 LINE_CHECK("roaming MANUAL");
5461 LINE_CHECK("roaming UNKNOWN (0x%x)",
5469 if (opmode == IEEE80211_M_AHDEMO) {
5470 if (get80211val(s, IEEE80211_IOC_TDMA_SLOT, &val) != -1)
5471 LINE_CHECK("tdmaslot %u", val);
5472 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1)
5473 LINE_CHECK("tdmaslotcnt %u", val);
5474 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1)
5475 LINE_CHECK("tdmaslotlen %u", val);
5476 if (get80211val(s, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1)
5477 LINE_CHECK("tdmabintval %u", val);
5478 } else if (get80211val(s, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) {
5479 /* XXX default define not visible */
5480 if (val != 100 || verbose)
5481 LINE_CHECK("bintval %u", val);
5484 if (wme && verbose) {
5489 if (opmode == IEEE80211_M_MBSS) {
5490 if (get80211val(s, IEEE80211_IOC_MESH_TTL, &val) != -1) {
5491 LINE_CHECK("meshttl %u", val);
5493 if (get80211val(s, IEEE80211_IOC_MESH_AP, &val) != -1) {
5495 LINE_CHECK("meshpeering");
5497 LINE_CHECK("-meshpeering");
5499 if (get80211val(s, IEEE80211_IOC_MESH_FWRD, &val) != -1) {
5501 LINE_CHECK("meshforward");
5503 LINE_CHECK("-meshforward");
5505 if (get80211val(s, IEEE80211_IOC_MESH_GATE, &val) != -1) {
5507 LINE_CHECK("meshgate");
5509 LINE_CHECK("-meshgate");
5511 if (get80211len(s, IEEE80211_IOC_MESH_PR_METRIC, data, 12,
5514 LINE_CHECK("meshmetric %s", data);
5516 if (get80211len(s, IEEE80211_IOC_MESH_PR_PATH, data, 12,
5519 LINE_CHECK("meshpath %s", data);
5521 if (get80211val(s, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) {
5523 case IEEE80211_HWMP_ROOTMODE_DISABLED:
5524 LINE_CHECK("hwmprootmode DISABLED");
5526 case IEEE80211_HWMP_ROOTMODE_NORMAL:
5527 LINE_CHECK("hwmprootmode NORMAL");
5529 case IEEE80211_HWMP_ROOTMODE_PROACTIVE:
5530 LINE_CHECK("hwmprootmode PROACTIVE");
5532 case IEEE80211_HWMP_ROOTMODE_RANN:
5533 LINE_CHECK("hwmprootmode RANN");
5536 LINE_CHECK("hwmprootmode UNKNOWN(%d)", val);
5540 if (get80211val(s, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) {
5541 LINE_CHECK("hwmpmaxhops %u", val);
5547 if (getdevicename(s, data, sizeof(data), &len) < 0)
5549 LINE_CHECK("parent interface: %s", data);
5555 get80211(int s, int type, void *data, int len)
5558 return (lib80211_get80211(s, name, type, data, len));
5562 get80211len(int s, int type, void *data, int len, int *plen)
5565 return (lib80211_get80211len(s, name, type, data, len, plen));
5569 get80211val(int s, int type, int *val)
5572 return (lib80211_get80211val(s, name, type, val));
5576 set80211(int s, int type, int val, int len, void *data)
5580 ret = lib80211_set80211(s, name, type, val, len, data);
5582 err(1, "SIOCS80211");
5586 get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
5594 hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x');
5600 if (sep != NULL && strchr(sep, *val) != NULL) {
5605 if (!isxdigit((u_char)val[0])) {
5606 warnx("bad hexadecimal digits");
5609 if (!isxdigit((u_char)val[1])) {
5610 warnx("odd count hexadecimal digits");
5614 if (p >= buf + len) {
5616 warnx("hexadecimal digits too long");
5618 warnx("string too long");
5622 #define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
5623 *p++ = (tohex((u_char)val[0]) << 4) |
5624 tohex((u_char)val[1]);
5631 /* The string "-" is treated as the empty string. */
5632 if (!hexstr && len == 1 && buf[0] == '-') {
5634 memset(buf, 0, *lenp);
5635 } else if (len < *lenp)
5636 memset(p, 0, *lenp - len);
5642 print_string(const u_int8_t *buf, int len)
5651 setlocale(LC_CTYPE, "");
5652 utf8 = strncmp("UTF-8", nl_langinfo(CODESET), 5) == 0;
5654 for (; i < len; i++) {
5655 if (!isprint(buf[i]) && buf[i] != '\0' && !utf8)
5657 if (isspace(buf[i]))
5660 if (i == len || utf8) {
5661 if (hasspc || len == 0 || buf[0] == '\0')
5662 printf("\"%.*s\"", len, buf);
5664 printf("%.*s", len, buf);
5667 for (i = 0; i < len; i++)
5668 printf("%02x", buf[i]);
5673 setdefregdomain(int s)
5675 struct regdata *rdp = getregdata();
5676 const struct regdomain *rd;
5678 /* Check if regdomain/country was already set by a previous call. */
5679 /* XXX is it possible? */
5680 if (regdomain.regdomain != 0 ||
5681 regdomain.country != CTRY_DEFAULT)
5686 /* Check if it was already set by the driver. */
5687 if (regdomain.regdomain != 0 ||
5688 regdomain.country != CTRY_DEFAULT)
5691 /* Set FCC/US as default. */
5692 rd = lib80211_regdomain_findbysku(rdp, SKU_FCC);
5694 errx(1, "FCC regdomain was not found");
5696 regdomain.regdomain = rd->sku;
5700 /* Send changes to net80211. */
5701 setregdomain_cb(s, ®domain);
5703 /* Cleanup (so it can be overriden by subsequent parameters). */
5704 regdomain.regdomain = 0;
5705 regdomain.country = CTRY_DEFAULT;
5706 regdomain.isocc[0] = 0;
5707 regdomain.isocc[1] = 0;
5711 * Virtual AP cloning support.
5713 static struct ieee80211_clone_params params = {
5714 .icp_opmode = IEEE80211_M_STA, /* default to station mode */
5718 wlan_create(int s, struct ifreq *ifr)
5720 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
5721 char orig_name[IFNAMSIZ];
5723 if (params.icp_parent[0] == '\0')
5724 errx(1, "must specify a parent device (wlandev) when creating "
5726 if (params.icp_opmode == IEEE80211_M_WDS &&
5727 memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0)
5728 errx(1, "no bssid specified for WDS (use wlanbssid)");
5729 ifr->ifr_data = (caddr_t) ¶ms;
5730 if (ioctl(s, SIOCIFCREATE2, ifr) < 0)
5731 err(1, "SIOCIFCREATE2");
5733 /* XXX preserve original name for ifclonecreate(). */
5734 strlcpy(orig_name, name, sizeof(orig_name));
5735 strlcpy(name, ifr->ifr_name, sizeof(name));
5739 strlcpy(name, orig_name, sizeof(name));
5743 DECL_CMD_FUNC(set80211clone_wlandev, arg, d)
5745 strlcpy(params.icp_parent, arg, IFNAMSIZ);
5749 DECL_CMD_FUNC(set80211clone_wlanbssid, arg, d)
5751 const struct ether_addr *ea;
5753 ea = ether_aton(arg);
5755 errx(1, "%s: cannot parse bssid", arg);
5756 memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN);
5760 DECL_CMD_FUNC(set80211clone_wlanaddr, arg, d)
5762 const struct ether_addr *ea;
5764 ea = ether_aton(arg);
5766 errx(1, "%s: cannot parse address", arg);
5767 memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN);
5768 params.icp_flags |= IEEE80211_CLONE_MACADDR;
5772 DECL_CMD_FUNC(set80211clone_wlanmode, arg, d)
5774 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
5775 if (iseq(arg, "sta"))
5776 params.icp_opmode = IEEE80211_M_STA;
5777 else if (iseq(arg, "ahdemo") || iseq(arg, "adhoc-demo"))
5778 params.icp_opmode = IEEE80211_M_AHDEMO;
5779 else if (iseq(arg, "ibss") || iseq(arg, "adhoc"))
5780 params.icp_opmode = IEEE80211_M_IBSS;
5781 else if (iseq(arg, "ap") || iseq(arg, "host"))
5782 params.icp_opmode = IEEE80211_M_HOSTAP;
5783 else if (iseq(arg, "wds"))
5784 params.icp_opmode = IEEE80211_M_WDS;
5785 else if (iseq(arg, "monitor"))
5786 params.icp_opmode = IEEE80211_M_MONITOR;
5787 else if (iseq(arg, "tdma")) {
5788 params.icp_opmode = IEEE80211_M_AHDEMO;
5789 params.icp_flags |= IEEE80211_CLONE_TDMA;
5790 } else if (iseq(arg, "mesh") || iseq(arg, "mp")) /* mesh point */
5791 params.icp_opmode = IEEE80211_M_MBSS;
5793 errx(1, "Don't know to create %s for %s", arg, name);
5798 set80211clone_beacons(const char *val, int d, int s, const struct afswtch *rafp)
5800 /* NB: inverted sense */
5802 params.icp_flags &= ~IEEE80211_CLONE_NOBEACONS;
5804 params.icp_flags |= IEEE80211_CLONE_NOBEACONS;
5808 set80211clone_bssid(const char *val, int d, int s, const struct afswtch *rafp)
5811 params.icp_flags |= IEEE80211_CLONE_BSSID;
5813 params.icp_flags &= ~IEEE80211_CLONE_BSSID;
5817 set80211clone_wdslegacy(const char *val, int d, int s, const struct afswtch *rafp)
5820 params.icp_flags |= IEEE80211_CLONE_WDSLEGACY;
5822 params.icp_flags &= ~IEEE80211_CLONE_WDSLEGACY;
5825 static struct cmd ieee80211_cmds[] = {
5826 DEF_CMD_ARG("ssid", set80211ssid),
5827 DEF_CMD_ARG("nwid", set80211ssid),
5828 DEF_CMD_ARG("meshid", set80211meshid),
5829 DEF_CMD_ARG("stationname", set80211stationname),
5830 DEF_CMD_ARG("station", set80211stationname), /* BSD/OS */
5831 DEF_CMD_ARG("channel", set80211channel),
5832 DEF_CMD_ARG("authmode", set80211authmode),
5833 DEF_CMD_ARG("powersavemode", set80211powersavemode),
5834 DEF_CMD("powersave", 1, set80211powersave),
5835 DEF_CMD("-powersave", 0, set80211powersave),
5836 DEF_CMD_ARG("powersavesleep", set80211powersavesleep),
5837 DEF_CMD_ARG("wepmode", set80211wepmode),
5838 DEF_CMD("wep", 1, set80211wep),
5839 DEF_CMD("-wep", 0, set80211wep),
5840 DEF_CMD_ARG("deftxkey", set80211weptxkey),
5841 DEF_CMD_ARG("weptxkey", set80211weptxkey),
5842 DEF_CMD_ARG("wepkey", set80211wepkey),
5843 DEF_CMD_ARG("nwkey", set80211nwkey), /* NetBSD */
5844 DEF_CMD("-nwkey", 0, set80211wep), /* NetBSD */
5845 DEF_CMD_ARG("rtsthreshold", set80211rtsthreshold),
5846 DEF_CMD_ARG("protmode", set80211protmode),
5847 DEF_CMD_ARG("txpower", set80211txpower),
5848 DEF_CMD_ARG("roaming", set80211roaming),
5849 DEF_CMD("wme", 1, set80211wme),
5850 DEF_CMD("-wme", 0, set80211wme),
5851 DEF_CMD("wmm", 1, set80211wme),
5852 DEF_CMD("-wmm", 0, set80211wme),
5853 DEF_CMD("hidessid", 1, set80211hidessid),
5854 DEF_CMD("-hidessid", 0, set80211hidessid),
5855 DEF_CMD("apbridge", 1, set80211apbridge),
5856 DEF_CMD("-apbridge", 0, set80211apbridge),
5857 DEF_CMD_ARG("chanlist", set80211chanlist),
5858 DEF_CMD_ARG("bssid", set80211bssid),
5859 DEF_CMD_ARG("ap", set80211bssid),
5860 DEF_CMD("scan", 0, set80211scan),
5861 DEF_CMD_ARG("list", set80211list),
5862 DEF_CMD_ARG2("cwmin", set80211cwmin),
5863 DEF_CMD_ARG2("cwmax", set80211cwmax),
5864 DEF_CMD_ARG2("aifs", set80211aifs),
5865 DEF_CMD_ARG2("txoplimit", set80211txoplimit),
5866 DEF_CMD_ARG("acm", set80211acm),
5867 DEF_CMD_ARG("-acm", set80211noacm),
5868 DEF_CMD_ARG("ack", set80211ackpolicy),
5869 DEF_CMD_ARG("-ack", set80211noackpolicy),
5870 DEF_CMD_ARG2("bss:cwmin", set80211bsscwmin),
5871 DEF_CMD_ARG2("bss:cwmax", set80211bsscwmax),
5872 DEF_CMD_ARG2("bss:aifs", set80211bssaifs),
5873 DEF_CMD_ARG2("bss:txoplimit", set80211bsstxoplimit),
5874 DEF_CMD_ARG("dtimperiod", set80211dtimperiod),
5875 DEF_CMD_ARG("bintval", set80211bintval),
5876 DEF_CMD("mac:open", IEEE80211_MACCMD_POLICY_OPEN, set80211maccmd),
5877 DEF_CMD("mac:allow", IEEE80211_MACCMD_POLICY_ALLOW, set80211maccmd),
5878 DEF_CMD("mac:deny", IEEE80211_MACCMD_POLICY_DENY, set80211maccmd),
5879 DEF_CMD("mac:radius", IEEE80211_MACCMD_POLICY_RADIUS, set80211maccmd),
5880 DEF_CMD("mac:flush", IEEE80211_MACCMD_FLUSH, set80211maccmd),
5881 DEF_CMD("mac:detach", IEEE80211_MACCMD_DETACH, set80211maccmd),
5882 DEF_CMD_ARG("mac:add", set80211addmac),
5883 DEF_CMD_ARG("mac:del", set80211delmac),
5884 DEF_CMD_ARG("mac:kick", set80211kickmac),
5885 DEF_CMD("pureg", 1, set80211pureg),
5886 DEF_CMD("-pureg", 0, set80211pureg),
5887 DEF_CMD("ff", 1, set80211fastframes),
5888 DEF_CMD("-ff", 0, set80211fastframes),
5889 DEF_CMD("dturbo", 1, set80211dturbo),
5890 DEF_CMD("-dturbo", 0, set80211dturbo),
5891 DEF_CMD("bgscan", 1, set80211bgscan),
5892 DEF_CMD("-bgscan", 0, set80211bgscan),
5893 DEF_CMD_ARG("bgscanidle", set80211bgscanidle),
5894 DEF_CMD_ARG("bgscanintvl", set80211bgscanintvl),
5895 DEF_CMD_ARG("scanvalid", set80211scanvalid),
5896 DEF_CMD("quiet", 1, set80211quiet),
5897 DEF_CMD("-quiet", 0, set80211quiet),
5898 DEF_CMD_ARG("quiet_count", set80211quietcount),
5899 DEF_CMD_ARG("quiet_period", set80211quietperiod),
5900 DEF_CMD_ARG("quiet_duration", set80211quietduration),
5901 DEF_CMD_ARG("quiet_offset", set80211quietoffset),
5902 DEF_CMD_ARG("roam:rssi", set80211roamrssi),
5903 DEF_CMD_ARG("roam:rate", set80211roamrate),
5904 DEF_CMD_ARG("mcastrate", set80211mcastrate),
5905 DEF_CMD_ARG("ucastrate", set80211ucastrate),
5906 DEF_CMD_ARG("mgtrate", set80211mgtrate),
5907 DEF_CMD_ARG("mgmtrate", set80211mgtrate),
5908 DEF_CMD_ARG("maxretry", set80211maxretry),
5909 DEF_CMD_ARG("fragthreshold", set80211fragthreshold),
5910 DEF_CMD("burst", 1, set80211burst),
5911 DEF_CMD("-burst", 0, set80211burst),
5912 DEF_CMD_ARG("bmiss", set80211bmissthreshold),
5913 DEF_CMD_ARG("bmissthreshold", set80211bmissthreshold),
5914 DEF_CMD("shortgi", 1, set80211shortgi),
5915 DEF_CMD("-shortgi", 0, set80211shortgi),
5916 DEF_CMD("ampdurx", 2, set80211ampdu),
5917 DEF_CMD("-ampdurx", -2, set80211ampdu),
5918 DEF_CMD("ampdutx", 1, set80211ampdu),
5919 DEF_CMD("-ampdutx", -1, set80211ampdu),
5920 DEF_CMD("ampdu", 3, set80211ampdu), /* NB: tx+rx */
5921 DEF_CMD("-ampdu", -3, set80211ampdu),
5922 DEF_CMD_ARG("ampdulimit", set80211ampdulimit),
5923 DEF_CMD_ARG("ampdudensity", set80211ampdudensity),
5924 DEF_CMD("amsdurx", 2, set80211amsdu),
5925 DEF_CMD("-amsdurx", -2, set80211amsdu),
5926 DEF_CMD("amsdutx", 1, set80211amsdu),
5927 DEF_CMD("-amsdutx", -1, set80211amsdu),
5928 DEF_CMD("amsdu", 3, set80211amsdu), /* NB: tx+rx */
5929 DEF_CMD("-amsdu", -3, set80211amsdu),
5930 DEF_CMD_ARG("amsdulimit", set80211amsdulimit),
5931 DEF_CMD("stbcrx", 2, set80211stbc),
5932 DEF_CMD("-stbcrx", -2, set80211stbc),
5933 DEF_CMD("stbctx", 1, set80211stbc),
5934 DEF_CMD("-stbctx", -1, set80211stbc),
5935 DEF_CMD("stbc", 3, set80211stbc), /* NB: tx+rx */
5936 DEF_CMD("-stbc", -3, set80211stbc),
5937 DEF_CMD("ldpcrx", 2, set80211ldpc),
5938 DEF_CMD("-ldpcrx", -2, set80211ldpc),
5939 DEF_CMD("ldpctx", 1, set80211ldpc),
5940 DEF_CMD("-ldpctx", -1, set80211ldpc),
5941 DEF_CMD("ldpc", 3, set80211ldpc), /* NB: tx+rx */
5942 DEF_CMD("-ldpc", -3, set80211ldpc),
5943 DEF_CMD("uapsd", 1, set80211uapsd),
5944 DEF_CMD("-uapsd", 0, set80211uapsd),
5945 DEF_CMD("puren", 1, set80211puren),
5946 DEF_CMD("-puren", 0, set80211puren),
5947 DEF_CMD("doth", 1, set80211doth),
5948 DEF_CMD("-doth", 0, set80211doth),
5949 DEF_CMD("dfs", 1, set80211dfs),
5950 DEF_CMD("-dfs", 0, set80211dfs),
5951 DEF_CMD("htcompat", 1, set80211htcompat),
5952 DEF_CMD("-htcompat", 0, set80211htcompat),
5953 DEF_CMD("dwds", 1, set80211dwds),
5954 DEF_CMD("-dwds", 0, set80211dwds),
5955 DEF_CMD("inact", 1, set80211inact),
5956 DEF_CMD("-inact", 0, set80211inact),
5957 DEF_CMD("tsn", 1, set80211tsn),
5958 DEF_CMD("-tsn", 0, set80211tsn),
5959 DEF_CMD_ARG("regdomain", set80211regdomain),
5960 DEF_CMD_ARG("country", set80211country),
5961 DEF_CMD("indoor", 'I', set80211location),
5962 DEF_CMD("-indoor", 'O', set80211location),
5963 DEF_CMD("outdoor", 'O', set80211location),
5964 DEF_CMD("-outdoor", 'I', set80211location),
5965 DEF_CMD("anywhere", ' ', set80211location),
5966 DEF_CMD("ecm", 1, set80211ecm),
5967 DEF_CMD("-ecm", 0, set80211ecm),
5968 DEF_CMD("dotd", 1, set80211dotd),
5969 DEF_CMD("-dotd", 0, set80211dotd),
5970 DEF_CMD_ARG("htprotmode", set80211htprotmode),
5971 DEF_CMD("ht20", 1, set80211htconf),
5972 DEF_CMD("-ht20", 0, set80211htconf),
5973 DEF_CMD("ht40", 3, set80211htconf), /* NB: 20+40 */
5974 DEF_CMD("-ht40", 0, set80211htconf),
5975 DEF_CMD("ht", 3, set80211htconf), /* NB: 20+40 */
5976 DEF_CMD("-ht", 0, set80211htconf),
5977 DEF_CMD("vht", IEEE80211_FVHT_VHT, set80211vhtconf),
5978 DEF_CMD("-vht", 0, set80211vhtconf),
5979 DEF_CMD("vht40", IEEE80211_FVHT_USEVHT40, set80211vhtconf),
5980 DEF_CMD("-vht40", -IEEE80211_FVHT_USEVHT40, set80211vhtconf),
5981 DEF_CMD("vht80", IEEE80211_FVHT_USEVHT80, set80211vhtconf),
5982 DEF_CMD("-vht80", -IEEE80211_FVHT_USEVHT80, set80211vhtconf),
5983 DEF_CMD("vht160", IEEE80211_FVHT_USEVHT160, set80211vhtconf),
5984 DEF_CMD("-vht160", -IEEE80211_FVHT_USEVHT160, set80211vhtconf),
5985 DEF_CMD("vht80p80", IEEE80211_FVHT_USEVHT80P80, set80211vhtconf),
5986 DEF_CMD("-vht80p80", -IEEE80211_FVHT_USEVHT80P80, set80211vhtconf),
5987 DEF_CMD("rifs", 1, set80211rifs),
5988 DEF_CMD("-rifs", 0, set80211rifs),
5989 DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA, set80211smps),
5990 DEF_CMD("smpsdyn", IEEE80211_HTCAP_SMPS_DYNAMIC, set80211smps),
5991 DEF_CMD("-smps", IEEE80211_HTCAP_SMPS_OFF, set80211smps),
5992 /* XXX for testing */
5993 DEF_CMD_ARG("chanswitch", set80211chanswitch),
5995 DEF_CMD_ARG("tdmaslot", set80211tdmaslot),
5996 DEF_CMD_ARG("tdmaslotcnt", set80211tdmaslotcnt),
5997 DEF_CMD_ARG("tdmaslotlen", set80211tdmaslotlen),
5998 DEF_CMD_ARG("tdmabintval", set80211tdmabintval),
6000 DEF_CMD_ARG("meshttl", set80211meshttl),
6001 DEF_CMD("meshforward", 1, set80211meshforward),
6002 DEF_CMD("-meshforward", 0, set80211meshforward),
6003 DEF_CMD("meshgate", 1, set80211meshgate),
6004 DEF_CMD("-meshgate", 0, set80211meshgate),
6005 DEF_CMD("meshpeering", 1, set80211meshpeering),
6006 DEF_CMD("-meshpeering", 0, set80211meshpeering),
6007 DEF_CMD_ARG("meshmetric", set80211meshmetric),
6008 DEF_CMD_ARG("meshpath", set80211meshpath),
6009 DEF_CMD("meshrt:flush", IEEE80211_MESH_RTCMD_FLUSH, set80211meshrtcmd),
6010 DEF_CMD_ARG("meshrt:add", set80211addmeshrt),
6011 DEF_CMD_ARG("meshrt:del", set80211delmeshrt),
6012 DEF_CMD_ARG("hwmprootmode", set80211hwmprootmode),
6013 DEF_CMD_ARG("hwmpmaxhops", set80211hwmpmaxhops),
6015 /* vap cloning support */
6016 DEF_CLONE_CMD_ARG("wlanaddr", set80211clone_wlanaddr),
6017 DEF_CLONE_CMD_ARG("wlanbssid", set80211clone_wlanbssid),
6018 DEF_CLONE_CMD_ARG("wlandev", set80211clone_wlandev),
6019 DEF_CLONE_CMD_ARG("wlanmode", set80211clone_wlanmode),
6020 DEF_CLONE_CMD("beacons", 1, set80211clone_beacons),
6021 DEF_CLONE_CMD("-beacons", 0, set80211clone_beacons),
6022 DEF_CLONE_CMD("bssid", 1, set80211clone_bssid),
6023 DEF_CLONE_CMD("-bssid", 0, set80211clone_bssid),
6024 DEF_CLONE_CMD("wdslegacy", 1, set80211clone_wdslegacy),
6025 DEF_CLONE_CMD("-wdslegacy", 0, set80211clone_wdslegacy),
6027 static struct afswtch af_ieee80211 = {
6028 .af_name = "af_ieee80211",
6030 .af_other_status = ieee80211_status,
6033 static __constructor void
6034 ieee80211_ctor(void)
6038 for (i = 0; i < nitems(ieee80211_cmds); i++)
6039 cmd_register(&ieee80211_cmds[i]);
6040 af_register(&af_ieee80211);
6041 clone_setdefcallback("wlan", wlan_create);