1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright 2001 The Aerospace Corporation. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of The Aerospace Corporation may not be used to endorse or 15 * promote products derived from this software. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 /*- 31 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc. 32 * All rights reserved. 33 * 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. 37 * 38 * Redistribution and use in source and binary forms, with or without 39 * modification, are permitted provided that the following conditions 40 * are met: 41 * 1. Redistributions of source code must retain the above copyright 42 * notice, this list of conditions and the following disclaimer. 43 * 2. Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in the 45 * documentation and/or other materials provided with the distribution. 46 * 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. 58 */ 59 60 #include <sys/param.h> 61 #include <sys/ioctl.h> 62 #include <sys/socket.h> 63 #include <sys/sysctl.h> 64 #include <sys/time.h> 65 66 #include <net/ethernet.h> 67 #include <net/if.h> 68 #include <net/if_dl.h> 69 #include <net/if_types.h> 70 #include <net/if_media.h> 71 #include <net/route.h> 72 73 #define WANT_NET80211 1 74 #include <net80211/ieee80211_ioctl.h> 75 #include <net80211/ieee80211_freebsd.h> 76 #include <net80211/ieee80211_superg.h> 77 #include <net80211/ieee80211_tdma.h> 78 #include <net80211/ieee80211_mesh.h> 79 #include <net80211/ieee80211_wps.h> 80 81 #include <assert.h> 82 #include <ctype.h> 83 #include <err.h> 84 #include <errno.h> 85 #include <fcntl.h> 86 #include <inttypes.h> 87 #include <stdio.h> 88 #include <stdlib.h> 89 #include <string.h> 90 #include <unistd.h> 91 #include <stdarg.h> 92 #include <stddef.h> /* NB: for offsetof */ 93 #include <locale.h> 94 #include <langinfo.h> 95 96 #include "ifconfig.h" 97 98 #include <lib80211/lib80211_regdomain.h> 99 #include <lib80211/lib80211_ioctl.h> 100 101 #ifndef IEEE80211_FIXED_RATE_NONE 102 #define IEEE80211_FIXED_RATE_NONE 0xff 103 #endif 104 105 /* XXX need these publicly defined or similar */ 106 #ifndef IEEE80211_NODE_AUTH 107 #define IEEE80211_NODE_AUTH 0x000001 /* authorized for data */ 108 #define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */ 109 #define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */ 110 #define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */ 111 #define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */ 112 #define IEEE80211_NODE_HT 0x000040 /* HT enabled */ 113 #define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */ 114 #define IEEE80211_NODE_WPS 0x000100 /* WPS association */ 115 #define IEEE80211_NODE_TSN 0x000200 /* TSN association */ 116 #define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */ 117 #define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */ 118 #define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */ 119 #define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */ 120 #define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */ 121 #define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */ 122 #define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */ 123 #define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */ 124 #define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */ 125 #define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */ 126 #define IEEE80211_NODE_VHT 0x100000 /* VHT enabled */ 127 #define IEEE80211_NODE_LDPC 0x200000 /* LDPC enabled */ 128 #define IEEE80211_NODE_UAPSD 0x400000 /* UAPSD enabled */ 129 #endif 130 131 /* XXX should also figure out where to put these for k/u-space sharing. */ 132 #ifndef IEEE80211_FVHT_VHT 133 #define IEEE80211_FVHT_VHT 0x000000001 /* CONF: VHT supported */ 134 #define IEEE80211_FVHT_USEVHT40 0x000000002 /* CONF: Use VHT40 */ 135 #define IEEE80211_FVHT_USEVHT80 0x000000004 /* CONF: Use VHT80 */ 136 #define IEEE80211_FVHT_USEVHT80P80 0x000000008 /* CONF: Use VHT 80+80 */ 137 #define IEEE80211_FVHT_USEVHT160 0x000000010 /* CONF: Use VHT160 */ 138 #define IEEE80211_FVHT_STBC_TX 0x00000020 /* CONF: STBC tx enabled */ 139 #define IEEE80211_FVHT_STBC_RX 0x00000040 /* CONF: STBC rx enabled */ 140 #endif 141 142 /* Helper macros unified. */ 143 #ifndef _IEEE80211_MASKSHIFT 144 #define _IEEE80211_MASKSHIFT(_v, _f) (((_v) & _f) >> _f##_S) 145 #endif 146 #ifndef _IEEE80211_SHIFTMASK 147 #define _IEEE80211_SHIFTMASK(_v, _f) (((_v) << _f##_S) & _f) 148 #endif 149 150 #define MAXCHAN 1536 /* max 1.5K channels */ 151 152 #define MAXCOL 78 153 static int col; 154 static char spacer; 155 156 static void LINE_INIT(char c); 157 static void LINE_BREAK(void); 158 static void LINE_CHECK(const char *fmt, ...); 159 160 static const char *modename[IEEE80211_MODE_MAX] = { 161 [IEEE80211_MODE_AUTO] = "auto", 162 [IEEE80211_MODE_11A] = "11a", 163 [IEEE80211_MODE_11B] = "11b", 164 [IEEE80211_MODE_11G] = "11g", 165 [IEEE80211_MODE_FH] = "fh", 166 [IEEE80211_MODE_TURBO_A] = "turboA", 167 [IEEE80211_MODE_TURBO_G] = "turboG", 168 [IEEE80211_MODE_STURBO_A] = "sturbo", 169 [IEEE80211_MODE_11NA] = "11na", 170 [IEEE80211_MODE_11NG] = "11ng", 171 [IEEE80211_MODE_HALF] = "half", 172 [IEEE80211_MODE_QUARTER] = "quarter", 173 [IEEE80211_MODE_VHT_2GHZ] = "11acg", 174 [IEEE80211_MODE_VHT_5GHZ] = "11ac", 175 }; 176 177 static void set80211(if_ctx *ctx, int type, int val, int len, void *data); 178 static int get80211(if_ctx *ctx, int type, void *data, int len); 179 static int get80211len(if_ctx *ctx, int type, void *data, int len, int *plen); 180 static int get80211val(if_ctx *ctx, int type, int *val); 181 static const char *get_string(const char *val, const char *sep, 182 u_int8_t *buf, int *lenp); 183 static void print_string(const u_int8_t *buf, int len); 184 static void print_regdomain(const struct ieee80211_regdomain *, int); 185 static void print_channels(if_ctx *, const struct ieee80211req_chaninfo *, 186 int allchans, int verbose); 187 static void regdomain_makechannels(if_ctx *, struct ieee80211_regdomain_req *, 188 const struct ieee80211_devcaps_req *); 189 static const char *mesh_linkstate_string(uint8_t state); 190 191 static struct ieee80211req_chaninfo *chaninfo; 192 static struct ieee80211_regdomain regdomain; 193 static int gotregdomain = 0; 194 static struct ieee80211_roamparams_req roamparams; 195 static int gotroam = 0; 196 static struct ieee80211_txparams_req txparams; 197 static int gottxparams = 0; 198 static struct ieee80211_channel curchan; 199 static int gotcurchan = 0; 200 static struct ifmediareq *global_ifmr; 201 202 /* HT */ 203 static int htconf = 0; 204 static int gothtconf = 0; 205 206 static void 207 gethtconf(if_ctx *ctx) 208 { 209 if (gothtconf) 210 return; 211 if (get80211val(ctx, IEEE80211_IOC_HTCONF, &htconf) < 0) 212 warn("unable to get HT configuration information"); 213 gothtconf = 1; 214 } 215 216 /* VHT */ 217 static int vhtconf = 0; 218 static int gotvhtconf = 0; 219 220 static void 221 getvhtconf(if_ctx *ctx) 222 { 223 if (gotvhtconf) 224 return; 225 if (get80211val(ctx, IEEE80211_IOC_VHTCONF, &vhtconf) < 0) 226 warn("unable to get VHT configuration information"); 227 gotvhtconf = 1; 228 } 229 230 /* 231 * Collect channel info from the kernel. We use this (mostly) 232 * to handle mapping between frequency and IEEE channel number. 233 */ 234 static void 235 getchaninfo(if_ctx *ctx) 236 { 237 if (chaninfo != NULL) 238 return; 239 chaninfo = malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN)); 240 if (chaninfo == NULL) 241 errx(1, "no space for channel list"); 242 if (get80211(ctx, IEEE80211_IOC_CHANINFO, chaninfo, 243 IEEE80211_CHANINFO_SIZE(MAXCHAN)) < 0) 244 err(1, "unable to get channel information"); 245 global_ifmr = ifmedia_getstate(ctx); 246 gethtconf(ctx); 247 getvhtconf(ctx); 248 } 249 250 static struct regdata * 251 getregdata(void) 252 { 253 static struct regdata *rdp = NULL; 254 if (rdp == NULL) { 255 rdp = lib80211_alloc_regdata(); 256 if (rdp == NULL) 257 errx(-1, "missing or corrupted regdomain database"); 258 } 259 return rdp; 260 } 261 262 /* 263 * Given the channel at index i with attributes from, 264 * check if there is a channel with attributes to in 265 * the channel table. With suitable attributes this 266 * allows the caller to look for promotion; e.g. from 267 * 11b > 11g. 268 */ 269 static int 270 canpromote(unsigned int i, uint32_t from, uint32_t to) 271 { 272 const struct ieee80211_channel *fc = &chaninfo->ic_chans[i]; 273 u_int j; 274 275 if ((fc->ic_flags & from) != from) 276 return i; 277 /* NB: quick check exploiting ordering of chans w/ same frequency */ 278 if (i+1 < chaninfo->ic_nchans && 279 chaninfo->ic_chans[i+1].ic_freq == fc->ic_freq && 280 (chaninfo->ic_chans[i+1].ic_flags & to) == to) 281 return i+1; 282 /* brute force search in case channel list is not ordered */ 283 for (j = 0; j < chaninfo->ic_nchans; j++) { 284 const struct ieee80211_channel *tc = &chaninfo->ic_chans[j]; 285 if (j != i && 286 tc->ic_freq == fc->ic_freq && (tc->ic_flags & to) == to) 287 return j; 288 } 289 return i; 290 } 291 292 /* 293 * Handle channel promotion. When a channel is specified with 294 * only a frequency we want to promote it to the ``best'' channel 295 * available. The channel list has separate entries for 11b, 11g, 296 * 11a, and 11n[ga] channels so specifying a frequency w/o any 297 * attributes requires we upgrade, e.g. from 11b -> 11g. This 298 * gets complicated when the channel is specified on the same 299 * command line with a media request that constrains the available 300 * channe list (e.g. mode 11a); we want to honor that to avoid 301 * confusing behaviour. 302 */ 303 /* 304 * XXX VHT 305 */ 306 static int 307 promote(unsigned int i) 308 { 309 /* 310 * Query the current mode of the interface in case it's 311 * constrained (e.g. to 11a). We must do this carefully 312 * as there may be a pending ifmedia request in which case 313 * asking the kernel will give us the wrong answer. This 314 * is an unfortunate side-effect of the way ifconfig is 315 * structure for modularity (yech). 316 * 317 * NB: ifmr is actually setup in getchaninfo (above); we 318 * assume it's called coincident with to this call so 319 * we have a ``current setting''; otherwise we must pass 320 * the socket descriptor down to here so we can make 321 * the ifmedia_getstate call ourselves. 322 */ 323 int chanmode = global_ifmr != NULL ? IFM_MODE(global_ifmr->ifm_current) : IFM_AUTO; 324 325 /* when ambiguous promote to ``best'' */ 326 /* NB: we abitrarily pick HT40+ over HT40- */ 327 if (chanmode != IFM_IEEE80211_11B) 328 i = canpromote(i, IEEE80211_CHAN_B, IEEE80211_CHAN_G); 329 if (chanmode != IFM_IEEE80211_11G && (htconf & 1)) { 330 i = canpromote(i, IEEE80211_CHAN_G, 331 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20); 332 if (htconf & 2) { 333 i = canpromote(i, IEEE80211_CHAN_G, 334 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D); 335 i = canpromote(i, IEEE80211_CHAN_G, 336 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U); 337 } 338 } 339 if (chanmode != IFM_IEEE80211_11A && (htconf & 1)) { 340 i = canpromote(i, IEEE80211_CHAN_A, 341 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20); 342 if (htconf & 2) { 343 i = canpromote(i, IEEE80211_CHAN_A, 344 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D); 345 i = canpromote(i, IEEE80211_CHAN_A, 346 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U); 347 } 348 } 349 return i; 350 } 351 352 static void 353 mapfreq(struct ieee80211_channel *chan, uint16_t freq, unsigned int flags) 354 { 355 u_int i; 356 357 for (i = 0; i < chaninfo->ic_nchans; i++) { 358 const struct ieee80211_channel *c = &chaninfo->ic_chans[i]; 359 360 if (c->ic_freq == freq && (c->ic_flags & flags) == flags) { 361 if (flags == 0) { 362 /* when ambiguous promote to ``best'' */ 363 c = &chaninfo->ic_chans[promote(i)]; 364 } 365 *chan = *c; 366 return; 367 } 368 } 369 errx(1, "unknown/undefined frequency %u/0x%x", freq, flags); 370 } 371 372 static void 373 mapchan(struct ieee80211_channel *chan, uint8_t ieee, unsigned int flags) 374 { 375 u_int i; 376 377 for (i = 0; i < chaninfo->ic_nchans; i++) { 378 const struct ieee80211_channel *c = &chaninfo->ic_chans[i]; 379 380 if (c->ic_ieee == ieee && (c->ic_flags & flags) == flags) { 381 if (flags == 0) { 382 /* when ambiguous promote to ``best'' */ 383 c = &chaninfo->ic_chans[promote(i)]; 384 } 385 *chan = *c; 386 return; 387 } 388 } 389 errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags); 390 } 391 392 static const struct ieee80211_channel * 393 getcurchan(if_ctx *ctx) 394 { 395 if (gotcurchan) 396 return &curchan; 397 if (get80211(ctx, IEEE80211_IOC_CURCHAN, &curchan, sizeof(curchan)) < 0) { 398 int val; 399 /* fall back to legacy ioctl */ 400 if (get80211val(ctx, IEEE80211_IOC_CHANNEL, &val) < 0) 401 err(-1, "cannot figure out current channel"); 402 getchaninfo(ctx); 403 mapchan(&curchan, val, 0); 404 } 405 gotcurchan = 1; 406 return &curchan; 407 } 408 409 static enum ieee80211_phymode 410 chan2mode(const struct ieee80211_channel *c) 411 { 412 if (IEEE80211_IS_CHAN_VHTA(c)) 413 return IEEE80211_MODE_VHT_5GHZ; 414 if (IEEE80211_IS_CHAN_VHTG(c)) 415 return IEEE80211_MODE_VHT_2GHZ; 416 if (IEEE80211_IS_CHAN_HTA(c)) 417 return IEEE80211_MODE_11NA; 418 if (IEEE80211_IS_CHAN_HTG(c)) 419 return IEEE80211_MODE_11NG; 420 if (IEEE80211_IS_CHAN_108A(c)) 421 return IEEE80211_MODE_TURBO_A; 422 if (IEEE80211_IS_CHAN_108G(c)) 423 return IEEE80211_MODE_TURBO_G; 424 if (IEEE80211_IS_CHAN_ST(c)) 425 return IEEE80211_MODE_STURBO_A; 426 if (IEEE80211_IS_CHAN_FHSS(c)) 427 return IEEE80211_MODE_FH; 428 if (IEEE80211_IS_CHAN_HALF(c)) 429 return IEEE80211_MODE_HALF; 430 if (IEEE80211_IS_CHAN_QUARTER(c)) 431 return IEEE80211_MODE_QUARTER; 432 if (IEEE80211_IS_CHAN_A(c)) 433 return IEEE80211_MODE_11A; 434 if (IEEE80211_IS_CHAN_ANYG(c)) 435 return IEEE80211_MODE_11G; 436 if (IEEE80211_IS_CHAN_B(c)) 437 return IEEE80211_MODE_11B; 438 return IEEE80211_MODE_AUTO; 439 } 440 441 static void 442 getroam(if_ctx *ctx) 443 { 444 if (gotroam) 445 return; 446 if (get80211(ctx, IEEE80211_IOC_ROAM, 447 &roamparams, sizeof(roamparams)) < 0) 448 err(1, "unable to get roaming parameters"); 449 gotroam = 1; 450 } 451 452 static void 453 setroam_cb(if_ctx *ctx, void *arg) 454 { 455 struct ieee80211_roamparams_req *roam = arg; 456 set80211(ctx, IEEE80211_IOC_ROAM, 0, sizeof(*roam), roam); 457 } 458 459 static void 460 gettxparams(if_ctx *ctx) 461 { 462 if (gottxparams) 463 return; 464 if (get80211(ctx, IEEE80211_IOC_TXPARAMS, 465 &txparams, sizeof(txparams)) < 0) 466 err(1, "unable to get transmit parameters"); 467 gottxparams = 1; 468 } 469 470 static void 471 settxparams_cb(if_ctx *ctx, void *arg) 472 { 473 struct ieee80211_txparams_req *txp = arg; 474 set80211(ctx, IEEE80211_IOC_TXPARAMS, 0, sizeof(*txp), txp); 475 } 476 477 static void 478 getregdomain(if_ctx *ctx) 479 { 480 if (gotregdomain) 481 return; 482 if (get80211(ctx, IEEE80211_IOC_REGDOMAIN, 483 ®domain, sizeof(regdomain)) < 0) 484 err(1, "unable to get regulatory domain info"); 485 gotregdomain = 1; 486 } 487 488 static void 489 getdevcaps(if_ctx *ctx, struct ieee80211_devcaps_req *dc) 490 { 491 if (get80211(ctx, IEEE80211_IOC_DEVCAPS, dc, 492 IEEE80211_DEVCAPS_SPACE(dc)) < 0) 493 err(1, "unable to get device capabilities"); 494 } 495 496 static void 497 setregdomain_cb(if_ctx *ctx, void *arg) 498 { 499 struct ieee80211_regdomain_req *req; 500 struct ieee80211_regdomain *rd = arg; 501 struct ieee80211_devcaps_req *dc; 502 struct regdata *rdp = getregdata(); 503 504 if (rd->country != NO_COUNTRY) { 505 const struct country *cc; 506 /* 507 * Check current country seting to make sure it's 508 * compatible with the new regdomain. If not, then 509 * override it with any default country for this 510 * SKU. If we cannot arrange a match, then abort. 511 */ 512 cc = lib80211_country_findbycc(rdp, rd->country); 513 if (cc == NULL) 514 errx(1, "unknown ISO country code %d", rd->country); 515 if (cc->rd->sku != rd->regdomain) { 516 const struct regdomain *rp; 517 /* 518 * Check if country is incompatible with regdomain. 519 * To enable multiple regdomains for a country code 520 * we permit a mismatch between the regdomain and 521 * the country's associated regdomain when the 522 * regdomain is setup w/o a default country. For 523 * example, US is bound to the FCC regdomain but 524 * we allow US to be combined with FCC3 because FCC3 525 * has not default country. This allows bogus 526 * combinations like FCC3+DK which are resolved when 527 * constructing the channel list by deferring to the 528 * regdomain to construct the channel list. 529 */ 530 rp = lib80211_regdomain_findbysku(rdp, rd->regdomain); 531 if (rp == NULL) 532 errx(1, "country %s (%s) is not usable with " 533 "regdomain %d", cc->isoname, cc->name, 534 rd->regdomain); 535 else if (rp->cc != NULL && rp->cc != cc) 536 errx(1, "country %s (%s) is not usable with " 537 "regdomain %s", cc->isoname, cc->name, 538 rp->name); 539 } 540 } 541 /* 542 * Fetch the device capabilities and calculate the 543 * full set of netbands for which we request a new 544 * channel list be constructed. Once that's done we 545 * push the regdomain info + channel list to the kernel. 546 */ 547 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN)); 548 if (dc == NULL) 549 errx(1, "no space for device capabilities"); 550 dc->dc_chaninfo.ic_nchans = MAXCHAN; 551 getdevcaps(ctx, dc); 552 #if 0 553 if (verbose) { 554 printf("drivercaps: 0x%x\n", dc->dc_drivercaps); 555 printf("cryptocaps: 0x%x\n", dc->dc_cryptocaps); 556 printf("htcaps : 0x%x\n", dc->dc_htcaps); 557 printf("vhtcaps : 0x%x\n", dc->dc_vhtcaps); 558 #if 0 559 memcpy(chaninfo, &dc->dc_chaninfo, 560 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo)); 561 print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, 1/*verbose*/); 562 #endif 563 } 564 #endif 565 req = malloc(IEEE80211_REGDOMAIN_SIZE(dc->dc_chaninfo.ic_nchans)); 566 if (req == NULL) 567 errx(1, "no space for regdomain request"); 568 req->rd = *rd; 569 regdomain_makechannels(ctx, req, dc); 570 if (ctx->args->verbose) { 571 LINE_INIT(':'); 572 print_regdomain(rd, 1/*verbose*/); 573 LINE_BREAK(); 574 /* blech, reallocate channel list for new data */ 575 if (chaninfo != NULL) 576 free(chaninfo); 577 chaninfo = malloc(IEEE80211_CHANINFO_SPACE(&req->chaninfo)); 578 if (chaninfo == NULL) 579 errx(1, "no space for channel list"); 580 memcpy(chaninfo, &req->chaninfo, 581 IEEE80211_CHANINFO_SPACE(&req->chaninfo)); 582 print_channels(ctx, &req->chaninfo, 1/*allchans*/, 1/*verbose*/); 583 } 584 if (req->chaninfo.ic_nchans == 0) 585 errx(1, "no channels calculated"); 586 set80211(ctx, IEEE80211_IOC_REGDOMAIN, 0, 587 IEEE80211_REGDOMAIN_SPACE(req), req); 588 free(req); 589 free(dc); 590 } 591 592 static int 593 ieee80211_mhz2ieee(int freq, int flags) 594 { 595 struct ieee80211_channel chan; 596 mapfreq(&chan, freq, flags); 597 return chan.ic_ieee; 598 } 599 600 static int 601 isanyarg(const char *arg) 602 { 603 return (strncmp(arg, "-", 1) == 0 || 604 strncasecmp(arg, "any", 3) == 0 || strncasecmp(arg, "off", 3) == 0); 605 } 606 607 static void 608 set80211ssid(if_ctx *ctx, const char *val, int dummy __unused) 609 { 610 int ssid; 611 int len; 612 u_int8_t data[IEEE80211_NWID_LEN]; 613 614 ssid = 0; 615 len = strlen(val); 616 if (len > 2 && isdigit((int)val[0]) && val[1] == ':') { 617 ssid = atoi(val)-1; 618 val += 2; 619 } 620 621 bzero(data, sizeof(data)); 622 len = sizeof(data); 623 if (get_string(val, NULL, data, &len) == NULL) 624 exit(1); 625 626 set80211(ctx, IEEE80211_IOC_SSID, ssid, len, data); 627 } 628 629 static void 630 set80211meshid(if_ctx *ctx, const char *val, int dummy __unused) 631 { 632 int len; 633 u_int8_t data[IEEE80211_NWID_LEN]; 634 635 memset(data, 0, sizeof(data)); 636 len = sizeof(data); 637 if (get_string(val, NULL, data, &len) == NULL) 638 exit(1); 639 640 set80211(ctx, IEEE80211_IOC_MESH_ID, 0, len, data); 641 } 642 643 static void 644 set80211stationname(if_ctx *ctx, const char *val, int dummy __unused) 645 { 646 int len; 647 u_int8_t data[33]; 648 649 bzero(data, sizeof(data)); 650 len = sizeof(data); 651 get_string(val, NULL, data, &len); 652 653 set80211(ctx, IEEE80211_IOC_STATIONNAME, 0, len, data); 654 } 655 656 /* 657 * Parse a channel specification for attributes/flags. 658 * The syntax is: 659 * freq/xx channel width (5,10,20,40,40+,40-) 660 * freq:mode channel mode (a,b,g,h,n,t,s,d) 661 * 662 * These can be combined in either order; e.g. 2437:ng/40. 663 * Modes are case insensitive. 664 * 665 * The result is not validated here; it's assumed to be 666 * checked against the channel table fetched from the kernel. 667 */ 668 static unsigned int 669 getchannelflags(const char *val, int freq) 670 { 671 #define _CHAN_HT 0x80000000 672 const char *cp; 673 int flags; 674 int is_vht = 0; 675 676 flags = 0; 677 678 cp = strchr(val, ':'); 679 if (cp != NULL) { 680 for (cp++; isalpha((int) *cp); cp++) { 681 /* accept mixed case */ 682 int c = *cp; 683 if (isupper(c)) 684 c = tolower(c); 685 switch (c) { 686 case 'a': /* 802.11a */ 687 flags |= IEEE80211_CHAN_A; 688 break; 689 case 'b': /* 802.11b */ 690 flags |= IEEE80211_CHAN_B; 691 break; 692 case 'g': /* 802.11g */ 693 flags |= IEEE80211_CHAN_G; 694 break; 695 case 'v': /* vht: 802.11ac */ 696 is_vht = 1; 697 /* Fallthrough */ 698 case 'h': /* ht = 802.11n */ 699 case 'n': /* 802.11n */ 700 flags |= _CHAN_HT; /* NB: private */ 701 break; 702 case 'd': /* dt = Atheros Dynamic Turbo */ 703 flags |= IEEE80211_CHAN_TURBO; 704 break; 705 case 't': /* ht, dt, st, t */ 706 /* dt and unadorned t specify Dynamic Turbo */ 707 if ((flags & (IEEE80211_CHAN_STURBO|_CHAN_HT)) == 0) 708 flags |= IEEE80211_CHAN_TURBO; 709 break; 710 case 's': /* st = Atheros Static Turbo */ 711 flags |= IEEE80211_CHAN_STURBO; 712 break; 713 default: 714 errx(-1, "%s: Invalid channel attribute %c\n", 715 val, *cp); 716 } 717 } 718 } 719 cp = strchr(val, '/'); 720 if (cp != NULL) { 721 char *ep; 722 u_long cw = strtoul(cp+1, &ep, 10); 723 724 switch (cw) { 725 case 5: 726 flags |= IEEE80211_CHAN_QUARTER; 727 break; 728 case 10: 729 flags |= IEEE80211_CHAN_HALF; 730 break; 731 case 20: 732 /* NB: this may be removed below */ 733 flags |= IEEE80211_CHAN_HT20; 734 break; 735 case 40: 736 case 80: 737 case 160: 738 /* Handle the 80/160 VHT flag */ 739 if (cw == 80) 740 flags |= IEEE80211_CHAN_VHT80; 741 else if (cw == 160) 742 flags |= IEEE80211_CHAN_VHT160; 743 744 /* Fallthrough */ 745 if (ep != NULL && *ep == '+') 746 flags |= IEEE80211_CHAN_HT40U; 747 else if (ep != NULL && *ep == '-') 748 flags |= IEEE80211_CHAN_HT40D; 749 break; 750 default: 751 errx(-1, "%s: Invalid channel width\n", val); 752 } 753 } 754 755 /* 756 * Cleanup specifications. 757 */ 758 if ((flags & _CHAN_HT) == 0) { 759 /* 760 * If user specified freq/20 or freq/40 quietly remove 761 * HT cw attributes depending on channel use. To give 762 * an explicit 20/40 width for an HT channel you must 763 * indicate it is an HT channel since all HT channels 764 * are also usable for legacy operation; e.g. freq:n/40. 765 */ 766 flags &= ~IEEE80211_CHAN_HT; 767 flags &= ~IEEE80211_CHAN_VHT; 768 } else { 769 /* 770 * Remove private indicator that this is an HT channel 771 * and if no explicit channel width has been given 772 * provide the default settings. 773 */ 774 flags &= ~_CHAN_HT; 775 if ((flags & IEEE80211_CHAN_HT) == 0) { 776 struct ieee80211_channel chan; 777 /* 778 * Consult the channel list to see if we can use 779 * HT40+ or HT40- (if both the map routines choose). 780 */ 781 if (freq > 255) 782 mapfreq(&chan, freq, 0); 783 else 784 mapchan(&chan, freq, 0); 785 flags |= (chan.ic_flags & IEEE80211_CHAN_HT); 786 } 787 788 /* 789 * If VHT is enabled, then also set the VHT flag and the 790 * relevant channel up/down. 791 */ 792 if (is_vht && (flags & IEEE80211_CHAN_HT)) { 793 /* 794 * XXX yes, maybe we should just have VHT, and reuse 795 * HT20/HT40U/HT40D 796 */ 797 if (flags & IEEE80211_CHAN_VHT80) 798 ; 799 else if (flags & IEEE80211_CHAN_HT20) 800 flags |= IEEE80211_CHAN_VHT20; 801 else if (flags & IEEE80211_CHAN_HT40U) 802 flags |= IEEE80211_CHAN_VHT40U; 803 else if (flags & IEEE80211_CHAN_HT40D) 804 flags |= IEEE80211_CHAN_VHT40D; 805 } 806 } 807 return flags; 808 #undef _CHAN_HT 809 } 810 811 static void 812 getchannel(if_ctx *ctx, struct ieee80211_channel *chan, const char *val) 813 { 814 unsigned int v, flags; 815 char *eptr; 816 817 memset(chan, 0, sizeof(*chan)); 818 if (isanyarg(val)) { 819 chan->ic_freq = IEEE80211_CHAN_ANY; 820 return; 821 } 822 getchaninfo(ctx); 823 errno = 0; 824 v = strtol(val, &eptr, 10); 825 if (val[0] == '\0' || val == eptr || errno == ERANGE || 826 /* channel may be suffixed with nothing, :flag, or /width */ 827 (eptr[0] != '\0' && eptr[0] != ':' && eptr[0] != '/')) 828 errx(1, "invalid channel specification%s", 829 errno == ERANGE ? " (out of range)" : ""); 830 flags = getchannelflags(val, v); 831 if (v > 255) { /* treat as frequency */ 832 mapfreq(chan, v, flags); 833 } else { 834 mapchan(chan, v, flags); 835 } 836 } 837 838 static void 839 set80211channel(if_ctx *ctx, const char *val, int dummy __unused) 840 { 841 struct ieee80211_channel chan; 842 843 getchannel(ctx, &chan, val); 844 set80211(ctx, IEEE80211_IOC_CURCHAN, 0, sizeof(chan), &chan); 845 } 846 847 static void 848 set80211chanswitch(if_ctx *ctx, const char *val, int dummy __unused) 849 { 850 struct ieee80211_chanswitch_req csr; 851 852 getchannel(ctx, &csr.csa_chan, val); 853 csr.csa_mode = 1; 854 csr.csa_count = 5; 855 set80211(ctx, IEEE80211_IOC_CHANSWITCH, 0, sizeof(csr), &csr); 856 } 857 858 static void 859 set80211authmode(if_ctx *ctx, const char *val, int dummy __unused) 860 { 861 int mode; 862 863 if (strcasecmp(val, "none") == 0) { 864 mode = IEEE80211_AUTH_NONE; 865 } else if (strcasecmp(val, "open") == 0) { 866 mode = IEEE80211_AUTH_OPEN; 867 } else if (strcasecmp(val, "shared") == 0) { 868 mode = IEEE80211_AUTH_SHARED; 869 } else if (strcasecmp(val, "8021x") == 0) { 870 mode = IEEE80211_AUTH_8021X; 871 } else if (strcasecmp(val, "wpa") == 0) { 872 mode = IEEE80211_AUTH_WPA; 873 } else { 874 errx(1, "unknown authmode"); 875 } 876 877 set80211(ctx, IEEE80211_IOC_AUTHMODE, mode, 0, NULL); 878 } 879 880 static void 881 set80211powersavemode(if_ctx *ctx, const char *val, int dummy __unused) 882 { 883 int mode; 884 885 if (strcasecmp(val, "off") == 0) { 886 mode = IEEE80211_POWERSAVE_OFF; 887 } else if (strcasecmp(val, "on") == 0) { 888 mode = IEEE80211_POWERSAVE_ON; 889 } else if (strcasecmp(val, "cam") == 0) { 890 mode = IEEE80211_POWERSAVE_CAM; 891 } else if (strcasecmp(val, "psp") == 0) { 892 mode = IEEE80211_POWERSAVE_PSP; 893 } else if (strcasecmp(val, "psp-cam") == 0) { 894 mode = IEEE80211_POWERSAVE_PSP_CAM; 895 } else { 896 errx(1, "unknown powersavemode"); 897 } 898 899 set80211(ctx, IEEE80211_IOC_POWERSAVE, mode, 0, NULL); 900 } 901 902 static void 903 set80211powersave(if_ctx *ctx, const char *val __unused, int d) 904 { 905 if (d == 0) 906 set80211(ctx, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_OFF, 907 0, NULL); 908 else 909 set80211(ctx, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_ON, 910 0, NULL); 911 } 912 913 static void 914 set80211powersavesleep(if_ctx *ctx, const char *val, int dummy __unused) 915 { 916 set80211(ctx, IEEE80211_IOC_POWERSAVESLEEP, atoi(val), 0, NULL); 917 } 918 919 static void 920 set80211wepmode(if_ctx *ctx, const char *val, int dummy __unused) 921 { 922 int mode; 923 924 if (strcasecmp(val, "off") == 0) { 925 mode = IEEE80211_WEP_OFF; 926 } else if (strcasecmp(val, "on") == 0) { 927 mode = IEEE80211_WEP_ON; 928 } else if (strcasecmp(val, "mixed") == 0) { 929 mode = IEEE80211_WEP_MIXED; 930 } else { 931 errx(1, "unknown wep mode"); 932 } 933 934 set80211(ctx, IEEE80211_IOC_WEP, mode, 0, NULL); 935 } 936 937 static void 938 set80211wep(if_ctx *ctx, const char *val __unused, int d) 939 { 940 set80211(ctx, IEEE80211_IOC_WEP, d, 0, NULL); 941 } 942 943 static int 944 isundefarg(const char *arg) 945 { 946 return (strcmp(arg, "-") == 0 || strncasecmp(arg, "undef", 5) == 0); 947 } 948 949 static void 950 set80211weptxkey(if_ctx *ctx, const char *val, int dummy __unused) 951 { 952 if (isundefarg(val)) 953 set80211(ctx, IEEE80211_IOC_WEPTXKEY, IEEE80211_KEYIX_NONE, 0, NULL); 954 else 955 set80211(ctx, IEEE80211_IOC_WEPTXKEY, atoi(val)-1, 0, NULL); 956 } 957 958 static void 959 set80211wepkey(if_ctx *ctx, const char *val, int dummy __unused) 960 { 961 int key = 0; 962 int len; 963 u_int8_t data[IEEE80211_KEYBUF_SIZE]; 964 965 if (isdigit((int)val[0]) && val[1] == ':') { 966 key = atoi(val)-1; 967 val += 2; 968 } 969 970 bzero(data, sizeof(data)); 971 len = sizeof(data); 972 get_string(val, NULL, data, &len); 973 974 set80211(ctx, IEEE80211_IOC_WEPKEY, key, len, data); 975 } 976 977 /* 978 * This function is purely a NetBSD compatibility interface. The NetBSD 979 * interface is too inflexible, but it's there so we'll support it since 980 * it's not all that hard. 981 */ 982 static void 983 set80211nwkey(if_ctx *ctx, const char *val, int dummy __unused) 984 { 985 int txkey; 986 int i, len; 987 u_int8_t data[IEEE80211_KEYBUF_SIZE]; 988 989 set80211(ctx, IEEE80211_IOC_WEP, IEEE80211_WEP_ON, 0, NULL); 990 991 if (isdigit((int)val[0]) && val[1] == ':') { 992 txkey = val[0]-'0'-1; 993 val += 2; 994 995 for (i = 0; i < 4; i++) { 996 bzero(data, sizeof(data)); 997 len = sizeof(data); 998 val = get_string(val, ",", data, &len); 999 if (val == NULL) 1000 exit(1); 1001 1002 set80211(ctx, IEEE80211_IOC_WEPKEY, i, len, data); 1003 } 1004 } else { 1005 bzero(data, sizeof(data)); 1006 len = sizeof(data); 1007 get_string(val, NULL, data, &len); 1008 txkey = 0; 1009 1010 set80211(ctx, IEEE80211_IOC_WEPKEY, 0, len, data); 1011 1012 bzero(data, sizeof(data)); 1013 for (i = 1; i < 4; i++) 1014 set80211(ctx, IEEE80211_IOC_WEPKEY, i, 0, data); 1015 } 1016 1017 set80211(ctx, IEEE80211_IOC_WEPTXKEY, txkey, 0, NULL); 1018 } 1019 1020 static void 1021 set80211rtsthreshold(if_ctx *ctx, const char *val, int dummy __unused) 1022 { 1023 set80211(ctx, IEEE80211_IOC_RTSTHRESHOLD, 1024 isundefarg(val) ? IEEE80211_RTS_MAX : atoi(val), 0, NULL); 1025 } 1026 1027 static void 1028 set80211protmode(if_ctx *ctx, const char *val, int dummy __unused) 1029 { 1030 int mode; 1031 1032 if (strcasecmp(val, "off") == 0) { 1033 mode = IEEE80211_PROTMODE_OFF; 1034 } else if (strcasecmp(val, "cts") == 0) { 1035 mode = IEEE80211_PROTMODE_CTS; 1036 } else if (strncasecmp(val, "rtscts", 3) == 0) { 1037 mode = IEEE80211_PROTMODE_RTSCTS; 1038 } else { 1039 errx(1, "unknown protection mode"); 1040 } 1041 1042 set80211(ctx, IEEE80211_IOC_PROTMODE, mode, 0, NULL); 1043 } 1044 1045 static void 1046 set80211htprotmode(if_ctx *ctx, const char *val, int dummy __unused) 1047 { 1048 int mode; 1049 1050 if (strcasecmp(val, "off") == 0) { 1051 mode = IEEE80211_PROTMODE_OFF; 1052 } else if (strncasecmp(val, "rts", 3) == 0) { 1053 mode = IEEE80211_PROTMODE_RTSCTS; 1054 } else { 1055 errx(1, "unknown protection mode"); 1056 } 1057 1058 set80211(ctx, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL); 1059 } 1060 1061 static void 1062 set80211txpower(if_ctx *ctx, const char *val, int dummy __unused) 1063 { 1064 double v = atof(val); 1065 int txpow; 1066 1067 txpow = (int) (2*v); 1068 if (txpow != 2*v) 1069 errx(-1, "invalid tx power (must be .5 dBm units)"); 1070 set80211(ctx, IEEE80211_IOC_TXPOWER, txpow, 0, NULL); 1071 } 1072 1073 #define IEEE80211_ROAMING_DEVICE 0 1074 #define IEEE80211_ROAMING_AUTO 1 1075 #define IEEE80211_ROAMING_MANUAL 2 1076 1077 static void 1078 set80211roaming(if_ctx *ctx, const char *val, int dummy __unused) 1079 { 1080 int mode; 1081 1082 if (strcasecmp(val, "device") == 0) { 1083 mode = IEEE80211_ROAMING_DEVICE; 1084 } else if (strcasecmp(val, "auto") == 0) { 1085 mode = IEEE80211_ROAMING_AUTO; 1086 } else if (strcasecmp(val, "manual") == 0) { 1087 mode = IEEE80211_ROAMING_MANUAL; 1088 } else { 1089 errx(1, "unknown roaming mode"); 1090 } 1091 set80211(ctx, IEEE80211_IOC_ROAMING, mode, 0, NULL); 1092 } 1093 1094 static void 1095 set80211wme(if_ctx *ctx, const char *val __unused, int d) 1096 { 1097 set80211(ctx, IEEE80211_IOC_WME, d, 0, NULL); 1098 } 1099 1100 static void 1101 set80211hidessid(if_ctx *ctx, const char *val __unused, int d) 1102 { 1103 set80211(ctx, IEEE80211_IOC_HIDESSID, d, 0, NULL); 1104 } 1105 1106 static void 1107 set80211apbridge(if_ctx *ctx, const char *val __unused, int d) 1108 { 1109 set80211(ctx, IEEE80211_IOC_APBRIDGE, d, 0, NULL); 1110 } 1111 1112 static void 1113 set80211fastframes(if_ctx *ctx, const char *val __unused, int d) 1114 { 1115 set80211(ctx, IEEE80211_IOC_FF, d, 0, NULL); 1116 } 1117 1118 static void 1119 set80211dturbo(if_ctx *ctx, const char *val __unused, int d) 1120 { 1121 set80211(ctx, IEEE80211_IOC_TURBOP, d, 0, NULL); 1122 } 1123 1124 static void 1125 set80211chanlist(if_ctx *ctx, const char *val, int dummy __unused) 1126 { 1127 struct ieee80211req_chanlist chanlist; 1128 char *temp, *cp, *tp; 1129 1130 temp = malloc(strlen(val) + 1); 1131 if (temp == NULL) 1132 errx(1, "malloc failed"); 1133 strcpy(temp, val); 1134 memset(&chanlist, 0, sizeof(chanlist)); 1135 cp = temp; 1136 for (;;) { 1137 int first, last, f, c; 1138 1139 tp = strchr(cp, ','); 1140 if (tp != NULL) 1141 *tp++ = '\0'; 1142 switch (sscanf(cp, "%u-%u", &first, &last)) { 1143 case 1: 1144 if (first > IEEE80211_CHAN_MAX) 1145 errx(-1, "channel %u out of range, max %u", 1146 first, IEEE80211_CHAN_MAX); 1147 setbit(chanlist.ic_channels, first); 1148 break; 1149 case 2: 1150 if (first > IEEE80211_CHAN_MAX) 1151 errx(-1, "channel %u out of range, max %u", 1152 first, IEEE80211_CHAN_MAX); 1153 if (last > IEEE80211_CHAN_MAX) 1154 errx(-1, "channel %u out of range, max %u", 1155 last, IEEE80211_CHAN_MAX); 1156 if (first > last) 1157 errx(-1, "void channel range, %u > %u", 1158 first, last); 1159 for (f = first; f <= last; f++) 1160 setbit(chanlist.ic_channels, f); 1161 break; 1162 } 1163 if (tp == NULL) 1164 break; 1165 c = *tp; 1166 while (isspace(c)) 1167 tp++; 1168 if (!isdigit(c)) 1169 break; 1170 cp = tp; 1171 } 1172 set80211(ctx, IEEE80211_IOC_CHANLIST, 0, sizeof(chanlist), &chanlist); 1173 free(temp); 1174 } 1175 1176 static void 1177 set80211bssid(if_ctx *ctx, const char *val, int dummy __unused) 1178 { 1179 if (!isanyarg(val)) { 1180 char *temp; 1181 struct sockaddr_dl sdl; 1182 1183 temp = malloc(strlen(val) + 2); /* ':' and '\0' */ 1184 if (temp == NULL) 1185 errx(1, "malloc failed"); 1186 temp[0] = ':'; 1187 strcpy(temp + 1, val); 1188 sdl.sdl_len = sizeof(sdl); 1189 link_addr(temp, &sdl); 1190 free(temp); 1191 if (sdl.sdl_alen != IEEE80211_ADDR_LEN) 1192 errx(1, "malformed link-level address"); 1193 set80211(ctx, IEEE80211_IOC_BSSID, 0, 1194 IEEE80211_ADDR_LEN, LLADDR(&sdl)); 1195 } else { 1196 uint8_t zerobssid[IEEE80211_ADDR_LEN]; 1197 memset(zerobssid, 0, sizeof(zerobssid)); 1198 set80211(ctx, IEEE80211_IOC_BSSID, 0, 1199 IEEE80211_ADDR_LEN, zerobssid); 1200 } 1201 } 1202 1203 static int 1204 getac(const char *ac) 1205 { 1206 if (strcasecmp(ac, "ac_be") == 0 || strcasecmp(ac, "be") == 0) 1207 return WME_AC_BE; 1208 if (strcasecmp(ac, "ac_bk") == 0 || strcasecmp(ac, "bk") == 0) 1209 return WME_AC_BK; 1210 if (strcasecmp(ac, "ac_vi") == 0 || strcasecmp(ac, "vi") == 0) 1211 return WME_AC_VI; 1212 if (strcasecmp(ac, "ac_vo") == 0 || strcasecmp(ac, "vo") == 0) 1213 return WME_AC_VO; 1214 errx(1, "unknown wme access class %s", ac); 1215 } 1216 1217 static void 1218 set80211cwmin(if_ctx *ctx, const char *ac, const char *val) 1219 { 1220 set80211(ctx, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac), NULL); 1221 } 1222 1223 static void 1224 set80211cwmax(if_ctx *ctx, const char *ac, const char *val) 1225 { 1226 set80211(ctx, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac), NULL); 1227 } 1228 1229 static void 1230 set80211aifs(if_ctx *ctx, const char *ac, const char *val) 1231 { 1232 set80211(ctx, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac), NULL); 1233 } 1234 1235 static void 1236 set80211txoplimit(if_ctx *ctx, const char *ac, const char *val) 1237 { 1238 set80211(ctx, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac), NULL); 1239 } 1240 1241 static void 1242 set80211acm(if_ctx *ctx, const char *ac, int dummy __unused) 1243 { 1244 set80211(ctx, IEEE80211_IOC_WME_ACM, 1, getac(ac), NULL); 1245 } 1246 1247 static void 1248 set80211noacm(if_ctx *ctx, const char *ac, int dummy __unused) 1249 { 1250 set80211(ctx, IEEE80211_IOC_WME_ACM, 0, getac(ac), NULL); 1251 } 1252 1253 static void 1254 set80211ackpolicy(if_ctx *ctx, const char *ac, int dummy __unused) 1255 { 1256 set80211(ctx, IEEE80211_IOC_WME_ACKPOLICY, 1, getac(ac), NULL); 1257 } 1258 static void 1259 set80211noackpolicy(if_ctx *ctx, const char *ac, int dummy __unused) 1260 { 1261 set80211(ctx, IEEE80211_IOC_WME_ACKPOLICY, 0, getac(ac), NULL); 1262 } 1263 1264 static void 1265 set80211bsscwmin(if_ctx *ctx, const char *ac, const char *val) 1266 { 1267 set80211(ctx, IEEE80211_IOC_WME_CWMIN, atoi(val), 1268 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL); 1269 } 1270 1271 static void 1272 set80211bsscwmax(if_ctx *ctx, const char *ac, const char *val) 1273 { 1274 set80211(ctx, IEEE80211_IOC_WME_CWMAX, atoi(val), 1275 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL); 1276 } 1277 1278 static void 1279 set80211bssaifs(if_ctx *ctx, const char *ac, const char *val) 1280 { 1281 set80211(ctx, IEEE80211_IOC_WME_AIFS, atoi(val), 1282 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL); 1283 } 1284 1285 static void 1286 set80211bsstxoplimit(if_ctx *ctx, const char *ac, const char *val) 1287 { 1288 set80211(ctx, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), 1289 getac(ac)|IEEE80211_WMEPARAM_BSS, NULL); 1290 } 1291 1292 static void 1293 set80211dtimperiod(if_ctx *ctx, const char *val, int dummy __unused) 1294 { 1295 set80211(ctx, IEEE80211_IOC_DTIM_PERIOD, atoi(val), 0, NULL); 1296 } 1297 1298 static void 1299 set80211bintval(if_ctx *ctx, const char *val, int dummy __unused) 1300 { 1301 set80211(ctx, IEEE80211_IOC_BEACON_INTERVAL, atoi(val), 0, NULL); 1302 } 1303 1304 static void 1305 set80211macmac(if_ctx *ctx, int op, const char *val) 1306 { 1307 char *temp; 1308 struct sockaddr_dl sdl; 1309 1310 temp = malloc(strlen(val) + 2); /* ':' and '\0' */ 1311 if (temp == NULL) 1312 errx(1, "malloc failed"); 1313 temp[0] = ':'; 1314 strcpy(temp + 1, val); 1315 sdl.sdl_len = sizeof(sdl); 1316 link_addr(temp, &sdl); 1317 free(temp); 1318 if (sdl.sdl_alen != IEEE80211_ADDR_LEN) 1319 errx(1, "malformed link-level address"); 1320 set80211(ctx, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl)); 1321 } 1322 1323 static void 1324 set80211addmac(if_ctx *ctx, const char *val, int dummy __unused) 1325 { 1326 set80211macmac(ctx, IEEE80211_IOC_ADDMAC, val); 1327 } 1328 1329 static void 1330 set80211delmac(if_ctx *ctx, const char *val, int dummy __unused) 1331 { 1332 set80211macmac(ctx, IEEE80211_IOC_DELMAC, val); 1333 } 1334 1335 static void 1336 set80211kickmac(if_ctx *ctx, const char *val, int dummy __unused) 1337 { 1338 char *temp; 1339 struct sockaddr_dl sdl; 1340 struct ieee80211req_mlme mlme; 1341 1342 temp = malloc(strlen(val) + 2); /* ':' and '\0' */ 1343 if (temp == NULL) 1344 errx(1, "malloc failed"); 1345 temp[0] = ':'; 1346 strcpy(temp + 1, val); 1347 sdl.sdl_len = sizeof(sdl); 1348 link_addr(temp, &sdl); 1349 free(temp); 1350 if (sdl.sdl_alen != IEEE80211_ADDR_LEN) 1351 errx(1, "malformed link-level address"); 1352 memset(&mlme, 0, sizeof(mlme)); 1353 mlme.im_op = IEEE80211_MLME_DEAUTH; 1354 mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE; 1355 memcpy(mlme.im_macaddr, LLADDR(&sdl), IEEE80211_ADDR_LEN); 1356 set80211(ctx, IEEE80211_IOC_MLME, 0, sizeof(mlme), &mlme); 1357 } 1358 1359 static void 1360 set80211maccmd(if_ctx *ctx, const char *val __unused, int d) 1361 { 1362 set80211(ctx, IEEE80211_IOC_MACCMD, d, 0, NULL); 1363 } 1364 1365 static void 1366 set80211meshrtmac(if_ctx *ctx, int req, const char *val) 1367 { 1368 char *temp; 1369 struct sockaddr_dl sdl; 1370 1371 temp = malloc(strlen(val) + 2); /* ':' and '\0' */ 1372 if (temp == NULL) 1373 errx(1, "malloc failed"); 1374 temp[0] = ':'; 1375 strcpy(temp + 1, val); 1376 sdl.sdl_len = sizeof(sdl); 1377 link_addr(temp, &sdl); 1378 free(temp); 1379 if (sdl.sdl_alen != IEEE80211_ADDR_LEN) 1380 errx(1, "malformed link-level address"); 1381 set80211(ctx, IEEE80211_IOC_MESH_RTCMD, req, 1382 IEEE80211_ADDR_LEN, LLADDR(&sdl)); 1383 } 1384 1385 static void 1386 set80211addmeshrt(if_ctx *ctx, const char *val, int dummy __unused) 1387 { 1388 set80211meshrtmac(ctx, IEEE80211_MESH_RTCMD_ADD, val); 1389 } 1390 1391 static void 1392 set80211delmeshrt(if_ctx *ctx, const char *val, int dummy __unused) 1393 { 1394 set80211meshrtmac(ctx, IEEE80211_MESH_RTCMD_DELETE, val); 1395 } 1396 1397 static void 1398 set80211meshrtcmd(if_ctx *ctx, const char *val __unused, int d) 1399 { 1400 set80211(ctx, IEEE80211_IOC_MESH_RTCMD, d, 0, NULL); 1401 } 1402 1403 static void 1404 set80211hwmprootmode(if_ctx *ctx, const char *val, int dummy __unused) 1405 { 1406 int mode; 1407 1408 if (strcasecmp(val, "normal") == 0) 1409 mode = IEEE80211_HWMP_ROOTMODE_NORMAL; 1410 else if (strcasecmp(val, "proactive") == 0) 1411 mode = IEEE80211_HWMP_ROOTMODE_PROACTIVE; 1412 else if (strcasecmp(val, "rann") == 0) 1413 mode = IEEE80211_HWMP_ROOTMODE_RANN; 1414 else 1415 mode = IEEE80211_HWMP_ROOTMODE_DISABLED; 1416 set80211(ctx, IEEE80211_IOC_HWMP_ROOTMODE, mode, 0, NULL); 1417 } 1418 1419 static void 1420 set80211hwmpmaxhops(if_ctx *ctx, const char *val, int dummy __unused) 1421 { 1422 set80211(ctx, IEEE80211_IOC_HWMP_MAXHOPS, atoi(val), 0, NULL); 1423 } 1424 1425 static void 1426 set80211pureg(if_ctx *ctx, const char *val __unused, int d) 1427 { 1428 set80211(ctx, IEEE80211_IOC_PUREG, d, 0, NULL); 1429 } 1430 1431 static void 1432 set80211quiet(if_ctx *ctx, const char *val __unused, int d) 1433 { 1434 set80211(ctx, IEEE80211_IOC_QUIET, d, 0, NULL); 1435 } 1436 1437 static void 1438 set80211quietperiod(if_ctx *ctx, const char *val, int dummy __unused) 1439 { 1440 set80211(ctx, IEEE80211_IOC_QUIET_PERIOD, atoi(val), 0, NULL); 1441 } 1442 1443 static void 1444 set80211quietcount(if_ctx *ctx, const char *val, int dummy __unused) 1445 { 1446 set80211(ctx, IEEE80211_IOC_QUIET_COUNT, atoi(val), 0, NULL); 1447 } 1448 1449 static void 1450 set80211quietduration(if_ctx *ctx, const char *val, int dummy __unused) 1451 { 1452 set80211(ctx, IEEE80211_IOC_QUIET_DUR, atoi(val), 0, NULL); 1453 } 1454 1455 static void 1456 set80211quietoffset(if_ctx *ctx, const char *val, int dummy __unused) 1457 { 1458 set80211(ctx, IEEE80211_IOC_QUIET_OFFSET, atoi(val), 0, NULL); 1459 } 1460 1461 static void 1462 set80211bgscan(if_ctx *ctx, const char *val __unused, int d) 1463 { 1464 set80211(ctx, IEEE80211_IOC_BGSCAN, d, 0, NULL); 1465 } 1466 1467 static void 1468 set80211bgscanidle(if_ctx *ctx, const char *val, int dummy __unused) 1469 { 1470 set80211(ctx, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL); 1471 } 1472 1473 static void 1474 set80211bgscanintvl(if_ctx *ctx, const char *val, int dummy __unused) 1475 { 1476 set80211(ctx, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL); 1477 } 1478 1479 static void 1480 set80211scanvalid(if_ctx *ctx, const char *val, int dummy __unused) 1481 { 1482 set80211(ctx, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL); 1483 } 1484 1485 /* 1486 * Parse an optional trailing specification of which netbands 1487 * to apply a parameter to. This is basically the same syntax 1488 * as used for channels but you can concatenate to specify 1489 * multiple. For example: 1490 * 14:abg apply to 11a, 11b, and 11g 1491 * 6:ht apply to 11na and 11ng 1492 * We don't make a big effort to catch silly things; this is 1493 * really a convenience mechanism. 1494 */ 1495 static int 1496 getmodeflags(const char *val) 1497 { 1498 const char *cp; 1499 int flags; 1500 1501 flags = 0; 1502 1503 cp = strchr(val, ':'); 1504 if (cp != NULL) { 1505 for (cp++; isalpha((int) *cp); cp++) { 1506 /* accept mixed case */ 1507 int c = *cp; 1508 if (isupper(c)) 1509 c = tolower(c); 1510 switch (c) { 1511 case 'a': /* 802.11a */ 1512 flags |= IEEE80211_CHAN_A; 1513 break; 1514 case 'b': /* 802.11b */ 1515 flags |= IEEE80211_CHAN_B; 1516 break; 1517 case 'g': /* 802.11g */ 1518 flags |= IEEE80211_CHAN_G; 1519 break; 1520 case 'n': /* 802.11n */ 1521 flags |= IEEE80211_CHAN_HT; 1522 break; 1523 case 'd': /* dt = Atheros Dynamic Turbo */ 1524 flags |= IEEE80211_CHAN_TURBO; 1525 break; 1526 case 't': /* ht, dt, st, t */ 1527 /* dt and unadorned t specify Dynamic Turbo */ 1528 if ((flags & (IEEE80211_CHAN_STURBO|IEEE80211_CHAN_HT)) == 0) 1529 flags |= IEEE80211_CHAN_TURBO; 1530 break; 1531 case 's': /* st = Atheros Static Turbo */ 1532 flags |= IEEE80211_CHAN_STURBO; 1533 break; 1534 case 'h': /* 1/2-width channels */ 1535 flags |= IEEE80211_CHAN_HALF; 1536 break; 1537 case 'q': /* 1/4-width channels */ 1538 flags |= IEEE80211_CHAN_QUARTER; 1539 break; 1540 case 'v': 1541 /* XXX set HT too? */ 1542 flags |= IEEE80211_CHAN_VHT; 1543 break; 1544 default: 1545 errx(-1, "%s: Invalid mode attribute %c\n", 1546 val, *cp); 1547 } 1548 } 1549 } 1550 return flags; 1551 } 1552 1553 #define _APPLY(_flags, _base, _param, _v) do { \ 1554 if (_flags & IEEE80211_CHAN_HT) { \ 1555 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\ 1556 _base.params[IEEE80211_MODE_11NA]._param = _v; \ 1557 _base.params[IEEE80211_MODE_11NG]._param = _v; \ 1558 } else if (_flags & IEEE80211_CHAN_5GHZ) \ 1559 _base.params[IEEE80211_MODE_11NA]._param = _v; \ 1560 else \ 1561 _base.params[IEEE80211_MODE_11NG]._param = _v; \ 1562 } \ 1563 if (_flags & IEEE80211_CHAN_TURBO) { \ 1564 if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\ 1565 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \ 1566 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \ 1567 } else if (_flags & IEEE80211_CHAN_5GHZ) \ 1568 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \ 1569 else \ 1570 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \ 1571 } \ 1572 if (_flags & IEEE80211_CHAN_STURBO) \ 1573 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \ 1574 if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \ 1575 _base.params[IEEE80211_MODE_11A]._param = _v; \ 1576 if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \ 1577 _base.params[IEEE80211_MODE_11G]._param = _v; \ 1578 if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \ 1579 _base.params[IEEE80211_MODE_11B]._param = _v; \ 1580 if (_flags & IEEE80211_CHAN_HALF) \ 1581 _base.params[IEEE80211_MODE_HALF]._param = _v; \ 1582 if (_flags & IEEE80211_CHAN_QUARTER) \ 1583 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \ 1584 } while (0) 1585 #define _APPLY1(_flags, _base, _param, _v) do { \ 1586 if (_flags & IEEE80211_CHAN_HT) { \ 1587 if (_flags & IEEE80211_CHAN_5GHZ) \ 1588 _base.params[IEEE80211_MODE_11NA]._param = _v; \ 1589 else \ 1590 _base.params[IEEE80211_MODE_11NG]._param = _v; \ 1591 } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \ 1592 _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \ 1593 else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \ 1594 _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \ 1595 else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \ 1596 _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \ 1597 else if (_flags & IEEE80211_CHAN_HALF) \ 1598 _base.params[IEEE80211_MODE_HALF]._param = _v; \ 1599 else if (_flags & IEEE80211_CHAN_QUARTER) \ 1600 _base.params[IEEE80211_MODE_QUARTER]._param = _v; \ 1601 else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \ 1602 _base.params[IEEE80211_MODE_11A]._param = _v; \ 1603 else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \ 1604 _base.params[IEEE80211_MODE_11G]._param = _v; \ 1605 else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \ 1606 _base.params[IEEE80211_MODE_11B]._param = _v; \ 1607 } while (0) 1608 #define _APPLY_RATE(_flags, _base, _param, _v) do { \ 1609 if (_flags & IEEE80211_CHAN_HT) { \ 1610 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \ 1611 } \ 1612 _APPLY(_flags, _base, _param, _v); \ 1613 } while (0) 1614 #define _APPLY_RATE1(_flags, _base, _param, _v) do { \ 1615 if (_flags & IEEE80211_CHAN_HT) { \ 1616 (_v) = (_v / 2) | IEEE80211_RATE_MCS; \ 1617 } \ 1618 _APPLY1(_flags, _base, _param, _v); \ 1619 } while (0) 1620 1621 static void 1622 set80211roamrssi(if_ctx *ctx, const char *val, int dummy __unused) 1623 { 1624 double v = atof(val); 1625 int rssi, flags; 1626 1627 rssi = (int) (2*v); 1628 if (rssi != 2*v) 1629 errx(-1, "invalid rssi (must be .5 dBm units)"); 1630 flags = getmodeflags(val); 1631 getroam(ctx); 1632 if (flags == 0) { /* NB: no flags => current channel */ 1633 flags = getcurchan(ctx)->ic_flags; 1634 _APPLY1(flags, roamparams, rssi, rssi); 1635 } else 1636 _APPLY(flags, roamparams, rssi, rssi); 1637 callback_register(setroam_cb, &roamparams); 1638 } 1639 1640 static int 1641 getrate(const char *val, const char *tag) 1642 { 1643 double v = atof(val); 1644 int rate; 1645 1646 rate = (int) (2*v); 1647 if (rate != 2*v) 1648 errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag); 1649 return rate; /* NB: returns 2x the specified value */ 1650 } 1651 1652 static void 1653 set80211roamrate(if_ctx *ctx, const char *val, int dummy __unused) 1654 { 1655 int rate, flags; 1656 1657 rate = getrate(val, "roam"); 1658 flags = getmodeflags(val); 1659 getroam(ctx); 1660 if (flags == 0) { /* NB: no flags => current channel */ 1661 flags = getcurchan(ctx)->ic_flags; 1662 _APPLY_RATE1(flags, roamparams, rate, rate); 1663 } else 1664 _APPLY_RATE(flags, roamparams, rate, rate); 1665 callback_register(setroam_cb, &roamparams); 1666 } 1667 1668 static void 1669 set80211mcastrate(if_ctx *ctx, const char *val, int dummy __unused) 1670 { 1671 int rate, flags; 1672 1673 rate = getrate(val, "mcast"); 1674 flags = getmodeflags(val); 1675 gettxparams(ctx); 1676 if (flags == 0) { /* NB: no flags => current channel */ 1677 flags = getcurchan(ctx)->ic_flags; 1678 _APPLY_RATE1(flags, txparams, mcastrate, rate); 1679 } else 1680 _APPLY_RATE(flags, txparams, mcastrate, rate); 1681 callback_register(settxparams_cb, &txparams); 1682 } 1683 1684 static void 1685 set80211mgtrate(if_ctx *ctx, const char *val, int dummy __unused) 1686 { 1687 int rate, flags; 1688 1689 rate = getrate(val, "mgmt"); 1690 flags = getmodeflags(val); 1691 gettxparams(ctx); 1692 if (flags == 0) { /* NB: no flags => current channel */ 1693 flags = getcurchan(ctx)->ic_flags; 1694 _APPLY_RATE1(flags, txparams, mgmtrate, rate); 1695 } else 1696 _APPLY_RATE(flags, txparams, mgmtrate, rate); 1697 callback_register(settxparams_cb, &txparams); 1698 } 1699 1700 static void 1701 set80211ucastrate(if_ctx *ctx, const char *val, int dummy __unused) 1702 { 1703 int flags; 1704 1705 gettxparams(ctx); 1706 flags = getmodeflags(val); 1707 if (isanyarg(val)) { 1708 if (flags == 0) { /* NB: no flags => current channel */ 1709 flags = getcurchan(ctx)->ic_flags; 1710 _APPLY1(flags, txparams, ucastrate, 1711 IEEE80211_FIXED_RATE_NONE); 1712 } else 1713 _APPLY(flags, txparams, ucastrate, 1714 IEEE80211_FIXED_RATE_NONE); 1715 } else { 1716 int rate = getrate(val, "ucast"); 1717 if (flags == 0) { /* NB: no flags => current channel */ 1718 flags = getcurchan(ctx)->ic_flags; 1719 _APPLY_RATE1(flags, txparams, ucastrate, rate); 1720 } else 1721 _APPLY_RATE(flags, txparams, ucastrate, rate); 1722 } 1723 callback_register(settxparams_cb, &txparams); 1724 } 1725 1726 static void 1727 set80211maxretry(if_ctx *ctx, const char *val, int dummy __unused) 1728 { 1729 int v = atoi(val), flags; 1730 1731 flags = getmodeflags(val); 1732 gettxparams(ctx); 1733 if (flags == 0) { /* NB: no flags => current channel */ 1734 flags = getcurchan(ctx)->ic_flags; 1735 _APPLY1(flags, txparams, maxretry, v); 1736 } else 1737 _APPLY(flags, txparams, maxretry, v); 1738 callback_register(settxparams_cb, &txparams); 1739 } 1740 #undef _APPLY_RATE 1741 #undef _APPLY 1742 1743 static void 1744 set80211fragthreshold(if_ctx *ctx, const char *val, int dummy __unused) 1745 { 1746 set80211(ctx, IEEE80211_IOC_FRAGTHRESHOLD, 1747 isundefarg(val) ? IEEE80211_FRAG_MAX : atoi(val), 0, NULL); 1748 } 1749 1750 static void 1751 set80211bmissthreshold(if_ctx *ctx, const char *val, int dummy __unused) 1752 { 1753 set80211(ctx, IEEE80211_IOC_BMISSTHRESHOLD, 1754 isundefarg(val) ? IEEE80211_HWBMISS_MAX : atoi(val), 0, NULL); 1755 } 1756 1757 static void 1758 set80211burst(if_ctx *ctx, const char *val __unused, int d) 1759 { 1760 set80211(ctx, IEEE80211_IOC_BURST, d, 0, NULL); 1761 } 1762 1763 static void 1764 set80211doth(if_ctx *ctx, const char *val __unused, int d) 1765 { 1766 set80211(ctx, IEEE80211_IOC_DOTH, d, 0, NULL); 1767 } 1768 1769 static void 1770 set80211dfs(if_ctx *ctx, const char *val __unused, int d) 1771 { 1772 set80211(ctx, IEEE80211_IOC_DFS, d, 0, NULL); 1773 } 1774 1775 static void 1776 set80211shortgi(if_ctx *ctx, const char *val __unused, int d) 1777 { 1778 set80211(ctx, IEEE80211_IOC_SHORTGI, 1779 d ? (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) : 0, 1780 0, NULL); 1781 } 1782 1783 /* XXX 11ac density/size is different */ 1784 static void 1785 set80211ampdu(if_ctx *ctx, const char *val __unused, int d) 1786 { 1787 int ampdu; 1788 1789 if (get80211val(ctx, IEEE80211_IOC_AMPDU, &du) < 0) 1790 errx(-1, "cannot set AMPDU setting"); 1791 if (d < 0) { 1792 d = -d; 1793 ampdu &= ~d; 1794 } else 1795 ampdu |= d; 1796 set80211(ctx, IEEE80211_IOC_AMPDU, ampdu, 0, NULL); 1797 } 1798 1799 static void 1800 set80211stbc(if_ctx *ctx, const char *val __unused, int d) 1801 { 1802 int stbc; 1803 1804 if (get80211val(ctx, IEEE80211_IOC_STBC, &stbc) < 0) 1805 errx(-1, "cannot set STBC setting"); 1806 if (d < 0) { 1807 d = -d; 1808 stbc &= ~d; 1809 } else 1810 stbc |= d; 1811 set80211(ctx, IEEE80211_IOC_STBC, stbc, 0, NULL); 1812 } 1813 1814 static void 1815 set80211ldpc(if_ctx *ctx, const char *val __unused, int d) 1816 { 1817 int ldpc; 1818 1819 if (get80211val(ctx, IEEE80211_IOC_LDPC, &ldpc) < 0) 1820 errx(-1, "cannot set LDPC setting"); 1821 if (d < 0) { 1822 d = -d; 1823 ldpc &= ~d; 1824 } else 1825 ldpc |= d; 1826 set80211(ctx, IEEE80211_IOC_LDPC, ldpc, 0, NULL); 1827 } 1828 1829 static void 1830 set80211uapsd(if_ctx *ctx, const char *val __unused, int d) 1831 { 1832 set80211(ctx, IEEE80211_IOC_UAPSD, d, 0, NULL); 1833 } 1834 1835 static void 1836 set80211ampdulimit(if_ctx *ctx, const char *val, int dummy __unused) 1837 { 1838 int v; 1839 1840 switch (atoi(val)) { 1841 case 8: 1842 case 8*1024: 1843 v = IEEE80211_HTCAP_MAXRXAMPDU_8K; 1844 break; 1845 case 16: 1846 case 16*1024: 1847 v = IEEE80211_HTCAP_MAXRXAMPDU_16K; 1848 break; 1849 case 32: 1850 case 32*1024: 1851 v = IEEE80211_HTCAP_MAXRXAMPDU_32K; 1852 break; 1853 case 64: 1854 case 64*1024: 1855 v = IEEE80211_HTCAP_MAXRXAMPDU_64K; 1856 break; 1857 default: 1858 errx(-1, "invalid A-MPDU limit %s", val); 1859 } 1860 set80211(ctx, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL); 1861 } 1862 1863 /* XXX 11ac density/size is different */ 1864 static void 1865 set80211ampdudensity(if_ctx *ctx, const char *val, int dummy __unused) 1866 { 1867 int v; 1868 1869 if (isanyarg(val) || strcasecmp(val, "na") == 0) 1870 v = IEEE80211_HTCAP_MPDUDENSITY_NA; 1871 else switch ((int)(atof(val)*4)) { 1872 case 0: 1873 v = IEEE80211_HTCAP_MPDUDENSITY_NA; 1874 break; 1875 case 1: 1876 v = IEEE80211_HTCAP_MPDUDENSITY_025; 1877 break; 1878 case 2: 1879 v = IEEE80211_HTCAP_MPDUDENSITY_05; 1880 break; 1881 case 4: 1882 v = IEEE80211_HTCAP_MPDUDENSITY_1; 1883 break; 1884 case 8: 1885 v = IEEE80211_HTCAP_MPDUDENSITY_2; 1886 break; 1887 case 16: 1888 v = IEEE80211_HTCAP_MPDUDENSITY_4; 1889 break; 1890 case 32: 1891 v = IEEE80211_HTCAP_MPDUDENSITY_8; 1892 break; 1893 case 64: 1894 v = IEEE80211_HTCAP_MPDUDENSITY_16; 1895 break; 1896 default: 1897 errx(-1, "invalid A-MPDU density %s", val); 1898 } 1899 set80211(ctx, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL); 1900 } 1901 1902 static void 1903 set80211amsdu(if_ctx *ctx, const char *val __unused, int d) 1904 { 1905 int amsdu; 1906 1907 if (get80211val(ctx, IEEE80211_IOC_AMSDU, &amsdu) < 0) 1908 err(-1, "cannot get AMSDU setting"); 1909 if (d < 0) { 1910 d = -d; 1911 amsdu &= ~d; 1912 } else 1913 amsdu |= d; 1914 set80211(ctx, IEEE80211_IOC_AMSDU, amsdu, 0, NULL); 1915 } 1916 1917 static void 1918 set80211amsdulimit(if_ctx *ctx, const char *val, int dummy __unused) 1919 { 1920 set80211(ctx, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL); 1921 } 1922 1923 static void 1924 set80211puren(if_ctx *ctx, const char *val __unused, int d) 1925 { 1926 set80211(ctx, IEEE80211_IOC_PUREN, d, 0, NULL); 1927 } 1928 1929 static void 1930 set80211htcompat(if_ctx *ctx, const char *val __unused, int d) 1931 { 1932 set80211(ctx, IEEE80211_IOC_HTCOMPAT, d, 0, NULL); 1933 } 1934 1935 static void 1936 set80211htconf(if_ctx *ctx, const char *val __unused, int d) 1937 { 1938 set80211(ctx, IEEE80211_IOC_HTCONF, d, 0, NULL); 1939 htconf = d; 1940 } 1941 1942 static void 1943 set80211dwds(if_ctx *ctx, const char *val __unused, int d) 1944 { 1945 set80211(ctx, IEEE80211_IOC_DWDS, d, 0, NULL); 1946 } 1947 1948 static void 1949 set80211inact(if_ctx *ctx, const char *val __unused, int d) 1950 { 1951 set80211(ctx, IEEE80211_IOC_INACTIVITY, d, 0, NULL); 1952 } 1953 1954 static void 1955 set80211tsn(if_ctx *ctx, const char *val __unused, int d) 1956 { 1957 set80211(ctx, IEEE80211_IOC_TSN, d, 0, NULL); 1958 } 1959 1960 static void 1961 set80211dotd(if_ctx *ctx, const char *val __unused, int d) 1962 { 1963 set80211(ctx, IEEE80211_IOC_DOTD, d, 0, NULL); 1964 } 1965 1966 static void 1967 set80211smps(if_ctx *ctx, const char *val __unused, int d) 1968 { 1969 set80211(ctx, IEEE80211_IOC_SMPS, d, 0, NULL); 1970 } 1971 1972 static void 1973 set80211rifs(if_ctx *ctx, const char *val __unused, int d) 1974 { 1975 set80211(ctx, IEEE80211_IOC_RIFS, d, 0, NULL); 1976 } 1977 1978 static void 1979 set80211vhtconf(if_ctx *ctx, const char *val __unused, int d) 1980 { 1981 if (get80211val(ctx, IEEE80211_IOC_VHTCONF, &vhtconf) < 0) 1982 errx(-1, "cannot set VHT setting"); 1983 if (d < 0) { 1984 d = -d; 1985 vhtconf &= ~d; 1986 } else 1987 vhtconf |= d; 1988 set80211(ctx, IEEE80211_IOC_VHTCONF, vhtconf, 0, NULL); 1989 } 1990 1991 static void 1992 set80211tdmaslot(if_ctx *ctx, const char *val, int dummy __unused) 1993 { 1994 set80211(ctx, IEEE80211_IOC_TDMA_SLOT, atoi(val), 0, NULL); 1995 } 1996 1997 static void 1998 set80211tdmaslotcnt(if_ctx *ctx, const char *val, int dummy __unused) 1999 { 2000 set80211(ctx, IEEE80211_IOC_TDMA_SLOTCNT, atoi(val), 0, NULL); 2001 } 2002 2003 static void 2004 set80211tdmaslotlen(if_ctx *ctx, const char *val, int dummy __unused) 2005 { 2006 set80211(ctx, IEEE80211_IOC_TDMA_SLOTLEN, atoi(val), 0, NULL); 2007 } 2008 2009 static void 2010 set80211tdmabintval(if_ctx *ctx, const char *val, int dummy __unused) 2011 { 2012 set80211(ctx, IEEE80211_IOC_TDMA_BINTERVAL, atoi(val), 0, NULL); 2013 } 2014 2015 static void 2016 set80211meshttl(if_ctx *ctx, const char *val, int dummy __unused) 2017 { 2018 set80211(ctx, IEEE80211_IOC_MESH_TTL, atoi(val), 0, NULL); 2019 } 2020 2021 static void 2022 set80211meshforward(if_ctx *ctx, const char *val __unused, int d) 2023 { 2024 set80211(ctx, IEEE80211_IOC_MESH_FWRD, d, 0, NULL); 2025 } 2026 2027 static void 2028 set80211meshgate(if_ctx *ctx, const char *val __unused, int d) 2029 { 2030 set80211(ctx, IEEE80211_IOC_MESH_GATE, d, 0, NULL); 2031 } 2032 2033 static void 2034 set80211meshpeering(if_ctx *ctx, const char *val __unused, int d) 2035 { 2036 set80211(ctx, IEEE80211_IOC_MESH_AP, d, 0, NULL); 2037 } 2038 2039 static void 2040 set80211meshmetric(if_ctx *ctx, const char *val, int dummy __unused) 2041 { 2042 char v[12]; 2043 2044 memcpy(v, val, sizeof(v)); 2045 set80211(ctx, IEEE80211_IOC_MESH_PR_METRIC, 0, 0, v); 2046 } 2047 2048 static void 2049 set80211meshpath(if_ctx *ctx, const char *val, int dummy __unused) 2050 { 2051 char v[12]; 2052 2053 memcpy(v, val, sizeof(v)); 2054 set80211(ctx, IEEE80211_IOC_MESH_PR_PATH, 0, 0, v); 2055 } 2056 2057 static int 2058 regdomain_sort(const void *a, const void *b) 2059 { 2060 #define CHAN_ALL \ 2061 (IEEE80211_CHAN_ALLTURBO|IEEE80211_CHAN_HALF|IEEE80211_CHAN_QUARTER) 2062 const struct ieee80211_channel *ca = a; 2063 const struct ieee80211_channel *cb = b; 2064 2065 return ca->ic_freq == cb->ic_freq ? 2066 (int)(ca->ic_flags & CHAN_ALL) - (int)(cb->ic_flags & CHAN_ALL) : 2067 ca->ic_freq - cb->ic_freq; 2068 #undef CHAN_ALL 2069 } 2070 2071 static const struct ieee80211_channel * 2072 chanlookup(const struct ieee80211_channel chans[], int nchans, 2073 int freq, uint32_t flags) 2074 { 2075 int i; 2076 2077 flags &= IEEE80211_CHAN_ALLTURBO; 2078 for (i = 0; i < nchans; i++) { 2079 const struct ieee80211_channel *c = &chans[i]; 2080 if (c->ic_freq == freq && 2081 (c->ic_flags & IEEE80211_CHAN_ALLTURBO) == flags) 2082 return c; 2083 } 2084 return NULL; 2085 } 2086 2087 static int 2088 chanfind(const struct ieee80211_channel chans[], int nchans, uint32_t flags) 2089 { 2090 for (int i = 0; i < nchans; i++) { 2091 const struct ieee80211_channel *c = &chans[i]; 2092 if ((c->ic_flags & flags) == flags) 2093 return 1; 2094 } 2095 return 0; 2096 } 2097 2098 /* 2099 * Check channel compatibility. 2100 */ 2101 static int 2102 checkchan(const struct ieee80211req_chaninfo *avail, int freq, uint32_t flags) 2103 { 2104 flags &= ~REQ_FLAGS; 2105 /* 2106 * Check if exact channel is in the calibration table; 2107 * everything below is to deal with channels that we 2108 * want to include but that are not explicitly listed. 2109 */ 2110 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, flags) != NULL) 2111 return 1; 2112 if (flags & IEEE80211_CHAN_GSM) { 2113 /* 2114 * XXX GSM frequency mapping is handled in the kernel 2115 * so we cannot find them in the calibration table; 2116 * just accept the channel and the kernel will reject 2117 * the channel list if it's wrong. 2118 */ 2119 return 1; 2120 } 2121 /* 2122 * If this is a 1/2 or 1/4 width channel allow it if a full 2123 * width channel is present for this frequency, and the device 2124 * supports fractional channels on this band. This is a hack 2125 * that avoids bloating the calibration table; it may be better 2126 * by per-band attributes though (we are effectively calculating 2127 * this attribute by scanning the channel list ourself). 2128 */ 2129 if ((flags & (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == 0) 2130 return 0; 2131 if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, 2132 flags &~ (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == NULL) 2133 return 0; 2134 if (flags & IEEE80211_CHAN_HALF) { 2135 return chanfind(avail->ic_chans, avail->ic_nchans, 2136 IEEE80211_CHAN_HALF | 2137 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ))); 2138 } else { 2139 return chanfind(avail->ic_chans, avail->ic_nchans, 2140 IEEE80211_CHAN_QUARTER | 2141 (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ))); 2142 } 2143 } 2144 2145 static void 2146 regdomain_addchans(if_ctx *ctx, struct ieee80211req_chaninfo *ci, 2147 const netband_head *bands, 2148 const struct ieee80211_regdomain *reg, 2149 uint32_t chanFlags, 2150 const struct ieee80211req_chaninfo *avail) 2151 { 2152 const struct netband *nb; 2153 const struct freqband *b; 2154 struct ieee80211_channel *c, *prev; 2155 int freq, hi_adj, lo_adj, channelSep; 2156 uint32_t flags; 2157 const int verbose = ctx->args->verbose; 2158 2159 hi_adj = (chanFlags & IEEE80211_CHAN_HT40U) ? -20 : 0; 2160 lo_adj = (chanFlags & IEEE80211_CHAN_HT40D) ? 20 : 0; 2161 channelSep = (chanFlags & IEEE80211_CHAN_2GHZ) ? 0 : 40; 2162 2163 LIST_FOREACH(nb, bands, next) { 2164 b = nb->band; 2165 if (verbose) { 2166 printf("%s:", __func__); 2167 printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS); 2168 printb(" bandFlags", nb->flags | b->flags, 2169 IEEE80211_CHAN_BITS); 2170 putchar('\n'); 2171 } 2172 prev = NULL; 2173 2174 for (freq = b->freqStart + lo_adj; 2175 freq <= b->freqEnd + hi_adj; freq += b->chanSep) { 2176 /* 2177 * Construct flags for the new channel. We take 2178 * the attributes from the band descriptions except 2179 * for HT40 which is enabled generically (i.e. +/- 2180 * extension channel) in the band description and 2181 * then constrained according by channel separation. 2182 */ 2183 flags = nb->flags | b->flags; 2184 2185 /* 2186 * VHT first - HT is a subset. 2187 */ 2188 if (flags & IEEE80211_CHAN_VHT) { 2189 if ((chanFlags & IEEE80211_CHAN_VHT20) && 2190 (flags & IEEE80211_CHAN_VHT20) == 0) { 2191 if (verbose) 2192 printf("%u: skip, not a " 2193 "VHT20 channel\n", freq); 2194 continue; 2195 } 2196 if ((chanFlags & IEEE80211_CHAN_VHT40) && 2197 (flags & IEEE80211_CHAN_VHT40) == 0) { 2198 if (verbose) 2199 printf("%u: skip, not a " 2200 "VHT40 channel\n", freq); 2201 continue; 2202 } 2203 if ((chanFlags & IEEE80211_CHAN_VHT80) && 2204 (flags & IEEE80211_CHAN_VHT80) == 0) { 2205 if (verbose) 2206 printf("%u: skip, not a " 2207 "VHT80 channel\n", freq); 2208 continue; 2209 } 2210 if ((chanFlags & IEEE80211_CHAN_VHT160) && 2211 (flags & IEEE80211_CHAN_VHT160) == 0) { 2212 if (verbose) 2213 printf("%u: skip, not a " 2214 "VHT160 channel\n", freq); 2215 continue; 2216 } 2217 if ((chanFlags & IEEE80211_CHAN_VHT80P80) && 2218 (flags & IEEE80211_CHAN_VHT80P80) == 0) { 2219 if (verbose) 2220 printf("%u: skip, not a " 2221 "VHT80+80 channel\n", freq); 2222 continue; 2223 } 2224 flags &= ~IEEE80211_CHAN_VHT; 2225 flags |= chanFlags & IEEE80211_CHAN_VHT; 2226 } 2227 2228 /* Now, constrain HT */ 2229 if (flags & IEEE80211_CHAN_HT) { 2230 /* 2231 * HT channels are generated specially; we're 2232 * called to add HT20, HT40+, and HT40- chan's 2233 * so we need to expand only band specs for 2234 * the HT channel type being added. 2235 */ 2236 if ((chanFlags & IEEE80211_CHAN_HT20) && 2237 (flags & IEEE80211_CHAN_HT20) == 0) { 2238 if (verbose) 2239 printf("%u: skip, not an " 2240 "HT20 channel\n", freq); 2241 continue; 2242 } 2243 if ((chanFlags & IEEE80211_CHAN_HT40) && 2244 (flags & IEEE80211_CHAN_HT40) == 0) { 2245 if (verbose) 2246 printf("%u: skip, not an " 2247 "HT40 channel\n", freq); 2248 continue; 2249 } 2250 /* NB: HT attribute comes from caller */ 2251 flags &= ~IEEE80211_CHAN_HT; 2252 flags |= chanFlags & IEEE80211_CHAN_HT; 2253 } 2254 /* 2255 * Check if device can operate on this frequency. 2256 */ 2257 if (!checkchan(avail, freq, flags)) { 2258 if (verbose) { 2259 printf("%u: skip, ", freq); 2260 printb("flags", flags, 2261 IEEE80211_CHAN_BITS); 2262 printf(" not available\n"); 2263 } 2264 continue; 2265 } 2266 if ((flags & REQ_ECM) && !reg->ecm) { 2267 if (verbose) 2268 printf("%u: skip, ECM channel\n", freq); 2269 continue; 2270 } 2271 if ((flags & REQ_INDOOR) && reg->location == 'O') { 2272 if (verbose) 2273 printf("%u: skip, indoor channel\n", 2274 freq); 2275 continue; 2276 } 2277 if ((flags & REQ_OUTDOOR) && reg->location == 'I') { 2278 if (verbose) 2279 printf("%u: skip, outdoor channel\n", 2280 freq); 2281 continue; 2282 } 2283 if ((flags & IEEE80211_CHAN_HT40) && 2284 prev != NULL && (freq - prev->ic_freq) < channelSep) { 2285 if (verbose) 2286 printf("%u: skip, only %u channel " 2287 "separation, need %d\n", freq, 2288 freq - prev->ic_freq, channelSep); 2289 continue; 2290 } 2291 if (ci->ic_nchans == IEEE80211_CHAN_MAX) { 2292 if (verbose) 2293 printf("%u: skip, channel table full\n", 2294 freq); 2295 break; 2296 } 2297 c = &ci->ic_chans[ci->ic_nchans++]; 2298 memset(c, 0, sizeof(*c)); 2299 c->ic_freq = freq; 2300 c->ic_flags = flags; 2301 if (c->ic_flags & IEEE80211_CHAN_DFS) 2302 c->ic_maxregpower = nb->maxPowerDFS; 2303 else 2304 c->ic_maxregpower = nb->maxPower; 2305 if (verbose) { 2306 printf("[%3d] add freq %u ", 2307 ci->ic_nchans-1, c->ic_freq); 2308 printb("flags", c->ic_flags, IEEE80211_CHAN_BITS); 2309 printf(" power %u\n", c->ic_maxregpower); 2310 } 2311 /* NB: kernel fills in other fields */ 2312 prev = c; 2313 } 2314 } 2315 } 2316 2317 static void 2318 regdomain_makechannels( 2319 if_ctx *ctx, 2320 struct ieee80211_regdomain_req *req, 2321 const struct ieee80211_devcaps_req *dc) 2322 { 2323 struct regdata *rdp = getregdata(); 2324 const struct country *cc; 2325 const struct ieee80211_regdomain *reg = &req->rd; 2326 struct ieee80211req_chaninfo *ci = &req->chaninfo; 2327 const struct regdomain *rd; 2328 2329 /* 2330 * Locate construction table for new channel list. We treat 2331 * the regdomain/SKU as definitive so a country can be in 2332 * multiple with different properties (e.g. US in FCC+FCC3). 2333 * If no regdomain is specified then we fallback on the country 2334 * code to find the associated regdomain since countries always 2335 * belong to at least one regdomain. 2336 */ 2337 if (reg->regdomain == 0) { 2338 cc = lib80211_country_findbycc(rdp, reg->country); 2339 if (cc == NULL) 2340 errx(1, "internal error, country %d not found", 2341 reg->country); 2342 rd = cc->rd; 2343 } else 2344 rd = lib80211_regdomain_findbysku(rdp, reg->regdomain); 2345 if (rd == NULL) 2346 errx(1, "internal error, regdomain %d not found", 2347 reg->regdomain); 2348 if (rd->sku != SKU_DEBUG) { 2349 /* 2350 * regdomain_addchans incrememnts the channel count for 2351 * each channel it adds so initialize ic_nchans to zero. 2352 * Note that we know we have enough space to hold all possible 2353 * channels because the devcaps list size was used to 2354 * allocate our request. 2355 */ 2356 ci->ic_nchans = 0; 2357 if (!LIST_EMPTY(&rd->bands_11b)) 2358 regdomain_addchans(ctx, ci, &rd->bands_11b, reg, 2359 IEEE80211_CHAN_B, &dc->dc_chaninfo); 2360 if (!LIST_EMPTY(&rd->bands_11g)) 2361 regdomain_addchans(ctx, ci, &rd->bands_11g, reg, 2362 IEEE80211_CHAN_G, &dc->dc_chaninfo); 2363 if (!LIST_EMPTY(&rd->bands_11a)) 2364 regdomain_addchans(ctx, ci, &rd->bands_11a, reg, 2365 IEEE80211_CHAN_A, &dc->dc_chaninfo); 2366 if (!LIST_EMPTY(&rd->bands_11na) && dc->dc_htcaps != 0) { 2367 regdomain_addchans(ctx, ci, &rd->bands_11na, reg, 2368 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20, 2369 &dc->dc_chaninfo); 2370 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) { 2371 regdomain_addchans(ctx, ci, &rd->bands_11na, reg, 2372 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U, 2373 &dc->dc_chaninfo); 2374 regdomain_addchans(ctx, ci, &rd->bands_11na, reg, 2375 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D, 2376 &dc->dc_chaninfo); 2377 } 2378 } 2379 if (!LIST_EMPTY(&rd->bands_11ac) && dc->dc_vhtcaps != 0) { 2380 regdomain_addchans(ctx, ci, &rd->bands_11ac, reg, 2381 IEEE80211_CHAN_A | IEEE80211_CHAN_HT20 | 2382 IEEE80211_CHAN_VHT20, 2383 &dc->dc_chaninfo); 2384 2385 /* VHT40 is a function of HT40.. */ 2386 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) { 2387 regdomain_addchans(ctx, ci, &rd->bands_11ac, reg, 2388 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U | 2389 IEEE80211_CHAN_VHT40U, 2390 &dc->dc_chaninfo); 2391 regdomain_addchans(ctx, ci, &rd->bands_11ac, reg, 2392 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D | 2393 IEEE80211_CHAN_VHT40D, 2394 &dc->dc_chaninfo); 2395 } 2396 2397 /* VHT80 is mandatory (and so should be VHT40 above). */ 2398 if (1) { 2399 regdomain_addchans(ctx, ci, &rd->bands_11ac, reg, 2400 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U | 2401 IEEE80211_CHAN_VHT80, 2402 &dc->dc_chaninfo); 2403 regdomain_addchans(ctx, ci, &rd->bands_11ac, reg, 2404 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D | 2405 IEEE80211_CHAN_VHT80, 2406 &dc->dc_chaninfo); 2407 } 2408 2409 /* VHT160 */ 2410 if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ( 2411 dc->dc_vhtcaps)) { 2412 regdomain_addchans(ctx, ci, &rd->bands_11ac, reg, 2413 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U | 2414 IEEE80211_CHAN_VHT160, 2415 &dc->dc_chaninfo); 2416 regdomain_addchans(ctx, ci, &rd->bands_11ac, reg, 2417 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D | 2418 IEEE80211_CHAN_VHT160, 2419 &dc->dc_chaninfo); 2420 } 2421 2422 /* VHT80P80 */ 2423 if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ( 2424 dc->dc_vhtcaps)) { 2425 regdomain_addchans(ctx, ci, &rd->bands_11ac, reg, 2426 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U | 2427 IEEE80211_CHAN_VHT80P80, 2428 &dc->dc_chaninfo); 2429 regdomain_addchans(ctx, ci, &rd->bands_11ac, reg, 2430 IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D | 2431 IEEE80211_CHAN_VHT80P80, 2432 &dc->dc_chaninfo); 2433 } 2434 } 2435 2436 if (!LIST_EMPTY(&rd->bands_11ng) && dc->dc_htcaps != 0) { 2437 regdomain_addchans(ctx, ci, &rd->bands_11ng, reg, 2438 IEEE80211_CHAN_G | IEEE80211_CHAN_HT20, 2439 &dc->dc_chaninfo); 2440 if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) { 2441 regdomain_addchans(ctx, ci, &rd->bands_11ng, reg, 2442 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U, 2443 &dc->dc_chaninfo); 2444 regdomain_addchans(ctx, ci, &rd->bands_11ng, reg, 2445 IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D, 2446 &dc->dc_chaninfo); 2447 } 2448 } 2449 qsort(ci->ic_chans, ci->ic_nchans, sizeof(ci->ic_chans[0]), 2450 regdomain_sort); 2451 } else 2452 memcpy(ci, &dc->dc_chaninfo, 2453 IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo)); 2454 } 2455 2456 static void 2457 list_countries(void) 2458 { 2459 struct regdata *rdp = getregdata(); 2460 const struct country *cp; 2461 const struct regdomain *dp; 2462 int i; 2463 2464 i = 0; 2465 printf("\nCountry codes:\n"); 2466 LIST_FOREACH(cp, &rdp->countries, next) { 2467 printf("%2s %-15.15s%s", cp->isoname, 2468 cp->name, ((i+1)%4) == 0 ? "\n" : " "); 2469 i++; 2470 } 2471 i = 0; 2472 printf("\nRegulatory domains:\n"); 2473 LIST_FOREACH(dp, &rdp->domains, next) { 2474 printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " "); 2475 i++; 2476 } 2477 printf("\n"); 2478 } 2479 2480 static void 2481 defaultcountry(const struct regdomain *rd) 2482 { 2483 struct regdata *rdp = getregdata(); 2484 const struct country *cc; 2485 2486 cc = lib80211_country_findbycc(rdp, rd->cc->code); 2487 if (cc == NULL) 2488 errx(1, "internal error, ISO country code %d not " 2489 "defined for regdomain %s", rd->cc->code, rd->name); 2490 regdomain.country = cc->code; 2491 regdomain.isocc[0] = cc->isoname[0]; 2492 regdomain.isocc[1] = cc->isoname[1]; 2493 } 2494 2495 static void 2496 set80211regdomain(if_ctx *ctx, const char *val, int dummy __unused) 2497 { 2498 struct regdata *rdp = getregdata(); 2499 const struct regdomain *rd; 2500 2501 rd = lib80211_regdomain_findbyname(rdp, val); 2502 if (rd == NULL) { 2503 char *eptr; 2504 long sku = strtol(val, &eptr, 0); 2505 2506 if (eptr != val) 2507 rd = lib80211_regdomain_findbysku(rdp, sku); 2508 if (eptr == val || rd == NULL) 2509 errx(1, "unknown regdomain %s", val); 2510 } 2511 getregdomain(ctx); 2512 regdomain.regdomain = rd->sku; 2513 if (regdomain.country == 0 && rd->cc != NULL) { 2514 /* 2515 * No country code setup and there's a default 2516 * one for this regdomain fill it in. 2517 */ 2518 defaultcountry(rd); 2519 } 2520 callback_register(setregdomain_cb, ®domain); 2521 } 2522 2523 static void 2524 set80211country(if_ctx *ctx, const char *val, int dummy __unused) 2525 { 2526 struct regdata *rdp = getregdata(); 2527 const struct country *cc; 2528 2529 cc = lib80211_country_findbyname(rdp, val); 2530 if (cc == NULL) { 2531 char *eptr; 2532 long code = strtol(val, &eptr, 0); 2533 2534 if (eptr != val) 2535 cc = lib80211_country_findbycc(rdp, code); 2536 if (eptr == val || cc == NULL) 2537 errx(1, "unknown ISO country code %s", val); 2538 } 2539 getregdomain(ctx); 2540 regdomain.regdomain = cc->rd->sku; 2541 regdomain.country = cc->code; 2542 regdomain.isocc[0] = cc->isoname[0]; 2543 regdomain.isocc[1] = cc->isoname[1]; 2544 callback_register(setregdomain_cb, ®domain); 2545 } 2546 2547 static void 2548 set80211location(if_ctx *ctx, const char *val __unused, int d) 2549 { 2550 getregdomain(ctx); 2551 regdomain.location = d; 2552 callback_register(setregdomain_cb, ®domain); 2553 } 2554 2555 static void 2556 set80211ecm(if_ctx *ctx, const char *val __unused, int d) 2557 { 2558 getregdomain(ctx); 2559 regdomain.ecm = d; 2560 callback_register(setregdomain_cb, ®domain); 2561 } 2562 2563 static void 2564 LINE_INIT(char c) 2565 { 2566 spacer = c; 2567 if (c == '\t') 2568 col = 8; 2569 else 2570 col = 1; 2571 } 2572 2573 static void 2574 LINE_BREAK(void) 2575 { 2576 if (spacer != '\t') { 2577 printf("\n"); 2578 spacer = '\t'; 2579 } 2580 col = 8; /* 8-col tab */ 2581 } 2582 2583 static void 2584 LINE_CHECK(const char *fmt, ...) 2585 { 2586 char buf[80]; 2587 va_list ap; 2588 int n; 2589 2590 va_start(ap, fmt); 2591 n = vsnprintf(buf+1, sizeof(buf)-1, fmt, ap); 2592 va_end(ap); 2593 col += 1+n; 2594 if (col > MAXCOL) { 2595 LINE_BREAK(); 2596 col += n; 2597 } 2598 buf[0] = spacer; 2599 printf("%s", buf); 2600 spacer = ' '; 2601 } 2602 2603 static int 2604 getmaxrate(const uint8_t rates[15], uint8_t nrates) 2605 { 2606 int i, maxrate = -1; 2607 2608 for (i = 0; i < nrates; i++) { 2609 int rate = rates[i] & IEEE80211_RATE_VAL; 2610 if (rate > maxrate) 2611 maxrate = rate; 2612 } 2613 return maxrate / 2; 2614 } 2615 2616 static const char * 2617 getcaps(int capinfo) 2618 { 2619 static char capstring[32]; 2620 char *cp = capstring; 2621 2622 if (capinfo & IEEE80211_CAPINFO_ESS) 2623 *cp++ = 'E'; 2624 if (capinfo & IEEE80211_CAPINFO_IBSS) 2625 *cp++ = 'I'; 2626 if (capinfo & IEEE80211_CAPINFO_CF_POLLABLE) 2627 *cp++ = 'c'; 2628 if (capinfo & IEEE80211_CAPINFO_CF_POLLREQ) 2629 *cp++ = 'C'; 2630 if (capinfo & IEEE80211_CAPINFO_PRIVACY) 2631 *cp++ = 'P'; 2632 if (capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE) 2633 *cp++ = 'S'; 2634 if (capinfo & IEEE80211_CAPINFO_PBCC) 2635 *cp++ = 'B'; 2636 if (capinfo & IEEE80211_CAPINFO_CHNL_AGILITY) 2637 *cp++ = 'A'; 2638 if (capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME) 2639 *cp++ = 's'; 2640 if (capinfo & IEEE80211_CAPINFO_RSN) 2641 *cp++ = 'R'; 2642 if (capinfo & IEEE80211_CAPINFO_DSSSOFDM) 2643 *cp++ = 'D'; 2644 *cp = '\0'; 2645 return capstring; 2646 } 2647 2648 static const char * 2649 getflags(int flags) 2650 { 2651 static char flagstring[32]; 2652 char *cp = flagstring; 2653 2654 if (flags & IEEE80211_NODE_AUTH) 2655 *cp++ = 'A'; 2656 if (flags & IEEE80211_NODE_QOS) 2657 *cp++ = 'Q'; 2658 if (flags & IEEE80211_NODE_ERP) 2659 *cp++ = 'E'; 2660 if (flags & IEEE80211_NODE_PWR_MGT) 2661 *cp++ = 'P'; 2662 if (flags & IEEE80211_NODE_HT) { 2663 *cp++ = 'H'; 2664 if (flags & IEEE80211_NODE_HTCOMPAT) 2665 *cp++ = '+'; 2666 } 2667 if (flags & IEEE80211_NODE_VHT) 2668 *cp++ = 'V'; 2669 if (flags & IEEE80211_NODE_WPS) 2670 *cp++ = 'W'; 2671 if (flags & IEEE80211_NODE_TSN) 2672 *cp++ = 'N'; 2673 if (flags & IEEE80211_NODE_AMPDU_TX) 2674 *cp++ = 'T'; 2675 if (flags & IEEE80211_NODE_AMPDU_RX) 2676 *cp++ = 'R'; 2677 if (flags & IEEE80211_NODE_MIMO_PS) { 2678 *cp++ = 'M'; 2679 if (flags & IEEE80211_NODE_MIMO_RTS) 2680 *cp++ = '+'; 2681 } 2682 if (flags & IEEE80211_NODE_RIFS) 2683 *cp++ = 'I'; 2684 if (flags & IEEE80211_NODE_SGI40) { 2685 *cp++ = 'S'; 2686 if (flags & IEEE80211_NODE_SGI20) 2687 *cp++ = '+'; 2688 } else if (flags & IEEE80211_NODE_SGI20) 2689 *cp++ = 's'; 2690 if (flags & IEEE80211_NODE_AMSDU_TX) 2691 *cp++ = 't'; 2692 if (flags & IEEE80211_NODE_AMSDU_RX) 2693 *cp++ = 'r'; 2694 if (flags & IEEE80211_NODE_UAPSD) 2695 *cp++ = 'U'; 2696 if (flags & IEEE80211_NODE_LDPC) 2697 *cp++ = 'L'; 2698 *cp = '\0'; 2699 return flagstring; 2700 } 2701 2702 static void 2703 printie(if_ctx *ctx, const char* tag, const uint8_t *ie, size_t ielen, unsigned int maxlen) 2704 { 2705 printf("%s", tag); 2706 if (ctx->args->verbose) { 2707 maxlen -= strlen(tag)+2; 2708 if (2*ielen > maxlen) 2709 maxlen--; 2710 printf("<"); 2711 for (; ielen > 0; ie++, ielen--) { 2712 if (maxlen-- <= 0) 2713 break; 2714 printf("%02x", *ie); 2715 } 2716 if (ielen != 0) 2717 printf("-"); 2718 printf(">"); 2719 } 2720 } 2721 2722 #define LE_READ_2(p) \ 2723 ((u_int16_t) \ 2724 ((((const u_int8_t *)(p))[0] ) | \ 2725 (((const u_int8_t *)(p))[1] << 8))) 2726 #define LE_READ_4(p) \ 2727 ((u_int32_t) \ 2728 ((((const u_int8_t *)(p))[0] ) | \ 2729 (((const u_int8_t *)(p))[1] << 8) | \ 2730 (((const u_int8_t *)(p))[2] << 16) | \ 2731 (((const u_int8_t *)(p))[3] << 24))) 2732 2733 /* 2734 * NB: The decoding routines assume a properly formatted ie 2735 * which should be safe as the kernel only retains them 2736 * if they parse ok. 2737 */ 2738 2739 static void 2740 printwmeparam(if_ctx *ctx, const char *tag, const u_int8_t *ie) 2741 { 2742 static const char *acnames[] = { "BE", "BK", "VO", "VI" }; 2743 const struct ieee80211_wme_param *wme = 2744 (const struct ieee80211_wme_param *) ie; 2745 int i; 2746 2747 printf("%s", tag); 2748 if (!ctx->args->verbose) 2749 return; 2750 printf("<qosinfo 0x%x", wme->param_qosInfo); 2751 ie += offsetof(struct ieee80211_wme_param, params_acParams); 2752 for (i = 0; i < WME_NUM_AC; i++) { 2753 const struct ieee80211_wme_acparams *ac = 2754 &wme->params_acParams[i]; 2755 2756 printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]", acnames[i], 2757 _IEEE80211_MASKSHIFT(ac->acp_aci_aifsn, WME_PARAM_ACM) ? 2758 "acm " : "", 2759 _IEEE80211_MASKSHIFT(ac->acp_aci_aifsn, WME_PARAM_AIFSN), 2760 _IEEE80211_MASKSHIFT(ac->acp_logcwminmax, 2761 WME_PARAM_LOGCWMIN), 2762 _IEEE80211_MASKSHIFT(ac->acp_logcwminmax, 2763 WME_PARAM_LOGCWMAX), 2764 LE_READ_2(&ac->acp_txop)); 2765 } 2766 printf(">"); 2767 } 2768 2769 static void 2770 printwmeinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie) 2771 { 2772 printf("%s", tag); 2773 if (ctx->args->verbose) { 2774 const struct ieee80211_wme_info *wme = 2775 (const struct ieee80211_wme_info *) ie; 2776 printf("<version 0x%x info 0x%x>", 2777 wme->wme_version, wme->wme_info); 2778 } 2779 } 2780 2781 static void 2782 printvhtcap(if_ctx *ctx, const char *tag, const u_int8_t *ie) 2783 { 2784 printf("%s", tag); 2785 if (ctx->args->verbose) { 2786 const struct ieee80211_vht_cap *vhtcap; 2787 uint32_t vhtcap_info; 2788 2789 /* Check that the right size. */ 2790 if (ie[1] != sizeof(*vhtcap)) { 2791 printf("<err: vht_cap inval. length>"); 2792 return; 2793 } 2794 /* Skip Element ID and Length. */ 2795 vhtcap = (const struct ieee80211_vht_cap *)(ie + 2); 2796 2797 vhtcap_info = LE_READ_4(&vhtcap->vht_cap_info); 2798 printf("<cap 0x%08x", vhtcap_info); 2799 printf(" rx_mcs_map 0x%x", 2800 LE_READ_2(&vhtcap->supp_mcs.rx_mcs_map)); 2801 printf(" rx_highest %d", 2802 LE_READ_2(&vhtcap->supp_mcs.rx_highest) & 0x1fff); 2803 printf(" tx_mcs_map 0x%x", 2804 LE_READ_2(&vhtcap->supp_mcs.tx_mcs_map)); 2805 printf(" tx_highest %d", 2806 LE_READ_2(&vhtcap->supp_mcs.tx_highest) & 0x1fff); 2807 2808 printf(">"); 2809 } 2810 } 2811 2812 static void 2813 printvhtinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie) 2814 { 2815 printf("%s", tag); 2816 if (ctx->args->verbose) { 2817 const struct ieee80211_vht_operation *vhtinfo; 2818 2819 /* Check that the right size. */ 2820 if (ie[1] != sizeof(*vhtinfo)) { 2821 printf("<err: vht_operation inval. length>"); 2822 return; 2823 } 2824 /* Skip Element ID and Length. */ 2825 vhtinfo = (const struct ieee80211_vht_operation *)(ie + 2); 2826 2827 printf("<chw %d freq0_idx %d freq1_idx %d basic_mcs_set 0x%04x>", 2828 vhtinfo->chan_width, 2829 vhtinfo->center_freq_seq0_idx, 2830 vhtinfo->center_freq_seq1_idx, 2831 LE_READ_2(&vhtinfo->basic_mcs_set)); 2832 } 2833 } 2834 2835 static void 2836 printvhtpwrenv(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen) 2837 { 2838 printf("%s", tag); 2839 static const char *txpwrmap[] = { 2840 "20", 2841 "40", 2842 "80", 2843 "160", 2844 }; 2845 if (ctx->args->verbose) { 2846 const struct ieee80211_ie_vht_txpwrenv *vhtpwr = 2847 (const struct ieee80211_ie_vht_txpwrenv *) ie; 2848 size_t i, n; 2849 const char *sep = ""; 2850 2851 /* Get count; trim at ielen */ 2852 n = (vhtpwr->tx_info & 2853 IEEE80211_VHT_TXPWRENV_INFO_COUNT_MASK) + 1; 2854 /* Trim at ielen */ 2855 if (n + 3 > ielen) 2856 n = ielen - 3; 2857 printf("<tx_info 0x%02x pwr:[", vhtpwr->tx_info); 2858 for (i = 0; i < n; i++) { 2859 printf("%s%s:%.2f", sep, txpwrmap[i], 2860 ((float) ((int8_t) ie[i+3])) / 2.0); 2861 sep = " "; 2862 } 2863 2864 printf("]>"); 2865 } 2866 } 2867 2868 static void 2869 printhtcap(if_ctx *ctx, const char *tag, const u_int8_t *ie) 2870 { 2871 printf("%s", tag); 2872 if (ctx->args->verbose) { 2873 const struct ieee80211_ie_htcap *htcap = 2874 (const struct ieee80211_ie_htcap *) ie; 2875 const char *sep; 2876 int i, j; 2877 2878 printf("<cap 0x%x param 0x%x", 2879 LE_READ_2(&htcap->hc_cap), htcap->hc_param); 2880 printf(" mcsset["); 2881 sep = ""; 2882 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++) 2883 if (isset(htcap->hc_mcsset, i)) { 2884 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++) 2885 if (isclr(htcap->hc_mcsset, j)) 2886 break; 2887 j--; 2888 if (i == j) 2889 printf("%s%u", sep, i); 2890 else 2891 printf("%s%u-%u", sep, i, j); 2892 i += j-i; 2893 sep = ","; 2894 } 2895 printf("] extcap 0x%x txbf 0x%x antenna 0x%x>", 2896 LE_READ_2(&htcap->hc_extcap), 2897 LE_READ_4(&htcap->hc_txbf), 2898 htcap->hc_antenna); 2899 } 2900 } 2901 2902 static void 2903 printhtinfo(if_ctx *ctx, const char *tag, const u_int8_t *ie) 2904 { 2905 printf("%s", tag); 2906 if (ctx->args->verbose) { 2907 const struct ieee80211_ie_htinfo *htinfo = 2908 (const struct ieee80211_ie_htinfo *) ie; 2909 const char *sep; 2910 int i, j; 2911 2912 printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel, 2913 htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3, 2914 LE_READ_2(&htinfo->hi_byte45)); 2915 printf(" basicmcs["); 2916 sep = ""; 2917 for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++) 2918 if (isset(htinfo->hi_basicmcsset, i)) { 2919 for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++) 2920 if (isclr(htinfo->hi_basicmcsset, j)) 2921 break; 2922 j--; 2923 if (i == j) 2924 printf("%s%u", sep, i); 2925 else 2926 printf("%s%u-%u", sep, i, j); 2927 i += j-i; 2928 sep = ","; 2929 } 2930 printf("]>"); 2931 } 2932 } 2933 2934 static void 2935 printathie(if_ctx *ctx, const char *tag, const u_int8_t *ie) 2936 { 2937 2938 printf("%s", tag); 2939 if (ctx->args->verbose) { 2940 const struct ieee80211_ath_ie *ath = 2941 (const struct ieee80211_ath_ie *)ie; 2942 2943 printf("<"); 2944 if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME) 2945 printf("DTURBO,"); 2946 if (ath->ath_capability & ATHEROS_CAP_COMPRESSION) 2947 printf("COMP,"); 2948 if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME) 2949 printf("FF,"); 2950 if (ath->ath_capability & ATHEROS_CAP_XR) 2951 printf("XR,"); 2952 if (ath->ath_capability & ATHEROS_CAP_AR) 2953 printf("AR,"); 2954 if (ath->ath_capability & ATHEROS_CAP_BURST) 2955 printf("BURST,"); 2956 if (ath->ath_capability & ATHEROS_CAP_WME) 2957 printf("WME,"); 2958 if (ath->ath_capability & ATHEROS_CAP_BOOST) 2959 printf("BOOST,"); 2960 printf("0x%x>", LE_READ_2(ath->ath_defkeyix)); 2961 } 2962 } 2963 2964 2965 static void 2966 printmeshconf(if_ctx *ctx, const char *tag, const uint8_t *ie) 2967 { 2968 2969 printf("%s", tag); 2970 if (ctx->args->verbose) { 2971 const struct ieee80211_meshconf_ie *mconf = 2972 (const struct ieee80211_meshconf_ie *)ie; 2973 printf("<PATH:"); 2974 if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP) 2975 printf("HWMP"); 2976 else 2977 printf("UNKNOWN"); 2978 printf(" LINK:"); 2979 if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME) 2980 printf("AIRTIME"); 2981 else 2982 printf("UNKNOWN"); 2983 printf(" CONGESTION:"); 2984 if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED) 2985 printf("DISABLED"); 2986 else 2987 printf("UNKNOWN"); 2988 printf(" SYNC:"); 2989 if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF) 2990 printf("NEIGHOFF"); 2991 else 2992 printf("UNKNOWN"); 2993 printf(" AUTH:"); 2994 if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED) 2995 printf("DISABLED"); 2996 else 2997 printf("UNKNOWN"); 2998 printf(" FORM:0x%x CAPS:0x%x>", mconf->conf_form, 2999 mconf->conf_cap); 3000 } 3001 } 3002 3003 static void 3004 printbssload(if_ctx *ctx, const char *tag, const uint8_t *ie) 3005 { 3006 printf("%s", tag); 3007 if (ctx->args->verbose) { 3008 const struct ieee80211_bss_load_ie *bssload = 3009 (const struct ieee80211_bss_load_ie *) ie; 3010 printf("<sta count %d, chan load %d, aac %d>", 3011 LE_READ_2(&bssload->sta_count), 3012 bssload->chan_load, 3013 bssload->aac); 3014 } 3015 } 3016 3017 static void 3018 printapchanrep(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen) 3019 { 3020 printf("%s", tag); 3021 if (ctx->args->verbose) { 3022 const struct ieee80211_ap_chan_report_ie *ap = 3023 (const struct ieee80211_ap_chan_report_ie *) ie; 3024 const char *sep = ""; 3025 3026 printf("<class %u, chan:[", ap->i_class); 3027 3028 for (size_t i = 3; i < ielen; i++) { 3029 printf("%s%u", sep, ie[i]); 3030 sep = ","; 3031 } 3032 printf("]>"); 3033 } 3034 } 3035 3036 static const char * 3037 wpa_cipher(const u_int8_t *sel) 3038 { 3039 #define WPA_SEL(x) (((x)<<24)|WPA_OUI) 3040 u_int32_t w = LE_READ_4(sel); 3041 3042 switch (w) { 3043 case WPA_SEL(WPA_CSE_NULL): 3044 return "NONE"; 3045 case WPA_SEL(WPA_CSE_WEP40): 3046 return "WEP40"; 3047 case WPA_SEL(WPA_CSE_WEP104): 3048 return "WEP104"; 3049 case WPA_SEL(WPA_CSE_TKIP): 3050 return "TKIP"; 3051 case WPA_SEL(WPA_CSE_CCMP): 3052 return "AES-CCMP"; 3053 } 3054 return "?"; /* NB: so 1<< is discarded */ 3055 #undef WPA_SEL 3056 } 3057 3058 static const char * 3059 wpa_keymgmt(const u_int8_t *sel) 3060 { 3061 #define WPA_SEL(x) (((x)<<24)|WPA_OUI) 3062 u_int32_t w = LE_READ_4(sel); 3063 3064 switch (w) { 3065 case WPA_SEL(WPA_ASE_8021X_UNSPEC): 3066 return "8021X-UNSPEC"; 3067 case WPA_SEL(WPA_ASE_8021X_PSK): 3068 return "8021X-PSK"; 3069 case WPA_SEL(WPA_ASE_NONE): 3070 return "NONE"; 3071 } 3072 return "?"; 3073 #undef WPA_SEL 3074 } 3075 3076 static void 3077 printwpaie(if_ctx *ctx, const char *tag, const u_int8_t *ie) 3078 { 3079 u_int8_t len = ie[1]; 3080 3081 printf("%s", tag); 3082 if (ctx->args->verbose) { 3083 const char *sep; 3084 int n; 3085 3086 ie += 6, len -= 4; /* NB: len is payload only */ 3087 3088 printf("<v%u", LE_READ_2(ie)); 3089 ie += 2, len -= 2; 3090 3091 printf(" mc:%s", wpa_cipher(ie)); 3092 ie += 4, len -= 4; 3093 3094 /* unicast ciphers */ 3095 n = LE_READ_2(ie); 3096 ie += 2, len -= 2; 3097 sep = " uc:"; 3098 for (; n > 0; n--) { 3099 printf("%s%s", sep, wpa_cipher(ie)); 3100 ie += 4, len -= 4; 3101 sep = "+"; 3102 } 3103 3104 /* key management algorithms */ 3105 n = LE_READ_2(ie); 3106 ie += 2, len -= 2; 3107 sep = " km:"; 3108 for (; n > 0; n--) { 3109 printf("%s%s", sep, wpa_keymgmt(ie)); 3110 ie += 4, len -= 4; 3111 sep = "+"; 3112 } 3113 3114 if (len > 2) /* optional capabilities */ 3115 printf(", caps 0x%x", LE_READ_2(ie)); 3116 printf(">"); 3117 } 3118 } 3119 3120 static const char * 3121 rsn_cipher(const u_int8_t *sel) 3122 { 3123 #define RSN_SEL(x) (((x)<<24)|RSN_OUI) 3124 u_int32_t w = LE_READ_4(sel); 3125 3126 switch (w) { 3127 case RSN_SEL(RSN_CSE_NULL): 3128 return "NONE"; 3129 case RSN_SEL(RSN_CSE_WEP40): 3130 return "WEP40"; 3131 case RSN_SEL(RSN_CSE_WEP104): 3132 return "WEP104"; 3133 case RSN_SEL(RSN_CSE_TKIP): 3134 return "TKIP"; 3135 case RSN_SEL(RSN_CSE_CCMP): 3136 return "AES-CCMP"; 3137 case RSN_SEL(RSN_CSE_WRAP): 3138 return "AES-OCB"; 3139 case RSN_SEL(RSN_CSE_GCMP_128): 3140 return "AES-GCMP"; 3141 case RSN_SEL(RSN_CSE_CCMP_256): 3142 return "AES-CCMP-256"; 3143 case RSN_SEL(RSN_CSE_GCMP_256): 3144 return "AES-GCMP-256"; 3145 } 3146 return "?"; 3147 #undef WPA_SEL 3148 } 3149 3150 static const char * 3151 rsn_keymgmt(const u_int8_t *sel) 3152 { 3153 #define RSN_SEL(x) (((x)<<24)|RSN_OUI) 3154 u_int32_t w = LE_READ_4(sel); 3155 3156 switch (w) { 3157 case RSN_SEL(RSN_ASE_8021X_UNSPEC): 3158 return "8021X-UNSPEC"; 3159 case RSN_SEL(RSN_ASE_8021X_PSK): 3160 return "8021X-PSK"; 3161 case RSN_SEL(RSN_ASE_8021X_UNSPEC_SHA256): 3162 return "8021X-UNSPEC-SHA256"; 3163 case RSN_SEL(RSN_ASE_8021X_PSK_SHA256): 3164 return "8021X-PSK-256"; 3165 case RSN_SEL(RSN_ASE_NONE): 3166 return "NONE"; 3167 } 3168 return "?"; 3169 #undef RSN_SEL 3170 } 3171 3172 static void 3173 printrsnie(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen) 3174 { 3175 printf("%s", tag); 3176 if (ctx->args->verbose) { 3177 const char *sep; 3178 int n; 3179 3180 ie += 2, ielen -= 2; 3181 3182 printf("<v%u", LE_READ_2(ie)); 3183 ie += 2, ielen -= 2; 3184 3185 printf(" mc:%s", rsn_cipher(ie)); 3186 ie += 4, ielen -= 4; 3187 3188 /* unicast ciphers */ 3189 n = LE_READ_2(ie); 3190 ie += 2, ielen -= 2; 3191 sep = " uc:"; 3192 for (; n > 0; n--) { 3193 printf("%s%s", sep, rsn_cipher(ie)); 3194 ie += 4, ielen -= 4; 3195 sep = "+"; 3196 } 3197 3198 /* key management algorithms */ 3199 n = LE_READ_2(ie); 3200 ie += 2, ielen -= 2; 3201 sep = " km:"; 3202 for (; n > 0; n--) { 3203 printf("%s%s", sep, rsn_keymgmt(ie)); 3204 ie += 4, ielen -= 4; 3205 sep = "+"; 3206 } 3207 3208 if (ielen > 2) /* optional capabilities */ 3209 printf(", caps 0x%x", LE_READ_2(ie)); 3210 /* XXXPMKID */ 3211 printf(">"); 3212 } 3213 } 3214 3215 #define BE_READ_2(p) \ 3216 ((u_int16_t) \ 3217 ((((const u_int8_t *)(p))[1] ) | \ 3218 (((const u_int8_t *)(p))[0] << 8))) 3219 3220 static void 3221 printwpsie(if_ctx *ctx, const char *tag, const u_int8_t *ie) 3222 { 3223 u_int8_t len = ie[1]; 3224 3225 printf("%s", tag); 3226 if (ctx->args->verbose) { 3227 static const char *dev_pass_id[] = { 3228 "D", /* Default (PIN) */ 3229 "U", /* User-specified */ 3230 "M", /* Machine-specified */ 3231 "K", /* Rekey */ 3232 "P", /* PushButton */ 3233 "R" /* Registrar-specified */ 3234 }; 3235 int n; 3236 int f; 3237 3238 ie +=6, len -= 4; /* NB: len is payload only */ 3239 3240 /* WPS IE in Beacon and Probe Resp frames have different fields */ 3241 printf("<"); 3242 while (len) { 3243 uint16_t tlv_type = BE_READ_2(ie); 3244 uint16_t tlv_len = BE_READ_2(ie + 2); 3245 uint16_t cfg_mthd; 3246 3247 /* some devices broadcast invalid WPS frames */ 3248 if (tlv_len > len) { 3249 printf("bad frame length tlv_type=0x%02x " 3250 "tlv_len=%d len=%d", tlv_type, tlv_len, 3251 len); 3252 break; 3253 } 3254 3255 ie += 4, len -= 4; 3256 3257 switch (tlv_type) { 3258 case IEEE80211_WPS_ATTR_VERSION: 3259 printf("v:%d.%d", *ie >> 4, *ie & 0xf); 3260 break; 3261 case IEEE80211_WPS_ATTR_AP_SETUP_LOCKED: 3262 printf(" ap_setup:%s", *ie ? "locked" : 3263 "unlocked"); 3264 break; 3265 case IEEE80211_WPS_ATTR_CONFIG_METHODS: 3266 case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS: 3267 if (tlv_type == IEEE80211_WPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS) 3268 printf(" sel_reg_cfg_mthd:"); 3269 else 3270 printf(" cfg_mthd:" ); 3271 cfg_mthd = BE_READ_2(ie); 3272 f = 0; 3273 for (n = 15; n >= 0; n--) { 3274 if (f) { 3275 printf(","); 3276 f = 0; 3277 } 3278 switch (cfg_mthd & (1 << n)) { 3279 case 0: 3280 break; 3281 case IEEE80211_WPS_CONFIG_USBA: 3282 printf("usba"); 3283 f++; 3284 break; 3285 case IEEE80211_WPS_CONFIG_ETHERNET: 3286 printf("ethernet"); 3287 f++; 3288 break; 3289 case IEEE80211_WPS_CONFIG_LABEL: 3290 printf("label"); 3291 f++; 3292 break; 3293 case IEEE80211_WPS_CONFIG_DISPLAY: 3294 if (!(cfg_mthd & 3295 (IEEE80211_WPS_CONFIG_VIRT_DISPLAY | 3296 IEEE80211_WPS_CONFIG_PHY_DISPLAY))) 3297 { 3298 printf("display"); 3299 f++; 3300 } 3301 break; 3302 case IEEE80211_WPS_CONFIG_EXT_NFC_TOKEN: 3303 printf("ext_nfc_tokenk"); 3304 f++; 3305 break; 3306 case IEEE80211_WPS_CONFIG_INT_NFC_TOKEN: 3307 printf("int_nfc_token"); 3308 f++; 3309 break; 3310 case IEEE80211_WPS_CONFIG_NFC_INTERFACE: 3311 printf("nfc_interface"); 3312 f++; 3313 break; 3314 case IEEE80211_WPS_CONFIG_PUSHBUTTON: 3315 if (!(cfg_mthd & 3316 (IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON | 3317 IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON))) { 3318 printf("push_button"); 3319 f++; 3320 } 3321 break; 3322 case IEEE80211_WPS_CONFIG_KEYPAD: 3323 printf("keypad"); 3324 f++; 3325 break; 3326 case IEEE80211_WPS_CONFIG_VIRT_PUSHBUTTON: 3327 printf("virtual_push_button"); 3328 f++; 3329 break; 3330 case IEEE80211_WPS_CONFIG_PHY_PUSHBUTTON: 3331 printf("physical_push_button"); 3332 f++; 3333 break; 3334 case IEEE80211_WPS_CONFIG_P2PS: 3335 printf("p2ps"); 3336 f++; 3337 break; 3338 case IEEE80211_WPS_CONFIG_VIRT_DISPLAY: 3339 printf("virtual_display"); 3340 f++; 3341 break; 3342 case IEEE80211_WPS_CONFIG_PHY_DISPLAY: 3343 printf("physical_display"); 3344 f++; 3345 break; 3346 default: 3347 printf("unknown_wps_config<%04x>", 3348 cfg_mthd & (1 << n)); 3349 f++; 3350 break; 3351 } 3352 } 3353 break; 3354 case IEEE80211_WPS_ATTR_DEV_NAME: 3355 printf(" device_name:<%.*s>", tlv_len, ie); 3356 break; 3357 case IEEE80211_WPS_ATTR_DEV_PASSWORD_ID: 3358 n = LE_READ_2(ie); 3359 if (n < (int)nitems(dev_pass_id)) 3360 printf(" dpi:%s", dev_pass_id[n]); 3361 break; 3362 case IEEE80211_WPS_ATTR_MANUFACTURER: 3363 printf(" manufacturer:<%.*s>", tlv_len, ie); 3364 break; 3365 case IEEE80211_WPS_ATTR_MODEL_NAME: 3366 printf(" model_name:<%.*s>", tlv_len, ie); 3367 break; 3368 case IEEE80211_WPS_ATTR_MODEL_NUMBER: 3369 printf(" model_number:<%.*s>", tlv_len, ie); 3370 break; 3371 case IEEE80211_WPS_ATTR_PRIMARY_DEV_TYPE: 3372 printf(" prim_dev:"); 3373 for (n = 0; n < tlv_len; n++) 3374 printf("%02x", ie[n]); 3375 break; 3376 case IEEE80211_WPS_ATTR_RF_BANDS: 3377 printf(" rf:"); 3378 f = 0; 3379 for (n = 7; n >= 0; n--) { 3380 if (f) { 3381 printf(","); 3382 f = 0; 3383 } 3384 switch (*ie & (1 << n)) { 3385 case 0: 3386 break; 3387 case IEEE80211_WPS_RF_BAND_24GHZ: 3388 printf("2.4Ghz"); 3389 f++; 3390 break; 3391 case IEEE80211_WPS_RF_BAND_50GHZ: 3392 printf("5Ghz"); 3393 f++; 3394 break; 3395 case IEEE80211_WPS_RF_BAND_600GHZ: 3396 printf("60Ghz"); 3397 f++; 3398 break; 3399 default: 3400 printf("unknown<%02x>", 3401 *ie & (1 << n)); 3402 f++; 3403 break; 3404 } 3405 } 3406 break; 3407 case IEEE80211_WPS_ATTR_RESPONSE_TYPE: 3408 printf(" resp_type:0x%02x", *ie); 3409 break; 3410 case IEEE80211_WPS_ATTR_SELECTED_REGISTRAR: 3411 printf(" sel:%s", *ie ? "T" : "F"); 3412 break; 3413 case IEEE80211_WPS_ATTR_SERIAL_NUMBER: 3414 printf(" serial_number:<%.*s>", tlv_len, ie); 3415 break; 3416 case IEEE80211_WPS_ATTR_UUID_E: 3417 printf(" uuid-e:"); 3418 for (n = 0; n < (tlv_len - 1); n++) 3419 printf("%02x-", ie[n]); 3420 printf("%02x", ie[n]); 3421 break; 3422 case IEEE80211_WPS_ATTR_VENDOR_EXT: 3423 printf(" vendor:"); 3424 for (n = 0; n < tlv_len; n++) 3425 printf("%02x", ie[n]); 3426 break; 3427 case IEEE80211_WPS_ATTR_WPS_STATE: 3428 switch (*ie) { 3429 case IEEE80211_WPS_STATE_NOT_CONFIGURED: 3430 printf(" state:N"); 3431 break; 3432 case IEEE80211_WPS_STATE_CONFIGURED: 3433 printf(" state:C"); 3434 break; 3435 default: 3436 printf(" state:B<%02x>", *ie); 3437 break; 3438 } 3439 break; 3440 default: 3441 printf(" unknown_wps_attr:0x%x", tlv_type); 3442 break; 3443 } 3444 ie += tlv_len, len -= tlv_len; 3445 } 3446 printf(">"); 3447 } 3448 } 3449 3450 static void 3451 printtdmaie(if_ctx *ctx, const char *tag, const u_int8_t *ie, size_t ielen) 3452 { 3453 printf("%s", tag); 3454 if (ctx->args->verbose && ielen >= sizeof(struct ieee80211_tdma_param)) { 3455 const struct ieee80211_tdma_param *tdma = 3456 (const struct ieee80211_tdma_param *) ie; 3457 3458 /* XXX tstamp */ 3459 printf("<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>", 3460 tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt, 3461 LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval, 3462 tdma->tdma_inuse[0]); 3463 } 3464 } 3465 3466 /* 3467 * Copy the ssid string contents into buf, truncating to fit. If the 3468 * ssid is entirely printable then just copy intact. Otherwise convert 3469 * to hexadecimal. If the result is truncated then replace the last 3470 * three characters with "...". 3471 */ 3472 static int 3473 copy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len) 3474 { 3475 const u_int8_t *p; 3476 size_t maxlen; 3477 u_int i; 3478 3479 if (essid_len > bufsize) 3480 maxlen = bufsize; 3481 else 3482 maxlen = essid_len; 3483 /* determine printable or not */ 3484 for (i = 0, p = essid; i < maxlen; i++, p++) { 3485 if (*p < ' ' || *p > 0x7e) 3486 break; 3487 } 3488 if (i != maxlen) { /* not printable, print as hex */ 3489 if (bufsize < 3) 3490 return 0; 3491 strlcpy(buf, "0x", bufsize); 3492 bufsize -= 2; 3493 p = essid; 3494 for (i = 0; i < maxlen && bufsize >= 2; i++) { 3495 sprintf(&buf[2+2*i], "%02x", p[i]); 3496 bufsize -= 2; 3497 } 3498 if (i != essid_len) 3499 memcpy(&buf[2+2*i-3], "...", 3); 3500 } else { /* printable, truncate as needed */ 3501 memcpy(buf, essid, maxlen); 3502 if (maxlen != essid_len) 3503 memcpy(&buf[maxlen-3], "...", 3); 3504 } 3505 return maxlen; 3506 } 3507 3508 static void 3509 printssid(const char *tag, const u_int8_t *ie, int maxlen) 3510 { 3511 char ssid[2*IEEE80211_NWID_LEN+1]; 3512 3513 printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid); 3514 } 3515 3516 static void 3517 printrates(const char *tag, const u_int8_t *ie, size_t ielen) 3518 { 3519 const char *sep; 3520 3521 printf("%s", tag); 3522 sep = "<"; 3523 for (size_t i = 2; i < ielen; i++) { 3524 printf("%s%s%d", sep, 3525 ie[i] & IEEE80211_RATE_BASIC ? "B" : "", 3526 ie[i] & IEEE80211_RATE_VAL); 3527 sep = ","; 3528 } 3529 printf(">"); 3530 } 3531 3532 static void 3533 printcountry(const char *tag, const u_int8_t *ie) 3534 { 3535 const struct ieee80211_country_ie *cie = 3536 (const struct ieee80211_country_ie *) ie; 3537 int i, nbands, schan, nchan; 3538 3539 printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]); 3540 nbands = (cie->len - 3) / sizeof(cie->band[0]); 3541 for (i = 0; i < nbands; i++) { 3542 schan = cie->band[i].schan; 3543 nchan = cie->band[i].nchan; 3544 if (nchan != 1) 3545 printf(" %u-%u,%u", schan, schan + nchan-1, 3546 cie->band[i].maxtxpwr); 3547 else 3548 printf(" %u,%u", schan, cie->band[i].maxtxpwr); 3549 } 3550 printf(">"); 3551 } 3552 3553 static __inline int 3554 iswpaoui(const u_int8_t *frm) 3555 { 3556 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI); 3557 } 3558 3559 static __inline int 3560 iswmeinfo(const u_int8_t *frm) 3561 { 3562 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) && 3563 frm[6] == WME_INFO_OUI_SUBTYPE; 3564 } 3565 3566 static __inline int 3567 iswmeparam(const u_int8_t *frm) 3568 { 3569 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) && 3570 frm[6] == WME_PARAM_OUI_SUBTYPE; 3571 } 3572 3573 static __inline int 3574 isatherosoui(const u_int8_t *frm) 3575 { 3576 return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI); 3577 } 3578 3579 static __inline int 3580 istdmaoui(const uint8_t *frm) 3581 { 3582 return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI); 3583 } 3584 3585 static __inline int 3586 iswpsoui(const uint8_t *frm) 3587 { 3588 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPS_OUI_TYPE<<24)|WPA_OUI); 3589 } 3590 3591 static const char * 3592 iename(int elemid) 3593 { 3594 static char iename_buf[64]; 3595 switch (elemid) { 3596 case IEEE80211_ELEMID_FHPARMS: return " FHPARMS"; 3597 case IEEE80211_ELEMID_CFPARMS: return " CFPARMS"; 3598 case IEEE80211_ELEMID_TIM: return " TIM"; 3599 case IEEE80211_ELEMID_IBSSPARMS:return " IBSSPARMS"; 3600 case IEEE80211_ELEMID_BSSLOAD: return " BSSLOAD"; 3601 case IEEE80211_ELEMID_CHALLENGE:return " CHALLENGE"; 3602 case IEEE80211_ELEMID_PWRCNSTR: return " PWRCNSTR"; 3603 case IEEE80211_ELEMID_PWRCAP: return " PWRCAP"; 3604 case IEEE80211_ELEMID_TPCREQ: return " TPCREQ"; 3605 case IEEE80211_ELEMID_TPCREP: return " TPCREP"; 3606 case IEEE80211_ELEMID_SUPPCHAN: return " SUPPCHAN"; 3607 case IEEE80211_ELEMID_CSA: return " CSA"; 3608 case IEEE80211_ELEMID_MEASREQ: return " MEASREQ"; 3609 case IEEE80211_ELEMID_MEASREP: return " MEASREP"; 3610 case IEEE80211_ELEMID_QUIET: return " QUIET"; 3611 case IEEE80211_ELEMID_IBSSDFS: return " IBSSDFS"; 3612 case IEEE80211_ELEMID_RESERVED_47: 3613 return " RESERVED_47"; 3614 case IEEE80211_ELEMID_MOBILITY_DOMAIN: 3615 return " MOBILITY_DOMAIN"; 3616 case IEEE80211_ELEMID_RRM_ENACAPS: 3617 return " RRM_ENCAPS"; 3618 case IEEE80211_ELEMID_OVERLAP_BSS_SCAN_PARAM: 3619 return " OVERLAP_BSS"; 3620 case IEEE80211_ELEMID_TPC: return " TPC"; 3621 case IEEE80211_ELEMID_CCKM: return " CCKM"; 3622 case IEEE80211_ELEMID_EXTCAP: return " EXTCAP"; 3623 } 3624 snprintf(iename_buf, sizeof(iename_buf), " UNKNOWN_ELEMID_%d", 3625 elemid); 3626 return (const char *) iename_buf; 3627 } 3628 3629 static void 3630 printies(if_ctx *ctx, const u_int8_t *vp, int ielen, unsigned int maxcols) 3631 { 3632 const int verbose = ctx->args->verbose; 3633 3634 while (ielen > 0) { 3635 switch (vp[0]) { 3636 case IEEE80211_ELEMID_SSID: 3637 if (verbose) 3638 printssid(" SSID", vp, maxcols); 3639 break; 3640 case IEEE80211_ELEMID_RATES: 3641 case IEEE80211_ELEMID_XRATES: 3642 if (verbose) 3643 printrates(vp[0] == IEEE80211_ELEMID_RATES ? 3644 " RATES" : " XRATES", vp, 2+vp[1]); 3645 break; 3646 case IEEE80211_ELEMID_DSPARMS: 3647 if (verbose) 3648 printf(" DSPARMS<%u>", vp[2]); 3649 break; 3650 case IEEE80211_ELEMID_COUNTRY: 3651 if (verbose) 3652 printcountry(" COUNTRY", vp); 3653 break; 3654 case IEEE80211_ELEMID_ERP: 3655 if (verbose) 3656 printf(" ERP<0x%x>", vp[2]); 3657 break; 3658 case IEEE80211_ELEMID_VENDOR: 3659 if (iswpaoui(vp)) 3660 printwpaie(ctx, " WPA", vp); 3661 else if (iswmeinfo(vp)) 3662 printwmeinfo(ctx, " WME", vp); 3663 else if (iswmeparam(vp)) 3664 printwmeparam(ctx, " WME", vp); 3665 else if (isatherosoui(vp)) 3666 printathie(ctx, " ATH", vp); 3667 else if (iswpsoui(vp)) 3668 printwpsie(ctx, " WPS", vp); 3669 else if (istdmaoui(vp)) 3670 printtdmaie(ctx, " TDMA", vp, 2+vp[1]); 3671 else if (verbose) 3672 printie(ctx, " VEN", vp, 2+vp[1], maxcols); 3673 break; 3674 case IEEE80211_ELEMID_RSN: 3675 printrsnie(ctx, " RSN", vp, 2+vp[1]); 3676 break; 3677 case IEEE80211_ELEMID_HTCAP: 3678 printhtcap(ctx, " HTCAP", vp); 3679 break; 3680 case IEEE80211_ELEMID_HTINFO: 3681 if (verbose) 3682 printhtinfo(ctx, " HTINFO", vp); 3683 break; 3684 case IEEE80211_ELEMID_MESHID: 3685 if (verbose) 3686 printssid(" MESHID", vp, maxcols); 3687 break; 3688 case IEEE80211_ELEMID_MESHCONF: 3689 printmeshconf(ctx, " MESHCONF", vp); 3690 break; 3691 case IEEE80211_ELEMID_VHT_CAP: 3692 printvhtcap(ctx, " VHTCAP", vp); 3693 break; 3694 case IEEE80211_ELEMID_VHT_OPMODE: 3695 printvhtinfo(ctx, " VHTOPMODE", vp); 3696 break; 3697 case IEEE80211_ELEMID_VHT_PWR_ENV: 3698 printvhtpwrenv(ctx, " VHTPWRENV", vp, 2+vp[1]); 3699 break; 3700 case IEEE80211_ELEMID_BSSLOAD: 3701 printbssload(ctx, " BSSLOAD", vp); 3702 break; 3703 case IEEE80211_ELEMID_APCHANREP: 3704 printapchanrep(ctx, " APCHANREP", vp, 2+vp[1]); 3705 break; 3706 default: 3707 if (verbose) 3708 printie(ctx, iename(vp[0]), vp, 2+vp[1], maxcols); 3709 break; 3710 } 3711 ielen -= 2+vp[1]; 3712 vp += 2+vp[1]; 3713 } 3714 } 3715 3716 static void 3717 printmimo(const struct ieee80211_mimo_info *mi) 3718 { 3719 int i; 3720 int r = 0; 3721 3722 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { 3723 if (mi->ch[i].rssi[0] != 0) { 3724 r = 1; 3725 break; 3726 } 3727 } 3728 3729 /* NB: don't muddy display unless there's something to show */ 3730 if (r == 0) 3731 return; 3732 3733 /* XXX TODO: ignore EVM; secondary channels for now */ 3734 printf(" (rssi %.1f:%.1f:%.1f:%.1f nf %d:%d:%d:%d)", 3735 mi->ch[0].rssi[0] / 2.0, 3736 mi->ch[1].rssi[0] / 2.0, 3737 mi->ch[2].rssi[0] / 2.0, 3738 mi->ch[3].rssi[0] / 2.0, 3739 mi->ch[0].noise[0], 3740 mi->ch[1].noise[0], 3741 mi->ch[2].noise[0], 3742 mi->ch[3].noise[0]); 3743 } 3744 3745 static void 3746 printbssidname(const struct ether_addr *n) 3747 { 3748 char name[MAXHOSTNAMELEN + 1]; 3749 3750 if (ether_ntohost(name, n) != 0) 3751 return; 3752 3753 printf(" (%s)", name); 3754 } 3755 3756 static void 3757 list_scan(if_ctx *ctx) 3758 { 3759 uint8_t buf[24*1024]; 3760 char ssid[IEEE80211_NWID_LEN+1]; 3761 const uint8_t *cp; 3762 int len, idlen; 3763 3764 if (get80211len(ctx, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0) 3765 errx(1, "unable to get scan results"); 3766 if (len < (int)sizeof(struct ieee80211req_scan_result)) 3767 return; 3768 3769 getchaninfo(ctx); 3770 3771 printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n" 3772 , IEEE80211_NWID_LEN, IEEE80211_NWID_LEN, "SSID/MESH ID" 3773 , "BSSID" 3774 , "CHAN" 3775 , "RATE" 3776 , " S:N" 3777 , "INT" 3778 , "CAPS" 3779 ); 3780 cp = buf; 3781 do { 3782 const struct ieee80211req_scan_result *sr; 3783 const uint8_t *vp, *idp; 3784 3785 sr = (const struct ieee80211req_scan_result *)(const void *) cp; 3786 vp = cp + sr->isr_ie_off; 3787 if (sr->isr_meshid_len) { 3788 idp = vp + sr->isr_ssid_len; 3789 idlen = sr->isr_meshid_len; 3790 } else { 3791 idp = vp; 3792 idlen = sr->isr_ssid_len; 3793 } 3794 printf("%-*.*s %s %3d %3dM %4d:%-4d %4d %-4.4s" 3795 , IEEE80211_NWID_LEN 3796 , copy_essid(ssid, IEEE80211_NWID_LEN, idp, idlen) 3797 , ssid 3798 , ether_ntoa((const struct ether_addr *) sr->isr_bssid) 3799 , ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags) 3800 , getmaxrate(sr->isr_rates, sr->isr_nrates) 3801 , (sr->isr_rssi/2)+sr->isr_noise, sr->isr_noise 3802 , sr->isr_intval 3803 , getcaps(sr->isr_capinfo) 3804 ); 3805 printies(ctx, vp + sr->isr_ssid_len + sr->isr_meshid_len, 3806 sr->isr_ie_len, 24); 3807 printbssidname((const struct ether_addr *)sr->isr_bssid); 3808 printf("\n"); 3809 cp += sr->isr_len, len -= sr->isr_len; 3810 } while (len >= (int)sizeof(struct ieee80211req_scan_result)); 3811 } 3812 3813 static void 3814 scan_and_wait(if_ctx *ctx) 3815 { 3816 struct ieee80211_scan_req sr; 3817 struct ieee80211req ireq; 3818 int sroute; 3819 3820 sroute = socket(PF_ROUTE, SOCK_RAW, 0); 3821 if (sroute < 0) { 3822 perror("socket(PF_ROUTE,SOCK_RAW)"); 3823 return; 3824 } 3825 memset(&ireq, 0, sizeof(ireq)); 3826 strlcpy(ireq.i_name, ctx->ifname, sizeof(ireq.i_name)); 3827 ireq.i_type = IEEE80211_IOC_SCAN_REQ; 3828 3829 memset(&sr, 0, sizeof(sr)); 3830 sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE 3831 | IEEE80211_IOC_SCAN_BGSCAN 3832 | IEEE80211_IOC_SCAN_NOPICK 3833 | IEEE80211_IOC_SCAN_ONCE; 3834 sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER; 3835 sr.sr_nssid = 0; 3836 3837 ireq.i_data = &sr; 3838 ireq.i_len = sizeof(sr); 3839 /* 3840 * NB: only root can trigger a scan so ignore errors. Also ignore 3841 * possible errors from net80211, even if no new scan could be 3842 * started there might still be a valid scan cache. 3843 */ 3844 if (ioctl_ctx(ctx, SIOCS80211, &ireq) == 0) { 3845 char buf[2048]; 3846 struct if_announcemsghdr *ifan; 3847 struct rt_msghdr *rtm; 3848 3849 do { 3850 if (read(sroute, buf, sizeof(buf)) < 0) { 3851 perror("read(PF_ROUTE)"); 3852 break; 3853 } 3854 rtm = (struct rt_msghdr *)(void *)buf; 3855 if (rtm->rtm_version != RTM_VERSION) 3856 break; 3857 ifan = (struct if_announcemsghdr *) rtm; 3858 } while (rtm->rtm_type != RTM_IEEE80211 || 3859 ifan->ifan_what != RTM_IEEE80211_SCAN); 3860 } 3861 close(sroute); 3862 } 3863 3864 static void 3865 set80211scan(if_ctx *ctx, const char *val __unused, int dummy __unused) 3866 { 3867 scan_and_wait(ctx); 3868 list_scan(ctx); 3869 } 3870 3871 static enum ieee80211_opmode get80211opmode(if_ctx *ctx); 3872 3873 static int 3874 gettxseq(const struct ieee80211req_sta_info *si) 3875 { 3876 int i, txseq; 3877 3878 if ((si->isi_state & IEEE80211_NODE_QOS) == 0) 3879 return si->isi_txseqs[0]; 3880 /* XXX not right but usually what folks want */ 3881 txseq = 0; 3882 for (i = 0; i < IEEE80211_TID_SIZE; i++) 3883 if (si->isi_txseqs[i] > txseq) 3884 txseq = si->isi_txseqs[i]; 3885 return txseq; 3886 } 3887 3888 static int 3889 getrxseq(const struct ieee80211req_sta_info *si) 3890 { 3891 int rxseq; 3892 3893 if ((si->isi_state & IEEE80211_NODE_QOS) == 0) 3894 return si->isi_rxseqs[0]; 3895 /* XXX not right but usually what folks want */ 3896 rxseq = 0; 3897 for (unsigned int i = 0; i < IEEE80211_TID_SIZE; i++) 3898 if (si->isi_rxseqs[i] > rxseq) 3899 rxseq = si->isi_rxseqs[i]; 3900 return rxseq; 3901 } 3902 3903 static void 3904 list_stations(if_ctx *ctx) 3905 { 3906 union { 3907 struct ieee80211req_sta_req req; 3908 uint8_t buf[24*1024]; 3909 } u; 3910 enum ieee80211_opmode opmode = get80211opmode(ctx); 3911 const uint8_t *cp; 3912 int len; 3913 3914 /* broadcast address =>'s get all stations */ 3915 (void) memset(u.req.is_u.macaddr, 0xff, IEEE80211_ADDR_LEN); 3916 if (opmode == IEEE80211_M_STA) { 3917 /* 3918 * Get information about the associated AP. 3919 */ 3920 (void) get80211(ctx, IEEE80211_IOC_BSSID, 3921 u.req.is_u.macaddr, IEEE80211_ADDR_LEN); 3922 } 3923 if (get80211len(ctx, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0) 3924 errx(1, "unable to get station information"); 3925 if (len < (int)sizeof(struct ieee80211req_sta_info)) 3926 return; 3927 3928 getchaninfo(ctx); 3929 3930 if (opmode == IEEE80211_M_MBSS) 3931 printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n" 3932 , "ADDR" 3933 , "CHAN" 3934 , "LOCAL" 3935 , "PEER" 3936 , "STATE" 3937 , "RATE" 3938 , "RSSI" 3939 , "IDLE" 3940 , "TXSEQ" 3941 , "RXSEQ" 3942 ); 3943 else 3944 printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-12s\n" 3945 , "ADDR" 3946 , "AID" 3947 , "CHAN" 3948 , "RATE" 3949 , "RSSI" 3950 , "IDLE" 3951 , "TXSEQ" 3952 , "RXSEQ" 3953 , "CAPS" 3954 , "FLAG" 3955 ); 3956 cp = (const uint8_t *) u.req.info; 3957 do { 3958 const struct ieee80211req_sta_info *si; 3959 3960 si = (const struct ieee80211req_sta_info *)(const void *)cp; 3961 if (si->isi_len < sizeof(*si)) 3962 break; 3963 if (opmode == IEEE80211_M_MBSS) 3964 printf("%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d" 3965 , ether_ntoa((const struct ether_addr*) 3966 si->isi_macaddr) 3967 , ieee80211_mhz2ieee(si->isi_freq, 3968 si->isi_flags) 3969 , si->isi_localid 3970 , si->isi_peerid 3971 , mesh_linkstate_string(si->isi_peerstate) 3972 , si->isi_txmbps/2 3973 , si->isi_rssi/2. 3974 , si->isi_inact 3975 , gettxseq(si) 3976 , getrxseq(si) 3977 ); 3978 else 3979 printf("%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-12.12s" 3980 , ether_ntoa((const struct ether_addr*) 3981 si->isi_macaddr) 3982 , IEEE80211_AID(si->isi_associd) 3983 , ieee80211_mhz2ieee(si->isi_freq, 3984 si->isi_flags) 3985 , si->isi_txmbps/2 3986 , si->isi_rssi/2. 3987 , si->isi_inact 3988 , gettxseq(si) 3989 , getrxseq(si) 3990 , getcaps(si->isi_capinfo) 3991 , getflags(si->isi_state) 3992 ); 3993 printies(ctx, cp + si->isi_ie_off, si->isi_ie_len, 24); 3994 printmimo(&si->isi_mimo); 3995 printf("\n"); 3996 cp += si->isi_len, len -= si->isi_len; 3997 } while (len >= (int)sizeof(struct ieee80211req_sta_info)); 3998 } 3999 4000 static const char * 4001 mesh_linkstate_string(uint8_t state) 4002 { 4003 static const char *state_names[] = { 4004 [0] = "IDLE", 4005 [1] = "OPEN-TX", 4006 [2] = "OPEN-RX", 4007 [3] = "CONF-RX", 4008 [4] = "ESTAB", 4009 [5] = "HOLDING", 4010 }; 4011 4012 if (state >= nitems(state_names)) { 4013 static char buf[10]; 4014 snprintf(buf, sizeof(buf), "#%u", state); 4015 return buf; 4016 } else 4017 return state_names[state]; 4018 } 4019 4020 static const char * 4021 get_chaninfo(const struct ieee80211_channel *c, int precise, 4022 char buf[], size_t bsize) 4023 { 4024 buf[0] = '\0'; 4025 if (IEEE80211_IS_CHAN_FHSS(c)) 4026 strlcat(buf, " FHSS", bsize); 4027 if (IEEE80211_IS_CHAN_A(c)) 4028 strlcat(buf, " 11a", bsize); 4029 else if (IEEE80211_IS_CHAN_ANYG(c)) 4030 strlcat(buf, " 11g", bsize); 4031 else if (IEEE80211_IS_CHAN_B(c)) 4032 strlcat(buf, " 11b", bsize); 4033 if (IEEE80211_IS_CHAN_HALF(c)) 4034 strlcat(buf, "/10MHz", bsize); 4035 if (IEEE80211_IS_CHAN_QUARTER(c)) 4036 strlcat(buf, "/5MHz", bsize); 4037 if (IEEE80211_IS_CHAN_TURBO(c)) 4038 strlcat(buf, " Turbo", bsize); 4039 if (precise) { 4040 if (IEEE80211_IS_CHAN_VHT80P80(c)) 4041 strlcat(buf, " vht/80p80", bsize); 4042 else if (IEEE80211_IS_CHAN_VHT160(c)) 4043 strlcat(buf, " vht/160", bsize); 4044 else if (IEEE80211_IS_CHAN_VHT80(c) && 4045 IEEE80211_IS_CHAN_HT40D(c)) 4046 strlcat(buf, " vht/80-", bsize); 4047 else if (IEEE80211_IS_CHAN_VHT80(c) && 4048 IEEE80211_IS_CHAN_HT40U(c)) 4049 strlcat(buf, " vht/80+", bsize); 4050 else if (IEEE80211_IS_CHAN_VHT80(c)) 4051 strlcat(buf, " vht/80", bsize); 4052 else if (IEEE80211_IS_CHAN_VHT40D(c)) 4053 strlcat(buf, " vht/40-", bsize); 4054 else if (IEEE80211_IS_CHAN_VHT40U(c)) 4055 strlcat(buf, " vht/40+", bsize); 4056 else if (IEEE80211_IS_CHAN_VHT20(c)) 4057 strlcat(buf, " vht/20", bsize); 4058 else if (IEEE80211_IS_CHAN_HT20(c)) 4059 strlcat(buf, " ht/20", bsize); 4060 else if (IEEE80211_IS_CHAN_HT40D(c)) 4061 strlcat(buf, " ht/40-", bsize); 4062 else if (IEEE80211_IS_CHAN_HT40U(c)) 4063 strlcat(buf, " ht/40+", bsize); 4064 } else { 4065 if (IEEE80211_IS_CHAN_VHT(c)) 4066 strlcat(buf, " vht", bsize); 4067 else if (IEEE80211_IS_CHAN_HT(c)) 4068 strlcat(buf, " ht", bsize); 4069 } 4070 return buf; 4071 } 4072 4073 static void 4074 print_chaninfo(const struct ieee80211_channel *c, int verb) 4075 { 4076 char buf[14]; 4077 4078 if (verb) 4079 printf("Channel %3u : %u%c%c%c%c%c MHz%-14.14s", 4080 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq, 4081 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ', 4082 IEEE80211_IS_CHAN_DFS(c) ? 'D' : ' ', 4083 IEEE80211_IS_CHAN_RADAR(c) ? 'R' : ' ', 4084 IEEE80211_IS_CHAN_CWINT(c) ? 'I' : ' ', 4085 IEEE80211_IS_CHAN_CACDONE(c) ? 'C' : ' ', 4086 get_chaninfo(c, verb, buf, sizeof(buf))); 4087 else 4088 printf("Channel %3u : %u%c MHz%-14.14s", 4089 ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq, 4090 IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ', 4091 get_chaninfo(c, verb, buf, sizeof(buf))); 4092 4093 } 4094 4095 static int 4096 chanpref(const struct ieee80211_channel *c) 4097 { 4098 4099 if (IEEE80211_IS_CHAN_VHT80P80(c)) 4100 return 90; 4101 if (IEEE80211_IS_CHAN_VHT160(c)) 4102 return 80; 4103 if (IEEE80211_IS_CHAN_VHT80(c)) 4104 return 70; 4105 if (IEEE80211_IS_CHAN_VHT40(c)) 4106 return 60; 4107 if (IEEE80211_IS_CHAN_VHT20(c)) 4108 return 50; 4109 if (IEEE80211_IS_CHAN_HT40(c)) 4110 return 40; 4111 if (IEEE80211_IS_CHAN_HT20(c)) 4112 return 30; 4113 if (IEEE80211_IS_CHAN_HALF(c)) 4114 return 10; 4115 if (IEEE80211_IS_CHAN_QUARTER(c)) 4116 return 5; 4117 if (IEEE80211_IS_CHAN_TURBO(c)) 4118 return 25; 4119 if (IEEE80211_IS_CHAN_A(c)) 4120 return 20; 4121 if (IEEE80211_IS_CHAN_G(c)) 4122 return 20; 4123 if (IEEE80211_IS_CHAN_B(c)) 4124 return 15; 4125 if (IEEE80211_IS_CHAN_PUREG(c)) 4126 return 15; 4127 return 0; 4128 } 4129 4130 static void 4131 print_channels(if_ctx *ctx, const struct ieee80211req_chaninfo *chans, 4132 int allchans, int verb) 4133 { 4134 struct ieee80211req_chaninfo *achans; 4135 uint8_t reported[IEEE80211_CHAN_BYTES]; 4136 const struct ieee80211_channel *c; 4137 unsigned int i, half; 4138 4139 achans = malloc(IEEE80211_CHANINFO_SPACE(chans)); 4140 if (achans == NULL) 4141 errx(1, "no space for active channel list"); 4142 achans->ic_nchans = 0; 4143 memset(reported, 0, sizeof(reported)); 4144 if (!allchans) { 4145 struct ieee80211req_chanlist active; 4146 4147 if (get80211(ctx, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0) 4148 errx(1, "unable to get active channel list"); 4149 for (i = 0; i < chans->ic_nchans; i++) { 4150 c = &chans->ic_chans[i]; 4151 if (!isset(active.ic_channels, c->ic_ieee)) 4152 continue; 4153 /* 4154 * Suppress compatible duplicates unless 4155 * verbose. The kernel gives us it's 4156 * complete channel list which has separate 4157 * entries for 11g/11b and 11a/turbo. 4158 */ 4159 if (isset(reported, c->ic_ieee) && !verb) { 4160 /* XXX we assume duplicates are adjacent */ 4161 achans->ic_chans[achans->ic_nchans-1] = *c; 4162 } else { 4163 achans->ic_chans[achans->ic_nchans++] = *c; 4164 setbit(reported, c->ic_ieee); 4165 } 4166 } 4167 } else { 4168 for (i = 0; i < chans->ic_nchans; i++) { 4169 c = &chans->ic_chans[i]; 4170 /* suppress duplicates as above */ 4171 if (isset(reported, c->ic_ieee) && !verb) { 4172 /* XXX we assume duplicates are adjacent */ 4173 struct ieee80211_channel *a = 4174 &achans->ic_chans[achans->ic_nchans-1]; 4175 if (chanpref(c) > chanpref(a)) 4176 *a = *c; 4177 } else { 4178 achans->ic_chans[achans->ic_nchans++] = *c; 4179 setbit(reported, c->ic_ieee); 4180 } 4181 } 4182 } 4183 half = achans->ic_nchans / 2; 4184 if (achans->ic_nchans % 2) 4185 half++; 4186 4187 for (i = 0; i < achans->ic_nchans / 2; i++) { 4188 print_chaninfo(&achans->ic_chans[i], verb); 4189 print_chaninfo(&achans->ic_chans[half+i], verb); 4190 printf("\n"); 4191 } 4192 if (achans->ic_nchans % 2) { 4193 print_chaninfo(&achans->ic_chans[i], verb); 4194 printf("\n"); 4195 } 4196 free(achans); 4197 } 4198 4199 static void 4200 list_channels(if_ctx *ctx, int allchans) 4201 { 4202 getchaninfo(ctx); 4203 print_channels(ctx, chaninfo, allchans, ctx->args->verbose); 4204 } 4205 4206 static void 4207 print_txpow(const struct ieee80211_channel *c) 4208 { 4209 printf("Channel %3u : %u MHz %3.1f reg %2d ", 4210 c->ic_ieee, c->ic_freq, 4211 c->ic_maxpower/2., c->ic_maxregpower); 4212 } 4213 4214 static void 4215 print_txpow_verbose(const struct ieee80211_channel *c) 4216 { 4217 print_chaninfo(c, 1); 4218 printf("min %4.1f dBm max %3.1f dBm reg %2d dBm", 4219 c->ic_minpower/2., c->ic_maxpower/2., c->ic_maxregpower); 4220 /* indicate where regulatory cap limits power use */ 4221 if (c->ic_maxpower > 2*c->ic_maxregpower) 4222 printf(" <"); 4223 } 4224 4225 static void 4226 list_txpow(if_ctx *ctx) 4227 { 4228 struct ieee80211req_chaninfo *achans; 4229 uint8_t reported[IEEE80211_CHAN_BYTES]; 4230 struct ieee80211_channel *c, *prev; 4231 unsigned int i, half; 4232 4233 getchaninfo(ctx); 4234 achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo)); 4235 if (achans == NULL) 4236 errx(1, "no space for active channel list"); 4237 achans->ic_nchans = 0; 4238 memset(reported, 0, sizeof(reported)); 4239 for (i = 0; i < chaninfo->ic_nchans; i++) { 4240 c = &chaninfo->ic_chans[i]; 4241 /* suppress duplicates as above */ 4242 if (isset(reported, c->ic_ieee) && !ctx->args->verbose) { 4243 /* XXX we assume duplicates are adjacent */ 4244 assert(achans->ic_nchans > 0); 4245 prev = &achans->ic_chans[achans->ic_nchans-1]; 4246 /* display highest power on channel */ 4247 if (c->ic_maxpower > prev->ic_maxpower) 4248 *prev = *c; 4249 } else { 4250 achans->ic_chans[achans->ic_nchans++] = *c; 4251 setbit(reported, c->ic_ieee); 4252 } 4253 } 4254 if (!ctx->args->verbose) { 4255 half = achans->ic_nchans / 2; 4256 if (achans->ic_nchans % 2) 4257 half++; 4258 4259 for (i = 0; i < achans->ic_nchans / 2; i++) { 4260 print_txpow(&achans->ic_chans[i]); 4261 print_txpow(&achans->ic_chans[half+i]); 4262 printf("\n"); 4263 } 4264 if (achans->ic_nchans % 2) { 4265 print_txpow(&achans->ic_chans[i]); 4266 printf("\n"); 4267 } 4268 } else { 4269 for (i = 0; i < achans->ic_nchans; i++) { 4270 print_txpow_verbose(&achans->ic_chans[i]); 4271 printf("\n"); 4272 } 4273 } 4274 free(achans); 4275 } 4276 4277 static void 4278 list_keys(int s __unused) 4279 { 4280 } 4281 4282 static void 4283 list_capabilities(if_ctx *ctx) 4284 { 4285 struct ieee80211_devcaps_req *dc; 4286 const int verbose = ctx->args->verbose; 4287 4288 if (verbose) 4289 dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN)); 4290 else 4291 dc = malloc(IEEE80211_DEVCAPS_SIZE(1)); 4292 if (dc == NULL) 4293 errx(1, "no space for device capabilities"); 4294 dc->dc_chaninfo.ic_nchans = verbose ? MAXCHAN : 1; 4295 getdevcaps(ctx, dc); 4296 printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS); 4297 if (dc->dc_cryptocaps != 0 || verbose) { 4298 putchar('\n'); 4299 printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS); 4300 } 4301 if (dc->dc_htcaps != 0 || verbose) { 4302 putchar('\n'); 4303 printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS); 4304 } 4305 if (dc->dc_vhtcaps != 0 || verbose) { 4306 putchar('\n'); 4307 printb("vhtcaps", dc->dc_vhtcaps, IEEE80211_VHTCAP_BITS); 4308 } 4309 4310 putchar('\n'); 4311 if (verbose) { 4312 chaninfo = &dc->dc_chaninfo; /* XXX */ 4313 print_channels(ctx, &dc->dc_chaninfo, 1/*allchans*/, verbose); 4314 } 4315 free(dc); 4316 } 4317 4318 static int 4319 get80211wme(if_ctx *ctx, int param, int ac, int *val) 4320 { 4321 struct ieee80211req ireq = {}; 4322 4323 strlcpy(ireq.i_name, ctx->ifname, sizeof(ireq.i_name)); 4324 ireq.i_type = param; 4325 ireq.i_len = ac; 4326 if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) { 4327 warn("cannot get WME parameter %d, ac %d%s", 4328 param, ac & IEEE80211_WMEPARAM_VAL, 4329 ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : ""); 4330 return -1; 4331 } 4332 *val = ireq.i_val; 4333 return 0; 4334 } 4335 4336 static void 4337 list_wme_aci(if_ctx *ctx, const char *tag, int ac) 4338 { 4339 int val; 4340 4341 printf("\t%s", tag); 4342 4343 /* show WME BSS parameters */ 4344 if (get80211wme(ctx, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1) 4345 printf(" cwmin %2u", val); 4346 if (get80211wme(ctx, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1) 4347 printf(" cwmax %2u", val); 4348 if (get80211wme(ctx, IEEE80211_IOC_WME_AIFS, ac, &val) != -1) 4349 printf(" aifs %2u", val); 4350 if (get80211wme(ctx, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1) 4351 printf(" txopLimit %3u", val); 4352 if (get80211wme(ctx, IEEE80211_IOC_WME_ACM, ac, &val) != -1) { 4353 if (val) 4354 printf(" acm"); 4355 else if (ctx->args->verbose) 4356 printf(" -acm"); 4357 } 4358 /* !BSS only */ 4359 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) { 4360 if (get80211wme(ctx, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) { 4361 if (!val) 4362 printf(" -ack"); 4363 else if (ctx->args->verbose) 4364 printf(" ack"); 4365 } 4366 } 4367 printf("\n"); 4368 } 4369 4370 static void 4371 list_wme(if_ctx *ctx) 4372 { 4373 static const char *acnames[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" }; 4374 int ac; 4375 4376 if (ctx->args->verbose) { 4377 /* display both BSS and local settings */ 4378 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) { 4379 again: 4380 if (ac & IEEE80211_WMEPARAM_BSS) 4381 list_wme_aci(ctx, " ", ac); 4382 else 4383 list_wme_aci(ctx, acnames[ac], ac); 4384 if ((ac & IEEE80211_WMEPARAM_BSS) == 0) { 4385 ac |= IEEE80211_WMEPARAM_BSS; 4386 goto again; 4387 } else 4388 ac &= ~IEEE80211_WMEPARAM_BSS; 4389 } 4390 } else { 4391 /* display only channel settings */ 4392 for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) 4393 list_wme_aci(ctx, acnames[ac], ac); 4394 } 4395 } 4396 4397 static void 4398 list_roam(if_ctx *ctx) 4399 { 4400 const struct ieee80211_roamparam *rp; 4401 int mode; 4402 4403 getroam(ctx); 4404 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) { 4405 rp = &roamparams.params[mode]; 4406 if (rp->rssi == 0 && rp->rate == 0) 4407 continue; 4408 if (mode == IEEE80211_MODE_11NA || 4409 mode == IEEE80211_MODE_11NG || 4410 mode == IEEE80211_MODE_VHT_2GHZ || 4411 mode == IEEE80211_MODE_VHT_5GHZ) { 4412 if (rp->rssi & 1) 4413 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm MCS %2u ", 4414 modename[mode], rp->rssi/2, 4415 rp->rate &~ IEEE80211_RATE_MCS); 4416 else 4417 LINE_CHECK("roam:%-7.7s rssi %4udBm MCS %2u ", 4418 modename[mode], rp->rssi/2, 4419 rp->rate &~ IEEE80211_RATE_MCS); 4420 } else { 4421 if (rp->rssi & 1) 4422 LINE_CHECK("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s", 4423 modename[mode], rp->rssi/2, rp->rate/2); 4424 else 4425 LINE_CHECK("roam:%-7.7s rssi %4udBm rate %2u Mb/s", 4426 modename[mode], rp->rssi/2, rp->rate/2); 4427 } 4428 } 4429 } 4430 4431 /* XXX TODO: rate-to-string method... */ 4432 static const char* 4433 get_mcs_mbs_rate_str(uint8_t rate) 4434 { 4435 return (rate & IEEE80211_RATE_MCS) ? "MCS " : "Mb/s"; 4436 } 4437 4438 static uint8_t 4439 get_rate_value(uint8_t rate) 4440 { 4441 if (rate & IEEE80211_RATE_MCS) 4442 return (rate &~ IEEE80211_RATE_MCS); 4443 return (rate / 2); 4444 } 4445 4446 static void 4447 list_txparams(if_ctx *ctx) 4448 { 4449 const struct ieee80211_txparam *tp; 4450 int mode; 4451 4452 gettxparams(ctx); 4453 for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) { 4454 tp = &txparams.params[mode]; 4455 if (tp->mgmtrate == 0 && tp->mcastrate == 0) 4456 continue; 4457 if (mode == IEEE80211_MODE_11NA || 4458 mode == IEEE80211_MODE_11NG || 4459 mode == IEEE80211_MODE_VHT_2GHZ || 4460 mode == IEEE80211_MODE_VHT_5GHZ) { 4461 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) 4462 LINE_CHECK("%-7.7s ucast NONE mgmt %2u %s " 4463 "mcast %2u %s maxretry %u", 4464 modename[mode], 4465 get_rate_value(tp->mgmtrate), 4466 get_mcs_mbs_rate_str(tp->mgmtrate), 4467 get_rate_value(tp->mcastrate), 4468 get_mcs_mbs_rate_str(tp->mcastrate), 4469 tp->maxretry); 4470 else 4471 LINE_CHECK("%-7.7s ucast %2u MCS mgmt %2u %s " 4472 "mcast %2u %s maxretry %u", 4473 modename[mode], 4474 tp->ucastrate &~ IEEE80211_RATE_MCS, 4475 get_rate_value(tp->mgmtrate), 4476 get_mcs_mbs_rate_str(tp->mgmtrate), 4477 get_rate_value(tp->mcastrate), 4478 get_mcs_mbs_rate_str(tp->mcastrate), 4479 tp->maxretry); 4480 } else { 4481 if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) 4482 LINE_CHECK("%-7.7s ucast NONE mgmt %2u Mb/s " 4483 "mcast %2u Mb/s maxretry %u", 4484 modename[mode], 4485 tp->mgmtrate/2, 4486 tp->mcastrate/2, tp->maxretry); 4487 else 4488 LINE_CHECK("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s " 4489 "mcast %2u Mb/s maxretry %u", 4490 modename[mode], 4491 tp->ucastrate/2, tp->mgmtrate/2, 4492 tp->mcastrate/2, tp->maxretry); 4493 } 4494 } 4495 } 4496 4497 static void 4498 printpolicy(int policy) 4499 { 4500 switch (policy) { 4501 case IEEE80211_MACCMD_POLICY_OPEN: 4502 printf("policy: open\n"); 4503 break; 4504 case IEEE80211_MACCMD_POLICY_ALLOW: 4505 printf("policy: allow\n"); 4506 break; 4507 case IEEE80211_MACCMD_POLICY_DENY: 4508 printf("policy: deny\n"); 4509 break; 4510 case IEEE80211_MACCMD_POLICY_RADIUS: 4511 printf("policy: radius\n"); 4512 break; 4513 default: 4514 printf("policy: unknown (%u)\n", policy); 4515 break; 4516 } 4517 } 4518 4519 static void 4520 list_mac(if_ctx *ctx) 4521 { 4522 struct ieee80211req ireq = {}; 4523 struct ieee80211req_maclist *acllist; 4524 int i, nacls, policy, len; 4525 uint8_t *data; 4526 char c; 4527 4528 strlcpy(ireq.i_name, ctx->ifname, sizeof(ireq.i_name)); /* XXX ?? */ 4529 ireq.i_type = IEEE80211_IOC_MACCMD; 4530 ireq.i_val = IEEE80211_MACCMD_POLICY; 4531 if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) { 4532 if (errno == EINVAL) { 4533 printf("No acl policy loaded\n"); 4534 return; 4535 } 4536 err(1, "unable to get mac policy"); 4537 } 4538 policy = ireq.i_val; 4539 if (policy == IEEE80211_MACCMD_POLICY_OPEN) { 4540 c = '*'; 4541 } else if (policy == IEEE80211_MACCMD_POLICY_ALLOW) { 4542 c = '+'; 4543 } else if (policy == IEEE80211_MACCMD_POLICY_DENY) { 4544 c = '-'; 4545 } else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) { 4546 c = 'r'; /* NB: should never have entries */ 4547 } else { 4548 printf("policy: unknown (%u)\n", policy); 4549 c = '?'; 4550 } 4551 if (ctx->args->verbose || c == '?') 4552 printpolicy(policy); 4553 4554 ireq.i_val = IEEE80211_MACCMD_LIST; 4555 ireq.i_len = 0; 4556 if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) 4557 err(1, "unable to get mac acl list size"); 4558 if (ireq.i_len == 0) { /* NB: no acls */ 4559 if (!(ctx->args->verbose || c == '?')) 4560 printpolicy(policy); 4561 return; 4562 } 4563 len = ireq.i_len; 4564 4565 data = malloc(len); 4566 if (data == NULL) 4567 err(1, "out of memory for acl list"); 4568 4569 ireq.i_data = data; 4570 if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) 4571 err(1, "unable to get mac acl list"); 4572 nacls = len / sizeof(*acllist); 4573 acllist = (struct ieee80211req_maclist *) data; 4574 for (i = 0; i < nacls; i++) 4575 printf("%c%s\n", c, ether_ntoa( 4576 (const struct ether_addr *) acllist[i].ml_macaddr)); 4577 free(data); 4578 } 4579 4580 static void 4581 print_regdomain(const struct ieee80211_regdomain *reg, int verb) 4582 { 4583 if ((reg->regdomain != 0 && 4584 reg->regdomain != reg->country) || verb) { 4585 const struct regdomain *rd = 4586 lib80211_regdomain_findbysku(getregdata(), reg->regdomain); 4587 if (rd == NULL) 4588 LINE_CHECK("regdomain %d", reg->regdomain); 4589 else 4590 LINE_CHECK("regdomain %s", rd->name); 4591 } 4592 if (reg->country != 0 || verb) { 4593 const struct country *cc = 4594 lib80211_country_findbycc(getregdata(), reg->country); 4595 if (cc == NULL) 4596 LINE_CHECK("country %d", reg->country); 4597 else 4598 LINE_CHECK("country %s", cc->isoname); 4599 } 4600 if (reg->location == 'I') 4601 LINE_CHECK("indoor"); 4602 else if (reg->location == 'O') 4603 LINE_CHECK("outdoor"); 4604 else if (verb) 4605 LINE_CHECK("anywhere"); 4606 if (reg->ecm) 4607 LINE_CHECK("ecm"); 4608 else if (verb) 4609 LINE_CHECK("-ecm"); 4610 } 4611 4612 static void 4613 list_regdomain(if_ctx *ctx, int channelsalso) 4614 { 4615 getregdomain(ctx); 4616 if (channelsalso) { 4617 getchaninfo(ctx); 4618 spacer = ':'; 4619 print_regdomain(®domain, 1); 4620 LINE_BREAK(); 4621 print_channels(ctx, chaninfo, 1/*allchans*/, 1/*verbose*/); 4622 } else 4623 print_regdomain(®domain, ctx->args->verbose); 4624 } 4625 4626 static void 4627 list_mesh(if_ctx *ctx) 4628 { 4629 struct ieee80211req ireq = {}; 4630 struct ieee80211req_mesh_route routes[128]; 4631 struct ieee80211req_mesh_route *rt; 4632 4633 strlcpy(ireq.i_name, ctx->ifname, sizeof(ireq.i_name)); 4634 ireq.i_type = IEEE80211_IOC_MESH_RTCMD; 4635 ireq.i_val = IEEE80211_MESH_RTCMD_LIST; 4636 ireq.i_data = &routes; 4637 ireq.i_len = sizeof(routes); 4638 if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) 4639 err(1, "unable to get the Mesh routing table"); 4640 4641 printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n" 4642 , "DEST" 4643 , "NEXT HOP" 4644 , "HOPS" 4645 , "METRIC" 4646 , "LIFETIME" 4647 , "MSEQ" 4648 , "FLAGS"); 4649 4650 for (unsigned int i = 0; i < ireq.i_len / sizeof(*rt); i++) { 4651 rt = &routes[i]; 4652 printf("%s ", 4653 ether_ntoa((const struct ether_addr *)rt->imr_dest)); 4654 printf("%s %4u %4u %6u %6u %c%c\n", 4655 ether_ntoa((const struct ether_addr *)rt->imr_nexthop), 4656 rt->imr_nhops, rt->imr_metric, rt->imr_lifetime, 4657 rt->imr_lastmseq, 4658 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_DISCOVER) ? 4659 'D' : 4660 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_VALID) ? 4661 'V' : '!', 4662 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ? 4663 'P' : 4664 (rt->imr_flags & IEEE80211_MESHRT_FLAGS_GATE) ? 4665 'G' :' '); 4666 } 4667 } 4668 4669 static void 4670 set80211list(if_ctx *ctx, const char *arg, int dummy __unused) 4671 { 4672 int s = ctx->io_s; 4673 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0) 4674 4675 LINE_INIT('\t'); 4676 4677 if (iseq(arg, "sta")) 4678 list_stations(ctx); 4679 else if (iseq(arg, "scan") || iseq(arg, "ap")) 4680 list_scan(ctx); 4681 else if (iseq(arg, "chan") || iseq(arg, "freq")) 4682 list_channels(ctx, 1); 4683 else if (iseq(arg, "active")) 4684 list_channels(ctx, 0); 4685 else if (iseq(arg, "keys")) 4686 list_keys(s); 4687 else if (iseq(arg, "caps")) 4688 list_capabilities(ctx); 4689 else if (iseq(arg, "wme") || iseq(arg, "wmm")) 4690 list_wme(ctx); 4691 else if (iseq(arg, "mac")) 4692 list_mac(ctx); 4693 else if (iseq(arg, "txpow")) 4694 list_txpow(ctx); 4695 else if (iseq(arg, "roam")) 4696 list_roam(ctx); 4697 else if (iseq(arg, "txparam") || iseq(arg, "txparm")) 4698 list_txparams(ctx); 4699 else if (iseq(arg, "regdomain")) 4700 list_regdomain(ctx, 1); 4701 else if (iseq(arg, "countries")) 4702 list_countries(); 4703 else if (iseq(arg, "mesh")) 4704 list_mesh(ctx); 4705 else 4706 errx(1, "Don't know how to list %s for %s", arg, ctx->ifname); 4707 LINE_BREAK(); 4708 #undef iseq 4709 } 4710 4711 static enum ieee80211_opmode 4712 get80211opmode(if_ctx *ctx) 4713 { 4714 struct ifmediareq ifmr = {}; 4715 4716 strlcpy(ifmr.ifm_name, ctx->ifname, sizeof(ifmr.ifm_name)); 4717 4718 if (ioctl_ctx(ctx, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) { 4719 if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) { 4720 if (ifmr.ifm_current & IFM_FLAG0) 4721 return IEEE80211_M_AHDEMO; 4722 else 4723 return IEEE80211_M_IBSS; 4724 } 4725 if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP) 4726 return IEEE80211_M_HOSTAP; 4727 if (ifmr.ifm_current & IFM_IEEE80211_IBSS) 4728 return IEEE80211_M_IBSS; 4729 if (ifmr.ifm_current & IFM_IEEE80211_MONITOR) 4730 return IEEE80211_M_MONITOR; 4731 if (ifmr.ifm_current & IFM_IEEE80211_MBSS) 4732 return IEEE80211_M_MBSS; 4733 } 4734 return IEEE80211_M_STA; 4735 } 4736 4737 #if 0 4738 static void 4739 printcipher(int s, struct ieee80211req *ireq, int keylenop) 4740 { 4741 switch (ireq->i_val) { 4742 case IEEE80211_CIPHER_WEP: 4743 ireq->i_type = keylenop; 4744 if (ioctl(s, SIOCG80211, ireq) != -1) 4745 printf("WEP-%s", 4746 ireq->i_len <= 5 ? "40" : 4747 ireq->i_len <= 13 ? "104" : "128"); 4748 else 4749 printf("WEP"); 4750 break; 4751 case IEEE80211_CIPHER_TKIP: 4752 printf("TKIP"); 4753 break; 4754 case IEEE80211_CIPHER_AES_OCB: 4755 printf("AES-OCB"); 4756 break; 4757 case IEEE80211_CIPHER_AES_CCM: 4758 printf("AES-CCM"); 4759 break; 4760 case IEEE80211_CIPHER_CKIP: 4761 printf("CKIP"); 4762 break; 4763 case IEEE80211_CIPHER_NONE: 4764 printf("NONE"); 4765 break; 4766 default: 4767 printf("UNKNOWN (0x%x)", ireq->i_val); 4768 break; 4769 } 4770 } 4771 #endif 4772 4773 static void 4774 printkey(if_ctx *ctx, const struct ieee80211req_key *ik) 4775 { 4776 static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE]; 4777 u_int keylen = ik->ik_keylen; 4778 int printcontents; 4779 const int verbose = ctx->args->verbose; 4780 const bool printkeys = ctx->args->printkeys; 4781 4782 printcontents = printkeys && 4783 (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose); 4784 if (printcontents) 4785 LINE_BREAK(); 4786 switch (ik->ik_type) { 4787 case IEEE80211_CIPHER_WEP: 4788 /* compatibility */ 4789 LINE_CHECK("wepkey %u:%s", ik->ik_keyix+1, 4790 keylen <= 5 ? "40-bit" : 4791 keylen <= 13 ? "104-bit" : "128-bit"); 4792 break; 4793 case IEEE80211_CIPHER_TKIP: 4794 if (keylen > 128/8) 4795 keylen -= 128/8; /* ignore MIC for now */ 4796 LINE_CHECK("TKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4797 break; 4798 case IEEE80211_CIPHER_AES_OCB: 4799 LINE_CHECK("AES-OCB %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4800 break; 4801 case IEEE80211_CIPHER_AES_CCM: 4802 LINE_CHECK("AES-CCM %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4803 break; 4804 case IEEE80211_CIPHER_CKIP: 4805 LINE_CHECK("CKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4806 break; 4807 case IEEE80211_CIPHER_NONE: 4808 LINE_CHECK("NULL %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4809 break; 4810 default: 4811 LINE_CHECK("UNKNOWN (0x%x) %u:%u-bit", 4812 ik->ik_type, ik->ik_keyix+1, 8*keylen); 4813 break; 4814 } 4815 if (printcontents) { 4816 u_int i; 4817 4818 printf(" <"); 4819 for (i = 0; i < keylen; i++) 4820 printf("%02x", ik->ik_keydata[i]); 4821 printf(">"); 4822 if (ik->ik_type != IEEE80211_CIPHER_WEP && 4823 (ik->ik_keyrsc != 0 || verbose)) 4824 printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc); 4825 if (ik->ik_type != IEEE80211_CIPHER_WEP && 4826 (ik->ik_keytsc != 0 || verbose)) 4827 printf(" tsc %ju", (uintmax_t)ik->ik_keytsc); 4828 if (ik->ik_flags != 0 && verbose) { 4829 const char *sep = " "; 4830 4831 if (ik->ik_flags & IEEE80211_KEY_XMIT) 4832 printf("%stx", sep), sep = "+"; 4833 if (ik->ik_flags & IEEE80211_KEY_RECV) 4834 printf("%srx", sep), sep = "+"; 4835 if (ik->ik_flags & IEEE80211_KEY_DEFAULT) 4836 printf("%sdef", sep), sep = "+"; 4837 } 4838 LINE_BREAK(); 4839 } 4840 } 4841 4842 static void 4843 printrate(const char *tag, int v, int defrate, int defmcs) 4844 { 4845 if ((v & IEEE80211_RATE_MCS) == 0) { 4846 if (v != defrate) { 4847 if (v & 1) 4848 LINE_CHECK("%s %d.5", tag, v/2); 4849 else 4850 LINE_CHECK("%s %d", tag, v/2); 4851 } 4852 } else { 4853 if (v != defmcs) 4854 LINE_CHECK("%s %d", tag, v &~ 0x80); 4855 } 4856 } 4857 4858 static int 4859 getid(if_ctx *ctx, int ix, void *data, size_t len, int *plen, int mesh) 4860 { 4861 struct ieee80211req ireq = {}; 4862 4863 strlcpy(ireq.i_name, ctx->ifname, sizeof(ireq.i_name)); 4864 ireq.i_type = (!mesh) ? IEEE80211_IOC_SSID : IEEE80211_IOC_MESH_ID; 4865 ireq.i_val = ix; 4866 ireq.i_data = data; 4867 ireq.i_len = len; 4868 if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) 4869 return -1; 4870 *plen = ireq.i_len; 4871 return 0; 4872 } 4873 4874 static int 4875 getdevicename(if_ctx *ctx, void *data, size_t len, int *plen) 4876 { 4877 struct ieee80211req ireq = {}; 4878 4879 strlcpy(ireq.i_name, ctx->ifname, sizeof(ireq.i_name)); 4880 ireq.i_type = IEEE80211_IOC_IC_NAME; 4881 ireq.i_val = -1; 4882 ireq.i_data = data; 4883 ireq.i_len = len; 4884 if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) 4885 return (-1); 4886 *plen = ireq.i_len; 4887 return (0); 4888 } 4889 4890 static void 4891 ieee80211_status(if_ctx *ctx) 4892 { 4893 int s = ctx->io_s; 4894 static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; 4895 enum ieee80211_opmode opmode = get80211opmode(ctx); 4896 int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode; 4897 uint8_t data[32]; 4898 const struct ieee80211_channel *c; 4899 const struct ieee80211_roamparam *rp; 4900 const struct ieee80211_txparam *tp; 4901 const int verbose = ctx->args->verbose; 4902 4903 if (getid(ctx, -1, data, sizeof(data), &len, 0) < 0) { 4904 /* If we can't get the SSID, this isn't an 802.11 device. */ 4905 return; 4906 } 4907 4908 /* 4909 * Invalidate cached state so printing status for multiple 4910 * if's doesn't reuse the first interfaces' cached state. 4911 */ 4912 gotcurchan = 0; 4913 gotroam = 0; 4914 gottxparams = 0; 4915 gothtconf = 0; 4916 gotregdomain = 0; 4917 4918 printf("\t"); 4919 if (opmode == IEEE80211_M_MBSS) { 4920 printf("meshid "); 4921 getid(ctx, 0, data, sizeof(data), &len, 1); 4922 print_string(data, len); 4923 } else { 4924 if (get80211val(ctx, IEEE80211_IOC_NUMSSIDS, &num) < 0) 4925 num = 0; 4926 printf("ssid "); 4927 if (num > 1) { 4928 for (i = 0; i < num; i++) { 4929 if (getid(ctx, i, data, sizeof(data), &len, 0) >= 0 && len > 0) { 4930 printf(" %d:", i + 1); 4931 print_string(data, len); 4932 } 4933 } 4934 } else 4935 print_string(data, len); 4936 } 4937 c = getcurchan(ctx); 4938 if (c->ic_freq != IEEE80211_CHAN_ANY) { 4939 char buf[14]; 4940 printf(" channel %d (%u MHz%s)", c->ic_ieee, c->ic_freq, 4941 get_chaninfo(c, 1, buf, sizeof(buf))); 4942 } else if (verbose) 4943 printf(" channel UNDEF"); 4944 4945 if (get80211(ctx, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 && 4946 (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose)) { 4947 printf(" bssid %s", ether_ntoa((struct ether_addr *)data)); 4948 printbssidname((struct ether_addr *)data); 4949 } 4950 4951 if (get80211len(ctx, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) { 4952 printf("\n\tstationname "); 4953 print_string(data, len); 4954 } 4955 4956 spacer = ' '; /* force first break */ 4957 LINE_BREAK(); 4958 4959 list_regdomain(ctx, 0); 4960 4961 wpa = 0; 4962 if (get80211val(ctx, IEEE80211_IOC_AUTHMODE, &val) != -1) { 4963 switch (val) { 4964 case IEEE80211_AUTH_NONE: 4965 LINE_CHECK("authmode NONE"); 4966 break; 4967 case IEEE80211_AUTH_OPEN: 4968 LINE_CHECK("authmode OPEN"); 4969 break; 4970 case IEEE80211_AUTH_SHARED: 4971 LINE_CHECK("authmode SHARED"); 4972 break; 4973 case IEEE80211_AUTH_8021X: 4974 LINE_CHECK("authmode 802.1x"); 4975 break; 4976 case IEEE80211_AUTH_WPA: 4977 if (get80211val(ctx, IEEE80211_IOC_WPA, &wpa) < 0) 4978 wpa = 1; /* default to WPA1 */ 4979 switch (wpa) { 4980 case 2: 4981 LINE_CHECK("authmode WPA2/802.11i"); 4982 break; 4983 case 3: 4984 LINE_CHECK("authmode WPA1+WPA2/802.11i"); 4985 break; 4986 default: 4987 LINE_CHECK("authmode WPA"); 4988 break; 4989 } 4990 break; 4991 case IEEE80211_AUTH_AUTO: 4992 LINE_CHECK("authmode AUTO"); 4993 break; 4994 default: 4995 LINE_CHECK("authmode UNKNOWN (0x%x)", val); 4996 break; 4997 } 4998 } 4999 5000 if (wpa || verbose) { 5001 if (get80211val(ctx, IEEE80211_IOC_WPS, &val) != -1) { 5002 if (val) 5003 LINE_CHECK("wps"); 5004 else if (verbose) 5005 LINE_CHECK("-wps"); 5006 } 5007 if (get80211val(ctx, IEEE80211_IOC_TSN, &val) != -1) { 5008 if (val) 5009 LINE_CHECK("tsn"); 5010 else if (verbose) 5011 LINE_CHECK("-tsn"); 5012 } 5013 if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) { 5014 if (val) 5015 LINE_CHECK("countermeasures"); 5016 else if (verbose) 5017 LINE_CHECK("-countermeasures"); 5018 } 5019 #if 0 5020 /* XXX not interesting with WPA done in user space */ 5021 ireq.i_type = IEEE80211_IOC_KEYMGTALGS; 5022 if (ioctl(s, SIOCG80211, &ireq) != -1) { 5023 } 5024 5025 ireq.i_type = IEEE80211_IOC_MCASTCIPHER; 5026 if (ioctl(s, SIOCG80211, &ireq) != -1) { 5027 LINE_CHECK("mcastcipher "); 5028 printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN); 5029 spacer = ' '; 5030 } 5031 5032 ireq.i_type = IEEE80211_IOC_UCASTCIPHER; 5033 if (ioctl(s, SIOCG80211, &ireq) != -1) { 5034 LINE_CHECK("ucastcipher "); 5035 printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN); 5036 } 5037 5038 if (wpa & 2) { 5039 ireq.i_type = IEEE80211_IOC_RSNCAPS; 5040 if (ioctl(s, SIOCG80211, &ireq) != -1) { 5041 LINE_CHECK("RSN caps 0x%x", ireq.i_val); 5042 spacer = ' '; 5043 } 5044 } 5045 5046 ireq.i_type = IEEE80211_IOC_UCASTCIPHERS; 5047 if (ioctl(s, SIOCG80211, &ireq) != -1) { 5048 } 5049 #endif 5050 } 5051 5052 if (get80211val(ctx, IEEE80211_IOC_WEP, &wepmode) != -1 && 5053 wepmode != IEEE80211_WEP_NOSUP) { 5054 5055 switch (wepmode) { 5056 case IEEE80211_WEP_OFF: 5057 LINE_CHECK("privacy OFF"); 5058 break; 5059 case IEEE80211_WEP_ON: 5060 LINE_CHECK("privacy ON"); 5061 break; 5062 case IEEE80211_WEP_MIXED: 5063 LINE_CHECK("privacy MIXED"); 5064 break; 5065 default: 5066 LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode); 5067 break; 5068 } 5069 5070 /* 5071 * If we get here then we've got WEP support so we need 5072 * to print WEP status. 5073 */ 5074 5075 if (get80211val(ctx, IEEE80211_IOC_WEPTXKEY, &val) < 0) { 5076 warn("WEP support, but no tx key!"); 5077 goto end; 5078 } 5079 if (val != -1) 5080 LINE_CHECK("deftxkey %d", val+1); 5081 else if (wepmode != IEEE80211_WEP_OFF || verbose) 5082 LINE_CHECK("deftxkey UNDEF"); 5083 5084 if (get80211val(ctx, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) { 5085 warn("WEP support, but no NUMWEPKEYS support!"); 5086 goto end; 5087 } 5088 5089 for (i = 0; i < num; i++) { 5090 struct ieee80211req_key ik; 5091 5092 memset(&ik, 0, sizeof(ik)); 5093 ik.ik_keyix = i; 5094 if (get80211(ctx, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) { 5095 warn("WEP support, but cannot get keys!"); 5096 goto end; 5097 } 5098 if (ik.ik_keylen != 0) { 5099 if (verbose) 5100 LINE_BREAK(); 5101 printkey(ctx, &ik); 5102 } 5103 } 5104 if (i > 0 && verbose) 5105 LINE_BREAK(); 5106 end: 5107 ; 5108 } 5109 5110 if (get80211val(ctx, IEEE80211_IOC_POWERSAVE, &val) != -1 && 5111 val != IEEE80211_POWERSAVE_NOSUP ) { 5112 if (val != IEEE80211_POWERSAVE_OFF || verbose) { 5113 switch (val) { 5114 case IEEE80211_POWERSAVE_OFF: 5115 LINE_CHECK("powersavemode OFF"); 5116 break; 5117 case IEEE80211_POWERSAVE_CAM: 5118 LINE_CHECK("powersavemode CAM"); 5119 break; 5120 case IEEE80211_POWERSAVE_PSP: 5121 LINE_CHECK("powersavemode PSP"); 5122 break; 5123 case IEEE80211_POWERSAVE_PSP_CAM: 5124 LINE_CHECK("powersavemode PSP-CAM"); 5125 break; 5126 } 5127 if (get80211val(ctx, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1) 5128 LINE_CHECK("powersavesleep %d", val); 5129 } 5130 } 5131 5132 if (get80211val(ctx, IEEE80211_IOC_TXPOWER, &val) != -1) { 5133 if (val & 1) 5134 LINE_CHECK("txpower %d.5", val/2); 5135 else 5136 LINE_CHECK("txpower %d", val/2); 5137 } 5138 if (verbose) { 5139 if (get80211val(ctx, IEEE80211_IOC_TXPOWMAX, &val) != -1) 5140 LINE_CHECK("txpowmax %.1f", val/2.); 5141 } 5142 5143 if (get80211val(ctx, IEEE80211_IOC_DOTD, &val) != -1) { 5144 if (val) 5145 LINE_CHECK("dotd"); 5146 else if (verbose) 5147 LINE_CHECK("-dotd"); 5148 } 5149 5150 if (get80211val(ctx, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) { 5151 if (val != IEEE80211_RTS_MAX || verbose) 5152 LINE_CHECK("rtsthreshold %d", val); 5153 } 5154 5155 if (get80211val(ctx, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) { 5156 if (val != IEEE80211_FRAG_MAX || verbose) 5157 LINE_CHECK("fragthreshold %d", val); 5158 } 5159 if (opmode == IEEE80211_M_STA || verbose) { 5160 if (get80211val(ctx, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) { 5161 if (val != IEEE80211_HWBMISS_MAX || verbose) 5162 LINE_CHECK("bmiss %d", val); 5163 } 5164 } 5165 5166 if (!verbose) { 5167 gettxparams(ctx); 5168 tp = &txparams.params[chan2mode(c)]; 5169 printrate("ucastrate", tp->ucastrate, 5170 IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE); 5171 printrate("mcastrate", tp->mcastrate, 2*1, 5172 IEEE80211_RATE_MCS|0); 5173 printrate("mgmtrate", tp->mgmtrate, 2*1, 5174 IEEE80211_RATE_MCS|0); 5175 if (tp->maxretry != 6) /* XXX */ 5176 LINE_CHECK("maxretry %d", tp->maxretry); 5177 } else { 5178 LINE_BREAK(); 5179 list_txparams(ctx); 5180 } 5181 5182 bgscaninterval = -1; 5183 (void) get80211val(ctx, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval); 5184 5185 if (get80211val(ctx, IEEE80211_IOC_SCANVALID, &val) != -1) { 5186 if (val != bgscaninterval || verbose) 5187 LINE_CHECK("scanvalid %u", val); 5188 } 5189 5190 bgscan = 0; 5191 if (get80211val(ctx, IEEE80211_IOC_BGSCAN, &bgscan) != -1) { 5192 if (bgscan) 5193 LINE_CHECK("bgscan"); 5194 else if (verbose) 5195 LINE_CHECK("-bgscan"); 5196 } 5197 if (bgscan || verbose) { 5198 if (bgscaninterval != -1) 5199 LINE_CHECK("bgscanintvl %u", bgscaninterval); 5200 if (get80211val(ctx, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1) 5201 LINE_CHECK("bgscanidle %u", val); 5202 if (!verbose) { 5203 getroam(ctx); 5204 rp = &roamparams.params[chan2mode(c)]; 5205 if (rp->rssi & 1) 5206 LINE_CHECK("roam:rssi %u.5", rp->rssi/2); 5207 else 5208 LINE_CHECK("roam:rssi %u", rp->rssi/2); 5209 LINE_CHECK("roam:rate %s%u", 5210 (rp->rate & IEEE80211_RATE_MCS) ? "MCS " : "", 5211 get_rate_value(rp->rate)); 5212 } else { 5213 LINE_BREAK(); 5214 list_roam(ctx); 5215 LINE_BREAK(); 5216 } 5217 } 5218 5219 if (IEEE80211_IS_CHAN_ANYG(c) || verbose) { 5220 if (get80211val(ctx, IEEE80211_IOC_PUREG, &val) != -1) { 5221 if (val) 5222 LINE_CHECK("pureg"); 5223 else if (verbose) 5224 LINE_CHECK("-pureg"); 5225 } 5226 if (get80211val(ctx, IEEE80211_IOC_PROTMODE, &val) != -1) { 5227 switch (val) { 5228 case IEEE80211_PROTMODE_OFF: 5229 LINE_CHECK("protmode OFF"); 5230 break; 5231 case IEEE80211_PROTMODE_CTS: 5232 LINE_CHECK("protmode CTS"); 5233 break; 5234 case IEEE80211_PROTMODE_RTSCTS: 5235 LINE_CHECK("protmode RTSCTS"); 5236 break; 5237 default: 5238 LINE_CHECK("protmode UNKNOWN (0x%x)", val); 5239 break; 5240 } 5241 } 5242 } 5243 5244 if (IEEE80211_IS_CHAN_HT(c) || verbose) { 5245 gethtconf(ctx); 5246 switch (htconf & 3) { 5247 case 0: 5248 case 2: 5249 LINE_CHECK("-ht"); 5250 break; 5251 case 1: 5252 LINE_CHECK("ht20"); 5253 break; 5254 case 3: 5255 if (verbose) 5256 LINE_CHECK("ht"); 5257 break; 5258 } 5259 if (get80211val(ctx, IEEE80211_IOC_HTCOMPAT, &val) != -1) { 5260 if (!val) 5261 LINE_CHECK("-htcompat"); 5262 else if (verbose) 5263 LINE_CHECK("htcompat"); 5264 } 5265 if (get80211val(ctx, IEEE80211_IOC_AMPDU, &val) != -1) { 5266 switch (val) { 5267 case 0: 5268 LINE_CHECK("-ampdu"); 5269 break; 5270 case 1: 5271 LINE_CHECK("ampdutx -ampdurx"); 5272 break; 5273 case 2: 5274 LINE_CHECK("-ampdutx ampdurx"); 5275 break; 5276 case 3: 5277 if (verbose) 5278 LINE_CHECK("ampdu"); 5279 break; 5280 } 5281 } 5282 /* XXX 11ac density/size is different */ 5283 if (get80211val(ctx, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) { 5284 switch (val) { 5285 case IEEE80211_HTCAP_MAXRXAMPDU_8K: 5286 LINE_CHECK("ampdulimit 8k"); 5287 break; 5288 case IEEE80211_HTCAP_MAXRXAMPDU_16K: 5289 LINE_CHECK("ampdulimit 16k"); 5290 break; 5291 case IEEE80211_HTCAP_MAXRXAMPDU_32K: 5292 LINE_CHECK("ampdulimit 32k"); 5293 break; 5294 case IEEE80211_HTCAP_MAXRXAMPDU_64K: 5295 LINE_CHECK("ampdulimit 64k"); 5296 break; 5297 } 5298 } 5299 /* XXX 11ac density/size is different */ 5300 if (get80211val(ctx, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) { 5301 switch (val) { 5302 case IEEE80211_HTCAP_MPDUDENSITY_NA: 5303 if (verbose) 5304 LINE_CHECK("ampdudensity NA"); 5305 break; 5306 case IEEE80211_HTCAP_MPDUDENSITY_025: 5307 LINE_CHECK("ampdudensity .25"); 5308 break; 5309 case IEEE80211_HTCAP_MPDUDENSITY_05: 5310 LINE_CHECK("ampdudensity .5"); 5311 break; 5312 case IEEE80211_HTCAP_MPDUDENSITY_1: 5313 LINE_CHECK("ampdudensity 1"); 5314 break; 5315 case IEEE80211_HTCAP_MPDUDENSITY_2: 5316 LINE_CHECK("ampdudensity 2"); 5317 break; 5318 case IEEE80211_HTCAP_MPDUDENSITY_4: 5319 LINE_CHECK("ampdudensity 4"); 5320 break; 5321 case IEEE80211_HTCAP_MPDUDENSITY_8: 5322 LINE_CHECK("ampdudensity 8"); 5323 break; 5324 case IEEE80211_HTCAP_MPDUDENSITY_16: 5325 LINE_CHECK("ampdudensity 16"); 5326 break; 5327 } 5328 } 5329 if (get80211val(ctx, IEEE80211_IOC_AMSDU, &val) != -1) { 5330 switch (val) { 5331 case 0: 5332 LINE_CHECK("-amsdu"); 5333 break; 5334 case 1: 5335 LINE_CHECK("amsdutx -amsdurx"); 5336 break; 5337 case 2: 5338 LINE_CHECK("-amsdutx amsdurx"); 5339 break; 5340 case 3: 5341 if (verbose) 5342 LINE_CHECK("amsdu"); 5343 break; 5344 } 5345 } 5346 /* XXX amsdu limit */ 5347 if (get80211val(ctx, IEEE80211_IOC_SHORTGI, &val) != -1) { 5348 if (val) 5349 LINE_CHECK("shortgi"); 5350 else if (verbose) 5351 LINE_CHECK("-shortgi"); 5352 } 5353 if (get80211val(ctx, IEEE80211_IOC_HTPROTMODE, &val) != -1) { 5354 if (val == IEEE80211_PROTMODE_OFF) 5355 LINE_CHECK("htprotmode OFF"); 5356 else if (val != IEEE80211_PROTMODE_RTSCTS) 5357 LINE_CHECK("htprotmode UNKNOWN (0x%x)", val); 5358 else if (verbose) 5359 LINE_CHECK("htprotmode RTSCTS"); 5360 } 5361 if (get80211val(ctx, IEEE80211_IOC_PUREN, &val) != -1) { 5362 if (val) 5363 LINE_CHECK("puren"); 5364 else if (verbose) 5365 LINE_CHECK("-puren"); 5366 } 5367 if (get80211val(ctx, IEEE80211_IOC_SMPS, &val) != -1) { 5368 if (val == IEEE80211_HTCAP_SMPS_DYNAMIC) 5369 LINE_CHECK("smpsdyn"); 5370 else if (val == IEEE80211_HTCAP_SMPS_ENA) 5371 LINE_CHECK("smps"); 5372 else if (verbose) 5373 LINE_CHECK("-smps"); 5374 } 5375 if (get80211val(ctx, IEEE80211_IOC_RIFS, &val) != -1) { 5376 if (val) 5377 LINE_CHECK("rifs"); 5378 else if (verbose) 5379 LINE_CHECK("-rifs"); 5380 } 5381 5382 /* XXX VHT STBC? */ 5383 if (get80211val(ctx, IEEE80211_IOC_STBC, &val) != -1) { 5384 switch (val) { 5385 case 0: 5386 LINE_CHECK("-stbc"); 5387 break; 5388 case 1: 5389 LINE_CHECK("stbctx -stbcrx"); 5390 break; 5391 case 2: 5392 LINE_CHECK("-stbctx stbcrx"); 5393 break; 5394 case 3: 5395 if (verbose) 5396 LINE_CHECK("stbc"); 5397 break; 5398 } 5399 } 5400 if (get80211val(ctx, IEEE80211_IOC_LDPC, &val) != -1) { 5401 switch (val) { 5402 case 0: 5403 LINE_CHECK("-ldpc"); 5404 break; 5405 case 1: 5406 LINE_CHECK("ldpctx -ldpcrx"); 5407 break; 5408 case 2: 5409 LINE_CHECK("-ldpctx ldpcrx"); 5410 break; 5411 case 3: 5412 if (verbose) 5413 LINE_CHECK("ldpc"); 5414 break; 5415 } 5416 } 5417 if (get80211val(ctx, IEEE80211_IOC_UAPSD, &val) != -1) { 5418 switch (val) { 5419 case 0: 5420 LINE_CHECK("-uapsd"); 5421 break; 5422 case 1: 5423 LINE_CHECK("uapsd"); 5424 break; 5425 } 5426 } 5427 } 5428 5429 if (IEEE80211_IS_CHAN_VHT(c) || verbose) { 5430 getvhtconf(ctx); 5431 if (vhtconf & IEEE80211_FVHT_VHT) { 5432 LINE_CHECK("vht"); 5433 5434 if (vhtconf & IEEE80211_FVHT_USEVHT40) 5435 LINE_CHECK("vht40"); 5436 else 5437 LINE_CHECK("-vht40"); 5438 if (vhtconf & IEEE80211_FVHT_USEVHT80) 5439 LINE_CHECK("vht80"); 5440 else 5441 LINE_CHECK("-vht80"); 5442 if (vhtconf & IEEE80211_FVHT_USEVHT160) 5443 LINE_CHECK("vht160"); 5444 else 5445 LINE_CHECK("-vht160"); 5446 if (vhtconf & IEEE80211_FVHT_USEVHT80P80) 5447 LINE_CHECK("vht80p80"); 5448 else 5449 LINE_CHECK("-vht80p80"); 5450 } else if (verbose) 5451 LINE_CHECK("-vht"); 5452 } 5453 5454 if (get80211val(ctx, IEEE80211_IOC_WME, &wme) != -1) { 5455 if (wme) 5456 LINE_CHECK("wme"); 5457 else if (verbose) 5458 LINE_CHECK("-wme"); 5459 } else 5460 wme = 0; 5461 5462 if (get80211val(ctx, IEEE80211_IOC_BURST, &val) != -1) { 5463 if (val) 5464 LINE_CHECK("burst"); 5465 else if (verbose) 5466 LINE_CHECK("-burst"); 5467 } 5468 5469 if (get80211val(ctx, IEEE80211_IOC_FF, &val) != -1) { 5470 if (val) 5471 LINE_CHECK("ff"); 5472 else if (verbose) 5473 LINE_CHECK("-ff"); 5474 } 5475 if (get80211val(ctx, IEEE80211_IOC_TURBOP, &val) != -1) { 5476 if (val) 5477 LINE_CHECK("dturbo"); 5478 else if (verbose) 5479 LINE_CHECK("-dturbo"); 5480 } 5481 if (get80211val(ctx, IEEE80211_IOC_DWDS, &val) != -1) { 5482 if (val) 5483 LINE_CHECK("dwds"); 5484 else if (verbose) 5485 LINE_CHECK("-dwds"); 5486 } 5487 5488 if (opmode == IEEE80211_M_HOSTAP) { 5489 if (get80211val(ctx, IEEE80211_IOC_HIDESSID, &val) != -1) { 5490 if (val) 5491 LINE_CHECK("hidessid"); 5492 else if (verbose) 5493 LINE_CHECK("-hidessid"); 5494 } 5495 if (get80211val(ctx, IEEE80211_IOC_APBRIDGE, &val) != -1) { 5496 if (!val) 5497 LINE_CHECK("-apbridge"); 5498 else if (verbose) 5499 LINE_CHECK("apbridge"); 5500 } 5501 if (get80211val(ctx, IEEE80211_IOC_DTIM_PERIOD, &val) != -1) 5502 LINE_CHECK("dtimperiod %u", val); 5503 5504 if (get80211val(ctx, IEEE80211_IOC_DOTH, &val) != -1) { 5505 if (!val) 5506 LINE_CHECK("-doth"); 5507 else if (verbose) 5508 LINE_CHECK("doth"); 5509 } 5510 if (get80211val(ctx, IEEE80211_IOC_DFS, &val) != -1) { 5511 if (!val) 5512 LINE_CHECK("-dfs"); 5513 else if (verbose) 5514 LINE_CHECK("dfs"); 5515 } 5516 if (get80211val(ctx, IEEE80211_IOC_INACTIVITY, &val) != -1) { 5517 if (!val) 5518 LINE_CHECK("-inact"); 5519 else if (verbose) 5520 LINE_CHECK("inact"); 5521 } 5522 } else { 5523 if (get80211val(ctx, IEEE80211_IOC_ROAMING, &val) != -1) { 5524 if (val != IEEE80211_ROAMING_AUTO || verbose) { 5525 switch (val) { 5526 case IEEE80211_ROAMING_DEVICE: 5527 LINE_CHECK("roaming DEVICE"); 5528 break; 5529 case IEEE80211_ROAMING_AUTO: 5530 LINE_CHECK("roaming AUTO"); 5531 break; 5532 case IEEE80211_ROAMING_MANUAL: 5533 LINE_CHECK("roaming MANUAL"); 5534 break; 5535 default: 5536 LINE_CHECK("roaming UNKNOWN (0x%x)", 5537 val); 5538 break; 5539 } 5540 } 5541 } 5542 } 5543 5544 if (opmode == IEEE80211_M_AHDEMO) { 5545 if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOT, &val) != -1) 5546 LINE_CHECK("tdmaslot %u", val); 5547 if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1) 5548 LINE_CHECK("tdmaslotcnt %u", val); 5549 if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1) 5550 LINE_CHECK("tdmaslotlen %u", val); 5551 if (get80211val(ctx, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1) 5552 LINE_CHECK("tdmabintval %u", val); 5553 } else if (get80211val(ctx, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) { 5554 /* XXX default define not visible */ 5555 if (val != 100 || verbose) 5556 LINE_CHECK("bintval %u", val); 5557 } 5558 5559 if (wme && verbose) { 5560 LINE_BREAK(); 5561 list_wme(ctx); 5562 } 5563 5564 if (opmode == IEEE80211_M_MBSS) { 5565 if (get80211val(ctx, IEEE80211_IOC_MESH_TTL, &val) != -1) { 5566 LINE_CHECK("meshttl %u", val); 5567 } 5568 if (get80211val(ctx, IEEE80211_IOC_MESH_AP, &val) != -1) { 5569 if (val) 5570 LINE_CHECK("meshpeering"); 5571 else 5572 LINE_CHECK("-meshpeering"); 5573 } 5574 if (get80211val(ctx, IEEE80211_IOC_MESH_FWRD, &val) != -1) { 5575 if (val) 5576 LINE_CHECK("meshforward"); 5577 else 5578 LINE_CHECK("-meshforward"); 5579 } 5580 if (get80211val(ctx, IEEE80211_IOC_MESH_GATE, &val) != -1) { 5581 if (val) 5582 LINE_CHECK("meshgate"); 5583 else 5584 LINE_CHECK("-meshgate"); 5585 } 5586 if (get80211len(ctx, IEEE80211_IOC_MESH_PR_METRIC, data, 12, 5587 &len) != -1) { 5588 data[len] = '\0'; 5589 LINE_CHECK("meshmetric %s", data); 5590 } 5591 if (get80211len(ctx, IEEE80211_IOC_MESH_PR_PATH, data, 12, 5592 &len) != -1) { 5593 data[len] = '\0'; 5594 LINE_CHECK("meshpath %s", data); 5595 } 5596 if (get80211val(ctx, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) { 5597 switch (val) { 5598 case IEEE80211_HWMP_ROOTMODE_DISABLED: 5599 LINE_CHECK("hwmprootmode DISABLED"); 5600 break; 5601 case IEEE80211_HWMP_ROOTMODE_NORMAL: 5602 LINE_CHECK("hwmprootmode NORMAL"); 5603 break; 5604 case IEEE80211_HWMP_ROOTMODE_PROACTIVE: 5605 LINE_CHECK("hwmprootmode PROACTIVE"); 5606 break; 5607 case IEEE80211_HWMP_ROOTMODE_RANN: 5608 LINE_CHECK("hwmprootmode RANN"); 5609 break; 5610 default: 5611 LINE_CHECK("hwmprootmode UNKNOWN(%d)", val); 5612 break; 5613 } 5614 } 5615 if (get80211val(ctx, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) { 5616 LINE_CHECK("hwmpmaxhops %u", val); 5617 } 5618 } 5619 5620 LINE_BREAK(); 5621 5622 if (getdevicename(ctx, data, sizeof(data), &len) < 0) 5623 return; 5624 LINE_CHECK("parent interface: %s", data); 5625 5626 LINE_BREAK(); 5627 } 5628 5629 static int 5630 get80211(if_ctx *ctx, int type, void *data, int len) 5631 { 5632 5633 return (lib80211_get80211(ctx->io_s, ctx->ifname, type, data, len)); 5634 } 5635 5636 static int 5637 get80211len(if_ctx *ctx, int type, void *data, int len, int *plen) 5638 { 5639 5640 return (lib80211_get80211len(ctx->io_s, ctx->ifname, type, data, len, plen)); 5641 } 5642 5643 static int 5644 get80211val(if_ctx *ctx, int type, int *val) 5645 { 5646 5647 return (lib80211_get80211val(ctx->io_s, ctx->ifname, type, val)); 5648 } 5649 5650 static void 5651 set80211(if_ctx *ctx, int type, int val, int len, void *data) 5652 { 5653 int ret; 5654 5655 ret = lib80211_set80211(ctx->io_s, ctx->ifname, type, val, len, data); 5656 if (ret < 0) 5657 err(1, "SIOCS80211"); 5658 } 5659 5660 static const char * 5661 get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp) 5662 { 5663 int len; 5664 int hexstr; 5665 u_int8_t *p; 5666 5667 len = *lenp; 5668 p = buf; 5669 hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x'); 5670 if (hexstr) 5671 val += 2; 5672 for (;;) { 5673 if (*val == '\0') 5674 break; 5675 if (sep != NULL && strchr(sep, *val) != NULL) { 5676 val++; 5677 break; 5678 } 5679 if (hexstr) { 5680 if (!isxdigit((u_char)val[0])) { 5681 warnx("bad hexadecimal digits"); 5682 return NULL; 5683 } 5684 if (!isxdigit((u_char)val[1])) { 5685 warnx("odd count hexadecimal digits"); 5686 return NULL; 5687 } 5688 } 5689 if (p >= buf + len) { 5690 if (hexstr) 5691 warnx("hexadecimal digits too long"); 5692 else 5693 warnx("string too long"); 5694 return NULL; 5695 } 5696 if (hexstr) { 5697 #define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10) 5698 *p++ = (tohex((u_char)val[0]) << 4) | 5699 tohex((u_char)val[1]); 5700 #undef tohex 5701 val += 2; 5702 } else 5703 *p++ = *val++; 5704 } 5705 len = p - buf; 5706 /* The string "-" is treated as the empty string. */ 5707 if (!hexstr && len == 1 && buf[0] == '-') { 5708 len = 0; 5709 memset(buf, 0, *lenp); 5710 } else if (len < *lenp) 5711 memset(p, 0, *lenp - len); 5712 *lenp = len; 5713 return val; 5714 } 5715 5716 static void 5717 print_string(const u_int8_t *buf, int len) 5718 { 5719 int i; 5720 int hasspc; 5721 int utf8; 5722 5723 i = 0; 5724 hasspc = 0; 5725 5726 setlocale(LC_CTYPE, ""); 5727 utf8 = strncmp("UTF-8", nl_langinfo(CODESET), 5) == 0; 5728 5729 for (; i < len; i++) { 5730 if (!isprint(buf[i]) && buf[i] != '\0' && !utf8) 5731 break; 5732 if (isspace(buf[i])) 5733 hasspc++; 5734 } 5735 if (i == len || utf8) { 5736 if (hasspc || len == 0 || buf[0] == '\0') 5737 printf("\"%.*s\"", len, buf); 5738 else 5739 printf("%.*s", len, buf); 5740 } else { 5741 printf("0x"); 5742 for (i = 0; i < len; i++) 5743 printf("%02x", buf[i]); 5744 } 5745 } 5746 5747 static void 5748 setdefregdomain(if_ctx *ctx) 5749 { 5750 struct regdata *rdp = getregdata(); 5751 const struct regdomain *rd; 5752 5753 /* Check if regdomain/country was already set by a previous call. */ 5754 /* XXX is it possible? */ 5755 if (regdomain.regdomain != 0 || 5756 regdomain.country != CTRY_DEFAULT) 5757 return; 5758 5759 getregdomain(ctx); 5760 5761 /* Check if it was already set by the driver. */ 5762 if (regdomain.regdomain != 0 || 5763 regdomain.country != CTRY_DEFAULT) 5764 return; 5765 5766 /* Set FCC/US as default. */ 5767 rd = lib80211_regdomain_findbysku(rdp, SKU_FCC); 5768 if (rd == NULL) 5769 errx(1, "FCC regdomain was not found"); 5770 5771 regdomain.regdomain = rd->sku; 5772 if (rd->cc != NULL) 5773 defaultcountry(rd); 5774 5775 /* Send changes to net80211. */ 5776 setregdomain_cb(ctx, ®domain); 5777 5778 /* Cleanup (so it can be overridden by subsequent parameters). */ 5779 regdomain.regdomain = 0; 5780 regdomain.country = CTRY_DEFAULT; 5781 regdomain.isocc[0] = 0; 5782 regdomain.isocc[1] = 0; 5783 } 5784 5785 /* 5786 * Virtual AP cloning support. 5787 */ 5788 static struct ieee80211_clone_params params = { 5789 .icp_opmode = IEEE80211_M_STA, /* default to station mode */ 5790 }; 5791 5792 static void 5793 wlan_create(if_ctx *ctx, struct ifreq *ifr) 5794 { 5795 static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; 5796 5797 if (params.icp_parent[0] == '\0') 5798 errx(1, "must specify a parent device (wlandev) when creating " 5799 "a wlan device"); 5800 if (params.icp_opmode == IEEE80211_M_WDS && 5801 memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0) 5802 errx(1, "no bssid specified for WDS (use wlanbssid)"); 5803 ifr->ifr_data = (caddr_t) ¶ms; 5804 ifcreate_ioctl(ctx, ifr); 5805 5806 setdefregdomain(ctx); 5807 } 5808 5809 static void 5810 set80211clone_wlandev(if_ctx *ctx __unused, const char *arg, int dummy __unused) 5811 { 5812 strlcpy(params.icp_parent, arg, IFNAMSIZ); 5813 } 5814 5815 static void 5816 set80211clone_wlanbssid(if_ctx *ctx __unused, const char *arg, int dummy __unused) 5817 { 5818 const struct ether_addr *ea; 5819 5820 ea = ether_aton(arg); 5821 if (ea == NULL) 5822 errx(1, "%s: cannot parse bssid", arg); 5823 memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN); 5824 } 5825 5826 static void 5827 set80211clone_wlanaddr(if_ctx *ctx __unused, const char *arg, int dummy __unused) 5828 { 5829 const struct ether_addr *ea; 5830 5831 ea = ether_aton(arg); 5832 if (ea == NULL) 5833 errx(1, "%s: cannot parse address", arg); 5834 memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN); 5835 params.icp_flags |= IEEE80211_CLONE_MACADDR; 5836 } 5837 5838 static void 5839 set80211clone_wlanmode(if_ctx *ctx, const char *arg, int dummy __unused) 5840 { 5841 #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0) 5842 if (iseq(arg, "sta")) 5843 params.icp_opmode = IEEE80211_M_STA; 5844 else if (iseq(arg, "ahdemo") || iseq(arg, "adhoc-demo")) 5845 params.icp_opmode = IEEE80211_M_AHDEMO; 5846 else if (iseq(arg, "ibss") || iseq(arg, "adhoc")) 5847 params.icp_opmode = IEEE80211_M_IBSS; 5848 else if (iseq(arg, "ap") || iseq(arg, "host")) 5849 params.icp_opmode = IEEE80211_M_HOSTAP; 5850 else if (iseq(arg, "wds")) 5851 params.icp_opmode = IEEE80211_M_WDS; 5852 else if (iseq(arg, "monitor")) 5853 params.icp_opmode = IEEE80211_M_MONITOR; 5854 else if (iseq(arg, "tdma")) { 5855 params.icp_opmode = IEEE80211_M_AHDEMO; 5856 params.icp_flags |= IEEE80211_CLONE_TDMA; 5857 } else if (iseq(arg, "mesh") || iseq(arg, "mp")) /* mesh point */ 5858 params.icp_opmode = IEEE80211_M_MBSS; 5859 else 5860 errx(1, "Don't know to create %s for %s", arg, ctx->ifname); 5861 #undef iseq 5862 } 5863 5864 static void 5865 set80211clone_beacons(if_ctx *ctx __unused, const char *val __unused, int d) 5866 { 5867 /* NB: inverted sense */ 5868 if (d) 5869 params.icp_flags &= ~IEEE80211_CLONE_NOBEACONS; 5870 else 5871 params.icp_flags |= IEEE80211_CLONE_NOBEACONS; 5872 } 5873 5874 static void 5875 set80211clone_bssid(if_ctx *ctx __unused, const char *val __unused, int d) 5876 { 5877 if (d) 5878 params.icp_flags |= IEEE80211_CLONE_BSSID; 5879 else 5880 params.icp_flags &= ~IEEE80211_CLONE_BSSID; 5881 } 5882 5883 static void 5884 set80211clone_wdslegacy(if_ctx *ctx __unused, const char *val __unused, int d) 5885 { 5886 if (d) 5887 params.icp_flags |= IEEE80211_CLONE_WDSLEGACY; 5888 else 5889 params.icp_flags &= ~IEEE80211_CLONE_WDSLEGACY; 5890 } 5891 5892 static struct cmd ieee80211_cmds[] = { 5893 DEF_CMD_ARG("ssid", set80211ssid), 5894 DEF_CMD_ARG("nwid", set80211ssid), 5895 DEF_CMD_ARG("meshid", set80211meshid), 5896 DEF_CMD_ARG("stationname", set80211stationname), 5897 DEF_CMD_ARG("station", set80211stationname), /* BSD/OS */ 5898 DEF_CMD_ARG("channel", set80211channel), 5899 DEF_CMD_ARG("authmode", set80211authmode), 5900 DEF_CMD_ARG("powersavemode", set80211powersavemode), 5901 DEF_CMD("powersave", 1, set80211powersave), 5902 DEF_CMD("-powersave", 0, set80211powersave), 5903 DEF_CMD_ARG("powersavesleep", set80211powersavesleep), 5904 DEF_CMD_ARG("wepmode", set80211wepmode), 5905 DEF_CMD("wep", 1, set80211wep), 5906 DEF_CMD("-wep", 0, set80211wep), 5907 DEF_CMD_ARG("deftxkey", set80211weptxkey), 5908 DEF_CMD_ARG("weptxkey", set80211weptxkey), 5909 DEF_CMD_ARG("wepkey", set80211wepkey), 5910 DEF_CMD_ARG("nwkey", set80211nwkey), /* NetBSD */ 5911 DEF_CMD("-nwkey", 0, set80211wep), /* NetBSD */ 5912 DEF_CMD_ARG("rtsthreshold", set80211rtsthreshold), 5913 DEF_CMD_ARG("protmode", set80211protmode), 5914 DEF_CMD_ARG("txpower", set80211txpower), 5915 DEF_CMD_ARG("roaming", set80211roaming), 5916 DEF_CMD("wme", 1, set80211wme), 5917 DEF_CMD("-wme", 0, set80211wme), 5918 DEF_CMD("wmm", 1, set80211wme), 5919 DEF_CMD("-wmm", 0, set80211wme), 5920 DEF_CMD("hidessid", 1, set80211hidessid), 5921 DEF_CMD("-hidessid", 0, set80211hidessid), 5922 DEF_CMD("apbridge", 1, set80211apbridge), 5923 DEF_CMD("-apbridge", 0, set80211apbridge), 5924 DEF_CMD_ARG("chanlist", set80211chanlist), 5925 DEF_CMD_ARG("bssid", set80211bssid), 5926 DEF_CMD_ARG("ap", set80211bssid), 5927 DEF_CMD("scan", 0, set80211scan), 5928 DEF_CMD_ARG("list", set80211list), 5929 DEF_CMD_ARG2("cwmin", set80211cwmin), 5930 DEF_CMD_ARG2("cwmax", set80211cwmax), 5931 DEF_CMD_ARG2("aifs", set80211aifs), 5932 DEF_CMD_ARG2("txoplimit", set80211txoplimit), 5933 DEF_CMD_ARG("acm", set80211acm), 5934 DEF_CMD_ARG("-acm", set80211noacm), 5935 DEF_CMD_ARG("ack", set80211ackpolicy), 5936 DEF_CMD_ARG("-ack", set80211noackpolicy), 5937 DEF_CMD_ARG2("bss:cwmin", set80211bsscwmin), 5938 DEF_CMD_ARG2("bss:cwmax", set80211bsscwmax), 5939 DEF_CMD_ARG2("bss:aifs", set80211bssaifs), 5940 DEF_CMD_ARG2("bss:txoplimit", set80211bsstxoplimit), 5941 DEF_CMD_ARG("dtimperiod", set80211dtimperiod), 5942 DEF_CMD_ARG("bintval", set80211bintval), 5943 DEF_CMD("mac:open", IEEE80211_MACCMD_POLICY_OPEN, set80211maccmd), 5944 DEF_CMD("mac:allow", IEEE80211_MACCMD_POLICY_ALLOW, set80211maccmd), 5945 DEF_CMD("mac:deny", IEEE80211_MACCMD_POLICY_DENY, set80211maccmd), 5946 DEF_CMD("mac:radius", IEEE80211_MACCMD_POLICY_RADIUS, set80211maccmd), 5947 DEF_CMD("mac:flush", IEEE80211_MACCMD_FLUSH, set80211maccmd), 5948 DEF_CMD("mac:detach", IEEE80211_MACCMD_DETACH, set80211maccmd), 5949 DEF_CMD_ARG("mac:add", set80211addmac), 5950 DEF_CMD_ARG("mac:del", set80211delmac), 5951 DEF_CMD_ARG("mac:kick", set80211kickmac), 5952 DEF_CMD("pureg", 1, set80211pureg), 5953 DEF_CMD("-pureg", 0, set80211pureg), 5954 DEF_CMD("ff", 1, set80211fastframes), 5955 DEF_CMD("-ff", 0, set80211fastframes), 5956 DEF_CMD("dturbo", 1, set80211dturbo), 5957 DEF_CMD("-dturbo", 0, set80211dturbo), 5958 DEF_CMD("bgscan", 1, set80211bgscan), 5959 DEF_CMD("-bgscan", 0, set80211bgscan), 5960 DEF_CMD_ARG("bgscanidle", set80211bgscanidle), 5961 DEF_CMD_ARG("bgscanintvl", set80211bgscanintvl), 5962 DEF_CMD_ARG("scanvalid", set80211scanvalid), 5963 DEF_CMD("quiet", 1, set80211quiet), 5964 DEF_CMD("-quiet", 0, set80211quiet), 5965 DEF_CMD_ARG("quiet_count", set80211quietcount), 5966 DEF_CMD_ARG("quiet_period", set80211quietperiod), 5967 DEF_CMD_ARG("quiet_duration", set80211quietduration), 5968 DEF_CMD_ARG("quiet_offset", set80211quietoffset), 5969 DEF_CMD_ARG("roam:rssi", set80211roamrssi), 5970 DEF_CMD_ARG("roam:rate", set80211roamrate), 5971 DEF_CMD_ARG("mcastrate", set80211mcastrate), 5972 DEF_CMD_ARG("ucastrate", set80211ucastrate), 5973 DEF_CMD_ARG("mgtrate", set80211mgtrate), 5974 DEF_CMD_ARG("mgmtrate", set80211mgtrate), 5975 DEF_CMD_ARG("maxretry", set80211maxretry), 5976 DEF_CMD_ARG("fragthreshold", set80211fragthreshold), 5977 DEF_CMD("burst", 1, set80211burst), 5978 DEF_CMD("-burst", 0, set80211burst), 5979 DEF_CMD_ARG("bmiss", set80211bmissthreshold), 5980 DEF_CMD_ARG("bmissthreshold", set80211bmissthreshold), 5981 DEF_CMD("shortgi", 1, set80211shortgi), 5982 DEF_CMD("-shortgi", 0, set80211shortgi), 5983 DEF_CMD("ampdurx", 2, set80211ampdu), 5984 DEF_CMD("-ampdurx", -2, set80211ampdu), 5985 DEF_CMD("ampdutx", 1, set80211ampdu), 5986 DEF_CMD("-ampdutx", -1, set80211ampdu), 5987 DEF_CMD("ampdu", 3, set80211ampdu), /* NB: tx+rx */ 5988 DEF_CMD("-ampdu", -3, set80211ampdu), 5989 DEF_CMD_ARG("ampdulimit", set80211ampdulimit), 5990 DEF_CMD_ARG("ampdudensity", set80211ampdudensity), 5991 DEF_CMD("amsdurx", 2, set80211amsdu), 5992 DEF_CMD("-amsdurx", -2, set80211amsdu), 5993 DEF_CMD("amsdutx", 1, set80211amsdu), 5994 DEF_CMD("-amsdutx", -1, set80211amsdu), 5995 DEF_CMD("amsdu", 3, set80211amsdu), /* NB: tx+rx */ 5996 DEF_CMD("-amsdu", -3, set80211amsdu), 5997 DEF_CMD_ARG("amsdulimit", set80211amsdulimit), 5998 DEF_CMD("stbcrx", 2, set80211stbc), 5999 DEF_CMD("-stbcrx", -2, set80211stbc), 6000 DEF_CMD("stbctx", 1, set80211stbc), 6001 DEF_CMD("-stbctx", -1, set80211stbc), 6002 DEF_CMD("stbc", 3, set80211stbc), /* NB: tx+rx */ 6003 DEF_CMD("-stbc", -3, set80211stbc), 6004 DEF_CMD("ldpcrx", 2, set80211ldpc), 6005 DEF_CMD("-ldpcrx", -2, set80211ldpc), 6006 DEF_CMD("ldpctx", 1, set80211ldpc), 6007 DEF_CMD("-ldpctx", -1, set80211ldpc), 6008 DEF_CMD("ldpc", 3, set80211ldpc), /* NB: tx+rx */ 6009 DEF_CMD("-ldpc", -3, set80211ldpc), 6010 DEF_CMD("uapsd", 1, set80211uapsd), 6011 DEF_CMD("-uapsd", 0, set80211uapsd), 6012 DEF_CMD("puren", 1, set80211puren), 6013 DEF_CMD("-puren", 0, set80211puren), 6014 DEF_CMD("doth", 1, set80211doth), 6015 DEF_CMD("-doth", 0, set80211doth), 6016 DEF_CMD("dfs", 1, set80211dfs), 6017 DEF_CMD("-dfs", 0, set80211dfs), 6018 DEF_CMD("htcompat", 1, set80211htcompat), 6019 DEF_CMD("-htcompat", 0, set80211htcompat), 6020 DEF_CMD("dwds", 1, set80211dwds), 6021 DEF_CMD("-dwds", 0, set80211dwds), 6022 DEF_CMD("inact", 1, set80211inact), 6023 DEF_CMD("-inact", 0, set80211inact), 6024 DEF_CMD("tsn", 1, set80211tsn), 6025 DEF_CMD("-tsn", 0, set80211tsn), 6026 DEF_CMD_ARG("regdomain", set80211regdomain), 6027 DEF_CMD_ARG("country", set80211country), 6028 DEF_CMD("indoor", 'I', set80211location), 6029 DEF_CMD("-indoor", 'O', set80211location), 6030 DEF_CMD("outdoor", 'O', set80211location), 6031 DEF_CMD("-outdoor", 'I', set80211location), 6032 DEF_CMD("anywhere", ' ', set80211location), 6033 DEF_CMD("ecm", 1, set80211ecm), 6034 DEF_CMD("-ecm", 0, set80211ecm), 6035 DEF_CMD("dotd", 1, set80211dotd), 6036 DEF_CMD("-dotd", 0, set80211dotd), 6037 DEF_CMD_ARG("htprotmode", set80211htprotmode), 6038 DEF_CMD("ht20", 1, set80211htconf), 6039 DEF_CMD("-ht20", 0, set80211htconf), 6040 DEF_CMD("ht40", 3, set80211htconf), /* NB: 20+40 */ 6041 DEF_CMD("-ht40", 0, set80211htconf), 6042 DEF_CMD("ht", 3, set80211htconf), /* NB: 20+40 */ 6043 DEF_CMD("-ht", 0, set80211htconf), 6044 DEF_CMD("vht", IEEE80211_FVHT_VHT, set80211vhtconf), 6045 DEF_CMD("-vht", -IEEE80211_FVHT_VHT, set80211vhtconf), 6046 DEF_CMD("vht40", IEEE80211_FVHT_USEVHT40, set80211vhtconf), 6047 DEF_CMD("-vht40", -IEEE80211_FVHT_USEVHT40, set80211vhtconf), 6048 DEF_CMD("vht80", IEEE80211_FVHT_USEVHT80, set80211vhtconf), 6049 DEF_CMD("-vht80", -IEEE80211_FVHT_USEVHT80, set80211vhtconf), 6050 DEF_CMD("vht160", IEEE80211_FVHT_USEVHT160, set80211vhtconf), 6051 DEF_CMD("-vht160", -IEEE80211_FVHT_USEVHT160, set80211vhtconf), 6052 DEF_CMD("vht80p80", IEEE80211_FVHT_USEVHT80P80, set80211vhtconf), 6053 DEF_CMD("-vht80p80", -IEEE80211_FVHT_USEVHT80P80, set80211vhtconf), 6054 DEF_CMD("vhtstbctx", IEEE80211_FVHT_STBC_TX, set80211vhtconf), 6055 DEF_CMD("-vhtstbctx", -IEEE80211_FVHT_STBC_TX, set80211vhtconf), 6056 DEF_CMD("vhtstbcrx", IEEE80211_FVHT_STBC_RX, set80211vhtconf), 6057 DEF_CMD("-vhtstbcrx", -IEEE80211_FVHT_STBC_RX, set80211vhtconf), 6058 DEF_CMD("vhtstbc", (IEEE80211_FVHT_STBC_TX|IEEE80211_FVHT_STBC_RX), set80211vhtconf), 6059 DEF_CMD("-vhtstbc", -(IEEE80211_FVHT_STBC_TX|IEEE80211_FVHT_STBC_RX), set80211vhtconf), 6060 DEF_CMD("rifs", 1, set80211rifs), 6061 DEF_CMD("-rifs", 0, set80211rifs), 6062 DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA, set80211smps), 6063 DEF_CMD("smpsdyn", IEEE80211_HTCAP_SMPS_DYNAMIC, set80211smps), 6064 DEF_CMD("-smps", IEEE80211_HTCAP_SMPS_OFF, set80211smps), 6065 /* XXX for testing */ 6066 DEF_CMD_ARG("chanswitch", set80211chanswitch), 6067 6068 DEF_CMD_ARG("tdmaslot", set80211tdmaslot), 6069 DEF_CMD_ARG("tdmaslotcnt", set80211tdmaslotcnt), 6070 DEF_CMD_ARG("tdmaslotlen", set80211tdmaslotlen), 6071 DEF_CMD_ARG("tdmabintval", set80211tdmabintval), 6072 6073 DEF_CMD_ARG("meshttl", set80211meshttl), 6074 DEF_CMD("meshforward", 1, set80211meshforward), 6075 DEF_CMD("-meshforward", 0, set80211meshforward), 6076 DEF_CMD("meshgate", 1, set80211meshgate), 6077 DEF_CMD("-meshgate", 0, set80211meshgate), 6078 DEF_CMD("meshpeering", 1, set80211meshpeering), 6079 DEF_CMD("-meshpeering", 0, set80211meshpeering), 6080 DEF_CMD_ARG("meshmetric", set80211meshmetric), 6081 DEF_CMD_ARG("meshpath", set80211meshpath), 6082 DEF_CMD("meshrt:flush", IEEE80211_MESH_RTCMD_FLUSH, set80211meshrtcmd), 6083 DEF_CMD_ARG("meshrt:add", set80211addmeshrt), 6084 DEF_CMD_ARG("meshrt:del", set80211delmeshrt), 6085 DEF_CMD_ARG("hwmprootmode", set80211hwmprootmode), 6086 DEF_CMD_ARG("hwmpmaxhops", set80211hwmpmaxhops), 6087 6088 /* vap cloning support */ 6089 DEF_CLONE_CMD_ARG("wlanaddr", set80211clone_wlanaddr), 6090 DEF_CLONE_CMD_ARG("wlanbssid", set80211clone_wlanbssid), 6091 DEF_CLONE_CMD_ARG("wlandev", set80211clone_wlandev), 6092 DEF_CLONE_CMD_ARG("wlanmode", set80211clone_wlanmode), 6093 DEF_CLONE_CMD("beacons", 1, set80211clone_beacons), 6094 DEF_CLONE_CMD("-beacons", 0, set80211clone_beacons), 6095 DEF_CLONE_CMD("bssid", 1, set80211clone_bssid), 6096 DEF_CLONE_CMD("-bssid", 0, set80211clone_bssid), 6097 DEF_CLONE_CMD("wdslegacy", 1, set80211clone_wdslegacy), 6098 DEF_CLONE_CMD("-wdslegacy", 0, set80211clone_wdslegacy), 6099 }; 6100 static struct afswtch af_ieee80211 = { 6101 .af_name = "af_ieee80211", 6102 .af_af = AF_UNSPEC, 6103 .af_other_status = ieee80211_status, 6104 }; 6105 6106 static __constructor void 6107 ieee80211_ctor(void) 6108 { 6109 for (size_t i = 0; i < nitems(ieee80211_cmds); i++) 6110 cmd_register(&ieee80211_cmds[i]); 6111 af_register(&af_ieee80211); 6112 clone_setdefcallback_prefix("wlan", wlan_create); 6113 } 6114