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/* 887148686Sstefanf * This function is purely a NetBSD compatability 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 1340170531Ssamset80211bgscan(const char *val, int d, int s, const struct afswtch *rafp) 1341153422Ssam{ 1342170531Ssam set80211(s, IEEE80211_IOC_BGSCAN, d, 0, NULL); 1343153422Ssam} 1344153422Ssam 1345148416Ssamstatic 1346170531SsamDECL_CMD_FUNC(set80211bgscanidle, val, d) 1347170531Ssam{ 1348170531Ssam set80211(s, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL); 1349170531Ssam} 1350170531Ssam 1351170531Ssamstatic 1352170531SsamDECL_CMD_FUNC(set80211bgscanintvl, val, d) 1353170531Ssam{ 1354170531Ssam set80211(s, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL); 1355170531Ssam} 1356170531Ssam 1357170531Ssamstatic 1358170531SsamDECL_CMD_FUNC(set80211scanvalid, val, d) 1359170531Ssam{ 1360170531Ssam set80211(s, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL); 1361170531Ssam} 1362170531Ssam 1363178354Ssam/* 1364178354Ssam * Parse an optional trailing specification of which netbands 1365178354Ssam * to apply a parameter to. This is basically the same syntax 1366178354Ssam * as used for channels but you can concatenate to specify 1367178354Ssam * multiple. For example: 1368178354Ssam * 14:abg apply to 11a, 11b, and 11g 1369178354Ssam * 6:ht apply to 11na and 11ng 1370178354Ssam * We don't make a big effort to catch silly things; this is 1371178354Ssam * really a convenience mechanism. 1372178354Ssam */ 1373178354Ssamstatic int 1374178354Ssamgetmodeflags(const char *val) 1375170531Ssam{ 1376178354Ssam const char *cp; 1377178354Ssam int flags; 1378178354Ssam 1379178354Ssam flags = 0; 1380178354Ssam 1381178354Ssam cp = strchr(val, ':'); 1382178354Ssam if (cp != NULL) { 1383178354Ssam for (cp++; isalpha((int) *cp); cp++) { 1384178354Ssam /* accept mixed case */ 1385178354Ssam int c = *cp; 1386178354Ssam if (isupper(c)) 1387178354Ssam c = tolower(c); 1388178354Ssam switch (c) { 1389178354Ssam case 'a': /* 802.11a */ 1390178354Ssam flags |= IEEE80211_CHAN_A; 1391178354Ssam break; 1392178354Ssam case 'b': /* 802.11b */ 1393178354Ssam flags |= IEEE80211_CHAN_B; 1394178354Ssam break; 1395178354Ssam case 'g': /* 802.11g */ 1396178354Ssam flags |= IEEE80211_CHAN_G; 1397178354Ssam break; 1398178354Ssam case 'n': /* 802.11n */ 1399178354Ssam flags |= IEEE80211_CHAN_HT; 1400178354Ssam break; 1401178354Ssam case 'd': /* dt = Atheros Dynamic Turbo */ 1402178354Ssam flags |= IEEE80211_CHAN_TURBO; 1403178354Ssam break; 1404178354Ssam case 't': /* ht, dt, st, t */ 1405178354Ssam /* dt and unadorned t specify Dynamic Turbo */ 1406178354Ssam if ((flags & (IEEE80211_CHAN_STURBO|IEEE80211_CHAN_HT)) == 0) 1407178354Ssam flags |= IEEE80211_CHAN_TURBO; 1408178354Ssam break; 1409178354Ssam case 's': /* st = Atheros Static Turbo */ 1410178354Ssam flags |= IEEE80211_CHAN_STURBO; 1411178354Ssam break; 1412188784Ssam case 'h': /* 1/2-width channels */ 1413188784Ssam flags |= IEEE80211_CHAN_HALF; 1414188784Ssam break; 1415188784Ssam case 'q': /* 1/4-width channels */ 1416188784Ssam flags |= IEEE80211_CHAN_QUARTER; 1417188784Ssam break; 1418178354Ssam default: 1419178354Ssam errx(-1, "%s: Invalid mode attribute %c\n", 1420178354Ssam val, *cp); 1421178354Ssam } 1422178354Ssam } 1423178354Ssam } 1424178354Ssam return flags; 1425170531Ssam} 1426170531Ssam 1427178354Ssam#define IEEE80211_CHAN_HTA (IEEE80211_CHAN_HT|IEEE80211_CHAN_5GHZ) 1428178354Ssam#define IEEE80211_CHAN_HTG (IEEE80211_CHAN_HT|IEEE80211_CHAN_2GHZ) 1429178354Ssam 1430178354Ssam#define _APPLY(_flags, _base, _param, _v) do { \ 1431178354Ssam if (_flags & IEEE80211_CHAN_HT) { \ 1432178354Ssam if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\ 1433178354Ssam _base.params[IEEE80211_MODE_11NA]._param = _v; \ 1434178354Ssam _base.params[IEEE80211_MODE_11NG]._param = _v; \ 1435178354Ssam } else if (_flags & IEEE80211_CHAN_5GHZ) \ 1436178354Ssam _base.params[IEEE80211_MODE_11NA]._param = _v; \ 1437178354Ssam else \ 1438178354Ssam _base.params[IEEE80211_MODE_11NG]._param = _v; \ 1439178354Ssam } \ 1440178354Ssam if (_flags & IEEE80211_CHAN_TURBO) { \ 1441178354Ssam if ((_flags & (IEEE80211_CHAN_5GHZ|IEEE80211_CHAN_2GHZ)) == 0) {\ 1442178354Ssam _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \ 1443178354Ssam _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \ 1444178354Ssam } else if (_flags & IEEE80211_CHAN_5GHZ) \ 1445178354Ssam _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \ 1446178354Ssam else \ 1447178354Ssam _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \ 1448178354Ssam } \ 1449178354Ssam if (_flags & IEEE80211_CHAN_STURBO) \ 1450178354Ssam _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \ 1451178354Ssam if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \ 1452178354Ssam _base.params[IEEE80211_MODE_11A]._param = _v; \ 1453178354Ssam if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \ 1454178354Ssam _base.params[IEEE80211_MODE_11G]._param = _v; \ 1455178354Ssam if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \ 1456178354Ssam _base.params[IEEE80211_MODE_11B]._param = _v; \ 1457188784Ssam if (_flags & IEEE80211_CHAN_HALF) \ 1458188784Ssam _base.params[IEEE80211_MODE_HALF]._param = _v; \ 1459188784Ssam if (_flags & IEEE80211_CHAN_QUARTER) \ 1460188784Ssam _base.params[IEEE80211_MODE_QUARTER]._param = _v; \ 1461178354Ssam} while (0) 1462178354Ssam#define _APPLY1(_flags, _base, _param, _v) do { \ 1463178354Ssam if (_flags & IEEE80211_CHAN_HT) { \ 1464178354Ssam if (_flags & IEEE80211_CHAN_5GHZ) \ 1465178354Ssam _base.params[IEEE80211_MODE_11NA]._param = _v; \ 1466178354Ssam else \ 1467178354Ssam _base.params[IEEE80211_MODE_11NG]._param = _v; \ 1468178354Ssam } else if ((_flags & IEEE80211_CHAN_108A) == IEEE80211_CHAN_108A) \ 1469178354Ssam _base.params[IEEE80211_MODE_TURBO_A]._param = _v; \ 1470178354Ssam else if ((_flags & IEEE80211_CHAN_108G) == IEEE80211_CHAN_108G) \ 1471178354Ssam _base.params[IEEE80211_MODE_TURBO_G]._param = _v; \ 1472178354Ssam else if ((_flags & IEEE80211_CHAN_ST) == IEEE80211_CHAN_ST) \ 1473178354Ssam _base.params[IEEE80211_MODE_STURBO_A]._param = _v; \ 1474188784Ssam else if (_flags & IEEE80211_CHAN_HALF) \ 1475188784Ssam _base.params[IEEE80211_MODE_HALF]._param = _v; \ 1476188784Ssam else if (_flags & IEEE80211_CHAN_QUARTER) \ 1477188784Ssam _base.params[IEEE80211_MODE_QUARTER]._param = _v; \ 1478178354Ssam else if ((_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) \ 1479178354Ssam _base.params[IEEE80211_MODE_11A]._param = _v; \ 1480178354Ssam else if ((_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) \ 1481178354Ssam _base.params[IEEE80211_MODE_11G]._param = _v; \ 1482178354Ssam else if ((_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) \ 1483178354Ssam _base.params[IEEE80211_MODE_11B]._param = _v; \ 1484178354Ssam} while (0) 1485178354Ssam#define _APPLY_RATE(_flags, _base, _param, _v) do { \ 1486178354Ssam if (_flags & IEEE80211_CHAN_HT) { \ 1487188784Ssam (_v) = (_v / 2) | IEEE80211_RATE_MCS; \ 1488178354Ssam } \ 1489188784Ssam _APPLY(_flags, _base, _param, _v); \ 1490178354Ssam} while (0) 1491178354Ssam#define _APPLY_RATE1(_flags, _base, _param, _v) do { \ 1492178354Ssam if (_flags & IEEE80211_CHAN_HT) { \ 1493188784Ssam (_v) = (_v / 2) | IEEE80211_RATE_MCS; \ 1494188784Ssam } \ 1495188784Ssam _APPLY1(_flags, _base, _param, _v); \ 1496178354Ssam} while (0) 1497178354Ssam 1498170531Ssamstatic 1499178354SsamDECL_CMD_FUNC(set80211roamrssi, val, d) 1500170531Ssam{ 1501178354Ssam double v = atof(val); 1502178354Ssam int rssi, flags; 1503178354Ssam 1504178354Ssam rssi = (int) (2*v); 1505178354Ssam if (rssi != 2*v) 1506178354Ssam errx(-1, "invalid rssi (must be .5 dBm units)"); 1507178354Ssam flags = getmodeflags(val); 1508178354Ssam getroam(s); 1509178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1510178354Ssam flags = getcurchan(s)->ic_flags; 1511178354Ssam _APPLY1(flags, roamparams, rssi, rssi); 1512178354Ssam } else 1513178354Ssam _APPLY(flags, roamparams, rssi, rssi); 1514178354Ssam callback_register(setroam_cb, &roamparams); 1515170531Ssam} 1516170531Ssam 1517188784Ssamstatic int 1518188784Ssamgetrate(const char *val, const char *tag) 1519188784Ssam{ 1520188784Ssam double v = atof(val); 1521188784Ssam int rate; 1522188784Ssam 1523188784Ssam rate = (int) (2*v); 1524188784Ssam if (rate != 2*v) 1525188784Ssam errx(-1, "invalid %s rate (must be .5 Mb/s units)", tag); 1526188784Ssam return rate; /* NB: returns 2x the specified value */ 1527188784Ssam} 1528188784Ssam 1529170531Ssamstatic 1530178354SsamDECL_CMD_FUNC(set80211roamrate, val, d) 1531170531Ssam{ 1532188784Ssam int rate, flags; 1533178354Ssam 1534188784Ssam rate = getrate(val, "roam"); 1535178354Ssam flags = getmodeflags(val); 1536178354Ssam getroam(s); 1537178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1538178354Ssam flags = getcurchan(s)->ic_flags; 1539188784Ssam _APPLY_RATE1(flags, roamparams, rate, rate); 1540178354Ssam } else 1541188784Ssam _APPLY_RATE(flags, roamparams, rate, rate); 1542178354Ssam callback_register(setroam_cb, &roamparams); 1543170531Ssam} 1544170531Ssam 1545170531Ssamstatic 1546178354SsamDECL_CMD_FUNC(set80211mcastrate, val, d) 1547170531Ssam{ 1548188784Ssam int rate, flags; 1549178354Ssam 1550188784Ssam rate = getrate(val, "mcast"); 1551178354Ssam flags = getmodeflags(val); 1552178354Ssam gettxparams(s); 1553178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1554178354Ssam flags = getcurchan(s)->ic_flags; 1555188784Ssam _APPLY_RATE1(flags, txparams, mcastrate, rate); 1556178354Ssam } else 1557188784Ssam _APPLY_RATE(flags, txparams, mcastrate, rate); 1558178354Ssam callback_register(settxparams_cb, &txparams); 1559170531Ssam} 1560170531Ssam 1561170531Ssamstatic 1562178354SsamDECL_CMD_FUNC(set80211mgtrate, val, d) 1563170531Ssam{ 1564188784Ssam int rate, flags; 1565178354Ssam 1566188784Ssam rate = getrate(val, "mgmt"); 1567178354Ssam flags = getmodeflags(val); 1568178354Ssam gettxparams(s); 1569178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1570178354Ssam flags = getcurchan(s)->ic_flags; 1571188784Ssam _APPLY_RATE1(flags, txparams, mgmtrate, rate); 1572178354Ssam } else 1573188784Ssam _APPLY_RATE(flags, txparams, mgmtrate, rate); 1574178354Ssam callback_register(settxparams_cb, &txparams); 1575170531Ssam} 1576170531Ssam 1577170531Ssamstatic 1578178354SsamDECL_CMD_FUNC(set80211ucastrate, val, d) 1579170531Ssam{ 1580188784Ssam int flags; 1581178354Ssam 1582178354Ssam gettxparams(s); 1583178354Ssam flags = getmodeflags(val); 1584178354Ssam if (isanyarg(val)) { 1585178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1586178354Ssam flags = getcurchan(s)->ic_flags; 1587178354Ssam _APPLY1(flags, txparams, ucastrate, 1588178354Ssam IEEE80211_FIXED_RATE_NONE); 1589178354Ssam } else 1590178354Ssam _APPLY(flags, txparams, ucastrate, 1591178354Ssam IEEE80211_FIXED_RATE_NONE); 1592178354Ssam } else { 1593188784Ssam int rate = getrate(val, "ucast"); 1594178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1595178354Ssam flags = getcurchan(s)->ic_flags; 1596188784Ssam _APPLY_RATE1(flags, txparams, ucastrate, rate); 1597178354Ssam } else 1598188784Ssam _APPLY_RATE(flags, txparams, ucastrate, rate); 1599178354Ssam } 1600178354Ssam callback_register(settxparams_cb, &txparams); 1601170531Ssam} 1602170531Ssam 1603170531Ssamstatic 1604178354SsamDECL_CMD_FUNC(set80211maxretry, val, d) 1605153354Ssam{ 1606178354Ssam int v = atoi(val), flags; 1607178354Ssam 1608178354Ssam flags = getmodeflags(val); 1609178354Ssam gettxparams(s); 1610178354Ssam if (flags == 0) { /* NB: no flags => current channel */ 1611178354Ssam flags = getcurchan(s)->ic_flags; 1612178354Ssam _APPLY1(flags, txparams, maxretry, v); 1613178354Ssam } else 1614178354Ssam _APPLY(flags, txparams, maxretry, v); 1615178354Ssam callback_register(settxparams_cb, &txparams); 1616153354Ssam} 1617178354Ssam#undef _APPLY_RATE 1618178354Ssam#undef _APPLY 1619178354Ssam#undef IEEE80211_CHAN_HTA 1620178354Ssam#undef IEEE80211_CHAN_HTG 1621153354Ssam 1622153354Ssamstatic 1623148416SsamDECL_CMD_FUNC(set80211fragthreshold, val, d) 1624148416Ssam{ 1625148416Ssam set80211(s, IEEE80211_IOC_FRAGTHRESHOLD, 1626148416Ssam isundefarg(val) ? IEEE80211_FRAG_MAX : atoi(val), 0, NULL); 1627148416Ssam} 1628148416Ssam 1629160687Ssamstatic 1630160687SsamDECL_CMD_FUNC(set80211bmissthreshold, val, d) 1631160687Ssam{ 1632160687Ssam set80211(s, IEEE80211_IOC_BMISSTHRESHOLD, 1633160687Ssam isundefarg(val) ? IEEE80211_HWBMISS_MAX : atoi(val), 0, NULL); 1634160687Ssam} 1635160687Ssam 1636170531Ssamstatic void 1637170531Ssamset80211burst(const char *val, int d, int s, const struct afswtch *rafp) 1638170531Ssam{ 1639170531Ssam set80211(s, IEEE80211_IOC_BURST, d, 0, NULL); 1640170531Ssam} 1641170531Ssam 1642170531Ssamstatic void 1643170531Ssamset80211doth(const char *val, int d, int s, const struct afswtch *rafp) 1644170531Ssam{ 1645170531Ssam set80211(s, IEEE80211_IOC_DOTH, d, 0, NULL); 1646170531Ssam} 1647170531Ssam 1648173275Ssamstatic void 1649178354Ssamset80211dfs(const char *val, int d, int s, const struct afswtch *rafp) 1650178354Ssam{ 1651178354Ssam set80211(s, IEEE80211_IOC_DFS, d, 0, NULL); 1652178354Ssam} 1653178354Ssam 1654178354Ssamstatic void 1655173275Ssamset80211shortgi(const char *val, int d, int s, const struct afswtch *rafp) 1656173275Ssam{ 1657173275Ssam set80211(s, IEEE80211_IOC_SHORTGI, 1658173275Ssam d ? (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) : 0, 1659173275Ssam 0, NULL); 1660173275Ssam} 1661173275Ssam 1662173275Ssamstatic void 1663173275Ssamset80211ampdu(const char *val, int d, int s, const struct afswtch *rafp) 1664173275Ssam{ 1665173275Ssam int ampdu; 1666173275Ssam 1667173275Ssam if (get80211val(s, IEEE80211_IOC_AMPDU, &du) < 0) 1668173275Ssam errx(-1, "cannot get AMPDU setting"); 1669173275Ssam if (d < 0) { 1670173275Ssam d = -d; 1671173275Ssam ampdu &= ~d; 1672173275Ssam } else 1673173275Ssam ampdu |= d; 1674173275Ssam set80211(s, IEEE80211_IOC_AMPDU, ampdu, 0, NULL); 1675173275Ssam} 1676173275Ssam 1677173275Ssamstatic 1678173275SsamDECL_CMD_FUNC(set80211ampdulimit, val, d) 1679173275Ssam{ 1680173275Ssam int v; 1681173275Ssam 1682173275Ssam switch (atoi(val)) { 1683173275Ssam case 8: 1684173275Ssam case 8*1024: 1685173275Ssam v = IEEE80211_HTCAP_MAXRXAMPDU_8K; 1686173275Ssam break; 1687173275Ssam case 16: 1688173275Ssam case 16*1024: 1689173275Ssam v = IEEE80211_HTCAP_MAXRXAMPDU_16K; 1690173275Ssam break; 1691173275Ssam case 32: 1692173275Ssam case 32*1024: 1693173275Ssam v = IEEE80211_HTCAP_MAXRXAMPDU_32K; 1694173275Ssam break; 1695173275Ssam case 64: 1696173275Ssam case 64*1024: 1697173275Ssam v = IEEE80211_HTCAP_MAXRXAMPDU_64K; 1698173275Ssam break; 1699173275Ssam default: 1700173275Ssam errx(-1, "invalid A-MPDU limit %s", val); 1701173275Ssam } 1702173275Ssam set80211(s, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL); 1703173275Ssam} 1704173275Ssam 1705173275Ssamstatic 1706173275SsamDECL_CMD_FUNC(set80211ampdudensity, val, d) 1707173275Ssam{ 1708173275Ssam int v; 1709173275Ssam 1710183260Ssam if (isanyarg(val) || strcasecmp(val, "na") == 0) 1711173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_NA; 1712173275Ssam else switch ((int)(atof(val)*4)) { 1713173275Ssam case 0: 1714173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_NA; 1715173275Ssam break; 1716173275Ssam case 1: 1717173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_025; 1718173275Ssam break; 1719173275Ssam case 2: 1720173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_05; 1721173275Ssam break; 1722173275Ssam case 4: 1723173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_1; 1724173275Ssam break; 1725173275Ssam case 8: 1726173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_2; 1727173275Ssam break; 1728173275Ssam case 16: 1729173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_4; 1730173275Ssam break; 1731173275Ssam case 32: 1732173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_8; 1733173275Ssam break; 1734173275Ssam case 64: 1735173275Ssam v = IEEE80211_HTCAP_MPDUDENSITY_16; 1736173275Ssam break; 1737173275Ssam default: 1738173275Ssam errx(-1, "invalid A-MPDU density %s", val); 1739173275Ssam } 1740173275Ssam set80211(s, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL); 1741173275Ssam} 1742173275Ssam 1743173275Ssamstatic void 1744173275Ssamset80211amsdu(const char *val, int d, int s, const struct afswtch *rafp) 1745173275Ssam{ 1746173275Ssam int amsdu; 1747173275Ssam 1748173275Ssam if (get80211val(s, IEEE80211_IOC_AMSDU, &amsdu) < 0) 1749187801Ssam err(-1, "cannot get AMSDU setting"); 1750173275Ssam if (d < 0) { 1751173275Ssam d = -d; 1752173275Ssam amsdu &= ~d; 1753173275Ssam } else 1754173275Ssam amsdu |= d; 1755173275Ssam set80211(s, IEEE80211_IOC_AMSDU, amsdu, 0, NULL); 1756173275Ssam} 1757173275Ssam 1758173275Ssamstatic 1759173275SsamDECL_CMD_FUNC(set80211amsdulimit, val, d) 1760173275Ssam{ 1761173275Ssam set80211(s, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL); 1762173275Ssam} 1763173275Ssam 1764173275Ssamstatic void 1765173275Ssamset80211puren(const char *val, int d, int s, const struct afswtch *rafp) 1766173275Ssam{ 1767173275Ssam set80211(s, IEEE80211_IOC_PUREN, d, 0, NULL); 1768173275Ssam} 1769173275Ssam 1770173275Ssamstatic void 1771173275Ssamset80211htcompat(const char *val, int d, int s, const struct afswtch *rafp) 1772173275Ssam{ 1773173275Ssam set80211(s, IEEE80211_IOC_HTCOMPAT, d, 0, NULL); 1774173275Ssam} 1775173275Ssam 1776173275Ssamstatic void 1777173275Ssamset80211htconf(const char *val, int d, int s, const struct afswtch *rafp) 1778173275Ssam{ 1779173275Ssam set80211(s, IEEE80211_IOC_HTCONF, d, 0, NULL); 1780173275Ssam htconf = d; 1781173275Ssam} 1782173275Ssam 1783173275Ssamstatic void 1784178354Ssamset80211dwds(const char *val, int d, int s, const struct afswtch *rafp) 1785178354Ssam{ 1786178354Ssam set80211(s, IEEE80211_IOC_DWDS, d, 0, NULL); 1787178354Ssam} 1788178354Ssam 1789178354Ssamstatic void 1790173275Ssamset80211inact(const char *val, int d, int s, const struct afswtch *rafp) 1791173275Ssam{ 1792173275Ssam set80211(s, IEEE80211_IOC_INACTIVITY, d, 0, NULL); 1793173275Ssam} 1794173275Ssam 1795173275Ssamstatic void 1796178354Ssamset80211tsn(const char *val, int d, int s, const struct afswtch *rafp) 1797178354Ssam{ 1798178354Ssam set80211(s, IEEE80211_IOC_TSN, d, 0, NULL); 1799178354Ssam} 1800178354Ssam 1801178354Ssamstatic void 1802178354Ssamset80211dotd(const char *val, int d, int s, const struct afswtch *rafp) 1803178354Ssam{ 1804178354Ssam set80211(s, IEEE80211_IOC_DOTD, d, 0, NULL); 1805178354Ssam} 1806178354Ssam 1807183261Ssamstatic void 1808183261Ssamset80211smps(const char *val, int d, int s, const struct afswtch *rafp) 1809183261Ssam{ 1810183261Ssam set80211(s, IEEE80211_IOC_SMPS, d, 0, NULL); 1811183261Ssam} 1812183261Ssam 1813183261Ssamstatic void 1814183261Ssamset80211rifs(const char *val, int d, int s, const struct afswtch *rafp) 1815183261Ssam{ 1816183261Ssam set80211(s, IEEE80211_IOC_RIFS, d, 0, NULL); 1817183261Ssam} 1818183261Ssam 1819186904Ssamstatic 1820186904SsamDECL_CMD_FUNC(set80211tdmaslot, val, d) 1821186904Ssam{ 1822186904Ssam set80211(s, IEEE80211_IOC_TDMA_SLOT, atoi(val), 0, NULL); 1823186904Ssam} 1824186904Ssam 1825186904Ssamstatic 1826186904SsamDECL_CMD_FUNC(set80211tdmaslotcnt, val, d) 1827186904Ssam{ 1828186904Ssam set80211(s, IEEE80211_IOC_TDMA_SLOTCNT, atoi(val), 0, NULL); 1829186904Ssam} 1830186904Ssam 1831186904Ssamstatic 1832186904SsamDECL_CMD_FUNC(set80211tdmaslotlen, val, d) 1833186904Ssam{ 1834186904Ssam set80211(s, IEEE80211_IOC_TDMA_SLOTLEN, atoi(val), 0, NULL); 1835186904Ssam} 1836186904Ssam 1837186904Ssamstatic 1838186904SsamDECL_CMD_FUNC(set80211tdmabintval, val, d) 1839186904Ssam{ 1840186904Ssam set80211(s, IEEE80211_IOC_TDMA_BINTERVAL, atoi(val), 0, NULL); 1841186904Ssam} 1842186904Ssam 1843195618Srpaulostatic 1844195618SrpauloDECL_CMD_FUNC(set80211meshttl, val, d) 1845195618Srpaulo{ 1846195618Srpaulo set80211(s, IEEE80211_IOC_MESH_TTL, atoi(val), 0, NULL); 1847195618Srpaulo} 1848195618Srpaulo 1849195618Srpaulostatic 1850195618SrpauloDECL_CMD_FUNC(set80211meshforward, val, d) 1851195618Srpaulo{ 1852233735Sbschmidt set80211(s, IEEE80211_IOC_MESH_FWRD, d, 0, NULL); 1853195618Srpaulo} 1854195618Srpaulo 1855195618Srpaulostatic 1856195618SrpauloDECL_CMD_FUNC(set80211meshpeering, val, d) 1857195618Srpaulo{ 1858233735Sbschmidt set80211(s, IEEE80211_IOC_MESH_AP, d, 0, NULL); 1859195618Srpaulo} 1860195618Srpaulo 1861195618Srpaulostatic 1862195618SrpauloDECL_CMD_FUNC(set80211meshmetric, val, d) 1863195618Srpaulo{ 1864195618Srpaulo char v[12]; 1865195618Srpaulo 1866195618Srpaulo memcpy(v, val, sizeof(v)); 1867195618Srpaulo set80211(s, IEEE80211_IOC_MESH_PR_METRIC, 0, 0, v); 1868195618Srpaulo} 1869195618Srpaulo 1870195618Srpaulostatic 1871195618SrpauloDECL_CMD_FUNC(set80211meshpath, val, d) 1872195618Srpaulo{ 1873195618Srpaulo char v[12]; 1874195618Srpaulo 1875195618Srpaulo memcpy(v, val, sizeof(v)); 1876195618Srpaulo set80211(s, IEEE80211_IOC_MESH_PR_PATH, 0, 0, v); 1877195618Srpaulo} 1878195618Srpaulo 1879178354Ssamstatic int 1880178354Ssamregdomain_sort(const void *a, const void *b) 1881178354Ssam{ 1882178354Ssam#define CHAN_ALL \ 1883178354Ssam (IEEE80211_CHAN_ALLTURBO|IEEE80211_CHAN_HALF|IEEE80211_CHAN_QUARTER) 1884178354Ssam const struct ieee80211_channel *ca = a; 1885178354Ssam const struct ieee80211_channel *cb = b; 1886178354Ssam 1887178354Ssam return ca->ic_freq == cb->ic_freq ? 1888178354Ssam (ca->ic_flags & CHAN_ALL) - (cb->ic_flags & CHAN_ALL) : 1889178354Ssam ca->ic_freq - cb->ic_freq; 1890178354Ssam#undef CHAN_ALL 1891178354Ssam} 1892178354Ssam 1893178354Ssamstatic const struct ieee80211_channel * 1894178354Ssamchanlookup(const struct ieee80211_channel chans[], int nchans, 1895178354Ssam int freq, int flags) 1896178354Ssam{ 1897178354Ssam int i; 1898178354Ssam 1899178354Ssam flags &= IEEE80211_CHAN_ALLTURBO; 1900178354Ssam for (i = 0; i < nchans; i++) { 1901178354Ssam const struct ieee80211_channel *c = &chans[i]; 1902178354Ssam if (c->ic_freq == freq && 1903178354Ssam (c->ic_flags & IEEE80211_CHAN_ALLTURBO) == flags) 1904178354Ssam return c; 1905178354Ssam } 1906178354Ssam return NULL; 1907178354Ssam} 1908178354Ssam 1909187841Ssamstatic int 1910187841Ssamchanfind(const struct ieee80211_channel chans[], int nchans, int flags) 1911187841Ssam{ 1912187841Ssam int i; 1913187841Ssam 1914187841Ssam for (i = 0; i < nchans; i++) { 1915187841Ssam const struct ieee80211_channel *c = &chans[i]; 1916187841Ssam if ((c->ic_flags & flags) == flags) 1917187841Ssam return 1; 1918187841Ssam } 1919187841Ssam return 0; 1920187841Ssam} 1921187841Ssam 1922188258Ssam/* 1923188258Ssam * Check channel compatibility. 1924188258Ssam */ 1925188258Ssamstatic int 1926188258Ssamcheckchan(const struct ieee80211req_chaninfo *avail, int freq, int flags) 1927188258Ssam{ 1928188258Ssam flags &= ~REQ_FLAGS; 1929188258Ssam /* 1930188258Ssam * Check if exact channel is in the calibration table; 1931188258Ssam * everything below is to deal with channels that we 1932188258Ssam * want to include but that are not explicitly listed. 1933188258Ssam */ 1934188258Ssam if (flags & IEEE80211_CHAN_HT40) { 1935188258Ssam /* NB: we use an HT40 channel center that matches HT20 */ 1936188258Ssam flags = (flags &~ IEEE80211_CHAN_HT40) | IEEE80211_CHAN_HT20; 1937188258Ssam } 1938188258Ssam if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, flags) != NULL) 1939188258Ssam return 1; 1940188258Ssam if (flags & IEEE80211_CHAN_GSM) { 1941188258Ssam /* 1942188258Ssam * XXX GSM frequency mapping is handled in the kernel 1943188258Ssam * so we cannot find them in the calibration table; 1944188258Ssam * just accept the channel and the kernel will reject 1945188258Ssam * the channel list if it's wrong. 1946188258Ssam */ 1947188258Ssam return 1; 1948188258Ssam } 1949188258Ssam /* 1950188258Ssam * If this is a 1/2 or 1/4 width channel allow it if a full 1951188258Ssam * width channel is present for this frequency, and the device 1952188258Ssam * supports fractional channels on this band. This is a hack 1953188258Ssam * that avoids bloating the calibration table; it may be better 1954188258Ssam * by per-band attributes though (we are effectively calculating 1955188258Ssam * this attribute by scanning the channel list ourself). 1956188258Ssam */ 1957188258Ssam if ((flags & (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == 0) 1958188258Ssam return 0; 1959188258Ssam if (chanlookup(avail->ic_chans, avail->ic_nchans, freq, 1960188258Ssam flags &~ (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) == NULL) 1961188258Ssam return 0; 1962188258Ssam if (flags & IEEE80211_CHAN_HALF) { 1963188258Ssam return chanfind(avail->ic_chans, avail->ic_nchans, 1964188258Ssam IEEE80211_CHAN_HALF | 1965188258Ssam (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ))); 1966188258Ssam } else { 1967188258Ssam return chanfind(avail->ic_chans, avail->ic_nchans, 1968188258Ssam IEEE80211_CHAN_QUARTER | 1969188258Ssam (flags & (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_5GHZ))); 1970188258Ssam } 1971188258Ssam} 1972188258Ssam 1973178354Ssamstatic void 1974178354Ssamregdomain_addchans(struct ieee80211req_chaninfo *ci, 1975178354Ssam const netband_head *bands, 1976178354Ssam const struct ieee80211_regdomain *reg, 1977178354Ssam uint32_t chanFlags, 1978178354Ssam const struct ieee80211req_chaninfo *avail) 1979178354Ssam{ 1980178354Ssam const struct netband *nb; 1981178354Ssam const struct freqband *b; 1982178354Ssam struct ieee80211_channel *c, *prev; 1983188258Ssam int freq, hi_adj, lo_adj, channelSep; 1984188258Ssam uint32_t flags; 1985178354Ssam 1986188258Ssam hi_adj = (chanFlags & IEEE80211_CHAN_HT40U) ? -20 : 0; 1987188258Ssam lo_adj = (chanFlags & IEEE80211_CHAN_HT40D) ? 20 : 0; 1988178354Ssam channelSep = (chanFlags & IEEE80211_CHAN_2GHZ) ? 0 : 40; 1989178354Ssam LIST_FOREACH(nb, bands, next) { 1990178354Ssam b = nb->band; 1991187842Ssam if (verbose) { 1992187842Ssam printf("%s:", __func__); 1993187842Ssam printb(" chanFlags", chanFlags, IEEE80211_CHAN_BITS); 1994187842Ssam printb(" bandFlags", nb->flags | b->flags, 1995187842Ssam IEEE80211_CHAN_BITS); 1996187842Ssam putchar('\n'); 1997187842Ssam } 1998178354Ssam prev = NULL; 1999188258Ssam for (freq = b->freqStart + lo_adj; 2000188258Ssam freq <= b->freqEnd + hi_adj; freq += b->chanSep) { 2001187841Ssam /* 2002188258Ssam * Construct flags for the new channel. We take 2003188258Ssam * the attributes from the band descriptions except 2004188258Ssam * for HT40 which is enabled generically (i.e. +/- 2005188258Ssam * extension channel) in the band description and 2006188258Ssam * then constrained according by channel separation. 2007187841Ssam */ 2008188258Ssam flags = nb->flags | b->flags; 2009188258Ssam if (flags & IEEE80211_CHAN_HT) { 2010188258Ssam /* 2011188258Ssam * HT channels are generated specially; we're 2012188258Ssam * called to add HT20, HT40+, and HT40- chan's 2013188258Ssam * so we need to expand only band specs for 2014188258Ssam * the HT channel type being added. 2015188258Ssam */ 2016188258Ssam if ((chanFlags & IEEE80211_CHAN_HT20) && 2017188258Ssam (flags & IEEE80211_CHAN_HT20) == 0) { 2018188258Ssam if (verbose) 2019188258Ssam printf("%u: skip, not an " 2020188258Ssam "HT20 channel\n", freq); 2021188258Ssam continue; 2022188258Ssam } 2023188258Ssam if ((chanFlags & IEEE80211_CHAN_HT40) && 2024188258Ssam (flags & IEEE80211_CHAN_HT40) == 0) { 2025188258Ssam if (verbose) 2026188258Ssam printf("%u: skip, not an " 2027188258Ssam "HT40 channel\n", freq); 2028188258Ssam continue; 2029188258Ssam } 2030188258Ssam /* NB: HT attribute comes from caller */ 2031188258Ssam flags &= ~IEEE80211_CHAN_HT; 2032188258Ssam flags |= chanFlags & IEEE80211_CHAN_HT; 2033188258Ssam } 2034188258Ssam /* 2035188258Ssam * Check if device can operate on this frequency. 2036188258Ssam */ 2037188258Ssam if (!checkchan(avail, freq, flags)) { 2038187842Ssam if (verbose) { 2039187842Ssam printf("%u: skip, ", freq); 2040188258Ssam printb("flags", flags, 2041187842Ssam IEEE80211_CHAN_BITS); 2042187842Ssam printf(" not available\n"); 2043187842Ssam } 2044178354Ssam continue; 2045178354Ssam } 2046188258Ssam if ((flags & REQ_ECM) && !reg->ecm) { 2047178354Ssam if (verbose) 2048188258Ssam printf("%u: skip, ECM channel\n", freq); 2049178354Ssam continue; 2050178354Ssam } 2051188258Ssam if ((flags & REQ_INDOOR) && reg->location == 'O') { 2052178354Ssam if (verbose) 2053188258Ssam printf("%u: skip, indoor channel\n", 2054187841Ssam freq); 2055178354Ssam continue; 2056178354Ssam } 2057178354Ssam if ((flags & REQ_OUTDOOR) && reg->location == 'I') { 2058178354Ssam if (verbose) 2059188258Ssam printf("%u: skip, outdoor channel\n", 2060188258Ssam freq); 2061178354Ssam continue; 2062178354Ssam } 2063178354Ssam if ((flags & IEEE80211_CHAN_HT40) && 2064178354Ssam prev != NULL && (freq - prev->ic_freq) < channelSep) { 2065178354Ssam if (verbose) 2066178354Ssam printf("%u: skip, only %u channel " 2067178354Ssam "separation, need %d\n", freq, 2068178354Ssam freq - prev->ic_freq, channelSep); 2069178354Ssam continue; 2070178354Ssam } 2071178354Ssam if (ci->ic_nchans == IEEE80211_CHAN_MAX) { 2072178354Ssam if (verbose) 2073187842Ssam printf("%u: skip, channel table full\n", 2074187842Ssam freq); 2075178354Ssam break; 2076178354Ssam } 2077178354Ssam c = &ci->ic_chans[ci->ic_nchans++]; 2078187801Ssam memset(c, 0, sizeof(*c)); 2079178354Ssam c->ic_freq = freq; 2080188258Ssam c->ic_flags = flags; 2081178354Ssam if (c->ic_flags & IEEE80211_CHAN_DFS) 2082178354Ssam c->ic_maxregpower = nb->maxPowerDFS; 2083178354Ssam else 2084178354Ssam c->ic_maxregpower = nb->maxPower; 2085187842Ssam if (verbose) { 2086187842Ssam printf("[%3d] add freq %u ", 2087187842Ssam ci->ic_nchans-1, c->ic_freq); 2088187842Ssam printb("flags", c->ic_flags, IEEE80211_CHAN_BITS); 2089187842Ssam printf(" power %u\n", c->ic_maxregpower); 2090187842Ssam } 2091178354Ssam /* NB: kernel fills in other fields */ 2092178354Ssam prev = c; 2093178354Ssam } 2094178354Ssam } 2095178354Ssam} 2096178354Ssam 2097178354Ssamstatic void 2098178354Ssamregdomain_makechannels( 2099178354Ssam struct ieee80211_regdomain_req *req, 2100178354Ssam const struct ieee80211_devcaps_req *dc) 2101178354Ssam{ 2102178354Ssam struct regdata *rdp = getregdata(); 2103178354Ssam const struct country *cc; 2104178354Ssam const struct ieee80211_regdomain *reg = &req->rd; 2105178354Ssam struct ieee80211req_chaninfo *ci = &req->chaninfo; 2106178354Ssam const struct regdomain *rd; 2107178354Ssam 2108178354Ssam /* 2109178354Ssam * Locate construction table for new channel list. We treat 2110178354Ssam * the regdomain/SKU as definitive so a country can be in 2111178354Ssam * multiple with different properties (e.g. US in FCC+FCC3). 2112178354Ssam * If no regdomain is specified then we fallback on the country 2113178354Ssam * code to find the associated regdomain since countries always 2114178354Ssam * belong to at least one regdomain. 2115178354Ssam */ 2116178354Ssam if (reg->regdomain == 0) { 2117178354Ssam cc = lib80211_country_findbycc(rdp, reg->country); 2118178354Ssam if (cc == NULL) 2119178354Ssam errx(1, "internal error, country %d not found", 2120178354Ssam reg->country); 2121178354Ssam rd = cc->rd; 2122178354Ssam } else 2123178354Ssam rd = lib80211_regdomain_findbysku(rdp, reg->regdomain); 2124178354Ssam if (rd == NULL) 2125178354Ssam errx(1, "internal error, regdomain %d not found", 2126178354Ssam reg->regdomain); 2127178354Ssam if (rd->sku != SKU_DEBUG) { 2128187801Ssam /* 2129187801Ssam * regdomain_addchans incrememnts the channel count for 2130187801Ssam * each channel it adds so initialize ic_nchans to zero. 2131187801Ssam * Note that we know we have enough space to hold all possible 2132187801Ssam * channels because the devcaps list size was used to 2133187801Ssam * allocate our request. 2134187801Ssam */ 2135187801Ssam ci->ic_nchans = 0; 2136178354Ssam if (!LIST_EMPTY(&rd->bands_11b)) 2137178354Ssam regdomain_addchans(ci, &rd->bands_11b, reg, 2138178354Ssam IEEE80211_CHAN_B, &dc->dc_chaninfo); 2139187841Ssam if (!LIST_EMPTY(&rd->bands_11g)) 2140178354Ssam regdomain_addchans(ci, &rd->bands_11g, reg, 2141178354Ssam IEEE80211_CHAN_G, &dc->dc_chaninfo); 2142187841Ssam if (!LIST_EMPTY(&rd->bands_11a)) 2143178354Ssam regdomain_addchans(ci, &rd->bands_11a, reg, 2144178354Ssam IEEE80211_CHAN_A, &dc->dc_chaninfo); 2145188258Ssam if (!LIST_EMPTY(&rd->bands_11na) && dc->dc_htcaps != 0) { 2146178354Ssam regdomain_addchans(ci, &rd->bands_11na, reg, 2147178354Ssam IEEE80211_CHAN_A | IEEE80211_CHAN_HT20, 2148178354Ssam &dc->dc_chaninfo); 2149188258Ssam if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) { 2150188258Ssam regdomain_addchans(ci, &rd->bands_11na, reg, 2151188258Ssam IEEE80211_CHAN_A | IEEE80211_CHAN_HT40U, 2152188258Ssam &dc->dc_chaninfo); 2153188258Ssam regdomain_addchans(ci, &rd->bands_11na, reg, 2154188258Ssam IEEE80211_CHAN_A | IEEE80211_CHAN_HT40D, 2155188258Ssam &dc->dc_chaninfo); 2156188258Ssam } 2157178354Ssam } 2158188258Ssam if (!LIST_EMPTY(&rd->bands_11ng) && dc->dc_htcaps != 0) { 2159178354Ssam regdomain_addchans(ci, &rd->bands_11ng, reg, 2160178354Ssam IEEE80211_CHAN_G | IEEE80211_CHAN_HT20, 2161178354Ssam &dc->dc_chaninfo); 2162188258Ssam if (dc->dc_htcaps & IEEE80211_HTCAP_CHWIDTH40) { 2163188258Ssam regdomain_addchans(ci, &rd->bands_11ng, reg, 2164188258Ssam IEEE80211_CHAN_G | IEEE80211_CHAN_HT40U, 2165188258Ssam &dc->dc_chaninfo); 2166188258Ssam regdomain_addchans(ci, &rd->bands_11ng, reg, 2167188258Ssam IEEE80211_CHAN_G | IEEE80211_CHAN_HT40D, 2168188258Ssam &dc->dc_chaninfo); 2169188258Ssam } 2170178354Ssam } 2171178354Ssam qsort(ci->ic_chans, ci->ic_nchans, sizeof(ci->ic_chans[0]), 2172178354Ssam regdomain_sort); 2173178354Ssam } else 2174187801Ssam memcpy(ci, &dc->dc_chaninfo, 2175187801Ssam IEEE80211_CHANINFO_SPACE(&dc->dc_chaninfo)); 2176178354Ssam} 2177178354Ssam 2178178354Ssamstatic void 2179178354Ssamlist_countries(void) 2180178354Ssam{ 2181178354Ssam struct regdata *rdp = getregdata(); 2182178354Ssam const struct country *cp; 2183178354Ssam const struct regdomain *dp; 2184178354Ssam int i; 2185178354Ssam 2186178354Ssam i = 0; 2187178354Ssam printf("\nCountry codes:\n"); 2188178354Ssam LIST_FOREACH(cp, &rdp->countries, next) { 2189178354Ssam printf("%2s %-15.15s%s", cp->isoname, 2190178354Ssam cp->name, ((i+1)%4) == 0 ? "\n" : " "); 2191178354Ssam i++; 2192178354Ssam } 2193178354Ssam i = 0; 2194178354Ssam printf("\nRegulatory domains:\n"); 2195178354Ssam LIST_FOREACH(dp, &rdp->domains, next) { 2196178354Ssam printf("%-15.15s%s", dp->name, ((i+1)%4) == 0 ? "\n" : " "); 2197178354Ssam i++; 2198178354Ssam } 2199178354Ssam printf("\n"); 2200178354Ssam} 2201178354Ssam 2202178354Ssamstatic void 2203178354Ssamdefaultcountry(const struct regdomain *rd) 2204178354Ssam{ 2205178354Ssam struct regdata *rdp = getregdata(); 2206178354Ssam const struct country *cc; 2207178354Ssam 2208178354Ssam cc = lib80211_country_findbycc(rdp, rd->cc->code); 2209178354Ssam if (cc == NULL) 2210178354Ssam errx(1, "internal error, ISO country code %d not " 2211178354Ssam "defined for regdomain %s", rd->cc->code, rd->name); 2212178354Ssam regdomain.country = cc->code; 2213178354Ssam regdomain.isocc[0] = cc->isoname[0]; 2214178354Ssam regdomain.isocc[1] = cc->isoname[1]; 2215178354Ssam} 2216178354Ssam 2217178354Ssamstatic 2218178354SsamDECL_CMD_FUNC(set80211regdomain, val, d) 2219178354Ssam{ 2220178354Ssam struct regdata *rdp = getregdata(); 2221178354Ssam const struct regdomain *rd; 2222178354Ssam 2223178354Ssam rd = lib80211_regdomain_findbyname(rdp, val); 2224178354Ssam if (rd == NULL) { 2225186104Ssam char *eptr; 2226186104Ssam long sku = strtol(val, &eptr, 0); 2227186104Ssam 2228186104Ssam if (eptr != val) 2229186104Ssam rd = lib80211_regdomain_findbysku(rdp, sku); 2230186104Ssam if (eptr == val || rd == NULL) 2231178354Ssam errx(1, "unknown regdomain %s", val); 2232178354Ssam } 2233178354Ssam getregdomain(s); 2234178354Ssam regdomain.regdomain = rd->sku; 2235178354Ssam if (regdomain.country == 0 && rd->cc != NULL) { 2236178354Ssam /* 2237178354Ssam * No country code setup and there's a default 2238178354Ssam * one for this regdomain fill it in. 2239178354Ssam */ 2240178354Ssam defaultcountry(rd); 2241178354Ssam } 2242178354Ssam callback_register(setregdomain_cb, ®domain); 2243178354Ssam} 2244178354Ssam 2245178354Ssamstatic 2246178354SsamDECL_CMD_FUNC(set80211country, val, d) 2247178354Ssam{ 2248178354Ssam struct regdata *rdp = getregdata(); 2249178354Ssam const struct country *cc; 2250178354Ssam 2251178354Ssam cc = lib80211_country_findbyname(rdp, val); 2252178354Ssam if (cc == NULL) { 2253186103Ssam char *eptr; 2254186103Ssam long code = strtol(val, &eptr, 0); 2255186103Ssam 2256186103Ssam if (eptr != val) 2257186103Ssam cc = lib80211_country_findbycc(rdp, code); 2258186103Ssam if (eptr == val || cc == NULL) 2259178354Ssam errx(1, "unknown ISO country code %s", val); 2260178354Ssam } 2261178354Ssam getregdomain(s); 2262178354Ssam regdomain.regdomain = cc->rd->sku; 2263178354Ssam regdomain.country = cc->code; 2264178354Ssam regdomain.isocc[0] = cc->isoname[0]; 2265178354Ssam regdomain.isocc[1] = cc->isoname[1]; 2266178354Ssam callback_register(setregdomain_cb, ®domain); 2267178354Ssam} 2268178354Ssam 2269178354Ssamstatic void 2270178354Ssamset80211location(const char *val, int d, int s, const struct afswtch *rafp) 2271178354Ssam{ 2272178354Ssam getregdomain(s); 2273178354Ssam regdomain.location = d; 2274178354Ssam callback_register(setregdomain_cb, ®domain); 2275178354Ssam} 2276178354Ssam 2277178354Ssamstatic void 2278178354Ssamset80211ecm(const char *val, int d, int s, const struct afswtch *rafp) 2279178354Ssam{ 2280178354Ssam getregdomain(s); 2281178354Ssam regdomain.ecm = d; 2282178354Ssam callback_register(setregdomain_cb, ®domain); 2283178354Ssam} 2284178354Ssam 2285178354Ssamstatic void 2286173275SsamLINE_INIT(char c) 2287173275Ssam{ 2288173275Ssam spacer = c; 2289173275Ssam if (c == '\t') 2290173275Ssam col = 8; 2291173275Ssam else 2292173275Ssam col = 1; 2293173275Ssam} 2294173275Ssam 2295173275Ssamstatic void 2296173275SsamLINE_BREAK(void) 2297173275Ssam{ 2298173275Ssam if (spacer != '\t') { 2299173275Ssam printf("\n"); 2300173275Ssam spacer = '\t'; 2301173275Ssam } 2302173275Ssam col = 8; /* 8-col tab */ 2303173275Ssam} 2304173275Ssam 2305173275Ssamstatic void 2306173275SsamLINE_CHECK(const char *fmt, ...) 2307173275Ssam{ 2308173275Ssam char buf[80]; 2309173275Ssam va_list ap; 2310173275Ssam int n; 2311173275Ssam 2312173275Ssam va_start(ap, fmt); 2313173275Ssam n = vsnprintf(buf+1, sizeof(buf)-1, fmt, ap); 2314173275Ssam va_end(ap); 2315173275Ssam col += 1+n; 2316173275Ssam if (col > MAXCOL) { 2317173275Ssam LINE_BREAK(); 2318173275Ssam col += n; 2319173275Ssam } 2320173275Ssam buf[0] = spacer; 2321173275Ssam printf("%s", buf); 2322173275Ssam spacer = ' '; 2323173275Ssam} 2324173275Ssam 2325138593Ssamstatic int 2326170531Ssamgetmaxrate(const uint8_t rates[15], uint8_t nrates) 2327138593Ssam{ 2328138593Ssam int i, maxrate = -1; 2329138593Ssam 2330138593Ssam for (i = 0; i < nrates; i++) { 2331138593Ssam int rate = rates[i] & IEEE80211_RATE_VAL; 2332138593Ssam if (rate > maxrate) 2333138593Ssam maxrate = rate; 2334138593Ssam } 2335138593Ssam return maxrate / 2; 2336138593Ssam} 2337138593Ssam 2338138593Ssamstatic const char * 2339138593Ssamgetcaps(int capinfo) 2340138593Ssam{ 2341138593Ssam static char capstring[32]; 2342138593Ssam char *cp = capstring; 2343138593Ssam 2344138593Ssam if (capinfo & IEEE80211_CAPINFO_ESS) 2345138593Ssam *cp++ = 'E'; 2346138593Ssam if (capinfo & IEEE80211_CAPINFO_IBSS) 2347138593Ssam *cp++ = 'I'; 2348138593Ssam if (capinfo & IEEE80211_CAPINFO_CF_POLLABLE) 2349138593Ssam *cp++ = 'c'; 2350138593Ssam if (capinfo & IEEE80211_CAPINFO_CF_POLLREQ) 2351138593Ssam *cp++ = 'C'; 2352138593Ssam if (capinfo & IEEE80211_CAPINFO_PRIVACY) 2353138593Ssam *cp++ = 'P'; 2354138593Ssam if (capinfo & IEEE80211_CAPINFO_SHORT_PREAMBLE) 2355138593Ssam *cp++ = 'S'; 2356138593Ssam if (capinfo & IEEE80211_CAPINFO_PBCC) 2357138593Ssam *cp++ = 'B'; 2358138593Ssam if (capinfo & IEEE80211_CAPINFO_CHNL_AGILITY) 2359138593Ssam *cp++ = 'A'; 2360138593Ssam if (capinfo & IEEE80211_CAPINFO_SHORT_SLOTTIME) 2361138593Ssam *cp++ = 's'; 2362138593Ssam if (capinfo & IEEE80211_CAPINFO_RSN) 2363138593Ssam *cp++ = 'R'; 2364138593Ssam if (capinfo & IEEE80211_CAPINFO_DSSSOFDM) 2365138593Ssam *cp++ = 'D'; 2366138593Ssam *cp = '\0'; 2367138593Ssam return capstring; 2368138593Ssam} 2369138593Ssam 2370159885Ssamstatic const char * 2371159885Ssamgetflags(int flags) 2372159885Ssam{ 2373159885Ssam static char flagstring[32]; 2374159885Ssam char *cp = flagstring; 2375159885Ssam 2376159885Ssam if (flags & IEEE80211_NODE_AUTH) 2377159885Ssam *cp++ = 'A'; 2378159885Ssam if (flags & IEEE80211_NODE_QOS) 2379159885Ssam *cp++ = 'Q'; 2380159885Ssam if (flags & IEEE80211_NODE_ERP) 2381159885Ssam *cp++ = 'E'; 2382159885Ssam if (flags & IEEE80211_NODE_PWR_MGT) 2383159885Ssam *cp++ = 'P'; 2384173275Ssam if (flags & IEEE80211_NODE_HT) { 2385170531Ssam *cp++ = 'H'; 2386173275Ssam if (flags & IEEE80211_NODE_HTCOMPAT) 2387173275Ssam *cp++ = '+'; 2388173275Ssam } 2389173275Ssam if (flags & IEEE80211_NODE_WPS) 2390173275Ssam *cp++ = 'W'; 2391173275Ssam if (flags & IEEE80211_NODE_TSN) 2392183261Ssam *cp++ = 'N'; 2393183261Ssam if (flags & IEEE80211_NODE_AMPDU_TX) 2394173275Ssam *cp++ = 'T'; 2395183261Ssam if (flags & IEEE80211_NODE_AMPDU_RX) 2396183261Ssam *cp++ = 'R'; 2397183261Ssam if (flags & IEEE80211_NODE_MIMO_PS) { 2398183261Ssam *cp++ = 'M'; 2399183261Ssam if (flags & IEEE80211_NODE_MIMO_RTS) 2400183261Ssam *cp++ = '+'; 2401183261Ssam } 2402183261Ssam if (flags & IEEE80211_NODE_RIFS) 2403183261Ssam *cp++ = 'I'; 2404194136Ssam if (flags & IEEE80211_NODE_SGI40) { 2405194136Ssam *cp++ = 'S'; 2406194136Ssam if (flags & IEEE80211_NODE_SGI20) 2407194136Ssam *cp++ = '+'; 2408194136Ssam } else if (flags & IEEE80211_NODE_SGI20) 2409194136Ssam *cp++ = 's'; 2410194136Ssam if (flags & IEEE80211_NODE_AMSDU_TX) 2411194136Ssam *cp++ = 't'; 2412194136Ssam if (flags & IEEE80211_NODE_AMSDU_RX) 2413194136Ssam *cp++ = 'r'; 2414159885Ssam *cp = '\0'; 2415159885Ssam return flagstring; 2416159885Ssam} 2417159885Ssam 2418138593Ssamstatic void 2419138593Ssamprintie(const char* tag, const uint8_t *ie, size_t ielen, int maxlen) 2420138593Ssam{ 2421138593Ssam printf("%s", tag); 2422138593Ssam if (verbose) { 2423138593Ssam maxlen -= strlen(tag)+2; 2424138593Ssam if (2*ielen > maxlen) 2425138593Ssam maxlen--; 2426138593Ssam printf("<"); 2427138593Ssam for (; ielen > 0; ie++, ielen--) { 2428138593Ssam if (maxlen-- <= 0) 2429138593Ssam break; 2430138593Ssam printf("%02x", *ie); 2431138593Ssam } 2432138593Ssam if (ielen != 0) 2433138593Ssam printf("-"); 2434138593Ssam printf(">"); 2435138593Ssam } 2436138593Ssam} 2437138593Ssam 2438170531Ssam#define LE_READ_2(p) \ 2439170531Ssam ((u_int16_t) \ 2440170531Ssam ((((const u_int8_t *)(p))[0] ) | \ 2441170531Ssam (((const u_int8_t *)(p))[1] << 8))) 2442170531Ssam#define LE_READ_4(p) \ 2443170531Ssam ((u_int32_t) \ 2444170531Ssam ((((const u_int8_t *)(p))[0] ) | \ 2445170531Ssam (((const u_int8_t *)(p))[1] << 8) | \ 2446170531Ssam (((const u_int8_t *)(p))[2] << 16) | \ 2447170531Ssam (((const u_int8_t *)(p))[3] << 24))) 2448170531Ssam 2449138593Ssam/* 2450170531Ssam * NB: The decoding routines assume a properly formatted ie 2451170531Ssam * which should be safe as the kernel only retains them 2452170531Ssam * if they parse ok. 2453170531Ssam */ 2454170531Ssam 2455170531Ssamstatic void 2456173275Ssamprintwmeparam(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2457170531Ssam{ 2458170531Ssam#define MS(_v, _f) (((_v) & _f) >> _f##_S) 2459170531Ssam static const char *acnames[] = { "BE", "BK", "VO", "VI" }; 2460173275Ssam const struct ieee80211_wme_param *wme = 2461173275Ssam (const struct ieee80211_wme_param *) ie; 2462170531Ssam int i; 2463170531Ssam 2464170531Ssam printf("%s", tag); 2465173275Ssam if (!verbose) 2466173275Ssam return; 2467173275Ssam printf("<qosinfo 0x%x", wme->param_qosInfo); 2468173275Ssam ie += offsetof(struct ieee80211_wme_param, params_acParams); 2469173275Ssam for (i = 0; i < WME_NUM_AC; i++) { 2470173275Ssam const struct ieee80211_wme_acparams *ac = 2471173275Ssam &wme->params_acParams[i]; 2472173275Ssam 2473173275Ssam printf(" %s[%saifsn %u cwmin %u cwmax %u txop %u]" 2474173275Ssam , acnames[i] 2475173275Ssam , MS(ac->acp_aci_aifsn, WME_PARAM_ACM) ? "acm " : "" 2476173275Ssam , MS(ac->acp_aci_aifsn, WME_PARAM_AIFSN) 2477173275Ssam , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMIN) 2478173275Ssam , MS(ac->acp_logcwminmax, WME_PARAM_LOGCWMAX) 2479173275Ssam , LE_READ_2(&ac->acp_txop) 2480173275Ssam ); 2481170531Ssam } 2482173275Ssam printf(">"); 2483170531Ssam#undef MS 2484170531Ssam} 2485170531Ssam 2486170531Ssamstatic void 2487173275Ssamprintwmeinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2488173275Ssam{ 2489173275Ssam printf("%s", tag); 2490173275Ssam if (verbose) { 2491173275Ssam const struct ieee80211_wme_info *wme = 2492173275Ssam (const struct ieee80211_wme_info *) ie; 2493173275Ssam printf("<version 0x%x info 0x%x>", 2494173275Ssam wme->wme_version, wme->wme_info); 2495173275Ssam } 2496173275Ssam} 2497173275Ssam 2498173275Ssamstatic void 2499173275Ssamprinthtcap(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2500173275Ssam{ 2501173275Ssam printf("%s", tag); 2502173275Ssam if (verbose) { 2503173275Ssam const struct ieee80211_ie_htcap *htcap = 2504173275Ssam (const struct ieee80211_ie_htcap *) ie; 2505173275Ssam const char *sep; 2506173275Ssam int i, j; 2507173275Ssam 2508173275Ssam printf("<cap 0x%x param 0x%x", 2509173275Ssam LE_READ_2(&htcap->hc_cap), htcap->hc_param); 2510173275Ssam printf(" mcsset["); 2511173275Ssam sep = ""; 2512173275Ssam for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++) 2513173275Ssam if (isset(htcap->hc_mcsset, i)) { 2514173275Ssam for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++) 2515173275Ssam if (isclr(htcap->hc_mcsset, j)) 2516173275Ssam break; 2517173275Ssam j--; 2518173275Ssam if (i == j) 2519173275Ssam printf("%s%u", sep, i); 2520173275Ssam else 2521173275Ssam printf("%s%u-%u", sep, i, j); 2522173275Ssam i += j-i; 2523173275Ssam sep = ","; 2524173275Ssam } 2525173275Ssam printf("] extcap 0x%x txbf 0x%x antenna 0x%x>", 2526173275Ssam LE_READ_2(&htcap->hc_extcap), 2527173275Ssam LE_READ_4(&htcap->hc_txbf), 2528173275Ssam htcap->hc_antenna); 2529173275Ssam } 2530173275Ssam} 2531173275Ssam 2532173275Ssamstatic void 2533173275Ssamprinthtinfo(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2534173275Ssam{ 2535173275Ssam printf("%s", tag); 2536173275Ssam if (verbose) { 2537173275Ssam const struct ieee80211_ie_htinfo *htinfo = 2538173275Ssam (const struct ieee80211_ie_htinfo *) ie; 2539173275Ssam const char *sep; 2540173275Ssam int i, j; 2541173275Ssam 2542173275Ssam printf("<ctl %u, %x,%x,%x,%x", htinfo->hi_ctrlchannel, 2543173275Ssam htinfo->hi_byte1, htinfo->hi_byte2, htinfo->hi_byte3, 2544173275Ssam LE_READ_2(&htinfo->hi_byte45)); 2545173275Ssam printf(" basicmcs["); 2546173275Ssam sep = ""; 2547173275Ssam for (i = 0; i < IEEE80211_HTRATE_MAXSIZE; i++) 2548173275Ssam if (isset(htinfo->hi_basicmcsset, i)) { 2549173275Ssam for (j = i+1; j < IEEE80211_HTRATE_MAXSIZE; j++) 2550173275Ssam if (isclr(htinfo->hi_basicmcsset, j)) 2551173275Ssam break; 2552173275Ssam j--; 2553173275Ssam if (i == j) 2554173275Ssam printf("%s%u", sep, i); 2555173275Ssam else 2556173275Ssam printf("%s%u-%u", sep, i, j); 2557173275Ssam i += j-i; 2558173275Ssam sep = ","; 2559173275Ssam } 2560173275Ssam printf("]>"); 2561173275Ssam } 2562173275Ssam} 2563173275Ssam 2564173275Ssamstatic void 2565170531Ssamprintathie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2566170531Ssam{ 2567170531Ssam 2568170531Ssam printf("%s", tag); 2569170531Ssam if (verbose) { 2570170531Ssam const struct ieee80211_ath_ie *ath = 2571170531Ssam (const struct ieee80211_ath_ie *)ie; 2572170531Ssam 2573170531Ssam printf("<"); 2574170531Ssam if (ath->ath_capability & ATHEROS_CAP_TURBO_PRIME) 2575170531Ssam printf("DTURBO,"); 2576170531Ssam if (ath->ath_capability & ATHEROS_CAP_COMPRESSION) 2577170531Ssam printf("COMP,"); 2578170531Ssam if (ath->ath_capability & ATHEROS_CAP_FAST_FRAME) 2579170531Ssam printf("FF,"); 2580170531Ssam if (ath->ath_capability & ATHEROS_CAP_XR) 2581170531Ssam printf("XR,"); 2582170531Ssam if (ath->ath_capability & ATHEROS_CAP_AR) 2583170531Ssam printf("AR,"); 2584170531Ssam if (ath->ath_capability & ATHEROS_CAP_BURST) 2585170531Ssam printf("BURST,"); 2586170531Ssam if (ath->ath_capability & ATHEROS_CAP_WME) 2587170531Ssam printf("WME,"); 2588170531Ssam if (ath->ath_capability & ATHEROS_CAP_BOOST) 2589170531Ssam printf("BOOST,"); 2590170531Ssam printf("0x%x>", LE_READ_2(ath->ath_defkeyix)); 2591170531Ssam } 2592170531Ssam} 2593170531Ssam 2594195618Srpaulo 2595195618Srpaulostatic void 2596195618Srpauloprintmeshconf(const char *tag, const uint8_t *ie, size_t ielen, int maxlen) 2597195618Srpaulo{ 2598195618Srpaulo#define MATCHOUI(field, oui, string) \ 2599195618Srpaulodo { \ 2600195618Srpaulo if (memcmp(field, oui, 4) == 0) \ 2601195618Srpaulo printf("%s", string); \ 2602195618Srpaulo} while (0) 2603195618Srpaulo 2604195618Srpaulo printf("%s", tag); 2605195618Srpaulo if (verbose) { 2606195618Srpaulo const struct ieee80211_meshconf_ie *mconf = 2607195618Srpaulo (const struct ieee80211_meshconf_ie *)ie; 2608197980Srpaulo printf("<PATH:"); 2609197980Srpaulo if (mconf->conf_pselid == IEEE80211_MESHCONF_PATH_HWMP) 2610197980Srpaulo printf("HWMP"); 2611197980Srpaulo else 2612197980Srpaulo printf("UNKNOWN"); 2613195618Srpaulo printf(" LINK:"); 2614197980Srpaulo if (mconf->conf_pmetid == IEEE80211_MESHCONF_METRIC_AIRTIME) 2615197980Srpaulo printf("AIRTIME"); 2616197980Srpaulo else 2617197980Srpaulo printf("UNKNOWN"); 2618195618Srpaulo printf(" CONGESTION:"); 2619197980Srpaulo if (mconf->conf_ccid == IEEE80211_MESHCONF_CC_DISABLED) 2620197980Srpaulo printf("DISABLED"); 2621197980Srpaulo else 2622197980Srpaulo printf("UNKNOWN"); 2623195618Srpaulo printf(" SYNC:"); 2624197980Srpaulo if (mconf->conf_syncid == IEEE80211_MESHCONF_SYNC_NEIGHOFF) 2625197980Srpaulo printf("NEIGHOFF"); 2626197980Srpaulo else 2627197980Srpaulo printf("UNKNOWN"); 2628195618Srpaulo printf(" AUTH:"); 2629197980Srpaulo if (mconf->conf_authid == IEEE80211_MESHCONF_AUTH_DISABLED) 2630197980Srpaulo printf("DISABLED"); 2631197980Srpaulo else 2632197980Srpaulo printf("UNKNOWN"); 2633195618Srpaulo printf(" FORM:0x%x CAPS:0x%x>", mconf->conf_form, 2634195618Srpaulo mconf->conf_cap); 2635195618Srpaulo } 2636195618Srpaulo#undef MATCHOUI 2637195618Srpaulo} 2638195618Srpaulo 2639170531Ssamstatic const char * 2640170531Ssamwpa_cipher(const u_int8_t *sel) 2641170531Ssam{ 2642170531Ssam#define WPA_SEL(x) (((x)<<24)|WPA_OUI) 2643170531Ssam u_int32_t w = LE_READ_4(sel); 2644170531Ssam 2645170531Ssam switch (w) { 2646170531Ssam case WPA_SEL(WPA_CSE_NULL): 2647170531Ssam return "NONE"; 2648170531Ssam case WPA_SEL(WPA_CSE_WEP40): 2649170531Ssam return "WEP40"; 2650170531Ssam case WPA_SEL(WPA_CSE_WEP104): 2651170531Ssam return "WEP104"; 2652170531Ssam case WPA_SEL(WPA_CSE_TKIP): 2653170531Ssam return "TKIP"; 2654170531Ssam case WPA_SEL(WPA_CSE_CCMP): 2655170531Ssam return "AES-CCMP"; 2656170531Ssam } 2657170531Ssam return "?"; /* NB: so 1<< is discarded */ 2658170531Ssam#undef WPA_SEL 2659170531Ssam} 2660170531Ssam 2661170531Ssamstatic const char * 2662170531Ssamwpa_keymgmt(const u_int8_t *sel) 2663170531Ssam{ 2664170531Ssam#define WPA_SEL(x) (((x)<<24)|WPA_OUI) 2665170531Ssam u_int32_t w = LE_READ_4(sel); 2666170531Ssam 2667170531Ssam switch (w) { 2668170531Ssam case WPA_SEL(WPA_ASE_8021X_UNSPEC): 2669170531Ssam return "8021X-UNSPEC"; 2670170531Ssam case WPA_SEL(WPA_ASE_8021X_PSK): 2671170531Ssam return "8021X-PSK"; 2672170531Ssam case WPA_SEL(WPA_ASE_NONE): 2673170531Ssam return "NONE"; 2674170531Ssam } 2675170531Ssam return "?"; 2676170531Ssam#undef WPA_SEL 2677170531Ssam} 2678170531Ssam 2679170531Ssamstatic void 2680170531Ssamprintwpaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2681170531Ssam{ 2682170531Ssam u_int8_t len = ie[1]; 2683170531Ssam 2684170531Ssam printf("%s", tag); 2685170531Ssam if (verbose) { 2686170531Ssam const char *sep; 2687170531Ssam int n; 2688170531Ssam 2689170531Ssam ie += 6, len -= 4; /* NB: len is payload only */ 2690170531Ssam 2691170531Ssam printf("<v%u", LE_READ_2(ie)); 2692170531Ssam ie += 2, len -= 2; 2693170531Ssam 2694170531Ssam printf(" mc:%s", wpa_cipher(ie)); 2695170531Ssam ie += 4, len -= 4; 2696170531Ssam 2697170531Ssam /* unicast ciphers */ 2698170531Ssam n = LE_READ_2(ie); 2699170531Ssam ie += 2, len -= 2; 2700170531Ssam sep = " uc:"; 2701170531Ssam for (; n > 0; n--) { 2702170531Ssam printf("%s%s", sep, wpa_cipher(ie)); 2703170531Ssam ie += 4, len -= 4; 2704170531Ssam sep = "+"; 2705170531Ssam } 2706170531Ssam 2707170531Ssam /* key management algorithms */ 2708170531Ssam n = LE_READ_2(ie); 2709170531Ssam ie += 2, len -= 2; 2710170531Ssam sep = " km:"; 2711170531Ssam for (; n > 0; n--) { 2712170531Ssam printf("%s%s", sep, wpa_keymgmt(ie)); 2713170531Ssam ie += 4, len -= 4; 2714170531Ssam sep = "+"; 2715170531Ssam } 2716170531Ssam 2717170531Ssam if (len > 2) /* optional capabilities */ 2718170531Ssam printf(", caps 0x%x", LE_READ_2(ie)); 2719170531Ssam printf(">"); 2720170531Ssam } 2721170531Ssam} 2722170531Ssam 2723170531Ssamstatic const char * 2724170531Ssamrsn_cipher(const u_int8_t *sel) 2725170531Ssam{ 2726170531Ssam#define RSN_SEL(x) (((x)<<24)|RSN_OUI) 2727170531Ssam u_int32_t w = LE_READ_4(sel); 2728170531Ssam 2729170531Ssam switch (w) { 2730170531Ssam case RSN_SEL(RSN_CSE_NULL): 2731170531Ssam return "NONE"; 2732170531Ssam case RSN_SEL(RSN_CSE_WEP40): 2733170531Ssam return "WEP40"; 2734170531Ssam case RSN_SEL(RSN_CSE_WEP104): 2735170531Ssam return "WEP104"; 2736170531Ssam case RSN_SEL(RSN_CSE_TKIP): 2737170531Ssam return "TKIP"; 2738170531Ssam case RSN_SEL(RSN_CSE_CCMP): 2739170531Ssam return "AES-CCMP"; 2740170531Ssam case RSN_SEL(RSN_CSE_WRAP): 2741170531Ssam return "AES-OCB"; 2742170531Ssam } 2743170531Ssam return "?"; 2744170531Ssam#undef WPA_SEL 2745170531Ssam} 2746170531Ssam 2747170531Ssamstatic const char * 2748170531Ssamrsn_keymgmt(const u_int8_t *sel) 2749170531Ssam{ 2750170531Ssam#define RSN_SEL(x) (((x)<<24)|RSN_OUI) 2751170531Ssam u_int32_t w = LE_READ_4(sel); 2752170531Ssam 2753170531Ssam switch (w) { 2754170531Ssam case RSN_SEL(RSN_ASE_8021X_UNSPEC): 2755170531Ssam return "8021X-UNSPEC"; 2756170531Ssam case RSN_SEL(RSN_ASE_8021X_PSK): 2757170531Ssam return "8021X-PSK"; 2758170531Ssam case RSN_SEL(RSN_ASE_NONE): 2759170531Ssam return "NONE"; 2760170531Ssam } 2761170531Ssam return "?"; 2762170531Ssam#undef RSN_SEL 2763170531Ssam} 2764170531Ssam 2765170531Ssamstatic void 2766170531Ssamprintrsnie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2767170531Ssam{ 2768170531Ssam printf("%s", tag); 2769170531Ssam if (verbose) { 2770170531Ssam const char *sep; 2771170531Ssam int n; 2772170531Ssam 2773173275Ssam ie += 2, ielen -= 2; 2774170531Ssam 2775170531Ssam printf("<v%u", LE_READ_2(ie)); 2776173275Ssam ie += 2, ielen -= 2; 2777170531Ssam 2778170531Ssam printf(" mc:%s", rsn_cipher(ie)); 2779173275Ssam ie += 4, ielen -= 4; 2780170531Ssam 2781170531Ssam /* unicast ciphers */ 2782170531Ssam n = LE_READ_2(ie); 2783173275Ssam ie += 2, ielen -= 2; 2784170531Ssam sep = " uc:"; 2785170531Ssam for (; n > 0; n--) { 2786170531Ssam printf("%s%s", sep, rsn_cipher(ie)); 2787173275Ssam ie += 4, ielen -= 4; 2788170531Ssam sep = "+"; 2789170531Ssam } 2790170531Ssam 2791170531Ssam /* key management algorithms */ 2792170531Ssam n = LE_READ_2(ie); 2793173275Ssam ie += 2, ielen -= 2; 2794170531Ssam sep = " km:"; 2795170531Ssam for (; n > 0; n--) { 2796170531Ssam printf("%s%s", sep, rsn_keymgmt(ie)); 2797173275Ssam ie += 4, ielen -= 4; 2798170531Ssam sep = "+"; 2799170531Ssam } 2800170531Ssam 2801173275Ssam if (ielen > 2) /* optional capabilities */ 2802170531Ssam printf(", caps 0x%x", LE_READ_2(ie)); 2803170531Ssam /* XXXPMKID */ 2804170531Ssam printf(">"); 2805170531Ssam } 2806170531Ssam} 2807170531Ssam 2808181454Ssam/* XXX move to a public include file */ 2809181454Ssam#define IEEE80211_WPS_DEV_PASS_ID 0x1012 2810181454Ssam#define IEEE80211_WPS_SELECTED_REG 0x1041 2811181454Ssam#define IEEE80211_WPS_SETUP_STATE 0x1044 2812181454Ssam#define IEEE80211_WPS_UUID_E 0x1047 2813181454Ssam#define IEEE80211_WPS_VERSION 0x104a 2814181454Ssam 2815181454Ssam#define BE_READ_2(p) \ 2816181454Ssam ((u_int16_t) \ 2817181454Ssam ((((const u_int8_t *)(p))[1] ) | \ 2818181454Ssam (((const u_int8_t *)(p))[0] << 8))) 2819181454Ssam 2820181454Ssamstatic void 2821181454Ssamprintwpsie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2822181454Ssam{ 2823181454Ssam#define N(a) (sizeof(a) / sizeof(a[0])) 2824181454Ssam u_int8_t len = ie[1]; 2825181454Ssam 2826181454Ssam printf("%s", tag); 2827181454Ssam if (verbose) { 2828181454Ssam static const char *dev_pass_id[] = { 2829181454Ssam "D", /* Default (PIN) */ 2830181454Ssam "U", /* User-specified */ 2831181454Ssam "M", /* Machine-specified */ 2832181454Ssam "K", /* Rekey */ 2833181454Ssam "P", /* PushButton */ 2834181454Ssam "R" /* Registrar-specified */ 2835181454Ssam }; 2836181454Ssam int n; 2837181454Ssam 2838181454Ssam ie +=6, len -= 4; /* NB: len is payload only */ 2839181454Ssam 2840181454Ssam /* WPS IE in Beacon and Probe Resp frames have different fields */ 2841181454Ssam printf("<"); 2842181454Ssam while (len) { 2843181454Ssam uint16_t tlv_type = BE_READ_2(ie); 2844181454Ssam uint16_t tlv_len = BE_READ_2(ie + 2); 2845181454Ssam 2846181454Ssam ie += 4, len -= 4; 2847181454Ssam 2848181454Ssam switch (tlv_type) { 2849181454Ssam case IEEE80211_WPS_VERSION: 2850181454Ssam printf("v:%d.%d", *ie >> 4, *ie & 0xf); 2851181454Ssam break; 2852181454Ssam case IEEE80211_WPS_SETUP_STATE: 2853181454Ssam /* Only 1 and 2 are valid */ 2854181454Ssam if (*ie == 0 || *ie >= 3) 2855181454Ssam printf(" state:B"); 2856181454Ssam else 2857181454Ssam printf(" st:%s", *ie == 1 ? "N" : "C"); 2858181454Ssam break; 2859181454Ssam case IEEE80211_WPS_SELECTED_REG: 2860181454Ssam printf(" sel:%s", *ie ? "T" : "F"); 2861181454Ssam break; 2862181454Ssam case IEEE80211_WPS_DEV_PASS_ID: 2863181454Ssam n = LE_READ_2(ie); 2864181454Ssam if (n < N(dev_pass_id)) 2865181454Ssam printf(" dpi:%s", dev_pass_id[n]); 2866181454Ssam break; 2867181454Ssam case IEEE80211_WPS_UUID_E: 2868181454Ssam printf(" uuid-e:"); 2869181454Ssam for (n = 0; n < (tlv_len - 1); n++) 2870181454Ssam printf("%02x-", ie[n]); 2871181454Ssam printf("%02x", ie[n]); 2872181454Ssam break; 2873181454Ssam } 2874181454Ssam ie += tlv_len, len -= tlv_len; 2875181454Ssam } 2876181454Ssam printf(">"); 2877181454Ssam } 2878181454Ssam#undef N 2879181454Ssam} 2880181454Ssam 2881186904Ssamstatic void 2882186904Ssamprinttdmaie(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2883186904Ssam{ 2884186904Ssam printf("%s", tag); 2885186904Ssam if (verbose && ielen >= sizeof(struct ieee80211_tdma_param)) { 2886186904Ssam const struct ieee80211_tdma_param *tdma = 2887186904Ssam (const struct ieee80211_tdma_param *) ie; 2888186904Ssam 2889186904Ssam /* XXX tstamp */ 2890186904Ssam printf("<v%u slot:%u slotcnt:%u slotlen:%u bintval:%u inuse:0x%x>", 2891186904Ssam tdma->tdma_version, tdma->tdma_slot, tdma->tdma_slotcnt, 2892186904Ssam LE_READ_2(&tdma->tdma_slotlen), tdma->tdma_bintval, 2893186904Ssam tdma->tdma_inuse[0]); 2894186904Ssam } 2895186904Ssam} 2896186904Ssam 2897170531Ssam/* 2898138593Ssam * Copy the ssid string contents into buf, truncating to fit. If the 2899138593Ssam * ssid is entirely printable then just copy intact. Otherwise convert 2900138593Ssam * to hexadecimal. If the result is truncated then replace the last 2901138593Ssam * three characters with "...". 2902138593Ssam */ 2903146873Sjhbstatic int 2904138593Ssamcopy_essid(char buf[], size_t bufsize, const u_int8_t *essid, size_t essid_len) 2905138593Ssam{ 2906138593Ssam const u_int8_t *p; 2907138593Ssam size_t maxlen; 2908138593Ssam int i; 2909138593Ssam 2910138593Ssam if (essid_len > bufsize) 2911138593Ssam maxlen = bufsize; 2912138593Ssam else 2913138593Ssam maxlen = essid_len; 2914138593Ssam /* determine printable or not */ 2915138593Ssam for (i = 0, p = essid; i < maxlen; i++, p++) { 2916138593Ssam if (*p < ' ' || *p > 0x7e) 2917138593Ssam break; 2918138593Ssam } 2919138593Ssam if (i != maxlen) { /* not printable, print as hex */ 2920138593Ssam if (bufsize < 3) 2921138593Ssam return 0; 2922138593Ssam strlcpy(buf, "0x", bufsize); 2923138593Ssam bufsize -= 2; 2924138593Ssam p = essid; 2925138593Ssam for (i = 0; i < maxlen && bufsize >= 2; i++) { 2926147489Savatar sprintf(&buf[2+2*i], "%02x", p[i]); 2927138593Ssam bufsize -= 2; 2928138593Ssam } 2929147489Savatar if (i != essid_len) 2930147489Savatar memcpy(&buf[2+2*i-3], "...", 3); 2931138593Ssam } else { /* printable, truncate as needed */ 2932138593Ssam memcpy(buf, essid, maxlen); 2933147489Savatar if (maxlen != essid_len) 2934147489Savatar memcpy(&buf[maxlen-3], "...", 3); 2935138593Ssam } 2936138593Ssam return maxlen; 2937138593Ssam} 2938138593Ssam 2939173275Ssamstatic void 2940173275Ssamprintssid(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2941173275Ssam{ 2942173275Ssam char ssid[2*IEEE80211_NWID_LEN+1]; 2943173275Ssam 2944173275Ssam printf("%s<%.*s>", tag, copy_essid(ssid, maxlen, ie+2, ie[1]), ssid); 2945173275Ssam} 2946173275Ssam 2947173275Ssamstatic void 2948173275Ssamprintrates(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2949173275Ssam{ 2950173275Ssam const char *sep; 2951173275Ssam int i; 2952173275Ssam 2953173275Ssam printf("%s", tag); 2954173275Ssam sep = "<"; 2955173275Ssam for (i = 2; i < ielen; i++) { 2956173275Ssam printf("%s%s%d", sep, 2957173275Ssam ie[i] & IEEE80211_RATE_BASIC ? "B" : "", 2958173275Ssam ie[i] & IEEE80211_RATE_VAL); 2959173275Ssam sep = ","; 2960173275Ssam } 2961173275Ssam printf(">"); 2962173275Ssam} 2963173275Ssam 2964173275Ssamstatic void 2965173275Ssamprintcountry(const char *tag, const u_int8_t *ie, size_t ielen, int maxlen) 2966173275Ssam{ 2967173275Ssam const struct ieee80211_country_ie *cie = 2968173275Ssam (const struct ieee80211_country_ie *) ie; 2969173275Ssam int i, nbands, schan, nchan; 2970173275Ssam 2971173275Ssam printf("%s<%c%c%c", tag, cie->cc[0], cie->cc[1], cie->cc[2]); 2972173275Ssam nbands = (cie->len - 3) / sizeof(cie->band[0]); 2973173275Ssam for (i = 0; i < nbands; i++) { 2974173275Ssam schan = cie->band[i].schan; 2975173275Ssam nchan = cie->band[i].nchan; 2976173275Ssam if (nchan != 1) 2977173275Ssam printf(" %u-%u,%u", schan, schan + nchan-1, 2978173275Ssam cie->band[i].maxtxpwr); 2979173275Ssam else 2980173275Ssam printf(" %u,%u", schan, cie->band[i].maxtxpwr); 2981173275Ssam } 2982173275Ssam printf(">"); 2983173275Ssam} 2984173275Ssam 2985148686Sstefanf/* unaligned little endian access */ 2986138593Ssam#define LE_READ_4(p) \ 2987138593Ssam ((u_int32_t) \ 2988138593Ssam ((((const u_int8_t *)(p))[0] ) | \ 2989138593Ssam (((const u_int8_t *)(p))[1] << 8) | \ 2990138593Ssam (((const u_int8_t *)(p))[2] << 16) | \ 2991138593Ssam (((const u_int8_t *)(p))[3] << 24))) 2992138593Ssam 2993178354Ssamstatic __inline int 2994138593Ssamiswpaoui(const u_int8_t *frm) 2995138593Ssam{ 2996138593Ssam return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI); 2997138593Ssam} 2998138593Ssam 2999178354Ssamstatic __inline int 3000173275Ssamiswmeinfo(const u_int8_t *frm) 3001138593Ssam{ 3002173275Ssam return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) && 3003173275Ssam frm[6] == WME_INFO_OUI_SUBTYPE; 3004138593Ssam} 3005138593Ssam 3006178354Ssamstatic __inline int 3007173275Ssamiswmeparam(const u_int8_t *frm) 3008173275Ssam{ 3009173275Ssam return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) && 3010173275Ssam frm[6] == WME_PARAM_OUI_SUBTYPE; 3011173275Ssam} 3012173275Ssam 3013178354Ssamstatic __inline int 3014138593Ssamisatherosoui(const u_int8_t *frm) 3015138593Ssam{ 3016138593Ssam return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI); 3017138593Ssam} 3018138593Ssam 3019181454Ssamstatic __inline int 3020186904Ssamistdmaoui(const uint8_t *frm) 3021186904Ssam{ 3022186904Ssam return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI); 3023186904Ssam} 3024186904Ssam 3025186904Ssamstatic __inline int 3026181454Ssamiswpsoui(const uint8_t *frm) 3027181454Ssam{ 3028181454Ssam return frm[1] > 3 && LE_READ_4(frm+2) == ((WPS_OUI_TYPE<<24)|WPA_OUI); 3029181454Ssam} 3030181454Ssam 3031173275Ssamstatic const char * 3032173275Ssamiename(int elemid) 3033173275Ssam{ 3034173275Ssam switch (elemid) { 3035173275Ssam case IEEE80211_ELEMID_FHPARMS: return " FHPARMS"; 3036173275Ssam case IEEE80211_ELEMID_CFPARMS: return " CFPARMS"; 3037173275Ssam case IEEE80211_ELEMID_TIM: return " TIM"; 3038173275Ssam case IEEE80211_ELEMID_IBSSPARMS:return " IBSSPARMS"; 3039173275Ssam case IEEE80211_ELEMID_CHALLENGE:return " CHALLENGE"; 3040173275Ssam case IEEE80211_ELEMID_PWRCNSTR: return " PWRCNSTR"; 3041173275Ssam case IEEE80211_ELEMID_PWRCAP: return " PWRCAP"; 3042173275Ssam case IEEE80211_ELEMID_TPCREQ: return " TPCREQ"; 3043173275Ssam case IEEE80211_ELEMID_TPCREP: return " TPCREP"; 3044173275Ssam case IEEE80211_ELEMID_SUPPCHAN: return " SUPPCHAN"; 3045193447Ssam case IEEE80211_ELEMID_CSA: return " CSA"; 3046173275Ssam case IEEE80211_ELEMID_MEASREQ: return " MEASREQ"; 3047173275Ssam case IEEE80211_ELEMID_MEASREP: return " MEASREP"; 3048173275Ssam case IEEE80211_ELEMID_QUIET: return " QUIET"; 3049173275Ssam case IEEE80211_ELEMID_IBSSDFS: return " IBSSDFS"; 3050173275Ssam case IEEE80211_ELEMID_TPC: return " TPC"; 3051173275Ssam case IEEE80211_ELEMID_CCKM: return " CCKM"; 3052173275Ssam } 3053173275Ssam return " ???"; 3054173275Ssam} 3055173275Ssam 3056138593Ssamstatic void 3057138593Ssamprinties(const u_int8_t *vp, int ielen, int maxcols) 3058138593Ssam{ 3059138593Ssam while (ielen > 0) { 3060138593Ssam switch (vp[0]) { 3061173275Ssam case IEEE80211_ELEMID_SSID: 3062173275Ssam if (verbose) 3063173275Ssam printssid(" SSID", vp, 2+vp[1], maxcols); 3064173275Ssam break; 3065173275Ssam case IEEE80211_ELEMID_RATES: 3066173275Ssam case IEEE80211_ELEMID_XRATES: 3067173275Ssam if (verbose) 3068173275Ssam printrates(vp[0] == IEEE80211_ELEMID_RATES ? 3069173275Ssam " RATES" : " XRATES", vp, 2+vp[1], maxcols); 3070173275Ssam break; 3071173275Ssam case IEEE80211_ELEMID_DSPARMS: 3072173275Ssam if (verbose) 3073173275Ssam printf(" DSPARMS<%u>", vp[2]); 3074173275Ssam break; 3075173275Ssam case IEEE80211_ELEMID_COUNTRY: 3076173275Ssam if (verbose) 3077173275Ssam printcountry(" COUNTRY", vp, 2+vp[1], maxcols); 3078173275Ssam break; 3079173275Ssam case IEEE80211_ELEMID_ERP: 3080173275Ssam if (verbose) 3081173275Ssam printf(" ERP<0x%x>", vp[2]); 3082173275Ssam break; 3083138593Ssam case IEEE80211_ELEMID_VENDOR: 3084138593Ssam if (iswpaoui(vp)) 3085170531Ssam printwpaie(" WPA", vp, 2+vp[1], maxcols); 3086173275Ssam else if (iswmeinfo(vp)) 3087173275Ssam printwmeinfo(" WME", vp, 2+vp[1], maxcols); 3088173275Ssam else if (iswmeparam(vp)) 3089173275Ssam printwmeparam(" WME", vp, 2+vp[1], maxcols); 3090139492Ssam else if (isatherosoui(vp)) 3091170531Ssam printathie(" ATH", vp, 2+vp[1], maxcols); 3092181454Ssam else if (iswpsoui(vp)) 3093181454Ssam printwpsie(" WPS", vp, 2+vp[1], maxcols); 3094186904Ssam else if (istdmaoui(vp)) 3095186904Ssam printtdmaie(" TDMA", vp, 2+vp[1], maxcols); 3096173275Ssam else if (verbose) 3097138593Ssam printie(" VEN", vp, 2+vp[1], maxcols); 3098138593Ssam break; 3099138593Ssam case IEEE80211_ELEMID_RSN: 3100170531Ssam printrsnie(" RSN", vp, 2+vp[1], maxcols); 3101138593Ssam break; 3102173275Ssam case IEEE80211_ELEMID_HTCAP: 3103173275Ssam printhtcap(" HTCAP", vp, 2+vp[1], maxcols); 3104173275Ssam break; 3105173275Ssam case IEEE80211_ELEMID_HTINFO: 3106173275Ssam if (verbose) 3107173275Ssam printhtinfo(" HTINFO", vp, 2+vp[1], maxcols); 3108173275Ssam break; 3109195618Srpaulo case IEEE80211_ELEMID_MESHID: 3110195618Srpaulo if (verbose) 3111195618Srpaulo printssid(" MESHID", vp, 2+vp[1], maxcols); 3112195618Srpaulo break; 3113195618Srpaulo case IEEE80211_ELEMID_MESHCONF: 3114195618Srpaulo printmeshconf(" MESHCONF", vp, 2+vp[1], maxcols); 3115195618Srpaulo break; 3116138593Ssam default: 3117173275Ssam if (verbose) 3118173275Ssam printie(iename(vp[0]), vp, 2+vp[1], maxcols); 3119138593Ssam break; 3120138593Ssam } 3121138593Ssam ielen -= 2+vp[1]; 3122138593Ssam vp += 2+vp[1]; 3123138593Ssam } 3124138593Ssam} 3125138593Ssam 3126138593Ssamstatic void 3127178354Ssamprintmimo(const struct ieee80211_mimo_info *mi) 3128178354Ssam{ 3129178354Ssam /* NB: don't muddy display unless there's something to show */ 3130220935Sadrian if (mi->rssi[0] != 0 || mi->rssi[1] != 0 || mi->rssi[2] != 0) { 3131178354Ssam /* XXX ignore EVM for now */ 3132178354Ssam printf(" (rssi %d:%d:%d nf %d:%d:%d)", 3133220935Sadrian mi->rssi[0], mi->rssi[1], mi->rssi[2], 3134220935Sadrian mi->noise[0], mi->noise[1], mi->noise[2]); 3135178354Ssam } 3136178354Ssam} 3137178354Ssam 3138178354Ssamstatic void 3139138593Ssamlist_scan(int s) 3140138593Ssam{ 3141138593Ssam uint8_t buf[24*1024]; 3142153892Srwatson char ssid[IEEE80211_NWID_LEN+1]; 3143173275Ssam const uint8_t *cp; 3144195618Srpaulo int len, ssidmax, idlen; 3145138593Ssam 3146173275Ssam if (get80211len(s, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0) 3147138593Ssam errx(1, "unable to get scan results"); 3148138593Ssam if (len < sizeof(struct ieee80211req_scan_result)) 3149138593Ssam return; 3150138593Ssam 3151170531Ssam getchaninfo(s); 3152170531Ssam 3153195618Srpaulo ssidmax = verbose ? IEEE80211_NWID_LEN - 1 : 14; 3154170531Ssam printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n" 3155195618Srpaulo , ssidmax, ssidmax, "SSID/MESH ID" 3156138593Ssam , "BSSID" 3157138593Ssam , "CHAN" 3158138593Ssam , "RATE" 3159170531Ssam , " S:N" 3160138593Ssam , "INT" 3161138593Ssam , "CAPS" 3162138593Ssam ); 3163138593Ssam cp = buf; 3164138593Ssam do { 3165170531Ssam const struct ieee80211req_scan_result *sr; 3166195618Srpaulo const uint8_t *vp, *idp; 3167138593Ssam 3168170531Ssam sr = (const struct ieee80211req_scan_result *) cp; 3169173275Ssam vp = cp + sr->isr_ie_off; 3170195618Srpaulo if (sr->isr_meshid_len) { 3171195618Srpaulo idp = vp + sr->isr_ssid_len; 3172195618Srpaulo idlen = sr->isr_meshid_len; 3173195618Srpaulo } else { 3174195618Srpaulo idp = vp; 3175195618Srpaulo idlen = sr->isr_ssid_len; 3176195618Srpaulo } 3177170531Ssam printf("%-*.*s %s %3d %3dM %3d:%-3d %3d %-4.4s" 3178154522Ssam , ssidmax 3179195618Srpaulo , copy_essid(ssid, ssidmax, idp, idlen) 3180154522Ssam , ssid 3181138593Ssam , ether_ntoa((const struct ether_addr *) sr->isr_bssid) 3182165570Ssam , ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags) 3183138593Ssam , getmaxrate(sr->isr_rates, sr->isr_nrates) 3184170531Ssam , (sr->isr_rssi/2)+sr->isr_noise, sr->isr_noise 3185138593Ssam , sr->isr_intval 3186138593Ssam , getcaps(sr->isr_capinfo) 3187138593Ssam ); 3188195618Srpaulo printies(vp + sr->isr_ssid_len + sr->isr_meshid_len, 3189195618Srpaulo sr->isr_ie_len, 24); 3190138593Ssam printf("\n"); 3191138593Ssam cp += sr->isr_len, len -= sr->isr_len; 3192138593Ssam } while (len >= sizeof(struct ieee80211req_scan_result)); 3193138593Ssam} 3194138593Ssam 3195138593Ssamstatic void 3196138593Ssamscan_and_wait(int s) 3197138593Ssam{ 3198178354Ssam struct ieee80211_scan_req sr; 3199138593Ssam struct ieee80211req ireq; 3200138593Ssam int sroute; 3201138593Ssam 3202138593Ssam sroute = socket(PF_ROUTE, SOCK_RAW, 0); 3203138593Ssam if (sroute < 0) { 3204138593Ssam perror("socket(PF_ROUTE,SOCK_RAW)"); 3205138593Ssam return; 3206138593Ssam } 3207138593Ssam (void) memset(&ireq, 0, sizeof(ireq)); 3208138593Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 3209138593Ssam ireq.i_type = IEEE80211_IOC_SCAN_REQ; 3210178354Ssam 3211178354Ssam memset(&sr, 0, sizeof(sr)); 3212178354Ssam sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE 3213218090Sbschmidt | IEEE80211_IOC_SCAN_BGSCAN 3214178354Ssam | IEEE80211_IOC_SCAN_NOPICK 3215178354Ssam | IEEE80211_IOC_SCAN_ONCE; 3216178354Ssam sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER; 3217178354Ssam sr.sr_nssid = 0; 3218178354Ssam 3219178354Ssam ireq.i_data = &sr; 3220178354Ssam ireq.i_len = sizeof(sr); 3221218093Sbschmidt /* 3222218093Sbschmidt * NB: only root can trigger a scan so ignore errors. Also ignore 3223218093Sbschmidt * possible errors from net80211, even if no new scan could be 3224218093Sbschmidt * started there might still be a valid scan cache. 3225218093Sbschmidt */ 3226218093Sbschmidt if (ioctl(s, SIOCS80211, &ireq) == 0) { 3227138593Ssam char buf[2048]; 3228138593Ssam struct if_announcemsghdr *ifan; 3229138593Ssam struct rt_msghdr *rtm; 3230138593Ssam 3231138593Ssam do { 3232138593Ssam if (read(sroute, buf, sizeof(buf)) < 0) { 3233138593Ssam perror("read(PF_ROUTE)"); 3234138593Ssam break; 3235138593Ssam } 3236138593Ssam rtm = (struct rt_msghdr *) buf; 3237138593Ssam if (rtm->rtm_version != RTM_VERSION) 3238138593Ssam break; 3239138593Ssam ifan = (struct if_announcemsghdr *) rtm; 3240138593Ssam } while (rtm->rtm_type != RTM_IEEE80211 || 3241138593Ssam ifan->ifan_what != RTM_IEEE80211_SCAN); 3242138593Ssam } 3243138593Ssam close(sroute); 3244138593Ssam} 3245138593Ssam 3246138593Ssamstatic 3247138593SsamDECL_CMD_FUNC(set80211scan, val, d) 3248138593Ssam{ 3249138593Ssam scan_and_wait(s); 3250138593Ssam list_scan(s); 3251138593Ssam} 3252138593Ssam 3253161147Ssamstatic enum ieee80211_opmode get80211opmode(int s); 3254161147Ssam 3255173275Ssamstatic int 3256173275Ssamgettxseq(const struct ieee80211req_sta_info *si) 3257173275Ssam{ 3258173275Ssam int i, txseq; 3259173275Ssam 3260173275Ssam if ((si->isi_state & IEEE80211_NODE_QOS) == 0) 3261173275Ssam return si->isi_txseqs[0]; 3262173275Ssam /* XXX not right but usually what folks want */ 3263173275Ssam txseq = 0; 3264173275Ssam for (i = 0; i < IEEE80211_TID_SIZE; i++) 3265173275Ssam if (si->isi_txseqs[i] > txseq) 3266173275Ssam txseq = si->isi_txseqs[i]; 3267173275Ssam return txseq; 3268173275Ssam} 3269173275Ssam 3270173275Ssamstatic int 3271173275Ssamgetrxseq(const struct ieee80211req_sta_info *si) 3272173275Ssam{ 3273173275Ssam int i, rxseq; 3274173275Ssam 3275173275Ssam if ((si->isi_state & IEEE80211_NODE_QOS) == 0) 3276173275Ssam return si->isi_rxseqs[0]; 3277173275Ssam /* XXX not right but usually what folks want */ 3278173275Ssam rxseq = 0; 3279173275Ssam for (i = 0; i < IEEE80211_TID_SIZE; i++) 3280173275Ssam if (si->isi_rxseqs[i] > rxseq) 3281173275Ssam rxseq = si->isi_rxseqs[i]; 3282173275Ssam return rxseq; 3283173275Ssam} 3284173275Ssam 3285138593Ssamstatic void 3286138593Ssamlist_stations(int s) 3287138593Ssam{ 3288161147Ssam union { 3289161147Ssam struct ieee80211req_sta_req req; 3290161147Ssam uint8_t buf[24*1024]; 3291161147Ssam } u; 3292161147Ssam enum ieee80211_opmode opmode = get80211opmode(s); 3293170531Ssam const uint8_t *cp; 3294138593Ssam int len; 3295138593Ssam 3296161147Ssam /* broadcast address =>'s get all stations */ 3297161147Ssam (void) memset(u.req.is_u.macaddr, 0xff, IEEE80211_ADDR_LEN); 3298161147Ssam if (opmode == IEEE80211_M_STA) { 3299161147Ssam /* 3300161147Ssam * Get information about the associated AP. 3301161147Ssam */ 3302173275Ssam (void) get80211(s, IEEE80211_IOC_BSSID, 3303173275Ssam u.req.is_u.macaddr, IEEE80211_ADDR_LEN); 3304161147Ssam } 3305173275Ssam if (get80211len(s, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0) 3306138593Ssam errx(1, "unable to get station information"); 3307138593Ssam if (len < sizeof(struct ieee80211req_sta_info)) 3308138593Ssam return; 3309138593Ssam 3310170531Ssam getchaninfo(s); 3311170531Ssam 3312195618Srpaulo if (opmode == IEEE80211_M_MBSS) 3313195618Srpaulo printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n" 3314195618Srpaulo , "ADDR" 3315195618Srpaulo , "CHAN" 3316195618Srpaulo , "LOCAL" 3317195618Srpaulo , "PEER" 3318195618Srpaulo , "STATE" 3319195618Srpaulo , "RATE" 3320195618Srpaulo , "RSSI" 3321195618Srpaulo , "IDLE" 3322195618Srpaulo , "TXSEQ" 3323195618Srpaulo , "RXSEQ" 3324195618Srpaulo ); 3325195618Srpaulo else 3326195618Srpaulo printf("%-17.17s %4s %4s %4s %4s %4s %6s %6s %4s %-7s\n" 3327195618Srpaulo , "ADDR" 3328195618Srpaulo , "AID" 3329195618Srpaulo , "CHAN" 3330195618Srpaulo , "RATE" 3331195618Srpaulo , "RSSI" 3332195618Srpaulo , "IDLE" 3333195618Srpaulo , "TXSEQ" 3334195618Srpaulo , "RXSEQ" 3335195618Srpaulo , "CAPS" 3336195618Srpaulo , "FLAG" 3337195618Srpaulo ); 3338170531Ssam cp = (const uint8_t *) u.req.info; 3339138593Ssam do { 3340170531Ssam const struct ieee80211req_sta_info *si; 3341138593Ssam 3342170531Ssam si = (const struct ieee80211req_sta_info *) cp; 3343161147Ssam if (si->isi_len < sizeof(*si)) 3344161147Ssam break; 3345195618Srpaulo if (opmode == IEEE80211_M_MBSS) 3346195618Srpaulo printf("%s %4d %5x %5x %7.7s %3dM %4.1f %4d %6d %6d" 3347195618Srpaulo , ether_ntoa((const struct ether_addr*) 3348195618Srpaulo si->isi_macaddr) 3349195618Srpaulo , ieee80211_mhz2ieee(si->isi_freq, 3350195618Srpaulo si->isi_flags) 3351195618Srpaulo , si->isi_localid 3352195618Srpaulo , si->isi_peerid 3353195618Srpaulo , mesh_linkstate_string(si->isi_peerstate) 3354195618Srpaulo , si->isi_txmbps/2 3355195618Srpaulo , si->isi_rssi/2. 3356195618Srpaulo , si->isi_inact 3357195618Srpaulo , gettxseq(si) 3358195618Srpaulo , getrxseq(si) 3359195618Srpaulo ); 3360195618Srpaulo else 3361195618Srpaulo printf("%s %4u %4d %3dM %4.1f %4d %6d %6d %-4.4s %-7.7s" 3362195618Srpaulo , ether_ntoa((const struct ether_addr*) 3363195618Srpaulo si->isi_macaddr) 3364195618Srpaulo , IEEE80211_AID(si->isi_associd) 3365195618Srpaulo , ieee80211_mhz2ieee(si->isi_freq, 3366195618Srpaulo si->isi_flags) 3367195618Srpaulo , si->isi_txmbps/2 3368195618Srpaulo , si->isi_rssi/2. 3369195618Srpaulo , si->isi_inact 3370195618Srpaulo , gettxseq(si) 3371195618Srpaulo , getrxseq(si) 3372195618Srpaulo , getcaps(si->isi_capinfo) 3373195618Srpaulo , getflags(si->isi_state) 3374195618Srpaulo ); 3375170531Ssam printies(cp + si->isi_ie_off, si->isi_ie_len, 24); 3376178354Ssam printmimo(&si->isi_mimo); 3377138593Ssam printf("\n"); 3378138593Ssam cp += si->isi_len, len -= si->isi_len; 3379138593Ssam } while (len >= sizeof(struct ieee80211req_sta_info)); 3380138593Ssam} 3381138593Ssam 3382170531Ssamstatic const char * 3383195618Srpaulomesh_linkstate_string(uint8_t state) 3384195618Srpaulo{ 3385195618Srpaulo#define N(a) (sizeof(a) / sizeof(a[0])) 3386195618Srpaulo static const char *state_names[] = { 3387195618Srpaulo [0] = "IDLE", 3388195618Srpaulo [1] = "OPEN-TX", 3389195618Srpaulo [2] = "OPEN-RX", 3390195618Srpaulo [3] = "CONF-RX", 3391195618Srpaulo [4] = "ESTAB", 3392195618Srpaulo [5] = "HOLDING", 3393195618Srpaulo }; 3394195618Srpaulo 3395195618Srpaulo if (state >= N(state_names)) { 3396195618Srpaulo static char buf[10]; 3397195618Srpaulo snprintf(buf, sizeof(buf), "#%u", state); 3398195618Srpaulo return buf; 3399195618Srpaulo } else 3400195618Srpaulo return state_names[state]; 3401195618Srpaulo#undef N 3402195618Srpaulo} 3403195618Srpaulo 3404195618Srpaulostatic const char * 3405170531Ssamget_chaninfo(const struct ieee80211_channel *c, int precise, 3406170531Ssam char buf[], size_t bsize) 3407138593Ssam{ 3408138593Ssam buf[0] = '\0'; 3409138593Ssam if (IEEE80211_IS_CHAN_FHSS(c)) 3410170531Ssam strlcat(buf, " FHSS", bsize); 3411187843Ssam if (IEEE80211_IS_CHAN_A(c)) 3412187843Ssam strlcat(buf, " 11a", bsize); 3413187843Ssam else if (IEEE80211_IS_CHAN_ANYG(c)) 3414187843Ssam strlcat(buf, " 11g", bsize); 3415187843Ssam else if (IEEE80211_IS_CHAN_B(c)) 3416170531Ssam strlcat(buf, " 11b", bsize); 3417187843Ssam if (IEEE80211_IS_CHAN_HALF(c)) 3418202161Sgavin strlcat(buf, "/10MHz", bsize); 3419187843Ssam if (IEEE80211_IS_CHAN_QUARTER(c)) 3420202161Sgavin strlcat(buf, "/5MHz", bsize); 3421170531Ssam if (IEEE80211_IS_CHAN_TURBO(c)) 3422170531Ssam strlcat(buf, " Turbo", bsize); 3423170531Ssam if (precise) { 3424170531Ssam if (IEEE80211_IS_CHAN_HT20(c)) 3425170531Ssam strlcat(buf, " ht/20", bsize); 3426170531Ssam else if (IEEE80211_IS_CHAN_HT40D(c)) 3427170531Ssam strlcat(buf, " ht/40-", bsize); 3428170531Ssam else if (IEEE80211_IS_CHAN_HT40U(c)) 3429170531Ssam strlcat(buf, " ht/40+", bsize); 3430170531Ssam } else { 3431170531Ssam if (IEEE80211_IS_CHAN_HT(c)) 3432170531Ssam strlcat(buf, " ht", bsize); 3433170531Ssam } 3434170531Ssam return buf; 3435170531Ssam} 3436170531Ssam 3437170531Ssamstatic void 3438173275Ssamprint_chaninfo(const struct ieee80211_channel *c, int verb) 3439170531Ssam{ 3440170531Ssam char buf[14]; 3441170531Ssam 3442224219Sadrian if (verb) 3443224219Sadrian printf("Channel %3u : %u%c%c%c%c%c MHz%-14.14s", 3444224219Sadrian ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq, 3445224219Sadrian IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ', 3446224219Sadrian IEEE80211_IS_CHAN_DFS(c) ? 'D' : ' ', 3447224219Sadrian IEEE80211_IS_CHAN_RADAR(c) ? 'R' : ' ', 3448224219Sadrian IEEE80211_IS_CHAN_CWINT(c) ? 'I' : ' ', 3449224219Sadrian IEEE80211_IS_CHAN_CACDONE(c) ? 'C' : ' ', 3450224219Sadrian get_chaninfo(c, verb, buf, sizeof(buf))); 3451224219Sadrian else 3452202161Sgavin printf("Channel %3u : %u%c MHz%-14.14s", 3453224219Sadrian ieee80211_mhz2ieee(c->ic_freq, c->ic_flags), c->ic_freq, 3454224219Sadrian IEEE80211_IS_CHAN_PASSIVE(c) ? '*' : ' ', 3455224219Sadrian get_chaninfo(c, verb, buf, sizeof(buf))); 3456224219Sadrian 3457138593Ssam} 3458138593Ssam 3459187844Ssamstatic int 3460187844Ssamchanpref(const struct ieee80211_channel *c) 3461187844Ssam{ 3462187844Ssam if (IEEE80211_IS_CHAN_HT40(c)) 3463187844Ssam return 40; 3464187844Ssam if (IEEE80211_IS_CHAN_HT20(c)) 3465187844Ssam return 30; 3466187844Ssam if (IEEE80211_IS_CHAN_HALF(c)) 3467187844Ssam return 10; 3468187844Ssam if (IEEE80211_IS_CHAN_QUARTER(c)) 3469187844Ssam return 5; 3470187844Ssam if (IEEE80211_IS_CHAN_TURBO(c)) 3471187844Ssam return 25; 3472187844Ssam if (IEEE80211_IS_CHAN_A(c)) 3473187844Ssam return 20; 3474187844Ssam if (IEEE80211_IS_CHAN_G(c)) 3475187844Ssam return 20; 3476187844Ssam if (IEEE80211_IS_CHAN_B(c)) 3477187844Ssam return 15; 3478187844Ssam if (IEEE80211_IS_CHAN_PUREG(c)) 3479187844Ssam return 15; 3480187844Ssam return 0; 3481187844Ssam} 3482187844Ssam 3483138593Ssamstatic void 3484173275Ssamprint_channels(int s, const struct ieee80211req_chaninfo *chans, 3485173275Ssam int allchans, int verb) 3486138593Ssam{ 3487187801Ssam struct ieee80211req_chaninfo *achans; 3488170531Ssam uint8_t reported[IEEE80211_CHAN_BYTES]; 3489138593Ssam const struct ieee80211_channel *c; 3490170531Ssam int i, half; 3491138593Ssam 3492187801Ssam achans = malloc(IEEE80211_CHANINFO_SPACE(chans)); 3493187801Ssam if (achans == NULL) 3494187801Ssam errx(1, "no space for active channel list"); 3495187801Ssam achans->ic_nchans = 0; 3496170531Ssam memset(reported, 0, sizeof(reported)); 3497138593Ssam if (!allchans) { 3498138593Ssam struct ieee80211req_chanlist active; 3499138593Ssam 3500173275Ssam if (get80211(s, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0) 3501138593Ssam errx(1, "unable to get active channel list"); 3502173275Ssam for (i = 0; i < chans->ic_nchans; i++) { 3503173275Ssam c = &chans->ic_chans[i]; 3504170531Ssam if (!isset(active.ic_channels, c->ic_ieee)) 3505170531Ssam continue; 3506170531Ssam /* 3507170531Ssam * Suppress compatible duplicates unless 3508170531Ssam * verbose. The kernel gives us it's 3509170531Ssam * complete channel list which has separate 3510170531Ssam * entries for 11g/11b and 11a/turbo. 3511170531Ssam */ 3512173275Ssam if (isset(reported, c->ic_ieee) && !verb) { 3513170531Ssam /* XXX we assume duplicates are adjacent */ 3514187801Ssam achans->ic_chans[achans->ic_nchans-1] = *c; 3515170531Ssam } else { 3516187801Ssam achans->ic_chans[achans->ic_nchans++] = *c; 3517170531Ssam setbit(reported, c->ic_ieee); 3518170531Ssam } 3519138593Ssam } 3520170531Ssam } else { 3521173275Ssam for (i = 0; i < chans->ic_nchans; i++) { 3522173275Ssam c = &chans->ic_chans[i]; 3523170531Ssam /* suppress duplicates as above */ 3524173275Ssam if (isset(reported, c->ic_ieee) && !verb) { 3525170531Ssam /* XXX we assume duplicates are adjacent */ 3526187844Ssam struct ieee80211_channel *a = 3527187844Ssam &achans->ic_chans[achans->ic_nchans-1]; 3528187844Ssam if (chanpref(c) > chanpref(a)) 3529187844Ssam *a = *c; 3530170531Ssam } else { 3531187801Ssam achans->ic_chans[achans->ic_nchans++] = *c; 3532170531Ssam setbit(reported, c->ic_ieee); 3533170531Ssam } 3534170531Ssam } 3535170531Ssam } 3536187801Ssam half = achans->ic_nchans / 2; 3537187801Ssam if (achans->ic_nchans % 2) 3538138593Ssam half++; 3539170531Ssam 3540187801Ssam for (i = 0; i < achans->ic_nchans / 2; i++) { 3541187801Ssam print_chaninfo(&achans->ic_chans[i], verb); 3542187801Ssam print_chaninfo(&achans->ic_chans[half+i], verb); 3543138593Ssam printf("\n"); 3544138593Ssam } 3545187801Ssam if (achans->ic_nchans % 2) { 3546187801Ssam print_chaninfo(&achans->ic_chans[i], verb); 3547138593Ssam printf("\n"); 3548138593Ssam } 3549187801Ssam free(achans); 3550138593Ssam} 3551138593Ssam 3552138593Ssamstatic void 3553173275Ssamlist_channels(int s, int allchans) 3554173275Ssam{ 3555173275Ssam getchaninfo(s); 3556187801Ssam print_channels(s, chaninfo, allchans, verbose); 3557173275Ssam} 3558173275Ssam 3559173275Ssamstatic void 3560170531Ssamprint_txpow(const struct ieee80211_channel *c) 3561170531Ssam{ 3562202161Sgavin printf("Channel %3u : %u MHz %3.1f reg %2d ", 3563170531Ssam c->ic_ieee, c->ic_freq, 3564170531Ssam c->ic_maxpower/2., c->ic_maxregpower); 3565170531Ssam} 3566170531Ssam 3567170531Ssamstatic void 3568170531Ssamprint_txpow_verbose(const struct ieee80211_channel *c) 3569170531Ssam{ 3570173275Ssam print_chaninfo(c, 1); 3571170531Ssam printf("min %4.1f dBm max %3.1f dBm reg %2d dBm", 3572170531Ssam c->ic_minpower/2., c->ic_maxpower/2., c->ic_maxregpower); 3573170531Ssam /* indicate where regulatory cap limits power use */ 3574170531Ssam if (c->ic_maxpower > 2*c->ic_maxregpower) 3575170531Ssam printf(" <"); 3576170531Ssam} 3577170531Ssam 3578170531Ssamstatic void 3579170531Ssamlist_txpow(int s) 3580170531Ssam{ 3581187801Ssam struct ieee80211req_chaninfo *achans; 3582170531Ssam uint8_t reported[IEEE80211_CHAN_BYTES]; 3583170531Ssam struct ieee80211_channel *c, *prev; 3584170531Ssam int i, half; 3585170531Ssam 3586170531Ssam getchaninfo(s); 3587187801Ssam achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo)); 3588187801Ssam if (achans == NULL) 3589187801Ssam errx(1, "no space for active channel list"); 3590187801Ssam achans->ic_nchans = 0; 3591170531Ssam memset(reported, 0, sizeof(reported)); 3592187801Ssam for (i = 0; i < chaninfo->ic_nchans; i++) { 3593187801Ssam c = &chaninfo->ic_chans[i]; 3594170531Ssam /* suppress duplicates as above */ 3595170531Ssam if (isset(reported, c->ic_ieee) && !verbose) { 3596170531Ssam /* XXX we assume duplicates are adjacent */ 3597187801Ssam prev = &achans->ic_chans[achans->ic_nchans-1]; 3598170531Ssam /* display highest power on channel */ 3599170531Ssam if (c->ic_maxpower > prev->ic_maxpower) 3600170531Ssam *prev = *c; 3601170531Ssam } else { 3602187801Ssam achans->ic_chans[achans->ic_nchans++] = *c; 3603170531Ssam setbit(reported, c->ic_ieee); 3604170531Ssam } 3605170531Ssam } 3606170531Ssam if (!verbose) { 3607187801Ssam half = achans->ic_nchans / 2; 3608187801Ssam if (achans->ic_nchans % 2) 3609170531Ssam half++; 3610170531Ssam 3611187801Ssam for (i = 0; i < achans->ic_nchans / 2; i++) { 3612187801Ssam print_txpow(&achans->ic_chans[i]); 3613187801Ssam print_txpow(&achans->ic_chans[half+i]); 3614170531Ssam printf("\n"); 3615170531Ssam } 3616187801Ssam if (achans->ic_nchans % 2) { 3617187801Ssam print_txpow(&achans->ic_chans[i]); 3618170531Ssam printf("\n"); 3619170531Ssam } 3620170531Ssam } else { 3621187801Ssam for (i = 0; i < achans->ic_nchans; i++) { 3622187801Ssam print_txpow_verbose(&achans->ic_chans[i]); 3623170531Ssam printf("\n"); 3624170531Ssam } 3625170531Ssam } 3626187801Ssam free(achans); 3627170531Ssam} 3628170531Ssam 3629170531Ssamstatic void 3630138593Ssamlist_keys(int s) 3631138593Ssam{ 3632138593Ssam} 3633138593Ssam 3634138593Ssam#define IEEE80211_C_BITS \ 3635195618Srpaulo "\20\1STA\002803ENCAP\7FF\10TURBOP\11IBSS\12PMGT" \ 3636178354Ssam "\13HOSTAP\14AHDEMO\15SWRETRY\16TXPMGT\17SHSLOT\20SHPREAMBLE" \ 3637195618Srpaulo "\21MONITOR\22DFS\23MBSS\30WPA1\31WPA2\32BURST\33WME\34WDS\36BGSCAN" \ 3638186904Ssam "\37TXFRAG\40TDMA" 3639138593Ssam 3640138593Ssamstatic void 3641138593Ssamlist_capabilities(int s) 3642138593Ssam{ 3643187801Ssam struct ieee80211_devcaps_req *dc; 3644138593Ssam 3645187845Ssam if (verbose) 3646187845Ssam dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN)); 3647187845Ssam else 3648187845Ssam dc = malloc(IEEE80211_DEVCAPS_SIZE(1)); 3649187801Ssam if (dc == NULL) 3650187801Ssam errx(1, "no space for device capabilities"); 3651187845Ssam dc->dc_chaninfo.ic_nchans = verbose ? MAXCHAN : 1; 3652187801Ssam getdevcaps(s, dc); 3653187801Ssam printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS); 3654187801Ssam if (dc->dc_cryptocaps != 0 || verbose) { 3655178354Ssam putchar('\n'); 3656187801Ssam printb("cryptocaps", dc->dc_cryptocaps, IEEE80211_CRYPTO_BITS); 3657178354Ssam } 3658187801Ssam if (dc->dc_htcaps != 0 || verbose) { 3659178354Ssam putchar('\n'); 3660187801Ssam printb("htcaps", dc->dc_htcaps, IEEE80211_HTCAP_BITS); 3661178354Ssam } 3662138593Ssam putchar('\n'); 3663187845Ssam if (verbose) { 3664187845Ssam chaninfo = &dc->dc_chaninfo; /* XXX */ 3665187845Ssam print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, verbose); 3666187845Ssam } 3667187801Ssam free(dc); 3668138593Ssam} 3669138593Ssam 3670173275Ssamstatic int 3671173275Ssamget80211wme(int s, int param, int ac, int *val) 3672173275Ssam{ 3673173275Ssam struct ieee80211req ireq; 3674173275Ssam 3675173275Ssam (void) memset(&ireq, 0, sizeof(ireq)); 3676173275Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 3677173275Ssam ireq.i_type = param; 3678173275Ssam ireq.i_len = ac; 3679173275Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) { 3680173275Ssam warn("cannot get WME parameter %d, ac %d%s", 3681173275Ssam param, ac & IEEE80211_WMEPARAM_VAL, 3682173275Ssam ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : ""); 3683173275Ssam return -1; 3684173275Ssam } 3685173275Ssam *val = ireq.i_val; 3686173275Ssam return 0; 3687173275Ssam} 3688173275Ssam 3689138593Ssamstatic void 3690181199Ssamlist_wme_aci(int s, const char *tag, int ac) 3691138593Ssam{ 3692181199Ssam int val; 3693138593Ssam 3694181199Ssam printf("\t%s", tag); 3695138593Ssam 3696181199Ssam /* show WME BSS parameters */ 3697181199Ssam if (get80211wme(s, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1) 3698181199Ssam printf(" cwmin %2u", val); 3699181199Ssam if (get80211wme(s, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1) 3700181199Ssam printf(" cwmax %2u", val); 3701181199Ssam if (get80211wme(s, IEEE80211_IOC_WME_AIFS, ac, &val) != -1) 3702181199Ssam printf(" aifs %2u", val); 3703181199Ssam if (get80211wme(s, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1) 3704181199Ssam printf(" txopLimit %3u", val); 3705181199Ssam if (get80211wme(s, IEEE80211_IOC_WME_ACM, ac, &val) != -1) { 3706181199Ssam if (val) 3707181199Ssam printf(" acm"); 3708181199Ssam else if (verbose) 3709181199Ssam printf(" -acm"); 3710181199Ssam } 3711181199Ssam /* !BSS only */ 3712181199Ssam if ((ac & IEEE80211_WMEPARAM_BSS) == 0) { 3713181199Ssam if (get80211wme(s, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) { 3714181199Ssam if (!val) 3715181199Ssam printf(" -ack"); 3716138593Ssam else if (verbose) 3717181199Ssam printf(" ack"); 3718138593Ssam } 3719181199Ssam } 3720181199Ssam printf("\n"); 3721181199Ssam} 3722181199Ssam 3723181199Ssamstatic void 3724181199Ssamlist_wme(int s) 3725181199Ssam{ 3726181199Ssam static const char *acnames[] = { "AC_BE", "AC_BK", "AC_VI", "AC_VO" }; 3727181199Ssam int ac; 3728181199Ssam 3729181199Ssam if (verbose) { 3730181199Ssam /* display both BSS and local settings */ 3731181199Ssam for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) { 3732181199Ssam again: 3733181199Ssam if (ac & IEEE80211_WMEPARAM_BSS) 3734181199Ssam list_wme_aci(s, " ", ac); 3735181199Ssam else 3736181199Ssam list_wme_aci(s, acnames[ac], ac); 3737181199Ssam if ((ac & IEEE80211_WMEPARAM_BSS) == 0) { 3738181199Ssam ac |= IEEE80211_WMEPARAM_BSS; 3739181199Ssam goto again; 3740181199Ssam } else 3741181199Ssam ac &= ~IEEE80211_WMEPARAM_BSS; 3742138593Ssam } 3743181199Ssam } else { 3744181199Ssam /* display only channel settings */ 3745181199Ssam for (ac = WME_AC_BE; ac <= WME_AC_VO; ac++) 3746181199Ssam list_wme_aci(s, acnames[ac], ac); 3747138593Ssam } 3748138593Ssam} 3749138593Ssam 3750149029Ssamstatic void 3751178354Ssamlist_roam(int s) 3752178354Ssam{ 3753178354Ssam const struct ieee80211_roamparam *rp; 3754178354Ssam int mode; 3755178354Ssam 3756178354Ssam getroam(s); 3757188784Ssam for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) { 3758178354Ssam rp = &roamparams.params[mode]; 3759178354Ssam if (rp->rssi == 0 && rp->rate == 0) 3760178354Ssam continue; 3761188784Ssam if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) { 3762188784Ssam if (rp->rssi & 1) 3763188784Ssam LINE_CHECK("roam:%-7.7s rssi %2u.5dBm MCS %2u ", 3764188784Ssam modename[mode], rp->rssi/2, 3765188784Ssam rp->rate &~ IEEE80211_RATE_MCS); 3766188784Ssam else 3767188784Ssam LINE_CHECK("roam:%-7.7s rssi %4udBm MCS %2u ", 3768188784Ssam modename[mode], rp->rssi/2, 3769188784Ssam rp->rate &~ IEEE80211_RATE_MCS); 3770188784Ssam } else { 3771188784Ssam if (rp->rssi & 1) 3772188784Ssam LINE_CHECK("roam:%-7.7s rssi %2u.5dBm rate %2u Mb/s", 3773188784Ssam modename[mode], rp->rssi/2, rp->rate/2); 3774188784Ssam else 3775188784Ssam LINE_CHECK("roam:%-7.7s rssi %4udBm rate %2u Mb/s", 3776188784Ssam modename[mode], rp->rssi/2, rp->rate/2); 3777188784Ssam } 3778178354Ssam } 3779178354Ssam} 3780178354Ssam 3781178354Ssamstatic void 3782178354Ssamlist_txparams(int s) 3783178354Ssam{ 3784178354Ssam const struct ieee80211_txparam *tp; 3785178354Ssam int mode; 3786178354Ssam 3787178354Ssam gettxparams(s); 3788188784Ssam for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) { 3789178354Ssam tp = &txparams.params[mode]; 3790178354Ssam if (tp->mgmtrate == 0 && tp->mcastrate == 0) 3791178354Ssam continue; 3792188784Ssam if (mode == IEEE80211_MODE_11NA || mode == IEEE80211_MODE_11NG) { 3793188784Ssam if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) 3794188784Ssam LINE_CHECK("%-7.7s ucast NONE mgmt %2u MCS " 3795188784Ssam "mcast %2u MCS maxretry %u", 3796188784Ssam modename[mode], 3797188784Ssam tp->mgmtrate &~ IEEE80211_RATE_MCS, 3798188784Ssam tp->mcastrate &~ IEEE80211_RATE_MCS, 3799188784Ssam tp->maxretry); 3800188784Ssam else 3801188784Ssam LINE_CHECK("%-7.7s ucast %2u MCS mgmt %2u MCS " 3802188784Ssam "mcast %2u MCS maxretry %u", 3803188784Ssam modename[mode], 3804188784Ssam tp->ucastrate &~ IEEE80211_RATE_MCS, 3805188784Ssam tp->mgmtrate &~ IEEE80211_RATE_MCS, 3806188784Ssam tp->mcastrate &~ IEEE80211_RATE_MCS, 3807188784Ssam tp->maxretry); 3808188784Ssam } else { 3809188784Ssam if (tp->ucastrate == IEEE80211_FIXED_RATE_NONE) 3810188784Ssam LINE_CHECK("%-7.7s ucast NONE mgmt %2u Mb/s " 3811188784Ssam "mcast %2u Mb/s maxretry %u", 3812188784Ssam modename[mode], 3813188784Ssam tp->mgmtrate/2, 3814188784Ssam tp->mcastrate/2, tp->maxretry); 3815188784Ssam else 3816188784Ssam LINE_CHECK("%-7.7s ucast %2u Mb/s mgmt %2u Mb/s " 3817188784Ssam "mcast %2u Mb/s maxretry %u", 3818188784Ssam modename[mode], 3819188784Ssam tp->ucastrate/2, tp->mgmtrate/2, 3820188784Ssam tp->mcastrate/2, tp->maxretry); 3821188784Ssam } 3822178354Ssam } 3823178354Ssam} 3824178354Ssam 3825178354Ssamstatic void 3826173275Ssamprintpolicy(int policy) 3827173275Ssam{ 3828173275Ssam switch (policy) { 3829173275Ssam case IEEE80211_MACCMD_POLICY_OPEN: 3830173275Ssam printf("policy: open\n"); 3831173275Ssam break; 3832173275Ssam case IEEE80211_MACCMD_POLICY_ALLOW: 3833173275Ssam printf("policy: allow\n"); 3834173275Ssam break; 3835173275Ssam case IEEE80211_MACCMD_POLICY_DENY: 3836173275Ssam printf("policy: deny\n"); 3837173275Ssam break; 3838178354Ssam case IEEE80211_MACCMD_POLICY_RADIUS: 3839178354Ssam printf("policy: radius\n"); 3840178354Ssam break; 3841173275Ssam default: 3842173275Ssam printf("policy: unknown (%u)\n", policy); 3843173275Ssam break; 3844173275Ssam } 3845173275Ssam} 3846173275Ssam 3847173275Ssamstatic void 3848149029Ssamlist_mac(int s) 3849149029Ssam{ 3850149029Ssam struct ieee80211req ireq; 3851149029Ssam struct ieee80211req_maclist *acllist; 3852173275Ssam int i, nacls, policy, len; 3853173275Ssam uint8_t *data; 3854149029Ssam char c; 3855149029Ssam 3856149029Ssam (void) memset(&ireq, 0, sizeof(ireq)); 3857149029Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); /* XXX ?? */ 3858149029Ssam ireq.i_type = IEEE80211_IOC_MACCMD; 3859149029Ssam ireq.i_val = IEEE80211_MACCMD_POLICY; 3860149029Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) { 3861149029Ssam if (errno == EINVAL) { 3862149029Ssam printf("No acl policy loaded\n"); 3863149029Ssam return; 3864149029Ssam } 3865149029Ssam err(1, "unable to get mac policy"); 3866149029Ssam } 3867149029Ssam policy = ireq.i_val; 3868149029Ssam if (policy == IEEE80211_MACCMD_POLICY_OPEN) { 3869149029Ssam c = '*'; 3870149029Ssam } else if (policy == IEEE80211_MACCMD_POLICY_ALLOW) { 3871149029Ssam c = '+'; 3872149029Ssam } else if (policy == IEEE80211_MACCMD_POLICY_DENY) { 3873149029Ssam c = '-'; 3874178354Ssam } else if (policy == IEEE80211_MACCMD_POLICY_RADIUS) { 3875178354Ssam c = 'r'; /* NB: should never have entries */ 3876149029Ssam } else { 3877149029Ssam printf("policy: unknown (%u)\n", policy); 3878149029Ssam c = '?'; 3879149029Ssam } 3880173275Ssam if (verbose || c == '?') 3881173275Ssam printpolicy(policy); 3882173275Ssam 3883175952Ssam ireq.i_val = IEEE80211_MACCMD_LIST; 3884175952Ssam ireq.i_len = 0; 3885175952Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) 3886173275Ssam err(1, "unable to get mac acl list size"); 3887175952Ssam if (ireq.i_len == 0) { /* NB: no acls */ 3888173275Ssam if (!(verbose || c == '?')) 3889173275Ssam printpolicy(policy); 3890173275Ssam return; 3891173275Ssam } 3892175952Ssam len = ireq.i_len; 3893173275Ssam 3894173275Ssam data = malloc(len); 3895173275Ssam if (data == NULL) 3896173275Ssam err(1, "out of memory for acl list"); 3897173275Ssam 3898175952Ssam ireq.i_data = data; 3899175952Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) 3900173275Ssam err(1, "unable to get mac acl list"); 3901173275Ssam nacls = len / sizeof(*acllist); 3902173275Ssam acllist = (struct ieee80211req_maclist *) data; 3903149029Ssam for (i = 0; i < nacls; i++) 3904149029Ssam printf("%c%s\n", c, ether_ntoa( 3905149029Ssam (const struct ether_addr *) acllist[i].ml_macaddr)); 3906173275Ssam free(data); 3907149029Ssam} 3908149029Ssam 3909178354Ssamstatic void 3910178354Ssamprint_regdomain(const struct ieee80211_regdomain *reg, int verb) 3911178354Ssam{ 3912178354Ssam if ((reg->regdomain != 0 && 3913178354Ssam reg->regdomain != reg->country) || verb) { 3914178354Ssam const struct regdomain *rd = 3915178354Ssam lib80211_regdomain_findbysku(getregdata(), reg->regdomain); 3916178354Ssam if (rd == NULL) 3917178354Ssam LINE_CHECK("regdomain %d", reg->regdomain); 3918178354Ssam else 3919178354Ssam LINE_CHECK("regdomain %s", rd->name); 3920178354Ssam } 3921178354Ssam if (reg->country != 0 || verb) { 3922178354Ssam const struct country *cc = 3923178354Ssam lib80211_country_findbycc(getregdata(), reg->country); 3924178354Ssam if (cc == NULL) 3925178354Ssam LINE_CHECK("country %d", reg->country); 3926178354Ssam else 3927178354Ssam LINE_CHECK("country %s", cc->isoname); 3928178354Ssam } 3929178354Ssam if (reg->location == 'I') 3930178354Ssam LINE_CHECK("indoor"); 3931178354Ssam else if (reg->location == 'O') 3932178354Ssam LINE_CHECK("outdoor"); 3933178354Ssam else if (verb) 3934178354Ssam LINE_CHECK("anywhere"); 3935178354Ssam if (reg->ecm) 3936178354Ssam LINE_CHECK("ecm"); 3937178354Ssam else if (verb) 3938178354Ssam LINE_CHECK("-ecm"); 3939178354Ssam} 3940178354Ssam 3941178354Ssamstatic void 3942178354Ssamlist_regdomain(int s, int channelsalso) 3943178354Ssam{ 3944178354Ssam getregdomain(s); 3945178354Ssam if (channelsalso) { 3946178354Ssam getchaninfo(s); 3947178354Ssam spacer = ':'; 3948178354Ssam print_regdomain(®domain, 1); 3949178354Ssam LINE_BREAK(); 3950187801Ssam print_channels(s, chaninfo, 1/*allchans*/, 1/*verbose*/); 3951178354Ssam } else 3952178354Ssam print_regdomain(®domain, verbose); 3953178354Ssam} 3954178354Ssam 3955195618Srpaulostatic void 3956195618Srpaulolist_mesh(int s) 3957195618Srpaulo{ 3958195618Srpaulo struct ieee80211req ireq; 3959195618Srpaulo struct ieee80211req_mesh_route routes[128]; 3960195908Srpaulo struct ieee80211req_mesh_route *rt; 3961195618Srpaulo 3962195618Srpaulo (void) memset(&ireq, 0, sizeof(ireq)); 3963195618Srpaulo (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 3964195618Srpaulo ireq.i_type = IEEE80211_IOC_MESH_RTCMD; 3965195618Srpaulo ireq.i_val = IEEE80211_MESH_RTCMD_LIST; 3966195618Srpaulo ireq.i_data = &routes; 3967195618Srpaulo ireq.i_len = sizeof(routes); 3968195618Srpaulo if (ioctl(s, SIOCG80211, &ireq) < 0) 3969195618Srpaulo err(1, "unable to get the Mesh routing table"); 3970195618Srpaulo 3971195908Srpaulo printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n" 3972195618Srpaulo , "DEST" 3973195618Srpaulo , "NEXT HOP" 3974195618Srpaulo , "HOPS" 3975195618Srpaulo , "METRIC" 3976195784Srpaulo , "LIFETIME" 3977195908Srpaulo , "MSEQ" 3978195908Srpaulo , "FLAGS"); 3979195618Srpaulo 3980195908Srpaulo for (rt = &routes[0]; rt - &routes[0] < ireq.i_len / sizeof(*rt); rt++){ 3981195618Srpaulo printf("%s ", 3982195908Srpaulo ether_ntoa((const struct ether_addr *)rt->imr_dest)); 3983195908Srpaulo printf("%s %4u %4u %6u %6u %c%c\n", 3984195908Srpaulo ether_ntoa((const struct ether_addr *)rt->imr_nexthop), 3985195908Srpaulo rt->imr_nhops, rt->imr_metric, rt->imr_lifetime, 3986195908Srpaulo rt->imr_lastmseq, 3987195908Srpaulo (rt->imr_flags & IEEE80211_MESHRT_FLAGS_VALID) ? 3988195908Srpaulo 'V' : '!', 3989195908Srpaulo (rt->imr_flags & IEEE80211_MESHRT_FLAGS_PROXY) ? 3990195908Srpaulo 'P' : ' '); 3991195618Srpaulo } 3992195618Srpaulo} 3993195618Srpaulo 3994138593Ssamstatic 3995138593SsamDECL_CMD_FUNC(set80211list, arg, d) 3996138593Ssam{ 3997138593Ssam#define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0) 3998138593Ssam 3999173275Ssam LINE_INIT('\t'); 4000173275Ssam 4001138593Ssam if (iseq(arg, "sta")) 4002138593Ssam list_stations(s); 4003138593Ssam else if (iseq(arg, "scan") || iseq(arg, "ap")) 4004138593Ssam list_scan(s); 4005138593Ssam else if (iseq(arg, "chan") || iseq(arg, "freq")) 4006138593Ssam list_channels(s, 1); 4007138593Ssam else if (iseq(arg, "active")) 4008138593Ssam list_channels(s, 0); 4009138593Ssam else if (iseq(arg, "keys")) 4010138593Ssam list_keys(s); 4011138593Ssam else if (iseq(arg, "caps")) 4012138593Ssam list_capabilities(s); 4013178354Ssam else if (iseq(arg, "wme") || iseq(arg, "wmm")) 4014138593Ssam list_wme(s); 4015149029Ssam else if (iseq(arg, "mac")) 4016149029Ssam list_mac(s); 4017170531Ssam else if (iseq(arg, "txpow")) 4018170531Ssam list_txpow(s); 4019178354Ssam else if (iseq(arg, "roam")) 4020178354Ssam list_roam(s); 4021178354Ssam else if (iseq(arg, "txparam") || iseq(arg, "txparm")) 4022178354Ssam list_txparams(s); 4023178354Ssam else if (iseq(arg, "regdomain")) 4024178354Ssam list_regdomain(s, 1); 4025178354Ssam else if (iseq(arg, "countries")) 4026178354Ssam list_countries(); 4027195618Srpaulo else if (iseq(arg, "mesh")) 4028195618Srpaulo list_mesh(s); 4029138593Ssam else 4030138593Ssam errx(1, "Don't know how to list %s for %s", arg, name); 4031178354Ssam LINE_BREAK(); 4032138593Ssam#undef iseq 4033138593Ssam} 4034138593Ssam 4035138593Ssamstatic enum ieee80211_opmode 4036138593Ssamget80211opmode(int s) 4037138593Ssam{ 4038138593Ssam struct ifmediareq ifmr; 4039138593Ssam 4040138593Ssam (void) memset(&ifmr, 0, sizeof(ifmr)); 4041138593Ssam (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); 4042138593Ssam 4043138593Ssam if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) { 4044186101Ssam if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) { 4045186101Ssam if (ifmr.ifm_current & IFM_FLAG0) 4046186101Ssam return IEEE80211_M_AHDEMO; 4047186101Ssam else 4048186101Ssam return IEEE80211_M_IBSS; 4049186101Ssam } 4050138593Ssam if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP) 4051138593Ssam return IEEE80211_M_HOSTAP; 4052138593Ssam if (ifmr.ifm_current & IFM_IEEE80211_MONITOR) 4053138593Ssam return IEEE80211_M_MONITOR; 4054195618Srpaulo if (ifmr.ifm_current & IFM_IEEE80211_MBSS) 4055195618Srpaulo return IEEE80211_M_MBSS; 4056138593Ssam } 4057138593Ssam return IEEE80211_M_STA; 4058138593Ssam} 4059138593Ssam 4060138593Ssam#if 0 4061138593Ssamstatic void 4062138593Ssamprintcipher(int s, struct ieee80211req *ireq, int keylenop) 4063138593Ssam{ 4064138593Ssam switch (ireq->i_val) { 4065138593Ssam case IEEE80211_CIPHER_WEP: 4066138593Ssam ireq->i_type = keylenop; 4067138593Ssam if (ioctl(s, SIOCG80211, ireq) != -1) 4068138593Ssam printf("WEP-%s", 4069138593Ssam ireq->i_len <= 5 ? "40" : 4070138593Ssam ireq->i_len <= 13 ? "104" : "128"); 4071138593Ssam else 4072138593Ssam printf("WEP"); 4073138593Ssam break; 4074138593Ssam case IEEE80211_CIPHER_TKIP: 4075138593Ssam printf("TKIP"); 4076138593Ssam break; 4077138593Ssam case IEEE80211_CIPHER_AES_OCB: 4078138593Ssam printf("AES-OCB"); 4079138593Ssam break; 4080138593Ssam case IEEE80211_CIPHER_AES_CCM: 4081138593Ssam printf("AES-CCM"); 4082138593Ssam break; 4083138593Ssam case IEEE80211_CIPHER_CKIP: 4084138593Ssam printf("CKIP"); 4085138593Ssam break; 4086138593Ssam case IEEE80211_CIPHER_NONE: 4087138593Ssam printf("NONE"); 4088138593Ssam break; 4089138593Ssam default: 4090138593Ssam printf("UNKNOWN (0x%x)", ireq->i_val); 4091138593Ssam break; 4092138593Ssam } 4093138593Ssam} 4094138593Ssam#endif 4095138593Ssam 4096155931Ssamstatic void 4097138593Ssamprintkey(const struct ieee80211req_key *ik) 4098138593Ssam{ 4099138593Ssam static const uint8_t zerodata[IEEE80211_KEYBUF_SIZE]; 4100138593Ssam int keylen = ik->ik_keylen; 4101138593Ssam int printcontents; 4102138593Ssam 4103148001Srwatson printcontents = printkeys && 4104138593Ssam (memcmp(ik->ik_keydata, zerodata, keylen) != 0 || verbose); 4105138593Ssam if (printcontents) 4106138593Ssam LINE_BREAK(); 4107138593Ssam switch (ik->ik_type) { 4108138593Ssam case IEEE80211_CIPHER_WEP: 4109138593Ssam /* compatibility */ 4110155931Ssam LINE_CHECK("wepkey %u:%s", ik->ik_keyix+1, 4111138593Ssam keylen <= 5 ? "40-bit" : 4112138593Ssam keylen <= 13 ? "104-bit" : "128-bit"); 4113138593Ssam break; 4114138593Ssam case IEEE80211_CIPHER_TKIP: 4115138593Ssam if (keylen > 128/8) 4116138593Ssam keylen -= 128/8; /* ignore MIC for now */ 4117155931Ssam LINE_CHECK("TKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4118138593Ssam break; 4119138593Ssam case IEEE80211_CIPHER_AES_OCB: 4120155931Ssam LINE_CHECK("AES-OCB %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4121138593Ssam break; 4122138593Ssam case IEEE80211_CIPHER_AES_CCM: 4123155931Ssam LINE_CHECK("AES-CCM %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4124138593Ssam break; 4125138593Ssam case IEEE80211_CIPHER_CKIP: 4126155931Ssam LINE_CHECK("CKIP %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4127138593Ssam break; 4128138593Ssam case IEEE80211_CIPHER_NONE: 4129155931Ssam LINE_CHECK("NULL %u:%u-bit", ik->ik_keyix+1, 8*keylen); 4130138593Ssam break; 4131138593Ssam default: 4132155931Ssam LINE_CHECK("UNKNOWN (0x%x) %u:%u-bit", 4133138593Ssam ik->ik_type, ik->ik_keyix+1, 8*keylen); 4134138593Ssam break; 4135138593Ssam } 4136138593Ssam if (printcontents) { 4137138593Ssam int i; 4138138593Ssam 4139138593Ssam printf(" <"); 4140138593Ssam for (i = 0; i < keylen; i++) 4141138593Ssam printf("%02x", ik->ik_keydata[i]); 4142138593Ssam printf(">"); 4143138593Ssam if (ik->ik_type != IEEE80211_CIPHER_WEP && 4144138593Ssam (ik->ik_keyrsc != 0 || verbose)) 4145146873Sjhb printf(" rsc %ju", (uintmax_t)ik->ik_keyrsc); 4146138593Ssam if (ik->ik_type != IEEE80211_CIPHER_WEP && 4147138593Ssam (ik->ik_keytsc != 0 || verbose)) 4148146873Sjhb printf(" tsc %ju", (uintmax_t)ik->ik_keytsc); 4149138593Ssam if (ik->ik_flags != 0 && verbose) { 4150138593Ssam const char *sep = " "; 4151138593Ssam 4152138593Ssam if (ik->ik_flags & IEEE80211_KEY_XMIT) 4153138593Ssam printf("%stx", sep), sep = "+"; 4154138593Ssam if (ik->ik_flags & IEEE80211_KEY_RECV) 4155138593Ssam printf("%srx", sep), sep = "+"; 4156138593Ssam if (ik->ik_flags & IEEE80211_KEY_DEFAULT) 4157138593Ssam printf("%sdef", sep), sep = "+"; 4158138593Ssam } 4159138593Ssam LINE_BREAK(); 4160138593Ssam } 4161138593Ssam} 4162138593Ssam 4163138593Ssamstatic void 4164173275Ssamprintrate(const char *tag, int v, int defrate, int defmcs) 4165138593Ssam{ 4166188784Ssam if ((v & IEEE80211_RATE_MCS) == 0) { 4167188784Ssam if (v != defrate) { 4168188784Ssam if (v & 1) 4169188784Ssam LINE_CHECK("%s %d.5", tag, v/2); 4170188784Ssam else 4171188784Ssam LINE_CHECK("%s %d", tag, v/2); 4172188784Ssam } 4173188784Ssam } else { 4174173275Ssam if (v != defmcs) 4175173275Ssam LINE_CHECK("%s %d", tag, v &~ 0x80); 4176173275Ssam } 4177173275Ssam} 4178173275Ssam 4179173275Ssamstatic int 4180195618Srpaulogetid(int s, int ix, void *data, size_t len, int *plen, int mesh) 4181173275Ssam{ 4182138593Ssam struct ieee80211req ireq; 4183138593Ssam 4184138593Ssam (void) memset(&ireq, 0, sizeof(ireq)); 4185138593Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 4186195618Srpaulo ireq.i_type = (!mesh) ? IEEE80211_IOC_SSID : IEEE80211_IOC_MESH_ID; 4187173275Ssam ireq.i_val = ix; 4188173275Ssam ireq.i_data = data; 4189173275Ssam ireq.i_len = len; 4190173275Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) 4191173275Ssam return -1; 4192173275Ssam *plen = ireq.i_len; 4193173275Ssam return 0; 4194173275Ssam} 419577218Sphk 4196173275Ssamstatic void 4197173275Ssamieee80211_status(int s) 4198173275Ssam{ 4199173275Ssam static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; 4200173275Ssam enum ieee80211_opmode opmode = get80211opmode(s); 4201173275Ssam int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode; 4202173275Ssam uint8_t data[32]; 4203173275Ssam const struct ieee80211_channel *c; 4204178354Ssam const struct ieee80211_roamparam *rp; 4205178354Ssam const struct ieee80211_txparam *tp; 4206173275Ssam 4207195618Srpaulo if (getid(s, -1, data, sizeof(data), &len, 0) < 0) { 4208148686Sstefanf /* If we can't get the SSID, this isn't an 802.11 device. */ 420977218Sphk return; 421077218Sphk } 4211173275Ssam 4212173275Ssam /* 4213173275Ssam * Invalidate cached state so printing status for multiple 4214173275Ssam * if's doesn't reuse the first interfaces' cached state. 4215173275Ssam */ 4216173275Ssam gotcurchan = 0; 4217178354Ssam gotroam = 0; 4218178354Ssam gottxparams = 0; 4219173275Ssam gothtconf = 0; 4220178354Ssam gotregdomain = 0; 4221173275Ssam 4222195618Srpaulo printf("\t"); 4223195618Srpaulo if (opmode == IEEE80211_M_MBSS) { 4224195618Srpaulo printf("meshid "); 4225195618Srpaulo getid(s, 0, data, sizeof(data), &len, 1); 4226195618Srpaulo print_string(data, len); 4227195618Srpaulo } else { 4228195618Srpaulo if (get80211val(s, IEEE80211_IOC_NUMSSIDS, &num) < 0) 4229195618Srpaulo num = 0; 4230195618Srpaulo printf("ssid "); 4231195618Srpaulo if (num > 1) { 4232195618Srpaulo for (i = 0; i < num; i++) { 4233195618Srpaulo if (getid(s, i, data, sizeof(data), &len, 0) >= 0 && len > 0) { 4234195618Srpaulo printf(" %d:", i + 1); 4235195618Srpaulo print_string(data, len); 4236195618Srpaulo } 4237138593Ssam } 4238195618Srpaulo } else 4239195618Srpaulo print_string(data, len); 4240195618Srpaulo } 4241173275Ssam c = getcurchan(s); 4242170531Ssam if (c->ic_freq != IEEE80211_CHAN_ANY) { 4243170531Ssam char buf[14]; 4244202161Sgavin printf(" channel %d (%u MHz%s)", c->ic_ieee, c->ic_freq, 4245170531Ssam get_chaninfo(c, 1, buf, sizeof(buf))); 4246138593Ssam } else if (verbose) 4247138593Ssam printf(" channel UNDEF"); 4248138593Ssam 4249173275Ssam if (get80211(s, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 && 4250173275Ssam (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose)) 4251173275Ssam printf(" bssid %s", ether_ntoa((struct ether_addr *)data)); 4252138593Ssam 4253173275Ssam if (get80211len(s, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) { 4254138593Ssam printf("\n\tstationname "); 4255173275Ssam print_string(data, len); 425677218Sphk } 425777218Sphk 4258138593Ssam spacer = ' '; /* force first break */ 4259138593Ssam LINE_BREAK(); 426077218Sphk 4261178354Ssam list_regdomain(s, 0); 4262178354Ssam 4263173275Ssam wpa = 0; 4264173275Ssam if (get80211val(s, IEEE80211_IOC_AUTHMODE, &val) != -1) { 4265173275Ssam switch (val) { 4266173275Ssam case IEEE80211_AUTH_NONE: 4267173275Ssam LINE_CHECK("authmode NONE"); 4268173275Ssam break; 4269173275Ssam case IEEE80211_AUTH_OPEN: 4270173275Ssam LINE_CHECK("authmode OPEN"); 4271173275Ssam break; 4272173275Ssam case IEEE80211_AUTH_SHARED: 4273173275Ssam LINE_CHECK("authmode SHARED"); 4274173275Ssam break; 4275173275Ssam case IEEE80211_AUTH_8021X: 4276173275Ssam LINE_CHECK("authmode 802.1x"); 4277173275Ssam break; 4278173275Ssam case IEEE80211_AUTH_WPA: 4279173275Ssam if (get80211val(s, IEEE80211_IOC_WPA, &wpa) < 0) 4280173275Ssam wpa = 1; /* default to WPA1 */ 4281173275Ssam switch (wpa) { 4282173275Ssam case 2: 4283173275Ssam LINE_CHECK("authmode WPA2/802.11i"); 428477218Sphk break; 4285173275Ssam case 3: 4286173275Ssam LINE_CHECK("authmode WPA1+WPA2/802.11i"); 428777218Sphk break; 4288127649Ssam default: 4289173275Ssam LINE_CHECK("authmode WPA"); 4290127649Ssam break; 4291173275Ssam } 4292173275Ssam break; 4293173275Ssam case IEEE80211_AUTH_AUTO: 4294173275Ssam LINE_CHECK("authmode AUTO"); 4295173275Ssam break; 4296173275Ssam default: 4297173275Ssam LINE_CHECK("authmode UNKNOWN (0x%x)", val); 4298173275Ssam break; 4299127649Ssam } 4300127649Ssam } 4301127649Ssam 4302173275Ssam if (wpa || verbose) { 4303178354Ssam if (get80211val(s, IEEE80211_IOC_WPS, &val) != -1) { 4304178354Ssam if (val) 4305178354Ssam LINE_CHECK("wps"); 4306178354Ssam else if (verbose) 4307178354Ssam LINE_CHECK("-wps"); 4308178354Ssam } 4309178354Ssam if (get80211val(s, IEEE80211_IOC_TSN, &val) != -1) { 4310178354Ssam if (val) 4311178354Ssam LINE_CHECK("tsn"); 4312178354Ssam else if (verbose) 4313178354Ssam LINE_CHECK("-tsn"); 4314178354Ssam } 4315173275Ssam if (ioctl(s, IEEE80211_IOC_COUNTERMEASURES, &val) != -1) { 4316173275Ssam if (val) 4317173275Ssam LINE_CHECK("countermeasures"); 4318173275Ssam else if (verbose) 4319173275Ssam LINE_CHECK("-countermeasures"); 4320173275Ssam } 4321178354Ssam#if 0 4322178354Ssam /* XXX not interesting with WPA done in user space */ 4323178354Ssam ireq.i_type = IEEE80211_IOC_KEYMGTALGS; 4324178354Ssam if (ioctl(s, SIOCG80211, &ireq) != -1) { 4325178354Ssam } 4326178354Ssam 4327178354Ssam ireq.i_type = IEEE80211_IOC_MCASTCIPHER; 4328178354Ssam if (ioctl(s, SIOCG80211, &ireq) != -1) { 4329178354Ssam LINE_CHECK("mcastcipher "); 4330178354Ssam printcipher(s, &ireq, IEEE80211_IOC_MCASTKEYLEN); 4331178354Ssam spacer = ' '; 4332178354Ssam } 4333178354Ssam 4334178354Ssam ireq.i_type = IEEE80211_IOC_UCASTCIPHER; 4335178354Ssam if (ioctl(s, SIOCG80211, &ireq) != -1) { 4336178354Ssam LINE_CHECK("ucastcipher "); 4337178354Ssam printcipher(s, &ireq, IEEE80211_IOC_UCASTKEYLEN); 4338178354Ssam } 4339178354Ssam 4340178354Ssam if (wpa & 2) { 4341178354Ssam ireq.i_type = IEEE80211_IOC_RSNCAPS; 4342178354Ssam if (ioctl(s, SIOCG80211, &ireq) != -1) { 4343178354Ssam LINE_CHECK("RSN caps 0x%x", ireq.i_val); 4344178354Ssam spacer = ' '; 4345178354Ssam } 4346178354Ssam } 4347178354Ssam 4348178354Ssam ireq.i_type = IEEE80211_IOC_UCASTCIPHERS; 4349178354Ssam if (ioctl(s, SIOCG80211, &ireq) != -1) { 4350178354Ssam } 4351178354Ssam#endif 4352173275Ssam } 4353138593Ssam 4354173275Ssam if (get80211val(s, IEEE80211_IOC_WEP, &wepmode) != -1 && 4355173275Ssam wepmode != IEEE80211_WEP_NOSUP) { 4356173275Ssam 4357138718Ssam switch (wepmode) { 4358173275Ssam case IEEE80211_WEP_OFF: 4359173275Ssam LINE_CHECK("privacy OFF"); 4360173275Ssam break; 4361173275Ssam case IEEE80211_WEP_ON: 4362173275Ssam LINE_CHECK("privacy ON"); 4363173275Ssam break; 4364173275Ssam case IEEE80211_WEP_MIXED: 4365173275Ssam LINE_CHECK("privacy MIXED"); 4366173275Ssam break; 4367173275Ssam default: 4368173275Ssam LINE_CHECK("privacy UNKNOWN (0x%x)", wepmode); 4369173275Ssam break; 437077218Sphk } 437177218Sphk 437277218Sphk /* 437377218Sphk * If we get here then we've got WEP support so we need 437477218Sphk * to print WEP status. 437591454Sbrooks */ 437677218Sphk 4377173275Ssam if (get80211val(s, IEEE80211_IOC_WEPTXKEY, &val) < 0) { 437877218Sphk warn("WEP support, but no tx key!"); 437977218Sphk goto end; 438077218Sphk } 4381173275Ssam if (val != -1) 4382173275Ssam LINE_CHECK("deftxkey %d", val+1); 4383138718Ssam else if (wepmode != IEEE80211_WEP_OFF || verbose) 4384155931Ssam LINE_CHECK("deftxkey UNDEF"); 438577218Sphk 4386173275Ssam if (get80211val(s, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) { 438777218Sphk warn("WEP support, but no NUMWEPKEYS support!"); 438877218Sphk goto end; 438977218Sphk } 439077218Sphk 4391138593Ssam for (i = 0; i < num; i++) { 4392138593Ssam struct ieee80211req_key ik; 439377218Sphk 4394138593Ssam memset(&ik, 0, sizeof(ik)); 4395138593Ssam ik.ik_keyix = i; 4396173275Ssam if (get80211(s, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) { 439777218Sphk warn("WEP support, but can get keys!"); 439877218Sphk goto end; 439977218Sphk } 4400138593Ssam if (ik.ik_keylen != 0) { 4401138593Ssam if (verbose) 4402138593Ssam LINE_BREAK(); 4403138593Ssam printkey(&ik); 4404138593Ssam } 4405138593Ssam } 4406173275Ssamend: 4407173275Ssam ; 4408138593Ssam } 4409138593Ssam 4410173275Ssam if (get80211val(s, IEEE80211_IOC_POWERSAVE, &val) != -1 && 4411173275Ssam val != IEEE80211_POWERSAVE_NOSUP ) { 4412173275Ssam if (val != IEEE80211_POWERSAVE_OFF || verbose) { 4413173275Ssam switch (val) { 4414173275Ssam case IEEE80211_POWERSAVE_OFF: 4415173275Ssam LINE_CHECK("powersavemode OFF"); 4416173275Ssam break; 4417173275Ssam case IEEE80211_POWERSAVE_CAM: 4418173275Ssam LINE_CHECK("powersavemode CAM"); 4419173275Ssam break; 4420173275Ssam case IEEE80211_POWERSAVE_PSP: 4421173275Ssam LINE_CHECK("powersavemode PSP"); 4422173275Ssam break; 4423173275Ssam case IEEE80211_POWERSAVE_PSP_CAM: 4424173275Ssam LINE_CHECK("powersavemode PSP-CAM"); 4425173275Ssam break; 4426138593Ssam } 4427173275Ssam if (get80211val(s, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1) 4428173275Ssam LINE_CHECK("powersavesleep %d", val); 4429138593Ssam } 4430138593Ssam } 4431138593Ssam 4432173275Ssam if (get80211val(s, IEEE80211_IOC_TXPOWER, &val) != -1) { 4433173275Ssam if (val & 1) 4434173275Ssam LINE_CHECK("txpower %d.5", val/2); 4435173275Ssam else 4436173275Ssam LINE_CHECK("txpower %d", val/2); 4437173275Ssam } 4438138593Ssam if (verbose) { 4439173275Ssam if (get80211val(s, IEEE80211_IOC_TXPOWMAX, &val) != -1) 4440173275Ssam LINE_CHECK("txpowmax %.1f", val/2.); 4441138593Ssam } 4442138593Ssam 4443178354Ssam if (get80211val(s, IEEE80211_IOC_DOTD, &val) != -1) { 4444178354Ssam if (val) 4445178354Ssam LINE_CHECK("dotd"); 4446178354Ssam else if (verbose) 4447178354Ssam LINE_CHECK("-dotd"); 4448178354Ssam } 4449178354Ssam 4450173275Ssam if (get80211val(s, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) { 4451173275Ssam if (val != IEEE80211_RTS_MAX || verbose) 4452173275Ssam LINE_CHECK("rtsthreshold %d", val); 4453138593Ssam } 4454138593Ssam 4455173275Ssam if (get80211val(s, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) { 4456173275Ssam if (val != IEEE80211_FRAG_MAX || verbose) 4457173275Ssam LINE_CHECK("fragthreshold %d", val); 4458170531Ssam } 4459173275Ssam if (opmode == IEEE80211_M_STA || verbose) { 4460173275Ssam if (get80211val(s, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) { 4461173275Ssam if (val != IEEE80211_HWBMISS_MAX || verbose) 4462173275Ssam LINE_CHECK("bmiss %d", val); 4463153354Ssam } 4464153354Ssam } 4465153354Ssam 4466178354Ssam if (!verbose) { 4467178354Ssam gettxparams(s); 4468178354Ssam tp = &txparams.params[chan2mode(c)]; 4469178354Ssam printrate("ucastrate", tp->ucastrate, 4470178354Ssam IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE); 4471188784Ssam printrate("mcastrate", tp->mcastrate, 2*1, 4472188784Ssam IEEE80211_RATE_MCS|0); 4473188784Ssam printrate("mgmtrate", tp->mgmtrate, 2*1, 4474188784Ssam IEEE80211_RATE_MCS|0); 4475178354Ssam if (tp->maxretry != 6) /* XXX */ 4476178354Ssam LINE_CHECK("maxretry %d", tp->maxretry); 4477178354Ssam } else { 4478178354Ssam LINE_BREAK(); 4479178354Ssam list_txparams(s); 4480178354Ssam } 4481170531Ssam 4482173275Ssam bgscaninterval = -1; 4483173275Ssam (void) get80211val(s, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval); 4484173275Ssam 4485173275Ssam if (get80211val(s, IEEE80211_IOC_SCANVALID, &val) != -1) { 4486173275Ssam if (val != bgscaninterval || verbose) 4487173275Ssam LINE_CHECK("scanvalid %u", val); 4488148416Ssam } 4489148416Ssam 4490173275Ssam bgscan = 0; 4491173275Ssam if (get80211val(s, IEEE80211_IOC_BGSCAN, &bgscan) != -1) { 4492173275Ssam if (bgscan) 4493170531Ssam LINE_CHECK("bgscan"); 4494170531Ssam else if (verbose) 4495170531Ssam LINE_CHECK("-bgscan"); 4496160687Ssam } 4497170531Ssam if (bgscan || verbose) { 4498170531Ssam if (bgscaninterval != -1) 4499170531Ssam LINE_CHECK("bgscanintvl %u", bgscaninterval); 4500173275Ssam if (get80211val(s, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1) 4501173275Ssam LINE_CHECK("bgscanidle %u", val); 4502178354Ssam if (!verbose) { 4503178354Ssam getroam(s); 4504178354Ssam rp = &roamparams.params[chan2mode(c)]; 4505178354Ssam if (rp->rssi & 1) 4506178354Ssam LINE_CHECK("roam:rssi %u.5", rp->rssi/2); 4507178354Ssam else 4508178354Ssam LINE_CHECK("roam:rssi %u", rp->rssi/2); 4509178354Ssam LINE_CHECK("roam:rate %u", rp->rate/2); 4510178354Ssam } else { 4511178354Ssam LINE_BREAK(); 4512178354Ssam list_roam(s); 4513205514Srpaulo LINE_BREAK(); 4514170531Ssam } 4515170531Ssam } 4516160687Ssam 4517165570Ssam if (IEEE80211_IS_CHAN_ANYG(c) || verbose) { 4518173275Ssam if (get80211val(s, IEEE80211_IOC_PUREG, &val) != -1) { 4519173275Ssam if (val) 4520155931Ssam LINE_CHECK("pureg"); 4521147795Ssam else if (verbose) 4522155931Ssam LINE_CHECK("-pureg"); 4523147795Ssam } 4524173275Ssam if (get80211val(s, IEEE80211_IOC_PROTMODE, &val) != -1) { 4525173275Ssam switch (val) { 4526173275Ssam case IEEE80211_PROTMODE_OFF: 4527173275Ssam LINE_CHECK("protmode OFF"); 4528173275Ssam break; 4529173275Ssam case IEEE80211_PROTMODE_CTS: 4530173275Ssam LINE_CHECK("protmode CTS"); 4531173275Ssam break; 4532173275Ssam case IEEE80211_PROTMODE_RTSCTS: 4533173275Ssam LINE_CHECK("protmode RTSCTS"); 4534173275Ssam break; 4535173275Ssam default: 4536173275Ssam LINE_CHECK("protmode UNKNOWN (0x%x)", val); 4537173275Ssam break; 4538138593Ssam } 4539138593Ssam } 4540138593Ssam } 4541138593Ssam 4542173275Ssam if (IEEE80211_IS_CHAN_HT(c) || verbose) { 4543173275Ssam gethtconf(s); 4544173275Ssam switch (htconf & 3) { 4545173275Ssam case 0: 4546173275Ssam case 2: 4547173275Ssam LINE_CHECK("-ht"); 4548173275Ssam break; 4549173275Ssam case 1: 4550173275Ssam LINE_CHECK("ht20"); 4551173275Ssam break; 4552173275Ssam case 3: 4553173275Ssam if (verbose) 4554173275Ssam LINE_CHECK("ht"); 4555173275Ssam break; 4556173275Ssam } 4557173275Ssam if (get80211val(s, IEEE80211_IOC_HTCOMPAT, &val) != -1) { 4558173275Ssam if (!val) 4559173275Ssam LINE_CHECK("-htcompat"); 4560173275Ssam else if (verbose) 4561173275Ssam LINE_CHECK("htcompat"); 4562173275Ssam } 4563173275Ssam if (get80211val(s, IEEE80211_IOC_AMPDU, &val) != -1) { 4564173275Ssam switch (val) { 4565173275Ssam case 0: 4566173275Ssam LINE_CHECK("-ampdu"); 4567173275Ssam break; 4568173275Ssam case 1: 4569173275Ssam LINE_CHECK("ampdutx -ampdurx"); 4570173275Ssam break; 4571173275Ssam case 2: 4572173275Ssam LINE_CHECK("-ampdutx ampdurx"); 4573173275Ssam break; 4574173275Ssam case 3: 4575173275Ssam if (verbose) 4576173275Ssam LINE_CHECK("ampdu"); 4577173275Ssam break; 4578173275Ssam } 4579173275Ssam } 4580173275Ssam if (get80211val(s, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) { 4581173275Ssam switch (val) { 4582173275Ssam case IEEE80211_HTCAP_MAXRXAMPDU_8K: 4583173275Ssam LINE_CHECK("ampdulimit 8k"); 4584173275Ssam break; 4585173275Ssam case IEEE80211_HTCAP_MAXRXAMPDU_16K: 4586173275Ssam LINE_CHECK("ampdulimit 16k"); 4587173275Ssam break; 4588173275Ssam case IEEE80211_HTCAP_MAXRXAMPDU_32K: 4589173275Ssam LINE_CHECK("ampdulimit 32k"); 4590173275Ssam break; 4591173275Ssam case IEEE80211_HTCAP_MAXRXAMPDU_64K: 4592173275Ssam LINE_CHECK("ampdulimit 64k"); 4593173275Ssam break; 4594173275Ssam } 4595173275Ssam } 4596173275Ssam if (get80211val(s, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) { 4597173275Ssam switch (val) { 4598173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_NA: 4599173275Ssam if (verbose) 4600183260Ssam LINE_CHECK("ampdudensity NA"); 4601173275Ssam break; 4602173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_025: 4603173275Ssam LINE_CHECK("ampdudensity .25"); 4604173275Ssam break; 4605173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_05: 4606173275Ssam LINE_CHECK("ampdudensity .5"); 4607173275Ssam break; 4608173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_1: 4609173275Ssam LINE_CHECK("ampdudensity 1"); 4610173275Ssam break; 4611173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_2: 4612173275Ssam LINE_CHECK("ampdudensity 2"); 4613173275Ssam break; 4614173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_4: 4615173275Ssam LINE_CHECK("ampdudensity 4"); 4616173275Ssam break; 4617173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_8: 4618173275Ssam LINE_CHECK("ampdudensity 8"); 4619173275Ssam break; 4620173275Ssam case IEEE80211_HTCAP_MPDUDENSITY_16: 4621173275Ssam LINE_CHECK("ampdudensity 16"); 4622173275Ssam break; 4623173275Ssam } 4624173275Ssam } 4625173275Ssam if (get80211val(s, IEEE80211_IOC_AMSDU, &val) != -1) { 4626173275Ssam switch (val) { 4627173275Ssam case 0: 4628173275Ssam LINE_CHECK("-amsdu"); 4629173275Ssam break; 4630173275Ssam case 1: 4631173275Ssam LINE_CHECK("amsdutx -amsdurx"); 4632173275Ssam break; 4633173275Ssam case 2: 4634173275Ssam LINE_CHECK("-amsdutx amsdurx"); 4635173275Ssam break; 4636173275Ssam case 3: 4637173275Ssam if (verbose) 4638173275Ssam LINE_CHECK("amsdu"); 4639173275Ssam break; 4640173275Ssam } 4641173275Ssam } 4642173275Ssam /* XXX amsdu limit */ 4643173275Ssam if (get80211val(s, IEEE80211_IOC_SHORTGI, &val) != -1) { 4644173275Ssam if (val) 4645173275Ssam LINE_CHECK("shortgi"); 4646173275Ssam else if (verbose) 4647173275Ssam LINE_CHECK("-shortgi"); 4648173275Ssam } 4649173275Ssam if (get80211val(s, IEEE80211_IOC_HTPROTMODE, &val) != -1) { 4650173275Ssam if (val == IEEE80211_PROTMODE_OFF) 4651173275Ssam LINE_CHECK("htprotmode OFF"); 4652173275Ssam else if (val != IEEE80211_PROTMODE_RTSCTS) 4653173275Ssam LINE_CHECK("htprotmode UNKNOWN (0x%x)", val); 4654173275Ssam else if (verbose) 4655173275Ssam LINE_CHECK("htprotmode RTSCTS"); 4656173275Ssam } 4657173275Ssam if (get80211val(s, IEEE80211_IOC_PUREN, &val) != -1) { 4658173275Ssam if (val) 4659173275Ssam LINE_CHECK("puren"); 4660173275Ssam else if (verbose) 4661173275Ssam LINE_CHECK("-puren"); 4662173275Ssam } 4663183261Ssam if (get80211val(s, IEEE80211_IOC_SMPS, &val) != -1) { 4664183261Ssam if (val == IEEE80211_HTCAP_SMPS_DYNAMIC) 4665183261Ssam LINE_CHECK("smpsdyn"); 4666183261Ssam else if (val == IEEE80211_HTCAP_SMPS_ENA) 4667183261Ssam LINE_CHECK("smps"); 4668183261Ssam else if (verbose) 4669183261Ssam LINE_CHECK("-smps"); 4670183261Ssam } 4671183261Ssam if (get80211val(s, IEEE80211_IOC_RIFS, &val) != -1) { 4672183261Ssam if (val) 4673183261Ssam LINE_CHECK("rifs"); 4674183261Ssam else if (verbose) 4675183261Ssam LINE_CHECK("-rifs"); 4676183261Ssam } 4677173275Ssam } 4678173275Ssam 4679173275Ssam if (get80211val(s, IEEE80211_IOC_WME, &wme) != -1) { 4680138593Ssam if (wme) 4681155931Ssam LINE_CHECK("wme"); 4682138593Ssam else if (verbose) 4683155931Ssam LINE_CHECK("-wme"); 4684138593Ssam } else 4685138593Ssam wme = 0; 4686138593Ssam 4687173275Ssam if (get80211val(s, IEEE80211_IOC_BURST, &val) != -1) { 4688173275Ssam if (val) 4689155931Ssam LINE_CHECK("burst"); 4690153422Ssam else if (verbose) 4691155931Ssam LINE_CHECK("-burst"); 4692153422Ssam } 4693153422Ssam 4694173275Ssam if (get80211val(s, IEEE80211_IOC_FF, &val) != -1) { 4695173275Ssam if (val) 4696170531Ssam LINE_CHECK("ff"); 4697170531Ssam else if (verbose) 4698170531Ssam LINE_CHECK("-ff"); 4699170531Ssam } 4700173275Ssam if (get80211val(s, IEEE80211_IOC_TURBOP, &val) != -1) { 4701173275Ssam if (val) 4702170531Ssam LINE_CHECK("dturbo"); 4703170531Ssam else if (verbose) 4704170531Ssam LINE_CHECK("-dturbo"); 4705170531Ssam } 4706178354Ssam if (get80211val(s, IEEE80211_IOC_DWDS, &val) != -1) { 4707178354Ssam if (val) 4708178354Ssam LINE_CHECK("dwds"); 4709178354Ssam else if (verbose) 4710178354Ssam LINE_CHECK("-dwds"); 4711178354Ssam } 4712170531Ssam 4713138593Ssam if (opmode == IEEE80211_M_HOSTAP) { 4714173275Ssam if (get80211val(s, IEEE80211_IOC_HIDESSID, &val) != -1) { 4715173275Ssam if (val) 4716168075Ssam LINE_CHECK("hidessid"); 4717138593Ssam else if (verbose) 4718168075Ssam LINE_CHECK("-hidessid"); 4719138593Ssam } 4720173275Ssam if (get80211val(s, IEEE80211_IOC_APBRIDGE, &val) != -1) { 4721173275Ssam if (!val) 4722155931Ssam LINE_CHECK("-apbridge"); 4723138593Ssam else if (verbose) 4724155931Ssam LINE_CHECK("apbridge"); 4725138593Ssam } 4726173275Ssam if (get80211val(s, IEEE80211_IOC_DTIM_PERIOD, &val) != -1) 4727173275Ssam LINE_CHECK("dtimperiod %u", val); 4728138593Ssam 4729173275Ssam if (get80211val(s, IEEE80211_IOC_DOTH, &val) != -1) { 4730173275Ssam if (!val) 4731170531Ssam LINE_CHECK("-doth"); 4732170531Ssam else if (verbose) 4733170531Ssam LINE_CHECK("doth"); 4734170531Ssam } 4735178354Ssam if (get80211val(s, IEEE80211_IOC_DFS, &val) != -1) { 4736178354Ssam if (!val) 4737178354Ssam LINE_CHECK("-dfs"); 4738178354Ssam else if (verbose) 4739178354Ssam LINE_CHECK("dfs"); 4740178354Ssam } 4741173275Ssam if (get80211val(s, IEEE80211_IOC_INACTIVITY, &val) != -1) { 4742173275Ssam if (!val) 4743173275Ssam LINE_CHECK("-inact"); 4744173275Ssam else if (verbose) 4745173275Ssam LINE_CHECK("inact"); 4746173275Ssam } 4747138593Ssam } else { 4748173275Ssam if (get80211val(s, IEEE80211_IOC_ROAMING, &val) != -1) { 4749173275Ssam if (val != IEEE80211_ROAMING_AUTO || verbose) { 4750173275Ssam switch (val) { 4751138593Ssam case IEEE80211_ROAMING_DEVICE: 4752155931Ssam LINE_CHECK("roaming DEVICE"); 4753138593Ssam break; 4754138593Ssam case IEEE80211_ROAMING_AUTO: 4755155931Ssam LINE_CHECK("roaming AUTO"); 4756138593Ssam break; 4757138593Ssam case IEEE80211_ROAMING_MANUAL: 4758155931Ssam LINE_CHECK("roaming MANUAL"); 4759138593Ssam break; 4760138593Ssam default: 4761155931Ssam LINE_CHECK("roaming UNKNOWN (0x%x)", 4762173275Ssam val); 4763138593Ssam break; 4764138593Ssam } 4765138593Ssam } 4766138593Ssam } 4767138593Ssam } 4768186101Ssam 4769186904Ssam if (opmode == IEEE80211_M_AHDEMO) { 4770186904Ssam if (get80211val(s, IEEE80211_IOC_TDMA_SLOT, &val) != -1) 4771186904Ssam LINE_CHECK("tdmaslot %u", val); 4772186904Ssam if (get80211val(s, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1) 4773186904Ssam LINE_CHECK("tdmaslotcnt %u", val); 4774186904Ssam if (get80211val(s, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1) 4775186904Ssam LINE_CHECK("tdmaslotlen %u", val); 4776186904Ssam if (get80211val(s, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1) 4777186904Ssam LINE_CHECK("tdmabintval %u", val); 4778186904Ssam } else if (get80211val(s, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) { 4779173275Ssam /* XXX default define not visible */ 4780173275Ssam if (val != 100 || verbose) 4781173275Ssam LINE_CHECK("bintval %u", val); 4782138593Ssam } 4783138593Ssam 4784138593Ssam if (wme && verbose) { 4785138593Ssam LINE_BREAK(); 4786138593Ssam list_wme(s); 4787138593Ssam } 4788195618Srpaulo 4789195618Srpaulo if (opmode == IEEE80211_M_MBSS) { 4790195618Srpaulo if (get80211val(s, IEEE80211_IOC_MESH_TTL, &val) != -1) { 4791195618Srpaulo LINE_CHECK("meshttl %u", val); 4792195618Srpaulo } 4793195618Srpaulo if (get80211val(s, IEEE80211_IOC_MESH_AP, &val) != -1) { 4794195618Srpaulo if (val) 4795195618Srpaulo LINE_CHECK("meshpeering"); 4796195618Srpaulo else 4797195618Srpaulo LINE_CHECK("-meshpeering"); 4798195618Srpaulo } 4799195618Srpaulo if (get80211val(s, IEEE80211_IOC_MESH_FWRD, &val) != -1) { 4800195618Srpaulo if (val) 4801195618Srpaulo LINE_CHECK("meshforward"); 4802195618Srpaulo else 4803195618Srpaulo LINE_CHECK("-meshforward"); 4804195618Srpaulo } 4805195618Srpaulo if (get80211len(s, IEEE80211_IOC_MESH_PR_METRIC, data, 12, 4806195618Srpaulo &len) != -1) { 4807195618Srpaulo data[len] = '\0'; 4808195618Srpaulo LINE_CHECK("meshmetric %s", data); 4809195618Srpaulo } 4810195618Srpaulo if (get80211len(s, IEEE80211_IOC_MESH_PR_PATH, data, 12, 4811195618Srpaulo &len) != -1) { 4812195618Srpaulo data[len] = '\0'; 4813195618Srpaulo LINE_CHECK("meshpath %s", data); 4814195618Srpaulo } 4815195618Srpaulo if (get80211val(s, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) { 4816195618Srpaulo switch (val) { 4817195618Srpaulo case IEEE80211_HWMP_ROOTMODE_DISABLED: 4818195618Srpaulo LINE_CHECK("hwmprootmode DISABLED"); 4819195618Srpaulo break; 4820195618Srpaulo case IEEE80211_HWMP_ROOTMODE_NORMAL: 4821195618Srpaulo LINE_CHECK("hwmprootmode NORMAL"); 4822195618Srpaulo break; 4823195618Srpaulo case IEEE80211_HWMP_ROOTMODE_PROACTIVE: 4824195618Srpaulo LINE_CHECK("hwmprootmode PROACTIVE"); 4825195618Srpaulo break; 4826195618Srpaulo case IEEE80211_HWMP_ROOTMODE_RANN: 4827195618Srpaulo LINE_CHECK("hwmprootmode RANN"); 4828195618Srpaulo break; 4829195618Srpaulo default: 4830195618Srpaulo LINE_CHECK("hwmprootmode UNKNOWN(%d)", val); 4831195618Srpaulo break; 4832195618Srpaulo } 4833195618Srpaulo } 4834195618Srpaulo if (get80211val(s, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) { 4835195618Srpaulo LINE_CHECK("hwmpmaxhops %u", val); 4836195618Srpaulo } 4837195618Srpaulo } 4838195618Srpaulo 4839173275Ssam LINE_BREAK(); 4840173275Ssam} 4841138593Ssam 4842173275Ssamstatic int 4843173275Ssamget80211(int s, int type, void *data, int len) 4844173275Ssam{ 4845173275Ssam struct ieee80211req ireq; 4846138593Ssam 4847173275Ssam (void) memset(&ireq, 0, sizeof(ireq)); 4848173275Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 4849173275Ssam ireq.i_type = type; 4850173275Ssam ireq.i_data = data; 4851173275Ssam ireq.i_len = len; 4852173275Ssam return ioctl(s, SIOCG80211, &ireq); 4853173275Ssam} 4854138593Ssam 4855173275Ssamstatic int 4856173275Ssamget80211len(int s, int type, void *data, int len, int *plen) 4857173275Ssam{ 4858173275Ssam struct ieee80211req ireq; 4859138593Ssam 4860173275Ssam (void) memset(&ireq, 0, sizeof(ireq)); 4861173275Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 4862173275Ssam ireq.i_type = type; 4863173275Ssam ireq.i_len = len; 4864187801Ssam assert(ireq.i_len == len); /* NB: check for 16-bit truncation */ 4865173275Ssam ireq.i_data = data; 4866173275Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) 4867173275Ssam return -1; 4868173275Ssam *plen = ireq.i_len; 4869173275Ssam return 0; 4870173275Ssam} 4871138593Ssam 4872173275Ssamstatic int 4873173275Ssamget80211val(int s, int type, int *val) 4874173275Ssam{ 4875173275Ssam struct ieee80211req ireq; 487677218Sphk 4877173275Ssam (void) memset(&ireq, 0, sizeof(ireq)); 4878173275Ssam (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 4879173275Ssam ireq.i_type = type; 4880173275Ssam if (ioctl(s, SIOCG80211, &ireq) < 0) 4881173275Ssam return -1; 4882173275Ssam *val = ireq.i_val; 4883173275Ssam return 0; 488477218Sphk} 488577218Sphk 488677218Sphkstatic void 4887170531Ssamset80211(int s, int type, int val, int len, void *data) 488877218Sphk{ 488977218Sphk struct ieee80211req ireq; 489077218Sphk 489177218Sphk (void) memset(&ireq, 0, sizeof(ireq)); 489277218Sphk (void) strncpy(ireq.i_name, name, sizeof(ireq.i_name)); 489377218Sphk ireq.i_type = type; 489477218Sphk ireq.i_val = val; 489577218Sphk ireq.i_len = len; 4896187801Ssam assert(ireq.i_len == len); /* NB: check for 16-bit truncation */ 489777218Sphk ireq.i_data = data; 489891454Sbrooks if (ioctl(s, SIOCS80211, &ireq) < 0) 489977218Sphk err(1, "SIOCS80211"); 490077218Sphk} 490177218Sphk 490277218Sphkstatic const char * 490377218Sphkget_string(const char *val, const char *sep, u_int8_t *buf, int *lenp) 490477218Sphk{ 490577218Sphk int len; 490677218Sphk int hexstr; 490777218Sphk u_int8_t *p; 490877218Sphk 490977218Sphk len = *lenp; 491077218Sphk p = buf; 491177218Sphk hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x'); 491277218Sphk if (hexstr) 491377218Sphk val += 2; 491477218Sphk for (;;) { 491577218Sphk if (*val == '\0') 491677218Sphk break; 491777218Sphk if (sep != NULL && strchr(sep, *val) != NULL) { 491877218Sphk val++; 491977218Sphk break; 492077218Sphk } 492177218Sphk if (hexstr) { 4922127831Sphk if (!isxdigit((u_char)val[0])) { 492377218Sphk warnx("bad hexadecimal digits"); 492477218Sphk return NULL; 492577218Sphk } 4926127831Sphk if (!isxdigit((u_char)val[1])) { 4927127831Sphk warnx("odd count hexadecimal digits"); 4928127831Sphk return NULL; 4929127831Sphk } 493077218Sphk } 4931127831Sphk if (p >= buf + len) { 493277218Sphk if (hexstr) 493377218Sphk warnx("hexadecimal digits too long"); 493477218Sphk else 4935127831Sphk warnx("string too long"); 493677218Sphk return NULL; 493777218Sphk } 493877218Sphk if (hexstr) { 493977218Sphk#define tohex(x) (isdigit(x) ? (x) - '0' : tolower(x) - 'a' + 10) 494077218Sphk *p++ = (tohex((u_char)val[0]) << 4) | 494177218Sphk tohex((u_char)val[1]); 494277218Sphk#undef tohex 494377218Sphk val += 2; 494477218Sphk } else 494577218Sphk *p++ = *val++; 494677218Sphk } 494777218Sphk len = p - buf; 494877218Sphk /* The string "-" is treated as the empty string. */ 4949165045Ssam if (!hexstr && len == 1 && buf[0] == '-') { 495077218Sphk len = 0; 4951165045Ssam memset(buf, 0, *lenp); 4952165045Ssam } else if (len < *lenp) 495377218Sphk memset(p, 0, *lenp - len); 495477218Sphk *lenp = len; 495577218Sphk return val; 495677218Sphk} 495777218Sphk 495877218Sphkstatic void 495977218Sphkprint_string(const u_int8_t *buf, int len) 496077218Sphk{ 496177218Sphk int i; 496277218Sphk int hasspc; 496377218Sphk 496477218Sphk i = 0; 496577218Sphk hasspc = 0; 496691454Sbrooks for (; i < len; i++) { 496777218Sphk if (!isprint(buf[i]) && buf[i] != '\0') 496877218Sphk break; 496977218Sphk if (isspace(buf[i])) 497077218Sphk hasspc++; 497177218Sphk } 497277218Sphk if (i == len) { 497377218Sphk if (hasspc || len == 0 || buf[0] == '\0') 497477218Sphk printf("\"%.*s\"", len, buf); 497577218Sphk else 497677218Sphk printf("%.*s", len, buf); 497777218Sphk } else { 497877218Sphk printf("0x"); 497977218Sphk for (i = 0; i < len; i++) 498077218Sphk printf("%02x", buf[i]); 498177218Sphk } 498277218Sphk} 498377218Sphk 4984178354Ssam/* 4985178354Ssam * Virtual AP cloning support. 4986178354Ssam */ 4987178354Ssamstatic struct ieee80211_clone_params params = { 4988178354Ssam .icp_opmode = IEEE80211_M_STA, /* default to station mode */ 4989178354Ssam}; 4990178354Ssam 4991178354Ssamstatic void 4992178354Ssamwlan_create(int s, struct ifreq *ifr) 4993178354Ssam{ 4994178354Ssam static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; 4995178354Ssam 4996178354Ssam if (params.icp_parent[0] == '\0') 4997189096Srpaulo errx(1, "must specify a parent device (wlandev) when creating " 4998189096Srpaulo "a wlan device"); 4999178354Ssam if (params.icp_opmode == IEEE80211_M_WDS && 5000178354Ssam memcmp(params.icp_bssid, zerobssid, sizeof(zerobssid)) == 0) 5001178354Ssam errx(1, "no bssid specified for WDS (use wlanbssid)"); 5002178354Ssam ifr->ifr_data = (caddr_t) ¶ms; 5003178354Ssam if (ioctl(s, SIOCIFCREATE2, ifr) < 0) 5004178354Ssam err(1, "SIOCIFCREATE2"); 5005178354Ssam} 5006178354Ssam 5007178354Ssamstatic 5008178354SsamDECL_CMD_FUNC(set80211clone_wlandev, arg, d) 5009178354Ssam{ 5010178354Ssam strlcpy(params.icp_parent, arg, IFNAMSIZ); 5011178354Ssam} 5012178354Ssam 5013178354Ssamstatic 5014178354SsamDECL_CMD_FUNC(set80211clone_wlanbssid, arg, d) 5015178354Ssam{ 5016178354Ssam const struct ether_addr *ea; 5017178354Ssam 5018178354Ssam ea = ether_aton(arg); 5019178354Ssam if (ea == NULL) 5020178354Ssam errx(1, "%s: cannot parse bssid", arg); 5021178354Ssam memcpy(params.icp_bssid, ea->octet, IEEE80211_ADDR_LEN); 5022178354Ssam} 5023178354Ssam 5024178354Ssamstatic 5025178354SsamDECL_CMD_FUNC(set80211clone_wlanaddr, arg, d) 5026178354Ssam{ 5027178354Ssam const struct ether_addr *ea; 5028178354Ssam 5029178354Ssam ea = ether_aton(arg); 5030178354Ssam if (ea == NULL) 5031207320Srpaulo errx(1, "%s: cannot parse address", arg); 5032178354Ssam memcpy(params.icp_macaddr, ea->octet, IEEE80211_ADDR_LEN); 5033178354Ssam params.icp_flags |= IEEE80211_CLONE_MACADDR; 5034178354Ssam} 5035178354Ssam 5036178354Ssamstatic 5037178354SsamDECL_CMD_FUNC(set80211clone_wlanmode, arg, d) 5038178354Ssam{ 5039178354Ssam#define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0) 5040178354Ssam if (iseq(arg, "sta")) 5041178354Ssam params.icp_opmode = IEEE80211_M_STA; 5042178354Ssam else if (iseq(arg, "ahdemo") || iseq(arg, "adhoc-demo")) 5043178354Ssam params.icp_opmode = IEEE80211_M_AHDEMO; 5044178354Ssam else if (iseq(arg, "ibss") || iseq(arg, "adhoc")) 5045178354Ssam params.icp_opmode = IEEE80211_M_IBSS; 5046178354Ssam else if (iseq(arg, "ap") || iseq(arg, "host")) 5047178354Ssam params.icp_opmode = IEEE80211_M_HOSTAP; 5048178354Ssam else if (iseq(arg, "wds")) 5049178354Ssam params.icp_opmode = IEEE80211_M_WDS; 5050178354Ssam else if (iseq(arg, "monitor")) 5051178354Ssam params.icp_opmode = IEEE80211_M_MONITOR; 5052186904Ssam else if (iseq(arg, "tdma")) { 5053186904Ssam params.icp_opmode = IEEE80211_M_AHDEMO; 5054186904Ssam params.icp_flags |= IEEE80211_CLONE_TDMA; 5055195618Srpaulo } else if (iseq(arg, "mesh") || iseq(arg, "mp")) /* mesh point */ 5056195618Srpaulo params.icp_opmode = IEEE80211_M_MBSS; 5057195618Srpaulo else 5058178354Ssam errx(1, "Don't know to create %s for %s", arg, name); 5059178354Ssam#undef iseq 5060178354Ssam} 5061178354Ssam 5062178354Ssamstatic void 5063178354Ssamset80211clone_beacons(const char *val, int d, int s, const struct afswtch *rafp) 5064178354Ssam{ 5065178354Ssam /* NB: inverted sense */ 5066178354Ssam if (d) 5067178354Ssam params.icp_flags &= ~IEEE80211_CLONE_NOBEACONS; 5068178354Ssam else 5069178354Ssam params.icp_flags |= IEEE80211_CLONE_NOBEACONS; 5070178354Ssam} 5071178354Ssam 5072178354Ssamstatic void 5073178354Ssamset80211clone_bssid(const char *val, int d, int s, const struct afswtch *rafp) 5074178354Ssam{ 5075178354Ssam if (d) 5076178354Ssam params.icp_flags |= IEEE80211_CLONE_BSSID; 5077178354Ssam else 5078178354Ssam params.icp_flags &= ~IEEE80211_CLONE_BSSID; 5079178354Ssam} 5080178354Ssam 5081178354Ssamstatic void 5082178354Ssamset80211clone_wdslegacy(const char *val, int d, int s, const struct afswtch *rafp) 5083178354Ssam{ 5084178354Ssam if (d) 5085178354Ssam params.icp_flags |= IEEE80211_CLONE_WDSLEGACY; 5086178354Ssam else 5087178354Ssam params.icp_flags &= ~IEEE80211_CLONE_WDSLEGACY; 5088178354Ssam} 5089178354Ssam 5090138593Ssamstatic struct cmd ieee80211_cmds[] = { 5091138593Ssam DEF_CMD_ARG("ssid", set80211ssid), 5092138593Ssam DEF_CMD_ARG("nwid", set80211ssid), 5093195618Srpaulo DEF_CMD_ARG("meshid", set80211meshid), 5094138593Ssam DEF_CMD_ARG("stationname", set80211stationname), 5095138593Ssam DEF_CMD_ARG("station", set80211stationname), /* BSD/OS */ 5096138593Ssam DEF_CMD_ARG("channel", set80211channel), 5097138593Ssam DEF_CMD_ARG("authmode", set80211authmode), 5098138593Ssam DEF_CMD_ARG("powersavemode", set80211powersavemode), 5099138593Ssam DEF_CMD("powersave", 1, set80211powersave), 5100138593Ssam DEF_CMD("-powersave", 0, set80211powersave), 5101138593Ssam DEF_CMD_ARG("powersavesleep", set80211powersavesleep), 5102138593Ssam DEF_CMD_ARG("wepmode", set80211wepmode), 5103138593Ssam DEF_CMD("wep", 1, set80211wep), 5104138593Ssam DEF_CMD("-wep", 0, set80211wep), 5105139493Ssam DEF_CMD_ARG("deftxkey", set80211weptxkey), 5106138593Ssam DEF_CMD_ARG("weptxkey", set80211weptxkey), 5107138593Ssam DEF_CMD_ARG("wepkey", set80211wepkey), 5108138593Ssam DEF_CMD_ARG("nwkey", set80211nwkey), /* NetBSD */ 5109138593Ssam DEF_CMD("-nwkey", 0, set80211wep), /* NetBSD */ 5110138593Ssam DEF_CMD_ARG("rtsthreshold", set80211rtsthreshold), 5111138593Ssam DEF_CMD_ARG("protmode", set80211protmode), 5112138593Ssam DEF_CMD_ARG("txpower", set80211txpower), 5113138593Ssam DEF_CMD_ARG("roaming", set80211roaming), 5114138593Ssam DEF_CMD("wme", 1, set80211wme), 5115138593Ssam DEF_CMD("-wme", 0, set80211wme), 5116178354Ssam DEF_CMD("wmm", 1, set80211wme), 5117178354Ssam DEF_CMD("-wmm", 0, set80211wme), 5118138593Ssam DEF_CMD("hidessid", 1, set80211hidessid), 5119138593Ssam DEF_CMD("-hidessid", 0, set80211hidessid), 5120138593Ssam DEF_CMD("apbridge", 1, set80211apbridge), 5121138593Ssam DEF_CMD("-apbridge", 0, set80211apbridge), 5122138593Ssam DEF_CMD_ARG("chanlist", set80211chanlist), 5123138593Ssam DEF_CMD_ARG("bssid", set80211bssid), 5124138593Ssam DEF_CMD_ARG("ap", set80211bssid), 5125138593Ssam DEF_CMD("scan", 0, set80211scan), 5126138593Ssam DEF_CMD_ARG("list", set80211list), 5127138593Ssam DEF_CMD_ARG2("cwmin", set80211cwmin), 5128138593Ssam DEF_CMD_ARG2("cwmax", set80211cwmax), 5129138593Ssam DEF_CMD_ARG2("aifs", set80211aifs), 5130138593Ssam DEF_CMD_ARG2("txoplimit", set80211txoplimit), 5131148621Ssam DEF_CMD_ARG("acm", set80211acm), 5132148621Ssam DEF_CMD_ARG("-acm", set80211noacm), 5133148621Ssam DEF_CMD_ARG("ack", set80211ackpolicy), 5134148621Ssam DEF_CMD_ARG("-ack", set80211noackpolicy), 5135138593Ssam DEF_CMD_ARG2("bss:cwmin", set80211bsscwmin), 5136138593Ssam DEF_CMD_ARG2("bss:cwmax", set80211bsscwmax), 5137138593Ssam DEF_CMD_ARG2("bss:aifs", set80211bssaifs), 5138138593Ssam DEF_CMD_ARG2("bss:txoplimit", set80211bsstxoplimit), 5139138593Ssam DEF_CMD_ARG("dtimperiod", set80211dtimperiod), 5140138593Ssam DEF_CMD_ARG("bintval", set80211bintval), 5141138593Ssam DEF_CMD("mac:open", IEEE80211_MACCMD_POLICY_OPEN, set80211maccmd), 5142138593Ssam DEF_CMD("mac:allow", IEEE80211_MACCMD_POLICY_ALLOW, set80211maccmd), 5143138593Ssam DEF_CMD("mac:deny", IEEE80211_MACCMD_POLICY_DENY, set80211maccmd), 5144178354Ssam DEF_CMD("mac:radius", IEEE80211_MACCMD_POLICY_RADIUS, set80211maccmd), 5145138593Ssam DEF_CMD("mac:flush", IEEE80211_MACCMD_FLUSH, set80211maccmd), 5146138593Ssam DEF_CMD("mac:detach", IEEE80211_MACCMD_DETACH, set80211maccmd), 5147138593Ssam DEF_CMD_ARG("mac:add", set80211addmac), 5148138593Ssam DEF_CMD_ARG("mac:del", set80211delmac), 5149138593Ssam DEF_CMD_ARG("mac:kick", set80211kickmac), 5150147795Ssam DEF_CMD("pureg", 1, set80211pureg), 5151147795Ssam DEF_CMD("-pureg", 0, set80211pureg), 5152170531Ssam DEF_CMD("ff", 1, set80211fastframes), 5153170531Ssam DEF_CMD("-ff", 0, set80211fastframes), 5154170531Ssam DEF_CMD("dturbo", 1, set80211dturbo), 5155170531Ssam DEF_CMD("-dturbo", 0, set80211dturbo), 5156170531Ssam DEF_CMD("bgscan", 1, set80211bgscan), 5157170531Ssam DEF_CMD("-bgscan", 0, set80211bgscan), 5158170531Ssam DEF_CMD_ARG("bgscanidle", set80211bgscanidle), 5159170531Ssam DEF_CMD_ARG("bgscanintvl", set80211bgscanintvl), 5160170531Ssam DEF_CMD_ARG("scanvalid", set80211scanvalid), 5161178354Ssam DEF_CMD_ARG("roam:rssi", set80211roamrssi), 5162178354Ssam DEF_CMD_ARG("roam:rate", set80211roamrate), 5163153354Ssam DEF_CMD_ARG("mcastrate", set80211mcastrate), 5164178354Ssam DEF_CMD_ARG("ucastrate", set80211ucastrate), 5165178354Ssam DEF_CMD_ARG("mgtrate", set80211mgtrate), 5166178354Ssam DEF_CMD_ARG("mgmtrate", set80211mgtrate), 5167178354Ssam DEF_CMD_ARG("maxretry", set80211maxretry), 5168148416Ssam DEF_CMD_ARG("fragthreshold", set80211fragthreshold), 5169153422Ssam DEF_CMD("burst", 1, set80211burst), 5170153422Ssam DEF_CMD("-burst", 0, set80211burst), 5171160687Ssam DEF_CMD_ARG("bmiss", set80211bmissthreshold), 5172160687Ssam DEF_CMD_ARG("bmissthreshold", set80211bmissthreshold), 5173173275Ssam DEF_CMD("shortgi", 1, set80211shortgi), 5174173275Ssam DEF_CMD("-shortgi", 0, set80211shortgi), 5175173275Ssam DEF_CMD("ampdurx", 2, set80211ampdu), 5176173275Ssam DEF_CMD("-ampdurx", -2, set80211ampdu), 5177173275Ssam DEF_CMD("ampdutx", 1, set80211ampdu), 5178173275Ssam DEF_CMD("-ampdutx", -1, set80211ampdu), 5179173275Ssam DEF_CMD("ampdu", 3, set80211ampdu), /* NB: tx+rx */ 5180173275Ssam DEF_CMD("-ampdu", -3, set80211ampdu), 5181173275Ssam DEF_CMD_ARG("ampdulimit", set80211ampdulimit), 5182173275Ssam DEF_CMD_ARG("ampdudensity", set80211ampdudensity), 5183173275Ssam DEF_CMD("amsdurx", 2, set80211amsdu), 5184173275Ssam DEF_CMD("-amsdurx", -2, set80211amsdu), 5185173275Ssam DEF_CMD("amsdutx", 1, set80211amsdu), 5186173275Ssam DEF_CMD("-amsdutx", -1, set80211amsdu), 5187173275Ssam DEF_CMD("amsdu", 3, set80211amsdu), /* NB: tx+rx */ 5188173275Ssam DEF_CMD("-amsdu", -3, set80211amsdu), 5189173275Ssam DEF_CMD_ARG("amsdulimit", set80211amsdulimit), 5190173275Ssam DEF_CMD("puren", 1, set80211puren), 5191173275Ssam DEF_CMD("-puren", 0, set80211puren), 5192170531Ssam DEF_CMD("doth", 1, set80211doth), 5193170531Ssam DEF_CMD("-doth", 0, set80211doth), 5194178354Ssam DEF_CMD("dfs", 1, set80211dfs), 5195178354Ssam DEF_CMD("-dfs", 0, set80211dfs), 5196173275Ssam DEF_CMD("htcompat", 1, set80211htcompat), 5197173275Ssam DEF_CMD("-htcompat", 0, set80211htcompat), 5198178354Ssam DEF_CMD("dwds", 1, set80211dwds), 5199178354Ssam DEF_CMD("-dwds", 0, set80211dwds), 5200173275Ssam DEF_CMD("inact", 1, set80211inact), 5201173275Ssam DEF_CMD("-inact", 0, set80211inact), 5202178354Ssam DEF_CMD("tsn", 1, set80211tsn), 5203178354Ssam DEF_CMD("-tsn", 0, set80211tsn), 5204178354Ssam DEF_CMD_ARG("regdomain", set80211regdomain), 5205178354Ssam DEF_CMD_ARG("country", set80211country), 5206178354Ssam DEF_CMD("indoor", 'I', set80211location), 5207178354Ssam DEF_CMD("-indoor", 'O', set80211location), 5208178354Ssam DEF_CMD("outdoor", 'O', set80211location), 5209178354Ssam DEF_CMD("-outdoor", 'I', set80211location), 5210178354Ssam DEF_CMD("anywhere", ' ', set80211location), 5211178354Ssam DEF_CMD("ecm", 1, set80211ecm), 5212178354Ssam DEF_CMD("-ecm", 0, set80211ecm), 5213178354Ssam DEF_CMD("dotd", 1, set80211dotd), 5214178354Ssam DEF_CMD("-dotd", 0, set80211dotd), 5215173275Ssam DEF_CMD_ARG("htprotmode", set80211htprotmode), 5216173275Ssam DEF_CMD("ht20", 1, set80211htconf), 5217173275Ssam DEF_CMD("-ht20", 0, set80211htconf), 5218173275Ssam DEF_CMD("ht40", 3, set80211htconf), /* NB: 20+40 */ 5219173275Ssam DEF_CMD("-ht40", 0, set80211htconf), 5220173275Ssam DEF_CMD("ht", 3, set80211htconf), /* NB: 20+40 */ 5221173275Ssam DEF_CMD("-ht", 0, set80211htconf), 5222183261Ssam DEF_CMD("rifs", 1, set80211rifs), 5223183261Ssam DEF_CMD("-rifs", 0, set80211rifs), 5224183261Ssam DEF_CMD("smps", IEEE80211_HTCAP_SMPS_ENA, set80211smps), 5225183261Ssam DEF_CMD("smpsdyn", IEEE80211_HTCAP_SMPS_DYNAMIC, set80211smps), 5226183261Ssam DEF_CMD("-smps", IEEE80211_HTCAP_SMPS_OFF, set80211smps), 5227178354Ssam /* XXX for testing */ 5228178354Ssam DEF_CMD_ARG("chanswitch", set80211chanswitch), 5229178354Ssam 5230186904Ssam DEF_CMD_ARG("tdmaslot", set80211tdmaslot), 5231186904Ssam DEF_CMD_ARG("tdmaslotcnt", set80211tdmaslotcnt), 5232186904Ssam DEF_CMD_ARG("tdmaslotlen", set80211tdmaslotlen), 5233186904Ssam DEF_CMD_ARG("tdmabintval", set80211tdmabintval), 5234186904Ssam 5235195618Srpaulo DEF_CMD_ARG("meshttl", set80211meshttl), 5236195618Srpaulo DEF_CMD("meshforward", 1, set80211meshforward), 5237195618Srpaulo DEF_CMD("-meshforward", 0, set80211meshforward), 5238195618Srpaulo DEF_CMD("meshpeering", 1, set80211meshpeering), 5239195618Srpaulo DEF_CMD("-meshpeering", 0, set80211meshpeering), 5240195618Srpaulo DEF_CMD_ARG("meshmetric", set80211meshmetric), 5241195618Srpaulo DEF_CMD_ARG("meshpath", set80211meshpath), 5242195618Srpaulo DEF_CMD("meshrt:flush", IEEE80211_MESH_RTCMD_FLUSH, set80211meshrtcmd), 5243195618Srpaulo DEF_CMD_ARG("meshrt:add", set80211addmeshrt), 5244195618Srpaulo DEF_CMD_ARG("meshrt:del", set80211delmeshrt), 5245195618Srpaulo DEF_CMD_ARG("hwmprootmode", set80211hwmprootmode), 5246195618Srpaulo DEF_CMD_ARG("hwmpmaxhops", set80211hwmpmaxhops), 5247195618Srpaulo 5248178354Ssam /* vap cloning support */ 5249178354Ssam DEF_CLONE_CMD_ARG("wlanaddr", set80211clone_wlanaddr), 5250178354Ssam DEF_CLONE_CMD_ARG("wlanbssid", set80211clone_wlanbssid), 5251178354Ssam DEF_CLONE_CMD_ARG("wlandev", set80211clone_wlandev), 5252178354Ssam DEF_CLONE_CMD_ARG("wlanmode", set80211clone_wlanmode), 5253178354Ssam DEF_CLONE_CMD("beacons", 1, set80211clone_beacons), 5254178354Ssam DEF_CLONE_CMD("-beacons", 0, set80211clone_beacons), 5255178354Ssam DEF_CLONE_CMD("bssid", 1, set80211clone_bssid), 5256178354Ssam DEF_CLONE_CMD("-bssid", 0, set80211clone_bssid), 5257178354Ssam DEF_CLONE_CMD("wdslegacy", 1, set80211clone_wdslegacy), 5258178354Ssam DEF_CLONE_CMD("-wdslegacy", 0, set80211clone_wdslegacy), 5259138593Ssam}; 5260138593Ssamstatic struct afswtch af_ieee80211 = { 5261138593Ssam .af_name = "af_ieee80211", 5262138593Ssam .af_af = AF_UNSPEC, 5263139494Ssam .af_other_status = ieee80211_status, 5264138593Ssam}; 5265138593Ssam 5266138593Ssamstatic __constructor void 5267138593Ssamieee80211_ctor(void) 5268138593Ssam{ 5269138593Ssam#define N(a) (sizeof(a) / sizeof(a[0])) 5270138593Ssam int i; 5271138593Ssam 5272138593Ssam for (i = 0; i < N(ieee80211_cmds); i++) 5273138593Ssam cmd_register(&ieee80211_cmds[i]); 5274138593Ssam af_register(&af_ieee80211); 5275189096Srpaulo clone_setdefcallback("wlan", wlan_create); 5276138593Ssam#undef N 5277138593Ssam} 5278