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 /* Helper macros unified. */
142 #ifndef _IEEE80211_MASKSHIFT
143 #define _IEEE80211_MASKSHIFT(_v, _f) (((_v) & _f) >> _f##_S)
145 #ifndef _IEEE80211_SHIFTMASK
146 #define _IEEE80211_SHIFTMASK(_v, _f) (((_v) << _f##_S) & _f)
149 #define MAXCHAN 1536 /* max 1.5K channels */
155 static void LINE_INIT(char c);
156 static void LINE_BREAK(void);
157 static void LINE_CHECK(const char *fmt, ...);
159 static const char *modename[IEEE80211_MODE_MAX] = {
160 [IEEE80211_MODE_AUTO] = "auto",
161 [IEEE80211_MODE_11A] = "11a",
162 [IEEE80211_MODE_11B] = "11b",
163 [IEEE80211_MODE_11G] = "11g",
164 [IEEE80211_MODE_FH] = "fh",
165 [IEEE80211_MODE_TURBO_A] = "turboA",
166 [IEEE80211_MODE_TURBO_G] = "turboG",
167 [IEEE80211_MODE_STURBO_A] = "sturbo",
168 [IEEE80211_MODE_11NA] = "11na",
169 [IEEE80211_MODE_11NG] = "11ng",
170 [IEEE80211_MODE_HALF] = "half",
171 [IEEE80211_MODE_QUARTER] = "quarter",
172 [IEEE80211_MODE_VHT_2GHZ] = "11acg",
173 [IEEE80211_MODE_VHT_5GHZ] = "11ac",
176 static void set80211(int s, int type, int val, int len, void *data);
177 static int get80211(int s, int type, void *data, int len);
178 static int get80211len(int s, int type, void *data, int len, int *plen);
179 static int get80211val(int s, int type, int *val);
180 static const char *get_string(const char *val, const char *sep,
181 u_int8_t *buf, int *lenp);
182 static void print_string(const u_int8_t *buf, int len);
183 static void print_regdomain(const struct ieee80211_regdomain *, int);
184 static void print_channels(int, const struct ieee80211req_chaninfo *,
185 int allchans, int verbose);
186 static void regdomain_makechannels(struct ieee80211_regdomain_req *,
187 const struct ieee80211_devcaps_req *);
188 static const char *mesh_linkstate_string(uint8_t state);
190 static struct ieee80211req_chaninfo *chaninfo;
191 static struct ieee80211_regdomain regdomain;
192 static int gotregdomain = 0;
193 static struct ieee80211_roamparams_req roamparams;
194 static int gotroam = 0;
195 static struct ieee80211_txparams_req txparams;
196 static int gottxparams = 0;
197 static struct ieee80211_channel curchan;
198 static int gotcurchan = 0;
199 static struct ifmediareq *ifmr;
200 static int htconf = 0;
201 static int gothtconf = 0;
208 if (get80211val(s, IEEE80211_IOC_HTCONF, &htconf) < 0)
209 warn("unable to get HT configuration information");
214 static int vhtconf = 0;
215 static int gotvhtconf = 0;
222 if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
223 warn("unable to get VHT configuration information");
228 * Collect channel info from the kernel. We use this (mostly)
229 * to handle mapping between frequency and IEEE channel number.
234 if (chaninfo != NULL)
236 chaninfo = malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN));
237 if (chaninfo == NULL)
238 errx(1, "no space for channel list");
239 if (get80211(s, IEEE80211_IOC_CHANINFO, chaninfo,
240 IEEE80211_CHANINFO_SIZE(MAXCHAN)) < 0)
241 err(1, "unable to get channel information");
242 ifmr = ifmedia_getstate(s);
247 static struct regdata *
250 static struct regdata *rdp = NULL;
252 rdp = lib80211_alloc_regdata();
254 errx(-1, "missing or corrupted regdomain database");
260 * Given the channel at index i with attributes from,
261 * check if there is a channel with attributes to in
262 * the channel table. With suitable attributes this
263 * allows the caller to look for promotion; e.g. from
267 canpromote(int i, int from, int to)
269 const struct ieee80211_channel *fc = &chaninfo->ic_chans[i];
272 if ((fc->ic_flags & from) != from)
274 /* NB: quick check exploiting ordering of chans w/ same frequency */
275 if (i+1 < chaninfo->ic_nchans &&
276 chaninfo->ic_chans[i+1].ic_freq == fc->ic_freq &&
277 (chaninfo->ic_chans[i+1].ic_flags & to) == to)
279 /* brute force search in case channel list is not ordered */
280 for (j = 0; j < chaninfo->ic_nchans; j++) {
281 const struct ieee80211_channel *tc = &chaninfo->ic_chans[j];
283 tc->ic_freq == fc->ic_freq && (tc->ic_flags & to) == to)
290 * Handle channel promotion. When a channel is specified with
291 * only a frequency we want to promote it to the ``best'' channel
292 * available. The channel list has separate entries for 11b, 11g,
293 * 11a, and 11n[ga] channels so specifying a frequency w/o any
294 * attributes requires we upgrade, e.g. from 11b -> 11g. This
295 * gets complicated when the channel is specified on the same
296 * command line with a media request that constrains the available
297 * channe list (e.g. mode 11a); we want to honor that to avoid
298 * confusing behaviour.
307 * Query the current mode of the interface in case it's
308 * constrained (e.g. to 11a). We must do this carefully
309 * as there may be a pending ifmedia request in which case
310 * asking the kernel will give us the wrong answer. This
311 * is an unfortunate side-effect of the way ifconfig is
312 * structure for modularity (yech).
314 * NB: ifmr is actually setup in getchaninfo (above); we
315 * assume it's called coincident with to this call so
316 * we have a ``current setting''; otherwise we must pass
317 * the socket descriptor down to here so we can make
318 * the ifmedia_getstate call ourselves.
320 int chanmode = ifmr != NULL ? IFM_MODE(ifmr->ifm_current) : IFM_AUTO;
322 /* when ambiguous promote to ``best'' */
323 /* NB: we abitrarily pick HT40+ over HT40- */
324 if (chanmode != IFM_IEEE80211_11B)
325 i = canpromote(i, IEEE80211_CHAN_B, IEEE80211_CHAN_G);
326 if (chanmode != IFM_IEEE80211_11G && (htconf & 1)) {
327 i = canpromote(i, IEEE80211_CHAN_G,
328 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20);
330 i = canpromote(i, IEEE80211_CHAN_G,
331 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D);
332 i = canpromote(i, IEEE80211_CHAN_G,
333 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U);
336 if (chanmode != IFM_IEEE80211_11A && (htconf & 1)) {
337 i = canpromote(i, IEEE80211_CHAN_A,
338 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20);
340 i = canpromote(i, IEEE80211_CHAN_A,
341 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D);
342 i = canpromote(i, IEEE80211_CHAN_A,
343 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U);
350 mapfreq(struct ieee80211_channel *chan, int freq, int flags)
354 for (i = 0; i < chaninfo->ic_nchans; i++) {
355 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
357 if (c->ic_freq == freq && (c->ic_flags & flags) == flags) {
359 /* when ambiguous promote to ``best'' */
360 c = &chaninfo->ic_chans[promote(i)];
366 errx(1, "unknown/undefined frequency %u/0x%x", freq, flags);
370 mapchan(struct ieee80211_channel *chan, int ieee, int flags)
374 for (i = 0; i < chaninfo->ic_nchans; i++) {
375 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
377 if (c->ic_ieee == ieee && (c->ic_flags & flags) == flags) {
379 /* when ambiguous promote to ``best'' */
380 c = &chaninfo->ic_chans[promote(i)];
386 errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags);
389 static const struct ieee80211_channel *
394 if (get80211(s, IEEE80211_IOC_CURCHAN, &curchan, sizeof(curchan)) < 0) {
396 /* fall back to legacy ioctl */
397 if (get80211val(s, IEEE80211_IOC_CHANNEL, &val) < 0)
398 err(-1, "cannot figure out current channel");
400 mapchan(&curchan, val, 0);
406 static enum ieee80211_phymode
407 chan2mode(const struct ieee80211_channel *c)
409 if (IEEE80211_IS_CHAN_VHTA(c))
410 return IEEE80211_MODE_VHT_5GHZ;
411 if (IEEE80211_IS_CHAN_VHTG(c))
412 return IEEE80211_MODE_VHT_2GHZ;
413 if (IEEE80211_IS_CHAN_HTA(c))
414 return IEEE80211_MODE_11NA;
415 if (IEEE80211_IS_CHAN_HTG(c))
416 return IEEE80211_MODE_11NG;
417 if (IEEE80211_IS_CHAN_108A(c))
418 return IEEE80211_MODE_TURBO_A;
419 if (IEEE80211_IS_CHAN_108G(c))
420 return IEEE80211_MODE_TURBO_G;
421 if (IEEE80211_IS_CHAN_ST(c))
422 return IEEE80211_MODE_STURBO_A;
423 if (IEEE80211_IS_CHAN_FHSS(c))
424 return IEEE80211_MODE_FH;
425 if (IEEE80211_IS_CHAN_HALF(c))
426 return IEEE80211_MODE_HALF;
427 if (IEEE80211_IS_CHAN_QUARTER(c))
428 return IEEE80211_MODE_QUARTER;
429 if (IEEE80211_IS_CHAN_A(c))
430 return IEEE80211_MODE_11A;
431 if (IEEE80211_IS_CHAN_ANYG(c))
432 return IEEE80211_MODE_11G;
433 if (IEEE80211_IS_CHAN_B(c))
434 return IEEE80211_MODE_11B;
435 return IEEE80211_MODE_AUTO;
443 if (get80211(s, IEEE80211_IOC_ROAM,
444 &roamparams, sizeof(roamparams)) < 0)
445 err(1, "unable to get roaming parameters");
450 setroam_cb(int s, void *arg)
452 struct ieee80211_roamparams_req *roam = arg;
453 set80211(s, IEEE80211_IOC_ROAM, 0, sizeof(*roam), roam);
461 if (get80211(s, IEEE80211_IOC_TXPARAMS,
462 &txparams, sizeof(txparams)) < 0)
463 err(1, "unable to get transmit parameters");
468 settxparams_cb(int s, void *arg)
470 struct ieee80211_txparams_req *txp = arg;
471 set80211(s, IEEE80211_IOC_TXPARAMS, 0, sizeof(*txp), txp);
479 if (get80211(s, IEEE80211_IOC_REGDOMAIN,
480 ®domain, sizeof(regdomain)) < 0)
481 err(1, "unable to get regulatory domain info");
486 getdevcaps(int s, struct ieee80211_devcaps_req *dc)
488 if (get80211(s, IEEE80211_IOC_DEVCAPS, dc,
489 IEEE80211_DEVCAPS_SPACE(dc)) < 0)
490 err(1, "unable to get device capabilities");
494 setregdomain_cb(int s, void *arg)
496 struct ieee80211_regdomain_req *req;
497 struct ieee80211_regdomain *rd = arg;
498 struct ieee80211_devcaps_req *dc;
499 struct regdata *rdp = getregdata();
501 if (rd->country != NO_COUNTRY) {
502 const struct country *cc;
504 * Check current country seting to make sure it's
505 * compatible with the new regdomain. If not, then
506 * override it with any default country for this
507 * SKU. If we cannot arrange a match, then abort.
509 cc = lib80211_country_findbycc(rdp, rd->country);
511 errx(1, "unknown ISO country code %d", rd->country);
512 if (cc->rd->sku != rd->regdomain) {
513 const struct regdomain *rp;
515 * Check if country is incompatible with regdomain.
516 * To enable multiple regdomains for a country code
517 * we permit a mismatch between the regdomain and
518 * the country's associated regdomain when the
519 * regdomain is setup w/o a default country. For
520 * example, US is bound to the FCC regdomain but
521 * we allow US to be combined with FCC3 because FCC3
522 * has not default country. This allows bogus
523 * combinations like FCC3+DK which are resolved when
524 * constructing the channel list by deferring to the
525 * regdomain to construct the channel list.
527 rp = lib80211_regdomain_findbysku(rdp, rd->regdomain);
529 errx(1, "country %s (%s) is not usable with "
530 "regdomain %d", cc->isoname, cc->name,
532 else if (rp->cc != NULL && rp->cc != cc)
533 errx(1, "country %s (%s) is not usable with "
534 "regdomain %s", cc->isoname, cc->name,
539 * Fetch the device capabilities and calculate the
540 * full set of netbands for which we request a new
541 * channel list be constructed. Once that's done we
542 * push the regdomain info + channel list to the kernel.
544 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
546 errx(1, "no space for device capabilities");
547 dc->dc_chaninfo.ic_nchans = MAXCHAN;
551 printf("drivercaps: 0x%x\n", dc->dc_drivercaps);
552 printf("cryptocaps: 0x%x\n", dc->dc_cryptocaps);
553 printf("htcaps : 0x%x\n", dc->dc_htcaps);
554 printf("vhtcaps : 0x%x\n", dc->dc_vhtcaps);
556 memcpy(chaninfo, &dc->dc_chaninfo,
557 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
558 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, 1/*verbose*/);
562 req = malloc(IEEE80211_REGDOMAIN_SIZE(dc->dc_chaninfo.ic_nchans));
564 errx(1, "no space for regdomain request");
566 regdomain_makechannels(req, dc);
569 print_regdomain(rd, 1/*verbose*/);
571 /* blech, reallocate channel list for new data */
572 if (chaninfo != NULL)
574 chaninfo = malloc(IEEE80211_CHANINFO_SPACE(&req->chaninfo));
575 if (chaninfo == NULL)
576 errx(1, "no space for channel list");
577 memcpy(chaninfo, &req->chaninfo,
578 IEEE80211_CHANINFO_SPACE(&req->chaninfo));
579 print_channels(s, &req->chaninfo, 1/*allchans*/, 1/*verbose*/);
581 if (req->chaninfo.ic_nchans == 0)
582 errx(1, "no channels calculated");
583 set80211(s, IEEE80211_IOC_REGDOMAIN, 0,
584 IEEE80211_REGDOMAIN_SPACE(req), req);
590 ieee80211_mhz2ieee(int freq, int flags)
592 struct ieee80211_channel chan;
593 mapfreq(&chan, freq, flags);
598 isanyarg(const char *arg)
600 return (strncmp(arg, "-", 1) == 0 ||
601 strncasecmp(arg, "any", 3) == 0 || strncasecmp(arg, "off", 3) == 0);
605 set80211ssid(const char *val, int d, int s, const struct afswtch *rafp)
609 u_int8_t data[IEEE80211_NWID_LEN];
613 if (len > 2 && isdigit((int)val[0]) && val[1] == ':') {
618 bzero(data, sizeof(data));
620 if (get_string(val, NULL, data, &len) == NULL)
623 set80211(s, IEEE80211_IOC_SSID, ssid, len, data);
627 set80211meshid(const char *val, int d, int s, const struct afswtch *rafp)
630 u_int8_t data[IEEE80211_NWID_LEN];
632 memset(data, 0, sizeof(data));
634 if (get_string(val, NULL, data, &len) == NULL)
637 set80211(s, IEEE80211_IOC_MESH_ID, 0, len, data);
641 set80211stationname(const char *val, int d, int s, const struct afswtch *rafp)
646 bzero(data, sizeof(data));
648 get_string(val, NULL, data, &len);
650 set80211(s, IEEE80211_IOC_STATIONNAME, 0, len, data);
654 * Parse a channel specification for attributes/flags.
656 * freq/xx channel width (5,10,20,40,40+,40-)
657 * freq:mode channel mode (a,b,g,h,n,t,s,d)
659 * These can be combined in either order; e.g. 2437:ng/40.
660 * Modes are case insensitive.
662 * The result is not validated here; it's assumed to be
663 * checked against the channel table fetched from the kernel.
666 getchannelflags(const char *val, int freq)
668 #define _CHAN_HT 0x80000000
675 cp = strchr(val, ':');
677 for (cp++; isalpha((int) *cp); cp++) {
678 /* accept mixed case */
683 case 'a': /* 802.11a */
684 flags |= IEEE80211_CHAN_A;
686 case 'b': /* 802.11b */
687 flags |= IEEE80211_CHAN_B;
689 case 'g': /* 802.11g */
690 flags |= IEEE80211_CHAN_G;
692 case 'v': /* vht: 802.11ac */
695 case 'h': /* ht = 802.11n */
696 case 'n': /* 802.11n */
697 flags |= _CHAN_HT; /* NB: private */
699 case 'd': /* dt = Atheros Dynamic Turbo */
700 flags |= IEEE80211_CHAN_TURBO;
702 case 't': /* ht, dt, st, t */
703 /* dt and unadorned t specify Dynamic Turbo */
704 if ((flags & (IEEE80211_CHAN_STURBO|_CHAN_HT)) == 0)
705 flags |= IEEE80211_CHAN_TURBO;
707 case 's': /* st = Atheros Static Turbo */
708 flags |= IEEE80211_CHAN_STURBO;
711 errx(-1, "%s: Invalid channel attribute %c\n",
716 cp = strchr(val, '/');
719 u_long cw = strtoul(cp+1, &ep, 10);
723 flags |= IEEE80211_CHAN_QUARTER;
726 flags |= IEEE80211_CHAN_HALF;
729 /* NB: this may be removed below */
730 flags |= IEEE80211_CHAN_HT20;
735 /* Handle the 80/160 VHT flag */
737 flags |= IEEE80211_CHAN_VHT80;
739 flags |= IEEE80211_CHAN_VHT160;
742 if (ep != NULL && *ep == '+')
743 flags |= IEEE80211_CHAN_HT40U;
744 else if (ep != NULL && *ep == '-')
745 flags |= IEEE80211_CHAN_HT40D;
748 errx(-1, "%s: Invalid channel width\n", val);
753 * Cleanup specifications.
755 if ((flags & _CHAN_HT) == 0) {
757 * If user specified freq/20 or freq/40 quietly remove
758 * HT cw attributes depending on channel use. To give
759 * an explicit 20/40 width for an HT channel you must
760 * indicate it is an HT channel since all HT channels
761 * are also usable for legacy operation; e.g. freq:n/40.
763 flags &= ~IEEE80211_CHAN_HT;
764 flags &= ~IEEE80211_CHAN_VHT;
767 * Remove private indicator that this is an HT channel
768 * and if no explicit channel width has been given
769 * provide the default settings.
772 if ((flags & IEEE80211_CHAN_HT) == 0) {
773 struct ieee80211_channel chan;
775 * Consult the channel list to see if we can use
776 * HT40+ or HT40- (if both the map routines choose).
779 mapfreq(&chan, freq, 0);
781 mapchan(&chan, freq, 0);
782 flags |= (chan.ic_flags & IEEE80211_CHAN_HT);
786 * If VHT is enabled, then also set the VHT flag and the
787 * relevant channel up/down.
789 if (is_vht && (flags & IEEE80211_CHAN_HT)) {
791 * XXX yes, maybe we should just have VHT, and reuse
794 if (flags & IEEE80211_CHAN_VHT80)
796 else if (flags & IEEE80211_CHAN_HT20)
797 flags |= IEEE80211_CHAN_VHT20;
798 else if (flags & IEEE80211_CHAN_HT40U)
799 flags |= IEEE80211_CHAN_VHT40U;
800 else if (flags & IEEE80211_CHAN_HT40D)
801 flags |= IEEE80211_CHAN_VHT40D;
809 getchannel(int s, struct ieee80211_channel *chan, const char *val)
814 memset(chan, 0, sizeof(*chan));
816 chan->ic_freq = IEEE80211_CHAN_ANY;
821 v = strtol(val, &eptr, 10);
822 if (val[0] == '\0' || val == eptr || errno == ERANGE ||
823 /* channel may be suffixed with nothing, :flag, or /width */
824 (eptr[0] != '\0' && eptr[0] != ':' && eptr[0] != '/'))
825 errx(1, "invalid channel specification%s",
826 errno == ERANGE ? " (out of range)" : "");
827 flags = getchannelflags(val, v);
828 if (v > 255) { /* treat as frequency */
829 mapfreq(chan, v, flags);
831 mapchan(chan, v, flags);
836 set80211channel(const char *val, int d, int s, const struct afswtch *rafp)
838 struct ieee80211_channel chan;
840 getchannel(s, &chan, val);
841 set80211(s, IEEE80211_IOC_CURCHAN, 0, sizeof(chan), &chan);
845 set80211chanswitch(const char *val, int d, int s, const struct afswtch *rafp)
847 struct ieee80211_chanswitch_req csr;
849 getchannel(s, &csr.csa_chan, val);
852 set80211(s, IEEE80211_IOC_CHANSWITCH, 0, sizeof(csr), &csr);
856 set80211authmode(const char *val, int d, int s, const struct afswtch *rafp)
860 if (strcasecmp(val, "none") == 0) {
861 mode = IEEE80211_AUTH_NONE;
862 } else if (strcasecmp(val, "open") == 0) {
863 mode = IEEE80211_AUTH_OPEN;
864 } else if (strcasecmp(val, "shared") == 0) {
865 mode = IEEE80211_AUTH_SHARED;
866 } else if (strcasecmp(val, "8021x") == 0) {
867 mode = IEEE80211_AUTH_8021X;
868 } else if (strcasecmp(val, "wpa") == 0) {
869 mode = IEEE80211_AUTH_WPA;
871 errx(1, "unknown authmode");
874 set80211(s, IEEE80211_IOC_AUTHMODE, mode, 0, NULL);
878 set80211powersavemode(const char *val, int d, int s, const struct afswtch *rafp)
882 if (strcasecmp(val, "off") == 0) {
883 mode = IEEE80211_POWERSAVE_OFF;
884 } else if (strcasecmp(val, "on") == 0) {
885 mode = IEEE80211_POWERSAVE_ON;
886 } else if (strcasecmp(val, "cam") == 0) {
887 mode = IEEE80211_POWERSAVE_CAM;
888 } else if (strcasecmp(val, "psp") == 0) {
889 mode = IEEE80211_POWERSAVE_PSP;
890 } else if (strcasecmp(val, "psp-cam") == 0) {
891 mode = IEEE80211_POWERSAVE_PSP_CAM;
893 errx(1, "unknown powersavemode");
896 set80211(s, IEEE80211_IOC_POWERSAVE, mode, 0, NULL);
900 set80211powersave(const char *val, int d, int s, const struct afswtch *rafp)
903 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_OFF,
906 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_ON,
911 set80211powersavesleep(const char *val, int d, int s, const struct afswtch *rafp)
913 set80211(s, IEEE80211_IOC_POWERSAVESLEEP, atoi(val), 0, NULL);
917 set80211wepmode(const char *val, int d, int s, const struct afswtch *rafp)
921 if (strcasecmp(val, "off") == 0) {
922 mode = IEEE80211_WEP_OFF;
923 } else if (strcasecmp(val, "on") == 0) {
924 mode = IEEE80211_WEP_ON;
925 } else if (strcasecmp(val, "mixed") == 0) {
926 mode = IEEE80211_WEP_MIXED;
928 errx(1, "unknown wep mode");
931 set80211(s, IEEE80211_IOC_WEP, mode, 0, NULL);
935 set80211wep(const char *val, int d, int s, const struct afswtch *rafp)
937 set80211(s, IEEE80211_IOC_WEP, d, 0, NULL);
941 isundefarg(const char *arg)
943 return (strcmp(arg, "-") == 0 || strncasecmp(arg, "undef", 5) == 0);
947 set80211weptxkey(const char *val, int d, int s, const struct afswtch *rafp)
950 set80211(s, IEEE80211_IOC_WEPTXKEY, IEEE80211_KEYIX_NONE, 0, NULL);
952 set80211(s, IEEE80211_IOC_WEPTXKEY, atoi(val)-1, 0, NULL);
956 set80211wepkey(const char *val, int d, int s, const struct afswtch *rafp)
960 u_int8_t data[IEEE80211_KEYBUF_SIZE];
962 if (isdigit((int)val[0]) && val[1] == ':') {
967 bzero(data, sizeof(data));
969 get_string(val, NULL, data, &len);
971 set80211(s, IEEE80211_IOC_WEPKEY, key, len, data);
975 * This function is purely a NetBSD compatibility interface. The NetBSD
976 * interface is too inflexible, but it's there so we'll support it since
977 * it's not all that hard.
980 set80211nwkey(const char *val, int d, int s, const struct afswtch *rafp)
984 u_int8_t data[IEEE80211_KEYBUF_SIZE];
986 set80211(s, IEEE80211_IOC_WEP, IEEE80211_WEP_ON, 0, NULL);
988 if (isdigit((int)val[0]) && val[1] == ':') {
989 txkey = val[0]-'0'-1;
992 for (i = 0; i < 4; i++) {
993 bzero(data, sizeof(data));
995 val = get_string(val, ",", data, &len);
999 set80211(s, IEEE80211_IOC_WEPKEY, i, len, data);
1002 bzero(data, sizeof(data));
1004 get_string(val, NULL, data, &len);
1007 set80211(s, IEEE80211_IOC_WEPKEY, 0, len, data);
1009 bzero(data, sizeof(data));
1010 for (i = 1; i < 4; i++)
1011 set80211(s, IEEE80211_IOC_WEPKEY, i, 0, data);
1014 set80211(s, IEEE80211_IOC_WEPTXKEY, txkey, 0, NULL);
1018 set80211rtsthreshold(const char *val, int d, int s, const struct afswtch *rafp)
1020 set80211(s, IEEE80211_IOC_RTSTHRESHOLD,
1021 isundefarg(val) ? IEEE80211_RTS_MAX : atoi(val), 0, NULL);
1025 set80211protmode(const char *val, int d, int s, const struct afswtch *rafp)
1029 if (strcasecmp(val, "off") == 0) {
1030 mode = IEEE80211_PROTMODE_OFF;
1031 } else if (strcasecmp(val, "cts") == 0) {
1032 mode = IEEE80211_PROTMODE_CTS;
1033 } else if (strncasecmp(val, "rtscts", 3) == 0) {
1034 mode = IEEE80211_PROTMODE_RTSCTS;
1036 errx(1, "unknown protection mode");
1039 set80211(s, IEEE80211_IOC_PROTMODE, mode, 0, NULL);
1043 set80211htprotmode(const char *val, int d, int s, const struct afswtch *rafp)
1047 if (strcasecmp(val, "off") == 0) {
1048 mode = IEEE80211_PROTMODE_OFF;
1049 } else if (strncasecmp(val, "rts", 3) == 0) {
1050 mode = IEEE80211_PROTMODE_RTSCTS;
1052 errx(1, "unknown protection mode");
1055 set80211(s, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL);
1059 set80211txpower(const char *val, int d, int s, const struct afswtch *rafp)
1061 double v = atof(val);
1064 txpow = (int) (2*v);
1066 errx(-1, "invalid tx power (must be .5 dBm units)");
1067 set80211(s, IEEE80211_IOC_TXPOWER, txpow, 0, NULL);
1070 #define IEEE80211_ROAMING_DEVICE 0
1071 #define IEEE80211_ROAMING_AUTO 1
1072 #define IEEE80211_ROAMING_MANUAL 2
1075 set80211roaming(const char *val, int d, int s, const struct afswtch *rafp)
1079 if (strcasecmp(val, "device") == 0) {
1080 mode = IEEE80211_ROAMING_DEVICE;
1081 } else if (strcasecmp(val, "auto") == 0) {
1082 mode = IEEE80211_ROAMING_AUTO;
1083 } else if (strcasecmp(val, "manual") == 0) {
1084 mode = IEEE80211_ROAMING_MANUAL;
1086 errx(1, "unknown roaming mode");
1088 set80211(s, IEEE80211_IOC_ROAMING, mode, 0, NULL);
1092 set80211wme(const char *val, int d, int s, const struct afswtch *rafp)
1094 set80211(s, IEEE80211_IOC_WME, d, 0, NULL);
1098 set80211hidessid(const char *val, int d, int s, const struct afswtch *rafp)
1100 set80211(s, IEEE80211_IOC_HIDESSID, d, 0, NULL);
1104 set80211apbridge(const char *val, int d, int s, const struct afswtch *rafp)
1106 set80211(s, IEEE80211_IOC_APBRIDGE, d, 0, NULL);
1110 set80211fastframes(const char *val, int d, int s, const struct afswtch *rafp)
1112 set80211(s, IEEE80211_IOC_FF, d, 0, NULL);
1116 set80211dturbo(const char *val, int d, int s, const struct afswtch *rafp)
1118 set80211(s, IEEE80211_IOC_TURBOP, d, 0, NULL);
1122 set80211chanlist(const char *val, int d, int s, const struct afswtch *rafp)
1124 struct ieee80211req_chanlist chanlist;
1125 char *temp, *cp, *tp;
1127 temp = malloc(strlen(val) + 1);
1129 errx(1, "malloc failed");
1131 memset(&chanlist, 0, sizeof(chanlist));
1134 int first, last, f, c;
1136 tp = strchr(cp, ',');
1139 switch (sscanf(cp, "%u-%u", &first, &last)) {
1141 if (first > IEEE80211_CHAN_MAX)
1142 errx(-1, "channel %u out of range, max %u",
1143 first, IEEE80211_CHAN_MAX);
1144 setbit(chanlist.ic_channels, first);
1147 if (first > IEEE80211_CHAN_MAX)
1148 errx(-1, "channel %u out of range, max %u",
1149 first, IEEE80211_CHAN_MAX);
1150 if (last > IEEE80211_CHAN_MAX)
1151 errx(-1, "channel %u out of range, max %u",
1152 last, IEEE80211_CHAN_MAX);
1154 errx(-1, "void channel range, %u > %u",
1156 for (f = first; f <= last; f++)
1157 setbit(chanlist.ic_channels, f);
1169 set80211(s, IEEE80211_IOC_CHANLIST, 0, sizeof(chanlist), &chanlist);
1174 set80211bssid(const char *val, int d, int s, const struct afswtch *rafp)
1177 if (!isanyarg(val)) {
1179 struct sockaddr_dl sdl;
1181 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1183 errx(1, "malloc failed");
1185 strcpy(temp + 1, val);
1186 sdl.sdl_len = sizeof(sdl);
1187 link_addr(temp, &sdl);
1189 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1190 errx(1, "malformed link-level address");
1191 set80211(s, IEEE80211_IOC_BSSID, 0,
1192 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1194 uint8_t zerobssid[IEEE80211_ADDR_LEN];
1195 memset(zerobssid, 0, sizeof(zerobssid));
1196 set80211(s, IEEE80211_IOC_BSSID, 0,
1197 IEEE80211_ADDR_LEN, zerobssid);
1202 getac(const char *ac)
1204 if (strcasecmp(ac, "ac_be") == 0 || strcasecmp(ac, "be") == 0)
1206 if (strcasecmp(ac, "ac_bk") == 0 || strcasecmp(ac, "bk") == 0)
1208 if (strcasecmp(ac, "ac_vi") == 0 || strcasecmp(ac, "vi") == 0)
1210 if (strcasecmp(ac, "ac_vo") == 0 || strcasecmp(ac, "vo") == 0)
1212 errx(1, "unknown wme access class %s", ac);
1216 DECL_CMD_FUNC2(set80211cwmin, ac, val)
1218 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac), NULL);
1222 DECL_CMD_FUNC2(set80211cwmax, ac, val)
1224 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac), NULL);
1228 DECL_CMD_FUNC2(set80211aifs, ac, val)
1230 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac), NULL);
1234 DECL_CMD_FUNC2(set80211txoplimit, ac, val)
1236 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac), NULL);
1240 DECL_CMD_FUNC(set80211acm, ac, d)
1242 set80211(s, IEEE80211_IOC_WME_ACM, 1, getac(ac), NULL);
1245 DECL_CMD_FUNC(set80211noacm, ac, d)
1247 set80211(s, IEEE80211_IOC_WME_ACM, 0, getac(ac), NULL);
1251 DECL_CMD_FUNC(set80211ackpolicy, ac, d)
1253 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 1, getac(ac), NULL);
1256 DECL_CMD_FUNC(set80211noackpolicy, ac, d)
1258 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 0, getac(ac), NULL);
1262 DECL_CMD_FUNC2(set80211bsscwmin, ac, val)
1264 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val),
1265 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1269 DECL_CMD_FUNC2(set80211bsscwmax, ac, val)
1271 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val),
1272 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1276 DECL_CMD_FUNC2(set80211bssaifs, ac, val)
1278 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val),
1279 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1283 DECL_CMD_FUNC2(set80211bsstxoplimit, ac, val)
1285 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val),
1286 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1290 DECL_CMD_FUNC(set80211dtimperiod, val, d)
1292 set80211(s, IEEE80211_IOC_DTIM_PERIOD, atoi(val), 0, NULL);
1296 DECL_CMD_FUNC(set80211bintval, val, d)
1298 set80211(s, IEEE80211_IOC_BEACON_INTERVAL, atoi(val), 0, NULL);
1302 set80211macmac(int s, int op, const char *val)
1305 struct sockaddr_dl sdl;
1307 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1309 errx(1, "malloc failed");
1311 strcpy(temp + 1, val);
1312 sdl.sdl_len = sizeof(sdl);
1313 link_addr(temp, &sdl);
1315 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1316 errx(1, "malformed link-level address");
1317 set80211(s, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl));
1321 DECL_CMD_FUNC(set80211addmac, val, d)
1323 set80211macmac(s, IEEE80211_IOC_ADDMAC, val);
1327 DECL_CMD_FUNC(set80211delmac, val, d)
1329 set80211macmac(s, IEEE80211_IOC_DELMAC, val);
1333 DECL_CMD_FUNC(set80211kickmac, val, d)
1336 struct sockaddr_dl sdl;
1337 struct ieee80211req_mlme mlme;
1339 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1341 errx(1, "malloc failed");
1343 strcpy(temp + 1, val);
1344 sdl.sdl_len = sizeof(sdl);
1345 link_addr(temp, &sdl);
1347 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1348 errx(1, "malformed link-level address");
1349 memset(&mlme, 0, sizeof(mlme));
1350 mlme.im_op = IEEE80211_MLME_DEAUTH;
1351 mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE;
1352 memcpy(mlme.im_macaddr, LLADDR(&sdl), IEEE80211_ADDR_LEN);
1353 set80211(s, IEEE80211_IOC_MLME, 0, sizeof(mlme), &mlme);
1357 DECL_CMD_FUNC(set80211maccmd, val, d)
1359 set80211(s, IEEE80211_IOC_MACCMD, d, 0, NULL);
1363 set80211meshrtmac(int s, int req, const char *val)
1366 struct sockaddr_dl sdl;
1368 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1370 errx(1, "malloc failed");
1372 strcpy(temp + 1, val);
1373 sdl.sdl_len = sizeof(sdl);
1374 link_addr(temp, &sdl);
1376 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1377 errx(1, "malformed link-level address");
1378 set80211(s, IEEE80211_IOC_MESH_RTCMD, req,
1379 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1383 DECL_CMD_FUNC(set80211addmeshrt, val, d)
1385 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_ADD, val);
1389 DECL_CMD_FUNC(set80211delmeshrt, val, d)
1391 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_DELETE, val);
1395 DECL_CMD_FUNC(set80211meshrtcmd, val, d)
1397 set80211(s, IEEE80211_IOC_MESH_RTCMD, d, 0, NULL);
1401 DECL_CMD_FUNC(set80211hwmprootmode, val, d)
1405 if (strcasecmp(val, "normal") == 0)
1406 mode = IEEE80211_HWMP_ROOTMODE_NORMAL;
1407 else if (strcasecmp(val, "proactive") == 0)
1408 mode = IEEE80211_HWMP_ROOTMODE_PROACTIVE;
1409 else if (strcasecmp(val, "rann") == 0)
1410 mode = IEEE80211_HWMP_ROOTMODE_RANN;
1412 mode = IEEE80211_HWMP_ROOTMODE_DISABLED;
1413 set80211(s, IEEE80211_IOC_HWMP_ROOTMODE, mode, 0, NULL);
1417 DECL_CMD_FUNC(set80211hwmpmaxhops, val, d)
1419 set80211(s, IEEE80211_IOC_HWMP_MAXHOPS, atoi(val), 0, NULL);
1423 set80211pureg(const char *val, int d, int s, const struct afswtch *rafp)
1425 set80211(s, IEEE80211_IOC_PUREG, d, 0, NULL);
1429 set80211quiet(const char *val, int d, int s, const struct afswtch *rafp)
1431 set80211(s, IEEE80211_IOC_QUIET, d, 0, NULL);
1435 DECL_CMD_FUNC(set80211quietperiod, val, d)
1437 set80211(s, IEEE80211_IOC_QUIET_PERIOD, atoi(val), 0, NULL);
1441 DECL_CMD_FUNC(set80211quietcount, val, d)
1443 set80211(s, IEEE80211_IOC_QUIET_COUNT, atoi(val), 0, NULL);
1447 DECL_CMD_FUNC(set80211quietduration, val, d)
1449 set80211(s, IEEE80211_IOC_QUIET_DUR, atoi(val), 0, NULL);
1453 DECL_CMD_FUNC(set80211quietoffset, val, d)
1455 set80211(s, IEEE80211_IOC_QUIET_OFFSET, atoi(val), 0, NULL);
1459 set80211bgscan(const char *val, int d, int s, const struct afswtch *rafp)
1461 set80211(s, IEEE80211_IOC_BGSCAN, d, 0, NULL);
1465 DECL_CMD_FUNC(set80211bgscanidle, val, d)
1467 set80211(s, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL);
1471 DECL_CMD_FUNC(set80211bgscanintvl, val, d)
1473 set80211(s, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL);
1477 DECL_CMD_FUNC(set80211scanvalid, val, d)
1479 set80211(s, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL);
1483 * Parse an optional trailing specification of which netbands
1484 * to apply a parameter to. This is basically the same syntax
1485 * as used for channels but you can concatenate to specify
1486 * multiple. For example:
1487 * 14:abg apply to 11a, 11b, and 11g
1488 * 6:ht apply to 11na and 11ng
1489 * We don't make a big effort to catch silly things; this is
1490 * really a convenience mechanism.
1493 getmodeflags(const char *val)
1500 cp = strchr(val, ':');
1502 for (cp++; isalpha((int) *cp); cp++) {
1503 /* accept mixed case */
1508 case 'a': /* 802.11a */
1509 flags |= IEEE80211_CHAN_A;
1511 case 'b': /* 802.11b */
1512 flags |= IEEE80211_CHAN_B;
1514 case 'g': /* 802.11g */
1515 flags |= IEEE80211_CHAN_G;
1517 case 'n': /* 802.11n */
1518 flags |= IEEE80211_CHAN_HT;
1520 case 'd': /* dt = Atheros Dynamic Turbo */
1521 flags |= IEEE80211_CHAN_TURBO;
1523 case 't': /* ht, dt, st, t */
1524 /* dt and unadorned t specify Dynamic Turbo */
1525 if ((flags & (IEEE80211_CHAN_STURBO|IEEE80211_CHAN_HT)) == 0)
1526 flags |= IEEE80211_CHAN_TURBO;
1528 case 's': /* st = Atheros Static Turbo */
1529 flags |= IEEE80211_CHAN_STURBO;
1531 case 'h': /* 1/2-width channels */
1532 flags |= IEEE80211_CHAN_HALF;
1534 case 'q': /* 1/4-width channels */
1535 flags |= IEEE80211_CHAN_QUARTER;
1538 /* XXX set HT too? */
1539 flags |= IEEE80211_CHAN_VHT;
1542 errx(-1, "%s: Invalid mode attribute %c\n",
1550 #define _APPLY(_flags, _base, _param, _v) do { \
1551 if (_flags & IEEE80211_CHAN_HT) { \
1552 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1553 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1554 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1555 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1556 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1558 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1560 if (_flags & IEEE80211_CHAN_TURBO) { \
1561 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1562 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1563 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1564 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1565 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1567 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1569 if (_flags & IEEE80211_CHAN_STURBO) \
1570 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1571 if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1572 _base.params[IEEE80211_MODE_11A]._param = _v; \
1573 if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1574 _base.params[IEEE80211_MODE_11G]._param = _v; \
1575 if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1576 _base.params[IEEE80211_MODE_11B]._param = _v; \
1577 if (_flags & IEEE80211_CHAN_HALF) \
1578 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1579 if (_flags & IEEE80211_CHAN_QUARTER) \
1580 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1582 #define _APPLY1(_flags, _base, _param, _v) do { \
1583 if (_flags & IEEE80211_CHAN_HT) { \
1584 if (_flags & IEEE80211_CHAN_5GHZ) \
1585 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1587 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1588 } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \
1589 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1590 else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \
1591 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1592 else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \
1593 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1594 else if (_flags & IEEE80211_CHAN_HALF) \
1595 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1596 else if (_flags & IEEE80211_CHAN_QUARTER) \
1597 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1598 else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1599 _base.params[IEEE80211_MODE_11A]._param = _v; \
1600 else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1601 _base.params[IEEE80211_MODE_11G]._param = _v; \
1602 else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1603 _base.params[IEEE80211_MODE_11B]._param = _v; \
1605 #define _APPLY_RATE(_flags, _base, _param, _v) do { \
1606 if (_flags & IEEE80211_CHAN_HT) { \
1607 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1609 _APPLY(_flags, _base, _param, _v); \
1611 #define _APPLY_RATE1(_flags, _base, _param, _v) do { \
1612 if (_flags & IEEE80211_CHAN_HT) { \
1613 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1615 _APPLY1(_flags, _base, _param, _v); \
1619 DECL_CMD_FUNC(set80211roamrssi, val, d)
1621 double v = atof(val);
1626 errx(-1, "invalid rssi (must be .5 dBm units)");
1627 flags = getmodeflags(val);
1629 if (flags == 0) { /* NB: no flags => current channel */
1630 flags = getcurchan(s)->ic_flags;
1631 _APPLY1(flags, roamparams, rssi, rssi);
1633 _APPLY(flags, roamparams, rssi, rssi);
1634 callback_register(setroam_cb, &roamparams);
1638 getrate(const char *val, const char *tag)
1640 double v = atof(val);
1645 errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag);
1646 return rate; /* NB: returns 2x the specified value */
1650 DECL_CMD_FUNC(set80211roamrate, val, d)
1654 rate = getrate(val, "roam");
1655 flags = getmodeflags(val);
1657 if (flags == 0) { /* NB: no flags => current channel */
1658 flags = getcurchan(s)->ic_flags;
1659 _APPLY_RATE1(flags, roamparams, rate, rate);
1661 _APPLY_RATE(flags, roamparams, rate, rate);
1662 callback_register(setroam_cb, &roamparams);
1666 DECL_CMD_FUNC(set80211mcastrate, val, d)
1670 rate = getrate(val, "mcast");
1671 flags = getmodeflags(val);
1673 if (flags == 0) { /* NB: no flags => current channel */
1674 flags = getcurchan(s)->ic_flags;
1675 _APPLY_RATE1(flags, txparams, mcastrate, rate);
1677 _APPLY_RATE(flags, txparams, mcastrate, rate);
1678 callback_register(settxparams_cb, &txparams);
1682 DECL_CMD_FUNC(set80211mgtrate, val, d)
1686 rate = getrate(val, "mgmt");
1687 flags = getmodeflags(val);
1689 if (flags == 0) { /* NB: no flags => current channel */
1690 flags = getcurchan(s)->ic_flags;
1691 _APPLY_RATE1(flags, txparams, mgmtrate, rate);
1693 _APPLY_RATE(flags, txparams, mgmtrate, rate);
1694 callback_register(settxparams_cb, &txparams);
1698 DECL_CMD_FUNC(set80211ucastrate, val, d)
1703 flags = getmodeflags(val);
1704 if (isanyarg(val)) {
1705 if (flags == 0) { /* NB: no flags => current channel */
1706 flags = getcurchan(s)->ic_flags;
1707 _APPLY1(flags, txparams, ucastrate,
1708 IEEE80211_FIXED_RATE_NONE);
1710 _APPLY(flags, txparams, ucastrate,
1711 IEEE80211_FIXED_RATE_NONE);
1713 int rate = getrate(val, "ucast");
1714 if (flags == 0) { /* NB: no flags => current channel */
1715 flags = getcurchan(s)->ic_flags;
1716 _APPLY_RATE1(flags, txparams, ucastrate, rate);
1718 _APPLY_RATE(flags, txparams, ucastrate, rate);
1720 callback_register(settxparams_cb, &txparams);
1724 DECL_CMD_FUNC(set80211maxretry, val, d)
1726 int v = atoi(val), flags;
1728 flags = getmodeflags(val);
1730 if (flags == 0) { /* NB: no flags => current channel */
1731 flags = getcurchan(s)->ic_flags;
1732 _APPLY1(flags, txparams, maxretry, v);
1734 _APPLY(flags, txparams, maxretry, v);
1735 callback_register(settxparams_cb, &txparams);
1741 DECL_CMD_FUNC(set80211fragthreshold, val, d)
1743 set80211(s, IEEE80211_IOC_FRAGTHRESHOLD,
1744 isundefarg(val) ? IEEE80211_FRAG_MAX : atoi(val), 0, NULL);
1748 DECL_CMD_FUNC(set80211bmissthreshold, val, d)
1750 set80211(s, IEEE80211_IOC_BMISSTHRESHOLD,
1751 isundefarg(val) ? IEEE80211_HWBMISS_MAX : atoi(val), 0, NULL);
1755 set80211burst(const char *val, int d, int s, const struct afswtch *rafp)
1757 set80211(s, IEEE80211_IOC_BURST, d, 0, NULL);
1761 set80211doth(const char *val, int d, int s, const struct afswtch *rafp)
1763 set80211(s, IEEE80211_IOC_DOTH, d, 0, NULL);
1767 set80211dfs(const char *val, int d, int s, const struct afswtch *rafp)
1769 set80211(s, IEEE80211_IOC_DFS, d, 0, NULL);
1773 set80211shortgi(const char *val, int d, int s, const struct afswtch *rafp)
1775 set80211(s, IEEE80211_IOC_SHORTGI,
1776 d ? (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) : 0,
1780 /* XXX 11ac density/size is different */
1782 set80211ampdu(const char *val, int d, int s, const struct afswtch *rafp)
1786 if (get80211val(s, IEEE80211_IOC_AMPDU, &du) < 0)
1787 errx(-1, "cannot set AMPDU setting");
1793 set80211(s, IEEE80211_IOC_AMPDU, ampdu, 0, NULL);
1797 set80211stbc(const char *val, int d, int s, const struct afswtch *rafp)
1801 if (get80211val(s, IEEE80211_IOC_STBC, &stbc) < 0)
1802 errx(-1, "cannot set STBC setting");
1808 set80211(s, IEEE80211_IOC_STBC, stbc, 0, NULL);
1812 set80211ldpc(const char *val, int d, int s, const struct afswtch *rafp)
1816 if (get80211val(s, IEEE80211_IOC_LDPC, &ldpc) < 0)
1817 errx(-1, "cannot set LDPC setting");
1823 set80211(s, IEEE80211_IOC_LDPC, ldpc, 0, NULL);
1827 set80211uapsd(const char *val, int d, int s, const struct afswtch *rafp)
1829 set80211(s, IEEE80211_IOC_UAPSD, d, 0, NULL);
1833 DECL_CMD_FUNC(set80211ampdulimit, val, d)
1837 switch (atoi(val)) {
1840 v = IEEE80211_HTCAP_MAXRXAMPDU_8K;
1844 v = IEEE80211_HTCAP_MAXRXAMPDU_16K;
1848 v = IEEE80211_HTCAP_MAXRXAMPDU_32K;
1852 v = IEEE80211_HTCAP_MAXRXAMPDU_64K;
1855 errx(-1, "invalid A-MPDU limit %s", val);
1857 set80211(s, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL);
1860 /* XXX 11ac density/size is different */
1862 DECL_CMD_FUNC(set80211ampdudensity, val, d)
1866 if (isanyarg(val) || strcasecmp(val, "na") == 0)
1867 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1868 else switch ((int)(atof(val)*4)) {
1870 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1873 v = IEEE80211_HTCAP_MPDUDENSITY_025;
1876 v = IEEE80211_HTCAP_MPDUDENSITY_05;
1879 v = IEEE80211_HTCAP_MPDUDENSITY_1;
1882 v = IEEE80211_HTCAP_MPDUDENSITY_2;
1885 v = IEEE80211_HTCAP_MPDUDENSITY_4;
1888 v = IEEE80211_HTCAP_MPDUDENSITY_8;
1891 v = IEEE80211_HTCAP_MPDUDENSITY_16;
1894 errx(-1, "invalid A-MPDU density %s", val);
1896 set80211(s, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL);
1900 set80211amsdu(const char *val, int d, int s, const struct afswtch *rafp)
1904 if (get80211val(s, IEEE80211_IOC_AMSDU, &amsdu) < 0)
1905 err(-1, "cannot get AMSDU setting");
1911 set80211(s, IEEE80211_IOC_AMSDU, amsdu, 0, NULL);
1915 DECL_CMD_FUNC(set80211amsdulimit, val, d)
1917 set80211(s, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL);
1921 set80211puren(const char *val, int d, int s, const struct afswtch *rafp)
1923 set80211(s, IEEE80211_IOC_PUREN, d, 0, NULL);
1927 set80211htcompat(const char *val, int d, int s, const struct afswtch *rafp)
1929 set80211(s, IEEE80211_IOC_HTCOMPAT, d, 0, NULL);
1933 set80211htconf(const char *val, int d, int s, const struct afswtch *rafp)
1935 set80211(s, IEEE80211_IOC_HTCONF, d, 0, NULL);
1940 set80211dwds(const char *val, int d, int s, const struct afswtch *rafp)
1942 set80211(s, IEEE80211_IOC_DWDS, d, 0, NULL);
1946 set80211inact(const char *val, int d, int s, const struct afswtch *rafp)
1948 set80211(s, IEEE80211_IOC_INACTIVITY, d, 0, NULL);
1952 set80211tsn(const char *val, int d, int s, const struct afswtch *rafp)
1954 set80211(s, IEEE80211_IOC_TSN, d, 0, NULL);
1958 set80211dotd(const char *val, int d, int s, const struct afswtch *rafp)
1960 set80211(s, IEEE80211_IOC_DOTD, d, 0, NULL);
1964 set80211smps(const char *val, int d, int s, const struct afswtch *rafp)
1966 set80211(s, IEEE80211_IOC_SMPS, d, 0, NULL);
1970 set80211rifs(const char *val, int d, int s, const struct afswtch *rafp)
1972 set80211(s, IEEE80211_IOC_RIFS, d, 0, NULL);
1976 set80211vhtconf(const char *val, int d, int s, const struct afswtch *rafp)
1978 if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
1979 errx(-1, "cannot set VHT setting");
1980 printf("%s: vhtconf=0x%08x, d=%d\n", __func__, vhtconf, d);
1986 printf("%s: vhtconf is now 0x%08x\n", __func__, vhtconf);
1987 set80211(s, IEEE80211_IOC_VHTCONF, vhtconf, 0, NULL);
1991 DECL_CMD_FUNC(set80211tdmaslot, val, d)
1993 set80211(s, IEEE80211_IOC_TDMA_SLOT, atoi(val), 0, NULL);
1997 DECL_CMD_FUNC(set80211tdmaslotcnt, val, d)
1999 set80211(s, IEEE80211_IOC_TDMA_SLOTCNT, atoi(val), 0, NULL);
2003 DECL_CMD_FUNC(set80211tdmaslotlen, val, d)
2005 set80211(s, IEEE80211_IOC_TDMA_SLOTLEN, atoi(val), 0, NULL);
2009 DECL_CMD_FUNC(set80211tdmabintval, val, d)
2011 set80211(s, IEEE80211_IOC_TDMA_BINTERVAL, atoi(val), 0, NULL);
2015 DECL_CMD_FUNC(set80211meshttl, val, d)
2017 set80211(s, IEEE80211_IOC_MESH_TTL, atoi(val), 0, NULL);
2021 DECL_CMD_FUNC(set80211meshforward, val, d)
2023 set80211(s, IEEE80211_IOC_MESH_FWRD, d, 0, NULL);
2027 DECL_CMD_FUNC(set80211meshgate, val, d)
2029 set80211(s, IEEE80211_IOC_MESH_GATE, d, 0, NULL);
2033 DECL_CMD_FUNC(set80211meshpeering, val, d)
2035 set80211(s, IEEE80211_IOC_MESH_AP, d, 0, NULL);
2039 DECL_CMD_FUNC(set80211meshmetric, val, d)
2043 memcpy(v, val, sizeof(v));
2044 set80211(s, IEEE80211_IOC_MESH_PR_METRIC, 0, 0, v);
2048 DECL_CMD_FUNC(set80211meshpath, val, d)
2052 memcpy(v, val, sizeof(v));
2053 set80211(s, IEEE80211_IOC_MESH_PR_PATH, 0, 0, v);
2057 regdomain_sort(const void *a, const void *b)
2060 (IEEE80211_CHAN_ALLTURBO|IEEE80211_CHAN_HALF|IEEE80211_CHAN_QUARTER)
2061 const struct ieee80211_channel *ca = a;
2062 const struct ieee80211_channel *cb = b;
2064 return ca->ic_freq == cb->ic_freq ?
2065 (ca->ic_flags & CHAN_ALL) - (cb->ic_flags & CHAN_ALL) :
2066 ca->ic_freq - cb->ic_freq;
2070 static const struct ieee80211_channel *
2071 chanlookup(const struct ieee80211_channel chans[], int nchans,
2072 int freq, int flags)
2076 flags &= IEEE80211_CHAN_ALLTURBO;
2077 for (i = 0; i < nchans; i++) {
2078 const struct ieee80211_channel *c = &chans[i];
2079 if (c->ic_freq == freq &&
2080 (c->ic_flags & IEEE80211_CHAN_ALLTURBO) == flags)
2087 chanfind(const struct ieee80211_channel chans[], int nchans, int flags)
2091 for (i = 0; i < nchans; i++) {
2092 const struct ieee80211_channel *c = &chans[i];
2093 if ((c->ic_flags & flags) == flags)
2100 * Check channel compatibility.
2103 checkchan(const struct ieee80211req_chaninfo *avail, int freq, int flags)
2105 flags &= ~REQ_FLAGS;
2107 * Check if exact channel is in the calibration table;
2108 * everything below is to deal with channels that we
2109 * want to include but that are not explicitly listed.
2111 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, flags) != NULL)
2113 if (flags & IEEE80211_CHAN_GSM) {
2115 * XXX GSM frequency mapping is handled in the kernel
2116 * so we cannot find them in the calibration table;
2117 * just accept the channel and the kernel will reject
2118 * the channel list if it's wrong.
2123 * If this is a 1/2 or 1/4 width channel allow it if a full
2124 * width channel is present for this frequency, and the device
2125 * supports fractional channels on this band. This is a hack
2126 * that avoids bloating the calibration table; it may be better
2127 * by per-band attributes though (we are effectively calculating
2128 * this attribute by scanning the channel list ourself).
2130 if ((flags & (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == 0)
2132 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq,
2133 flags &~ (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == NULL)
2135 if (flags & IEEE80211_CHAN_HALF) {
2136 return chanfind(avail->ic_chans, avail->ic_nchans,
2137 IEEE80211_CHAN_HALF |
2138 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2140 return chanfind(avail->ic_chans, avail->ic_nchans,
2141 IEEE80211_CHAN_QUARTER |
2142 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2147 regdomain_addchans(struct ieee80211req_chaninfo *ci,
2148 const netband_head *bands,
2149 const struct ieee80211_regdomain *reg,
2151 const struct ieee80211req_chaninfo *avail)
2153 const struct netband *nb;
2154 const struct freqband *b;
2155 struct ieee80211_channel *c, *prev;
2156 int freq, hi_adj, lo_adj, channelSep;
2159 hi_adj = (chanFlags & IEEE80211_CHAN_HT40U) ? -20 : 0;
2160 lo_adj = (chanFlags & IEEE80211_CHAN_HT40D) ? 20 : 0;
2161 channelSep = (chanFlags & IEEE80211_CHAN_2GHZ) ? 0 : 40;
2163 LIST_FOREACH(nb, bands, next) {
2166 printf("%s:", __func__);
2167 printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS);
2168 printb(" bandFlags", nb->flags | b->flags,
2169 IEEE80211_CHAN_BITS);
2174 for (freq = b->freqStart + lo_adj;
2175 freq <= b->freqEnd + hi_adj; freq += b->chanSep) {
2177 * Construct flags for the new channel. We take
2178 * the attributes from the band descriptions except
2179 * for HT40 which is enabled generically (i.e. +/-
2180 * extension channel) in the band description and
2181 * then constrained according by channel separation.
2183 flags = nb->flags | b->flags;
2186 * VHT first - HT is a subset.
2188 if (flags & IEEE80211_CHAN_VHT) {
2189 if ((chanFlags & IEEE80211_CHAN_VHT20) &&
2190 (flags & IEEE80211_CHAN_VHT20) == 0) {
2192 printf("%u: skip, not a "
2193 "VHT20 channel\n", freq);
2196 if ((chanFlags & IEEE80211_CHAN_VHT40) &&
2197 (flags & IEEE80211_CHAN_VHT40) == 0) {
2199 printf("%u: skip, not a "
2200 "VHT40 channel\n", freq);
2203 if ((chanFlags & IEEE80211_CHAN_VHT80) &&
2204 (flags & IEEE80211_CHAN_VHT80) == 0) {
2206 printf("%u: skip, not a "
2207 "VHT80 channel\n", freq);
2210 if ((chanFlags & IEEE80211_CHAN_VHT160) &&
2211 (flags & IEEE80211_CHAN_VHT160) == 0) {
2213 printf("%u: skip, not a "
2214 "VHT160 channel\n", freq);
2217 if ((chanFlags & IEEE80211_CHAN_VHT80P80) &&
2218 (flags & IEEE80211_CHAN_VHT80P80) == 0) {
2220 printf("%u: skip, not a "
2221 "VHT80+80 channel\n", freq);
2224 flags &= ~IEEE80211_CHAN_VHT;
2225 flags |= chanFlags & IEEE80211_CHAN_VHT;
2228 /* Now, constrain HT */
2229 if (flags & IEEE80211_CHAN_HT) {
2231 * HT channels are generated specially; we're
2232 * called to add HT20, HT40+, and HT40- chan's
2233 * so we need to expand only band specs for
2234 * the HT channel type being added.
2236 if ((chanFlags & IEEE80211_CHAN_HT20) &&
2237 (flags & IEEE80211_CHAN_HT20) == 0) {
2239 printf("%u: skip, not an "
2240 "HT20 channel\n", freq);
2243 if ((chanFlags & IEEE80211_CHAN_HT40) &&
2244 (flags & IEEE80211_CHAN_HT40) == 0) {
2246 printf("%u: skip, not an "
2247 "HT40 channel\n", freq);
2250 /* NB: HT attribute comes from caller */
2251 flags &= ~IEEE80211_CHAN_HT;
2252 flags |= chanFlags & IEEE80211_CHAN_HT;
2255 * Check if device can operate on this frequency.
2257 if (!checkchan(avail, freq, flags)) {
2259 printf("%u: skip, ", freq);
2260 printb("flags", flags,
2261 IEEE80211_CHAN_BITS);
2262 printf(" not available\n");
2266 if ((flags & REQ_ECM) && !reg->ecm) {
2268 printf("%u: skip, ECM channel\n", freq);
2271 if ((flags & REQ_INDOOR) && reg->location == 'O') {
2273 printf("%u: skip, indoor channel\n",
2277 if ((flags & REQ_OUTDOOR) && reg->location == 'I') {
2279 printf("%u: skip, outdoor channel\n",
2283 if ((flags & IEEE80211_CHAN_HT40) &&
2284 prev != NULL && (freq - prev->ic_freq) < channelSep) {
2286 printf("%u: skip, only %u channel "
2287 "separation, need %d\n", freq,
2288 freq - prev->ic_freq, channelSep);
2291 if (ci->ic_nchans == IEEE80211_CHAN_MAX) {
2293 printf("%u: skip, channel table full\n",
2297 c = &ci->ic_chans[ci->ic_nchans++];
2298 memset(c, 0, sizeof(*c));
2300 c->ic_flags = flags;
2301 if (c->ic_flags & IEEE80211_CHAN_DFS)
2302 c->ic_maxregpower = nb->maxPowerDFS;
2304 c->ic_maxregpower = nb->maxPower;
2306 printf("[%3d] add freq %u ",
2307 ci->ic_nchans-1, c->ic_freq);
2308 printb("flags", c->ic_flags, IEEE80211_CHAN_BITS);
2309 printf(" power %u\n", c->ic_maxregpower);
2311 /* NB: kernel fills in other fields */
2318 regdomain_makechannels(
2319 struct ieee80211_regdomain_req *req,
2320 const struct ieee80211_devcaps_req *dc)
2322 struct regdata *rdp = getregdata();
2323 const struct country *cc;
2324 const struct ieee80211_regdomain *reg = &req->rd;
2325 struct ieee80211req_chaninfo *ci = &req->chaninfo;
2326 const struct regdomain *rd;
2329 * Locate construction table for new channel list. We treat
2330 * the regdomain/SKU as definitive so a country can be in
2331 * multiple with different properties (e.g. US in FCC+FCC3).
2332 * If no regdomain is specified then we fallback on the country
2333 * code to find the associated regdomain since countries always
2334 * belong to at least one regdomain.
2336 if (reg->regdomain == 0) {
2337 cc = lib80211_country_findbycc(rdp, reg->country);
2339 errx(1, "internal error, country %d not found",
2343 rd = lib80211_regdomain_findbysku(rdp, reg->regdomain);
2345 errx(1, "internal error, regdomain %d not found",
2347 if (rd->sku != SKU_DEBUG) {
2349 * regdomain_addchans incrememnts the channel count for
2350 * each channel it adds so initialize ic_nchans to zero.
2351 * Note that we know we have enough space to hold all possible
2352 * channels because the devcaps list size was used to
2353 * allocate our request.
2356 if (!LIST_EMPTY(&rd->bands_11b))
2357 regdomain_addchans(ci, &rd->bands_11b, reg,
2358 IEEE80211_CHAN_B, &dc->dc_chaninfo);
2359 if (!LIST_EMPTY(&rd->bands_11g))
2360 regdomain_addchans(ci, &rd->bands_11g, reg,
2361 IEEE80211_CHAN_G, &dc->dc_chaninfo);
2362 if (!LIST_EMPTY(&rd->bands_11a))
2363 regdomain_addchans(ci, &rd->bands_11a, reg,
2364 IEEE80211_CHAN_A, &dc->dc_chaninfo);
2365 if (!LIST_EMPTY(&rd->bands_11na) && dc->dc_htcaps != 0) {
2366 regdomain_addchans(ci, &rd->bands_11na, reg,
2367 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20,
2369 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2370 regdomain_addchans(ci, &rd->bands_11na, reg,
2371 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U,
2373 regdomain_addchans(ci, &rd->bands_11na, reg,
2374 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D,
2378 if (!LIST_EMPTY(&rd->bands_11ac) && dc->dc_vhtcaps != 0) {
2379 regdomain_addchans(ci, &rd->bands_11ac, reg,
2380 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20 |
2381 IEEE80211_CHAN_VHT20,
2384 /* VHT40 is a function of HT40.. */
2385 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2386 regdomain_addchans(ci, &rd->bands_11ac, reg,
2387 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U |
2388 IEEE80211_CHAN_VHT40U,
2390 regdomain_addchans(ci, &rd->bands_11ac, reg,
2391 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D |
2392 IEEE80211_CHAN_VHT40D,
2396 /* VHT80 is mandatory (and so should be VHT40 above). */
2398 regdomain_addchans(ci, &rd->bands_11ac, reg,
2399 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U |
2400 IEEE80211_CHAN_VHT80,
2402 regdomain_addchans(ci, &rd->bands_11ac, reg,
2403 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D |
2404 IEEE80211_CHAN_VHT80,
2409 if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ(
2411 regdomain_addchans(ci, &rd->bands_11ac, reg,
2412 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U |
2413 IEEE80211_CHAN_VHT160,
2415 regdomain_addchans(ci, &rd->bands_11ac, reg,
2416 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D |
2417 IEEE80211_CHAN_VHT160,
2422 if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ(
2424 regdomain_addchans(ci, &rd->bands_11ac, reg,
2425 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U |
2426 IEEE80211_CHAN_VHT80P80,
2428 regdomain_addchans(ci, &rd->bands_11ac, reg,
2429 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D |
2430 IEEE80211_CHAN_VHT80P80,
2435 if (!LIST_EMPTY(&rd->bands_11ng) && dc->dc_htcaps != 0) {
2436 regdomain_addchans(ci, &rd->bands_11ng, reg,
2437 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20,
2439 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2440 regdomain_addchans(ci, &rd->bands_11ng, reg,
2441 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U,
2443 regdomain_addchans(ci, &rd->bands_11ng, reg,
2444 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D,
2448 qsort(ci->ic_chans, ci->ic_nchans, sizeof(ci->ic_chans[0]),
2451 memcpy(ci, &dc->dc_chaninfo,
2452 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
2456 list_countries(void)
2458 struct regdata *rdp = getregdata();
2459 const struct country *cp;
2460 const struct regdomain *dp;
2464 printf("\nCountry codes:\n");
2465 LIST_FOREACH(cp, &rdp->countries, next) {
2466 printf("%2s %-15.15s%s", cp->isoname,
2467 cp->name, ((i+1)%4) == 0 ? "\n" : " ");
2471 printf("\nRegulatory domains:\n");
2472 LIST_FOREACH(dp, &rdp->domains, next) {
2473 printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " ");
2480 defaultcountry(const struct regdomain *rd)
2482 struct regdata *rdp = getregdata();
2483 const struct country *cc;
2485 cc = lib80211_country_findbycc(rdp, rd->cc->code);
2487 errx(1, "internal error, ISO country code %d not "
2488 "defined for regdomain %s", rd->cc->code, rd->name);
2489 regdomain.country = cc->code;
2490 regdomain.isocc[0] = cc->isoname[0];
2491 regdomain.isocc[1] = cc->isoname[1];
2495 DECL_CMD_FUNC(set80211regdomain, val, d)
2497 struct regdata *rdp = getregdata();
2498 const struct regdomain *rd;
2500 rd = lib80211_regdomain_findbyname(rdp, val);
2503 long sku = strtol(val, &eptr, 0);
2506 rd = lib80211_regdomain_findbysku(rdp, sku);
2507 if (eptr == val || rd == NULL)
2508 errx(1, "unknown regdomain %s", val);
2511 regdomain.regdomain = rd->sku;
2512 if (regdomain.country == 0 && rd->cc != NULL) {
2514 * No country code setup and there's a default
2515 * one for this regdomain fill it in.
2519 callback_register(setregdomain_cb, ®domain);
2523 DECL_CMD_FUNC(set80211country, val, d)
2525 struct regdata *rdp = getregdata();
2526 const struct country *cc;
2528 cc = lib80211_country_findbyname(rdp, val);
2531 long code = strtol(val, &eptr, 0);
2534 cc = lib80211_country_findbycc(rdp, code);
2535 if (eptr == val || cc == NULL)
2536 errx(1, "unknown ISO country code %s", val);
2539 regdomain.regdomain = cc->rd->sku;
2540 regdomain.country = cc->code;
2541 regdomain.isocc[0] = cc->isoname[0];
2542 regdomain.isocc[1] = cc->isoname[1];
2543 callback_register(setregdomain_cb, ®domain);
2547 set80211location(const char *val, int d, int s, const struct afswtch *rafp)
2550 regdomain.location = d;
2551 callback_register(setregdomain_cb, ®domain);
2555 set80211ecm(const char *val, int d, int s, const struct afswtch *rafp)
2559 callback_register(setregdomain_cb, ®domain);
2575 if (spacer != '\t') {
2579 col = 8; /* 8-col tab */
2583 LINE_CHECK(const char *fmt, ...)
2590 n = vsnprintf(buf+1, sizeof(buf)-1, fmt, ap);
2603 getmaxrate(const uint8_t rates[15], uint8_t nrates)
2605 int i, maxrate = -1;
2607 for (i = 0; i < nrates; i++) {
2608 int rate = rates[i] & IEEE80211_RATE_VAL;
2616 getcaps(int capinfo)
2618 static char capstring[32];
2619 char *cp = capstring;
2621 if (capinfo & IEEE80211_CAPINFO_ESS)
2623 if (capinfo & IEEE80211_CAPINFO_IBSS)
2625 if (capinfo & IEEE80211_CAPINFO_CF_POLLABLE)
2627 if (capinfo & IEEE80211_CAPINFO_CF_POLLREQ)
2629 if (capinfo & IEEE80211_CAPINFO_PRIVACY)
2631 if (capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)
2633 if (capinfo & IEEE80211_CAPINFO_PBCC)
2635 if (capinfo & IEEE80211_CAPINFO_CHNL_AGILITY)
2637 if (capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME)
2639 if (capinfo & IEEE80211_CAPINFO_RSN)
2641 if (capinfo & IEEE80211_CAPINFO_DSSSOFDM)
2650 static char flagstring[32];
2651 char *cp = flagstring;
2653 if (flags & IEEE80211_NODE_AUTH)
2655 if (flags & IEEE80211_NODE_QOS)
2657 if (flags & IEEE80211_NODE_ERP)
2659 if (flags & IEEE80211_NODE_PWR_MGT)
2661 if (flags & IEEE80211_NODE_HT) {
2663 if (flags & IEEE80211_NODE_HTCOMPAT)
2666 if (flags & IEEE80211_NODE_VHT)
2668 if (flags & IEEE80211_NODE_WPS)
2670 if (flags & IEEE80211_NODE_TSN)
2672 if (flags & IEEE80211_NODE_AMPDU_TX)
2674 if (flags & IEEE80211_NODE_AMPDU_RX)
2676 if (flags & IEEE80211_NODE_MIMO_PS) {
2678 if (flags & IEEE80211_NODE_MIMO_RTS)
2681 if (flags & IEEE80211_NODE_RIFS)
2683 if (flags & IEEE80211_NODE_SGI40) {
2685 if (flags & IEEE80211_NODE_SGI20)
2687 } else if (flags & IEEE80211_NODE_SGI20)
2689 if (flags & IEEE80211_NODE_AMSDU_TX)
2691 if (flags & IEEE80211_NODE_AMSDU_RX)
2693 if (flags & IEEE80211_NODE_UAPSD)
2695 if (flags & IEEE80211_NODE_LDPC)
2702 printie(const char* tag, const uint8_t *ie, size_t ielen, int maxlen)
2706 maxlen -= strlen(tag)+2;
2707 if (2*ielen > maxlen)
2710 for (; ielen > 0; ie++, ielen--) {
2713 printf("%02x", *ie);
2721 #define LE_READ_2(p) \
2723 ((((const u_int8_t *)(p))[0] ) | \
2724 (((const u_int8_t *)(p))[1] << 8)))
2725 #define LE_READ_4(p) \
2727 ((((const u_int8_t *)(p))[0] ) | \
2728 (((const u_int8_t *)(p))[1] << 8) | \
2729 (((const u_int8_t *)(p))[2] << 16) | \
2730 (((const u_int8_t *)(p))[3] << 24)))
2733 * NB: The decoding routines assume a properly formatted ie
2734 * which should be safe as the kernel only retains them
2739 printwmeparam(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2741 static const char *acnames[] = { "BE", "BK", "VO", "VI" };
2742 const struct ieee80211_wme_param *wme =
2743 (const struct ieee80211_wme_param *) ie;
2749 printf("<qosinfo 0x%x", wme->param_qosInfo);
2750 ie += offsetof(struct ieee80211_wme_param, params_acParams);
2751 for (i = 0; i < WME_NUM_AC; i++) {
2752 const struct ieee80211_wme_acparams *ac =
2753 &wme->params_acParams[i];
2755 printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]", acnames[i],
2756 _IEEE80211_MASKSHIFT(ac->acp_aci_aifsn, WME_PARAM_ACM) ?
2758 _IEEE80211_MASKSHIFT(ac->acp_aci_aifsn, WME_PARAM_AIFSN),
2759 _IEEE80211_MASKSHIFT(ac->acp_logcwminmax,
2760 WME_PARAM_LOGCWMIN),
2761 _IEEE80211_MASKSHIFT(ac->acp_logcwminmax,
2762 WME_PARAM_LOGCWMAX),
2763 LE_READ_2(&ac->acp_txop));
2769 printwmeinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2773 const struct ieee80211_wme_info *wme =
2774 (const struct ieee80211_wme_info *) ie;
2775 printf("<version 0x%x info 0x%x>",
2776 wme->wme_version, wme->wme_info);
2781 printvhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2785 const struct ieee80211_ie_vhtcap *vhtcap =
2786 (const struct ieee80211_ie_vhtcap *) ie;
2787 uint32_t vhtcap_info = LE_READ_4(&vhtcap->vht_cap_info);
2789 printf("<cap 0x%08x", vhtcap_info);
2790 printf(" rx_mcs_map 0x%x",
2791 LE_READ_2(&vhtcap->supp_mcs.rx_mcs_map));
2792 printf(" rx_highest %d",
2793 LE_READ_2(&vhtcap->supp_mcs.rx_highest) & 0x1fff);
2794 printf(" tx_mcs_map 0x%x",
2795 LE_READ_2(&vhtcap->supp_mcs.tx_mcs_map));
2796 printf(" tx_highest %d",
2797 LE_READ_2(&vhtcap->supp_mcs.tx_highest) & 0x1fff);
2804 printvhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2808 const struct ieee80211_ie_vht_operation *vhtinfo =
2809 (const struct ieee80211_ie_vht_operation *) ie;
2811 printf("<chw %d freq1_idx %d freq2_idx %d basic_mcs_set 0x%04x>",
2812 vhtinfo->chan_width,
2813 vhtinfo->center_freq_seg1_idx,
2814 vhtinfo->center_freq_seg2_idx,
2815 LE_READ_2(&vhtinfo->basic_mcs_set));
2820 printvhtpwrenv(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2823 static const char *txpwrmap[] = {
2830 const struct ieee80211_ie_vht_txpwrenv *vhtpwr =
2831 (const struct ieee80211_ie_vht_txpwrenv *) ie;
2833 const char *sep = "";
2835 /* Get count; trim at ielen */
2836 n = (vhtpwr->tx_info &
2837 IEEE80211_VHT_TXPWRENV_INFO_COUNT_MASK) + 1;
2841 printf("<tx_info 0x%02x pwr:[", vhtpwr->tx_info);
2842 for (i = 0; i < n; i++) {
2843 printf("%s%s:%.2f", sep, txpwrmap[i],
2844 ((float) ((int8_t) ie[i+3])) / 2.0);
2853 printhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2857 const struct ieee80211_ie_htcap *htcap =
2858 (const struct ieee80211_ie_htcap *) ie;
2862 printf("<cap 0x%x param 0x%x",
2863 LE_READ_2(&htcap->hc_cap), htcap->hc_param);
2866 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2867 if (isset(htcap->hc_mcsset, i)) {
2868 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2869 if (isclr(htcap->hc_mcsset, j))
2873 printf("%s%u", sep, i);
2875 printf("%s%u-%u", sep, i, j);
2879 printf("] extcap 0x%x txbf 0x%x antenna 0x%x>",
2880 LE_READ_2(&htcap->hc_extcap),
2881 LE_READ_4(&htcap->hc_txbf),
2887 printhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2891 const struct ieee80211_ie_htinfo *htinfo =
2892 (const struct ieee80211_ie_htinfo *) ie;
2896 printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel,
2897 htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3,
2898 LE_READ_2(&htinfo->hi_byte45));
2899 printf(" basicmcs[");
2901 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2902 if (isset(htinfo->hi_basicmcsset, i)) {
2903 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2904 if (isclr(htinfo->hi_basicmcsset, j))
2908 printf("%s%u", sep, i);
2910 printf("%s%u-%u", sep, i, j);
2919 printathie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2924 const struct ieee80211_ath_ie *ath =
2925 (const struct ieee80211_ath_ie *)ie;
2928 if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME)
2930 if (ath->ath_capability & ATHEROS_CAP_COMPRESSION)
2932 if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME)
2934 if (ath->ath_capability & ATHEROS_CAP_XR)
2936 if (ath->ath_capability & ATHEROS_CAP_AR)
2938 if (ath->ath_capability & ATHEROS_CAP_BURST)
2940 if (ath->ath_capability & ATHEROS_CAP_WME)
2942 if (ath->ath_capability & ATHEROS_CAP_BOOST)
2944 printf("0x%x>", LE_READ_2(ath->ath_defkeyix));
2950 printmeshconf(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2955 const struct ieee80211_meshconf_ie *mconf =
2956 (const struct ieee80211_meshconf_ie *)ie;
2958 if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP)
2963 if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME)
2967 printf(" CONGESTION:");
2968 if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED)
2973 if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF)
2978 if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED)
2982 printf(" FORM:0x%x CAPS:0x%x>", mconf->conf_form,
2988 printbssload(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2992 const struct ieee80211_bss_load_ie *bssload =
2993 (const struct ieee80211_bss_load_ie *) ie;
2994 printf("<sta count %d, chan load %d, aac %d>",
2995 LE_READ_2(&bssload->sta_count),
3002 printapchanrep(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3006 const struct ieee80211_ap_chan_report_ie *ap =
3007 (const struct ieee80211_ap_chan_report_ie *) ie;
3008 const char *sep = "";
3011 printf("<class %u, chan:[", ap->i_class);
3013 for (i = 3; i < ielen; i++) {
3014 printf("%s%u", sep, ie[i]);
3022 wpa_cipher(const u_int8_t *sel)
3024 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
3025 u_int32_t w = LE_READ_4(sel);
3028 case WPA_SEL(WPA_CSE_NULL):
3030 case WPA_SEL(WPA_CSE_WEP40):
3032 case WPA_SEL(WPA_CSE_WEP104):
3034 case WPA_SEL(WPA_CSE_TKIP):
3036 case WPA_SEL(WPA_CSE_CCMP):
3039 return "?"; /* NB: so 1<< is discarded */
3044 wpa_keymgmt(const u_int8_t *sel)
3046 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
3047 u_int32_t w = LE_READ_4(sel);
3050 case WPA_SEL(WPA_ASE_8021X_UNSPEC):
3051 return "8021X-UNSPEC";
3052 case WPA_SEL(WPA_ASE_8021X_PSK):
3054 case WPA_SEL(WPA_ASE_NONE):
3062 printwpaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3064 u_int8_t len = ie[1];
3071 ie += 6, len -= 4; /* NB: len is payload only */
3073 printf("<v%u", LE_READ_2(ie));
3076 printf(" mc:%s", wpa_cipher(ie));
3079 /* unicast ciphers */
3083 for (; n > 0; n--) {
3084 printf("%s%s", sep, wpa_cipher(ie));
3089 /* key management algorithms */
3093 for (; n > 0; n--) {
3094 printf("%s%s", sep, wpa_keymgmt(ie));
3099 if (len > 2) /* optional capabilities */
3100 printf(", caps 0x%x", LE_READ_2(ie));
3106 rsn_cipher(const u_int8_t *sel)
3108 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
3109 u_int32_t w = LE_READ_4(sel);
3112 case RSN_SEL(RSN_CSE_NULL):
3114 case RSN_SEL(RSN_CSE_WEP40):
3116 case RSN_SEL(RSN_CSE_WEP104):
3118 case RSN_SEL(RSN_CSE_TKIP):
3120 case RSN_SEL(RSN_CSE_CCMP):
3122 case RSN_SEL(RSN_CSE_WRAP):
3130 rsn_keymgmt(const u_int8_t *sel)
3132 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
3133 u_int32_t w = LE_READ_4(sel);
3136 case RSN_SEL(RSN_ASE_8021X_UNSPEC):
3137 return "8021X-UNSPEC";
3138 case RSN_SEL(RSN_ASE_8021X_PSK):
3140 case RSN_SEL(RSN_ASE_NONE):
3148 printrsnie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3155 ie += 2, ielen -= 2;
3157 printf("<v%u", LE_READ_2(ie));
3158 ie += 2, ielen -= 2;
3160 printf(" mc:%s", rsn_cipher(ie));
3161 ie += 4, ielen -= 4;
3163 /* unicast ciphers */
3165 ie += 2, ielen -= 2;
3167 for (; n > 0; n--) {
3168 printf("%s%s", sep, rsn_cipher(ie));
3169 ie += 4, ielen -= 4;
3173 /* key management algorithms */
3175 ie += 2, ielen -= 2;
3177 for (; n > 0; n--) {
3178 printf("%s%s", sep, rsn_keymgmt(ie));
3179 ie += 4, ielen -= 4;
3183 if (ielen > 2) /* optional capabilities */
3184 printf(", caps 0x%x", LE_READ_2(ie));
3190 #define BE_READ_2(p) \
3192 ((((const u_int8_t *)(p))[1] ) | \
3193 (((const u_int8_t *)(p))[0] << 8)))
3196 printwpsie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3198 u_int8_t len = ie[1];
3202 static const char *dev_pass_id[] = {
3203 "D", /* Default (PIN) */
3204 "U", /* User-specified */
3205 "M", /* Machine-specified */
3207 "P", /* PushButton */
3208 "R" /* Registrar-specified */
3213 ie +=6, len -= 4; /* NB: len is payload only */
3215 /* WPS IE in Beacon and Probe Resp frames have different fields */
3218 uint16_t tlv_type = BE_READ_2(ie);
3219 uint16_t tlv_len = BE_READ_2(ie + 2);
3222 /* some devices broadcast invalid WPS frames */
3223 if (tlv_len > len) {
3224 printf("bad frame length tlv_type=0x%02x "
3225 "tlv_len=%d len=%d", tlv_type, tlv_len,
3233 case IEEE80211_WPS_ATTR_VERSION:
3234 printf("v:%d.%d", *ie >> 4, *ie & 0xf);
3236 case IEEE80211_WPS_ATTR_AP_SETUP_LOCKED:
3237 printf(" ap_setup:%s", *ie ? "locked" :
3240 case IEEE80211_WPS_ATTR_CONFIG_METHODS:
3241 case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS:
3242 if (tlv_type == IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS)
3243 printf(" sel_reg_cfg_mthd:");
3245 printf(" cfg_mthd:" );
3246 cfg_mthd = BE_READ_2(ie);
3248 for (n = 15; n >= 0; n--) {
3253 switch (cfg_mthd & (1 << n)) {
3256 case IEEE80211_WPS_CONFIG_USBA:
3260 case IEEE80211_WPS_CONFIG_ETHERNET:
3264 case IEEE80211_WPS_CONFIG_LABEL:
3268 case IEEE80211_WPS_CONFIG_DISPLAY:
3270 (IEEE80211_WPS_CONFIG_VIRT_DISPLAY |
3271 IEEE80211_WPS_CONFIG_PHY_DISPLAY)))
3277 case IEEE80211_WPS_CONFIG_EXT_NFC_TOKEN:
3278 printf("ext_nfc_tokenk");
3281 case IEEE80211_WPS_CONFIG_INT_NFC_TOKEN:
3282 printf("int_nfc_token");
3285 case IEEE80211_WPS_CONFIG_NFC_INTERFACE:
3286 printf("nfc_interface");
3289 case IEEE80211_WPS_CONFIG_PUSHBUTTON:
3291 (IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON |
3292 IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON))) {
3293 printf("push_button");
3297 case IEEE80211_WPS_CONFIG_KEYPAD:
3301 case IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON:
3302 printf("virtual_push_button");
3305 case IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON:
3306 printf("physical_push_button");
3309 case IEEE80211_WPS_CONFIG_P2PS:
3313 case IEEE80211_WPS_CONFIG_VIRT_DISPLAY:
3314 printf("virtual_display");
3317 case IEEE80211_WPS_CONFIG_PHY_DISPLAY:
3318 printf("physical_display");
3322 printf("unknown_wps_config<%04x>",
3323 cfg_mthd & (1 << n));
3329 case IEEE80211_WPS_ATTR_DEV_NAME:
3330 printf(" device_name:<%.*s>", tlv_len, ie);
3332 case IEEE80211_WPS_ATTR_DEV_PASSWORD_ID:
3334 if (n < nitems(dev_pass_id))
3335 printf(" dpi:%s", dev_pass_id[n]);
3337 case IEEE80211_WPS_ATTR_MANUFACTURER:
3338 printf(" manufacturer:<%.*s>", tlv_len, ie);
3340 case IEEE80211_WPS_ATTR_MODEL_NAME:
3341 printf(" model_name:<%.*s>", tlv_len, ie);
3343 case IEEE80211_WPS_ATTR_MODEL_NUMBER:
3344 printf(" model_number:<%.*s>", tlv_len, ie);
3346 case IEEE80211_WPS_ATTR_PRIMARY_DEV_TYPE:
3347 printf(" prim_dev:");
3348 for (n = 0; n < tlv_len; n++)
3349 printf("%02x", ie[n]);
3351 case IEEE80211_WPS_ATTR_RF_BANDS:
3354 for (n = 7; n >= 0; n--) {
3359 switch (*ie & (1 << n)) {
3362 case IEEE80211_WPS_RF_BAND_24GHZ:
3366 case IEEE80211_WPS_RF_BAND_50GHZ:
3370 case IEEE80211_WPS_RF_BAND_600GHZ:
3375 printf("unknown<%02x>",
3382 case IEEE80211_WPS_ATTR_RESPONSE_TYPE:
3383 printf(" resp_type:0x%02x", *ie);
3385 case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR:
3386 printf(" sel:%s", *ie ? "T" : "F");
3388 case IEEE80211_WPS_ATTR_SERIAL_NUMBER:
3389 printf(" serial_number:<%.*s>", tlv_len, ie);
3391 case IEEE80211_WPS_ATTR_UUID_E:
3393 for (n = 0; n < (tlv_len - 1); n++)
3394 printf("%02x-", ie[n]);
3395 printf("%02x", ie[n]);
3397 case IEEE80211_WPS_ATTR_VENDOR_EXT:
3399 for (n = 0; n < tlv_len; n++)
3400 printf("%02x", ie[n]);
3402 case IEEE80211_WPS_ATTR_WPS_STATE:
3404 case IEEE80211_WPS_STATE_NOT_CONFIGURED:
3407 case IEEE80211_WPS_STATE_CONFIGURED:
3411 printf(" state:B<%02x>", *ie);
3416 printf(" unknown_wps_attr:0x%x", tlv_type);
3419 ie += tlv_len, len -= tlv_len;
3426 printtdmaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3429 if (verbose && ielen >= sizeof(struct ieee80211_tdma_param)) {
3430 const struct ieee80211_tdma_param *tdma =
3431 (const struct ieee80211_tdma_param *) ie;
3434 printf("<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>",
3435 tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt,
3436 LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval,
3437 tdma->tdma_inuse[0]);
3442 * Copy the ssid string contents into buf, truncating to fit. If the
3443 * ssid is entirely printable then just copy intact. Otherwise convert
3444 * to hexadecimal. If the result is truncated then replace the last
3445 * three characters with "...".
3448 copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len)
3454 if (essid_len > bufsize)
3458 /* determine printable or not */
3459 for (i = 0, p = essid; i < maxlen; i++, p++) {
3460 if (*p < ' ' || *p > 0x7e)
3463 if (i != maxlen) { /* not printable, print as hex */
3466 strlcpy(buf, "0x", bufsize);
3469 for (i = 0; i < maxlen && bufsize >= 2; i++) {
3470 sprintf(&buf[2+2*i], "%02x", p[i]);
3474 memcpy(&buf[2+2*i-3], "...", 3);
3475 } else { /* printable, truncate as needed */
3476 memcpy(buf, essid, maxlen);
3477 if (maxlen != essid_len)
3478 memcpy(&buf[maxlen-3], "...", 3);
3484 printssid(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3486 char ssid[2*IEEE80211_NWID_LEN+1];
3488 printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid);
3492 printrates(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3499 for (i = 2; i < ielen; i++) {
3500 printf("%s%s%d", sep,
3501 ie[i] & IEEE80211_RATE_BASIC ? "B" : "",
3502 ie[i] & IEEE80211_RATE_VAL);
3509 printcountry(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3511 const struct ieee80211_country_ie *cie =
3512 (const struct ieee80211_country_ie *) ie;
3513 int i, nbands, schan, nchan;
3515 printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]);
3516 nbands = (cie->len - 3) / sizeof(cie->band[0]);
3517 for (i = 0; i < nbands; i++) {
3518 schan = cie->band[i].schan;
3519 nchan = cie->band[i].nchan;
3521 printf(" %u-%u,%u", schan, schan + nchan-1,
3522 cie->band[i].maxtxpwr);
3524 printf(" %u,%u", schan, cie->band[i].maxtxpwr);
3530 iswpaoui(const u_int8_t *frm)
3532 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI);
3536 iswmeinfo(const u_int8_t *frm)
3538 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3539 frm[6] == WME_INFO_OUI_SUBTYPE;
3543 iswmeparam(const u_int8_t *frm)
3545 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3546 frm[6] == WME_PARAM_OUI_SUBTYPE;
3550 isatherosoui(const u_int8_t *frm)
3552 return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI);
3556 istdmaoui(const uint8_t *frm)
3558 return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI);
3562 iswpsoui(const uint8_t *frm)
3564 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPS_OUI_TYPE<<24)|WPA_OUI);
3570 static char iename_buf[64];
3572 case IEEE80211_ELEMID_FHPARMS: return " FHPARMS";
3573 case IEEE80211_ELEMID_CFPARMS: return " CFPARMS";
3574 case IEEE80211_ELEMID_TIM: return " TIM";
3575 case IEEE80211_ELEMID_IBSSPARMS:return " IBSSPARMS";
3576 case IEEE80211_ELEMID_BSSLOAD: return " BSSLOAD";
3577 case IEEE80211_ELEMID_CHALLENGE:return " CHALLENGE";
3578 case IEEE80211_ELEMID_PWRCNSTR: return " PWRCNSTR";
3579 case IEEE80211_ELEMID_PWRCAP: return " PWRCAP";
3580 case IEEE80211_ELEMID_TPCREQ: return " TPCREQ";
3581 case IEEE80211_ELEMID_TPCREP: return " TPCREP";
3582 case IEEE80211_ELEMID_SUPPCHAN: return " SUPPCHAN";
3583 case IEEE80211_ELEMID_CSA: return " CSA";
3584 case IEEE80211_ELEMID_MEASREQ: return " MEASREQ";
3585 case IEEE80211_ELEMID_MEASREP: return " MEASREP";
3586 case IEEE80211_ELEMID_QUIET: return " QUIET";
3587 case IEEE80211_ELEMID_IBSSDFS: return " IBSSDFS";
3588 case IEEE80211_ELEMID_RESERVED_47:
3589 return " RESERVED_47";
3590 case IEEE80211_ELEMID_MOBILITY_DOMAIN:
3591 return " MOBILITY_DOMAIN";
3592 case IEEE80211_ELEMID_RRM_ENACAPS:
3593 return " RRM_ENCAPS";
3594 case IEEE80211_ELEMID_OVERLAP_BSS_SCAN_PARAM:
3595 return " OVERLAP_BSS";
3596 case IEEE80211_ELEMID_TPC: return " TPC";
3597 case IEEE80211_ELEMID_CCKM: return " CCKM";
3598 case IEEE80211_ELEMID_EXTCAP: return " EXTCAP";
3600 snprintf(iename_buf, sizeof(iename_buf), " UNKNOWN_ELEMID_%d",
3602 return (const char *) iename_buf;
3606 printies(const u_int8_t *vp, int ielen, int maxcols)
3610 case IEEE80211_ELEMID_SSID:
3612 printssid(" SSID", vp, 2+vp[1], maxcols);
3614 case IEEE80211_ELEMID_RATES:
3615 case IEEE80211_ELEMID_XRATES:
3617 printrates(vp[0] == IEEE80211_ELEMID_RATES ?
3618 " RATES" : " XRATES", vp, 2+vp[1], maxcols);
3620 case IEEE80211_ELEMID_DSPARMS:
3622 printf(" DSPARMS<%u>", vp[2]);
3624 case IEEE80211_ELEMID_COUNTRY:
3626 printcountry(" COUNTRY", vp, 2+vp[1], maxcols);
3628 case IEEE80211_ELEMID_ERP:
3630 printf(" ERP<0x%x>", vp[2]);
3632 case IEEE80211_ELEMID_VENDOR:
3634 printwpaie(" WPA", vp, 2+vp[1], maxcols);
3635 else if (iswmeinfo(vp))
3636 printwmeinfo(" WME", vp, 2+vp[1], maxcols);
3637 else if (iswmeparam(vp))
3638 printwmeparam(" WME", vp, 2+vp[1], maxcols);
3639 else if (isatherosoui(vp))
3640 printathie(" ATH", vp, 2+vp[1], maxcols);
3641 else if (iswpsoui(vp))
3642 printwpsie(" WPS", vp, 2+vp[1], maxcols);
3643 else if (istdmaoui(vp))
3644 printtdmaie(" TDMA", vp, 2+vp[1], maxcols);
3646 printie(" VEN", vp, 2+vp[1], maxcols);
3648 case IEEE80211_ELEMID_RSN:
3649 printrsnie(" RSN", vp, 2+vp[1], maxcols);
3651 case IEEE80211_ELEMID_HTCAP:
3652 printhtcap(" HTCAP", vp, 2+vp[1], maxcols);
3654 case IEEE80211_ELEMID_HTINFO:
3656 printhtinfo(" HTINFO", vp, 2+vp[1], maxcols);
3658 case IEEE80211_ELEMID_MESHID:
3660 printssid(" MESHID", vp, 2+vp[1], maxcols);
3662 case IEEE80211_ELEMID_MESHCONF:
3663 printmeshconf(" MESHCONF", vp, 2+vp[1], maxcols);
3665 case IEEE80211_ELEMID_VHT_CAP:
3666 printvhtcap(" VHTCAP", vp, 2+vp[1], maxcols);
3668 case IEEE80211_ELEMID_VHT_OPMODE:
3669 printvhtinfo(" VHTOPMODE", vp, 2+vp[1], maxcols);
3671 case IEEE80211_ELEMID_VHT_PWR_ENV:
3672 printvhtpwrenv(" VHTPWRENV", vp, 2+vp[1], maxcols);
3674 case IEEE80211_ELEMID_BSSLOAD:
3675 printbssload(" BSSLOAD", vp, 2+vp[1], maxcols);
3677 case IEEE80211_ELEMID_APCHANREP:
3678 printapchanrep(" APCHANREP", vp, 2+vp[1], maxcols);
3682 printie(iename(vp[0]), vp, 2+vp[1], maxcols);
3691 printmimo(const struct ieee80211_mimo_info *mi)
3696 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3697 if (mi->ch[i].rssi != 0) {
3703 /* NB: don't muddy display unless there's something to show */
3707 /* XXX TODO: ignore EVM; secondary channels for now */
3708 printf(" (rssi %.1f:%.1f:%.1f:%.1f nf %d:%d:%d:%d)",
3709 mi->ch[0].rssi[0] / 2.0,
3710 mi->ch[1].rssi[0] / 2.0,
3711 mi->ch[2].rssi[0] / 2.0,
3712 mi->ch[3].rssi[0] / 2.0,
3716 mi->ch[3].noise[0]);
3722 uint8_t buf[24*1024];
3723 char ssid[IEEE80211_NWID_LEN+1];
3727 if (get80211len(s, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0)
3728 errx(1, "unable to get scan results");
3729 if (len < sizeof(struct ieee80211req_scan_result))
3734 printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n"
3735 , IEEE80211_NWID_LEN, IEEE80211_NWID_LEN, "SSID/MESH ID"
3745 const struct ieee80211req_scan_result *sr;
3746 const uint8_t *vp, *idp;
3748 sr = (const struct ieee80211req_scan_result *) cp;
3749 vp = cp + sr->isr_ie_off;
3750 if (sr->isr_meshid_len) {
3751 idp = vp + sr->isr_ssid_len;
3752 idlen = sr->isr_meshid_len;
3755 idlen = sr->isr_ssid_len;
3757 printf("%-*.*s %s %3d %3dM %4d:%-4d %4d %-4.4s"
3758 , IEEE80211_NWID_LEN
3759 , copy_essid(ssid, IEEE80211_NWID_LEN, idp, idlen)
3761 , ether_ntoa((const struct ether_addr *) sr->isr_bssid)
3762 , ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags)
3763 , getmaxrate(sr->isr_rates, sr->isr_nrates)
3764 , (sr->isr_rssi/2)+sr->isr_noise, sr->isr_noise
3766 , getcaps(sr->isr_capinfo)
3768 printies(vp + sr->isr_ssid_len + sr->isr_meshid_len,
3769 sr->isr_ie_len, 24);
3771 cp += sr->isr_len, len -= sr->isr_len;
3772 } while (len >= sizeof(struct ieee80211req_scan_result));
3776 scan_and_wait(int s)
3778 struct ieee80211_scan_req sr;
3779 struct ieee80211req ireq;
3782 sroute = socket(PF_ROUTE, SOCK_RAW, 0);
3784 perror("socket(PF_ROUTE,SOCK_RAW)");
3787 (void) memset(&ireq, 0, sizeof(ireq));
3788 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
3789 ireq.i_type = IEEE80211_IOC_SCAN_REQ;
3791 memset(&sr, 0, sizeof(sr));
3792 sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE
3793 | IEEE80211_IOC_SCAN_BGSCAN
3794 | IEEE80211_IOC_SCAN_NOPICK
3795 | IEEE80211_IOC_SCAN_ONCE;
3796 sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER;
3800 ireq.i_len = sizeof(sr);
3802 * NB: only root can trigger a scan so ignore errors. Also ignore
3803 * possible errors from net80211, even if no new scan could be
3804 * started there might still be a valid scan cache.
3806 if (ioctl(s, SIOCS80211, &ireq) == 0) {
3808 struct if_announcemsghdr *ifan;
3809 struct rt_msghdr *rtm;
3812 if (read(sroute, buf, sizeof(buf)) < 0) {
3813 perror("read(PF_ROUTE)");
3816 rtm = (struct rt_msghdr *) buf;
3817 if (rtm->rtm_version != RTM_VERSION)
3819 ifan = (struct if_announcemsghdr *) rtm;
3820 } while (rtm->rtm_type != RTM_IEEE80211 ||
3821 ifan->ifan_what != RTM_IEEE80211_SCAN);
3827 DECL_CMD_FUNC(set80211scan, val, d)
3833 static enum ieee80211_opmode get80211opmode(int s);
3836 gettxseq(const struct ieee80211req_sta_info *si)
3840 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3841 return si->isi_txseqs[0];
3842 /* XXX not right but usually what folks want */
3844 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3845 if (si->isi_txseqs[i] > txseq)
3846 txseq = si->isi_txseqs[i];
3851 getrxseq(const struct ieee80211req_sta_info *si)
3855 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3856 return si->isi_rxseqs[0];
3857 /* XXX not right but usually what folks want */
3859 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3860 if (si->isi_rxseqs[i] > rxseq)
3861 rxseq = si->isi_rxseqs[i];
3866 list_stations(int s)
3869 struct ieee80211req_sta_req req;
3870 uint8_t buf[24*1024];
3872 enum ieee80211_opmode opmode = get80211opmode(s);
3876 /* broadcast address =>'s get all stations */
3877 (void) memset(u.req.is_u.macaddr, 0xff, IEEE80211_ADDR_LEN);
3878 if (opmode == IEEE80211_M_STA) {
3880 * Get information about the associated AP.
3882 (void) get80211(s, IEEE80211_IOC_BSSID,
3883 u.req.is_u.macaddr, IEEE80211_ADDR_LEN);
3885 if (get80211len(s, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0)
3886 errx(1, "unable to get station information");
3887 if (len < sizeof(struct ieee80211req_sta_info))
3892 if (opmode == IEEE80211_M_MBSS)
3893 printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n"
3906 printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-12s\n"
3918 cp = (const uint8_t *) u.req.info;
3920 const struct ieee80211req_sta_info *si;
3922 si = (const struct ieee80211req_sta_info *) cp;
3923 if (si->isi_len < sizeof(*si))
3925 if (opmode == IEEE80211_M_MBSS)
3926 printf("%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d"
3927 , ether_ntoa((const struct ether_addr*)
3929 , ieee80211_mhz2ieee(si->isi_freq,
3933 , mesh_linkstate_string(si->isi_peerstate)
3941 printf("%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-12.12s"
3942 , ether_ntoa((const struct ether_addr*)
3944 , IEEE80211_AID(si->isi_associd)
3945 , ieee80211_mhz2ieee(si->isi_freq,
3952 , getcaps(si->isi_capinfo)
3953 , getflags(si->isi_state)
3955 printies(cp + si->isi_ie_off, si->isi_ie_len, 24);
3956 printmimo(&si->isi_mimo);
3958 cp += si->isi_len, len -= si->isi_len;
3959 } while (len >= sizeof(struct ieee80211req_sta_info));
3963 mesh_linkstate_string(uint8_t state)
3965 static const char *state_names[] = {
3974 if (state >= nitems(state_names)) {
3975 static char buf[10];
3976 snprintf(buf, sizeof(buf), "#%u", state);
3979 return state_names[state];
3983 get_chaninfo(const struct ieee80211_channel *c, int precise,
3984 char buf[], size_t bsize)
3987 if (IEEE80211_IS_CHAN_FHSS(c))
3988 strlcat(buf, " FHSS", bsize);
3989 if (IEEE80211_IS_CHAN_A(c))
3990 strlcat(buf, " 11a", bsize);
3991 else if (IEEE80211_IS_CHAN_ANYG(c))
3992 strlcat(buf, " 11g", bsize);
3993 else if (IEEE80211_IS_CHAN_B(c))
3994 strlcat(buf, " 11b", bsize);
3995 if (IEEE80211_IS_CHAN_HALF(c))
3996 strlcat(buf, "/10MHz", bsize);
3997 if (IEEE80211_IS_CHAN_QUARTER(c))
3998 strlcat(buf, "/5MHz", bsize);
3999 if (IEEE80211_IS_CHAN_TURBO(c))
4000 strlcat(buf, " Turbo", bsize);
4002 if (IEEE80211_IS_CHAN_VHT80P80(c))
4003 strlcat(buf, " vht/80p80", bsize);
4004 else if (IEEE80211_IS_CHAN_VHT160(c))
4005 strlcat(buf, " vht/160", bsize);
4006 else if (IEEE80211_IS_CHAN_VHT80(c) &&
4007 IEEE80211_IS_CHAN_HT40D(c))
4008 strlcat(buf, " vht/80-", bsize);
4009 else if (IEEE80211_IS_CHAN_VHT80(c) &&
4010 IEEE80211_IS_CHAN_HT40U(c))
4011 strlcat(buf, " vht/80+", bsize);
4012 else if (IEEE80211_IS_CHAN_VHT80(c))
4013 strlcat(buf, " vht/80", bsize);
4014 else if (IEEE80211_IS_CHAN_VHT40D(c))
4015 strlcat(buf, " vht/40-", bsize);
4016 else if (IEEE80211_IS_CHAN_VHT40U(c))
4017 strlcat(buf, " vht/40+", bsize);
4018 else if (IEEE80211_IS_CHAN_VHT20(c))
4019 strlcat(buf, " vht/20", bsize);
4020 else if (IEEE80211_IS_CHAN_HT20(c))
4021 strlcat(buf, " ht/20", bsize);
4022 else if (IEEE80211_IS_CHAN_HT40D(c))
4023 strlcat(buf, " ht/40-", bsize);
4024 else if (IEEE80211_IS_CHAN_HT40U(c))
4025 strlcat(buf, " ht/40+", bsize);
4027 if (IEEE80211_IS_CHAN_VHT(c))
4028 strlcat(buf, " vht", bsize);
4029 else if (IEEE80211_IS_CHAN_HT(c))
4030 strlcat(buf, " ht", bsize);
4036 print_chaninfo(const struct ieee80211_channel *c, int verb)
4041 printf("Channel %3u : %u%c%c%c%c%c MHz%-14.14s",
4042 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
4043 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
4044 IEEE80211_IS_CHAN_DFS(c) ? 'D' : ' ',
4045 IEEE80211_IS_CHAN_RADAR(c) ? 'R' : ' ',
4046 IEEE80211_IS_CHAN_CWINT(c) ? 'I' : ' ',
4047 IEEE80211_IS_CHAN_CACDONE(c) ? 'C' : ' ',
4048 get_chaninfo(c, verb, buf, sizeof(buf)));
4050 printf("Channel %3u : %u%c MHz%-14.14s",
4051 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
4052 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
4053 get_chaninfo(c, verb, buf, sizeof(buf)));
4058 chanpref(const struct ieee80211_channel *c)
4061 if (IEEE80211_IS_CHAN_VHT80P80(c))
4063 if (IEEE80211_IS_CHAN_VHT160(c))
4065 if (IEEE80211_IS_CHAN_VHT80(c))
4067 if (IEEE80211_IS_CHAN_VHT40(c))
4069 if (IEEE80211_IS_CHAN_VHT20(c))
4071 if (IEEE80211_IS_CHAN_HT40(c))
4073 if (IEEE80211_IS_CHAN_HT20(c))
4075 if (IEEE80211_IS_CHAN_HALF(c))
4077 if (IEEE80211_IS_CHAN_QUARTER(c))
4079 if (IEEE80211_IS_CHAN_TURBO(c))
4081 if (IEEE80211_IS_CHAN_A(c))
4083 if (IEEE80211_IS_CHAN_G(c))
4085 if (IEEE80211_IS_CHAN_B(c))
4087 if (IEEE80211_IS_CHAN_PUREG(c))
4093 print_channels(int s, const struct ieee80211req_chaninfo *chans,
4094 int allchans, int verb)
4096 struct ieee80211req_chaninfo *achans;
4097 uint8_t reported[IEEE80211_CHAN_BYTES];
4098 const struct ieee80211_channel *c;
4101 achans = malloc(IEEE80211_CHANINFO_SPACE(chans));
4103 errx(1, "no space for active channel list");
4104 achans->ic_nchans = 0;
4105 memset(reported, 0, sizeof(reported));
4107 struct ieee80211req_chanlist active;
4109 if (get80211(s, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0)
4110 errx(1, "unable to get active channel list");
4111 for (i = 0; i < chans->ic_nchans; i++) {
4112 c = &chans->ic_chans[i];
4113 if (!isset(active.ic_channels, c->ic_ieee))
4116 * Suppress compatible duplicates unless
4117 * verbose. The kernel gives us it's
4118 * complete channel list which has separate
4119 * entries for 11g/11b and 11a/turbo.
4121 if (isset(reported, c->ic_ieee) && !verb) {
4122 /* XXX we assume duplicates are adjacent */
4123 achans->ic_chans[achans->ic_nchans-1] = *c;
4125 achans->ic_chans[achans->ic_nchans++] = *c;
4126 setbit(reported, c->ic_ieee);
4130 for (i = 0; i < chans->ic_nchans; i++) {
4131 c = &chans->ic_chans[i];
4132 /* suppress duplicates as above */
4133 if (isset(reported, c->ic_ieee) && !verb) {
4134 /* XXX we assume duplicates are adjacent */
4135 struct ieee80211_channel *a =
4136 &achans->ic_chans[achans->ic_nchans-1];
4137 if (chanpref(c) > chanpref(a))
4140 achans->ic_chans[achans->ic_nchans++] = *c;
4141 setbit(reported, c->ic_ieee);
4145 half = achans->ic_nchans / 2;
4146 if (achans->ic_nchans % 2)
4149 for (i = 0; i < achans->ic_nchans / 2; i++) {
4150 print_chaninfo(&achans->ic_chans[i], verb);
4151 print_chaninfo(&achans->ic_chans[half+i], verb);
4154 if (achans->ic_nchans % 2) {
4155 print_chaninfo(&achans->ic_chans[i], verb);
4162 list_channels(int s, int allchans)
4165 print_channels(s, chaninfo, allchans, verbose);
4169 print_txpow(const struct ieee80211_channel *c)
4171 printf("Channel %3u : %u MHz %3.1f reg %2d ",
4172 c->ic_ieee, c->ic_freq,
4173 c->ic_maxpower/2., c->ic_maxregpower);
4177 print_txpow_verbose(const struct ieee80211_channel *c)
4179 print_chaninfo(c, 1);
4180 printf("min %4.1f dBm max %3.1f dBm reg %2d dBm",
4181 c->ic_minpower/2., c->ic_maxpower/2., c->ic_maxregpower);
4182 /* indicate where regulatory cap limits power use */
4183 if (c->ic_maxpower > 2*c->ic_maxregpower)
4190 struct ieee80211req_chaninfo *achans;
4191 uint8_t reported[IEEE80211_CHAN_BYTES];
4192 struct ieee80211_channel *c, *prev;
4196 achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo));
4198 errx(1, "no space for active channel list");
4199 achans->ic_nchans = 0;
4200 memset(reported, 0, sizeof(reported));
4201 for (i = 0; i < chaninfo->ic_nchans; i++) {
4202 c = &chaninfo->ic_chans[i];
4203 /* suppress duplicates as above */
4204 if (isset(reported, c->ic_ieee) && !verbose) {
4205 /* XXX we assume duplicates are adjacent */
4206 assert(achans->ic_nchans > 0);
4207 prev = &achans->ic_chans[achans->ic_nchans-1];
4208 /* display highest power on channel */
4209 if (c->ic_maxpower > prev->ic_maxpower)
4212 achans->ic_chans[achans->ic_nchans++] = *c;
4213 setbit(reported, c->ic_ieee);
4217 half = achans->ic_nchans / 2;
4218 if (achans->ic_nchans % 2)
4221 for (i = 0; i < achans->ic_nchans / 2; i++) {
4222 print_txpow(&achans->ic_chans[i]);
4223 print_txpow(&achans->ic_chans[half+i]);
4226 if (achans->ic_nchans % 2) {
4227 print_txpow(&achans->ic_chans[i]);
4231 for (i = 0; i < achans->ic_nchans; i++) {
4232 print_txpow_verbose(&achans->ic_chans[i]);
4245 list_capabilities(int s)
4247 struct ieee80211_devcaps_req *dc;
4250 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
4252 dc = malloc(IEEE80211_DEVCAPS_SIZE(1));
4254 errx(1, "no space for device capabilities");
4255 dc->dc_chaninfo.ic_nchans = verbose ? MAXCHAN : 1;
4257 printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS);
4258 if (dc->dc_cryptocaps != 0 || verbose) {
4260 printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS);
4262 if (dc->dc_htcaps != 0 || verbose) {
4264 printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS);
4266 if (dc->dc_vhtcaps != 0 || verbose) {
4268 printb("vhtcaps", dc->dc_vhtcaps, IEEE80211_VHTCAP_BITS);
4273 chaninfo = &dc->dc_chaninfo; /* XXX */
4274 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, verbose);
4280 get80211wme(int s, int param, int ac, int *val)
4282 struct ieee80211req ireq;
4284 (void) memset(&ireq, 0, sizeof(ireq));
4285 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4286 ireq.i_type = param;
4288 if (ioctl(s, SIOCG80211, &ireq) < 0) {
4289 warn("cannot get WME parameter %d, ac %d%s",
4290 param, ac & IEEE80211_WMEPARAM_VAL,
4291 ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : "");
4299 list_wme_aci(int s, const char *tag, int ac)
4303 printf("\t%s", tag);
4305 /* show WME BSS parameters */
4306 if (get80211wme(s, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1)
4307 printf(" cwmin %2u", val);
4308 if (get80211wme(s, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1)
4309 printf(" cwmax %2u", val);
4310 if (get80211wme(s, IEEE80211_IOC_WME_AIFS, ac, &val) != -1)
4311 printf(" aifs %2u", val);
4312 if (get80211wme(s, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1)
4313 printf(" txopLimit %3u", val);
4314 if (get80211wme(s, IEEE80211_IOC_WME_ACM, ac, &val) != -1) {
4321 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
4322 if (get80211wme(s, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) {
4335 static const char *acnames[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
4339 /* display both BSS and local settings */
4340 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) {
4342 if (ac & IEEE80211_WMEPARAM_BSS)
4343 list_wme_aci(s, " ", ac);
4345 list_wme_aci(s, acnames[ac], ac);
4346 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
4347 ac |= IEEE80211_WMEPARAM_BSS;
4350 ac &= ~IEEE80211_WMEPARAM_BSS;
4353 /* display only channel settings */
4354 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++)
4355 list_wme_aci(s, acnames[ac], ac);
4362 const struct ieee80211_roamparam *rp;
4366 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
4367 rp = &roamparams.params[mode];
4368 if (rp->rssi == 0 && rp->rate == 0)
4370 if (mode == IEEE80211_MODE_11NA ||
4371 mode == IEEE80211_MODE_11NG ||
4372 mode == IEEE80211_MODE_VHT_2GHZ ||
4373 mode == IEEE80211_MODE_VHT_5GHZ) {
4375 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm MCS %2u ",
4376 modename[mode], rp->rssi/2,
4377 rp->rate &~ IEEE80211_RATE_MCS);
4379 LINE_CHECK("roam:%-7.7s rssi %4udBm MCS %2u ",
4380 modename[mode], rp->rssi/2,
4381 rp->rate &~ IEEE80211_RATE_MCS);
4384 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s",
4385 modename[mode], rp->rssi/2, rp->rate/2);
4387 LINE_CHECK("roam:%-7.7s rssi %4udBm rate %2u Mb/s",
4388 modename[mode], rp->rssi/2, rp->rate/2);
4393 /* XXX TODO: rate-to-string method... */
4395 get_mcs_mbs_rate_str(uint8_t rate)
4397 return (rate & IEEE80211_RATE_MCS) ? "MCS " : "Mb/s";
4401 get_rate_value(uint8_t rate)
4403 if (rate & IEEE80211_RATE_MCS)
4404 return (rate &~ IEEE80211_RATE_MCS);
4409 list_txparams(int s)
4411 const struct ieee80211_txparam *tp;
4415 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
4416 tp = &txparams.params[mode];
4417 if (tp->mgmtrate == 0 && tp->mcastrate == 0)
4419 if (mode == IEEE80211_MODE_11NA ||
4420 mode == IEEE80211_MODE_11NG ||
4421 mode == IEEE80211_MODE_VHT_2GHZ ||
4422 mode == IEEE80211_MODE_VHT_5GHZ) {
4423 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
4424 LINE_CHECK("%-7.7s ucast NONE mgmt %2u %s "
4425 "mcast %2u %s maxretry %u",
4427 get_rate_value(tp->mgmtrate),
4428 get_mcs_mbs_rate_str(tp->mgmtrate),
4429 get_rate_value(tp->mcastrate),
4430 get_mcs_mbs_rate_str(tp->mcastrate),
4433 LINE_CHECK("%-7.7s ucast %2u MCS mgmt %2u %s "
4434 "mcast %2u %s maxretry %u",
4436 tp->ucastrate &~ IEEE80211_RATE_MCS,
4437 get_rate_value(tp->mgmtrate),
4438 get_mcs_mbs_rate_str(tp->mgmtrate),
4439 get_rate_value(tp->mcastrate),
4440 get_mcs_mbs_rate_str(tp->mcastrate),
4443 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
4444 LINE_CHECK("%-7.7s ucast NONE mgmt %2u Mb/s "
4445 "mcast %2u Mb/s maxretry %u",
4448 tp->mcastrate/2, tp->maxretry);
4450 LINE_CHECK("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s "
4451 "mcast %2u Mb/s maxretry %u",
4453 tp->ucastrate/2, tp->mgmtrate/2,
4454 tp->mcastrate/2, tp->maxretry);
4460 printpolicy(int policy)
4463 case IEEE80211_MACCMD_POLICY_OPEN:
4464 printf("policy: open\n");
4466 case IEEE80211_MACCMD_POLICY_ALLOW:
4467 printf("policy: allow\n");
4469 case IEEE80211_MACCMD_POLICY_DENY:
4470 printf("policy: deny\n");
4472 case IEEE80211_MACCMD_POLICY_RADIUS:
4473 printf("policy: radius\n");
4476 printf("policy: unknown (%u)\n", policy);
4484 struct ieee80211req ireq;
4485 struct ieee80211req_maclist *acllist;
4486 int i, nacls, policy, len;
4490 (void) memset(&ireq, 0, sizeof(ireq));
4491 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name)); /* XXX ?? */
4492 ireq.i_type = IEEE80211_IOC_MACCMD;
4493 ireq.i_val = IEEE80211_MACCMD_POLICY;
4494 if (ioctl(s, SIOCG80211, &ireq) < 0) {
4495 if (errno == EINVAL) {
4496 printf("No acl policy loaded\n");
4499 err(1, "unable to get mac policy");
4501 policy = ireq.i_val;
4502 if (policy == IEEE80211_MACCMD_POLICY_OPEN) {
4504 } else if (policy == IEEE80211_MACCMD_POLICY_ALLOW) {
4506 } else if (policy == IEEE80211_MACCMD_POLICY_DENY) {
4508 } else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) {
4509 c = 'r'; /* NB: should never have entries */
4511 printf("policy: unknown (%u)\n", policy);
4514 if (verbose || c == '?')
4515 printpolicy(policy);
4517 ireq.i_val = IEEE80211_MACCMD_LIST;
4519 if (ioctl(s, SIOCG80211, &ireq) < 0)
4520 err(1, "unable to get mac acl list size");
4521 if (ireq.i_len == 0) { /* NB: no acls */
4522 if (!(verbose || c == '?'))
4523 printpolicy(policy);
4530 err(1, "out of memory for acl list");
4533 if (ioctl(s, SIOCG80211, &ireq) < 0)
4534 err(1, "unable to get mac acl list");
4535 nacls = len / sizeof(*acllist);
4536 acllist = (struct ieee80211req_maclist *) data;
4537 for (i = 0; i < nacls; i++)
4538 printf("%c%s\n", c, ether_ntoa(
4539 (const struct ether_addr *) acllist[i].ml_macaddr));
4544 print_regdomain(const struct ieee80211_regdomain *reg, int verb)
4546 if ((reg->regdomain != 0 &&
4547 reg->regdomain != reg->country) || verb) {
4548 const struct regdomain *rd =
4549 lib80211_regdomain_findbysku(getregdata(), reg->regdomain);
4551 LINE_CHECK("regdomain %d", reg->regdomain);
4553 LINE_CHECK("regdomain %s", rd->name);
4555 if (reg->country != 0 || verb) {
4556 const struct country *cc =
4557 lib80211_country_findbycc(getregdata(), reg->country);
4559 LINE_CHECK("country %d", reg->country);
4561 LINE_CHECK("country %s", cc->isoname);
4563 if (reg->location == 'I')
4564 LINE_CHECK("indoor");
4565 else if (reg->location == 'O')
4566 LINE_CHECK("outdoor");
4568 LINE_CHECK("anywhere");
4576 list_regdomain(int s, int channelsalso)
4582 print_regdomain(®domain, 1);
4584 print_channels(s, chaninfo, 1/*allchans*/, 1/*verbose*/);
4586 print_regdomain(®domain, verbose);
4592 struct ieee80211req ireq;
4593 struct ieee80211req_mesh_route routes[128];
4594 struct ieee80211req_mesh_route *rt;
4596 (void) memset(&ireq, 0, sizeof(ireq));
4597 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4598 ireq.i_type = IEEE80211_IOC_MESH_RTCMD;
4599 ireq.i_val = IEEE80211_MESH_RTCMD_LIST;
4600 ireq.i_data = &routes;
4601 ireq.i_len = sizeof(routes);
4602 if (ioctl(s, SIOCG80211, &ireq) < 0)
4603 err(1, "unable to get the Mesh routing table");
4605 printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n"
4614 for (rt = &routes[0]; rt - &routes[0] < ireq.i_len / sizeof(*rt); rt++){
4616 ether_ntoa((const struct ether_addr *)rt->imr_dest));
4617 printf("%s %4u %4u %6u %6u %c%c\n",
4618 ether_ntoa((const struct ether_addr *)rt->imr_nexthop),
4619 rt->imr_nhops, rt->imr_metric, rt->imr_lifetime,
4621 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_DISCOVER) ?
4623 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_VALID) ?
4625 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ?
4627 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_GATE) ?
4633 DECL_CMD_FUNC(set80211list, arg, d)
4635 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
4639 if (iseq(arg, "sta"))
4641 else if (iseq(arg, "scan") || iseq(arg, "ap"))
4643 else if (iseq(arg, "chan") || iseq(arg, "freq"))
4644 list_channels(s, 1);
4645 else if (iseq(arg, "active"))
4646 list_channels(s, 0);
4647 else if (iseq(arg, "keys"))
4649 else if (iseq(arg, "caps"))
4650 list_capabilities(s);
4651 else if (iseq(arg, "wme") || iseq(arg, "wmm"))
4653 else if (iseq(arg, "mac"))
4655 else if (iseq(arg, "txpow"))
4657 else if (iseq(arg, "roam"))
4659 else if (iseq(arg, "txparam") || iseq(arg, "txparm"))
4661 else if (iseq(arg, "regdomain"))
4662 list_regdomain(s, 1);
4663 else if (iseq(arg, "countries"))
4665 else if (iseq(arg, "mesh"))
4668 errx(1, "Don't know how to list %s for %s", arg, name);
4673 static enum ieee80211_opmode
4674 get80211opmode(int s)
4676 struct ifmediareq ifmr;
4678 (void) memset(&ifmr, 0, sizeof(ifmr));
4679 (void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
4681 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) {
4682 if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) {
4683 if (ifmr.ifm_current & IFM_FLAG0)
4684 return IEEE80211_M_AHDEMO;
4686 return IEEE80211_M_IBSS;
4688 if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP)
4689 return IEEE80211_M_HOSTAP;
4690 if (ifmr.ifm_current & IFM_IEEE80211_IBSS)
4691 return IEEE80211_M_IBSS;
4692 if (ifmr.ifm_current & IFM_IEEE80211_MONITOR)
4693 return IEEE80211_M_MONITOR;
4694 if (ifmr.ifm_current & IFM_IEEE80211_MBSS)
4695 return IEEE80211_M_MBSS;
4697 return IEEE80211_M_STA;
4702 printcipher(int s, struct ieee80211req *ireq, int keylenop)
4704 switch (ireq->i_val) {
4705 case IEEE80211_CIPHER_WEP:
4706 ireq->i_type = keylenop;
4707 if (ioctl(s, SIOCG80211, ireq) != -1)
4709 ireq->i_len <= 5 ? "40" :
4710 ireq->i_len <= 13 ? "104" : "128");
4714 case IEEE80211_CIPHER_TKIP:
4717 case IEEE80211_CIPHER_AES_OCB:
4720 case IEEE80211_CIPHER_AES_CCM:
4723 case IEEE80211_CIPHER_CKIP:
4726 case IEEE80211_CIPHER_NONE:
4730 printf("UNKNOWN (0x%x)", ireq->i_val);
4737 printkey(const struct ieee80211req_key *ik)
4739 static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
4740 u_int keylen = ik->ik_keylen;
4743 printcontents = printkeys &&
4744 (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose);
4747 switch (ik->ik_type) {
4748 case IEEE80211_CIPHER_WEP:
4750 LINE_CHECK("wepkey %u:%s", ik->ik_keyix+1,
4751 keylen <= 5 ? "40-bit" :
4752 keylen <= 13 ? "104-bit" : "128-bit");
4754 case IEEE80211_CIPHER_TKIP:
4756 keylen -= 128/8; /* ignore MIC for now */
4757 LINE_CHECK("TKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4759 case IEEE80211_CIPHER_AES_OCB:
4760 LINE_CHECK("AES-OCB %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4762 case IEEE80211_CIPHER_AES_CCM:
4763 LINE_CHECK("AES-CCM %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4765 case IEEE80211_CIPHER_CKIP:
4766 LINE_CHECK("CKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4768 case IEEE80211_CIPHER_NONE:
4769 LINE_CHECK("NULL %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4772 LINE_CHECK("UNKNOWN (0x%x) %u:%u-bit",
4773 ik->ik_type, ik->ik_keyix+1, 8*keylen);
4776 if (printcontents) {
4780 for (i = 0; i < keylen; i++)
4781 printf("%02x", ik->ik_keydata[i]);
4783 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4784 (ik->ik_keyrsc != 0 || verbose))
4785 printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc);
4786 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4787 (ik->ik_keytsc != 0 || verbose))
4788 printf(" tsc %ju", (uintmax_t)ik->ik_keytsc);
4789 if (ik->ik_flags != 0 && verbose) {
4790 const char *sep = " ";
4792 if (ik->ik_flags & IEEE80211_KEY_XMIT)
4793 printf("%stx", sep), sep = "+";
4794 if (ik->ik_flags & IEEE80211_KEY_RECV)
4795 printf("%srx", sep), sep = "+";
4796 if (ik->ik_flags & IEEE80211_KEY_DEFAULT)
4797 printf("%sdef", sep), sep = "+";
4804 printrate(const char *tag, int v, int defrate, int defmcs)
4806 if ((v & IEEE80211_RATE_MCS) == 0) {
4809 LINE_CHECK("%s %d.5", tag, v/2);
4811 LINE_CHECK("%s %d", tag, v/2);
4815 LINE_CHECK("%s %d", tag, v &~ 0x80);
4820 getid(int s, int ix, void *data, size_t len, int *plen, int mesh)
4822 struct ieee80211req ireq;
4824 (void) memset(&ireq, 0, sizeof(ireq));
4825 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4826 ireq.i_type = (!mesh) ? IEEE80211_IOC_SSID : IEEE80211_IOC_MESH_ID;
4830 if (ioctl(s, SIOCG80211, &ireq) < 0)
4837 getdevicename(int s, void *data, size_t len, int *plen)
4839 struct ieee80211req ireq;
4841 (void) memset(&ireq, 0, sizeof(ireq));
4842 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4843 ireq.i_type = IEEE80211_IOC_IC_NAME;
4847 if (ioctl(s, SIOCG80211, &ireq) < 0)
4854 ieee80211_status(int s)
4856 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
4857 enum ieee80211_opmode opmode = get80211opmode(s);
4858 int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode;
4860 const struct ieee80211_channel *c;
4861 const struct ieee80211_roamparam *rp;
4862 const struct ieee80211_txparam *tp;
4864 if (getid(s, -1, data, sizeof(data), &len, 0) < 0) {
4865 /* If we can't get the SSID, this isn't an 802.11 device. */
4870 * Invalidate cached state so printing status for multiple
4871 * if's doesn't reuse the first interfaces' cached state.
4880 if (opmode == IEEE80211_M_MBSS) {
4882 getid(s, 0, data, sizeof(data), &len, 1);
4883 print_string(data, len);
4885 if (get80211val(s, IEEE80211_IOC_NUMSSIDS, &num) < 0)
4889 for (i = 0; i < num; i++) {
4890 if (getid(s, i, data, sizeof(data), &len, 0) >= 0 && len > 0) {
4891 printf(" %d:", i + 1);
4892 print_string(data, len);
4896 print_string(data, len);
4899 if (c->ic_freq != IEEE80211_CHAN_ANY) {
4901 printf(" channel %d (%u MHz%s)", c->ic_ieee, c->ic_freq,
4902 get_chaninfo(c, 1, buf, sizeof(buf)));
4904 printf(" channel UNDEF");
4906 if (get80211(s, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 &&
4907 (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose))
4908 printf(" bssid %s", ether_ntoa((struct ether_addr *)data));
4910 if (get80211len(s, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) {
4911 printf("\n\tstationname ");
4912 print_string(data, len);
4915 spacer = ' '; /* force first break */
4918 list_regdomain(s, 0);
4921 if (get80211val(s, IEEE80211_IOC_AUTHMODE, &val) != -1) {
4923 case IEEE80211_AUTH_NONE:
4924 LINE_CHECK("authmode NONE");
4926 case IEEE80211_AUTH_OPEN:
4927 LINE_CHECK("authmode OPEN");
4929 case IEEE80211_AUTH_SHARED:
4930 LINE_CHECK("authmode SHARED");
4932 case IEEE80211_AUTH_8021X:
4933 LINE_CHECK("authmode 802.1x");
4935 case IEEE80211_AUTH_WPA:
4936 if (get80211val(s, IEEE80211_IOC_WPA, &wpa) < 0)
4937 wpa = 1; /* default to WPA1 */
4940 LINE_CHECK("authmode WPA2/802.11i");
4943 LINE_CHECK("authmode WPA1+WPA2/802.11i");
4946 LINE_CHECK("authmode WPA");
4950 case IEEE80211_AUTH_AUTO:
4951 LINE_CHECK("authmode AUTO");
4954 LINE_CHECK("authmode UNKNOWN (0x%x)", val);
4959 if (wpa || verbose) {
4960 if (get80211val(s, IEEE80211_IOC_WPS, &val) != -1) {
4966 if (get80211val(s, IEEE80211_IOC_TSN, &val) != -1) {
4972 if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) {
4974 LINE_CHECK("countermeasures");
4976 LINE_CHECK("-countermeasures");
4979 /* XXX not interesting with WPA done in user space */
4980 ireq.i_type = IEEE80211_IOC_KEYMGTALGS;
4981 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4984 ireq.i_type = IEEE80211_IOC_MCASTCIPHER;
4985 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4986 LINE_CHECK("mcastcipher ");
4987 printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN);
4991 ireq.i_type = IEEE80211_IOC_UCASTCIPHER;
4992 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4993 LINE_CHECK("ucastcipher ");
4994 printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN);
4998 ireq.i_type = IEEE80211_IOC_RSNCAPS;
4999 if (ioctl(s, SIOCG80211, &ireq) != -1) {
5000 LINE_CHECK("RSN caps 0x%x", ireq.i_val);
5005 ireq.i_type = IEEE80211_IOC_UCASTCIPHERS;
5006 if (ioctl(s, SIOCG80211, &ireq) != -1) {
5011 if (get80211val(s, IEEE80211_IOC_WEP, &wepmode) != -1 &&
5012 wepmode != IEEE80211_WEP_NOSUP) {
5015 case IEEE80211_WEP_OFF:
5016 LINE_CHECK("privacy OFF");
5018 case IEEE80211_WEP_ON:
5019 LINE_CHECK("privacy ON");
5021 case IEEE80211_WEP_MIXED:
5022 LINE_CHECK("privacy MIXED");
5025 LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode);
5030 * If we get here then we've got WEP support so we need
5031 * to print WEP status.
5034 if (get80211val(s, IEEE80211_IOC_WEPTXKEY, &val) < 0) {
5035 warn("WEP support, but no tx key!");
5039 LINE_CHECK("deftxkey %d", val+1);
5040 else if (wepmode != IEEE80211_WEP_OFF || verbose)
5041 LINE_CHECK("deftxkey UNDEF");
5043 if (get80211val(s, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) {
5044 warn("WEP support, but no NUMWEPKEYS support!");
5048 for (i = 0; i < num; i++) {
5049 struct ieee80211req_key ik;
5051 memset(&ik, 0, sizeof(ik));
5053 if (get80211(s, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) {
5054 warn("WEP support, but can get keys!");
5057 if (ik.ik_keylen != 0) {
5067 if (get80211val(s, IEEE80211_IOC_POWERSAVE, &val) != -1 &&
5068 val != IEEE80211_POWERSAVE_NOSUP ) {
5069 if (val != IEEE80211_POWERSAVE_OFF || verbose) {
5071 case IEEE80211_POWERSAVE_OFF:
5072 LINE_CHECK("powersavemode OFF");
5074 case IEEE80211_POWERSAVE_CAM:
5075 LINE_CHECK("powersavemode CAM");
5077 case IEEE80211_POWERSAVE_PSP:
5078 LINE_CHECK("powersavemode PSP");
5080 case IEEE80211_POWERSAVE_PSP_CAM:
5081 LINE_CHECK("powersavemode PSP-CAM");
5084 if (get80211val(s, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1)
5085 LINE_CHECK("powersavesleep %d", val);
5089 if (get80211val(s, IEEE80211_IOC_TXPOWER, &val) != -1) {
5091 LINE_CHECK("txpower %d.5", val/2);
5093 LINE_CHECK("txpower %d", val/2);
5096 if (get80211val(s, IEEE80211_IOC_TXPOWMAX, &val) != -1)
5097 LINE_CHECK("txpowmax %.1f", val/2.);
5100 if (get80211val(s, IEEE80211_IOC_DOTD, &val) != -1) {
5104 LINE_CHECK("-dotd");
5107 if (get80211val(s, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) {
5108 if (val != IEEE80211_RTS_MAX || verbose)
5109 LINE_CHECK("rtsthreshold %d", val);
5112 if (get80211val(s, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) {
5113 if (val != IEEE80211_FRAG_MAX || verbose)
5114 LINE_CHECK("fragthreshold %d", val);
5116 if (opmode == IEEE80211_M_STA || verbose) {
5117 if (get80211val(s, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) {
5118 if (val != IEEE80211_HWBMISS_MAX || verbose)
5119 LINE_CHECK("bmiss %d", val);
5125 tp = &txparams.params[chan2mode(c)];
5126 printrate("ucastrate", tp->ucastrate,
5127 IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE);
5128 printrate("mcastrate", tp->mcastrate, 2*1,
5129 IEEE80211_RATE_MCS|0);
5130 printrate("mgmtrate", tp->mgmtrate, 2*1,
5131 IEEE80211_RATE_MCS|0);
5132 if (tp->maxretry != 6) /* XXX */
5133 LINE_CHECK("maxretry %d", tp->maxretry);
5139 bgscaninterval = -1;
5140 (void) get80211val(s, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval);
5142 if (get80211val(s, IEEE80211_IOC_SCANVALID, &val) != -1) {
5143 if (val != bgscaninterval || verbose)
5144 LINE_CHECK("scanvalid %u", val);
5148 if (get80211val(s, IEEE80211_IOC_BGSCAN, &bgscan) != -1) {
5150 LINE_CHECK("bgscan");
5152 LINE_CHECK("-bgscan");
5154 if (bgscan || verbose) {
5155 if (bgscaninterval != -1)
5156 LINE_CHECK("bgscanintvl %u", bgscaninterval);
5157 if (get80211val(s, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1)
5158 LINE_CHECK("bgscanidle %u", val);
5161 rp = &roamparams.params[chan2mode(c)];
5163 LINE_CHECK("roam:rssi %u.5", rp->rssi/2);
5165 LINE_CHECK("roam:rssi %u", rp->rssi/2);
5166 LINE_CHECK("roam:rate %s%u",
5167 (rp->rate & IEEE80211_RATE_MCS) ? "MCS " : "",
5168 get_rate_value(rp->rate));
5176 if (IEEE80211_IS_CHAN_ANYG(c) || verbose) {
5177 if (get80211val(s, IEEE80211_IOC_PUREG, &val) != -1) {
5179 LINE_CHECK("pureg");
5181 LINE_CHECK("-pureg");
5183 if (get80211val(s, IEEE80211_IOC_PROTMODE, &val) != -1) {
5185 case IEEE80211_PROTMODE_OFF:
5186 LINE_CHECK("protmode OFF");
5188 case IEEE80211_PROTMODE_CTS:
5189 LINE_CHECK("protmode CTS");
5191 case IEEE80211_PROTMODE_RTSCTS:
5192 LINE_CHECK("protmode RTSCTS");
5195 LINE_CHECK("protmode UNKNOWN (0x%x)", val);
5201 if (IEEE80211_IS_CHAN_HT(c) || verbose) {
5203 switch (htconf & 3) {
5216 if (get80211val(s, IEEE80211_IOC_HTCOMPAT, &val) != -1) {
5218 LINE_CHECK("-htcompat");
5220 LINE_CHECK("htcompat");
5222 if (get80211val(s, IEEE80211_IOC_AMPDU, &val) != -1) {
5225 LINE_CHECK("-ampdu");
5228 LINE_CHECK("ampdutx -ampdurx");
5231 LINE_CHECK("-ampdutx ampdurx");
5235 LINE_CHECK("ampdu");
5239 /* XXX 11ac density/size is different */
5240 if (get80211val(s, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) {
5242 case IEEE80211_HTCAP_MAXRXAMPDU_8K:
5243 LINE_CHECK("ampdulimit 8k");
5245 case IEEE80211_HTCAP_MAXRXAMPDU_16K:
5246 LINE_CHECK("ampdulimit 16k");
5248 case IEEE80211_HTCAP_MAXRXAMPDU_32K:
5249 LINE_CHECK("ampdulimit 32k");
5251 case IEEE80211_HTCAP_MAXRXAMPDU_64K:
5252 LINE_CHECK("ampdulimit 64k");
5256 /* XXX 11ac density/size is different */
5257 if (get80211val(s, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) {
5259 case IEEE80211_HTCAP_MPDUDENSITY_NA:
5261 LINE_CHECK("ampdudensity NA");
5263 case IEEE80211_HTCAP_MPDUDENSITY_025:
5264 LINE_CHECK("ampdudensity .25");
5266 case IEEE80211_HTCAP_MPDUDENSITY_05:
5267 LINE_CHECK("ampdudensity .5");
5269 case IEEE80211_HTCAP_MPDUDENSITY_1:
5270 LINE_CHECK("ampdudensity 1");
5272 case IEEE80211_HTCAP_MPDUDENSITY_2:
5273 LINE_CHECK("ampdudensity 2");
5275 case IEEE80211_HTCAP_MPDUDENSITY_4:
5276 LINE_CHECK("ampdudensity 4");
5278 case IEEE80211_HTCAP_MPDUDENSITY_8:
5279 LINE_CHECK("ampdudensity 8");
5281 case IEEE80211_HTCAP_MPDUDENSITY_16:
5282 LINE_CHECK("ampdudensity 16");
5286 if (get80211val(s, IEEE80211_IOC_AMSDU, &val) != -1) {
5289 LINE_CHECK("-amsdu");
5292 LINE_CHECK("amsdutx -amsdurx");
5295 LINE_CHECK("-amsdutx amsdurx");
5299 LINE_CHECK("amsdu");
5303 /* XXX amsdu limit */
5304 if (get80211val(s, IEEE80211_IOC_SHORTGI, &val) != -1) {
5306 LINE_CHECK("shortgi");
5308 LINE_CHECK("-shortgi");
5310 if (get80211val(s, IEEE80211_IOC_HTPROTMODE, &val) != -1) {
5311 if (val == IEEE80211_PROTMODE_OFF)
5312 LINE_CHECK("htprotmode OFF");
5313 else if (val != IEEE80211_PROTMODE_RTSCTS)
5314 LINE_CHECK("htprotmode UNKNOWN (0x%x)", val);
5316 LINE_CHECK("htprotmode RTSCTS");
5318 if (get80211val(s, IEEE80211_IOC_PUREN, &val) != -1) {
5320 LINE_CHECK("puren");
5322 LINE_CHECK("-puren");
5324 if (get80211val(s, IEEE80211_IOC_SMPS, &val) != -1) {
5325 if (val == IEEE80211_HTCAP_SMPS_DYNAMIC)
5326 LINE_CHECK("smpsdyn");
5327 else if (val == IEEE80211_HTCAP_SMPS_ENA)
5330 LINE_CHECK("-smps");
5332 if (get80211val(s, IEEE80211_IOC_RIFS, &val) != -1) {
5336 LINE_CHECK("-rifs");
5340 if (get80211val(s, IEEE80211_IOC_STBC, &val) != -1) {
5343 LINE_CHECK("-stbc");
5346 LINE_CHECK("stbctx -stbcrx");
5349 LINE_CHECK("-stbctx stbcrx");
5357 if (get80211val(s, IEEE80211_IOC_LDPC, &val) != -1) {
5360 LINE_CHECK("-ldpc");
5363 LINE_CHECK("ldpctx -ldpcrx");
5366 LINE_CHECK("-ldpctx ldpcrx");
5374 if (get80211val(s, IEEE80211_IOC_UAPSD, &val) != -1) {
5377 LINE_CHECK("-uapsd");
5380 LINE_CHECK("uapsd");
5386 if (IEEE80211_IS_CHAN_VHT(c) || verbose) {
5388 if (vhtconf & IEEE80211_FVHT_VHT)
5392 if (vhtconf & IEEE80211_FVHT_USEVHT40)
5393 LINE_CHECK("vht40");
5395 LINE_CHECK("-vht40");
5396 if (vhtconf & IEEE80211_FVHT_USEVHT80)
5397 LINE_CHECK("vht80");
5399 LINE_CHECK("-vht80");
5400 if (vhtconf & IEEE80211_FVHT_USEVHT160)
5401 LINE_CHECK("vht160");
5403 LINE_CHECK("-vht160");
5404 if (vhtconf & IEEE80211_FVHT_USEVHT80P80)
5405 LINE_CHECK("vht80p80");
5407 LINE_CHECK("-vht80p80");
5410 if (get80211val(s, IEEE80211_IOC_WME, &wme) != -1) {
5418 if (get80211val(s, IEEE80211_IOC_BURST, &val) != -1) {
5420 LINE_CHECK("burst");
5422 LINE_CHECK("-burst");
5425 if (get80211val(s, IEEE80211_IOC_FF, &val) != -1) {
5431 if (get80211val(s, IEEE80211_IOC_TURBOP, &val) != -1) {
5433 LINE_CHECK("dturbo");
5435 LINE_CHECK("-dturbo");
5437 if (get80211val(s, IEEE80211_IOC_DWDS, &val) != -1) {
5441 LINE_CHECK("-dwds");
5444 if (opmode == IEEE80211_M_HOSTAP) {
5445 if (get80211val(s, IEEE80211_IOC_HIDESSID, &val) != -1) {
5447 LINE_CHECK("hidessid");
5449 LINE_CHECK("-hidessid");
5451 if (get80211val(s, IEEE80211_IOC_APBRIDGE, &val) != -1) {
5453 LINE_CHECK("-apbridge");
5455 LINE_CHECK("apbridge");
5457 if (get80211val(s, IEEE80211_IOC_DTIM_PERIOD, &val) != -1)
5458 LINE_CHECK("dtimperiod %u", val);
5460 if (get80211val(s, IEEE80211_IOC_DOTH, &val) != -1) {
5462 LINE_CHECK("-doth");
5466 if (get80211val(s, IEEE80211_IOC_DFS, &val) != -1) {
5472 if (get80211val(s, IEEE80211_IOC_INACTIVITY, &val) != -1) {
5474 LINE_CHECK("-inact");
5476 LINE_CHECK("inact");
5479 if (get80211val(s, IEEE80211_IOC_ROAMING, &val) != -1) {
5480 if (val != IEEE80211_ROAMING_AUTO || verbose) {
5482 case IEEE80211_ROAMING_DEVICE:
5483 LINE_CHECK("roaming DEVICE");
5485 case IEEE80211_ROAMING_AUTO:
5486 LINE_CHECK("roaming AUTO");
5488 case IEEE80211_ROAMING_MANUAL:
5489 LINE_CHECK("roaming MANUAL");
5492 LINE_CHECK("roaming UNKNOWN (0x%x)",
5500 if (opmode == IEEE80211_M_AHDEMO) {
5501 if (get80211val(s, IEEE80211_IOC_TDMA_SLOT, &val) != -1)
5502 LINE_CHECK("tdmaslot %u", val);
5503 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1)
5504 LINE_CHECK("tdmaslotcnt %u", val);
5505 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1)
5506 LINE_CHECK("tdmaslotlen %u", val);
5507 if (get80211val(s, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1)
5508 LINE_CHECK("tdmabintval %u", val);
5509 } else if (get80211val(s, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) {
5510 /* XXX default define not visible */
5511 if (val != 100 || verbose)
5512 LINE_CHECK("bintval %u", val);
5515 if (wme && verbose) {
5520 if (opmode == IEEE80211_M_MBSS) {
5521 if (get80211val(s, IEEE80211_IOC_MESH_TTL, &val) != -1) {
5522 LINE_CHECK("meshttl %u", val);
5524 if (get80211val(s, IEEE80211_IOC_MESH_AP, &val) != -1) {
5526 LINE_CHECK("meshpeering");
5528 LINE_CHECK("-meshpeering");
5530 if (get80211val(s, IEEE80211_IOC_MESH_FWRD, &val) != -1) {
5532 LINE_CHECK("meshforward");
5534 LINE_CHECK("-meshforward");
5536 if (get80211val(s, IEEE80211_IOC_MESH_GATE, &val) != -1) {
5538 LINE_CHECK("meshgate");
5540 LINE_CHECK("-meshgate");
5542 if (get80211len(s, IEEE80211_IOC_MESH_PR_METRIC, data, 12,
5545 LINE_CHECK("meshmetric %s", data);
5547 if (get80211len(s, IEEE80211_IOC_MESH_PR_PATH, data, 12,
5550 LINE_CHECK("meshpath %s", data);
5552 if (get80211val(s, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) {
5554 case IEEE80211_HWMP_ROOTMODE_DISABLED:
5555 LINE_CHECK("hwmprootmode DISABLED");
5557 case IEEE80211_HWMP_ROOTMODE_NORMAL:
5558 LINE_CHECK("hwmprootmode NORMAL");
5560 case IEEE80211_HWMP_ROOTMODE_PROACTIVE:
5561 LINE_CHECK("hwmprootmode PROACTIVE");
5563 case IEEE80211_HWMP_ROOTMODE_RANN:
5564 LINE_CHECK("hwmprootmode RANN");
5567 LINE_CHECK("hwmprootmode UNKNOWN(%d)", val);
5571 if (get80211val(s, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) {
5572 LINE_CHECK("hwmpmaxhops %u", val);
5578 if (getdevicename(s, data, sizeof(data), &len) < 0)
5580 LINE_CHECK("parent interface: %s", data);
5586 get80211(int s, int type, void *data, int len)
5589 return (lib80211_get80211(s, name, type, data, len));
5593 get80211len(int s, int type, void *data, int len, int *plen)
5596 return (lib80211_get80211len(s, name, type, data, len, plen));
5600 get80211val(int s, int type, int *val)
5603 return (lib80211_get80211val(s, name, type, val));
5607 set80211(int s, int type, int val, int len, void *data)
5611 ret = lib80211_set80211(s, name, type, val, len, data);
5613 err(1, "SIOCS80211");
5617 get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
5625 hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x');
5631 if (sep != NULL && strchr(sep, *val) != NULL) {
5636 if (!isxdigit((u_char)val[0])) {
5637 warnx("bad hexadecimal digits");
5640 if (!isxdigit((u_char)val[1])) {
5641 warnx("odd count hexadecimal digits");
5645 if (p >= buf + len) {
5647 warnx("hexadecimal digits too long");
5649 warnx("string too long");
5653 #define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
5654 *p++ = (tohex((u_char)val[0]) << 4) |
5655 tohex((u_char)val[1]);
5662 /* The string "-" is treated as the empty string. */
5663 if (!hexstr && len == 1 && buf[0] == '-') {
5665 memset(buf, 0, *lenp);
5666 } else if (len < *lenp)
5667 memset(p, 0, *lenp - len);
5673 print_string(const u_int8_t *buf, int len)
5682 setlocale(LC_CTYPE, "");
5683 utf8 = strncmp("UTF-8", nl_langinfo(CODESET), 5) == 0;
5685 for (; i < len; i++) {
5686 if (!isprint(buf[i]) && buf[i] != '\0' && !utf8)
5688 if (isspace(buf[i]))
5691 if (i == len || utf8) {
5692 if (hasspc || len == 0 || buf[0] == '\0')
5693 printf("\"%.*s\"", len, buf);
5695 printf("%.*s", len, buf);
5698 for (i = 0; i < len; i++)
5699 printf("%02x", buf[i]);
5704 setdefregdomain(int s)
5706 struct regdata *rdp = getregdata();
5707 const struct regdomain *rd;
5709 /* Check if regdomain/country was already set by a previous call. */
5710 /* XXX is it possible? */
5711 if (regdomain.regdomain != 0 ||
5712 regdomain.country != CTRY_DEFAULT)
5717 /* Check if it was already set by the driver. */
5718 if (regdomain.regdomain != 0 ||
5719 regdomain.country != CTRY_DEFAULT)
5722 /* Set FCC/US as default. */
5723 rd = lib80211_regdomain_findbysku(rdp, SKU_FCC);
5725 errx(1, "FCC regdomain was not found");
5727 regdomain.regdomain = rd->sku;
5731 /* Send changes to net80211. */
5732 setregdomain_cb(s, ®domain);
5734 /* Cleanup (so it can be overriden by subsequent parameters). */
5735 regdomain.regdomain = 0;
5736 regdomain.country = CTRY_DEFAULT;
5737 regdomain.isocc[0] = 0;
5738 regdomain.isocc[1] = 0;
5742 * Virtual AP cloning support.
5744 static struct ieee80211_clone_params params = {
5745 .icp_opmode = IEEE80211_M_STA, /* default to station mode */
5749 wlan_create(int s, struct ifreq *ifr)
5751 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
5752 char orig_name[IFNAMSIZ];
5754 if (params.icp_parent[0] == '\0')
5755 errx(1, "must specify a parent device (wlandev) when creating "
5757 if (params.icp_opmode == IEEE80211_M_WDS &&
5758 memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0)
5759 errx(1, "no bssid specified for WDS (use wlanbssid)");
5760 ifr->ifr_data = (caddr_t) ¶ms;
5761 ioctl_ifcreate(s, ifr);
5763 /* XXX preserve original name for ifclonecreate(). */
5764 strlcpy(orig_name, name, sizeof(orig_name));
5765 strlcpy(name, ifr->ifr_name, sizeof(name));
5769 strlcpy(name, orig_name, sizeof(name));
5773 DECL_CMD_FUNC(set80211clone_wlandev, arg, d)
5775 strlcpy(params.icp_parent, arg, IFNAMSIZ);
5779 DECL_CMD_FUNC(set80211clone_wlanbssid, arg, d)
5781 const struct ether_addr *ea;
5783 ea = ether_aton(arg);
5785 errx(1, "%s: cannot parse bssid", arg);
5786 memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN);
5790 DECL_CMD_FUNC(set80211clone_wlanaddr, arg, d)
5792 const struct ether_addr *ea;
5794 ea = ether_aton(arg);
5796 errx(1, "%s: cannot parse address", arg);
5797 memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN);
5798 params.icp_flags |= IEEE80211_CLONE_MACADDR;
5802 DECL_CMD_FUNC(set80211clone_wlanmode, arg, d)
5804 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
5805 if (iseq(arg, "sta"))
5806 params.icp_opmode = IEEE80211_M_STA;
5807 else if (iseq(arg, "ahdemo") || iseq(arg, "adhoc-demo"))
5808 params.icp_opmode = IEEE80211_M_AHDEMO;
5809 else if (iseq(arg, "ibss") || iseq(arg, "adhoc"))
5810 params.icp_opmode = IEEE80211_M_IBSS;
5811 else if (iseq(arg, "ap") || iseq(arg, "host"))
5812 params.icp_opmode = IEEE80211_M_HOSTAP;
5813 else if (iseq(arg, "wds"))
5814 params.icp_opmode = IEEE80211_M_WDS;
5815 else if (iseq(arg, "monitor"))
5816 params.icp_opmode = IEEE80211_M_MONITOR;
5817 else if (iseq(arg, "tdma")) {
5818 params.icp_opmode = IEEE80211_M_AHDEMO;
5819 params.icp_flags |= IEEE80211_CLONE_TDMA;
5820 } else if (iseq(arg, "mesh") || iseq(arg, "mp")) /* mesh point */
5821 params.icp_opmode = IEEE80211_M_MBSS;
5823 errx(1, "Don't know to create %s for %s", arg, name);
5828 set80211clone_beacons(const char *val, int d, int s, const struct afswtch *rafp)
5830 /* NB: inverted sense */
5832 params.icp_flags &= ~IEEE80211_CLONE_NOBEACONS;
5834 params.icp_flags |= IEEE80211_CLONE_NOBEACONS;
5838 set80211clone_bssid(const char *val, int d, int s, const struct afswtch *rafp)
5841 params.icp_flags |= IEEE80211_CLONE_BSSID;
5843 params.icp_flags &= ~IEEE80211_CLONE_BSSID;
5847 set80211clone_wdslegacy(const char *val, int d, int s, const struct afswtch *rafp)
5850 params.icp_flags |= IEEE80211_CLONE_WDSLEGACY;
5852 params.icp_flags &= ~IEEE80211_CLONE_WDSLEGACY;
5855 static struct cmd ieee80211_cmds[] = {
5856 DEF_CMD_ARG("ssid", set80211ssid),
5857 DEF_CMD_ARG("nwid", set80211ssid),
5858 DEF_CMD_ARG("meshid", set80211meshid),
5859 DEF_CMD_ARG("stationname", set80211stationname),
5860 DEF_CMD_ARG("station", set80211stationname), /* BSD/OS */
5861 DEF_CMD_ARG("channel", set80211channel),
5862 DEF_CMD_ARG("authmode", set80211authmode),
5863 DEF_CMD_ARG("powersavemode", set80211powersavemode),
5864 DEF_CMD("powersave", 1, set80211powersave),
5865 DEF_CMD("-powersave", 0, set80211powersave),
5866 DEF_CMD_ARG("powersavesleep", set80211powersavesleep),
5867 DEF_CMD_ARG("wepmode", set80211wepmode),
5868 DEF_CMD("wep", 1, set80211wep),
5869 DEF_CMD("-wep", 0, set80211wep),
5870 DEF_CMD_ARG("deftxkey", set80211weptxkey),
5871 DEF_CMD_ARG("weptxkey", set80211weptxkey),
5872 DEF_CMD_ARG("wepkey", set80211wepkey),
5873 DEF_CMD_ARG("nwkey", set80211nwkey), /* NetBSD */
5874 DEF_CMD("-nwkey", 0, set80211wep), /* NetBSD */
5875 DEF_CMD_ARG("rtsthreshold", set80211rtsthreshold),
5876 DEF_CMD_ARG("protmode", set80211protmode),
5877 DEF_CMD_ARG("txpower", set80211txpower),
5878 DEF_CMD_ARG("roaming", set80211roaming),
5879 DEF_CMD("wme", 1, set80211wme),
5880 DEF_CMD("-wme", 0, set80211wme),
5881 DEF_CMD("wmm", 1, set80211wme),
5882 DEF_CMD("-wmm", 0, set80211wme),
5883 DEF_CMD("hidessid", 1, set80211hidessid),
5884 DEF_CMD("-hidessid", 0, set80211hidessid),
5885 DEF_CMD("apbridge", 1, set80211apbridge),
5886 DEF_CMD("-apbridge", 0, set80211apbridge),
5887 DEF_CMD_ARG("chanlist", set80211chanlist),
5888 DEF_CMD_ARG("bssid", set80211bssid),
5889 DEF_CMD_ARG("ap", set80211bssid),
5890 DEF_CMD("scan", 0, set80211scan),
5891 DEF_CMD_ARG("list", set80211list),
5892 DEF_CMD_ARG2("cwmin", set80211cwmin),
5893 DEF_CMD_ARG2("cwmax", set80211cwmax),
5894 DEF_CMD_ARG2("aifs", set80211aifs),
5895 DEF_CMD_ARG2("txoplimit", set80211txoplimit),
5896 DEF_CMD_ARG("acm", set80211acm),
5897 DEF_CMD_ARG("-acm", set80211noacm),
5898 DEF_CMD_ARG("ack", set80211ackpolicy),
5899 DEF_CMD_ARG("-ack", set80211noackpolicy),
5900 DEF_CMD_ARG2("bss:cwmin", set80211bsscwmin),
5901 DEF_CMD_ARG2("bss:cwmax", set80211bsscwmax),
5902 DEF_CMD_ARG2("bss:aifs", set80211bssaifs),
5903 DEF_CMD_ARG2("bss:txoplimit", set80211bsstxoplimit),
5904 DEF_CMD_ARG("dtimperiod", set80211dtimperiod),
5905 DEF_CMD_ARG("bintval", set80211bintval),
5906 DEF_CMD("mac:open", IEEE80211_MACCMD_POLICY_OPEN, set80211maccmd),
5907 DEF_CMD("mac:allow", IEEE80211_MACCMD_POLICY_ALLOW, set80211maccmd),
5908 DEF_CMD("mac:deny", IEEE80211_MACCMD_POLICY_DENY, set80211maccmd),
5909 DEF_CMD("mac:radius", IEEE80211_MACCMD_POLICY_RADIUS, set80211maccmd),
5910 DEF_CMD("mac:flush", IEEE80211_MACCMD_FLUSH, set80211maccmd),
5911 DEF_CMD("mac:detach", IEEE80211_MACCMD_DETACH, set80211maccmd),
5912 DEF_CMD_ARG("mac:add", set80211addmac),
5913 DEF_CMD_ARG("mac:del", set80211delmac),
5914 DEF_CMD_ARG("mac:kick", set80211kickmac),
5915 DEF_CMD("pureg", 1, set80211pureg),
5916 DEF_CMD("-pureg", 0, set80211pureg),
5917 DEF_CMD("ff", 1, set80211fastframes),
5918 DEF_CMD("-ff", 0, set80211fastframes),
5919 DEF_CMD("dturbo", 1, set80211dturbo),
5920 DEF_CMD("-dturbo", 0, set80211dturbo),
5921 DEF_CMD("bgscan", 1, set80211bgscan),
5922 DEF_CMD("-bgscan", 0, set80211bgscan),
5923 DEF_CMD_ARG("bgscanidle", set80211bgscanidle),
5924 DEF_CMD_ARG("bgscanintvl", set80211bgscanintvl),
5925 DEF_CMD_ARG("scanvalid", set80211scanvalid),
5926 DEF_CMD("quiet", 1, set80211quiet),
5927 DEF_CMD("-quiet", 0, set80211quiet),
5928 DEF_CMD_ARG("quiet_count", set80211quietcount),
5929 DEF_CMD_ARG("quiet_period", set80211quietperiod),
5930 DEF_CMD_ARG("quiet_duration", set80211quietduration),
5931 DEF_CMD_ARG("quiet_offset", set80211quietoffset),
5932 DEF_CMD_ARG("roam:rssi", set80211roamrssi),
5933 DEF_CMD_ARG("roam:rate", set80211roamrate),
5934 DEF_CMD_ARG("mcastrate", set80211mcastrate),
5935 DEF_CMD_ARG("ucastrate", set80211ucastrate),
5936 DEF_CMD_ARG("mgtrate", set80211mgtrate),
5937 DEF_CMD_ARG("mgmtrate", set80211mgtrate),
5938 DEF_CMD_ARG("maxretry", set80211maxretry),
5939 DEF_CMD_ARG("fragthreshold", set80211fragthreshold),
5940 DEF_CMD("burst", 1, set80211burst),
5941 DEF_CMD("-burst", 0, set80211burst),
5942 DEF_CMD_ARG("bmiss", set80211bmissthreshold),
5943 DEF_CMD_ARG("bmissthreshold", set80211bmissthreshold),
5944 DEF_CMD("shortgi", 1, set80211shortgi),
5945 DEF_CMD("-shortgi", 0, set80211shortgi),
5946 DEF_CMD("ampdurx", 2, set80211ampdu),
5947 DEF_CMD("-ampdurx", -2, set80211ampdu),
5948 DEF_CMD("ampdutx", 1, set80211ampdu),
5949 DEF_CMD("-ampdutx", -1, set80211ampdu),
5950 DEF_CMD("ampdu", 3, set80211ampdu), /* NB: tx+rx */
5951 DEF_CMD("-ampdu", -3, set80211ampdu),
5952 DEF_CMD_ARG("ampdulimit", set80211ampdulimit),
5953 DEF_CMD_ARG("ampdudensity", set80211ampdudensity),
5954 DEF_CMD("amsdurx", 2, set80211amsdu),
5955 DEF_CMD("-amsdurx", -2, set80211amsdu),
5956 DEF_CMD("amsdutx", 1, set80211amsdu),
5957 DEF_CMD("-amsdutx", -1, set80211amsdu),
5958 DEF_CMD("amsdu", 3, set80211amsdu), /* NB: tx+rx */
5959 DEF_CMD("-amsdu", -3, set80211amsdu),
5960 DEF_CMD_ARG("amsdulimit", set80211amsdulimit),
5961 DEF_CMD("stbcrx", 2, set80211stbc),
5962 DEF_CMD("-stbcrx", -2, set80211stbc),
5963 DEF_CMD("stbctx", 1, set80211stbc),
5964 DEF_CMD("-stbctx", -1, set80211stbc),
5965 DEF_CMD("stbc", 3, set80211stbc), /* NB: tx+rx */
5966 DEF_CMD("-stbc", -3, set80211stbc),
5967 DEF_CMD("ldpcrx", 2, set80211ldpc),
5968 DEF_CMD("-ldpcrx", -2, set80211ldpc),
5969 DEF_CMD("ldpctx", 1, set80211ldpc),
5970 DEF_CMD("-ldpctx", -1, set80211ldpc),
5971 DEF_CMD("ldpc", 3, set80211ldpc), /* NB: tx+rx */
5972 DEF_CMD("-ldpc", -3, set80211ldpc),
5973 DEF_CMD("uapsd", 1, set80211uapsd),
5974 DEF_CMD("-uapsd", 0, set80211uapsd),
5975 DEF_CMD("puren", 1, set80211puren),
5976 DEF_CMD("-puren", 0, set80211puren),
5977 DEF_CMD("doth", 1, set80211doth),
5978 DEF_CMD("-doth", 0, set80211doth),
5979 DEF_CMD("dfs", 1, set80211dfs),
5980 DEF_CMD("-dfs", 0, set80211dfs),
5981 DEF_CMD("htcompat", 1, set80211htcompat),
5982 DEF_CMD("-htcompat", 0, set80211htcompat),
5983 DEF_CMD("dwds", 1, set80211dwds),
5984 DEF_CMD("-dwds", 0, set80211dwds),
5985 DEF_CMD("inact", 1, set80211inact),
5986 DEF_CMD("-inact", 0, set80211inact),
5987 DEF_CMD("tsn", 1, set80211tsn),
5988 DEF_CMD("-tsn", 0, set80211tsn),
5989 DEF_CMD_ARG("regdomain", set80211regdomain),
5990 DEF_CMD_ARG("country", set80211country),
5991 DEF_CMD("indoor", 'I', set80211location),
5992 DEF_CMD("-indoor", 'O', set80211location),
5993 DEF_CMD("outdoor", 'O', set80211location),
5994 DEF_CMD("-outdoor", 'I', set80211location),
5995 DEF_CMD("anywhere", ' ', set80211location),
5996 DEF_CMD("ecm", 1, set80211ecm),
5997 DEF_CMD("-ecm", 0, set80211ecm),
5998 DEF_CMD("dotd", 1, set80211dotd),
5999 DEF_CMD("-dotd", 0, set80211dotd),
6000 DEF_CMD_ARG("htprotmode", set80211htprotmode),
6001 DEF_CMD("ht20", 1, set80211htconf),
6002 DEF_CMD("-ht20", 0, set80211htconf),
6003 DEF_CMD("ht40", 3, set80211htconf), /* NB: 20+40 */
6004 DEF_CMD("-ht40", 0, set80211htconf),
6005 DEF_CMD("ht", 3, set80211htconf), /* NB: 20+40 */
6006 DEF_CMD("-ht", 0, set80211htconf),
6007 DEF_CMD("vht", IEEE80211_FVHT_VHT, set80211vhtconf),
6008 DEF_CMD("-vht", 0, set80211vhtconf),
6009 DEF_CMD("vht40", IEEE80211_FVHT_USEVHT40, set80211vhtconf),
6010 DEF_CMD("-vht40", -IEEE80211_FVHT_USEVHT40, set80211vhtconf),
6011 DEF_CMD("vht80", IEEE80211_FVHT_USEVHT80, set80211vhtconf),
6012 DEF_CMD("-vht80", -IEEE80211_FVHT_USEVHT80, set80211vhtconf),
6013 DEF_CMD("vht160", IEEE80211_FVHT_USEVHT160, set80211vhtconf),
6014 DEF_CMD("-vht160", -IEEE80211_FVHT_USEVHT160, set80211vhtconf),
6015 DEF_CMD("vht80p80", IEEE80211_FVHT_USEVHT80P80, set80211vhtconf),
6016 DEF_CMD("-vht80p80", -IEEE80211_FVHT_USEVHT80P80, set80211vhtconf),
6017 DEF_CMD("rifs", 1, set80211rifs),
6018 DEF_CMD("-rifs", 0, set80211rifs),
6019 DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA, set80211smps),
6020 DEF_CMD("smpsdyn", IEEE80211_HTCAP_SMPS_DYNAMIC, set80211smps),
6021 DEF_CMD("-smps", IEEE80211_HTCAP_SMPS_OFF, set80211smps),
6022 /* XXX for testing */
6023 DEF_CMD_ARG("chanswitch", set80211chanswitch),
6025 DEF_CMD_ARG("tdmaslot", set80211tdmaslot),
6026 DEF_CMD_ARG("tdmaslotcnt", set80211tdmaslotcnt),
6027 DEF_CMD_ARG("tdmaslotlen", set80211tdmaslotlen),
6028 DEF_CMD_ARG("tdmabintval", set80211tdmabintval),
6030 DEF_CMD_ARG("meshttl", set80211meshttl),
6031 DEF_CMD("meshforward", 1, set80211meshforward),
6032 DEF_CMD("-meshforward", 0, set80211meshforward),
6033 DEF_CMD("meshgate", 1, set80211meshgate),
6034 DEF_CMD("-meshgate", 0, set80211meshgate),
6035 DEF_CMD("meshpeering", 1, set80211meshpeering),
6036 DEF_CMD("-meshpeering", 0, set80211meshpeering),
6037 DEF_CMD_ARG("meshmetric", set80211meshmetric),
6038 DEF_CMD_ARG("meshpath", set80211meshpath),
6039 DEF_CMD("meshrt:flush", IEEE80211_MESH_RTCMD_FLUSH, set80211meshrtcmd),
6040 DEF_CMD_ARG("meshrt:add", set80211addmeshrt),
6041 DEF_CMD_ARG("meshrt:del", set80211delmeshrt),
6042 DEF_CMD_ARG("hwmprootmode", set80211hwmprootmode),
6043 DEF_CMD_ARG("hwmpmaxhops", set80211hwmpmaxhops),
6045 /* vap cloning support */
6046 DEF_CLONE_CMD_ARG("wlanaddr", set80211clone_wlanaddr),
6047 DEF_CLONE_CMD_ARG("wlanbssid", set80211clone_wlanbssid),
6048 DEF_CLONE_CMD_ARG("wlandev", set80211clone_wlandev),
6049 DEF_CLONE_CMD_ARG("wlanmode", set80211clone_wlanmode),
6050 DEF_CLONE_CMD("beacons", 1, set80211clone_beacons),
6051 DEF_CLONE_CMD("-beacons", 0, set80211clone_beacons),
6052 DEF_CLONE_CMD("bssid", 1, set80211clone_bssid),
6053 DEF_CLONE_CMD("-bssid", 0, set80211clone_bssid),
6054 DEF_CLONE_CMD("wdslegacy", 1, set80211clone_wdslegacy),
6055 DEF_CLONE_CMD("-wdslegacy", 0, set80211clone_wdslegacy),
6057 static struct afswtch af_ieee80211 = {
6058 .af_name = "af_ieee80211",
6060 .af_other_status = ieee80211_status,
6063 static __constructor void
6064 ieee80211_ctor(void)
6068 for (i = 0; i < nitems(ieee80211_cmds); i++)
6069 cmd_register(&ieee80211_cmds[i]);
6070 af_register(&af_ieee80211);
6071 clone_setdefcallback_prefix("wlan", wlan_create);