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 */
130 #define MAXCHAN 1536 /* max 1.5K channels */
136 static void LINE_INIT(char c);
137 static void LINE_BREAK(void);
138 static void LINE_CHECK(const char *fmt, ...);
140 static const char *modename[IEEE80211_MODE_MAX] = {
141 [IEEE80211_MODE_AUTO] = "auto",
142 [IEEE80211_MODE_11A] = "11a",
143 [IEEE80211_MODE_11B] = "11b",
144 [IEEE80211_MODE_11G] = "11g",
145 [IEEE80211_MODE_FH] = "fh",
146 [IEEE80211_MODE_TURBO_A] = "turboA",
147 [IEEE80211_MODE_TURBO_G] = "turboG",
148 [IEEE80211_MODE_STURBO_A] = "sturbo",
149 [IEEE80211_MODE_11NA] = "11na",
150 [IEEE80211_MODE_11NG] = "11ng",
151 [IEEE80211_MODE_HALF] = "half",
152 [IEEE80211_MODE_QUARTER] = "quarter",
153 [IEEE80211_MODE_VHT_2GHZ] = "11acg",
154 [IEEE80211_MODE_VHT_5GHZ] = "11ac",
157 static void set80211(int s, int type, int val, int len, void *data);
158 static int get80211(int s, int type, void *data, int len);
159 static int get80211len(int s, int type, void *data, int len, int *plen);
160 static int get80211val(int s, int type, int *val);
161 static const char *get_string(const char *val, const char *sep,
162 u_int8_t *buf, int *lenp);
163 static void print_string(const u_int8_t *buf, int len);
164 static void print_regdomain(const struct ieee80211_regdomain *, int);
165 static void print_channels(int, const struct ieee80211req_chaninfo *,
166 int allchans, int verbose);
167 static void regdomain_makechannels(struct ieee80211_regdomain_req *,
168 const struct ieee80211_devcaps_req *);
169 static const char *mesh_linkstate_string(uint8_t state);
171 static struct ieee80211req_chaninfo *chaninfo;
172 static struct ieee80211_regdomain regdomain;
173 static int gotregdomain = 0;
174 static struct ieee80211_roamparams_req roamparams;
175 static int gotroam = 0;
176 static struct ieee80211_txparams_req txparams;
177 static int gottxparams = 0;
178 static struct ieee80211_channel curchan;
179 static int gotcurchan = 0;
180 static struct ifmediareq *ifmr;
181 static int htconf = 0;
182 static int gothtconf = 0;
189 if (get80211val(s, IEEE80211_IOC_HTCONF, &htconf) < 0)
190 warn("unable to get HT configuration information");
195 static int vhtconf = 0;
196 static int gotvhtconf = 0;
203 if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
204 warn("unable to get VHT configuration information");
209 * Collect channel info from the kernel. We use this (mostly)
210 * to handle mapping between frequency and IEEE channel number.
215 if (chaninfo != NULL)
217 chaninfo = malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN));
218 if (chaninfo == NULL)
219 errx(1, "no space for channel list");
220 if (get80211(s, IEEE80211_IOC_CHANINFO, chaninfo,
221 IEEE80211_CHANINFO_SIZE(MAXCHAN)) < 0)
222 err(1, "unable to get channel information");
223 ifmr = ifmedia_getstate(s);
228 static struct regdata *
231 static struct regdata *rdp = NULL;
233 rdp = lib80211_alloc_regdata();
235 errx(-1, "missing or corrupted regdomain database");
241 * Given the channel at index i with attributes from,
242 * check if there is a channel with attributes to in
243 * the channel table. With suitable attributes this
244 * allows the caller to look for promotion; e.g. from
248 canpromote(int i, int from, int to)
250 const struct ieee80211_channel *fc = &chaninfo->ic_chans[i];
253 if ((fc->ic_flags & from) != from)
255 /* NB: quick check exploiting ordering of chans w/ same frequency */
256 if (i+1 < chaninfo->ic_nchans &&
257 chaninfo->ic_chans[i+1].ic_freq == fc->ic_freq &&
258 (chaninfo->ic_chans[i+1].ic_flags & to) == to)
260 /* brute force search in case channel list is not ordered */
261 for (j = 0; j < chaninfo->ic_nchans; j++) {
262 const struct ieee80211_channel *tc = &chaninfo->ic_chans[j];
264 tc->ic_freq == fc->ic_freq && (tc->ic_flags & to) == to)
271 * Handle channel promotion. When a channel is specified with
272 * only a frequency we want to promote it to the ``best'' channel
273 * available. The channel list has separate entries for 11b, 11g,
274 * 11a, and 11n[ga] channels so specifying a frequency w/o any
275 * attributes requires we upgrade, e.g. from 11b -> 11g. This
276 * gets complicated when the channel is specified on the same
277 * command line with a media request that constrains the available
278 * channe list (e.g. mode 11a); we want to honor that to avoid
279 * confusing behaviour.
288 * Query the current mode of the interface in case it's
289 * constrained (e.g. to 11a). We must do this carefully
290 * as there may be a pending ifmedia request in which case
291 * asking the kernel will give us the wrong answer. This
292 * is an unfortunate side-effect of the way ifconfig is
293 * structure for modularity (yech).
295 * NB: ifmr is actually setup in getchaninfo (above); we
296 * assume it's called coincident with to this call so
297 * we have a ``current setting''; otherwise we must pass
298 * the socket descriptor down to here so we can make
299 * the ifmedia_getstate call ourselves.
301 int chanmode = ifmr != NULL ? IFM_MODE(ifmr->ifm_current) : IFM_AUTO;
303 /* when ambiguous promote to ``best'' */
304 /* NB: we abitrarily pick HT40+ over HT40- */
305 if (chanmode != IFM_IEEE80211_11B)
306 i = canpromote(i, IEEE80211_CHAN_B, IEEE80211_CHAN_G);
307 if (chanmode != IFM_IEEE80211_11G && (htconf & 1)) {
308 i = canpromote(i, IEEE80211_CHAN_G,
309 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20);
311 i = canpromote(i, IEEE80211_CHAN_G,
312 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D);
313 i = canpromote(i, IEEE80211_CHAN_G,
314 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U);
317 if (chanmode != IFM_IEEE80211_11A && (htconf & 1)) {
318 i = canpromote(i, IEEE80211_CHAN_A,
319 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20);
321 i = canpromote(i, IEEE80211_CHAN_A,
322 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D);
323 i = canpromote(i, IEEE80211_CHAN_A,
324 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U);
331 mapfreq(struct ieee80211_channel *chan, int freq, int flags)
335 for (i = 0; i < chaninfo->ic_nchans; i++) {
336 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
338 if (c->ic_freq == freq && (c->ic_flags & flags) == flags) {
340 /* when ambiguous promote to ``best'' */
341 c = &chaninfo->ic_chans[promote(i)];
347 errx(1, "unknown/undefined frequency %u/0x%x", freq, flags);
351 mapchan(struct ieee80211_channel *chan, int ieee, int flags)
355 for (i = 0; i < chaninfo->ic_nchans; i++) {
356 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
358 if (c->ic_ieee == ieee && (c->ic_flags & flags) == flags) {
360 /* when ambiguous promote to ``best'' */
361 c = &chaninfo->ic_chans[promote(i)];
367 errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags);
370 static const struct ieee80211_channel *
375 if (get80211(s, IEEE80211_IOC_CURCHAN, &curchan, sizeof(curchan)) < 0) {
377 /* fall back to legacy ioctl */
378 if (get80211val(s, IEEE80211_IOC_CHANNEL, &val) < 0)
379 err(-1, "cannot figure out current channel");
381 mapchan(&curchan, val, 0);
387 static enum ieee80211_phymode
388 chan2mode(const struct ieee80211_channel *c)
390 if (IEEE80211_IS_CHAN_VHTA(c))
391 return IEEE80211_MODE_VHT_5GHZ;
392 if (IEEE80211_IS_CHAN_VHTG(c))
393 return IEEE80211_MODE_VHT_2GHZ;
394 if (IEEE80211_IS_CHAN_HTA(c))
395 return IEEE80211_MODE_11NA;
396 if (IEEE80211_IS_CHAN_HTG(c))
397 return IEEE80211_MODE_11NG;
398 if (IEEE80211_IS_CHAN_108A(c))
399 return IEEE80211_MODE_TURBO_A;
400 if (IEEE80211_IS_CHAN_108G(c))
401 return IEEE80211_MODE_TURBO_G;
402 if (IEEE80211_IS_CHAN_ST(c))
403 return IEEE80211_MODE_STURBO_A;
404 if (IEEE80211_IS_CHAN_FHSS(c))
405 return IEEE80211_MODE_FH;
406 if (IEEE80211_IS_CHAN_HALF(c))
407 return IEEE80211_MODE_HALF;
408 if (IEEE80211_IS_CHAN_QUARTER(c))
409 return IEEE80211_MODE_QUARTER;
410 if (IEEE80211_IS_CHAN_A(c))
411 return IEEE80211_MODE_11A;
412 if (IEEE80211_IS_CHAN_ANYG(c))
413 return IEEE80211_MODE_11G;
414 if (IEEE80211_IS_CHAN_B(c))
415 return IEEE80211_MODE_11B;
416 return IEEE80211_MODE_AUTO;
424 if (get80211(s, IEEE80211_IOC_ROAM,
425 &roamparams, sizeof(roamparams)) < 0)
426 err(1, "unable to get roaming parameters");
431 setroam_cb(int s, void *arg)
433 struct ieee80211_roamparams_req *roam = arg;
434 set80211(s, IEEE80211_IOC_ROAM, 0, sizeof(*roam), roam);
442 if (get80211(s, IEEE80211_IOC_TXPARAMS,
443 &txparams, sizeof(txparams)) < 0)
444 err(1, "unable to get transmit parameters");
449 settxparams_cb(int s, void *arg)
451 struct ieee80211_txparams_req *txp = arg;
452 set80211(s, IEEE80211_IOC_TXPARAMS, 0, sizeof(*txp), txp);
460 if (get80211(s, IEEE80211_IOC_REGDOMAIN,
461 ®domain, sizeof(regdomain)) < 0)
462 err(1, "unable to get regulatory domain info");
467 getdevcaps(int s, struct ieee80211_devcaps_req *dc)
469 if (get80211(s, IEEE80211_IOC_DEVCAPS, dc,
470 IEEE80211_DEVCAPS_SPACE(dc)) < 0)
471 err(1, "unable to get device capabilities");
475 setregdomain_cb(int s, void *arg)
477 struct ieee80211_regdomain_req *req;
478 struct ieee80211_regdomain *rd = arg;
479 struct ieee80211_devcaps_req *dc;
480 struct regdata *rdp = getregdata();
482 if (rd->country != NO_COUNTRY) {
483 const struct country *cc;
485 * Check current country seting to make sure it's
486 * compatible with the new regdomain. If not, then
487 * override it with any default country for this
488 * SKU. If we cannot arrange a match, then abort.
490 cc = lib80211_country_findbycc(rdp, rd->country);
492 errx(1, "unknown ISO country code %d", rd->country);
493 if (cc->rd->sku != rd->regdomain) {
494 const struct regdomain *rp;
496 * Check if country is incompatible with regdomain.
497 * To enable multiple regdomains for a country code
498 * we permit a mismatch between the regdomain and
499 * the country's associated regdomain when the
500 * regdomain is setup w/o a default country. For
501 * example, US is bound to the FCC regdomain but
502 * we allow US to be combined with FCC3 because FCC3
503 * has not default country. This allows bogus
504 * combinations like FCC3+DK which are resolved when
505 * constructing the channel list by deferring to the
506 * regdomain to construct the channel list.
508 rp = lib80211_regdomain_findbysku(rdp, rd->regdomain);
510 errx(1, "country %s (%s) is not usable with "
511 "regdomain %d", cc->isoname, cc->name,
513 else if (rp->cc != NULL && rp->cc != cc)
514 errx(1, "country %s (%s) is not usable with "
515 "regdomain %s", cc->isoname, cc->name,
520 * Fetch the device capabilities and calculate the
521 * full set of netbands for which we request a new
522 * channel list be constructed. Once that's done we
523 * push the regdomain info + channel list to the kernel.
525 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
527 errx(1, "no space for device capabilities");
528 dc->dc_chaninfo.ic_nchans = MAXCHAN;
532 printf("drivercaps: 0x%x\n", dc->dc_drivercaps);
533 printf("cryptocaps: 0x%x\n", dc->dc_cryptocaps);
534 printf("htcaps : 0x%x\n", dc->dc_htcaps);
535 printf("vhtcaps : 0x%x\n", dc->dc_vhtcaps);
537 memcpy(chaninfo, &dc->dc_chaninfo,
538 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
539 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, 1/*verbose*/);
543 req = malloc(IEEE80211_REGDOMAIN_SIZE(dc->dc_chaninfo.ic_nchans));
545 errx(1, "no space for regdomain request");
547 regdomain_makechannels(req, dc);
550 print_regdomain(rd, 1/*verbose*/);
552 /* blech, reallocate channel list for new data */
553 if (chaninfo != NULL)
555 chaninfo = malloc(IEEE80211_CHANINFO_SPACE(&req->chaninfo));
556 if (chaninfo == NULL)
557 errx(1, "no space for channel list");
558 memcpy(chaninfo, &req->chaninfo,
559 IEEE80211_CHANINFO_SPACE(&req->chaninfo));
560 print_channels(s, &req->chaninfo, 1/*allchans*/, 1/*verbose*/);
562 if (req->chaninfo.ic_nchans == 0)
563 errx(1, "no channels calculated");
564 set80211(s, IEEE80211_IOC_REGDOMAIN, 0,
565 IEEE80211_REGDOMAIN_SPACE(req), req);
571 ieee80211_mhz2ieee(int freq, int flags)
573 struct ieee80211_channel chan;
574 mapfreq(&chan, freq, flags);
579 isanyarg(const char *arg)
581 return (strncmp(arg, "-", 1) == 0 ||
582 strncasecmp(arg, "any", 3) == 0 || strncasecmp(arg, "off", 3) == 0);
586 set80211ssid(const char *val, int d, int s, const struct afswtch *rafp)
590 u_int8_t data[IEEE80211_NWID_LEN];
594 if (len > 2 && isdigit((int)val[0]) && val[1] == ':') {
599 bzero(data, sizeof(data));
601 if (get_string(val, NULL, data, &len) == NULL)
604 set80211(s, IEEE80211_IOC_SSID, ssid, len, data);
608 set80211meshid(const char *val, int d, int s, const struct afswtch *rafp)
611 u_int8_t data[IEEE80211_NWID_LEN];
613 memset(data, 0, sizeof(data));
615 if (get_string(val, NULL, data, &len) == NULL)
618 set80211(s, IEEE80211_IOC_MESH_ID, 0, len, data);
622 set80211stationname(const char *val, int d, int s, const struct afswtch *rafp)
627 bzero(data, sizeof(data));
629 get_string(val, NULL, data, &len);
631 set80211(s, IEEE80211_IOC_STATIONNAME, 0, len, data);
635 * Parse a channel specification for attributes/flags.
637 * freq/xx channel width (5,10,20,40,40+,40-)
638 * freq:mode channel mode (a,b,g,h,n,t,s,d)
640 * These can be combined in either order; e.g. 2437:ng/40.
641 * Modes are case insensitive.
643 * The result is not validated here; it's assumed to be
644 * checked against the channel table fetched from the kernel.
647 getchannelflags(const char *val, int freq)
649 #define _CHAN_HT 0x80000000
656 cp = strchr(val, ':');
658 for (cp++; isalpha((int) *cp); cp++) {
659 /* accept mixed case */
664 case 'a': /* 802.11a */
665 flags |= IEEE80211_CHAN_A;
667 case 'b': /* 802.11b */
668 flags |= IEEE80211_CHAN_B;
670 case 'g': /* 802.11g */
671 flags |= IEEE80211_CHAN_G;
673 case 'v': /* vht: 802.11ac */
676 case 'h': /* ht = 802.11n */
677 case 'n': /* 802.11n */
678 flags |= _CHAN_HT; /* NB: private */
680 case 'd': /* dt = Atheros Dynamic Turbo */
681 flags |= IEEE80211_CHAN_TURBO;
683 case 't': /* ht, dt, st, t */
684 /* dt and unadorned t specify Dynamic Turbo */
685 if ((flags & (IEEE80211_CHAN_STURBO|_CHAN_HT)) == 0)
686 flags |= IEEE80211_CHAN_TURBO;
688 case 's': /* st = Atheros Static Turbo */
689 flags |= IEEE80211_CHAN_STURBO;
692 errx(-1, "%s: Invalid channel attribute %c\n",
697 cp = strchr(val, '/');
700 u_long cw = strtoul(cp+1, &ep, 10);
704 flags |= IEEE80211_CHAN_QUARTER;
707 flags |= IEEE80211_CHAN_HALF;
710 /* NB: this may be removed below */
711 flags |= IEEE80211_CHAN_HT20;
716 /* Handle the 80/160 VHT flag */
718 flags |= IEEE80211_CHAN_VHT80;
720 flags |= IEEE80211_CHAN_VHT160;
723 if (ep != NULL && *ep == '+')
724 flags |= IEEE80211_CHAN_HT40U;
725 else if (ep != NULL && *ep == '-')
726 flags |= IEEE80211_CHAN_HT40D;
729 errx(-1, "%s: Invalid channel width\n", val);
734 * Cleanup specifications.
736 if ((flags & _CHAN_HT) == 0) {
738 * If user specified freq/20 or freq/40 quietly remove
739 * HT cw attributes depending on channel use. To give
740 * an explicit 20/40 width for an HT channel you must
741 * indicate it is an HT channel since all HT channels
742 * are also usable for legacy operation; e.g. freq:n/40.
744 flags &= ~IEEE80211_CHAN_HT;
745 flags &= ~IEEE80211_CHAN_VHT;
748 * Remove private indicator that this is an HT channel
749 * and if no explicit channel width has been given
750 * provide the default settings.
753 if ((flags & IEEE80211_CHAN_HT) == 0) {
754 struct ieee80211_channel chan;
756 * Consult the channel list to see if we can use
757 * HT40+ or HT40- (if both the map routines choose).
760 mapfreq(&chan, freq, 0);
762 mapchan(&chan, freq, 0);
763 flags |= (chan.ic_flags & IEEE80211_CHAN_HT);
767 * If VHT is enabled, then also set the VHT flag and the
768 * relevant channel up/down.
770 if (is_vht && (flags & IEEE80211_CHAN_HT)) {
772 * XXX yes, maybe we should just have VHT, and reuse
775 if (flags & IEEE80211_CHAN_VHT80)
777 else if (flags & IEEE80211_CHAN_HT20)
778 flags |= IEEE80211_CHAN_VHT20;
779 else if (flags & IEEE80211_CHAN_HT40U)
780 flags |= IEEE80211_CHAN_VHT40U;
781 else if (flags & IEEE80211_CHAN_HT40D)
782 flags |= IEEE80211_CHAN_VHT40D;
790 getchannel(int s, struct ieee80211_channel *chan, const char *val)
795 memset(chan, 0, sizeof(*chan));
797 chan->ic_freq = IEEE80211_CHAN_ANY;
802 v = strtol(val, &eptr, 10);
803 if (val[0] == '\0' || val == eptr || errno == ERANGE ||
804 /* channel may be suffixed with nothing, :flag, or /width */
805 (eptr[0] != '\0' && eptr[0] != ':' && eptr[0] != '/'))
806 errx(1, "invalid channel specification%s",
807 errno == ERANGE ? " (out of range)" : "");
808 flags = getchannelflags(val, v);
809 if (v > 255) { /* treat as frequency */
810 mapfreq(chan, v, flags);
812 mapchan(chan, v, flags);
817 set80211channel(const char *val, int d, int s, const struct afswtch *rafp)
819 struct ieee80211_channel chan;
821 getchannel(s, &chan, val);
822 set80211(s, IEEE80211_IOC_CURCHAN, 0, sizeof(chan), &chan);
826 set80211chanswitch(const char *val, int d, int s, const struct afswtch *rafp)
828 struct ieee80211_chanswitch_req csr;
830 getchannel(s, &csr.csa_chan, val);
833 set80211(s, IEEE80211_IOC_CHANSWITCH, 0, sizeof(csr), &csr);
837 set80211authmode(const char *val, int d, int s, const struct afswtch *rafp)
841 if (strcasecmp(val, "none") == 0) {
842 mode = IEEE80211_AUTH_NONE;
843 } else if (strcasecmp(val, "open") == 0) {
844 mode = IEEE80211_AUTH_OPEN;
845 } else if (strcasecmp(val, "shared") == 0) {
846 mode = IEEE80211_AUTH_SHARED;
847 } else if (strcasecmp(val, "8021x") == 0) {
848 mode = IEEE80211_AUTH_8021X;
849 } else if (strcasecmp(val, "wpa") == 0) {
850 mode = IEEE80211_AUTH_WPA;
852 errx(1, "unknown authmode");
855 set80211(s, IEEE80211_IOC_AUTHMODE, mode, 0, NULL);
859 set80211powersavemode(const char *val, int d, int s, const struct afswtch *rafp)
863 if (strcasecmp(val, "off") == 0) {
864 mode = IEEE80211_POWERSAVE_OFF;
865 } else if (strcasecmp(val, "on") == 0) {
866 mode = IEEE80211_POWERSAVE_ON;
867 } else if (strcasecmp(val, "cam") == 0) {
868 mode = IEEE80211_POWERSAVE_CAM;
869 } else if (strcasecmp(val, "psp") == 0) {
870 mode = IEEE80211_POWERSAVE_PSP;
871 } else if (strcasecmp(val, "psp-cam") == 0) {
872 mode = IEEE80211_POWERSAVE_PSP_CAM;
874 errx(1, "unknown powersavemode");
877 set80211(s, IEEE80211_IOC_POWERSAVE, mode, 0, NULL);
881 set80211powersave(const char *val, int d, int s, const struct afswtch *rafp)
884 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_OFF,
887 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_ON,
892 set80211powersavesleep(const char *val, int d, int s, const struct afswtch *rafp)
894 set80211(s, IEEE80211_IOC_POWERSAVESLEEP, atoi(val), 0, NULL);
898 set80211wepmode(const char *val, int d, int s, const struct afswtch *rafp)
902 if (strcasecmp(val, "off") == 0) {
903 mode = IEEE80211_WEP_OFF;
904 } else if (strcasecmp(val, "on") == 0) {
905 mode = IEEE80211_WEP_ON;
906 } else if (strcasecmp(val, "mixed") == 0) {
907 mode = IEEE80211_WEP_MIXED;
909 errx(1, "unknown wep mode");
912 set80211(s, IEEE80211_IOC_WEP, mode, 0, NULL);
916 set80211wep(const char *val, int d, int s, const struct afswtch *rafp)
918 set80211(s, IEEE80211_IOC_WEP, d, 0, NULL);
922 isundefarg(const char *arg)
924 return (strcmp(arg, "-") == 0 || strncasecmp(arg, "undef", 5) == 0);
928 set80211weptxkey(const char *val, int d, int s, const struct afswtch *rafp)
931 set80211(s, IEEE80211_IOC_WEPTXKEY, IEEE80211_KEYIX_NONE, 0, NULL);
933 set80211(s, IEEE80211_IOC_WEPTXKEY, atoi(val)-1, 0, NULL);
937 set80211wepkey(const char *val, int d, int s, const struct afswtch *rafp)
941 u_int8_t data[IEEE80211_KEYBUF_SIZE];
943 if (isdigit((int)val[0]) && val[1] == ':') {
948 bzero(data, sizeof(data));
950 get_string(val, NULL, data, &len);
952 set80211(s, IEEE80211_IOC_WEPKEY, key, len, data);
956 * This function is purely a NetBSD compatibility interface. The NetBSD
957 * interface is too inflexible, but it's there so we'll support it since
958 * it's not all that hard.
961 set80211nwkey(const char *val, int d, int s, const struct afswtch *rafp)
965 u_int8_t data[IEEE80211_KEYBUF_SIZE];
967 set80211(s, IEEE80211_IOC_WEP, IEEE80211_WEP_ON, 0, NULL);
969 if (isdigit((int)val[0]) && val[1] == ':') {
970 txkey = val[0]-'0'-1;
973 for (i = 0; i < 4; i++) {
974 bzero(data, sizeof(data));
976 val = get_string(val, ",", data, &len);
980 set80211(s, IEEE80211_IOC_WEPKEY, i, len, data);
983 bzero(data, sizeof(data));
985 get_string(val, NULL, data, &len);
988 set80211(s, IEEE80211_IOC_WEPKEY, 0, len, data);
990 bzero(data, sizeof(data));
991 for (i = 1; i < 4; i++)
992 set80211(s, IEEE80211_IOC_WEPKEY, i, 0, data);
995 set80211(s, IEEE80211_IOC_WEPTXKEY, txkey, 0, NULL);
999 set80211rtsthreshold(const char *val, int d, int s, const struct afswtch *rafp)
1001 set80211(s, IEEE80211_IOC_RTSTHRESHOLD,
1002 isundefarg(val) ? IEEE80211_RTS_MAX : atoi(val), 0, NULL);
1006 set80211protmode(const char *val, int d, int s, const struct afswtch *rafp)
1010 if (strcasecmp(val, "off") == 0) {
1011 mode = IEEE80211_PROTMODE_OFF;
1012 } else if (strcasecmp(val, "cts") == 0) {
1013 mode = IEEE80211_PROTMODE_CTS;
1014 } else if (strncasecmp(val, "rtscts", 3) == 0) {
1015 mode = IEEE80211_PROTMODE_RTSCTS;
1017 errx(1, "unknown protection mode");
1020 set80211(s, IEEE80211_IOC_PROTMODE, mode, 0, NULL);
1024 set80211htprotmode(const char *val, int d, int s, const struct afswtch *rafp)
1028 if (strcasecmp(val, "off") == 0) {
1029 mode = IEEE80211_PROTMODE_OFF;
1030 } else if (strncasecmp(val, "rts", 3) == 0) {
1031 mode = IEEE80211_PROTMODE_RTSCTS;
1033 errx(1, "unknown protection mode");
1036 set80211(s, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL);
1040 set80211txpower(const char *val, int d, int s, const struct afswtch *rafp)
1042 double v = atof(val);
1045 txpow = (int) (2*v);
1047 errx(-1, "invalid tx power (must be .5 dBm units)");
1048 set80211(s, IEEE80211_IOC_TXPOWER, txpow, 0, NULL);
1051 #define IEEE80211_ROAMING_DEVICE 0
1052 #define IEEE80211_ROAMING_AUTO 1
1053 #define IEEE80211_ROAMING_MANUAL 2
1056 set80211roaming(const char *val, int d, int s, const struct afswtch *rafp)
1060 if (strcasecmp(val, "device") == 0) {
1061 mode = IEEE80211_ROAMING_DEVICE;
1062 } else if (strcasecmp(val, "auto") == 0) {
1063 mode = IEEE80211_ROAMING_AUTO;
1064 } else if (strcasecmp(val, "manual") == 0) {
1065 mode = IEEE80211_ROAMING_MANUAL;
1067 errx(1, "unknown roaming mode");
1069 set80211(s, IEEE80211_IOC_ROAMING, mode, 0, NULL);
1073 set80211wme(const char *val, int d, int s, const struct afswtch *rafp)
1075 set80211(s, IEEE80211_IOC_WME, d, 0, NULL);
1079 set80211hidessid(const char *val, int d, int s, const struct afswtch *rafp)
1081 set80211(s, IEEE80211_IOC_HIDESSID, d, 0, NULL);
1085 set80211apbridge(const char *val, int d, int s, const struct afswtch *rafp)
1087 set80211(s, IEEE80211_IOC_APBRIDGE, d, 0, NULL);
1091 set80211fastframes(const char *val, int d, int s, const struct afswtch *rafp)
1093 set80211(s, IEEE80211_IOC_FF, d, 0, NULL);
1097 set80211dturbo(const char *val, int d, int s, const struct afswtch *rafp)
1099 set80211(s, IEEE80211_IOC_TURBOP, d, 0, NULL);
1103 set80211chanlist(const char *val, int d, int s, const struct afswtch *rafp)
1105 struct ieee80211req_chanlist chanlist;
1106 char *temp, *cp, *tp;
1108 temp = malloc(strlen(val) + 1);
1110 errx(1, "malloc failed");
1112 memset(&chanlist, 0, sizeof(chanlist));
1115 int first, last, f, c;
1117 tp = strchr(cp, ',');
1120 switch (sscanf(cp, "%u-%u", &first, &last)) {
1122 if (first > IEEE80211_CHAN_MAX)
1123 errx(-1, "channel %u out of range, max %u",
1124 first, IEEE80211_CHAN_MAX);
1125 setbit(chanlist.ic_channels, first);
1128 if (first > IEEE80211_CHAN_MAX)
1129 errx(-1, "channel %u out of range, max %u",
1130 first, IEEE80211_CHAN_MAX);
1131 if (last > IEEE80211_CHAN_MAX)
1132 errx(-1, "channel %u out of range, max %u",
1133 last, IEEE80211_CHAN_MAX);
1135 errx(-1, "void channel range, %u > %u",
1137 for (f = first; f <= last; f++)
1138 setbit(chanlist.ic_channels, f);
1150 set80211(s, IEEE80211_IOC_CHANLIST, 0, sizeof(chanlist), &chanlist);
1155 set80211bssid(const char *val, int d, int s, const struct afswtch *rafp)
1158 if (!isanyarg(val)) {
1160 struct sockaddr_dl sdl;
1162 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1164 errx(1, "malloc failed");
1166 strcpy(temp + 1, val);
1167 sdl.sdl_len = sizeof(sdl);
1168 link_addr(temp, &sdl);
1170 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1171 errx(1, "malformed link-level address");
1172 set80211(s, IEEE80211_IOC_BSSID, 0,
1173 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1175 uint8_t zerobssid[IEEE80211_ADDR_LEN];
1176 memset(zerobssid, 0, sizeof(zerobssid));
1177 set80211(s, IEEE80211_IOC_BSSID, 0,
1178 IEEE80211_ADDR_LEN, zerobssid);
1183 getac(const char *ac)
1185 if (strcasecmp(ac, "ac_be") == 0 || strcasecmp(ac, "be") == 0)
1187 if (strcasecmp(ac, "ac_bk") == 0 || strcasecmp(ac, "bk") == 0)
1189 if (strcasecmp(ac, "ac_vi") == 0 || strcasecmp(ac, "vi") == 0)
1191 if (strcasecmp(ac, "ac_vo") == 0 || strcasecmp(ac, "vo") == 0)
1193 errx(1, "unknown wme access class %s", ac);
1197 DECL_CMD_FUNC2(set80211cwmin, ac, val)
1199 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac), NULL);
1203 DECL_CMD_FUNC2(set80211cwmax, ac, val)
1205 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac), NULL);
1209 DECL_CMD_FUNC2(set80211aifs, ac, val)
1211 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac), NULL);
1215 DECL_CMD_FUNC2(set80211txoplimit, ac, val)
1217 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac), NULL);
1221 DECL_CMD_FUNC(set80211acm, ac, d)
1223 set80211(s, IEEE80211_IOC_WME_ACM, 1, getac(ac), NULL);
1226 DECL_CMD_FUNC(set80211noacm, ac, d)
1228 set80211(s, IEEE80211_IOC_WME_ACM, 0, getac(ac), NULL);
1232 DECL_CMD_FUNC(set80211ackpolicy, ac, d)
1234 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 1, getac(ac), NULL);
1237 DECL_CMD_FUNC(set80211noackpolicy, ac, d)
1239 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 0, getac(ac), NULL);
1243 DECL_CMD_FUNC2(set80211bsscwmin, ac, val)
1245 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val),
1246 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1250 DECL_CMD_FUNC2(set80211bsscwmax, ac, val)
1252 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val),
1253 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1257 DECL_CMD_FUNC2(set80211bssaifs, ac, val)
1259 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val),
1260 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1264 DECL_CMD_FUNC2(set80211bsstxoplimit, ac, val)
1266 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val),
1267 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1271 DECL_CMD_FUNC(set80211dtimperiod, val, d)
1273 set80211(s, IEEE80211_IOC_DTIM_PERIOD, atoi(val), 0, NULL);
1277 DECL_CMD_FUNC(set80211bintval, val, d)
1279 set80211(s, IEEE80211_IOC_BEACON_INTERVAL, atoi(val), 0, NULL);
1283 set80211macmac(int s, int op, const char *val)
1286 struct sockaddr_dl sdl;
1288 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1290 errx(1, "malloc failed");
1292 strcpy(temp + 1, val);
1293 sdl.sdl_len = sizeof(sdl);
1294 link_addr(temp, &sdl);
1296 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1297 errx(1, "malformed link-level address");
1298 set80211(s, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl));
1302 DECL_CMD_FUNC(set80211addmac, val, d)
1304 set80211macmac(s, IEEE80211_IOC_ADDMAC, val);
1308 DECL_CMD_FUNC(set80211delmac, val, d)
1310 set80211macmac(s, IEEE80211_IOC_DELMAC, val);
1314 DECL_CMD_FUNC(set80211kickmac, val, d)
1317 struct sockaddr_dl sdl;
1318 struct ieee80211req_mlme mlme;
1320 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1322 errx(1, "malloc failed");
1324 strcpy(temp + 1, val);
1325 sdl.sdl_len = sizeof(sdl);
1326 link_addr(temp, &sdl);
1328 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1329 errx(1, "malformed link-level address");
1330 memset(&mlme, 0, sizeof(mlme));
1331 mlme.im_op = IEEE80211_MLME_DEAUTH;
1332 mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE;
1333 memcpy(mlme.im_macaddr, LLADDR(&sdl), IEEE80211_ADDR_LEN);
1334 set80211(s, IEEE80211_IOC_MLME, 0, sizeof(mlme), &mlme);
1338 DECL_CMD_FUNC(set80211maccmd, val, d)
1340 set80211(s, IEEE80211_IOC_MACCMD, d, 0, NULL);
1344 set80211meshrtmac(int s, int req, const char *val)
1347 struct sockaddr_dl sdl;
1349 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1351 errx(1, "malloc failed");
1353 strcpy(temp + 1, val);
1354 sdl.sdl_len = sizeof(sdl);
1355 link_addr(temp, &sdl);
1357 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1358 errx(1, "malformed link-level address");
1359 set80211(s, IEEE80211_IOC_MESH_RTCMD, req,
1360 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1364 DECL_CMD_FUNC(set80211addmeshrt, val, d)
1366 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_ADD, val);
1370 DECL_CMD_FUNC(set80211delmeshrt, val, d)
1372 set80211meshrtmac(s, IEEE80211_MESH_RTCMD_DELETE, val);
1376 DECL_CMD_FUNC(set80211meshrtcmd, val, d)
1378 set80211(s, IEEE80211_IOC_MESH_RTCMD, d, 0, NULL);
1382 DECL_CMD_FUNC(set80211hwmprootmode, val, d)
1386 if (strcasecmp(val, "normal") == 0)
1387 mode = IEEE80211_HWMP_ROOTMODE_NORMAL;
1388 else if (strcasecmp(val, "proactive") == 0)
1389 mode = IEEE80211_HWMP_ROOTMODE_PROACTIVE;
1390 else if (strcasecmp(val, "rann") == 0)
1391 mode = IEEE80211_HWMP_ROOTMODE_RANN;
1393 mode = IEEE80211_HWMP_ROOTMODE_DISABLED;
1394 set80211(s, IEEE80211_IOC_HWMP_ROOTMODE, mode, 0, NULL);
1398 DECL_CMD_FUNC(set80211hwmpmaxhops, val, d)
1400 set80211(s, IEEE80211_IOC_HWMP_MAXHOPS, atoi(val), 0, NULL);
1404 set80211pureg(const char *val, int d, int s, const struct afswtch *rafp)
1406 set80211(s, IEEE80211_IOC_PUREG, d, 0, NULL);
1410 set80211quiet(const char *val, int d, int s, const struct afswtch *rafp)
1412 set80211(s, IEEE80211_IOC_QUIET, d, 0, NULL);
1416 DECL_CMD_FUNC(set80211quietperiod, val, d)
1418 set80211(s, IEEE80211_IOC_QUIET_PERIOD, atoi(val), 0, NULL);
1422 DECL_CMD_FUNC(set80211quietcount, val, d)
1424 set80211(s, IEEE80211_IOC_QUIET_COUNT, atoi(val), 0, NULL);
1428 DECL_CMD_FUNC(set80211quietduration, val, d)
1430 set80211(s, IEEE80211_IOC_QUIET_DUR, atoi(val), 0, NULL);
1434 DECL_CMD_FUNC(set80211quietoffset, val, d)
1436 set80211(s, IEEE80211_IOC_QUIET_OFFSET, atoi(val), 0, NULL);
1440 set80211bgscan(const char *val, int d, int s, const struct afswtch *rafp)
1442 set80211(s, IEEE80211_IOC_BGSCAN, d, 0, NULL);
1446 DECL_CMD_FUNC(set80211bgscanidle, val, d)
1448 set80211(s, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL);
1452 DECL_CMD_FUNC(set80211bgscanintvl, val, d)
1454 set80211(s, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL);
1458 DECL_CMD_FUNC(set80211scanvalid, val, d)
1460 set80211(s, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL);
1464 * Parse an optional trailing specification of which netbands
1465 * to apply a parameter to. This is basically the same syntax
1466 * as used for channels but you can concatenate to specify
1467 * multiple. For example:
1468 * 14:abg apply to 11a, 11b, and 11g
1469 * 6:ht apply to 11na and 11ng
1470 * We don't make a big effort to catch silly things; this is
1471 * really a convenience mechanism.
1474 getmodeflags(const char *val)
1481 cp = strchr(val, ':');
1483 for (cp++; isalpha((int) *cp); cp++) {
1484 /* accept mixed case */
1489 case 'a': /* 802.11a */
1490 flags |= IEEE80211_CHAN_A;
1492 case 'b': /* 802.11b */
1493 flags |= IEEE80211_CHAN_B;
1495 case 'g': /* 802.11g */
1496 flags |= IEEE80211_CHAN_G;
1498 case 'n': /* 802.11n */
1499 flags |= IEEE80211_CHAN_HT;
1501 case 'd': /* dt = Atheros Dynamic Turbo */
1502 flags |= IEEE80211_CHAN_TURBO;
1504 case 't': /* ht, dt, st, t */
1505 /* dt and unadorned t specify Dynamic Turbo */
1506 if ((flags & (IEEE80211_CHAN_STURBO|IEEE80211_CHAN_HT)) == 0)
1507 flags |= IEEE80211_CHAN_TURBO;
1509 case 's': /* st = Atheros Static Turbo */
1510 flags |= IEEE80211_CHAN_STURBO;
1512 case 'h': /* 1/2-width channels */
1513 flags |= IEEE80211_CHAN_HALF;
1515 case 'q': /* 1/4-width channels */
1516 flags |= IEEE80211_CHAN_QUARTER;
1519 /* XXX set HT too? */
1520 flags |= IEEE80211_CHAN_VHT;
1523 errx(-1, "%s: Invalid mode attribute %c\n",
1531 #define _APPLY(_flags, _base, _param, _v) do { \
1532 if (_flags & IEEE80211_CHAN_HT) { \
1533 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1534 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1535 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1536 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1537 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1539 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1541 if (_flags & IEEE80211_CHAN_TURBO) { \
1542 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1543 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1544 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1545 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1546 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1548 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1550 if (_flags & IEEE80211_CHAN_STURBO) \
1551 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1552 if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1553 _base.params[IEEE80211_MODE_11A]._param = _v; \
1554 if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1555 _base.params[IEEE80211_MODE_11G]._param = _v; \
1556 if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1557 _base.params[IEEE80211_MODE_11B]._param = _v; \
1558 if (_flags & IEEE80211_CHAN_HALF) \
1559 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1560 if (_flags & IEEE80211_CHAN_QUARTER) \
1561 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1563 #define _APPLY1(_flags, _base, _param, _v) do { \
1564 if (_flags & IEEE80211_CHAN_HT) { \
1565 if (_flags & IEEE80211_CHAN_5GHZ) \
1566 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1568 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1569 } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \
1570 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1571 else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \
1572 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1573 else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \
1574 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1575 else if (_flags & IEEE80211_CHAN_HALF) \
1576 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1577 else if (_flags & IEEE80211_CHAN_QUARTER) \
1578 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1579 else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1580 _base.params[IEEE80211_MODE_11A]._param = _v; \
1581 else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1582 _base.params[IEEE80211_MODE_11G]._param = _v; \
1583 else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1584 _base.params[IEEE80211_MODE_11B]._param = _v; \
1586 #define _APPLY_RATE(_flags, _base, _param, _v) do { \
1587 if (_flags & IEEE80211_CHAN_HT) { \
1588 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1590 _APPLY(_flags, _base, _param, _v); \
1592 #define _APPLY_RATE1(_flags, _base, _param, _v) do { \
1593 if (_flags & IEEE80211_CHAN_HT) { \
1594 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1596 _APPLY1(_flags, _base, _param, _v); \
1600 DECL_CMD_FUNC(set80211roamrssi, val, d)
1602 double v = atof(val);
1607 errx(-1, "invalid rssi (must be .5 dBm units)");
1608 flags = getmodeflags(val);
1610 if (flags == 0) { /* NB: no flags => current channel */
1611 flags = getcurchan(s)->ic_flags;
1612 _APPLY1(flags, roamparams, rssi, rssi);
1614 _APPLY(flags, roamparams, rssi, rssi);
1615 callback_register(setroam_cb, &roamparams);
1619 getrate(const char *val, const char *tag)
1621 double v = atof(val);
1626 errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag);
1627 return rate; /* NB: returns 2x the specified value */
1631 DECL_CMD_FUNC(set80211roamrate, val, d)
1635 rate = getrate(val, "roam");
1636 flags = getmodeflags(val);
1638 if (flags == 0) { /* NB: no flags => current channel */
1639 flags = getcurchan(s)->ic_flags;
1640 _APPLY_RATE1(flags, roamparams, rate, rate);
1642 _APPLY_RATE(flags, roamparams, rate, rate);
1643 callback_register(setroam_cb, &roamparams);
1647 DECL_CMD_FUNC(set80211mcastrate, val, d)
1651 rate = getrate(val, "mcast");
1652 flags = getmodeflags(val);
1654 if (flags == 0) { /* NB: no flags => current channel */
1655 flags = getcurchan(s)->ic_flags;
1656 _APPLY_RATE1(flags, txparams, mcastrate, rate);
1658 _APPLY_RATE(flags, txparams, mcastrate, rate);
1659 callback_register(settxparams_cb, &txparams);
1663 DECL_CMD_FUNC(set80211mgtrate, val, d)
1667 rate = getrate(val, "mgmt");
1668 flags = getmodeflags(val);
1670 if (flags == 0) { /* NB: no flags => current channel */
1671 flags = getcurchan(s)->ic_flags;
1672 _APPLY_RATE1(flags, txparams, mgmtrate, rate);
1674 _APPLY_RATE(flags, txparams, mgmtrate, rate);
1675 callback_register(settxparams_cb, &txparams);
1679 DECL_CMD_FUNC(set80211ucastrate, val, d)
1684 flags = getmodeflags(val);
1685 if (isanyarg(val)) {
1686 if (flags == 0) { /* NB: no flags => current channel */
1687 flags = getcurchan(s)->ic_flags;
1688 _APPLY1(flags, txparams, ucastrate,
1689 IEEE80211_FIXED_RATE_NONE);
1691 _APPLY(flags, txparams, ucastrate,
1692 IEEE80211_FIXED_RATE_NONE);
1694 int rate = getrate(val, "ucast");
1695 if (flags == 0) { /* NB: no flags => current channel */
1696 flags = getcurchan(s)->ic_flags;
1697 _APPLY_RATE1(flags, txparams, ucastrate, rate);
1699 _APPLY_RATE(flags, txparams, ucastrate, rate);
1701 callback_register(settxparams_cb, &txparams);
1705 DECL_CMD_FUNC(set80211maxretry, val, d)
1707 int v = atoi(val), flags;
1709 flags = getmodeflags(val);
1711 if (flags == 0) { /* NB: no flags => current channel */
1712 flags = getcurchan(s)->ic_flags;
1713 _APPLY1(flags, txparams, maxretry, v);
1715 _APPLY(flags, txparams, maxretry, v);
1716 callback_register(settxparams_cb, &txparams);
1722 DECL_CMD_FUNC(set80211fragthreshold, val, d)
1724 set80211(s, IEEE80211_IOC_FRAGTHRESHOLD,
1725 isundefarg(val) ? IEEE80211_FRAG_MAX : atoi(val), 0, NULL);
1729 DECL_CMD_FUNC(set80211bmissthreshold, val, d)
1731 set80211(s, IEEE80211_IOC_BMISSTHRESHOLD,
1732 isundefarg(val) ? IEEE80211_HWBMISS_MAX : atoi(val), 0, NULL);
1736 set80211burst(const char *val, int d, int s, const struct afswtch *rafp)
1738 set80211(s, IEEE80211_IOC_BURST, d, 0, NULL);
1742 set80211doth(const char *val, int d, int s, const struct afswtch *rafp)
1744 set80211(s, IEEE80211_IOC_DOTH, d, 0, NULL);
1748 set80211dfs(const char *val, int d, int s, const struct afswtch *rafp)
1750 set80211(s, IEEE80211_IOC_DFS, d, 0, NULL);
1754 set80211shortgi(const char *val, int d, int s, const struct afswtch *rafp)
1756 set80211(s, IEEE80211_IOC_SHORTGI,
1757 d ? (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) : 0,
1761 /* XXX 11ac density/size is different */
1763 set80211ampdu(const char *val, int d, int s, const struct afswtch *rafp)
1767 if (get80211val(s, IEEE80211_IOC_AMPDU, &du) < 0)
1768 errx(-1, "cannot set AMPDU setting");
1774 set80211(s, IEEE80211_IOC_AMPDU, ampdu, 0, NULL);
1778 set80211stbc(const char *val, int d, int s, const struct afswtch *rafp)
1782 if (get80211val(s, IEEE80211_IOC_STBC, &stbc) < 0)
1783 errx(-1, "cannot set STBC setting");
1789 set80211(s, IEEE80211_IOC_STBC, stbc, 0, NULL);
1793 set80211ldpc(const char *val, int d, int s, const struct afswtch *rafp)
1797 if (get80211val(s, IEEE80211_IOC_LDPC, &ldpc) < 0)
1798 errx(-1, "cannot set LDPC setting");
1804 set80211(s, IEEE80211_IOC_LDPC, ldpc, 0, NULL);
1808 set80211uapsd(const char *val, int d, int s, const struct afswtch *rafp)
1810 set80211(s, IEEE80211_IOC_UAPSD, d, 0, NULL);
1814 DECL_CMD_FUNC(set80211ampdulimit, val, d)
1818 switch (atoi(val)) {
1821 v = IEEE80211_HTCAP_MAXRXAMPDU_8K;
1825 v = IEEE80211_HTCAP_MAXRXAMPDU_16K;
1829 v = IEEE80211_HTCAP_MAXRXAMPDU_32K;
1833 v = IEEE80211_HTCAP_MAXRXAMPDU_64K;
1836 errx(-1, "invalid A-MPDU limit %s", val);
1838 set80211(s, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL);
1841 /* XXX 11ac density/size is different */
1843 DECL_CMD_FUNC(set80211ampdudensity, val, d)
1847 if (isanyarg(val) || strcasecmp(val, "na") == 0)
1848 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1849 else switch ((int)(atof(val)*4)) {
1851 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1854 v = IEEE80211_HTCAP_MPDUDENSITY_025;
1857 v = IEEE80211_HTCAP_MPDUDENSITY_05;
1860 v = IEEE80211_HTCAP_MPDUDENSITY_1;
1863 v = IEEE80211_HTCAP_MPDUDENSITY_2;
1866 v = IEEE80211_HTCAP_MPDUDENSITY_4;
1869 v = IEEE80211_HTCAP_MPDUDENSITY_8;
1872 v = IEEE80211_HTCAP_MPDUDENSITY_16;
1875 errx(-1, "invalid A-MPDU density %s", val);
1877 set80211(s, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL);
1881 set80211amsdu(const char *val, int d, int s, const struct afswtch *rafp)
1885 if (get80211val(s, IEEE80211_IOC_AMSDU, &amsdu) < 0)
1886 err(-1, "cannot get AMSDU setting");
1892 set80211(s, IEEE80211_IOC_AMSDU, amsdu, 0, NULL);
1896 DECL_CMD_FUNC(set80211amsdulimit, val, d)
1898 set80211(s, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL);
1902 set80211puren(const char *val, int d, int s, const struct afswtch *rafp)
1904 set80211(s, IEEE80211_IOC_PUREN, d, 0, NULL);
1908 set80211htcompat(const char *val, int d, int s, const struct afswtch *rafp)
1910 set80211(s, IEEE80211_IOC_HTCOMPAT, d, 0, NULL);
1914 set80211htconf(const char *val, int d, int s, const struct afswtch *rafp)
1916 set80211(s, IEEE80211_IOC_HTCONF, d, 0, NULL);
1921 set80211dwds(const char *val, int d, int s, const struct afswtch *rafp)
1923 set80211(s, IEEE80211_IOC_DWDS, d, 0, NULL);
1927 set80211inact(const char *val, int d, int s, const struct afswtch *rafp)
1929 set80211(s, IEEE80211_IOC_INACTIVITY, d, 0, NULL);
1933 set80211tsn(const char *val, int d, int s, const struct afswtch *rafp)
1935 set80211(s, IEEE80211_IOC_TSN, d, 0, NULL);
1939 set80211dotd(const char *val, int d, int s, const struct afswtch *rafp)
1941 set80211(s, IEEE80211_IOC_DOTD, d, 0, NULL);
1945 set80211smps(const char *val, int d, int s, const struct afswtch *rafp)
1947 set80211(s, IEEE80211_IOC_SMPS, d, 0, NULL);
1951 set80211rifs(const char *val, int d, int s, const struct afswtch *rafp)
1953 set80211(s, IEEE80211_IOC_RIFS, d, 0, NULL);
1957 set80211vhtconf(const char *val, int d, int s, const struct afswtch *rafp)
1959 if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0)
1960 errx(-1, "cannot set VHT setting");
1961 printf("%s: vhtconf=0x%08x, d=%d\n", __func__, vhtconf, d);
1967 printf("%s: vhtconf is now 0x%08x\n", __func__, vhtconf);
1968 set80211(s, IEEE80211_IOC_VHTCONF, vhtconf, 0, NULL);
1972 DECL_CMD_FUNC(set80211tdmaslot, val, d)
1974 set80211(s, IEEE80211_IOC_TDMA_SLOT, atoi(val), 0, NULL);
1978 DECL_CMD_FUNC(set80211tdmaslotcnt, val, d)
1980 set80211(s, IEEE80211_IOC_TDMA_SLOTCNT, atoi(val), 0, NULL);
1984 DECL_CMD_FUNC(set80211tdmaslotlen, val, d)
1986 set80211(s, IEEE80211_IOC_TDMA_SLOTLEN, atoi(val), 0, NULL);
1990 DECL_CMD_FUNC(set80211tdmabintval, val, d)
1992 set80211(s, IEEE80211_IOC_TDMA_BINTERVAL, atoi(val), 0, NULL);
1996 DECL_CMD_FUNC(set80211meshttl, val, d)
1998 set80211(s, IEEE80211_IOC_MESH_TTL, atoi(val), 0, NULL);
2002 DECL_CMD_FUNC(set80211meshforward, val, d)
2004 set80211(s, IEEE80211_IOC_MESH_FWRD, d, 0, NULL);
2008 DECL_CMD_FUNC(set80211meshgate, val, d)
2010 set80211(s, IEEE80211_IOC_MESH_GATE, d, 0, NULL);
2014 DECL_CMD_FUNC(set80211meshpeering, val, d)
2016 set80211(s, IEEE80211_IOC_MESH_AP, d, 0, NULL);
2020 DECL_CMD_FUNC(set80211meshmetric, val, d)
2024 memcpy(v, val, sizeof(v));
2025 set80211(s, IEEE80211_IOC_MESH_PR_METRIC, 0, 0, v);
2029 DECL_CMD_FUNC(set80211meshpath, val, d)
2033 memcpy(v, val, sizeof(v));
2034 set80211(s, IEEE80211_IOC_MESH_PR_PATH, 0, 0, v);
2038 regdomain_sort(const void *a, const void *b)
2041 (IEEE80211_CHAN_ALLTURBO|IEEE80211_CHAN_HALF|IEEE80211_CHAN_QUARTER)
2042 const struct ieee80211_channel *ca = a;
2043 const struct ieee80211_channel *cb = b;
2045 return ca->ic_freq == cb->ic_freq ?
2046 (ca->ic_flags & CHAN_ALL) - (cb->ic_flags & CHAN_ALL) :
2047 ca->ic_freq - cb->ic_freq;
2051 static const struct ieee80211_channel *
2052 chanlookup(const struct ieee80211_channel chans[], int nchans,
2053 int freq, int flags)
2057 flags &= IEEE80211_CHAN_ALLTURBO;
2058 for (i = 0; i < nchans; i++) {
2059 const struct ieee80211_channel *c = &chans[i];
2060 if (c->ic_freq == freq &&
2061 (c->ic_flags & IEEE80211_CHAN_ALLTURBO) == flags)
2068 chanfind(const struct ieee80211_channel chans[], int nchans, int flags)
2072 for (i = 0; i < nchans; i++) {
2073 const struct ieee80211_channel *c = &chans[i];
2074 if ((c->ic_flags & flags) == flags)
2081 * Check channel compatibility.
2084 checkchan(const struct ieee80211req_chaninfo *avail, int freq, int flags)
2086 flags &= ~REQ_FLAGS;
2088 * Check if exact channel is in the calibration table;
2089 * everything below is to deal with channels that we
2090 * want to include but that are not explicitly listed.
2092 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, flags) != NULL)
2094 if (flags & IEEE80211_CHAN_GSM) {
2096 * XXX GSM frequency mapping is handled in the kernel
2097 * so we cannot find them in the calibration table;
2098 * just accept the channel and the kernel will reject
2099 * the channel list if it's wrong.
2104 * If this is a 1/2 or 1/4 width channel allow it if a full
2105 * width channel is present for this frequency, and the device
2106 * supports fractional channels on this band. This is a hack
2107 * that avoids bloating the calibration table; it may be better
2108 * by per-band attributes though (we are effectively calculating
2109 * this attribute by scanning the channel list ourself).
2111 if ((flags & (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == 0)
2113 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq,
2114 flags &~ (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == NULL)
2116 if (flags & IEEE80211_CHAN_HALF) {
2117 return chanfind(avail->ic_chans, avail->ic_nchans,
2118 IEEE80211_CHAN_HALF |
2119 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2121 return chanfind(avail->ic_chans, avail->ic_nchans,
2122 IEEE80211_CHAN_QUARTER |
2123 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
2128 regdomain_addchans(struct ieee80211req_chaninfo *ci,
2129 const netband_head *bands,
2130 const struct ieee80211_regdomain *reg,
2132 const struct ieee80211req_chaninfo *avail)
2134 const struct netband *nb;
2135 const struct freqband *b;
2136 struct ieee80211_channel *c, *prev;
2137 int freq, hi_adj, lo_adj, channelSep;
2140 hi_adj = (chanFlags & IEEE80211_CHAN_HT40U) ? -20 : 0;
2141 lo_adj = (chanFlags & IEEE80211_CHAN_HT40D) ? 20 : 0;
2142 channelSep = (chanFlags & IEEE80211_CHAN_2GHZ) ? 0 : 40;
2144 LIST_FOREACH(nb, bands, next) {
2147 printf("%s:", __func__);
2148 printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS);
2149 printb(" bandFlags", nb->flags | b->flags,
2150 IEEE80211_CHAN_BITS);
2155 for (freq = b->freqStart + lo_adj;
2156 freq <= b->freqEnd + hi_adj; freq += b->chanSep) {
2158 * Construct flags for the new channel. We take
2159 * the attributes from the band descriptions except
2160 * for HT40 which is enabled generically (i.e. +/-
2161 * extension channel) in the band description and
2162 * then constrained according by channel separation.
2164 flags = nb->flags | b->flags;
2167 * VHT first - HT is a subset.
2169 * XXX TODO: VHT80p80, VHT160 is not yet done.
2171 if (flags & IEEE80211_CHAN_VHT) {
2172 if ((chanFlags & IEEE80211_CHAN_VHT20) &&
2173 (flags & IEEE80211_CHAN_VHT20) == 0) {
2175 printf("%u: skip, not a "
2176 "VHT20 channel\n", freq);
2179 if ((chanFlags & IEEE80211_CHAN_VHT40) &&
2180 (flags & IEEE80211_CHAN_VHT40) == 0) {
2182 printf("%u: skip, not a "
2183 "VHT40 channel\n", freq);
2186 if ((chanFlags & IEEE80211_CHAN_VHT80) &&
2187 (flags & IEEE80211_CHAN_VHT80) == 0) {
2189 printf("%u: skip, not a "
2190 "VHT80 channel\n", freq);
2194 flags &= ~IEEE80211_CHAN_VHT;
2195 flags |= chanFlags & IEEE80211_CHAN_VHT;
2198 /* Now, constrain HT */
2199 if (flags & IEEE80211_CHAN_HT) {
2201 * HT channels are generated specially; we're
2202 * called to add HT20, HT40+, and HT40- chan's
2203 * so we need to expand only band specs for
2204 * the HT channel type being added.
2206 if ((chanFlags & IEEE80211_CHAN_HT20) &&
2207 (flags & IEEE80211_CHAN_HT20) == 0) {
2209 printf("%u: skip, not an "
2210 "HT20 channel\n", freq);
2213 if ((chanFlags & IEEE80211_CHAN_HT40) &&
2214 (flags & IEEE80211_CHAN_HT40) == 0) {
2216 printf("%u: skip, not an "
2217 "HT40 channel\n", freq);
2220 /* NB: HT attribute comes from caller */
2221 flags &= ~IEEE80211_CHAN_HT;
2222 flags |= chanFlags & IEEE80211_CHAN_HT;
2225 * Check if device can operate on this frequency.
2227 if (!checkchan(avail, freq, flags)) {
2229 printf("%u: skip, ", freq);
2230 printb("flags", flags,
2231 IEEE80211_CHAN_BITS);
2232 printf(" not available\n");
2236 if ((flags & REQ_ECM) && !reg->ecm) {
2238 printf("%u: skip, ECM channel\n", freq);
2241 if ((flags & REQ_INDOOR) && reg->location == 'O') {
2243 printf("%u: skip, indoor channel\n",
2247 if ((flags & REQ_OUTDOOR) && reg->location == 'I') {
2249 printf("%u: skip, outdoor channel\n",
2253 if ((flags & IEEE80211_CHAN_HT40) &&
2254 prev != NULL && (freq - prev->ic_freq) < channelSep) {
2256 printf("%u: skip, only %u channel "
2257 "separation, need %d\n", freq,
2258 freq - prev->ic_freq, channelSep);
2261 if (ci->ic_nchans == IEEE80211_CHAN_MAX) {
2263 printf("%u: skip, channel table full\n",
2267 c = &ci->ic_chans[ci->ic_nchans++];
2268 memset(c, 0, sizeof(*c));
2270 c->ic_flags = flags;
2271 if (c->ic_flags & IEEE80211_CHAN_DFS)
2272 c->ic_maxregpower = nb->maxPowerDFS;
2274 c->ic_maxregpower = nb->maxPower;
2276 printf("[%3d] add freq %u ",
2277 ci->ic_nchans-1, c->ic_freq);
2278 printb("flags", c->ic_flags, IEEE80211_CHAN_BITS);
2279 printf(" power %u\n", c->ic_maxregpower);
2281 /* NB: kernel fills in other fields */
2288 regdomain_makechannels(
2289 struct ieee80211_regdomain_req *req,
2290 const struct ieee80211_devcaps_req *dc)
2292 struct regdata *rdp = getregdata();
2293 const struct country *cc;
2294 const struct ieee80211_regdomain *reg = &req->rd;
2295 struct ieee80211req_chaninfo *ci = &req->chaninfo;
2296 const struct regdomain *rd;
2299 * Locate construction table for new channel list. We treat
2300 * the regdomain/SKU as definitive so a country can be in
2301 * multiple with different properties (e.g. US in FCC+FCC3).
2302 * If no regdomain is specified then we fallback on the country
2303 * code to find the associated regdomain since countries always
2304 * belong to at least one regdomain.
2306 if (reg->regdomain == 0) {
2307 cc = lib80211_country_findbycc(rdp, reg->country);
2309 errx(1, "internal error, country %d not found",
2313 rd = lib80211_regdomain_findbysku(rdp, reg->regdomain);
2315 errx(1, "internal error, regdomain %d not found",
2317 if (rd->sku != SKU_DEBUG) {
2319 * regdomain_addchans incrememnts the channel count for
2320 * each channel it adds so initialize ic_nchans to zero.
2321 * Note that we know we have enough space to hold all possible
2322 * channels because the devcaps list size was used to
2323 * allocate our request.
2326 if (!LIST_EMPTY(&rd->bands_11b))
2327 regdomain_addchans(ci, &rd->bands_11b, reg,
2328 IEEE80211_CHAN_B, &dc->dc_chaninfo);
2329 if (!LIST_EMPTY(&rd->bands_11g))
2330 regdomain_addchans(ci, &rd->bands_11g, reg,
2331 IEEE80211_CHAN_G, &dc->dc_chaninfo);
2332 if (!LIST_EMPTY(&rd->bands_11a))
2333 regdomain_addchans(ci, &rd->bands_11a, reg,
2334 IEEE80211_CHAN_A, &dc->dc_chaninfo);
2335 if (!LIST_EMPTY(&rd->bands_11na) && dc->dc_htcaps != 0) {
2336 regdomain_addchans(ci, &rd->bands_11na, reg,
2337 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20,
2339 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2340 regdomain_addchans(ci, &rd->bands_11na, reg,
2341 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U,
2343 regdomain_addchans(ci, &rd->bands_11na, reg,
2344 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D,
2348 if (!LIST_EMPTY(&rd->bands_11ac) && dc->dc_vhtcaps != 0) {
2349 regdomain_addchans(ci, &rd->bands_11ac, reg,
2350 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20 |
2351 IEEE80211_CHAN_VHT20,
2354 /* VHT40 is a function of HT40.. */
2355 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2356 regdomain_addchans(ci, &rd->bands_11ac, reg,
2357 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U |
2358 IEEE80211_CHAN_VHT40U,
2360 regdomain_addchans(ci, &rd->bands_11ac, reg,
2361 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D |
2362 IEEE80211_CHAN_VHT40D,
2367 /* XXX dc_vhtcap? */
2369 regdomain_addchans(ci, &rd->bands_11ac, reg,
2370 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U |
2371 IEEE80211_CHAN_VHT80,
2373 regdomain_addchans(ci, &rd->bands_11ac, reg,
2374 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D |
2375 IEEE80211_CHAN_VHT80,
2379 /* XXX TODO: VHT80_80, VHT160 */
2382 if (!LIST_EMPTY(&rd->bands_11ng) && dc->dc_htcaps != 0) {
2383 regdomain_addchans(ci, &rd->bands_11ng, reg,
2384 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20,
2386 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2387 regdomain_addchans(ci, &rd->bands_11ng, reg,
2388 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U,
2390 regdomain_addchans(ci, &rd->bands_11ng, reg,
2391 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D,
2395 qsort(ci->ic_chans, ci->ic_nchans, sizeof(ci->ic_chans[0]),
2398 memcpy(ci, &dc->dc_chaninfo,
2399 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
2403 list_countries(void)
2405 struct regdata *rdp = getregdata();
2406 const struct country *cp;
2407 const struct regdomain *dp;
2411 printf("\nCountry codes:\n");
2412 LIST_FOREACH(cp, &rdp->countries, next) {
2413 printf("%2s %-15.15s%s", cp->isoname,
2414 cp->name, ((i+1)%4) == 0 ? "\n" : " ");
2418 printf("\nRegulatory domains:\n");
2419 LIST_FOREACH(dp, &rdp->domains, next) {
2420 printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " ");
2427 defaultcountry(const struct regdomain *rd)
2429 struct regdata *rdp = getregdata();
2430 const struct country *cc;
2432 cc = lib80211_country_findbycc(rdp, rd->cc->code);
2434 errx(1, "internal error, ISO country code %d not "
2435 "defined for regdomain %s", rd->cc->code, rd->name);
2436 regdomain.country = cc->code;
2437 regdomain.isocc[0] = cc->isoname[0];
2438 regdomain.isocc[1] = cc->isoname[1];
2442 DECL_CMD_FUNC(set80211regdomain, val, d)
2444 struct regdata *rdp = getregdata();
2445 const struct regdomain *rd;
2447 rd = lib80211_regdomain_findbyname(rdp, val);
2450 long sku = strtol(val, &eptr, 0);
2453 rd = lib80211_regdomain_findbysku(rdp, sku);
2454 if (eptr == val || rd == NULL)
2455 errx(1, "unknown regdomain %s", val);
2458 regdomain.regdomain = rd->sku;
2459 if (regdomain.country == 0 && rd->cc != NULL) {
2461 * No country code setup and there's a default
2462 * one for this regdomain fill it in.
2466 callback_register(setregdomain_cb, ®domain);
2470 DECL_CMD_FUNC(set80211country, val, d)
2472 struct regdata *rdp = getregdata();
2473 const struct country *cc;
2475 cc = lib80211_country_findbyname(rdp, val);
2478 long code = strtol(val, &eptr, 0);
2481 cc = lib80211_country_findbycc(rdp, code);
2482 if (eptr == val || cc == NULL)
2483 errx(1, "unknown ISO country code %s", val);
2486 regdomain.regdomain = cc->rd->sku;
2487 regdomain.country = cc->code;
2488 regdomain.isocc[0] = cc->isoname[0];
2489 regdomain.isocc[1] = cc->isoname[1];
2490 callback_register(setregdomain_cb, ®domain);
2494 set80211location(const char *val, int d, int s, const struct afswtch *rafp)
2497 regdomain.location = d;
2498 callback_register(setregdomain_cb, ®domain);
2502 set80211ecm(const char *val, int d, int s, const struct afswtch *rafp)
2506 callback_register(setregdomain_cb, ®domain);
2522 if (spacer != '\t') {
2526 col = 8; /* 8-col tab */
2530 LINE_CHECK(const char *fmt, ...)
2537 n = vsnprintf(buf+1, sizeof(buf)-1, fmt, ap);
2550 getmaxrate(const uint8_t rates[15], uint8_t nrates)
2552 int i, maxrate = -1;
2554 for (i = 0; i < nrates; i++) {
2555 int rate = rates[i] & IEEE80211_RATE_VAL;
2563 getcaps(int capinfo)
2565 static char capstring[32];
2566 char *cp = capstring;
2568 if (capinfo & IEEE80211_CAPINFO_ESS)
2570 if (capinfo & IEEE80211_CAPINFO_IBSS)
2572 if (capinfo & IEEE80211_CAPINFO_CF_POLLABLE)
2574 if (capinfo & IEEE80211_CAPINFO_CF_POLLREQ)
2576 if (capinfo & IEEE80211_CAPINFO_PRIVACY)
2578 if (capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)
2580 if (capinfo & IEEE80211_CAPINFO_PBCC)
2582 if (capinfo & IEEE80211_CAPINFO_CHNL_AGILITY)
2584 if (capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME)
2586 if (capinfo & IEEE80211_CAPINFO_RSN)
2588 if (capinfo & IEEE80211_CAPINFO_DSSSOFDM)
2597 static char flagstring[32];
2598 char *cp = flagstring;
2600 if (flags & IEEE80211_NODE_AUTH)
2602 if (flags & IEEE80211_NODE_QOS)
2604 if (flags & IEEE80211_NODE_ERP)
2606 if (flags & IEEE80211_NODE_PWR_MGT)
2608 if (flags & IEEE80211_NODE_HT) {
2610 if (flags & IEEE80211_NODE_HTCOMPAT)
2613 if (flags & IEEE80211_NODE_VHT)
2615 if (flags & IEEE80211_NODE_WPS)
2617 if (flags & IEEE80211_NODE_TSN)
2619 if (flags & IEEE80211_NODE_AMPDU_TX)
2621 if (flags & IEEE80211_NODE_AMPDU_RX)
2623 if (flags & IEEE80211_NODE_MIMO_PS) {
2625 if (flags & IEEE80211_NODE_MIMO_RTS)
2628 if (flags & IEEE80211_NODE_RIFS)
2630 if (flags & IEEE80211_NODE_SGI40) {
2632 if (flags & IEEE80211_NODE_SGI20)
2634 } else if (flags & IEEE80211_NODE_SGI20)
2636 if (flags & IEEE80211_NODE_AMSDU_TX)
2638 if (flags & IEEE80211_NODE_AMSDU_RX)
2645 printie(const char* tag, const uint8_t *ie, size_t ielen, int maxlen)
2649 maxlen -= strlen(tag)+2;
2650 if (2*ielen > maxlen)
2653 for (; ielen > 0; ie++, ielen--) {
2656 printf("%02x", *ie);
2664 #define LE_READ_2(p) \
2666 ((((const u_int8_t *)(p))[0] ) | \
2667 (((const u_int8_t *)(p))[1] << 8)))
2668 #define LE_READ_4(p) \
2670 ((((const u_int8_t *)(p))[0] ) | \
2671 (((const u_int8_t *)(p))[1] << 8) | \
2672 (((const u_int8_t *)(p))[2] << 16) | \
2673 (((const u_int8_t *)(p))[3] << 24)))
2676 * NB: The decoding routines assume a properly formatted ie
2677 * which should be safe as the kernel only retains them
2682 printwmeparam(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2684 #define MS(_v, _f) (((_v) & _f) >> _f##_S)
2685 static const char *acnames[] = { "BE", "BK", "VO", "VI" };
2686 const struct ieee80211_wme_param *wme =
2687 (const struct ieee80211_wme_param *) ie;
2693 printf("<qosinfo 0x%x", wme->param_qosInfo);
2694 ie += offsetof(struct ieee80211_wme_param, params_acParams);
2695 for (i = 0; i < WME_NUM_AC; i++) {
2696 const struct ieee80211_wme_acparams *ac =
2697 &wme->params_acParams[i];
2699 printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]"
2701 , MS(ac->acp_aci_aifsn, WME_PARAM_ACM) ? "acm " : ""
2702 , MS(ac->acp_aci_aifsn, WME_PARAM_AIFSN)
2703 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMIN)
2704 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMAX)
2705 , LE_READ_2(&ac->acp_txop)
2713 printwmeinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2717 const struct ieee80211_wme_info *wme =
2718 (const struct ieee80211_wme_info *) ie;
2719 printf("<version 0x%x info 0x%x>",
2720 wme->wme_version, wme->wme_info);
2725 printvhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2729 const struct ieee80211_ie_vhtcap *vhtcap =
2730 (const struct ieee80211_ie_vhtcap *) ie;
2731 uint32_t vhtcap_info = LE_READ_4(&vhtcap->vht_cap_info);
2733 printf("<cap 0x%08x", vhtcap_info);
2734 printf(" rx_mcs_map 0x%x",
2735 LE_READ_2(&vhtcap->supp_mcs.rx_mcs_map));
2736 printf(" rx_highest %d",
2737 LE_READ_2(&vhtcap->supp_mcs.rx_highest) & 0x1fff);
2738 printf(" tx_mcs_map 0x%x",
2739 LE_READ_2(&vhtcap->supp_mcs.tx_mcs_map));
2740 printf(" tx_highest %d",
2741 LE_READ_2(&vhtcap->supp_mcs.tx_highest) & 0x1fff);
2748 printvhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2752 const struct ieee80211_ie_vht_operation *vhtinfo =
2753 (const struct ieee80211_ie_vht_operation *) ie;
2755 printf("<chw %d freq1_idx %d freq2_idx %d basic_mcs_set 0x%04x>",
2756 vhtinfo->chan_width,
2757 vhtinfo->center_freq_seg1_idx,
2758 vhtinfo->center_freq_seg2_idx,
2759 LE_READ_2(&vhtinfo->basic_mcs_set));
2764 printvhtpwrenv(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2767 static const char *txpwrmap[] = {
2774 const struct ieee80211_ie_vht_txpwrenv *vhtpwr =
2775 (const struct ieee80211_ie_vht_txpwrenv *) ie;
2777 const char *sep = "";
2779 /* Get count; trim at ielen */
2780 n = (vhtpwr->tx_info &
2781 IEEE80211_VHT_TXPWRENV_INFO_COUNT_MASK) + 1;
2785 printf("<tx_info 0x%02x pwr:[", vhtpwr->tx_info);
2786 for (i = 0; i < n; i++) {
2787 printf("%s%s:%.2f", sep, txpwrmap[i],
2788 ((float) ((int8_t) ie[i+3])) / 2.0);
2797 printhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2801 const struct ieee80211_ie_htcap *htcap =
2802 (const struct ieee80211_ie_htcap *) ie;
2806 printf("<cap 0x%x param 0x%x",
2807 LE_READ_2(&htcap->hc_cap), htcap->hc_param);
2810 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2811 if (isset(htcap->hc_mcsset, i)) {
2812 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2813 if (isclr(htcap->hc_mcsset, j))
2817 printf("%s%u", sep, i);
2819 printf("%s%u-%u", sep, i, j);
2823 printf("] extcap 0x%x txbf 0x%x antenna 0x%x>",
2824 LE_READ_2(&htcap->hc_extcap),
2825 LE_READ_4(&htcap->hc_txbf),
2831 printhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2835 const struct ieee80211_ie_htinfo *htinfo =
2836 (const struct ieee80211_ie_htinfo *) ie;
2840 printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel,
2841 htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3,
2842 LE_READ_2(&htinfo->hi_byte45));
2843 printf(" basicmcs[");
2845 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2846 if (isset(htinfo->hi_basicmcsset, i)) {
2847 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2848 if (isclr(htinfo->hi_basicmcsset, j))
2852 printf("%s%u", sep, i);
2854 printf("%s%u-%u", sep, i, j);
2863 printathie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2868 const struct ieee80211_ath_ie *ath =
2869 (const struct ieee80211_ath_ie *)ie;
2872 if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME)
2874 if (ath->ath_capability & ATHEROS_CAP_COMPRESSION)
2876 if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME)
2878 if (ath->ath_capability & ATHEROS_CAP_XR)
2880 if (ath->ath_capability & ATHEROS_CAP_AR)
2882 if (ath->ath_capability & ATHEROS_CAP_BURST)
2884 if (ath->ath_capability & ATHEROS_CAP_WME)
2886 if (ath->ath_capability & ATHEROS_CAP_BOOST)
2888 printf("0x%x>", LE_READ_2(ath->ath_defkeyix));
2894 printmeshconf(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2899 const struct ieee80211_meshconf_ie *mconf =
2900 (const struct ieee80211_meshconf_ie *)ie;
2902 if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP)
2907 if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME)
2911 printf(" CONGESTION:");
2912 if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED)
2917 if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF)
2922 if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED)
2926 printf(" FORM:0x%x CAPS:0x%x>", mconf->conf_form,
2932 printbssload(const char *tag, const uint8_t *ie, size_t ielen, int maxlen)
2936 const struct ieee80211_bss_load_ie *bssload =
2937 (const struct ieee80211_bss_load_ie *) ie;
2938 printf("<sta count %d, chan load %d, aac %d>",
2939 LE_READ_2(&bssload->sta_count),
2946 printapchanrep(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2950 const struct ieee80211_ap_chan_report_ie *ap =
2951 (const struct ieee80211_ap_chan_report_ie *) ie;
2952 const char *sep = "";
2955 printf("<class %u, chan:[", ap->i_class);
2957 for (i = 3; i < ielen; i++) {
2958 printf("%s%u", sep, ie[i]);
2966 wpa_cipher(const u_int8_t *sel)
2968 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2969 u_int32_t w = LE_READ_4(sel);
2972 case WPA_SEL(WPA_CSE_NULL):
2974 case WPA_SEL(WPA_CSE_WEP40):
2976 case WPA_SEL(WPA_CSE_WEP104):
2978 case WPA_SEL(WPA_CSE_TKIP):
2980 case WPA_SEL(WPA_CSE_CCMP):
2983 return "?"; /* NB: so 1<< is discarded */
2988 wpa_keymgmt(const u_int8_t *sel)
2990 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2991 u_int32_t w = LE_READ_4(sel);
2994 case WPA_SEL(WPA_ASE_8021X_UNSPEC):
2995 return "8021X-UNSPEC";
2996 case WPA_SEL(WPA_ASE_8021X_PSK):
2998 case WPA_SEL(WPA_ASE_NONE):
3006 printwpaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3008 u_int8_t len = ie[1];
3015 ie += 6, len -= 4; /* NB: len is payload only */
3017 printf("<v%u", LE_READ_2(ie));
3020 printf(" mc:%s", wpa_cipher(ie));
3023 /* unicast ciphers */
3027 for (; n > 0; n--) {
3028 printf("%s%s", sep, wpa_cipher(ie));
3033 /* key management algorithms */
3037 for (; n > 0; n--) {
3038 printf("%s%s", sep, wpa_keymgmt(ie));
3043 if (len > 2) /* optional capabilities */
3044 printf(", caps 0x%x", LE_READ_2(ie));
3050 rsn_cipher(const u_int8_t *sel)
3052 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
3053 u_int32_t w = LE_READ_4(sel);
3056 case RSN_SEL(RSN_CSE_NULL):
3058 case RSN_SEL(RSN_CSE_WEP40):
3060 case RSN_SEL(RSN_CSE_WEP104):
3062 case RSN_SEL(RSN_CSE_TKIP):
3064 case RSN_SEL(RSN_CSE_CCMP):
3066 case RSN_SEL(RSN_CSE_WRAP):
3074 rsn_keymgmt(const u_int8_t *sel)
3076 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
3077 u_int32_t w = LE_READ_4(sel);
3080 case RSN_SEL(RSN_ASE_8021X_UNSPEC):
3081 return "8021X-UNSPEC";
3082 case RSN_SEL(RSN_ASE_8021X_PSK):
3084 case RSN_SEL(RSN_ASE_NONE):
3092 printrsnie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3099 ie += 2, ielen -= 2;
3101 printf("<v%u", LE_READ_2(ie));
3102 ie += 2, ielen -= 2;
3104 printf(" mc:%s", rsn_cipher(ie));
3105 ie += 4, ielen -= 4;
3107 /* unicast ciphers */
3109 ie += 2, ielen -= 2;
3111 for (; n > 0; n--) {
3112 printf("%s%s", sep, rsn_cipher(ie));
3113 ie += 4, ielen -= 4;
3117 /* key management algorithms */
3119 ie += 2, ielen -= 2;
3121 for (; n > 0; n--) {
3122 printf("%s%s", sep, rsn_keymgmt(ie));
3123 ie += 4, ielen -= 4;
3127 if (ielen > 2) /* optional capabilities */
3128 printf(", caps 0x%x", LE_READ_2(ie));
3134 #define BE_READ_2(p) \
3136 ((((const u_int8_t *)(p))[1] ) | \
3137 (((const u_int8_t *)(p))[0] << 8)))
3140 printwpsie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3142 u_int8_t len = ie[1];
3146 static const char *dev_pass_id[] = {
3147 "D", /* Default (PIN) */
3148 "U", /* User-specified */
3149 "M", /* Machine-specified */
3151 "P", /* PushButton */
3152 "R" /* Registrar-specified */
3157 ie +=6, len -= 4; /* NB: len is payload only */
3159 /* WPS IE in Beacon and Probe Resp frames have different fields */
3162 uint16_t tlv_type = BE_READ_2(ie);
3163 uint16_t tlv_len = BE_READ_2(ie + 2);
3166 /* some devices broadcast invalid WPS frames */
3167 if (tlv_len > len) {
3168 printf("bad frame length tlv_type=0x%02x "
3169 "tlv_len=%d len=%d", tlv_type, tlv_len,
3177 case IEEE80211_WPS_ATTR_VERSION:
3178 printf("v:%d.%d", *ie >> 4, *ie & 0xf);
3180 case IEEE80211_WPS_ATTR_AP_SETUP_LOCKED:
3181 printf(" ap_setup:%s", *ie ? "locked" :
3184 case IEEE80211_WPS_ATTR_CONFIG_METHODS:
3185 case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS:
3186 if (tlv_type == IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS)
3187 printf(" sel_reg_cfg_mthd:");
3189 printf(" cfg_mthd:" );
3190 cfg_mthd = BE_READ_2(ie);
3192 for (n = 15; n >= 0; n--) {
3197 switch (cfg_mthd & (1 << n)) {
3200 case IEEE80211_WPS_CONFIG_USBA:
3204 case IEEE80211_WPS_CONFIG_ETHERNET:
3208 case IEEE80211_WPS_CONFIG_LABEL:
3212 case IEEE80211_WPS_CONFIG_DISPLAY:
3214 (IEEE80211_WPS_CONFIG_VIRT_DISPLAY |
3215 IEEE80211_WPS_CONFIG_PHY_DISPLAY)))
3221 case IEEE80211_WPS_CONFIG_EXT_NFC_TOKEN:
3222 printf("ext_nfc_tokenk");
3225 case IEEE80211_WPS_CONFIG_INT_NFC_TOKEN:
3226 printf("int_nfc_token");
3229 case IEEE80211_WPS_CONFIG_NFC_INTERFACE:
3230 printf("nfc_interface");
3233 case IEEE80211_WPS_CONFIG_PUSHBUTTON:
3235 (IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON |
3236 IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON))) {
3237 printf("push_button");
3241 case IEEE80211_WPS_CONFIG_KEYPAD:
3245 case IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON:
3246 printf("virtual_push_button");
3249 case IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON:
3250 printf("physical_push_button");
3253 case IEEE80211_WPS_CONFIG_P2PS:
3257 case IEEE80211_WPS_CONFIG_VIRT_DISPLAY:
3258 printf("virtual_display");
3261 case IEEE80211_WPS_CONFIG_PHY_DISPLAY:
3262 printf("physical_display");
3266 printf("unknown_wps_config<%04x>",
3267 cfg_mthd & (1 << n));
3273 case IEEE80211_WPS_ATTR_DEV_NAME:
3274 printf(" device_name:<%.*s>", tlv_len, ie);
3276 case IEEE80211_WPS_ATTR_DEV_PASSWORD_ID:
3278 if (n < nitems(dev_pass_id))
3279 printf(" dpi:%s", dev_pass_id[n]);
3281 case IEEE80211_WPS_ATTR_MANUFACTURER:
3282 printf(" manufacturer:<%.*s>", tlv_len, ie);
3284 case IEEE80211_WPS_ATTR_MODEL_NAME:
3285 printf(" model_name:<%.*s>", tlv_len, ie);
3287 case IEEE80211_WPS_ATTR_MODEL_NUMBER:
3288 printf(" model_number:<%.*s>", tlv_len, ie);
3290 case IEEE80211_WPS_ATTR_PRIMARY_DEV_TYPE:
3291 printf(" prim_dev:");
3292 for (n = 0; n < tlv_len; n++)
3293 printf("%02x", ie[n]);
3295 case IEEE80211_WPS_ATTR_RF_BANDS:
3298 for (n = 7; n >= 0; n--) {
3303 switch (*ie & (1 << n)) {
3306 case IEEE80211_WPS_RF_BAND_24GHZ:
3310 case IEEE80211_WPS_RF_BAND_50GHZ:
3314 case IEEE80211_WPS_RF_BAND_600GHZ:
3319 printf("unknown<%02x>",
3326 case IEEE80211_WPS_ATTR_RESPONSE_TYPE:
3327 printf(" resp_type:0x%02x", *ie);
3329 case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR:
3330 printf(" sel:%s", *ie ? "T" : "F");
3332 case IEEE80211_WPS_ATTR_SERIAL_NUMBER:
3333 printf(" serial_number:<%.*s>", tlv_len, ie);
3335 case IEEE80211_WPS_ATTR_UUID_E:
3337 for (n = 0; n < (tlv_len - 1); n++)
3338 printf("%02x-", ie[n]);
3339 printf("%02x", ie[n]);
3341 case IEEE80211_WPS_ATTR_VENDOR_EXT:
3343 for (n = 0; n < tlv_len; n++)
3344 printf("%02x", ie[n]);
3346 case IEEE80211_WPS_ATTR_WPS_STATE:
3348 case IEEE80211_WPS_STATE_NOT_CONFIGURED:
3351 case IEEE80211_WPS_STATE_CONFIGURED:
3355 printf(" state:B<%02x>", *ie);
3360 printf(" unknown_wps_attr:0x%x", tlv_type);
3363 ie += tlv_len, len -= tlv_len;
3370 printtdmaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3373 if (verbose && ielen >= sizeof(struct ieee80211_tdma_param)) {
3374 const struct ieee80211_tdma_param *tdma =
3375 (const struct ieee80211_tdma_param *) ie;
3378 printf("<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>",
3379 tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt,
3380 LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval,
3381 tdma->tdma_inuse[0]);
3386 * Copy the ssid string contents into buf, truncating to fit. If the
3387 * ssid is entirely printable then just copy intact. Otherwise convert
3388 * to hexadecimal. If the result is truncated then replace the last
3389 * three characters with "...".
3392 copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len)
3398 if (essid_len > bufsize)
3402 /* determine printable or not */
3403 for (i = 0, p = essid; i < maxlen; i++, p++) {
3404 if (*p < ' ' || *p > 0x7e)
3407 if (i != maxlen) { /* not printable, print as hex */
3410 strlcpy(buf, "0x", bufsize);
3413 for (i = 0; i < maxlen && bufsize >= 2; i++) {
3414 sprintf(&buf[2+2*i], "%02x", p[i]);
3418 memcpy(&buf[2+2*i-3], "...", 3);
3419 } else { /* printable, truncate as needed */
3420 memcpy(buf, essid, maxlen);
3421 if (maxlen != essid_len)
3422 memcpy(&buf[maxlen-3], "...", 3);
3428 printssid(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3430 char ssid[2*IEEE80211_NWID_LEN+1];
3432 printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid);
3436 printrates(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3443 for (i = 2; i < ielen; i++) {
3444 printf("%s%s%d", sep,
3445 ie[i] & IEEE80211_RATE_BASIC ? "B" : "",
3446 ie[i] & IEEE80211_RATE_VAL);
3453 printcountry(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
3455 const struct ieee80211_country_ie *cie =
3456 (const struct ieee80211_country_ie *) ie;
3457 int i, nbands, schan, nchan;
3459 printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]);
3460 nbands = (cie->len - 3) / sizeof(cie->band[0]);
3461 for (i = 0; i < nbands; i++) {
3462 schan = cie->band[i].schan;
3463 nchan = cie->band[i].nchan;
3465 printf(" %u-%u,%u", schan, schan + nchan-1,
3466 cie->band[i].maxtxpwr);
3468 printf(" %u,%u", schan, cie->band[i].maxtxpwr);
3474 iswpaoui(const u_int8_t *frm)
3476 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI);
3480 iswmeinfo(const u_int8_t *frm)
3482 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3483 frm[6] == WME_INFO_OUI_SUBTYPE;
3487 iswmeparam(const u_int8_t *frm)
3489 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
3490 frm[6] == WME_PARAM_OUI_SUBTYPE;
3494 isatherosoui(const u_int8_t *frm)
3496 return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI);
3500 istdmaoui(const uint8_t *frm)
3502 return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI);
3506 iswpsoui(const uint8_t *frm)
3508 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPS_OUI_TYPE<<24)|WPA_OUI);
3514 static char iename_buf[64];
3516 case IEEE80211_ELEMID_FHPARMS: return " FHPARMS";
3517 case IEEE80211_ELEMID_CFPARMS: return " CFPARMS";
3518 case IEEE80211_ELEMID_TIM: return " TIM";
3519 case IEEE80211_ELEMID_IBSSPARMS:return " IBSSPARMS";
3520 case IEEE80211_ELEMID_BSSLOAD: return " BSSLOAD";
3521 case IEEE80211_ELEMID_CHALLENGE:return " CHALLENGE";
3522 case IEEE80211_ELEMID_PWRCNSTR: return " PWRCNSTR";
3523 case IEEE80211_ELEMID_PWRCAP: return " PWRCAP";
3524 case IEEE80211_ELEMID_TPCREQ: return " TPCREQ";
3525 case IEEE80211_ELEMID_TPCREP: return " TPCREP";
3526 case IEEE80211_ELEMID_SUPPCHAN: return " SUPPCHAN";
3527 case IEEE80211_ELEMID_CSA: return " CSA";
3528 case IEEE80211_ELEMID_MEASREQ: return " MEASREQ";
3529 case IEEE80211_ELEMID_MEASREP: return " MEASREP";
3530 case IEEE80211_ELEMID_QUIET: return " QUIET";
3531 case IEEE80211_ELEMID_IBSSDFS: return " IBSSDFS";
3532 case IEEE80211_ELEMID_RESERVED_47:
3533 return " RESERVED_47";
3534 case IEEE80211_ELEMID_MOBILITY_DOMAIN:
3535 return " MOBILITY_DOMAIN";
3536 case IEEE80211_ELEMID_RRM_ENACAPS:
3537 return " RRM_ENCAPS";
3538 case IEEE80211_ELEMID_OVERLAP_BSS_SCAN_PARAM:
3539 return " OVERLAP_BSS";
3540 case IEEE80211_ELEMID_TPC: return " TPC";
3541 case IEEE80211_ELEMID_CCKM: return " CCKM";
3542 case IEEE80211_ELEMID_EXTCAP: return " EXTCAP";
3544 snprintf(iename_buf, sizeof(iename_buf), " UNKNOWN_ELEMID_%d",
3546 return (const char *) iename_buf;
3550 printies(const u_int8_t *vp, int ielen, int maxcols)
3554 case IEEE80211_ELEMID_SSID:
3556 printssid(" SSID", vp, 2+vp[1], maxcols);
3558 case IEEE80211_ELEMID_RATES:
3559 case IEEE80211_ELEMID_XRATES:
3561 printrates(vp[0] == IEEE80211_ELEMID_RATES ?
3562 " RATES" : " XRATES", vp, 2+vp[1], maxcols);
3564 case IEEE80211_ELEMID_DSPARMS:
3566 printf(" DSPARMS<%u>", vp[2]);
3568 case IEEE80211_ELEMID_COUNTRY:
3570 printcountry(" COUNTRY", vp, 2+vp[1], maxcols);
3572 case IEEE80211_ELEMID_ERP:
3574 printf(" ERP<0x%x>", vp[2]);
3576 case IEEE80211_ELEMID_VENDOR:
3578 printwpaie(" WPA", vp, 2+vp[1], maxcols);
3579 else if (iswmeinfo(vp))
3580 printwmeinfo(" WME", vp, 2+vp[1], maxcols);
3581 else if (iswmeparam(vp))
3582 printwmeparam(" WME", vp, 2+vp[1], maxcols);
3583 else if (isatherosoui(vp))
3584 printathie(" ATH", vp, 2+vp[1], maxcols);
3585 else if (iswpsoui(vp))
3586 printwpsie(" WPS", vp, 2+vp[1], maxcols);
3587 else if (istdmaoui(vp))
3588 printtdmaie(" TDMA", vp, 2+vp[1], maxcols);
3590 printie(" VEN", vp, 2+vp[1], maxcols);
3592 case IEEE80211_ELEMID_RSN:
3593 printrsnie(" RSN", vp, 2+vp[1], maxcols);
3595 case IEEE80211_ELEMID_HTCAP:
3596 printhtcap(" HTCAP", vp, 2+vp[1], maxcols);
3598 case IEEE80211_ELEMID_HTINFO:
3600 printhtinfo(" HTINFO", vp, 2+vp[1], maxcols);
3602 case IEEE80211_ELEMID_MESHID:
3604 printssid(" MESHID", vp, 2+vp[1], maxcols);
3606 case IEEE80211_ELEMID_MESHCONF:
3607 printmeshconf(" MESHCONF", vp, 2+vp[1], maxcols);
3609 case IEEE80211_ELEMID_VHT_CAP:
3610 printvhtcap(" VHTCAP", vp, 2+vp[1], maxcols);
3612 case IEEE80211_ELEMID_VHT_OPMODE:
3613 printvhtinfo(" VHTOPMODE", vp, 2+vp[1], maxcols);
3615 case IEEE80211_ELEMID_VHT_PWR_ENV:
3616 printvhtpwrenv(" VHTPWRENV", vp, 2+vp[1], maxcols);
3618 case IEEE80211_ELEMID_BSSLOAD:
3619 printbssload(" BSSLOAD", vp, 2+vp[1], maxcols);
3621 case IEEE80211_ELEMID_APCHANREP:
3622 printapchanrep(" APCHANREP", vp, 2+vp[1], maxcols);
3626 printie(iename(vp[0]), vp, 2+vp[1], maxcols);
3635 printmimo(const struct ieee80211_mimo_info *mi)
3640 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3641 if (mi->ch[i].rssi != 0) {
3647 /* NB: don't muddy display unless there's something to show */
3651 /* XXX TODO: ignore EVM; secondary channels for now */
3652 printf(" (rssi %.1f:%.1f:%.1f:%.1f nf %d:%d:%d:%d)",
3653 mi->ch[0].rssi[0] / 2.0,
3654 mi->ch[1].rssi[0] / 2.0,
3655 mi->ch[2].rssi[0] / 2.0,
3656 mi->ch[3].rssi[0] / 2.0,
3660 mi->ch[3].noise[0]);
3666 uint8_t buf[24*1024];
3667 char ssid[IEEE80211_NWID_LEN+1];
3671 if (get80211len(s, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0)
3672 errx(1, "unable to get scan results");
3673 if (len < sizeof(struct ieee80211req_scan_result))
3678 printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n"
3679 , IEEE80211_NWID_LEN, IEEE80211_NWID_LEN, "SSID/MESH ID"
3689 const struct ieee80211req_scan_result *sr;
3690 const uint8_t *vp, *idp;
3692 sr = (const struct ieee80211req_scan_result *) cp;
3693 vp = cp + sr->isr_ie_off;
3694 if (sr->isr_meshid_len) {
3695 idp = vp + sr->isr_ssid_len;
3696 idlen = sr->isr_meshid_len;
3699 idlen = sr->isr_ssid_len;
3701 printf("%-*.*s %s %3d %3dM %4d:%-4d %4d %-4.4s"
3702 , IEEE80211_NWID_LEN
3703 , copy_essid(ssid, IEEE80211_NWID_LEN, idp, idlen)
3705 , ether_ntoa((const struct ether_addr *) sr->isr_bssid)
3706 , ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags)
3707 , getmaxrate(sr->isr_rates, sr->isr_nrates)
3708 , (sr->isr_rssi/2)+sr->isr_noise, sr->isr_noise
3710 , getcaps(sr->isr_capinfo)
3712 printies(vp + sr->isr_ssid_len + sr->isr_meshid_len,
3713 sr->isr_ie_len, 24);
3715 cp += sr->isr_len, len -= sr->isr_len;
3716 } while (len >= sizeof(struct ieee80211req_scan_result));
3720 scan_and_wait(int s)
3722 struct ieee80211_scan_req sr;
3723 struct ieee80211req ireq;
3726 sroute = socket(PF_ROUTE, SOCK_RAW, 0);
3728 perror("socket(PF_ROUTE,SOCK_RAW)");
3731 (void) memset(&ireq, 0, sizeof(ireq));
3732 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
3733 ireq.i_type = IEEE80211_IOC_SCAN_REQ;
3735 memset(&sr, 0, sizeof(sr));
3736 sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE
3737 | IEEE80211_IOC_SCAN_BGSCAN
3738 | IEEE80211_IOC_SCAN_NOPICK
3739 | IEEE80211_IOC_SCAN_ONCE;
3740 sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER;
3744 ireq.i_len = sizeof(sr);
3746 * NB: only root can trigger a scan so ignore errors. Also ignore
3747 * possible errors from net80211, even if no new scan could be
3748 * started there might still be a valid scan cache.
3750 if (ioctl(s, SIOCS80211, &ireq) == 0) {
3752 struct if_announcemsghdr *ifan;
3753 struct rt_msghdr *rtm;
3756 if (read(sroute, buf, sizeof(buf)) < 0) {
3757 perror("read(PF_ROUTE)");
3760 rtm = (struct rt_msghdr *) buf;
3761 if (rtm->rtm_version != RTM_VERSION)
3763 ifan = (struct if_announcemsghdr *) rtm;
3764 } while (rtm->rtm_type != RTM_IEEE80211 ||
3765 ifan->ifan_what != RTM_IEEE80211_SCAN);
3771 DECL_CMD_FUNC(set80211scan, val, d)
3777 static enum ieee80211_opmode get80211opmode(int s);
3780 gettxseq(const struct ieee80211req_sta_info *si)
3784 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3785 return si->isi_txseqs[0];
3786 /* XXX not right but usually what folks want */
3788 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3789 if (si->isi_txseqs[i] > txseq)
3790 txseq = si->isi_txseqs[i];
3795 getrxseq(const struct ieee80211req_sta_info *si)
3799 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3800 return si->isi_rxseqs[0];
3801 /* XXX not right but usually what folks want */
3803 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3804 if (si->isi_rxseqs[i] > rxseq)
3805 rxseq = si->isi_rxseqs[i];
3810 list_stations(int s)
3813 struct ieee80211req_sta_req req;
3814 uint8_t buf[24*1024];
3816 enum ieee80211_opmode opmode = get80211opmode(s);
3820 /* broadcast address =>'s get all stations */
3821 (void) memset(u.req.is_u.macaddr, 0xff, IEEE80211_ADDR_LEN);
3822 if (opmode == IEEE80211_M_STA) {
3824 * Get information about the associated AP.
3826 (void) get80211(s, IEEE80211_IOC_BSSID,
3827 u.req.is_u.macaddr, IEEE80211_ADDR_LEN);
3829 if (get80211len(s, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0)
3830 errx(1, "unable to get station information");
3831 if (len < sizeof(struct ieee80211req_sta_info))
3836 if (opmode == IEEE80211_M_MBSS)
3837 printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n"
3850 printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-7s\n"
3862 cp = (const uint8_t *) u.req.info;
3864 const struct ieee80211req_sta_info *si;
3866 si = (const struct ieee80211req_sta_info *) cp;
3867 if (si->isi_len < sizeof(*si))
3869 if (opmode == IEEE80211_M_MBSS)
3870 printf("%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d"
3871 , ether_ntoa((const struct ether_addr*)
3873 , ieee80211_mhz2ieee(si->isi_freq,
3877 , mesh_linkstate_string(si->isi_peerstate)
3885 printf("%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-7.7s"
3886 , ether_ntoa((const struct ether_addr*)
3888 , IEEE80211_AID(si->isi_associd)
3889 , ieee80211_mhz2ieee(si->isi_freq,
3896 , getcaps(si->isi_capinfo)
3897 , getflags(si->isi_state)
3899 printies(cp + si->isi_ie_off, si->isi_ie_len, 24);
3900 printmimo(&si->isi_mimo);
3902 cp += si->isi_len, len -= si->isi_len;
3903 } while (len >= sizeof(struct ieee80211req_sta_info));
3907 mesh_linkstate_string(uint8_t state)
3909 static const char *state_names[] = {
3918 if (state >= nitems(state_names)) {
3919 static char buf[10];
3920 snprintf(buf, sizeof(buf), "#%u", state);
3923 return state_names[state];
3927 get_chaninfo(const struct ieee80211_channel *c, int precise,
3928 char buf[], size_t bsize)
3931 if (IEEE80211_IS_CHAN_FHSS(c))
3932 strlcat(buf, " FHSS", bsize);
3933 if (IEEE80211_IS_CHAN_A(c))
3934 strlcat(buf, " 11a", bsize);
3935 else if (IEEE80211_IS_CHAN_ANYG(c))
3936 strlcat(buf, " 11g", bsize);
3937 else if (IEEE80211_IS_CHAN_B(c))
3938 strlcat(buf, " 11b", bsize);
3939 if (IEEE80211_IS_CHAN_HALF(c))
3940 strlcat(buf, "/10MHz", bsize);
3941 if (IEEE80211_IS_CHAN_QUARTER(c))
3942 strlcat(buf, "/5MHz", bsize);
3943 if (IEEE80211_IS_CHAN_TURBO(c))
3944 strlcat(buf, " Turbo", bsize);
3946 /* XXX should make VHT80U, VHT80D */
3947 if (IEEE80211_IS_CHAN_VHT80(c) &&
3948 IEEE80211_IS_CHAN_HT40D(c))
3949 strlcat(buf, " vht/80-", bsize);
3950 else if (IEEE80211_IS_CHAN_VHT80(c) &&
3951 IEEE80211_IS_CHAN_HT40U(c))
3952 strlcat(buf, " vht/80+", bsize);
3953 else if (IEEE80211_IS_CHAN_VHT80(c))
3954 strlcat(buf, " vht/80", bsize);
3955 else if (IEEE80211_IS_CHAN_VHT40D(c))
3956 strlcat(buf, " vht/40-", bsize);
3957 else if (IEEE80211_IS_CHAN_VHT40U(c))
3958 strlcat(buf, " vht/40+", bsize);
3959 else if (IEEE80211_IS_CHAN_VHT20(c))
3960 strlcat(buf, " vht/20", bsize);
3961 else if (IEEE80211_IS_CHAN_HT20(c))
3962 strlcat(buf, " ht/20", bsize);
3963 else if (IEEE80211_IS_CHAN_HT40D(c))
3964 strlcat(buf, " ht/40-", bsize);
3965 else if (IEEE80211_IS_CHAN_HT40U(c))
3966 strlcat(buf, " ht/40+", bsize);
3968 if (IEEE80211_IS_CHAN_VHT(c))
3969 strlcat(buf, " vht", bsize);
3970 else if (IEEE80211_IS_CHAN_HT(c))
3971 strlcat(buf, " ht", bsize);
3977 print_chaninfo(const struct ieee80211_channel *c, int verb)
3982 printf("Channel %3u : %u%c%c%c%c%c MHz%-14.14s",
3983 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
3984 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
3985 IEEE80211_IS_CHAN_DFS(c) ? 'D' : ' ',
3986 IEEE80211_IS_CHAN_RADAR(c) ? 'R' : ' ',
3987 IEEE80211_IS_CHAN_CWINT(c) ? 'I' : ' ',
3988 IEEE80211_IS_CHAN_CACDONE(c) ? 'C' : ' ',
3989 get_chaninfo(c, verb, buf, sizeof(buf)));
3991 printf("Channel %3u : %u%c MHz%-14.14s",
3992 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
3993 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
3994 get_chaninfo(c, verb, buf, sizeof(buf)));
3999 chanpref(const struct ieee80211_channel *c)
4001 if (IEEE80211_IS_CHAN_VHT160(c))
4003 if (IEEE80211_IS_CHAN_VHT80_80(c))
4005 if (IEEE80211_IS_CHAN_VHT80(c))
4007 if (IEEE80211_IS_CHAN_VHT40(c))
4009 if (IEEE80211_IS_CHAN_VHT20(c))
4011 if (IEEE80211_IS_CHAN_HT40(c))
4013 if (IEEE80211_IS_CHAN_HT20(c))
4015 if (IEEE80211_IS_CHAN_HALF(c))
4017 if (IEEE80211_IS_CHAN_QUARTER(c))
4019 if (IEEE80211_IS_CHAN_TURBO(c))
4021 if (IEEE80211_IS_CHAN_A(c))
4023 if (IEEE80211_IS_CHAN_G(c))
4025 if (IEEE80211_IS_CHAN_B(c))
4027 if (IEEE80211_IS_CHAN_PUREG(c))
4033 print_channels(int s, const struct ieee80211req_chaninfo *chans,
4034 int allchans, int verb)
4036 struct ieee80211req_chaninfo *achans;
4037 uint8_t reported[IEEE80211_CHAN_BYTES];
4038 const struct ieee80211_channel *c;
4041 achans = malloc(IEEE80211_CHANINFO_SPACE(chans));
4043 errx(1, "no space for active channel list");
4044 achans->ic_nchans = 0;
4045 memset(reported, 0, sizeof(reported));
4047 struct ieee80211req_chanlist active;
4049 if (get80211(s, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0)
4050 errx(1, "unable to get active channel list");
4051 for (i = 0; i < chans->ic_nchans; i++) {
4052 c = &chans->ic_chans[i];
4053 if (!isset(active.ic_channels, c->ic_ieee))
4056 * Suppress compatible duplicates unless
4057 * verbose. The kernel gives us it's
4058 * complete channel list which has separate
4059 * entries for 11g/11b and 11a/turbo.
4061 if (isset(reported, c->ic_ieee) && !verb) {
4062 /* XXX we assume duplicates are adjacent */
4063 achans->ic_chans[achans->ic_nchans-1] = *c;
4065 achans->ic_chans[achans->ic_nchans++] = *c;
4066 setbit(reported, c->ic_ieee);
4070 for (i = 0; i < chans->ic_nchans; i++) {
4071 c = &chans->ic_chans[i];
4072 /* suppress duplicates as above */
4073 if (isset(reported, c->ic_ieee) && !verb) {
4074 /* XXX we assume duplicates are adjacent */
4075 struct ieee80211_channel *a =
4076 &achans->ic_chans[achans->ic_nchans-1];
4077 if (chanpref(c) > chanpref(a))
4080 achans->ic_chans[achans->ic_nchans++] = *c;
4081 setbit(reported, c->ic_ieee);
4085 half = achans->ic_nchans / 2;
4086 if (achans->ic_nchans % 2)
4089 for (i = 0; i < achans->ic_nchans / 2; i++) {
4090 print_chaninfo(&achans->ic_chans[i], verb);
4091 print_chaninfo(&achans->ic_chans[half+i], verb);
4094 if (achans->ic_nchans % 2) {
4095 print_chaninfo(&achans->ic_chans[i], verb);
4102 list_channels(int s, int allchans)
4105 print_channels(s, chaninfo, allchans, verbose);
4109 print_txpow(const struct ieee80211_channel *c)
4111 printf("Channel %3u : %u MHz %3.1f reg %2d ",
4112 c->ic_ieee, c->ic_freq,
4113 c->ic_maxpower/2., c->ic_maxregpower);
4117 print_txpow_verbose(const struct ieee80211_channel *c)
4119 print_chaninfo(c, 1);
4120 printf("min %4.1f dBm max %3.1f dBm reg %2d dBm",
4121 c->ic_minpower/2., c->ic_maxpower/2., c->ic_maxregpower);
4122 /* indicate where regulatory cap limits power use */
4123 if (c->ic_maxpower > 2*c->ic_maxregpower)
4130 struct ieee80211req_chaninfo *achans;
4131 uint8_t reported[IEEE80211_CHAN_BYTES];
4132 struct ieee80211_channel *c, *prev;
4136 achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo));
4138 errx(1, "no space for active channel list");
4139 achans->ic_nchans = 0;
4140 memset(reported, 0, sizeof(reported));
4141 for (i = 0; i < chaninfo->ic_nchans; i++) {
4142 c = &chaninfo->ic_chans[i];
4143 /* suppress duplicates as above */
4144 if (isset(reported, c->ic_ieee) && !verbose) {
4145 /* XXX we assume duplicates are adjacent */
4146 assert(achans->ic_nchans > 0);
4147 prev = &achans->ic_chans[achans->ic_nchans-1];
4148 /* display highest power on channel */
4149 if (c->ic_maxpower > prev->ic_maxpower)
4152 achans->ic_chans[achans->ic_nchans++] = *c;
4153 setbit(reported, c->ic_ieee);
4157 half = achans->ic_nchans / 2;
4158 if (achans->ic_nchans % 2)
4161 for (i = 0; i < achans->ic_nchans / 2; i++) {
4162 print_txpow(&achans->ic_chans[i]);
4163 print_txpow(&achans->ic_chans[half+i]);
4166 if (achans->ic_nchans % 2) {
4167 print_txpow(&achans->ic_chans[i]);
4171 for (i = 0; i < achans->ic_nchans; i++) {
4172 print_txpow_verbose(&achans->ic_chans[i]);
4185 list_capabilities(int s)
4187 struct ieee80211_devcaps_req *dc;
4190 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
4192 dc = malloc(IEEE80211_DEVCAPS_SIZE(1));
4194 errx(1, "no space for device capabilities");
4195 dc->dc_chaninfo.ic_nchans = verbose ? MAXCHAN : 1;
4197 printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS);
4198 if (dc->dc_cryptocaps != 0 || verbose) {
4200 printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS);
4202 if (dc->dc_htcaps != 0 || verbose) {
4204 printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS);
4206 if (dc->dc_vhtcaps != 0 || verbose) {
4208 printb("vhtcaps", dc->dc_vhtcaps, IEEE80211_VHTCAP_BITS);
4213 chaninfo = &dc->dc_chaninfo; /* XXX */
4214 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, verbose);
4220 get80211wme(int s, int param, int ac, int *val)
4222 struct ieee80211req ireq;
4224 (void) memset(&ireq, 0, sizeof(ireq));
4225 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4226 ireq.i_type = param;
4228 if (ioctl(s, SIOCG80211, &ireq) < 0) {
4229 warn("cannot get WME parameter %d, ac %d%s",
4230 param, ac & IEEE80211_WMEPARAM_VAL,
4231 ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : "");
4239 list_wme_aci(int s, const char *tag, int ac)
4243 printf("\t%s", tag);
4245 /* show WME BSS parameters */
4246 if (get80211wme(s, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1)
4247 printf(" cwmin %2u", val);
4248 if (get80211wme(s, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1)
4249 printf(" cwmax %2u", val);
4250 if (get80211wme(s, IEEE80211_IOC_WME_AIFS, ac, &val) != -1)
4251 printf(" aifs %2u", val);
4252 if (get80211wme(s, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1)
4253 printf(" txopLimit %3u", val);
4254 if (get80211wme(s, IEEE80211_IOC_WME_ACM, ac, &val) != -1) {
4261 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
4262 if (get80211wme(s, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) {
4275 static const char *acnames[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
4279 /* display both BSS and local settings */
4280 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) {
4282 if (ac & IEEE80211_WMEPARAM_BSS)
4283 list_wme_aci(s, " ", ac);
4285 list_wme_aci(s, acnames[ac], ac);
4286 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
4287 ac |= IEEE80211_WMEPARAM_BSS;
4290 ac &= ~IEEE80211_WMEPARAM_BSS;
4293 /* display only channel settings */
4294 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++)
4295 list_wme_aci(s, acnames[ac], ac);
4302 const struct ieee80211_roamparam *rp;
4306 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
4307 rp = &roamparams.params[mode];
4308 if (rp->rssi == 0 && rp->rate == 0)
4310 if (mode == IEEE80211_MODE_11NA ||
4311 mode == IEEE80211_MODE_11NG ||
4312 mode == IEEE80211_MODE_VHT_2GHZ ||
4313 mode == IEEE80211_MODE_VHT_5GHZ) {
4315 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm MCS %2u ",
4316 modename[mode], rp->rssi/2,
4317 rp->rate &~ IEEE80211_RATE_MCS);
4319 LINE_CHECK("roam:%-7.7s rssi %4udBm MCS %2u ",
4320 modename[mode], rp->rssi/2,
4321 rp->rate &~ IEEE80211_RATE_MCS);
4324 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s",
4325 modename[mode], rp->rssi/2, rp->rate/2);
4327 LINE_CHECK("roam:%-7.7s rssi %4udBm rate %2u Mb/s",
4328 modename[mode], rp->rssi/2, rp->rate/2);
4333 /* XXX TODO: rate-to-string method... */
4335 get_mcs_mbs_rate_str(uint8_t rate)
4337 return (rate & IEEE80211_RATE_MCS) ? "MCS " : "Mb/s";
4341 get_rate_value(uint8_t rate)
4343 if (rate & IEEE80211_RATE_MCS)
4344 return (rate &~ IEEE80211_RATE_MCS);
4349 list_txparams(int s)
4351 const struct ieee80211_txparam *tp;
4355 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
4356 tp = &txparams.params[mode];
4357 if (tp->mgmtrate == 0 && tp->mcastrate == 0)
4359 if (mode == IEEE80211_MODE_11NA ||
4360 mode == IEEE80211_MODE_11NG ||
4361 mode == IEEE80211_MODE_VHT_2GHZ ||
4362 mode == IEEE80211_MODE_VHT_5GHZ) {
4363 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
4364 LINE_CHECK("%-7.7s ucast NONE mgmt %2u %s "
4365 "mcast %2u %s maxretry %u",
4367 get_rate_value(tp->mgmtrate),
4368 get_mcs_mbs_rate_str(tp->mgmtrate),
4369 get_rate_value(tp->mcastrate),
4370 get_mcs_mbs_rate_str(tp->mcastrate),
4373 LINE_CHECK("%-7.7s ucast %2u MCS mgmt %2u %s "
4374 "mcast %2u %s maxretry %u",
4376 tp->ucastrate &~ IEEE80211_RATE_MCS,
4377 get_rate_value(tp->mgmtrate),
4378 get_mcs_mbs_rate_str(tp->mgmtrate),
4379 get_rate_value(tp->mcastrate),
4380 get_mcs_mbs_rate_str(tp->mcastrate),
4383 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
4384 LINE_CHECK("%-7.7s ucast NONE mgmt %2u Mb/s "
4385 "mcast %2u Mb/s maxretry %u",
4388 tp->mcastrate/2, tp->maxretry);
4390 LINE_CHECK("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s "
4391 "mcast %2u Mb/s maxretry %u",
4393 tp->ucastrate/2, tp->mgmtrate/2,
4394 tp->mcastrate/2, tp->maxretry);
4400 printpolicy(int policy)
4403 case IEEE80211_MACCMD_POLICY_OPEN:
4404 printf("policy: open\n");
4406 case IEEE80211_MACCMD_POLICY_ALLOW:
4407 printf("policy: allow\n");
4409 case IEEE80211_MACCMD_POLICY_DENY:
4410 printf("policy: deny\n");
4412 case IEEE80211_MACCMD_POLICY_RADIUS:
4413 printf("policy: radius\n");
4416 printf("policy: unknown (%u)\n", policy);
4424 struct ieee80211req ireq;
4425 struct ieee80211req_maclist *acllist;
4426 int i, nacls, policy, len;
4430 (void) memset(&ireq, 0, sizeof(ireq));
4431 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name)); /* XXX ?? */
4432 ireq.i_type = IEEE80211_IOC_MACCMD;
4433 ireq.i_val = IEEE80211_MACCMD_POLICY;
4434 if (ioctl(s, SIOCG80211, &ireq) < 0) {
4435 if (errno == EINVAL) {
4436 printf("No acl policy loaded\n");
4439 err(1, "unable to get mac policy");
4441 policy = ireq.i_val;
4442 if (policy == IEEE80211_MACCMD_POLICY_OPEN) {
4444 } else if (policy == IEEE80211_MACCMD_POLICY_ALLOW) {
4446 } else if (policy == IEEE80211_MACCMD_POLICY_DENY) {
4448 } else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) {
4449 c = 'r'; /* NB: should never have entries */
4451 printf("policy: unknown (%u)\n", policy);
4454 if (verbose || c == '?')
4455 printpolicy(policy);
4457 ireq.i_val = IEEE80211_MACCMD_LIST;
4459 if (ioctl(s, SIOCG80211, &ireq) < 0)
4460 err(1, "unable to get mac acl list size");
4461 if (ireq.i_len == 0) { /* NB: no acls */
4462 if (!(verbose || c == '?'))
4463 printpolicy(policy);
4470 err(1, "out of memory for acl list");
4473 if (ioctl(s, SIOCG80211, &ireq) < 0)
4474 err(1, "unable to get mac acl list");
4475 nacls = len / sizeof(*acllist);
4476 acllist = (struct ieee80211req_maclist *) data;
4477 for (i = 0; i < nacls; i++)
4478 printf("%c%s\n", c, ether_ntoa(
4479 (const struct ether_addr *) acllist[i].ml_macaddr));
4484 print_regdomain(const struct ieee80211_regdomain *reg, int verb)
4486 if ((reg->regdomain != 0 &&
4487 reg->regdomain != reg->country) || verb) {
4488 const struct regdomain *rd =
4489 lib80211_regdomain_findbysku(getregdata(), reg->regdomain);
4491 LINE_CHECK("regdomain %d", reg->regdomain);
4493 LINE_CHECK("regdomain %s", rd->name);
4495 if (reg->country != 0 || verb) {
4496 const struct country *cc =
4497 lib80211_country_findbycc(getregdata(), reg->country);
4499 LINE_CHECK("country %d", reg->country);
4501 LINE_CHECK("country %s", cc->isoname);
4503 if (reg->location == 'I')
4504 LINE_CHECK("indoor");
4505 else if (reg->location == 'O')
4506 LINE_CHECK("outdoor");
4508 LINE_CHECK("anywhere");
4516 list_regdomain(int s, int channelsalso)
4522 print_regdomain(®domain, 1);
4524 print_channels(s, chaninfo, 1/*allchans*/, 1/*verbose*/);
4526 print_regdomain(®domain, verbose);
4532 struct ieee80211req ireq;
4533 struct ieee80211req_mesh_route routes[128];
4534 struct ieee80211req_mesh_route *rt;
4536 (void) memset(&ireq, 0, sizeof(ireq));
4537 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4538 ireq.i_type = IEEE80211_IOC_MESH_RTCMD;
4539 ireq.i_val = IEEE80211_MESH_RTCMD_LIST;
4540 ireq.i_data = &routes;
4541 ireq.i_len = sizeof(routes);
4542 if (ioctl(s, SIOCG80211, &ireq) < 0)
4543 err(1, "unable to get the Mesh routing table");
4545 printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n"
4554 for (rt = &routes[0]; rt - &routes[0] < ireq.i_len / sizeof(*rt); rt++){
4556 ether_ntoa((const struct ether_addr *)rt->imr_dest));
4557 printf("%s %4u %4u %6u %6u %c%c\n",
4558 ether_ntoa((const struct ether_addr *)rt->imr_nexthop),
4559 rt->imr_nhops, rt->imr_metric, rt->imr_lifetime,
4561 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_DISCOVER) ?
4563 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_VALID) ?
4565 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ?
4567 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_GATE) ?
4573 DECL_CMD_FUNC(set80211list, arg, d)
4575 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
4579 if (iseq(arg, "sta"))
4581 else if (iseq(arg, "scan") || iseq(arg, "ap"))
4583 else if (iseq(arg, "chan") || iseq(arg, "freq"))
4584 list_channels(s, 1);
4585 else if (iseq(arg, "active"))
4586 list_channels(s, 0);
4587 else if (iseq(arg, "keys"))
4589 else if (iseq(arg, "caps"))
4590 list_capabilities(s);
4591 else if (iseq(arg, "wme") || iseq(arg, "wmm"))
4593 else if (iseq(arg, "mac"))
4595 else if (iseq(arg, "txpow"))
4597 else if (iseq(arg, "roam"))
4599 else if (iseq(arg, "txparam") || iseq(arg, "txparm"))
4601 else if (iseq(arg, "regdomain"))
4602 list_regdomain(s, 1);
4603 else if (iseq(arg, "countries"))
4605 else if (iseq(arg, "mesh"))
4608 errx(1, "Don't know how to list %s for %s", arg, name);
4613 static enum ieee80211_opmode
4614 get80211opmode(int s)
4616 struct ifmediareq ifmr;
4618 (void) memset(&ifmr, 0, sizeof(ifmr));
4619 (void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
4621 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) {
4622 if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) {
4623 if (ifmr.ifm_current & IFM_FLAG0)
4624 return IEEE80211_M_AHDEMO;
4626 return IEEE80211_M_IBSS;
4628 if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP)
4629 return IEEE80211_M_HOSTAP;
4630 if (ifmr.ifm_current & IFM_IEEE80211_IBSS)
4631 return IEEE80211_M_IBSS;
4632 if (ifmr.ifm_current & IFM_IEEE80211_MONITOR)
4633 return IEEE80211_M_MONITOR;
4634 if (ifmr.ifm_current & IFM_IEEE80211_MBSS)
4635 return IEEE80211_M_MBSS;
4637 return IEEE80211_M_STA;
4642 printcipher(int s, struct ieee80211req *ireq, int keylenop)
4644 switch (ireq->i_val) {
4645 case IEEE80211_CIPHER_WEP:
4646 ireq->i_type = keylenop;
4647 if (ioctl(s, SIOCG80211, ireq) != -1)
4649 ireq->i_len <= 5 ? "40" :
4650 ireq->i_len <= 13 ? "104" : "128");
4654 case IEEE80211_CIPHER_TKIP:
4657 case IEEE80211_CIPHER_AES_OCB:
4660 case IEEE80211_CIPHER_AES_CCM:
4663 case IEEE80211_CIPHER_CKIP:
4666 case IEEE80211_CIPHER_NONE:
4670 printf("UNKNOWN (0x%x)", ireq->i_val);
4677 printkey(const struct ieee80211req_key *ik)
4679 static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
4680 u_int keylen = ik->ik_keylen;
4683 printcontents = printkeys &&
4684 (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose);
4687 switch (ik->ik_type) {
4688 case IEEE80211_CIPHER_WEP:
4690 LINE_CHECK("wepkey %u:%s", ik->ik_keyix+1,
4691 keylen <= 5 ? "40-bit" :
4692 keylen <= 13 ? "104-bit" : "128-bit");
4694 case IEEE80211_CIPHER_TKIP:
4696 keylen -= 128/8; /* ignore MIC for now */
4697 LINE_CHECK("TKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4699 case IEEE80211_CIPHER_AES_OCB:
4700 LINE_CHECK("AES-OCB %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4702 case IEEE80211_CIPHER_AES_CCM:
4703 LINE_CHECK("AES-CCM %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4705 case IEEE80211_CIPHER_CKIP:
4706 LINE_CHECK("CKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4708 case IEEE80211_CIPHER_NONE:
4709 LINE_CHECK("NULL %u:%u-bit", ik->ik_keyix+1, 8*keylen);
4712 LINE_CHECK("UNKNOWN (0x%x) %u:%u-bit",
4713 ik->ik_type, ik->ik_keyix+1, 8*keylen);
4716 if (printcontents) {
4720 for (i = 0; i < keylen; i++)
4721 printf("%02x", ik->ik_keydata[i]);
4723 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4724 (ik->ik_keyrsc != 0 || verbose))
4725 printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc);
4726 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
4727 (ik->ik_keytsc != 0 || verbose))
4728 printf(" tsc %ju", (uintmax_t)ik->ik_keytsc);
4729 if (ik->ik_flags != 0 && verbose) {
4730 const char *sep = " ";
4732 if (ik->ik_flags & IEEE80211_KEY_XMIT)
4733 printf("%stx", sep), sep = "+";
4734 if (ik->ik_flags & IEEE80211_KEY_RECV)
4735 printf("%srx", sep), sep = "+";
4736 if (ik->ik_flags & IEEE80211_KEY_DEFAULT)
4737 printf("%sdef", sep), sep = "+";
4744 printrate(const char *tag, int v, int defrate, int defmcs)
4746 if ((v & IEEE80211_RATE_MCS) == 0) {
4749 LINE_CHECK("%s %d.5", tag, v/2);
4751 LINE_CHECK("%s %d", tag, v/2);
4755 LINE_CHECK("%s %d", tag, v &~ 0x80);
4760 getid(int s, int ix, void *data, size_t len, int *plen, int mesh)
4762 struct ieee80211req ireq;
4764 (void) memset(&ireq, 0, sizeof(ireq));
4765 (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name));
4766 ireq.i_type = (!mesh) ? IEEE80211_IOC_SSID : IEEE80211_IOC_MESH_ID;
4770 if (ioctl(s, SIOCG80211, &ireq) < 0)
4777 ieee80211_status(int s)
4779 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
4780 enum ieee80211_opmode opmode = get80211opmode(s);
4781 int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode;
4783 const struct ieee80211_channel *c;
4784 const struct ieee80211_roamparam *rp;
4785 const struct ieee80211_txparam *tp;
4787 if (getid(s, -1, data, sizeof(data), &len, 0) < 0) {
4788 /* If we can't get the SSID, this isn't an 802.11 device. */
4793 * Invalidate cached state so printing status for multiple
4794 * if's doesn't reuse the first interfaces' cached state.
4803 if (opmode == IEEE80211_M_MBSS) {
4805 getid(s, 0, data, sizeof(data), &len, 1);
4806 print_string(data, len);
4808 if (get80211val(s, IEEE80211_IOC_NUMSSIDS, &num) < 0)
4812 for (i = 0; i < num; i++) {
4813 if (getid(s, i, data, sizeof(data), &len, 0) >= 0 && len > 0) {
4814 printf(" %d:", i + 1);
4815 print_string(data, len);
4819 print_string(data, len);
4822 if (c->ic_freq != IEEE80211_CHAN_ANY) {
4824 printf(" channel %d (%u MHz%s)", c->ic_ieee, c->ic_freq,
4825 get_chaninfo(c, 1, buf, sizeof(buf)));
4827 printf(" channel UNDEF");
4829 if (get80211(s, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 &&
4830 (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose))
4831 printf(" bssid %s", ether_ntoa((struct ether_addr *)data));
4833 if (get80211len(s, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) {
4834 printf("\n\tstationname ");
4835 print_string(data, len);
4838 spacer = ' '; /* force first break */
4841 list_regdomain(s, 0);
4844 if (get80211val(s, IEEE80211_IOC_AUTHMODE, &val) != -1) {
4846 case IEEE80211_AUTH_NONE:
4847 LINE_CHECK("authmode NONE");
4849 case IEEE80211_AUTH_OPEN:
4850 LINE_CHECK("authmode OPEN");
4852 case IEEE80211_AUTH_SHARED:
4853 LINE_CHECK("authmode SHARED");
4855 case IEEE80211_AUTH_8021X:
4856 LINE_CHECK("authmode 802.1x");
4858 case IEEE80211_AUTH_WPA:
4859 if (get80211val(s, IEEE80211_IOC_WPA, &wpa) < 0)
4860 wpa = 1; /* default to WPA1 */
4863 LINE_CHECK("authmode WPA2/802.11i");
4866 LINE_CHECK("authmode WPA1+WPA2/802.11i");
4869 LINE_CHECK("authmode WPA");
4873 case IEEE80211_AUTH_AUTO:
4874 LINE_CHECK("authmode AUTO");
4877 LINE_CHECK("authmode UNKNOWN (0x%x)", val);
4882 if (wpa || verbose) {
4883 if (get80211val(s, IEEE80211_IOC_WPS, &val) != -1) {
4889 if (get80211val(s, IEEE80211_IOC_TSN, &val) != -1) {
4895 if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) {
4897 LINE_CHECK("countermeasures");
4899 LINE_CHECK("-countermeasures");
4902 /* XXX not interesting with WPA done in user space */
4903 ireq.i_type = IEEE80211_IOC_KEYMGTALGS;
4904 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4907 ireq.i_type = IEEE80211_IOC_MCASTCIPHER;
4908 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4909 LINE_CHECK("mcastcipher ");
4910 printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN);
4914 ireq.i_type = IEEE80211_IOC_UCASTCIPHER;
4915 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4916 LINE_CHECK("ucastcipher ");
4917 printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN);
4921 ireq.i_type = IEEE80211_IOC_RSNCAPS;
4922 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4923 LINE_CHECK("RSN caps 0x%x", ireq.i_val);
4928 ireq.i_type = IEEE80211_IOC_UCASTCIPHERS;
4929 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4934 if (get80211val(s, IEEE80211_IOC_WEP, &wepmode) != -1 &&
4935 wepmode != IEEE80211_WEP_NOSUP) {
4938 case IEEE80211_WEP_OFF:
4939 LINE_CHECK("privacy OFF");
4941 case IEEE80211_WEP_ON:
4942 LINE_CHECK("privacy ON");
4944 case IEEE80211_WEP_MIXED:
4945 LINE_CHECK("privacy MIXED");
4948 LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode);
4953 * If we get here then we've got WEP support so we need
4954 * to print WEP status.
4957 if (get80211val(s, IEEE80211_IOC_WEPTXKEY, &val) < 0) {
4958 warn("WEP support, but no tx key!");
4962 LINE_CHECK("deftxkey %d", val+1);
4963 else if (wepmode != IEEE80211_WEP_OFF || verbose)
4964 LINE_CHECK("deftxkey UNDEF");
4966 if (get80211val(s, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) {
4967 warn("WEP support, but no NUMWEPKEYS support!");
4971 for (i = 0; i < num; i++) {
4972 struct ieee80211req_key ik;
4974 memset(&ik, 0, sizeof(ik));
4976 if (get80211(s, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) {
4977 warn("WEP support, but can get keys!");
4980 if (ik.ik_keylen != 0) {
4990 if (get80211val(s, IEEE80211_IOC_POWERSAVE, &val) != -1 &&
4991 val != IEEE80211_POWERSAVE_NOSUP ) {
4992 if (val != IEEE80211_POWERSAVE_OFF || verbose) {
4994 case IEEE80211_POWERSAVE_OFF:
4995 LINE_CHECK("powersavemode OFF");
4997 case IEEE80211_POWERSAVE_CAM:
4998 LINE_CHECK("powersavemode CAM");
5000 case IEEE80211_POWERSAVE_PSP:
5001 LINE_CHECK("powersavemode PSP");
5003 case IEEE80211_POWERSAVE_PSP_CAM:
5004 LINE_CHECK("powersavemode PSP-CAM");
5007 if (get80211val(s, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1)
5008 LINE_CHECK("powersavesleep %d", val);
5012 if (get80211val(s, IEEE80211_IOC_TXPOWER, &val) != -1) {
5014 LINE_CHECK("txpower %d.5", val/2);
5016 LINE_CHECK("txpower %d", val/2);
5019 if (get80211val(s, IEEE80211_IOC_TXPOWMAX, &val) != -1)
5020 LINE_CHECK("txpowmax %.1f", val/2.);
5023 if (get80211val(s, IEEE80211_IOC_DOTD, &val) != -1) {
5027 LINE_CHECK("-dotd");
5030 if (get80211val(s, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) {
5031 if (val != IEEE80211_RTS_MAX || verbose)
5032 LINE_CHECK("rtsthreshold %d", val);
5035 if (get80211val(s, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) {
5036 if (val != IEEE80211_FRAG_MAX || verbose)
5037 LINE_CHECK("fragthreshold %d", val);
5039 if (opmode == IEEE80211_M_STA || verbose) {
5040 if (get80211val(s, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) {
5041 if (val != IEEE80211_HWBMISS_MAX || verbose)
5042 LINE_CHECK("bmiss %d", val);
5048 tp = &txparams.params[chan2mode(c)];
5049 printrate("ucastrate", tp->ucastrate,
5050 IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE);
5051 printrate("mcastrate", tp->mcastrate, 2*1,
5052 IEEE80211_RATE_MCS|0);
5053 printrate("mgmtrate", tp->mgmtrate, 2*1,
5054 IEEE80211_RATE_MCS|0);
5055 if (tp->maxretry != 6) /* XXX */
5056 LINE_CHECK("maxretry %d", tp->maxretry);
5062 bgscaninterval = -1;
5063 (void) get80211val(s, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval);
5065 if (get80211val(s, IEEE80211_IOC_SCANVALID, &val) != -1) {
5066 if (val != bgscaninterval || verbose)
5067 LINE_CHECK("scanvalid %u", val);
5071 if (get80211val(s, IEEE80211_IOC_BGSCAN, &bgscan) != -1) {
5073 LINE_CHECK("bgscan");
5075 LINE_CHECK("-bgscan");
5077 if (bgscan || verbose) {
5078 if (bgscaninterval != -1)
5079 LINE_CHECK("bgscanintvl %u", bgscaninterval);
5080 if (get80211val(s, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1)
5081 LINE_CHECK("bgscanidle %u", val);
5084 rp = &roamparams.params[chan2mode(c)];
5086 LINE_CHECK("roam:rssi %u.5", rp->rssi/2);
5088 LINE_CHECK("roam:rssi %u", rp->rssi/2);
5089 LINE_CHECK("roam:rate %s%u",
5090 (rp->rate & IEEE80211_RATE_MCS) ? "MCS " : "",
5091 get_rate_value(rp->rate));
5099 if (IEEE80211_IS_CHAN_ANYG(c) || verbose) {
5100 if (get80211val(s, IEEE80211_IOC_PUREG, &val) != -1) {
5102 LINE_CHECK("pureg");
5104 LINE_CHECK("-pureg");
5106 if (get80211val(s, IEEE80211_IOC_PROTMODE, &val) != -1) {
5108 case IEEE80211_PROTMODE_OFF:
5109 LINE_CHECK("protmode OFF");
5111 case IEEE80211_PROTMODE_CTS:
5112 LINE_CHECK("protmode CTS");
5114 case IEEE80211_PROTMODE_RTSCTS:
5115 LINE_CHECK("protmode RTSCTS");
5118 LINE_CHECK("protmode UNKNOWN (0x%x)", val);
5124 if (IEEE80211_IS_CHAN_HT(c) || verbose) {
5126 switch (htconf & 3) {
5139 if (get80211val(s, IEEE80211_IOC_HTCOMPAT, &val) != -1) {
5141 LINE_CHECK("-htcompat");
5143 LINE_CHECK("htcompat");
5145 if (get80211val(s, IEEE80211_IOC_AMPDU, &val) != -1) {
5148 LINE_CHECK("-ampdu");
5151 LINE_CHECK("ampdutx -ampdurx");
5154 LINE_CHECK("-ampdutx ampdurx");
5158 LINE_CHECK("ampdu");
5162 /* XXX 11ac density/size is different */
5163 if (get80211val(s, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) {
5165 case IEEE80211_HTCAP_MAXRXAMPDU_8K:
5166 LINE_CHECK("ampdulimit 8k");
5168 case IEEE80211_HTCAP_MAXRXAMPDU_16K:
5169 LINE_CHECK("ampdulimit 16k");
5171 case IEEE80211_HTCAP_MAXRXAMPDU_32K:
5172 LINE_CHECK("ampdulimit 32k");
5174 case IEEE80211_HTCAP_MAXRXAMPDU_64K:
5175 LINE_CHECK("ampdulimit 64k");
5179 /* XXX 11ac density/size is different */
5180 if (get80211val(s, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) {
5182 case IEEE80211_HTCAP_MPDUDENSITY_NA:
5184 LINE_CHECK("ampdudensity NA");
5186 case IEEE80211_HTCAP_MPDUDENSITY_025:
5187 LINE_CHECK("ampdudensity .25");
5189 case IEEE80211_HTCAP_MPDUDENSITY_05:
5190 LINE_CHECK("ampdudensity .5");
5192 case IEEE80211_HTCAP_MPDUDENSITY_1:
5193 LINE_CHECK("ampdudensity 1");
5195 case IEEE80211_HTCAP_MPDUDENSITY_2:
5196 LINE_CHECK("ampdudensity 2");
5198 case IEEE80211_HTCAP_MPDUDENSITY_4:
5199 LINE_CHECK("ampdudensity 4");
5201 case IEEE80211_HTCAP_MPDUDENSITY_8:
5202 LINE_CHECK("ampdudensity 8");
5204 case IEEE80211_HTCAP_MPDUDENSITY_16:
5205 LINE_CHECK("ampdudensity 16");
5209 if (get80211val(s, IEEE80211_IOC_AMSDU, &val) != -1) {
5212 LINE_CHECK("-amsdu");
5215 LINE_CHECK("amsdutx -amsdurx");
5218 LINE_CHECK("-amsdutx amsdurx");
5222 LINE_CHECK("amsdu");
5226 /* XXX amsdu limit */
5227 if (get80211val(s, IEEE80211_IOC_SHORTGI, &val) != -1) {
5229 LINE_CHECK("shortgi");
5231 LINE_CHECK("-shortgi");
5233 if (get80211val(s, IEEE80211_IOC_HTPROTMODE, &val) != -1) {
5234 if (val == IEEE80211_PROTMODE_OFF)
5235 LINE_CHECK("htprotmode OFF");
5236 else if (val != IEEE80211_PROTMODE_RTSCTS)
5237 LINE_CHECK("htprotmode UNKNOWN (0x%x)", val);
5239 LINE_CHECK("htprotmode RTSCTS");
5241 if (get80211val(s, IEEE80211_IOC_PUREN, &val) != -1) {
5243 LINE_CHECK("puren");
5245 LINE_CHECK("-puren");
5247 if (get80211val(s, IEEE80211_IOC_SMPS, &val) != -1) {
5248 if (val == IEEE80211_HTCAP_SMPS_DYNAMIC)
5249 LINE_CHECK("smpsdyn");
5250 else if (val == IEEE80211_HTCAP_SMPS_ENA)
5253 LINE_CHECK("-smps");
5255 if (get80211val(s, IEEE80211_IOC_RIFS, &val) != -1) {
5259 LINE_CHECK("-rifs");
5263 if (get80211val(s, IEEE80211_IOC_STBC, &val) != -1) {
5266 LINE_CHECK("-stbc");
5269 LINE_CHECK("stbctx -stbcrx");
5272 LINE_CHECK("-stbctx stbcrx");
5280 if (get80211val(s, IEEE80211_IOC_LDPC, &val) != -1) {
5283 LINE_CHECK("-ldpc");
5286 LINE_CHECK("ldpctx -ldpcrx");
5289 LINE_CHECK("-ldpctx ldpcrx");
5297 if (get80211val(s, IEEE80211_IOC_UAPSD, &val) != -1) {
5300 LINE_CHECK("-uapsd");
5303 LINE_CHECK("uapsd");
5309 if (IEEE80211_IS_CHAN_VHT(c) || verbose) {
5316 LINE_CHECK("vht40");
5318 LINE_CHECK("-vht40");
5320 LINE_CHECK("vht80");
5322 LINE_CHECK("-vht80");
5324 LINE_CHECK("vht80p80");
5326 LINE_CHECK("-vht80p80");
5328 LINE_CHECK("vht160");
5330 LINE_CHECK("-vht160");
5333 if (get80211val(s, IEEE80211_IOC_WME, &wme) != -1) {
5341 if (get80211val(s, IEEE80211_IOC_BURST, &val) != -1) {
5343 LINE_CHECK("burst");
5345 LINE_CHECK("-burst");
5348 if (get80211val(s, IEEE80211_IOC_FF, &val) != -1) {
5354 if (get80211val(s, IEEE80211_IOC_TURBOP, &val) != -1) {
5356 LINE_CHECK("dturbo");
5358 LINE_CHECK("-dturbo");
5360 if (get80211val(s, IEEE80211_IOC_DWDS, &val) != -1) {
5364 LINE_CHECK("-dwds");
5367 if (opmode == IEEE80211_M_HOSTAP) {
5368 if (get80211val(s, IEEE80211_IOC_HIDESSID, &val) != -1) {
5370 LINE_CHECK("hidessid");
5372 LINE_CHECK("-hidessid");
5374 if (get80211val(s, IEEE80211_IOC_APBRIDGE, &val) != -1) {
5376 LINE_CHECK("-apbridge");
5378 LINE_CHECK("apbridge");
5380 if (get80211val(s, IEEE80211_IOC_DTIM_PERIOD, &val) != -1)
5381 LINE_CHECK("dtimperiod %u", val);
5383 if (get80211val(s, IEEE80211_IOC_DOTH, &val) != -1) {
5385 LINE_CHECK("-doth");
5389 if (get80211val(s, IEEE80211_IOC_DFS, &val) != -1) {
5395 if (get80211val(s, IEEE80211_IOC_INACTIVITY, &val) != -1) {
5397 LINE_CHECK("-inact");
5399 LINE_CHECK("inact");
5402 if (get80211val(s, IEEE80211_IOC_ROAMING, &val) != -1) {
5403 if (val != IEEE80211_ROAMING_AUTO || verbose) {
5405 case IEEE80211_ROAMING_DEVICE:
5406 LINE_CHECK("roaming DEVICE");
5408 case IEEE80211_ROAMING_AUTO:
5409 LINE_CHECK("roaming AUTO");
5411 case IEEE80211_ROAMING_MANUAL:
5412 LINE_CHECK("roaming MANUAL");
5415 LINE_CHECK("roaming UNKNOWN (0x%x)",
5423 if (opmode == IEEE80211_M_AHDEMO) {
5424 if (get80211val(s, IEEE80211_IOC_TDMA_SLOT, &val) != -1)
5425 LINE_CHECK("tdmaslot %u", val);
5426 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1)
5427 LINE_CHECK("tdmaslotcnt %u", val);
5428 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1)
5429 LINE_CHECK("tdmaslotlen %u", val);
5430 if (get80211val(s, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1)
5431 LINE_CHECK("tdmabintval %u", val);
5432 } else if (get80211val(s, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) {
5433 /* XXX default define not visible */
5434 if (val != 100 || verbose)
5435 LINE_CHECK("bintval %u", val);
5438 if (wme && verbose) {
5443 if (opmode == IEEE80211_M_MBSS) {
5444 if (get80211val(s, IEEE80211_IOC_MESH_TTL, &val) != -1) {
5445 LINE_CHECK("meshttl %u", val);
5447 if (get80211val(s, IEEE80211_IOC_MESH_AP, &val) != -1) {
5449 LINE_CHECK("meshpeering");
5451 LINE_CHECK("-meshpeering");
5453 if (get80211val(s, IEEE80211_IOC_MESH_FWRD, &val) != -1) {
5455 LINE_CHECK("meshforward");
5457 LINE_CHECK("-meshforward");
5459 if (get80211val(s, IEEE80211_IOC_MESH_GATE, &val) != -1) {
5461 LINE_CHECK("meshgate");
5463 LINE_CHECK("-meshgate");
5465 if (get80211len(s, IEEE80211_IOC_MESH_PR_METRIC, data, 12,
5468 LINE_CHECK("meshmetric %s", data);
5470 if (get80211len(s, IEEE80211_IOC_MESH_PR_PATH, data, 12,
5473 LINE_CHECK("meshpath %s", data);
5475 if (get80211val(s, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) {
5477 case IEEE80211_HWMP_ROOTMODE_DISABLED:
5478 LINE_CHECK("hwmprootmode DISABLED");
5480 case IEEE80211_HWMP_ROOTMODE_NORMAL:
5481 LINE_CHECK("hwmprootmode NORMAL");
5483 case IEEE80211_HWMP_ROOTMODE_PROACTIVE:
5484 LINE_CHECK("hwmprootmode PROACTIVE");
5486 case IEEE80211_HWMP_ROOTMODE_RANN:
5487 LINE_CHECK("hwmprootmode RANN");
5490 LINE_CHECK("hwmprootmode UNKNOWN(%d)", val);
5494 if (get80211val(s, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) {
5495 LINE_CHECK("hwmpmaxhops %u", val);
5503 get80211(int s, int type, void *data, int len)
5506 return (lib80211_get80211(s, name, type, data, len));
5510 get80211len(int s, int type, void *data, int len, int *plen)
5513 return (lib80211_get80211len(s, name, type, data, len, plen));
5517 get80211val(int s, int type, int *val)
5520 return (lib80211_get80211val(s, name, type, val));
5524 set80211(int s, int type, int val, int len, void *data)
5528 ret = lib80211_set80211(s, name, type, val, len, data);
5530 err(1, "SIOCS80211");
5534 get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
5542 hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x');
5548 if (sep != NULL && strchr(sep, *val) != NULL) {
5553 if (!isxdigit((u_char)val[0])) {
5554 warnx("bad hexadecimal digits");
5557 if (!isxdigit((u_char)val[1])) {
5558 warnx("odd count hexadecimal digits");
5562 if (p >= buf + len) {
5564 warnx("hexadecimal digits too long");
5566 warnx("string too long");
5570 #define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
5571 *p++ = (tohex((u_char)val[0]) << 4) |
5572 tohex((u_char)val[1]);
5579 /* The string "-" is treated as the empty string. */
5580 if (!hexstr && len == 1 && buf[0] == '-') {
5582 memset(buf, 0, *lenp);
5583 } else if (len < *lenp)
5584 memset(p, 0, *lenp - len);
5590 print_string(const u_int8_t *buf, int len)
5599 setlocale(LC_CTYPE, "");
5600 utf8 = strncmp("UTF-8", nl_langinfo(CODESET), 5) == 0;
5602 for (; i < len; i++) {
5603 if (!isprint(buf[i]) && buf[i] != '\0' && !utf8)
5605 if (isspace(buf[i]))
5608 if (i == len || utf8) {
5609 if (hasspc || len == 0 || buf[0] == '\0')
5610 printf("\"%.*s\"", len, buf);
5612 printf("%.*s", len, buf);
5615 for (i = 0; i < len; i++)
5616 printf("%02x", buf[i]);
5621 setdefregdomain(int s)
5623 struct regdata *rdp = getregdata();
5624 const struct regdomain *rd;
5626 /* Check if regdomain/country was already set by a previous call. */
5627 /* XXX is it possible? */
5628 if (regdomain.regdomain != 0 ||
5629 regdomain.country != CTRY_DEFAULT)
5634 /* Check if it was already set by the driver. */
5635 if (regdomain.regdomain != 0 ||
5636 regdomain.country != CTRY_DEFAULT)
5639 /* Set FCC/US as default. */
5640 rd = lib80211_regdomain_findbysku(rdp, SKU_FCC);
5642 errx(1, "FCC regdomain was not found");
5644 regdomain.regdomain = rd->sku;
5648 /* Send changes to net80211. */
5649 setregdomain_cb(s, ®domain);
5651 /* Cleanup (so it can be overriden by subsequent parameters). */
5652 regdomain.regdomain = 0;
5653 regdomain.country = CTRY_DEFAULT;
5654 regdomain.isocc[0] = 0;
5655 regdomain.isocc[1] = 0;
5659 * Virtual AP cloning support.
5661 static struct ieee80211_clone_params params = {
5662 .icp_opmode = IEEE80211_M_STA, /* default to station mode */
5666 wlan_create(int s, struct ifreq *ifr)
5668 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
5669 char orig_name[IFNAMSIZ];
5671 if (params.icp_parent[0] == '\0')
5672 errx(1, "must specify a parent device (wlandev) when creating "
5674 if (params.icp_opmode == IEEE80211_M_WDS &&
5675 memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0)
5676 errx(1, "no bssid specified for WDS (use wlanbssid)");
5677 ifr->ifr_data = (caddr_t) ¶ms;
5678 if (ioctl(s, SIOCIFCREATE2, ifr) < 0)
5679 err(1, "SIOCIFCREATE2");
5681 /* XXX preserve original name for ifclonecreate(). */
5682 strlcpy(orig_name, name, sizeof(orig_name));
5683 strlcpy(name, ifr->ifr_name, sizeof(name));
5687 strlcpy(name, orig_name, sizeof(name));
5691 DECL_CMD_FUNC(set80211clone_wlandev, arg, d)
5693 strlcpy(params.icp_parent, arg, IFNAMSIZ);
5697 DECL_CMD_FUNC(set80211clone_wlanbssid, arg, d)
5699 const struct ether_addr *ea;
5701 ea = ether_aton(arg);
5703 errx(1, "%s: cannot parse bssid", arg);
5704 memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN);
5708 DECL_CMD_FUNC(set80211clone_wlanaddr, arg, d)
5710 const struct ether_addr *ea;
5712 ea = ether_aton(arg);
5714 errx(1, "%s: cannot parse address", arg);
5715 memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN);
5716 params.icp_flags |= IEEE80211_CLONE_MACADDR;
5720 DECL_CMD_FUNC(set80211clone_wlanmode, arg, d)
5722 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
5723 if (iseq(arg, "sta"))
5724 params.icp_opmode = IEEE80211_M_STA;
5725 else if (iseq(arg, "ahdemo") || iseq(arg, "adhoc-demo"))
5726 params.icp_opmode = IEEE80211_M_AHDEMO;
5727 else if (iseq(arg, "ibss") || iseq(arg, "adhoc"))
5728 params.icp_opmode = IEEE80211_M_IBSS;
5729 else if (iseq(arg, "ap") || iseq(arg, "host"))
5730 params.icp_opmode = IEEE80211_M_HOSTAP;
5731 else if (iseq(arg, "wds"))
5732 params.icp_opmode = IEEE80211_M_WDS;
5733 else if (iseq(arg, "monitor"))
5734 params.icp_opmode = IEEE80211_M_MONITOR;
5735 else if (iseq(arg, "tdma")) {
5736 params.icp_opmode = IEEE80211_M_AHDEMO;
5737 params.icp_flags |= IEEE80211_CLONE_TDMA;
5738 } else if (iseq(arg, "mesh") || iseq(arg, "mp")) /* mesh point */
5739 params.icp_opmode = IEEE80211_M_MBSS;
5741 errx(1, "Don't know to create %s for %s", arg, name);
5746 set80211clone_beacons(const char *val, int d, int s, const struct afswtch *rafp)
5748 /* NB: inverted sense */
5750 params.icp_flags &= ~IEEE80211_CLONE_NOBEACONS;
5752 params.icp_flags |= IEEE80211_CLONE_NOBEACONS;
5756 set80211clone_bssid(const char *val, int d, int s, const struct afswtch *rafp)
5759 params.icp_flags |= IEEE80211_CLONE_BSSID;
5761 params.icp_flags &= ~IEEE80211_CLONE_BSSID;
5765 set80211clone_wdslegacy(const char *val, int d, int s, const struct afswtch *rafp)
5768 params.icp_flags |= IEEE80211_CLONE_WDSLEGACY;
5770 params.icp_flags &= ~IEEE80211_CLONE_WDSLEGACY;
5773 static struct cmd ieee80211_cmds[] = {
5774 DEF_CMD_ARG("ssid", set80211ssid),
5775 DEF_CMD_ARG("nwid", set80211ssid),
5776 DEF_CMD_ARG("meshid", set80211meshid),
5777 DEF_CMD_ARG("stationname", set80211stationname),
5778 DEF_CMD_ARG("station", set80211stationname), /* BSD/OS */
5779 DEF_CMD_ARG("channel", set80211channel),
5780 DEF_CMD_ARG("authmode", set80211authmode),
5781 DEF_CMD_ARG("powersavemode", set80211powersavemode),
5782 DEF_CMD("powersave", 1, set80211powersave),
5783 DEF_CMD("-powersave", 0, set80211powersave),
5784 DEF_CMD_ARG("powersavesleep", set80211powersavesleep),
5785 DEF_CMD_ARG("wepmode", set80211wepmode),
5786 DEF_CMD("wep", 1, set80211wep),
5787 DEF_CMD("-wep", 0, set80211wep),
5788 DEF_CMD_ARG("deftxkey", set80211weptxkey),
5789 DEF_CMD_ARG("weptxkey", set80211weptxkey),
5790 DEF_CMD_ARG("wepkey", set80211wepkey),
5791 DEF_CMD_ARG("nwkey", set80211nwkey), /* NetBSD */
5792 DEF_CMD("-nwkey", 0, set80211wep), /* NetBSD */
5793 DEF_CMD_ARG("rtsthreshold", set80211rtsthreshold),
5794 DEF_CMD_ARG("protmode", set80211protmode),
5795 DEF_CMD_ARG("txpower", set80211txpower),
5796 DEF_CMD_ARG("roaming", set80211roaming),
5797 DEF_CMD("wme", 1, set80211wme),
5798 DEF_CMD("-wme", 0, set80211wme),
5799 DEF_CMD("wmm", 1, set80211wme),
5800 DEF_CMD("-wmm", 0, set80211wme),
5801 DEF_CMD("hidessid", 1, set80211hidessid),
5802 DEF_CMD("-hidessid", 0, set80211hidessid),
5803 DEF_CMD("apbridge", 1, set80211apbridge),
5804 DEF_CMD("-apbridge", 0, set80211apbridge),
5805 DEF_CMD_ARG("chanlist", set80211chanlist),
5806 DEF_CMD_ARG("bssid", set80211bssid),
5807 DEF_CMD_ARG("ap", set80211bssid),
5808 DEF_CMD("scan", 0, set80211scan),
5809 DEF_CMD_ARG("list", set80211list),
5810 DEF_CMD_ARG2("cwmin", set80211cwmin),
5811 DEF_CMD_ARG2("cwmax", set80211cwmax),
5812 DEF_CMD_ARG2("aifs", set80211aifs),
5813 DEF_CMD_ARG2("txoplimit", set80211txoplimit),
5814 DEF_CMD_ARG("acm", set80211acm),
5815 DEF_CMD_ARG("-acm", set80211noacm),
5816 DEF_CMD_ARG("ack", set80211ackpolicy),
5817 DEF_CMD_ARG("-ack", set80211noackpolicy),
5818 DEF_CMD_ARG2("bss:cwmin", set80211bsscwmin),
5819 DEF_CMD_ARG2("bss:cwmax", set80211bsscwmax),
5820 DEF_CMD_ARG2("bss:aifs", set80211bssaifs),
5821 DEF_CMD_ARG2("bss:txoplimit", set80211bsstxoplimit),
5822 DEF_CMD_ARG("dtimperiod", set80211dtimperiod),
5823 DEF_CMD_ARG("bintval", set80211bintval),
5824 DEF_CMD("mac:open", IEEE80211_MACCMD_POLICY_OPEN, set80211maccmd),
5825 DEF_CMD("mac:allow", IEEE80211_MACCMD_POLICY_ALLOW, set80211maccmd),
5826 DEF_CMD("mac:deny", IEEE80211_MACCMD_POLICY_DENY, set80211maccmd),
5827 DEF_CMD("mac:radius", IEEE80211_MACCMD_POLICY_RADIUS, set80211maccmd),
5828 DEF_CMD("mac:flush", IEEE80211_MACCMD_FLUSH, set80211maccmd),
5829 DEF_CMD("mac:detach", IEEE80211_MACCMD_DETACH, set80211maccmd),
5830 DEF_CMD_ARG("mac:add", set80211addmac),
5831 DEF_CMD_ARG("mac:del", set80211delmac),
5832 DEF_CMD_ARG("mac:kick", set80211kickmac),
5833 DEF_CMD("pureg", 1, set80211pureg),
5834 DEF_CMD("-pureg", 0, set80211pureg),
5835 DEF_CMD("ff", 1, set80211fastframes),
5836 DEF_CMD("-ff", 0, set80211fastframes),
5837 DEF_CMD("dturbo", 1, set80211dturbo),
5838 DEF_CMD("-dturbo", 0, set80211dturbo),
5839 DEF_CMD("bgscan", 1, set80211bgscan),
5840 DEF_CMD("-bgscan", 0, set80211bgscan),
5841 DEF_CMD_ARG("bgscanidle", set80211bgscanidle),
5842 DEF_CMD_ARG("bgscanintvl", set80211bgscanintvl),
5843 DEF_CMD_ARG("scanvalid", set80211scanvalid),
5844 DEF_CMD("quiet", 1, set80211quiet),
5845 DEF_CMD("-quiet", 0, set80211quiet),
5846 DEF_CMD_ARG("quiet_count", set80211quietcount),
5847 DEF_CMD_ARG("quiet_period", set80211quietperiod),
5848 DEF_CMD_ARG("quiet_duration", set80211quietduration),
5849 DEF_CMD_ARG("quiet_offset", set80211quietoffset),
5850 DEF_CMD_ARG("roam:rssi", set80211roamrssi),
5851 DEF_CMD_ARG("roam:rate", set80211roamrate),
5852 DEF_CMD_ARG("mcastrate", set80211mcastrate),
5853 DEF_CMD_ARG("ucastrate", set80211ucastrate),
5854 DEF_CMD_ARG("mgtrate", set80211mgtrate),
5855 DEF_CMD_ARG("mgmtrate", set80211mgtrate),
5856 DEF_CMD_ARG("maxretry", set80211maxretry),
5857 DEF_CMD_ARG("fragthreshold", set80211fragthreshold),
5858 DEF_CMD("burst", 1, set80211burst),
5859 DEF_CMD("-burst", 0, set80211burst),
5860 DEF_CMD_ARG("bmiss", set80211bmissthreshold),
5861 DEF_CMD_ARG("bmissthreshold", set80211bmissthreshold),
5862 DEF_CMD("shortgi", 1, set80211shortgi),
5863 DEF_CMD("-shortgi", 0, set80211shortgi),
5864 DEF_CMD("ampdurx", 2, set80211ampdu),
5865 DEF_CMD("-ampdurx", -2, set80211ampdu),
5866 DEF_CMD("ampdutx", 1, set80211ampdu),
5867 DEF_CMD("-ampdutx", -1, set80211ampdu),
5868 DEF_CMD("ampdu", 3, set80211ampdu), /* NB: tx+rx */
5869 DEF_CMD("-ampdu", -3, set80211ampdu),
5870 DEF_CMD_ARG("ampdulimit", set80211ampdulimit),
5871 DEF_CMD_ARG("ampdudensity", set80211ampdudensity),
5872 DEF_CMD("amsdurx", 2, set80211amsdu),
5873 DEF_CMD("-amsdurx", -2, set80211amsdu),
5874 DEF_CMD("amsdutx", 1, set80211amsdu),
5875 DEF_CMD("-amsdutx", -1, set80211amsdu),
5876 DEF_CMD("amsdu", 3, set80211amsdu), /* NB: tx+rx */
5877 DEF_CMD("-amsdu", -3, set80211amsdu),
5878 DEF_CMD_ARG("amsdulimit", set80211amsdulimit),
5879 DEF_CMD("stbcrx", 2, set80211stbc),
5880 DEF_CMD("-stbcrx", -2, set80211stbc),
5881 DEF_CMD("stbctx", 1, set80211stbc),
5882 DEF_CMD("-stbctx", -1, set80211stbc),
5883 DEF_CMD("stbc", 3, set80211stbc), /* NB: tx+rx */
5884 DEF_CMD("-stbc", -3, set80211stbc),
5885 DEF_CMD("ldpcrx", 2, set80211ldpc),
5886 DEF_CMD("-ldpcrx", -2, set80211ldpc),
5887 DEF_CMD("ldpctx", 1, set80211ldpc),
5888 DEF_CMD("-ldpctx", -1, set80211ldpc),
5889 DEF_CMD("ldpc", 3, set80211ldpc), /* NB: tx+rx */
5890 DEF_CMD("-ldpc", -3, set80211ldpc),
5891 DEF_CMD("uapsd", 1, set80211uapsd),
5892 DEF_CMD("-uapsd", 0, set80211uapsd),
5893 DEF_CMD("puren", 1, set80211puren),
5894 DEF_CMD("-puren", 0, set80211puren),
5895 DEF_CMD("doth", 1, set80211doth),
5896 DEF_CMD("-doth", 0, set80211doth),
5897 DEF_CMD("dfs", 1, set80211dfs),
5898 DEF_CMD("-dfs", 0, set80211dfs),
5899 DEF_CMD("htcompat", 1, set80211htcompat),
5900 DEF_CMD("-htcompat", 0, set80211htcompat),
5901 DEF_CMD("dwds", 1, set80211dwds),
5902 DEF_CMD("-dwds", 0, set80211dwds),
5903 DEF_CMD("inact", 1, set80211inact),
5904 DEF_CMD("-inact", 0, set80211inact),
5905 DEF_CMD("tsn", 1, set80211tsn),
5906 DEF_CMD("-tsn", 0, set80211tsn),
5907 DEF_CMD_ARG("regdomain", set80211regdomain),
5908 DEF_CMD_ARG("country", set80211country),
5909 DEF_CMD("indoor", 'I', set80211location),
5910 DEF_CMD("-indoor", 'O', set80211location),
5911 DEF_CMD("outdoor", 'O', set80211location),
5912 DEF_CMD("-outdoor", 'I', set80211location),
5913 DEF_CMD("anywhere", ' ', set80211location),
5914 DEF_CMD("ecm", 1, set80211ecm),
5915 DEF_CMD("-ecm", 0, set80211ecm),
5916 DEF_CMD("dotd", 1, set80211dotd),
5917 DEF_CMD("-dotd", 0, set80211dotd),
5918 DEF_CMD_ARG("htprotmode", set80211htprotmode),
5919 DEF_CMD("ht20", 1, set80211htconf),
5920 DEF_CMD("-ht20", 0, set80211htconf),
5921 DEF_CMD("ht40", 3, set80211htconf), /* NB: 20+40 */
5922 DEF_CMD("-ht40", 0, set80211htconf),
5923 DEF_CMD("ht", 3, set80211htconf), /* NB: 20+40 */
5924 DEF_CMD("-ht", 0, set80211htconf),
5925 DEF_CMD("vht", 1, set80211vhtconf),
5926 DEF_CMD("-vht", 0, set80211vhtconf),
5927 DEF_CMD("vht40", 2, set80211vhtconf),
5928 DEF_CMD("-vht40", -2, set80211vhtconf),
5929 DEF_CMD("vht80", 4, set80211vhtconf),
5930 DEF_CMD("-vht80", -4, set80211vhtconf),
5931 DEF_CMD("vht80p80", 8, set80211vhtconf),
5932 DEF_CMD("-vht80p80", -8, set80211vhtconf),
5933 DEF_CMD("vht160", 16, set80211vhtconf),
5934 DEF_CMD("-vht160", -16, set80211vhtconf),
5935 DEF_CMD("rifs", 1, set80211rifs),
5936 DEF_CMD("-rifs", 0, set80211rifs),
5937 DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA, set80211smps),
5938 DEF_CMD("smpsdyn", IEEE80211_HTCAP_SMPS_DYNAMIC, set80211smps),
5939 DEF_CMD("-smps", IEEE80211_HTCAP_SMPS_OFF, set80211smps),
5940 /* XXX for testing */
5941 DEF_CMD_ARG("chanswitch", set80211chanswitch),
5943 DEF_CMD_ARG("tdmaslot", set80211tdmaslot),
5944 DEF_CMD_ARG("tdmaslotcnt", set80211tdmaslotcnt),
5945 DEF_CMD_ARG("tdmaslotlen", set80211tdmaslotlen),
5946 DEF_CMD_ARG("tdmabintval", set80211tdmabintval),
5948 DEF_CMD_ARG("meshttl", set80211meshttl),
5949 DEF_CMD("meshforward", 1, set80211meshforward),
5950 DEF_CMD("-meshforward", 0, set80211meshforward),
5951 DEF_CMD("meshgate", 1, set80211meshgate),
5952 DEF_CMD("-meshgate", 0, set80211meshgate),
5953 DEF_CMD("meshpeering", 1, set80211meshpeering),
5954 DEF_CMD("-meshpeering", 0, set80211meshpeering),
5955 DEF_CMD_ARG("meshmetric", set80211meshmetric),
5956 DEF_CMD_ARG("meshpath", set80211meshpath),
5957 DEF_CMD("meshrt:flush", IEEE80211_MESH_RTCMD_FLUSH, set80211meshrtcmd),
5958 DEF_CMD_ARG("meshrt:add", set80211addmeshrt),
5959 DEF_CMD_ARG("meshrt:del", set80211delmeshrt),
5960 DEF_CMD_ARG("hwmprootmode", set80211hwmprootmode),
5961 DEF_CMD_ARG("hwmpmaxhops", set80211hwmpmaxhops),
5963 /* vap cloning support */
5964 DEF_CLONE_CMD_ARG("wlanaddr", set80211clone_wlanaddr),
5965 DEF_CLONE_CMD_ARG("wlanbssid", set80211clone_wlanbssid),
5966 DEF_CLONE_CMD_ARG("wlandev", set80211clone_wlandev),
5967 DEF_CLONE_CMD_ARG("wlanmode", set80211clone_wlanmode),
5968 DEF_CLONE_CMD("beacons", 1, set80211clone_beacons),
5969 DEF_CLONE_CMD("-beacons", 0, set80211clone_beacons),
5970 DEF_CLONE_CMD("bssid", 1, set80211clone_bssid),
5971 DEF_CLONE_CMD("-bssid", 0, set80211clone_bssid),
5972 DEF_CLONE_CMD("wdslegacy", 1, set80211clone_wdslegacy),
5973 DEF_CLONE_CMD("-wdslegacy", 0, set80211clone_wdslegacy),
5975 static struct afswtch af_ieee80211 = {
5976 .af_name = "af_ieee80211",
5978 .af_other_status = ieee80211_status,
5981 static __constructor void
5982 ieee80211_ctor(void)
5986 for (i = 0; i < nitems(ieee80211_cmds); i++)
5987 cmd_register(&ieee80211_cmds[i]);
5988 af_register(&af_ieee80211);
5989 clone_setdefcallback("wlan", wlan_create);