177218Sphk/* 277218Sphk * Copyright 2001 The Aerospace Corporation. All rights reserved. 377218Sphk * 477218Sphk * Redistribution and use in source and binary forms, with or without 577218Sphk * modification, are permitted provided that the following conditions 677218Sphk * are met: 777218Sphk * 1. Redistributions of source code must retain the above copyright 877218Sphk * notice, this list of conditions and the following disclaimer. 977218Sphk * 2. Redistributions in binary form must reproduce the above copyright 1077218Sphk * notice, this list of conditions and the following disclaimer in the 1177218Sphk * documentation and/or other materials provided with the distribution. 1291454Sbrooks * 3. The name of The Aerospace Corporation may not be used to endorse or 1391454Sbrooks * promote products derived from this software. 1477218Sphk * 1577218Sphk * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``AS IS'' AND 1677218Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1777218Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1877218Sphk * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE 1977218Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2077218Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2177218Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2277218Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2377218Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2477218Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2577218Sphk * SUCH DAMAGE. 2677218Sphk * 2777218Sphk * $FreeBSD$ 2877218Sphk */ 2977218Sphk 3077218Sphk/*- 3177218Sphk * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc. 3277218Sphk * All rights reserved. 3377218Sphk * 3477218Sphk * This code is derived from software contributed to The NetBSD Foundation 3577218Sphk * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 3677218Sphk * NASA Ames Research Center. 3777218Sphk * 3877218Sphk * Redistribution and use in source and binary forms, with or without 3977218Sphk * modification, are permitted provided that the following conditions 4077218Sphk * are met: 4177218Sphk * 1. Redistributions of source code must retain the above copyright 4277218Sphk * notice, this list of conditions and the following disclaimer. 4377218Sphk * 2. Redistributions in binary form must reproduce the above copyright 4477218Sphk * notice, this list of conditions and the following disclaimer in the 4577218Sphk * documentation and/or other materials provided with the distribution. 4677218Sphk * 4777218Sphk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 4877218Sphk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 4977218Sphk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 5077218Sphk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 5177218Sphk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 5277218Sphk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 5377218Sphk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 5477218Sphk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 5577218Sphk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 5677218Sphk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 5777218Sphk * POSSIBILITY OF SUCH DAMAGE. 5877218Sphk */ 5977218Sphk 6077218Sphk#include <sys/param.h> 6177218Sphk#include <sys/ioctl.h> 6277218Sphk#include <sys/socket.h> 6377218Sphk#include <sys/sysctl.h> 6477218Sphk#include <sys/time.h> 6577218Sphk 6677218Sphk#include <net/ethernet.h> 6777218Sphk#include <net/if.h> 6877218Sphk#include <net/if_dl.h> 6977218Sphk#include <net/if_types.h> 70138593Ssam#include <net/if_media.h> 7177218Sphk#include <net/route.h> 72138593Ssam 73116957Ssam#include <net80211/ieee80211_ioctl.h> 74190456Ssam#include <net80211/ieee80211_freebsd.h> 75190456Ssam#include <net80211/ieee80211_superg.h> 76190456Ssam#include <net80211/ieee80211_tdma.h> 77195618Srpaulo#include <net80211/ieee80211_mesh.h> 7877218Sphk 79187801Ssam#include <assert.h> 8077218Sphk#include <ctype.h> 8177218Sphk#include <err.h> 8277218Sphk#include <errno.h> 8377218Sphk#include <fcntl.h> 84146873Sjhb#include <inttypes.h> 8577218Sphk#include <stdio.h> 8677218Sphk#include <stdlib.h> 8777218Sphk#include <string.h> 8877218Sphk#include <unistd.h> 89155931Ssam#include <stdarg.h> 90173275Ssam#include <stddef.h> /* NB: for offsetof */ 9177218Sphk 9277218Sphk#include "ifconfig.h" 93178354Ssam#include "regdomain.h" 9477218Sphk 95178354Ssam#ifndef IEEE80211_FIXED_RATE_NONE 96178354Ssam#define IEEE80211_FIXED_RATE_NONE 0xff 97178354Ssam#endif 98178354Ssam 99178354Ssam/* XXX need these publicly defined or similar */ 100178354Ssam#ifndef IEEE80211_NODE_AUTH 101194136Ssam#define IEEE80211_NODE_AUTH 0x000001 /* authorized for data */ 102194136Ssam#define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */ 103194136Ssam#define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */ 104194136Ssam#define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */ 105194136Ssam#define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */ 106194136Ssam#define IEEE80211_NODE_HT 0x000040 /* HT enabled */ 107194136Ssam#define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */ 108194136Ssam#define IEEE80211_NODE_WPS 0x000100 /* WPS association */ 109194136Ssam#define IEEE80211_NODE_TSN 0x000200 /* TSN association */ 110194136Ssam#define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */ 111194136Ssam#define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */ 112194136Ssam#define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */ 113194136Ssam#define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */ 114194136Ssam#define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */ 115194136Ssam#define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */ 116194136Ssam#define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */ 117194136Ssam#define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */ 118194136Ssam#define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */ 119194136Ssam#define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */ 120178354Ssam#endif 121178354Ssam 122187801Ssam#define MAXCHAN 1536 /* max 1.5K channels */ 123187801Ssam 124173275Ssam#define MAXCOL 78 125173275Ssamstatic int col; 126173275Ssamstatic char spacer; 127173275Ssam 128173275Ssamstatic void LINE_INIT(char c); 129173275Ssamstatic void LINE_BREAK(void); 130173275Ssamstatic void LINE_CHECK(const char *fmt, ...); 131173275Ssam 132188784Ssamstatic const char *modename[IEEE80211_MODE_MAX] = { 133188784Ssam [IEEE80211_MODE_AUTO] = "auto", 134188784Ssam [IEEE80211_MODE_11A] = "11a", 135188784Ssam [IEEE80211_MODE_11B] = "11b", 136188784Ssam [IEEE80211_MODE_11G] = "11g", 137188784Ssam [IEEE80211_MODE_FH] = "fh", 138188784Ssam [IEEE80211_MODE_TURBO_A] = "turboA", 139188784Ssam [IEEE80211_MODE_TURBO_G] = "turboG", 140188784Ssam [IEEE80211_MODE_STURBO_A] = "sturbo", 141188784Ssam [IEEE80211_MODE_11NA] = "11na", 142188784Ssam [IEEE80211_MODE_11NG] = "11ng", 143188784Ssam [IEEE80211_MODE_HALF] = "half", 144188784Ssam [IEEE80211_MODE_QUARTER] = "quarter" 145173275Ssam}; 146173275Ssam 147178354Ssamstatic void set80211(int s, int type, int val, int len, void *data); 148173275Ssamstatic int get80211(int s, int type, void *data, int len); 149173275Ssamstatic int get80211len(int s, int type, void *data, int len, int *plen); 150173275Ssamstatic int get80211val(int s, int type, int *val); 15177218Sphkstatic const char *get_string(const char *val, const char *sep, 15277218Sphk u_int8_t *buf, int *lenp); 15377218Sphkstatic void print_string(const u_int8_t *buf, int len); 154178354Ssamstatic void print_regdomain(const struct ieee80211_regdomain *, int); 155178354Ssamstatic void print_channels(int, const struct ieee80211req_chaninfo *, 156178354Ssam int allchans, int verbose); 157178354Ssamstatic void regdomain_makechannels(struct ieee80211_regdomain_req *, 158178354Ssam const struct ieee80211_devcaps_req *); 159195618Srpaulostatic const char *mesh_linkstate_string(uint8_t state); 16077218Sphk 161187801Ssamstatic struct ieee80211req_chaninfo *chaninfo; 162178354Ssamstatic struct ieee80211_regdomain regdomain; 163178354Ssamstatic int gotregdomain = 0; 164178354Ssamstatic struct ieee80211_roamparams_req roamparams; 165178354Ssamstatic int gotroam = 0; 166178354Ssamstatic struct ieee80211_txparams_req txparams; 167178354Ssamstatic int gottxparams = 0; 168173275Ssamstatic struct ieee80211_channel curchan; 169173275Ssamstatic int gotcurchan = 0; 170178354Ssamstatic struct ifmediareq *ifmr; 171173275Ssamstatic int htconf = 0; 172173275Ssamstatic int gothtconf = 0; 173170531Ssam 174173275Ssamstatic void 175173275Ssamgethtconf(int s) 176173275Ssam{ 177173275Ssam if (gothtconf) 178173275Ssam return; 179173275Ssam if (get80211val(s, IEEE80211_IOC_HTCONF, &htconf) < 0) 180173275Ssam warn("unable to get HT configuration information"); 181173275Ssam gothtconf = 1; 182173275Ssam} 183173275Ssam 184170531Ssam/* 185170531Ssam * Collect channel info from the kernel. We use this (mostly) 186170531Ssam * to handle mapping between frequency and IEEE channel number. 187170531Ssam */ 188170531Ssamstatic void 189170531Ssamgetchaninfo(int s) 190170531Ssam{ 191187801Ssam if (chaninfo != NULL) 192170531Ssam return; 193187801Ssam chaninfo = malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN)); 194187801Ssam if (chaninfo == NULL) 195187801Ssam errx(1, "no space for channel list"); 196187801Ssam if (get80211(s, IEEE80211_IOC_CHANINFO, chaninfo, 197187801Ssam IEEE80211_CHANINFO_SIZE(MAXCHAN)) < 0) 198187801Ssam err(1, "unable to get channel information"); 199170531Ssam ifmr = ifmedia_getstate(s); 200173275Ssam gethtconf(s); 201170531Ssam} 202170531Ssam 203178354Ssamstatic struct regdata * 204178354Ssamgetregdata(void) 205178354Ssam{ 206178354Ssam static struct regdata *rdp = NULL; 207178354Ssam if (rdp == NULL) { 208178354Ssam rdp = lib80211_alloc_regdata(); 209178354Ssam if (rdp == NULL) 210181198Ssam errx(-1, "missing or corrupted regdomain database"); 211178354Ssam } 212178354Ssam return rdp; 213178354Ssam} 214178354Ssam 215170531Ssam/* 216170531Ssam * Given the channel at index i with attributes from, 217170531Ssam * check if there is a channel with attributes to in 218170531Ssam * the channel table. With suitable attributes this 219170531Ssam * allows the caller to look for promotion; e.g. from 220170531Ssam * 11b > 11g. 221170531Ssam */ 222138593Ssamstatic int 223170531Ssamcanpromote(int i, int from, int to) 224170531Ssam{ 225187801Ssam const struct ieee80211_channel *fc = &chaninfo->ic_chans[i]; 226170531Ssam int j; 227170531Ssam 228170531Ssam if ((fc->ic_flags & from) != from) 229170531Ssam return i; 230170531Ssam /* NB: quick check exploiting ordering of chans w/ same frequency */ 231187801Ssam if (i+1 < chaninfo->ic_nchans && 232187801Ssam chaninfo->ic_chans[i+1].ic_freq == fc->ic_freq && 233187801Ssam (chaninfo->ic_chans[i+1].ic_flags & to) == to) 234170531Ssam return i+1; 235170531Ssam /* brute force search in case channel list is not ordered */ 236187801Ssam for (j = 0; j < chaninfo->ic_nchans; j++) { 237187801Ssam const struct ieee80211_channel *tc = &chaninfo->ic_chans[j]; 238170531Ssam if (j != i && 239170531Ssam tc->ic_freq == fc->ic_freq && (tc->ic_flags & to) == to) 240170531Ssam return j; 241170531Ssam } 242170531Ssam return i; 243170531Ssam} 244170531Ssam 245170531Ssam/* 246170531Ssam * Handle channel promotion. When a channel is specified with 247170531Ssam * only a frequency we want to promote it to the ``best'' channel 248170531Ssam * available. The channel list has separate entries for 11b, 11g, 249170531Ssam * 11a, and 11n[ga] channels so specifying a frequency w/o any 250170531Ssam * attributes requires we upgrade, e.g. from 11b -> 11g. This 251170531Ssam * gets complicated when the channel is specified on the same 252170531Ssam * command line with a media request that constrains the available 253170531Ssam * channe list (e.g. mode 11a); we want to honor that to avoid 254170531Ssam * confusing behaviour. 255170531Ssam */ 256170531Ssamstatic int 257170531Ssampromote(int i) 258170531Ssam{ 259170531Ssam /* 260170531Ssam * Query the current mode of the interface in case it's 261170531Ssam * constrained (e.g. to 11a). We must do this carefully 262170531Ssam * as there may be a pending ifmedia request in which case 263170531Ssam * asking the kernel will give us the wrong answer. This 264170531Ssam * is an unfortunate side-effect of the way ifconfig is 265170531Ssam * structure for modularity (yech). 266170531Ssam * 267170531Ssam * NB: ifmr is actually setup in getchaninfo (above); we 268170531Ssam * assume it's called coincident with to this call so 269170531Ssam * we have a ``current setting''; otherwise we must pass 270170531Ssam * the socket descriptor down to here so we can make 271170531Ssam * the ifmedia_getstate call ourselves. 272170531Ssam */ 273170531Ssam int chanmode = ifmr != NULL ? IFM_MODE(ifmr->ifm_current) : IFM_AUTO; 274170531Ssam 275170531Ssam /* when ambiguous promote to ``best'' */ 276170531Ssam /* NB: we abitrarily pick HT40+ over HT40- */ 277170531Ssam if (chanmode != IFM_IEEE80211_11B) 278170531Ssam i = canpromote(i, IEEE80211_CHAN_B, IEEE80211_CHAN_G); 279173275Ssam if (chanmode != IFM_IEEE80211_11G && (htconf & 1)) { 280170531Ssam i = canpromote(i, IEEE80211_CHAN_G, 281170531Ssam IEEE80211_CHAN_G | IEEE80211_CHAN_HT20); 282173275Ssam if (htconf & 2) { 283173275Ssam i = canpromote(i, IEEE80211_CHAN_G, 284173275Ssam IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D); 285173275Ssam i = canpromote(i, IEEE80211_CHAN_G, 286173275Ssam IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U); 287173275Ssam } 288170531Ssam } 289173275Ssam if (chanmode != IFM_IEEE80211_11A && (htconf & 1)) { 290170531Ssam i = canpromote(i, IEEE80211_CHAN_A, 291170531Ssam IEEE80211_CHAN_A | IEEE80211_CHAN_HT20); 292173275Ssam if (htconf & 2) { 293173275Ssam i = canpromote(i, IEEE80211_CHAN_A, 294173275Ssam IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D); 295173275Ssam i = canpromote(i, IEEE80211_CHAN_A, 296173275Ssam IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U); 297173275Ssam } 298170531Ssam } 299170531Ssam return i; 300170531Ssam} 301170531Ssam 302170531Ssamstatic void 303170531Ssammapfreq(struct ieee80211_channel *chan, int freq, int flags) 304170531Ssam{ 305170531Ssam int i; 306170531Ssam 307187801Ssam for (i = 0; i < chaninfo->ic_nchans; i++) { 308187801Ssam const struct ieee80211_channel *c = &chaninfo->ic_chans[i]; 309170531Ssam 310170531Ssam if (c->ic_freq == freq && (c->ic_flags & flags) == flags) { 311170531Ssam if (flags == 0) { 312170531Ssam /* when ambiguous promote to ``best'' */ 313187801Ssam c = &chaninfo->ic_chans[promote(i)]; 314170531Ssam } 315170531Ssam *chan = *c; 316170531Ssam return; 317170531Ssam } 318170531Ssam } 319170531Ssam errx(1, "unknown/undefined frequency %u/0x%x", freq, flags); 320170531Ssam} 321170531Ssam 322170531Ssamstatic void 323170531Ssammapchan(struct ieee80211_channel *chan, int ieee, int flags) 324170531Ssam{ 325170531Ssam int i; 326170531Ssam 327187801Ssam for (i = 0; i < chaninfo->ic_nchans; i++) { 328187801Ssam const struct ieee80211_channel *c = &chaninfo->ic_chans[i]; 329170531Ssam 330170531Ssam if (c->ic_ieee == ieee && (c->ic_flags & flags) == flags) { 331170531Ssam if (flags == 0) { 332170531Ssam /* when ambiguous promote to ``best'' */ 333187801Ssam c = &chaninfo->ic_chans[promote(i)]; 334170531Ssam } 335170531Ssam *chan = *c; 336170531Ssam return; 337170531Ssam } 338170531Ssam } 339173275Ssam errx(1, "unknown/undefined channel number %d flags 0x%x", ieee, flags); 340170531Ssam} 341170531Ssam 342173275Ssamstatic const struct ieee80211_channel * 343173275Ssamgetcurchan(int s) 344173275Ssam{ 345173275Ssam if (gotcurchan) 346173275Ssam return &curchan; 347173275Ssam if (get80211(s, IEEE80211_IOC_CURCHAN, &curchan, sizeof(curchan)) < 0) { 348173275Ssam int val; 349173275Ssam /* fall back to legacy ioctl */ 350173275Ssam if (get80211val(s, IEEE80211_IOC_CHANNEL, &val) < 0) 351187801Ssam err(-1, "cannot figure out current channel"); 352173275Ssam getchaninfo(s); 353173275Ssam mapchan(&curchan, val, 0); 354173275Ssam } 355173275Ssam gotcurchan = 1; 356173275Ssam return &curchan; 357173275Ssam} 358173275Ssam 359178354Ssamstatic enum ieee80211_phymode 360178354Ssamchan2mode(const struct ieee80211_channel *c) 361178354Ssam{ 362178354Ssam if (IEEE80211_IS_CHAN_HTA(c)) 363178354Ssam return IEEE80211_MODE_11NA; 364178354Ssam if (IEEE80211_IS_CHAN_HTG(c)) 365178354Ssam return IEEE80211_MODE_11NG; 366178354Ssam if (IEEE80211_IS_CHAN_108A(c)) 367178354Ssam return IEEE80211_MODE_TURBO_A; 368178354Ssam if (IEEE80211_IS_CHAN_108G(c)) 369178354Ssam return IEEE80211_MODE_TURBO_G; 370178354Ssam if (IEEE80211_IS_CHAN_ST(c)) 371178354Ssam return IEEE80211_MODE_STURBO_A; 372178354Ssam if (IEEE80211_IS_CHAN_FHSS(c)) 373178354Ssam return IEEE80211_MODE_FH; 374188784Ssam if (IEEE80211_IS_CHAN_HALF(c)) 375188784Ssam return IEEE80211_MODE_HALF; 376188784Ssam if (IEEE80211_IS_CHAN_QUARTER(c)) 377188784Ssam return IEEE80211_MODE_QUARTER; 378178354Ssam if (IEEE80211_IS_CHAN_A(c)) 379178354Ssam return IEEE80211_MODE_11A; 380178354Ssam if (IEEE80211_IS_CHAN_ANYG(c)) 381178354Ssam return IEEE80211_MODE_11G; 382178354Ssam if (IEEE80211_IS_CHAN_B(c)) 383178354Ssam return IEEE80211_MODE_11B; 384178354Ssam return IEEE80211_MODE_AUTO; 385178354Ssam} 386178354Ssam 387178354Ssamstatic void 388178354Ssamgetroam(int s) 389178354Ssam{ 390178354Ssam if (gotroam) 391178354Ssam return; 392178354Ssam if (get80211(s, IEEE80211_IOC_ROAM, 393178354Ssam &roamparams, sizeof(roamparams)) < 0) 394187801Ssam err(1, "unable to get roaming parameters"); 395178354Ssam gotroam = 1; 396178354Ssam} 397178354Ssam 398178354Ssamstatic void 399178354Ssamsetroam_cb(int s, void *arg) 400178354Ssam{ 401178354Ssam struct ieee80211_roamparams_req *roam = arg; 402178354Ssam set80211(s, IEEE80211_IOC_ROAM, 0, sizeof(*roam), roam); 403178354Ssam} 404178354Ssam 405178354Ssamstatic void 406178354Ssamgettxparams(int s) 407178354Ssam{ 408178354Ssam if (gottxparams) 409178354Ssam return; 410178354Ssam if (get80211(s, IEEE80211_IOC_TXPARAMS, 411178354Ssam &txparams, sizeof(txparams)) < 0) 412187801Ssam err(1, "unable to get transmit parameters"); 413178354Ssam gottxparams = 1; 414178354Ssam} 415178354Ssam 416178354Ssamstatic void 417178354Ssamsettxparams_cb(int s, void *arg) 418178354Ssam{ 419178354Ssam struct ieee80211_txparams_req *txp = arg; 420178354Ssam set80211(s, IEEE80211_IOC_TXPARAMS, 0, sizeof(*txp), txp); 421178354Ssam} 422178354Ssam 423178354Ssamstatic void 424178354Ssamgetregdomain(int s) 425178354Ssam{ 426178354Ssam if (gotregdomain) 427178354Ssam return; 428178354Ssam if (get80211(s, IEEE80211_IOC_REGDOMAIN, 429178354Ssam ®domain, sizeof(regdomain)) < 0) 430187801Ssam err(1, "unable to get regulatory domain info"); 431178354Ssam gotregdomain = 1; 432178354Ssam} 433178354Ssam 434178354Ssamstatic void 435178354Ssamgetdevcaps(int s, struct ieee80211_devcaps_req *dc) 436178354Ssam{ 437187801Ssam if (get80211(s, IEEE80211_IOC_DEVCAPS, dc, 438187801Ssam IEEE80211_DEVCAPS_SPACE(dc)) < 0) 439187801Ssam err(1, "unable to get device capabilities"); 440178354Ssam} 441178354Ssam 442178354Ssamstatic void 443178354Ssamsetregdomain_cb(int s, void *arg) 444178354Ssam{ 445187801Ssam struct ieee80211_regdomain_req *req; 446178354Ssam struct ieee80211_regdomain *rd = arg; 447187801Ssam struct ieee80211_devcaps_req *dc; 448178354Ssam struct regdata *rdp = getregdata(); 449178354Ssam 450186102Ssam if (rd->country != NO_COUNTRY) { 451178354Ssam const struct country *cc; 452178354Ssam /* 453178354Ssam * Check current country seting to make sure it's 454178354Ssam * compatible with the new regdomain. If not, then 455178354Ssam * override it with any default country for this 456178354Ssam * SKU. If we cannot arrange a match, then abort. 457178354Ssam */ 458178354Ssam cc = lib80211_country_findbycc(rdp, rd->country); 459178354Ssam if (cc == NULL) 460178354Ssam errx(1, "unknown ISO country code %d", rd->country); 461178354Ssam if (cc->rd->sku != rd->regdomain) { 462178354Ssam const struct regdomain *rp; 463178354Ssam /* 464178354Ssam * Check if country is incompatible with regdomain. 465178354Ssam * To enable multiple regdomains for a country code 466178354Ssam * we permit a mismatch between the regdomain and 467178354Ssam * the country's associated regdomain when the 468178354Ssam * regdomain is setup w/o a default country. For 469178354Ssam * example, US is bound to the FCC regdomain but 470178354Ssam * we allow US to be combined with FCC3 because FCC3 471178354Ssam * has not default country. This allows bogus 472178354Ssam * combinations like FCC3+DK which are resolved when 473178354Ssam * constructing the channel list by deferring to the 474178354Ssam * regdomain to construct the channel list. 475178354Ssam */ 476178354Ssam rp = lib80211_regdomain_findbysku(rdp, rd->regdomain); 477178354Ssam if (rp == NULL) 478178354Ssam errx(1, "country %s (%s) is not usable with " 479178354Ssam "regdomain %d", cc->isoname, cc->name, 480178354Ssam rd->regdomain); 481186102Ssam else if (rp->cc != NULL && rp->cc != cc) 482178354Ssam errx(1, "country %s (%s) is not usable with " 483178354Ssam "regdomain %s", cc->isoname, cc->name, 484178354Ssam rp->name); 485178354Ssam } 486178354Ssam } 487178354Ssam /* 488178354Ssam * Fetch the device capabilities and calculate the 489178354Ssam * full set of netbands for which we request a new 490178354Ssam * channel list be constructed. Once that's done we 491178354Ssam * push the regdomain info + channel list to the kernel. 492178354Ssam */ 493187801Ssam dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN)); 494187801Ssam if (dc == NULL) 495187801Ssam errx(1, "no space for device capabilities"); 496187801Ssam dc->dc_chaninfo.ic_nchans = MAXCHAN; 497187801Ssam getdevcaps(s, dc); 498178354Ssam#if 0 499178354Ssam if (verbose) { 500187801Ssam printf("drivercaps: 0x%x\n", dc->dc_drivercaps); 501187801Ssam printf("cryptocaps: 0x%x\n", dc->dc_cryptocaps); 502187801Ssam printf("htcaps : 0x%x\n", dc->dc_htcaps); 503187801Ssam memcpy(chaninfo, &dc->dc_chaninfo, 504187801Ssam IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo)); 505187801Ssam print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, 1/*verbose*/); 506178354Ssam } 507178354Ssam#endif 508187801Ssam req = malloc(IEEE80211_REGDOMAIN_SIZE(dc->dc_chaninfo.ic_nchans)); 509187801Ssam if (req == NULL) 510187801Ssam errx(1, "no space for regdomain request"); 511187801Ssam req->rd = *rd; 512187801Ssam regdomain_makechannels(req, dc); 513178354Ssam if (verbose) { 514178354Ssam LINE_INIT(':'); 515178354Ssam print_regdomain(rd, 1/*verbose*/); 516178354Ssam LINE_BREAK(); 517187801Ssam /* blech, reallocate channel list for new data */ 518187801Ssam if (chaninfo != NULL) 519187801Ssam free(chaninfo); 520187801Ssam chaninfo = malloc(IEEE80211_CHANINFO_SPACE(&req->chaninfo)); 521187801Ssam if (chaninfo == NULL) 522187801Ssam errx(1, "no space for channel list"); 523187801Ssam memcpy(chaninfo, &req->chaninfo, 524187801Ssam IEEE80211_CHANINFO_SPACE(&req->chaninfo)); 525187801Ssam print_channels(s, &req->chaninfo, 1/*allchans*/, 1/*verbose*/); 526178354Ssam } 527187801Ssam if (req->chaninfo.ic_nchans == 0) 528178354Ssam errx(1, "no channels calculated"); 529187801Ssam set80211(s, IEEE80211_IOC_REGDOMAIN, 0, 530187801Ssam IEEE80211_REGDOMAIN_SPACE(req), req); 531187801Ssam free(req); 532187801Ssam free(dc); 533178354Ssam} 534178354Ssam 535170531Ssamstatic int 536170531Ssamieee80211_mhz2ieee(int freq, int flags) 537170531Ssam{ 538170531Ssam struct ieee80211_channel chan; 539170531Ssam mapfreq(&chan, freq, flags); 540170531Ssam return chan.ic_ieee; 541170531Ssam} 542170531Ssam 543170531Ssamstatic int 544138593Ssamisanyarg(const char *arg) 545138593Ssam{ 546173275Ssam return (strncmp(arg, "-", 1) == 0 || 547173275Ssam strncasecmp(arg, "any", 3) == 0 || strncasecmp(arg, "off", 3) == 0); 548138593Ssam} 549138593Ssam 550138593Ssamstatic void 55177218Sphkset80211ssid(const char *val, int d, int s, const struct afswtch *rafp) 55277218Sphk{ 55377218Sphk int ssid; 55477218Sphk int len; 555151883Sbrooks u_int8_t data[IEEE80211_NWID_LEN]; 55677218Sphk 55777218Sphk ssid = 0; 558121827Sbrooks len = strlen(val); 559178354Ssam if (len > 2 && isdigit((int)val[0]) && val[1] == ':') { 56088748Sambrisko ssid = atoi(val)-1; 56188748Sambrisko val += 2; 56288748Sambrisko } 56377218Sphk 56477218Sphk bzero(data, sizeof(data)); 56577218Sphk len = sizeof(data); 566151883Sbrooks if (get_string(val, NULL, data, &len) == NULL) 567151883Sbrooks exit(1); 56877218Sphk 56977218Sphk set80211(s, IEEE80211_IOC_SSID, ssid, len, data); 57077218Sphk} 57177218Sphk 572138593Ssamstatic void 573195618Srpauloset80211meshid(const char *val, int d, int s, const struct afswtch *rafp) 574195618Srpaulo{ 575195618Srpaulo int len; 576195618Srpaulo u_int8_t data[IEEE80211_NWID_LEN]; 577195618Srpaulo 578195618Srpaulo memset(data, 0, sizeof(data)); 579195618Srpaulo len = sizeof(data); 580195618Srpaulo if (get_string(val, NULL, data, &len) == NULL) 581195618Srpaulo exit(1); 582195618Srpaulo 583195618Srpaulo set80211(s, IEEE80211_IOC_MESH_ID, 0, len, data); 584195618Srpaulo} 585195618Srpaulo 586195618Srpaulostatic void 58777218Sphkset80211stationname(const char *val, int d, int s, const struct afswtch *rafp) 58877218Sphk{ 58977218Sphk int len; 59077218Sphk u_int8_t data[33]; 59177218Sphk 59277218Sphk bzero(data, sizeof(data)); 59377218Sphk len = sizeof(data); 59477218Sphk get_string(val, NULL, data, &len); 59577218Sphk 59677218Sphk set80211(s, IEEE80211_IOC_STATIONNAME, 0, len, data); 59777218Sphk} 59877218Sphk 599138593Ssam/* 600170531Ssam * Parse a channel specification for attributes/flags. 601170531Ssam * The syntax is: 602170531Ssam * freq/xx channel width (5,10,20,40,40+,40-) 603170531Ssam * freq:mode channel mode (a,b,g,h,n,t,s,d) 604170531Ssam * 605170531Ssam * These can be combined in either order; e.g. 2437:ng/40. 606170531Ssam * Modes are case insensitive. 607170531Ssam * 608170531Ssam * The result is not validated here; it's assumed to be 609170531Ssam * checked against the channel table fetched from the kernel. 610170531Ssam */ 611170531Ssamstatic int 612173275Ssamgetchannelflags(const char *val, int freq) 613138593Ssam{ 614170531Ssam#define _CHAN_HT 0x80000000 615170531Ssam const char *cp; 616170531Ssam int flags; 617138593Ssam 618170531Ssam flags = 0; 619166015Ssam 620170531Ssam cp = strchr(val, ':'); 621170531Ssam if (cp != NULL) { 622170531Ssam for (cp++; isalpha((int) *cp); cp++) { 623170531Ssam /* accept mixed case */ 624170531Ssam int c = *cp; 625170531Ssam if (isupper(c)) 626170531Ssam c = tolower(c); 627170531Ssam switch (c) { 628170531Ssam case 'a': /* 802.11a */ 629170531Ssam flags |= IEEE80211_CHAN_A; 630170531Ssam break; 631170531Ssam case 'b': /* 802.11b */ 632170531Ssam flags |= IEEE80211_CHAN_B; 633170531Ssam break; 634170531Ssam case 'g': /* 802.11g */ 635170531Ssam flags |= IEEE80211_CHAN_G; 636170531Ssam break; 637170531Ssam case 'h': /* ht = 802.11n */ 638170531Ssam case 'n': /* 802.11n */ 639170531Ssam flags |= _CHAN_HT; /* NB: private */ 640170531Ssam break; 641170531Ssam case 'd': /* dt = Atheros Dynamic Turbo */ 642170531Ssam flags |= IEEE80211_CHAN_TURBO; 643170531Ssam break; 644170531Ssam case 't': /* ht, dt, st, t */ 645170531Ssam /* dt and unadorned t specify Dynamic Turbo */ 646170531Ssam if ((flags & (IEEE80211_CHAN_STURBO|_CHAN_HT)) == 0) 647170531Ssam flags |= IEEE80211_CHAN_TURBO; 648170531Ssam break; 649170531Ssam case 's': /* st = Atheros Static Turbo */ 650170531Ssam flags |= IEEE80211_CHAN_STURBO; 651170531Ssam break; 652170531Ssam default: 653173275Ssam errx(-1, "%s: Invalid channel attribute %c\n", 654170531Ssam val, *cp); 655170531Ssam } 656170531Ssam } 657170531Ssam } 658170531Ssam cp = strchr(val, '/'); 659170531Ssam if (cp != NULL) { 660170531Ssam char *ep; 661170531Ssam u_long cw = strtoul(cp+1, &ep, 10); 662166015Ssam 663170531Ssam switch (cw) { 664170531Ssam case 5: 665170531Ssam flags |= IEEE80211_CHAN_QUARTER; 666170531Ssam break; 667170531Ssam case 10: 668170531Ssam flags |= IEEE80211_CHAN_HALF; 669170531Ssam break; 670170531Ssam case 20: 671170531Ssam /* NB: this may be removed below */ 672170531Ssam flags |= IEEE80211_CHAN_HT20; 673170531Ssam break; 674170531Ssam case 40: 675170531Ssam if (ep != NULL && *ep == '+') 676170531Ssam flags |= IEEE80211_CHAN_HT40U; 677170531Ssam else if (ep != NULL && *ep == '-') 678170531Ssam flags |= IEEE80211_CHAN_HT40D; 679170531Ssam break; 680170531Ssam default: 681173275Ssam errx(-1, "%s: Invalid channel width\n", val); 682170531Ssam } 683165570Ssam } 684170531Ssam /* 685170531Ssam * Cleanup specifications. 686170531Ssam */ 687170531Ssam if ((flags & _CHAN_HT) == 0) { 688170531Ssam /* 689170531Ssam * If user specified freq/20 or freq/40 quietly remove 690170531Ssam * HT cw attributes depending on channel use. To give 691170531Ssam * an explicit 20/40 width for an HT channel you must 692170531Ssam * indicate it is an HT channel since all HT channels 693170531Ssam * are also usable for legacy operation; e.g. freq:n/40. 694170531Ssam */ 695170531Ssam flags &= ~IEEE80211_CHAN_HT; 696170531Ssam } else { 697170531Ssam /* 698170531Ssam * Remove private indicator that this is an HT channel 699170531Ssam * and if no explicit channel width has been given 700170531Ssam * provide the default settings. 701170531Ssam */ 702170531Ssam flags &= ~_CHAN_HT; 703173275Ssam if ((flags & IEEE80211_CHAN_HT) == 0) { 704173275Ssam struct ieee80211_channel chan; 705173275Ssam /* 706173275Ssam * Consult the channel list to see if we can use 707173275Ssam * HT40+ or HT40- (if both the map routines choose). 708173275Ssam */ 709173275Ssam if (freq > 255) 710173275Ssam mapfreq(&chan, freq, 0); 711173275Ssam else 712173275Ssam mapchan(&chan, freq, 0); 713173275Ssam flags |= (chan.ic_flags & IEEE80211_CHAN_HT); 714173275Ssam } 715170531Ssam } 716170531Ssam return flags; 717170531Ssam#undef _CHAN_HT 718138593Ssam} 719138593Ssam 720138593Ssamstatic void 721186105Ssamgetchannel(int s, struct ieee80211_channel *chan, const char *val) 722186105Ssam{ 723186105Ssam int v, flags; 724186105Ssam char *eptr; 725186105Ssam 726186105Ssam memset(chan, 0, sizeof(*chan)); 727186105Ssam if (isanyarg(val)) { 728186105Ssam chan->ic_freq = IEEE80211_CHAN_ANY; 729186105Ssam return; 730186105Ssam } 731186105Ssam getchaninfo(s); 732186105Ssam errno = 0; 733186105Ssam v = strtol(val, &eptr, 10); 734186105Ssam if (val[0] == '\0' || val == eptr || errno == ERANGE || 735186105Ssam /* channel may be suffixed with nothing, :flag, or /width */ 736186105Ssam (eptr[0] != '\0' && eptr[0] != ':' && eptr[0] != '/')) 737186105Ssam errx(1, "invalid channel specification%s", 738186105Ssam errno == ERANGE ? " (out of range)" : ""); 739186105Ssam flags = getchannelflags(val, v); 740186105Ssam if (v > 255) { /* treat as frequency */ 741186105Ssam mapfreq(chan, v, flags); 742186105Ssam } else { 743186105Ssam mapchan(chan, v, flags); 744186105Ssam } 745186105Ssam} 746186105Ssam 747186105Ssamstatic void 74877218Sphkset80211channel(const char *val, int d, int s, const struct afswtch *rafp) 74977218Sphk{ 750170531Ssam struct ieee80211_channel chan; 751170531Ssam 752186105Ssam getchannel(s, &chan, val); 753170531Ssam set80211(s, IEEE80211_IOC_CURCHAN, 0, sizeof(chan), &chan); 75477218Sphk} 75577218Sphk 756138593Ssamstatic void 757178354Ssamset80211chanswitch(const char *val, int d, int s, const struct afswtch *rafp) 758178354Ssam{ 759178354Ssam struct ieee80211_chanswitch_req csr; 760178354Ssam 761186105Ssam getchannel(s, &csr.csa_chan, val); 762178354Ssam csr.csa_mode = 1; 763178354Ssam csr.csa_count = 5; 764178354Ssam set80211(s, IEEE80211_IOC_CHANSWITCH, 0, sizeof(csr), &csr); 765178354Ssam} 766178354Ssam 767178354Ssamstatic void 76877218Sphkset80211authmode(const char *val, int d, int s, const struct afswtch *rafp) 76977218Sphk{ 77077218Sphk int mode; 77177218Sphk 77291454Sbrooks if (strcasecmp(val, "none") == 0) { 77377218Sphk mode = IEEE80211_AUTH_NONE; 77491454Sbrooks } else if (strcasecmp(val, "open") == 0) { 77577218Sphk mode = IEEE80211_AUTH_OPEN; 77691454Sbrooks } else if (strcasecmp(val, "shared") == 0) { 77777218Sphk mode = IEEE80211_AUTH_SHARED; 778138593Ssam } else if (strcasecmp(val, "8021x") == 0) { 779138593Ssam mode = IEEE80211_AUTH_8021X; 780138593Ssam } else if (strcasecmp(val, "wpa") == 0) { 781138593Ssam mode = IEEE80211_AUTH_WPA; 78277218Sphk } else { 783150708Sru errx(1, "unknown authmode"); 78477218Sphk } 78577218Sphk 78677218Sphk set80211(s, IEEE80211_IOC_AUTHMODE, mode, 0, NULL); 78777218Sphk} 78877218Sphk 789138593Ssamstatic void 79077218Sphkset80211powersavemode(const char *val, int d, int s, const struct afswtch *rafp) 79177218Sphk{ 79277218Sphk int mode; 79377218Sphk 79491454Sbrooks if (strcasecmp(val, "off") == 0) { 79577218Sphk mode = IEEE80211_POWERSAVE_OFF; 79691454Sbrooks } else if (strcasecmp(val, "on") == 0) { 79777218Sphk mode = IEEE80211_POWERSAVE_ON; 79891454Sbrooks } else if (strcasecmp(val, "cam") == 0) { 79977218Sphk mode = IEEE80211_POWERSAVE_CAM; 80091454Sbrooks } else if (strcasecmp(val, "psp") == 0) { 80177218Sphk mode = IEEE80211_POWERSAVE_PSP; 80291454Sbrooks } else if (strcasecmp(val, "psp-cam") == 0) { 80377218Sphk mode = IEEE80211_POWERSAVE_PSP_CAM; 80477218Sphk } else { 805150708Sru errx(1, "unknown powersavemode"); 80677218Sphk } 80777218Sphk 80877218Sphk set80211(s, IEEE80211_IOC_POWERSAVE, mode, 0, NULL); 80977218Sphk} 81077218Sphk 811138593Ssamstatic void 81277218Sphkset80211powersave(const char *val, int d, int s, const struct afswtch *rafp) 81377218Sphk{ 81477218Sphk if (d == 0) 81577218Sphk set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_OFF, 81677218Sphk 0, NULL); 81777218Sphk else 81877218Sphk set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_ON, 81977218Sphk 0, NULL); 82077218Sphk} 82177218Sphk 822138593Ssamstatic void 82377218Sphkset80211powersavesleep(const char *val, int d, int s, const struct afswtch *rafp) 82477218Sphk{ 82577218Sphk set80211(s, IEEE80211_IOC_POWERSAVESLEEP, atoi(val), 0, NULL); 82677218Sphk} 82777218Sphk 828138593Ssamstatic void 82977218Sphkset80211wepmode(const char *val, int d, int s, const struct afswtch *rafp) 83077218Sphk{ 83177218Sphk int mode; 83277218Sphk 83391454Sbrooks if (strcasecmp(val, "off") == 0) { 83477218Sphk mode = IEEE80211_WEP_OFF; 83591454Sbrooks } else if (strcasecmp(val, "on") == 0) { 83677218Sphk mode = IEEE80211_WEP_ON; 83791454Sbrooks } else if (strcasecmp(val, "mixed") == 0) { 83877218Sphk mode = IEEE80211_WEP_MIXED; 83977218Sphk } else { 840150708Sru errx(1, "unknown wep mode"); 84177218Sphk } 84277218Sphk 84377218Sphk set80211(s, IEEE80211_IOC_WEP, mode, 0, NULL); 84477218Sphk} 84577218Sphk 846138593Ssamstatic void 84777218Sphkset80211wep(const char *val, int d, int s, const struct afswtch *rafp) 84877218Sphk{ 84977218Sphk set80211(s, IEEE80211_IOC_WEP, d, 0, NULL); 85077218Sphk} 85177218Sphk 852139493Ssamstatic int 853139493Ssamisundefarg(const char *arg) 854139493Ssam{ 855139493Ssam return (strcmp(arg, "-") == 0 || strncasecmp(arg, "undef", 5) == 0); 856139493Ssam} 857139493Ssam 858138593Ssamstatic void 85977218Sphkset80211weptxkey(const char *val, int d, int s, const struct afswtch *rafp) 86077218Sphk{ 861139493Ssam if (isundefarg(val)) 862139493Ssam set80211(s, IEEE80211_IOC_WEPTXKEY, IEEE80211_KEYIX_NONE, 0, NULL); 863139493Ssam else 864139493Ssam set80211(s, IEEE80211_IOC_WEPTXKEY, atoi(val)-1, 0, NULL); 86577218Sphk} 86677218Sphk 867138593Ssamstatic void 86877218Sphkset80211wepkey(const char *val, int d, int s, const struct afswtch *rafp) 86977218Sphk{ 87077218Sphk int key = 0; 87177218Sphk int len; 872120178Ssam u_int8_t data[IEEE80211_KEYBUF_SIZE]; 87377218Sphk 874178354Ssam if (isdigit((int)val[0]) && val[1] == ':') { 87577218Sphk key = atoi(val)-1; 87677218Sphk val += 2; 87777218Sphk } 87877218Sphk 87977218Sphk bzero(data, sizeof(data)); 88077218Sphk len = sizeof(data); 88177218Sphk get_string(val, NULL, data, &len); 88277218Sphk 88377218Sphk set80211(s, IEEE80211_IOC_WEPKEY, key, len, data); 88477218Sphk} 88577218Sphk 88677218Sphk/* 887229778Suqs * This function is purely a NetBSD compatibility interface. The NetBSD 888148686Sstefanf * interface is too inflexible, but it's there so we'll support it since 88977218Sphk * it's not all that hard. 89077218Sphk */ 891138593Ssamstatic void 89277218Sphkset80211nwkey(const char *val, int d, int s, const struct afswtch *rafp) 89377218Sphk{ 89477218Sphk int txkey; 89577218Sphk int i, len; 896120178Ssam u_int8_t data[IEEE80211_KEYBUF_SIZE]; 89777218Sphk 89877218Sphk set80211(s, IEEE80211_IOC_WEP, IEEE80211_WEP_ON, 0, NULL); 89977218Sphk 900178354Ssam if (isdigit((int)val[0]) && val[1] == ':') { 90177218Sphk txkey = val[0]-'0'-1; 90277218Sphk val += 2; 90377218Sphk 90491454Sbrooks for (i = 0; i < 4; i++) { 90577218Sphk bzero(data, sizeof(data)); 90677218Sphk len = sizeof(data); 90777218Sphk val = get_string(val, ",", data, &len); 908151827Sbrooks if (val == NULL) 909151827Sbrooks exit(1); 91077218Sphk 91177218Sphk set80211(s, IEEE80211_IOC_WEPKEY, i, len, data); 91277218Sphk } 91377218Sphk } else { 91477218Sphk bzero(data, sizeof(data)); 91577218Sphk len = sizeof(data); 91677218Sphk get_string(val, NULL, data, &len); 91777218Sphk txkey = 0; 91877218Sphk 91977218Sphk set80211(s, IEEE80211_IOC_WEPKEY, 0, len, data); 92077218Sphk 92177218Sphk bzero(data, sizeof(data)); 92291454Sbrooks for (i = 1; i < 4; i++) 92377218Sphk set80211(s, IEEE80211_IOC_WEPKEY, i, 0, data); 92477218Sphk } 92577218Sphk 92677218Sphk set80211(s, IEEE80211_IOC_WEPTXKEY, txkey, 0, NULL); 92777218Sphk} 92877218Sphk 929138593Ssamstatic void 930127649Ssamset80211rtsthreshold(const char *val, int d, int s, const struct afswtch *rafp) 931127649Ssam{ 932148416Ssam set80211(s, IEEE80211_IOC_RTSTHRESHOLD, 933148416Ssam isundefarg(val) ? IEEE80211_RTS_MAX : atoi(val), 0, NULL); 934127649Ssam} 935127649Ssam 936138593Ssamstatic void 937127649Ssamset80211protmode(const char *val, int d, int s, const struct afswtch *rafp) 938127649Ssam{ 939127649Ssam int mode; 940127649Ssam 941127649Ssam if (strcasecmp(val, "off") == 0) { 942127649Ssam mode = IEEE80211_PROTMODE_OFF; 943127649Ssam } else if (strcasecmp(val, "cts") == 0) { 944127649Ssam mode = IEEE80211_PROTMODE_CTS; 945173275Ssam } else if (strncasecmp(val, "rtscts", 3) == 0) { 946127649Ssam mode = IEEE80211_PROTMODE_RTSCTS; 947127649Ssam } else { 948150708Sru errx(1, "unknown protection mode"); 949127649Ssam } 950127649Ssam 951127649Ssam set80211(s, IEEE80211_IOC_PROTMODE, mode, 0, NULL); 952127649Ssam} 953127649Ssam 954138593Ssamstatic void 955173275Ssamset80211htprotmode(const char *val, int d, int s, const struct afswtch *rafp) 956173275Ssam{ 957173275Ssam int mode; 958173275Ssam 959173275Ssam if (strcasecmp(val, "off") == 0) { 960173275Ssam mode = IEEE80211_PROTMODE_OFF; 961173275Ssam } else if (strncasecmp(val, "rts", 3) == 0) { 962173275Ssam mode = IEEE80211_PROTMODE_RTSCTS; 963173275Ssam } else { 964173275Ssam errx(1, "unknown protection mode"); 965173275Ssam } 966173275Ssam 967173275Ssam set80211(s, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL); 968173275Ssam} 969173275Ssam 970173275Ssamstatic void 971127649Ssamset80211txpower(const char *val, int d, int s, const struct afswtch *rafp) 972127649Ssam{ 973173275Ssam double v = atof(val); 974173275Ssam int txpow; 975173275Ssam 976173275Ssam txpow = (int) (2*v); 977173275Ssam if (txpow != 2*v) 978173275Ssam errx(-1, "invalid tx power (must be .5 dBm units)"); 979173275Ssam set80211(s, IEEE80211_IOC_TXPOWER, txpow, 0, NULL); 980127649Ssam} 981127649Ssam 982138593Ssam#define IEEE80211_ROAMING_DEVICE 0 983138593Ssam#define IEEE80211_ROAMING_AUTO 1 984138593Ssam#define IEEE80211_ROAMING_MANUAL 2 985138593Ssam 986138593Ssamstatic void 987138593Ssamset80211roaming(const char *val, int d, int s, const struct afswtch *rafp) 98877218Sphk{ 989138593Ssam int mode; 99077218Sphk 991138593Ssam if (strcasecmp(val, "device") == 0) { 992138593Ssam mode = IEEE80211_ROAMING_DEVICE; 993138593Ssam } else if (strcasecmp(val, "auto") == 0) { 994138593Ssam mode = IEEE80211_ROAMING_AUTO; 995138593Ssam } else if (strcasecmp(val, "manual") == 0) { 996138593Ssam mode = IEEE80211_ROAMING_MANUAL; 997138593Ssam } else { 998150708Sru errx(1, "unknown roaming mode"); 999138593Ssam } 1000138593Ssam set80211(s, IEEE80211_IOC_ROAMING, mode, 0, NULL); 1001138593Ssam} 1002138593Ssam 1003138593Ssamstatic void 1004138593Ssamset80211wme(const char *val, int d, int s, const struct afswtch *rafp) 1005138593Ssam{ 1006138593Ssam set80211(s, IEEE80211_IOC_WME, d, 0, NULL); 1007138593Ssam} 1008138593Ssam 1009138593Ssamstatic void 1010138593Ssamset80211hidessid(const char *val, int d, int s, const struct afswtch *rafp) 1011138593Ssam{ 1012138593Ssam set80211(s, IEEE80211_IOC_HIDESSID, d, 0, NULL); 1013138593Ssam} 1014138593Ssam 1015138593Ssamstatic void 1016138593Ssamset80211apbridge(const char *val, int d, int s, const struct afswtch *rafp) 1017138593Ssam{ 1018138593Ssam set80211(s, IEEE80211_IOC_APBRIDGE, d, 0, NULL); 1019138593Ssam} 1020138593Ssam 1021138593Ssamstatic void 1022170531Ssamset80211fastframes(const char *val, int d, int s, const struct afswtch *rafp) 1023170531Ssam{ 1024170531Ssam set80211(s, IEEE80211_IOC_FF, d, 0, NULL); 1025170531Ssam} 1026170531Ssam 1027170531Ssamstatic void 1028170531Ssamset80211dturbo(const char *val, int d, int s, const struct afswtch *rafp) 1029170531Ssam{ 1030170531Ssam set80211(s, IEEE80211_IOC_TURBOP, d, 0, NULL); 1031170531Ssam} 1032170531Ssam 1033170531Ssamstatic void 1034138593Ssamset80211chanlist(const char *val, int d, int s, const struct afswtch *rafp) 1035138593Ssam{ 1036138593Ssam struct ieee80211req_chanlist chanlist; 1037138593Ssam char *temp, *cp, *tp; 1038138593Ssam 1039138593Ssam temp = malloc(strlen(val) + 1); 1040138593Ssam if (temp == NULL) 1041138593Ssam errx(1, "malloc failed"); 1042138593Ssam strcpy(temp, val); 1043138593Ssam memset(&chanlist, 0, sizeof(chanlist)); 1044138593Ssam cp = temp; 1045138593Ssam for (;;) { 1046173275Ssam int first, last, f, c; 1047138593Ssam 1048138593Ssam tp = strchr(cp, ','); 1049138593Ssam if (tp != NULL) 1050138593Ssam *tp++ = '\0'; 1051138593Ssam switch (sscanf(cp, "%u-%u", &first, &last)) { 1052138593Ssam case 1: 1053187801Ssam if (first > IEEE80211_CHAN_MAX) 1054188038Sdelphij errx(-1, "channel %u out of range, max %u", 1055187801Ssam first, IEEE80211_CHAN_MAX); 1056138593Ssam setbit(chanlist.ic_channels, first); 1057138593Ssam break; 1058138593Ssam case 2: 1059187801Ssam if (first > IEEE80211_CHAN_MAX) 1060188038Sdelphij errx(-1, "channel %u out of range, max %u", 1061187801Ssam first, IEEE80211_CHAN_MAX); 1062187801Ssam if (last > IEEE80211_CHAN_MAX) 1063188038Sdelphij errx(-1, "channel %u out of range, max %u", 1064187801Ssam last, IEEE80211_CHAN_MAX); 1065138593Ssam if (first > last) 1066138593Ssam errx(-1, "void channel range, %u > %u", 1067138593Ssam first, last); 1068138593Ssam for (f = first; f <= last; f++) 1069138593Ssam setbit(chanlist.ic_channels, f); 1070138593Ssam break; 1071138593Ssam } 1072138593Ssam if (tp == NULL) 1073138593Ssam break; 1074173275Ssam c = *tp; 1075173275Ssam while (isspace(c)) 1076138593Ssam tp++; 1077173275Ssam if (!isdigit(c)) 1078138593Ssam break; 1079138593Ssam cp = tp; 1080138593Ssam } 1081170531Ssam set80211(s, IEEE80211_IOC_CHANLIST, 0, sizeof(chanlist), &chanlist); 1082138593Ssam} 1083138593Ssam 1084138593Ssamstatic void 1085138593Ssamset80211bssid(const char *val, int d, int s, const struct afswtch *rafp) 1086138593Ssam{ 1087138593Ssam 1088138593Ssam if (!isanyarg(val)) { 1089138593Ssam char *temp; 1090138593Ssam struct sockaddr_dl sdl; 1091138593Ssam 1092155702Ssam temp = malloc(strlen(val) + 2); /* ':' and '\0' */ 1093138593Ssam if (temp == NULL) 1094138593Ssam errx(1, "malloc failed"); 1095138593Ssam temp[0] = ':'; 1096138593Ssam strcpy(temp + 1, val); 1097138593Ssam sdl.sdl_len = sizeof(sdl); 1098138593Ssam link_addr(temp, &sdl); 1099138593Ssam free(temp); 1100138593Ssam if (sdl.sdl_alen != IEEE80211_ADDR_LEN) 1101138593Ssam errx(1, "malformed link-level address"); 1102138593Ssam set80211(s, IEEE80211_IOC_BSSID, 0, 1103138593Ssam IEEE80211_ADDR_LEN, LLADDR(&sdl)); 1104138593Ssam } else { 1105138593Ssam uint8_t zerobssid[IEEE80211_ADDR_LEN]; 1106138593Ssam memset(zerobssid, 0, sizeof(zerobssid)); 1107138593Ssam set80211(s, IEEE80211_IOC_BSSID, 0, 1108138593Ssam IEEE80211_ADDR_LEN, zerobssid); 1109138593Ssam } 1110138593Ssam} 1111138593Ssam 1112138593Ssamstatic int 1113138593Ssamgetac(const char *ac) 1114138593Ssam{ 1115138593Ssam if (strcasecmp(ac, "ac_be") == 0 || strcasecmp(ac, "be") == 0) 1116138593Ssam return WME_AC_BE; 1117138593Ssam if (strcasecmp(ac, "ac_bk") == 0 || strcasecmp(ac, "bk") == 0) 1118138593Ssam return WME_AC_BK; 1119138593Ssam if (strcasecmp(ac, "ac_vi") == 0 || strcasecmp(ac, "vi") == 0) 1120138593Ssam return WME_AC_VI; 1121138593Ssam if (strcasecmp(ac, "ac_vo") == 0 || strcasecmp(ac, "vo") == 0) 1122138593Ssam return WME_AC_VO; 1123138593Ssam errx(1, "unknown wme access class %s", ac); 1124138593Ssam} 1125138593Ssam 1126138593Ssamstatic 1127138593SsamDECL_CMD_FUNC2(set80211cwmin, ac, val) 1128138593Ssam{ 1129138593Ssam set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac), NULL); 1130138593Ssam} 1131138593Ssam 1132138593Ssamstatic 1133138593SsamDECL_CMD_FUNC2(set80211cwmax, ac, val) 1134138593Ssam{ 1135138593Ssam set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac), NULL); 1136138593Ssam} 1137138593Ssam 1138138593Ssamstatic 1139138593SsamDECL_CMD_FUNC2(set80211aifs, ac, val) 1140138593Ssam{ 1141138593Ssam set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac), NULL); 1142138593Ssam} 1143138593Ssam 1144138593Ssamstatic 1145138593SsamDECL_CMD_FUNC2(set80211txoplimit, ac, val) 1146138593Ssam{ 1147138593Ssam set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac), NULL); 1148138593Ssam} 1149138593Ssam 1150138593Ssamstatic 1151148621SsamDECL_CMD_FUNC(set80211acm, ac, d) 1152138593Ssam{ 1153148621Ssam set80211(s, IEEE80211_IOC_WME_ACM, 1, getac(ac), NULL); 1154138593Ssam} 1155148621Ssamstatic 1156148621SsamDECL_CMD_FUNC(set80211noacm, ac, d) 1157148621Ssam{ 1158148621Ssam set80211(s, IEEE80211_IOC_WME_ACM, 0, getac(ac), NULL); 1159148621Ssam} 1160138593Ssam 1161138593Ssamstatic 1162148621SsamDECL_CMD_FUNC(set80211ackpolicy, ac, d) 1163138593Ssam{ 1164148621Ssam set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 1, getac(ac), NULL); 1165138593Ssam} 1166148621Ssamstatic 1167148621SsamDECL_CMD_FUNC(set80211noackpolicy, ac, d) 1168148621Ssam{ 1169148621Ssam set80211(s, IEEE80211_IOC_WME_ACKPOLICY, 0, getac(ac), NULL); 1170148621Ssam} 1171138593Ssam 1172138593Ssamstatic 1173138593SsamDECL_CMD_FUNC2(set80211bsscwmin, ac, val) 1174138593Ssam{ 1175138593Ssam set80211(s, IEEE80211_IOC_WME_CWMIN, atoi(val), 1176138593Ssam getac(ac)|IEEE80211_WMEPARAM_BSS, NULL); 1177138593Ssam} 1178138593Ssam 1179138593Ssamstatic 1180138593SsamDECL_CMD_FUNC2(set80211bsscwmax, ac, val) 1181138593Ssam{ 1182138593Ssam set80211(s, IEEE80211_IOC_WME_CWMAX, atoi(val), 1183138593Ssam getac(ac)|IEEE80211_WMEPARAM_BSS, NULL); 1184138593Ssam} 1185138593Ssam 1186138593Ssamstatic 1187138593SsamDECL_CMD_FUNC2(set80211bssaifs, ac, val) 1188138593Ssam{ 1189138593Ssam set80211(s, IEEE80211_IOC_WME_AIFS, atoi(val), 1190138593Ssam getac(ac)|IEEE80211_WMEPARAM_BSS, NULL); 1191138593Ssam} 1192138593Ssam 1193138593Ssamstatic 1194138593SsamDECL_CMD_FUNC2(set80211bsstxoplimit, ac, val) 1195138593Ssam{ 1196138593Ssam set80211(s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), 1197138593Ssam getac(ac)|IEEE80211_WMEPARAM_BSS, NULL); 1198138593Ssam} 1199138593Ssam 1200138593Ssamstatic 1201138593SsamDECL_CMD_FUNC(set80211dtimperiod, val, d) 1202138593Ssam{ 1203138593Ssam set80211(s, IEEE80211_IOC_DTIM_PERIOD, atoi(val), 0, NULL); 1204138593Ssam} 1205138593Ssam 1206138593Ssamstatic 1207138593SsamDECL_CMD_FUNC(set80211bintval, val, d) 1208138593Ssam{ 1209138593Ssam set80211(s, IEEE80211_IOC_BEACON_INTERVAL, atoi(val), 0, NULL); 1210138593Ssam} 1211138593Ssam 1212138593Ssamstatic void 1213138593Ssamset80211macmac(int s, int op, const char *val) 1214138593Ssam{ 1215138593Ssam char *temp; 1216138593Ssam struct sockaddr_dl sdl; 1217138593Ssam 1218155702Ssam temp = malloc(strlen(val) + 2); /* ':' and '\0' */ 1219138593Ssam if (temp == NULL) 1220138593Ssam errx(1, "malloc failed"); 1221138593Ssam temp[0] = ':'; 1222138593Ssam strcpy(temp + 1, val); 1223138593Ssam sdl.sdl_len = sizeof(sdl); 1224138593Ssam link_addr(temp, &sdl); 1225138593Ssam free(temp); 1226138593Ssam if (sdl.sdl_alen != IEEE80211_ADDR_LEN) 1227138593Ssam errx(1, "malformed link-level address"); 1228138593Ssam set80211(s, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl)); 1229138593Ssam} 1230138593Ssam 1231138593Ssamstatic 1232138593SsamDECL_CMD_FUNC(set80211addmac, val, d) 1233138593Ssam{ 1234138593Ssam set80211macmac(s, IEEE80211_IOC_ADDMAC, val); 1235138593Ssam} 1236138593Ssam 1237138593Ssamstatic 1238138593SsamDECL_CMD_FUNC(set80211delmac, val, d) 1239138593Ssam{ 1240138593Ssam set80211macmac(s, IEEE80211_IOC_DELMAC, val); 1241138593Ssam} 1242138593Ssam 1243138593Ssamstatic 1244149029SsamDECL_CMD_FUNC(set80211kickmac, val, d) 1245149029Ssam{ 1246149029Ssam char *temp; 1247149029Ssam struct sockaddr_dl sdl; 1248149029Ssam struct ieee80211req_mlme mlme; 1249149029Ssam 1250155702Ssam temp = malloc(strlen(val) + 2); /* ':' and '\0' */ 1251149029Ssam if (temp == NULL) 1252149029Ssam errx(1, "malloc failed"); 1253149029Ssam temp[0] = ':'; 1254149029Ssam strcpy(temp + 1, val); 1255149029Ssam sdl.sdl_len = sizeof(sdl); 1256149029Ssam link_addr(temp, &sdl); 1257149029Ssam free(temp); 1258149029Ssam if (sdl.sdl_alen != IEEE80211_ADDR_LEN) 1259149029Ssam errx(1, "malformed link-level address"); 1260149029Ssam memset(&mlme, 0, sizeof(mlme)); 1261149029Ssam mlme.im_op = IEEE80211_MLME_DEAUTH; 1262149029Ssam mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE; 1263149029Ssam memcpy(mlme.im_macaddr, LLADDR(&sdl), IEEE80211_ADDR_LEN); 1264170531Ssam set80211(s, IEEE80211_IOC_MLME, 0, sizeof(mlme), &mlme); 1265149029Ssam} 1266149029Ssam 1267149029Ssamstatic 1268138593SsamDECL_CMD_FUNC(set80211maccmd, val, d) 1269138593Ssam{ 1270138593Ssam set80211(s, IEEE80211_IOC_MACCMD, d, 0, NULL); 1271138593Ssam} 1272138593Ssam 1273147795Ssamstatic void 1274195618Srpauloset80211meshrtmac(int s, int req, const char *val) 1275195618Srpaulo{ 1276195618Srpaulo char *temp; 1277195618Srpaulo struct sockaddr_dl sdl; 1278195618Srpaulo 1279195618Srpaulo temp = malloc(strlen(val) + 2); /* ':' and '\0' */ 1280195618Srpaulo if (temp == NULL) 1281195618Srpaulo errx(1, "malloc failed"); 1282195618Srpaulo temp[0] = ':'; 1283195618Srpaulo strcpy(temp + 1, val); 1284195618Srpaulo sdl.sdl_len = sizeof(sdl); 1285195618Srpaulo link_addr(temp, &sdl); 1286195618Srpaulo free(temp); 1287195618Srpaulo if (sdl.sdl_alen != IEEE80211_ADDR_LEN) 1288195618Srpaulo errx(1, "malformed link-level address"); 1289195618Srpaulo set80211(s, IEEE80211_IOC_MESH_RTCMD, req, 1290195618Srpaulo IEEE80211_ADDR_LEN, LLADDR(&sdl)); 1291195618Srpaulo} 1292195618Srpaulo 1293195618Srpaulostatic 1294195618SrpauloDECL_CMD_FUNC(set80211addmeshrt, val, d) 1295195618Srpaulo{ 1296195618Srpaulo set80211meshrtmac(s, IEEE80211_MESH_RTCMD_ADD, val); 1297195618Srpaulo} 1298195618Srpaulo 1299195618Srpaulostatic 1300195618SrpauloDECL_CMD_FUNC(set80211delmeshrt, val, d) 1301195618Srpaulo{ 1302195618Srpaulo set80211meshrtmac(s, IEEE80211_MESH_RTCMD_DELETE, val); 1303195618Srpaulo} 1304195618Srpaulo 1305195618Srpaulostatic 1306195618SrpauloDECL_CMD_FUNC(set80211meshrtcmd, val, d) 1307195618Srpaulo{ 1308195618Srpaulo set80211(s, IEEE80211_IOC_MESH_RTCMD, d, 0, NULL); 1309195618Srpaulo} 1310195618Srpaulo 1311195618Srpaulostatic 1312195618SrpauloDECL_CMD_FUNC(set80211hwmprootmode, val, d) 1313195618Srpaulo{ 1314195618Srpaulo int mode; 1315195618Srpaulo 1316195618Srpaulo if (strcasecmp(val, "normal") == 0) 1317195618Srpaulo mode = IEEE80211_HWMP_ROOTMODE_NORMAL; 1318195618Srpaulo else if (strcasecmp(val, "proactive") == 0) 1319195618Srpaulo mode = IEEE80211_HWMP_ROOTMODE_PROACTIVE; 1320195618Srpaulo else if (strcasecmp(val, "rann") == 0) 1321195618Srpaulo mode = IEEE80211_HWMP_ROOTMODE_RANN; 1322195618Srpaulo else 1323195618Srpaulo mode = IEEE80211_HWMP_ROOTMODE_DISABLED; 1324195618Srpaulo set80211(s, IEEE80211_IOC_HWMP_ROOTMODE, mode, 0, NULL); 1325195618Srpaulo} 1326195618Srpaulo 1327195618Srpaulostatic 1328195618SrpauloDECL_CMD_FUNC(set80211hwmpmaxhops, val, d) 1329195618Srpaulo{ 1330195618Srpaulo set80211(s, IEEE80211_IOC_HWMP_MAXHOPS, atoi(val), 0, NULL); 1331195618Srpaulo} 1332195618Srpaulo 1333195618Srpaulostatic void 1334147795Ssamset80211pureg(const char *val, int d, int s, const struct afswtch *rafp) 1335147795Ssam{ 1336147795Ssam set80211(s, IEEE80211_IOC_PUREG, d, 0, NULL); 1337147795Ssam} 1338147795Ssam 1339153422Ssamstatic void 1340227336Sadrianset80211quiet(const char *val, int d, int s, const struct afswtch *rafp) 1341227336Sadrian{ 1342227336Sadrian set80211(s, IEEE80211_IOC_QUIET, d, 0, NULL); 1343227336Sadrian} 1344227336Sadrian 1345227336Sadrianstatic 1346227336SadrianDECL_CMD_FUNC(set80211quietperiod, val, d) 1347227336Sadrian{ 1348227336Sadrian set80211(s, IEEE80211_IOC_QUIET_PERIOD, atoi(val), 0, NULL); 1349227336Sadrian} 1350227336Sadrian 1351227336Sadrianstatic 1352227336SadrianDECL_CMD_FUNC(set80211quietcount, val, d) 1353227336Sadrian{ 1354227336Sadrian set80211(s, IEEE80211_IOC_QUIET_COUNT, atoi(val), 0, NULL); 1355227336Sadrian} 1356227336Sadrian 1357227336Sadrianstatic 1358227336SadrianDECL_CMD_FUNC(set80211quietduration, val, d) 1359227336Sadrian{ 1360227336Sadrian set80211(s, IEEE80211_IOC_QUIET_DUR, atoi(val), 0, NULL); 1361227336Sadrian} 1362227336Sadrian 1363227336Sadrianstatic 1364227336SadrianDECL_CMD_FUNC(set80211quietoffset, val, d) 1365227336Sadrian{ 1366227336Sadrian set80211(s, IEEE80211_IOC_QUIET_OFFSET, atoi(val), 0, NULL); 1367227336Sadrian} 1368227336Sadrian 1369227336Sadrianstatic void 1370170531Ssamset80211bgscan(const char *val, int d, int s, const struct afswtch *rafp) 1371153422Ssam{ 1372170531Ssam set80211(s, IEEE80211_IOC_BGSCAN, d, 0, NULL); 1373153422Ssam} 1374153422Ssam 1375148416Ssamstatic 1376170531SsamDECL_CMD_FUNC(set80211bgscanidle, val, d) 1377170531Ssam{ 1378170531Ssam set80211(s, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL); 1379170531Ssam} 1380170531Ssam 1381170531Ssamstatic 1382170531SsamDECL_CMD_FUNC(set80211bgscanintvl, val, d) 1383170531Ssam{ 1384170531Ssam set80211(s, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL); 1385170531Ssam} 1386170531Ssam 1387170531Ssamstatic 1388170531SsamDECL_CMD_FUNC(set80211scanvalid, val, d) 1389170531Ssam{ 1390170531Ssam set80211(s, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL); 1391170531Ssam} 1392170531Ssam 1393178354Ssam/* 1394178354Ssam * Parse an optional trailing specification of which netbands 1395178354Ssam * to apply a parameter to. This is basically the same syntax 1396178354Ssam * as used for channels but you can concatenate to specify 1397178354Ssam * multiple. For example: 1398178354Ssam * 14:abg apply to 11a, 11b, and 11g 1399178354Ssam * 6:ht apply to 11na and 11ng 1400178354Ssam * We don't make a big effort to catch silly things; this is 1401178354Ssam * really a convenience mechanism. 1402178354Ssam */ 1403178354Ssamstatic int 1404178354Ssamgetmodeflags(const char *val) 1405170531Ssam{ 1406178354Ssam const char *cp; 1407178354Ssam int flags; 1408178354Ssam 1409178354Ssam flags = 0; 1410178354Ssam 1411178354Ssam cp = strchr(val, ':'); 1412178354Ssam if (cp != NULL) { 1413178354Ssam for (cp++; isalpha((int) *cp); cp++) { 1414178354Ssam /* accept mixed case */ 1415178354Ssam int c = *cp; 1416178354Ssam if (isupper(c)) 1417178354Ssam c = tolower(c); 1418178354Ssam switch (c) { 1419178354Ssam case 'a': /* 802.11a */ 1420178354Ssam flags |= IEEE80211_CHAN_A; 1421178354Ssam break; 1422178354Ssam case 'b': /* 802.11b */ 1423178354Ssam flags |= IEEE80211_CHAN_B; 1424178354Ssam break; 1425178354Ssam case 'g': /* 802.11g */ 1426178354Ssam flags |= IEEE80211_CHAN_G; 1427178354Ssam break; 1428178354Ssam case 'n': /* 802.11n */ 1429178354Ssam flags |= IEEE80211_CHAN_HT; 1430178354Ssam break; 1431178354Ssam case 'd': /* dt = Atheros Dynamic Turbo */ 1432178354Ssam flags |= IEEE80211_CHAN_TURBO; 1433178354Ssam break; 1434178354Ssam case 't': /* ht, dt, st, t */ 1435178354Ssam /* dt and unadorned t specify Dynamic Turbo */ 1436178354Ssam if ((flags & (IEEE80211_CHAN_STURBO|IEEE80211_CHAN_HT)) == 0) 1437178354Ssam flags |= IEEE80211_CHAN_TURBO; 1438178354Ssam break; 1439178354Ssam case 's': /* st = Atheros Static Turbo */ 1440178354Ssam flags |= IEEE80211_CHAN_STURBO; 1441178354Ssam break; 1442188784Ssam case 'h': /* 1/2-width channels */ 1443188784Ssam flags |= IEEE80211_CHAN_HALF; 1444188784Ssam break; 1445188784Ssam case 'q': /* 1/4-width channels */ 1446188784Ssam flags |= IEEE80211_CHAN_QUARTER; 1447188784Ssam break; 1448178354Ssam default: 1449178354Ssam errx(-1, "%s: Invalid mode attribute %c\n", 1450178354Ssam val, *cp); 1451178354Ssam } 1452178354Ssam } 1453178354Ssam } 1454178354Ssam return flags; 1455170531Ssam} 1456170531Ssam 1457178354Ssam#define IEEE80211_CHAN_HTA (IEEE80211_CHAN_HT|IEEE80211_CHAN_5GHZ) 1458178354Ssam#define IEEE80211_CHAN_HTG (IEEE80211_CHAN_HT|IEEE80211_CHAN_2GHZ) 1459178354Ssam 1460178354Ssam#define _APPLY(_flags, _base, _param, _v) do { \ 1461178354Ssam if (_flags & IEEE80211_CHAN_HT) { \ 1462178354Ssam if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\ 1463178354Ssam _base.params[IEEE80211_MODE_11NA]._param = _v; \ 1464178354Ssam _base.params[IEEE80211_MODE_11NG]._param = _v; \ 1465178354Ssam } else if (_flags & IEEE80211_CHAN_5GHZ) \ 1466178354Ssam _base.params[IEEE80211_MODE_11NA]._param = _v; \ 1467178354Ssam else \ 1468178354Ssam _base.params[IEEE80211_MODE_11NG]._param = _v; \ 1469178354Ssam } \ 1470178354Ssam if (_flags & IEEE80211_CHAN_TURBO) { \ 1471178354Ssam if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\ 1472178354Ssam _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \ 1473178354Ssam _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \ 1474178354Ssam } else if (_flags & IEEE80211_CHAN_5GHZ) \ 1475178354Ssam _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \ 1476178354Ssam else \ 1477178354Ssam _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \ 1478178354Ssam } \ 1479178354Ssam if (_flags & IEEE80211_CHAN_STURBO) \ 1480178354Ssam _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \ 1481178354Ssam if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \ 1482178354Ssam _base.params[IEEE80211_MODE_11A]._param = _v; \ 1483178354Ssam if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \ 1484178354Ssam _base.params[IEEE80211_MODE_11G]._param = _v; \ 1485178354Ssam if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \ 1486178354Ssam _base.params[IEEE80211_MODE_11B]._param = _v; \ 1487188784Ssam if (_flags & IEEE80211_CHAN_HALF) \ 1488188784Ssam _base.params[IEEE80211_MODE_HALF]._param = _v; \ 1489188784Ssam if (_flags & IEEE80211_CHAN_QUARTER) \ 1490188784Ssam _base.params[IEEE80211_MODE_QUARTER]._param = _v; \ 1491178354Ssam} while (0) 1492178354Ssam#define _APPLY1(_flags, _base, _param, _v) do { \ 1493178354Ssam if (_flags & IEEE80211_CHAN_HT) { \ 1494178354Ssam if (_flags & IEEE80211_CHAN_5GHZ) \ 1495178354Ssam _base.params[IEEE80211_MODE_11NA]._param = _v; \ 1496178354Ssam else \ 1497178354Ssam _base.params[IEEE80211_MODE_11NG]._param = _v; \ 1498178354Ssam } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \ 1499178354Ssam _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \ 1500178354Ssam else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \ 1501178354Ssam _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \ 1502178354Ssam else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \ 1503178354Ssam _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \ 1504188784Ssam else if (_flags & IEEE80211_CHAN_HALF) \ 1505188784Ssam _base.params[IEEE80211_MODE_HALF]._param = _v; \ 1506188784Ssam else if (_flags & IEEE80211_CHAN_QUARTER) \ 1507188784Ssam _base.params[IEEE80211_MODE_QUARTER]._param = _v; \ 1508178354Ssam else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \ 1509178354Ssam _base.params[IEEE80211_MODE_11A]._param = _v; \ 1510178354Ssam else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \ 1511178354Ssam _base.params[IEEE80211_MODE_11G]._param = _v; \ 1512178354Ssam else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \ 1513178354Ssam _base.params[IEEE80211_MODE_11B]._param = _v; \ 1514178354Ssam} while (0) 1515178354Ssam#define _APPLY_RATE(_flags, _base, _param, _v) do { \ 1516178354Ssam if (_flags & IEEE80211_CHAN_HT) { \ 1517188784Ssam (_v) = (_v / 2) | IEEE80211_RATE_MCS; \ 1518178354Ssam } \ 1519188784Ssam _APPLY(_flags, _base, _param, _v); \ 1520178354Ssam} while (0) 1521178354Ssam#define _APPLY_RATE1(_flags, _base, _param, _v) do { \ 1522178354Ssam if (_flags & IEEE80211_CHAN_HT) { \ 1523188784Ssam (_v) = (_v / 2) | IEEE80211_RATE_MCS; \ 1524188784Ssam } \ 1525188784Ssam _APPLY1(_flags, _base, _param, _v); \ 1526178354Ssam} while (0) 1527178354Ssam 1528170531Ssamstatic 1529178354SsamDECL_CMD_FUNC(set80211roamrssi, val, d) 1530170531Ssam{ 1531178354Ssam double v = atof(val); 1532178354Ssam int rssi, flags; 1533178354Ssam 1534178354Ssam rssi = (int) (2*v); 1535178354Ssam if (rssi != 2*v) 1536178354Ssam errx(-1, "invalid rssi (must be .5 dBm units)"); 1537178354Ssam flags = getmodeflags(val); 1538178354Ssam getroam(s); 1539178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1540178354Ssam flags = getcurchan(s)->ic_flags; 1541178354Ssam _APPLY1(flags, roamparams, rssi, rssi); 1542178354Ssam } else 1543178354Ssam _APPLY(flags, roamparams, rssi, rssi); 1544178354Ssam callback_register(setroam_cb, &roamparams); 1545170531Ssam} 1546170531Ssam 1547188784Ssamstatic int 1548188784Ssamgetrate(const char *val, const char *tag) 1549188784Ssam{ 1550188784Ssam double v = atof(val); 1551188784Ssam int rate; 1552188784Ssam 1553188784Ssam rate = (int) (2*v); 1554188784Ssam if (rate != 2*v) 1555188784Ssam errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag); 1556188784Ssam return rate; /* NB: returns 2x the specified value */ 1557188784Ssam} 1558188784Ssam 1559170531Ssamstatic 1560178354SsamDECL_CMD_FUNC(set80211roamrate, val, d) 1561170531Ssam{ 1562188784Ssam int rate, flags; 1563178354Ssam 1564188784Ssam rate = getrate(val, "roam"); 1565178354Ssam flags = getmodeflags(val); 1566178354Ssam getroam(s); 1567178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1568178354Ssam flags = getcurchan(s)->ic_flags; 1569188784Ssam _APPLY_RATE1(flags, roamparams, rate, rate); 1570178354Ssam } else 1571188784Ssam _APPLY_RATE(flags, roamparams, rate, rate); 1572178354Ssam callback_register(setroam_cb, &roamparams); 1573170531Ssam} 1574170531Ssam 1575170531Ssamstatic 1576178354SsamDECL_CMD_FUNC(set80211mcastrate, val, d) 1577170531Ssam{ 1578188784Ssam int rate, flags; 1579178354Ssam 1580188784Ssam rate = getrate(val, "mcast"); 1581178354Ssam flags = getmodeflags(val); 1582178354Ssam gettxparams(s); 1583178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1584178354Ssam flags = getcurchan(s)->ic_flags; 1585188784Ssam _APPLY_RATE1(flags, txparams, mcastrate, rate); 1586178354Ssam } else 1587188784Ssam _APPLY_RATE(flags, txparams, mcastrate, rate); 1588178354Ssam callback_register(settxparams_cb, &txparams); 1589170531Ssam} 1590170531Ssam 1591170531Ssamstatic 1592178354SsamDECL_CMD_FUNC(set80211mgtrate, val, d) 1593170531Ssam{ 1594188784Ssam int rate, flags; 1595178354Ssam 1596188784Ssam rate = getrate(val, "mgmt"); 1597178354Ssam flags = getmodeflags(val); 1598178354Ssam gettxparams(s); 1599178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1600178354Ssam flags = getcurchan(s)->ic_flags; 1601188784Ssam _APPLY_RATE1(flags, txparams, mgmtrate, rate); 1602178354Ssam } else 1603188784Ssam _APPLY_RATE(flags, txparams, mgmtrate, rate); 1604178354Ssam callback_register(settxparams_cb, &txparams); 1605170531Ssam} 1606170531Ssam 1607170531Ssamstatic 1608178354SsamDECL_CMD_FUNC(set80211ucastrate, val, d) 1609170531Ssam{ 1610188784Ssam int flags; 1611178354Ssam 1612178354Ssam gettxparams(s); 1613178354Ssam flags = getmodeflags(val); 1614178354Ssam if (isanyarg(val)) { 1615178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1616178354Ssam flags = getcurchan(s)->ic_flags; 1617178354Ssam _APPLY1(flags, txparams, ucastrate, 1618178354Ssam IEEE80211_FIXED_RATE_NONE); 1619178354Ssam } else 1620178354Ssam _APPLY(flags, txparams, ucastrate, 1621178354Ssam IEEE80211_FIXED_RATE_NONE); 1622178354Ssam } else { 1623188784Ssam int rate = getrate(val, "ucast"); 1624178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1625178354Ssam flags = getcurchan(s)->ic_flags; 1626188784Ssam _APPLY_RATE1(flags, txparams, ucastrate, rate); 1627178354Ssam } else 1628188784Ssam _APPLY_RATE(flags, txparams, ucastrate, rate); 1629178354Ssam } 1630178354Ssam callback_register(settxparams_cb, &txparams); 1631170531Ssam} 1632170531Ssam 1633170531Ssamstatic 1634178354SsamDECL_CMD_FUNC(set80211maxretry, val, d) 1635153354Ssam{ 1636178354Ssam int v = atoi(val), flags; 1637178354Ssam 1638178354Ssam flags = getmodeflags(val); 1639178354Ssam gettxparams(s); 1640178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1641178354Ssam flags = getcurchan(s)->ic_flags; 1642178354Ssam _APPLY1(flags, txparams, maxretry, v); 1643178354Ssam } else 1644178354Ssam _APPLY(flags, txparams, maxretry, v); 1645178354Ssam callback_register(settxparams_cb, &txparams); 1646153354Ssam} 1647178354Ssam#undef _APPLY_RATE 1648178354Ssam#undef _APPLY 1649178354Ssam#undef IEEE80211_CHAN_HTA 1650178354Ssam#undef IEEE80211_CHAN_HTG 1651153354Ssam 1652153354Ssamstatic 1653148416SsamDECL_CMD_FUNC(set80211fragthreshold, val, d) 1654148416Ssam{ 1655148416Ssam set80211(s, IEEE80211_IOC_FRAGTHRESHOLD, 1656148416Ssam isundefarg(val) ? IEEE80211_FRAG_MAX : atoi(val), 0, NULL); 1657148416Ssam} 1658148416Ssam 1659160687Ssamstatic 1660160687SsamDECL_CMD_FUNC(set80211bmissthreshold, val, d) 1661160687Ssam{ 1662160687Ssam set80211(s, IEEE80211_IOC_BMISSTHRESHOLD, 1663160687Ssam isundefarg(val) ? IEEE80211_HWBMISS_MAX : atoi(val), 0, NULL); 1664160687Ssam} 1665160687Ssam 1666170531Ssamstatic void 1667170531Ssamset80211burst(const char *val, int d, int s, const struct afswtch *rafp) 1668170531Ssam{ 1669170531Ssam set80211(s, IEEE80211_IOC_BURST, d, 0, NULL); 1670170531Ssam} 1671170531Ssam 1672170531Ssamstatic void 1673170531Ssamset80211doth(const char *val, int d, int s, const struct afswtch *rafp) 1674170531Ssam{ 1675170531Ssam set80211(s, IEEE80211_IOC_DOTH, d, 0, NULL); 1676170531Ssam} 1677170531Ssam 1678173275Ssamstatic void 1679178354Ssamset80211dfs(const char *val, int d, int s, const struct afswtch *rafp) 1680178354Ssam{ 1681178354Ssam set80211(s, IEEE80211_IOC_DFS, d, 0, NULL); 1682178354Ssam} 1683178354Ssam 1684178354Ssamstatic void 1685173275Ssamset80211shortgi(const char *val, int d, int s, const struct afswtch *rafp) 1686173275Ssam{ 1687173275Ssam set80211(s, IEEE80211_IOC_SHORTGI, 1688173275Ssam d ? (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) : 0, 1689173275Ssam 0, NULL); 1690173275Ssam} 1691173275Ssam 1692173275Ssamstatic void 1693173275Ssamset80211ampdu(const char *val, int d, int s, const struct afswtch *rafp) 1694173275Ssam{ 1695173275Ssam int ampdu; 1696173275Ssam 1697173275Ssam if (get80211val(s, IEEE80211_IOC_AMPDU, &du) < 0) 1698173275Ssam errx(-1, "cannot get AMPDU setting"); 1699173275Ssam if (d < 0) { 1700173275Ssam d = -d; 1701173275Ssam ampdu &= ~d; 1702173275Ssam } else 1703173275Ssam ampdu |= d; 1704173275Ssam set80211(s, IEEE80211_IOC_AMPDU, ampdu, 0, NULL); 1705173275Ssam} 1706173275Ssam 1707173275Ssamstatic 1708173275SsamDECL_CMD_FUNC(set80211ampdulimit, val, d) 1709173275Ssam{ 1710173275Ssam int v; 1711173275Ssam 1712173275Ssam switch (atoi(val)) { 1713173275Ssam case 8: 1714173275Ssam case 8*1024: 1715173275Ssam v = IEEE80211_HTCAP_MAXRXAMPDU_8K; 1716173275Ssam break; 1717173275Ssam case 16: 1718173275Ssam case 16*1024: 1719173275Ssam v = IEEE80211_HTCAP_MAXRXAMPDU_16K; 1720173275Ssam break; 1721173275Ssam case 32: 1722173275Ssam case 32*1024: 1723173275Ssam v = IEEE80211_HTCAP_MAXRXAMPDU_32K; 1724173275Ssam break; 1725173275Ssam case 64: 1726173275Ssam case 64*1024: 1727173275Ssam v = IEEE80211_HTCAP_MAXRXAMPDU_64K; 1728173275Ssam break; 1729173275Ssam default: 1730173275Ssam errx(-1, "invalid A-MPDU limit %s", val); 1731173275Ssam } 1732173275Ssam set80211(s, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL); 1733173275Ssam} 1734173275Ssam 1735173275Ssamstatic 1736173275SsamDECL_CMD_FUNC(set80211ampdudensity, val, d) 1737173275Ssam{ 1738173275Ssam int v; 1739173275Ssam 1740183260Ssam if (isanyarg(val) || strcasecmp(val, "na") == 0) 1741173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_NA; 1742173275Ssam else switch ((int)(atof(val)*4)) { 1743173275Ssam case 0: 1744173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_NA; 1745173275Ssam break; 1746173275Ssam case 1: 1747173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_025; 1748173275Ssam break; 1749173275Ssam case 2: 1750173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_05; 1751173275Ssam break; 1752173275Ssam case 4: 1753173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_1; 1754173275Ssam break; 1755173275Ssam case 8: 1756173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_2; 1757173275Ssam break; 1758173275Ssam case 16: 1759173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_4; 1760173275Ssam break; 1761173275Ssam case 32: 1762173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_8; 1763173275Ssam break; 1764173275Ssam case 64: 1765173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_16; 1766173275Ssam break; 1767173275Ssam default: 1768173275Ssam errx(-1, "invalid A-MPDU density %s", val); 1769173275Ssam } 1770173275Ssam set80211(s, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL); 1771173275Ssam} 1772173275Ssam 1773173275Ssamstatic void 1774173275Ssamset80211amsdu(const char *val, int d, int s, const struct afswtch *rafp) 1775173275Ssam{ 1776173275Ssam int amsdu; 1777173275Ssam 1778173275Ssam if (get80211val(s, IEEE80211_IOC_AMSDU, &amsdu) < 0) 1779187801Ssam err(-1, "cannot get AMSDU setting"); 1780173275Ssam if (d < 0) { 1781173275Ssam d = -d; 1782173275Ssam amsdu &= ~d; 1783173275Ssam } else 1784173275Ssam amsdu |= d; 1785173275Ssam set80211(s, IEEE80211_IOC_AMSDU, amsdu, 0, NULL); 1786173275Ssam} 1787173275Ssam 1788173275Ssamstatic 1789173275SsamDECL_CMD_FUNC(set80211amsdulimit, val, d) 1790173275Ssam{ 1791173275Ssam set80211(s, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL); 1792173275Ssam} 1793173275Ssam 1794173275Ssamstatic void 1795173275Ssamset80211puren(const char *val, int d, int s, const struct afswtch *rafp) 1796173275Ssam{ 1797173275Ssam set80211(s, IEEE80211_IOC_PUREN, d, 0, NULL); 1798173275Ssam} 1799173275Ssam 1800173275Ssamstatic void 1801173275Ssamset80211htcompat(const char *val, int d, int s, const struct afswtch *rafp) 1802173275Ssam{ 1803173275Ssam set80211(s, IEEE80211_IOC_HTCOMPAT, d, 0, NULL); 1804173275Ssam} 1805173275Ssam 1806173275Ssamstatic void 1807173275Ssamset80211htconf(const char *val, int d, int s, const struct afswtch *rafp) 1808173275Ssam{ 1809173275Ssam set80211(s, IEEE80211_IOC_HTCONF, d, 0, NULL); 1810173275Ssam htconf = d; 1811173275Ssam} 1812173275Ssam 1813173275Ssamstatic void 1814178354Ssamset80211dwds(const char *val, int d, int s, const struct afswtch *rafp) 1815178354Ssam{ 1816178354Ssam set80211(s, IEEE80211_IOC_DWDS, d, 0, NULL); 1817178354Ssam} 1818178354Ssam 1819178354Ssamstatic void 1820173275Ssamset80211inact(const char *val, int d, int s, const struct afswtch *rafp) 1821173275Ssam{ 1822173275Ssam set80211(s, IEEE80211_IOC_INACTIVITY, d, 0, NULL); 1823173275Ssam} 1824173275Ssam 1825173275Ssamstatic void 1826178354Ssamset80211tsn(const char *val, int d, int s, const struct afswtch *rafp) 1827178354Ssam{ 1828178354Ssam set80211(s, IEEE80211_IOC_TSN, d, 0, NULL); 1829178354Ssam} 1830178354Ssam 1831178354Ssamstatic void 1832178354Ssamset80211dotd(const char *val, int d, int s, const struct afswtch *rafp) 1833178354Ssam{ 1834178354Ssam set80211(s, IEEE80211_IOC_DOTD, d, 0, NULL); 1835178354Ssam} 1836178354Ssam 1837183261Ssamstatic void 1838183261Ssamset80211smps(const char *val, int d, int s, const struct afswtch *rafp) 1839183261Ssam{ 1840183261Ssam set80211(s, IEEE80211_IOC_SMPS, d, 0, NULL); 1841183261Ssam} 1842183261Ssam 1843183261Ssamstatic void 1844183261Ssamset80211rifs(const char *val, int d, int s, const struct afswtch *rafp) 1845183261Ssam{ 1846183261Ssam set80211(s, IEEE80211_IOC_RIFS, d, 0, NULL); 1847183261Ssam} 1848183261Ssam 1849186904Ssamstatic 1850186904SsamDECL_CMD_FUNC(set80211tdmaslot, val, d) 1851186904Ssam{ 1852186904Ssam set80211(s, IEEE80211_IOC_TDMA_SLOT, atoi(val), 0, NULL); 1853186904Ssam} 1854186904Ssam 1855186904Ssamstatic 1856186904SsamDECL_CMD_FUNC(set80211tdmaslotcnt, val, d) 1857186904Ssam{ 1858186904Ssam set80211(s, IEEE80211_IOC_TDMA_SLOTCNT, atoi(val), 0, NULL); 1859186904Ssam} 1860186904Ssam 1861186904Ssamstatic 1862186904SsamDECL_CMD_FUNC(set80211tdmaslotlen, val, d) 1863186904Ssam{ 1864186904Ssam set80211(s, IEEE80211_IOC_TDMA_SLOTLEN, atoi(val), 0, NULL); 1865186904Ssam} 1866186904Ssam 1867186904Ssamstatic 1868186904SsamDECL_CMD_FUNC(set80211tdmabintval, val, d) 1869186904Ssam{ 1870186904Ssam set80211(s, IEEE80211_IOC_TDMA_BINTERVAL, atoi(val), 0, NULL); 1871186904Ssam} 1872186904Ssam 1873195618Srpaulostatic 1874195618SrpauloDECL_CMD_FUNC(set80211meshttl, val, d) 1875195618Srpaulo{ 1876195618Srpaulo set80211(s, IEEE80211_IOC_MESH_TTL, atoi(val), 0, NULL); 1877195618Srpaulo} 1878195618Srpaulo 1879195618Srpaulostatic 1880195618SrpauloDECL_CMD_FUNC(set80211meshforward, val, d) 1881195618Srpaulo{ 1882233328Sadrian set80211(s, IEEE80211_IOC_MESH_FWRD, d, 0, NULL); 1883195618Srpaulo} 1884195618Srpaulo 1885195618Srpaulostatic 1886234893SmonthadarDECL_CMD_FUNC(set80211meshgate, val, d) 1887234893Smonthadar{ 1888234893Smonthadar set80211(s, IEEE80211_IOC_MESH_GATE, d, 0, NULL); 1889234893Smonthadar} 1890234893Smonthadar 1891234893Smonthadarstatic 1892195618SrpauloDECL_CMD_FUNC(set80211meshpeering, val, d) 1893195618Srpaulo{ 1894233382Sbschmidt set80211(s, IEEE80211_IOC_MESH_AP, d, 0, NULL); 1895195618Srpaulo} 1896195618Srpaulo 1897195618Srpaulostatic 1898195618SrpauloDECL_CMD_FUNC(set80211meshmetric, val, d) 1899195618Srpaulo{ 1900195618Srpaulo char v[12]; 1901195618Srpaulo 1902195618Srpaulo memcpy(v, val, sizeof(v)); 1903195618Srpaulo set80211(s, IEEE80211_IOC_MESH_PR_METRIC, 0, 0, v); 1904195618Srpaulo} 1905195618Srpaulo 1906195618Srpaulostatic 1907195618SrpauloDECL_CMD_FUNC(set80211meshpath, val, d) 1908195618Srpaulo{ 1909195618Srpaulo char v[12]; 1910195618Srpaulo 1911195618Srpaulo memcpy(v, val, sizeof(v)); 1912195618Srpaulo set80211(s, IEEE80211_IOC_MESH_PR_PATH, 0, 0, v); 1913195618Srpaulo} 1914195618Srpaulo 1915178354Ssamstatic int 1916178354Ssamregdomain_sort(const void *a, const void *b) 1917178354Ssam{ 1918178354Ssam#define CHAN_ALL \ 1919178354Ssam (IEEE80211_CHAN_ALLTURBO|IEEE80211_CHAN_HALF|IEEE80211_CHAN_QUARTER) 1920178354Ssam const struct ieee80211_channel *ca = a; 1921178354Ssam const struct ieee80211_channel *cb = b; 1922178354Ssam 1923178354Ssam return ca->ic_freq == cb->ic_freq ? 1924178354Ssam (ca->ic_flags & CHAN_ALL) - (cb->ic_flags & CHAN_ALL) : 1925178354Ssam ca->ic_freq - cb->ic_freq; 1926178354Ssam#undef CHAN_ALL 1927178354Ssam} 1928178354Ssam 1929178354Ssamstatic const struct ieee80211_channel * 1930178354Ssamchanlookup(const struct ieee80211_channel chans[], int nchans, 1931178354Ssam int freq, int flags) 1932178354Ssam{ 1933178354Ssam int i; 1934178354Ssam 1935178354Ssam flags &= IEEE80211_CHAN_ALLTURBO; 1936178354Ssam for (i = 0; i < nchans; i++) { 1937178354Ssam const struct ieee80211_channel *c = &chans[i]; 1938178354Ssam if (c->ic_freq == freq && 1939178354Ssam (c->ic_flags & IEEE80211_CHAN_ALLTURBO) == flags) 1940178354Ssam return c; 1941178354Ssam } 1942178354Ssam return NULL; 1943178354Ssam} 1944178354Ssam 1945187841Ssamstatic int 1946187841Ssamchanfind(const struct ieee80211_channel chans[], int nchans, int flags) 1947187841Ssam{ 1948187841Ssam int i; 1949187841Ssam 1950187841Ssam for (i = 0; i < nchans; i++) { 1951187841Ssam const struct ieee80211_channel *c = &chans[i]; 1952187841Ssam if ((c->ic_flags & flags) == flags) 1953187841Ssam return 1; 1954187841Ssam } 1955187841Ssam return 0; 1956187841Ssam} 1957187841Ssam 1958188258Ssam/* 1959188258Ssam * Check channel compatibility. 1960188258Ssam */ 1961188258Ssamstatic int 1962188258Ssamcheckchan(const struct ieee80211req_chaninfo *avail, int freq, int flags) 1963188258Ssam{ 1964188258Ssam flags &= ~REQ_FLAGS; 1965188258Ssam /* 1966188258Ssam * Check if exact channel is in the calibration table; 1967188258Ssam * everything below is to deal with channels that we 1968188258Ssam * want to include but that are not explicitly listed. 1969188258Ssam */ 1970188258Ssam if (flags & IEEE80211_CHAN_HT40) { 1971188258Ssam /* NB: we use an HT40 channel center that matches HT20 */ 1972188258Ssam flags = (flags &~ IEEE80211_CHAN_HT40) | IEEE80211_CHAN_HT20; 1973188258Ssam } 1974188258Ssam if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, flags) != NULL) 1975188258Ssam return 1; 1976188258Ssam if (flags & IEEE80211_CHAN_GSM) { 1977188258Ssam /* 1978188258Ssam * XXX GSM frequency mapping is handled in the kernel 1979188258Ssam * so we cannot find them in the calibration table; 1980188258Ssam * just accept the channel and the kernel will reject 1981188258Ssam * the channel list if it's wrong. 1982188258Ssam */ 1983188258Ssam return 1; 1984188258Ssam } 1985188258Ssam /* 1986188258Ssam * If this is a 1/2 or 1/4 width channel allow it if a full 1987188258Ssam * width channel is present for this frequency, and the device 1988188258Ssam * supports fractional channels on this band. This is a hack 1989188258Ssam * that avoids bloating the calibration table; it may be better 1990188258Ssam * by per-band attributes though (we are effectively calculating 1991188258Ssam * this attribute by scanning the channel list ourself). 1992188258Ssam */ 1993188258Ssam if ((flags & (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == 0) 1994188258Ssam return 0; 1995188258Ssam if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, 1996188258Ssam flags &~ (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == NULL) 1997188258Ssam return 0; 1998188258Ssam if (flags & IEEE80211_CHAN_HALF) { 1999188258Ssam return chanfind(avail->ic_chans, avail->ic_nchans, 2000188258Ssam IEEE80211_CHAN_HALF | 2001188258Ssam (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ))); 2002188258Ssam } else { 2003188258Ssam return chanfind(avail->ic_chans, avail->ic_nchans, 2004188258Ssam IEEE80211_CHAN_QUARTER | 2005188258Ssam (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ))); 2006188258Ssam } 2007188258Ssam} 2008188258Ssam 2009178354Ssamstatic void 2010178354Ssamregdomain_addchans(struct ieee80211req_chaninfo *ci, 2011178354Ssam const netband_head *bands, 2012178354Ssam const struct ieee80211_regdomain *reg, 2013178354Ssam uint32_t chanFlags, 2014178354Ssam const struct ieee80211req_chaninfo *avail) 2015178354Ssam{ 2016178354Ssam const struct netband *nb; 2017178354Ssam const struct freqband *b; 2018178354Ssam struct ieee80211_channel *c, *prev; 2019188258Ssam int freq, hi_adj, lo_adj, channelSep; 2020188258Ssam uint32_t flags; 2021178354Ssam 2022188258Ssam hi_adj = (chanFlags & IEEE80211_CHAN_HT40U) ? -20 : 0; 2023188258Ssam lo_adj = (chanFlags & IEEE80211_CHAN_HT40D) ? 20 : 0; 2024178354Ssam channelSep = (chanFlags & IEEE80211_CHAN_2GHZ) ? 0 : 40; 2025178354Ssam LIST_FOREACH(nb, bands, next) { 2026178354Ssam b = nb->band; 2027187842Ssam if (verbose) { 2028187842Ssam printf("%s:", __func__); 2029187842Ssam printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS); 2030187842Ssam printb(" bandFlags", nb->flags | b->flags, 2031187842Ssam IEEE80211_CHAN_BITS); 2032187842Ssam putchar('\n'); 2033187842Ssam } 2034178354Ssam prev = NULL; 2035188258Ssam for (freq = b->freqStart + lo_adj; 2036188258Ssam freq <= b->freqEnd + hi_adj; freq += b->chanSep) { 2037187841Ssam /* 2038188258Ssam * Construct flags for the new channel. We take 2039188258Ssam * the attributes from the band descriptions except 2040188258Ssam * for HT40 which is enabled generically (i.e. +/- 2041188258Ssam * extension channel) in the band description and 2042188258Ssam * then constrained according by channel separation. 2043187841Ssam */ 2044188258Ssam flags = nb->flags | b->flags; 2045188258Ssam if (flags & IEEE80211_CHAN_HT) { 2046188258Ssam /* 2047188258Ssam * HT channels are generated specially; we're 2048188258Ssam * called to add HT20, HT40+, and HT40- chan's 2049188258Ssam * so we need to expand only band specs for 2050188258Ssam * the HT channel type being added. 2051188258Ssam */ 2052188258Ssam if ((chanFlags & IEEE80211_CHAN_HT20) && 2053188258Ssam (flags & IEEE80211_CHAN_HT20) == 0) { 2054188258Ssam if (verbose) 2055188258Ssam printf("%u: skip, not an " 2056188258Ssam "HT20 channel\n", freq); 2057188258Ssam continue; 2058188258Ssam } 2059188258Ssam if ((chanFlags & IEEE80211_CHAN_HT40) && 2060188258Ssam (flags & IEEE80211_CHAN_HT40) == 0) { 2061188258Ssam if (verbose) 2062188258Ssam printf("%u: skip, not an " 2063188258Ssam "HT40 channel\n", freq); 2064188258Ssam continue; 2065188258Ssam } 2066188258Ssam /* NB: HT attribute comes from caller */ 2067188258Ssam flags &= ~IEEE80211_CHAN_HT; 2068188258Ssam flags |= chanFlags & IEEE80211_CHAN_HT; 2069188258Ssam } 2070188258Ssam /* 2071188258Ssam * Check if device can operate on this frequency. 2072188258Ssam */ 2073188258Ssam if (!checkchan(avail, freq, flags)) { 2074187842Ssam if (verbose) { 2075187842Ssam printf("%u: skip, ", freq); 2076188258Ssam printb("flags", flags, 2077187842Ssam IEEE80211_CHAN_BITS); 2078187842Ssam printf(" not available\n"); 2079187842Ssam } 2080178354Ssam continue; 2081178354Ssam } 2082188258Ssam if ((flags & REQ_ECM) && !reg->ecm) { 2083178354Ssam if (verbose) 2084188258Ssam printf("%u: skip, ECM channel\n", freq); 2085178354Ssam continue; 2086178354Ssam } 2087188258Ssam if ((flags & REQ_INDOOR) && reg->location == 'O') { 2088178354Ssam if (verbose) 2089188258Ssam printf("%u: skip, indoor channel\n", 2090187841Ssam freq); 2091178354Ssam continue; 2092178354Ssam } 2093178354Ssam if ((flags & REQ_OUTDOOR) && reg->location == 'I') { 2094178354Ssam if (verbose) 2095188258Ssam printf("%u: skip, outdoor channel\n", 2096188258Ssam freq); 2097178354Ssam continue; 2098178354Ssam } 2099178354Ssam if ((flags & IEEE80211_CHAN_HT40) && 2100178354Ssam prev != NULL && (freq - prev->ic_freq) < channelSep) { 2101178354Ssam if (verbose) 2102178354Ssam printf("%u: skip, only %u channel " 2103178354Ssam "separation, need %d\n", freq, 2104178354Ssam freq - prev->ic_freq, channelSep); 2105178354Ssam continue; 2106178354Ssam } 2107178354Ssam if (ci->ic_nchans == IEEE80211_CHAN_MAX) { 2108178354Ssam if (verbose) 2109187842Ssam printf("%u: skip, channel table full\n", 2110187842Ssam freq); 2111178354Ssam break; 2112178354Ssam } 2113178354Ssam c = &ci->ic_chans[ci->ic_nchans++]; 2114187801Ssam memset(c, 0, sizeof(*c)); 2115178354Ssam c->ic_freq = freq; 2116188258Ssam c->ic_flags = flags; 2117178354Ssam if (c->ic_flags & IEEE80211_CHAN_DFS) 2118178354Ssam c->ic_maxregpower = nb->maxPowerDFS; 2119178354Ssam else 2120178354Ssam c->ic_maxregpower = nb->maxPower; 2121187842Ssam if (verbose) { 2122187842Ssam printf("[%3d] add freq %u ", 2123187842Ssam ci->ic_nchans-1, c->ic_freq); 2124187842Ssam printb("flags", c->ic_flags, IEEE80211_CHAN_BITS); 2125187842Ssam printf(" power %u\n", c->ic_maxregpower); 2126187842Ssam } 2127178354Ssam /* NB: kernel fills in other fields */ 2128178354Ssam prev = c; 2129178354Ssam } 2130178354Ssam } 2131178354Ssam} 2132178354Ssam 2133178354Ssamstatic void 2134178354Ssamregdomain_makechannels( 2135178354Ssam struct ieee80211_regdomain_req *req, 2136178354Ssam const struct ieee80211_devcaps_req *dc) 2137178354Ssam{ 2138178354Ssam struct regdata *rdp = getregdata(); 2139178354Ssam const struct country *cc; 2140178354Ssam const struct ieee80211_regdomain *reg = &req->rd; 2141178354Ssam struct ieee80211req_chaninfo *ci = &req->chaninfo; 2142178354Ssam const struct regdomain *rd; 2143178354Ssam 2144178354Ssam /* 2145178354Ssam * Locate construction table for new channel list. We treat 2146178354Ssam * the regdomain/SKU as definitive so a country can be in 2147178354Ssam * multiple with different properties (e.g. US in FCC+FCC3). 2148178354Ssam * If no regdomain is specified then we fallback on the country 2149178354Ssam * code to find the associated regdomain since countries always 2150178354Ssam * belong to at least one regdomain. 2151178354Ssam */ 2152178354Ssam if (reg->regdomain == 0) { 2153178354Ssam cc = lib80211_country_findbycc(rdp, reg->country); 2154178354Ssam if (cc == NULL) 2155178354Ssam errx(1, "internal error, country %d not found", 2156178354Ssam reg->country); 2157178354Ssam rd = cc->rd; 2158178354Ssam } else 2159178354Ssam rd = lib80211_regdomain_findbysku(rdp, reg->regdomain); 2160178354Ssam if (rd == NULL) 2161178354Ssam errx(1, "internal error, regdomain %d not found", 2162178354Ssam reg->regdomain); 2163178354Ssam if (rd->sku != SKU_DEBUG) { 2164187801Ssam /* 2165187801Ssam * regdomain_addchans incrememnts the channel count for 2166187801Ssam * each channel it adds so initialize ic_nchans to zero. 2167187801Ssam * Note that we know we have enough space to hold all possible 2168187801Ssam * channels because the devcaps list size was used to 2169187801Ssam * allocate our request. 2170187801Ssam */ 2171187801Ssam ci->ic_nchans = 0; 2172178354Ssam if (!LIST_EMPTY(&rd->bands_11b)) 2173178354Ssam regdomain_addchans(ci, &rd->bands_11b, reg, 2174178354Ssam IEEE80211_CHAN_B, &dc->dc_chaninfo); 2175187841Ssam if (!LIST_EMPTY(&rd->bands_11g)) 2176178354Ssam regdomain_addchans(ci, &rd->bands_11g, reg, 2177178354Ssam IEEE80211_CHAN_G, &dc->dc_chaninfo); 2178187841Ssam if (!LIST_EMPTY(&rd->bands_11a)) 2179178354Ssam regdomain_addchans(ci, &rd->bands_11a, reg, 2180178354Ssam IEEE80211_CHAN_A, &dc->dc_chaninfo); 2181188258Ssam if (!LIST_EMPTY(&rd->bands_11na) && dc->dc_htcaps != 0) { 2182178354Ssam regdomain_addchans(ci, &rd->bands_11na, reg, 2183178354Ssam IEEE80211_CHAN_A | IEEE80211_CHAN_HT20, 2184178354Ssam &dc->dc_chaninfo); 2185188258Ssam if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) { 2186188258Ssam regdomain_addchans(ci, &rd->bands_11na, reg, 2187188258Ssam IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U, 2188188258Ssam &dc->dc_chaninfo); 2189188258Ssam regdomain_addchans(ci, &rd->bands_11na, reg, 2190188258Ssam IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D, 2191188258Ssam &dc->dc_chaninfo); 2192188258Ssam } 2193178354Ssam } 2194188258Ssam if (!LIST_EMPTY(&rd->bands_11ng) && dc->dc_htcaps != 0) { 2195178354Ssam regdomain_addchans(ci, &rd->bands_11ng, reg, 2196178354Ssam IEEE80211_CHAN_G | IEEE80211_CHAN_HT20, 2197178354Ssam &dc->dc_chaninfo); 2198188258Ssam if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) { 2199188258Ssam regdomain_addchans(ci, &rd->bands_11ng, reg, 2200188258Ssam IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U, 2201188258Ssam &dc->dc_chaninfo); 2202188258Ssam regdomain_addchans(ci, &rd->bands_11ng, reg, 2203188258Ssam IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D, 2204188258Ssam &dc->dc_chaninfo); 2205188258Ssam } 2206178354Ssam } 2207178354Ssam qsort(ci->ic_chans, ci->ic_nchans, sizeof(ci->ic_chans[0]), 2208178354Ssam regdomain_sort); 2209178354Ssam } else 2210187801Ssam memcpy(ci, &dc->dc_chaninfo, 2211187801Ssam IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo)); 2212178354Ssam} 2213178354Ssam 2214178354Ssamstatic void 2215178354Ssamlist_countries(void) 2216178354Ssam{ 2217178354Ssam struct regdata *rdp = getregdata(); 2218178354Ssam const struct country *cp; 2219178354Ssam const struct regdomain *dp; 2220178354Ssam int i; 2221178354Ssam 2222178354Ssam i = 0; 2223178354Ssam printf("\nCountry codes:\n"); 2224178354Ssam LIST_FOREACH(cp, &rdp->countries, next) { 2225178354Ssam printf("%2s %-15.15s%s", cp->isoname, 2226178354Ssam cp->name, ((i+1)%4) == 0 ? "\n" : " "); 2227178354Ssam i++; 2228178354Ssam } 2229178354Ssam i = 0; 2230178354Ssam printf("\nRegulatory domains:\n"); 2231178354Ssam LIST_FOREACH(dp, &rdp->domains, next) { 2232178354Ssam printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " "); 2233178354Ssam i++; 2234178354Ssam } 2235178354Ssam printf("\n"); 2236178354Ssam} 2237178354Ssam 2238178354Ssamstatic void 2239178354Ssamdefaultcountry(const struct regdomain *rd) 2240178354Ssam{ 2241178354Ssam struct regdata *rdp = getregdata(); 2242178354Ssam const struct country *cc; 2243178354Ssam 2244178354Ssam cc = lib80211_country_findbycc(rdp, rd->cc->code); 2245178354Ssam if (cc == NULL) 2246178354Ssam errx(1, "internal error, ISO country code %d not " 2247178354Ssam "defined for regdomain %s", rd->cc->code, rd->name); 2248178354Ssam regdomain.country = cc->code; 2249178354Ssam regdomain.isocc[0] = cc->isoname[0]; 2250178354Ssam regdomain.isocc[1] = cc->isoname[1]; 2251178354Ssam} 2252178354Ssam 2253178354Ssamstatic 2254178354SsamDECL_CMD_FUNC(set80211regdomain, val, d) 2255178354Ssam{ 2256178354Ssam struct regdata *rdp = getregdata(); 2257178354Ssam const struct regdomain *rd; 2258178354Ssam 2259178354Ssam rd = lib80211_regdomain_findbyname(rdp, val); 2260178354Ssam if (rd == NULL) { 2261186104Ssam char *eptr; 2262186104Ssam long sku = strtol(val, &eptr, 0); 2263186104Ssam 2264186104Ssam if (eptr != val) 2265186104Ssam rd = lib80211_regdomain_findbysku(rdp, sku); 2266186104Ssam if (eptr == val || rd == NULL) 2267178354Ssam errx(1, "unknown regdomain %s", val); 2268178354Ssam } 2269178354Ssam getregdomain(s); 2270178354Ssam regdomain.regdomain = rd->sku; 2271178354Ssam if (regdomain.country == 0 && rd->cc != NULL) { 2272178354Ssam /* 2273178354Ssam * No country code setup and there's a default 2274178354Ssam * one for this regdomain fill it in. 2275178354Ssam */ 2276178354Ssam defaultcountry(rd); 2277178354Ssam } 2278178354Ssam callback_register(setregdomain_cb, ®domain); 2279178354Ssam} 2280178354Ssam 2281178354Ssamstatic 2282178354SsamDECL_CMD_FUNC(set80211country, val, d) 2283178354Ssam{ 2284178354Ssam struct regdata *rdp = getregdata(); 2285178354Ssam const struct country *cc; 2286178354Ssam 2287178354Ssam cc = lib80211_country_findbyname(rdp, val); 2288178354Ssam if (cc == NULL) { 2289186103Ssam char *eptr; 2290186103Ssam long code = strtol(val, &eptr, 0); 2291186103Ssam 2292186103Ssam if (eptr != val) 2293186103Ssam cc = lib80211_country_findbycc(rdp, code); 2294186103Ssam if (eptr == val || cc == NULL) 2295178354Ssam errx(1, "unknown ISO country code %s", val); 2296178354Ssam } 2297178354Ssam getregdomain(s); 2298178354Ssam regdomain.regdomain = cc->rd->sku; 2299178354Ssam regdomain.country = cc->code; 2300178354Ssam regdomain.isocc[0] = cc->isoname[0]; 2301178354Ssam regdomain.isocc[1] = cc->isoname[1]; 2302178354Ssam callback_register(setregdomain_cb, ®domain); 2303178354Ssam} 2304178354Ssam 2305178354Ssamstatic void 2306178354Ssamset80211location(const char *val, int d, int s, const struct afswtch *rafp) 2307178354Ssam{ 2308178354Ssam getregdomain(s); 2309178354Ssam regdomain.location = d; 2310178354Ssam callback_register(setregdomain_cb, ®domain); 2311178354Ssam} 2312178354Ssam 2313178354Ssamstatic void 2314178354Ssamset80211ecm(const char *val, int d, int s, const struct afswtch *rafp) 2315178354Ssam{ 2316178354Ssam getregdomain(s); 2317178354Ssam regdomain.ecm = d; 2318178354Ssam callback_register(setregdomain_cb, ®domain); 2319178354Ssam} 2320178354Ssam 2321178354Ssamstatic void 2322173275SsamLINE_INIT(char c) 2323173275Ssam{ 2324173275Ssam spacer = c; 2325173275Ssam if (c == '\t') 2326173275Ssam col = 8; 2327173275Ssam else 2328173275Ssam col = 1; 2329173275Ssam} 2330173275Ssam 2331173275Ssamstatic void 2332173275SsamLINE_BREAK(void) 2333173275Ssam{ 2334173275Ssam if (spacer != '\t') { 2335173275Ssam printf("\n"); 2336173275Ssam spacer = '\t'; 2337173275Ssam } 2338173275Ssam col = 8; /* 8-col tab */ 2339173275Ssam} 2340173275Ssam 2341173275Ssamstatic void 2342173275SsamLINE_CHECK(const char *fmt, ...) 2343173275Ssam{ 2344173275Ssam char buf[80]; 2345173275Ssam va_list ap; 2346173275Ssam int n; 2347173275Ssam 2348173275Ssam va_start(ap, fmt); 2349173275Ssam n = vsnprintf(buf+1, sizeof(buf)-1, fmt, ap); 2350173275Ssam va_end(ap); 2351173275Ssam col += 1+n; 2352173275Ssam if (col > MAXCOL) { 2353173275Ssam LINE_BREAK(); 2354173275Ssam col += n; 2355173275Ssam } 2356173275Ssam buf[0] = spacer; 2357173275Ssam printf("%s", buf); 2358173275Ssam spacer = ' '; 2359173275Ssam} 2360173275Ssam 2361138593Ssamstatic int 2362170531Ssamgetmaxrate(const uint8_t rates[15], uint8_t nrates) 2363138593Ssam{ 2364138593Ssam int i, maxrate = -1; 2365138593Ssam 2366138593Ssam for (i = 0; i < nrates; i++) { 2367138593Ssam int rate = rates[i] & IEEE80211_RATE_VAL; 2368138593Ssam if (rate > maxrate) 2369138593Ssam maxrate = rate; 2370138593Ssam } 2371138593Ssam return maxrate / 2; 2372138593Ssam} 2373138593Ssam 2374138593Ssamstatic const char * 2375138593Ssamgetcaps(int capinfo) 2376138593Ssam{ 2377138593Ssam static char capstring[32]; 2378138593Ssam char *cp = capstring; 2379138593Ssam 2380138593Ssam if (capinfo & IEEE80211_CAPINFO_ESS) 2381138593Ssam *cp++ = 'E'; 2382138593Ssam if (capinfo & IEEE80211_CAPINFO_IBSS) 2383138593Ssam *cp++ = 'I'; 2384138593Ssam if (capinfo & IEEE80211_CAPINFO_CF_POLLABLE) 2385138593Ssam *cp++ = 'c'; 2386138593Ssam if (capinfo & IEEE80211_CAPINFO_CF_POLLREQ) 2387138593Ssam *cp++ = 'C'; 2388138593Ssam if (capinfo & IEEE80211_CAPINFO_PRIVACY) 2389138593Ssam *cp++ = 'P'; 2390138593Ssam if (capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE) 2391138593Ssam *cp++ = 'S'; 2392138593Ssam if (capinfo & IEEE80211_CAPINFO_PBCC) 2393138593Ssam *cp++ = 'B'; 2394138593Ssam if (capinfo & IEEE80211_CAPINFO_CHNL_AGILITY) 2395138593Ssam *cp++ = 'A'; 2396138593Ssam if (capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME) 2397138593Ssam *cp++ = 's'; 2398138593Ssam if (capinfo & IEEE80211_CAPINFO_RSN) 2399138593Ssam *cp++ = 'R'; 2400138593Ssam if (capinfo & IEEE80211_CAPINFO_DSSSOFDM) 2401138593Ssam *cp++ = 'D'; 2402138593Ssam *cp = '\0'; 2403138593Ssam return capstring; 2404138593Ssam} 2405138593Ssam 2406159885Ssamstatic const char * 2407159885Ssamgetflags(int flags) 2408159885Ssam{ 2409159885Ssam static char flagstring[32]; 2410159885Ssam char *cp = flagstring; 2411159885Ssam 2412159885Ssam if (flags & IEEE80211_NODE_AUTH) 2413159885Ssam *cp++ = 'A'; 2414159885Ssam if (flags & IEEE80211_NODE_QOS) 2415159885Ssam *cp++ = 'Q'; 2416159885Ssam if (flags & IEEE80211_NODE_ERP) 2417159885Ssam *cp++ = 'E'; 2418159885Ssam if (flags & IEEE80211_NODE_PWR_MGT) 2419159885Ssam *cp++ = 'P'; 2420173275Ssam if (flags & IEEE80211_NODE_HT) { 2421170531Ssam *cp++ = 'H'; 2422173275Ssam if (flags & IEEE80211_NODE_HTCOMPAT) 2423173275Ssam *cp++ = '+'; 2424173275Ssam } 2425173275Ssam if (flags & IEEE80211_NODE_WPS) 2426173275Ssam *cp++ = 'W'; 2427173275Ssam if (flags & IEEE80211_NODE_TSN) 2428183261Ssam *cp++ = 'N'; 2429183261Ssam if (flags & IEEE80211_NODE_AMPDU_TX) 2430173275Ssam *cp++ = 'T'; 2431183261Ssam if (flags & IEEE80211_NODE_AMPDU_RX) 2432183261Ssam *cp++ = 'R'; 2433183261Ssam if (flags & IEEE80211_NODE_MIMO_PS) { 2434183261Ssam *cp++ = 'M'; 2435183261Ssam if (flags & IEEE80211_NODE_MIMO_RTS) 2436183261Ssam *cp++ = '+'; 2437183261Ssam } 2438183261Ssam if (flags & IEEE80211_NODE_RIFS) 2439183261Ssam *cp++ = 'I'; 2440194136Ssam if (flags & IEEE80211_NODE_SGI40) { 2441194136Ssam *cp++ = 'S'; 2442194136Ssam if (flags & IEEE80211_NODE_SGI20) 2443194136Ssam *cp++ = '+'; 2444194136Ssam } else if (flags & IEEE80211_NODE_SGI20) 2445194136Ssam *cp++ = 's'; 2446194136Ssam if (flags & IEEE80211_NODE_AMSDU_TX) 2447194136Ssam *cp++ = 't'; 2448194136Ssam if (flags & IEEE80211_NODE_AMSDU_RX) 2449194136Ssam *cp++ = 'r'; 2450159885Ssam *cp = '\0'; 2451159885Ssam return flagstring; 2452159885Ssam} 2453159885Ssam 2454138593Ssamstatic void 2455138593Ssamprintie(const char* tag, const uint8_t *ie, size_t ielen, int maxlen) 2456138593Ssam{ 2457138593Ssam printf("%s", tag); 2458138593Ssam if (verbose) { 2459138593Ssam maxlen -= strlen(tag)+2; 2460138593Ssam if (2*ielen > maxlen) 2461138593Ssam maxlen--; 2462138593Ssam printf("<"); 2463138593Ssam for (; ielen > 0; ie++, ielen--) { 2464138593Ssam if (maxlen-- <= 0) 2465138593Ssam break; 2466138593Ssam printf("%02x", *ie); 2467138593Ssam } 2468138593Ssam if (ielen != 0) 2469138593Ssam printf("-"); 2470138593Ssam printf(">"); 2471138593Ssam } 2472138593Ssam} 2473138593Ssam 2474170531Ssam#define LE_READ_2(p) \ 2475170531Ssam ((u_int16_t) \ 2476170531Ssam ((((const u_int8_t *)(p))[0] ) | \ 2477170531Ssam (((const u_int8_t *)(p))[1] << 8))) 2478170531Ssam#define LE_READ_4(p) \ 2479170531Ssam ((u_int32_t) \ 2480170531Ssam ((((const u_int8_t *)(p))[0] ) | \ 2481170531Ssam (((const u_int8_t *)(p))[1] << 8) | \ 2482170531Ssam (((const u_int8_t *)(p))[2] << 16) | \ 2483170531Ssam (((const u_int8_t *)(p))[3] << 24))) 2484170531Ssam 2485138593Ssam/* 2486170531Ssam * NB: The decoding routines assume a properly formatted ie 2487170531Ssam * which should be safe as the kernel only retains them 2488170531Ssam * if they parse ok. 2489170531Ssam */ 2490170531Ssam 2491170531Ssamstatic void 2492173275Ssamprintwmeparam(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2493170531Ssam{ 2494170531Ssam#define MS(_v, _f) (((_v) & _f) >> _f##_S) 2495170531Ssam static const char *acnames[] = { "BE", "BK", "VO", "VI" }; 2496173275Ssam const struct ieee80211_wme_param *wme = 2497173275Ssam (const struct ieee80211_wme_param *) ie; 2498170531Ssam int i; 2499170531Ssam 2500170531Ssam printf("%s", tag); 2501173275Ssam if (!verbose) 2502173275Ssam return; 2503173275Ssam printf("<qosinfo 0x%x", wme->param_qosInfo); 2504173275Ssam ie += offsetof(struct ieee80211_wme_param, params_acParams); 2505173275Ssam for (i = 0; i < WME_NUM_AC; i++) { 2506173275Ssam const struct ieee80211_wme_acparams *ac = 2507173275Ssam &wme->params_acParams[i]; 2508173275Ssam 2509173275Ssam printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]" 2510173275Ssam , acnames[i] 2511173275Ssam , MS(ac->acp_aci_aifsn, WME_PARAM_ACM) ? "acm " : "" 2512173275Ssam , MS(ac->acp_aci_aifsn, WME_PARAM_AIFSN) 2513173275Ssam , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMIN) 2514173275Ssam , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMAX) 2515173275Ssam , LE_READ_2(&ac->acp_txop) 2516173275Ssam ); 2517170531Ssam } 2518173275Ssam printf(">"); 2519170531Ssam#undef MS 2520170531Ssam} 2521170531Ssam 2522170531Ssamstatic void 2523173275Ssamprintwmeinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2524173275Ssam{ 2525173275Ssam printf("%s", tag); 2526173275Ssam if (verbose) { 2527173275Ssam const struct ieee80211_wme_info *wme = 2528173275Ssam (const struct ieee80211_wme_info *) ie; 2529173275Ssam printf("<version 0x%x info 0x%x>", 2530173275Ssam wme->wme_version, wme->wme_info); 2531173275Ssam } 2532173275Ssam} 2533173275Ssam 2534173275Ssamstatic void 2535173275Ssamprinthtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2536173275Ssam{ 2537173275Ssam printf("%s", tag); 2538173275Ssam if (verbose) { 2539173275Ssam const struct ieee80211_ie_htcap *htcap = 2540173275Ssam (const struct ieee80211_ie_htcap *) ie; 2541173275Ssam const char *sep; 2542173275Ssam int i, j; 2543173275Ssam 2544173275Ssam printf("<cap 0x%x param 0x%x", 2545173275Ssam LE_READ_2(&htcap->hc_cap), htcap->hc_param); 2546173275Ssam printf(" mcsset["); 2547173275Ssam sep = ""; 2548173275Ssam for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++) 2549173275Ssam if (isset(htcap->hc_mcsset, i)) { 2550173275Ssam for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++) 2551173275Ssam if (isclr(htcap->hc_mcsset, j)) 2552173275Ssam break; 2553173275Ssam j--; 2554173275Ssam if (i == j) 2555173275Ssam printf("%s%u", sep, i); 2556173275Ssam else 2557173275Ssam printf("%s%u-%u", sep, i, j); 2558173275Ssam i += j-i; 2559173275Ssam sep = ","; 2560173275Ssam } 2561173275Ssam printf("] extcap 0x%x txbf 0x%x antenna 0x%x>", 2562173275Ssam LE_READ_2(&htcap->hc_extcap), 2563173275Ssam LE_READ_4(&htcap->hc_txbf), 2564173275Ssam htcap->hc_antenna); 2565173275Ssam } 2566173275Ssam} 2567173275Ssam 2568173275Ssamstatic void 2569173275Ssamprinthtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2570173275Ssam{ 2571173275Ssam printf("%s", tag); 2572173275Ssam if (verbose) { 2573173275Ssam const struct ieee80211_ie_htinfo *htinfo = 2574173275Ssam (const struct ieee80211_ie_htinfo *) ie; 2575173275Ssam const char *sep; 2576173275Ssam int i, j; 2577173275Ssam 2578173275Ssam printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel, 2579173275Ssam htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3, 2580173275Ssam LE_READ_2(&htinfo->hi_byte45)); 2581173275Ssam printf(" basicmcs["); 2582173275Ssam sep = ""; 2583173275Ssam for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++) 2584173275Ssam if (isset(htinfo->hi_basicmcsset, i)) { 2585173275Ssam for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++) 2586173275Ssam if (isclr(htinfo->hi_basicmcsset, j)) 2587173275Ssam break; 2588173275Ssam j--; 2589173275Ssam if (i == j) 2590173275Ssam printf("%s%u", sep, i); 2591173275Ssam else 2592173275Ssam printf("%s%u-%u", sep, i, j); 2593173275Ssam i += j-i; 2594173275Ssam sep = ","; 2595173275Ssam } 2596173275Ssam printf("]>"); 2597173275Ssam } 2598173275Ssam} 2599173275Ssam 2600173275Ssamstatic void 2601170531Ssamprintathie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2602170531Ssam{ 2603170531Ssam 2604170531Ssam printf("%s", tag); 2605170531Ssam if (verbose) { 2606170531Ssam const struct ieee80211_ath_ie *ath = 2607170531Ssam (const struct ieee80211_ath_ie *)ie; 2608170531Ssam 2609170531Ssam printf("<"); 2610170531Ssam if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME) 2611170531Ssam printf("DTURBO,"); 2612170531Ssam if (ath->ath_capability & ATHEROS_CAP_COMPRESSION) 2613170531Ssam printf("COMP,"); 2614170531Ssam if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME) 2615170531Ssam printf("FF,"); 2616170531Ssam if (ath->ath_capability & ATHEROS_CAP_XR) 2617170531Ssam printf("XR,"); 2618170531Ssam if (ath->ath_capability & ATHEROS_CAP_AR) 2619170531Ssam printf("AR,"); 2620170531Ssam if (ath->ath_capability & ATHEROS_CAP_BURST) 2621170531Ssam printf("BURST,"); 2622170531Ssam if (ath->ath_capability & ATHEROS_CAP_WME) 2623170531Ssam printf("WME,"); 2624170531Ssam if (ath->ath_capability & ATHEROS_CAP_BOOST) 2625170531Ssam printf("BOOST,"); 2626170531Ssam printf("0x%x>", LE_READ_2(ath->ath_defkeyix)); 2627170531Ssam } 2628170531Ssam} 2629170531Ssam 2630195618Srpaulo 2631195618Srpaulostatic void 2632195618Srpauloprintmeshconf(const char *tag, const uint8_t *ie, size_t ielen, int maxlen) 2633195618Srpaulo{ 2634195618Srpaulo#define MATCHOUI(field, oui, string) \ 2635195618Srpaulodo { \ 2636195618Srpaulo if (memcmp(field, oui, 4) == 0) \ 2637195618Srpaulo printf("%s", string); \ 2638195618Srpaulo} while (0) 2639195618Srpaulo 2640195618Srpaulo printf("%s", tag); 2641195618Srpaulo if (verbose) { 2642195618Srpaulo const struct ieee80211_meshconf_ie *mconf = 2643195618Srpaulo (const struct ieee80211_meshconf_ie *)ie; 2644197980Srpaulo printf("<PATH:"); 2645197980Srpaulo if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP) 2646197980Srpaulo printf("HWMP"); 2647197980Srpaulo else 2648197980Srpaulo printf("UNKNOWN"); 2649195618Srpaulo printf(" LINK:"); 2650197980Srpaulo if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME) 2651197980Srpaulo printf("AIRTIME"); 2652197980Srpaulo else 2653197980Srpaulo printf("UNKNOWN"); 2654195618Srpaulo printf(" CONGESTION:"); 2655197980Srpaulo if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED) 2656197980Srpaulo printf("DISABLED"); 2657197980Srpaulo else 2658197980Srpaulo printf("UNKNOWN"); 2659195618Srpaulo printf(" SYNC:"); 2660197980Srpaulo if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF) 2661197980Srpaulo printf("NEIGHOFF"); 2662197980Srpaulo else 2663197980Srpaulo printf("UNKNOWN"); 2664195618Srpaulo printf(" AUTH:"); 2665197980Srpaulo if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED) 2666197980Srpaulo printf("DISABLED"); 2667197980Srpaulo else 2668197980Srpaulo printf("UNKNOWN"); 2669195618Srpaulo printf(" FORM:0x%x CAPS:0x%x>", mconf->conf_form, 2670195618Srpaulo mconf->conf_cap); 2671195618Srpaulo } 2672195618Srpaulo#undef MATCHOUI 2673195618Srpaulo} 2674195618Srpaulo 2675170531Ssamstatic const char * 2676170531Ssamwpa_cipher(const u_int8_t *sel) 2677170531Ssam{ 2678170531Ssam#define WPA_SEL(x) (((x)<<24)|WPA_OUI) 2679170531Ssam u_int32_t w = LE_READ_4(sel); 2680170531Ssam 2681170531Ssam switch (w) { 2682170531Ssam case WPA_SEL(WPA_CSE_NULL): 2683170531Ssam return "NONE"; 2684170531Ssam case WPA_SEL(WPA_CSE_WEP40): 2685170531Ssam return "WEP40"; 2686170531Ssam case WPA_SEL(WPA_CSE_WEP104): 2687170531Ssam return "WEP104"; 2688170531Ssam case WPA_SEL(WPA_CSE_TKIP): 2689170531Ssam return "TKIP"; 2690170531Ssam case WPA_SEL(WPA_CSE_CCMP): 2691170531Ssam return "AES-CCMP"; 2692170531Ssam } 2693170531Ssam return "?"; /* NB: so 1<< is discarded */ 2694170531Ssam#undef WPA_SEL 2695170531Ssam} 2696170531Ssam 2697170531Ssamstatic const char * 2698170531Ssamwpa_keymgmt(const u_int8_t *sel) 2699170531Ssam{ 2700170531Ssam#define WPA_SEL(x) (((x)<<24)|WPA_OUI) 2701170531Ssam u_int32_t w = LE_READ_4(sel); 2702170531Ssam 2703170531Ssam switch (w) { 2704170531Ssam case WPA_SEL(WPA_ASE_8021X_UNSPEC): 2705170531Ssam return "8021X-UNSPEC"; 2706170531Ssam case WPA_SEL(WPA_ASE_8021X_PSK): 2707170531Ssam return "8021X-PSK"; 2708170531Ssam case WPA_SEL(WPA_ASE_NONE): 2709170531Ssam return "NONE"; 2710170531Ssam } 2711170531Ssam return "?"; 2712170531Ssam#undef WPA_SEL 2713170531Ssam} 2714170531Ssam 2715170531Ssamstatic void 2716170531Ssamprintwpaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2717170531Ssam{ 2718170531Ssam u_int8_t len = ie[1]; 2719170531Ssam 2720170531Ssam printf("%s", tag); 2721170531Ssam if (verbose) { 2722170531Ssam const char *sep; 2723170531Ssam int n; 2724170531Ssam 2725170531Ssam ie += 6, len -= 4; /* NB: len is payload only */ 2726170531Ssam 2727170531Ssam printf("<v%u", LE_READ_2(ie)); 2728170531Ssam ie += 2, len -= 2; 2729170531Ssam 2730170531Ssam printf(" mc:%s", wpa_cipher(ie)); 2731170531Ssam ie += 4, len -= 4; 2732170531Ssam 2733170531Ssam /* unicast ciphers */ 2734170531Ssam n = LE_READ_2(ie); 2735170531Ssam ie += 2, len -= 2; 2736170531Ssam sep = " uc:"; 2737170531Ssam for (; n > 0; n--) { 2738170531Ssam printf("%s%s", sep, wpa_cipher(ie)); 2739170531Ssam ie += 4, len -= 4; 2740170531Ssam sep = "+"; 2741170531Ssam } 2742170531Ssam 2743170531Ssam /* key management algorithms */ 2744170531Ssam n = LE_READ_2(ie); 2745170531Ssam ie += 2, len -= 2; 2746170531Ssam sep = " km:"; 2747170531Ssam for (; n > 0; n--) { 2748170531Ssam printf("%s%s", sep, wpa_keymgmt(ie)); 2749170531Ssam ie += 4, len -= 4; 2750170531Ssam sep = "+"; 2751170531Ssam } 2752170531Ssam 2753170531Ssam if (len > 2) /* optional capabilities */ 2754170531Ssam printf(", caps 0x%x", LE_READ_2(ie)); 2755170531Ssam printf(">"); 2756170531Ssam } 2757170531Ssam} 2758170531Ssam 2759170531Ssamstatic const char * 2760170531Ssamrsn_cipher(const u_int8_t *sel) 2761170531Ssam{ 2762170531Ssam#define RSN_SEL(x) (((x)<<24)|RSN_OUI) 2763170531Ssam u_int32_t w = LE_READ_4(sel); 2764170531Ssam 2765170531Ssam switch (w) { 2766170531Ssam case RSN_SEL(RSN_CSE_NULL): 2767170531Ssam return "NONE"; 2768170531Ssam case RSN_SEL(RSN_CSE_WEP40): 2769170531Ssam return "WEP40"; 2770170531Ssam case RSN_SEL(RSN_CSE_WEP104): 2771170531Ssam return "WEP104"; 2772170531Ssam case RSN_SEL(RSN_CSE_TKIP): 2773170531Ssam return "TKIP"; 2774170531Ssam case RSN_SEL(RSN_CSE_CCMP): 2775170531Ssam return "AES-CCMP"; 2776170531Ssam case RSN_SEL(RSN_CSE_WRAP): 2777170531Ssam return "AES-OCB"; 2778170531Ssam } 2779170531Ssam return "?"; 2780170531Ssam#undef WPA_SEL 2781170531Ssam} 2782170531Ssam 2783170531Ssamstatic const char * 2784170531Ssamrsn_keymgmt(const u_int8_t *sel) 2785170531Ssam{ 2786170531Ssam#define RSN_SEL(x) (((x)<<24)|RSN_OUI) 2787170531Ssam u_int32_t w = LE_READ_4(sel); 2788170531Ssam 2789170531Ssam switch (w) { 2790170531Ssam case RSN_SEL(RSN_ASE_8021X_UNSPEC): 2791170531Ssam return "8021X-UNSPEC"; 2792170531Ssam case RSN_SEL(RSN_ASE_8021X_PSK): 2793170531Ssam return "8021X-PSK"; 2794170531Ssam case RSN_SEL(RSN_ASE_NONE): 2795170531Ssam return "NONE"; 2796170531Ssam } 2797170531Ssam return "?"; 2798170531Ssam#undef RSN_SEL 2799170531Ssam} 2800170531Ssam 2801170531Ssamstatic void 2802170531Ssamprintrsnie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2803170531Ssam{ 2804170531Ssam printf("%s", tag); 2805170531Ssam if (verbose) { 2806170531Ssam const char *sep; 2807170531Ssam int n; 2808170531Ssam 2809173275Ssam ie += 2, ielen -= 2; 2810170531Ssam 2811170531Ssam printf("<v%u", LE_READ_2(ie)); 2812173275Ssam ie += 2, ielen -= 2; 2813170531Ssam 2814170531Ssam printf(" mc:%s", rsn_cipher(ie)); 2815173275Ssam ie += 4, ielen -= 4; 2816170531Ssam 2817170531Ssam /* unicast ciphers */ 2818170531Ssam n = LE_READ_2(ie); 2819173275Ssam ie += 2, ielen -= 2; 2820170531Ssam sep = " uc:"; 2821170531Ssam for (; n > 0; n--) { 2822170531Ssam printf("%s%s", sep, rsn_cipher(ie)); 2823173275Ssam ie += 4, ielen -= 4; 2824170531Ssam sep = "+"; 2825170531Ssam } 2826170531Ssam 2827170531Ssam /* key management algorithms */ 2828170531Ssam n = LE_READ_2(ie); 2829173275Ssam ie += 2, ielen -= 2; 2830170531Ssam sep = " km:"; 2831170531Ssam for (; n > 0; n--) { 2832170531Ssam printf("%s%s", sep, rsn_keymgmt(ie)); 2833173275Ssam ie += 4, ielen -= 4; 2834170531Ssam sep = "+"; 2835170531Ssam } 2836170531Ssam 2837173275Ssam if (ielen > 2) /* optional capabilities */ 2838170531Ssam printf(", caps 0x%x", LE_READ_2(ie)); 2839170531Ssam /* XXXPMKID */ 2840170531Ssam printf(">"); 2841170531Ssam } 2842170531Ssam} 2843170531Ssam 2844181454Ssam/* XXX move to a public include file */ 2845181454Ssam#define IEEE80211_WPS_DEV_PASS_ID 0x1012 2846181454Ssam#define IEEE80211_WPS_SELECTED_REG 0x1041 2847181454Ssam#define IEEE80211_WPS_SETUP_STATE 0x1044 2848181454Ssam#define IEEE80211_WPS_UUID_E 0x1047 2849181454Ssam#define IEEE80211_WPS_VERSION 0x104a 2850181454Ssam 2851181454Ssam#define BE_READ_2(p) \ 2852181454Ssam ((u_int16_t) \ 2853181454Ssam ((((const u_int8_t *)(p))[1] ) | \ 2854181454Ssam (((const u_int8_t *)(p))[0] << 8))) 2855181454Ssam 2856181454Ssamstatic void 2857181454Ssamprintwpsie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2858181454Ssam{ 2859181454Ssam#define N(a) (sizeof(a) / sizeof(a[0])) 2860181454Ssam u_int8_t len = ie[1]; 2861181454Ssam 2862181454Ssam printf("%s", tag); 2863181454Ssam if (verbose) { 2864181454Ssam static const char *dev_pass_id[] = { 2865181454Ssam "D", /* Default (PIN) */ 2866181454Ssam "U", /* User-specified */ 2867181454Ssam "M", /* Machine-specified */ 2868181454Ssam "K", /* Rekey */ 2869181454Ssam "P", /* PushButton */ 2870181454Ssam "R" /* Registrar-specified */ 2871181454Ssam }; 2872181454Ssam int n; 2873181454Ssam 2874181454Ssam ie +=6, len -= 4; /* NB: len is payload only */ 2875181454Ssam 2876181454Ssam /* WPS IE in Beacon and Probe Resp frames have different fields */ 2877181454Ssam printf("<"); 2878181454Ssam while (len) { 2879181454Ssam uint16_t tlv_type = BE_READ_2(ie); 2880181454Ssam uint16_t tlv_len = BE_READ_2(ie + 2); 2881181454Ssam 2882181454Ssam ie += 4, len -= 4; 2883181454Ssam 2884181454Ssam switch (tlv_type) { 2885181454Ssam case IEEE80211_WPS_VERSION: 2886181454Ssam printf("v:%d.%d", *ie >> 4, *ie & 0xf); 2887181454Ssam break; 2888181454Ssam case IEEE80211_WPS_SETUP_STATE: 2889181454Ssam /* Only 1 and 2 are valid */ 2890181454Ssam if (*ie == 0 || *ie >= 3) 2891181454Ssam printf(" state:B"); 2892181454Ssam else 2893181454Ssam printf(" st:%s", *ie == 1 ? "N" : "C"); 2894181454Ssam break; 2895181454Ssam case IEEE80211_WPS_SELECTED_REG: 2896181454Ssam printf(" sel:%s", *ie ? "T" : "F"); 2897181454Ssam break; 2898181454Ssam case IEEE80211_WPS_DEV_PASS_ID: 2899181454Ssam n = LE_READ_2(ie); 2900181454Ssam if (n < N(dev_pass_id)) 2901181454Ssam printf(" dpi:%s", dev_pass_id[n]); 2902181454Ssam break; 2903181454Ssam case IEEE80211_WPS_UUID_E: 2904181454Ssam printf(" uuid-e:"); 2905181454Ssam for (n = 0; n < (tlv_len - 1); n++) 2906181454Ssam printf("%02x-", ie[n]); 2907181454Ssam printf("%02x", ie[n]); 2908181454Ssam break; 2909181454Ssam } 2910181454Ssam ie += tlv_len, len -= tlv_len; 2911181454Ssam } 2912181454Ssam printf(">"); 2913181454Ssam } 2914181454Ssam#undef N 2915181454Ssam} 2916181454Ssam 2917186904Ssamstatic void 2918186904Ssamprinttdmaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2919186904Ssam{ 2920186904Ssam printf("%s", tag); 2921186904Ssam if (verbose && ielen >= sizeof(struct ieee80211_tdma_param)) { 2922186904Ssam const struct ieee80211_tdma_param *tdma = 2923186904Ssam (const struct ieee80211_tdma_param *) ie; 2924186904Ssam 2925186904Ssam /* XXX tstamp */ 2926186904Ssam printf("<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>", 2927186904Ssam tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt, 2928186904Ssam LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval, 2929186904Ssam tdma->tdma_inuse[0]); 2930186904Ssam } 2931186904Ssam} 2932186904Ssam 2933170531Ssam/* 2934138593Ssam * Copy the ssid string contents into buf, truncating to fit. If the 2935138593Ssam * ssid is entirely printable then just copy intact. Otherwise convert 2936138593Ssam * to hexadecimal. If the result is truncated then replace the last 2937138593Ssam * three characters with "...". 2938138593Ssam */ 2939146873Sjhbstatic int 2940138593Ssamcopy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len) 2941138593Ssam{ 2942138593Ssam const u_int8_t *p; 2943138593Ssam size_t maxlen; 2944138593Ssam int i; 2945138593Ssam 2946138593Ssam if (essid_len > bufsize) 2947138593Ssam maxlen = bufsize; 2948138593Ssam else 2949138593Ssam maxlen = essid_len; 2950138593Ssam /* determine printable or not */ 2951138593Ssam for (i = 0, p = essid; i < maxlen; i++, p++) { 2952138593Ssam if (*p < ' ' || *p > 0x7e) 2953138593Ssam break; 2954138593Ssam } 2955138593Ssam if (i != maxlen) { /* not printable, print as hex */ 2956138593Ssam if (bufsize < 3) 2957138593Ssam return 0; 2958138593Ssam strlcpy(buf, "0x", bufsize); 2959138593Ssam bufsize -= 2; 2960138593Ssam p = essid; 2961138593Ssam for (i = 0; i < maxlen && bufsize >= 2; i++) { 2962147489Savatar sprintf(&buf[2+2*i], "%02x", p[i]); 2963138593Ssam bufsize -= 2; 2964138593Ssam } 2965147489Savatar if (i != essid_len) 2966147489Savatar memcpy(&buf[2+2*i-3], "...", 3); 2967138593Ssam } else { /* printable, truncate as needed */ 2968138593Ssam memcpy(buf, essid, maxlen); 2969147489Savatar if (maxlen != essid_len) 2970147489Savatar memcpy(&buf[maxlen-3], "...", 3); 2971138593Ssam } 2972138593Ssam return maxlen; 2973138593Ssam} 2974138593Ssam 2975173275Ssamstatic void 2976173275Ssamprintssid(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2977173275Ssam{ 2978173275Ssam char ssid[2*IEEE80211_NWID_LEN+1]; 2979173275Ssam 2980173275Ssam printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid); 2981173275Ssam} 2982173275Ssam 2983173275Ssamstatic void 2984173275Ssamprintrates(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2985173275Ssam{ 2986173275Ssam const char *sep; 2987173275Ssam int i; 2988173275Ssam 2989173275Ssam printf("%s", tag); 2990173275Ssam sep = "<"; 2991173275Ssam for (i = 2; i < ielen; i++) { 2992173275Ssam printf("%s%s%d", sep, 2993173275Ssam ie[i] & IEEE80211_RATE_BASIC ? "B" : "", 2994173275Ssam ie[i] & IEEE80211_RATE_VAL); 2995173275Ssam sep = ","; 2996173275Ssam } 2997173275Ssam printf(">"); 2998173275Ssam} 2999173275Ssam 3000173275Ssamstatic void 3001173275Ssamprintcountry(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 3002173275Ssam{ 3003173275Ssam const struct ieee80211_country_ie *cie = 3004173275Ssam (const struct ieee80211_country_ie *) ie; 3005173275Ssam int i, nbands, schan, nchan; 3006173275Ssam 3007173275Ssam printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]); 3008173275Ssam nbands = (cie->len - 3) / sizeof(cie->band[0]); 3009173275Ssam for (i = 0; i < nbands; i++) { 3010173275Ssam schan = cie->band[i].schan; 3011173275Ssam nchan = cie->band[i].nchan; 3012173275Ssam if (nchan != 1) 3013173275Ssam printf(" %u-%u,%u", schan, schan + nchan-1, 3014173275Ssam cie->band[i].maxtxpwr); 3015173275Ssam else 3016173275Ssam printf(" %u,%u", schan, cie->band[i].maxtxpwr); 3017173275Ssam } 3018173275Ssam printf(">"); 3019173275Ssam} 3020173275Ssam 3021148686Sstefanf/* unaligned little endian access */ 3022138593Ssam#define LE_READ_4(p) \ 3023138593Ssam ((u_int32_t) \ 3024138593Ssam ((((const u_int8_t *)(p))[0] ) | \ 3025138593Ssam (((const u_int8_t *)(p))[1] << 8) | \ 3026138593Ssam (((const u_int8_t *)(p))[2] << 16) | \ 3027138593Ssam (((const u_int8_t *)(p))[3] << 24))) 3028138593Ssam 3029178354Ssamstatic __inline int 3030138593Ssamiswpaoui(const u_int8_t *frm) 3031138593Ssam{ 3032138593Ssam return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI); 3033138593Ssam} 3034138593Ssam 3035178354Ssamstatic __inline int 3036173275Ssamiswmeinfo(const u_int8_t *frm) 3037138593Ssam{ 3038173275Ssam return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) && 3039173275Ssam frm[6] == WME_INFO_OUI_SUBTYPE; 3040138593Ssam} 3041138593Ssam 3042178354Ssamstatic __inline int 3043173275Ssamiswmeparam(const u_int8_t *frm) 3044173275Ssam{ 3045173275Ssam return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) && 3046173275Ssam frm[6] == WME_PARAM_OUI_SUBTYPE; 3047173275Ssam} 3048173275Ssam 3049178354Ssamstatic __inline int 3050138593Ssamisatherosoui(const u_int8_t *frm) 3051138593Ssam{ 3052138593Ssam return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI); 3053138593Ssam} 3054138593Ssam 3055181454Ssamstatic __inline int 3056186904Ssamistdmaoui(const uint8_t *frm) 3057186904Ssam{ 3058186904Ssam return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI); 3059186904Ssam} 3060186904Ssam 3061186904Ssamstatic __inline int 3062181454Ssamiswpsoui(const uint8_t *frm) 3063181454Ssam{ 3064181454Ssam return frm[1] > 3 && LE_READ_4(frm+2) == ((WPS_OUI_TYPE<<24)|WPA_OUI); 3065181454Ssam} 3066181454Ssam 3067173275Ssamstatic const char * 3068173275Ssamiename(int elemid) 3069173275Ssam{ 3070173275Ssam switch (elemid) { 3071173275Ssam case IEEE80211_ELEMID_FHPARMS: return " FHPARMS"; 3072173275Ssam case IEEE80211_ELEMID_CFPARMS: return " CFPARMS"; 3073173275Ssam case IEEE80211_ELEMID_TIM: return " TIM"; 3074173275Ssam case IEEE80211_ELEMID_IBSSPARMS:return " IBSSPARMS"; 3075173275Ssam case IEEE80211_ELEMID_CHALLENGE:return " CHALLENGE"; 3076173275Ssam case IEEE80211_ELEMID_PWRCNSTR: return " PWRCNSTR"; 3077173275Ssam case IEEE80211_ELEMID_PWRCAP: return " PWRCAP"; 3078173275Ssam case IEEE80211_ELEMID_TPCREQ: return " TPCREQ"; 3079173275Ssam case IEEE80211_ELEMID_TPCREP: return " TPCREP"; 3080173275Ssam case IEEE80211_ELEMID_SUPPCHAN: return " SUPPCHAN"; 3081193447Ssam case IEEE80211_ELEMID_CSA: return " CSA"; 3082173275Ssam case IEEE80211_ELEMID_MEASREQ: return " MEASREQ"; 3083173275Ssam case IEEE80211_ELEMID_MEASREP: return " MEASREP"; 3084173275Ssam case IEEE80211_ELEMID_QUIET: return " QUIET"; 3085173275Ssam case IEEE80211_ELEMID_IBSSDFS: return " IBSSDFS"; 3086173275Ssam case IEEE80211_ELEMID_TPC: return " TPC"; 3087173275Ssam case IEEE80211_ELEMID_CCKM: return " CCKM"; 3088173275Ssam } 3089173275Ssam return " ???"; 3090173275Ssam} 3091173275Ssam 3092138593Ssamstatic void 3093138593Ssamprinties(const u_int8_t *vp, int ielen, int maxcols) 3094138593Ssam{ 3095138593Ssam while (ielen > 0) { 3096138593Ssam switch (vp[0]) { 3097173275Ssam case IEEE80211_ELEMID_SSID: 3098173275Ssam if (verbose) 3099173275Ssam printssid(" SSID", vp, 2+vp[1], maxcols); 3100173275Ssam break; 3101173275Ssam case IEEE80211_ELEMID_RATES: 3102173275Ssam case IEEE80211_ELEMID_XRATES: 3103173275Ssam if (verbose) 3104173275Ssam printrates(vp[0] == IEEE80211_ELEMID_RATES ? 3105173275Ssam " RATES" : " XRATES", vp, 2+vp[1], maxcols); 3106173275Ssam break; 3107173275Ssam case IEEE80211_ELEMID_DSPARMS: 3108173275Ssam if (verbose) 3109173275Ssam printf(" DSPARMS<%u>", vp[2]); 3110173275Ssam break; 3111173275Ssam case IEEE80211_ELEMID_COUNTRY: 3112173275Ssam if (verbose) 3113173275Ssam printcountry(" COUNTRY", vp, 2+vp[1], maxcols); 3114173275Ssam break; 3115173275Ssam case IEEE80211_ELEMID_ERP: 3116173275Ssam if (verbose) 3117173275Ssam printf(" ERP<0x%x>", vp[2]); 3118173275Ssam break; 3119138593Ssam case IEEE80211_ELEMID_VENDOR: 3120138593Ssam if (iswpaoui(vp)) 3121170531Ssam printwpaie(" WPA", vp, 2+vp[1], maxcols); 3122173275Ssam else if (iswmeinfo(vp)) 3123173275Ssam printwmeinfo(" WME", vp, 2+vp[1], maxcols); 3124173275Ssam else if (iswmeparam(vp)) 3125173275Ssam printwmeparam(" WME", vp, 2+vp[1], maxcols); 3126139492Ssam else if (isatherosoui(vp)) 3127170531Ssam printathie(" ATH", vp, 2+vp[1], maxcols); 3128181454Ssam else if (iswpsoui(vp)) 3129181454Ssam printwpsie(" WPS", vp, 2+vp[1], maxcols); 3130186904Ssam else if (istdmaoui(vp)) 3131186904Ssam printtdmaie(" TDMA", vp, 2+vp[1], maxcols); 3132173275Ssam else if (verbose) 3133138593Ssam printie(" VEN", vp, 2+vp[1], maxcols); 3134138593Ssam break; 3135138593Ssam case IEEE80211_ELEMID_RSN: 3136170531Ssam printrsnie(" RSN", vp, 2+vp[1], maxcols); 3137138593Ssam break; 3138173275Ssam case IEEE80211_ELEMID_HTCAP: 3139173275Ssam printhtcap(" HTCAP", vp, 2+vp[1], maxcols); 3140173275Ssam break; 3141173275Ssam case IEEE80211_ELEMID_HTINFO: 3142173275Ssam if (verbose) 3143173275Ssam printhtinfo(" HTINFO", vp, 2+vp[1], maxcols); 3144173275Ssam break; 3145195618Srpaulo case IEEE80211_ELEMID_MESHID: 3146195618Srpaulo if (verbose) 3147195618Srpaulo printssid(" MESHID", vp, 2+vp[1], maxcols); 3148195618Srpaulo break; 3149195618Srpaulo case IEEE80211_ELEMID_MESHCONF: 3150195618Srpaulo printmeshconf(" MESHCONF", vp, 2+vp[1], maxcols); 3151195618Srpaulo break; 3152138593Ssam default: 3153173275Ssam if (verbose) 3154173275Ssam printie(iename(vp[0]), vp, 2+vp[1], maxcols); 3155138593Ssam break; 3156138593Ssam } 3157138593Ssam ielen -= 2+vp[1]; 3158138593Ssam vp += 2+vp[1]; 3159138593Ssam } 3160138593Ssam} 3161138593Ssam 3162138593Ssamstatic void 3163178354Ssamprintmimo(const struct ieee80211_mimo_info *mi) 3164178354Ssam{ 3165178354Ssam /* NB: don't muddy display unless there's something to show */ 3166220935Sadrian if (mi->rssi[0] != 0 || mi->rssi[1] != 0 || mi->rssi[2] != 0) { 3167178354Ssam /* XXX ignore EVM for now */ 3168178354Ssam printf(" (rssi %d:%d:%d nf %d:%d:%d)", 3169220935Sadrian mi->rssi[0], mi->rssi[1], mi->rssi[2], 3170220935Sadrian mi->noise[0], mi->noise[1], mi->noise[2]); 3171178354Ssam } 3172178354Ssam} 3173178354Ssam 3174178354Ssamstatic void 3175138593Ssamlist_scan(int s) 3176138593Ssam{ 3177138593Ssam uint8_t buf[24*1024]; 3178153892Srwatson char ssid[IEEE80211_NWID_LEN+1]; 3179173275Ssam const uint8_t *cp; 3180195618Srpaulo int len, ssidmax, idlen; 3181138593Ssam 3182173275Ssam if (get80211len(s, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0) 3183138593Ssam errx(1, "unable to get scan results"); 3184138593Ssam if (len < sizeof(struct ieee80211req_scan_result)) 3185138593Ssam return; 3186138593Ssam 3187170531Ssam getchaninfo(s); 3188170531Ssam 3189195618Srpaulo ssidmax = verbose ? IEEE80211_NWID_LEN - 1 : 14; 3190170531Ssam printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n" 3191195618Srpaulo , ssidmax, ssidmax, "SSID/MESH ID" 3192138593Ssam , "BSSID" 3193138593Ssam , "CHAN" 3194138593Ssam , "RATE" 3195170531Ssam , " S:N" 3196138593Ssam , "INT" 3197138593Ssam , "CAPS" 3198138593Ssam ); 3199138593Ssam cp = buf; 3200138593Ssam do { 3201170531Ssam const struct ieee80211req_scan_result *sr; 3202195618Srpaulo const uint8_t *vp, *idp; 3203138593Ssam 3204170531Ssam sr = (const struct ieee80211req_scan_result *) cp; 3205173275Ssam vp = cp + sr->isr_ie_off; 3206195618Srpaulo if (sr->isr_meshid_len) { 3207195618Srpaulo idp = vp + sr->isr_ssid_len; 3208195618Srpaulo idlen = sr->isr_meshid_len; 3209195618Srpaulo } else { 3210195618Srpaulo idp = vp; 3211195618Srpaulo idlen = sr->isr_ssid_len; 3212195618Srpaulo } 3213170531Ssam printf("%-*.*s %s %3d %3dM %3d:%-3d %3d %-4.4s" 3214154522Ssam , ssidmax 3215195618Srpaulo , copy_essid(ssid, ssidmax, idp, idlen) 3216154522Ssam , ssid 3217138593Ssam , ether_ntoa((const struct ether_addr *) sr->isr_bssid) 3218165570Ssam , ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags) 3219138593Ssam , getmaxrate(sr->isr_rates, sr->isr_nrates) 3220170531Ssam , (sr->isr_rssi/2)+sr->isr_noise, sr->isr_noise 3221138593Ssam , sr->isr_intval 3222138593Ssam , getcaps(sr->isr_capinfo) 3223138593Ssam ); 3224195618Srpaulo printies(vp + sr->isr_ssid_len + sr->isr_meshid_len, 3225195618Srpaulo sr->isr_ie_len, 24); 3226138593Ssam printf("\n"); 3227138593Ssam cp += sr->isr_len, len -= sr->isr_len; 3228138593Ssam } while (len >= sizeof(struct ieee80211req_scan_result)); 3229138593Ssam} 3230138593Ssam 3231138593Ssamstatic void 3232138593Ssamscan_and_wait(int s) 3233138593Ssam{ 3234178354Ssam struct ieee80211_scan_req sr; 3235138593Ssam struct ieee80211req ireq; 3236138593Ssam int sroute; 3237138593Ssam 3238138593Ssam sroute = socket(PF_ROUTE, SOCK_RAW, 0); 3239138593Ssam if (sroute < 0) { 3240138593Ssam perror("socket(PF_ROUTE,SOCK_RAW)"); 3241138593Ssam return; 3242138593Ssam } 3243138593Ssam (void) memset(&ireq, 0, sizeof(ireq)); 3244138593Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 3245138593Ssam ireq.i_type = IEEE80211_IOC_SCAN_REQ; 3246178354Ssam 3247178354Ssam memset(&sr, 0, sizeof(sr)); 3248178354Ssam sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE 3249218090Sbschmidt | IEEE80211_IOC_SCAN_BGSCAN 3250178354Ssam | IEEE80211_IOC_SCAN_NOPICK 3251178354Ssam | IEEE80211_IOC_SCAN_ONCE; 3252178354Ssam sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER; 3253178354Ssam sr.sr_nssid = 0; 3254178354Ssam 3255178354Ssam ireq.i_data = &sr; 3256178354Ssam ireq.i_len = sizeof(sr); 3257218093Sbschmidt /* 3258218093Sbschmidt * NB: only root can trigger a scan so ignore errors. Also ignore 3259218093Sbschmidt * possible errors from net80211, even if no new scan could be 3260218093Sbschmidt * started there might still be a valid scan cache. 3261218093Sbschmidt */ 3262218093Sbschmidt if (ioctl(s, SIOCS80211, &ireq) == 0) { 3263138593Ssam char buf[2048]; 3264138593Ssam struct if_announcemsghdr *ifan; 3265138593Ssam struct rt_msghdr *rtm; 3266138593Ssam 3267138593Ssam do { 3268138593Ssam if (read(sroute, buf, sizeof(buf)) < 0) { 3269138593Ssam perror("read(PF_ROUTE)"); 3270138593Ssam break; 3271138593Ssam } 3272138593Ssam rtm = (struct rt_msghdr *) buf; 3273138593Ssam if (rtm->rtm_version != RTM_VERSION) 3274138593Ssam break; 3275138593Ssam ifan = (struct if_announcemsghdr *) rtm; 3276138593Ssam } while (rtm->rtm_type != RTM_IEEE80211 || 3277138593Ssam ifan->ifan_what != RTM_IEEE80211_SCAN); 3278138593Ssam } 3279138593Ssam close(sroute); 3280138593Ssam} 3281138593Ssam 3282138593Ssamstatic 3283138593SsamDECL_CMD_FUNC(set80211scan, val, d) 3284138593Ssam{ 3285138593Ssam scan_and_wait(s); 3286138593Ssam list_scan(s); 3287138593Ssam} 3288138593Ssam 3289161147Ssamstatic enum ieee80211_opmode get80211opmode(int s); 3290161147Ssam 3291173275Ssamstatic int 3292173275Ssamgettxseq(const struct ieee80211req_sta_info *si) 3293173275Ssam{ 3294173275Ssam int i, txseq; 3295173275Ssam 3296173275Ssam if ((si->isi_state & IEEE80211_NODE_QOS) == 0) 3297173275Ssam return si->isi_txseqs[0]; 3298173275Ssam /* XXX not right but usually what folks want */ 3299173275Ssam txseq = 0; 3300173275Ssam for (i = 0; i < IEEE80211_TID_SIZE; i++) 3301173275Ssam if (si->isi_txseqs[i] > txseq) 3302173275Ssam txseq = si->isi_txseqs[i]; 3303173275Ssam return txseq; 3304173275Ssam} 3305173275Ssam 3306173275Ssamstatic int 3307173275Ssamgetrxseq(const struct ieee80211req_sta_info *si) 3308173275Ssam{ 3309173275Ssam int i, rxseq; 3310173275Ssam 3311173275Ssam if ((si->isi_state & IEEE80211_NODE_QOS) == 0) 3312173275Ssam return si->isi_rxseqs[0]; 3313173275Ssam /* XXX not right but usually what folks want */ 3314173275Ssam rxseq = 0; 3315173275Ssam for (i = 0; i < IEEE80211_TID_SIZE; i++) 3316173275Ssam if (si->isi_rxseqs[i] > rxseq) 3317173275Ssam rxseq = si->isi_rxseqs[i]; 3318173275Ssam return rxseq; 3319173275Ssam} 3320173275Ssam 3321138593Ssamstatic void 3322138593Ssamlist_stations(int s) 3323138593Ssam{ 3324161147Ssam union { 3325161147Ssam struct ieee80211req_sta_req req; 3326161147Ssam uint8_t buf[24*1024]; 3327161147Ssam } u; 3328161147Ssam enum ieee80211_opmode opmode = get80211opmode(s); 3329170531Ssam const uint8_t *cp; 3330138593Ssam int len; 3331138593Ssam 3332161147Ssam /* broadcast address =>'s get all stations */ 3333161147Ssam (void) memset(u.req.is_u.macaddr, 0xff, IEEE80211_ADDR_LEN); 3334161147Ssam if (opmode == IEEE80211_M_STA) { 3335161147Ssam /* 3336161147Ssam * Get information about the associated AP. 3337161147Ssam */ 3338173275Ssam (void) get80211(s, IEEE80211_IOC_BSSID, 3339173275Ssam u.req.is_u.macaddr, IEEE80211_ADDR_LEN); 3340161147Ssam } 3341173275Ssam if (get80211len(s, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0) 3342138593Ssam errx(1, "unable to get station information"); 3343138593Ssam if (len < sizeof(struct ieee80211req_sta_info)) 3344138593Ssam return; 3345138593Ssam 3346170531Ssam getchaninfo(s); 3347170531Ssam 3348195618Srpaulo if (opmode == IEEE80211_M_MBSS) 3349195618Srpaulo printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n" 3350195618Srpaulo , "ADDR" 3351195618Srpaulo , "CHAN" 3352195618Srpaulo , "LOCAL" 3353195618Srpaulo , "PEER" 3354195618Srpaulo , "STATE" 3355195618Srpaulo , "RATE" 3356195618Srpaulo , "RSSI" 3357195618Srpaulo , "IDLE" 3358195618Srpaulo , "TXSEQ" 3359195618Srpaulo , "RXSEQ" 3360195618Srpaulo ); 3361195618Srpaulo else 3362195618Srpaulo printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-7s\n" 3363195618Srpaulo , "ADDR" 3364195618Srpaulo , "AID" 3365195618Srpaulo , "CHAN" 3366195618Srpaulo , "RATE" 3367195618Srpaulo , "RSSI" 3368195618Srpaulo , "IDLE" 3369195618Srpaulo , "TXSEQ" 3370195618Srpaulo , "RXSEQ" 3371195618Srpaulo , "CAPS" 3372195618Srpaulo , "FLAG" 3373195618Srpaulo ); 3374170531Ssam cp = (const uint8_t *) u.req.info; 3375138593Ssam do { 3376170531Ssam const struct ieee80211req_sta_info *si; 3377138593Ssam 3378170531Ssam si = (const struct ieee80211req_sta_info *) cp; 3379161147Ssam if (si->isi_len < sizeof(*si)) 3380161147Ssam break; 3381195618Srpaulo if (opmode == IEEE80211_M_MBSS) 3382195618Srpaulo printf("%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d" 3383195618Srpaulo , ether_ntoa((const struct ether_addr*) 3384195618Srpaulo si->isi_macaddr) 3385195618Srpaulo , ieee80211_mhz2ieee(si->isi_freq, 3386195618Srpaulo si->isi_flags) 3387195618Srpaulo , si->isi_localid 3388195618Srpaulo , si->isi_peerid 3389195618Srpaulo , mesh_linkstate_string(si->isi_peerstate) 3390195618Srpaulo , si->isi_txmbps/2 3391195618Srpaulo , si->isi_rssi/2. 3392195618Srpaulo , si->isi_inact 3393195618Srpaulo , gettxseq(si) 3394195618Srpaulo , getrxseq(si) 3395195618Srpaulo ); 3396195618Srpaulo else 3397195618Srpaulo printf("%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-7.7s" 3398195618Srpaulo , ether_ntoa((const struct ether_addr*) 3399195618Srpaulo si->isi_macaddr) 3400195618Srpaulo , IEEE80211_AID(si->isi_associd) 3401195618Srpaulo , ieee80211_mhz2ieee(si->isi_freq, 3402195618Srpaulo si->isi_flags) 3403195618Srpaulo , si->isi_txmbps/2 3404195618Srpaulo , si->isi_rssi/2. 3405195618Srpaulo , si->isi_inact 3406195618Srpaulo , gettxseq(si) 3407195618Srpaulo , getrxseq(si) 3408195618Srpaulo , getcaps(si->isi_capinfo) 3409195618Srpaulo , getflags(si->isi_state) 3410195618Srpaulo ); 3411170531Ssam printies(cp + si->isi_ie_off, si->isi_ie_len, 24); 3412178354Ssam printmimo(&si->isi_mimo); 3413138593Ssam printf("\n"); 3414138593Ssam cp += si->isi_len, len -= si->isi_len; 3415138593Ssam } while (len >= sizeof(struct ieee80211req_sta_info)); 3416138593Ssam} 3417138593Ssam 3418170531Ssamstatic const char * 3419195618Srpaulomesh_linkstate_string(uint8_t state) 3420195618Srpaulo{ 3421195618Srpaulo#define N(a) (sizeof(a) / sizeof(a[0])) 3422195618Srpaulo static const char *state_names[] = { 3423195618Srpaulo [0] = "IDLE", 3424195618Srpaulo [1] = "OPEN-TX", 3425195618Srpaulo [2] = "OPEN-RX", 3426195618Srpaulo [3] = "CONF-RX", 3427195618Srpaulo [4] = "ESTAB", 3428195618Srpaulo [5] = "HOLDING", 3429195618Srpaulo }; 3430195618Srpaulo 3431195618Srpaulo if (state >= N(state_names)) { 3432195618Srpaulo static char buf[10]; 3433195618Srpaulo snprintf(buf, sizeof(buf), "#%u", state); 3434195618Srpaulo return buf; 3435195618Srpaulo } else 3436195618Srpaulo return state_names[state]; 3437195618Srpaulo#undef N 3438195618Srpaulo} 3439195618Srpaulo 3440195618Srpaulostatic const char * 3441170531Ssamget_chaninfo(const struct ieee80211_channel *c, int precise, 3442170531Ssam char buf[], size_t bsize) 3443138593Ssam{ 3444138593Ssam buf[0] = '\0'; 3445138593Ssam if (IEEE80211_IS_CHAN_FHSS(c)) 3446170531Ssam strlcat(buf, " FHSS", bsize); 3447187843Ssam if (IEEE80211_IS_CHAN_A(c)) 3448187843Ssam strlcat(buf, " 11a", bsize); 3449187843Ssam else if (IEEE80211_IS_CHAN_ANYG(c)) 3450187843Ssam strlcat(buf, " 11g", bsize); 3451187843Ssam else if (IEEE80211_IS_CHAN_B(c)) 3452170531Ssam strlcat(buf, " 11b", bsize); 3453187843Ssam if (IEEE80211_IS_CHAN_HALF(c)) 3454202161Sgavin strlcat(buf, "/10MHz", bsize); 3455187843Ssam if (IEEE80211_IS_CHAN_QUARTER(c)) 3456202161Sgavin strlcat(buf, "/5MHz", bsize); 3457170531Ssam if (IEEE80211_IS_CHAN_TURBO(c)) 3458170531Ssam strlcat(buf, " Turbo", bsize); 3459170531Ssam if (precise) { 3460170531Ssam if (IEEE80211_IS_CHAN_HT20(c)) 3461170531Ssam strlcat(buf, " ht/20", bsize); 3462170531Ssam else if (IEEE80211_IS_CHAN_HT40D(c)) 3463170531Ssam strlcat(buf, " ht/40-", bsize); 3464170531Ssam else if (IEEE80211_IS_CHAN_HT40U(c)) 3465170531Ssam strlcat(buf, " ht/40+", bsize); 3466170531Ssam } else { 3467170531Ssam if (IEEE80211_IS_CHAN_HT(c)) 3468170531Ssam strlcat(buf, " ht", bsize); 3469170531Ssam } 3470170531Ssam return buf; 3471170531Ssam} 3472170531Ssam 3473170531Ssamstatic void 3474173275Ssamprint_chaninfo(const struct ieee80211_channel *c, int verb) 3475170531Ssam{ 3476170531Ssam char buf[14]; 3477170531Ssam 3478224219Sadrian if (verb) 3479224219Sadrian printf("Channel %3u : %u%c%c%c%c%c MHz%-14.14s", 3480224219Sadrian ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq, 3481224219Sadrian IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ', 3482224219Sadrian IEEE80211_IS_CHAN_DFS(c) ? 'D' : ' ', 3483224219Sadrian IEEE80211_IS_CHAN_RADAR(c) ? 'R' : ' ', 3484224219Sadrian IEEE80211_IS_CHAN_CWINT(c) ? 'I' : ' ', 3485224219Sadrian IEEE80211_IS_CHAN_CACDONE(c) ? 'C' : ' ', 3486224219Sadrian get_chaninfo(c, verb, buf, sizeof(buf))); 3487224219Sadrian else 3488202161Sgavin printf("Channel %3u : %u%c MHz%-14.14s", 3489224219Sadrian ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq, 3490224219Sadrian IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ', 3491224219Sadrian get_chaninfo(c, verb, buf, sizeof(buf))); 3492224219Sadrian 3493138593Ssam} 3494138593Ssam 3495187844Ssamstatic int 3496187844Ssamchanpref(const struct ieee80211_channel *c) 3497187844Ssam{ 3498187844Ssam if (IEEE80211_IS_CHAN_HT40(c)) 3499187844Ssam return 40; 3500187844Ssam if (IEEE80211_IS_CHAN_HT20(c)) 3501187844Ssam return 30; 3502187844Ssam if (IEEE80211_IS_CHAN_HALF(c)) 3503187844Ssam return 10; 3504187844Ssam if (IEEE80211_IS_CHAN_QUARTER(c)) 3505187844Ssam return 5; 3506187844Ssam if (IEEE80211_IS_CHAN_TURBO(c)) 3507187844Ssam return 25; 3508187844Ssam if (IEEE80211_IS_CHAN_A(c)) 3509187844Ssam return 20; 3510187844Ssam if (IEEE80211_IS_CHAN_G(c)) 3511187844Ssam return 20; 3512187844Ssam if (IEEE80211_IS_CHAN_B(c)) 3513187844Ssam return 15; 3514187844Ssam if (IEEE80211_IS_CHAN_PUREG(c)) 3515187844Ssam return 15; 3516187844Ssam return 0; 3517187844Ssam} 3518187844Ssam 3519138593Ssamstatic void 3520173275Ssamprint_channels(int s, const struct ieee80211req_chaninfo *chans, 3521173275Ssam int allchans, int verb) 3522138593Ssam{ 3523187801Ssam struct ieee80211req_chaninfo *achans; 3524170531Ssam uint8_t reported[IEEE80211_CHAN_BYTES]; 3525138593Ssam const struct ieee80211_channel *c; 3526170531Ssam int i, half; 3527138593Ssam 3528187801Ssam achans = malloc(IEEE80211_CHANINFO_SPACE(chans)); 3529187801Ssam if (achans == NULL) 3530187801Ssam errx(1, "no space for active channel list"); 3531187801Ssam achans->ic_nchans = 0; 3532170531Ssam memset(reported, 0, sizeof(reported)); 3533138593Ssam if (!allchans) { 3534138593Ssam struct ieee80211req_chanlist active; 3535138593Ssam 3536173275Ssam if (get80211(s, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0) 3537138593Ssam errx(1, "unable to get active channel list"); 3538173275Ssam for (i = 0; i < chans->ic_nchans; i++) { 3539173275Ssam c = &chans->ic_chans[i]; 3540170531Ssam if (!isset(active.ic_channels, c->ic_ieee)) 3541170531Ssam continue; 3542170531Ssam /* 3543170531Ssam * Suppress compatible duplicates unless 3544170531Ssam * verbose. The kernel gives us it's 3545170531Ssam * complete channel list which has separate 3546170531Ssam * entries for 11g/11b and 11a/turbo. 3547170531Ssam */ 3548173275Ssam if (isset(reported, c->ic_ieee) && !verb) { 3549170531Ssam /* XXX we assume duplicates are adjacent */ 3550187801Ssam achans->ic_chans[achans->ic_nchans-1] = *c; 3551170531Ssam } else { 3552187801Ssam achans->ic_chans[achans->ic_nchans++] = *c; 3553170531Ssam setbit(reported, c->ic_ieee); 3554170531Ssam } 3555138593Ssam } 3556170531Ssam } else { 3557173275Ssam for (i = 0; i < chans->ic_nchans; i++) { 3558173275Ssam c = &chans->ic_chans[i]; 3559170531Ssam /* suppress duplicates as above */ 3560173275Ssam if (isset(reported, c->ic_ieee) && !verb) { 3561170531Ssam /* XXX we assume duplicates are adjacent */ 3562187844Ssam struct ieee80211_channel *a = 3563187844Ssam &achans->ic_chans[achans->ic_nchans-1]; 3564187844Ssam if (chanpref(c) > chanpref(a)) 3565187844Ssam *a = *c; 3566170531Ssam } else { 3567187801Ssam achans->ic_chans[achans->ic_nchans++] = *c; 3568170531Ssam setbit(reported, c->ic_ieee); 3569170531Ssam } 3570170531Ssam } 3571170531Ssam } 3572187801Ssam half = achans->ic_nchans / 2; 3573187801Ssam if (achans->ic_nchans % 2) 3574138593Ssam half++; 3575170531Ssam 3576187801Ssam for (i = 0; i < achans->ic_nchans / 2; i++) { 3577187801Ssam print_chaninfo(&achans->ic_chans[i], verb); 3578187801Ssam print_chaninfo(&achans->ic_chans[half+i], verb); 3579138593Ssam printf("\n"); 3580138593Ssam } 3581187801Ssam if (achans->ic_nchans % 2) { 3582187801Ssam print_chaninfo(&achans->ic_chans[i], verb); 3583138593Ssam printf("\n"); 3584138593Ssam } 3585187801Ssam free(achans); 3586138593Ssam} 3587138593Ssam 3588138593Ssamstatic void 3589173275Ssamlist_channels(int s, int allchans) 3590173275Ssam{ 3591173275Ssam getchaninfo(s); 3592187801Ssam print_channels(s, chaninfo, allchans, verbose); 3593173275Ssam} 3594173275Ssam 3595173275Ssamstatic void 3596170531Ssamprint_txpow(const struct ieee80211_channel *c) 3597170531Ssam{ 3598202161Sgavin printf("Channel %3u : %u MHz %3.1f reg %2d ", 3599170531Ssam c->ic_ieee, c->ic_freq, 3600170531Ssam c->ic_maxpower/2., c->ic_maxregpower); 3601170531Ssam} 3602170531Ssam 3603170531Ssamstatic void 3604170531Ssamprint_txpow_verbose(const struct ieee80211_channel *c) 3605170531Ssam{ 3606173275Ssam print_chaninfo(c, 1); 3607170531Ssam printf("min %4.1f dBm max %3.1f dBm reg %2d dBm", 3608170531Ssam c->ic_minpower/2., c->ic_maxpower/2., c->ic_maxregpower); 3609170531Ssam /* indicate where regulatory cap limits power use */ 3610170531Ssam if (c->ic_maxpower > 2*c->ic_maxregpower) 3611170531Ssam printf(" <"); 3612170531Ssam} 3613170531Ssam 3614170531Ssamstatic void 3615170531Ssamlist_txpow(int s) 3616170531Ssam{ 3617187801Ssam struct ieee80211req_chaninfo *achans; 3618170531Ssam uint8_t reported[IEEE80211_CHAN_BYTES]; 3619170531Ssam struct ieee80211_channel *c, *prev; 3620170531Ssam int i, half; 3621170531Ssam 3622170531Ssam getchaninfo(s); 3623187801Ssam achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo)); 3624187801Ssam if (achans == NULL) 3625187801Ssam errx(1, "no space for active channel list"); 3626187801Ssam achans->ic_nchans = 0; 3627170531Ssam memset(reported, 0, sizeof(reported)); 3628187801Ssam for (i = 0; i < chaninfo->ic_nchans; i++) { 3629187801Ssam c = &chaninfo->ic_chans[i]; 3630170531Ssam /* suppress duplicates as above */ 3631170531Ssam if (isset(reported, c->ic_ieee) && !verbose) { 3632170531Ssam /* XXX we assume duplicates are adjacent */ 3633187801Ssam prev = &achans->ic_chans[achans->ic_nchans-1]; 3634170531Ssam /* display highest power on channel */ 3635170531Ssam if (c->ic_maxpower > prev->ic_maxpower) 3636170531Ssam *prev = *c; 3637170531Ssam } else { 3638187801Ssam achans->ic_chans[achans->ic_nchans++] = *c; 3639170531Ssam setbit(reported, c->ic_ieee); 3640170531Ssam } 3641170531Ssam } 3642170531Ssam if (!verbose) { 3643187801Ssam half = achans->ic_nchans / 2; 3644187801Ssam if (achans->ic_nchans % 2) 3645170531Ssam half++; 3646170531Ssam 3647187801Ssam for (i = 0; i < achans->ic_nchans / 2; i++) { 3648187801Ssam print_txpow(&achans->ic_chans[i]); 3649187801Ssam print_txpow(&achans->ic_chans[half+i]); 3650170531Ssam printf("\n"); 3651170531Ssam } 3652187801Ssam if (achans->ic_nchans % 2) { 3653187801Ssam print_txpow(&achans->ic_chans[i]); 3654170531Ssam printf("\n"); 3655170531Ssam } 3656170531Ssam } else { 3657187801Ssam for (i = 0; i < achans->ic_nchans; i++) { 3658187801Ssam print_txpow_verbose(&achans->ic_chans[i]); 3659170531Ssam printf("\n"); 3660170531Ssam } 3661170531Ssam } 3662187801Ssam free(achans); 3663170531Ssam} 3664170531Ssam 3665170531Ssamstatic void 3666138593Ssamlist_keys(int s) 3667138593Ssam{ 3668138593Ssam} 3669138593Ssam 3670138593Ssam#define IEEE80211_C_BITS \ 3671195618Srpaulo "\20\1STA\002803ENCAP\7FF\10TURBOP\11IBSS\12PMGT" \ 3672178354Ssam "\13HOSTAP\14AHDEMO\15SWRETRY\16TXPMGT\17SHSLOT\20SHPREAMBLE" \ 3673195618Srpaulo "\21MONITOR\22DFS\23MBSS\30WPA1\31WPA2\32BURST\33WME\34WDS\36BGSCAN" \ 3674186904Ssam "\37TXFRAG\40TDMA" 3675138593Ssam 3676138593Ssamstatic void 3677138593Ssamlist_capabilities(int s) 3678138593Ssam{ 3679187801Ssam struct ieee80211_devcaps_req *dc; 3680138593Ssam 3681187845Ssam if (verbose) 3682187845Ssam dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN)); 3683187845Ssam else 3684187845Ssam dc = malloc(IEEE80211_DEVCAPS_SIZE(1)); 3685187801Ssam if (dc == NULL) 3686187801Ssam errx(1, "no space for device capabilities"); 3687187845Ssam dc->dc_chaninfo.ic_nchans = verbose ? MAXCHAN : 1; 3688187801Ssam getdevcaps(s, dc); 3689187801Ssam printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS); 3690187801Ssam if (dc->dc_cryptocaps != 0 || verbose) { 3691178354Ssam putchar('\n'); 3692187801Ssam printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS); 3693178354Ssam } 3694187801Ssam if (dc->dc_htcaps != 0 || verbose) { 3695178354Ssam putchar('\n'); 3696187801Ssam printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS); 3697178354Ssam } 3698138593Ssam putchar('\n'); 3699187845Ssam if (verbose) { 3700187845Ssam chaninfo = &dc->dc_chaninfo; /* XXX */ 3701187845Ssam print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, verbose); 3702187845Ssam } 3703187801Ssam free(dc); 3704138593Ssam} 3705138593Ssam 3706173275Ssamstatic int 3707173275Ssamget80211wme(int s, int param, int ac, int *val) 3708173275Ssam{ 3709173275Ssam struct ieee80211req ireq; 3710173275Ssam 3711173275Ssam (void) memset(&ireq, 0, sizeof(ireq)); 3712173275Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 3713173275Ssam ireq.i_type = param; 3714173275Ssam ireq.i_len = ac; 3715173275Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) { 3716173275Ssam warn("cannot get WME parameter %d, ac %d%s", 3717173275Ssam param, ac & IEEE80211_WMEPARAM_VAL, 3718173275Ssam ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : ""); 3719173275Ssam return -1; 3720173275Ssam } 3721173275Ssam *val = ireq.i_val; 3722173275Ssam return 0; 3723173275Ssam} 3724173275Ssam 3725138593Ssamstatic void 3726181199Ssamlist_wme_aci(int s, const char *tag, int ac) 3727138593Ssam{ 3728181199Ssam int val; 3729138593Ssam 3730181199Ssam printf("\t%s", tag); 3731138593Ssam 3732181199Ssam /* show WME BSS parameters */ 3733181199Ssam if (get80211wme(s, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1) 3734181199Ssam printf(" cwmin %2u", val); 3735181199Ssam if (get80211wme(s, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1) 3736181199Ssam printf(" cwmax %2u", val); 3737181199Ssam if (get80211wme(s, IEEE80211_IOC_WME_AIFS, ac, &val) != -1) 3738181199Ssam printf(" aifs %2u", val); 3739181199Ssam if (get80211wme(s, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1) 3740181199Ssam printf(" txopLimit %3u", val); 3741181199Ssam if (get80211wme(s, IEEE80211_IOC_WME_ACM, ac, &val) != -1) { 3742181199Ssam if (val) 3743181199Ssam printf(" acm"); 3744181199Ssam else if (verbose) 3745181199Ssam printf(" -acm"); 3746181199Ssam } 3747181199Ssam /* !BSS only */ 3748181199Ssam if ((ac & IEEE80211_WMEPARAM_BSS) == 0) { 3749181199Ssam if (get80211wme(s, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) { 3750181199Ssam if (!val) 3751181199Ssam printf(" -ack"); 3752138593Ssam else if (verbose) 3753181199Ssam printf(" ack"); 3754138593Ssam } 3755181199Ssam } 3756181199Ssam printf("\n"); 3757181199Ssam} 3758181199Ssam 3759181199Ssamstatic void 3760181199Ssamlist_wme(int s) 3761181199Ssam{ 3762181199Ssam static const char *acnames[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" }; 3763181199Ssam int ac; 3764181199Ssam 3765181199Ssam if (verbose) { 3766181199Ssam /* display both BSS and local settings */ 3767181199Ssam for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) { 3768181199Ssam again: 3769181199Ssam if (ac & IEEE80211_WMEPARAM_BSS) 3770181199Ssam list_wme_aci(s, " ", ac); 3771181199Ssam else 3772181199Ssam list_wme_aci(s, acnames[ac], ac); 3773181199Ssam if ((ac & IEEE80211_WMEPARAM_BSS) == 0) { 3774181199Ssam ac |= IEEE80211_WMEPARAM_BSS; 3775181199Ssam goto again; 3776181199Ssam } else 3777181199Ssam ac &= ~IEEE80211_WMEPARAM_BSS; 3778138593Ssam } 3779181199Ssam } else { 3780181199Ssam /* display only channel settings */ 3781181199Ssam for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) 3782181199Ssam list_wme_aci(s, acnames[ac], ac); 3783138593Ssam } 3784138593Ssam} 3785138593Ssam 3786149029Ssamstatic void 3787178354Ssamlist_roam(int s) 3788178354Ssam{ 3789178354Ssam const struct ieee80211_roamparam *rp; 3790178354Ssam int mode; 3791178354Ssam 3792178354Ssam getroam(s); 3793188784Ssam for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) { 3794178354Ssam rp = &roamparams.params[mode]; 3795178354Ssam if (rp->rssi == 0 && rp->rate == 0) 3796178354Ssam continue; 3797188784Ssam if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) { 3798188784Ssam if (rp->rssi & 1) 3799188784Ssam LINE_CHECK("roam:%-7.7s rssi %2u.5dBm MCS %2u ", 3800188784Ssam modename[mode], rp->rssi/2, 3801188784Ssam rp->rate &~ IEEE80211_RATE_MCS); 3802188784Ssam else 3803188784Ssam LINE_CHECK("roam:%-7.7s rssi %4udBm MCS %2u ", 3804188784Ssam modename[mode], rp->rssi/2, 3805188784Ssam rp->rate &~ IEEE80211_RATE_MCS); 3806188784Ssam } else { 3807188784Ssam if (rp->rssi & 1) 3808188784Ssam LINE_CHECK("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s", 3809188784Ssam modename[mode], rp->rssi/2, rp->rate/2); 3810188784Ssam else 3811188784Ssam LINE_CHECK("roam:%-7.7s rssi %4udBm rate %2u Mb/s", 3812188784Ssam modename[mode], rp->rssi/2, rp->rate/2); 3813188784Ssam } 3814178354Ssam } 3815178354Ssam} 3816178354Ssam 3817178354Ssamstatic void 3818178354Ssamlist_txparams(int s) 3819178354Ssam{ 3820178354Ssam const struct ieee80211_txparam *tp; 3821178354Ssam int mode; 3822178354Ssam 3823178354Ssam gettxparams(s); 3824188784Ssam for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) { 3825178354Ssam tp = &txparams.params[mode]; 3826178354Ssam if (tp->mgmtrate == 0 && tp->mcastrate == 0) 3827178354Ssam continue; 3828188784Ssam if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) { 3829188784Ssam if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) 3830188784Ssam LINE_CHECK("%-7.7s ucast NONE mgmt %2u MCS " 3831188784Ssam "mcast %2u MCS maxretry %u", 3832188784Ssam modename[mode], 3833188784Ssam tp->mgmtrate &~ IEEE80211_RATE_MCS, 3834188784Ssam tp->mcastrate &~ IEEE80211_RATE_MCS, 3835188784Ssam tp->maxretry); 3836188784Ssam else 3837188784Ssam LINE_CHECK("%-7.7s ucast %2u MCS mgmt %2u MCS " 3838188784Ssam "mcast %2u MCS maxretry %u", 3839188784Ssam modename[mode], 3840188784Ssam tp->ucastrate &~ IEEE80211_RATE_MCS, 3841188784Ssam tp->mgmtrate &~ IEEE80211_RATE_MCS, 3842188784Ssam tp->mcastrate &~ IEEE80211_RATE_MCS, 3843188784Ssam tp->maxretry); 3844188784Ssam } else { 3845188784Ssam if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) 3846188784Ssam LINE_CHECK("%-7.7s ucast NONE mgmt %2u Mb/s " 3847188784Ssam "mcast %2u Mb/s maxretry %u", 3848188784Ssam modename[mode], 3849188784Ssam tp->mgmtrate/2, 3850188784Ssam tp->mcastrate/2, tp->maxretry); 3851188784Ssam else 3852188784Ssam LINE_CHECK("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s " 3853188784Ssam "mcast %2u Mb/s maxretry %u", 3854188784Ssam modename[mode], 3855188784Ssam tp->ucastrate/2, tp->mgmtrate/2, 3856188784Ssam tp->mcastrate/2, tp->maxretry); 3857188784Ssam } 3858178354Ssam } 3859178354Ssam} 3860178354Ssam 3861178354Ssamstatic void 3862173275Ssamprintpolicy(int policy) 3863173275Ssam{ 3864173275Ssam switch (policy) { 3865173275Ssam case IEEE80211_MACCMD_POLICY_OPEN: 3866173275Ssam printf("policy: open\n"); 3867173275Ssam break; 3868173275Ssam case IEEE80211_MACCMD_POLICY_ALLOW: 3869173275Ssam printf("policy: allow\n"); 3870173275Ssam break; 3871173275Ssam case IEEE80211_MACCMD_POLICY_DENY: 3872173275Ssam printf("policy: deny\n"); 3873173275Ssam break; 3874178354Ssam case IEEE80211_MACCMD_POLICY_RADIUS: 3875178354Ssam printf("policy: radius\n"); 3876178354Ssam break; 3877173275Ssam default: 3878173275Ssam printf("policy: unknown (%u)\n", policy); 3879173275Ssam break; 3880173275Ssam } 3881173275Ssam} 3882173275Ssam 3883173275Ssamstatic void 3884149029Ssamlist_mac(int s) 3885149029Ssam{ 3886149029Ssam struct ieee80211req ireq; 3887149029Ssam struct ieee80211req_maclist *acllist; 3888173275Ssam int i, nacls, policy, len; 3889173275Ssam uint8_t *data; 3890149029Ssam char c; 3891149029Ssam 3892149029Ssam (void) memset(&ireq, 0, sizeof(ireq)); 3893149029Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); /* XXX ?? */ 3894149029Ssam ireq.i_type = IEEE80211_IOC_MACCMD; 3895149029Ssam ireq.i_val = IEEE80211_MACCMD_POLICY; 3896149029Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) { 3897149029Ssam if (errno == EINVAL) { 3898149029Ssam printf("No acl policy loaded\n"); 3899149029Ssam return; 3900149029Ssam } 3901149029Ssam err(1, "unable to get mac policy"); 3902149029Ssam } 3903149029Ssam policy = ireq.i_val; 3904149029Ssam if (policy == IEEE80211_MACCMD_POLICY_OPEN) { 3905149029Ssam c = '*'; 3906149029Ssam } else if (policy == IEEE80211_MACCMD_POLICY_ALLOW) { 3907149029Ssam c = '+'; 3908149029Ssam } else if (policy == IEEE80211_MACCMD_POLICY_DENY) { 3909149029Ssam c = '-'; 3910178354Ssam } else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) { 3911178354Ssam c = 'r'; /* NB: should never have entries */ 3912149029Ssam } else { 3913149029Ssam printf("policy: unknown (%u)\n", policy); 3914149029Ssam c = '?'; 3915149029Ssam } 3916173275Ssam if (verbose || c == '?') 3917173275Ssam printpolicy(policy); 3918173275Ssam 3919175952Ssam ireq.i_val = IEEE80211_MACCMD_LIST; 3920175952Ssam ireq.i_len = 0; 3921175952Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) 3922173275Ssam err(1, "unable to get mac acl list size"); 3923175952Ssam if (ireq.i_len == 0) { /* NB: no acls */ 3924173275Ssam if (!(verbose || c == '?')) 3925173275Ssam printpolicy(policy); 3926173275Ssam return; 3927173275Ssam } 3928175952Ssam len = ireq.i_len; 3929173275Ssam 3930173275Ssam data = malloc(len); 3931173275Ssam if (data == NULL) 3932173275Ssam err(1, "out of memory for acl list"); 3933173275Ssam 3934175952Ssam ireq.i_data = data; 3935175952Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) 3936173275Ssam err(1, "unable to get mac acl list"); 3937173275Ssam nacls = len / sizeof(*acllist); 3938173275Ssam acllist = (struct ieee80211req_maclist *) data; 3939149029Ssam for (i = 0; i < nacls; i++) 3940149029Ssam printf("%c%s\n", c, ether_ntoa( 3941149029Ssam (const struct ether_addr *) acllist[i].ml_macaddr)); 3942173275Ssam free(data); 3943149029Ssam} 3944149029Ssam 3945178354Ssamstatic void 3946178354Ssamprint_regdomain(const struct ieee80211_regdomain *reg, int verb) 3947178354Ssam{ 3948178354Ssam if ((reg->regdomain != 0 && 3949178354Ssam reg->regdomain != reg->country) || verb) { 3950178354Ssam const struct regdomain *rd = 3951178354Ssam lib80211_regdomain_findbysku(getregdata(), reg->regdomain); 3952178354Ssam if (rd == NULL) 3953178354Ssam LINE_CHECK("regdomain %d", reg->regdomain); 3954178354Ssam else 3955178354Ssam LINE_CHECK("regdomain %s", rd->name); 3956178354Ssam } 3957178354Ssam if (reg->country != 0 || verb) { 3958178354Ssam const struct country *cc = 3959178354Ssam lib80211_country_findbycc(getregdata(), reg->country); 3960178354Ssam if (cc == NULL) 3961178354Ssam LINE_CHECK("country %d", reg->country); 3962178354Ssam else 3963178354Ssam LINE_CHECK("country %s", cc->isoname); 3964178354Ssam } 3965178354Ssam if (reg->location == 'I') 3966178354Ssam LINE_CHECK("indoor"); 3967178354Ssam else if (reg->location == 'O') 3968178354Ssam LINE_CHECK("outdoor"); 3969178354Ssam else if (verb) 3970178354Ssam LINE_CHECK("anywhere"); 3971178354Ssam if (reg->ecm) 3972178354Ssam LINE_CHECK("ecm"); 3973178354Ssam else if (verb) 3974178354Ssam LINE_CHECK("-ecm"); 3975178354Ssam} 3976178354Ssam 3977178354Ssamstatic void 3978178354Ssamlist_regdomain(int s, int channelsalso) 3979178354Ssam{ 3980178354Ssam getregdomain(s); 3981178354Ssam if (channelsalso) { 3982178354Ssam getchaninfo(s); 3983178354Ssam spacer = ':'; 3984178354Ssam print_regdomain(®domain, 1); 3985178354Ssam LINE_BREAK(); 3986187801Ssam print_channels(s, chaninfo, 1/*allchans*/, 1/*verbose*/); 3987178354Ssam } else 3988178354Ssam print_regdomain(®domain, verbose); 3989178354Ssam} 3990178354Ssam 3991195618Srpaulostatic void 3992195618Srpaulolist_mesh(int s) 3993195618Srpaulo{ 3994195618Srpaulo struct ieee80211req ireq; 3995195618Srpaulo struct ieee80211req_mesh_route routes[128]; 3996195908Srpaulo struct ieee80211req_mesh_route *rt; 3997195618Srpaulo 3998195618Srpaulo (void) memset(&ireq, 0, sizeof(ireq)); 3999195618Srpaulo (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 4000195618Srpaulo ireq.i_type = IEEE80211_IOC_MESH_RTCMD; 4001195618Srpaulo ireq.i_val = IEEE80211_MESH_RTCMD_LIST; 4002195618Srpaulo ireq.i_data = &routes; 4003195618Srpaulo ireq.i_len = sizeof(routes); 4004195618Srpaulo if (ioctl(s, SIOCG80211, &ireq) < 0) 4005195618Srpaulo err(1, "unable to get the Mesh routing table"); 4006195618Srpaulo 4007195908Srpaulo printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n" 4008195618Srpaulo , "DEST" 4009195618Srpaulo , "NEXT HOP" 4010195618Srpaulo , "HOPS" 4011195618Srpaulo , "METRIC" 4012195784Srpaulo , "LIFETIME" 4013195908Srpaulo , "MSEQ" 4014195908Srpaulo , "FLAGS"); 4015195618Srpaulo 4016195908Srpaulo for (rt = &routes[0]; rt - &routes[0] < ireq.i_len / sizeof(*rt); rt++){ 4017195618Srpaulo printf("%s ", 4018195908Srpaulo ether_ntoa((const struct ether_addr *)rt->imr_dest)); 4019195908Srpaulo printf("%s %4u %4u %6u %6u %c%c\n", 4020195908Srpaulo ether_ntoa((const struct ether_addr *)rt->imr_nexthop), 4021195908Srpaulo rt->imr_nhops, rt->imr_metric, rt->imr_lifetime, 4022195908Srpaulo rt->imr_lastmseq, 4023234895Smonthadar (rt->imr_flags & IEEE80211_MESHRT_FLAGS_DISCOVER) ? 4024234895Smonthadar 'D' : 4025195908Srpaulo (rt->imr_flags & IEEE80211_MESHRT_FLAGS_VALID) ? 4026195908Srpaulo 'V' : '!', 4027195908Srpaulo (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ? 4028246505Smonthadar 'P' : 4029246505Smonthadar (rt->imr_flags & IEEE80211_MESHRT_FLAGS_GATE) ? 4030246505Smonthadar 'G' :' '); 4031195618Srpaulo } 4032195618Srpaulo} 4033195618Srpaulo 4034138593Ssamstatic 4035138593SsamDECL_CMD_FUNC(set80211list, arg, d) 4036138593Ssam{ 4037138593Ssam#define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0) 4038138593Ssam 4039173275Ssam LINE_INIT('\t'); 4040173275Ssam 4041138593Ssam if (iseq(arg, "sta")) 4042138593Ssam list_stations(s); 4043138593Ssam else if (iseq(arg, "scan") || iseq(arg, "ap")) 4044138593Ssam list_scan(s); 4045138593Ssam else if (iseq(arg, "chan") || iseq(arg, "freq")) 4046138593Ssam list_channels(s, 1); 4047138593Ssam else if (iseq(arg, "active")) 4048138593Ssam list_channels(s, 0); 4049138593Ssam else if (iseq(arg, "keys")) 4050138593Ssam list_keys(s); 4051138593Ssam else if (iseq(arg, "caps")) 4052138593Ssam list_capabilities(s); 4053178354Ssam else if (iseq(arg, "wme") || iseq(arg, "wmm")) 4054138593Ssam list_wme(s); 4055149029Ssam else if (iseq(arg, "mac")) 4056149029Ssam list_mac(s); 4057170531Ssam else if (iseq(arg, "txpow")) 4058170531Ssam list_txpow(s); 4059178354Ssam else if (iseq(arg, "roam")) 4060178354Ssam list_roam(s); 4061178354Ssam else if (iseq(arg, "txparam") || iseq(arg, "txparm")) 4062178354Ssam list_txparams(s); 4063178354Ssam else if (iseq(arg, "regdomain")) 4064178354Ssam list_regdomain(s, 1); 4065178354Ssam else if (iseq(arg, "countries")) 4066178354Ssam list_countries(); 4067195618Srpaulo else if (iseq(arg, "mesh")) 4068195618Srpaulo list_mesh(s); 4069138593Ssam else 4070138593Ssam errx(1, "Don't know how to list %s for %s", arg, name); 4071178354Ssam LINE_BREAK(); 4072138593Ssam#undef iseq 4073138593Ssam} 4074138593Ssam 4075138593Ssamstatic enum ieee80211_opmode 4076138593Ssamget80211opmode(int s) 4077138593Ssam{ 4078138593Ssam struct ifmediareq ifmr; 4079138593Ssam 4080138593Ssam (void) memset(&ifmr, 0, sizeof(ifmr)); 4081138593Ssam (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); 4082138593Ssam 4083138593Ssam if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) { 4084186101Ssam if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) { 4085186101Ssam if (ifmr.ifm_current & IFM_FLAG0) 4086186101Ssam return IEEE80211_M_AHDEMO; 4087186101Ssam else 4088186101Ssam return IEEE80211_M_IBSS; 4089186101Ssam } 4090138593Ssam if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP) 4091138593Ssam return IEEE80211_M_HOSTAP; 4092138593Ssam if (ifmr.ifm_current & IFM_IEEE80211_MONITOR) 4093138593Ssam return IEEE80211_M_MONITOR; 4094195618Srpaulo if (ifmr.ifm_current & IFM_IEEE80211_MBSS) 4095195618Srpaulo return IEEE80211_M_MBSS; 4096138593Ssam } 4097138593Ssam return IEEE80211_M_STA; 4098138593Ssam} 4099138593Ssam 4100138593Ssam#if 0 4101138593Ssamstatic void 4102138593Ssamprintcipher(int s, struct ieee80211req *ireq, int keylenop) 4103138593Ssam{ 4104138593Ssam switch (ireq->i_val) { 4105138593Ssam case IEEE80211_CIPHER_WEP: 4106138593Ssam ireq->i_type = keylenop; 4107138593Ssam if (ioctl(s, SIOCG80211, ireq) != -1) 4108138593Ssam printf("WEP-%s", 4109138593Ssam ireq->i_len <= 5 ? "40" : 4110138593Ssam ireq->i_len <= 13 ? "104" : "128"); 4111138593Ssam else 4112138593Ssam printf("WEP"); 4113138593Ssam break; 4114138593Ssam case IEEE80211_CIPHER_TKIP: 4115138593Ssam printf("TKIP"); 4116138593Ssam break; 4117138593Ssam case IEEE80211_CIPHER_AES_OCB: 4118138593Ssam printf("AES-OCB"); 4119138593Ssam break; 4120138593Ssam case IEEE80211_CIPHER_AES_CCM: 4121138593Ssam printf("AES-CCM"); 4122138593Ssam break; 4123138593Ssam case IEEE80211_CIPHER_CKIP: 4124138593Ssam printf("CKIP"); 4125138593Ssam break; 4126138593Ssam case IEEE80211_CIPHER_NONE: 4127138593Ssam printf("NONE"); 4128138593Ssam break; 4129138593Ssam default: 4130138593Ssam printf("UNKNOWN (0x%x)", ireq->i_val); 4131138593Ssam break; 4132138593Ssam } 4133138593Ssam} 4134138593Ssam#endif 4135138593Ssam 4136155931Ssamstatic void 4137138593Ssamprintkey(const struct ieee80211req_key *ik) 4138138593Ssam{ 4139138593Ssam static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE]; 4140138593Ssam int keylen = ik->ik_keylen; 4141138593Ssam int printcontents; 4142138593Ssam 4143148001Srwatson printcontents = printkeys && 4144138593Ssam (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose); 4145138593Ssam if (printcontents) 4146138593Ssam LINE_BREAK(); 4147138593Ssam switch (ik->ik_type) { 4148138593Ssam case IEEE80211_CIPHER_WEP: 4149138593Ssam /* compatibility */ 4150155931Ssam LINE_CHECK("wepkey %u:%s", ik->ik_keyix+1, 4151138593Ssam keylen <= 5 ? "40-bit" : 4152138593Ssam keylen <= 13 ? "104-bit" : "128-bit"); 4153138593Ssam break; 4154138593Ssam case IEEE80211_CIPHER_TKIP: 4155138593Ssam if (keylen > 128/8) 4156138593Ssam keylen -= 128/8; /* ignore MIC for now */ 4157155931Ssam LINE_CHECK("TKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4158138593Ssam break; 4159138593Ssam case IEEE80211_CIPHER_AES_OCB: 4160155931Ssam LINE_CHECK("AES-OCB %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4161138593Ssam break; 4162138593Ssam case IEEE80211_CIPHER_AES_CCM: 4163155931Ssam LINE_CHECK("AES-CCM %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4164138593Ssam break; 4165138593Ssam case IEEE80211_CIPHER_CKIP: 4166155931Ssam LINE_CHECK("CKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4167138593Ssam break; 4168138593Ssam case IEEE80211_CIPHER_NONE: 4169155931Ssam LINE_CHECK("NULL %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4170138593Ssam break; 4171138593Ssam default: 4172155931Ssam LINE_CHECK("UNKNOWN (0x%x) %u:%u-bit", 4173138593Ssam ik->ik_type, ik->ik_keyix+1, 8*keylen); 4174138593Ssam break; 4175138593Ssam } 4176138593Ssam if (printcontents) { 4177138593Ssam int i; 4178138593Ssam 4179138593Ssam printf(" <"); 4180138593Ssam for (i = 0; i < keylen; i++) 4181138593Ssam printf("%02x", ik->ik_keydata[i]); 4182138593Ssam printf(">"); 4183138593Ssam if (ik->ik_type != IEEE80211_CIPHER_WEP && 4184138593Ssam (ik->ik_keyrsc != 0 || verbose)) 4185146873Sjhb printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc); 4186138593Ssam if (ik->ik_type != IEEE80211_CIPHER_WEP && 4187138593Ssam (ik->ik_keytsc != 0 || verbose)) 4188146873Sjhb printf(" tsc %ju", (uintmax_t)ik->ik_keytsc); 4189138593Ssam if (ik->ik_flags != 0 && verbose) { 4190138593Ssam const char *sep = " "; 4191138593Ssam 4192138593Ssam if (ik->ik_flags & IEEE80211_KEY_XMIT) 4193138593Ssam printf("%stx", sep), sep = "+"; 4194138593Ssam if (ik->ik_flags & IEEE80211_KEY_RECV) 4195138593Ssam printf("%srx", sep), sep = "+"; 4196138593Ssam if (ik->ik_flags & IEEE80211_KEY_DEFAULT) 4197138593Ssam printf("%sdef", sep), sep = "+"; 4198138593Ssam } 4199138593Ssam LINE_BREAK(); 4200138593Ssam } 4201138593Ssam} 4202138593Ssam 4203138593Ssamstatic void 4204173275Ssamprintrate(const char *tag, int v, int defrate, int defmcs) 4205138593Ssam{ 4206188784Ssam if ((v & IEEE80211_RATE_MCS) == 0) { 4207188784Ssam if (v != defrate) { 4208188784Ssam if (v & 1) 4209188784Ssam LINE_CHECK("%s %d.5", tag, v/2); 4210188784Ssam else 4211188784Ssam LINE_CHECK("%s %d", tag, v/2); 4212188784Ssam } 4213188784Ssam } else { 4214173275Ssam if (v != defmcs) 4215173275Ssam LINE_CHECK("%s %d", tag, v &~ 0x80); 4216173275Ssam } 4217173275Ssam} 4218173275Ssam 4219173275Ssamstatic int 4220195618Srpaulogetid(int s, int ix, void *data, size_t len, int *plen, int mesh) 4221173275Ssam{ 4222138593Ssam struct ieee80211req ireq; 4223138593Ssam 4224138593Ssam (void) memset(&ireq, 0, sizeof(ireq)); 4225138593Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 4226195618Srpaulo ireq.i_type = (!mesh) ? IEEE80211_IOC_SSID : IEEE80211_IOC_MESH_ID; 4227173275Ssam ireq.i_val = ix; 4228173275Ssam ireq.i_data = data; 4229173275Ssam ireq.i_len = len; 4230173275Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) 4231173275Ssam return -1; 4232173275Ssam *plen = ireq.i_len; 4233173275Ssam return 0; 4234173275Ssam} 423577218Sphk 4236173275Ssamstatic void 4237173275Ssamieee80211_status(int s) 4238173275Ssam{ 4239173275Ssam static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; 4240173275Ssam enum ieee80211_opmode opmode = get80211opmode(s); 4241173275Ssam int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode; 4242173275Ssam uint8_t data[32]; 4243173275Ssam const struct ieee80211_channel *c; 4244178354Ssam const struct ieee80211_roamparam *rp; 4245178354Ssam const struct ieee80211_txparam *tp; 4246173275Ssam 4247195618Srpaulo if (getid(s, -1, data, sizeof(data), &len, 0) < 0) { 4248148686Sstefanf /* If we can't get the SSID, this isn't an 802.11 device. */ 424977218Sphk return; 425077218Sphk } 4251173275Ssam 4252173275Ssam /* 4253173275Ssam * Invalidate cached state so printing status for multiple 4254173275Ssam * if's doesn't reuse the first interfaces' cached state. 4255173275Ssam */ 4256173275Ssam gotcurchan = 0; 4257178354Ssam gotroam = 0; 4258178354Ssam gottxparams = 0; 4259173275Ssam gothtconf = 0; 4260178354Ssam gotregdomain = 0; 4261173275Ssam 4262195618Srpaulo printf("\t"); 4263195618Srpaulo if (opmode == IEEE80211_M_MBSS) { 4264195618Srpaulo printf("meshid "); 4265195618Srpaulo getid(s, 0, data, sizeof(data), &len, 1); 4266195618Srpaulo print_string(data, len); 4267195618Srpaulo } else { 4268195618Srpaulo if (get80211val(s, IEEE80211_IOC_NUMSSIDS, &num) < 0) 4269195618Srpaulo num = 0; 4270195618Srpaulo printf("ssid "); 4271195618Srpaulo if (num > 1) { 4272195618Srpaulo for (i = 0; i < num; i++) { 4273195618Srpaulo if (getid(s, i, data, sizeof(data), &len, 0) >= 0 && len > 0) { 4274195618Srpaulo printf(" %d:", i + 1); 4275195618Srpaulo print_string(data, len); 4276195618Srpaulo } 4277138593Ssam } 4278195618Srpaulo } else 4279195618Srpaulo print_string(data, len); 4280195618Srpaulo } 4281173275Ssam c = getcurchan(s); 4282170531Ssam if (c->ic_freq != IEEE80211_CHAN_ANY) { 4283170531Ssam char buf[14]; 4284202161Sgavin printf(" channel %d (%u MHz%s)", c->ic_ieee, c->ic_freq, 4285170531Ssam get_chaninfo(c, 1, buf, sizeof(buf))); 4286138593Ssam } else if (verbose) 4287138593Ssam printf(" channel UNDEF"); 4288138593Ssam 4289173275Ssam if (get80211(s, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 && 4290173275Ssam (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose)) 4291173275Ssam printf(" bssid %s", ether_ntoa((struct ether_addr *)data)); 4292138593Ssam 4293173275Ssam if (get80211len(s, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) { 4294138593Ssam printf("\n\tstationname "); 4295173275Ssam print_string(data, len); 429677218Sphk } 429777218Sphk 4298138593Ssam spacer = ' '; /* force first break */ 4299138593Ssam LINE_BREAK(); 430077218Sphk 4301178354Ssam list_regdomain(s, 0); 4302178354Ssam 4303173275Ssam wpa = 0; 4304173275Ssam if (get80211val(s, IEEE80211_IOC_AUTHMODE, &val) != -1) { 4305173275Ssam switch (val) { 4306173275Ssam case IEEE80211_AUTH_NONE: 4307173275Ssam LINE_CHECK("authmode NONE"); 4308173275Ssam break; 4309173275Ssam case IEEE80211_AUTH_OPEN: 4310173275Ssam LINE_CHECK("authmode OPEN"); 4311173275Ssam break; 4312173275Ssam case IEEE80211_AUTH_SHARED: 4313173275Ssam LINE_CHECK("authmode SHARED"); 4314173275Ssam break; 4315173275Ssam case IEEE80211_AUTH_8021X: 4316173275Ssam LINE_CHECK("authmode 802.1x"); 4317173275Ssam break; 4318173275Ssam case IEEE80211_AUTH_WPA: 4319173275Ssam if (get80211val(s, IEEE80211_IOC_WPA, &wpa) < 0) 4320173275Ssam wpa = 1; /* default to WPA1 */ 4321173275Ssam switch (wpa) { 4322173275Ssam case 2: 4323173275Ssam LINE_CHECK("authmode WPA2/802.11i"); 432477218Sphk break; 4325173275Ssam case 3: 4326173275Ssam LINE_CHECK("authmode WPA1+WPA2/802.11i"); 432777218Sphk break; 4328127649Ssam default: 4329173275Ssam LINE_CHECK("authmode WPA"); 4330127649Ssam break; 4331173275Ssam } 4332173275Ssam break; 4333173275Ssam case IEEE80211_AUTH_AUTO: 4334173275Ssam LINE_CHECK("authmode AUTO"); 4335173275Ssam break; 4336173275Ssam default: 4337173275Ssam LINE_CHECK("authmode UNKNOWN (0x%x)", val); 4338173275Ssam break; 4339127649Ssam } 4340127649Ssam } 4341127649Ssam 4342173275Ssam if (wpa || verbose) { 4343178354Ssam if (get80211val(s, IEEE80211_IOC_WPS, &val) != -1) { 4344178354Ssam if (val) 4345178354Ssam LINE_CHECK("wps"); 4346178354Ssam else if (verbose) 4347178354Ssam LINE_CHECK("-wps"); 4348178354Ssam } 4349178354Ssam if (get80211val(s, IEEE80211_IOC_TSN, &val) != -1) { 4350178354Ssam if (val) 4351178354Ssam LINE_CHECK("tsn"); 4352178354Ssam else if (verbose) 4353178354Ssam LINE_CHECK("-tsn"); 4354178354Ssam } 4355173275Ssam if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) { 4356173275Ssam if (val) 4357173275Ssam LINE_CHECK("countermeasures"); 4358173275Ssam else if (verbose) 4359173275Ssam LINE_CHECK("-countermeasures"); 4360173275Ssam } 4361178354Ssam#if 0 4362178354Ssam /* XXX not interesting with WPA done in user space */ 4363178354Ssam ireq.i_type = IEEE80211_IOC_KEYMGTALGS; 4364178354Ssam if (ioctl(s, SIOCG80211, &ireq) != -1) { 4365178354Ssam } 4366178354Ssam 4367178354Ssam ireq.i_type = IEEE80211_IOC_MCASTCIPHER; 4368178354Ssam if (ioctl(s, SIOCG80211, &ireq) != -1) { 4369178354Ssam LINE_CHECK("mcastcipher "); 4370178354Ssam printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN); 4371178354Ssam spacer = ' '; 4372178354Ssam } 4373178354Ssam 4374178354Ssam ireq.i_type = IEEE80211_IOC_UCASTCIPHER; 4375178354Ssam if (ioctl(s, SIOCG80211, &ireq) != -1) { 4376178354Ssam LINE_CHECK("ucastcipher "); 4377178354Ssam printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN); 4378178354Ssam } 4379178354Ssam 4380178354Ssam if (wpa & 2) { 4381178354Ssam ireq.i_type = IEEE80211_IOC_RSNCAPS; 4382178354Ssam if (ioctl(s, SIOCG80211, &ireq) != -1) { 4383178354Ssam LINE_CHECK("RSN caps 0x%x", ireq.i_val); 4384178354Ssam spacer = ' '; 4385178354Ssam } 4386178354Ssam } 4387178354Ssam 4388178354Ssam ireq.i_type = IEEE80211_IOC_UCASTCIPHERS; 4389178354Ssam if (ioctl(s, SIOCG80211, &ireq) != -1) { 4390178354Ssam } 4391178354Ssam#endif 4392173275Ssam } 4393138593Ssam 4394173275Ssam if (get80211val(s, IEEE80211_IOC_WEP, &wepmode) != -1 && 4395173275Ssam wepmode != IEEE80211_WEP_NOSUP) { 4396173275Ssam 4397138718Ssam switch (wepmode) { 4398173275Ssam case IEEE80211_WEP_OFF: 4399173275Ssam LINE_CHECK("privacy OFF"); 4400173275Ssam break; 4401173275Ssam case IEEE80211_WEP_ON: 4402173275Ssam LINE_CHECK("privacy ON"); 4403173275Ssam break; 4404173275Ssam case IEEE80211_WEP_MIXED: 4405173275Ssam LINE_CHECK("privacy MIXED"); 4406173275Ssam break; 4407173275Ssam default: 4408173275Ssam LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode); 4409173275Ssam break; 441077218Sphk } 441177218Sphk 441277218Sphk /* 441377218Sphk * If we get here then we've got WEP support so we need 441477218Sphk * to print WEP status. 441591454Sbrooks */ 441677218Sphk 4417173275Ssam if (get80211val(s, IEEE80211_IOC_WEPTXKEY, &val) < 0) { 441877218Sphk warn("WEP support, but no tx key!"); 441977218Sphk goto end; 442077218Sphk } 4421173275Ssam if (val != -1) 4422173275Ssam LINE_CHECK("deftxkey %d", val+1); 4423138718Ssam else if (wepmode != IEEE80211_WEP_OFF || verbose) 4424155931Ssam LINE_CHECK("deftxkey UNDEF"); 442577218Sphk 4426173275Ssam if (get80211val(s, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) { 442777218Sphk warn("WEP support, but no NUMWEPKEYS support!"); 442877218Sphk goto end; 442977218Sphk } 443077218Sphk 4431138593Ssam for (i = 0; i < num; i++) { 4432138593Ssam struct ieee80211req_key ik; 443377218Sphk 4434138593Ssam memset(&ik, 0, sizeof(ik)); 4435138593Ssam ik.ik_keyix = i; 4436173275Ssam if (get80211(s, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) { 443777218Sphk warn("WEP support, but can get keys!"); 443877218Sphk goto end; 443977218Sphk } 4440138593Ssam if (ik.ik_keylen != 0) { 4441138593Ssam if (verbose) 4442138593Ssam LINE_BREAK(); 4443138593Ssam printkey(&ik); 4444138593Ssam } 4445138593Ssam } 4446173275Ssamend: 4447173275Ssam ; 4448138593Ssam } 4449138593Ssam 4450173275Ssam if (get80211val(s, IEEE80211_IOC_POWERSAVE, &val) != -1 && 4451173275Ssam val != IEEE80211_POWERSAVE_NOSUP ) { 4452173275Ssam if (val != IEEE80211_POWERSAVE_OFF || verbose) { 4453173275Ssam switch (val) { 4454173275Ssam case IEEE80211_POWERSAVE_OFF: 4455173275Ssam LINE_CHECK("powersavemode OFF"); 4456173275Ssam break; 4457173275Ssam case IEEE80211_POWERSAVE_CAM: 4458173275Ssam LINE_CHECK("powersavemode CAM"); 4459173275Ssam break; 4460173275Ssam case IEEE80211_POWERSAVE_PSP: 4461173275Ssam LINE_CHECK("powersavemode PSP"); 4462173275Ssam break; 4463173275Ssam case IEEE80211_POWERSAVE_PSP_CAM: 4464173275Ssam LINE_CHECK("powersavemode PSP-CAM"); 4465173275Ssam break; 4466138593Ssam } 4467173275Ssam if (get80211val(s, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1) 4468173275Ssam LINE_CHECK("powersavesleep %d", val); 4469138593Ssam } 4470138593Ssam } 4471138593Ssam 4472173275Ssam if (get80211val(s, IEEE80211_IOC_TXPOWER, &val) != -1) { 4473173275Ssam if (val & 1) 4474173275Ssam LINE_CHECK("txpower %d.5", val/2); 4475173275Ssam else 4476173275Ssam LINE_CHECK("txpower %d", val/2); 4477173275Ssam } 4478138593Ssam if (verbose) { 4479173275Ssam if (get80211val(s, IEEE80211_IOC_TXPOWMAX, &val) != -1) 4480173275Ssam LINE_CHECK("txpowmax %.1f", val/2.); 4481138593Ssam } 4482138593Ssam 4483178354Ssam if (get80211val(s, IEEE80211_IOC_DOTD, &val) != -1) { 4484178354Ssam if (val) 4485178354Ssam LINE_CHECK("dotd"); 4486178354Ssam else if (verbose) 4487178354Ssam LINE_CHECK("-dotd"); 4488178354Ssam } 4489178354Ssam 4490173275Ssam if (get80211val(s, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) { 4491173275Ssam if (val != IEEE80211_RTS_MAX || verbose) 4492173275Ssam LINE_CHECK("rtsthreshold %d", val); 4493138593Ssam } 4494138593Ssam 4495173275Ssam if (get80211val(s, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) { 4496173275Ssam if (val != IEEE80211_FRAG_MAX || verbose) 4497173275Ssam LINE_CHECK("fragthreshold %d", val); 4498170531Ssam } 4499173275Ssam if (opmode == IEEE80211_M_STA || verbose) { 4500173275Ssam if (get80211val(s, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) { 4501173275Ssam if (val != IEEE80211_HWBMISS_MAX || verbose) 4502173275Ssam LINE_CHECK("bmiss %d", val); 4503153354Ssam } 4504153354Ssam } 4505153354Ssam 4506178354Ssam if (!verbose) { 4507178354Ssam gettxparams(s); 4508178354Ssam tp = &txparams.params[chan2mode(c)]; 4509178354Ssam printrate("ucastrate", tp->ucastrate, 4510178354Ssam IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE); 4511188784Ssam printrate("mcastrate", tp->mcastrate, 2*1, 4512188784Ssam IEEE80211_RATE_MCS|0); 4513188784Ssam printrate("mgmtrate", tp->mgmtrate, 2*1, 4514188784Ssam IEEE80211_RATE_MCS|0); 4515178354Ssam if (tp->maxretry != 6) /* XXX */ 4516178354Ssam LINE_CHECK("maxretry %d", tp->maxretry); 4517178354Ssam } else { 4518178354Ssam LINE_BREAK(); 4519178354Ssam list_txparams(s); 4520178354Ssam } 4521170531Ssam 4522173275Ssam bgscaninterval = -1; 4523173275Ssam (void) get80211val(s, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval); 4524173275Ssam 4525173275Ssam if (get80211val(s, IEEE80211_IOC_SCANVALID, &val) != -1) { 4526173275Ssam if (val != bgscaninterval || verbose) 4527173275Ssam LINE_CHECK("scanvalid %u", val); 4528148416Ssam } 4529148416Ssam 4530173275Ssam bgscan = 0; 4531173275Ssam if (get80211val(s, IEEE80211_IOC_BGSCAN, &bgscan) != -1) { 4532173275Ssam if (bgscan) 4533170531Ssam LINE_CHECK("bgscan"); 4534170531Ssam else if (verbose) 4535170531Ssam LINE_CHECK("-bgscan"); 4536160687Ssam } 4537170531Ssam if (bgscan || verbose) { 4538170531Ssam if (bgscaninterval != -1) 4539170531Ssam LINE_CHECK("bgscanintvl %u", bgscaninterval); 4540173275Ssam if (get80211val(s, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1) 4541173275Ssam LINE_CHECK("bgscanidle %u", val); 4542178354Ssam if (!verbose) { 4543178354Ssam getroam(s); 4544178354Ssam rp = &roamparams.params[chan2mode(c)]; 4545178354Ssam if (rp->rssi & 1) 4546178354Ssam LINE_CHECK("roam:rssi %u.5", rp->rssi/2); 4547178354Ssam else 4548178354Ssam LINE_CHECK("roam:rssi %u", rp->rssi/2); 4549178354Ssam LINE_CHECK("roam:rate %u", rp->rate/2); 4550178354Ssam } else { 4551178354Ssam LINE_BREAK(); 4552178354Ssam list_roam(s); 4553205514Srpaulo LINE_BREAK(); 4554170531Ssam } 4555170531Ssam } 4556160687Ssam 4557165570Ssam if (IEEE80211_IS_CHAN_ANYG(c) || verbose) { 4558173275Ssam if (get80211val(s, IEEE80211_IOC_PUREG, &val) != -1) { 4559173275Ssam if (val) 4560155931Ssam LINE_CHECK("pureg"); 4561147795Ssam else if (verbose) 4562155931Ssam LINE_CHECK("-pureg"); 4563147795Ssam } 4564173275Ssam if (get80211val(s, IEEE80211_IOC_PROTMODE, &val) != -1) { 4565173275Ssam switch (val) { 4566173275Ssam case IEEE80211_PROTMODE_OFF: 4567173275Ssam LINE_CHECK("protmode OFF"); 4568173275Ssam break; 4569173275Ssam case IEEE80211_PROTMODE_CTS: 4570173275Ssam LINE_CHECK("protmode CTS"); 4571173275Ssam break; 4572173275Ssam case IEEE80211_PROTMODE_RTSCTS: 4573173275Ssam LINE_CHECK("protmode RTSCTS"); 4574173275Ssam break; 4575173275Ssam default: 4576173275Ssam LINE_CHECK("protmode UNKNOWN (0x%x)", val); 4577173275Ssam break; 4578138593Ssam } 4579138593Ssam } 4580138593Ssam } 4581138593Ssam 4582173275Ssam if (IEEE80211_IS_CHAN_HT(c) || verbose) { 4583173275Ssam gethtconf(s); 4584173275Ssam switch (htconf & 3) { 4585173275Ssam case 0: 4586173275Ssam case 2: 4587173275Ssam LINE_CHECK("-ht"); 4588173275Ssam break; 4589173275Ssam case 1: 4590173275Ssam LINE_CHECK("ht20"); 4591173275Ssam break; 4592173275Ssam case 3: 4593173275Ssam if (verbose) 4594173275Ssam LINE_CHECK("ht"); 4595173275Ssam break; 4596173275Ssam } 4597173275Ssam if (get80211val(s, IEEE80211_IOC_HTCOMPAT, &val) != -1) { 4598173275Ssam if (!val) 4599173275Ssam LINE_CHECK("-htcompat"); 4600173275Ssam else if (verbose) 4601173275Ssam LINE_CHECK("htcompat"); 4602173275Ssam } 4603173275Ssam if (get80211val(s, IEEE80211_IOC_AMPDU, &val) != -1) { 4604173275Ssam switch (val) { 4605173275Ssam case 0: 4606173275Ssam LINE_CHECK("-ampdu"); 4607173275Ssam break; 4608173275Ssam case 1: 4609173275Ssam LINE_CHECK("ampdutx -ampdurx"); 4610173275Ssam break; 4611173275Ssam case 2: 4612173275Ssam LINE_CHECK("-ampdutx ampdurx"); 4613173275Ssam break; 4614173275Ssam case 3: 4615173275Ssam if (verbose) 4616173275Ssam LINE_CHECK("ampdu"); 4617173275Ssam break; 4618173275Ssam } 4619173275Ssam } 4620173275Ssam if (get80211val(s, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) { 4621173275Ssam switch (val) { 4622173275Ssam case IEEE80211_HTCAP_MAXRXAMPDU_8K: 4623173275Ssam LINE_CHECK("ampdulimit 8k"); 4624173275Ssam break; 4625173275Ssam case IEEE80211_HTCAP_MAXRXAMPDU_16K: 4626173275Ssam LINE_CHECK("ampdulimit 16k"); 4627173275Ssam break; 4628173275Ssam case IEEE80211_HTCAP_MAXRXAMPDU_32K: 4629173275Ssam LINE_CHECK("ampdulimit 32k"); 4630173275Ssam break; 4631173275Ssam case IEEE80211_HTCAP_MAXRXAMPDU_64K: 4632173275Ssam LINE_CHECK("ampdulimit 64k"); 4633173275Ssam break; 4634173275Ssam } 4635173275Ssam } 4636173275Ssam if (get80211val(s, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) { 4637173275Ssam switch (val) { 4638173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_NA: 4639173275Ssam if (verbose) 4640183260Ssam LINE_CHECK("ampdudensity NA"); 4641173275Ssam break; 4642173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_025: 4643173275Ssam LINE_CHECK("ampdudensity .25"); 4644173275Ssam break; 4645173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_05: 4646173275Ssam LINE_CHECK("ampdudensity .5"); 4647173275Ssam break; 4648173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_1: 4649173275Ssam LINE_CHECK("ampdudensity 1"); 4650173275Ssam break; 4651173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_2: 4652173275Ssam LINE_CHECK("ampdudensity 2"); 4653173275Ssam break; 4654173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_4: 4655173275Ssam LINE_CHECK("ampdudensity 4"); 4656173275Ssam break; 4657173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_8: 4658173275Ssam LINE_CHECK("ampdudensity 8"); 4659173275Ssam break; 4660173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_16: 4661173275Ssam LINE_CHECK("ampdudensity 16"); 4662173275Ssam break; 4663173275Ssam } 4664173275Ssam } 4665173275Ssam if (get80211val(s, IEEE80211_IOC_AMSDU, &val) != -1) { 4666173275Ssam switch (val) { 4667173275Ssam case 0: 4668173275Ssam LINE_CHECK("-amsdu"); 4669173275Ssam break; 4670173275Ssam case 1: 4671173275Ssam LINE_CHECK("amsdutx -amsdurx"); 4672173275Ssam break; 4673173275Ssam case 2: 4674173275Ssam LINE_CHECK("-amsdutx amsdurx"); 4675173275Ssam break; 4676173275Ssam case 3: 4677173275Ssam if (verbose) 4678173275Ssam LINE_CHECK("amsdu"); 4679173275Ssam break; 4680173275Ssam } 4681173275Ssam } 4682173275Ssam /* XXX amsdu limit */ 4683173275Ssam if (get80211val(s, IEEE80211_IOC_SHORTGI, &val) != -1) { 4684173275Ssam if (val) 4685173275Ssam LINE_CHECK("shortgi"); 4686173275Ssam else if (verbose) 4687173275Ssam LINE_CHECK("-shortgi"); 4688173275Ssam } 4689173275Ssam if (get80211val(s, IEEE80211_IOC_HTPROTMODE, &val) != -1) { 4690173275Ssam if (val == IEEE80211_PROTMODE_OFF) 4691173275Ssam LINE_CHECK("htprotmode OFF"); 4692173275Ssam else if (val != IEEE80211_PROTMODE_RTSCTS) 4693173275Ssam LINE_CHECK("htprotmode UNKNOWN (0x%x)", val); 4694173275Ssam else if (verbose) 4695173275Ssam LINE_CHECK("htprotmode RTSCTS"); 4696173275Ssam } 4697173275Ssam if (get80211val(s, IEEE80211_IOC_PUREN, &val) != -1) { 4698173275Ssam if (val) 4699173275Ssam LINE_CHECK("puren"); 4700173275Ssam else if (verbose) 4701173275Ssam LINE_CHECK("-puren"); 4702173275Ssam } 4703183261Ssam if (get80211val(s, IEEE80211_IOC_SMPS, &val) != -1) { 4704183261Ssam if (val == IEEE80211_HTCAP_SMPS_DYNAMIC) 4705183261Ssam LINE_CHECK("smpsdyn"); 4706183261Ssam else if (val == IEEE80211_HTCAP_SMPS_ENA) 4707183261Ssam LINE_CHECK("smps"); 4708183261Ssam else if (verbose) 4709183261Ssam LINE_CHECK("-smps"); 4710183261Ssam } 4711183261Ssam if (get80211val(s, IEEE80211_IOC_RIFS, &val) != -1) { 4712183261Ssam if (val) 4713183261Ssam LINE_CHECK("rifs"); 4714183261Ssam else if (verbose) 4715183261Ssam LINE_CHECK("-rifs"); 4716183261Ssam } 4717173275Ssam } 4718173275Ssam 4719173275Ssam if (get80211val(s, IEEE80211_IOC_WME, &wme) != -1) { 4720138593Ssam if (wme) 4721155931Ssam LINE_CHECK("wme"); 4722138593Ssam else if (verbose) 4723155931Ssam LINE_CHECK("-wme"); 4724138593Ssam } else 4725138593Ssam wme = 0; 4726138593Ssam 4727173275Ssam if (get80211val(s, IEEE80211_IOC_BURST, &val) != -1) { 4728173275Ssam if (val) 4729155931Ssam LINE_CHECK("burst"); 4730153422Ssam else if (verbose) 4731155931Ssam LINE_CHECK("-burst"); 4732153422Ssam } 4733153422Ssam 4734173275Ssam if (get80211val(s, IEEE80211_IOC_FF, &val) != -1) { 4735173275Ssam if (val) 4736170531Ssam LINE_CHECK("ff"); 4737170531Ssam else if (verbose) 4738170531Ssam LINE_CHECK("-ff"); 4739170531Ssam } 4740173275Ssam if (get80211val(s, IEEE80211_IOC_TURBOP, &val) != -1) { 4741173275Ssam if (val) 4742170531Ssam LINE_CHECK("dturbo"); 4743170531Ssam else if (verbose) 4744170531Ssam LINE_CHECK("-dturbo"); 4745170531Ssam } 4746178354Ssam if (get80211val(s, IEEE80211_IOC_DWDS, &val) != -1) { 4747178354Ssam if (val) 4748178354Ssam LINE_CHECK("dwds"); 4749178354Ssam else if (verbose) 4750178354Ssam LINE_CHECK("-dwds"); 4751178354Ssam } 4752170531Ssam 4753138593Ssam if (opmode == IEEE80211_M_HOSTAP) { 4754173275Ssam if (get80211val(s, IEEE80211_IOC_HIDESSID, &val) != -1) { 4755173275Ssam if (val) 4756168075Ssam LINE_CHECK("hidessid"); 4757138593Ssam else if (verbose) 4758168075Ssam LINE_CHECK("-hidessid"); 4759138593Ssam } 4760173275Ssam if (get80211val(s, IEEE80211_IOC_APBRIDGE, &val) != -1) { 4761173275Ssam if (!val) 4762155931Ssam LINE_CHECK("-apbridge"); 4763138593Ssam else if (verbose) 4764155931Ssam LINE_CHECK("apbridge"); 4765138593Ssam } 4766173275Ssam if (get80211val(s, IEEE80211_IOC_DTIM_PERIOD, &val) != -1) 4767173275Ssam LINE_CHECK("dtimperiod %u", val); 4768138593Ssam 4769173275Ssam if (get80211val(s, IEEE80211_IOC_DOTH, &val) != -1) { 4770173275Ssam if (!val) 4771170531Ssam LINE_CHECK("-doth"); 4772170531Ssam else if (verbose) 4773170531Ssam LINE_CHECK("doth"); 4774170531Ssam } 4775178354Ssam if (get80211val(s, IEEE80211_IOC_DFS, &val) != -1) { 4776178354Ssam if (!val) 4777178354Ssam LINE_CHECK("-dfs"); 4778178354Ssam else if (verbose) 4779178354Ssam LINE_CHECK("dfs"); 4780178354Ssam } 4781173275Ssam if (get80211val(s, IEEE80211_IOC_INACTIVITY, &val) != -1) { 4782173275Ssam if (!val) 4783173275Ssam LINE_CHECK("-inact"); 4784173275Ssam else if (verbose) 4785173275Ssam LINE_CHECK("inact"); 4786173275Ssam } 4787138593Ssam } else { 4788173275Ssam if (get80211val(s, IEEE80211_IOC_ROAMING, &val) != -1) { 4789173275Ssam if (val != IEEE80211_ROAMING_AUTO || verbose) { 4790173275Ssam switch (val) { 4791138593Ssam case IEEE80211_ROAMING_DEVICE: 4792155931Ssam LINE_CHECK("roaming DEVICE"); 4793138593Ssam break; 4794138593Ssam case IEEE80211_ROAMING_AUTO: 4795155931Ssam LINE_CHECK("roaming AUTO"); 4796138593Ssam break; 4797138593Ssam case IEEE80211_ROAMING_MANUAL: 4798155931Ssam LINE_CHECK("roaming MANUAL"); 4799138593Ssam break; 4800138593Ssam default: 4801155931Ssam LINE_CHECK("roaming UNKNOWN (0x%x)", 4802173275Ssam val); 4803138593Ssam break; 4804138593Ssam } 4805138593Ssam } 4806138593Ssam } 4807138593Ssam } 4808186101Ssam 4809186904Ssam if (opmode == IEEE80211_M_AHDEMO) { 4810186904Ssam if (get80211val(s, IEEE80211_IOC_TDMA_SLOT, &val) != -1) 4811186904Ssam LINE_CHECK("tdmaslot %u", val); 4812186904Ssam if (get80211val(s, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1) 4813186904Ssam LINE_CHECK("tdmaslotcnt %u", val); 4814186904Ssam if (get80211val(s, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1) 4815186904Ssam LINE_CHECK("tdmaslotlen %u", val); 4816186904Ssam if (get80211val(s, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1) 4817186904Ssam LINE_CHECK("tdmabintval %u", val); 4818186904Ssam } else if (get80211val(s, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) { 4819173275Ssam /* XXX default define not visible */ 4820173275Ssam if (val != 100 || verbose) 4821173275Ssam LINE_CHECK("bintval %u", val); 4822138593Ssam } 4823138593Ssam 4824138593Ssam if (wme && verbose) { 4825138593Ssam LINE_BREAK(); 4826138593Ssam list_wme(s); 4827138593Ssam } 4828195618Srpaulo 4829195618Srpaulo if (opmode == IEEE80211_M_MBSS) { 4830195618Srpaulo if (get80211val(s, IEEE80211_IOC_MESH_TTL, &val) != -1) { 4831195618Srpaulo LINE_CHECK("meshttl %u", val); 4832195618Srpaulo } 4833195618Srpaulo if (get80211val(s, IEEE80211_IOC_MESH_AP, &val) != -1) { 4834195618Srpaulo if (val) 4835195618Srpaulo LINE_CHECK("meshpeering"); 4836195618Srpaulo else 4837195618Srpaulo LINE_CHECK("-meshpeering"); 4838195618Srpaulo } 4839195618Srpaulo if (get80211val(s, IEEE80211_IOC_MESH_FWRD, &val) != -1) { 4840195618Srpaulo if (val) 4841195618Srpaulo LINE_CHECK("meshforward"); 4842195618Srpaulo else 4843195618Srpaulo LINE_CHECK("-meshforward"); 4844195618Srpaulo } 4845234893Smonthadar if (get80211val(s, IEEE80211_IOC_MESH_GATE, &val) != -1) { 4846234893Smonthadar if (val) 4847234893Smonthadar LINE_CHECK("meshgate"); 4848234893Smonthadar else 4849234893Smonthadar LINE_CHECK("-meshgate"); 4850234893Smonthadar } 4851195618Srpaulo if (get80211len(s, IEEE80211_IOC_MESH_PR_METRIC, data, 12, 4852195618Srpaulo &len) != -1) { 4853195618Srpaulo data[len] = '\0'; 4854195618Srpaulo LINE_CHECK("meshmetric %s", data); 4855195618Srpaulo } 4856195618Srpaulo if (get80211len(s, IEEE80211_IOC_MESH_PR_PATH, data, 12, 4857195618Srpaulo &len) != -1) { 4858195618Srpaulo data[len] = '\0'; 4859195618Srpaulo LINE_CHECK("meshpath %s", data); 4860195618Srpaulo } 4861195618Srpaulo if (get80211val(s, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) { 4862195618Srpaulo switch (val) { 4863195618Srpaulo case IEEE80211_HWMP_ROOTMODE_DISABLED: 4864195618Srpaulo LINE_CHECK("hwmprootmode DISABLED"); 4865195618Srpaulo break; 4866195618Srpaulo case IEEE80211_HWMP_ROOTMODE_NORMAL: 4867195618Srpaulo LINE_CHECK("hwmprootmode NORMAL"); 4868195618Srpaulo break; 4869195618Srpaulo case IEEE80211_HWMP_ROOTMODE_PROACTIVE: 4870195618Srpaulo LINE_CHECK("hwmprootmode PROACTIVE"); 4871195618Srpaulo break; 4872195618Srpaulo case IEEE80211_HWMP_ROOTMODE_RANN: 4873195618Srpaulo LINE_CHECK("hwmprootmode RANN"); 4874195618Srpaulo break; 4875195618Srpaulo default: 4876195618Srpaulo LINE_CHECK("hwmprootmode UNKNOWN(%d)", val); 4877195618Srpaulo break; 4878195618Srpaulo } 4879195618Srpaulo } 4880195618Srpaulo if (get80211val(s, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) { 4881195618Srpaulo LINE_CHECK("hwmpmaxhops %u", val); 4882195618Srpaulo } 4883195618Srpaulo } 4884195618Srpaulo 4885173275Ssam LINE_BREAK(); 4886173275Ssam} 4887138593Ssam 4888173275Ssamstatic int 4889173275Ssamget80211(int s, int type, void *data, int len) 4890173275Ssam{ 4891173275Ssam struct ieee80211req ireq; 4892138593Ssam 4893173275Ssam (void) memset(&ireq, 0, sizeof(ireq)); 4894173275Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 4895173275Ssam ireq.i_type = type; 4896173275Ssam ireq.i_data = data; 4897173275Ssam ireq.i_len = len; 4898173275Ssam return ioctl(s, SIOCG80211, &ireq); 4899173275Ssam} 4900138593Ssam 4901173275Ssamstatic int 4902173275Ssamget80211len(int s, int type, void *data, int len, int *plen) 4903173275Ssam{ 4904173275Ssam struct ieee80211req ireq; 4905138593Ssam 4906173275Ssam (void) memset(&ireq, 0, sizeof(ireq)); 4907173275Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 4908173275Ssam ireq.i_type = type; 4909173275Ssam ireq.i_len = len; 4910187801Ssam assert(ireq.i_len == len); /* NB: check for 16-bit truncation */ 4911173275Ssam ireq.i_data = data; 4912173275Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) 4913173275Ssam return -1; 4914173275Ssam *plen = ireq.i_len; 4915173275Ssam return 0; 4916173275Ssam} 4917138593Ssam 4918173275Ssamstatic int 4919173275Ssamget80211val(int s, int type, int *val) 4920173275Ssam{ 4921173275Ssam struct ieee80211req ireq; 492277218Sphk 4923173275Ssam (void) memset(&ireq, 0, sizeof(ireq)); 4924173275Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 4925173275Ssam ireq.i_type = type; 4926173275Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) 4927173275Ssam return -1; 4928173275Ssam *val = ireq.i_val; 4929173275Ssam return 0; 493077218Sphk} 493177218Sphk 493277218Sphkstatic void 4933170531Ssamset80211(int s, int type, int val, int len, void *data) 493477218Sphk{ 493577218Sphk struct ieee80211req ireq; 493677218Sphk 493777218Sphk (void) memset(&ireq, 0, sizeof(ireq)); 493877218Sphk (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 493977218Sphk ireq.i_type = type; 494077218Sphk ireq.i_val = val; 494177218Sphk ireq.i_len = len; 4942187801Ssam assert(ireq.i_len == len); /* NB: check for 16-bit truncation */ 494377218Sphk ireq.i_data = data; 494491454Sbrooks if (ioctl(s, SIOCS80211, &ireq) < 0) 494577218Sphk err(1, "SIOCS80211"); 494677218Sphk} 494777218Sphk 494877218Sphkstatic const char * 494977218Sphkget_string(const char *val, const char *sep, u_int8_t *buf, int *lenp) 495077218Sphk{ 495177218Sphk int len; 495277218Sphk int hexstr; 495377218Sphk u_int8_t *p; 495477218Sphk 495577218Sphk len = *lenp; 495677218Sphk p = buf; 495777218Sphk hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x'); 495877218Sphk if (hexstr) 495977218Sphk val += 2; 496077218Sphk for (;;) { 496177218Sphk if (*val == '\0') 496277218Sphk break; 496377218Sphk if (sep != NULL && strchr(sep, *val) != NULL) { 496477218Sphk val++; 496577218Sphk break; 496677218Sphk } 496777218Sphk if (hexstr) { 4968127831Sphk if (!isxdigit((u_char)val[0])) { 496977218Sphk warnx("bad hexadecimal digits"); 497077218Sphk return NULL; 497177218Sphk } 4972127831Sphk if (!isxdigit((u_char)val[1])) { 4973127831Sphk warnx("odd count hexadecimal digits"); 4974127831Sphk return NULL; 4975127831Sphk } 497677218Sphk } 4977127831Sphk if (p >= buf + len) { 497877218Sphk if (hexstr) 497977218Sphk warnx("hexadecimal digits too long"); 498077218Sphk else 4981127831Sphk warnx("string too long"); 498277218Sphk return NULL; 498377218Sphk } 498477218Sphk if (hexstr) { 498577218Sphk#define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10) 498677218Sphk *p++ = (tohex((u_char)val[0]) << 4) | 498777218Sphk tohex((u_char)val[1]); 498877218Sphk#undef tohex 498977218Sphk val += 2; 499077218Sphk } else 499177218Sphk *p++ = *val++; 499277218Sphk } 499377218Sphk len = p - buf; 499477218Sphk /* The string "-" is treated as the empty string. */ 4995165045Ssam if (!hexstr && len == 1 && buf[0] == '-') { 499677218Sphk len = 0; 4997165045Ssam memset(buf, 0, *lenp); 4998165045Ssam } else if (len < *lenp) 499977218Sphk memset(p, 0, *lenp - len); 500077218Sphk *lenp = len; 500177218Sphk return val; 500277218Sphk} 500377218Sphk 500477218Sphkstatic void 500577218Sphkprint_string(const u_int8_t *buf, int len) 500677218Sphk{ 500777218Sphk int i; 500877218Sphk int hasspc; 500977218Sphk 501077218Sphk i = 0; 501177218Sphk hasspc = 0; 501291454Sbrooks for (; i < len; i++) { 501377218Sphk if (!isprint(buf[i]) && buf[i] != '\0') 501477218Sphk break; 501577218Sphk if (isspace(buf[i])) 501677218Sphk hasspc++; 501777218Sphk } 501877218Sphk if (i == len) { 501977218Sphk if (hasspc || len == 0 || buf[0] == '\0') 502077218Sphk printf("\"%.*s\"", len, buf); 502177218Sphk else 502277218Sphk printf("%.*s", len, buf); 502377218Sphk } else { 502477218Sphk printf("0x"); 502577218Sphk for (i = 0; i < len; i++) 502677218Sphk printf("%02x", buf[i]); 502777218Sphk } 502877218Sphk} 502977218Sphk 5030178354Ssam/* 5031178354Ssam * Virtual AP cloning support. 5032178354Ssam */ 5033178354Ssamstatic struct ieee80211_clone_params params = { 5034178354Ssam .icp_opmode = IEEE80211_M_STA, /* default to station mode */ 5035178354Ssam}; 5036178354Ssam 5037178354Ssamstatic void 5038178354Ssamwlan_create(int s, struct ifreq *ifr) 5039178354Ssam{ 5040178354Ssam static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; 5041178354Ssam 5042178354Ssam if (params.icp_parent[0] == '\0') 5043189096Srpaulo errx(1, "must specify a parent device (wlandev) when creating " 5044189096Srpaulo "a wlan device"); 5045178354Ssam if (params.icp_opmode == IEEE80211_M_WDS && 5046178354Ssam memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0) 5047178354Ssam errx(1, "no bssid specified for WDS (use wlanbssid)"); 5048178354Ssam ifr->ifr_data = (caddr_t) ¶ms; 5049178354Ssam if (ioctl(s, SIOCIFCREATE2, ifr) < 0) 5050178354Ssam err(1, "SIOCIFCREATE2"); 5051178354Ssam} 5052178354Ssam 5053178354Ssamstatic 5054178354SsamDECL_CMD_FUNC(set80211clone_wlandev, arg, d) 5055178354Ssam{ 5056178354Ssam strlcpy(params.icp_parent, arg, IFNAMSIZ); 5057178354Ssam} 5058178354Ssam 5059178354Ssamstatic 5060178354SsamDECL_CMD_FUNC(set80211clone_wlanbssid, arg, d) 5061178354Ssam{ 5062178354Ssam const struct ether_addr *ea; 5063178354Ssam 5064178354Ssam ea = ether_aton(arg); 5065178354Ssam if (ea == NULL) 5066178354Ssam errx(1, "%s: cannot parse bssid", arg); 5067178354Ssam memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN); 5068178354Ssam} 5069178354Ssam 5070178354Ssamstatic 5071178354SsamDECL_CMD_FUNC(set80211clone_wlanaddr, arg, d) 5072178354Ssam{ 5073178354Ssam const struct ether_addr *ea; 5074178354Ssam 5075178354Ssam ea = ether_aton(arg); 5076178354Ssam if (ea == NULL) 5077207320Srpaulo errx(1, "%s: cannot parse address", arg); 5078178354Ssam memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN); 5079178354Ssam params.icp_flags |= IEEE80211_CLONE_MACADDR; 5080178354Ssam} 5081178354Ssam 5082178354Ssamstatic 5083178354SsamDECL_CMD_FUNC(set80211clone_wlanmode, arg, d) 5084178354Ssam{ 5085178354Ssam#define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0) 5086178354Ssam if (iseq(arg, "sta")) 5087178354Ssam params.icp_opmode = IEEE80211_M_STA; 5088178354Ssam else if (iseq(arg, "ahdemo") || iseq(arg, "adhoc-demo")) 5089178354Ssam params.icp_opmode = IEEE80211_M_AHDEMO; 5090178354Ssam else if (iseq(arg, "ibss") || iseq(arg, "adhoc")) 5091178354Ssam params.icp_opmode = IEEE80211_M_IBSS; 5092178354Ssam else if (iseq(arg, "ap") || iseq(arg, "host")) 5093178354Ssam params.icp_opmode = IEEE80211_M_HOSTAP; 5094178354Ssam else if (iseq(arg, "wds")) 5095178354Ssam params.icp_opmode = IEEE80211_M_WDS; 5096178354Ssam else if (iseq(arg, "monitor")) 5097178354Ssam params.icp_opmode = IEEE80211_M_MONITOR; 5098186904Ssam else if (iseq(arg, "tdma")) { 5099186904Ssam params.icp_opmode = IEEE80211_M_AHDEMO; 5100186904Ssam params.icp_flags |= IEEE80211_CLONE_TDMA; 5101195618Srpaulo } else if (iseq(arg, "mesh") || iseq(arg, "mp")) /* mesh point */ 5102195618Srpaulo params.icp_opmode = IEEE80211_M_MBSS; 5103195618Srpaulo else 5104178354Ssam errx(1, "Don't know to create %s for %s", arg, name); 5105178354Ssam#undef iseq 5106178354Ssam} 5107178354Ssam 5108178354Ssamstatic void 5109178354Ssamset80211clone_beacons(const char *val, int d, int s, const struct afswtch *rafp) 5110178354Ssam{ 5111178354Ssam /* NB: inverted sense */ 5112178354Ssam if (d) 5113178354Ssam params.icp_flags &= ~IEEE80211_CLONE_NOBEACONS; 5114178354Ssam else 5115178354Ssam params.icp_flags |= IEEE80211_CLONE_NOBEACONS; 5116178354Ssam} 5117178354Ssam 5118178354Ssamstatic void 5119178354Ssamset80211clone_bssid(const char *val, int d, int s, const struct afswtch *rafp) 5120178354Ssam{ 5121178354Ssam if (d) 5122178354Ssam params.icp_flags |= IEEE80211_CLONE_BSSID; 5123178354Ssam else 5124178354Ssam params.icp_flags &= ~IEEE80211_CLONE_BSSID; 5125178354Ssam} 5126178354Ssam 5127178354Ssamstatic void 5128178354Ssamset80211clone_wdslegacy(const char *val, int d, int s, const struct afswtch *rafp) 5129178354Ssam{ 5130178354Ssam if (d) 5131178354Ssam params.icp_flags |= IEEE80211_CLONE_WDSLEGACY; 5132178354Ssam else 5133178354Ssam params.icp_flags &= ~IEEE80211_CLONE_WDSLEGACY; 5134178354Ssam} 5135178354Ssam 5136138593Ssamstatic struct cmd ieee80211_cmds[] = { 5137138593Ssam DEF_CMD_ARG("ssid", set80211ssid), 5138138593Ssam DEF_CMD_ARG("nwid", set80211ssid), 5139195618Srpaulo DEF_CMD_ARG("meshid", set80211meshid), 5140138593Ssam DEF_CMD_ARG("stationname", set80211stationname), 5141138593Ssam DEF_CMD_ARG("station", set80211stationname), /* BSD/OS */ 5142138593Ssam DEF_CMD_ARG("channel", set80211channel), 5143138593Ssam DEF_CMD_ARG("authmode", set80211authmode), 5144138593Ssam DEF_CMD_ARG("powersavemode", set80211powersavemode), 5145138593Ssam DEF_CMD("powersave", 1, set80211powersave), 5146138593Ssam DEF_CMD("-powersave", 0, set80211powersave), 5147138593Ssam DEF_CMD_ARG("powersavesleep", set80211powersavesleep), 5148138593Ssam DEF_CMD_ARG("wepmode", set80211wepmode), 5149138593Ssam DEF_CMD("wep", 1, set80211wep), 5150138593Ssam DEF_CMD("-wep", 0, set80211wep), 5151139493Ssam DEF_CMD_ARG("deftxkey", set80211weptxkey), 5152138593Ssam DEF_CMD_ARG("weptxkey", set80211weptxkey), 5153138593Ssam DEF_CMD_ARG("wepkey", set80211wepkey), 5154138593Ssam DEF_CMD_ARG("nwkey", set80211nwkey), /* NetBSD */ 5155138593Ssam DEF_CMD("-nwkey", 0, set80211wep), /* NetBSD */ 5156138593Ssam DEF_CMD_ARG("rtsthreshold", set80211rtsthreshold), 5157138593Ssam DEF_CMD_ARG("protmode", set80211protmode), 5158138593Ssam DEF_CMD_ARG("txpower", set80211txpower), 5159138593Ssam DEF_CMD_ARG("roaming", set80211roaming), 5160138593Ssam DEF_CMD("wme", 1, set80211wme), 5161138593Ssam DEF_CMD("-wme", 0, set80211wme), 5162178354Ssam DEF_CMD("wmm", 1, set80211wme), 5163178354Ssam DEF_CMD("-wmm", 0, set80211wme), 5164138593Ssam DEF_CMD("hidessid", 1, set80211hidessid), 5165138593Ssam DEF_CMD("-hidessid", 0, set80211hidessid), 5166138593Ssam DEF_CMD("apbridge", 1, set80211apbridge), 5167138593Ssam DEF_CMD("-apbridge", 0, set80211apbridge), 5168138593Ssam DEF_CMD_ARG("chanlist", set80211chanlist), 5169138593Ssam DEF_CMD_ARG("bssid", set80211bssid), 5170138593Ssam DEF_CMD_ARG("ap", set80211bssid), 5171138593Ssam DEF_CMD("scan", 0, set80211scan), 5172138593Ssam DEF_CMD_ARG("list", set80211list), 5173138593Ssam DEF_CMD_ARG2("cwmin", set80211cwmin), 5174138593Ssam DEF_CMD_ARG2("cwmax", set80211cwmax), 5175138593Ssam DEF_CMD_ARG2("aifs", set80211aifs), 5176138593Ssam DEF_CMD_ARG2("txoplimit", set80211txoplimit), 5177148621Ssam DEF_CMD_ARG("acm", set80211acm), 5178148621Ssam DEF_CMD_ARG("-acm", set80211noacm), 5179148621Ssam DEF_CMD_ARG("ack", set80211ackpolicy), 5180148621Ssam DEF_CMD_ARG("-ack", set80211noackpolicy), 5181138593Ssam DEF_CMD_ARG2("bss:cwmin", set80211bsscwmin), 5182138593Ssam DEF_CMD_ARG2("bss:cwmax", set80211bsscwmax), 5183138593Ssam DEF_CMD_ARG2("bss:aifs", set80211bssaifs), 5184138593Ssam DEF_CMD_ARG2("bss:txoplimit", set80211bsstxoplimit), 5185138593Ssam DEF_CMD_ARG("dtimperiod", set80211dtimperiod), 5186138593Ssam DEF_CMD_ARG("bintval", set80211bintval), 5187138593Ssam DEF_CMD("mac:open", IEEE80211_MACCMD_POLICY_OPEN, set80211maccmd), 5188138593Ssam DEF_CMD("mac:allow", IEEE80211_MACCMD_POLICY_ALLOW, set80211maccmd), 5189138593Ssam DEF_CMD("mac:deny", IEEE80211_MACCMD_POLICY_DENY, set80211maccmd), 5190178354Ssam DEF_CMD("mac:radius", IEEE80211_MACCMD_POLICY_RADIUS, set80211maccmd), 5191138593Ssam DEF_CMD("mac:flush", IEEE80211_MACCMD_FLUSH, set80211maccmd), 5192138593Ssam DEF_CMD("mac:detach", IEEE80211_MACCMD_DETACH, set80211maccmd), 5193138593Ssam DEF_CMD_ARG("mac:add", set80211addmac), 5194138593Ssam DEF_CMD_ARG("mac:del", set80211delmac), 5195138593Ssam DEF_CMD_ARG("mac:kick", set80211kickmac), 5196147795Ssam DEF_CMD("pureg", 1, set80211pureg), 5197147795Ssam DEF_CMD("-pureg", 0, set80211pureg), 5198170531Ssam DEF_CMD("ff", 1, set80211fastframes), 5199170531Ssam DEF_CMD("-ff", 0, set80211fastframes), 5200170531Ssam DEF_CMD("dturbo", 1, set80211dturbo), 5201170531Ssam DEF_CMD("-dturbo", 0, set80211dturbo), 5202170531Ssam DEF_CMD("bgscan", 1, set80211bgscan), 5203170531Ssam DEF_CMD("-bgscan", 0, set80211bgscan), 5204170531Ssam DEF_CMD_ARG("bgscanidle", set80211bgscanidle), 5205170531Ssam DEF_CMD_ARG("bgscanintvl", set80211bgscanintvl), 5206170531Ssam DEF_CMD_ARG("scanvalid", set80211scanvalid), 5207227336Sadrian DEF_CMD("quiet", 1, set80211quiet), 5208227336Sadrian DEF_CMD("-quiet", 0, set80211quiet), 5209227336Sadrian DEF_CMD_ARG("quiet_count", set80211quietcount), 5210227336Sadrian DEF_CMD_ARG("quiet_period", set80211quietperiod), 5211227336Sadrian DEF_CMD_ARG("quiet_dur", set80211quietduration), 5212227336Sadrian DEF_CMD_ARG("quiet_offset", set80211quietoffset), 5213178354Ssam DEF_CMD_ARG("roam:rssi", set80211roamrssi), 5214178354Ssam DEF_CMD_ARG("roam:rate", set80211roamrate), 5215153354Ssam DEF_CMD_ARG("mcastrate", set80211mcastrate), 5216178354Ssam DEF_CMD_ARG("ucastrate", set80211ucastrate), 5217178354Ssam DEF_CMD_ARG("mgtrate", set80211mgtrate), 5218178354Ssam DEF_CMD_ARG("mgmtrate", set80211mgtrate), 5219178354Ssam DEF_CMD_ARG("maxretry", set80211maxretry), 5220148416Ssam DEF_CMD_ARG("fragthreshold", set80211fragthreshold), 5221153422Ssam DEF_CMD("burst", 1, set80211burst), 5222153422Ssam DEF_CMD("-burst", 0, set80211burst), 5223160687Ssam DEF_CMD_ARG("bmiss", set80211bmissthreshold), 5224160687Ssam DEF_CMD_ARG("bmissthreshold", set80211bmissthreshold), 5225173275Ssam DEF_CMD("shortgi", 1, set80211shortgi), 5226173275Ssam DEF_CMD("-shortgi", 0, set80211shortgi), 5227173275Ssam DEF_CMD("ampdurx", 2, set80211ampdu), 5228173275Ssam DEF_CMD("-ampdurx", -2, set80211ampdu), 5229173275Ssam DEF_CMD("ampdutx", 1, set80211ampdu), 5230173275Ssam DEF_CMD("-ampdutx", -1, set80211ampdu), 5231173275Ssam DEF_CMD("ampdu", 3, set80211ampdu), /* NB: tx+rx */ 5232173275Ssam DEF_CMD("-ampdu", -3, set80211ampdu), 5233173275Ssam DEF_CMD_ARG("ampdulimit", set80211ampdulimit), 5234173275Ssam DEF_CMD_ARG("ampdudensity", set80211ampdudensity), 5235173275Ssam DEF_CMD("amsdurx", 2, set80211amsdu), 5236173275Ssam DEF_CMD("-amsdurx", -2, set80211amsdu), 5237173275Ssam DEF_CMD("amsdutx", 1, set80211amsdu), 5238173275Ssam DEF_CMD("-amsdutx", -1, set80211amsdu), 5239173275Ssam DEF_CMD("amsdu", 3, set80211amsdu), /* NB: tx+rx */ 5240173275Ssam DEF_CMD("-amsdu", -3, set80211amsdu), 5241173275Ssam DEF_CMD_ARG("amsdulimit", set80211amsdulimit), 5242173275Ssam DEF_CMD("puren", 1, set80211puren), 5243173275Ssam DEF_CMD("-puren", 0, set80211puren), 5244170531Ssam DEF_CMD("doth", 1, set80211doth), 5245170531Ssam DEF_CMD("-doth", 0, set80211doth), 5246178354Ssam DEF_CMD("dfs", 1, set80211dfs), 5247178354Ssam DEF_CMD("-dfs", 0, set80211dfs), 5248173275Ssam DEF_CMD("htcompat", 1, set80211htcompat), 5249173275Ssam DEF_CMD("-htcompat", 0, set80211htcompat), 5250178354Ssam DEF_CMD("dwds", 1, set80211dwds), 5251178354Ssam DEF_CMD("-dwds", 0, set80211dwds), 5252173275Ssam DEF_CMD("inact", 1, set80211inact), 5253173275Ssam DEF_CMD("-inact", 0, set80211inact), 5254178354Ssam DEF_CMD("tsn", 1, set80211tsn), 5255178354Ssam DEF_CMD("-tsn", 0, set80211tsn), 5256178354Ssam DEF_CMD_ARG("regdomain", set80211regdomain), 5257178354Ssam DEF_CMD_ARG("country", set80211country), 5258178354Ssam DEF_CMD("indoor", 'I', set80211location), 5259178354Ssam DEF_CMD("-indoor", 'O', set80211location), 5260178354Ssam DEF_CMD("outdoor", 'O', set80211location), 5261178354Ssam DEF_CMD("-outdoor", 'I', set80211location), 5262178354Ssam DEF_CMD("anywhere", ' ', set80211location), 5263178354Ssam DEF_CMD("ecm", 1, set80211ecm), 5264178354Ssam DEF_CMD("-ecm", 0, set80211ecm), 5265178354Ssam DEF_CMD("dotd", 1, set80211dotd), 5266178354Ssam DEF_CMD("-dotd", 0, set80211dotd), 5267173275Ssam DEF_CMD_ARG("htprotmode", set80211htprotmode), 5268173275Ssam DEF_CMD("ht20", 1, set80211htconf), 5269173275Ssam DEF_CMD("-ht20", 0, set80211htconf), 5270173275Ssam DEF_CMD("ht40", 3, set80211htconf), /* NB: 20+40 */ 5271173275Ssam DEF_CMD("-ht40", 0, set80211htconf), 5272173275Ssam DEF_CMD("ht", 3, set80211htconf), /* NB: 20+40 */ 5273173275Ssam DEF_CMD("-ht", 0, set80211htconf), 5274183261Ssam DEF_CMD("rifs", 1, set80211rifs), 5275183261Ssam DEF_CMD("-rifs", 0, set80211rifs), 5276183261Ssam DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA, set80211smps), 5277183261Ssam DEF_CMD("smpsdyn", IEEE80211_HTCAP_SMPS_DYNAMIC, set80211smps), 5278183261Ssam DEF_CMD("-smps", IEEE80211_HTCAP_SMPS_OFF, set80211smps), 5279178354Ssam /* XXX for testing */ 5280178354Ssam DEF_CMD_ARG("chanswitch", set80211chanswitch), 5281178354Ssam 5282186904Ssam DEF_CMD_ARG("tdmaslot", set80211tdmaslot), 5283186904Ssam DEF_CMD_ARG("tdmaslotcnt", set80211tdmaslotcnt), 5284186904Ssam DEF_CMD_ARG("tdmaslotlen", set80211tdmaslotlen), 5285186904Ssam DEF_CMD_ARG("tdmabintval", set80211tdmabintval), 5286186904Ssam 5287195618Srpaulo DEF_CMD_ARG("meshttl", set80211meshttl), 5288195618Srpaulo DEF_CMD("meshforward", 1, set80211meshforward), 5289195618Srpaulo DEF_CMD("-meshforward", 0, set80211meshforward), 5290234893Smonthadar DEF_CMD("meshgate", 1, set80211meshgate), 5291234893Smonthadar DEF_CMD("-meshgate", 0, set80211meshgate), 5292195618Srpaulo DEF_CMD("meshpeering", 1, set80211meshpeering), 5293195618Srpaulo DEF_CMD("-meshpeering", 0, set80211meshpeering), 5294195618Srpaulo DEF_CMD_ARG("meshmetric", set80211meshmetric), 5295195618Srpaulo DEF_CMD_ARG("meshpath", set80211meshpath), 5296195618Srpaulo DEF_CMD("meshrt:flush", IEEE80211_MESH_RTCMD_FLUSH, set80211meshrtcmd), 5297195618Srpaulo DEF_CMD_ARG("meshrt:add", set80211addmeshrt), 5298195618Srpaulo DEF_CMD_ARG("meshrt:del", set80211delmeshrt), 5299195618Srpaulo DEF_CMD_ARG("hwmprootmode", set80211hwmprootmode), 5300195618Srpaulo DEF_CMD_ARG("hwmpmaxhops", set80211hwmpmaxhops), 5301195618Srpaulo 5302178354Ssam /* vap cloning support */ 5303178354Ssam DEF_CLONE_CMD_ARG("wlanaddr", set80211clone_wlanaddr), 5304178354Ssam DEF_CLONE_CMD_ARG("wlanbssid", set80211clone_wlanbssid), 5305178354Ssam DEF_CLONE_CMD_ARG("wlandev", set80211clone_wlandev), 5306178354Ssam DEF_CLONE_CMD_ARG("wlanmode", set80211clone_wlanmode), 5307178354Ssam DEF_CLONE_CMD("beacons", 1, set80211clone_beacons), 5308178354Ssam DEF_CLONE_CMD("-beacons", 0, set80211clone_beacons), 5309178354Ssam DEF_CLONE_CMD("bssid", 1, set80211clone_bssid), 5310178354Ssam DEF_CLONE_CMD("-bssid", 0, set80211clone_bssid), 5311178354Ssam DEF_CLONE_CMD("wdslegacy", 1, set80211clone_wdslegacy), 5312178354Ssam DEF_CLONE_CMD("-wdslegacy", 0, set80211clone_wdslegacy), 5313138593Ssam}; 5314138593Ssamstatic struct afswtch af_ieee80211 = { 5315138593Ssam .af_name = "af_ieee80211", 5316138593Ssam .af_af = AF_UNSPEC, 5317139494Ssam .af_other_status = ieee80211_status, 5318138593Ssam}; 5319138593Ssam 5320138593Ssamstatic __constructor void 5321138593Ssamieee80211_ctor(void) 5322138593Ssam{ 5323138593Ssam#define N(a) (sizeof(a) / sizeof(a[0])) 5324138593Ssam int i; 5325138593Ssam 5326138593Ssam for (i = 0; i < N(ieee80211_cmds); i++) 5327138593Ssam cmd_register(&ieee80211_cmds[i]); 5328138593Ssam af_register(&af_ieee80211); 5329189096Srpaulo clone_setdefcallback("wlan", wlan_create); 5330138593Ssam#undef N 5331138593Ssam} 5332