2 * Copyright 2001 The Aerospace Corporation. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of The Aerospace Corporation may not be used to endorse or
13 * promote products derived from this software.
15 * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
32 * All rights reserved.
34 * This code is derived from software contributed to The NetBSD Foundation
35 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
36 * NASA Ames Research Center.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the NetBSD
49 * Foundation, Inc. and its contributors.
50 * 4. Neither the name of The NetBSD Foundation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
55 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
56 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
58 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64 * POSSIBILITY OF SUCH DAMAGE.
67 #include <sys/param.h>
68 #include <sys/ioctl.h>
69 #include <sys/socket.h>
70 #include <sys/sysctl.h>
73 #include <net/ethernet.h>
75 #include <net/if_dl.h>
76 #include <net/if_types.h>
77 #include <net/if_media.h>
78 #include <net/route.h>
80 #include <net80211/ieee80211_ioctl.h>
93 #include <stddef.h> /* NB: for offsetof */
96 #include "regdomain.h"
98 #ifndef IEEE80211_FIXED_RATE_NONE
99 #define IEEE80211_FIXED_RATE_NONE 0xff
102 /* XXX need these publicly defined or similar */
103 #ifndef IEEE80211_NODE_AUTH
104 #define IEEE80211_NODE_AUTH 0x0001 /* authorized for data */
105 #define IEEE80211_NODE_QOS 0x0002 /* QoS enabled */
106 #define IEEE80211_NODE_ERP 0x0004 /* ERP enabled */
107 #define IEEE80211_NODE_PWR_MGT 0x0010 /* power save mode enabled */
108 #define IEEE80211_NODE_HT 0x0040 /* HT enabled */
109 #define IEEE80211_NODE_HTCOMPAT 0x0080 /* HT setup w/ vendor OUI's */
110 #define IEEE80211_NODE_WPS 0x0100 /* WPS association */
111 #define IEEE80211_NODE_TSN 0x0200 /* TSN association */
112 #define IEEE80211_NODE_AMPDU_RX 0x0400 /* AMPDU rx enabled */
113 #define IEEE80211_NODE_AMPDU_TX 0x0800 /* AMPDU tx enabled */
114 #define IEEE80211_NODE_MIMO_PS 0x1000 /* MIMO power save enabled */
115 #define IEEE80211_NODE_MIMO_RTS 0x2000 /* send RTS in MIMO PS */
116 #define IEEE80211_NODE_RIFS 0x4000 /* RIFS enabled */
119 #define MAXCHAN 1536 /* max 1.5K channels */
125 static void LINE_INIT(char c);
126 static void LINE_BREAK(void);
127 static void LINE_CHECK(const char *fmt, ...);
129 static const char *modename[IEEE80211_MODE_MAX] = {
130 [IEEE80211_MODE_AUTO] = "auto",
131 [IEEE80211_MODE_11A] = "11a",
132 [IEEE80211_MODE_11B] = "11b",
133 [IEEE80211_MODE_11G] = "11g",
134 [IEEE80211_MODE_FH] = "fh",
135 [IEEE80211_MODE_TURBO_A] = "turboA",
136 [IEEE80211_MODE_TURBO_G] = "turboG",
137 [IEEE80211_MODE_STURBO_A] = "sturbo",
138 [IEEE80211_MODE_11NA] = "11na",
139 [IEEE80211_MODE_11NG] = "11ng",
140 [IEEE80211_MODE_HALF] = "half",
141 [IEEE80211_MODE_QUARTER] = "quarter"
144 static void set80211(int s, int type, int val, int len, void *data);
145 static int get80211(int s, int type, void *data, int len);
146 static int get80211len(int s, int type, void *data, int len, int *plen);
147 static int get80211val(int s, int type, int *val);
148 static const char *get_string(const char *val, const char *sep,
149 u_int8_t *buf, int *lenp);
150 static void print_string(const u_int8_t *buf, int len);
151 static void print_regdomain(const struct ieee80211_regdomain *, int);
152 static void print_channels(int, const struct ieee80211req_chaninfo *,
153 int allchans, int verbose);
154 static void regdomain_makechannels(struct ieee80211_regdomain_req *,
155 const struct ieee80211_devcaps_req *);
157 static struct ieee80211req_chaninfo *chaninfo;
158 static struct ieee80211_regdomain regdomain;
159 static int gotregdomain = 0;
160 static struct ieee80211_roamparams_req roamparams;
161 static int gotroam = 0;
162 static struct ieee80211_txparams_req txparams;
163 static int gottxparams = 0;
164 static struct ieee80211_channel curchan;
165 static int gotcurchan = 0;
166 static struct ifmediareq *ifmr;
167 static int htconf = 0;
168 static int gothtconf = 0;
175 if (get80211val(s, IEEE80211_IOC_HTCONF, &htconf) < 0)
176 warn("unable to get HT configuration information");
181 * Collect channel info from the kernel. We use this (mostly)
182 * to handle mapping between frequency and IEEE channel number.
187 if (chaninfo != NULL)
189 chaninfo = malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN));
190 if (chaninfo == NULL)
191 errx(1, "no space for channel list");
192 if (get80211(s, IEEE80211_IOC_CHANINFO, chaninfo,
193 IEEE80211_CHANINFO_SIZE(MAXCHAN)) < 0)
194 err(1, "unable to get channel information");
195 ifmr = ifmedia_getstate(s);
199 static struct regdata *
202 static struct regdata *rdp = NULL;
204 rdp = lib80211_alloc_regdata();
206 errx(-1, "missing or corrupted regdomain database");
212 * Given the channel at index i with attributes from,
213 * check if there is a channel with attributes to in
214 * the channel table. With suitable attributes this
215 * allows the caller to look for promotion; e.g. from
219 canpromote(int i, int from, int to)
221 const struct ieee80211_channel *fc = &chaninfo->ic_chans[i];
224 if ((fc->ic_flags & from) != from)
226 /* NB: quick check exploiting ordering of chans w/ same frequency */
227 if (i+1 < chaninfo->ic_nchans &&
228 chaninfo->ic_chans[i+1].ic_freq == fc->ic_freq &&
229 (chaninfo->ic_chans[i+1].ic_flags & to) == to)
231 /* brute force search in case channel list is not ordered */
232 for (j = 0; j < chaninfo->ic_nchans; j++) {
233 const struct ieee80211_channel *tc = &chaninfo->ic_chans[j];
235 tc->ic_freq == fc->ic_freq && (tc->ic_flags & to) == to)
242 * Handle channel promotion. When a channel is specified with
243 * only a frequency we want to promote it to the ``best'' channel
244 * available. The channel list has separate entries for 11b, 11g,
245 * 11a, and 11n[ga] channels so specifying a frequency w/o any
246 * attributes requires we upgrade, e.g. from 11b -> 11g. This
247 * gets complicated when the channel is specified on the same
248 * command line with a media request that constrains the available
249 * channe list (e.g. mode 11a); we want to honor that to avoid
250 * confusing behaviour.
256 * Query the current mode of the interface in case it's
257 * constrained (e.g. to 11a). We must do this carefully
258 * as there may be a pending ifmedia request in which case
259 * asking the kernel will give us the wrong answer. This
260 * is an unfortunate side-effect of the way ifconfig is
261 * structure for modularity (yech).
263 * NB: ifmr is actually setup in getchaninfo (above); we
264 * assume it's called coincident with to this call so
265 * we have a ``current setting''; otherwise we must pass
266 * the socket descriptor down to here so we can make
267 * the ifmedia_getstate call ourselves.
269 int chanmode = ifmr != NULL ? IFM_MODE(ifmr->ifm_current) : IFM_AUTO;
271 /* when ambiguous promote to ``best'' */
272 /* NB: we abitrarily pick HT40+ over HT40- */
273 if (chanmode != IFM_IEEE80211_11B)
274 i = canpromote(i, IEEE80211_CHAN_B, IEEE80211_CHAN_G);
275 if (chanmode != IFM_IEEE80211_11G && (htconf & 1)) {
276 i = canpromote(i, IEEE80211_CHAN_G,
277 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20);
279 i = canpromote(i, IEEE80211_CHAN_G,
280 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D);
281 i = canpromote(i, IEEE80211_CHAN_G,
282 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U);
285 if (chanmode != IFM_IEEE80211_11A && (htconf & 1)) {
286 i = canpromote(i, IEEE80211_CHAN_A,
287 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20);
289 i = canpromote(i, IEEE80211_CHAN_A,
290 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D);
291 i = canpromote(i, IEEE80211_CHAN_A,
292 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U);
299 mapfreq(struct ieee80211_channel *chan, int freq, int flags)
303 for (i = 0; i < chaninfo->ic_nchans; i++) {
304 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
306 if (c->ic_freq == freq && (c->ic_flags & flags) == flags) {
308 /* when ambiguous promote to ``best'' */
309 c = &chaninfo->ic_chans[promote(i)];
315 errx(1, "unknown/undefined frequency %u/0x%x", freq, flags);
319 mapchan(struct ieee80211_channel *chan, int ieee, int flags)
323 for (i = 0; i < chaninfo->ic_nchans; i++) {
324 const struct ieee80211_channel *c = &chaninfo->ic_chans[i];
326 if (c->ic_ieee == ieee && (c->ic_flags & flags) == flags) {
328 /* when ambiguous promote to ``best'' */
329 c = &chaninfo->ic_chans[promote(i)];
335 errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags);
338 static const struct ieee80211_channel *
343 if (get80211(s, IEEE80211_IOC_CURCHAN, &curchan, sizeof(curchan)) < 0) {
345 /* fall back to legacy ioctl */
346 if (get80211val(s, IEEE80211_IOC_CHANNEL, &val) < 0)
347 err(-1, "cannot figure out current channel");
349 mapchan(&curchan, val, 0);
355 static enum ieee80211_phymode
356 chan2mode(const struct ieee80211_channel *c)
358 if (IEEE80211_IS_CHAN_HTA(c))
359 return IEEE80211_MODE_11NA;
360 if (IEEE80211_IS_CHAN_HTG(c))
361 return IEEE80211_MODE_11NG;
362 if (IEEE80211_IS_CHAN_108A(c))
363 return IEEE80211_MODE_TURBO_A;
364 if (IEEE80211_IS_CHAN_108G(c))
365 return IEEE80211_MODE_TURBO_G;
366 if (IEEE80211_IS_CHAN_ST(c))
367 return IEEE80211_MODE_STURBO_A;
368 if (IEEE80211_IS_CHAN_FHSS(c))
369 return IEEE80211_MODE_FH;
370 if (IEEE80211_IS_CHAN_HALF(c))
371 return IEEE80211_MODE_HALF;
372 if (IEEE80211_IS_CHAN_QUARTER(c))
373 return IEEE80211_MODE_QUARTER;
374 if (IEEE80211_IS_CHAN_A(c))
375 return IEEE80211_MODE_11A;
376 if (IEEE80211_IS_CHAN_ANYG(c))
377 return IEEE80211_MODE_11G;
378 if (IEEE80211_IS_CHAN_B(c))
379 return IEEE80211_MODE_11B;
380 return IEEE80211_MODE_AUTO;
388 if (get80211(s, IEEE80211_IOC_ROAM,
389 &roamparams, sizeof(roamparams)) < 0)
390 err(1, "unable to get roaming parameters");
395 setroam_cb(int s, void *arg)
397 struct ieee80211_roamparams_req *roam = arg;
398 set80211(s, IEEE80211_IOC_ROAM, 0, sizeof(*roam), roam);
406 if (get80211(s, IEEE80211_IOC_TXPARAMS,
407 &txparams, sizeof(txparams)) < 0)
408 err(1, "unable to get transmit parameters");
413 settxparams_cb(int s, void *arg)
415 struct ieee80211_txparams_req *txp = arg;
416 set80211(s, IEEE80211_IOC_TXPARAMS, 0, sizeof(*txp), txp);
424 if (get80211(s, IEEE80211_IOC_REGDOMAIN,
425 ®domain, sizeof(regdomain)) < 0)
426 err(1, "unable to get regulatory domain info");
431 getdevcaps(int s, struct ieee80211_devcaps_req *dc)
433 if (get80211(s, IEEE80211_IOC_DEVCAPS, dc,
434 IEEE80211_DEVCAPS_SPACE(dc)) < 0)
435 err(1, "unable to get device capabilities");
439 setregdomain_cb(int s, void *arg)
441 struct ieee80211_regdomain_req *req;
442 struct ieee80211_regdomain *rd = arg;
443 struct ieee80211_devcaps_req *dc;
444 struct regdata *rdp = getregdata();
446 if (rd->country != NO_COUNTRY) {
447 const struct country *cc;
449 * Check current country seting to make sure it's
450 * compatible with the new regdomain. If not, then
451 * override it with any default country for this
452 * SKU. If we cannot arrange a match, then abort.
454 cc = lib80211_country_findbycc(rdp, rd->country);
456 errx(1, "unknown ISO country code %d", rd->country);
457 if (cc->rd->sku != rd->regdomain) {
458 const struct regdomain *rp;
460 * Check if country is incompatible with regdomain.
461 * To enable multiple regdomains for a country code
462 * we permit a mismatch between the regdomain and
463 * the country's associated regdomain when the
464 * regdomain is setup w/o a default country. For
465 * example, US is bound to the FCC regdomain but
466 * we allow US to be combined with FCC3 because FCC3
467 * has not default country. This allows bogus
468 * combinations like FCC3+DK which are resolved when
469 * constructing the channel list by deferring to the
470 * regdomain to construct the channel list.
472 rp = lib80211_regdomain_findbysku(rdp, rd->regdomain);
474 errx(1, "country %s (%s) is not usable with "
475 "regdomain %d", cc->isoname, cc->name,
477 else if (rp->cc != NULL && rp->cc != cc)
478 errx(1, "country %s (%s) is not usable with "
479 "regdomain %s", cc->isoname, cc->name,
484 * Fetch the device capabilities and calculate the
485 * full set of netbands for which we request a new
486 * channel list be constructed. Once that's done we
487 * push the regdomain info + channel list to the kernel.
489 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
491 errx(1, "no space for device capabilities");
492 dc->dc_chaninfo.ic_nchans = MAXCHAN;
496 printf("drivercaps: 0x%x\n", dc->dc_drivercaps);
497 printf("cryptocaps: 0x%x\n", dc->dc_cryptocaps);
498 printf("htcaps : 0x%x\n", dc->dc_htcaps);
499 memcpy(chaninfo, &dc->dc_chaninfo,
500 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
501 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, 1/*verbose*/);
504 req = malloc(IEEE80211_REGDOMAIN_SIZE(dc->dc_chaninfo.ic_nchans));
506 errx(1, "no space for regdomain request");
508 regdomain_makechannels(req, dc);
511 print_regdomain(rd, 1/*verbose*/);
513 /* blech, reallocate channel list for new data */
514 if (chaninfo != NULL)
516 chaninfo = malloc(IEEE80211_CHANINFO_SPACE(&req->chaninfo));
517 if (chaninfo == NULL)
518 errx(1, "no space for channel list");
519 memcpy(chaninfo, &req->chaninfo,
520 IEEE80211_CHANINFO_SPACE(&req->chaninfo));
521 print_channels(s, &req->chaninfo, 1/*allchans*/, 1/*verbose*/);
523 if (req->chaninfo.ic_nchans == 0)
524 errx(1, "no channels calculated");
525 set80211(s, IEEE80211_IOC_REGDOMAIN, 0,
526 IEEE80211_REGDOMAIN_SPACE(req), req);
532 ieee80211_mhz2ieee(int freq, int flags)
534 struct ieee80211_channel chan;
535 mapfreq(&chan, freq, flags);
540 isanyarg(const char *arg)
542 return (strncmp(arg, "-", 1) == 0 ||
543 strncasecmp(arg, "any", 3) == 0 || strncasecmp(arg, "off", 3) == 0);
547 set80211ssid(const char *val, int d, int s, const struct afswtch *rafp)
551 u_int8_t data[IEEE80211_NWID_LEN];
555 if (len > 2 && isdigit((int)val[0]) && val[1] == ':') {
560 bzero(data, sizeof(data));
562 if (get_string(val, NULL, data, &len) == NULL)
565 set80211(s, IEEE80211_IOC_SSID, ssid, len, data);
569 set80211stationname(const char *val, int d, int s, const struct afswtch *rafp)
574 bzero(data, sizeof(data));
576 get_string(val, NULL, data, &len);
578 set80211(s, IEEE80211_IOC_STATIONNAME, 0, len, data);
582 * Parse a channel specification for attributes/flags.
584 * freq/xx channel width (5,10,20,40,40+,40-)
585 * freq:mode channel mode (a,b,g,h,n,t,s,d)
587 * These can be combined in either order; e.g. 2437:ng/40.
588 * Modes are case insensitive.
590 * The result is not validated here; it's assumed to be
591 * checked against the channel table fetched from the kernel.
594 getchannelflags(const char *val, int freq)
596 #define _CHAN_HT 0x80000000
602 cp = strchr(val, ':');
604 for (cp++; isalpha((int) *cp); cp++) {
605 /* accept mixed case */
610 case 'a': /* 802.11a */
611 flags |= IEEE80211_CHAN_A;
613 case 'b': /* 802.11b */
614 flags |= IEEE80211_CHAN_B;
616 case 'g': /* 802.11g */
617 flags |= IEEE80211_CHAN_G;
619 case 'h': /* ht = 802.11n */
620 case 'n': /* 802.11n */
621 flags |= _CHAN_HT; /* NB: private */
623 case 'd': /* dt = Atheros Dynamic Turbo */
624 flags |= IEEE80211_CHAN_TURBO;
626 case 't': /* ht, dt, st, t */
627 /* dt and unadorned t specify Dynamic Turbo */
628 if ((flags & (IEEE80211_CHAN_STURBO|_CHAN_HT)) == 0)
629 flags |= IEEE80211_CHAN_TURBO;
631 case 's': /* st = Atheros Static Turbo */
632 flags |= IEEE80211_CHAN_STURBO;
635 errx(-1, "%s: Invalid channel attribute %c\n",
640 cp = strchr(val, '/');
643 u_long cw = strtoul(cp+1, &ep, 10);
647 flags |= IEEE80211_CHAN_QUARTER;
650 flags |= IEEE80211_CHAN_HALF;
653 /* NB: this may be removed below */
654 flags |= IEEE80211_CHAN_HT20;
657 if (ep != NULL && *ep == '+')
658 flags |= IEEE80211_CHAN_HT40U;
659 else if (ep != NULL && *ep == '-')
660 flags |= IEEE80211_CHAN_HT40D;
663 errx(-1, "%s: Invalid channel width\n", val);
667 * Cleanup specifications.
669 if ((flags & _CHAN_HT) == 0) {
671 * If user specified freq/20 or freq/40 quietly remove
672 * HT cw attributes depending on channel use. To give
673 * an explicit 20/40 width for an HT channel you must
674 * indicate it is an HT channel since all HT channels
675 * are also usable for legacy operation; e.g. freq:n/40.
677 flags &= ~IEEE80211_CHAN_HT;
680 * Remove private indicator that this is an HT channel
681 * and if no explicit channel width has been given
682 * provide the default settings.
685 if ((flags & IEEE80211_CHAN_HT) == 0) {
686 struct ieee80211_channel chan;
688 * Consult the channel list to see if we can use
689 * HT40+ or HT40- (if both the map routines choose).
692 mapfreq(&chan, freq, 0);
694 mapchan(&chan, freq, 0);
695 flags |= (chan.ic_flags & IEEE80211_CHAN_HT);
703 getchannel(int s, struct ieee80211_channel *chan, const char *val)
708 memset(chan, 0, sizeof(*chan));
710 chan->ic_freq = IEEE80211_CHAN_ANY;
715 v = strtol(val, &eptr, 10);
716 if (val[0] == '\0' || val == eptr || errno == ERANGE ||
717 /* channel may be suffixed with nothing, :flag, or /width */
718 (eptr[0] != '\0' && eptr[0] != ':' && eptr[0] != '/'))
719 errx(1, "invalid channel specification%s",
720 errno == ERANGE ? " (out of range)" : "");
721 flags = getchannelflags(val, v);
722 if (v > 255) { /* treat as frequency */
723 mapfreq(chan, v, flags);
725 mapchan(chan, v, flags);
730 set80211channel(const char *val, int d, int s, const struct afswtch *rafp)
732 struct ieee80211_channel chan;
734 getchannel(s, &chan, val);
735 set80211(s, IEEE80211_IOC_CURCHAN, 0, sizeof(chan), &chan);
739 set80211chanswitch(const char *val, int d, int s, const struct afswtch *rafp)
741 struct ieee80211_chanswitch_req csr;
743 getchannel(s, &csr.csa_chan, val);
746 set80211(s, IEEE80211_IOC_CHANSWITCH, 0, sizeof(csr), &csr);
750 set80211authmode(const char *val, int d, int s, const struct afswtch *rafp)
754 if (strcasecmp(val, "none") == 0) {
755 mode = IEEE80211_AUTH_NONE;
756 } else if (strcasecmp(val, "open") == 0) {
757 mode = IEEE80211_AUTH_OPEN;
758 } else if (strcasecmp(val, "shared") == 0) {
759 mode = IEEE80211_AUTH_SHARED;
760 } else if (strcasecmp(val, "8021x") == 0) {
761 mode = IEEE80211_AUTH_8021X;
762 } else if (strcasecmp(val, "wpa") == 0) {
763 mode = IEEE80211_AUTH_WPA;
765 errx(1, "unknown authmode");
768 set80211(s, IEEE80211_IOC_AUTHMODE, mode, 0, NULL);
772 set80211powersavemode(const char *val, int d, int s, const struct afswtch *rafp)
776 if (strcasecmp(val, "off") == 0) {
777 mode = IEEE80211_POWERSAVE_OFF;
778 } else if (strcasecmp(val, "on") == 0) {
779 mode = IEEE80211_POWERSAVE_ON;
780 } else if (strcasecmp(val, "cam") == 0) {
781 mode = IEEE80211_POWERSAVE_CAM;
782 } else if (strcasecmp(val, "psp") == 0) {
783 mode = IEEE80211_POWERSAVE_PSP;
784 } else if (strcasecmp(val, "psp-cam") == 0) {
785 mode = IEEE80211_POWERSAVE_PSP_CAM;
787 errx(1, "unknown powersavemode");
790 set80211(s, IEEE80211_IOC_POWERSAVE, mode, 0, NULL);
794 set80211powersave(const char *val, int d, int s, const struct afswtch *rafp)
797 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_OFF,
800 set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_ON,
805 set80211powersavesleep(const char *val, int d, int s, const struct afswtch *rafp)
807 set80211(s, IEEE80211_IOC_POWERSAVESLEEP, atoi(val), 0, NULL);
811 set80211wepmode(const char *val, int d, int s, const struct afswtch *rafp)
815 if (strcasecmp(val, "off") == 0) {
816 mode = IEEE80211_WEP_OFF;
817 } else if (strcasecmp(val, "on") == 0) {
818 mode = IEEE80211_WEP_ON;
819 } else if (strcasecmp(val, "mixed") == 0) {
820 mode = IEEE80211_WEP_MIXED;
822 errx(1, "unknown wep mode");
825 set80211(s, IEEE80211_IOC_WEP, mode, 0, NULL);
829 set80211wep(const char *val, int d, int s, const struct afswtch *rafp)
831 set80211(s, IEEE80211_IOC_WEP, d, 0, NULL);
835 isundefarg(const char *arg)
837 return (strcmp(arg, "-") == 0 || strncasecmp(arg, "undef", 5) == 0);
841 set80211weptxkey(const char *val, int d, int s, const struct afswtch *rafp)
844 set80211(s, IEEE80211_IOC_WEPTXKEY, IEEE80211_KEYIX_NONE, 0, NULL);
846 set80211(s, IEEE80211_IOC_WEPTXKEY, atoi(val)-1, 0, NULL);
850 set80211wepkey(const char *val, int d, int s, const struct afswtch *rafp)
854 u_int8_t data[IEEE80211_KEYBUF_SIZE];
856 if (isdigit((int)val[0]) && val[1] == ':') {
861 bzero(data, sizeof(data));
863 get_string(val, NULL, data, &len);
865 set80211(s, IEEE80211_IOC_WEPKEY, key, len, data);
869 * This function is purely a NetBSD compatability interface. The NetBSD
870 * interface is too inflexible, but it's there so we'll support it since
871 * it's not all that hard.
874 set80211nwkey(const char *val, int d, int s, const struct afswtch *rafp)
878 u_int8_t data[IEEE80211_KEYBUF_SIZE];
880 set80211(s, IEEE80211_IOC_WEP, IEEE80211_WEP_ON, 0, NULL);
882 if (isdigit((int)val[0]) && val[1] == ':') {
883 txkey = val[0]-'0'-1;
886 for (i = 0; i < 4; i++) {
887 bzero(data, sizeof(data));
889 val = get_string(val, ",", data, &len);
893 set80211(s, IEEE80211_IOC_WEPKEY, i, len, data);
896 bzero(data, sizeof(data));
898 get_string(val, NULL, data, &len);
901 set80211(s, IEEE80211_IOC_WEPKEY, 0, len, data);
903 bzero(data, sizeof(data));
904 for (i = 1; i < 4; i++)
905 set80211(s, IEEE80211_IOC_WEPKEY, i, 0, data);
908 set80211(s, IEEE80211_IOC_WEPTXKEY, txkey, 0, NULL);
912 set80211rtsthreshold(const char *val, int d, int s, const struct afswtch *rafp)
914 set80211(s, IEEE80211_IOC_RTSTHRESHOLD,
915 isundefarg(val) ? IEEE80211_RTS_MAX : atoi(val), 0, NULL);
919 set80211protmode(const char *val, int d, int s, const struct afswtch *rafp)
923 if (strcasecmp(val, "off") == 0) {
924 mode = IEEE80211_PROTMODE_OFF;
925 } else if (strcasecmp(val, "cts") == 0) {
926 mode = IEEE80211_PROTMODE_CTS;
927 } else if (strncasecmp(val, "rtscts", 3) == 0) {
928 mode = IEEE80211_PROTMODE_RTSCTS;
930 errx(1, "unknown protection mode");
933 set80211(s, IEEE80211_IOC_PROTMODE, mode, 0, NULL);
937 set80211htprotmode(const char *val, int d, int s, const struct afswtch *rafp)
941 if (strcasecmp(val, "off") == 0) {
942 mode = IEEE80211_PROTMODE_OFF;
943 } else if (strncasecmp(val, "rts", 3) == 0) {
944 mode = IEEE80211_PROTMODE_RTSCTS;
946 errx(1, "unknown protection mode");
949 set80211(s, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL);
953 set80211txpower(const char *val, int d, int s, const struct afswtch *rafp)
955 double v = atof(val);
960 errx(-1, "invalid tx power (must be .5 dBm units)");
961 set80211(s, IEEE80211_IOC_TXPOWER, txpow, 0, NULL);
964 #define IEEE80211_ROAMING_DEVICE 0
965 #define IEEE80211_ROAMING_AUTO 1
966 #define IEEE80211_ROAMING_MANUAL 2
969 set80211roaming(const char *val, int d, int s, const struct afswtch *rafp)
973 if (strcasecmp(val, "device") == 0) {
974 mode = IEEE80211_ROAMING_DEVICE;
975 } else if (strcasecmp(val, "auto") == 0) {
976 mode = IEEE80211_ROAMING_AUTO;
977 } else if (strcasecmp(val, "manual") == 0) {
978 mode = IEEE80211_ROAMING_MANUAL;
980 errx(1, "unknown roaming mode");
982 set80211(s, IEEE80211_IOC_ROAMING, mode, 0, NULL);
986 set80211wme(const char *val, int d, int s, const struct afswtch *rafp)
988 set80211(s, IEEE80211_IOC_WME, d, 0, NULL);
992 set80211hidessid(const char *val, int d, int s, const struct afswtch *rafp)
994 set80211(s, IEEE80211_IOC_HIDESSID, d, 0, NULL);
998 set80211apbridge(const char *val, int d, int s, const struct afswtch *rafp)
1000 set80211(s, IEEE80211_IOC_APBRIDGE, d, 0, NULL);
1004 set80211fastframes(const char *val, int d, int s, const struct afswtch *rafp)
1006 set80211(s, IEEE80211_IOC_FF, d, 0, NULL);
1010 set80211dturbo(const char *val, int d, int s, const struct afswtch *rafp)
1012 set80211(s, IEEE80211_IOC_TURBOP, d, 0, NULL);
1016 set80211chanlist(const char *val, int d, int s, const struct afswtch *rafp)
1018 struct ieee80211req_chanlist chanlist;
1019 char *temp, *cp, *tp;
1021 temp = malloc(strlen(val) + 1);
1023 errx(1, "malloc failed");
1025 memset(&chanlist, 0, sizeof(chanlist));
1028 int first, last, f, c;
1030 tp = strchr(cp, ',');
1033 switch (sscanf(cp, "%u-%u", &first, &last)) {
1035 if (first > IEEE80211_CHAN_MAX)
1036 errx(-1, "channel %u out of range, max %u",
1037 first, IEEE80211_CHAN_MAX);
1038 setbit(chanlist.ic_channels, first);
1041 if (first > IEEE80211_CHAN_MAX)
1042 errx(-1, "channel %u out of range, max %u",
1043 first, IEEE80211_CHAN_MAX);
1044 if (last > IEEE80211_CHAN_MAX)
1045 errx(-1, "channel %u out of range, max %u",
1046 last, IEEE80211_CHAN_MAX);
1048 errx(-1, "void channel range, %u > %u",
1050 for (f = first; f <= last; f++)
1051 setbit(chanlist.ic_channels, f);
1063 set80211(s, IEEE80211_IOC_CHANLIST, 0, sizeof(chanlist), &chanlist);
1067 set80211bssid(const char *val, int d, int s, const struct afswtch *rafp)
1070 if (!isanyarg(val)) {
1072 struct sockaddr_dl sdl;
1074 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1076 errx(1, "malloc failed");
1078 strcpy(temp + 1, val);
1079 sdl.sdl_len = sizeof(sdl);
1080 link_addr(temp, &sdl);
1082 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1083 errx(1, "malformed link-level address");
1084 set80211(s, IEEE80211_IOC_BSSID, 0,
1085 IEEE80211_ADDR_LEN, LLADDR(&sdl));
1087 uint8_t zerobssid[IEEE80211_ADDR_LEN];
1088 memset(zerobssid, 0, sizeof(zerobssid));
1089 set80211(s, IEEE80211_IOC_BSSID, 0,
1090 IEEE80211_ADDR_LEN, zerobssid);
1095 getac(const char *ac)
1097 if (strcasecmp(ac, "ac_be") == 0 || strcasecmp(ac, "be") == 0)
1099 if (strcasecmp(ac, "ac_bk") == 0 || strcasecmp(ac, "bk") == 0)
1101 if (strcasecmp(ac, "ac_vi") == 0 || strcasecmp(ac, "vi") == 0)
1103 if (strcasecmp(ac, "ac_vo") == 0 || strcasecmp(ac, "vo") == 0)
1105 errx(1, "unknown wme access class %s", ac);
1109 DECL_CMD_FUNC2(set80211cwmin, ac, val)
1111 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac), NULL);
1115 DECL_CMD_FUNC2(set80211cwmax, ac, val)
1117 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac), NULL);
1121 DECL_CMD_FUNC2(set80211aifs, ac, val)
1123 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac), NULL);
1127 DECL_CMD_FUNC2(set80211txoplimit, ac, val)
1129 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac), NULL);
1133 DECL_CMD_FUNC(set80211acm, ac, d)
1135 set80211(s, IEEE80211_IOC_WME_ACM, 1, getac(ac), NULL);
1138 DECL_CMD_FUNC(set80211noacm, ac, d)
1140 set80211(s, IEEE80211_IOC_WME_ACM, 0, getac(ac), NULL);
1144 DECL_CMD_FUNC(set80211ackpolicy, ac, d)
1146 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 1, getac(ac), NULL);
1149 DECL_CMD_FUNC(set80211noackpolicy, ac, d)
1151 set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 0, getac(ac), NULL);
1155 DECL_CMD_FUNC2(set80211bsscwmin, ac, val)
1157 set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val),
1158 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1162 DECL_CMD_FUNC2(set80211bsscwmax, ac, val)
1164 set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val),
1165 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1169 DECL_CMD_FUNC2(set80211bssaifs, ac, val)
1171 set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val),
1172 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1176 DECL_CMD_FUNC2(set80211bsstxoplimit, ac, val)
1178 set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val),
1179 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL);
1183 DECL_CMD_FUNC(set80211dtimperiod, val, d)
1185 set80211(s, IEEE80211_IOC_DTIM_PERIOD, atoi(val), 0, NULL);
1189 DECL_CMD_FUNC(set80211bintval, val, d)
1191 set80211(s, IEEE80211_IOC_BEACON_INTERVAL, atoi(val), 0, NULL);
1195 set80211macmac(int s, int op, const char *val)
1198 struct sockaddr_dl sdl;
1200 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1202 errx(1, "malloc failed");
1204 strcpy(temp + 1, val);
1205 sdl.sdl_len = sizeof(sdl);
1206 link_addr(temp, &sdl);
1208 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1209 errx(1, "malformed link-level address");
1210 set80211(s, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl));
1214 DECL_CMD_FUNC(set80211addmac, val, d)
1216 set80211macmac(s, IEEE80211_IOC_ADDMAC, val);
1220 DECL_CMD_FUNC(set80211delmac, val, d)
1222 set80211macmac(s, IEEE80211_IOC_DELMAC, val);
1226 DECL_CMD_FUNC(set80211kickmac, val, d)
1229 struct sockaddr_dl sdl;
1230 struct ieee80211req_mlme mlme;
1232 temp = malloc(strlen(val) + 2); /* ':' and '\0' */
1234 errx(1, "malloc failed");
1236 strcpy(temp + 1, val);
1237 sdl.sdl_len = sizeof(sdl);
1238 link_addr(temp, &sdl);
1240 if (sdl.sdl_alen != IEEE80211_ADDR_LEN)
1241 errx(1, "malformed link-level address");
1242 memset(&mlme, 0, sizeof(mlme));
1243 mlme.im_op = IEEE80211_MLME_DEAUTH;
1244 mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE;
1245 memcpy(mlme.im_macaddr, LLADDR(&sdl), IEEE80211_ADDR_LEN);
1246 set80211(s, IEEE80211_IOC_MLME, 0, sizeof(mlme), &mlme);
1250 DECL_CMD_FUNC(set80211maccmd, val, d)
1252 set80211(s, IEEE80211_IOC_MACCMD, d, 0, NULL);
1256 set80211pureg(const char *val, int d, int s, const struct afswtch *rafp)
1258 set80211(s, IEEE80211_IOC_PUREG, d, 0, NULL);
1262 set80211bgscan(const char *val, int d, int s, const struct afswtch *rafp)
1264 set80211(s, IEEE80211_IOC_BGSCAN, d, 0, NULL);
1268 DECL_CMD_FUNC(set80211bgscanidle, val, d)
1270 set80211(s, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL);
1274 DECL_CMD_FUNC(set80211bgscanintvl, val, d)
1276 set80211(s, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL);
1280 DECL_CMD_FUNC(set80211scanvalid, val, d)
1282 set80211(s, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL);
1286 * Parse an optional trailing specification of which netbands
1287 * to apply a parameter to. This is basically the same syntax
1288 * as used for channels but you can concatenate to specify
1289 * multiple. For example:
1290 * 14:abg apply to 11a, 11b, and 11g
1291 * 6:ht apply to 11na and 11ng
1292 * We don't make a big effort to catch silly things; this is
1293 * really a convenience mechanism.
1296 getmodeflags(const char *val)
1303 cp = strchr(val, ':');
1305 for (cp++; isalpha((int) *cp); cp++) {
1306 /* accept mixed case */
1311 case 'a': /* 802.11a */
1312 flags |= IEEE80211_CHAN_A;
1314 case 'b': /* 802.11b */
1315 flags |= IEEE80211_CHAN_B;
1317 case 'g': /* 802.11g */
1318 flags |= IEEE80211_CHAN_G;
1320 case 'n': /* 802.11n */
1321 flags |= IEEE80211_CHAN_HT;
1323 case 'd': /* dt = Atheros Dynamic Turbo */
1324 flags |= IEEE80211_CHAN_TURBO;
1326 case 't': /* ht, dt, st, t */
1327 /* dt and unadorned t specify Dynamic Turbo */
1328 if ((flags & (IEEE80211_CHAN_STURBO|IEEE80211_CHAN_HT)) == 0)
1329 flags |= IEEE80211_CHAN_TURBO;
1331 case 's': /* st = Atheros Static Turbo */
1332 flags |= IEEE80211_CHAN_STURBO;
1334 case 'h': /* 1/2-width channels */
1335 flags |= IEEE80211_CHAN_HALF;
1337 case 'q': /* 1/4-width channels */
1338 flags |= IEEE80211_CHAN_QUARTER;
1341 errx(-1, "%s: Invalid mode attribute %c\n",
1349 #define IEEE80211_CHAN_HTA (IEEE80211_CHAN_HT|IEEE80211_CHAN_5GHZ)
1350 #define IEEE80211_CHAN_HTG (IEEE80211_CHAN_HT|IEEE80211_CHAN_2GHZ)
1352 #define _APPLY(_flags, _base, _param, _v) do { \
1353 if (_flags & IEEE80211_CHAN_HT) { \
1354 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1355 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1356 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1357 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1358 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1360 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1362 if (_flags & IEEE80211_CHAN_TURBO) { \
1363 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1364 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1365 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1366 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1367 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1369 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1371 if (_flags & IEEE80211_CHAN_STURBO) \
1372 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1373 if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1374 _base.params[IEEE80211_MODE_11A]._param = _v; \
1375 if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1376 _base.params[IEEE80211_MODE_11G]._param = _v; \
1377 if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1378 _base.params[IEEE80211_MODE_11B]._param = _v; \
1379 if (_flags & IEEE80211_CHAN_HALF) \
1380 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1381 if (_flags & IEEE80211_CHAN_QUARTER) \
1382 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1384 #define _APPLY1(_flags, _base, _param, _v) do { \
1385 if (_flags & IEEE80211_CHAN_HT) { \
1386 if (_flags & IEEE80211_CHAN_5GHZ) \
1387 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1389 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1390 } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \
1391 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1392 else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \
1393 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1394 else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \
1395 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1396 else if (_flags & IEEE80211_CHAN_HALF) \
1397 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1398 else if (_flags & IEEE80211_CHAN_QUARTER) \
1399 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1400 else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1401 _base.params[IEEE80211_MODE_11A]._param = _v; \
1402 else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1403 _base.params[IEEE80211_MODE_11G]._param = _v; \
1404 else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1405 _base.params[IEEE80211_MODE_11B]._param = _v; \
1407 #define _APPLY_RATE(_flags, _base, _param, _v) do { \
1408 if (_flags & IEEE80211_CHAN_HT) { \
1409 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1411 _APPLY(_flags, _base, _param, _v); \
1413 #define _APPLY_RATE1(_flags, _base, _param, _v) do { \
1414 if (_flags & IEEE80211_CHAN_HT) { \
1415 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1417 _APPLY1(_flags, _base, _param, _v); \
1421 DECL_CMD_FUNC(set80211roamrssi, val, d)
1423 double v = atof(val);
1428 errx(-1, "invalid rssi (must be .5 dBm units)");
1429 flags = getmodeflags(val);
1431 if (flags == 0) { /* NB: no flags => current channel */
1432 flags = getcurchan(s)->ic_flags;
1433 _APPLY1(flags, roamparams, rssi, rssi);
1435 _APPLY(flags, roamparams, rssi, rssi);
1436 callback_register(setroam_cb, &roamparams);
1440 getrate(const char *val, const char *tag)
1442 double v = atof(val);
1447 errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag);
1448 return rate; /* NB: returns 2x the specified value */
1452 DECL_CMD_FUNC(set80211roamrate, val, d)
1456 rate = getrate(val, "roam");
1457 flags = getmodeflags(val);
1459 if (flags == 0) { /* NB: no flags => current channel */
1460 flags = getcurchan(s)->ic_flags;
1461 _APPLY_RATE1(flags, roamparams, rate, rate);
1463 _APPLY_RATE(flags, roamparams, rate, rate);
1464 callback_register(setroam_cb, &roamparams);
1468 DECL_CMD_FUNC(set80211mcastrate, val, d)
1472 rate = getrate(val, "mcast");
1473 flags = getmodeflags(val);
1475 if (flags == 0) { /* NB: no flags => current channel */
1476 flags = getcurchan(s)->ic_flags;
1477 _APPLY_RATE1(flags, txparams, mcastrate, rate);
1479 _APPLY_RATE(flags, txparams, mcastrate, rate);
1480 callback_register(settxparams_cb, &txparams);
1484 DECL_CMD_FUNC(set80211mgtrate, val, d)
1488 rate = getrate(val, "mgmt");
1489 flags = getmodeflags(val);
1491 if (flags == 0) { /* NB: no flags => current channel */
1492 flags = getcurchan(s)->ic_flags;
1493 _APPLY_RATE1(flags, txparams, mgmtrate, rate);
1495 _APPLY_RATE(flags, txparams, mgmtrate, rate);
1496 callback_register(settxparams_cb, &txparams);
1500 DECL_CMD_FUNC(set80211ucastrate, val, d)
1505 flags = getmodeflags(val);
1506 if (isanyarg(val)) {
1507 if (flags == 0) { /* NB: no flags => current channel */
1508 flags = getcurchan(s)->ic_flags;
1509 _APPLY1(flags, txparams, ucastrate,
1510 IEEE80211_FIXED_RATE_NONE);
1512 _APPLY(flags, txparams, ucastrate,
1513 IEEE80211_FIXED_RATE_NONE);
1515 int rate = getrate(val, "ucast");
1516 if (flags == 0) { /* NB: no flags => current channel */
1517 flags = getcurchan(s)->ic_flags;
1518 _APPLY_RATE1(flags, txparams, ucastrate, rate);
1520 _APPLY_RATE(flags, txparams, ucastrate, rate);
1522 callback_register(settxparams_cb, &txparams);
1526 DECL_CMD_FUNC(set80211maxretry, val, d)
1528 int v = atoi(val), flags;
1530 flags = getmodeflags(val);
1532 if (flags == 0) { /* NB: no flags => current channel */
1533 flags = getcurchan(s)->ic_flags;
1534 _APPLY1(flags, txparams, maxretry, v);
1536 _APPLY(flags, txparams, maxretry, v);
1537 callback_register(settxparams_cb, &txparams);
1541 #undef IEEE80211_CHAN_HTA
1542 #undef IEEE80211_CHAN_HTG
1545 DECL_CMD_FUNC(set80211fragthreshold, val, d)
1547 set80211(s, IEEE80211_IOC_FRAGTHRESHOLD,
1548 isundefarg(val) ? IEEE80211_FRAG_MAX : atoi(val), 0, NULL);
1552 DECL_CMD_FUNC(set80211bmissthreshold, val, d)
1554 set80211(s, IEEE80211_IOC_BMISSTHRESHOLD,
1555 isundefarg(val) ? IEEE80211_HWBMISS_MAX : atoi(val), 0, NULL);
1559 set80211burst(const char *val, int d, int s, const struct afswtch *rafp)
1561 set80211(s, IEEE80211_IOC_BURST, d, 0, NULL);
1565 set80211doth(const char *val, int d, int s, const struct afswtch *rafp)
1567 set80211(s, IEEE80211_IOC_DOTH, d, 0, NULL);
1571 set80211dfs(const char *val, int d, int s, const struct afswtch *rafp)
1573 set80211(s, IEEE80211_IOC_DFS, d, 0, NULL);
1577 set80211shortgi(const char *val, int d, int s, const struct afswtch *rafp)
1579 set80211(s, IEEE80211_IOC_SHORTGI,
1580 d ? (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) : 0,
1585 set80211ampdu(const char *val, int d, int s, const struct afswtch *rafp)
1589 if (get80211val(s, IEEE80211_IOC_AMPDU, &du) < 0)
1590 errx(-1, "cannot get AMPDU setting");
1596 set80211(s, IEEE80211_IOC_AMPDU, ampdu, 0, NULL);
1600 DECL_CMD_FUNC(set80211ampdulimit, val, d)
1604 switch (atoi(val)) {
1607 v = IEEE80211_HTCAP_MAXRXAMPDU_8K;
1611 v = IEEE80211_HTCAP_MAXRXAMPDU_16K;
1615 v = IEEE80211_HTCAP_MAXRXAMPDU_32K;
1619 v = IEEE80211_HTCAP_MAXRXAMPDU_64K;
1622 errx(-1, "invalid A-MPDU limit %s", val);
1624 set80211(s, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL);
1628 DECL_CMD_FUNC(set80211ampdudensity, val, d)
1632 if (isanyarg(val) || strcasecmp(val, "na") == 0)
1633 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1634 else switch ((int)(atof(val)*4)) {
1636 v = IEEE80211_HTCAP_MPDUDENSITY_NA;
1639 v = IEEE80211_HTCAP_MPDUDENSITY_025;
1642 v = IEEE80211_HTCAP_MPDUDENSITY_05;
1645 v = IEEE80211_HTCAP_MPDUDENSITY_1;
1648 v = IEEE80211_HTCAP_MPDUDENSITY_2;
1651 v = IEEE80211_HTCAP_MPDUDENSITY_4;
1654 v = IEEE80211_HTCAP_MPDUDENSITY_8;
1657 v = IEEE80211_HTCAP_MPDUDENSITY_16;
1660 errx(-1, "invalid A-MPDU density %s", val);
1662 set80211(s, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL);
1666 set80211amsdu(const char *val, int d, int s, const struct afswtch *rafp)
1670 if (get80211val(s, IEEE80211_IOC_AMSDU, &amsdu) < 0)
1671 err(-1, "cannot get AMSDU setting");
1677 set80211(s, IEEE80211_IOC_AMSDU, amsdu, 0, NULL);
1681 DECL_CMD_FUNC(set80211amsdulimit, val, d)
1683 set80211(s, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL);
1687 set80211puren(const char *val, int d, int s, const struct afswtch *rafp)
1689 set80211(s, IEEE80211_IOC_PUREN, d, 0, NULL);
1693 set80211htcompat(const char *val, int d, int s, const struct afswtch *rafp)
1695 set80211(s, IEEE80211_IOC_HTCOMPAT, d, 0, NULL);
1699 set80211htconf(const char *val, int d, int s, const struct afswtch *rafp)
1701 set80211(s, IEEE80211_IOC_HTCONF, d, 0, NULL);
1706 set80211dwds(const char *val, int d, int s, const struct afswtch *rafp)
1708 set80211(s, IEEE80211_IOC_DWDS, d, 0, NULL);
1712 set80211inact(const char *val, int d, int s, const struct afswtch *rafp)
1714 set80211(s, IEEE80211_IOC_INACTIVITY, d, 0, NULL);
1718 set80211tsn(const char *val, int d, int s, const struct afswtch *rafp)
1720 set80211(s, IEEE80211_IOC_TSN, d, 0, NULL);
1724 set80211dotd(const char *val, int d, int s, const struct afswtch *rafp)
1726 set80211(s, IEEE80211_IOC_DOTD, d, 0, NULL);
1730 set80211smps(const char *val, int d, int s, const struct afswtch *rafp)
1732 set80211(s, IEEE80211_IOC_SMPS, d, 0, NULL);
1736 set80211rifs(const char *val, int d, int s, const struct afswtch *rafp)
1738 set80211(s, IEEE80211_IOC_RIFS, d, 0, NULL);
1742 DECL_CMD_FUNC(set80211tdmaslot, val, d)
1744 set80211(s, IEEE80211_IOC_TDMA_SLOT, atoi(val), 0, NULL);
1748 DECL_CMD_FUNC(set80211tdmaslotcnt, val, d)
1750 set80211(s, IEEE80211_IOC_TDMA_SLOTCNT, atoi(val), 0, NULL);
1754 DECL_CMD_FUNC(set80211tdmaslotlen, val, d)
1756 set80211(s, IEEE80211_IOC_TDMA_SLOTLEN, atoi(val), 0, NULL);
1760 DECL_CMD_FUNC(set80211tdmabintval, val, d)
1762 set80211(s, IEEE80211_IOC_TDMA_BINTERVAL, atoi(val), 0, NULL);
1766 regdomain_sort(const void *a, const void *b)
1769 (IEEE80211_CHAN_ALLTURBO|IEEE80211_CHAN_HALF|IEEE80211_CHAN_QUARTER)
1770 const struct ieee80211_channel *ca = a;
1771 const struct ieee80211_channel *cb = b;
1773 return ca->ic_freq == cb->ic_freq ?
1774 (ca->ic_flags & CHAN_ALL) - (cb->ic_flags & CHAN_ALL) :
1775 ca->ic_freq - cb->ic_freq;
1779 static const struct ieee80211_channel *
1780 chanlookup(const struct ieee80211_channel chans[], int nchans,
1781 int freq, int flags)
1785 flags &= IEEE80211_CHAN_ALLTURBO;
1786 for (i = 0; i < nchans; i++) {
1787 const struct ieee80211_channel *c = &chans[i];
1788 if (c->ic_freq == freq &&
1789 (c->ic_flags & IEEE80211_CHAN_ALLTURBO) == flags)
1796 chanfind(const struct ieee80211_channel chans[], int nchans, int flags)
1800 for (i = 0; i < nchans; i++) {
1801 const struct ieee80211_channel *c = &chans[i];
1802 if ((c->ic_flags & flags) == flags)
1809 * Check channel compatibility.
1812 checkchan(const struct ieee80211req_chaninfo *avail, int freq, int flags)
1814 flags &= ~REQ_FLAGS;
1816 * Check if exact channel is in the calibration table;
1817 * everything below is to deal with channels that we
1818 * want to include but that are not explicitly listed.
1820 if (flags & IEEE80211_CHAN_HT40) {
1821 /* NB: we use an HT40 channel center that matches HT20 */
1822 flags = (flags &~ IEEE80211_CHAN_HT40) | IEEE80211_CHAN_HT20;
1824 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, flags) != NULL)
1826 if (flags & IEEE80211_CHAN_GSM) {
1828 * XXX GSM frequency mapping is handled in the kernel
1829 * so we cannot find them in the calibration table;
1830 * just accept the channel and the kernel will reject
1831 * the channel list if it's wrong.
1836 * If this is a 1/2 or 1/4 width channel allow it if a full
1837 * width channel is present for this frequency, and the device
1838 * supports fractional channels on this band. This is a hack
1839 * that avoids bloating the calibration table; it may be better
1840 * by per-band attributes though (we are effectively calculating
1841 * this attribute by scanning the channel list ourself).
1843 if ((flags & (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == 0)
1845 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq,
1846 flags &~ (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == NULL)
1848 if (flags & IEEE80211_CHAN_HALF) {
1849 return chanfind(avail->ic_chans, avail->ic_nchans,
1850 IEEE80211_CHAN_HALF |
1851 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
1853 return chanfind(avail->ic_chans, avail->ic_nchans,
1854 IEEE80211_CHAN_QUARTER |
1855 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ)));
1860 regdomain_addchans(struct ieee80211req_chaninfo *ci,
1861 const netband_head *bands,
1862 const struct ieee80211_regdomain *reg,
1864 const struct ieee80211req_chaninfo *avail)
1866 const struct netband *nb;
1867 const struct freqband *b;
1868 struct ieee80211_channel *c, *prev;
1869 int freq, hi_adj, lo_adj, channelSep;
1872 hi_adj = (chanFlags & IEEE80211_CHAN_HT40U) ? -20 : 0;
1873 lo_adj = (chanFlags & IEEE80211_CHAN_HT40D) ? 20 : 0;
1874 channelSep = (chanFlags & IEEE80211_CHAN_2GHZ) ? 0 : 40;
1875 LIST_FOREACH(nb, bands, next) {
1878 printf("%s:", __func__);
1879 printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS);
1880 printb(" bandFlags", nb->flags | b->flags,
1881 IEEE80211_CHAN_BITS);
1885 for (freq = b->freqStart + lo_adj;
1886 freq <= b->freqEnd + hi_adj; freq += b->chanSep) {
1888 * Construct flags for the new channel. We take
1889 * the attributes from the band descriptions except
1890 * for HT40 which is enabled generically (i.e. +/-
1891 * extension channel) in the band description and
1892 * then constrained according by channel separation.
1894 flags = nb->flags | b->flags;
1895 if (flags & IEEE80211_CHAN_HT) {
1897 * HT channels are generated specially; we're
1898 * called to add HT20, HT40+, and HT40- chan's
1899 * so we need to expand only band specs for
1900 * the HT channel type being added.
1902 if ((chanFlags & IEEE80211_CHAN_HT20) &&
1903 (flags & IEEE80211_CHAN_HT20) == 0) {
1905 printf("%u: skip, not an "
1906 "HT20 channel\n", freq);
1909 if ((chanFlags & IEEE80211_CHAN_HT40) &&
1910 (flags & IEEE80211_CHAN_HT40) == 0) {
1912 printf("%u: skip, not an "
1913 "HT40 channel\n", freq);
1917 * DFS and HT40 don't mix. This should be
1918 * expressed in the regdomain database but
1919 * just in case enforce it here.
1921 if ((chanFlags & IEEE80211_CHAN_HT40) &&
1922 (flags & IEEE80211_CHAN_DFS)) {
1924 printf("%u: skip, HT40+DFS "
1925 "not permitted\n", freq);
1928 /* NB: HT attribute comes from caller */
1929 flags &= ~IEEE80211_CHAN_HT;
1930 flags |= chanFlags & IEEE80211_CHAN_HT;
1933 * Check if device can operate on this frequency.
1935 if (!checkchan(avail, freq, flags)) {
1937 printf("%u: skip, ", freq);
1938 printb("flags", flags,
1939 IEEE80211_CHAN_BITS);
1940 printf(" not available\n");
1944 if ((flags & REQ_ECM) && !reg->ecm) {
1946 printf("%u: skip, ECM channel\n", freq);
1949 if ((flags & REQ_INDOOR) && reg->location == 'O') {
1951 printf("%u: skip, indoor channel\n",
1955 if ((flags & REQ_OUTDOOR) && reg->location == 'I') {
1957 printf("%u: skip, outdoor channel\n",
1961 if ((flags & IEEE80211_CHAN_HT40) &&
1962 prev != NULL && (freq - prev->ic_freq) < channelSep) {
1964 printf("%u: skip, only %u channel "
1965 "separation, need %d\n", freq,
1966 freq - prev->ic_freq, channelSep);
1969 if (ci->ic_nchans == IEEE80211_CHAN_MAX) {
1971 printf("%u: skip, channel table full\n",
1975 c = &ci->ic_chans[ci->ic_nchans++];
1976 memset(c, 0, sizeof(*c));
1978 c->ic_flags = flags;
1979 if (c->ic_flags & IEEE80211_CHAN_DFS)
1980 c->ic_maxregpower = nb->maxPowerDFS;
1982 c->ic_maxregpower = nb->maxPower;
1984 printf("[%3d] add freq %u ",
1985 ci->ic_nchans-1, c->ic_freq);
1986 printb("flags", c->ic_flags, IEEE80211_CHAN_BITS);
1987 printf(" power %u\n", c->ic_maxregpower);
1989 /* NB: kernel fills in other fields */
1996 regdomain_makechannels(
1997 struct ieee80211_regdomain_req *req,
1998 const struct ieee80211_devcaps_req *dc)
2000 struct regdata *rdp = getregdata();
2001 const struct country *cc;
2002 const struct ieee80211_regdomain *reg = &req->rd;
2003 struct ieee80211req_chaninfo *ci = &req->chaninfo;
2004 const struct regdomain *rd;
2007 * Locate construction table for new channel list. We treat
2008 * the regdomain/SKU as definitive so a country can be in
2009 * multiple with different properties (e.g. US in FCC+FCC3).
2010 * If no regdomain is specified then we fallback on the country
2011 * code to find the associated regdomain since countries always
2012 * belong to at least one regdomain.
2014 if (reg->regdomain == 0) {
2015 cc = lib80211_country_findbycc(rdp, reg->country);
2017 errx(1, "internal error, country %d not found",
2021 rd = lib80211_regdomain_findbysku(rdp, reg->regdomain);
2023 errx(1, "internal error, regdomain %d not found",
2025 if (rd->sku != SKU_DEBUG) {
2027 * regdomain_addchans incrememnts the channel count for
2028 * each channel it adds so initialize ic_nchans to zero.
2029 * Note that we know we have enough space to hold all possible
2030 * channels because the devcaps list size was used to
2031 * allocate our request.
2034 if (!LIST_EMPTY(&rd->bands_11b))
2035 regdomain_addchans(ci, &rd->bands_11b, reg,
2036 IEEE80211_CHAN_B, &dc->dc_chaninfo);
2037 if (!LIST_EMPTY(&rd->bands_11g))
2038 regdomain_addchans(ci, &rd->bands_11g, reg,
2039 IEEE80211_CHAN_G, &dc->dc_chaninfo);
2040 if (!LIST_EMPTY(&rd->bands_11a))
2041 regdomain_addchans(ci, &rd->bands_11a, reg,
2042 IEEE80211_CHAN_A, &dc->dc_chaninfo);
2043 if (!LIST_EMPTY(&rd->bands_11na) && dc->dc_htcaps != 0) {
2044 regdomain_addchans(ci, &rd->bands_11na, reg,
2045 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20,
2047 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2048 regdomain_addchans(ci, &rd->bands_11na, reg,
2049 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U,
2051 regdomain_addchans(ci, &rd->bands_11na, reg,
2052 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D,
2056 if (!LIST_EMPTY(&rd->bands_11ng) && dc->dc_htcaps != 0) {
2057 regdomain_addchans(ci, &rd->bands_11ng, reg,
2058 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20,
2060 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) {
2061 regdomain_addchans(ci, &rd->bands_11ng, reg,
2062 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U,
2064 regdomain_addchans(ci, &rd->bands_11ng, reg,
2065 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D,
2069 qsort(ci->ic_chans, ci->ic_nchans, sizeof(ci->ic_chans[0]),
2072 memcpy(ci, &dc->dc_chaninfo,
2073 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo));
2077 list_countries(void)
2079 struct regdata *rdp = getregdata();
2080 const struct country *cp;
2081 const struct regdomain *dp;
2085 printf("\nCountry codes:\n");
2086 LIST_FOREACH(cp, &rdp->countries, next) {
2087 printf("%2s %-15.15s%s", cp->isoname,
2088 cp->name, ((i+1)%4) == 0 ? "\n" : " ");
2092 printf("\nRegulatory domains:\n");
2093 LIST_FOREACH(dp, &rdp->domains, next) {
2094 printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " ");
2101 defaultcountry(const struct regdomain *rd)
2103 struct regdata *rdp = getregdata();
2104 const struct country *cc;
2106 cc = lib80211_country_findbycc(rdp, rd->cc->code);
2108 errx(1, "internal error, ISO country code %d not "
2109 "defined for regdomain %s", rd->cc->code, rd->name);
2110 regdomain.country = cc->code;
2111 regdomain.isocc[0] = cc->isoname[0];
2112 regdomain.isocc[1] = cc->isoname[1];
2116 DECL_CMD_FUNC(set80211regdomain, val, d)
2118 struct regdata *rdp = getregdata();
2119 const struct regdomain *rd;
2121 rd = lib80211_regdomain_findbyname(rdp, val);
2124 long sku = strtol(val, &eptr, 0);
2127 rd = lib80211_regdomain_findbysku(rdp, sku);
2128 if (eptr == val || rd == NULL)
2129 errx(1, "unknown regdomain %s", val);
2132 regdomain.regdomain = rd->sku;
2133 if (regdomain.country == 0 && rd->cc != NULL) {
2135 * No country code setup and there's a default
2136 * one for this regdomain fill it in.
2140 callback_register(setregdomain_cb, ®domain);
2144 DECL_CMD_FUNC(set80211country, val, d)
2146 struct regdata *rdp = getregdata();
2147 const struct country *cc;
2149 cc = lib80211_country_findbyname(rdp, val);
2152 long code = strtol(val, &eptr, 0);
2155 cc = lib80211_country_findbycc(rdp, code);
2156 if (eptr == val || cc == NULL)
2157 errx(1, "unknown ISO country code %s", val);
2160 regdomain.regdomain = cc->rd->sku;
2161 regdomain.country = cc->code;
2162 regdomain.isocc[0] = cc->isoname[0];
2163 regdomain.isocc[1] = cc->isoname[1];
2164 callback_register(setregdomain_cb, ®domain);
2168 set80211location(const char *val, int d, int s, const struct afswtch *rafp)
2171 regdomain.location = d;
2172 callback_register(setregdomain_cb, ®domain);
2176 set80211ecm(const char *val, int d, int s, const struct afswtch *rafp)
2180 callback_register(setregdomain_cb, ®domain);
2196 if (spacer != '\t') {
2200 col = 8; /* 8-col tab */
2204 LINE_CHECK(const char *fmt, ...)
2211 n = vsnprintf(buf+1, sizeof(buf)-1, fmt, ap);
2224 getmaxrate(const uint8_t rates[15], uint8_t nrates)
2226 int i, maxrate = -1;
2228 for (i = 0; i < nrates; i++) {
2229 int rate = rates[i] & IEEE80211_RATE_VAL;
2237 getcaps(int capinfo)
2239 static char capstring[32];
2240 char *cp = capstring;
2242 if (capinfo & IEEE80211_CAPINFO_ESS)
2244 if (capinfo & IEEE80211_CAPINFO_IBSS)
2246 if (capinfo & IEEE80211_CAPINFO_CF_POLLABLE)
2248 if (capinfo & IEEE80211_CAPINFO_CF_POLLREQ)
2250 if (capinfo & IEEE80211_CAPINFO_PRIVACY)
2252 if (capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE)
2254 if (capinfo & IEEE80211_CAPINFO_PBCC)
2256 if (capinfo & IEEE80211_CAPINFO_CHNL_AGILITY)
2258 if (capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME)
2260 if (capinfo & IEEE80211_CAPINFO_RSN)
2262 if (capinfo & IEEE80211_CAPINFO_DSSSOFDM)
2271 static char flagstring[32];
2272 char *cp = flagstring;
2274 if (flags & IEEE80211_NODE_AUTH)
2276 if (flags & IEEE80211_NODE_QOS)
2278 if (flags & IEEE80211_NODE_ERP)
2280 if (flags & IEEE80211_NODE_PWR_MGT)
2282 if (flags & IEEE80211_NODE_HT) {
2284 if (flags & IEEE80211_NODE_HTCOMPAT)
2287 if (flags & IEEE80211_NODE_WPS)
2289 if (flags & IEEE80211_NODE_TSN)
2291 if (flags & IEEE80211_NODE_AMPDU_TX)
2293 if (flags & IEEE80211_NODE_AMPDU_RX)
2295 if (flags & IEEE80211_NODE_MIMO_PS) {
2297 if (flags & IEEE80211_NODE_MIMO_RTS)
2300 if (flags & IEEE80211_NODE_RIFS)
2307 printie(const char* tag, const uint8_t *ie, size_t ielen, int maxlen)
2311 maxlen -= strlen(tag)+2;
2312 if (2*ielen > maxlen)
2315 for (; ielen > 0; ie++, ielen--) {
2318 printf("%02x", *ie);
2326 #define LE_READ_2(p) \
2328 ((((const u_int8_t *)(p))[0] ) | \
2329 (((const u_int8_t *)(p))[1] << 8)))
2330 #define LE_READ_4(p) \
2332 ((((const u_int8_t *)(p))[0] ) | \
2333 (((const u_int8_t *)(p))[1] << 8) | \
2334 (((const u_int8_t *)(p))[2] << 16) | \
2335 (((const u_int8_t *)(p))[3] << 24)))
2338 * NB: The decoding routines assume a properly formatted ie
2339 * which should be safe as the kernel only retains them
2344 printwmeparam(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2346 #define MS(_v, _f) (((_v) & _f) >> _f##_S)
2347 static const char *acnames[] = { "BE", "BK", "VO", "VI" };
2348 const struct ieee80211_wme_param *wme =
2349 (const struct ieee80211_wme_param *) ie;
2355 printf("<qosinfo 0x%x", wme->param_qosInfo);
2356 ie += offsetof(struct ieee80211_wme_param, params_acParams);
2357 for (i = 0; i < WME_NUM_AC; i++) {
2358 const struct ieee80211_wme_acparams *ac =
2359 &wme->params_acParams[i];
2361 printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]"
2363 , MS(ac->acp_aci_aifsn, WME_PARAM_ACM) ? "acm " : ""
2364 , MS(ac->acp_aci_aifsn, WME_PARAM_AIFSN)
2365 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMIN)
2366 , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMAX)
2367 , LE_READ_2(&ac->acp_txop)
2375 printwmeinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2379 const struct ieee80211_wme_info *wme =
2380 (const struct ieee80211_wme_info *) ie;
2381 printf("<version 0x%x info 0x%x>",
2382 wme->wme_version, wme->wme_info);
2387 printhtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2391 const struct ieee80211_ie_htcap *htcap =
2392 (const struct ieee80211_ie_htcap *) ie;
2396 printf("<cap 0x%x param 0x%x",
2397 LE_READ_2(&htcap->hc_cap), htcap->hc_param);
2400 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2401 if (isset(htcap->hc_mcsset, i)) {
2402 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2403 if (isclr(htcap->hc_mcsset, j))
2407 printf("%s%u", sep, i);
2409 printf("%s%u-%u", sep, i, j);
2413 printf("] extcap 0x%x txbf 0x%x antenna 0x%x>",
2414 LE_READ_2(&htcap->hc_extcap),
2415 LE_READ_4(&htcap->hc_txbf),
2421 printhtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2425 const struct ieee80211_ie_htinfo *htinfo =
2426 (const struct ieee80211_ie_htinfo *) ie;
2430 printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel,
2431 htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3,
2432 LE_READ_2(&htinfo->hi_byte45));
2433 printf(" basicmcs[");
2435 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++)
2436 if (isset(htinfo->hi_basicmcsset, i)) {
2437 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++)
2438 if (isclr(htinfo->hi_basicmcsset, j))
2442 printf("%s%u", sep, i);
2444 printf("%s%u-%u", sep, i, j);
2453 printathie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2458 const struct ieee80211_ath_ie *ath =
2459 (const struct ieee80211_ath_ie *)ie;
2462 if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME)
2464 if (ath->ath_capability & ATHEROS_CAP_COMPRESSION)
2466 if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME)
2468 if (ath->ath_capability & ATHEROS_CAP_XR)
2470 if (ath->ath_capability & ATHEROS_CAP_AR)
2472 if (ath->ath_capability & ATHEROS_CAP_BURST)
2474 if (ath->ath_capability & ATHEROS_CAP_WME)
2476 if (ath->ath_capability & ATHEROS_CAP_BOOST)
2478 printf("0x%x>", LE_READ_2(ath->ath_defkeyix));
2483 wpa_cipher(const u_int8_t *sel)
2485 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2486 u_int32_t w = LE_READ_4(sel);
2489 case WPA_SEL(WPA_CSE_NULL):
2491 case WPA_SEL(WPA_CSE_WEP40):
2493 case WPA_SEL(WPA_CSE_WEP104):
2495 case WPA_SEL(WPA_CSE_TKIP):
2497 case WPA_SEL(WPA_CSE_CCMP):
2500 return "?"; /* NB: so 1<< is discarded */
2505 wpa_keymgmt(const u_int8_t *sel)
2507 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2508 u_int32_t w = LE_READ_4(sel);
2511 case WPA_SEL(WPA_ASE_8021X_UNSPEC):
2512 return "8021X-UNSPEC";
2513 case WPA_SEL(WPA_ASE_8021X_PSK):
2515 case WPA_SEL(WPA_ASE_NONE):
2523 printwpaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2525 u_int8_t len = ie[1];
2532 ie += 6, len -= 4; /* NB: len is payload only */
2534 printf("<v%u", LE_READ_2(ie));
2537 printf(" mc:%s", wpa_cipher(ie));
2540 /* unicast ciphers */
2544 for (; n > 0; n--) {
2545 printf("%s%s", sep, wpa_cipher(ie));
2550 /* key management algorithms */
2554 for (; n > 0; n--) {
2555 printf("%s%s", sep, wpa_keymgmt(ie));
2560 if (len > 2) /* optional capabilities */
2561 printf(", caps 0x%x", LE_READ_2(ie));
2567 rsn_cipher(const u_int8_t *sel)
2569 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
2570 u_int32_t w = LE_READ_4(sel);
2573 case RSN_SEL(RSN_CSE_NULL):
2575 case RSN_SEL(RSN_CSE_WEP40):
2577 case RSN_SEL(RSN_CSE_WEP104):
2579 case RSN_SEL(RSN_CSE_TKIP):
2581 case RSN_SEL(RSN_CSE_CCMP):
2583 case RSN_SEL(RSN_CSE_WRAP):
2591 rsn_keymgmt(const u_int8_t *sel)
2593 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
2594 u_int32_t w = LE_READ_4(sel);
2597 case RSN_SEL(RSN_ASE_8021X_UNSPEC):
2598 return "8021X-UNSPEC";
2599 case RSN_SEL(RSN_ASE_8021X_PSK):
2601 case RSN_SEL(RSN_ASE_NONE):
2609 printrsnie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2616 ie += 2, ielen -= 2;
2618 printf("<v%u", LE_READ_2(ie));
2619 ie += 2, ielen -= 2;
2621 printf(" mc:%s", rsn_cipher(ie));
2622 ie += 4, ielen -= 4;
2624 /* unicast ciphers */
2626 ie += 2, ielen -= 2;
2628 for (; n > 0; n--) {
2629 printf("%s%s", sep, rsn_cipher(ie));
2630 ie += 4, ielen -= 4;
2634 /* key management algorithms */
2636 ie += 2, ielen -= 2;
2638 for (; n > 0; n--) {
2639 printf("%s%s", sep, rsn_keymgmt(ie));
2640 ie += 4, ielen -= 4;
2644 if (ielen > 2) /* optional capabilities */
2645 printf(", caps 0x%x", LE_READ_2(ie));
2651 /* XXX move to a public include file */
2652 #define IEEE80211_WPS_DEV_PASS_ID 0x1012
2653 #define IEEE80211_WPS_SELECTED_REG 0x1041
2654 #define IEEE80211_WPS_SETUP_STATE 0x1044
2655 #define IEEE80211_WPS_UUID_E 0x1047
2656 #define IEEE80211_WPS_VERSION 0x104a
2658 #define BE_READ_2(p) \
2660 ((((const u_int8_t *)(p))[1] ) | \
2661 (((const u_int8_t *)(p))[0] << 8)))
2664 printwpsie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2666 #define N(a) (sizeof(a) / sizeof(a[0]))
2667 u_int8_t len = ie[1];
2671 static const char *dev_pass_id[] = {
2672 "D", /* Default (PIN) */
2673 "U", /* User-specified */
2674 "M", /* Machine-specified */
2676 "P", /* PushButton */
2677 "R" /* Registrar-specified */
2681 ie +=6, len -= 4; /* NB: len is payload only */
2683 /* WPS IE in Beacon and Probe Resp frames have different fields */
2686 uint16_t tlv_type = BE_READ_2(ie);
2687 uint16_t tlv_len = BE_READ_2(ie + 2);
2692 case IEEE80211_WPS_VERSION:
2693 printf("v:%d.%d", *ie >> 4, *ie & 0xf);
2695 case IEEE80211_WPS_SETUP_STATE:
2696 /* Only 1 and 2 are valid */
2697 if (*ie == 0 || *ie >= 3)
2700 printf(" st:%s", *ie == 1 ? "N" : "C");
2702 case IEEE80211_WPS_SELECTED_REG:
2703 printf(" sel:%s", *ie ? "T" : "F");
2705 case IEEE80211_WPS_DEV_PASS_ID:
2707 if (n < N(dev_pass_id))
2708 printf(" dpi:%s", dev_pass_id[n]);
2710 case IEEE80211_WPS_UUID_E:
2712 for (n = 0; n < (tlv_len - 1); n++)
2713 printf("%02x-", ie[n]);
2714 printf("%02x", ie[n]);
2717 ie += tlv_len, len -= tlv_len;
2725 printtdmaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2728 if (verbose && ielen >= sizeof(struct ieee80211_tdma_param)) {
2729 const struct ieee80211_tdma_param *tdma =
2730 (const struct ieee80211_tdma_param *) ie;
2733 printf("<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>",
2734 tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt,
2735 LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval,
2736 tdma->tdma_inuse[0]);
2741 * Copy the ssid string contents into buf, truncating to fit. If the
2742 * ssid is entirely printable then just copy intact. Otherwise convert
2743 * to hexadecimal. If the result is truncated then replace the last
2744 * three characters with "...".
2747 copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len)
2753 if (essid_len > bufsize)
2757 /* determine printable or not */
2758 for (i = 0, p = essid; i < maxlen; i++, p++) {
2759 if (*p < ' ' || *p > 0x7e)
2762 if (i != maxlen) { /* not printable, print as hex */
2765 strlcpy(buf, "0x", bufsize);
2768 for (i = 0; i < maxlen && bufsize >= 2; i++) {
2769 sprintf(&buf[2+2*i], "%02x", p[i]);
2773 memcpy(&buf[2+2*i-3], "...", 3);
2774 } else { /* printable, truncate as needed */
2775 memcpy(buf, essid, maxlen);
2776 if (maxlen != essid_len)
2777 memcpy(&buf[maxlen-3], "...", 3);
2783 printssid(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2785 char ssid[2*IEEE80211_NWID_LEN+1];
2787 printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid);
2791 printrates(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2798 for (i = 2; i < ielen; i++) {
2799 printf("%s%s%d", sep,
2800 ie[i] & IEEE80211_RATE_BASIC ? "B" : "",
2801 ie[i] & IEEE80211_RATE_VAL);
2808 printcountry(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen)
2810 const struct ieee80211_country_ie *cie =
2811 (const struct ieee80211_country_ie *) ie;
2812 int i, nbands, schan, nchan;
2814 printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]);
2815 nbands = (cie->len - 3) / sizeof(cie->band[0]);
2816 for (i = 0; i < nbands; i++) {
2817 schan = cie->band[i].schan;
2818 nchan = cie->band[i].nchan;
2820 printf(" %u-%u,%u", schan, schan + nchan-1,
2821 cie->band[i].maxtxpwr);
2823 printf(" %u,%u", schan, cie->band[i].maxtxpwr);
2828 /* unaligned little endian access */
2829 #define LE_READ_4(p) \
2831 ((((const u_int8_t *)(p))[0] ) | \
2832 (((const u_int8_t *)(p))[1] << 8) | \
2833 (((const u_int8_t *)(p))[2] << 16) | \
2834 (((const u_int8_t *)(p))[3] << 24)))
2837 iswpaoui(const u_int8_t *frm)
2839 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI);
2843 iswmeinfo(const u_int8_t *frm)
2845 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
2846 frm[6] == WME_INFO_OUI_SUBTYPE;
2850 iswmeparam(const u_int8_t *frm)
2852 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
2853 frm[6] == WME_PARAM_OUI_SUBTYPE;
2857 isatherosoui(const u_int8_t *frm)
2859 return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI);
2863 istdmaoui(const uint8_t *frm)
2865 return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI);
2869 iswpsoui(const uint8_t *frm)
2871 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPS_OUI_TYPE<<24)|WPA_OUI);
2878 case IEEE80211_ELEMID_FHPARMS: return " FHPARMS";
2879 case IEEE80211_ELEMID_CFPARMS: return " CFPARMS";
2880 case IEEE80211_ELEMID_TIM: return " TIM";
2881 case IEEE80211_ELEMID_IBSSPARMS:return " IBSSPARMS";
2882 case IEEE80211_ELEMID_CHALLENGE:return " CHALLENGE";
2883 case IEEE80211_ELEMID_PWRCNSTR: return " PWRCNSTR";
2884 case IEEE80211_ELEMID_PWRCAP: return " PWRCAP";
2885 case IEEE80211_ELEMID_TPCREQ: return " TPCREQ";
2886 case IEEE80211_ELEMID_TPCREP: return " TPCREP";
2887 case IEEE80211_ELEMID_SUPPCHAN: return " SUPPCHAN";
2888 case IEEE80211_ELEMID_CHANSWITCHANN:return " CSA";
2889 case IEEE80211_ELEMID_MEASREQ: return " MEASREQ";
2890 case IEEE80211_ELEMID_MEASREP: return " MEASREP";
2891 case IEEE80211_ELEMID_QUIET: return " QUIET";
2892 case IEEE80211_ELEMID_IBSSDFS: return " IBSSDFS";
2893 case IEEE80211_ELEMID_TPC: return " TPC";
2894 case IEEE80211_ELEMID_CCKM: return " CCKM";
2900 printies(const u_int8_t *vp, int ielen, int maxcols)
2904 case IEEE80211_ELEMID_SSID:
2906 printssid(" SSID", vp, 2+vp[1], maxcols);
2908 case IEEE80211_ELEMID_RATES:
2909 case IEEE80211_ELEMID_XRATES:
2911 printrates(vp[0] == IEEE80211_ELEMID_RATES ?
2912 " RATES" : " XRATES", vp, 2+vp[1], maxcols);
2914 case IEEE80211_ELEMID_DSPARMS:
2916 printf(" DSPARMS<%u>", vp[2]);
2918 case IEEE80211_ELEMID_COUNTRY:
2920 printcountry(" COUNTRY", vp, 2+vp[1], maxcols);
2922 case IEEE80211_ELEMID_ERP:
2924 printf(" ERP<0x%x>", vp[2]);
2926 case IEEE80211_ELEMID_VENDOR:
2928 printwpaie(" WPA", vp, 2+vp[1], maxcols);
2929 else if (iswmeinfo(vp))
2930 printwmeinfo(" WME", vp, 2+vp[1], maxcols);
2931 else if (iswmeparam(vp))
2932 printwmeparam(" WME", vp, 2+vp[1], maxcols);
2933 else if (isatherosoui(vp))
2934 printathie(" ATH", vp, 2+vp[1], maxcols);
2935 else if (iswpsoui(vp))
2936 printwpsie(" WPS", vp, 2+vp[1], maxcols);
2937 else if (istdmaoui(vp))
2938 printtdmaie(" TDMA", vp, 2+vp[1], maxcols);
2940 printie(" VEN", vp, 2+vp[1], maxcols);
2942 case IEEE80211_ELEMID_RSN:
2943 printrsnie(" RSN", vp, 2+vp[1], maxcols);
2945 case IEEE80211_ELEMID_HTCAP:
2946 printhtcap(" HTCAP", vp, 2+vp[1], maxcols);
2948 case IEEE80211_ELEMID_HTINFO:
2950 printhtinfo(" HTINFO", vp, 2+vp[1], maxcols);
2954 printie(iename(vp[0]), vp, 2+vp[1], maxcols);
2963 printmimo(const struct ieee80211_mimo_info *mi)
2965 /* NB: don't muddy display unless there's something to show */
2966 if (mi->rssi[0] != 0 || mi->rssi[1] != 0 || mi->rssi[2] != 0) {
2967 /* XXX ignore EVM for now */
2968 printf(" (rssi %d:%d:%d nf %d:%d:%d)",
2969 mi->rssi[0], mi->rssi[1], mi->rssi[2],
2970 mi->noise[0], mi->noise[1], mi->noise[2]);
2977 uint8_t buf[24*1024];
2978 char ssid[IEEE80211_NWID_LEN+1];
2982 if (get80211len(s, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0)
2983 errx(1, "unable to get scan results");
2984 if (len < sizeof(struct ieee80211req_scan_result))
2989 ssidmax = verbose ? IEEE80211_NWID_LEN : 14;
2990 printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n"
2991 , ssidmax, ssidmax, "SSID"
3001 const struct ieee80211req_scan_result *sr;
3004 sr = (const struct ieee80211req_scan_result *) cp;
3005 vp = cp + sr->isr_ie_off;
3006 printf("%-*.*s %s %3d %3dM %3d:%-3d %3d %-4.4s"
3008 , copy_essid(ssid, ssidmax, vp, sr->isr_ssid_len)
3010 , ether_ntoa((const struct ether_addr *) sr->isr_bssid)
3011 , ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags)
3012 , getmaxrate(sr->isr_rates, sr->isr_nrates)
3013 , (sr->isr_rssi/2)+sr->isr_noise, sr->isr_noise
3015 , getcaps(sr->isr_capinfo)
3017 printies(vp + sr->isr_ssid_len, sr->isr_ie_len, 24);
3019 cp += sr->isr_len, len -= sr->isr_len;
3020 } while (len >= sizeof(struct ieee80211req_scan_result));
3024 #include <net80211/ieee80211_freebsd.h>
3027 #include <net80211/ieee80211_netbsd.h>
3031 scan_and_wait(int s)
3033 struct ieee80211_scan_req sr;
3034 struct ieee80211req ireq;
3037 sroute = socket(PF_ROUTE, SOCK_RAW, 0);
3039 perror("socket(PF_ROUTE,SOCK_RAW)");
3042 (void) memset(&ireq, 0, sizeof(ireq));
3043 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
3044 ireq.i_type = IEEE80211_IOC_SCAN_REQ;
3046 memset(&sr, 0, sizeof(sr));
3047 sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE
3048 | IEEE80211_IOC_SCAN_NOPICK
3049 | IEEE80211_IOC_SCAN_ONCE;
3050 sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER;
3054 ireq.i_len = sizeof(sr);
3055 /* NB: only root can trigger a scan so ignore errors */
3056 if (ioctl(s, SIOCS80211, &ireq) >= 0) {
3058 struct if_announcemsghdr *ifan;
3059 struct rt_msghdr *rtm;
3062 if (read(sroute, buf, sizeof(buf)) < 0) {
3063 perror("read(PF_ROUTE)");
3066 rtm = (struct rt_msghdr *) buf;
3067 if (rtm->rtm_version != RTM_VERSION)
3069 ifan = (struct if_announcemsghdr *) rtm;
3070 } while (rtm->rtm_type != RTM_IEEE80211 ||
3071 ifan->ifan_what != RTM_IEEE80211_SCAN);
3077 DECL_CMD_FUNC(set80211scan, val, d)
3083 static enum ieee80211_opmode get80211opmode(int s);
3086 gettxseq(const struct ieee80211req_sta_info *si)
3088 #define IEEE80211_NODE_QOS 0x0002 /* QoS enabled */
3092 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3093 return si->isi_txseqs[0];
3094 /* XXX not right but usually what folks want */
3096 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3097 if (si->isi_txseqs[i] > txseq)
3098 txseq = si->isi_txseqs[i];
3100 #undef IEEE80211_NODE_QOS
3104 getrxseq(const struct ieee80211req_sta_info *si)
3106 #define IEEE80211_NODE_QOS 0x0002 /* QoS enabled */
3110 if ((si->isi_state & IEEE80211_NODE_QOS) == 0)
3111 return si->isi_rxseqs[0];
3112 /* XXX not right but usually what folks want */
3114 for (i = 0; i < IEEE80211_TID_SIZE; i++)
3115 if (si->isi_rxseqs[i] > rxseq)
3116 rxseq = si->isi_rxseqs[i];
3118 #undef IEEE80211_NODE_QOS
3122 list_stations(int s)
3125 struct ieee80211req_sta_req req;
3126 uint8_t buf[24*1024];
3128 enum ieee80211_opmode opmode = get80211opmode(s);
3132 /* broadcast address =>'s get all stations */
3133 (void) memset(u.req.is_u.macaddr, 0xff, IEEE80211_ADDR_LEN);
3134 if (opmode == IEEE80211_M_STA) {
3136 * Get information about the associated AP.
3138 (void) get80211(s, IEEE80211_IOC_BSSID,
3139 u.req.is_u.macaddr, IEEE80211_ADDR_LEN);
3141 if (get80211len(s, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0)
3142 errx(1, "unable to get station information");
3143 if (len < sizeof(struct ieee80211req_sta_info))
3148 printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %4s\n"
3160 cp = (const uint8_t *) u.req.info;
3162 const struct ieee80211req_sta_info *si;
3164 si = (const struct ieee80211req_sta_info *) cp;
3165 if (si->isi_len < sizeof(*si))
3167 printf("%s %4u %4d %3dM %3.1f %4d %6d %6d %-4.4s %-4.4s"
3168 , ether_ntoa((const struct ether_addr*) si->isi_macaddr)
3169 , IEEE80211_AID(si->isi_associd)
3170 , ieee80211_mhz2ieee(si->isi_freq, si->isi_flags)
3176 , getcaps(si->isi_capinfo)
3177 , getflags(si->isi_state)
3179 printies(cp + si->isi_ie_off, si->isi_ie_len, 24);
3180 printmimo(&si->isi_mimo);
3182 cp += si->isi_len, len -= si->isi_len;
3183 } while (len >= sizeof(struct ieee80211req_sta_info));
3187 get_chaninfo(const struct ieee80211_channel *c, int precise,
3188 char buf[], size_t bsize)
3191 if (IEEE80211_IS_CHAN_FHSS(c))
3192 strlcat(buf, " FHSS", bsize);
3193 if (IEEE80211_IS_CHAN_A(c))
3194 strlcat(buf, " 11a", bsize);
3195 else if (IEEE80211_IS_CHAN_ANYG(c))
3196 strlcat(buf, " 11g", bsize);
3197 else if (IEEE80211_IS_CHAN_B(c))
3198 strlcat(buf, " 11b", bsize);
3199 if (IEEE80211_IS_CHAN_HALF(c))
3200 strlcat(buf, "/10Mhz", bsize);
3201 if (IEEE80211_IS_CHAN_QUARTER(c))
3202 strlcat(buf, "/5Mhz", bsize);
3203 if (IEEE80211_IS_CHAN_TURBO(c))
3204 strlcat(buf, " Turbo", bsize);
3206 if (IEEE80211_IS_CHAN_HT20(c))
3207 strlcat(buf, " ht/20", bsize);
3208 else if (IEEE80211_IS_CHAN_HT40D(c))
3209 strlcat(buf, " ht/40-", bsize);
3210 else if (IEEE80211_IS_CHAN_HT40U(c))
3211 strlcat(buf, " ht/40+", bsize);
3213 if (IEEE80211_IS_CHAN_HT(c))
3214 strlcat(buf, " ht", bsize);
3220 print_chaninfo(const struct ieee80211_channel *c, int verb)
3224 printf("Channel %3u : %u%c Mhz%-14.14s",
3225 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq,
3226 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ',
3227 get_chaninfo(c, verb, buf, sizeof(buf)));
3231 chanpref(const struct ieee80211_channel *c)
3233 if (IEEE80211_IS_CHAN_HT40(c))
3235 if (IEEE80211_IS_CHAN_HT20(c))
3237 if (IEEE80211_IS_CHAN_HALF(c))
3239 if (IEEE80211_IS_CHAN_QUARTER(c))
3241 if (IEEE80211_IS_CHAN_TURBO(c))
3243 if (IEEE80211_IS_CHAN_A(c))
3245 if (IEEE80211_IS_CHAN_G(c))
3247 if (IEEE80211_IS_CHAN_B(c))
3249 if (IEEE80211_IS_CHAN_PUREG(c))
3255 print_channels(int s, const struct ieee80211req_chaninfo *chans,
3256 int allchans, int verb)
3258 struct ieee80211req_chaninfo *achans;
3259 uint8_t reported[IEEE80211_CHAN_BYTES];
3260 const struct ieee80211_channel *c;
3263 achans = malloc(IEEE80211_CHANINFO_SPACE(chans));
3265 errx(1, "no space for active channel list");
3266 achans->ic_nchans = 0;
3267 memset(reported, 0, sizeof(reported));
3269 struct ieee80211req_chanlist active;
3271 if (get80211(s, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0)
3272 errx(1, "unable to get active channel list");
3273 for (i = 0; i < chans->ic_nchans; i++) {
3274 c = &chans->ic_chans[i];
3275 if (!isset(active.ic_channels, c->ic_ieee))
3278 * Suppress compatible duplicates unless
3279 * verbose. The kernel gives us it's
3280 * complete channel list which has separate
3281 * entries for 11g/11b and 11a/turbo.
3283 if (isset(reported, c->ic_ieee) && !verb) {
3284 /* XXX we assume duplicates are adjacent */
3285 achans->ic_chans[achans->ic_nchans-1] = *c;
3287 achans->ic_chans[achans->ic_nchans++] = *c;
3288 setbit(reported, c->ic_ieee);
3292 for (i = 0; i < chans->ic_nchans; i++) {
3293 c = &chans->ic_chans[i];
3294 /* suppress duplicates as above */
3295 if (isset(reported, c->ic_ieee) && !verb) {
3296 /* XXX we assume duplicates are adjacent */
3297 struct ieee80211_channel *a =
3298 &achans->ic_chans[achans->ic_nchans-1];
3299 if (chanpref(c) > chanpref(a))
3302 achans->ic_chans[achans->ic_nchans++] = *c;
3303 setbit(reported, c->ic_ieee);
3307 half = achans->ic_nchans / 2;
3308 if (achans->ic_nchans % 2)
3311 for (i = 0; i < achans->ic_nchans / 2; i++) {
3312 print_chaninfo(&achans->ic_chans[i], verb);
3313 print_chaninfo(&achans->ic_chans[half+i], verb);
3316 if (achans->ic_nchans % 2) {
3317 print_chaninfo(&achans->ic_chans[i], verb);
3324 list_channels(int s, int allchans)
3327 print_channels(s, chaninfo, allchans, verbose);
3331 print_txpow(const struct ieee80211_channel *c)
3333 printf("Channel %3u : %u Mhz %3.1f reg %2d ",
3334 c->ic_ieee, c->ic_freq,
3335 c->ic_maxpower/2., c->ic_maxregpower);
3339 print_txpow_verbose(const struct ieee80211_channel *c)
3341 print_chaninfo(c, 1);
3342 printf("min %4.1f dBm max %3.1f dBm reg %2d dBm",
3343 c->ic_minpower/2., c->ic_maxpower/2., c->ic_maxregpower);
3344 /* indicate where regulatory cap limits power use */
3345 if (c->ic_maxpower > 2*c->ic_maxregpower)
3352 struct ieee80211req_chaninfo *achans;
3353 uint8_t reported[IEEE80211_CHAN_BYTES];
3354 struct ieee80211_channel *c, *prev;
3358 achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo));
3360 errx(1, "no space for active channel list");
3361 achans->ic_nchans = 0;
3362 memset(reported, 0, sizeof(reported));
3363 for (i = 0; i < chaninfo->ic_nchans; i++) {
3364 c = &chaninfo->ic_chans[i];
3365 /* suppress duplicates as above */
3366 if (isset(reported, c->ic_ieee) && !verbose) {
3367 /* XXX we assume duplicates are adjacent */
3368 prev = &achans->ic_chans[achans->ic_nchans-1];
3369 /* display highest power on channel */
3370 if (c->ic_maxpower > prev->ic_maxpower)
3373 achans->ic_chans[achans->ic_nchans++] = *c;
3374 setbit(reported, c->ic_ieee);
3378 half = achans->ic_nchans / 2;
3379 if (achans->ic_nchans % 2)
3382 for (i = 0; i < achans->ic_nchans / 2; i++) {
3383 print_txpow(&achans->ic_chans[i]);
3384 print_txpow(&achans->ic_chans[half+i]);
3387 if (achans->ic_nchans % 2) {
3388 print_txpow(&achans->ic_chans[i]);
3392 for (i = 0; i < achans->ic_nchans; i++) {
3393 print_txpow_verbose(&achans->ic_chans[i]);
3405 #define IEEE80211_C_BITS \
3406 "\20\1STA\7FF\10TURBOP\11IBSS\12PMGT" \
3407 "\13HOSTAP\14AHDEMO\15SWRETRY\16TXPMGT\17SHSLOT\20SHPREAMBLE" \
3408 "\21MONITOR\22DFS\30WPA1\31WPA2\32BURST\33WME\34WDS\36BGSCAN" \
3412 list_capabilities(int s)
3414 struct ieee80211_devcaps_req *dc;
3417 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN));
3419 dc = malloc(IEEE80211_DEVCAPS_SIZE(1));
3421 errx(1, "no space for device capabilities");
3422 dc->dc_chaninfo.ic_nchans = verbose ? MAXCHAN : 1;
3424 printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS);
3425 if (dc->dc_cryptocaps != 0 || verbose) {
3427 printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS);
3429 if (dc->dc_htcaps != 0 || verbose) {
3431 printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS);
3435 chaninfo = &dc->dc_chaninfo; /* XXX */
3436 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, verbose);
3442 get80211wme(int s, int param, int ac, int *val)
3444 struct ieee80211req ireq;
3446 (void) memset(&ireq, 0, sizeof(ireq));
3447 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
3448 ireq.i_type = param;
3450 if (ioctl(s, SIOCG80211, &ireq) < 0) {
3451 warn("cannot get WME parameter %d, ac %d%s",
3452 param, ac & IEEE80211_WMEPARAM_VAL,
3453 ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : "");
3461 list_wme_aci(int s, const char *tag, int ac)
3465 printf("\t%s", tag);
3467 /* show WME BSS parameters */
3468 if (get80211wme(s, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1)
3469 printf(" cwmin %2u", val);
3470 if (get80211wme(s, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1)
3471 printf(" cwmax %2u", val);
3472 if (get80211wme(s, IEEE80211_IOC_WME_AIFS, ac, &val) != -1)
3473 printf(" aifs %2u", val);
3474 if (get80211wme(s, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1)
3475 printf(" txopLimit %3u", val);
3476 if (get80211wme(s, IEEE80211_IOC_WME_ACM, ac, &val) != -1) {
3483 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
3484 if (get80211wme(s, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) {
3497 static const char *acnames[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
3501 /* display both BSS and local settings */
3502 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) {
3504 if (ac & IEEE80211_WMEPARAM_BSS)
3505 list_wme_aci(s, " ", ac);
3507 list_wme_aci(s, acnames[ac], ac);
3508 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) {
3509 ac |= IEEE80211_WMEPARAM_BSS;
3512 ac &= ~IEEE80211_WMEPARAM_BSS;
3515 /* display only channel settings */
3516 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++)
3517 list_wme_aci(s, acnames[ac], ac);
3524 const struct ieee80211_roamparam *rp;
3528 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
3529 rp = &roamparams.params[mode];
3530 if (rp->rssi == 0 && rp->rate == 0)
3532 if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) {
3534 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm MCS %2u ",
3535 modename[mode], rp->rssi/2,
3536 rp->rate &~ IEEE80211_RATE_MCS);
3538 LINE_CHECK("roam:%-7.7s rssi %4udBm MCS %2u ",
3539 modename[mode], rp->rssi/2,
3540 rp->rate &~ IEEE80211_RATE_MCS);
3543 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s",
3544 modename[mode], rp->rssi/2, rp->rate/2);
3546 LINE_CHECK("roam:%-7.7s rssi %4udBm rate %2u Mb/s",
3547 modename[mode], rp->rssi/2, rp->rate/2);
3553 list_txparams(int s)
3555 const struct ieee80211_txparam *tp;
3559 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) {
3560 tp = &txparams.params[mode];
3561 if (tp->mgmtrate == 0 && tp->mcastrate == 0)
3563 if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) {
3564 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
3565 LINE_CHECK("%-7.7s ucast NONE mgmt %2u MCS "
3566 "mcast %2u MCS maxretry %u",
3568 tp->mgmtrate &~ IEEE80211_RATE_MCS,
3569 tp->mcastrate &~ IEEE80211_RATE_MCS,
3572 LINE_CHECK("%-7.7s ucast %2u MCS mgmt %2u MCS "
3573 "mcast %2u MCS maxretry %u",
3575 tp->ucastrate &~ IEEE80211_RATE_MCS,
3576 tp->mgmtrate &~ IEEE80211_RATE_MCS,
3577 tp->mcastrate &~ IEEE80211_RATE_MCS,
3580 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE)
3581 LINE_CHECK("%-7.7s ucast NONE mgmt %2u Mb/s "
3582 "mcast %2u Mb/s maxretry %u",
3585 tp->mcastrate/2, tp->maxretry);
3587 LINE_CHECK("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s "
3588 "mcast %2u Mb/s maxretry %u",
3590 tp->ucastrate/2, tp->mgmtrate/2,
3591 tp->mcastrate/2, tp->maxretry);
3597 printpolicy(int policy)
3600 case IEEE80211_MACCMD_POLICY_OPEN:
3601 printf("policy: open\n");
3603 case IEEE80211_MACCMD_POLICY_ALLOW:
3604 printf("policy: allow\n");
3606 case IEEE80211_MACCMD_POLICY_DENY:
3607 printf("policy: deny\n");
3609 case IEEE80211_MACCMD_POLICY_RADIUS:
3610 printf("policy: radius\n");
3613 printf("policy: unknown (%u)\n", policy);
3621 struct ieee80211req ireq;
3622 struct ieee80211req_maclist *acllist;
3623 int i, nacls, policy, len;
3627 (void) memset(&ireq, 0, sizeof(ireq));
3628 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); /* XXX ?? */
3629 ireq.i_type = IEEE80211_IOC_MACCMD;
3630 ireq.i_val = IEEE80211_MACCMD_POLICY;
3631 if (ioctl(s, SIOCG80211, &ireq) < 0) {
3632 if (errno == EINVAL) {
3633 printf("No acl policy loaded\n");
3636 err(1, "unable to get mac policy");
3638 policy = ireq.i_val;
3639 if (policy == IEEE80211_MACCMD_POLICY_OPEN) {
3641 } else if (policy == IEEE80211_MACCMD_POLICY_ALLOW) {
3643 } else if (policy == IEEE80211_MACCMD_POLICY_DENY) {
3645 } else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) {
3646 c = 'r'; /* NB: should never have entries */
3648 printf("policy: unknown (%u)\n", policy);
3651 if (verbose || c == '?')
3652 printpolicy(policy);
3654 ireq.i_val = IEEE80211_MACCMD_LIST;
3656 if (ioctl(s, SIOCG80211, &ireq) < 0)
3657 err(1, "unable to get mac acl list size");
3658 if (ireq.i_len == 0) { /* NB: no acls */
3659 if (!(verbose || c == '?'))
3660 printpolicy(policy);
3667 err(1, "out of memory for acl list");
3670 if (ioctl(s, SIOCG80211, &ireq) < 0)
3671 err(1, "unable to get mac acl list");
3672 nacls = len / sizeof(*acllist);
3673 acllist = (struct ieee80211req_maclist *) data;
3674 for (i = 0; i < nacls; i++)
3675 printf("%c%s\n", c, ether_ntoa(
3676 (const struct ether_addr *) acllist[i].ml_macaddr));
3681 print_regdomain(const struct ieee80211_regdomain *reg, int verb)
3683 if ((reg->regdomain != 0 &&
3684 reg->regdomain != reg->country) || verb) {
3685 const struct regdomain *rd =
3686 lib80211_regdomain_findbysku(getregdata(), reg->regdomain);
3688 LINE_CHECK("regdomain %d", reg->regdomain);
3690 LINE_CHECK("regdomain %s", rd->name);
3692 if (reg->country != 0 || verb) {
3693 const struct country *cc =
3694 lib80211_country_findbycc(getregdata(), reg->country);
3696 LINE_CHECK("country %d", reg->country);
3698 LINE_CHECK("country %s", cc->isoname);
3700 if (reg->location == 'I')
3701 LINE_CHECK("indoor");
3702 else if (reg->location == 'O')
3703 LINE_CHECK("outdoor");
3705 LINE_CHECK("anywhere");
3713 list_regdomain(int s, int channelsalso)
3719 print_regdomain(®domain, 1);
3721 print_channels(s, chaninfo, 1/*allchans*/, 1/*verbose*/);
3723 print_regdomain(®domain, verbose);
3727 DECL_CMD_FUNC(set80211list, arg, d)
3729 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
3733 if (iseq(arg, "sta"))
3735 else if (iseq(arg, "scan") || iseq(arg, "ap"))
3737 else if (iseq(arg, "chan") || iseq(arg, "freq"))
3738 list_channels(s, 1);
3739 else if (iseq(arg, "active"))
3740 list_channels(s, 0);
3741 else if (iseq(arg, "keys"))
3743 else if (iseq(arg, "caps"))
3744 list_capabilities(s);
3745 else if (iseq(arg, "wme") || iseq(arg, "wmm"))
3747 else if (iseq(arg, "mac"))
3749 else if (iseq(arg, "txpow"))
3751 else if (iseq(arg, "roam"))
3753 else if (iseq(arg, "txparam") || iseq(arg, "txparm"))
3755 else if (iseq(arg, "regdomain"))
3756 list_regdomain(s, 1);
3757 else if (iseq(arg, "countries"))
3760 errx(1, "Don't know how to list %s for %s", arg, name);
3765 static enum ieee80211_opmode
3766 get80211opmode(int s)
3768 struct ifmediareq ifmr;
3770 (void) memset(&ifmr, 0, sizeof(ifmr));
3771 (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
3773 if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) {
3774 if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) {
3775 if (ifmr.ifm_current & IFM_FLAG0)
3776 return IEEE80211_M_AHDEMO;
3778 return IEEE80211_M_IBSS;
3780 if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP)
3781 return IEEE80211_M_HOSTAP;
3782 if (ifmr.ifm_current & IFM_IEEE80211_MONITOR)
3783 return IEEE80211_M_MONITOR;
3785 return IEEE80211_M_STA;
3790 printcipher(int s, struct ieee80211req *ireq, int keylenop)
3792 switch (ireq->i_val) {
3793 case IEEE80211_CIPHER_WEP:
3794 ireq->i_type = keylenop;
3795 if (ioctl(s, SIOCG80211, ireq) != -1)
3797 ireq->i_len <= 5 ? "40" :
3798 ireq->i_len <= 13 ? "104" : "128");
3802 case IEEE80211_CIPHER_TKIP:
3805 case IEEE80211_CIPHER_AES_OCB:
3808 case IEEE80211_CIPHER_AES_CCM:
3811 case IEEE80211_CIPHER_CKIP:
3814 case IEEE80211_CIPHER_NONE:
3818 printf("UNKNOWN (0x%x)", ireq->i_val);
3825 printkey(const struct ieee80211req_key *ik)
3827 static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE];
3828 int keylen = ik->ik_keylen;
3831 printcontents = printkeys &&
3832 (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose);
3835 switch (ik->ik_type) {
3836 case IEEE80211_CIPHER_WEP:
3838 LINE_CHECK("wepkey %u:%s", ik->ik_keyix+1,
3839 keylen <= 5 ? "40-bit" :
3840 keylen <= 13 ? "104-bit" : "128-bit");
3842 case IEEE80211_CIPHER_TKIP:
3844 keylen -= 128/8; /* ignore MIC for now */
3845 LINE_CHECK("TKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
3847 case IEEE80211_CIPHER_AES_OCB:
3848 LINE_CHECK("AES-OCB %u:%u-bit", ik->ik_keyix+1, 8*keylen);
3850 case IEEE80211_CIPHER_AES_CCM:
3851 LINE_CHECK("AES-CCM %u:%u-bit", ik->ik_keyix+1, 8*keylen);
3853 case IEEE80211_CIPHER_CKIP:
3854 LINE_CHECK("CKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen);
3856 case IEEE80211_CIPHER_NONE:
3857 LINE_CHECK("NULL %u:%u-bit", ik->ik_keyix+1, 8*keylen);
3860 LINE_CHECK("UNKNOWN (0x%x) %u:%u-bit",
3861 ik->ik_type, ik->ik_keyix+1, 8*keylen);
3864 if (printcontents) {
3868 for (i = 0; i < keylen; i++)
3869 printf("%02x", ik->ik_keydata[i]);
3871 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
3872 (ik->ik_keyrsc != 0 || verbose))
3873 printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc);
3874 if (ik->ik_type != IEEE80211_CIPHER_WEP &&
3875 (ik->ik_keytsc != 0 || verbose))
3876 printf(" tsc %ju", (uintmax_t)ik->ik_keytsc);
3877 if (ik->ik_flags != 0 && verbose) {
3878 const char *sep = " ";
3880 if (ik->ik_flags & IEEE80211_KEY_XMIT)
3881 printf("%stx", sep), sep = "+";
3882 if (ik->ik_flags & IEEE80211_KEY_RECV)
3883 printf("%srx", sep), sep = "+";
3884 if (ik->ik_flags & IEEE80211_KEY_DEFAULT)
3885 printf("%sdef", sep), sep = "+";
3892 printrate(const char *tag, int v, int defrate, int defmcs)
3894 if ((v & IEEE80211_RATE_MCS) == 0) {
3897 LINE_CHECK("%s %d.5", tag, v/2);
3899 LINE_CHECK("%s %d", tag, v/2);
3903 LINE_CHECK("%s %d", tag, v &~ 0x80);
3908 getssid(int s, int ix, void *data, size_t len, int *plen)
3910 struct ieee80211req ireq;
3912 (void) memset(&ireq, 0, sizeof(ireq));
3913 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
3914 ireq.i_type = IEEE80211_IOC_SSID;
3918 if (ioctl(s, SIOCG80211, &ireq) < 0)
3925 ieee80211_status(int s)
3927 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
3928 enum ieee80211_opmode opmode = get80211opmode(s);
3929 int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode;
3931 const struct ieee80211_channel *c;
3932 const struct ieee80211_roamparam *rp;
3933 const struct ieee80211_txparam *tp;
3935 if (getssid(s, -1, data, sizeof(data), &len) < 0) {
3936 /* If we can't get the SSID, this isn't an 802.11 device. */
3941 * Invalidate cached state so printing status for multiple
3942 * if's doesn't reuse the first interfaces' cached state.
3950 if (get80211val(s, IEEE80211_IOC_NUMSSIDS, &num) < 0)
3954 for (i = 0; i < num; i++) {
3955 if (getssid(s, i, data, sizeof(data), &len) >= 0 && len > 0) {
3956 printf(" %d:", i + 1);
3957 print_string(data, len);
3961 print_string(data, len);
3964 if (c->ic_freq != IEEE80211_CHAN_ANY) {
3966 printf(" channel %d (%u Mhz%s)", c->ic_ieee, c->ic_freq,
3967 get_chaninfo(c, 1, buf, sizeof(buf)));
3969 printf(" channel UNDEF");
3971 if (get80211(s, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 &&
3972 (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose))
3973 printf(" bssid %s", ether_ntoa((struct ether_addr *)data));
3975 if (get80211len(s, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) {
3976 printf("\n\tstationname ");
3977 print_string(data, len);
3980 spacer = ' '; /* force first break */
3983 list_regdomain(s, 0);
3986 if (get80211val(s, IEEE80211_IOC_AUTHMODE, &val) != -1) {
3988 case IEEE80211_AUTH_NONE:
3989 LINE_CHECK("authmode NONE");
3991 case IEEE80211_AUTH_OPEN:
3992 LINE_CHECK("authmode OPEN");
3994 case IEEE80211_AUTH_SHARED:
3995 LINE_CHECK("authmode SHARED");
3997 case IEEE80211_AUTH_8021X:
3998 LINE_CHECK("authmode 802.1x");
4000 case IEEE80211_AUTH_WPA:
4001 if (get80211val(s, IEEE80211_IOC_WPA, &wpa) < 0)
4002 wpa = 1; /* default to WPA1 */
4005 LINE_CHECK("authmode WPA2/802.11i");
4008 LINE_CHECK("authmode WPA1+WPA2/802.11i");
4011 LINE_CHECK("authmode WPA");
4015 case IEEE80211_AUTH_AUTO:
4016 LINE_CHECK("authmode AUTO");
4019 LINE_CHECK("authmode UNKNOWN (0x%x)", val);
4024 if (wpa || verbose) {
4025 if (get80211val(s, IEEE80211_IOC_WPS, &val) != -1) {
4031 if (get80211val(s, IEEE80211_IOC_TSN, &val) != -1) {
4037 if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) {
4039 LINE_CHECK("countermeasures");
4041 LINE_CHECK("-countermeasures");
4044 /* XXX not interesting with WPA done in user space */
4045 ireq.i_type = IEEE80211_IOC_KEYMGTALGS;
4046 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4049 ireq.i_type = IEEE80211_IOC_MCASTCIPHER;
4050 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4051 LINE_CHECK("mcastcipher ");
4052 printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN);
4056 ireq.i_type = IEEE80211_IOC_UCASTCIPHER;
4057 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4058 LINE_CHECK("ucastcipher ");
4059 printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN);
4063 ireq.i_type = IEEE80211_IOC_RSNCAPS;
4064 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4065 LINE_CHECK("RSN caps 0x%x", ireq.i_val);
4070 ireq.i_type = IEEE80211_IOC_UCASTCIPHERS;
4071 if (ioctl(s, SIOCG80211, &ireq) != -1) {
4076 if (get80211val(s, IEEE80211_IOC_WEP, &wepmode) != -1 &&
4077 wepmode != IEEE80211_WEP_NOSUP) {
4081 case IEEE80211_WEP_OFF:
4082 LINE_CHECK("privacy OFF");
4084 case IEEE80211_WEP_ON:
4085 LINE_CHECK("privacy ON");
4087 case IEEE80211_WEP_MIXED:
4088 LINE_CHECK("privacy MIXED");
4091 LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode);
4096 * If we get here then we've got WEP support so we need
4097 * to print WEP status.
4100 if (get80211val(s, IEEE80211_IOC_WEPTXKEY, &val) < 0) {
4101 warn("WEP support, but no tx key!");
4105 LINE_CHECK("deftxkey %d", val+1);
4106 else if (wepmode != IEEE80211_WEP_OFF || verbose)
4107 LINE_CHECK("deftxkey UNDEF");
4109 if (get80211val(s, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) {
4110 warn("WEP support, but no NUMWEPKEYS support!");
4115 for (i = 0; i < num; i++) {
4116 struct ieee80211req_key ik;
4118 memset(&ik, 0, sizeof(ik));
4120 if (get80211(s, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) {
4121 warn("WEP support, but can get keys!");
4124 if (ik.ik_keylen != 0) {
4135 if (get80211val(s, IEEE80211_IOC_POWERSAVE, &val) != -1 &&
4136 val != IEEE80211_POWERSAVE_NOSUP ) {
4137 if (val != IEEE80211_POWERSAVE_OFF || verbose) {
4139 case IEEE80211_POWERSAVE_OFF:
4140 LINE_CHECK("powersavemode OFF");
4142 case IEEE80211_POWERSAVE_CAM:
4143 LINE_CHECK("powersavemode CAM");
4145 case IEEE80211_POWERSAVE_PSP:
4146 LINE_CHECK("powersavemode PSP");
4148 case IEEE80211_POWERSAVE_PSP_CAM:
4149 LINE_CHECK("powersavemode PSP-CAM");
4152 if (get80211val(s, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1)
4153 LINE_CHECK("powersavesleep %d", val);
4157 if (get80211val(s, IEEE80211_IOC_TXPOWER, &val) != -1) {
4159 LINE_CHECK("txpower %d.5", val/2);
4161 LINE_CHECK("txpower %d", val/2);
4164 if (get80211val(s, IEEE80211_IOC_TXPOWMAX, &val) != -1)
4165 LINE_CHECK("txpowmax %.1f", val/2.);
4168 if (get80211val(s, IEEE80211_IOC_DOTD, &val) != -1) {
4172 LINE_CHECK("-dotd");
4175 if (get80211val(s, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) {
4176 if (val != IEEE80211_RTS_MAX || verbose)
4177 LINE_CHECK("rtsthreshold %d", val);
4180 if (get80211val(s, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) {
4181 if (val != IEEE80211_FRAG_MAX || verbose)
4182 LINE_CHECK("fragthreshold %d", val);
4184 if (opmode == IEEE80211_M_STA || verbose) {
4185 if (get80211val(s, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) {
4186 if (val != IEEE80211_HWBMISS_MAX || verbose)
4187 LINE_CHECK("bmiss %d", val);
4193 tp = &txparams.params[chan2mode(c)];
4194 printrate("ucastrate", tp->ucastrate,
4195 IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE);
4196 printrate("mcastrate", tp->mcastrate, 2*1,
4197 IEEE80211_RATE_MCS|0);
4198 printrate("mgmtrate", tp->mgmtrate, 2*1,
4199 IEEE80211_RATE_MCS|0);
4200 if (tp->maxretry != 6) /* XXX */
4201 LINE_CHECK("maxretry %d", tp->maxretry);
4207 bgscaninterval = -1;
4208 (void) get80211val(s, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval);
4210 if (get80211val(s, IEEE80211_IOC_SCANVALID, &val) != -1) {
4211 if (val != bgscaninterval || verbose)
4212 LINE_CHECK("scanvalid %u", val);
4216 if (get80211val(s, IEEE80211_IOC_BGSCAN, &bgscan) != -1) {
4218 LINE_CHECK("bgscan");
4220 LINE_CHECK("-bgscan");
4222 if (bgscan || verbose) {
4223 if (bgscaninterval != -1)
4224 LINE_CHECK("bgscanintvl %u", bgscaninterval);
4225 if (get80211val(s, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1)
4226 LINE_CHECK("bgscanidle %u", val);
4229 rp = &roamparams.params[chan2mode(c)];
4231 LINE_CHECK("roam:rssi %u.5", rp->rssi/2);
4233 LINE_CHECK("roam:rssi %u", rp->rssi/2);
4234 LINE_CHECK("roam:rate %u", rp->rate/2);
4241 if (IEEE80211_IS_CHAN_ANYG(c) || verbose) {
4242 if (get80211val(s, IEEE80211_IOC_PUREG, &val) != -1) {
4244 LINE_CHECK("pureg");
4246 LINE_CHECK("-pureg");
4248 if (get80211val(s, IEEE80211_IOC_PROTMODE, &val) != -1) {
4250 case IEEE80211_PROTMODE_OFF:
4251 LINE_CHECK("protmode OFF");
4253 case IEEE80211_PROTMODE_CTS:
4254 LINE_CHECK("protmode CTS");
4256 case IEEE80211_PROTMODE_RTSCTS:
4257 LINE_CHECK("protmode RTSCTS");
4260 LINE_CHECK("protmode UNKNOWN (0x%x)", val);
4266 if (IEEE80211_IS_CHAN_HT(c) || verbose) {
4268 switch (htconf & 3) {
4281 if (get80211val(s, IEEE80211_IOC_HTCOMPAT, &val) != -1) {
4283 LINE_CHECK("-htcompat");
4285 LINE_CHECK("htcompat");
4287 if (get80211val(s, IEEE80211_IOC_AMPDU, &val) != -1) {
4290 LINE_CHECK("-ampdu");
4293 LINE_CHECK("ampdutx -ampdurx");
4296 LINE_CHECK("-ampdutx ampdurx");
4300 LINE_CHECK("ampdu");
4304 if (get80211val(s, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) {
4306 case IEEE80211_HTCAP_MAXRXAMPDU_8K:
4307 LINE_CHECK("ampdulimit 8k");
4309 case IEEE80211_HTCAP_MAXRXAMPDU_16K:
4310 LINE_CHECK("ampdulimit 16k");
4312 case IEEE80211_HTCAP_MAXRXAMPDU_32K:
4313 LINE_CHECK("ampdulimit 32k");
4315 case IEEE80211_HTCAP_MAXRXAMPDU_64K:
4316 LINE_CHECK("ampdulimit 64k");
4320 if (get80211val(s, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) {
4322 case IEEE80211_HTCAP_MPDUDENSITY_NA:
4324 LINE_CHECK("ampdudensity NA");
4326 case IEEE80211_HTCAP_MPDUDENSITY_025:
4327 LINE_CHECK("ampdudensity .25");
4329 case IEEE80211_HTCAP_MPDUDENSITY_05:
4330 LINE_CHECK("ampdudensity .5");
4332 case IEEE80211_HTCAP_MPDUDENSITY_1:
4333 LINE_CHECK("ampdudensity 1");
4335 case IEEE80211_HTCAP_MPDUDENSITY_2:
4336 LINE_CHECK("ampdudensity 2");
4338 case IEEE80211_HTCAP_MPDUDENSITY_4:
4339 LINE_CHECK("ampdudensity 4");
4341 case IEEE80211_HTCAP_MPDUDENSITY_8:
4342 LINE_CHECK("ampdudensity 8");
4344 case IEEE80211_HTCAP_MPDUDENSITY_16:
4345 LINE_CHECK("ampdudensity 16");
4349 if (get80211val(s, IEEE80211_IOC_AMSDU, &val) != -1) {
4352 LINE_CHECK("-amsdu");
4355 LINE_CHECK("amsdutx -amsdurx");
4358 LINE_CHECK("-amsdutx amsdurx");
4362 LINE_CHECK("amsdu");
4366 /* XXX amsdu limit */
4367 if (get80211val(s, IEEE80211_IOC_SHORTGI, &val) != -1) {
4369 LINE_CHECK("shortgi");
4371 LINE_CHECK("-shortgi");
4373 if (get80211val(s, IEEE80211_IOC_HTPROTMODE, &val) != -1) {
4374 if (val == IEEE80211_PROTMODE_OFF)
4375 LINE_CHECK("htprotmode OFF");
4376 else if (val != IEEE80211_PROTMODE_RTSCTS)
4377 LINE_CHECK("htprotmode UNKNOWN (0x%x)", val);
4379 LINE_CHECK("htprotmode RTSCTS");
4381 if (get80211val(s, IEEE80211_IOC_PUREN, &val) != -1) {
4383 LINE_CHECK("puren");
4385 LINE_CHECK("-puren");
4387 if (get80211val(s, IEEE80211_IOC_SMPS, &val) != -1) {
4388 if (val == IEEE80211_HTCAP_SMPS_DYNAMIC)
4389 LINE_CHECK("smpsdyn");
4390 else if (val == IEEE80211_HTCAP_SMPS_ENA)
4393 LINE_CHECK("-smps");
4395 if (get80211val(s, IEEE80211_IOC_RIFS, &val) != -1) {
4399 LINE_CHECK("-rifs");
4403 if (get80211val(s, IEEE80211_IOC_WME, &wme) != -1) {
4411 if (get80211val(s, IEEE80211_IOC_BURST, &val) != -1) {
4413 LINE_CHECK("burst");
4415 LINE_CHECK("-burst");
4418 if (get80211val(s, IEEE80211_IOC_FF, &val) != -1) {
4424 if (get80211val(s, IEEE80211_IOC_TURBOP, &val) != -1) {
4426 LINE_CHECK("dturbo");
4428 LINE_CHECK("-dturbo");
4430 if (get80211val(s, IEEE80211_IOC_DWDS, &val) != -1) {
4434 LINE_CHECK("-dwds");
4437 if (opmode == IEEE80211_M_HOSTAP) {
4438 if (get80211val(s, IEEE80211_IOC_HIDESSID, &val) != -1) {
4440 LINE_CHECK("hidessid");
4442 LINE_CHECK("-hidessid");
4444 if (get80211val(s, IEEE80211_IOC_APBRIDGE, &val) != -1) {
4446 LINE_CHECK("-apbridge");
4448 LINE_CHECK("apbridge");
4450 if (get80211val(s, IEEE80211_IOC_DTIM_PERIOD, &val) != -1)
4451 LINE_CHECK("dtimperiod %u", val);
4453 if (get80211val(s, IEEE80211_IOC_DOTH, &val) != -1) {
4455 LINE_CHECK("-doth");
4459 if (get80211val(s, IEEE80211_IOC_DFS, &val) != -1) {
4465 if (get80211val(s, IEEE80211_IOC_INACTIVITY, &val) != -1) {
4467 LINE_CHECK("-inact");
4469 LINE_CHECK("inact");
4472 if (get80211val(s, IEEE80211_IOC_ROAMING, &val) != -1) {
4473 if (val != IEEE80211_ROAMING_AUTO || verbose) {
4475 case IEEE80211_ROAMING_DEVICE:
4476 LINE_CHECK("roaming DEVICE");
4478 case IEEE80211_ROAMING_AUTO:
4479 LINE_CHECK("roaming AUTO");
4481 case IEEE80211_ROAMING_MANUAL:
4482 LINE_CHECK("roaming MANUAL");
4485 LINE_CHECK("roaming UNKNOWN (0x%x)",
4493 if (opmode == IEEE80211_M_AHDEMO) {
4494 if (get80211val(s, IEEE80211_IOC_TDMA_SLOT, &val) != -1)
4495 LINE_CHECK("tdmaslot %u", val);
4496 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1)
4497 LINE_CHECK("tdmaslotcnt %u", val);
4498 if (get80211val(s, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1)
4499 LINE_CHECK("tdmaslotlen %u", val);
4500 if (get80211val(s, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1)
4501 LINE_CHECK("tdmabintval %u", val);
4502 } else if (get80211val(s, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) {
4503 /* XXX default define not visible */
4504 if (val != 100 || verbose)
4505 LINE_CHECK("bintval %u", val);
4508 if (wme && verbose) {
4516 get80211(int s, int type, void *data, int len)
4518 struct ieee80211req ireq;
4520 (void) memset(&ireq, 0, sizeof(ireq));
4521 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
4525 return ioctl(s, SIOCG80211, &ireq);
4529 get80211len(int s, int type, void *data, int len, int *plen)
4531 struct ieee80211req ireq;
4533 (void) memset(&ireq, 0, sizeof(ireq));
4534 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
4537 assert(ireq.i_len == len); /* NB: check for 16-bit truncation */
4539 if (ioctl(s, SIOCG80211, &ireq) < 0)
4546 get80211val(int s, int type, int *val)
4548 struct ieee80211req ireq;
4550 (void) memset(&ireq, 0, sizeof(ireq));
4551 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
4553 if (ioctl(s, SIOCG80211, &ireq) < 0)
4560 set80211(int s, int type, int val, int len, void *data)
4562 struct ieee80211req ireq;
4564 (void) memset(&ireq, 0, sizeof(ireq));
4565 (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
4569 assert(ireq.i_len == len); /* NB: check for 16-bit truncation */
4571 if (ioctl(s, SIOCS80211, &ireq) < 0)
4572 err(1, "SIOCS80211");
4576 get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
4584 hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x');
4590 if (sep != NULL && strchr(sep, *val) != NULL) {
4595 if (!isxdigit((u_char)val[0])) {
4596 warnx("bad hexadecimal digits");
4599 if (!isxdigit((u_char)val[1])) {
4600 warnx("odd count hexadecimal digits");
4604 if (p >= buf + len) {
4606 warnx("hexadecimal digits too long");
4608 warnx("string too long");
4612 #define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
4613 *p++ = (tohex((u_char)val[0]) << 4) |
4614 tohex((u_char)val[1]);
4621 /* The string "-" is treated as the empty string. */
4622 if (!hexstr && len == 1 && buf[0] == '-') {
4624 memset(buf, 0, *lenp);
4625 } else if (len < *lenp)
4626 memset(p, 0, *lenp - len);
4632 print_string(const u_int8_t *buf, int len)
4639 for (; i < len; i++) {
4640 if (!isprint(buf[i]) && buf[i] != '\0')
4642 if (isspace(buf[i]))
4646 if (hasspc || len == 0 || buf[0] == '\0')
4647 printf("\"%.*s\"", len, buf);
4649 printf("%.*s", len, buf);
4652 for (i = 0; i < len; i++)
4653 printf("%02x", buf[i]);
4658 * Virtual AP cloning support.
4660 static struct ieee80211_clone_params params = {
4661 .icp_opmode = IEEE80211_M_STA, /* default to station mode */
4665 wlan_create(int s, struct ifreq *ifr)
4667 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
4669 if (params.icp_parent[0] == '\0')
4670 errx(1, "must specify a parent when creating a wlan device");
4671 if (params.icp_opmode == IEEE80211_M_WDS &&
4672 memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0)
4673 errx(1, "no bssid specified for WDS (use wlanbssid)");
4674 ifr->ifr_data = (caddr_t) ¶ms;
4675 if (ioctl(s, SIOCIFCREATE2, ifr) < 0)
4676 err(1, "SIOCIFCREATE2");
4680 DECL_CMD_FUNC(set80211clone_wlandev, arg, d)
4682 strlcpy(params.icp_parent, arg, IFNAMSIZ);
4683 clone_setcallback(wlan_create);
4687 DECL_CMD_FUNC(set80211clone_wlanbssid, arg, d)
4689 const struct ether_addr *ea;
4691 ea = ether_aton(arg);
4693 errx(1, "%s: cannot parse bssid", arg);
4694 memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN);
4695 clone_setcallback(wlan_create);
4699 DECL_CMD_FUNC(set80211clone_wlanaddr, arg, d)
4701 const struct ether_addr *ea;
4703 ea = ether_aton(arg);
4705 errx(1, "%s: cannot parse addres", arg);
4706 memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN);
4707 params.icp_flags |= IEEE80211_CLONE_MACADDR;
4708 clone_setcallback(wlan_create);
4712 DECL_CMD_FUNC(set80211clone_wlanmode, arg, d)
4714 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0)
4715 if (iseq(arg, "sta"))
4716 params.icp_opmode = IEEE80211_M_STA;
4717 else if (iseq(arg, "ahdemo") || iseq(arg, "adhoc-demo"))
4718 params.icp_opmode = IEEE80211_M_AHDEMO;
4719 else if (iseq(arg, "ibss") || iseq(arg, "adhoc"))
4720 params.icp_opmode = IEEE80211_M_IBSS;
4721 else if (iseq(arg, "ap") || iseq(arg, "host"))
4722 params.icp_opmode = IEEE80211_M_HOSTAP;
4723 else if (iseq(arg, "wds"))
4724 params.icp_opmode = IEEE80211_M_WDS;
4725 else if (iseq(arg, "monitor"))
4726 params.icp_opmode = IEEE80211_M_MONITOR;
4727 else if (iseq(arg, "tdma")) {
4728 params.icp_opmode = IEEE80211_M_AHDEMO;
4729 params.icp_flags |= IEEE80211_CLONE_TDMA;
4731 errx(1, "Don't know to create %s for %s", arg, name);
4732 clone_setcallback(wlan_create);
4737 set80211clone_beacons(const char *val, int d, int s, const struct afswtch *rafp)
4739 /* NB: inverted sense */
4741 params.icp_flags &= ~IEEE80211_CLONE_NOBEACONS;
4743 params.icp_flags |= IEEE80211_CLONE_NOBEACONS;
4744 clone_setcallback(wlan_create);
4748 set80211clone_bssid(const char *val, int d, int s, const struct afswtch *rafp)
4751 params.icp_flags |= IEEE80211_CLONE_BSSID;
4753 params.icp_flags &= ~IEEE80211_CLONE_BSSID;
4754 clone_setcallback(wlan_create);
4758 set80211clone_wdslegacy(const char *val, int d, int s, const struct afswtch *rafp)
4761 params.icp_flags |= IEEE80211_CLONE_WDSLEGACY;
4763 params.icp_flags &= ~IEEE80211_CLONE_WDSLEGACY;
4764 clone_setcallback(wlan_create);
4767 static struct cmd ieee80211_cmds[] = {
4768 DEF_CMD_ARG("ssid", set80211ssid),
4769 DEF_CMD_ARG("nwid", set80211ssid),
4770 DEF_CMD_ARG("stationname", set80211stationname),
4771 DEF_CMD_ARG("station", set80211stationname), /* BSD/OS */
4772 DEF_CMD_ARG("channel", set80211channel),
4773 DEF_CMD_ARG("authmode", set80211authmode),
4774 DEF_CMD_ARG("powersavemode", set80211powersavemode),
4775 DEF_CMD("powersave", 1, set80211powersave),
4776 DEF_CMD("-powersave", 0, set80211powersave),
4777 DEF_CMD_ARG("powersavesleep", set80211powersavesleep),
4778 DEF_CMD_ARG("wepmode", set80211wepmode),
4779 DEF_CMD("wep", 1, set80211wep),
4780 DEF_CMD("-wep", 0, set80211wep),
4781 DEF_CMD_ARG("deftxkey", set80211weptxkey),
4782 DEF_CMD_ARG("weptxkey", set80211weptxkey),
4783 DEF_CMD_ARG("wepkey", set80211wepkey),
4784 DEF_CMD_ARG("nwkey", set80211nwkey), /* NetBSD */
4785 DEF_CMD("-nwkey", 0, set80211wep), /* NetBSD */
4786 DEF_CMD_ARG("rtsthreshold", set80211rtsthreshold),
4787 DEF_CMD_ARG("protmode", set80211protmode),
4788 DEF_CMD_ARG("txpower", set80211txpower),
4789 DEF_CMD_ARG("roaming", set80211roaming),
4790 DEF_CMD("wme", 1, set80211wme),
4791 DEF_CMD("-wme", 0, set80211wme),
4792 DEF_CMD("wmm", 1, set80211wme),
4793 DEF_CMD("-wmm", 0, set80211wme),
4794 DEF_CMD("hidessid", 1, set80211hidessid),
4795 DEF_CMD("-hidessid", 0, set80211hidessid),
4796 DEF_CMD("apbridge", 1, set80211apbridge),
4797 DEF_CMD("-apbridge", 0, set80211apbridge),
4798 DEF_CMD_ARG("chanlist", set80211chanlist),
4799 DEF_CMD_ARG("bssid", set80211bssid),
4800 DEF_CMD_ARG("ap", set80211bssid),
4801 DEF_CMD("scan", 0, set80211scan),
4802 DEF_CMD_ARG("list", set80211list),
4803 DEF_CMD_ARG2("cwmin", set80211cwmin),
4804 DEF_CMD_ARG2("cwmax", set80211cwmax),
4805 DEF_CMD_ARG2("aifs", set80211aifs),
4806 DEF_CMD_ARG2("txoplimit", set80211txoplimit),
4807 DEF_CMD_ARG("acm", set80211acm),
4808 DEF_CMD_ARG("-acm", set80211noacm),
4809 DEF_CMD_ARG("ack", set80211ackpolicy),
4810 DEF_CMD_ARG("-ack", set80211noackpolicy),
4811 DEF_CMD_ARG2("bss:cwmin", set80211bsscwmin),
4812 DEF_CMD_ARG2("bss:cwmax", set80211bsscwmax),
4813 DEF_CMD_ARG2("bss:aifs", set80211bssaifs),
4814 DEF_CMD_ARG2("bss:txoplimit", set80211bsstxoplimit),
4815 DEF_CMD_ARG("dtimperiod", set80211dtimperiod),
4816 DEF_CMD_ARG("bintval", set80211bintval),
4817 DEF_CMD("mac:open", IEEE80211_MACCMD_POLICY_OPEN, set80211maccmd),
4818 DEF_CMD("mac:allow", IEEE80211_MACCMD_POLICY_ALLOW, set80211maccmd),
4819 DEF_CMD("mac:deny", IEEE80211_MACCMD_POLICY_DENY, set80211maccmd),
4820 DEF_CMD("mac:radius", IEEE80211_MACCMD_POLICY_RADIUS, set80211maccmd),
4821 DEF_CMD("mac:flush", IEEE80211_MACCMD_FLUSH, set80211maccmd),
4822 DEF_CMD("mac:detach", IEEE80211_MACCMD_DETACH, set80211maccmd),
4823 DEF_CMD_ARG("mac:add", set80211addmac),
4824 DEF_CMD_ARG("mac:del", set80211delmac),
4825 DEF_CMD_ARG("mac:kick", set80211kickmac),
4826 DEF_CMD("pureg", 1, set80211pureg),
4827 DEF_CMD("-pureg", 0, set80211pureg),
4828 DEF_CMD("ff", 1, set80211fastframes),
4829 DEF_CMD("-ff", 0, set80211fastframes),
4830 DEF_CMD("dturbo", 1, set80211dturbo),
4831 DEF_CMD("-dturbo", 0, set80211dturbo),
4832 DEF_CMD("bgscan", 1, set80211bgscan),
4833 DEF_CMD("-bgscan", 0, set80211bgscan),
4834 DEF_CMD_ARG("bgscanidle", set80211bgscanidle),
4835 DEF_CMD_ARG("bgscanintvl", set80211bgscanintvl),
4836 DEF_CMD_ARG("scanvalid", set80211scanvalid),
4837 DEF_CMD_ARG("roam:rssi", set80211roamrssi),
4838 DEF_CMD_ARG("roam:rate", set80211roamrate),
4839 DEF_CMD_ARG("mcastrate", set80211mcastrate),
4840 DEF_CMD_ARG("ucastrate", set80211ucastrate),
4841 DEF_CMD_ARG("mgtrate", set80211mgtrate),
4842 DEF_CMD_ARG("mgmtrate", set80211mgtrate),
4843 DEF_CMD_ARG("maxretry", set80211maxretry),
4844 DEF_CMD_ARG("fragthreshold", set80211fragthreshold),
4845 DEF_CMD("burst", 1, set80211burst),
4846 DEF_CMD("-burst", 0, set80211burst),
4847 DEF_CMD_ARG("bmiss", set80211bmissthreshold),
4848 DEF_CMD_ARG("bmissthreshold", set80211bmissthreshold),
4849 DEF_CMD("shortgi", 1, set80211shortgi),
4850 DEF_CMD("-shortgi", 0, set80211shortgi),
4851 DEF_CMD("ampdurx", 2, set80211ampdu),
4852 DEF_CMD("-ampdurx", -2, set80211ampdu),
4853 DEF_CMD("ampdutx", 1, set80211ampdu),
4854 DEF_CMD("-ampdutx", -1, set80211ampdu),
4855 DEF_CMD("ampdu", 3, set80211ampdu), /* NB: tx+rx */
4856 DEF_CMD("-ampdu", -3, set80211ampdu),
4857 DEF_CMD_ARG("ampdulimit", set80211ampdulimit),
4858 DEF_CMD_ARG("ampdudensity", set80211ampdudensity),
4859 DEF_CMD("amsdurx", 2, set80211amsdu),
4860 DEF_CMD("-amsdurx", -2, set80211amsdu),
4861 DEF_CMD("amsdutx", 1, set80211amsdu),
4862 DEF_CMD("-amsdutx", -1, set80211amsdu),
4863 DEF_CMD("amsdu", 3, set80211amsdu), /* NB: tx+rx */
4864 DEF_CMD("-amsdu", -3, set80211amsdu),
4865 DEF_CMD_ARG("amsdulimit", set80211amsdulimit),
4866 DEF_CMD("puren", 1, set80211puren),
4867 DEF_CMD("-puren", 0, set80211puren),
4868 DEF_CMD("doth", 1, set80211doth),
4869 DEF_CMD("-doth", 0, set80211doth),
4870 DEF_CMD("dfs", 1, set80211dfs),
4871 DEF_CMD("-dfs", 0, set80211dfs),
4872 DEF_CMD("htcompat", 1, set80211htcompat),
4873 DEF_CMD("-htcompat", 0, set80211htcompat),
4874 DEF_CMD("dwds", 1, set80211dwds),
4875 DEF_CMD("-dwds", 0, set80211dwds),
4876 DEF_CMD("inact", 1, set80211inact),
4877 DEF_CMD("-inact", 0, set80211inact),
4878 DEF_CMD("tsn", 1, set80211tsn),
4879 DEF_CMD("-tsn", 0, set80211tsn),
4880 DEF_CMD_ARG("regdomain", set80211regdomain),
4881 DEF_CMD_ARG("country", set80211country),
4882 DEF_CMD("indoor", 'I', set80211location),
4883 DEF_CMD("-indoor", 'O', set80211location),
4884 DEF_CMD("outdoor", 'O', set80211location),
4885 DEF_CMD("-outdoor", 'I', set80211location),
4886 DEF_CMD("anywhere", ' ', set80211location),
4887 DEF_CMD("ecm", 1, set80211ecm),
4888 DEF_CMD("-ecm", 0, set80211ecm),
4889 DEF_CMD("dotd", 1, set80211dotd),
4890 DEF_CMD("-dotd", 0, set80211dotd),
4891 DEF_CMD_ARG("htprotmode", set80211htprotmode),
4892 DEF_CMD("ht20", 1, set80211htconf),
4893 DEF_CMD("-ht20", 0, set80211htconf),
4894 DEF_CMD("ht40", 3, set80211htconf), /* NB: 20+40 */
4895 DEF_CMD("-ht40", 0, set80211htconf),
4896 DEF_CMD("ht", 3, set80211htconf), /* NB: 20+40 */
4897 DEF_CMD("-ht", 0, set80211htconf),
4898 DEF_CMD("rifs", 1, set80211rifs),
4899 DEF_CMD("-rifs", 0, set80211rifs),
4900 DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA, set80211smps),
4901 DEF_CMD("smpsdyn", IEEE80211_HTCAP_SMPS_DYNAMIC, set80211smps),
4902 DEF_CMD("-smps", IEEE80211_HTCAP_SMPS_OFF, set80211smps),
4903 /* XXX for testing */
4904 DEF_CMD_ARG("chanswitch", set80211chanswitch),
4906 DEF_CMD_ARG("tdmaslot", set80211tdmaslot),
4907 DEF_CMD_ARG("tdmaslotcnt", set80211tdmaslotcnt),
4908 DEF_CMD_ARG("tdmaslotlen", set80211tdmaslotlen),
4909 DEF_CMD_ARG("tdmabintval", set80211tdmabintval),
4911 /* vap cloning support */
4912 DEF_CLONE_CMD_ARG("wlanaddr", set80211clone_wlanaddr),
4913 DEF_CLONE_CMD_ARG("wlanbssid", set80211clone_wlanbssid),
4914 DEF_CLONE_CMD_ARG("wlandev", set80211clone_wlandev),
4915 DEF_CLONE_CMD_ARG("wlanmode", set80211clone_wlanmode),
4916 DEF_CLONE_CMD("beacons", 1, set80211clone_beacons),
4917 DEF_CLONE_CMD("-beacons", 0, set80211clone_beacons),
4918 DEF_CLONE_CMD("bssid", 1, set80211clone_bssid),
4919 DEF_CLONE_CMD("-bssid", 0, set80211clone_bssid),
4920 DEF_CLONE_CMD("wdslegacy", 1, set80211clone_wdslegacy),
4921 DEF_CLONE_CMD("-wdslegacy", 0, set80211clone_wdslegacy),
4923 static struct afswtch af_ieee80211 = {
4924 .af_name = "af_ieee80211",
4926 .af_other_status = ieee80211_status,
4929 static __constructor void
4930 ieee80211_ctor(void)
4932 #define N(a) (sizeof(a) / sizeof(a[0]))
4935 for (i = 0; i < N(ieee80211_cmds); i++)
4936 cmd_register(&ieee80211_cmds[i]);
4937 af_register(&af_ieee80211);