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