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
27 * $FreeBSD: head/sbin/ifconfig/ifieee80211.c 203970 2010-02-16 21:39:20Z imp $
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.
47 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
48 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
49 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
51 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57 * POSSIBILITY OF SUCH DAMAGE.
60 #include <sys/param.h>
61 #include <sys/ioctl.h>
62 #include <sys/socket.h>
63 #include <sys/sysctl.h>
66 #include <net/ethernet.h>
68 #include <net/if_dl.h>
69 #include <net/if_types.h>
70 #include <net/if_media.h>
71 #include <net/route.h>
73 #include <netproto/802_11/ieee80211_ioctl.h>
74 #include <netproto/802_11/ieee80211_dragonfly.h>
75 #include <netproto/802_11/ieee80211_superg.h>
76 #include <netproto/802_11/ieee80211_tdma.h>
77 #include <netproto/802_11/ieee80211_mesh.h>
78 #include <netproto/802_11/ieee80211_wps.h>
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 0x000001 /* authorized for data */
105 #define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */
106 #define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */
107 #define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */
108 #define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */
109 #define IEEE80211_NODE_HT 0x000040 /* HT enabled */
110 #define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */
111 #define IEEE80211_NODE_WPS 0x000100 /* WPS association */
112 #define IEEE80211_NODE_TSN 0x000200 /* TSN association */
113 #define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */
114 #define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */
115 #define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */
116 #define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */
117 #define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */
118 #define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */
119 #define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */
120 #define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */
121 #define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */
122 #define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */
125 #define MAXCHAN 1536 /* max 1.5K channels */
131 static void LINE_INIT(char c
);
132 static void LINE_BREAK(void);
133 static void LINE_CHECK(const char *fmt
, ...) __printflike(1, 2);
135 static const char *modename
[IEEE80211_MODE_MAX
] = {
136 [IEEE80211_MODE_AUTO
] = "auto",
137 [IEEE80211_MODE_11A
] = "11a",
138 [IEEE80211_MODE_11B
] = "11b",
139 [IEEE80211_MODE_11G
] = "11g",
140 [IEEE80211_MODE_FH
] = "fh",
141 [IEEE80211_MODE_TURBO_A
] = "turboA",
142 [IEEE80211_MODE_TURBO_G
] = "turboG",
143 [IEEE80211_MODE_STURBO_A
] = "sturbo",
144 [IEEE80211_MODE_11NA
] = "11na",
145 [IEEE80211_MODE_11NG
] = "11ng",
146 [IEEE80211_MODE_HALF
] = "half",
147 [IEEE80211_MODE_QUARTER
] = "quarter"
150 static void set80211(int s
, int type
, int val
, int len
, void *data
);
151 static int get80211(int s
, int type
, void *data
, int len
);
152 static int get80211len(int s
, int type
, void *data
, size_t len
, size_t *plen
);
153 static int get80211val(int s
, int type
, int *val
);
154 static const char *get_string(const char *val
, const char *sep
,
155 u_int8_t
*buf
, int *lenp
);
156 static void print_string(const u_int8_t
*buf
, int len
);
157 static void print_regdomain(const struct ieee80211_regdomain
*, int);
158 static void print_channels(int, const struct ieee80211req_chaninfo
*,
159 int allchans
, int verbose
);
160 static void regdomain_makechannels(struct ieee80211_regdomain_req
*,
161 const struct ieee80211_devcaps_req
*);
162 static const char *mesh_linkstate_string(uint8_t state
);
164 static struct ieee80211req_chaninfo
*chaninfo
;
165 static struct ieee80211_regdomain regdomain
;
166 static int gotregdomain
= 0;
167 static struct ieee80211_roamparams_req roamparams
;
168 static int gotroam
= 0;
169 static struct ieee80211_txparams_req txparams
;
170 static int gottxparams
= 0;
171 static struct ieee80211_channel curchan
;
172 static int gotcurchan
= 0;
173 static struct ifmediareq
*ifmr
;
174 static int htconf
= 0;
175 static int gothtconf
= 0;
178 iseq(const char *a
, const char *b
)
180 return (strcasecmp(a
, b
) == 0);
184 ismatch(const char *a
, const char *b
)
186 return (strncasecmp(a
, b
, strlen(b
)) == 0);
194 if (get80211val(s
, IEEE80211_IOC_HTCONF
, &htconf
) < 0)
195 warn("unable to get HT configuration information");
200 * Collect channel info from the kernel. We use this (mostly)
201 * to handle mapping between frequency and IEEE channel number.
206 if (chaninfo
!= NULL
)
208 chaninfo
= malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN
));
209 if (chaninfo
== NULL
)
210 errx(1, "no space for channel list");
211 if (get80211(s
, IEEE80211_IOC_CHANINFO
, chaninfo
,
212 IEEE80211_CHANINFO_SIZE(MAXCHAN
)) < 0)
213 err(1, "unable to get channel information");
214 ifmr
= ifmedia_getstate(s
);
218 static struct regdata
*
221 static struct regdata
*rdp
= NULL
;
223 rdp
= lib80211_alloc_regdata();
225 errx(-1, "missing or corrupted regdomain database");
231 * Given the channel at index i with attributes from,
232 * check if there is a channel with attributes to in
233 * the channel table. With suitable attributes this
234 * allows the caller to look for promotion; e.g. from
238 canpromote(u_int i
, uint32_t from
, uint32_t to
)
240 const struct ieee80211_channel
*fc
= &chaninfo
->ic_chans
[i
];
243 if ((fc
->ic_flags
& from
) != from
)
245 /* NB: quick check exploiting ordering of chans w/ same frequency */
246 if (i
+1 < chaninfo
->ic_nchans
&&
247 chaninfo
->ic_chans
[i
+1].ic_freq
== fc
->ic_freq
&&
248 (chaninfo
->ic_chans
[i
+1].ic_flags
& to
) == to
)
250 /* brute force search in case channel list is not ordered */
251 for (j
= 0; j
< chaninfo
->ic_nchans
; j
++) {
252 const struct ieee80211_channel
*tc
= &chaninfo
->ic_chans
[j
];
254 tc
->ic_freq
== fc
->ic_freq
&& (tc
->ic_flags
& to
) == to
)
261 * Handle channel promotion. When a channel is specified with
262 * only a frequency we want to promote it to the ``best'' channel
263 * available. The channel list has separate entries for 11b, 11g,
264 * 11a, and 11n[ga] channels so specifying a frequency w/o any
265 * attributes requires we upgrade, e.g. from 11b -> 11g. This
266 * gets complicated when the channel is specified on the same
267 * command line with a media request that constrains the available
268 * channe list (e.g. mode 11a); we want to honor that to avoid
269 * confusing behaviour.
275 * Query the current mode of the interface in case it's
276 * constrained (e.g. to 11a). We must do this carefully
277 * as there may be a pending ifmedia request in which case
278 * asking the kernel will give us the wrong answer. This
279 * is an unfortunate side-effect of the way ifconfig is
280 * structure for modularity (yech).
282 * NB: ifmr is actually setup in getchaninfo (above); we
283 * assume it's called coincident with to this call so
284 * we have a ``current setting''; otherwise we must pass
285 * the socket descriptor down to here so we can make
286 * the ifmedia_getstate call ourselves.
288 int chanmode
= ifmr
!= NULL
? IFM_MODE(ifmr
->ifm_current
) : IFM_AUTO
;
290 /* when ambiguous promote to ``best'' */
291 /* NB: we abitrarily pick HT40+ over HT40- */
292 if (chanmode
!= IFM_IEEE80211_11B
)
293 i
= canpromote(i
, IEEE80211_CHAN_B
, IEEE80211_CHAN_G
);
294 if (chanmode
!= IFM_IEEE80211_11G
&& (htconf
& 1)) {
295 i
= canpromote(i
, IEEE80211_CHAN_G
,
296 IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
);
298 i
= canpromote(i
, IEEE80211_CHAN_G
,
299 IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40D
);
300 i
= canpromote(i
, IEEE80211_CHAN_G
,
301 IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40U
);
304 if (chanmode
!= IFM_IEEE80211_11A
&& (htconf
& 1)) {
305 i
= canpromote(i
, IEEE80211_CHAN_A
,
306 IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
);
308 i
= canpromote(i
, IEEE80211_CHAN_A
,
309 IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40D
);
310 i
= canpromote(i
, IEEE80211_CHAN_A
,
311 IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40U
);
318 mapfreq(struct ieee80211_channel
*chan
, uint16_t freq
, uint32_t flags
)
322 for (i
= 0; i
< chaninfo
->ic_nchans
; i
++) {
323 const struct ieee80211_channel
*c
= &chaninfo
->ic_chans
[i
];
325 if (c
->ic_freq
== freq
&& (c
->ic_flags
& flags
) == flags
) {
327 /* when ambiguous promote to ``best'' */
328 c
= &chaninfo
->ic_chans
[promote(i
)];
334 errx(1, "unknown/undefined frequency %u/0x%x", freq
, flags
);
338 mapchan(struct ieee80211_channel
*chan
, uint8_t ieee
, uint32_t flags
)
342 for (i
= 0; i
< chaninfo
->ic_nchans
; i
++) {
343 const struct ieee80211_channel
*c
= &chaninfo
->ic_chans
[i
];
345 if (c
->ic_ieee
== ieee
&& (c
->ic_flags
& flags
) == flags
) {
347 /* when ambiguous promote to ``best'' */
348 c
= &chaninfo
->ic_chans
[promote(i
)];
354 errx(1, "unknown/undefined channel number %d flags 0x%x", ieee
, flags
);
357 static const struct ieee80211_channel
*
362 if (get80211(s
, IEEE80211_IOC_CURCHAN
, &curchan
, sizeof(curchan
)) < 0) {
364 /* fall back to legacy ioctl */
365 if (get80211val(s
, IEEE80211_IOC_CHANNEL
, &val
) < 0)
366 err(-1, "cannot figure out current channel");
368 mapchan(&curchan
, val
, 0);
374 static enum ieee80211_phymode
375 chan2mode(const struct ieee80211_channel
*c
)
377 if (IEEE80211_IS_CHAN_HTA(c
))
378 return IEEE80211_MODE_11NA
;
379 if (IEEE80211_IS_CHAN_HTG(c
))
380 return IEEE80211_MODE_11NG
;
381 if (IEEE80211_IS_CHAN_108A(c
))
382 return IEEE80211_MODE_TURBO_A
;
383 if (IEEE80211_IS_CHAN_108G(c
))
384 return IEEE80211_MODE_TURBO_G
;
385 if (IEEE80211_IS_CHAN_ST(c
))
386 return IEEE80211_MODE_STURBO_A
;
387 if (IEEE80211_IS_CHAN_FHSS(c
))
388 return IEEE80211_MODE_FH
;
389 if (IEEE80211_IS_CHAN_HALF(c
))
390 return IEEE80211_MODE_HALF
;
391 if (IEEE80211_IS_CHAN_QUARTER(c
))
392 return IEEE80211_MODE_QUARTER
;
393 if (IEEE80211_IS_CHAN_A(c
))
394 return IEEE80211_MODE_11A
;
395 if (IEEE80211_IS_CHAN_ANYG(c
))
396 return IEEE80211_MODE_11G
;
397 if (IEEE80211_IS_CHAN_B(c
))
398 return IEEE80211_MODE_11B
;
399 return IEEE80211_MODE_AUTO
;
407 if (get80211(s
, IEEE80211_IOC_ROAM
,
408 &roamparams
, sizeof(roamparams
)) < 0)
409 err(1, "unable to get roaming parameters");
414 setroam_cb(int s
, void *arg
)
416 struct ieee80211_roamparams_req
*roam
= arg
;
417 set80211(s
, IEEE80211_IOC_ROAM
, 0, sizeof(*roam
), roam
);
425 if (get80211(s
, IEEE80211_IOC_TXPARAMS
,
426 &txparams
, sizeof(txparams
)) < 0)
427 err(1, "unable to get transmit parameters");
432 settxparams_cb(int s
, void *arg
)
434 struct ieee80211_txparams_req
*txp
= arg
;
435 set80211(s
, IEEE80211_IOC_TXPARAMS
, 0, sizeof(*txp
), txp
);
443 if (get80211(s
, IEEE80211_IOC_REGDOMAIN
,
444 ®domain
, sizeof(regdomain
)) < 0)
445 err(1, "unable to get regulatory domain info");
450 getdevcaps(int s
, struct ieee80211_devcaps_req
*dc
)
452 if (get80211(s
, IEEE80211_IOC_DEVCAPS
, dc
,
453 IEEE80211_DEVCAPS_SPACE(dc
)) < 0)
454 err(1, "unable to get device capabilities");
458 setregdomain_cb(int s
, void *arg
)
460 struct ieee80211_regdomain_req
*req
;
461 struct ieee80211_regdomain
*rd
= arg
;
462 struct ieee80211_devcaps_req
*dc
;
463 struct regdata
*rdp
= getregdata();
465 if (rd
->country
!= NO_COUNTRY
) {
466 const struct country
*cc
;
468 * Check current country seting to make sure it's
469 * compatible with the new regdomain. If not, then
470 * override it with any default country for this
471 * SKU. If we cannot arrange a match, then abort.
473 cc
= lib80211_country_findbycc(rdp
, rd
->country
);
475 errx(1, "unknown ISO country code %d", rd
->country
);
476 if (cc
->rd
->sku
!= rd
->regdomain
) {
477 const struct regdomain
*rp
;
479 * Check if country is incompatible with regdomain.
480 * To enable multiple regdomains for a country code
481 * we permit a mismatch between the regdomain and
482 * the country's associated regdomain when the
483 * regdomain is setup w/o a default country. For
484 * example, US is bound to the FCC regdomain but
485 * we allow US to be combined with FCC3 because FCC3
486 * has not default country. This allows bogus
487 * combinations like FCC3+DK which are resolved when
488 * constructing the channel list by deferring to the
489 * regdomain to construct the channel list.
491 rp
= lib80211_regdomain_findbysku(rdp
, rd
->regdomain
);
493 errx(1, "country %s (%s) is not usable with "
494 "regdomain %d", cc
->isoname
, cc
->name
,
496 else if (rp
->cc
!= NULL
&& rp
->cc
!= cc
)
497 errx(1, "country %s (%s) is not usable with "
498 "regdomain %s", cc
->isoname
, cc
->name
,
503 * Fetch the device capabilities and calculate the
504 * full set of netbands for which we request a new
505 * channel list be constructed. Once that's done we
506 * push the regdomain info + channel list to the kernel.
508 dc
= malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN
));
510 errx(1, "no space for device capabilities");
511 dc
->dc_chaninfo
.ic_nchans
= MAXCHAN
;
515 printf("drivercaps: 0x%x\n", dc
->dc_drivercaps
);
516 printf("cryptocaps: 0x%x\n", dc
->dc_cryptocaps
);
517 printf("htcaps : 0x%x\n", dc
->dc_htcaps
);
518 memcpy(chaninfo
, &dc
->dc_chaninfo
,
519 IEEE80211_CHANINFO_SPACE(&dc
->dc_chaninfo
));
520 print_channels(s
, &dc
->dc_chaninfo
, 1/*allchans*/, 1/*verbose*/);
523 req
= malloc(IEEE80211_REGDOMAIN_SIZE(dc
->dc_chaninfo
.ic_nchans
));
525 errx(1, "no space for regdomain request");
527 regdomain_makechannels(req
, dc
);
530 print_regdomain(rd
, 1/*verbose*/);
532 /* blech, reallocate channel list for new data */
533 if (chaninfo
!= NULL
)
535 chaninfo
= malloc(IEEE80211_CHANINFO_SPACE(&req
->chaninfo
));
536 if (chaninfo
== NULL
)
537 errx(1, "no space for channel list");
538 memcpy(chaninfo
, &req
->chaninfo
,
539 IEEE80211_CHANINFO_SPACE(&req
->chaninfo
));
540 print_channels(s
, &req
->chaninfo
, 1/*allchans*/, 1/*verbose*/);
542 if (req
->chaninfo
.ic_nchans
== 0)
543 errx(1, "no channels calculated");
544 set80211(s
, IEEE80211_IOC_REGDOMAIN
, 0,
545 IEEE80211_REGDOMAIN_SPACE(req
), req
);
551 ieee80211_mhz2ieee(int freq
, int flags
)
553 struct ieee80211_channel chan
;
554 mapfreq(&chan
, freq
, flags
);
559 isanyarg(const char *arg
)
561 return (ismatch(arg
, "-") ||
562 ismatch(arg
, "any") ||
563 ismatch(arg
, "off"));
567 set80211ssid(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
571 u_int8_t data
[IEEE80211_NWID_LEN
];
575 if (len
> 2 && isdigit((int)val
[0]) && val
[1] == ':') {
580 bzero(data
, sizeof(data
));
582 if (get_string(val
, NULL
, data
, &len
) == NULL
)
585 set80211(s
, IEEE80211_IOC_SSID
, ssid
, len
, data
);
589 set80211meshid(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
592 u_int8_t data
[IEEE80211_NWID_LEN
];
594 memset(data
, 0, sizeof(data
));
596 if (get_string(val
, NULL
, data
, &len
) == NULL
)
599 set80211(s
, IEEE80211_IOC_MESH_ID
, 0, len
, data
);
603 set80211stationname(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
608 bzero(data
, sizeof(data
));
610 get_string(val
, NULL
, data
, &len
);
612 set80211(s
, IEEE80211_IOC_STATIONNAME
, 0, len
, data
);
616 * Parse a channel specification for attributes/flags.
618 * freq/xx channel width (5,10,20,40,40+,40-)
619 * freq:mode channel mode (a,b,g,h,n,t,s,d)
621 * These can be combined in either order; e.g. 2437:ng/40.
622 * Modes are case insensitive.
624 * The result is not validated here; it's assumed to be
625 * checked against the channel table fetched from the kernel.
628 getchannelflags(const char *val
, int freq
)
630 #define _CHAN_HT 0x80000000
636 cp
= strchr(val
, ':');
638 for (cp
++; isalpha((int) *cp
); cp
++) {
639 /* accept mixed case */
644 case 'a': /* 802.11a */
645 flags
|= IEEE80211_CHAN_A
;
647 case 'b': /* 802.11b */
648 flags
|= IEEE80211_CHAN_B
;
650 case 'g': /* 802.11g */
651 flags
|= IEEE80211_CHAN_G
;
653 case 'h': /* ht = 802.11n */
654 case 'n': /* 802.11n */
655 flags
|= _CHAN_HT
; /* NB: private */
657 case 'd': /* dt = Atheros Dynamic Turbo */
658 flags
|= IEEE80211_CHAN_TURBO
;
660 case 't': /* ht, dt, st, t */
661 /* dt and unadorned t specify Dynamic Turbo */
662 if ((flags
& (IEEE80211_CHAN_STURBO
|_CHAN_HT
)) == 0)
663 flags
|= IEEE80211_CHAN_TURBO
;
665 case 's': /* st = Atheros Static Turbo */
666 flags
|= IEEE80211_CHAN_STURBO
;
669 errx(-1, "%s: Invalid channel attribute %c\n",
674 cp
= strchr(val
, '/');
677 u_long cw
= strtoul(cp
+1, &ep
, 10);
681 flags
|= IEEE80211_CHAN_QUARTER
;
684 flags
|= IEEE80211_CHAN_HALF
;
687 /* NB: this may be removed below */
688 flags
|= IEEE80211_CHAN_HT20
;
691 if (ep
!= NULL
&& *ep
== '+')
692 flags
|= IEEE80211_CHAN_HT40U
;
693 else if (ep
!= NULL
&& *ep
== '-')
694 flags
|= IEEE80211_CHAN_HT40D
;
697 errx(-1, "%s: Invalid channel width\n", val
);
701 * Cleanup specifications.
703 if ((flags
& _CHAN_HT
) == 0) {
705 * If user specified freq/20 or freq/40 quietly remove
706 * HT cw attributes depending on channel use. To give
707 * an explicit 20/40 width for an HT channel you must
708 * indicate it is an HT channel since all HT channels
709 * are also usable for legacy operation; e.g. freq:n/40.
711 flags
&= ~IEEE80211_CHAN_HT
;
714 * Remove private indicator that this is an HT channel
715 * and if no explicit channel width has been given
716 * provide the default settings.
719 if ((flags
& IEEE80211_CHAN_HT
) == 0) {
720 struct ieee80211_channel chan
;
722 * Consult the channel list to see if we can use
723 * HT40+ or HT40- (if both the map routines choose).
726 mapfreq(&chan
, freq
, 0);
728 mapchan(&chan
, freq
, 0);
729 flags
|= (chan
.ic_flags
& IEEE80211_CHAN_HT
);
737 getchannel(int s
, struct ieee80211_channel
*chan
, const char *val
)
742 memset(chan
, 0, sizeof(*chan
));
744 chan
->ic_freq
= IEEE80211_CHAN_ANY
;
749 v
= strtol(val
, &eptr
, 10);
750 if (val
[0] == '\0' || val
== eptr
|| errno
== ERANGE
||
751 /* channel may be suffixed with nothing, :flag, or /width */
752 (eptr
[0] != '\0' && eptr
[0] != ':' && eptr
[0] != '/'))
753 errx(1, "invalid channel specification%s",
754 errno
== ERANGE
? " (out of range)" : "");
755 flags
= getchannelflags(val
, v
);
756 if (v
> 255) { /* treat as frequency */
757 mapfreq(chan
, v
, flags
);
759 mapchan(chan
, v
, flags
);
764 set80211channel(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
766 struct ieee80211_channel chan
;
768 getchannel(s
, &chan
, val
);
769 set80211(s
, IEEE80211_IOC_CURCHAN
, 0, sizeof(chan
), &chan
);
773 set80211chanswitch(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
775 struct ieee80211_chanswitch_req csr
;
777 getchannel(s
, &csr
.csa_chan
, val
);
780 set80211(s
, IEEE80211_IOC_CHANSWITCH
, 0, sizeof(csr
), &csr
);
784 set80211authmode(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
788 if (iseq(val
, "none")) {
789 mode
= IEEE80211_AUTH_NONE
;
790 } else if (iseq(val
, "open")) {
791 mode
= IEEE80211_AUTH_OPEN
;
792 } else if (iseq(val
, "shared")) {
793 mode
= IEEE80211_AUTH_SHARED
;
794 } else if (iseq(val
, "8021x")) {
795 mode
= IEEE80211_AUTH_8021X
;
796 } else if (iseq(val
, "wpa")) {
797 mode
= IEEE80211_AUTH_WPA
;
799 errx(1, "unknown authmode");
802 set80211(s
, IEEE80211_IOC_AUTHMODE
, mode
, 0, NULL
);
806 set80211powersavemode(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
810 if (iseq(val
, "off")) {
811 mode
= IEEE80211_POWERSAVE_OFF
;
812 } else if (iseq(val
, "on")) {
813 mode
= IEEE80211_POWERSAVE_ON
;
814 } else if (iseq(val
, "cam")) {
815 mode
= IEEE80211_POWERSAVE_CAM
;
816 } else if (iseq(val
, "psp")) {
817 mode
= IEEE80211_POWERSAVE_PSP
;
818 } else if (iseq(val
, "psp-cam")) {
819 mode
= IEEE80211_POWERSAVE_PSP_CAM
;
821 errx(1, "unknown powersavemode");
824 set80211(s
, IEEE80211_IOC_POWERSAVE
, mode
, 0, NULL
);
828 set80211powersave(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
831 set80211(s
, IEEE80211_IOC_POWERSAVE
, IEEE80211_POWERSAVE_OFF
,
834 set80211(s
, IEEE80211_IOC_POWERSAVE
, IEEE80211_POWERSAVE_ON
,
839 set80211powersavesleep(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
841 set80211(s
, IEEE80211_IOC_POWERSAVESLEEP
, atoi(val
), 0, NULL
);
845 set80211wepmode(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
849 if (iseq(val
, "off")) {
850 mode
= IEEE80211_WEP_OFF
;
851 } else if (iseq(val
, "on")) {
852 mode
= IEEE80211_WEP_ON
;
853 } else if (iseq(val
, "mixed")) {
854 mode
= IEEE80211_WEP_MIXED
;
856 errx(1, "unknown wep mode");
859 set80211(s
, IEEE80211_IOC_WEP
, mode
, 0, NULL
);
863 set80211wep(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
865 set80211(s
, IEEE80211_IOC_WEP
, d
, 0, NULL
);
869 isundefarg(const char *arg
)
871 return (strcmp(arg
, "-") == 0 || ismatch(arg
, "undef"));
875 set80211weptxkey(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
878 set80211(s
, IEEE80211_IOC_WEPTXKEY
, IEEE80211_KEYIX_NONE
, 0, NULL
);
880 set80211(s
, IEEE80211_IOC_WEPTXKEY
, atoi(val
)-1, 0, NULL
);
884 set80211wepkey(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
888 u_int8_t data
[IEEE80211_KEYBUF_SIZE
];
890 if (isdigit((int)val
[0]) && val
[1] == ':') {
895 bzero(data
, sizeof(data
));
897 get_string(val
, NULL
, data
, &len
);
899 set80211(s
, IEEE80211_IOC_WEPKEY
, key
, len
, data
);
903 * This function is purely a NetBSD compatibility interface. The NetBSD
904 * interface is too inflexible, but it's there so we'll support it since
905 * it's not all that hard.
908 set80211nwkey(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
912 u_int8_t data
[IEEE80211_KEYBUF_SIZE
];
914 set80211(s
, IEEE80211_IOC_WEP
, IEEE80211_WEP_ON
, 0, NULL
);
916 if (isdigit((int)val
[0]) && val
[1] == ':') {
917 txkey
= val
[0]-'0'-1;
920 for (i
= 0; i
< 4; i
++) {
921 bzero(data
, sizeof(data
));
923 val
= get_string(val
, ",", data
, &len
);
927 set80211(s
, IEEE80211_IOC_WEPKEY
, i
, len
, data
);
930 bzero(data
, sizeof(data
));
932 get_string(val
, NULL
, data
, &len
);
935 set80211(s
, IEEE80211_IOC_WEPKEY
, 0, len
, data
);
937 bzero(data
, sizeof(data
));
938 for (i
= 1; i
< 4; i
++)
939 set80211(s
, IEEE80211_IOC_WEPKEY
, i
, 0, data
);
942 set80211(s
, IEEE80211_IOC_WEPTXKEY
, txkey
, 0, NULL
);
946 set80211rtsthreshold(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
948 set80211(s
, IEEE80211_IOC_RTSTHRESHOLD
,
949 isundefarg(val
) ? IEEE80211_RTS_MAX
: atoi(val
), 0, NULL
);
953 set80211protmode(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
957 if (iseq(val
, "off")) {
958 mode
= IEEE80211_PROTMODE_OFF
;
959 } else if (iseq(val
, "cts")) {
960 mode
= IEEE80211_PROTMODE_CTS
;
961 } else if (ismatch(val
, "rts")) {
962 mode
= IEEE80211_PROTMODE_RTSCTS
;
964 errx(1, "unknown protection mode");
967 set80211(s
, IEEE80211_IOC_PROTMODE
, mode
, 0, NULL
);
971 set80211htprotmode(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
975 if (iseq(val
, "off")) {
976 mode
= IEEE80211_PROTMODE_OFF
;
977 } else if (ismatch(val
, "rts")) {
978 mode
= IEEE80211_PROTMODE_RTSCTS
;
980 errx(1, "unknown protection mode");
983 set80211(s
, IEEE80211_IOC_HTPROTMODE
, mode
, 0, NULL
);
987 set80211txpower(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
989 double v
= atof(val
);
994 errx(-1, "invalid tx power (must be .5 dBm units)");
995 set80211(s
, IEEE80211_IOC_TXPOWER
, txpow
, 0, NULL
);
998 #define IEEE80211_ROAMING_DEVICE 0
999 #define IEEE80211_ROAMING_AUTO 1
1000 #define IEEE80211_ROAMING_MANUAL 2
1003 set80211roaming(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1007 if (iseq(val
, "device")) {
1008 mode
= IEEE80211_ROAMING_DEVICE
;
1009 } else if (iseq(val
, "auto")) {
1010 mode
= IEEE80211_ROAMING_AUTO
;
1011 } else if (iseq(val
, "manual")) {
1012 mode
= IEEE80211_ROAMING_MANUAL
;
1014 errx(1, "unknown roaming mode");
1016 set80211(s
, IEEE80211_IOC_ROAMING
, mode
, 0, NULL
);
1020 set80211wme(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1022 set80211(s
, IEEE80211_IOC_WME
, d
, 0, NULL
);
1026 set80211hidessid(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1028 set80211(s
, IEEE80211_IOC_HIDESSID
, d
, 0, NULL
);
1032 set80211apbridge(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1034 set80211(s
, IEEE80211_IOC_APBRIDGE
, d
, 0, NULL
);
1038 set80211fastframes(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1040 set80211(s
, IEEE80211_IOC_FF
, d
, 0, NULL
);
1044 set80211dturbo(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1046 set80211(s
, IEEE80211_IOC_TURBOP
, d
, 0, NULL
);
1050 set80211chanlist(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1052 struct ieee80211req_chanlist chanlist
;
1053 char *temp
, *cp
, *tp
;
1057 errx(1, "strdup failed");
1058 memset(&chanlist
, 0, sizeof(chanlist
));
1061 int first
, last
, f
, c
;
1063 tp
= strchr(cp
, ',');
1066 switch (sscanf(cp
, "%u-%u", &first
, &last
)) {
1068 if (first
> IEEE80211_CHAN_MAX
)
1069 errx(-1, "channel %u out of range, max %u",
1070 first
, IEEE80211_CHAN_MAX
);
1071 setbit(chanlist
.ic_channels
, first
);
1074 if (first
> IEEE80211_CHAN_MAX
)
1075 errx(-1, "channel %u out of range, max %u",
1076 first
, IEEE80211_CHAN_MAX
);
1077 if (last
> IEEE80211_CHAN_MAX
)
1078 errx(-1, "channel %u out of range, max %u",
1079 last
, IEEE80211_CHAN_MAX
);
1081 errx(-1, "void channel range, %u > %u",
1083 for (f
= first
; f
<= last
; f
++)
1084 setbit(chanlist
.ic_channels
, f
);
1096 set80211(s
, IEEE80211_IOC_CHANLIST
, 0, sizeof(chanlist
), &chanlist
);
1100 set80211bssid(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1103 if (!isanyarg(val
)) {
1105 struct sockaddr_dl sdl
;
1107 temp
= malloc(strlen(val
) + 2); /* ':' and '\0' */
1109 errx(1, "malloc failed");
1111 strcpy(temp
+ 1, val
);
1112 sdl
.sdl_len
= sizeof(sdl
);
1113 link_addr(temp
, &sdl
);
1115 if (sdl
.sdl_alen
!= IEEE80211_ADDR_LEN
)
1116 errx(1, "malformed link-level address");
1117 set80211(s
, IEEE80211_IOC_BSSID
, 0,
1118 IEEE80211_ADDR_LEN
, LLADDR(&sdl
));
1120 uint8_t zerobssid
[IEEE80211_ADDR_LEN
];
1121 memset(zerobssid
, 0, sizeof(zerobssid
));
1122 set80211(s
, IEEE80211_IOC_BSSID
, 0,
1123 IEEE80211_ADDR_LEN
, zerobssid
);
1128 getac(const char *ac
)
1130 if (iseq(ac
, "ac_be") || iseq(ac
, "be"))
1132 if (iseq(ac
, "ac_bk") || iseq(ac
, "bk"))
1134 if (iseq(ac
, "ac_vi") || iseq(ac
, "vi"))
1136 if (iseq(ac
, "ac_vo") || iseq(ac
, "vo"))
1138 errx(1, "unknown wme access class %s", ac
);
1142 DECL_CMD_FUNC2(set80211cwmin
, ac
, val
)
1144 set80211(s
, IEEE80211_IOC_WME_CWMIN
, atoi(val
), getac(ac
), NULL
);
1148 DECL_CMD_FUNC2(set80211cwmax
, ac
, val
)
1150 set80211(s
, IEEE80211_IOC_WME_CWMAX
, atoi(val
), getac(ac
), NULL
);
1154 DECL_CMD_FUNC2(set80211aifs
, ac
, val
)
1156 set80211(s
, IEEE80211_IOC_WME_AIFS
, atoi(val
), getac(ac
), NULL
);
1160 DECL_CMD_FUNC2(set80211txoplimit
, ac
, val
)
1162 set80211(s
, IEEE80211_IOC_WME_TXOPLIMIT
, atoi(val
), getac(ac
), NULL
);
1166 DECL_CMD_FUNC(set80211acm
, ac
, d
)
1168 set80211(s
, IEEE80211_IOC_WME_ACM
, 1, getac(ac
), NULL
);
1171 DECL_CMD_FUNC(set80211noacm
, ac
, d
)
1173 set80211(s
, IEEE80211_IOC_WME_ACM
, 0, getac(ac
), NULL
);
1177 DECL_CMD_FUNC(set80211ackpolicy
, ac
, d
)
1179 set80211(s
, IEEE80211_IOC_WME_ACKPOLICY
, 1, getac(ac
), NULL
);
1182 DECL_CMD_FUNC(set80211noackpolicy
, ac
, d
)
1184 set80211(s
, IEEE80211_IOC_WME_ACKPOLICY
, 0, getac(ac
), NULL
);
1188 DECL_CMD_FUNC2(set80211bsscwmin
, ac
, val
)
1190 set80211(s
, IEEE80211_IOC_WME_CWMIN
, atoi(val
),
1191 getac(ac
)|IEEE80211_WMEPARAM_BSS
, NULL
);
1195 DECL_CMD_FUNC2(set80211bsscwmax
, ac
, val
)
1197 set80211(s
, IEEE80211_IOC_WME_CWMAX
, atoi(val
),
1198 getac(ac
)|IEEE80211_WMEPARAM_BSS
, NULL
);
1202 DECL_CMD_FUNC2(set80211bssaifs
, ac
, val
)
1204 set80211(s
, IEEE80211_IOC_WME_AIFS
, atoi(val
),
1205 getac(ac
)|IEEE80211_WMEPARAM_BSS
, NULL
);
1209 DECL_CMD_FUNC2(set80211bsstxoplimit
, ac
, val
)
1211 set80211(s
, IEEE80211_IOC_WME_TXOPLIMIT
, atoi(val
),
1212 getac(ac
)|IEEE80211_WMEPARAM_BSS
, NULL
);
1216 DECL_CMD_FUNC(set80211dtimperiod
, val
, d
)
1218 set80211(s
, IEEE80211_IOC_DTIM_PERIOD
, atoi(val
), 0, NULL
);
1222 DECL_CMD_FUNC(set80211bintval
, val
, d
)
1224 set80211(s
, IEEE80211_IOC_BEACON_INTERVAL
, atoi(val
), 0, NULL
);
1228 set80211macmac(int s
, int op
, const char *val
)
1231 struct sockaddr_dl sdl
;
1233 temp
= malloc(strlen(val
) + 2); /* ':' and '\0' */
1235 errx(1, "malloc failed");
1237 strcpy(temp
+ 1, val
);
1238 sdl
.sdl_len
= sizeof(sdl
);
1239 link_addr(temp
, &sdl
);
1241 if (sdl
.sdl_alen
!= IEEE80211_ADDR_LEN
)
1242 errx(1, "malformed link-level address");
1243 set80211(s
, op
, 0, IEEE80211_ADDR_LEN
, LLADDR(&sdl
));
1247 DECL_CMD_FUNC(set80211addmac
, val
, d
)
1249 set80211macmac(s
, IEEE80211_IOC_ADDMAC
, val
);
1253 DECL_CMD_FUNC(set80211delmac
, val
, d
)
1255 set80211macmac(s
, IEEE80211_IOC_DELMAC
, val
);
1259 DECL_CMD_FUNC(set80211kickmac
, val
, d
)
1262 struct sockaddr_dl sdl
;
1263 struct ieee80211req_mlme mlme
;
1265 temp
= malloc(strlen(val
) + 2); /* ':' and '\0' */
1267 errx(1, "malloc failed");
1269 strcpy(temp
+ 1, val
);
1270 sdl
.sdl_len
= sizeof(sdl
);
1271 link_addr(temp
, &sdl
);
1273 if (sdl
.sdl_alen
!= IEEE80211_ADDR_LEN
)
1274 errx(1, "malformed link-level address");
1275 memset(&mlme
, 0, sizeof(mlme
));
1276 mlme
.im_op
= IEEE80211_MLME_DEAUTH
;
1277 mlme
.im_reason
= IEEE80211_REASON_AUTH_EXPIRE
;
1278 memcpy(mlme
.im_macaddr
, LLADDR(&sdl
), IEEE80211_ADDR_LEN
);
1279 set80211(s
, IEEE80211_IOC_MLME
, 0, sizeof(mlme
), &mlme
);
1283 DECL_CMD_FUNC(set80211maccmd
, val
, d
)
1285 set80211(s
, IEEE80211_IOC_MACCMD
, d
, 0, NULL
);
1289 set80211meshrtmac(int s
, int req
, const char *val
)
1292 struct sockaddr_dl sdl
;
1294 temp
= malloc(strlen(val
) + 2); /* ':' and '\0' */
1296 errx(1, "malloc failed");
1298 strcpy(temp
+ 1, val
);
1299 sdl
.sdl_len
= sizeof(sdl
);
1300 link_addr(temp
, &sdl
);
1302 if (sdl
.sdl_alen
!= IEEE80211_ADDR_LEN
)
1303 errx(1, "malformed link-level address");
1304 set80211(s
, IEEE80211_IOC_MESH_RTCMD
, req
,
1305 IEEE80211_ADDR_LEN
, LLADDR(&sdl
));
1309 DECL_CMD_FUNC(set80211addmeshrt
, val
, d
)
1311 set80211meshrtmac(s
, IEEE80211_MESH_RTCMD_ADD
, val
);
1315 DECL_CMD_FUNC(set80211delmeshrt
, val
, d
)
1317 set80211meshrtmac(s
, IEEE80211_MESH_RTCMD_DELETE
, val
);
1321 DECL_CMD_FUNC(set80211meshrtcmd
, val
, d
)
1323 set80211(s
, IEEE80211_IOC_MESH_RTCMD
, d
, 0, NULL
);
1327 DECL_CMD_FUNC(set80211hwmprootmode
, val
, d
)
1331 if (iseq(val
, "normal"))
1332 mode
= IEEE80211_HWMP_ROOTMODE_NORMAL
;
1333 else if (iseq(val
, "proactive"))
1334 mode
= IEEE80211_HWMP_ROOTMODE_PROACTIVE
;
1335 else if (iseq(val
, "rann"))
1336 mode
= IEEE80211_HWMP_ROOTMODE_RANN
;
1338 mode
= IEEE80211_HWMP_ROOTMODE_DISABLED
;
1339 set80211(s
, IEEE80211_IOC_HWMP_ROOTMODE
, mode
, 0, NULL
);
1343 DECL_CMD_FUNC(set80211hwmpmaxhops
, val
, d
)
1345 set80211(s
, IEEE80211_IOC_HWMP_MAXHOPS
, atoi(val
), 0, NULL
);
1349 set80211pureg(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1351 set80211(s
, IEEE80211_IOC_PUREG
, d
, 0, NULL
);
1355 set80211bgscan(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1357 set80211(s
, IEEE80211_IOC_BGSCAN
, d
, 0, NULL
);
1361 DECL_CMD_FUNC(set80211bgscanidle
, val
, d
)
1363 set80211(s
, IEEE80211_IOC_BGSCAN_IDLE
, atoi(val
), 0, NULL
);
1367 DECL_CMD_FUNC(set80211bgscanintvl
, val
, d
)
1369 set80211(s
, IEEE80211_IOC_BGSCAN_INTERVAL
, atoi(val
), 0, NULL
);
1373 DECL_CMD_FUNC(set80211scanvalid
, val
, d
)
1375 set80211(s
, IEEE80211_IOC_SCANVALID
, atoi(val
), 0, NULL
);
1379 * Parse an optional trailing specification of which netbands
1380 * to apply a parameter to. This is basically the same syntax
1381 * as used for channels but you can concatenate to specify
1382 * multiple. For example:
1383 * 14:abg apply to 11a, 11b, and 11g
1384 * 6:ht apply to 11na and 11ng
1385 * We don't make a big effort to catch silly things; this is
1386 * really a convenience mechanism.
1389 getmodeflags(const char *val
)
1396 cp
= strchr(val
, ':');
1398 for (cp
++; isalpha((int) *cp
); cp
++) {
1399 /* accept mixed case */
1404 case 'a': /* 802.11a */
1405 flags
|= IEEE80211_CHAN_A
;
1407 case 'b': /* 802.11b */
1408 flags
|= IEEE80211_CHAN_B
;
1410 case 'g': /* 802.11g */
1411 flags
|= IEEE80211_CHAN_G
;
1413 case 'n': /* 802.11n */
1414 flags
|= IEEE80211_CHAN_HT
;
1416 case 'd': /* dt = Atheros Dynamic Turbo */
1417 flags
|= IEEE80211_CHAN_TURBO
;
1419 case 't': /* ht, dt, st, t */
1420 /* dt and unadorned t specify Dynamic Turbo */
1421 if ((flags
& (IEEE80211_CHAN_STURBO
|IEEE80211_CHAN_HT
)) == 0)
1422 flags
|= IEEE80211_CHAN_TURBO
;
1424 case 's': /* st = Atheros Static Turbo */
1425 flags
|= IEEE80211_CHAN_STURBO
;
1427 case 'h': /* 1/2-width channels */
1428 flags
|= IEEE80211_CHAN_HALF
;
1430 case 'q': /* 1/4-width channels */
1431 flags
|= IEEE80211_CHAN_QUARTER
;
1434 errx(-1, "%s: Invalid mode attribute %c\n",
1442 #define _APPLY(_flags, _base, _param, _v) do { \
1443 if (_flags & IEEE80211_CHAN_HT) { \
1444 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1445 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1446 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1447 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1448 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1450 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1452 if (_flags & IEEE80211_CHAN_TURBO) { \
1453 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\
1454 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1455 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1456 } else if (_flags & IEEE80211_CHAN_5GHZ) \
1457 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1459 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1461 if (_flags & IEEE80211_CHAN_STURBO) \
1462 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1463 if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1464 _base.params[IEEE80211_MODE_11A]._param = _v; \
1465 if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1466 _base.params[IEEE80211_MODE_11G]._param = _v; \
1467 if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1468 _base.params[IEEE80211_MODE_11B]._param = _v; \
1469 if (_flags & IEEE80211_CHAN_HALF) \
1470 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1471 if (_flags & IEEE80211_CHAN_QUARTER) \
1472 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1474 #define _APPLY1(_flags, _base, _param, _v) do { \
1475 if (_flags & IEEE80211_CHAN_HT) { \
1476 if (_flags & IEEE80211_CHAN_5GHZ) \
1477 _base.params[IEEE80211_MODE_11NA]._param = _v; \
1479 _base.params[IEEE80211_MODE_11NG]._param = _v; \
1480 } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \
1481 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \
1482 else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \
1483 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \
1484 else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \
1485 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \
1486 else if (_flags & IEEE80211_CHAN_HALF) \
1487 _base.params[IEEE80211_MODE_HALF]._param = _v; \
1488 else if (_flags & IEEE80211_CHAN_QUARTER) \
1489 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \
1490 else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \
1491 _base.params[IEEE80211_MODE_11A]._param = _v; \
1492 else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \
1493 _base.params[IEEE80211_MODE_11G]._param = _v; \
1494 else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \
1495 _base.params[IEEE80211_MODE_11B]._param = _v; \
1497 #define _APPLY_RATE(_flags, _base, _param, _v) do { \
1498 if (_flags & IEEE80211_CHAN_HT) { \
1499 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1501 _APPLY(_flags, _base, _param, _v); \
1503 #define _APPLY_RATE1(_flags, _base, _param, _v) do { \
1504 if (_flags & IEEE80211_CHAN_HT) { \
1505 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \
1507 _APPLY1(_flags, _base, _param, _v); \
1511 DECL_CMD_FUNC(set80211roamrssi
, val
, d
)
1513 double v
= atof(val
);
1518 errx(-1, "invalid rssi (must be .5 dBm units)");
1519 flags
= getmodeflags(val
);
1521 if (flags
== 0) { /* NB: no flags => current channel */
1522 flags
= getcurchan(s
)->ic_flags
;
1523 _APPLY1(flags
, roamparams
, rssi
, rssi
);
1525 _APPLY(flags
, roamparams
, rssi
, rssi
);
1526 callback_register(setroam_cb
, &roamparams
);
1530 getrate(const char *val
, const char *tag
)
1532 double v
= atof(val
);
1537 errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag
);
1538 return rate
; /* NB: returns 2x the specified value */
1542 DECL_CMD_FUNC(set80211roamrate
, val
, d
)
1546 rate
= getrate(val
, "roam");
1547 flags
= getmodeflags(val
);
1549 if (flags
== 0) { /* NB: no flags => current channel */
1550 flags
= getcurchan(s
)->ic_flags
;
1551 _APPLY_RATE1(flags
, roamparams
, rate
, rate
);
1553 _APPLY_RATE(flags
, roamparams
, rate
, rate
);
1554 callback_register(setroam_cb
, &roamparams
);
1558 DECL_CMD_FUNC(set80211mcastrate
, val
, d
)
1562 rate
= getrate(val
, "mcast");
1563 flags
= getmodeflags(val
);
1565 if (flags
== 0) { /* NB: no flags => current channel */
1566 flags
= getcurchan(s
)->ic_flags
;
1567 _APPLY_RATE1(flags
, txparams
, mcastrate
, rate
);
1569 _APPLY_RATE(flags
, txparams
, mcastrate
, rate
);
1570 callback_register(settxparams_cb
, &txparams
);
1574 DECL_CMD_FUNC(set80211mgtrate
, val
, d
)
1578 rate
= getrate(val
, "mgmt");
1579 flags
= getmodeflags(val
);
1581 if (flags
== 0) { /* NB: no flags => current channel */
1582 flags
= getcurchan(s
)->ic_flags
;
1583 _APPLY_RATE1(flags
, txparams
, mgmtrate
, rate
);
1585 _APPLY_RATE(flags
, txparams
, mgmtrate
, rate
);
1586 callback_register(settxparams_cb
, &txparams
);
1590 DECL_CMD_FUNC(set80211ucastrate
, val
, d
)
1595 flags
= getmodeflags(val
);
1596 if (isanyarg(val
)) {
1597 if (flags
== 0) { /* NB: no flags => current channel */
1598 flags
= getcurchan(s
)->ic_flags
;
1599 _APPLY1(flags
, txparams
, ucastrate
,
1600 IEEE80211_FIXED_RATE_NONE
);
1602 _APPLY(flags
, txparams
, ucastrate
,
1603 IEEE80211_FIXED_RATE_NONE
);
1605 int rate
= getrate(val
, "ucast");
1606 if (flags
== 0) { /* NB: no flags => current channel */
1607 flags
= getcurchan(s
)->ic_flags
;
1608 _APPLY_RATE1(flags
, txparams
, ucastrate
, rate
);
1610 _APPLY_RATE(flags
, txparams
, ucastrate
, rate
);
1612 callback_register(settxparams_cb
, &txparams
);
1616 DECL_CMD_FUNC(set80211maxretry
, val
, d
)
1618 int v
= atoi(val
), flags
;
1620 flags
= getmodeflags(val
);
1622 if (flags
== 0) { /* NB: no flags => current channel */
1623 flags
= getcurchan(s
)->ic_flags
;
1624 _APPLY1(flags
, txparams
, maxretry
, v
);
1626 _APPLY(flags
, txparams
, maxretry
, v
);
1627 callback_register(settxparams_cb
, &txparams
);
1633 DECL_CMD_FUNC(set80211fragthreshold
, val
, d
)
1635 set80211(s
, IEEE80211_IOC_FRAGTHRESHOLD
,
1636 isundefarg(val
) ? IEEE80211_FRAG_MAX
: atoi(val
), 0, NULL
);
1640 DECL_CMD_FUNC(set80211bmissthreshold
, val
, d
)
1642 set80211(s
, IEEE80211_IOC_BMISSTHRESHOLD
,
1643 isundefarg(val
) ? IEEE80211_HWBMISS_MAX
: atoi(val
), 0, NULL
);
1647 set80211burst(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1649 set80211(s
, IEEE80211_IOC_BURST
, d
, 0, NULL
);
1653 set80211doth(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1655 set80211(s
, IEEE80211_IOC_DOTH
, d
, 0, NULL
);
1659 set80211dfs(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1661 set80211(s
, IEEE80211_IOC_DFS
, d
, 0, NULL
);
1665 set80211shortgi(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1667 set80211(s
, IEEE80211_IOC_SHORTGI
,
1668 d
? (IEEE80211_HTCAP_SHORTGI20
| IEEE80211_HTCAP_SHORTGI40
) : 0,
1673 set80211ampdu(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1677 if (get80211val(s
, IEEE80211_IOC_AMPDU
, &du
) < 0)
1678 errx(-1, "cannot get AMPDU setting");
1684 set80211(s
, IEEE80211_IOC_AMPDU
, ampdu
, 0, NULL
);
1688 DECL_CMD_FUNC(set80211ampdulimit
, val
, d
)
1692 switch (atoi(val
)) {
1695 v
= IEEE80211_HTCAP_MAXRXAMPDU_8K
;
1699 v
= IEEE80211_HTCAP_MAXRXAMPDU_16K
;
1703 v
= IEEE80211_HTCAP_MAXRXAMPDU_32K
;
1707 v
= IEEE80211_HTCAP_MAXRXAMPDU_64K
;
1710 errx(-1, "invalid A-MPDU limit %s", val
);
1712 set80211(s
, IEEE80211_IOC_AMPDU_LIMIT
, v
, 0, NULL
);
1716 DECL_CMD_FUNC(set80211ampdudensity
, val
, d
)
1720 if (isanyarg(val
) || iseq(val
, "na"))
1721 v
= IEEE80211_HTCAP_MPDUDENSITY_NA
;
1722 else switch ((int)(atof(val
)*4)) {
1724 v
= IEEE80211_HTCAP_MPDUDENSITY_NA
;
1727 v
= IEEE80211_HTCAP_MPDUDENSITY_025
;
1730 v
= IEEE80211_HTCAP_MPDUDENSITY_05
;
1733 v
= IEEE80211_HTCAP_MPDUDENSITY_1
;
1736 v
= IEEE80211_HTCAP_MPDUDENSITY_2
;
1739 v
= IEEE80211_HTCAP_MPDUDENSITY_4
;
1742 v
= IEEE80211_HTCAP_MPDUDENSITY_8
;
1745 v
= IEEE80211_HTCAP_MPDUDENSITY_16
;
1748 errx(-1, "invalid A-MPDU density %s", val
);
1750 set80211(s
, IEEE80211_IOC_AMPDU_DENSITY
, v
, 0, NULL
);
1754 set80211amsdu(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1758 if (get80211val(s
, IEEE80211_IOC_AMSDU
, &amsdu
) < 0)
1759 err(-1, "cannot get AMSDU setting");
1765 set80211(s
, IEEE80211_IOC_AMSDU
, amsdu
, 0, NULL
);
1769 DECL_CMD_FUNC(set80211amsdulimit
, val
, d
)
1771 set80211(s
, IEEE80211_IOC_AMSDU_LIMIT
, atoi(val
), 0, NULL
);
1775 set80211puren(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1777 set80211(s
, IEEE80211_IOC_PUREN
, d
, 0, NULL
);
1781 set80211htcompat(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1783 set80211(s
, IEEE80211_IOC_HTCOMPAT
, d
, 0, NULL
);
1787 set80211htconf(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1789 set80211(s
, IEEE80211_IOC_HTCONF
, d
, 0, NULL
);
1794 set80211dwds(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1796 set80211(s
, IEEE80211_IOC_DWDS
, d
, 0, NULL
);
1800 set80211inact(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1802 set80211(s
, IEEE80211_IOC_INACTIVITY
, d
, 0, NULL
);
1806 set80211tsn(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1808 set80211(s
, IEEE80211_IOC_TSN
, d
, 0, NULL
);
1812 set80211dotd(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1814 set80211(s
, IEEE80211_IOC_DOTD
, d
, 0, NULL
);
1818 set80211smps(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1820 set80211(s
, IEEE80211_IOC_SMPS
, d
, 0, NULL
);
1824 set80211rifs(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1826 set80211(s
, IEEE80211_IOC_RIFS
, d
, 0, NULL
);
1830 DECL_CMD_FUNC(set80211tdmaslot
, val
, d
)
1832 set80211(s
, IEEE80211_IOC_TDMA_SLOT
, atoi(val
), 0, NULL
);
1836 DECL_CMD_FUNC(set80211tdmaslotcnt
, val
, d
)
1838 set80211(s
, IEEE80211_IOC_TDMA_SLOTCNT
, atoi(val
), 0, NULL
);
1842 DECL_CMD_FUNC(set80211tdmaslotlen
, val
, d
)
1844 set80211(s
, IEEE80211_IOC_TDMA_SLOTLEN
, atoi(val
), 0, NULL
);
1848 DECL_CMD_FUNC(set80211tdmabintval
, val
, d
)
1850 set80211(s
, IEEE80211_IOC_TDMA_BINTERVAL
, atoi(val
), 0, NULL
);
1854 DECL_CMD_FUNC(set80211meshttl
, val
, d
)
1856 set80211(s
, IEEE80211_IOC_MESH_TTL
, atoi(val
), 0, NULL
);
1860 DECL_CMD_FUNC(set80211meshforward
, val
, d
)
1862 set80211(s
, IEEE80211_IOC_MESH_FWRD
, atoi(val
), 0, NULL
);
1866 DECL_CMD_FUNC(set80211meshpeering
, val
, d
)
1868 set80211(s
, IEEE80211_IOC_MESH_AP
, atoi(val
), 0, NULL
);
1872 DECL_CMD_FUNC(set80211meshmetric
, val
, d
)
1876 memcpy(v
, val
, sizeof(v
));
1877 set80211(s
, IEEE80211_IOC_MESH_PR_METRIC
, 0, 0, v
);
1881 DECL_CMD_FUNC(set80211meshpath
, val
, d
)
1885 memcpy(v
, val
, sizeof(v
));
1886 set80211(s
, IEEE80211_IOC_MESH_PR_PATH
, 0, 0, v
);
1890 regdomain_sort(const void *a
, const void *b
)
1893 (IEEE80211_CHAN_ALLTURBO|IEEE80211_CHAN_HALF|IEEE80211_CHAN_QUARTER)
1894 const struct ieee80211_channel
*ca
= a
;
1895 const struct ieee80211_channel
*cb
= b
;
1897 return ca
->ic_freq
== cb
->ic_freq
?
1898 ((int)ca
->ic_flags
& CHAN_ALL
) - ((int)cb
->ic_flags
& CHAN_ALL
) :
1899 ca
->ic_freq
- cb
->ic_freq
;
1903 static const struct ieee80211_channel
*
1904 chanlookup(const struct ieee80211_channel chans
[], int nchans
,
1905 int freq
, int flags
)
1909 flags
&= IEEE80211_CHAN_ALLTURBO
;
1910 for (i
= 0; i
< nchans
; i
++) {
1911 const struct ieee80211_channel
*c
= &chans
[i
];
1912 if (c
->ic_freq
== freq
&&
1913 ((int)c
->ic_flags
& IEEE80211_CHAN_ALLTURBO
) == flags
)
1920 chanfind(const struct ieee80211_channel chans
[], int nchans
, int flags
)
1924 for (i
= 0; i
< nchans
; i
++) {
1925 const struct ieee80211_channel
*c
= &chans
[i
];
1926 if (((int)c
->ic_flags
& flags
) == flags
)
1933 * Check channel compatibility.
1936 checkchan(const struct ieee80211req_chaninfo
*avail
, int freq
, int flags
)
1938 flags
&= ~REQ_FLAGS
;
1940 * Check if exact channel is in the calibration table;
1941 * everything below is to deal with channels that we
1942 * want to include but that are not explicitly listed.
1944 if (flags
& IEEE80211_CHAN_HT40
) {
1945 /* NB: we use an HT40 channel center that matches HT20 */
1946 flags
= (flags
&~ IEEE80211_CHAN_HT40
) | IEEE80211_CHAN_HT20
;
1948 if (chanlookup(avail
->ic_chans
, avail
->ic_nchans
, freq
, flags
) != NULL
)
1950 if (flags
& IEEE80211_CHAN_GSM
) {
1952 * XXX GSM frequency mapping is handled in the kernel
1953 * so we cannot find them in the calibration table;
1954 * just accept the channel and the kernel will reject
1955 * the channel list if it's wrong.
1960 * If this is a 1/2 or 1/4 width channel allow it if a full
1961 * width channel is present for this frequency, and the device
1962 * supports fractional channels on this band. This is a hack
1963 * that avoids bloating the calibration table; it may be better
1964 * by per-band attributes though (we are effectively calculating
1965 * this attribute by scanning the channel list ourself).
1967 if ((flags
& (IEEE80211_CHAN_HALF
| IEEE80211_CHAN_QUARTER
)) == 0)
1969 if (chanlookup(avail
->ic_chans
, avail
->ic_nchans
, freq
,
1970 flags
&~ (IEEE80211_CHAN_HALF
| IEEE80211_CHAN_QUARTER
)) == NULL
)
1972 if (flags
& IEEE80211_CHAN_HALF
) {
1973 return chanfind(avail
->ic_chans
, avail
->ic_nchans
,
1974 IEEE80211_CHAN_HALF
|
1975 (flags
& (IEEE80211_CHAN_2GHZ
| IEEE80211_CHAN_5GHZ
)));
1977 return chanfind(avail
->ic_chans
, avail
->ic_nchans
,
1978 IEEE80211_CHAN_QUARTER
|
1979 (flags
& (IEEE80211_CHAN_2GHZ
| IEEE80211_CHAN_5GHZ
)));
1984 regdomain_addchans(struct ieee80211req_chaninfo
*ci
,
1985 const netband_head
*bands
,
1986 const struct ieee80211_regdomain
*reg
,
1988 const struct ieee80211req_chaninfo
*avail
)
1990 const struct netband
*nb
;
1991 const struct freqband
*b
;
1992 struct ieee80211_channel
*c
, *prev
;
1993 int freq
, hi_adj
, lo_adj
, channelSep
;
1996 hi_adj
= (chanFlags
& IEEE80211_CHAN_HT40U
) ? -20 : 0;
1997 lo_adj
= (chanFlags
& IEEE80211_CHAN_HT40D
) ? 20 : 0;
1998 channelSep
= (chanFlags
& IEEE80211_CHAN_2GHZ
) ? 0 : 40;
1999 LIST_FOREACH(nb
, bands
, next
) {
2002 printf("%s:", __func__
);
2003 printb(" chanFlags", chanFlags
, IEEE80211_CHAN_BITS
);
2004 printb(" bandFlags", nb
->flags
| b
->flags
,
2005 IEEE80211_CHAN_BITS
);
2009 for (freq
= b
->freqStart
+ lo_adj
;
2010 freq
<= b
->freqEnd
+ hi_adj
; freq
+= b
->chanSep
) {
2012 * Construct flags for the new channel. We take
2013 * the attributes from the band descriptions except
2014 * for HT40 which is enabled generically (i.e. +/-
2015 * extension channel) in the band description and
2016 * then constrained according by channel separation.
2018 flags
= nb
->flags
| b
->flags
;
2019 if (flags
& IEEE80211_CHAN_HT
) {
2021 * HT channels are generated specially; we're
2022 * called to add HT20, HT40+, and HT40- chan's
2023 * so we need to expand only band specs for
2024 * the HT channel type being added.
2026 if ((chanFlags
& IEEE80211_CHAN_HT20
) &&
2027 (flags
& IEEE80211_CHAN_HT20
) == 0) {
2029 printf("%u: skip, not an "
2030 "HT20 channel\n", freq
);
2033 if ((chanFlags
& IEEE80211_CHAN_HT40
) &&
2034 (flags
& IEEE80211_CHAN_HT40
) == 0) {
2036 printf("%u: skip, not an "
2037 "HT40 channel\n", freq
);
2041 * DFS and HT40 don't mix. This should be
2042 * expressed in the regdomain database but
2043 * just in case enforce it here.
2045 if ((chanFlags
& IEEE80211_CHAN_HT40
) &&
2046 (flags
& IEEE80211_CHAN_DFS
)) {
2048 printf("%u: skip, HT40+DFS "
2049 "not permitted\n", freq
);
2052 /* NB: HT attribute comes from caller */
2053 flags
&= ~IEEE80211_CHAN_HT
;
2054 flags
|= chanFlags
& IEEE80211_CHAN_HT
;
2057 * Check if device can operate on this frequency.
2059 if (!checkchan(avail
, freq
, flags
)) {
2061 printf("%u: skip, ", freq
);
2062 printb("flags", flags
,
2063 IEEE80211_CHAN_BITS
);
2064 printf(" not available\n");
2068 if ((flags
& REQ_ECM
) && !reg
->ecm
) {
2070 printf("%u: skip, ECM channel\n", freq
);
2073 if ((flags
& REQ_INDOOR
) && reg
->location
== 'O') {
2075 printf("%u: skip, indoor channel\n",
2079 if ((flags
& REQ_OUTDOOR
) && reg
->location
== 'I') {
2081 printf("%u: skip, outdoor channel\n",
2085 if ((flags
& IEEE80211_CHAN_HT40
) &&
2086 prev
!= NULL
&& (freq
- prev
->ic_freq
) < channelSep
) {
2088 printf("%u: skip, only %u channel "
2089 "separation, need %d\n", freq
,
2090 freq
- prev
->ic_freq
, channelSep
);
2093 if (ci
->ic_nchans
== IEEE80211_CHAN_MAX
) {
2095 printf("%u: skip, channel table full\n",
2099 c
= &ci
->ic_chans
[ci
->ic_nchans
++];
2100 memset(c
, 0, sizeof(*c
));
2102 c
->ic_flags
= flags
;
2103 if (c
->ic_flags
& IEEE80211_CHAN_DFS
)
2104 c
->ic_maxregpower
= nb
->maxPowerDFS
;
2106 c
->ic_maxregpower
= nb
->maxPower
;
2108 printf("[%3d] add freq %u ",
2109 ci
->ic_nchans
-1, c
->ic_freq
);
2110 printb("flags", c
->ic_flags
, IEEE80211_CHAN_BITS
);
2111 printf(" power %u\n", c
->ic_maxregpower
);
2113 /* NB: kernel fills in other fields */
2120 regdomain_makechannels(
2121 struct ieee80211_regdomain_req
*req
,
2122 const struct ieee80211_devcaps_req
*dc
)
2124 struct regdata
*rdp
= getregdata();
2125 const struct country
*cc
;
2126 const struct ieee80211_regdomain
*reg
= &req
->rd
;
2127 struct ieee80211req_chaninfo
*ci
= &req
->chaninfo
;
2128 const struct regdomain
*rd
;
2131 * Locate construction table for new channel list. We treat
2132 * the regdomain/SKU as definitive so a country can be in
2133 * multiple with different properties (e.g. US in FCC+FCC3).
2134 * If no regdomain is specified then we fallback on the country
2135 * code to find the associated regdomain since countries always
2136 * belong to at least one regdomain.
2138 if (reg
->regdomain
== 0) {
2139 cc
= lib80211_country_findbycc(rdp
, reg
->country
);
2141 errx(1, "internal error, country %d not found",
2145 rd
= lib80211_regdomain_findbysku(rdp
, reg
->regdomain
);
2147 errx(1, "internal error, regdomain %d not found",
2149 if (rd
->sku
!= SKU_DEBUG
) {
2151 * regdomain_addchans incrememnts the channel count for
2152 * each channel it adds so initialize ic_nchans to zero.
2153 * Note that we know we have enough space to hold all possible
2154 * channels because the devcaps list size was used to
2155 * allocate our request.
2158 if (!LIST_EMPTY(&rd
->bands_11b
))
2159 regdomain_addchans(ci
, &rd
->bands_11b
, reg
,
2160 IEEE80211_CHAN_B
, &dc
->dc_chaninfo
);
2161 if (!LIST_EMPTY(&rd
->bands_11g
))
2162 regdomain_addchans(ci
, &rd
->bands_11g
, reg
,
2163 IEEE80211_CHAN_G
, &dc
->dc_chaninfo
);
2164 if (!LIST_EMPTY(&rd
->bands_11a
))
2165 regdomain_addchans(ci
, &rd
->bands_11a
, reg
,
2166 IEEE80211_CHAN_A
, &dc
->dc_chaninfo
);
2167 if (!LIST_EMPTY(&rd
->bands_11na
) && dc
->dc_htcaps
!= 0) {
2168 regdomain_addchans(ci
, &rd
->bands_11na
, reg
,
2169 IEEE80211_CHAN_A
| IEEE80211_CHAN_HT20
,
2171 if (dc
->dc_htcaps
& IEEE80211_HTCAP_CHWIDTH40
) {
2172 regdomain_addchans(ci
, &rd
->bands_11na
, reg
,
2173 IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40U
,
2175 regdomain_addchans(ci
, &rd
->bands_11na
, reg
,
2176 IEEE80211_CHAN_A
| IEEE80211_CHAN_HT40D
,
2180 if (!LIST_EMPTY(&rd
->bands_11ng
) && dc
->dc_htcaps
!= 0) {
2181 regdomain_addchans(ci
, &rd
->bands_11ng
, reg
,
2182 IEEE80211_CHAN_G
| IEEE80211_CHAN_HT20
,
2184 if (dc
->dc_htcaps
& IEEE80211_HTCAP_CHWIDTH40
) {
2185 regdomain_addchans(ci
, &rd
->bands_11ng
, reg
,
2186 IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40U
,
2188 regdomain_addchans(ci
, &rd
->bands_11ng
, reg
,
2189 IEEE80211_CHAN_G
| IEEE80211_CHAN_HT40D
,
2193 qsort(ci
->ic_chans
, ci
->ic_nchans
, sizeof(ci
->ic_chans
[0]),
2196 memcpy(ci
, &dc
->dc_chaninfo
,
2197 IEEE80211_CHANINFO_SPACE(&dc
->dc_chaninfo
));
2201 list_countries(void)
2203 struct regdata
*rdp
= getregdata();
2204 const struct country
*cp
;
2205 const struct regdomain
*dp
;
2209 printf("\nCountry codes:\n");
2210 LIST_FOREACH(cp
, &rdp
->countries
, next
) {
2211 printf("%2s %-15.15s%s", cp
->isoname
,
2212 cp
->name
, ((i
+1)%4) == 0 ? "\n" : " ");
2216 printf("\nRegulatory domains:\n");
2217 LIST_FOREACH(dp
, &rdp
->domains
, next
) {
2218 printf("%-15.15s%s", dp
->name
, ((i
+1)%4) == 0 ? "\n" : " ");
2225 defaultcountry(const struct regdomain
*rd
)
2227 struct regdata
*rdp
= getregdata();
2228 const struct country
*cc
;
2230 cc
= lib80211_country_findbycc(rdp
, rd
->cc
->code
);
2232 errx(1, "internal error, ISO country code %d not "
2233 "defined for regdomain %s", rd
->cc
->code
, rd
->name
);
2234 regdomain
.country
= cc
->code
;
2235 regdomain
.isocc
[0] = cc
->isoname
[0];
2236 regdomain
.isocc
[1] = cc
->isoname
[1];
2240 DECL_CMD_FUNC(set80211regdomain
, val
, d
)
2242 struct regdata
*rdp
= getregdata();
2243 const struct regdomain
*rd
;
2245 rd
= lib80211_regdomain_findbyname(rdp
, val
);
2248 long sku
= strtol(val
, &eptr
, 0);
2251 rd
= lib80211_regdomain_findbysku(rdp
, sku
);
2252 if (eptr
== val
|| rd
== NULL
)
2253 errx(1, "unknown regdomain %s", val
);
2256 regdomain
.regdomain
= rd
->sku
;
2257 if (regdomain
.country
== 0 && rd
->cc
!= NULL
) {
2259 * No country code setup and there's a default
2260 * one for this regdomain fill it in.
2264 callback_register(setregdomain_cb
, ®domain
);
2268 DECL_CMD_FUNC(set80211country
, val
, d
)
2270 struct regdata
*rdp
= getregdata();
2271 const struct country
*cc
;
2273 cc
= lib80211_country_findbyname(rdp
, val
);
2276 long code
= strtol(val
, &eptr
, 0);
2279 cc
= lib80211_country_findbycc(rdp
, code
);
2280 if (eptr
== val
|| cc
== NULL
)
2281 errx(1, "unknown ISO country code %s", val
);
2284 regdomain
.regdomain
= cc
->rd
->sku
;
2285 regdomain
.country
= cc
->code
;
2286 regdomain
.isocc
[0] = cc
->isoname
[0];
2287 regdomain
.isocc
[1] = cc
->isoname
[1];
2288 callback_register(setregdomain_cb
, ®domain
);
2292 set80211location(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
2295 regdomain
.location
= d
;
2296 callback_register(setregdomain_cb
, ®domain
);
2300 set80211ecm(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
2304 callback_register(setregdomain_cb
, ®domain
);
2320 if (spacer
!= '\t') {
2324 col
= 8; /* 8-col tab */
2328 LINE_CHECK(const char *fmt
, ...)
2335 n
= vsnprintf(buf
+1, sizeof(buf
)-1, fmt
, ap
);
2348 getmaxrate(const uint8_t rates
[15], uint8_t nrates
)
2350 int i
, maxrate
= -1;
2352 for (i
= 0; i
< nrates
; i
++) {
2353 int rate
= rates
[i
] & IEEE80211_RATE_VAL
;
2361 getcaps(int capinfo
)
2363 static char capstring
[32];
2364 char *cp
= capstring
;
2366 if (capinfo
& IEEE80211_CAPINFO_ESS
)
2368 if (capinfo
& IEEE80211_CAPINFO_IBSS
)
2370 if (capinfo
& IEEE80211_CAPINFO_CF_POLLABLE
)
2372 if (capinfo
& IEEE80211_CAPINFO_CF_POLLREQ
)
2374 if (capinfo
& IEEE80211_CAPINFO_PRIVACY
)
2376 if (capinfo
& IEEE80211_CAPINFO_SHORT_PREAMBLE
)
2378 if (capinfo
& IEEE80211_CAPINFO_PBCC
)
2380 if (capinfo
& IEEE80211_CAPINFO_CHNL_AGILITY
)
2382 if (capinfo
& IEEE80211_CAPINFO_SHORT_SLOTTIME
)
2384 if (capinfo
& IEEE80211_CAPINFO_RSN
)
2386 if (capinfo
& IEEE80211_CAPINFO_DSSSOFDM
)
2395 static char flagstring
[32];
2396 char *cp
= flagstring
;
2398 if (flags
& IEEE80211_NODE_AUTH
)
2400 if (flags
& IEEE80211_NODE_QOS
)
2402 if (flags
& IEEE80211_NODE_ERP
)
2404 if (flags
& IEEE80211_NODE_PWR_MGT
)
2406 if (flags
& IEEE80211_NODE_HT
) {
2408 if (flags
& IEEE80211_NODE_HTCOMPAT
)
2411 if (flags
& IEEE80211_NODE_WPS
)
2413 if (flags
& IEEE80211_NODE_TSN
)
2415 if (flags
& IEEE80211_NODE_AMPDU_TX
)
2417 if (flags
& IEEE80211_NODE_AMPDU_RX
)
2419 if (flags
& IEEE80211_NODE_MIMO_PS
) {
2421 if (flags
& IEEE80211_NODE_MIMO_RTS
)
2424 if (flags
& IEEE80211_NODE_RIFS
)
2426 if (flags
& IEEE80211_NODE_SGI40
) {
2428 if (flags
& IEEE80211_NODE_SGI20
)
2430 } else if (flags
& IEEE80211_NODE_SGI20
)
2432 if (flags
& IEEE80211_NODE_AMSDU_TX
)
2434 if (flags
& IEEE80211_NODE_AMSDU_RX
)
2441 printie(const char* tag
, const uint8_t *ie
, size_t ielen
, int maxlen
)
2445 maxlen
-= strlen(tag
)+2;
2446 if (2*ielen
> (size_t)maxlen
)
2449 for (; ielen
> 0; ie
++, ielen
--) {
2452 printf("%02x", *ie
);
2460 #define LE_READ_2(p) \
2462 ((((const u_int8_t *)(p))[0] ) | \
2463 (((const u_int8_t *)(p))[1] << 8)))
2464 #define LE_READ_4(p) \
2466 ((((const u_int8_t *)(p))[0] ) | \
2467 (((const u_int8_t *)(p))[1] << 8) | \
2468 (((const u_int8_t *)(p))[2] << 16) | \
2469 (((const u_int8_t *)(p))[3] << 24)))
2472 * NB: The decoding routines assume a properly formatted ie
2473 * which should be safe as the kernel only retains them
2478 printwmeparam(const char *tag
, const u_int8_t
*ie
, size_t ielen
, int maxlen
)
2480 #define MS(_v, _f) (((_v) & _f) >> _f##_S)
2481 static const char *acnames
[] = { "BE", "BK", "VO", "VI" };
2482 const struct ieee80211_wme_param
*wme
=
2483 (const struct ieee80211_wme_param
*) ie
;
2489 printf("<qosinfo 0x%x", wme
->param_qosInfo
);
2490 ie
+= offsetof(struct ieee80211_wme_param
, params_acParams
);
2491 for (i
= 0; i
< WME_NUM_AC
; i
++) {
2492 const struct ieee80211_wme_acparams
*ac
=
2493 &wme
->params_acParams
[i
];
2495 printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]"
2497 , MS(ac
->acp_aci_aifsn
, WME_PARAM_ACM
) ? "acm " : ""
2498 , MS(ac
->acp_aci_aifsn
, WME_PARAM_AIFSN
)
2499 , MS(ac
->acp_logcwminmax
, WME_PARAM_LOGCWMIN
)
2500 , MS(ac
->acp_logcwminmax
, WME_PARAM_LOGCWMAX
)
2501 , LE_READ_2(&ac
->acp_txop
)
2509 printwmeinfo(const char *tag
, const u_int8_t
*ie
, size_t ielen
, int maxlen
)
2513 const struct ieee80211_wme_info
*wme
=
2514 (const struct ieee80211_wme_info
*) ie
;
2515 printf("<version 0x%x info 0x%x>",
2516 wme
->wme_version
, wme
->wme_info
);
2521 printhtcap(const char *tag
, const u_int8_t
*ie
, size_t ielen
, int maxlen
)
2525 const struct ieee80211_ie_htcap
*htcap
=
2526 (const struct ieee80211_ie_htcap
*) ie
;
2530 printf("<cap 0x%x param 0x%x",
2531 LE_READ_2(&htcap
->hc_cap
), htcap
->hc_param
);
2534 for (i
= 0; i
< IEEE80211_HTRATE_MAXSIZE
; i
++)
2535 if (isset(htcap
->hc_mcsset
, i
)) {
2536 for (j
= i
+1; j
< IEEE80211_HTRATE_MAXSIZE
; j
++)
2537 if (isclr(htcap
->hc_mcsset
, j
))
2541 printf("%s%u", sep
, i
);
2543 printf("%s%u-%u", sep
, i
, j
);
2547 printf("] extcap 0x%x txbf 0x%x antenna 0x%x>",
2548 LE_READ_2(&htcap
->hc_extcap
),
2549 LE_READ_4(&htcap
->hc_txbf
),
2555 printhtinfo(const char *tag
, const u_int8_t
*ie
, size_t ielen
, int maxlen
)
2559 const struct ieee80211_ie_htinfo
*htinfo
=
2560 (const struct ieee80211_ie_htinfo
*) ie
;
2564 printf("<ctl %u, %x,%x,%x,%x", htinfo
->hi_ctrlchannel
,
2565 htinfo
->hi_byte1
, htinfo
->hi_byte2
, htinfo
->hi_byte3
,
2566 LE_READ_2(&htinfo
->hi_byte45
));
2567 printf(" basicmcs[");
2569 for (i
= 0; i
< IEEE80211_HTRATE_MAXSIZE
; i
++)
2570 if (isset(htinfo
->hi_basicmcsset
, i
)) {
2571 for (j
= i
+1; j
< IEEE80211_HTRATE_MAXSIZE
; j
++)
2572 if (isclr(htinfo
->hi_basicmcsset
, j
))
2576 printf("%s%u", sep
, i
);
2578 printf("%s%u-%u", sep
, i
, j
);
2587 printathie(const char *tag
, const u_int8_t
*ie
, size_t ielen
, int maxlen
)
2592 const struct ieee80211_ath_ie
*ath
=
2593 (const struct ieee80211_ath_ie
*)ie
;
2596 if (ath
->ath_capability
& ATHEROS_CAP_TURBO_PRIME
)
2598 if (ath
->ath_capability
& ATHEROS_CAP_COMPRESSION
)
2600 if (ath
->ath_capability
& ATHEROS_CAP_FAST_FRAME
)
2602 if (ath
->ath_capability
& ATHEROS_CAP_XR
)
2604 if (ath
->ath_capability
& ATHEROS_CAP_AR
)
2606 if (ath
->ath_capability
& ATHEROS_CAP_BURST
)
2608 if (ath
->ath_capability
& ATHEROS_CAP_WME
)
2610 if (ath
->ath_capability
& ATHEROS_CAP_BOOST
)
2612 printf("0x%x>", LE_READ_2(ath
->ath_defkeyix
));
2618 printmeshconf(const char *tag
, const uint8_t *ie
, size_t ielen
, int maxlen
)
2620 #define MATCHOUI(field, oui, string) \
2622 if (memcmp(field, oui, 4) == 0) \
2623 printf("%s", string); \
2628 const struct ieee80211_meshconf_ie
*mconf
=
2629 (const struct ieee80211_meshconf_ie
*)ie
;
2631 if (mconf
->conf_pselid
== IEEE80211_MESHCONF_PATH_HWMP
)
2636 if (mconf
->conf_pmetid
== IEEE80211_MESHCONF_METRIC_AIRTIME
)
2640 printf(" CONGESTION:");
2641 if (mconf
->conf_ccid
== IEEE80211_MESHCONF_CC_DISABLED
)
2646 if (mconf
->conf_syncid
== IEEE80211_MESHCONF_SYNC_NEIGHOFF
)
2651 if (mconf
->conf_authid
== IEEE80211_MESHCONF_AUTH_DISABLED
)
2655 printf(" FORM:0x%x CAPS:0x%x>", mconf
->conf_form
,
2662 wpa_cipher(const u_int8_t
*sel
)
2664 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2665 u_int32_t w
= LE_READ_4(sel
);
2668 case WPA_SEL(WPA_CSE_NULL
):
2670 case WPA_SEL(WPA_CSE_WEP40
):
2672 case WPA_SEL(WPA_CSE_WEP104
):
2674 case WPA_SEL(WPA_CSE_TKIP
):
2676 case WPA_SEL(WPA_CSE_CCMP
):
2679 return "?"; /* NB: so 1<< is discarded */
2684 wpa_keymgmt(const u_int8_t
*sel
)
2686 #define WPA_SEL(x) (((x)<<24)|WPA_OUI)
2687 u_int32_t w
= LE_READ_4(sel
);
2690 case WPA_SEL(WPA_ASE_8021X_UNSPEC
):
2691 return "8021X-UNSPEC";
2692 case WPA_SEL(WPA_ASE_8021X_PSK
):
2694 case WPA_SEL(WPA_ASE_NONE
):
2702 printwpaie(const char *tag
, const u_int8_t
*ie
, size_t ielen
, int maxlen
)
2704 u_int8_t len
= ie
[1];
2711 ie
+= 6, len
-= 4; /* NB: len is payload only */
2713 printf("<v%u", LE_READ_2(ie
));
2716 printf(" mc:%s", wpa_cipher(ie
));
2719 /* unicast ciphers */
2723 for (; n
> 0; n
--) {
2724 printf("%s%s", sep
, wpa_cipher(ie
));
2729 /* key management algorithms */
2733 for (; n
> 0; n
--) {
2734 printf("%s%s", sep
, wpa_keymgmt(ie
));
2739 if (len
> 2) /* optional capabilities */
2740 printf(", caps 0x%x", LE_READ_2(ie
));
2746 rsn_cipher(const u_int8_t
*sel
)
2748 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
2749 u_int32_t w
= LE_READ_4(sel
);
2752 case RSN_SEL(RSN_CSE_NULL
):
2754 case RSN_SEL(RSN_CSE_WEP40
):
2756 case RSN_SEL(RSN_CSE_WEP104
):
2758 case RSN_SEL(RSN_CSE_TKIP
):
2760 case RSN_SEL(RSN_CSE_CCMP
):
2762 case RSN_SEL(RSN_CSE_WRAP
):
2770 rsn_keymgmt(const u_int8_t
*sel
)
2772 #define RSN_SEL(x) (((x)<<24)|RSN_OUI)
2773 u_int32_t w
= LE_READ_4(sel
);
2776 case RSN_SEL(RSN_ASE_8021X_UNSPEC
):
2777 return "8021X-UNSPEC";
2778 case RSN_SEL(RSN_ASE_8021X_PSK
):
2780 case RSN_SEL(RSN_ASE_NONE
):
2788 printrsnie(const char *tag
, const u_int8_t
*ie
, size_t ielen
, int maxlen
)
2795 ie
+= 2, ielen
-= 2;
2797 printf("<v%u", LE_READ_2(ie
));
2798 ie
+= 2, ielen
-= 2;
2800 printf(" mc:%s", rsn_cipher(ie
));
2801 ie
+= 4, ielen
-= 4;
2803 /* unicast ciphers */
2805 ie
+= 2, ielen
-= 2;
2807 for (; n
> 0; n
--) {
2808 printf("%s%s", sep
, rsn_cipher(ie
));
2809 ie
+= 4, ielen
-= 4;
2813 /* key management algorithms */
2815 ie
+= 2, ielen
-= 2;
2817 for (; n
> 0; n
--) {
2818 printf("%s%s", sep
, rsn_keymgmt(ie
));
2819 ie
+= 4, ielen
-= 4;
2823 if (ielen
> 2) /* optional capabilities */
2824 printf(", caps 0x%x", LE_READ_2(ie
));
2830 #define BE_READ_2(p) \
2832 ((((const u_int8_t *)(p))[1] ) | \
2833 (((const u_int8_t *)(p))[0] << 8)))
2836 printwpsie(const char *tag
, const u_int8_t
*ie
, size_t ielen
, int maxlen
)
2838 u_int8_t len
= ie
[1];
2847 static const char *dev_pass_id
[] = {
2848 "D", /* Default (PIN) */
2849 "U", /* User-specified */
2850 "M", /* Machine-specified */
2852 "P", /* PushButton */
2853 "R" /* Registrar-specified */
2856 ie
+=6, len
-= 4; /* NB: len is payload only */
2858 /* WPS IE in Beacon and Probe Resp frames have different fields */
2861 tlv_type
= BE_READ_2(ie
);
2862 tlv_len
= BE_READ_2(ie
+ 2);
2864 /* some devices broadcast invalid WPS frames */
2865 if (tlv_len
> len
) {
2866 printf("bad frame length tlv_type=0x%02x "
2867 "tlv_len=%d len=%d", tlv_type
, tlv_len
,
2875 case IEEE80211_WPS_ATTR_VERSION
:
2876 printf("v:%d.%d", *ie
>> 4, *ie
& 0xf);
2878 case IEEE80211_WPS_ATTR_AP_SETUP_LOCKED
:
2879 printf(" ap_setup:%s", *ie
? "locked" :
2882 case IEEE80211_WPS_ATTR_CONFIG_METHODS
:
2883 case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS
:
2884 if (tlv_type
== IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS
)
2885 printf(" sel_reg_cfg_mthd:");
2887 printf(" cfg_mthd:" );
2888 cfg_mthd
= BE_READ_2(ie
);
2890 for (n
= 15; n
>= 0; n
--) {
2895 switch (cfg_mthd
& (1 << n
)) {
2898 case IEEE80211_WPS_CONFIG_USBA
:
2902 case IEEE80211_WPS_CONFIG_ETHERNET
:
2906 case IEEE80211_WPS_CONFIG_LABEL
:
2910 case IEEE80211_WPS_CONFIG_DISPLAY
:
2912 (IEEE80211_WPS_CONFIG_VIRT_DISPLAY
|
2913 IEEE80211_WPS_CONFIG_PHY_DISPLAY
)))
2919 case IEEE80211_WPS_CONFIG_EXT_NFC_TOKEN
:
2920 printf("ext_nfc_tokenk");
2923 case IEEE80211_WPS_CONFIG_INT_NFC_TOKEN
:
2924 printf("int_nfc_token");
2927 case IEEE80211_WPS_CONFIG_NFC_INTERFACE
:
2928 printf("nfc_interface");
2931 case IEEE80211_WPS_CONFIG_PUSHBUTTON
:
2933 (IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON
|
2934 IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON
))) {
2935 printf("push_button");
2939 case IEEE80211_WPS_CONFIG_KEYPAD
:
2943 case IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON
:
2944 printf("virtual_push_button");
2947 case IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON
:
2948 printf("physical_push_button");
2951 case IEEE80211_WPS_CONFIG_P2PS
:
2955 case IEEE80211_WPS_CONFIG_VIRT_DISPLAY
:
2956 printf("virtual_display");
2959 case IEEE80211_WPS_CONFIG_PHY_DISPLAY
:
2960 printf("physical_display");
2964 printf("unknown_wps_config<%04x>",
2965 cfg_mthd
& (1 << n
));
2971 case IEEE80211_WPS_ATTR_DEV_NAME
:
2972 printf(" device_name:<%.*s>", tlv_len
, ie
);
2974 case IEEE80211_WPS_ATTR_DEV_PASSWORD_ID
:
2976 if (n
< (int)nitems(dev_pass_id
))
2977 printf(" dpi:%s", dev_pass_id
[n
]);
2979 case IEEE80211_WPS_ATTR_MANUFACTURER
:
2980 printf(" manufacturer:<%.*s>", tlv_len
, ie
);
2982 case IEEE80211_WPS_ATTR_MODEL_NAME
:
2983 printf(" model_name:<%.*s>", tlv_len
, ie
);
2985 case IEEE80211_WPS_ATTR_MODEL_NUMBER
:
2986 printf(" model_number:<%.*s>", tlv_len
, ie
);
2988 case IEEE80211_WPS_ATTR_PRIMARY_DEV_TYPE
:
2989 printf(" prim_dev:");
2990 for (n
= 0; n
< tlv_len
; n
++)
2991 printf("%02x", ie
[n
]);
2993 case IEEE80211_WPS_ATTR_RF_BANDS
:
2996 for (n
= 7; n
>= 0; n
--) {
3001 switch (*ie
& (1 << n
)) {
3004 case IEEE80211_WPS_RF_BAND_24GHZ
:
3008 case IEEE80211_WPS_RF_BAND_50GHZ
:
3012 case IEEE80211_WPS_RF_BAND_600GHZ
:
3017 printf("unknown<%02x>",
3024 case IEEE80211_WPS_ATTR_RESPONSE_TYPE
:
3025 printf(" resp_type:0x%02x", *ie
);
3027 case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR
:
3028 printf(" sel:%s", *ie
? "T" : "F");
3030 case IEEE80211_WPS_ATTR_SERIAL_NUMBER
:
3031 printf(" serial_number:<%.*s>", tlv_len
, ie
);
3033 case IEEE80211_WPS_ATTR_UUID_E
:
3035 for (n
= 0; n
< (tlv_len
- 1); n
++)
3036 printf("%02x-", ie
[n
]);
3037 printf("%02x", ie
[n
]);
3039 case IEEE80211_WPS_ATTR_VENDOR_EXT
:
3041 for (n
= 0; n
< tlv_len
; n
++)
3042 printf("%02x", ie
[n
]);
3044 case IEEE80211_WPS_ATTR_WPS_STATE
:
3046 case IEEE80211_WPS_STATE_NOT_CONFIGURED
:
3049 case IEEE80211_WPS_STATE_CONFIGURED
:
3053 printf(" state:B<%02x>", *ie
);
3058 printf(" unknown_wps_attr:0x%x", tlv_type
);
3061 ie
+= tlv_len
, len
-= tlv_len
;
3068 printtdmaie(const char *tag
, const u_int8_t
*ie
, size_t ielen
, int maxlen
)
3071 if (verbose
&& ielen
>= sizeof(struct ieee80211_tdma_param
)) {
3072 const struct ieee80211_tdma_param
*tdma
=
3073 (const struct ieee80211_tdma_param
*) ie
;
3076 printf("<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>",
3077 tdma
->tdma_version
, tdma
->tdma_slot
, tdma
->tdma_slotcnt
,
3078 LE_READ_2(&tdma
->tdma_slotlen
), tdma
->tdma_bintval
,
3079 tdma
->tdma_inuse
[0]);
3084 * Copy the ssid string contents into buf, truncating to fit. If the
3085 * ssid is entirely printable then just copy intact. Otherwise convert
3086 * to hexadecimal. If the result is truncated then replace the last
3087 * three characters with "...".
3090 copy_essid(char buf
[], size_t bufsize
, const u_int8_t
*essid
, size_t essid_len
)
3096 if (essid_len
> bufsize
)
3100 /* determine printable or not */
3101 for (i
= 0, p
= essid
; i
< maxlen
; i
++, p
++) {
3102 if (*p
< ' ' || *p
> 0x7e)
3105 if (i
!= maxlen
) { /* not printable, print as hex */
3108 strlcpy(buf
, "0x", bufsize
);
3111 for (i
= 0; i
< maxlen
&& bufsize
>= 2; i
++) {
3112 sprintf(&buf
[2+2*i
], "%02x", p
[i
]);
3116 memcpy(&buf
[2+2*i
-3], "...", 3);
3117 } else { /* printable, truncate as needed */
3118 memcpy(buf
, essid
, maxlen
);
3119 if (maxlen
!= essid_len
)
3120 memcpy(&buf
[maxlen
-3], "...", 3);
3126 printssid(const char *tag
, const u_int8_t
*ie
, size_t ielen
, int maxlen
)
3128 char ssid
[2*IEEE80211_NWID_LEN
+1];
3130 printf("%s<%.*s>", tag
, copy_essid(ssid
, maxlen
, ie
+2, ie
[1]), ssid
);
3134 printrates(const char *tag
, const u_int8_t
*ie
, size_t ielen
,
3135 __unused
int maxlen
)
3142 for (i
= 2; i
< ielen
; i
++) {
3143 printf("%s%s%d", sep
,
3144 ie
[i
] & IEEE80211_RATE_BASIC
? "B" : "",
3145 ie
[i
] & IEEE80211_RATE_VAL
);
3152 printcountry(const char *tag
, const u_int8_t
*ie
, size_t ielen
,
3153 __unused
int maxlen
)
3155 const struct ieee80211_country_ie
*cie
=
3156 (const struct ieee80211_country_ie
*) ie
;
3157 size_t i
, nbands
, schan
, nchan
;
3159 printf("%s<%c%c%c", tag
, cie
->cc
[0], cie
->cc
[1], cie
->cc
[2]);
3160 nbands
= (cie
->len
- 3) / sizeof(cie
->band
[0]);
3161 for (i
= 0; i
< nbands
; i
++) {
3162 schan
= cie
->band
[i
].schan
;
3163 nchan
= cie
->band
[i
].nchan
;
3165 printf(" %zu-%zu,%u", schan
, schan
+ nchan
-1,
3166 cie
->band
[i
].maxtxpwr
);
3168 printf(" %zu,%u", schan
, cie
->band
[i
].maxtxpwr
);
3173 /* unaligned little endian access */
3174 #define LE_READ_4(p) \
3176 ((((const u_int8_t *)(p))[0] ) | \
3177 (((const u_int8_t *)(p))[1] << 8) | \
3178 (((const u_int8_t *)(p))[2] << 16) | \
3179 (((const u_int8_t *)(p))[3] << 24)))
3182 iswpaoui(const u_int8_t
*frm
)
3184 return frm
[1] > 3 && LE_READ_4(frm
+2) == ((WPA_OUI_TYPE
<<24)|WPA_OUI
);
3188 iswmeinfo(const u_int8_t
*frm
)
3190 return frm
[1] > 5 && LE_READ_4(frm
+2) == ((WME_OUI_TYPE
<<24)|WME_OUI
) &&
3191 frm
[6] == WME_INFO_OUI_SUBTYPE
;
3195 iswmeparam(const u_int8_t
*frm
)
3197 return frm
[1] > 5 && LE_READ_4(frm
+2) == ((WME_OUI_TYPE
<<24)|WME_OUI
) &&
3198 frm
[6] == WME_PARAM_OUI_SUBTYPE
;
3202 isatherosoui(const u_int8_t
*frm
)
3204 return frm
[1] > 3 && LE_READ_4(frm
+2) == ((ATH_OUI_TYPE
<<24)|ATH_OUI
);
3208 istdmaoui(const uint8_t *frm
)
3210 return frm
[1] > 3 && LE_READ_4(frm
+2) == ((TDMA_OUI_TYPE
<<24)|TDMA_OUI
);
3214 iswpsoui(const uint8_t *frm
)
3216 return frm
[1] > 3 && LE_READ_4(frm
+2) == ((WPS_OUI_TYPE
<<24)|WPA_OUI
);
3222 static char iename_buf
[64];
3224 case IEEE80211_ELEMID_FHPARMS
: return " FHPARMS";
3225 case IEEE80211_ELEMID_CFPARMS
: return " CFPARMS";
3226 case IEEE80211_ELEMID_TIM
: return " TIM";
3227 case IEEE80211_ELEMID_IBSSPARMS
:return " IBSSPARMS";
3228 case IEEE80211_ELEMID_CHALLENGE
:return " CHALLENGE";
3229 case IEEE80211_ELEMID_PWRCNSTR
: return " PWRCNSTR";
3230 case IEEE80211_ELEMID_PWRCAP
: return " PWRCAP";
3231 case IEEE80211_ELEMID_TPCREQ
: return " TPCREQ";
3232 case IEEE80211_ELEMID_TPCREP
: return " TPCREP";
3233 case IEEE80211_ELEMID_SUPPCHAN
: return " SUPPCHAN";
3234 case IEEE80211_ELEMID_CSA
: return " CSA";
3235 case IEEE80211_ELEMID_MEASREQ
: return " MEASREQ";
3236 case IEEE80211_ELEMID_MEASREP
: return " MEASREP";
3237 case IEEE80211_ELEMID_QUIET
: return " QUIET";
3238 case IEEE80211_ELEMID_IBSSDFS
: return " IBSSDFS";
3239 case IEEE80211_ELEMID_RESERVED_47
:
3240 return " RESERVED_47";
3241 case IEEE80211_ELEMID_MOBILITY_DOMAIN
:
3242 return " MOBILITY_DOMAIN";
3243 case IEEE80211_ELEMID_RRM_ENACAPS
:
3244 return " RRM_ENCAPS";
3245 case IEEE80211_ELEMID_OVERLAP_BSS_SCAN_PARAM
:
3246 return " OVERLAP_BSS";
3247 case IEEE80211_ELEMID_TPC
: return " TPC";
3248 case IEEE80211_ELEMID_CCKM
: return " CCKM";
3249 case IEEE80211_ELEMID_EXTCAP
: return " EXTCAP";
3251 snprintf(iename_buf
, sizeof(iename_buf
), " UNKNOWN_ELEMID_%d",
3253 return (const char *) iename_buf
;
3257 printies(const u_int8_t
*vp
, int ielen
, int maxcols
)
3261 case IEEE80211_ELEMID_SSID
:
3263 printssid(" SSID", vp
, 2+vp
[1], maxcols
);
3265 case IEEE80211_ELEMID_RATES
:
3266 case IEEE80211_ELEMID_XRATES
:
3268 printrates(vp
[0] == IEEE80211_ELEMID_RATES
?
3269 " RATES" : " XRATES", vp
, 2+vp
[1], maxcols
);
3271 case IEEE80211_ELEMID_DSPARMS
:
3273 printf(" DSPARMS<%u>", vp
[2]);
3275 case IEEE80211_ELEMID_COUNTRY
:
3277 printcountry(" COUNTRY", vp
, 2+vp
[1], maxcols
);
3279 case IEEE80211_ELEMID_ERP
:
3281 printf(" ERP<0x%x>", vp
[2]);
3283 case IEEE80211_ELEMID_VENDOR
:
3285 printwpaie(" WPA", vp
, 2+vp
[1], maxcols
);
3286 else if (iswmeinfo(vp
))
3287 printwmeinfo(" WME", vp
, 2+vp
[1], maxcols
);
3288 else if (iswmeparam(vp
))
3289 printwmeparam(" WME", vp
, 2+vp
[1], maxcols
);
3290 else if (isatherosoui(vp
))
3291 printathie(" ATH", vp
, 2+vp
[1], maxcols
);
3292 else if (iswpsoui(vp
))
3293 printwpsie(" WPS", vp
, 2+vp
[1], maxcols
);
3294 else if (istdmaoui(vp
))
3295 printtdmaie(" TDMA", vp
, 2+vp
[1], maxcols
);
3297 printie(" VEN", vp
, 2+vp
[1], maxcols
);
3299 case IEEE80211_ELEMID_RSN
:
3300 printrsnie(" RSN", vp
, 2+vp
[1], maxcols
);
3302 case IEEE80211_ELEMID_HTCAP
:
3303 printhtcap(" HTCAP", vp
, 2+vp
[1], maxcols
);
3305 case IEEE80211_ELEMID_HTINFO
:
3307 printhtinfo(" HTINFO", vp
, 2+vp
[1], maxcols
);
3309 case IEEE80211_ELEMID_MESHID
:
3311 printssid(" MESHID", vp
, 2+vp
[1], maxcols
);
3313 case IEEE80211_ELEMID_MESHCONF
:
3314 printmeshconf(" MESHCONF", vp
, 2+vp
[1], maxcols
);
3318 printie(iename(vp
[0]), vp
, 2+vp
[1], maxcols
);
3327 printmimo(const struct ieee80211_mimo_info
*mi
)
3329 /* NB: don't muddy display unless there's something to show */
3330 if (mi
->rssi
[0] != 0 || mi
->rssi
[1] != 0 || mi
->rssi
[2] != 0) {
3331 /* XXX ignore EVM for now */
3332 printf(" (rssi %d:%d:%d nf %d:%d:%d)",
3333 mi
->rssi
[0], mi
->rssi
[1], mi
->rssi
[2],
3334 mi
->noise
[0], mi
->noise
[1], mi
->noise
[2]);
3339 list_scan(int s
, int long_ssids
)
3341 uint8_t buf
[24*1024];
3342 char ssid
[IEEE80211_NWID_LEN
+1];
3344 size_t len
, ssidmax
, idlen
;
3346 if (get80211len(s
, IEEE80211_IOC_SCAN_RESULTS
, buf
, sizeof(buf
), &len
) < 0)
3347 errx(1, "unable to get scan results");
3348 if (len
< sizeof(struct ieee80211req_scan_result
))
3353 ssidmax
= (verbose
|| long_ssids
) ? IEEE80211_NWID_LEN
- 1 : 14;
3354 printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n"
3355 , (int)ssidmax
, (int)ssidmax
, "SSID/MESH ID"
3365 const struct ieee80211req_scan_result
*sr
;
3366 const uint8_t *vp
, *idp
;
3368 sr
= (const struct ieee80211req_scan_result
*) cp
;
3369 vp
= cp
+ sr
->isr_ie_off
;
3370 if (sr
->isr_meshid_len
) {
3371 idp
= vp
+ sr
->isr_ssid_len
;
3372 idlen
= sr
->isr_meshid_len
;
3375 idlen
= sr
->isr_ssid_len
;
3377 printf("%-*.*s %s %3d %3dM %3d:%-3d %3d %-4.4s"
3379 , copy_essid(ssid
, ssidmax
, idp
, idlen
)
3381 , ether_ntoa((const struct ether_addr
*) sr
->isr_bssid
)
3382 , ieee80211_mhz2ieee(sr
->isr_freq
, sr
->isr_flags
)
3383 , getmaxrate(sr
->isr_rates
, sr
->isr_nrates
)
3384 , (sr
->isr_rssi
/2)+sr
->isr_noise
, sr
->isr_noise
3386 , getcaps(sr
->isr_capinfo
)
3388 printies(vp
+ sr
->isr_ssid_len
+ sr
->isr_meshid_len
,
3389 sr
->isr_ie_len
, 24);
3391 cp
+= sr
->isr_len
, len
-= sr
->isr_len
;
3392 } while (len
>= sizeof(struct ieee80211req_scan_result
));
3396 scan_and_wait(int s
)
3398 struct ieee80211_scan_req sr
;
3399 struct ieee80211req ireq
;
3402 sroute
= socket(PF_ROUTE
, SOCK_RAW
, 0);
3404 perror("socket(PF_ROUTE,SOCK_RAW)");
3407 memset(&ireq
, 0, sizeof(ireq
));
3408 strlcpy(ireq
.i_name
, name
, sizeof(ireq
.i_name
));
3409 ireq
.i_type
= IEEE80211_IOC_SCAN_REQ
;
3411 memset(&sr
, 0, sizeof(sr
));
3412 sr
.sr_flags
= IEEE80211_IOC_SCAN_ACTIVE
3413 | IEEE80211_IOC_SCAN_NOPICK
3414 | IEEE80211_IOC_SCAN_ONCE
;
3415 sr
.sr_duration
= IEEE80211_IOC_SCAN_FOREVER
;
3419 ireq
.i_len
= sizeof(sr
);
3420 /* NB: only root can trigger a scan so ignore errors */
3421 if (ioctl(s
, SIOCS80211
, &ireq
) >= 0) {
3423 struct if_announcemsghdr
*ifan
;
3424 struct rt_msghdr
*rtm
;
3427 if (read(sroute
, buf
, sizeof(buf
)) < 0) {
3428 perror("read(PF_ROUTE)");
3431 rtm
= (struct rt_msghdr
*) buf
;
3432 if (rtm
->rtm_version
!= RTM_VERSION
)
3434 ifan
= (struct if_announcemsghdr
*) rtm
;
3435 } while (rtm
->rtm_type
!= RTM_IEEE80211
||
3436 ifan
->ifan_what
!= RTM_IEEE80211_SCAN
);
3442 DECL_CMD_FUNC(set80211scan
, val
, d
)
3448 static enum ieee80211_opmode
get80211opmode(int s
);
3451 gettxseq(const struct ieee80211req_sta_info
*si
)
3455 if ((si
->isi_state
& IEEE80211_NODE_QOS
) == 0)
3456 return si
->isi_txseqs
[0];
3457 /* XXX not right but usually what folks want */
3459 for (i
= 0; i
< IEEE80211_TID_SIZE
; i
++)
3460 if (si
->isi_txseqs
[i
] > txseq
)
3461 txseq
= si
->isi_txseqs
[i
];
3466 getrxseq(const struct ieee80211req_sta_info
*si
)
3470 if ((si
->isi_state
& IEEE80211_NODE_QOS
) == 0)
3471 return si
->isi_rxseqs
[0];
3472 /* XXX not right but usually what folks want */
3474 for (i
= 0; i
< IEEE80211_TID_SIZE
; i
++)
3475 if (si
->isi_rxseqs
[i
] > rxseq
)
3476 rxseq
= si
->isi_rxseqs
[i
];
3481 list_stations(int s
)
3484 struct ieee80211req_sta_req req
;
3485 uint8_t buf
[24*1024];
3487 enum ieee80211_opmode opmode
= get80211opmode(s
);
3491 /* broadcast address =>'s get all stations */
3492 memset(u
.req
.is_u
.macaddr
, 0xff, IEEE80211_ADDR_LEN
);
3493 if (opmode
== IEEE80211_M_STA
) {
3495 * Get information about the associated AP.
3497 get80211(s
, IEEE80211_IOC_BSSID
,
3498 u
.req
.is_u
.macaddr
, IEEE80211_ADDR_LEN
);
3500 if (get80211len(s
, IEEE80211_IOC_STA_INFO
, &u
, sizeof(u
), &len
) < 0)
3501 errx(1, "unable to get station information");
3502 if (len
< sizeof(struct ieee80211req_sta_info
))
3507 if (opmode
== IEEE80211_M_MBSS
) {
3508 printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n"
3521 printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-7s\n"
3534 cp
= (const uint8_t *) u
.req
.info
;
3536 const struct ieee80211req_sta_info
*si
;
3538 si
= (const struct ieee80211req_sta_info
*) cp
;
3539 if (si
->isi_len
< sizeof(*si
))
3541 if (opmode
== IEEE80211_M_MBSS
) {
3542 printf("%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d"
3543 , ether_ntoa((const struct ether_addr
*)
3545 , ieee80211_mhz2ieee(si
->isi_freq
,
3549 , mesh_linkstate_string(si
->isi_peerstate
)
3557 printf("%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-7.7s"
3558 , ether_ntoa((const struct ether_addr
*)
3560 , IEEE80211_AID(si
->isi_associd
)
3561 , ieee80211_mhz2ieee(si
->isi_freq
,
3568 , getcaps(si
->isi_capinfo
)
3569 , getflags(si
->isi_state
)
3572 printies(cp
+ si
->isi_ie_off
, si
->isi_ie_len
, 24);
3573 printmimo(&si
->isi_mimo
);
3575 cp
+= si
->isi_len
, len
-= si
->isi_len
;
3576 } while (len
>= sizeof(struct ieee80211req_sta_info
));
3580 mesh_linkstate_string(uint8_t state
)
3582 static const char *state_names
[] = {
3591 if (state
>= nitems(state_names
)) {
3592 static char buf
[10];
3593 snprintf(buf
, sizeof(buf
), "#%u", state
);
3596 return state_names
[state
];
3601 get_chaninfo(const struct ieee80211_channel
*c
, int precise
,
3602 char buf
[], size_t bsize
)
3605 if (IEEE80211_IS_CHAN_FHSS(c
))
3606 strlcat(buf
, " FHSS", bsize
);
3607 if (IEEE80211_IS_CHAN_A(c
))
3608 strlcat(buf
, " 11a", bsize
);
3609 else if (IEEE80211_IS_CHAN_ANYG(c
))
3610 strlcat(buf
, " 11g", bsize
);
3611 else if (IEEE80211_IS_CHAN_B(c
))
3612 strlcat(buf
, " 11b", bsize
);
3613 if (IEEE80211_IS_CHAN_HALF(c
))
3614 strlcat(buf
, "/10MHz", bsize
);
3615 if (IEEE80211_IS_CHAN_QUARTER(c
))
3616 strlcat(buf
, "/5MHz", bsize
);
3617 if (IEEE80211_IS_CHAN_TURBO(c
))
3618 strlcat(buf
, " Turbo", bsize
);
3620 if (IEEE80211_IS_CHAN_HT20(c
))
3621 strlcat(buf
, " ht/20", bsize
);
3622 else if (IEEE80211_IS_CHAN_HT40D(c
))
3623 strlcat(buf
, " ht/40-", bsize
);
3624 else if (IEEE80211_IS_CHAN_HT40U(c
))
3625 strlcat(buf
, " ht/40+", bsize
);
3627 if (IEEE80211_IS_CHAN_HT(c
))
3628 strlcat(buf
, " ht", bsize
);
3634 print_chaninfo(const struct ieee80211_channel
*c
, int verb
)
3638 printf("Channel %3u : %u%c MHz%-14.14s",
3639 ieee80211_mhz2ieee(c
->ic_freq
, c
->ic_flags
), c
->ic_freq
,
3640 IEEE80211_IS_CHAN_PASSIVE(c
) ? '*' : ' ',
3641 get_chaninfo(c
, verb
, buf
, sizeof(buf
)));
3645 chanpref(const struct ieee80211_channel
*c
)
3647 if (IEEE80211_IS_CHAN_HT40(c
))
3649 if (IEEE80211_IS_CHAN_HT20(c
))
3651 if (IEEE80211_IS_CHAN_HALF(c
))
3653 if (IEEE80211_IS_CHAN_QUARTER(c
))
3655 if (IEEE80211_IS_CHAN_TURBO(c
))
3657 if (IEEE80211_IS_CHAN_A(c
))
3659 if (IEEE80211_IS_CHAN_G(c
))
3661 if (IEEE80211_IS_CHAN_B(c
))
3663 if (IEEE80211_IS_CHAN_PUREG(c
))
3669 print_channels(int s
, const struct ieee80211req_chaninfo
*chans
,
3670 int allchans
, int verb
)
3672 struct ieee80211req_chaninfo
*achans
;
3673 uint8_t reported
[IEEE80211_CHAN_BYTES
];
3674 const struct ieee80211_channel
*c
;
3677 achans
= malloc(IEEE80211_CHANINFO_SPACE(chans
));
3679 errx(1, "no space for active channel list");
3680 achans
->ic_nchans
= 0;
3681 memset(reported
, 0, sizeof(reported
));
3683 struct ieee80211req_chanlist active
;
3685 if (get80211(s
, IEEE80211_IOC_CHANLIST
, &active
, sizeof(active
)) < 0)
3686 errx(1, "unable to get active channel list");
3687 for (i
= 0; i
< chans
->ic_nchans
; i
++) {
3688 c
= &chans
->ic_chans
[i
];
3689 if (!isset(active
.ic_channels
, c
->ic_ieee
))
3692 * Suppress compatible duplicates unless
3693 * verbose. The kernel gives us it's
3694 * complete channel list which has separate
3695 * entries for 11g/11b and 11a/turbo.
3697 if (isset(reported
, c
->ic_ieee
) && !verb
) {
3698 /* XXX we assume duplicates are adjacent */
3699 achans
->ic_chans
[achans
->ic_nchans
-1] = *c
;
3701 achans
->ic_chans
[achans
->ic_nchans
++] = *c
;
3702 setbit(reported
, c
->ic_ieee
);
3706 for (i
= 0; i
< chans
->ic_nchans
; i
++) {
3707 c
= &chans
->ic_chans
[i
];
3708 /* suppress duplicates as above */
3709 if (isset(reported
, c
->ic_ieee
) && !verb
) {
3710 /* XXX we assume duplicates are adjacent */
3711 struct ieee80211_channel
*a
=
3712 &achans
->ic_chans
[achans
->ic_nchans
-1];
3713 if (chanpref(c
) > chanpref(a
))
3716 achans
->ic_chans
[achans
->ic_nchans
++] = *c
;
3717 setbit(reported
, c
->ic_ieee
);
3721 half
= achans
->ic_nchans
/ 2;
3722 if (achans
->ic_nchans
% 2)
3725 for (i
= 0; i
< achans
->ic_nchans
/ 2; i
++) {
3726 print_chaninfo(&achans
->ic_chans
[i
], verb
);
3727 print_chaninfo(&achans
->ic_chans
[half
+i
], verb
);
3730 if (achans
->ic_nchans
% 2) {
3731 print_chaninfo(&achans
->ic_chans
[i
], verb
);
3738 list_channels(int s
, int allchans
)
3741 print_channels(s
, chaninfo
, allchans
, verbose
);
3745 print_txpow(const struct ieee80211_channel
*c
)
3747 printf("Channel %3u : %u MHz %3.1f reg %2d ",
3748 c
->ic_ieee
, c
->ic_freq
,
3749 c
->ic_maxpower
/2., c
->ic_maxregpower
);
3753 print_txpow_verbose(const struct ieee80211_channel
*c
)
3755 print_chaninfo(c
, 1);
3756 printf("min %4.1f dBm max %3.1f dBm reg %2d dBm",
3757 c
->ic_minpower
/2., c
->ic_maxpower
/2., c
->ic_maxregpower
);
3758 /* indicate where regulatory cap limits power use */
3759 if (c
->ic_maxpower
> 2*c
->ic_maxregpower
)
3766 struct ieee80211req_chaninfo
*achans
;
3767 uint8_t reported
[IEEE80211_CHAN_BYTES
];
3768 struct ieee80211_channel
*c
, *prev
;
3772 achans
= malloc(IEEE80211_CHANINFO_SPACE(chaninfo
));
3774 errx(1, "no space for active channel list");
3775 achans
->ic_nchans
= 0;
3776 memset(reported
, 0, sizeof(reported
));
3777 for (i
= 0; i
< chaninfo
->ic_nchans
; i
++) {
3778 c
= &chaninfo
->ic_chans
[i
];
3779 /* suppress duplicates as above */
3780 if (isset(reported
, c
->ic_ieee
) && !verbose
) {
3781 /* XXX we assume duplicates are adjacent */
3782 prev
= &achans
->ic_chans
[achans
->ic_nchans
-1];
3783 /* display highest power on channel */
3784 if (c
->ic_maxpower
> prev
->ic_maxpower
)
3787 achans
->ic_chans
[achans
->ic_nchans
++] = *c
;
3788 setbit(reported
, c
->ic_ieee
);
3792 half
= achans
->ic_nchans
/ 2;
3793 if (achans
->ic_nchans
% 2)
3796 for (i
= 0; i
< achans
->ic_nchans
/ 2; i
++) {
3797 print_txpow(&achans
->ic_chans
[i
]);
3798 print_txpow(&achans
->ic_chans
[half
+i
]);
3801 if (achans
->ic_nchans
% 2) {
3802 print_txpow(&achans
->ic_chans
[i
]);
3806 for (i
= 0; i
< achans
->ic_nchans
; i
++) {
3807 print_txpow_verbose(&achans
->ic_chans
[i
]);
3819 #define IEEE80211_C_BITS \
3820 "\20\1STA\002803ENCAP\7FF\10TURBOP\11IBSS\12PMGT" \
3821 "\13HOSTAP\14AHDEMO\15SWRETRY\16TXPMGT\17SHSLOT\20SHPREAMBLE" \
3822 "\21MONITOR\22DFS\23MBSS\30WPA1\31WPA2\32BURST\33WME\34WDS\36BGSCAN" \
3826 list_capabilities(int s
)
3828 struct ieee80211_devcaps_req
*dc
;
3831 dc
= malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN
));
3833 dc
= malloc(IEEE80211_DEVCAPS_SIZE(1));
3835 errx(1, "no space for device capabilities");
3836 dc
->dc_chaninfo
.ic_nchans
= verbose
? MAXCHAN
: 1;
3838 printb("drivercaps", dc
->dc_drivercaps
, IEEE80211_C_BITS
);
3839 if (dc
->dc_cryptocaps
!= 0 || verbose
) {
3841 printb("cryptocaps", dc
->dc_cryptocaps
, IEEE80211_CRYPTO_BITS
);
3843 if (dc
->dc_htcaps
!= 0 || verbose
) {
3845 printb("htcaps", dc
->dc_htcaps
, IEEE80211_HTCAP_BITS
);
3849 chaninfo
= &dc
->dc_chaninfo
; /* XXX */
3850 print_channels(s
, &dc
->dc_chaninfo
, 1/*allchans*/, verbose
);
3856 get80211wme(int s
, int param
, int ac
, int *val
)
3858 struct ieee80211req ireq
;
3860 memset(&ireq
, 0, sizeof(ireq
));
3861 strlcpy(ireq
.i_name
, name
, sizeof(ireq
.i_name
));
3862 ireq
.i_type
= param
;
3864 if (ioctl(s
, SIOCG80211
, &ireq
) < 0) {
3865 warn("cannot get WME parameter %d, ac %d%s",
3866 param
, ac
& IEEE80211_WMEPARAM_VAL
,
3867 ac
& IEEE80211_WMEPARAM_BSS
? " (BSS)" : "");
3875 list_wme_aci(int s
, const char *tag
, int ac
)
3879 printf("\t%s", tag
);
3881 /* show WME BSS parameters */
3882 if (get80211wme(s
, IEEE80211_IOC_WME_CWMIN
, ac
, &val
) != -1)
3883 printf(" cwmin %2u", val
);
3884 if (get80211wme(s
, IEEE80211_IOC_WME_CWMAX
, ac
, &val
) != -1)
3885 printf(" cwmax %2u", val
);
3886 if (get80211wme(s
, IEEE80211_IOC_WME_AIFS
, ac
, &val
) != -1)
3887 printf(" aifs %2u", val
);
3888 if (get80211wme(s
, IEEE80211_IOC_WME_TXOPLIMIT
, ac
, &val
) != -1)
3889 printf(" txopLimit %3u", val
);
3890 if (get80211wme(s
, IEEE80211_IOC_WME_ACM
, ac
, &val
) != -1) {
3897 if ((ac
& IEEE80211_WMEPARAM_BSS
) == 0) {
3898 if (get80211wme(s
, IEEE80211_IOC_WME_ACKPOLICY
, ac
, &val
) != -1) {
3911 static const char *acnames
[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" };
3915 /* display both BSS and local settings */
3916 for (ac
= WME_AC_BE
; ac
<= WME_AC_VO
; ac
++) {
3918 if (ac
& IEEE80211_WMEPARAM_BSS
)
3919 list_wme_aci(s
, " ", ac
);
3921 list_wme_aci(s
, acnames
[ac
], ac
);
3922 if ((ac
& IEEE80211_WMEPARAM_BSS
) == 0) {
3923 ac
|= IEEE80211_WMEPARAM_BSS
;
3926 ac
&= ~IEEE80211_WMEPARAM_BSS
;
3929 /* display only channel settings */
3930 for (ac
= WME_AC_BE
; ac
<= WME_AC_VO
; ac
++)
3931 list_wme_aci(s
, acnames
[ac
], ac
);
3938 const struct ieee80211_roamparam
*rp
;
3942 for (mode
= IEEE80211_MODE_11A
; mode
< IEEE80211_MODE_MAX
; mode
++) {
3943 rp
= &roamparams
.params
[mode
];
3944 if (rp
->rssi
== 0 && rp
->rate
== 0)
3946 if (mode
== IEEE80211_MODE_11NA
|| mode
== IEEE80211_MODE_11NG
) {
3948 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm MCS %2u ",
3949 modename
[mode
], rp
->rssi
/2,
3950 rp
->rate
&~ IEEE80211_RATE_MCS
);
3952 LINE_CHECK("roam:%-7.7s rssi %4udBm MCS %2u ",
3953 modename
[mode
], rp
->rssi
/2,
3954 rp
->rate
&~ IEEE80211_RATE_MCS
);
3957 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s",
3958 modename
[mode
], rp
->rssi
/2, rp
->rate
/2);
3960 LINE_CHECK("roam:%-7.7s rssi %4udBm rate %2u Mb/s",
3961 modename
[mode
], rp
->rssi
/2, rp
->rate
/2);
3967 list_txparams(int s
)
3969 const struct ieee80211_txparam
*tp
;
3973 for (mode
= IEEE80211_MODE_11A
; mode
< IEEE80211_MODE_MAX
; mode
++) {
3974 tp
= &txparams
.params
[mode
];
3975 if (tp
->mgmtrate
== 0 && tp
->mcastrate
== 0)
3977 if (mode
== IEEE80211_MODE_11NA
|| mode
== IEEE80211_MODE_11NG
) {
3978 if (tp
->ucastrate
== IEEE80211_FIXED_RATE_NONE
)
3979 LINE_CHECK("%-7.7s ucast NONE mgmt %2u MCS "
3980 "mcast %2u MCS maxretry %u",
3982 tp
->mgmtrate
&~ IEEE80211_RATE_MCS
,
3983 tp
->mcastrate
&~ IEEE80211_RATE_MCS
,
3986 LINE_CHECK("%-7.7s ucast %2u MCS mgmt %2u MCS "
3987 "mcast %2u MCS maxretry %u",
3989 tp
->ucastrate
&~ IEEE80211_RATE_MCS
,
3990 tp
->mgmtrate
&~ IEEE80211_RATE_MCS
,
3991 tp
->mcastrate
&~ IEEE80211_RATE_MCS
,
3994 if (tp
->ucastrate
== IEEE80211_FIXED_RATE_NONE
)
3995 LINE_CHECK("%-7.7s ucast NONE mgmt %2u Mb/s "
3996 "mcast %2u Mb/s maxretry %u",
3999 tp
->mcastrate
/2, tp
->maxretry
);
4001 LINE_CHECK("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s "
4002 "mcast %2u Mb/s maxretry %u",
4004 tp
->ucastrate
/2, tp
->mgmtrate
/2,
4005 tp
->mcastrate
/2, tp
->maxretry
);
4011 printpolicy(int policy
)
4014 case IEEE80211_MACCMD_POLICY_OPEN
:
4015 printf("policy: open\n");
4017 case IEEE80211_MACCMD_POLICY_ALLOW
:
4018 printf("policy: allow\n");
4020 case IEEE80211_MACCMD_POLICY_DENY
:
4021 printf("policy: deny\n");
4023 case IEEE80211_MACCMD_POLICY_RADIUS
:
4024 printf("policy: radius\n");
4027 printf("policy: unknown (%u)\n", policy
);
4035 struct ieee80211req ireq
;
4036 struct ieee80211req_maclist
*acllist
;
4037 int i
, nacls
, policy
, len
;
4041 memset(&ireq
, 0, sizeof(ireq
));
4042 strlcpy(ireq
.i_name
, name
, sizeof(ireq
.i_name
)); /* XXX ?? */
4043 ireq
.i_type
= IEEE80211_IOC_MACCMD
;
4044 ireq
.i_val
= IEEE80211_MACCMD_POLICY
;
4045 if (ioctl(s
, SIOCG80211
, &ireq
) < 0) {
4046 if (errno
== EINVAL
) {
4047 printf("No acl policy loaded\n");
4050 err(1, "unable to get mac policy");
4052 policy
= ireq
.i_val
;
4053 if (policy
== IEEE80211_MACCMD_POLICY_OPEN
) {
4055 } else if (policy
== IEEE80211_MACCMD_POLICY_ALLOW
) {
4057 } else if (policy
== IEEE80211_MACCMD_POLICY_DENY
) {
4059 } else if (policy
== IEEE80211_MACCMD_POLICY_RADIUS
) {
4060 c
= 'r'; /* NB: should never have entries */
4062 printf("policy: unknown (%u)\n", policy
);
4065 if (verbose
|| c
== '?')
4066 printpolicy(policy
);
4068 ireq
.i_val
= IEEE80211_MACCMD_LIST
;
4070 if (ioctl(s
, SIOCG80211
, &ireq
) < 0)
4071 err(1, "unable to get mac acl list size");
4072 if (ireq
.i_len
== 0) { /* NB: no acls */
4073 if (!(verbose
|| c
== '?'))
4074 printpolicy(policy
);
4081 err(1, "out of memory for acl list");
4084 if (ioctl(s
, SIOCG80211
, &ireq
) < 0)
4085 err(1, "unable to get mac acl list");
4086 nacls
= len
/ sizeof(*acllist
);
4087 acllist
= (struct ieee80211req_maclist
*) data
;
4088 for (i
= 0; i
< nacls
; i
++)
4089 printf("%c%s\n", c
, ether_ntoa(
4090 (const struct ether_addr
*) acllist
[i
].ml_macaddr
));
4095 print_regdomain(const struct ieee80211_regdomain
*reg
, int verb
)
4097 if ((reg
->regdomain
!= 0 &&
4098 reg
->regdomain
!= reg
->country
) || verb
) {
4099 const struct regdomain
*rd
=
4100 lib80211_regdomain_findbysku(getregdata(), reg
->regdomain
);
4102 LINE_CHECK("regdomain %d", reg
->regdomain
);
4104 LINE_CHECK("regdomain %s", rd
->name
);
4106 if (reg
->country
!= 0 || verb
) {
4107 const struct country
*cc
=
4108 lib80211_country_findbycc(getregdata(), reg
->country
);
4110 LINE_CHECK("country %d", reg
->country
);
4112 LINE_CHECK("country %s", cc
->isoname
);
4114 if (reg
->location
== 'I')
4115 LINE_CHECK("indoor");
4116 else if (reg
->location
== 'O')
4117 LINE_CHECK("outdoor");
4119 LINE_CHECK("anywhere");
4127 list_regdomain(int s
, int channelsalso
)
4133 print_regdomain(®domain
, 1);
4135 print_channels(s
, chaninfo
, 1/*allchans*/, 1/*verbose*/);
4137 print_regdomain(®domain
, verbose
);
4143 struct ieee80211req ireq
;
4144 struct ieee80211req_mesh_route routes
[128];
4145 struct ieee80211req_mesh_route
*rt
;
4147 memset(&ireq
, 0, sizeof(ireq
));
4148 strlcpy(ireq
.i_name
, name
, sizeof(ireq
.i_name
));
4149 ireq
.i_type
= IEEE80211_IOC_MESH_RTCMD
;
4150 ireq
.i_val
= IEEE80211_MESH_RTCMD_LIST
;
4151 ireq
.i_data
= &routes
;
4152 ireq
.i_len
= sizeof(routes
);
4153 if (ioctl(s
, SIOCG80211
, &ireq
) < 0)
4154 err(1, "unable to get the Mesh routing table");
4156 printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n"
4165 for (rt
= &routes
[0];
4166 rt
- &routes
[0] < (int)(ireq
.i_len
/ sizeof(*rt
));
4169 ether_ntoa((const struct ether_addr
*)rt
->imr_dest
));
4170 printf("%s %4u %4u %6u %6u %c%c\n",
4171 ether_ntoa((const struct ether_addr
*)rt
->imr_nexthop
),
4172 rt
->imr_nhops
, rt
->imr_metric
, rt
->imr_lifetime
,
4174 (rt
->imr_flags
& IEEE80211_MESHRT_FLAGS_VALID
) ?
4176 (rt
->imr_flags
& IEEE80211_MESHRT_FLAGS_PROXY
) ?
4182 DECL_CMD_FUNC(set80211list
, arg
, d
)
4186 if (iseq(arg
, "sta"))
4188 else if (iseq(arg
, "scan") || iseq(arg
, "ap"))
4190 else if (iseq(arg
, "lscan"))
4192 else if (iseq(arg
, "chan") || iseq(arg
, "freq"))
4193 list_channels(s
, 1);
4194 else if (iseq(arg
, "active"))
4195 list_channels(s
, 0);
4196 else if (iseq(arg
, "keys"))
4198 else if (iseq(arg
, "caps"))
4199 list_capabilities(s
);
4200 else if (iseq(arg
, "wme") || iseq(arg
, "wmm"))
4202 else if (iseq(arg
, "mac"))
4204 else if (iseq(arg
, "txpow"))
4206 else if (iseq(arg
, "roam"))
4208 else if (iseq(arg
, "txparam") || iseq(arg
, "txparm"))
4210 else if (iseq(arg
, "regdomain"))
4211 list_regdomain(s
, 1);
4212 else if (iseq(arg
, "countries"))
4214 else if (iseq(arg
, "mesh"))
4217 errx(1, "Don't know how to list %s for %s", arg
, name
);
4221 static enum ieee80211_opmode
4222 get80211opmode(int s
)
4224 struct ifmediareq ifmr
;
4226 memset(&ifmr
, 0, sizeof(ifmr
));
4227 strlcpy(ifmr
.ifm_name
, name
, sizeof(ifmr
.ifm_name
));
4229 if (ioctl(s
, SIOCGIFMEDIA
, (caddr_t
)&ifmr
) >= 0) {
4230 if (ifmr
.ifm_current
& IFM_IEEE80211_ADHOC
) {
4231 if (ifmr
.ifm_current
& IFM_FLAG0
)
4232 return IEEE80211_M_AHDEMO
;
4234 return IEEE80211_M_IBSS
;
4236 if (ifmr
.ifm_current
& IFM_IEEE80211_HOSTAP
)
4237 return IEEE80211_M_HOSTAP
;
4238 if (ifmr
.ifm_current
& IFM_IEEE80211_MONITOR
)
4239 return IEEE80211_M_MONITOR
;
4240 if (ifmr
.ifm_current
& IFM_IEEE80211_MBSS
)
4241 return IEEE80211_M_MBSS
;
4243 return IEEE80211_M_STA
;
4248 printcipher(int s
, struct ieee80211req
*ireq
, int keylenop
)
4250 switch (ireq
->i_val
) {
4251 case IEEE80211_CIPHER_WEP
:
4252 ireq
->i_type
= keylenop
;
4253 if (ioctl(s
, SIOCG80211
, ireq
) != -1)
4255 ireq
->i_len
<= 5 ? "40" :
4256 ireq
->i_len
<= 13 ? "104" : "128");
4260 case IEEE80211_CIPHER_TKIP
:
4263 case IEEE80211_CIPHER_AES_OCB
:
4266 case IEEE80211_CIPHER_AES_CCM
:
4269 case IEEE80211_CIPHER_CKIP
:
4272 case IEEE80211_CIPHER_NONE
:
4276 printf("UNKNOWN (0x%x)", ireq
->i_val
);
4283 printkey(const struct ieee80211req_key
*ik
)
4285 static const uint8_t zerodata
[IEEE80211_KEYBUF_SIZE
];
4286 int keylen
= ik
->ik_keylen
;
4289 printcontents
= printkeys
&&
4290 (memcmp(ik
->ik_keydata
, zerodata
, keylen
) != 0 || verbose
);
4293 switch (ik
->ik_type
) {
4294 case IEEE80211_CIPHER_WEP
:
4296 LINE_CHECK("wepkey %u:%s", ik
->ik_keyix
+1,
4297 keylen
<= 5 ? "40-bit" :
4298 keylen
<= 13 ? "104-bit" : "128-bit");
4300 case IEEE80211_CIPHER_TKIP
:
4302 keylen
-= 128/8; /* ignore MIC for now */
4303 LINE_CHECK("TKIP %u:%u-bit", ik
->ik_keyix
+1, 8*keylen
);
4305 case IEEE80211_CIPHER_AES_OCB
:
4306 LINE_CHECK("AES-OCB %u:%u-bit", ik
->ik_keyix
+1, 8*keylen
);
4308 case IEEE80211_CIPHER_AES_CCM
:
4309 LINE_CHECK("AES-CCM %u:%u-bit", ik
->ik_keyix
+1, 8*keylen
);
4311 case IEEE80211_CIPHER_CKIP
:
4312 LINE_CHECK("CKIP %u:%u-bit", ik
->ik_keyix
+1, 8*keylen
);
4314 case IEEE80211_CIPHER_NONE
:
4315 LINE_CHECK("NULL %u:%u-bit", ik
->ik_keyix
+1, 8*keylen
);
4318 LINE_CHECK("UNKNOWN (0x%x) %u:%u-bit",
4319 ik
->ik_type
, ik
->ik_keyix
+1, 8*keylen
);
4322 if (printcontents
) {
4326 for (i
= 0; i
< keylen
; i
++)
4327 printf("%02x", ik
->ik_keydata
[i
]);
4329 if (ik
->ik_type
!= IEEE80211_CIPHER_WEP
&&
4330 (ik
->ik_keyrsc
!= 0 || verbose
))
4331 printf(" rsc %ju", (uintmax_t)ik
->ik_keyrsc
);
4332 if (ik
->ik_type
!= IEEE80211_CIPHER_WEP
&&
4333 (ik
->ik_keytsc
!= 0 || verbose
))
4334 printf(" tsc %ju", (uintmax_t)ik
->ik_keytsc
);
4335 if (ik
->ik_flags
!= 0 && verbose
) {
4336 const char *sep
= " ";
4338 if (ik
->ik_flags
& IEEE80211_KEY_XMIT
)
4339 printf("%stx", sep
), sep
= "+";
4340 if (ik
->ik_flags
& IEEE80211_KEY_RECV
)
4341 printf("%srx", sep
), sep
= "+";
4342 if (ik
->ik_flags
& IEEE80211_KEY_DEFAULT
)
4343 printf("%sdef", sep
), sep
= "+";
4350 printrate(const char *tag
, int v
, int defrate
, int defmcs
)
4352 if ((v
& IEEE80211_RATE_MCS
) == 0) {
4355 LINE_CHECK("%s %d.5", tag
, v
/2);
4357 LINE_CHECK("%s %d", tag
, v
/2);
4361 LINE_CHECK("%s %d", tag
, v
&~ 0x80);
4366 getid(int s
, int ix
, void *data
, size_t len
, size_t *plen
, int mesh
)
4368 struct ieee80211req ireq
;
4370 memset(&ireq
, 0, sizeof(ireq
));
4371 strlcpy(ireq
.i_name
, name
, sizeof(ireq
.i_name
));
4372 ireq
.i_type
= (!mesh
) ? IEEE80211_IOC_SSID
: IEEE80211_IOC_MESH_ID
;
4376 if (ioctl(s
, SIOCG80211
, &ireq
) < 0)
4383 ieee80211_status(int s
)
4385 static const uint8_t zerobssid
[IEEE80211_ADDR_LEN
];
4386 enum ieee80211_opmode opmode
= get80211opmode(s
);
4387 int i
, num
, wpa
, wme
, bgscan
, bgscaninterval
, val
, wepmode
;
4390 const struct ieee80211_channel
*c
;
4391 const struct ieee80211_roamparam
*rp
;
4392 const struct ieee80211_txparam
*tp
;
4394 if (getid(s
, -1, data
, sizeof(data
), &len
, 0) < 0) {
4395 /* If we can't get the SSID, this isn't an 802.11 device. */
4400 * Invalidate cached state so printing status for multiple
4401 * if's doesn't reuse the first interfaces' cached state.
4410 if (opmode
== IEEE80211_M_MBSS
) {
4412 getid(s
, 0, data
, sizeof(data
), &len
, 1);
4413 print_string(data
, len
);
4415 if (get80211val(s
, IEEE80211_IOC_NUMSSIDS
, &num
) < 0)
4419 for (i
= 0; i
< num
; i
++) {
4420 if (getid(s
, i
, data
, sizeof(data
), &len
, 0) >= 0 && len
> 0) {
4421 printf(" %d:", i
+ 1);
4422 print_string(data
, len
);
4426 print_string(data
, len
);
4429 if (c
->ic_freq
!= IEEE80211_CHAN_ANY
) {
4431 printf(" channel %d (%u MHz%s)", c
->ic_ieee
, c
->ic_freq
,
4432 get_chaninfo(c
, 1, buf
, sizeof(buf
)));
4434 printf(" channel UNDEF");
4436 if (get80211(s
, IEEE80211_IOC_BSSID
, data
, IEEE80211_ADDR_LEN
) >= 0 &&
4437 (memcmp(data
, zerobssid
, sizeof(zerobssid
)) != 0 || verbose
))
4438 printf(" bssid %s", ether_ntoa((struct ether_addr
*)data
));
4440 if (get80211len(s
, IEEE80211_IOC_STATIONNAME
, data
, sizeof(data
), &len
) != -1) {
4441 printf("\n\tstationname ");
4442 print_string(data
, len
);
4445 spacer
= ' '; /* force first break */
4448 list_regdomain(s
, 0);
4451 if (get80211val(s
, IEEE80211_IOC_AUTHMODE
, &val
) != -1) {
4453 case IEEE80211_AUTH_NONE
:
4454 LINE_CHECK("authmode NONE");
4456 case IEEE80211_AUTH_OPEN
:
4457 LINE_CHECK("authmode OPEN");
4459 case IEEE80211_AUTH_SHARED
:
4460 LINE_CHECK("authmode SHARED");
4462 case IEEE80211_AUTH_8021X
:
4463 LINE_CHECK("authmode 802.1x");
4465 case IEEE80211_AUTH_WPA
:
4466 if (get80211val(s
, IEEE80211_IOC_WPA
, &wpa
) < 0)
4467 wpa
= 1; /* default to WPA1 */
4470 LINE_CHECK("authmode WPA2/802.11i");
4473 LINE_CHECK("authmode WPA1+WPA2/802.11i");
4476 LINE_CHECK("authmode WPA");
4480 case IEEE80211_AUTH_AUTO
:
4481 LINE_CHECK("authmode AUTO");
4484 LINE_CHECK("authmode UNKNOWN (0x%x)", val
);
4489 if (wpa
|| verbose
) {
4490 if (get80211val(s
, IEEE80211_IOC_WPS
, &val
) != -1) {
4496 if (get80211val(s
, IEEE80211_IOC_TSN
, &val
) != -1) {
4502 if (ioctl(s
, IEEE80211_IOC_COUNTERMEASURES
, &val
) != -1) {
4504 LINE_CHECK("countermeasures");
4506 LINE_CHECK("-countermeasures");
4509 /* XXX not interesting with WPA done in user space */
4510 ireq
.i_type
= IEEE80211_IOC_KEYMGTALGS
;
4511 if (ioctl(s
, SIOCG80211
, &ireq
) != -1) {
4514 ireq
.i_type
= IEEE80211_IOC_MCASTCIPHER
;
4515 if (ioctl(s
, SIOCG80211
, &ireq
) != -1) {
4516 LINE_CHECK("mcastcipher ");
4517 printcipher(s
, &ireq
, IEEE80211_IOC_MCASTKEYLEN
);
4521 ireq
.i_type
= IEEE80211_IOC_UCASTCIPHER
;
4522 if (ioctl(s
, SIOCG80211
, &ireq
) != -1) {
4523 LINE_CHECK("ucastcipher ");
4524 printcipher(s
, &ireq
, IEEE80211_IOC_UCASTKEYLEN
);
4528 ireq
.i_type
= IEEE80211_IOC_RSNCAPS
;
4529 if (ioctl(s
, SIOCG80211
, &ireq
) != -1) {
4530 LINE_CHECK("RSN caps 0x%x", ireq
.i_val
);
4535 ireq
.i_type
= IEEE80211_IOC_UCASTCIPHERS
;
4536 if (ioctl(s
, SIOCG80211
, &ireq
) != -1) {
4541 if (get80211val(s
, IEEE80211_IOC_WEP
, &wepmode
) != -1 &&
4542 wepmode
!= IEEE80211_WEP_NOSUP
) {
4544 case IEEE80211_WEP_OFF
:
4545 LINE_CHECK("privacy OFF");
4547 case IEEE80211_WEP_ON
:
4548 LINE_CHECK("privacy ON");
4550 case IEEE80211_WEP_MIXED
:
4551 LINE_CHECK("privacy MIXED");
4554 LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode
);
4559 * If we get here then we've got WEP support so we need
4560 * to print WEP status.
4563 if (get80211val(s
, IEEE80211_IOC_WEPTXKEY
, &val
) < 0) {
4564 warn("WEP support, but no tx key!");
4568 LINE_CHECK("deftxkey %d", val
+1);
4569 else if (wepmode
!= IEEE80211_WEP_OFF
|| verbose
)
4570 LINE_CHECK("deftxkey UNDEF");
4572 if (get80211val(s
, IEEE80211_IOC_NUMWEPKEYS
, &num
) < 0) {
4573 warn("WEP support, but no NUMWEPKEYS support!");
4577 for (i
= 0; i
< num
; i
++) {
4578 struct ieee80211req_key ik
;
4580 memset(&ik
, 0, sizeof(ik
));
4582 if (get80211(s
, IEEE80211_IOC_WPAKEY
, &ik
, sizeof(ik
)) < 0) {
4583 warn("WEP support, but can get keys!");
4586 if (ik
.ik_keylen
!= 0) {
4596 if (get80211val(s
, IEEE80211_IOC_POWERSAVE
, &val
) != -1 &&
4597 val
!= IEEE80211_POWERSAVE_NOSUP
) {
4598 if (val
!= IEEE80211_POWERSAVE_OFF
|| verbose
) {
4600 case IEEE80211_POWERSAVE_OFF
:
4601 LINE_CHECK("powersavemode OFF");
4603 case IEEE80211_POWERSAVE_CAM
:
4604 LINE_CHECK("powersavemode CAM");
4606 case IEEE80211_POWERSAVE_PSP
:
4607 LINE_CHECK("powersavemode PSP");
4609 case IEEE80211_POWERSAVE_PSP_CAM
:
4610 LINE_CHECK("powersavemode PSP-CAM");
4613 if (get80211val(s
, IEEE80211_IOC_POWERSAVESLEEP
, &val
) != -1)
4614 LINE_CHECK("powersavesleep %d", val
);
4618 if (get80211val(s
, IEEE80211_IOC_TXPOWER
, &val
) != -1) {
4620 LINE_CHECK("txpower %d.5", val
/2);
4622 LINE_CHECK("txpower %d", val
/2);
4625 if (get80211val(s
, IEEE80211_IOC_TXPOWMAX
, &val
) != -1)
4626 LINE_CHECK("txpowmax %.1f", val
/2.);
4629 if (get80211val(s
, IEEE80211_IOC_DOTD
, &val
) != -1) {
4633 LINE_CHECK("-dotd");
4636 if (get80211val(s
, IEEE80211_IOC_RTSTHRESHOLD
, &val
) != -1) {
4637 if (val
!= IEEE80211_RTS_MAX
|| verbose
)
4638 LINE_CHECK("rtsthreshold %d", val
);
4641 if (get80211val(s
, IEEE80211_IOC_FRAGTHRESHOLD
, &val
) != -1) {
4642 if (val
!= IEEE80211_FRAG_MAX
|| verbose
)
4643 LINE_CHECK("fragthreshold %d", val
);
4645 if (opmode
== IEEE80211_M_STA
|| verbose
) {
4646 if (get80211val(s
, IEEE80211_IOC_BMISSTHRESHOLD
, &val
) != -1) {
4647 if (val
!= IEEE80211_HWBMISS_MAX
|| verbose
)
4648 LINE_CHECK("bmiss %d", val
);
4654 tp
= &txparams
.params
[chan2mode(c
)];
4655 printrate("ucastrate", tp
->ucastrate
,
4656 IEEE80211_FIXED_RATE_NONE
, IEEE80211_FIXED_RATE_NONE
);
4657 printrate("mcastrate", tp
->mcastrate
, 2*1,
4658 IEEE80211_RATE_MCS
|0);
4659 printrate("mgmtrate", tp
->mgmtrate
, 2*1,
4660 IEEE80211_RATE_MCS
|0);
4661 if (tp
->maxretry
!= 6) /* XXX */
4662 LINE_CHECK("maxretry %d", tp
->maxretry
);
4668 bgscaninterval
= -1;
4669 get80211val(s
, IEEE80211_IOC_BGSCAN_INTERVAL
, &bgscaninterval
);
4671 if (get80211val(s
, IEEE80211_IOC_SCANVALID
, &val
) != -1) {
4672 if (val
!= bgscaninterval
|| verbose
)
4673 LINE_CHECK("scanvalid %u", val
);
4677 if (get80211val(s
, IEEE80211_IOC_BGSCAN
, &bgscan
) != -1) {
4679 LINE_CHECK("bgscan");
4681 LINE_CHECK("-bgscan");
4683 if (bgscan
|| verbose
) {
4684 if (bgscaninterval
!= -1)
4685 LINE_CHECK("bgscanintvl %u", bgscaninterval
);
4686 if (get80211val(s
, IEEE80211_IOC_BGSCAN_IDLE
, &val
) != -1)
4687 LINE_CHECK("bgscanidle %u", val
);
4690 rp
= &roamparams
.params
[chan2mode(c
)];
4692 LINE_CHECK("roam:rssi %u.5", rp
->rssi
/2);
4694 LINE_CHECK("roam:rssi %u", rp
->rssi
/2);
4695 LINE_CHECK("roam:rate %u", rp
->rate
/2);
4702 if (IEEE80211_IS_CHAN_ANYG(c
) || verbose
) {
4703 if (get80211val(s
, IEEE80211_IOC_PUREG
, &val
) != -1) {
4705 LINE_CHECK("pureg");
4707 LINE_CHECK("-pureg");
4709 if (get80211val(s
, IEEE80211_IOC_PROTMODE
, &val
) != -1) {
4711 case IEEE80211_PROTMODE_OFF
:
4712 LINE_CHECK("protmode OFF");
4714 case IEEE80211_PROTMODE_CTS
:
4715 LINE_CHECK("protmode CTS");
4717 case IEEE80211_PROTMODE_RTSCTS
:
4718 LINE_CHECK("protmode RTSCTS");
4721 LINE_CHECK("protmode UNKNOWN (0x%x)", val
);
4727 if (IEEE80211_IS_CHAN_HT(c
) || verbose
) {
4729 switch (htconf
& 3) {
4742 if (get80211val(s
, IEEE80211_IOC_HTCOMPAT
, &val
) != -1) {
4744 LINE_CHECK("-htcompat");
4746 LINE_CHECK("htcompat");
4748 if (get80211val(s
, IEEE80211_IOC_AMPDU
, &val
) != -1) {
4751 LINE_CHECK("-ampdu");
4754 LINE_CHECK("ampdutx -ampdurx");
4757 LINE_CHECK("-ampdutx ampdurx");
4761 LINE_CHECK("ampdu");
4765 if (get80211val(s
, IEEE80211_IOC_AMPDU_LIMIT
, &val
) != -1) {
4767 case IEEE80211_HTCAP_MAXRXAMPDU_8K
:
4768 LINE_CHECK("ampdulimit 8k");
4770 case IEEE80211_HTCAP_MAXRXAMPDU_16K
:
4771 LINE_CHECK("ampdulimit 16k");
4773 case IEEE80211_HTCAP_MAXRXAMPDU_32K
:
4774 LINE_CHECK("ampdulimit 32k");
4776 case IEEE80211_HTCAP_MAXRXAMPDU_64K
:
4777 LINE_CHECK("ampdulimit 64k");
4781 if (get80211val(s
, IEEE80211_IOC_AMPDU_DENSITY
, &val
) != -1) {
4783 case IEEE80211_HTCAP_MPDUDENSITY_NA
:
4785 LINE_CHECK("ampdudensity NA");
4787 case IEEE80211_HTCAP_MPDUDENSITY_025
:
4788 LINE_CHECK("ampdudensity .25");
4790 case IEEE80211_HTCAP_MPDUDENSITY_05
:
4791 LINE_CHECK("ampdudensity .5");
4793 case IEEE80211_HTCAP_MPDUDENSITY_1
:
4794 LINE_CHECK("ampdudensity 1");
4796 case IEEE80211_HTCAP_MPDUDENSITY_2
:
4797 LINE_CHECK("ampdudensity 2");
4799 case IEEE80211_HTCAP_MPDUDENSITY_4
:
4800 LINE_CHECK("ampdudensity 4");
4802 case IEEE80211_HTCAP_MPDUDENSITY_8
:
4803 LINE_CHECK("ampdudensity 8");
4805 case IEEE80211_HTCAP_MPDUDENSITY_16
:
4806 LINE_CHECK("ampdudensity 16");
4810 if (get80211val(s
, IEEE80211_IOC_AMSDU
, &val
) != -1) {
4813 LINE_CHECK("-amsdu");
4816 LINE_CHECK("amsdutx -amsdurx");
4819 LINE_CHECK("-amsdutx amsdurx");
4823 LINE_CHECK("amsdu");
4827 /* XXX amsdu limit */
4828 if (get80211val(s
, IEEE80211_IOC_SHORTGI
, &val
) != -1) {
4830 LINE_CHECK("shortgi");
4832 LINE_CHECK("-shortgi");
4834 if (get80211val(s
, IEEE80211_IOC_HTPROTMODE
, &val
) != -1) {
4835 if (val
== IEEE80211_PROTMODE_OFF
)
4836 LINE_CHECK("htprotmode OFF");
4837 else if (val
!= IEEE80211_PROTMODE_RTSCTS
)
4838 LINE_CHECK("htprotmode UNKNOWN (0x%x)", val
);
4840 LINE_CHECK("htprotmode RTSCTS");
4842 if (get80211val(s
, IEEE80211_IOC_PUREN
, &val
) != -1) {
4844 LINE_CHECK("puren");
4846 LINE_CHECK("-puren");
4848 if (get80211val(s
, IEEE80211_IOC_SMPS
, &val
) != -1) {
4849 if (val
== IEEE80211_HTCAP_SMPS_DYNAMIC
)
4850 LINE_CHECK("smpsdyn");
4851 else if (val
== IEEE80211_HTCAP_SMPS_ENA
)
4854 LINE_CHECK("-smps");
4856 if (get80211val(s
, IEEE80211_IOC_RIFS
, &val
) != -1) {
4860 LINE_CHECK("-rifs");
4864 if (get80211val(s
, IEEE80211_IOC_WME
, &wme
) != -1) {
4872 if (get80211val(s
, IEEE80211_IOC_BURST
, &val
) != -1) {
4874 LINE_CHECK("burst");
4876 LINE_CHECK("-burst");
4879 if (get80211val(s
, IEEE80211_IOC_FF
, &val
) != -1) {
4885 if (get80211val(s
, IEEE80211_IOC_TURBOP
, &val
) != -1) {
4887 LINE_CHECK("dturbo");
4889 LINE_CHECK("-dturbo");
4891 if (get80211val(s
, IEEE80211_IOC_DWDS
, &val
) != -1) {
4895 LINE_CHECK("-dwds");
4898 if (opmode
== IEEE80211_M_HOSTAP
) {
4899 if (get80211val(s
, IEEE80211_IOC_HIDESSID
, &val
) != -1) {
4901 LINE_CHECK("hidessid");
4903 LINE_CHECK("-hidessid");
4905 if (get80211val(s
, IEEE80211_IOC_APBRIDGE
, &val
) != -1) {
4907 LINE_CHECK("-apbridge");
4909 LINE_CHECK("apbridge");
4911 if (get80211val(s
, IEEE80211_IOC_DTIM_PERIOD
, &val
) != -1)
4912 LINE_CHECK("dtimperiod %u", val
);
4914 if (get80211val(s
, IEEE80211_IOC_DOTH
, &val
) != -1) {
4916 LINE_CHECK("-doth");
4920 if (get80211val(s
, IEEE80211_IOC_DFS
, &val
) != -1) {
4926 if (get80211val(s
, IEEE80211_IOC_INACTIVITY
, &val
) != -1) {
4928 LINE_CHECK("-inact");
4930 LINE_CHECK("inact");
4933 if (get80211val(s
, IEEE80211_IOC_ROAMING
, &val
) != -1) {
4934 if (val
!= IEEE80211_ROAMING_AUTO
|| verbose
) {
4936 case IEEE80211_ROAMING_DEVICE
:
4937 LINE_CHECK("roaming DEVICE");
4939 case IEEE80211_ROAMING_AUTO
:
4940 LINE_CHECK("roaming AUTO");
4942 case IEEE80211_ROAMING_MANUAL
:
4943 LINE_CHECK("roaming MANUAL");
4946 LINE_CHECK("roaming UNKNOWN (0x%x)",
4954 if (opmode
== IEEE80211_M_AHDEMO
) {
4955 if (get80211val(s
, IEEE80211_IOC_TDMA_SLOT
, &val
) != -1)
4956 LINE_CHECK("tdmaslot %u", val
);
4957 if (get80211val(s
, IEEE80211_IOC_TDMA_SLOTCNT
, &val
) != -1)
4958 LINE_CHECK("tdmaslotcnt %u", val
);
4959 if (get80211val(s
, IEEE80211_IOC_TDMA_SLOTLEN
, &val
) != -1)
4960 LINE_CHECK("tdmaslotlen %u", val
);
4961 if (get80211val(s
, IEEE80211_IOC_TDMA_BINTERVAL
, &val
) != -1)
4962 LINE_CHECK("tdmabintval %u", val
);
4963 } else if (get80211val(s
, IEEE80211_IOC_BEACON_INTERVAL
, &val
) != -1) {
4964 /* XXX default define not visible */
4965 if (val
!= 100 || verbose
)
4966 LINE_CHECK("bintval %u", val
);
4969 if (wme
&& verbose
) {
4974 if (opmode
== IEEE80211_M_MBSS
) {
4975 if (get80211val(s
, IEEE80211_IOC_MESH_TTL
, &val
) != -1) {
4976 LINE_CHECK("meshttl %u", val
);
4978 if (get80211val(s
, IEEE80211_IOC_MESH_AP
, &val
) != -1) {
4980 LINE_CHECK("meshpeering");
4982 LINE_CHECK("-meshpeering");
4984 if (get80211val(s
, IEEE80211_IOC_MESH_FWRD
, &val
) != -1) {
4986 LINE_CHECK("meshforward");
4988 LINE_CHECK("-meshforward");
4990 if (get80211len(s
, IEEE80211_IOC_MESH_PR_METRIC
, data
, 12,
4993 LINE_CHECK("meshmetric %s", data
);
4995 if (get80211len(s
, IEEE80211_IOC_MESH_PR_PATH
, data
, 12,
4998 LINE_CHECK("meshpath %s", data
);
5000 if (get80211val(s
, IEEE80211_IOC_HWMP_ROOTMODE
, &val
) != -1) {
5002 case IEEE80211_HWMP_ROOTMODE_DISABLED
:
5003 LINE_CHECK("hwmprootmode DISABLED");
5005 case IEEE80211_HWMP_ROOTMODE_NORMAL
:
5006 LINE_CHECK("hwmprootmode NORMAL");
5008 case IEEE80211_HWMP_ROOTMODE_PROACTIVE
:
5009 LINE_CHECK("hwmprootmode PROACTIVE");
5011 case IEEE80211_HWMP_ROOTMODE_RANN
:
5012 LINE_CHECK("hwmprootmode RANN");
5015 LINE_CHECK("hwmprootmode UNKNOWN(%d)", val
);
5019 if (get80211val(s
, IEEE80211_IOC_HWMP_MAXHOPS
, &val
) != -1) {
5020 LINE_CHECK("hwmpmaxhops %u", val
);
5028 get80211(int s
, int type
, void *data
, int len
)
5030 struct ieee80211req ireq
;
5032 memset(&ireq
, 0, sizeof(ireq
));
5033 strlcpy(ireq
.i_name
, name
, sizeof(ireq
.i_name
));
5037 return ioctl(s
, SIOCG80211
, &ireq
);
5041 get80211len(int s
, int type
, void *data
, size_t len
, size_t *plen
)
5043 struct ieee80211req ireq
;
5045 memset(&ireq
, 0, sizeof(ireq
));
5046 strlcpy(ireq
.i_name
, name
, sizeof(ireq
.i_name
));
5049 assert(ireq
.i_len
== len
); /* NB: check for 16-bit truncation */
5051 if (ioctl(s
, SIOCG80211
, &ireq
) < 0)
5058 get80211val(int s
, int type
, int *val
)
5060 struct ieee80211req ireq
;
5062 memset(&ireq
, 0, sizeof(ireq
));
5063 strlcpy(ireq
.i_name
, name
, sizeof(ireq
.i_name
));
5065 if (ioctl(s
, SIOCG80211
, &ireq
) < 0)
5072 set80211(int s
, int type
, int val
, int len
, void *data
)
5074 struct ieee80211req ireq
;
5076 memset(&ireq
, 0, sizeof(ireq
));
5077 strlcpy(ireq
.i_name
, name
, sizeof(ireq
.i_name
));
5081 assert(ireq
.i_len
== len
); /* NB: check for 16-bit truncation */
5083 if (ioctl(s
, SIOCS80211
, &ireq
) < 0)
5084 err(1, "SIOCS80211");
5088 get_string(const char *val
, const char *sep
, u_int8_t
*buf
, int *lenp
)
5096 hexstr
= (val
[0] == '0' && tolower((u_char
)val
[1]) == 'x');
5102 if (sep
!= NULL
&& strchr(sep
, *val
) != NULL
) {
5107 if (!isxdigit((u_char
)val
[0])) {
5108 warnx("bad hexadecimal digits");
5111 if (!isxdigit((u_char
)val
[1])) {
5112 warnx("odd count hexadecimal digits");
5116 if (p
>= buf
+ len
) {
5118 warnx("hexadecimal digits too long");
5120 warnx("string too long");
5124 #define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10)
5125 *p
++ = (tohex((u_char
)val
[0]) << 4) |
5126 tohex((u_char
)val
[1]);
5133 /* The string "-" is treated as the empty string. */
5134 if (!hexstr
&& len
== 1 && buf
[0] == '-') {
5136 memset(buf
, 0, *lenp
);
5137 } else if (len
< *lenp
)
5138 memset(p
, 0, *lenp
- len
);
5144 print_string(const u_int8_t
*buf
, int len
)
5153 setlocale(LC_CTYPE
, "");
5154 utf8
= strncmp("UTF-8", nl_langinfo(CODESET
), 5) == 0;
5156 for (; i
< len
; i
++) {
5157 if (!isprint(buf
[i
]) && buf
[i
] != '\0' && !utf8
)
5159 if (isspace(buf
[i
]))
5162 if (i
== len
|| utf8
) {
5163 if (hasspc
|| len
== 0 || buf
[0] == '\0')
5164 printf("\"%.*s\"", len
, buf
);
5166 printf("%.*s", len
, buf
);
5169 for (i
= 0; i
< len
; i
++)
5170 printf("%02x", buf
[i
]);
5175 * Virtual AP cloning support.
5177 static struct ieee80211_clone_params params
= {
5178 .icp_opmode
= IEEE80211_M_STA
, /* default to station mode */
5182 wlan_create(int s
, struct ifreq
*ifr
)
5184 static const uint8_t zerobssid
[IEEE80211_ADDR_LEN
];
5186 if (params
.icp_parent
[0] == '\0')
5187 errx(1, "must specify a parent device (wlandev) when creating "
5189 if (params
.icp_opmode
== IEEE80211_M_WDS
&&
5190 memcmp(params
.icp_bssid
, zerobssid
, sizeof(zerobssid
)) == 0)
5191 errx(1, "no bssid specified for WDS (use wlanbssid)");
5192 ifr
->ifr_data
= (caddr_t
) ¶ms
;
5193 if (ioctl(s
, SIOCIFCREATE2
, ifr
) < 0)
5194 err(1, "SIOCIFCREATE2");
5198 DECL_CMD_FUNC(set80211clone_wlandev
, arg
, d
)
5200 strlcpy(params
.icp_parent
, arg
, IFNAMSIZ
);
5204 DECL_CMD_FUNC(set80211clone_wlanbssid
, arg
, d
)
5206 const struct ether_addr
*ea
;
5208 ea
= ether_aton(arg
);
5210 errx(1, "%s: cannot parse bssid", arg
);
5211 memcpy(params
.icp_bssid
, ea
->octet
, IEEE80211_ADDR_LEN
);
5215 DECL_CMD_FUNC(set80211clone_wlanaddr
, arg
, d
)
5217 const struct ether_addr
*ea
;
5219 ea
= ether_aton(arg
);
5221 errx(1, "%s: cannot parse address", arg
);
5222 memcpy(params
.icp_macaddr
, ea
->octet
, IEEE80211_ADDR_LEN
);
5223 params
.icp_flags
|= IEEE80211_CLONE_MACADDR
;
5227 DECL_CMD_FUNC(set80211clone_wlanmode
, arg
, d
)
5229 if (iseq(arg
, "sta"))
5230 params
.icp_opmode
= IEEE80211_M_STA
;
5231 else if (iseq(arg
, "ahdemo") || iseq(arg
, "adhoc-demo"))
5232 params
.icp_opmode
= IEEE80211_M_AHDEMO
;
5233 else if (iseq(arg
, "ibss") || iseq(arg
, "adhoc"))
5234 params
.icp_opmode
= IEEE80211_M_IBSS
;
5235 else if (iseq(arg
, "ap") || iseq(arg
, "host"))
5236 params
.icp_opmode
= IEEE80211_M_HOSTAP
;
5237 else if (iseq(arg
, "wds"))
5238 params
.icp_opmode
= IEEE80211_M_WDS
;
5239 else if (iseq(arg
, "monitor"))
5240 params
.icp_opmode
= IEEE80211_M_MONITOR
;
5241 else if (iseq(arg
, "tdma")) {
5242 params
.icp_opmode
= IEEE80211_M_AHDEMO
;
5243 params
.icp_flags
|= IEEE80211_CLONE_TDMA
;
5244 } else if (iseq(arg
, "mesh") || iseq(arg
, "mp")) /* mesh point */
5245 params
.icp_opmode
= IEEE80211_M_MBSS
;
5247 errx(1, "Don't know to create %s for %s", arg
, name
);
5251 set80211clone_beacons(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
5253 /* NB: inverted sense */
5255 params
.icp_flags
&= ~IEEE80211_CLONE_NOBEACONS
;
5257 params
.icp_flags
|= IEEE80211_CLONE_NOBEACONS
;
5261 set80211clone_bssid(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
5264 params
.icp_flags
|= IEEE80211_CLONE_BSSID
;
5266 params
.icp_flags
&= ~IEEE80211_CLONE_BSSID
;
5270 set80211clone_wdslegacy(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
5273 params
.icp_flags
|= IEEE80211_CLONE_WDSLEGACY
;
5275 params
.icp_flags
&= ~IEEE80211_CLONE_WDSLEGACY
;
5278 static struct cmd ieee80211_cmds
[] = {
5279 DEF_CMD_ARG("ssid", set80211ssid
),
5280 DEF_CMD_ARG("nwid", set80211ssid
),
5281 DEF_CMD_ARG("meshid", set80211meshid
),
5282 DEF_CMD_ARG("stationname", set80211stationname
),
5283 DEF_CMD_ARG("station", set80211stationname
), /* BSD/OS */
5284 DEF_CMD_ARG("channel", set80211channel
),
5285 DEF_CMD_ARG("authmode", set80211authmode
),
5286 DEF_CMD_ARG("powersavemode", set80211powersavemode
),
5287 DEF_CMD("powersave", 1, set80211powersave
),
5288 DEF_CMD("-powersave", 0, set80211powersave
),
5289 DEF_CMD_ARG("powersavesleep", set80211powersavesleep
),
5290 DEF_CMD_ARG("wepmode", set80211wepmode
),
5291 DEF_CMD("wep", 1, set80211wep
),
5292 DEF_CMD("-wep", 0, set80211wep
),
5293 DEF_CMD_ARG("deftxkey", set80211weptxkey
),
5294 DEF_CMD_ARG("weptxkey", set80211weptxkey
),
5295 DEF_CMD_ARG("wepkey", set80211wepkey
),
5296 DEF_CMD_ARG("nwkey", set80211nwkey
), /* NetBSD */
5297 DEF_CMD("-nwkey", 0, set80211wep
), /* NetBSD */
5298 DEF_CMD_ARG("rtsthreshold", set80211rtsthreshold
),
5299 DEF_CMD_ARG("protmode", set80211protmode
),
5300 DEF_CMD_ARG("txpower", set80211txpower
),
5301 DEF_CMD_ARG("roaming", set80211roaming
),
5302 DEF_CMD("wme", 1, set80211wme
),
5303 DEF_CMD("-wme", 0, set80211wme
),
5304 DEF_CMD("wmm", 1, set80211wme
),
5305 DEF_CMD("-wmm", 0, set80211wme
),
5306 DEF_CMD("hidessid", 1, set80211hidessid
),
5307 DEF_CMD("-hidessid", 0, set80211hidessid
),
5308 DEF_CMD("apbridge", 1, set80211apbridge
),
5309 DEF_CMD("-apbridge", 0, set80211apbridge
),
5310 DEF_CMD_ARG("chanlist", set80211chanlist
),
5311 DEF_CMD_ARG("bssid", set80211bssid
),
5312 DEF_CMD_ARG("ap", set80211bssid
),
5313 DEF_CMD("scan", 0, set80211scan
),
5314 DEF_CMD_ARG("list", set80211list
),
5315 DEF_CMD_ARG2("cwmin", set80211cwmin
),
5316 DEF_CMD_ARG2("cwmax", set80211cwmax
),
5317 DEF_CMD_ARG2("aifs", set80211aifs
),
5318 DEF_CMD_ARG2("txoplimit", set80211txoplimit
),
5319 DEF_CMD_ARG("acm", set80211acm
),
5320 DEF_CMD_ARG("-acm", set80211noacm
),
5321 DEF_CMD_ARG("ack", set80211ackpolicy
),
5322 DEF_CMD_ARG("-ack", set80211noackpolicy
),
5323 DEF_CMD_ARG2("bss:cwmin", set80211bsscwmin
),
5324 DEF_CMD_ARG2("bss:cwmax", set80211bsscwmax
),
5325 DEF_CMD_ARG2("bss:aifs", set80211bssaifs
),
5326 DEF_CMD_ARG2("bss:txoplimit", set80211bsstxoplimit
),
5327 DEF_CMD_ARG("dtimperiod", set80211dtimperiod
),
5328 DEF_CMD_ARG("bintval", set80211bintval
),
5329 DEF_CMD("mac:open", IEEE80211_MACCMD_POLICY_OPEN
, set80211maccmd
),
5330 DEF_CMD("mac:allow", IEEE80211_MACCMD_POLICY_ALLOW
, set80211maccmd
),
5331 DEF_CMD("mac:deny", IEEE80211_MACCMD_POLICY_DENY
, set80211maccmd
),
5332 DEF_CMD("mac:radius", IEEE80211_MACCMD_POLICY_RADIUS
, set80211maccmd
),
5333 DEF_CMD("mac:flush", IEEE80211_MACCMD_FLUSH
, set80211maccmd
),
5334 DEF_CMD("mac:detach", IEEE80211_MACCMD_DETACH
, set80211maccmd
),
5335 DEF_CMD_ARG("mac:add", set80211addmac
),
5336 DEF_CMD_ARG("mac:del", set80211delmac
),
5337 DEF_CMD_ARG("mac:kick", set80211kickmac
),
5338 DEF_CMD("pureg", 1, set80211pureg
),
5339 DEF_CMD("-pureg", 0, set80211pureg
),
5340 DEF_CMD("ff", 1, set80211fastframes
),
5341 DEF_CMD("-ff", 0, set80211fastframes
),
5342 DEF_CMD("dturbo", 1, set80211dturbo
),
5343 DEF_CMD("-dturbo", 0, set80211dturbo
),
5344 DEF_CMD("bgscan", 1, set80211bgscan
),
5345 DEF_CMD("-bgscan", 0, set80211bgscan
),
5346 DEF_CMD_ARG("bgscanidle", set80211bgscanidle
),
5347 DEF_CMD_ARG("bgscanintvl", set80211bgscanintvl
),
5348 DEF_CMD_ARG("scanvalid", set80211scanvalid
),
5349 DEF_CMD_ARG("roam:rssi", set80211roamrssi
),
5350 DEF_CMD_ARG("roam:rate", set80211roamrate
),
5351 DEF_CMD_ARG("mcastrate", set80211mcastrate
),
5352 DEF_CMD_ARG("ucastrate", set80211ucastrate
),
5353 DEF_CMD_ARG("mgtrate", set80211mgtrate
),
5354 DEF_CMD_ARG("mgmtrate", set80211mgtrate
),
5355 DEF_CMD_ARG("maxretry", set80211maxretry
),
5356 DEF_CMD_ARG("fragthreshold", set80211fragthreshold
),
5357 DEF_CMD("burst", 1, set80211burst
),
5358 DEF_CMD("-burst", 0, set80211burst
),
5359 DEF_CMD_ARG("bmiss", set80211bmissthreshold
),
5360 DEF_CMD_ARG("bmissthreshold", set80211bmissthreshold
),
5361 DEF_CMD("shortgi", 1, set80211shortgi
),
5362 DEF_CMD("-shortgi", 0, set80211shortgi
),
5363 DEF_CMD("ampdurx", 2, set80211ampdu
),
5364 DEF_CMD("-ampdurx", -2, set80211ampdu
),
5365 DEF_CMD("ampdutx", 1, set80211ampdu
),
5366 DEF_CMD("-ampdutx", -1, set80211ampdu
),
5367 DEF_CMD("ampdu", 3, set80211ampdu
), /* NB: tx+rx */
5368 DEF_CMD("-ampdu", -3, set80211ampdu
),
5369 DEF_CMD_ARG("ampdulimit", set80211ampdulimit
),
5370 DEF_CMD_ARG("ampdudensity", set80211ampdudensity
),
5371 DEF_CMD("amsdurx", 2, set80211amsdu
),
5372 DEF_CMD("-amsdurx", -2, set80211amsdu
),
5373 DEF_CMD("amsdutx", 1, set80211amsdu
),
5374 DEF_CMD("-amsdutx", -1, set80211amsdu
),
5375 DEF_CMD("amsdu", 3, set80211amsdu
), /* NB: tx+rx */
5376 DEF_CMD("-amsdu", -3, set80211amsdu
),
5377 DEF_CMD_ARG("amsdulimit", set80211amsdulimit
),
5378 DEF_CMD("puren", 1, set80211puren
),
5379 DEF_CMD("-puren", 0, set80211puren
),
5380 DEF_CMD("doth", 1, set80211doth
),
5381 DEF_CMD("-doth", 0, set80211doth
),
5382 DEF_CMD("dfs", 1, set80211dfs
),
5383 DEF_CMD("-dfs", 0, set80211dfs
),
5384 DEF_CMD("htcompat", 1, set80211htcompat
),
5385 DEF_CMD("-htcompat", 0, set80211htcompat
),
5386 DEF_CMD("dwds", 1, set80211dwds
),
5387 DEF_CMD("-dwds", 0, set80211dwds
),
5388 DEF_CMD("inact", 1, set80211inact
),
5389 DEF_CMD("-inact", 0, set80211inact
),
5390 DEF_CMD("tsn", 1, set80211tsn
),
5391 DEF_CMD("-tsn", 0, set80211tsn
),
5392 DEF_CMD_ARG("regdomain", set80211regdomain
),
5393 DEF_CMD_ARG("country", set80211country
),
5394 DEF_CMD("indoor", 'I', set80211location
),
5395 DEF_CMD("-indoor", 'O', set80211location
),
5396 DEF_CMD("outdoor", 'O', set80211location
),
5397 DEF_CMD("-outdoor", 'I', set80211location
),
5398 DEF_CMD("anywhere", ' ', set80211location
),
5399 DEF_CMD("ecm", 1, set80211ecm
),
5400 DEF_CMD("-ecm", 0, set80211ecm
),
5401 DEF_CMD("dotd", 1, set80211dotd
),
5402 DEF_CMD("-dotd", 0, set80211dotd
),
5403 DEF_CMD_ARG("htprotmode", set80211htprotmode
),
5404 DEF_CMD("ht20", 1, set80211htconf
),
5405 DEF_CMD("-ht20", 0, set80211htconf
),
5406 DEF_CMD("ht40", 3, set80211htconf
), /* NB: 20+40 */
5407 DEF_CMD("-ht40", 0, set80211htconf
),
5408 DEF_CMD("ht", 3, set80211htconf
), /* NB: 20+40 */
5409 DEF_CMD("-ht", 0, set80211htconf
),
5410 DEF_CMD("rifs", 1, set80211rifs
),
5411 DEF_CMD("-rifs", 0, set80211rifs
),
5412 DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA
, set80211smps
),
5413 DEF_CMD("smpsdyn", IEEE80211_HTCAP_SMPS_DYNAMIC
, set80211smps
),
5414 DEF_CMD("-smps", IEEE80211_HTCAP_SMPS_OFF
, set80211smps
),
5415 /* XXX for testing */
5416 DEF_CMD_ARG("chanswitch", set80211chanswitch
),
5418 DEF_CMD_ARG("tdmaslot", set80211tdmaslot
),
5419 DEF_CMD_ARG("tdmaslotcnt", set80211tdmaslotcnt
),
5420 DEF_CMD_ARG("tdmaslotlen", set80211tdmaslotlen
),
5421 DEF_CMD_ARG("tdmabintval", set80211tdmabintval
),
5423 DEF_CMD_ARG("meshttl", set80211meshttl
),
5424 DEF_CMD("meshforward", 1, set80211meshforward
),
5425 DEF_CMD("-meshforward", 0, set80211meshforward
),
5426 DEF_CMD("meshpeering", 1, set80211meshpeering
),
5427 DEF_CMD("-meshpeering", 0, set80211meshpeering
),
5428 DEF_CMD_ARG("meshmetric", set80211meshmetric
),
5429 DEF_CMD_ARG("meshpath", set80211meshpath
),
5430 DEF_CMD("meshrt:flush", IEEE80211_MESH_RTCMD_FLUSH
, set80211meshrtcmd
),
5431 DEF_CMD_ARG("meshrt:add", set80211addmeshrt
),
5432 DEF_CMD_ARG("meshrt:del", set80211delmeshrt
),
5433 DEF_CMD_ARG("hwmprootmode", set80211hwmprootmode
),
5434 DEF_CMD_ARG("hwmpmaxhops", set80211hwmpmaxhops
),
5436 /* vap cloning support */
5437 DEF_CLONE_CMD_ARG("wlanaddr", set80211clone_wlanaddr
),
5438 DEF_CLONE_CMD_ARG("wlanbssid", set80211clone_wlanbssid
),
5439 DEF_CLONE_CMD_ARG("wlandev", set80211clone_wlandev
),
5440 DEF_CLONE_CMD_ARG("wlanmode", set80211clone_wlanmode
),
5441 DEF_CLONE_CMD("beacons", 1, set80211clone_beacons
),
5442 DEF_CLONE_CMD("-beacons", 0, set80211clone_beacons
),
5443 DEF_CLONE_CMD("bssid", 1, set80211clone_bssid
),
5444 DEF_CLONE_CMD("-bssid", 0, set80211clone_bssid
),
5445 DEF_CLONE_CMD("wdslegacy", 1, set80211clone_wdslegacy
),
5446 DEF_CLONE_CMD("-wdslegacy", 0, set80211clone_wdslegacy
),
5448 static struct afswtch af_ieee80211
= {
5449 .af_name
= "af_ieee80211",
5451 .af_other_status
= ieee80211_status
,
5454 static __constructor(101) void
5455 ieee80211_ctor(void)
5459 for (i
= 0; i
< nitems(ieee80211_cmds
); i
++)
5460 cmd_register(&ieee80211_cmds
[i
]);
5461 af_register(&af_ieee80211
);
5462 clone_setdefcallback("wlan", wlan_create
);