1 /*- 2 * Copyright (c) 2001 Atsushi Onoe 3 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #include <sys/cdefs.h> 28 __FBSDID("$FreeBSD$"); 29 30 /* 31 * IEEE 802.11 ioctl support (FreeBSD-specific) 32 */ 33 34 #include "opt_inet.h" 35 #include "opt_wlan.h" 36 37 #include <sys/endian.h> 38 #include <sys/param.h> 39 #include <sys/kernel.h> 40 #include <sys/malloc.h> 41 #include <sys/priv.h> 42 #include <sys/socket.h> 43 #include <sys/sockio.h> 44 #include <sys/systm.h> 45 46 #include <net/if.h> 47 #include <net/if_var.h> 48 #include <net/if_dl.h> 49 #include <net/if_media.h> 50 #include <net/ethernet.h> 51 52 #ifdef INET 53 #include <netinet/in.h> 54 #include <netinet/if_ether.h> 55 #endif 56 57 #include <net80211/ieee80211_var.h> 58 #include <net80211/ieee80211_ioctl.h> 59 #include <net80211/ieee80211_regdomain.h> 60 #include <net80211/ieee80211_input.h> 61 62 #define IS_UP_AUTO(_vap) \ 63 (IFNET_IS_UP_RUNNING((_vap)->iv_ifp) && \ 64 (_vap)->iv_roaming == IEEE80211_ROAMING_AUTO) 65 66 static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; 67 static struct ieee80211_channel *findchannel(struct ieee80211com *, 68 int ieee, int mode); 69 static int ieee80211_scanreq(struct ieee80211vap *, 70 struct ieee80211_scan_req *); 71 72 static int 73 ieee80211_ioctl_getkey(struct ieee80211vap *vap, struct ieee80211req *ireq) 74 { 75 struct ieee80211com *ic = vap->iv_ic; 76 struct ieee80211_node *ni; 77 struct ieee80211req_key ik; 78 struct ieee80211_key *wk; 79 const struct ieee80211_cipher *cip; 80 u_int kid; 81 int error; 82 83 if (ireq->i_len != sizeof(ik)) 84 return EINVAL; 85 error = copyin(ireq->i_data, &ik, sizeof(ik)); 86 if (error) 87 return error; 88 kid = ik.ik_keyix; 89 if (kid == IEEE80211_KEYIX_NONE) { 90 ni = ieee80211_find_vap_node(&ic->ic_sta, vap, ik.ik_macaddr); 91 if (ni == NULL) 92 return ENOENT; 93 wk = &ni->ni_ucastkey; 94 } else { 95 if (kid >= IEEE80211_WEP_NKID) 96 return EINVAL; 97 wk = &vap->iv_nw_keys[kid]; 98 IEEE80211_ADDR_COPY(&ik.ik_macaddr, vap->iv_bss->ni_macaddr); 99 ni = NULL; 100 } 101 cip = wk->wk_cipher; 102 ik.ik_type = cip->ic_cipher; 103 ik.ik_keylen = wk->wk_keylen; 104 ik.ik_flags = wk->wk_flags & (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV); 105 if (wk->wk_keyix == vap->iv_def_txkey) 106 ik.ik_flags |= IEEE80211_KEY_DEFAULT; 107 if (priv_check(curthread, PRIV_NET80211_GETKEY) == 0) { 108 /* NB: only root can read key data */ 109 ik.ik_keyrsc = wk->wk_keyrsc[IEEE80211_NONQOS_TID]; 110 ik.ik_keytsc = wk->wk_keytsc; 111 memcpy(ik.ik_keydata, wk->wk_key, wk->wk_keylen); 112 if (cip->ic_cipher == IEEE80211_CIPHER_TKIP) { 113 memcpy(ik.ik_keydata+wk->wk_keylen, 114 wk->wk_key + IEEE80211_KEYBUF_SIZE, 115 IEEE80211_MICBUF_SIZE); 116 ik.ik_keylen += IEEE80211_MICBUF_SIZE; 117 } 118 } else { 119 ik.ik_keyrsc = 0; 120 ik.ik_keytsc = 0; 121 memset(ik.ik_keydata, 0, sizeof(ik.ik_keydata)); 122 } 123 if (ni != NULL) 124 ieee80211_free_node(ni); 125 return copyout(&ik, ireq->i_data, sizeof(ik)); 126 } 127 128 static int 129 ieee80211_ioctl_getchanlist(struct ieee80211vap *vap, struct ieee80211req *ireq) 130 { 131 struct ieee80211com *ic = vap->iv_ic; 132 133 if (sizeof(ic->ic_chan_active) < ireq->i_len) 134 ireq->i_len = sizeof(ic->ic_chan_active); 135 return copyout(&ic->ic_chan_active, ireq->i_data, ireq->i_len); 136 } 137 138 static int 139 ieee80211_ioctl_getchaninfo(struct ieee80211vap *vap, struct ieee80211req *ireq) 140 { 141 struct ieee80211com *ic = vap->iv_ic; 142 uint32_t space; 143 144 space = __offsetof(struct ieee80211req_chaninfo, 145 ic_chans[ic->ic_nchans]); 146 if (space > ireq->i_len) 147 space = ireq->i_len; 148 /* XXX assumes compatible layout */ 149 return copyout(&ic->ic_nchans, ireq->i_data, space); 150 } 151 152 static int 153 ieee80211_ioctl_getwpaie(struct ieee80211vap *vap, 154 struct ieee80211req *ireq, int req) 155 { 156 struct ieee80211_node *ni; 157 struct ieee80211req_wpaie2 *wpaie; 158 int error; 159 160 if (ireq->i_len < IEEE80211_ADDR_LEN) 161 return EINVAL; 162 wpaie = IEEE80211_MALLOC(sizeof(*wpaie), M_TEMP, 163 IEEE80211_M_NOWAIT | IEEE80211_M_ZERO); 164 if (wpaie == NULL) 165 return ENOMEM; 166 error = copyin(ireq->i_data, wpaie->wpa_macaddr, IEEE80211_ADDR_LEN); 167 if (error != 0) 168 goto bad; 169 ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, wpaie->wpa_macaddr); 170 if (ni == NULL) { 171 error = ENOENT; 172 goto bad; 173 } 174 if (ni->ni_ies.wpa_ie != NULL) { 175 int ielen = ni->ni_ies.wpa_ie[1] + 2; 176 if (ielen > sizeof(wpaie->wpa_ie)) 177 ielen = sizeof(wpaie->wpa_ie); 178 memcpy(wpaie->wpa_ie, ni->ni_ies.wpa_ie, ielen); 179 } 180 if (req == IEEE80211_IOC_WPAIE2) { 181 if (ni->ni_ies.rsn_ie != NULL) { 182 int ielen = ni->ni_ies.rsn_ie[1] + 2; 183 if (ielen > sizeof(wpaie->rsn_ie)) 184 ielen = sizeof(wpaie->rsn_ie); 185 memcpy(wpaie->rsn_ie, ni->ni_ies.rsn_ie, ielen); 186 } 187 if (ireq->i_len > sizeof(struct ieee80211req_wpaie2)) 188 ireq->i_len = sizeof(struct ieee80211req_wpaie2); 189 } else { 190 /* compatibility op, may overwrite wpa ie */ 191 /* XXX check ic_flags? */ 192 if (ni->ni_ies.rsn_ie != NULL) { 193 int ielen = ni->ni_ies.rsn_ie[1] + 2; 194 if (ielen > sizeof(wpaie->wpa_ie)) 195 ielen = sizeof(wpaie->wpa_ie); 196 memcpy(wpaie->wpa_ie, ni->ni_ies.rsn_ie, ielen); 197 } 198 if (ireq->i_len > sizeof(struct ieee80211req_wpaie)) 199 ireq->i_len = sizeof(struct ieee80211req_wpaie); 200 } 201 ieee80211_free_node(ni); 202 error = copyout(wpaie, ireq->i_data, ireq->i_len); 203 bad: 204 IEEE80211_FREE(wpaie, M_TEMP); 205 return error; 206 } 207 208 static int 209 ieee80211_ioctl_getstastats(struct ieee80211vap *vap, struct ieee80211req *ireq) 210 { 211 struct ieee80211_node *ni; 212 uint8_t macaddr[IEEE80211_ADDR_LEN]; 213 const size_t off = __offsetof(struct ieee80211req_sta_stats, is_stats); 214 int error; 215 216 if (ireq->i_len < off) 217 return EINVAL; 218 error = copyin(ireq->i_data, macaddr, IEEE80211_ADDR_LEN); 219 if (error != 0) 220 return error; 221 ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, macaddr); 222 if (ni == NULL) 223 return ENOENT; 224 if (ireq->i_len > sizeof(struct ieee80211req_sta_stats)) 225 ireq->i_len = sizeof(struct ieee80211req_sta_stats); 226 /* NB: copy out only the statistics */ 227 error = copyout(&ni->ni_stats, (uint8_t *) ireq->i_data + off, 228 ireq->i_len - off); 229 ieee80211_free_node(ni); 230 return error; 231 } 232 233 struct scanreq { 234 struct ieee80211req_scan_result *sr; 235 size_t space; 236 }; 237 238 static size_t 239 scan_space(const struct ieee80211_scan_entry *se, int *ielen) 240 { 241 size_t len; 242 243 *ielen = se->se_ies.len; 244 /* 245 * NB: ie's can be no more than 255 bytes and the max 802.11 246 * packet is <3Kbytes so we are sure this doesn't overflow 247 * 16-bits; if this is a concern we can drop the ie's. 248 */ 249 len = sizeof(struct ieee80211req_scan_result) + se->se_ssid[1] + 250 se->se_meshid[1] + *ielen; 251 return roundup(len, sizeof(uint32_t)); 252 } 253 254 static void 255 get_scan_space(void *arg, const struct ieee80211_scan_entry *se) 256 { 257 struct scanreq *req = arg; 258 int ielen; 259 260 req->space += scan_space(se, &ielen); 261 } 262 263 static void 264 get_scan_result(void *arg, const struct ieee80211_scan_entry *se) 265 { 266 struct scanreq *req = arg; 267 struct ieee80211req_scan_result *sr; 268 int ielen, len, nr, nxr; 269 uint8_t *cp; 270 271 len = scan_space(se, &ielen); 272 if (len > req->space) 273 return; 274 275 sr = req->sr; 276 KASSERT(len <= 65535 && ielen <= 65535, 277 ("len %u ssid %u ie %u", len, se->se_ssid[1], ielen)); 278 sr->isr_len = len; 279 sr->isr_ie_off = sizeof(struct ieee80211req_scan_result); 280 sr->isr_ie_len = ielen; 281 sr->isr_freq = se->se_chan->ic_freq; 282 sr->isr_flags = se->se_chan->ic_flags; 283 sr->isr_rssi = se->se_rssi; 284 sr->isr_noise = se->se_noise; 285 sr->isr_intval = se->se_intval; 286 sr->isr_capinfo = se->se_capinfo; 287 sr->isr_erp = se->se_erp; 288 IEEE80211_ADDR_COPY(sr->isr_bssid, se->se_bssid); 289 nr = min(se->se_rates[1], IEEE80211_RATE_MAXSIZE); 290 memcpy(sr->isr_rates, se->se_rates+2, nr); 291 nxr = min(se->se_xrates[1], IEEE80211_RATE_MAXSIZE - nr); 292 memcpy(sr->isr_rates+nr, se->se_xrates+2, nxr); 293 sr->isr_nrates = nr + nxr; 294 295 /* copy SSID */ 296 sr->isr_ssid_len = se->se_ssid[1]; 297 cp = ((uint8_t *)sr) + sr->isr_ie_off; 298 memcpy(cp, se->se_ssid+2, sr->isr_ssid_len); 299 300 /* copy mesh id */ 301 cp += sr->isr_ssid_len; 302 sr->isr_meshid_len = se->se_meshid[1]; 303 memcpy(cp, se->se_meshid+2, sr->isr_meshid_len); 304 cp += sr->isr_meshid_len; 305 306 if (ielen) 307 memcpy(cp, se->se_ies.data, ielen); 308 309 req->space -= len; 310 req->sr = (struct ieee80211req_scan_result *)(((uint8_t *)sr) + len); 311 } 312 313 static int 314 ieee80211_ioctl_getscanresults(struct ieee80211vap *vap, 315 struct ieee80211req *ireq) 316 { 317 struct scanreq req; 318 int error; 319 320 if (ireq->i_len < sizeof(struct scanreq)) 321 return EFAULT; 322 323 error = 0; 324 req.space = 0; 325 ieee80211_scan_iterate(vap, get_scan_space, &req); 326 if (req.space > ireq->i_len) 327 req.space = ireq->i_len; 328 if (req.space > 0) { 329 uint32_t space; 330 void *p; 331 332 space = req.space; 333 /* XXX M_WAITOK after driver lock released */ 334 p = IEEE80211_MALLOC(space, M_TEMP, 335 IEEE80211_M_NOWAIT | IEEE80211_M_ZERO); 336 if (p == NULL) 337 return ENOMEM; 338 req.sr = p; 339 ieee80211_scan_iterate(vap, get_scan_result, &req); 340 ireq->i_len = space - req.space; 341 error = copyout(p, ireq->i_data, ireq->i_len); 342 IEEE80211_FREE(p, M_TEMP); 343 } else 344 ireq->i_len = 0; 345 346 return error; 347 } 348 349 struct stainforeq { 350 struct ieee80211req_sta_info *si; 351 size_t space; 352 }; 353 354 static size_t 355 sta_space(const struct ieee80211_node *ni, size_t *ielen) 356 { 357 *ielen = ni->ni_ies.len; 358 return roundup(sizeof(struct ieee80211req_sta_info) + *ielen, 359 sizeof(uint32_t)); 360 } 361 362 static void 363 get_sta_space(void *arg, struct ieee80211_node *ni) 364 { 365 struct stainforeq *req = arg; 366 size_t ielen; 367 368 if (ni->ni_vap->iv_opmode == IEEE80211_M_HOSTAP && 369 ni->ni_associd == 0) /* only associated stations */ 370 return; 371 req->space += sta_space(ni, &ielen); 372 } 373 374 static void 375 get_sta_info(void *arg, struct ieee80211_node *ni) 376 { 377 struct stainforeq *req = arg; 378 struct ieee80211vap *vap = ni->ni_vap; 379 struct ieee80211req_sta_info *si; 380 size_t ielen, len; 381 uint8_t *cp; 382 383 if (vap->iv_opmode == IEEE80211_M_HOSTAP && 384 ni->ni_associd == 0) /* only associated stations */ 385 return; 386 if (ni->ni_chan == IEEE80211_CHAN_ANYC) /* XXX bogus entry */ 387 return; 388 len = sta_space(ni, &ielen); 389 if (len > req->space) 390 return; 391 si = req->si; 392 si->isi_len = len; 393 si->isi_ie_off = sizeof(struct ieee80211req_sta_info); 394 si->isi_ie_len = ielen; 395 si->isi_freq = ni->ni_chan->ic_freq; 396 si->isi_flags = ni->ni_chan->ic_flags; 397 si->isi_state = ni->ni_flags; 398 si->isi_authmode = ni->ni_authmode; 399 vap->iv_ic->ic_node_getsignal(ni, &si->isi_rssi, &si->isi_noise); 400 vap->iv_ic->ic_node_getmimoinfo(ni, &si->isi_mimo); 401 si->isi_capinfo = ni->ni_capinfo; 402 si->isi_erp = ni->ni_erp; 403 IEEE80211_ADDR_COPY(si->isi_macaddr, ni->ni_macaddr); 404 si->isi_nrates = ni->ni_rates.rs_nrates; 405 if (si->isi_nrates > 15) 406 si->isi_nrates = 15; 407 memcpy(si->isi_rates, ni->ni_rates.rs_rates, si->isi_nrates); 408 si->isi_txrate = ni->ni_txrate; 409 if (si->isi_txrate & IEEE80211_RATE_MCS) { 410 const struct ieee80211_mcs_rates *mcs = 411 &ieee80211_htrates[ni->ni_txrate &~ IEEE80211_RATE_MCS]; 412 if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) { 413 if (ni->ni_flags & IEEE80211_NODE_SGI40) 414 si->isi_txmbps = mcs->ht40_rate_800ns; 415 else 416 si->isi_txmbps = mcs->ht40_rate_400ns; 417 } else { 418 if (ni->ni_flags & IEEE80211_NODE_SGI20) 419 si->isi_txmbps = mcs->ht20_rate_800ns; 420 else 421 si->isi_txmbps = mcs->ht20_rate_400ns; 422 } 423 } else 424 si->isi_txmbps = si->isi_txrate; 425 si->isi_associd = ni->ni_associd; 426 si->isi_txpower = ni->ni_txpower; 427 si->isi_vlan = ni->ni_vlan; 428 if (ni->ni_flags & IEEE80211_NODE_QOS) { 429 memcpy(si->isi_txseqs, ni->ni_txseqs, sizeof(ni->ni_txseqs)); 430 memcpy(si->isi_rxseqs, ni->ni_rxseqs, sizeof(ni->ni_rxseqs)); 431 } else { 432 si->isi_txseqs[0] = ni->ni_txseqs[IEEE80211_NONQOS_TID]; 433 si->isi_rxseqs[0] = ni->ni_rxseqs[IEEE80211_NONQOS_TID]; 434 } 435 /* NB: leave all cases in case we relax ni_associd == 0 check */ 436 if (ieee80211_node_is_authorized(ni)) 437 si->isi_inact = vap->iv_inact_run; 438 else if (ni->ni_associd != 0 || 439 (vap->iv_opmode == IEEE80211_M_WDS && 440 (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY))) 441 si->isi_inact = vap->iv_inact_auth; 442 else 443 si->isi_inact = vap->iv_inact_init; 444 si->isi_inact = (si->isi_inact - ni->ni_inact) * IEEE80211_INACT_WAIT; 445 si->isi_localid = ni->ni_mllid; 446 si->isi_peerid = ni->ni_mlpid; 447 si->isi_peerstate = ni->ni_mlstate; 448 449 if (ielen) { 450 cp = ((uint8_t *)si) + si->isi_ie_off; 451 memcpy(cp, ni->ni_ies.data, ielen); 452 } 453 454 req->si = (struct ieee80211req_sta_info *)(((uint8_t *)si) + len); 455 req->space -= len; 456 } 457 458 static int 459 getstainfo_common(struct ieee80211vap *vap, struct ieee80211req *ireq, 460 struct ieee80211_node *ni, size_t off) 461 { 462 struct ieee80211com *ic = vap->iv_ic; 463 struct stainforeq req; 464 size_t space; 465 void *p; 466 int error; 467 468 error = 0; 469 req.space = 0; 470 if (ni == NULL) { 471 ieee80211_iterate_nodes_vap(&ic->ic_sta, vap, get_sta_space, 472 &req); 473 } else 474 get_sta_space(&req, ni); 475 if (req.space > ireq->i_len) 476 req.space = ireq->i_len; 477 if (req.space > 0) { 478 space = req.space; 479 /* XXX M_WAITOK after driver lock released */ 480 p = IEEE80211_MALLOC(space, M_TEMP, 481 IEEE80211_M_NOWAIT | IEEE80211_M_ZERO); 482 if (p == NULL) { 483 error = ENOMEM; 484 goto bad; 485 } 486 req.si = p; 487 if (ni == NULL) { 488 ieee80211_iterate_nodes_vap(&ic->ic_sta, vap, 489 get_sta_info, &req); 490 } else 491 get_sta_info(&req, ni); 492 ireq->i_len = space - req.space; 493 error = copyout(p, (uint8_t *) ireq->i_data+off, ireq->i_len); 494 IEEE80211_FREE(p, M_TEMP); 495 } else 496 ireq->i_len = 0; 497 bad: 498 if (ni != NULL) 499 ieee80211_free_node(ni); 500 return error; 501 } 502 503 static int 504 ieee80211_ioctl_getstainfo(struct ieee80211vap *vap, struct ieee80211req *ireq) 505 { 506 uint8_t macaddr[IEEE80211_ADDR_LEN]; 507 const size_t off = __offsetof(struct ieee80211req_sta_req, info); 508 struct ieee80211_node *ni; 509 int error; 510 511 if (ireq->i_len < sizeof(struct ieee80211req_sta_req)) 512 return EFAULT; 513 error = copyin(ireq->i_data, macaddr, IEEE80211_ADDR_LEN); 514 if (error != 0) 515 return error; 516 if (IEEE80211_ADDR_EQ(macaddr, vap->iv_ifp->if_broadcastaddr)) { 517 ni = NULL; 518 } else { 519 ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, macaddr); 520 if (ni == NULL) 521 return ENOENT; 522 } 523 return getstainfo_common(vap, ireq, ni, off); 524 } 525 526 static int 527 ieee80211_ioctl_getstatxpow(struct ieee80211vap *vap, struct ieee80211req *ireq) 528 { 529 struct ieee80211_node *ni; 530 struct ieee80211req_sta_txpow txpow; 531 int error; 532 533 if (ireq->i_len != sizeof(txpow)) 534 return EINVAL; 535 error = copyin(ireq->i_data, &txpow, sizeof(txpow)); 536 if (error != 0) 537 return error; 538 ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, txpow.it_macaddr); 539 if (ni == NULL) 540 return ENOENT; 541 txpow.it_txpow = ni->ni_txpower; 542 error = copyout(&txpow, ireq->i_data, sizeof(txpow)); 543 ieee80211_free_node(ni); 544 return error; 545 } 546 547 static int 548 ieee80211_ioctl_getwmeparam(struct ieee80211vap *vap, struct ieee80211req *ireq) 549 { 550 struct ieee80211com *ic = vap->iv_ic; 551 struct ieee80211_wme_state *wme = &ic->ic_wme; 552 struct wmeParams *wmep; 553 int ac; 554 555 if ((ic->ic_caps & IEEE80211_C_WME) == 0) 556 return EINVAL; 557 558 ac = (ireq->i_len & IEEE80211_WMEPARAM_VAL); 559 if (ac >= WME_NUM_AC) 560 ac = WME_AC_BE; 561 if (ireq->i_len & IEEE80211_WMEPARAM_BSS) 562 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac]; 563 else 564 wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac]; 565 switch (ireq->i_type) { 566 case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */ 567 ireq->i_val = wmep->wmep_logcwmin; 568 break; 569 case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */ 570 ireq->i_val = wmep->wmep_logcwmax; 571 break; 572 case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */ 573 ireq->i_val = wmep->wmep_aifsn; 574 break; 575 case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */ 576 ireq->i_val = wmep->wmep_txopLimit; 577 break; 578 case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */ 579 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac]; 580 ireq->i_val = wmep->wmep_acm; 581 break; 582 case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only)*/ 583 wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac]; 584 ireq->i_val = !wmep->wmep_noackPolicy; 585 break; 586 } 587 return 0; 588 } 589 590 static int 591 ieee80211_ioctl_getmaccmd(struct ieee80211vap *vap, struct ieee80211req *ireq) 592 { 593 const struct ieee80211_aclator *acl = vap->iv_acl; 594 595 return (acl == NULL ? EINVAL : acl->iac_getioctl(vap, ireq)); 596 } 597 598 static int 599 ieee80211_ioctl_getcurchan(struct ieee80211vap *vap, struct ieee80211req *ireq) 600 { 601 struct ieee80211com *ic = vap->iv_ic; 602 struct ieee80211_channel *c; 603 604 if (ireq->i_len != sizeof(struct ieee80211_channel)) 605 return EINVAL; 606 /* 607 * vap's may have different operating channels when HT is 608 * in use. When in RUN state report the vap-specific channel. 609 * Otherwise return curchan. 610 */ 611 if (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP) 612 c = vap->iv_bss->ni_chan; 613 else 614 c = ic->ic_curchan; 615 return copyout(c, ireq->i_data, sizeof(*c)); 616 } 617 618 static int 619 getappie(const struct ieee80211_appie *aie, struct ieee80211req *ireq) 620 { 621 if (aie == NULL) 622 return EINVAL; 623 /* NB: truncate, caller can check length */ 624 if (ireq->i_len > aie->ie_len) 625 ireq->i_len = aie->ie_len; 626 return copyout(aie->ie_data, ireq->i_data, ireq->i_len); 627 } 628 629 static int 630 ieee80211_ioctl_getappie(struct ieee80211vap *vap, struct ieee80211req *ireq) 631 { 632 uint8_t fc0; 633 634 fc0 = ireq->i_val & 0xff; 635 if ((fc0 & IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_MGT) 636 return EINVAL; 637 /* NB: could check iv_opmode and reject but hardly worth the effort */ 638 switch (fc0 & IEEE80211_FC0_SUBTYPE_MASK) { 639 case IEEE80211_FC0_SUBTYPE_BEACON: 640 return getappie(vap->iv_appie_beacon, ireq); 641 case IEEE80211_FC0_SUBTYPE_PROBE_RESP: 642 return getappie(vap->iv_appie_proberesp, ireq); 643 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP: 644 return getappie(vap->iv_appie_assocresp, ireq); 645 case IEEE80211_FC0_SUBTYPE_PROBE_REQ: 646 return getappie(vap->iv_appie_probereq, ireq); 647 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ: 648 return getappie(vap->iv_appie_assocreq, ireq); 649 case IEEE80211_FC0_SUBTYPE_BEACON|IEEE80211_FC0_SUBTYPE_PROBE_RESP: 650 return getappie(vap->iv_appie_wpa, ireq); 651 } 652 return EINVAL; 653 } 654 655 static int 656 ieee80211_ioctl_getregdomain(struct ieee80211vap *vap, 657 const struct ieee80211req *ireq) 658 { 659 struct ieee80211com *ic = vap->iv_ic; 660 661 if (ireq->i_len != sizeof(ic->ic_regdomain)) 662 return EINVAL; 663 return copyout(&ic->ic_regdomain, ireq->i_data, 664 sizeof(ic->ic_regdomain)); 665 } 666 667 static int 668 ieee80211_ioctl_getroam(struct ieee80211vap *vap, 669 const struct ieee80211req *ireq) 670 { 671 size_t len = ireq->i_len; 672 /* NB: accept short requests for backwards compat */ 673 if (len > sizeof(vap->iv_roamparms)) 674 len = sizeof(vap->iv_roamparms); 675 return copyout(vap->iv_roamparms, ireq->i_data, len); 676 } 677 678 static int 679 ieee80211_ioctl_gettxparams(struct ieee80211vap *vap, 680 const struct ieee80211req *ireq) 681 { 682 size_t len = ireq->i_len; 683 /* NB: accept short requests for backwards compat */ 684 if (len > sizeof(vap->iv_txparms)) 685 len = sizeof(vap->iv_txparms); 686 return copyout(vap->iv_txparms, ireq->i_data, len); 687 } 688 689 static int 690 ieee80211_ioctl_getdevcaps(struct ieee80211com *ic, 691 const struct ieee80211req *ireq) 692 { 693 struct ieee80211_devcaps_req *dc; 694 struct ieee80211req_chaninfo *ci; 695 int maxchans, error; 696 697 maxchans = 1 + ((ireq->i_len - sizeof(struct ieee80211_devcaps_req)) / 698 sizeof(struct ieee80211_channel)); 699 /* NB: require 1 so we know ic_nchans is accessible */ 700 if (maxchans < 1) 701 return EINVAL; 702 /* constrain max request size, 2K channels is ~24Kbytes */ 703 if (maxchans > 2048) 704 maxchans = 2048; 705 dc = (struct ieee80211_devcaps_req *) 706 IEEE80211_MALLOC(IEEE80211_DEVCAPS_SIZE(maxchans), M_TEMP, 707 IEEE80211_M_NOWAIT | IEEE80211_M_ZERO); 708 if (dc == NULL) 709 return ENOMEM; 710 dc->dc_drivercaps = ic->ic_caps; 711 dc->dc_cryptocaps = ic->ic_cryptocaps; 712 dc->dc_htcaps = ic->ic_htcaps; 713 dc->dc_vhtcaps = ic->ic_vhtcaps; 714 ci = &dc->dc_chaninfo; 715 ic->ic_getradiocaps(ic, maxchans, &ci->ic_nchans, ci->ic_chans); 716 KASSERT(ci->ic_nchans <= maxchans, 717 ("nchans %d maxchans %d", ci->ic_nchans, maxchans)); 718 ieee80211_sort_channels(ci->ic_chans, ci->ic_nchans); 719 error = copyout(dc, ireq->i_data, IEEE80211_DEVCAPS_SPACE(dc)); 720 IEEE80211_FREE(dc, M_TEMP); 721 return error; 722 } 723 724 static int 725 ieee80211_ioctl_getstavlan(struct ieee80211vap *vap, struct ieee80211req *ireq) 726 { 727 struct ieee80211_node *ni; 728 struct ieee80211req_sta_vlan vlan; 729 int error; 730 731 if (ireq->i_len != sizeof(vlan)) 732 return EINVAL; 733 error = copyin(ireq->i_data, &vlan, sizeof(vlan)); 734 if (error != 0) 735 return error; 736 if (!IEEE80211_ADDR_EQ(vlan.sv_macaddr, zerobssid)) { 737 ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, 738 vlan.sv_macaddr); 739 if (ni == NULL) 740 return ENOENT; 741 } else 742 ni = ieee80211_ref_node(vap->iv_bss); 743 vlan.sv_vlan = ni->ni_vlan; 744 error = copyout(&vlan, ireq->i_data, sizeof(vlan)); 745 ieee80211_free_node(ni); 746 return error; 747 } 748 749 /* 750 * Dummy ioctl get handler so the linker set is defined. 751 */ 752 static int 753 dummy_ioctl_get(struct ieee80211vap *vap, struct ieee80211req *ireq) 754 { 755 return ENOSYS; 756 } 757 IEEE80211_IOCTL_GET(dummy, dummy_ioctl_get); 758 759 static int 760 ieee80211_ioctl_getdefault(struct ieee80211vap *vap, struct ieee80211req *ireq) 761 { 762 ieee80211_ioctl_getfunc * const *get; 763 int error; 764 765 SET_FOREACH(get, ieee80211_ioctl_getset) { 766 error = (*get)(vap, ireq); 767 if (error != ENOSYS) 768 return error; 769 } 770 return EINVAL; 771 } 772 773 static int 774 ieee80211_ioctl_get80211(struct ieee80211vap *vap, u_long cmd, 775 struct ieee80211req *ireq) 776 { 777 #define MS(_v, _f) (((_v) & _f) >> _f##_S) 778 struct ieee80211com *ic = vap->iv_ic; 779 u_int kid, len; 780 uint8_t tmpkey[IEEE80211_KEYBUF_SIZE]; 781 char tmpssid[IEEE80211_NWID_LEN]; 782 int error = 0; 783 784 switch (ireq->i_type) { 785 case IEEE80211_IOC_SSID: 786 switch (vap->iv_state) { 787 case IEEE80211_S_INIT: 788 case IEEE80211_S_SCAN: 789 ireq->i_len = vap->iv_des_ssid[0].len; 790 memcpy(tmpssid, vap->iv_des_ssid[0].ssid, ireq->i_len); 791 break; 792 default: 793 ireq->i_len = vap->iv_bss->ni_esslen; 794 memcpy(tmpssid, vap->iv_bss->ni_essid, ireq->i_len); 795 break; 796 } 797 error = copyout(tmpssid, ireq->i_data, ireq->i_len); 798 break; 799 case IEEE80211_IOC_NUMSSIDS: 800 ireq->i_val = 1; 801 break; 802 case IEEE80211_IOC_WEP: 803 if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) 804 ireq->i_val = IEEE80211_WEP_OFF; 805 else if (vap->iv_flags & IEEE80211_F_DROPUNENC) 806 ireq->i_val = IEEE80211_WEP_ON; 807 else 808 ireq->i_val = IEEE80211_WEP_MIXED; 809 break; 810 case IEEE80211_IOC_WEPKEY: 811 kid = (u_int) ireq->i_val; 812 if (kid >= IEEE80211_WEP_NKID) 813 return EINVAL; 814 len = (u_int) vap->iv_nw_keys[kid].wk_keylen; 815 /* NB: only root can read WEP keys */ 816 if (priv_check(curthread, PRIV_NET80211_GETKEY) == 0) { 817 bcopy(vap->iv_nw_keys[kid].wk_key, tmpkey, len); 818 } else { 819 bzero(tmpkey, len); 820 } 821 ireq->i_len = len; 822 error = copyout(tmpkey, ireq->i_data, len); 823 break; 824 case IEEE80211_IOC_NUMWEPKEYS: 825 ireq->i_val = IEEE80211_WEP_NKID; 826 break; 827 case IEEE80211_IOC_WEPTXKEY: 828 ireq->i_val = vap->iv_def_txkey; 829 break; 830 case IEEE80211_IOC_AUTHMODE: 831 if (vap->iv_flags & IEEE80211_F_WPA) 832 ireq->i_val = IEEE80211_AUTH_WPA; 833 else 834 ireq->i_val = vap->iv_bss->ni_authmode; 835 break; 836 case IEEE80211_IOC_CHANNEL: 837 ireq->i_val = ieee80211_chan2ieee(ic, ic->ic_curchan); 838 break; 839 case IEEE80211_IOC_POWERSAVE: 840 if (vap->iv_flags & IEEE80211_F_PMGTON) 841 ireq->i_val = IEEE80211_POWERSAVE_ON; 842 else 843 ireq->i_val = IEEE80211_POWERSAVE_OFF; 844 break; 845 case IEEE80211_IOC_POWERSAVESLEEP: 846 ireq->i_val = ic->ic_lintval; 847 break; 848 case IEEE80211_IOC_RTSTHRESHOLD: 849 ireq->i_val = vap->iv_rtsthreshold; 850 break; 851 case IEEE80211_IOC_PROTMODE: 852 ireq->i_val = ic->ic_protmode; 853 break; 854 case IEEE80211_IOC_TXPOWER: 855 /* 856 * Tx power limit is the min of max regulatory 857 * power, any user-set limit, and the max the 858 * radio can do. 859 * 860 * TODO: methodize this 861 */ 862 ireq->i_val = 2*ic->ic_curchan->ic_maxregpower; 863 if (ireq->i_val > ic->ic_txpowlimit) 864 ireq->i_val = ic->ic_txpowlimit; 865 if (ireq->i_val > ic->ic_curchan->ic_maxpower) 866 ireq->i_val = ic->ic_curchan->ic_maxpower; 867 break; 868 case IEEE80211_IOC_WPA: 869 switch (vap->iv_flags & IEEE80211_F_WPA) { 870 case IEEE80211_F_WPA1: 871 ireq->i_val = 1; 872 break; 873 case IEEE80211_F_WPA2: 874 ireq->i_val = 2; 875 break; 876 case IEEE80211_F_WPA1 | IEEE80211_F_WPA2: 877 ireq->i_val = 3; 878 break; 879 default: 880 ireq->i_val = 0; 881 break; 882 } 883 break; 884 case IEEE80211_IOC_CHANLIST: 885 error = ieee80211_ioctl_getchanlist(vap, ireq); 886 break; 887 case IEEE80211_IOC_ROAMING: 888 ireq->i_val = vap->iv_roaming; 889 break; 890 case IEEE80211_IOC_PRIVACY: 891 ireq->i_val = (vap->iv_flags & IEEE80211_F_PRIVACY) != 0; 892 break; 893 case IEEE80211_IOC_DROPUNENCRYPTED: 894 ireq->i_val = (vap->iv_flags & IEEE80211_F_DROPUNENC) != 0; 895 break; 896 case IEEE80211_IOC_COUNTERMEASURES: 897 ireq->i_val = (vap->iv_flags & IEEE80211_F_COUNTERM) != 0; 898 break; 899 case IEEE80211_IOC_WME: 900 ireq->i_val = (vap->iv_flags & IEEE80211_F_WME) != 0; 901 break; 902 case IEEE80211_IOC_HIDESSID: 903 ireq->i_val = (vap->iv_flags & IEEE80211_F_HIDESSID) != 0; 904 break; 905 case IEEE80211_IOC_APBRIDGE: 906 ireq->i_val = (vap->iv_flags & IEEE80211_F_NOBRIDGE) == 0; 907 break; 908 case IEEE80211_IOC_WPAKEY: 909 error = ieee80211_ioctl_getkey(vap, ireq); 910 break; 911 case IEEE80211_IOC_CHANINFO: 912 error = ieee80211_ioctl_getchaninfo(vap, ireq); 913 break; 914 case IEEE80211_IOC_BSSID: 915 if (ireq->i_len != IEEE80211_ADDR_LEN) 916 return EINVAL; 917 if (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP) { 918 error = copyout(vap->iv_opmode == IEEE80211_M_WDS ? 919 vap->iv_bss->ni_macaddr : vap->iv_bss->ni_bssid, 920 ireq->i_data, ireq->i_len); 921 } else 922 error = copyout(vap->iv_des_bssid, ireq->i_data, 923 ireq->i_len); 924 break; 925 case IEEE80211_IOC_WPAIE: 926 case IEEE80211_IOC_WPAIE2: 927 error = ieee80211_ioctl_getwpaie(vap, ireq, ireq->i_type); 928 break; 929 case IEEE80211_IOC_SCAN_RESULTS: 930 error = ieee80211_ioctl_getscanresults(vap, ireq); 931 break; 932 case IEEE80211_IOC_STA_STATS: 933 error = ieee80211_ioctl_getstastats(vap, ireq); 934 break; 935 case IEEE80211_IOC_TXPOWMAX: 936 ireq->i_val = vap->iv_bss->ni_txpower; 937 break; 938 case IEEE80211_IOC_STA_TXPOW: 939 error = ieee80211_ioctl_getstatxpow(vap, ireq); 940 break; 941 case IEEE80211_IOC_STA_INFO: 942 error = ieee80211_ioctl_getstainfo(vap, ireq); 943 break; 944 case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */ 945 case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */ 946 case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */ 947 case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */ 948 case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */ 949 case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only) */ 950 error = ieee80211_ioctl_getwmeparam(vap, ireq); 951 break; 952 case IEEE80211_IOC_DTIM_PERIOD: 953 ireq->i_val = vap->iv_dtim_period; 954 break; 955 case IEEE80211_IOC_BEACON_INTERVAL: 956 /* NB: get from ic_bss for station mode */ 957 ireq->i_val = vap->iv_bss->ni_intval; 958 break; 959 case IEEE80211_IOC_PUREG: 960 ireq->i_val = (vap->iv_flags & IEEE80211_F_PUREG) != 0; 961 break; 962 case IEEE80211_IOC_QUIET: 963 ireq->i_val = vap->iv_quiet; 964 break; 965 case IEEE80211_IOC_QUIET_COUNT: 966 ireq->i_val = vap->iv_quiet_count; 967 break; 968 case IEEE80211_IOC_QUIET_PERIOD: 969 ireq->i_val = vap->iv_quiet_period; 970 break; 971 case IEEE80211_IOC_QUIET_DUR: 972 ireq->i_val = vap->iv_quiet_duration; 973 break; 974 case IEEE80211_IOC_QUIET_OFFSET: 975 ireq->i_val = vap->iv_quiet_offset; 976 break; 977 case IEEE80211_IOC_BGSCAN: 978 ireq->i_val = (vap->iv_flags & IEEE80211_F_BGSCAN) != 0; 979 break; 980 case IEEE80211_IOC_BGSCAN_IDLE: 981 ireq->i_val = vap->iv_bgscanidle*hz/1000; /* ms */ 982 break; 983 case IEEE80211_IOC_BGSCAN_INTERVAL: 984 ireq->i_val = vap->iv_bgscanintvl/hz; /* seconds */ 985 break; 986 case IEEE80211_IOC_SCANVALID: 987 ireq->i_val = vap->iv_scanvalid/hz; /* seconds */ 988 break; 989 case IEEE80211_IOC_FRAGTHRESHOLD: 990 ireq->i_val = vap->iv_fragthreshold; 991 break; 992 case IEEE80211_IOC_MACCMD: 993 error = ieee80211_ioctl_getmaccmd(vap, ireq); 994 break; 995 case IEEE80211_IOC_BURST: 996 ireq->i_val = (vap->iv_flags & IEEE80211_F_BURST) != 0; 997 break; 998 case IEEE80211_IOC_BMISSTHRESHOLD: 999 ireq->i_val = vap->iv_bmissthreshold; 1000 break; 1001 case IEEE80211_IOC_CURCHAN: 1002 error = ieee80211_ioctl_getcurchan(vap, ireq); 1003 break; 1004 case IEEE80211_IOC_SHORTGI: 1005 ireq->i_val = 0; 1006 if (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI20) 1007 ireq->i_val |= IEEE80211_HTCAP_SHORTGI20; 1008 if (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI40) 1009 ireq->i_val |= IEEE80211_HTCAP_SHORTGI40; 1010 break; 1011 case IEEE80211_IOC_AMPDU: 1012 ireq->i_val = 0; 1013 if (vap->iv_flags_ht & IEEE80211_FHT_AMPDU_TX) 1014 ireq->i_val |= 1; 1015 if (vap->iv_flags_ht & IEEE80211_FHT_AMPDU_RX) 1016 ireq->i_val |= 2; 1017 break; 1018 case IEEE80211_IOC_AMPDU_LIMIT: 1019 /* XXX TODO: make this a per-node thing; and leave this as global */ 1020 if (vap->iv_opmode == IEEE80211_M_HOSTAP) 1021 ireq->i_val = vap->iv_ampdu_rxmax; 1022 else if (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP) 1023 /* 1024 * XXX TODO: this isn't completely correct, as we've 1025 * negotiated the higher of the two. 1026 */ 1027 ireq->i_val = MS(vap->iv_bss->ni_htparam, 1028 IEEE80211_HTCAP_MAXRXAMPDU); 1029 else 1030 ireq->i_val = vap->iv_ampdu_limit; 1031 break; 1032 case IEEE80211_IOC_AMPDU_DENSITY: 1033 /* XXX TODO: make this a per-node thing; and leave this as global */ 1034 if (vap->iv_opmode == IEEE80211_M_STA && 1035 (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP)) 1036 /* 1037 * XXX TODO: this isn't completely correct, as we've 1038 * negotiated the higher of the two. 1039 */ 1040 ireq->i_val = MS(vap->iv_bss->ni_htparam, 1041 IEEE80211_HTCAP_MPDUDENSITY); 1042 else 1043 ireq->i_val = vap->iv_ampdu_density; 1044 break; 1045 case IEEE80211_IOC_AMSDU: 1046 ireq->i_val = 0; 1047 if (vap->iv_flags_ht & IEEE80211_FHT_AMSDU_TX) 1048 ireq->i_val |= 1; 1049 if (vap->iv_flags_ht & IEEE80211_FHT_AMSDU_RX) 1050 ireq->i_val |= 2; 1051 break; 1052 case IEEE80211_IOC_AMSDU_LIMIT: 1053 ireq->i_val = vap->iv_amsdu_limit; /* XXX truncation? */ 1054 break; 1055 case IEEE80211_IOC_PUREN: 1056 ireq->i_val = (vap->iv_flags_ht & IEEE80211_FHT_PUREN) != 0; 1057 break; 1058 case IEEE80211_IOC_DOTH: 1059 ireq->i_val = (vap->iv_flags & IEEE80211_F_DOTH) != 0; 1060 break; 1061 case IEEE80211_IOC_REGDOMAIN: 1062 error = ieee80211_ioctl_getregdomain(vap, ireq); 1063 break; 1064 case IEEE80211_IOC_ROAM: 1065 error = ieee80211_ioctl_getroam(vap, ireq); 1066 break; 1067 case IEEE80211_IOC_TXPARAMS: 1068 error = ieee80211_ioctl_gettxparams(vap, ireq); 1069 break; 1070 case IEEE80211_IOC_HTCOMPAT: 1071 ireq->i_val = (vap->iv_flags_ht & IEEE80211_FHT_HTCOMPAT) != 0; 1072 break; 1073 case IEEE80211_IOC_DWDS: 1074 ireq->i_val = (vap->iv_flags & IEEE80211_F_DWDS) != 0; 1075 break; 1076 case IEEE80211_IOC_INACTIVITY: 1077 ireq->i_val = (vap->iv_flags_ext & IEEE80211_FEXT_INACT) != 0; 1078 break; 1079 case IEEE80211_IOC_APPIE: 1080 error = ieee80211_ioctl_getappie(vap, ireq); 1081 break; 1082 case IEEE80211_IOC_WPS: 1083 ireq->i_val = (vap->iv_flags_ext & IEEE80211_FEXT_WPS) != 0; 1084 break; 1085 case IEEE80211_IOC_TSN: 1086 ireq->i_val = (vap->iv_flags_ext & IEEE80211_FEXT_TSN) != 0; 1087 break; 1088 case IEEE80211_IOC_DFS: 1089 ireq->i_val = (vap->iv_flags_ext & IEEE80211_FEXT_DFS) != 0; 1090 break; 1091 case IEEE80211_IOC_DOTD: 1092 ireq->i_val = (vap->iv_flags_ext & IEEE80211_FEXT_DOTD) != 0; 1093 break; 1094 case IEEE80211_IOC_DEVCAPS: 1095 error = ieee80211_ioctl_getdevcaps(ic, ireq); 1096 break; 1097 case IEEE80211_IOC_HTPROTMODE: 1098 ireq->i_val = ic->ic_htprotmode; 1099 break; 1100 case IEEE80211_IOC_HTCONF: 1101 if (vap->iv_flags_ht & IEEE80211_FHT_HT) { 1102 ireq->i_val = 1; 1103 if (vap->iv_flags_ht & IEEE80211_FHT_USEHT40) 1104 ireq->i_val |= 2; 1105 } else 1106 ireq->i_val = 0; 1107 break; 1108 case IEEE80211_IOC_STA_VLAN: 1109 error = ieee80211_ioctl_getstavlan(vap, ireq); 1110 break; 1111 case IEEE80211_IOC_SMPS: 1112 if (vap->iv_opmode == IEEE80211_M_STA && 1113 (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP)) { 1114 if (vap->iv_bss->ni_flags & IEEE80211_NODE_MIMO_RTS) 1115 ireq->i_val = IEEE80211_HTCAP_SMPS_DYNAMIC; 1116 else if (vap->iv_bss->ni_flags & IEEE80211_NODE_MIMO_PS) 1117 ireq->i_val = IEEE80211_HTCAP_SMPS_ENA; 1118 else 1119 ireq->i_val = IEEE80211_HTCAP_SMPS_OFF; 1120 } else 1121 ireq->i_val = vap->iv_htcaps & IEEE80211_HTCAP_SMPS; 1122 break; 1123 case IEEE80211_IOC_RIFS: 1124 if (vap->iv_opmode == IEEE80211_M_STA && 1125 (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP)) 1126 ireq->i_val = 1127 (vap->iv_bss->ni_flags & IEEE80211_NODE_RIFS) != 0; 1128 else 1129 ireq->i_val = 1130 (vap->iv_flags_ht & IEEE80211_FHT_RIFS) != 0; 1131 break; 1132 case IEEE80211_IOC_STBC: 1133 ireq->i_val = 0; 1134 if (vap->iv_flags_ht & IEEE80211_FHT_STBC_TX) 1135 ireq->i_val |= 1; 1136 if (vap->iv_flags_ht & IEEE80211_FHT_STBC_RX) 1137 ireq->i_val |= 2; 1138 break; 1139 case IEEE80211_IOC_LDPC: 1140 ireq->i_val = 0; 1141 if (vap->iv_flags_ht & IEEE80211_FHT_LDPC_TX) 1142 ireq->i_val |= 1; 1143 if (vap->iv_flags_ht & IEEE80211_FHT_LDPC_RX) 1144 ireq->i_val |= 2; 1145 break; 1146 1147 /* VHT */ 1148 case IEEE80211_IOC_VHTCONF: 1149 ireq->i_val = 0; 1150 if (vap->iv_flags_vht & IEEE80211_FVHT_VHT) 1151 ireq->i_val |= 1; 1152 if (vap->iv_flags_vht & IEEE80211_FVHT_USEVHT40) 1153 ireq->i_val |= 2; 1154 if (vap->iv_flags_vht & IEEE80211_FVHT_USEVHT80) 1155 ireq->i_val |= 4; 1156 if (vap->iv_flags_vht & IEEE80211_FVHT_USEVHT80P80) 1157 ireq->i_val |= 8; 1158 if (vap->iv_flags_vht & IEEE80211_FVHT_USEVHT160) 1159 ireq->i_val |= 16; 1160 break; 1161 1162 default: 1163 error = ieee80211_ioctl_getdefault(vap, ireq); 1164 break; 1165 } 1166 return error; 1167 #undef MS 1168 } 1169 1170 static int 1171 ieee80211_ioctl_setkey(struct ieee80211vap *vap, struct ieee80211req *ireq) 1172 { 1173 struct ieee80211req_key ik; 1174 struct ieee80211_node *ni; 1175 struct ieee80211_key *wk; 1176 uint16_t kid; 1177 int error, i; 1178 1179 if (ireq->i_len != sizeof(ik)) 1180 return EINVAL; 1181 error = copyin(ireq->i_data, &ik, sizeof(ik)); 1182 if (error) 1183 return error; 1184 /* NB: cipher support is verified by ieee80211_crypt_newkey */ 1185 /* NB: this also checks ik->ik_keylen > sizeof(wk->wk_key) */ 1186 if (ik.ik_keylen > sizeof(ik.ik_keydata)) 1187 return E2BIG; 1188 kid = ik.ik_keyix; 1189 if (kid == IEEE80211_KEYIX_NONE) { 1190 /* XXX unicast keys currently must be tx/rx */ 1191 if (ik.ik_flags != (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV)) 1192 return EINVAL; 1193 if (vap->iv_opmode == IEEE80211_M_STA) { 1194 ni = ieee80211_ref_node(vap->iv_bss); 1195 if (!IEEE80211_ADDR_EQ(ik.ik_macaddr, ni->ni_bssid)) { 1196 ieee80211_free_node(ni); 1197 return EADDRNOTAVAIL; 1198 } 1199 } else { 1200 ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, 1201 ik.ik_macaddr); 1202 if (ni == NULL) 1203 return ENOENT; 1204 } 1205 wk = &ni->ni_ucastkey; 1206 } else { 1207 if (kid >= IEEE80211_WEP_NKID) 1208 return EINVAL; 1209 wk = &vap->iv_nw_keys[kid]; 1210 /* 1211 * Global slots start off w/o any assigned key index. 1212 * Force one here for consistency with IEEE80211_IOC_WEPKEY. 1213 */ 1214 if (wk->wk_keyix == IEEE80211_KEYIX_NONE) 1215 wk->wk_keyix = kid; 1216 ni = NULL; 1217 } 1218 error = 0; 1219 ieee80211_key_update_begin(vap); 1220 if (ieee80211_crypto_newkey(vap, ik.ik_type, ik.ik_flags, wk)) { 1221 wk->wk_keylen = ik.ik_keylen; 1222 /* NB: MIC presence is implied by cipher type */ 1223 if (wk->wk_keylen > IEEE80211_KEYBUF_SIZE) 1224 wk->wk_keylen = IEEE80211_KEYBUF_SIZE; 1225 for (i = 0; i < IEEE80211_TID_SIZE; i++) 1226 wk->wk_keyrsc[i] = ik.ik_keyrsc; 1227 wk->wk_keytsc = 0; /* new key, reset */ 1228 memset(wk->wk_key, 0, sizeof(wk->wk_key)); 1229 memcpy(wk->wk_key, ik.ik_keydata, ik.ik_keylen); 1230 IEEE80211_ADDR_COPY(wk->wk_macaddr, 1231 ni != NULL ? ni->ni_macaddr : ik.ik_macaddr); 1232 if (!ieee80211_crypto_setkey(vap, wk)) 1233 error = EIO; 1234 else if ((ik.ik_flags & IEEE80211_KEY_DEFAULT)) 1235 /* 1236 * Inform the driver that this is the default 1237 * transmit key. Now, ideally we'd just set 1238 * a flag in the key update that would 1239 * say "yes, we're the default key", but 1240 * that currently isn't the way the ioctl -> 1241 * key interface works. 1242 */ 1243 ieee80211_crypto_set_deftxkey(vap, kid); 1244 } else 1245 error = ENXIO; 1246 ieee80211_key_update_end(vap); 1247 if (ni != NULL) 1248 ieee80211_free_node(ni); 1249 return error; 1250 } 1251 1252 static int 1253 ieee80211_ioctl_delkey(struct ieee80211vap *vap, struct ieee80211req *ireq) 1254 { 1255 struct ieee80211req_del_key dk; 1256 int kid, error; 1257 1258 if (ireq->i_len != sizeof(dk)) 1259 return EINVAL; 1260 error = copyin(ireq->i_data, &dk, sizeof(dk)); 1261 if (error) 1262 return error; 1263 kid = dk.idk_keyix; 1264 /* XXX uint8_t -> uint16_t */ 1265 if (dk.idk_keyix == (uint8_t) IEEE80211_KEYIX_NONE) { 1266 struct ieee80211_node *ni; 1267 1268 if (vap->iv_opmode == IEEE80211_M_STA) { 1269 ni = ieee80211_ref_node(vap->iv_bss); 1270 if (!IEEE80211_ADDR_EQ(dk.idk_macaddr, ni->ni_bssid)) { 1271 ieee80211_free_node(ni); 1272 return EADDRNOTAVAIL; 1273 } 1274 } else { 1275 ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, 1276 dk.idk_macaddr); 1277 if (ni == NULL) 1278 return ENOENT; 1279 } 1280 /* XXX error return */ 1281 ieee80211_node_delucastkey(ni); 1282 ieee80211_free_node(ni); 1283 } else { 1284 if (kid >= IEEE80211_WEP_NKID) 1285 return EINVAL; 1286 /* XXX error return */ 1287 ieee80211_crypto_delkey(vap, &vap->iv_nw_keys[kid]); 1288 } 1289 return 0; 1290 } 1291 1292 struct mlmeop { 1293 struct ieee80211vap *vap; 1294 int op; 1295 int reason; 1296 }; 1297 1298 static void 1299 mlmedebug(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN], 1300 int op, int reason) 1301 { 1302 #ifdef IEEE80211_DEBUG 1303 static const struct { 1304 int mask; 1305 const char *opstr; 1306 } ops[] = { 1307 { 0, "op#0" }, 1308 { IEEE80211_MSG_IOCTL | IEEE80211_MSG_STATE | 1309 IEEE80211_MSG_ASSOC, "assoc" }, 1310 { IEEE80211_MSG_IOCTL | IEEE80211_MSG_STATE | 1311 IEEE80211_MSG_ASSOC, "disassoc" }, 1312 { IEEE80211_MSG_IOCTL | IEEE80211_MSG_STATE | 1313 IEEE80211_MSG_AUTH, "deauth" }, 1314 { IEEE80211_MSG_IOCTL | IEEE80211_MSG_STATE | 1315 IEEE80211_MSG_AUTH, "authorize" }, 1316 { IEEE80211_MSG_IOCTL | IEEE80211_MSG_STATE | 1317 IEEE80211_MSG_AUTH, "unauthorize" }, 1318 }; 1319 1320 if (op == IEEE80211_MLME_AUTH) { 1321 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_IOCTL | 1322 IEEE80211_MSG_STATE | IEEE80211_MSG_AUTH, mac, 1323 "station authenticate %s via MLME (reason: %d (%s))", 1324 reason == IEEE80211_STATUS_SUCCESS ? "ACCEPT" : "REJECT", 1325 reason, ieee80211_reason_to_string(reason)); 1326 } else if (!(IEEE80211_MLME_ASSOC <= op && op <= IEEE80211_MLME_AUTH)) { 1327 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_ANY, mac, 1328 "unknown MLME request %d (reason: %d (%s))", op, reason, 1329 ieee80211_reason_to_string(reason)); 1330 } else if (reason == IEEE80211_STATUS_SUCCESS) { 1331 IEEE80211_NOTE_MAC(vap, ops[op].mask, mac, 1332 "station %s via MLME", ops[op].opstr); 1333 } else { 1334 IEEE80211_NOTE_MAC(vap, ops[op].mask, mac, 1335 "station %s via MLME (reason: %d (%s))", ops[op].opstr, 1336 reason, ieee80211_reason_to_string(reason)); 1337 } 1338 #endif /* IEEE80211_DEBUG */ 1339 } 1340 1341 static void 1342 domlme(void *arg, struct ieee80211_node *ni) 1343 { 1344 struct mlmeop *mop = arg; 1345 struct ieee80211vap *vap = ni->ni_vap; 1346 1347 if (vap != mop->vap) 1348 return; 1349 /* 1350 * NB: if ni_associd is zero then the node is already cleaned 1351 * up and we don't need to do this (we're safely holding a 1352 * reference but should otherwise not modify it's state). 1353 */ 1354 if (ni->ni_associd == 0) 1355 return; 1356 mlmedebug(vap, ni->ni_macaddr, mop->op, mop->reason); 1357 if (mop->op == IEEE80211_MLME_DEAUTH) { 1358 IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DEAUTH, 1359 mop->reason); 1360 } else { 1361 IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DISASSOC, 1362 mop->reason); 1363 } 1364 ieee80211_node_leave(ni); 1365 } 1366 1367 static int 1368 setmlme_dropsta(struct ieee80211vap *vap, 1369 const uint8_t mac[IEEE80211_ADDR_LEN], struct mlmeop *mlmeop) 1370 { 1371 struct ieee80211_node_table *nt = &vap->iv_ic->ic_sta; 1372 struct ieee80211_node *ni; 1373 int error = 0; 1374 1375 /* NB: the broadcast address means do 'em all */ 1376 if (!IEEE80211_ADDR_EQ(mac, vap->iv_ifp->if_broadcastaddr)) { 1377 IEEE80211_NODE_LOCK(nt); 1378 ni = ieee80211_find_node_locked(nt, mac); 1379 IEEE80211_NODE_UNLOCK(nt); 1380 /* 1381 * Don't do the node update inside the node 1382 * table lock. This unfortunately causes LORs 1383 * with drivers and their TX paths. 1384 */ 1385 if (ni != NULL) { 1386 domlme(mlmeop, ni); 1387 ieee80211_free_node(ni); 1388 } else 1389 error = ENOENT; 1390 } else { 1391 ieee80211_iterate_nodes(nt, domlme, mlmeop); 1392 } 1393 return error; 1394 } 1395 1396 static int 1397 setmlme_common(struct ieee80211vap *vap, int op, 1398 const uint8_t mac[IEEE80211_ADDR_LEN], int reason) 1399 { 1400 struct ieee80211com *ic = vap->iv_ic; 1401 struct ieee80211_node_table *nt = &ic->ic_sta; 1402 struct ieee80211_node *ni; 1403 struct mlmeop mlmeop; 1404 int error; 1405 1406 error = 0; 1407 switch (op) { 1408 case IEEE80211_MLME_DISASSOC: 1409 case IEEE80211_MLME_DEAUTH: 1410 switch (vap->iv_opmode) { 1411 case IEEE80211_M_STA: 1412 mlmedebug(vap, vap->iv_bss->ni_macaddr, op, reason); 1413 /* XXX not quite right */ 1414 ieee80211_new_state(vap, IEEE80211_S_INIT, reason); 1415 break; 1416 case IEEE80211_M_HOSTAP: 1417 mlmeop.vap = vap; 1418 mlmeop.op = op; 1419 mlmeop.reason = reason; 1420 error = setmlme_dropsta(vap, mac, &mlmeop); 1421 break; 1422 case IEEE80211_M_WDS: 1423 /* XXX user app should send raw frame? */ 1424 if (op != IEEE80211_MLME_DEAUTH) { 1425 error = EINVAL; 1426 break; 1427 } 1428 #if 0 1429 /* XXX accept any address, simplifies user code */ 1430 if (!IEEE80211_ADDR_EQ(mac, vap->iv_bss->ni_macaddr)) { 1431 error = EINVAL; 1432 break; 1433 } 1434 #endif 1435 mlmedebug(vap, vap->iv_bss->ni_macaddr, op, reason); 1436 ni = ieee80211_ref_node(vap->iv_bss); 1437 IEEE80211_SEND_MGMT(ni, 1438 IEEE80211_FC0_SUBTYPE_DEAUTH, reason); 1439 ieee80211_free_node(ni); 1440 break; 1441 case IEEE80211_M_MBSS: 1442 IEEE80211_NODE_LOCK(nt); 1443 ni = ieee80211_find_node_locked(nt, mac); 1444 /* 1445 * Don't do the node update inside the node 1446 * table lock. This unfortunately causes LORs 1447 * with drivers and their TX paths. 1448 */ 1449 IEEE80211_NODE_UNLOCK(nt); 1450 if (ni != NULL) { 1451 ieee80211_node_leave(ni); 1452 ieee80211_free_node(ni); 1453 } else { 1454 error = ENOENT; 1455 } 1456 break; 1457 default: 1458 error = EINVAL; 1459 break; 1460 } 1461 break; 1462 case IEEE80211_MLME_AUTHORIZE: 1463 case IEEE80211_MLME_UNAUTHORIZE: 1464 if (vap->iv_opmode != IEEE80211_M_HOSTAP && 1465 vap->iv_opmode != IEEE80211_M_WDS) { 1466 error = EINVAL; 1467 break; 1468 } 1469 IEEE80211_NODE_LOCK(nt); 1470 ni = ieee80211_find_vap_node_locked(nt, vap, mac); 1471 /* 1472 * Don't do the node update inside the node 1473 * table lock. This unfortunately causes LORs 1474 * with drivers and their TX paths. 1475 */ 1476 IEEE80211_NODE_UNLOCK(nt); 1477 if (ni != NULL) { 1478 mlmedebug(vap, mac, op, reason); 1479 if (op == IEEE80211_MLME_AUTHORIZE) 1480 ieee80211_node_authorize(ni); 1481 else 1482 ieee80211_node_unauthorize(ni); 1483 ieee80211_free_node(ni); 1484 } else 1485 error = ENOENT; 1486 break; 1487 case IEEE80211_MLME_AUTH: 1488 if (vap->iv_opmode != IEEE80211_M_HOSTAP) { 1489 error = EINVAL; 1490 break; 1491 } 1492 IEEE80211_NODE_LOCK(nt); 1493 ni = ieee80211_find_vap_node_locked(nt, vap, mac); 1494 /* 1495 * Don't do the node update inside the node 1496 * table lock. This unfortunately causes LORs 1497 * with drivers and their TX paths. 1498 */ 1499 IEEE80211_NODE_UNLOCK(nt); 1500 if (ni != NULL) { 1501 mlmedebug(vap, mac, op, reason); 1502 if (reason == IEEE80211_STATUS_SUCCESS) { 1503 IEEE80211_SEND_MGMT(ni, 1504 IEEE80211_FC0_SUBTYPE_AUTH, 2); 1505 /* 1506 * For shared key auth, just continue the 1507 * exchange. Otherwise when 802.1x is not in 1508 * use mark the port authorized at this point 1509 * so traffic can flow. 1510 */ 1511 if (ni->ni_authmode != IEEE80211_AUTH_8021X && 1512 ni->ni_challenge == NULL) 1513 ieee80211_node_authorize(ni); 1514 } else { 1515 vap->iv_stats.is_rx_acl++; 1516 ieee80211_send_error(ni, ni->ni_macaddr, 1517 IEEE80211_FC0_SUBTYPE_AUTH, 2|(reason<<16)); 1518 ieee80211_node_leave(ni); 1519 } 1520 ieee80211_free_node(ni); 1521 } else 1522 error = ENOENT; 1523 break; 1524 default: 1525 error = EINVAL; 1526 break; 1527 } 1528 return error; 1529 } 1530 1531 struct scanlookup { 1532 const uint8_t *mac; 1533 int esslen; 1534 const uint8_t *essid; 1535 const struct ieee80211_scan_entry *se; 1536 }; 1537 1538 /* 1539 * Match mac address and any ssid. 1540 */ 1541 static void 1542 mlmelookup(void *arg, const struct ieee80211_scan_entry *se) 1543 { 1544 struct scanlookup *look = arg; 1545 1546 if (!IEEE80211_ADDR_EQ(look->mac, se->se_macaddr)) 1547 return; 1548 if (look->esslen != 0) { 1549 if (se->se_ssid[1] != look->esslen) 1550 return; 1551 if (memcmp(look->essid, se->se_ssid+2, look->esslen)) 1552 return; 1553 } 1554 look->se = se; 1555 } 1556 1557 static int 1558 setmlme_assoc_sta(struct ieee80211vap *vap, 1559 const uint8_t mac[IEEE80211_ADDR_LEN], int ssid_len, 1560 const uint8_t ssid[IEEE80211_NWID_LEN]) 1561 { 1562 struct scanlookup lookup; 1563 1564 KASSERT(vap->iv_opmode == IEEE80211_M_STA, 1565 ("expected opmode STA not %s", 1566 ieee80211_opmode_name[vap->iv_opmode])); 1567 1568 /* NB: this is racey if roaming is !manual */ 1569 lookup.se = NULL; 1570 lookup.mac = mac; 1571 lookup.esslen = ssid_len; 1572 lookup.essid = ssid; 1573 ieee80211_scan_iterate(vap, mlmelookup, &lookup); 1574 if (lookup.se == NULL) 1575 return ENOENT; 1576 mlmedebug(vap, mac, IEEE80211_MLME_ASSOC, 0); 1577 if (!ieee80211_sta_join(vap, lookup.se->se_chan, lookup.se)) 1578 return EIO; /* XXX unique but could be better */ 1579 return 0; 1580 } 1581 1582 static int 1583 setmlme_assoc_adhoc(struct ieee80211vap *vap, 1584 const uint8_t mac[IEEE80211_ADDR_LEN], int ssid_len, 1585 const uint8_t ssid[IEEE80211_NWID_LEN]) 1586 { 1587 struct ieee80211_scan_req *sr; 1588 int error; 1589 1590 KASSERT(vap->iv_opmode == IEEE80211_M_IBSS || 1591 vap->iv_opmode == IEEE80211_M_AHDEMO, 1592 ("expected opmode IBSS or AHDEMO not %s", 1593 ieee80211_opmode_name[vap->iv_opmode])); 1594 1595 if (ssid_len == 0) 1596 return EINVAL; 1597 1598 sr = IEEE80211_MALLOC(sizeof(*sr), M_TEMP, 1599 IEEE80211_M_NOWAIT | IEEE80211_M_ZERO); 1600 if (sr == NULL) 1601 return ENOMEM; 1602 1603 /* NB: IEEE80211_IOC_SSID call missing for ap_scan=2. */ 1604 memset(vap->iv_des_ssid[0].ssid, 0, IEEE80211_NWID_LEN); 1605 vap->iv_des_ssid[0].len = ssid_len; 1606 memcpy(vap->iv_des_ssid[0].ssid, ssid, ssid_len); 1607 vap->iv_des_nssid = 1; 1608 1609 sr->sr_flags = IEEE80211_IOC_SCAN_ACTIVE | IEEE80211_IOC_SCAN_ONCE; 1610 sr->sr_duration = IEEE80211_IOC_SCAN_FOREVER; 1611 memcpy(sr->sr_ssid[0].ssid, ssid, ssid_len); 1612 sr->sr_ssid[0].len = ssid_len; 1613 sr->sr_nssid = 1; 1614 1615 error = ieee80211_scanreq(vap, sr); 1616 1617 IEEE80211_FREE(sr, M_TEMP); 1618 return error; 1619 } 1620 1621 static int 1622 ieee80211_ioctl_setmlme(struct ieee80211vap *vap, struct ieee80211req *ireq) 1623 { 1624 struct ieee80211req_mlme mlme; 1625 int error; 1626 1627 if (ireq->i_len != sizeof(mlme)) 1628 return EINVAL; 1629 error = copyin(ireq->i_data, &mlme, sizeof(mlme)); 1630 if (error) 1631 return error; 1632 if (vap->iv_opmode == IEEE80211_M_STA && 1633 mlme.im_op == IEEE80211_MLME_ASSOC) 1634 return setmlme_assoc_sta(vap, mlme.im_macaddr, 1635 vap->iv_des_ssid[0].len, vap->iv_des_ssid[0].ssid); 1636 else if ((vap->iv_opmode == IEEE80211_M_IBSS || 1637 vap->iv_opmode == IEEE80211_M_AHDEMO) && 1638 mlme.im_op == IEEE80211_MLME_ASSOC) 1639 return setmlme_assoc_adhoc(vap, mlme.im_macaddr, 1640 mlme.im_ssid_len, mlme.im_ssid); 1641 else 1642 return setmlme_common(vap, mlme.im_op, 1643 mlme.im_macaddr, mlme.im_reason); 1644 } 1645 1646 static int 1647 ieee80211_ioctl_macmac(struct ieee80211vap *vap, struct ieee80211req *ireq) 1648 { 1649 uint8_t mac[IEEE80211_ADDR_LEN]; 1650 const struct ieee80211_aclator *acl = vap->iv_acl; 1651 int error; 1652 1653 if (ireq->i_len != sizeof(mac)) 1654 return EINVAL; 1655 error = copyin(ireq->i_data, mac, ireq->i_len); 1656 if (error) 1657 return error; 1658 if (acl == NULL) { 1659 acl = ieee80211_aclator_get("mac"); 1660 if (acl == NULL || !acl->iac_attach(vap)) 1661 return EINVAL; 1662 vap->iv_acl = acl; 1663 } 1664 if (ireq->i_type == IEEE80211_IOC_ADDMAC) 1665 acl->iac_add(vap, mac); 1666 else 1667 acl->iac_remove(vap, mac); 1668 return 0; 1669 } 1670 1671 static int 1672 ieee80211_ioctl_setmaccmd(struct ieee80211vap *vap, struct ieee80211req *ireq) 1673 { 1674 const struct ieee80211_aclator *acl = vap->iv_acl; 1675 1676 switch (ireq->i_val) { 1677 case IEEE80211_MACCMD_POLICY_OPEN: 1678 case IEEE80211_MACCMD_POLICY_ALLOW: 1679 case IEEE80211_MACCMD_POLICY_DENY: 1680 case IEEE80211_MACCMD_POLICY_RADIUS: 1681 if (acl == NULL) { 1682 acl = ieee80211_aclator_get("mac"); 1683 if (acl == NULL || !acl->iac_attach(vap)) 1684 return EINVAL; 1685 vap->iv_acl = acl; 1686 } 1687 acl->iac_setpolicy(vap, ireq->i_val); 1688 break; 1689 case IEEE80211_MACCMD_FLUSH: 1690 if (acl != NULL) 1691 acl->iac_flush(vap); 1692 /* NB: silently ignore when not in use */ 1693 break; 1694 case IEEE80211_MACCMD_DETACH: 1695 if (acl != NULL) { 1696 vap->iv_acl = NULL; 1697 acl->iac_detach(vap); 1698 } 1699 break; 1700 default: 1701 if (acl == NULL) 1702 return EINVAL; 1703 else 1704 return acl->iac_setioctl(vap, ireq); 1705 } 1706 return 0; 1707 } 1708 1709 static int 1710 ieee80211_ioctl_setchanlist(struct ieee80211vap *vap, struct ieee80211req *ireq) 1711 { 1712 struct ieee80211com *ic = vap->iv_ic; 1713 uint8_t *chanlist, *list; 1714 int i, nchan, maxchan, error; 1715 1716 if (ireq->i_len > sizeof(ic->ic_chan_active)) 1717 ireq->i_len = sizeof(ic->ic_chan_active); 1718 list = IEEE80211_MALLOC(ireq->i_len + IEEE80211_CHAN_BYTES, M_TEMP, 1719 IEEE80211_M_NOWAIT | IEEE80211_M_ZERO); 1720 if (list == NULL) 1721 return ENOMEM; 1722 error = copyin(ireq->i_data, list, ireq->i_len); 1723 if (error) { 1724 IEEE80211_FREE(list, M_TEMP); 1725 return error; 1726 } 1727 nchan = 0; 1728 chanlist = list + ireq->i_len; /* NB: zero'd already */ 1729 maxchan = ireq->i_len * NBBY; 1730 for (i = 0; i < ic->ic_nchans; i++) { 1731 const struct ieee80211_channel *c = &ic->ic_channels[i]; 1732 /* 1733 * Calculate the intersection of the user list and the 1734 * available channels so users can do things like specify 1735 * 1-255 to get all available channels. 1736 */ 1737 if (c->ic_ieee < maxchan && isset(list, c->ic_ieee)) { 1738 setbit(chanlist, c->ic_ieee); 1739 nchan++; 1740 } 1741 } 1742 if (nchan == 0) { 1743 IEEE80211_FREE(list, M_TEMP); 1744 return EINVAL; 1745 } 1746 if (ic->ic_bsschan != IEEE80211_CHAN_ANYC && /* XXX */ 1747 isclr(chanlist, ic->ic_bsschan->ic_ieee)) 1748 ic->ic_bsschan = IEEE80211_CHAN_ANYC; 1749 memcpy(ic->ic_chan_active, chanlist, IEEE80211_CHAN_BYTES); 1750 ieee80211_scan_flush(vap); 1751 IEEE80211_FREE(list, M_TEMP); 1752 return ENETRESET; 1753 } 1754 1755 static int 1756 ieee80211_ioctl_setstastats(struct ieee80211vap *vap, struct ieee80211req *ireq) 1757 { 1758 struct ieee80211_node *ni; 1759 uint8_t macaddr[IEEE80211_ADDR_LEN]; 1760 int error; 1761 1762 /* 1763 * NB: we could copyin ieee80211req_sta_stats so apps 1764 * could make selective changes but that's overkill; 1765 * just clear all stats for now. 1766 */ 1767 if (ireq->i_len < IEEE80211_ADDR_LEN) 1768 return EINVAL; 1769 error = copyin(ireq->i_data, macaddr, IEEE80211_ADDR_LEN); 1770 if (error != 0) 1771 return error; 1772 ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, macaddr); 1773 if (ni == NULL) 1774 return ENOENT; 1775 /* XXX require ni_vap == vap? */ 1776 memset(&ni->ni_stats, 0, sizeof(ni->ni_stats)); 1777 ieee80211_free_node(ni); 1778 return 0; 1779 } 1780 1781 static int 1782 ieee80211_ioctl_setstatxpow(struct ieee80211vap *vap, struct ieee80211req *ireq) 1783 { 1784 struct ieee80211_node *ni; 1785 struct ieee80211req_sta_txpow txpow; 1786 int error; 1787 1788 if (ireq->i_len != sizeof(txpow)) 1789 return EINVAL; 1790 error = copyin(ireq->i_data, &txpow, sizeof(txpow)); 1791 if (error != 0) 1792 return error; 1793 ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, txpow.it_macaddr); 1794 if (ni == NULL) 1795 return ENOENT; 1796 ni->ni_txpower = txpow.it_txpow; 1797 ieee80211_free_node(ni); 1798 return error; 1799 } 1800 1801 static int 1802 ieee80211_ioctl_setwmeparam(struct ieee80211vap *vap, struct ieee80211req *ireq) 1803 { 1804 struct ieee80211com *ic = vap->iv_ic; 1805 struct ieee80211_wme_state *wme = &ic->ic_wme; 1806 struct wmeParams *wmep, *chanp; 1807 int isbss, ac, aggrmode; 1808 1809 if ((ic->ic_caps & IEEE80211_C_WME) == 0) 1810 return EOPNOTSUPP; 1811 1812 isbss = (ireq->i_len & IEEE80211_WMEPARAM_BSS); 1813 ac = (ireq->i_len & IEEE80211_WMEPARAM_VAL); 1814 aggrmode = (wme->wme_flags & WME_F_AGGRMODE); 1815 if (ac >= WME_NUM_AC) 1816 ac = WME_AC_BE; 1817 if (isbss) { 1818 chanp = &wme->wme_bssChanParams.cap_wmeParams[ac]; 1819 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac]; 1820 } else { 1821 chanp = &wme->wme_chanParams.cap_wmeParams[ac]; 1822 wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac]; 1823 } 1824 switch (ireq->i_type) { 1825 case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */ 1826 wmep->wmep_logcwmin = ireq->i_val; 1827 if (!isbss || !aggrmode) 1828 chanp->wmep_logcwmin = ireq->i_val; 1829 break; 1830 case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */ 1831 wmep->wmep_logcwmax = ireq->i_val; 1832 if (!isbss || !aggrmode) 1833 chanp->wmep_logcwmax = ireq->i_val; 1834 break; 1835 case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */ 1836 wmep->wmep_aifsn = ireq->i_val; 1837 if (!isbss || !aggrmode) 1838 chanp->wmep_aifsn = ireq->i_val; 1839 break; 1840 case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */ 1841 wmep->wmep_txopLimit = ireq->i_val; 1842 if (!isbss || !aggrmode) 1843 chanp->wmep_txopLimit = ireq->i_val; 1844 break; 1845 case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */ 1846 wmep->wmep_acm = ireq->i_val; 1847 if (!aggrmode) 1848 chanp->wmep_acm = ireq->i_val; 1849 break; 1850 case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only)*/ 1851 wmep->wmep_noackPolicy = chanp->wmep_noackPolicy = 1852 (ireq->i_val) == 0; 1853 break; 1854 } 1855 ieee80211_wme_updateparams(vap); 1856 return 0; 1857 } 1858 1859 static int 1860 find11gchannel(struct ieee80211com *ic, int start, int freq) 1861 { 1862 const struct ieee80211_channel *c; 1863 int i; 1864 1865 for (i = start+1; i < ic->ic_nchans; i++) { 1866 c = &ic->ic_channels[i]; 1867 if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c)) 1868 return 1; 1869 } 1870 /* NB: should not be needed but in case things are mis-sorted */ 1871 for (i = 0; i < start; i++) { 1872 c = &ic->ic_channels[i]; 1873 if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c)) 1874 return 1; 1875 } 1876 return 0; 1877 } 1878 1879 static struct ieee80211_channel * 1880 findchannel(struct ieee80211com *ic, int ieee, int mode) 1881 { 1882 static const u_int chanflags[IEEE80211_MODE_MAX] = { 1883 [IEEE80211_MODE_AUTO] = 0, 1884 [IEEE80211_MODE_11A] = IEEE80211_CHAN_A, 1885 [IEEE80211_MODE_11B] = IEEE80211_CHAN_B, 1886 [IEEE80211_MODE_11G] = IEEE80211_CHAN_G, 1887 [IEEE80211_MODE_FH] = IEEE80211_CHAN_FHSS, 1888 [IEEE80211_MODE_TURBO_A] = IEEE80211_CHAN_108A, 1889 [IEEE80211_MODE_TURBO_G] = IEEE80211_CHAN_108G, 1890 [IEEE80211_MODE_STURBO_A] = IEEE80211_CHAN_STURBO, 1891 [IEEE80211_MODE_HALF] = IEEE80211_CHAN_HALF, 1892 [IEEE80211_MODE_QUARTER] = IEEE80211_CHAN_QUARTER, 1893 /* NB: handled specially below */ 1894 [IEEE80211_MODE_11NA] = IEEE80211_CHAN_A, 1895 [IEEE80211_MODE_11NG] = IEEE80211_CHAN_G, 1896 [IEEE80211_MODE_VHT_5GHZ] = IEEE80211_CHAN_A, 1897 [IEEE80211_MODE_VHT_2GHZ] = IEEE80211_CHAN_G, 1898 }; 1899 u_int modeflags; 1900 int i; 1901 1902 modeflags = chanflags[mode]; 1903 for (i = 0; i < ic->ic_nchans; i++) { 1904 struct ieee80211_channel *c = &ic->ic_channels[i]; 1905 1906 if (c->ic_ieee != ieee) 1907 continue; 1908 if (mode == IEEE80211_MODE_AUTO) { 1909 /* ignore turbo channels for autoselect */ 1910 if (IEEE80211_IS_CHAN_TURBO(c)) 1911 continue; 1912 /* 1913 * XXX special-case 11b/g channels so we 1914 * always select the g channel if both 1915 * are present. 1916 * XXX prefer HT to non-HT? 1917 */ 1918 if (!IEEE80211_IS_CHAN_B(c) || 1919 !find11gchannel(ic, i, c->ic_freq)) 1920 return c; 1921 } else { 1922 /* must check VHT specifically */ 1923 if ((mode == IEEE80211_MODE_VHT_5GHZ || 1924 mode == IEEE80211_MODE_VHT_2GHZ) && 1925 !IEEE80211_IS_CHAN_VHT(c)) 1926 continue; 1927 1928 /* 1929 * Must check HT specially - only match on HT, 1930 * not HT+VHT channels 1931 */ 1932 if ((mode == IEEE80211_MODE_11NA || 1933 mode == IEEE80211_MODE_11NG) && 1934 !IEEE80211_IS_CHAN_HT(c)) 1935 continue; 1936 1937 if ((mode == IEEE80211_MODE_11NA || 1938 mode == IEEE80211_MODE_11NG) && 1939 IEEE80211_IS_CHAN_VHT(c)) 1940 continue; 1941 1942 /* Check that the modeflags above match */ 1943 if ((c->ic_flags & modeflags) == modeflags) 1944 return c; 1945 } 1946 } 1947 return NULL; 1948 } 1949 1950 /* 1951 * Check the specified against any desired mode (aka netband). 1952 * This is only used (presently) when operating in hostap mode 1953 * to enforce consistency. 1954 */ 1955 static int 1956 check_mode_consistency(const struct ieee80211_channel *c, int mode) 1957 { 1958 KASSERT(c != IEEE80211_CHAN_ANYC, ("oops, no channel")); 1959 1960 switch (mode) { 1961 case IEEE80211_MODE_11B: 1962 return (IEEE80211_IS_CHAN_B(c)); 1963 case IEEE80211_MODE_11G: 1964 return (IEEE80211_IS_CHAN_ANYG(c) && !IEEE80211_IS_CHAN_HT(c)); 1965 case IEEE80211_MODE_11A: 1966 return (IEEE80211_IS_CHAN_A(c) && !IEEE80211_IS_CHAN_HT(c)); 1967 case IEEE80211_MODE_STURBO_A: 1968 return (IEEE80211_IS_CHAN_STURBO(c)); 1969 case IEEE80211_MODE_11NA: 1970 return (IEEE80211_IS_CHAN_HTA(c)); 1971 case IEEE80211_MODE_11NG: 1972 return (IEEE80211_IS_CHAN_HTG(c)); 1973 } 1974 return 1; 1975 1976 } 1977 1978 /* 1979 * Common code to set the current channel. If the device 1980 * is up and running this may result in an immediate channel 1981 * change or a kick of the state machine. 1982 */ 1983 static int 1984 setcurchan(struct ieee80211vap *vap, struct ieee80211_channel *c) 1985 { 1986 struct ieee80211com *ic = vap->iv_ic; 1987 int error; 1988 1989 if (c != IEEE80211_CHAN_ANYC) { 1990 if (IEEE80211_IS_CHAN_RADAR(c)) 1991 return EBUSY; /* XXX better code? */ 1992 if (vap->iv_opmode == IEEE80211_M_HOSTAP) { 1993 if (IEEE80211_IS_CHAN_NOHOSTAP(c)) 1994 return EINVAL; 1995 if (!check_mode_consistency(c, vap->iv_des_mode)) 1996 return EINVAL; 1997 } else if (vap->iv_opmode == IEEE80211_M_IBSS) { 1998 if (IEEE80211_IS_CHAN_NOADHOC(c)) 1999 return EINVAL; 2000 } 2001 if ((vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP) && 2002 vap->iv_bss->ni_chan == c) 2003 return 0; /* NB: nothing to do */ 2004 } 2005 vap->iv_des_chan = c; 2006 2007 error = 0; 2008 if (vap->iv_opmode == IEEE80211_M_MONITOR && 2009 vap->iv_des_chan != IEEE80211_CHAN_ANYC) { 2010 /* 2011 * Monitor mode can switch directly. 2012 */ 2013 if (IFNET_IS_UP_RUNNING(vap->iv_ifp)) { 2014 /* XXX need state machine for other vap's to follow */ 2015 ieee80211_setcurchan(ic, vap->iv_des_chan); 2016 vap->iv_bss->ni_chan = ic->ic_curchan; 2017 } else 2018 ic->ic_curchan = vap->iv_des_chan; 2019 ic->ic_rt = ieee80211_get_ratetable(ic->ic_curchan); 2020 } else { 2021 /* 2022 * Need to go through the state machine in case we 2023 * need to reassociate or the like. The state machine 2024 * will pickup the desired channel and avoid scanning. 2025 */ 2026 if (IS_UP_AUTO(vap)) 2027 ieee80211_new_state(vap, IEEE80211_S_SCAN, 0); 2028 else if (vap->iv_des_chan != IEEE80211_CHAN_ANYC) { 2029 /* 2030 * When not up+running and a real channel has 2031 * been specified fix the current channel so 2032 * there is immediate feedback; e.g. via ifconfig. 2033 */ 2034 ic->ic_curchan = vap->iv_des_chan; 2035 ic->ic_rt = ieee80211_get_ratetable(ic->ic_curchan); 2036 } 2037 } 2038 return error; 2039 } 2040 2041 /* 2042 * Old api for setting the current channel; this is 2043 * deprecated because channel numbers are ambiguous. 2044 */ 2045 static int 2046 ieee80211_ioctl_setchannel(struct ieee80211vap *vap, 2047 const struct ieee80211req *ireq) 2048 { 2049 struct ieee80211com *ic = vap->iv_ic; 2050 struct ieee80211_channel *c; 2051 2052 /* XXX 0xffff overflows 16-bit signed */ 2053 if (ireq->i_val == 0 || 2054 ireq->i_val == (int16_t) IEEE80211_CHAN_ANY) { 2055 c = IEEE80211_CHAN_ANYC; 2056 } else { 2057 struct ieee80211_channel *c2; 2058 2059 c = findchannel(ic, ireq->i_val, vap->iv_des_mode); 2060 if (c == NULL) { 2061 c = findchannel(ic, ireq->i_val, 2062 IEEE80211_MODE_AUTO); 2063 if (c == NULL) 2064 return EINVAL; 2065 } 2066 2067 /* 2068 * Fine tune channel selection based on desired mode: 2069 * if 11b is requested, find the 11b version of any 2070 * 11g channel returned, 2071 * if static turbo, find the turbo version of any 2072 * 11a channel return, 2073 * if 11na is requested, find the ht version of any 2074 * 11a channel returned, 2075 * if 11ng is requested, find the ht version of any 2076 * 11g channel returned, 2077 * if 11ac is requested, find the 11ac version 2078 * of any 11a/11na channel returned, 2079 * (TBD) 11acg (2GHz VHT) 2080 * otherwise we should be ok with what we've got. 2081 */ 2082 switch (vap->iv_des_mode) { 2083 case IEEE80211_MODE_11B: 2084 if (IEEE80211_IS_CHAN_ANYG(c)) { 2085 c2 = findchannel(ic, ireq->i_val, 2086 IEEE80211_MODE_11B); 2087 /* NB: should not happen, =>'s 11g w/o 11b */ 2088 if (c2 != NULL) 2089 c = c2; 2090 } 2091 break; 2092 case IEEE80211_MODE_TURBO_A: 2093 if (IEEE80211_IS_CHAN_A(c)) { 2094 c2 = findchannel(ic, ireq->i_val, 2095 IEEE80211_MODE_TURBO_A); 2096 if (c2 != NULL) 2097 c = c2; 2098 } 2099 break; 2100 case IEEE80211_MODE_11NA: 2101 if (IEEE80211_IS_CHAN_A(c)) { 2102 c2 = findchannel(ic, ireq->i_val, 2103 IEEE80211_MODE_11NA); 2104 if (c2 != NULL) 2105 c = c2; 2106 } 2107 break; 2108 case IEEE80211_MODE_11NG: 2109 if (IEEE80211_IS_CHAN_ANYG(c)) { 2110 c2 = findchannel(ic, ireq->i_val, 2111 IEEE80211_MODE_11NG); 2112 if (c2 != NULL) 2113 c = c2; 2114 } 2115 break; 2116 case IEEE80211_MODE_VHT_2GHZ: 2117 printf("%s: TBD\n", __func__); 2118 break; 2119 case IEEE80211_MODE_VHT_5GHZ: 2120 if (IEEE80211_IS_CHAN_A(c)) { 2121 c2 = findchannel(ic, ireq->i_val, 2122 IEEE80211_MODE_VHT_5GHZ); 2123 if (c2 != NULL) 2124 c = c2; 2125 } 2126 break; 2127 default: /* NB: no static turboG */ 2128 break; 2129 } 2130 } 2131 return setcurchan(vap, c); 2132 } 2133 2134 /* 2135 * New/current api for setting the current channel; a complete 2136 * channel description is provide so there is no ambiguity in 2137 * identifying the channel. 2138 */ 2139 static int 2140 ieee80211_ioctl_setcurchan(struct ieee80211vap *vap, 2141 const struct ieee80211req *ireq) 2142 { 2143 struct ieee80211com *ic = vap->iv_ic; 2144 struct ieee80211_channel chan, *c; 2145 int error; 2146 2147 if (ireq->i_len != sizeof(chan)) 2148 return EINVAL; 2149 error = copyin(ireq->i_data, &chan, sizeof(chan)); 2150 if (error != 0) 2151 return error; 2152 2153 /* XXX 0xffff overflows 16-bit signed */ 2154 if (chan.ic_freq == 0 || chan.ic_freq == IEEE80211_CHAN_ANY) { 2155 c = IEEE80211_CHAN_ANYC; 2156 } else { 2157 c = ieee80211_find_channel(ic, chan.ic_freq, chan.ic_flags); 2158 if (c == NULL) 2159 return EINVAL; 2160 } 2161 return setcurchan(vap, c); 2162 } 2163 2164 static int 2165 ieee80211_ioctl_setregdomain(struct ieee80211vap *vap, 2166 const struct ieee80211req *ireq) 2167 { 2168 struct ieee80211_regdomain_req *reg; 2169 int nchans, error; 2170 2171 nchans = 1 + ((ireq->i_len - sizeof(struct ieee80211_regdomain_req)) / 2172 sizeof(struct ieee80211_channel)); 2173 if (!(1 <= nchans && nchans <= IEEE80211_CHAN_MAX)) { 2174 IEEE80211_DPRINTF(vap, IEEE80211_MSG_IOCTL, 2175 "%s: bad # chans, i_len %d nchans %d\n", __func__, 2176 ireq->i_len, nchans); 2177 return EINVAL; 2178 } 2179 reg = (struct ieee80211_regdomain_req *) 2180 IEEE80211_MALLOC(IEEE80211_REGDOMAIN_SIZE(nchans), M_TEMP, 2181 IEEE80211_M_NOWAIT | IEEE80211_M_ZERO); 2182 if (reg == NULL) { 2183 IEEE80211_DPRINTF(vap, IEEE80211_MSG_IOCTL, 2184 "%s: no memory, nchans %d\n", __func__, nchans); 2185 return ENOMEM; 2186 } 2187 error = copyin(ireq->i_data, reg, IEEE80211_REGDOMAIN_SIZE(nchans)); 2188 if (error == 0) { 2189 /* NB: validate inline channel count against storage size */ 2190 if (reg->chaninfo.ic_nchans != nchans) { 2191 IEEE80211_DPRINTF(vap, IEEE80211_MSG_IOCTL, 2192 "%s: chan cnt mismatch, %d != %d\n", __func__, 2193 reg->chaninfo.ic_nchans, nchans); 2194 error = EINVAL; 2195 } else 2196 error = ieee80211_setregdomain(vap, reg); 2197 } 2198 IEEE80211_FREE(reg, M_TEMP); 2199 2200 return (error == 0 ? ENETRESET : error); 2201 } 2202 2203 static int 2204 ieee80211_ioctl_setroam(struct ieee80211vap *vap, 2205 const struct ieee80211req *ireq) 2206 { 2207 if (ireq->i_len != sizeof(vap->iv_roamparms)) 2208 return EINVAL; 2209 /* XXX validate params */ 2210 /* XXX? ENETRESET to push to device? */ 2211 return copyin(ireq->i_data, vap->iv_roamparms, 2212 sizeof(vap->iv_roamparms)); 2213 } 2214 2215 static int 2216 checkrate(const struct ieee80211_rateset *rs, int rate) 2217 { 2218 int i; 2219 2220 if (rate == IEEE80211_FIXED_RATE_NONE) 2221 return 1; 2222 for (i = 0; i < rs->rs_nrates; i++) 2223 if ((rs->rs_rates[i] & IEEE80211_RATE_VAL) == rate) 2224 return 1; 2225 return 0; 2226 } 2227 2228 static int 2229 checkmcs(int mcs) 2230 { 2231 if (mcs == IEEE80211_FIXED_RATE_NONE) 2232 return 1; 2233 if ((mcs & IEEE80211_RATE_MCS) == 0) /* MCS always have 0x80 set */ 2234 return 0; 2235 return (mcs & 0x7f) <= 31; /* XXX could search ht rate set */ 2236 } 2237 2238 static int 2239 ieee80211_ioctl_settxparams(struct ieee80211vap *vap, 2240 const struct ieee80211req *ireq) 2241 { 2242 struct ieee80211com *ic = vap->iv_ic; 2243 struct ieee80211_txparams_req parms; /* XXX stack use? */ 2244 struct ieee80211_txparam *src, *dst; 2245 const struct ieee80211_rateset *rs; 2246 int error, mode, changed, is11n, nmodes; 2247 2248 /* NB: accept short requests for backwards compat */ 2249 if (ireq->i_len > sizeof(parms)) 2250 return EINVAL; 2251 error = copyin(ireq->i_data, &parms, ireq->i_len); 2252 if (error != 0) 2253 return error; 2254 nmodes = ireq->i_len / sizeof(struct ieee80211_txparam); 2255 changed = 0; 2256 /* validate parameters and check if anything changed */ 2257 for (mode = IEEE80211_MODE_11A; mode < nmodes; mode++) { 2258 if (isclr(ic->ic_modecaps, mode)) 2259 continue; 2260 src = &parms.params[mode]; 2261 dst = &vap->iv_txparms[mode]; 2262 rs = &ic->ic_sup_rates[mode]; /* NB: 11n maps to legacy */ 2263 is11n = (mode == IEEE80211_MODE_11NA || 2264 mode == IEEE80211_MODE_11NG); 2265 if (src->ucastrate != dst->ucastrate) { 2266 if (!checkrate(rs, src->ucastrate) && 2267 (!is11n || !checkmcs(src->ucastrate))) 2268 return EINVAL; 2269 changed++; 2270 } 2271 if (src->mcastrate != dst->mcastrate) { 2272 if (!checkrate(rs, src->mcastrate) && 2273 (!is11n || !checkmcs(src->mcastrate))) 2274 return EINVAL; 2275 changed++; 2276 } 2277 if (src->mgmtrate != dst->mgmtrate) { 2278 if (!checkrate(rs, src->mgmtrate) && 2279 (!is11n || !checkmcs(src->mgmtrate))) 2280 return EINVAL; 2281 changed++; 2282 } 2283 if (src->maxretry != dst->maxretry) /* NB: no bounds */ 2284 changed++; 2285 } 2286 if (changed) { 2287 /* 2288 * Copy new parameters in place and notify the 2289 * driver so it can push state to the device. 2290 */ 2291 for (mode = IEEE80211_MODE_11A; mode < nmodes; mode++) { 2292 if (isset(ic->ic_modecaps, mode)) 2293 vap->iv_txparms[mode] = parms.params[mode]; 2294 } 2295 /* XXX could be more intelligent, 2296 e.g. don't reset if setting not being used */ 2297 return ENETRESET; 2298 } 2299 return 0; 2300 } 2301 2302 /* 2303 * Application Information Element support. 2304 */ 2305 static int 2306 setappie(struct ieee80211_appie **aie, const struct ieee80211req *ireq) 2307 { 2308 struct ieee80211_appie *app = *aie; 2309 struct ieee80211_appie *napp; 2310 int error; 2311 2312 if (ireq->i_len == 0) { /* delete any existing ie */ 2313 if (app != NULL) { 2314 *aie = NULL; /* XXX racey */ 2315 IEEE80211_FREE(app, M_80211_NODE_IE); 2316 } 2317 return 0; 2318 } 2319 if (!(2 <= ireq->i_len && ireq->i_len <= IEEE80211_MAX_APPIE)) 2320 return EINVAL; 2321 /* 2322 * Allocate a new appie structure and copy in the user data. 2323 * When done swap in the new structure. Note that we do not 2324 * guard against users holding a ref to the old structure; 2325 * this must be handled outside this code. 2326 * 2327 * XXX bad bad bad 2328 */ 2329 napp = (struct ieee80211_appie *) IEEE80211_MALLOC( 2330 sizeof(struct ieee80211_appie) + ireq->i_len, M_80211_NODE_IE, 2331 IEEE80211_M_NOWAIT); 2332 if (napp == NULL) 2333 return ENOMEM; 2334 /* XXX holding ic lock */ 2335 error = copyin(ireq->i_data, napp->ie_data, ireq->i_len); 2336 if (error) { 2337 IEEE80211_FREE(napp, M_80211_NODE_IE); 2338 return error; 2339 } 2340 napp->ie_len = ireq->i_len; 2341 *aie = napp; 2342 if (app != NULL) 2343 IEEE80211_FREE(app, M_80211_NODE_IE); 2344 return 0; 2345 } 2346 2347 static void 2348 setwparsnie(struct ieee80211vap *vap, uint8_t *ie, int space) 2349 { 2350 /* validate data is present as best we can */ 2351 if (space == 0 || 2+ie[1] > space) 2352 return; 2353 if (ie[0] == IEEE80211_ELEMID_VENDOR) 2354 vap->iv_wpa_ie = ie; 2355 else if (ie[0] == IEEE80211_ELEMID_RSN) 2356 vap->iv_rsn_ie = ie; 2357 } 2358 2359 static int 2360 ieee80211_ioctl_setappie_locked(struct ieee80211vap *vap, 2361 const struct ieee80211req *ireq, int fc0) 2362 { 2363 int error; 2364 2365 IEEE80211_LOCK_ASSERT(vap->iv_ic); 2366 2367 switch (fc0 & IEEE80211_FC0_SUBTYPE_MASK) { 2368 case IEEE80211_FC0_SUBTYPE_BEACON: 2369 if (vap->iv_opmode != IEEE80211_M_HOSTAP && 2370 vap->iv_opmode != IEEE80211_M_IBSS) { 2371 error = EINVAL; 2372 break; 2373 } 2374 error = setappie(&vap->iv_appie_beacon, ireq); 2375 if (error == 0) 2376 ieee80211_beacon_notify(vap, IEEE80211_BEACON_APPIE); 2377 break; 2378 case IEEE80211_FC0_SUBTYPE_PROBE_RESP: 2379 error = setappie(&vap->iv_appie_proberesp, ireq); 2380 break; 2381 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP: 2382 if (vap->iv_opmode == IEEE80211_M_HOSTAP) 2383 error = setappie(&vap->iv_appie_assocresp, ireq); 2384 else 2385 error = EINVAL; 2386 break; 2387 case IEEE80211_FC0_SUBTYPE_PROBE_REQ: 2388 error = setappie(&vap->iv_appie_probereq, ireq); 2389 break; 2390 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ: 2391 if (vap->iv_opmode == IEEE80211_M_STA) 2392 error = setappie(&vap->iv_appie_assocreq, ireq); 2393 else 2394 error = EINVAL; 2395 break; 2396 case (IEEE80211_APPIE_WPA & IEEE80211_FC0_SUBTYPE_MASK): 2397 error = setappie(&vap->iv_appie_wpa, ireq); 2398 if (error == 0) { 2399 /* 2400 * Must split single blob of data into separate 2401 * WPA and RSN ie's because they go in different 2402 * locations in the mgt frames. 2403 * XXX use IEEE80211_IOC_WPA2 so user code does split 2404 */ 2405 vap->iv_wpa_ie = NULL; 2406 vap->iv_rsn_ie = NULL; 2407 if (vap->iv_appie_wpa != NULL) { 2408 struct ieee80211_appie *appie = 2409 vap->iv_appie_wpa; 2410 uint8_t *data = appie->ie_data; 2411 2412 /* XXX ie length validate is painful, cheat */ 2413 setwparsnie(vap, data, appie->ie_len); 2414 setwparsnie(vap, data + 2 + data[1], 2415 appie->ie_len - (2 + data[1])); 2416 } 2417 if (vap->iv_opmode == IEEE80211_M_HOSTAP || 2418 vap->iv_opmode == IEEE80211_M_IBSS) { 2419 /* 2420 * Must rebuild beacon frame as the update 2421 * mechanism doesn't handle WPA/RSN ie's. 2422 * Could extend it but it doesn't normally 2423 * change; this is just to deal with hostapd 2424 * plumbing the ie after the interface is up. 2425 */ 2426 error = ENETRESET; 2427 } 2428 } 2429 break; 2430 default: 2431 error = EINVAL; 2432 break; 2433 } 2434 return error; 2435 } 2436 2437 static int 2438 ieee80211_ioctl_setappie(struct ieee80211vap *vap, 2439 const struct ieee80211req *ireq) 2440 { 2441 struct ieee80211com *ic = vap->iv_ic; 2442 int error; 2443 uint8_t fc0; 2444 2445 fc0 = ireq->i_val & 0xff; 2446 if ((fc0 & IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_MGT) 2447 return EINVAL; 2448 /* NB: could check iv_opmode and reject but hardly worth the effort */ 2449 IEEE80211_LOCK(ic); 2450 error = ieee80211_ioctl_setappie_locked(vap, ireq, fc0); 2451 IEEE80211_UNLOCK(ic); 2452 return error; 2453 } 2454 2455 static int 2456 ieee80211_ioctl_chanswitch(struct ieee80211vap *vap, struct ieee80211req *ireq) 2457 { 2458 struct ieee80211com *ic = vap->iv_ic; 2459 struct ieee80211_chanswitch_req csr; 2460 struct ieee80211_channel *c; 2461 int error; 2462 2463 if (ireq->i_len != sizeof(csr)) 2464 return EINVAL; 2465 error = copyin(ireq->i_data, &csr, sizeof(csr)); 2466 if (error != 0) 2467 return error; 2468 /* XXX adhoc mode not supported */ 2469 if (vap->iv_opmode != IEEE80211_M_HOSTAP || 2470 (vap->iv_flags & IEEE80211_F_DOTH) == 0) 2471 return EOPNOTSUPP; 2472 c = ieee80211_find_channel(ic, 2473 csr.csa_chan.ic_freq, csr.csa_chan.ic_flags); 2474 if (c == NULL) 2475 return ENOENT; 2476 IEEE80211_LOCK(ic); 2477 if ((ic->ic_flags & IEEE80211_F_CSAPENDING) == 0) 2478 ieee80211_csa_startswitch(ic, c, csr.csa_mode, csr.csa_count); 2479 else if (csr.csa_count == 0) 2480 ieee80211_csa_cancelswitch(ic); 2481 else 2482 error = EBUSY; 2483 IEEE80211_UNLOCK(ic); 2484 return error; 2485 } 2486 2487 static int 2488 ieee80211_scanreq(struct ieee80211vap *vap, struct ieee80211_scan_req *sr) 2489 { 2490 #define IEEE80211_IOC_SCAN_FLAGS \ 2491 (IEEE80211_IOC_SCAN_NOPICK | IEEE80211_IOC_SCAN_ACTIVE | \ 2492 IEEE80211_IOC_SCAN_PICK1ST | IEEE80211_IOC_SCAN_BGSCAN | \ 2493 IEEE80211_IOC_SCAN_ONCE | IEEE80211_IOC_SCAN_NOBCAST | \ 2494 IEEE80211_IOC_SCAN_NOJOIN | IEEE80211_IOC_SCAN_FLUSH | \ 2495 IEEE80211_IOC_SCAN_CHECK) 2496 struct ieee80211com *ic = vap->iv_ic; 2497 int error, i; 2498 2499 /* convert duration */ 2500 if (sr->sr_duration == IEEE80211_IOC_SCAN_FOREVER) 2501 sr->sr_duration = IEEE80211_SCAN_FOREVER; 2502 else { 2503 if (sr->sr_duration < IEEE80211_IOC_SCAN_DURATION_MIN || 2504 sr->sr_duration > IEEE80211_IOC_SCAN_DURATION_MAX) 2505 return EINVAL; 2506 sr->sr_duration = msecs_to_ticks(sr->sr_duration); 2507 if (sr->sr_duration < 1) 2508 sr->sr_duration = 1; 2509 } 2510 /* convert min/max channel dwell */ 2511 if (sr->sr_mindwell != 0) { 2512 sr->sr_mindwell = msecs_to_ticks(sr->sr_mindwell); 2513 if (sr->sr_mindwell < 1) 2514 sr->sr_mindwell = 1; 2515 } 2516 if (sr->sr_maxdwell != 0) { 2517 sr->sr_maxdwell = msecs_to_ticks(sr->sr_maxdwell); 2518 if (sr->sr_maxdwell < 1) 2519 sr->sr_maxdwell = 1; 2520 } 2521 /* NB: silently reduce ssid count to what is supported */ 2522 if (sr->sr_nssid > IEEE80211_SCAN_MAX_SSID) 2523 sr->sr_nssid = IEEE80211_SCAN_MAX_SSID; 2524 for (i = 0; i < sr->sr_nssid; i++) 2525 if (sr->sr_ssid[i].len > IEEE80211_NWID_LEN) 2526 return EINVAL; 2527 /* cleanse flags just in case, could reject if invalid flags */ 2528 sr->sr_flags &= IEEE80211_IOC_SCAN_FLAGS; 2529 /* 2530 * Add an implicit NOPICK if the vap is not marked UP. This 2531 * allows applications to scan without joining a bss (or picking 2532 * a channel and setting up a bss) and without forcing manual 2533 * roaming mode--you just need to mark the parent device UP. 2534 */ 2535 if ((vap->iv_ifp->if_flags & IFF_UP) == 0) 2536 sr->sr_flags |= IEEE80211_IOC_SCAN_NOPICK; 2537 2538 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, 2539 "%s: flags 0x%x%s duration 0x%x mindwell %u maxdwell %u nssid %d\n", 2540 __func__, sr->sr_flags, 2541 (vap->iv_ifp->if_flags & IFF_UP) == 0 ? " (!IFF_UP)" : "", 2542 sr->sr_duration, sr->sr_mindwell, sr->sr_maxdwell, sr->sr_nssid); 2543 /* 2544 * If we are in INIT state then the driver has never had a chance 2545 * to setup hardware state to do a scan; we must use the state 2546 * machine to get us up to the SCAN state but once we reach SCAN 2547 * state we then want to use the supplied params. Stash the 2548 * parameters in the vap and mark IEEE80211_FEXT_SCANREQ; the 2549 * state machines will recognize this and use the stashed params 2550 * to issue the scan request. 2551 * 2552 * Otherwise just invoke the scan machinery directly. 2553 */ 2554 IEEE80211_LOCK(ic); 2555 if (ic->ic_nrunning == 0) { 2556 IEEE80211_UNLOCK(ic); 2557 return ENXIO; 2558 } 2559 2560 if (vap->iv_state == IEEE80211_S_INIT) { 2561 /* NB: clobbers previous settings */ 2562 vap->iv_scanreq_flags = sr->sr_flags; 2563 vap->iv_scanreq_duration = sr->sr_duration; 2564 vap->iv_scanreq_nssid = sr->sr_nssid; 2565 for (i = 0; i < sr->sr_nssid; i++) { 2566 vap->iv_scanreq_ssid[i].len = sr->sr_ssid[i].len; 2567 memcpy(vap->iv_scanreq_ssid[i].ssid, 2568 sr->sr_ssid[i].ssid, sr->sr_ssid[i].len); 2569 } 2570 vap->iv_flags_ext |= IEEE80211_FEXT_SCANREQ; 2571 IEEE80211_UNLOCK(ic); 2572 ieee80211_new_state(vap, IEEE80211_S_SCAN, 0); 2573 } else { 2574 vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANREQ; 2575 IEEE80211_UNLOCK(ic); 2576 if (sr->sr_flags & IEEE80211_IOC_SCAN_CHECK) { 2577 error = ieee80211_check_scan(vap, sr->sr_flags, 2578 sr->sr_duration, sr->sr_mindwell, sr->sr_maxdwell, 2579 sr->sr_nssid, 2580 /* NB: cheat, we assume structures are compatible */ 2581 (const struct ieee80211_scan_ssid *) &sr->sr_ssid[0]); 2582 } else { 2583 error = ieee80211_start_scan(vap, sr->sr_flags, 2584 sr->sr_duration, sr->sr_mindwell, sr->sr_maxdwell, 2585 sr->sr_nssid, 2586 /* NB: cheat, we assume structures are compatible */ 2587 (const struct ieee80211_scan_ssid *) &sr->sr_ssid[0]); 2588 } 2589 if (error == 0) 2590 return EINPROGRESS; 2591 } 2592 return 0; 2593 #undef IEEE80211_IOC_SCAN_FLAGS 2594 } 2595 2596 static int 2597 ieee80211_ioctl_scanreq(struct ieee80211vap *vap, struct ieee80211req *ireq) 2598 { 2599 struct ieee80211_scan_req *sr; 2600 int error; 2601 2602 if (ireq->i_len != sizeof(*sr)) 2603 return EINVAL; 2604 sr = IEEE80211_MALLOC(sizeof(*sr), M_TEMP, 2605 IEEE80211_M_NOWAIT | IEEE80211_M_ZERO); 2606 if (sr == NULL) 2607 return ENOMEM; 2608 error = copyin(ireq->i_data, sr, sizeof(*sr)); 2609 if (error != 0) 2610 goto bad; 2611 error = ieee80211_scanreq(vap, sr); 2612 bad: 2613 IEEE80211_FREE(sr, M_TEMP); 2614 return error; 2615 } 2616 2617 static int 2618 ieee80211_ioctl_setstavlan(struct ieee80211vap *vap, struct ieee80211req *ireq) 2619 { 2620 struct ieee80211_node *ni; 2621 struct ieee80211req_sta_vlan vlan; 2622 int error; 2623 2624 if (ireq->i_len != sizeof(vlan)) 2625 return EINVAL; 2626 error = copyin(ireq->i_data, &vlan, sizeof(vlan)); 2627 if (error != 0) 2628 return error; 2629 if (!IEEE80211_ADDR_EQ(vlan.sv_macaddr, zerobssid)) { 2630 ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, 2631 vlan.sv_macaddr); 2632 if (ni == NULL) 2633 return ENOENT; 2634 } else 2635 ni = ieee80211_ref_node(vap->iv_bss); 2636 ni->ni_vlan = vlan.sv_vlan; 2637 ieee80211_free_node(ni); 2638 return error; 2639 } 2640 2641 static int 2642 isvap11g(const struct ieee80211vap *vap) 2643 { 2644 const struct ieee80211_node *bss = vap->iv_bss; 2645 return bss->ni_chan != IEEE80211_CHAN_ANYC && 2646 IEEE80211_IS_CHAN_ANYG(bss->ni_chan); 2647 } 2648 2649 static int 2650 isvapht(const struct ieee80211vap *vap) 2651 { 2652 const struct ieee80211_node *bss = vap->iv_bss; 2653 return bss->ni_chan != IEEE80211_CHAN_ANYC && 2654 IEEE80211_IS_CHAN_HT(bss->ni_chan); 2655 } 2656 2657 /* 2658 * Dummy ioctl set handler so the linker set is defined. 2659 */ 2660 static int 2661 dummy_ioctl_set(struct ieee80211vap *vap, struct ieee80211req *ireq) 2662 { 2663 return ENOSYS; 2664 } 2665 IEEE80211_IOCTL_SET(dummy, dummy_ioctl_set); 2666 2667 static int 2668 ieee80211_ioctl_setdefault(struct ieee80211vap *vap, struct ieee80211req *ireq) 2669 { 2670 ieee80211_ioctl_setfunc * const *set; 2671 int error; 2672 2673 SET_FOREACH(set, ieee80211_ioctl_setset) { 2674 error = (*set)(vap, ireq); 2675 if (error != ENOSYS) 2676 return error; 2677 } 2678 return EINVAL; 2679 } 2680 2681 static int 2682 ieee80211_ioctl_set80211(struct ieee80211vap *vap, u_long cmd, struct ieee80211req *ireq) 2683 { 2684 struct ieee80211com *ic = vap->iv_ic; 2685 int error; 2686 const struct ieee80211_authenticator *auth; 2687 uint8_t tmpkey[IEEE80211_KEYBUF_SIZE]; 2688 char tmpssid[IEEE80211_NWID_LEN]; 2689 uint8_t tmpbssid[IEEE80211_ADDR_LEN]; 2690 struct ieee80211_key *k; 2691 u_int kid; 2692 uint32_t flags; 2693 2694 error = 0; 2695 switch (ireq->i_type) { 2696 case IEEE80211_IOC_SSID: 2697 if (ireq->i_val != 0 || 2698 ireq->i_len > IEEE80211_NWID_LEN) 2699 return EINVAL; 2700 error = copyin(ireq->i_data, tmpssid, ireq->i_len); 2701 if (error) 2702 break; 2703 memset(vap->iv_des_ssid[0].ssid, 0, IEEE80211_NWID_LEN); 2704 vap->iv_des_ssid[0].len = ireq->i_len; 2705 memcpy(vap->iv_des_ssid[0].ssid, tmpssid, ireq->i_len); 2706 vap->iv_des_nssid = (ireq->i_len > 0); 2707 error = ENETRESET; 2708 break; 2709 case IEEE80211_IOC_WEP: 2710 switch (ireq->i_val) { 2711 case IEEE80211_WEP_OFF: 2712 vap->iv_flags &= ~IEEE80211_F_PRIVACY; 2713 vap->iv_flags &= ~IEEE80211_F_DROPUNENC; 2714 break; 2715 case IEEE80211_WEP_ON: 2716 vap->iv_flags |= IEEE80211_F_PRIVACY; 2717 vap->iv_flags |= IEEE80211_F_DROPUNENC; 2718 break; 2719 case IEEE80211_WEP_MIXED: 2720 vap->iv_flags |= IEEE80211_F_PRIVACY; 2721 vap->iv_flags &= ~IEEE80211_F_DROPUNENC; 2722 break; 2723 } 2724 error = ENETRESET; 2725 break; 2726 case IEEE80211_IOC_WEPKEY: 2727 kid = (u_int) ireq->i_val; 2728 if (kid >= IEEE80211_WEP_NKID) 2729 return EINVAL; 2730 k = &vap->iv_nw_keys[kid]; 2731 if (ireq->i_len == 0) { 2732 /* zero-len =>'s delete any existing key */ 2733 (void) ieee80211_crypto_delkey(vap, k); 2734 break; 2735 } 2736 if (ireq->i_len > sizeof(tmpkey)) 2737 return EINVAL; 2738 memset(tmpkey, 0, sizeof(tmpkey)); 2739 error = copyin(ireq->i_data, tmpkey, ireq->i_len); 2740 if (error) 2741 break; 2742 ieee80211_key_update_begin(vap); 2743 k->wk_keyix = kid; /* NB: force fixed key id */ 2744 if (ieee80211_crypto_newkey(vap, IEEE80211_CIPHER_WEP, 2745 IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV, k)) { 2746 k->wk_keylen = ireq->i_len; 2747 memcpy(k->wk_key, tmpkey, sizeof(tmpkey)); 2748 IEEE80211_ADDR_COPY(k->wk_macaddr, vap->iv_myaddr); 2749 if (!ieee80211_crypto_setkey(vap, k)) 2750 error = EINVAL; 2751 } else 2752 error = EINVAL; 2753 ieee80211_key_update_end(vap); 2754 break; 2755 case IEEE80211_IOC_WEPTXKEY: 2756 kid = (u_int) ireq->i_val; 2757 if (kid >= IEEE80211_WEP_NKID && 2758 (uint16_t) kid != IEEE80211_KEYIX_NONE) 2759 return EINVAL; 2760 /* 2761 * Firmware devices may need to be told about an explicit 2762 * key index here, versus just inferring it from the 2763 * key set / change. Since we may also need to pause 2764 * things like transmit before the key is updated, 2765 * give the driver a chance to flush things by tying 2766 * into key update begin/end. 2767 */ 2768 ieee80211_key_update_begin(vap); 2769 ieee80211_crypto_set_deftxkey(vap, kid); 2770 ieee80211_key_update_end(vap); 2771 break; 2772 case IEEE80211_IOC_AUTHMODE: 2773 switch (ireq->i_val) { 2774 case IEEE80211_AUTH_WPA: 2775 case IEEE80211_AUTH_8021X: /* 802.1x */ 2776 case IEEE80211_AUTH_OPEN: /* open */ 2777 case IEEE80211_AUTH_SHARED: /* shared-key */ 2778 case IEEE80211_AUTH_AUTO: /* auto */ 2779 auth = ieee80211_authenticator_get(ireq->i_val); 2780 if (auth == NULL) 2781 return EINVAL; 2782 break; 2783 default: 2784 return EINVAL; 2785 } 2786 switch (ireq->i_val) { 2787 case IEEE80211_AUTH_WPA: /* WPA w/ 802.1x */ 2788 vap->iv_flags |= IEEE80211_F_PRIVACY; 2789 ireq->i_val = IEEE80211_AUTH_8021X; 2790 break; 2791 case IEEE80211_AUTH_OPEN: /* open */ 2792 vap->iv_flags &= ~(IEEE80211_F_WPA|IEEE80211_F_PRIVACY); 2793 break; 2794 case IEEE80211_AUTH_SHARED: /* shared-key */ 2795 case IEEE80211_AUTH_8021X: /* 802.1x */ 2796 vap->iv_flags &= ~IEEE80211_F_WPA; 2797 /* both require a key so mark the PRIVACY capability */ 2798 vap->iv_flags |= IEEE80211_F_PRIVACY; 2799 break; 2800 case IEEE80211_AUTH_AUTO: /* auto */ 2801 vap->iv_flags &= ~IEEE80211_F_WPA; 2802 /* XXX PRIVACY handling? */ 2803 /* XXX what's the right way to do this? */ 2804 break; 2805 } 2806 /* NB: authenticator attach/detach happens on state change */ 2807 vap->iv_bss->ni_authmode = ireq->i_val; 2808 /* XXX mixed/mode/usage? */ 2809 vap->iv_auth = auth; 2810 error = ENETRESET; 2811 break; 2812 case IEEE80211_IOC_CHANNEL: 2813 error = ieee80211_ioctl_setchannel(vap, ireq); 2814 break; 2815 case IEEE80211_IOC_POWERSAVE: 2816 switch (ireq->i_val) { 2817 case IEEE80211_POWERSAVE_OFF: 2818 if (vap->iv_flags & IEEE80211_F_PMGTON) { 2819 ieee80211_syncflag(vap, -IEEE80211_F_PMGTON); 2820 error = ERESTART; 2821 } 2822 break; 2823 case IEEE80211_POWERSAVE_ON: 2824 if ((vap->iv_caps & IEEE80211_C_PMGT) == 0) 2825 error = EOPNOTSUPP; 2826 else if ((vap->iv_flags & IEEE80211_F_PMGTON) == 0) { 2827 ieee80211_syncflag(vap, IEEE80211_F_PMGTON); 2828 error = ERESTART; 2829 } 2830 break; 2831 default: 2832 error = EINVAL; 2833 break; 2834 } 2835 break; 2836 case IEEE80211_IOC_POWERSAVESLEEP: 2837 if (ireq->i_val < 0) 2838 return EINVAL; 2839 ic->ic_lintval = ireq->i_val; 2840 error = ERESTART; 2841 break; 2842 case IEEE80211_IOC_RTSTHRESHOLD: 2843 if (!(IEEE80211_RTS_MIN <= ireq->i_val && 2844 ireq->i_val <= IEEE80211_RTS_MAX)) 2845 return EINVAL; 2846 vap->iv_rtsthreshold = ireq->i_val; 2847 error = ERESTART; 2848 break; 2849 case IEEE80211_IOC_PROTMODE: 2850 if (ireq->i_val > IEEE80211_PROT_RTSCTS) 2851 return EINVAL; 2852 ic->ic_protmode = (enum ieee80211_protmode)ireq->i_val; 2853 /* NB: if not operating in 11g this can wait */ 2854 if (ic->ic_bsschan != IEEE80211_CHAN_ANYC && 2855 IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan)) 2856 error = ERESTART; 2857 break; 2858 case IEEE80211_IOC_TXPOWER: 2859 if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0) 2860 return EOPNOTSUPP; 2861 if (!(IEEE80211_TXPOWER_MIN <= ireq->i_val && 2862 ireq->i_val <= IEEE80211_TXPOWER_MAX)) 2863 return EINVAL; 2864 ic->ic_txpowlimit = ireq->i_val; 2865 error = ERESTART; 2866 break; 2867 case IEEE80211_IOC_ROAMING: 2868 if (!(IEEE80211_ROAMING_DEVICE <= ireq->i_val && 2869 ireq->i_val <= IEEE80211_ROAMING_MANUAL)) 2870 return EINVAL; 2871 vap->iv_roaming = (enum ieee80211_roamingmode)ireq->i_val; 2872 /* XXXX reset? */ 2873 break; 2874 case IEEE80211_IOC_PRIVACY: 2875 if (ireq->i_val) { 2876 /* XXX check for key state? */ 2877 vap->iv_flags |= IEEE80211_F_PRIVACY; 2878 } else 2879 vap->iv_flags &= ~IEEE80211_F_PRIVACY; 2880 /* XXX ERESTART? */ 2881 break; 2882 case IEEE80211_IOC_DROPUNENCRYPTED: 2883 if (ireq->i_val) 2884 vap->iv_flags |= IEEE80211_F_DROPUNENC; 2885 else 2886 vap->iv_flags &= ~IEEE80211_F_DROPUNENC; 2887 /* XXX ERESTART? */ 2888 break; 2889 case IEEE80211_IOC_WPAKEY: 2890 error = ieee80211_ioctl_setkey(vap, ireq); 2891 break; 2892 case IEEE80211_IOC_DELKEY: 2893 error = ieee80211_ioctl_delkey(vap, ireq); 2894 break; 2895 case IEEE80211_IOC_MLME: 2896 error = ieee80211_ioctl_setmlme(vap, ireq); 2897 break; 2898 case IEEE80211_IOC_COUNTERMEASURES: 2899 if (ireq->i_val) { 2900 if ((vap->iv_flags & IEEE80211_F_WPA) == 0) 2901 return EOPNOTSUPP; 2902 vap->iv_flags |= IEEE80211_F_COUNTERM; 2903 } else 2904 vap->iv_flags &= ~IEEE80211_F_COUNTERM; 2905 /* XXX ERESTART? */ 2906 break; 2907 case IEEE80211_IOC_WPA: 2908 if (ireq->i_val > 3) 2909 return EINVAL; 2910 /* XXX verify ciphers available */ 2911 flags = vap->iv_flags & ~IEEE80211_F_WPA; 2912 switch (ireq->i_val) { 2913 case 0: 2914 /* wpa_supplicant calls this to clear the WPA config */ 2915 break; 2916 case 1: 2917 if (!(vap->iv_caps & IEEE80211_C_WPA1)) 2918 return EOPNOTSUPP; 2919 flags |= IEEE80211_F_WPA1; 2920 break; 2921 case 2: 2922 if (!(vap->iv_caps & IEEE80211_C_WPA2)) 2923 return EOPNOTSUPP; 2924 flags |= IEEE80211_F_WPA2; 2925 break; 2926 case 3: 2927 if ((vap->iv_caps & IEEE80211_C_WPA) != IEEE80211_C_WPA) 2928 return EOPNOTSUPP; 2929 flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2; 2930 break; 2931 default: /* Can't set any -> error */ 2932 return EOPNOTSUPP; 2933 } 2934 vap->iv_flags = flags; 2935 error = ERESTART; /* NB: can change beacon frame */ 2936 break; 2937 case IEEE80211_IOC_WME: 2938 if (ireq->i_val) { 2939 if ((vap->iv_caps & IEEE80211_C_WME) == 0) 2940 return EOPNOTSUPP; 2941 ieee80211_syncflag(vap, IEEE80211_F_WME); 2942 } else 2943 ieee80211_syncflag(vap, -IEEE80211_F_WME); 2944 error = ERESTART; /* NB: can change beacon frame */ 2945 break; 2946 case IEEE80211_IOC_HIDESSID: 2947 if (ireq->i_val) 2948 vap->iv_flags |= IEEE80211_F_HIDESSID; 2949 else 2950 vap->iv_flags &= ~IEEE80211_F_HIDESSID; 2951 error = ERESTART; /* XXX ENETRESET? */ 2952 break; 2953 case IEEE80211_IOC_APBRIDGE: 2954 if (ireq->i_val == 0) 2955 vap->iv_flags |= IEEE80211_F_NOBRIDGE; 2956 else 2957 vap->iv_flags &= ~IEEE80211_F_NOBRIDGE; 2958 break; 2959 case IEEE80211_IOC_BSSID: 2960 if (ireq->i_len != sizeof(tmpbssid)) 2961 return EINVAL; 2962 error = copyin(ireq->i_data, tmpbssid, ireq->i_len); 2963 if (error) 2964 break; 2965 IEEE80211_ADDR_COPY(vap->iv_des_bssid, tmpbssid); 2966 if (IEEE80211_ADDR_EQ(vap->iv_des_bssid, zerobssid)) 2967 vap->iv_flags &= ~IEEE80211_F_DESBSSID; 2968 else 2969 vap->iv_flags |= IEEE80211_F_DESBSSID; 2970 error = ENETRESET; 2971 break; 2972 case IEEE80211_IOC_CHANLIST: 2973 error = ieee80211_ioctl_setchanlist(vap, ireq); 2974 break; 2975 #define OLD_IEEE80211_IOC_SCAN_REQ 23 2976 #ifdef OLD_IEEE80211_IOC_SCAN_REQ 2977 case OLD_IEEE80211_IOC_SCAN_REQ: 2978 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, 2979 "%s: active scan request\n", __func__); 2980 /* 2981 * If we are in INIT state then the driver has never 2982 * had a chance to setup hardware state to do a scan; 2983 * use the state machine to get us up the SCAN state. 2984 * Otherwise just invoke the scan machinery to start 2985 * a one-time scan. 2986 */ 2987 if (vap->iv_state == IEEE80211_S_INIT) 2988 ieee80211_new_state(vap, IEEE80211_S_SCAN, 0); 2989 else 2990 (void) ieee80211_start_scan(vap, 2991 IEEE80211_SCAN_ACTIVE | 2992 IEEE80211_SCAN_NOPICK | 2993 IEEE80211_SCAN_ONCE, 2994 IEEE80211_SCAN_FOREVER, 0, 0, 2995 /* XXX use ioctl params */ 2996 vap->iv_des_nssid, vap->iv_des_ssid); 2997 break; 2998 #endif /* OLD_IEEE80211_IOC_SCAN_REQ */ 2999 case IEEE80211_IOC_SCAN_REQ: 3000 error = ieee80211_ioctl_scanreq(vap, ireq); 3001 break; 3002 case IEEE80211_IOC_SCAN_CANCEL: 3003 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, 3004 "%s: cancel scan\n", __func__); 3005 ieee80211_cancel_scan(vap); 3006 break; 3007 case IEEE80211_IOC_HTCONF: 3008 if (ireq->i_val & 1) 3009 ieee80211_syncflag_ht(vap, IEEE80211_FHT_HT); 3010 else 3011 ieee80211_syncflag_ht(vap, -IEEE80211_FHT_HT); 3012 if (ireq->i_val & 2) 3013 ieee80211_syncflag_ht(vap, IEEE80211_FHT_USEHT40); 3014 else 3015 ieee80211_syncflag_ht(vap, -IEEE80211_FHT_USEHT40); 3016 error = ENETRESET; 3017 break; 3018 case IEEE80211_IOC_ADDMAC: 3019 case IEEE80211_IOC_DELMAC: 3020 error = ieee80211_ioctl_macmac(vap, ireq); 3021 break; 3022 case IEEE80211_IOC_MACCMD: 3023 error = ieee80211_ioctl_setmaccmd(vap, ireq); 3024 break; 3025 case IEEE80211_IOC_STA_STATS: 3026 error = ieee80211_ioctl_setstastats(vap, ireq); 3027 break; 3028 case IEEE80211_IOC_STA_TXPOW: 3029 error = ieee80211_ioctl_setstatxpow(vap, ireq); 3030 break; 3031 case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */ 3032 case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */ 3033 case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */ 3034 case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */ 3035 case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */ 3036 case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only) */ 3037 error = ieee80211_ioctl_setwmeparam(vap, ireq); 3038 break; 3039 case IEEE80211_IOC_DTIM_PERIOD: 3040 if (vap->iv_opmode != IEEE80211_M_HOSTAP && 3041 vap->iv_opmode != IEEE80211_M_MBSS && 3042 vap->iv_opmode != IEEE80211_M_IBSS) 3043 return EINVAL; 3044 if (IEEE80211_DTIM_MIN <= ireq->i_val && 3045 ireq->i_val <= IEEE80211_DTIM_MAX) { 3046 vap->iv_dtim_period = ireq->i_val; 3047 error = ENETRESET; /* requires restart */ 3048 } else 3049 error = EINVAL; 3050 break; 3051 case IEEE80211_IOC_BEACON_INTERVAL: 3052 if (vap->iv_opmode != IEEE80211_M_HOSTAP && 3053 vap->iv_opmode != IEEE80211_M_MBSS && 3054 vap->iv_opmode != IEEE80211_M_IBSS) 3055 return EINVAL; 3056 if (IEEE80211_BINTVAL_MIN <= ireq->i_val && 3057 ireq->i_val <= IEEE80211_BINTVAL_MAX) { 3058 ic->ic_bintval = ireq->i_val; 3059 error = ENETRESET; /* requires restart */ 3060 } else 3061 error = EINVAL; 3062 break; 3063 case IEEE80211_IOC_PUREG: 3064 if (ireq->i_val) 3065 vap->iv_flags |= IEEE80211_F_PUREG; 3066 else 3067 vap->iv_flags &= ~IEEE80211_F_PUREG; 3068 /* NB: reset only if we're operating on an 11g channel */ 3069 if (isvap11g(vap)) 3070 error = ENETRESET; 3071 break; 3072 case IEEE80211_IOC_QUIET: 3073 vap->iv_quiet= ireq->i_val; 3074 break; 3075 case IEEE80211_IOC_QUIET_COUNT: 3076 vap->iv_quiet_count=ireq->i_val; 3077 break; 3078 case IEEE80211_IOC_QUIET_PERIOD: 3079 vap->iv_quiet_period=ireq->i_val; 3080 break; 3081 case IEEE80211_IOC_QUIET_OFFSET: 3082 vap->iv_quiet_offset=ireq->i_val; 3083 break; 3084 case IEEE80211_IOC_QUIET_DUR: 3085 if(ireq->i_val < vap->iv_bss->ni_intval) 3086 vap->iv_quiet_duration = ireq->i_val; 3087 else 3088 error = EINVAL; 3089 break; 3090 case IEEE80211_IOC_BGSCAN: 3091 if (ireq->i_val) { 3092 if ((vap->iv_caps & IEEE80211_C_BGSCAN) == 0) 3093 return EOPNOTSUPP; 3094 vap->iv_flags |= IEEE80211_F_BGSCAN; 3095 } else 3096 vap->iv_flags &= ~IEEE80211_F_BGSCAN; 3097 break; 3098 case IEEE80211_IOC_BGSCAN_IDLE: 3099 if (ireq->i_val >= IEEE80211_BGSCAN_IDLE_MIN) 3100 vap->iv_bgscanidle = ireq->i_val*hz/1000; 3101 else 3102 error = EINVAL; 3103 break; 3104 case IEEE80211_IOC_BGSCAN_INTERVAL: 3105 if (ireq->i_val >= IEEE80211_BGSCAN_INTVAL_MIN) 3106 vap->iv_bgscanintvl = ireq->i_val*hz; 3107 else 3108 error = EINVAL; 3109 break; 3110 case IEEE80211_IOC_SCANVALID: 3111 if (ireq->i_val >= IEEE80211_SCAN_VALID_MIN) 3112 vap->iv_scanvalid = ireq->i_val*hz; 3113 else 3114 error = EINVAL; 3115 break; 3116 case IEEE80211_IOC_FRAGTHRESHOLD: 3117 if ((vap->iv_caps & IEEE80211_C_TXFRAG) == 0 && 3118 ireq->i_val != IEEE80211_FRAG_MAX) 3119 return EOPNOTSUPP; 3120 if (!(IEEE80211_FRAG_MIN <= ireq->i_val && 3121 ireq->i_val <= IEEE80211_FRAG_MAX)) 3122 return EINVAL; 3123 vap->iv_fragthreshold = ireq->i_val; 3124 error = ERESTART; 3125 break; 3126 case IEEE80211_IOC_BURST: 3127 if (ireq->i_val) { 3128 if ((vap->iv_caps & IEEE80211_C_BURST) == 0) 3129 return EOPNOTSUPP; 3130 ieee80211_syncflag(vap, IEEE80211_F_BURST); 3131 } else 3132 ieee80211_syncflag(vap, -IEEE80211_F_BURST); 3133 error = ERESTART; 3134 break; 3135 case IEEE80211_IOC_BMISSTHRESHOLD: 3136 if (!(IEEE80211_HWBMISS_MIN <= ireq->i_val && 3137 ireq->i_val <= IEEE80211_HWBMISS_MAX)) 3138 return EINVAL; 3139 vap->iv_bmissthreshold = ireq->i_val; 3140 error = ERESTART; 3141 break; 3142 case IEEE80211_IOC_CURCHAN: 3143 error = ieee80211_ioctl_setcurchan(vap, ireq); 3144 break; 3145 case IEEE80211_IOC_SHORTGI: 3146 if (ireq->i_val) { 3147 #define IEEE80211_HTCAP_SHORTGI \ 3148 (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) 3149 if (((ireq->i_val ^ vap->iv_htcaps) & IEEE80211_HTCAP_SHORTGI) != 0) 3150 return EINVAL; 3151 if (ireq->i_val & IEEE80211_HTCAP_SHORTGI20) 3152 vap->iv_flags_ht |= IEEE80211_FHT_SHORTGI20; 3153 if (ireq->i_val & IEEE80211_HTCAP_SHORTGI40) 3154 vap->iv_flags_ht |= IEEE80211_FHT_SHORTGI40; 3155 #undef IEEE80211_HTCAP_SHORTGI 3156 } else 3157 vap->iv_flags_ht &= 3158 ~(IEEE80211_FHT_SHORTGI20 | IEEE80211_FHT_SHORTGI40); 3159 error = ERESTART; 3160 break; 3161 case IEEE80211_IOC_AMPDU: 3162 if (ireq->i_val && (vap->iv_htcaps & IEEE80211_HTC_AMPDU) == 0) 3163 return EINVAL; 3164 if (ireq->i_val & 1) 3165 vap->iv_flags_ht |= IEEE80211_FHT_AMPDU_TX; 3166 else 3167 vap->iv_flags_ht &= ~IEEE80211_FHT_AMPDU_TX; 3168 if (ireq->i_val & 2) 3169 vap->iv_flags_ht |= IEEE80211_FHT_AMPDU_RX; 3170 else 3171 vap->iv_flags_ht &= ~IEEE80211_FHT_AMPDU_RX; 3172 /* NB: reset only if we're operating on an 11n channel */ 3173 if (isvapht(vap)) 3174 error = ERESTART; 3175 break; 3176 case IEEE80211_IOC_AMPDU_LIMIT: 3177 /* XXX TODO: figure out ampdu_limit versus ampdu_rxmax */ 3178 if (!(IEEE80211_HTCAP_MAXRXAMPDU_8K <= ireq->i_val && 3179 ireq->i_val <= IEEE80211_HTCAP_MAXRXAMPDU_64K)) 3180 return EINVAL; 3181 if (vap->iv_opmode == IEEE80211_M_HOSTAP) 3182 vap->iv_ampdu_rxmax = ireq->i_val; 3183 else 3184 vap->iv_ampdu_limit = ireq->i_val; 3185 error = ERESTART; 3186 break; 3187 case IEEE80211_IOC_AMPDU_DENSITY: 3188 if (!(IEEE80211_HTCAP_MPDUDENSITY_NA <= ireq->i_val && 3189 ireq->i_val <= IEEE80211_HTCAP_MPDUDENSITY_16)) 3190 return EINVAL; 3191 vap->iv_ampdu_density = ireq->i_val; 3192 error = ERESTART; 3193 break; 3194 case IEEE80211_IOC_AMSDU: 3195 if (ireq->i_val && (vap->iv_htcaps & IEEE80211_HTC_AMSDU) == 0) 3196 return EINVAL; 3197 if (ireq->i_val & 1) 3198 vap->iv_flags_ht |= IEEE80211_FHT_AMSDU_TX; 3199 else 3200 vap->iv_flags_ht &= ~IEEE80211_FHT_AMSDU_TX; 3201 if (ireq->i_val & 2) 3202 vap->iv_flags_ht |= IEEE80211_FHT_AMSDU_RX; 3203 else 3204 vap->iv_flags_ht &= ~IEEE80211_FHT_AMSDU_RX; 3205 /* NB: reset only if we're operating on an 11n channel */ 3206 if (isvapht(vap)) 3207 error = ERESTART; 3208 break; 3209 case IEEE80211_IOC_AMSDU_LIMIT: 3210 /* XXX validate */ 3211 vap->iv_amsdu_limit = ireq->i_val; /* XXX truncation? */ 3212 break; 3213 case IEEE80211_IOC_PUREN: 3214 if (ireq->i_val) { 3215 if ((vap->iv_flags_ht & IEEE80211_FHT_HT) == 0) 3216 return EINVAL; 3217 vap->iv_flags_ht |= IEEE80211_FHT_PUREN; 3218 } else 3219 vap->iv_flags_ht &= ~IEEE80211_FHT_PUREN; 3220 /* NB: reset only if we're operating on an 11n channel */ 3221 if (isvapht(vap)) 3222 error = ERESTART; 3223 break; 3224 case IEEE80211_IOC_DOTH: 3225 if (ireq->i_val) { 3226 #if 0 3227 /* XXX no capability */ 3228 if ((vap->iv_caps & IEEE80211_C_DOTH) == 0) 3229 return EOPNOTSUPP; 3230 #endif 3231 vap->iv_flags |= IEEE80211_F_DOTH; 3232 } else 3233 vap->iv_flags &= ~IEEE80211_F_DOTH; 3234 error = ENETRESET; 3235 break; 3236 case IEEE80211_IOC_REGDOMAIN: 3237 error = ieee80211_ioctl_setregdomain(vap, ireq); 3238 break; 3239 case IEEE80211_IOC_ROAM: 3240 error = ieee80211_ioctl_setroam(vap, ireq); 3241 break; 3242 case IEEE80211_IOC_TXPARAMS: 3243 error = ieee80211_ioctl_settxparams(vap, ireq); 3244 break; 3245 case IEEE80211_IOC_HTCOMPAT: 3246 if (ireq->i_val) { 3247 if ((vap->iv_flags_ht & IEEE80211_FHT_HT) == 0) 3248 return EOPNOTSUPP; 3249 vap->iv_flags_ht |= IEEE80211_FHT_HTCOMPAT; 3250 } else 3251 vap->iv_flags_ht &= ~IEEE80211_FHT_HTCOMPAT; 3252 /* NB: reset only if we're operating on an 11n channel */ 3253 if (isvapht(vap)) 3254 error = ERESTART; 3255 break; 3256 case IEEE80211_IOC_DWDS: 3257 if (ireq->i_val) { 3258 /* NB: DWDS only makes sense for WDS-capable devices */ 3259 if ((ic->ic_caps & IEEE80211_C_WDS) == 0) 3260 return EOPNOTSUPP; 3261 /* NB: DWDS is used only with ap+sta vaps */ 3262 if (vap->iv_opmode != IEEE80211_M_HOSTAP && 3263 vap->iv_opmode != IEEE80211_M_STA) 3264 return EINVAL; 3265 vap->iv_flags |= IEEE80211_F_DWDS; 3266 if (vap->iv_opmode == IEEE80211_M_STA) 3267 vap->iv_flags_ext |= IEEE80211_FEXT_4ADDR; 3268 } else { 3269 vap->iv_flags &= ~IEEE80211_F_DWDS; 3270 if (vap->iv_opmode == IEEE80211_M_STA) 3271 vap->iv_flags_ext &= ~IEEE80211_FEXT_4ADDR; 3272 } 3273 break; 3274 case IEEE80211_IOC_INACTIVITY: 3275 if (ireq->i_val) 3276 vap->iv_flags_ext |= IEEE80211_FEXT_INACT; 3277 else 3278 vap->iv_flags_ext &= ~IEEE80211_FEXT_INACT; 3279 break; 3280 case IEEE80211_IOC_APPIE: 3281 error = ieee80211_ioctl_setappie(vap, ireq); 3282 break; 3283 case IEEE80211_IOC_WPS: 3284 if (ireq->i_val) { 3285 if ((vap->iv_caps & IEEE80211_C_WPA) == 0) 3286 return EOPNOTSUPP; 3287 vap->iv_flags_ext |= IEEE80211_FEXT_WPS; 3288 } else 3289 vap->iv_flags_ext &= ~IEEE80211_FEXT_WPS; 3290 break; 3291 case IEEE80211_IOC_TSN: 3292 if (ireq->i_val) { 3293 if ((vap->iv_caps & IEEE80211_C_WPA) == 0) 3294 return EOPNOTSUPP; 3295 vap->iv_flags_ext |= IEEE80211_FEXT_TSN; 3296 } else 3297 vap->iv_flags_ext &= ~IEEE80211_FEXT_TSN; 3298 break; 3299 case IEEE80211_IOC_CHANSWITCH: 3300 error = ieee80211_ioctl_chanswitch(vap, ireq); 3301 break; 3302 case IEEE80211_IOC_DFS: 3303 if (ireq->i_val) { 3304 if ((vap->iv_caps & IEEE80211_C_DFS) == 0) 3305 return EOPNOTSUPP; 3306 /* NB: DFS requires 11h support */ 3307 if ((vap->iv_flags & IEEE80211_F_DOTH) == 0) 3308 return EINVAL; 3309 vap->iv_flags_ext |= IEEE80211_FEXT_DFS; 3310 } else 3311 vap->iv_flags_ext &= ~IEEE80211_FEXT_DFS; 3312 break; 3313 case IEEE80211_IOC_DOTD: 3314 if (ireq->i_val) 3315 vap->iv_flags_ext |= IEEE80211_FEXT_DOTD; 3316 else 3317 vap->iv_flags_ext &= ~IEEE80211_FEXT_DOTD; 3318 if (vap->iv_opmode == IEEE80211_M_STA) 3319 error = ENETRESET; 3320 break; 3321 case IEEE80211_IOC_HTPROTMODE: 3322 if (ireq->i_val > IEEE80211_PROT_RTSCTS) 3323 return EINVAL; 3324 ic->ic_htprotmode = ireq->i_val ? 3325 IEEE80211_PROT_RTSCTS : IEEE80211_PROT_NONE; 3326 /* NB: if not operating in 11n this can wait */ 3327 if (isvapht(vap)) 3328 error = ERESTART; 3329 break; 3330 case IEEE80211_IOC_STA_VLAN: 3331 error = ieee80211_ioctl_setstavlan(vap, ireq); 3332 break; 3333 case IEEE80211_IOC_SMPS: 3334 if ((ireq->i_val &~ IEEE80211_HTCAP_SMPS) != 0 || 3335 ireq->i_val == 0x0008) /* value of 2 is reserved */ 3336 return EINVAL; 3337 if (ireq->i_val != IEEE80211_HTCAP_SMPS_OFF && 3338 (vap->iv_htcaps & IEEE80211_HTC_SMPS) == 0) 3339 return EOPNOTSUPP; 3340 vap->iv_htcaps = (vap->iv_htcaps &~ IEEE80211_HTCAP_SMPS) | 3341 ireq->i_val; 3342 /* NB: if not operating in 11n this can wait */ 3343 if (isvapht(vap)) 3344 error = ERESTART; 3345 break; 3346 case IEEE80211_IOC_RIFS: 3347 if (ireq->i_val != 0) { 3348 if ((vap->iv_htcaps & IEEE80211_HTC_RIFS) == 0) 3349 return EOPNOTSUPP; 3350 vap->iv_flags_ht |= IEEE80211_FHT_RIFS; 3351 } else 3352 vap->iv_flags_ht &= ~IEEE80211_FHT_RIFS; 3353 /* NB: if not operating in 11n this can wait */ 3354 if (isvapht(vap)) 3355 error = ERESTART; 3356 break; 3357 case IEEE80211_IOC_STBC: 3358 /* Check if we can do STBC TX/RX before changing the setting */ 3359 if ((ireq->i_val & 1) && 3360 ((vap->iv_htcaps & IEEE80211_HTCAP_TXSTBC) == 0)) 3361 return EOPNOTSUPP; 3362 if ((ireq->i_val & 2) && 3363 ((vap->iv_htcaps & IEEE80211_HTCAP_RXSTBC) == 0)) 3364 return EOPNOTSUPP; 3365 3366 /* TX */ 3367 if (ireq->i_val & 1) 3368 vap->iv_flags_ht |= IEEE80211_FHT_STBC_TX; 3369 else 3370 vap->iv_flags_ht &= ~IEEE80211_FHT_STBC_TX; 3371 3372 /* RX */ 3373 if (ireq->i_val & 2) 3374 vap->iv_flags_ht |= IEEE80211_FHT_STBC_RX; 3375 else 3376 vap->iv_flags_ht &= ~IEEE80211_FHT_STBC_RX; 3377 3378 /* NB: reset only if we're operating on an 11n channel */ 3379 if (isvapht(vap)) 3380 error = ERESTART; 3381 break; 3382 case IEEE80211_IOC_LDPC: 3383 /* Check if we can do LDPC TX/RX before changing the setting */ 3384 if ((ireq->i_val & 1) && 3385 (vap->iv_htcaps & IEEE80211_HTC_TXLDPC) == 0) 3386 return EOPNOTSUPP; 3387 if ((ireq->i_val & 2) && 3388 (vap->iv_htcaps & IEEE80211_HTCAP_LDPC) == 0) 3389 return EOPNOTSUPP; 3390 3391 /* TX */ 3392 if (ireq->i_val & 1) 3393 vap->iv_flags_ht |= IEEE80211_FHT_LDPC_TX; 3394 else 3395 vap->iv_flags_ht &= ~IEEE80211_FHT_LDPC_TX; 3396 3397 /* RX */ 3398 if (ireq->i_val & 2) 3399 vap->iv_flags_ht |= IEEE80211_FHT_LDPC_RX; 3400 else 3401 vap->iv_flags_ht &= ~IEEE80211_FHT_LDPC_RX; 3402 3403 /* NB: reset only if we're operating on an 11n channel */ 3404 if (isvapht(vap)) 3405 error = ERESTART; 3406 break; 3407 3408 /* VHT */ 3409 case IEEE80211_IOC_VHTCONF: 3410 if (ireq->i_val & 1) 3411 ieee80211_syncflag_vht(vap, IEEE80211_FVHT_VHT); 3412 else 3413 ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_VHT); 3414 3415 if (ireq->i_val & 2) 3416 ieee80211_syncflag_vht(vap, IEEE80211_FVHT_USEVHT40); 3417 else 3418 ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_USEVHT40); 3419 3420 if (ireq->i_val & 4) 3421 ieee80211_syncflag_vht(vap, IEEE80211_FVHT_USEVHT80); 3422 else 3423 ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_USEVHT80); 3424 3425 if (ireq->i_val & 8) 3426 ieee80211_syncflag_vht(vap, IEEE80211_FVHT_USEVHT80P80); 3427 else 3428 ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_USEVHT80P80); 3429 3430 if (ireq->i_val & 16) 3431 ieee80211_syncflag_vht(vap, IEEE80211_FVHT_USEVHT160); 3432 else 3433 ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_USEVHT160); 3434 3435 error = ENETRESET; 3436 break; 3437 3438 default: 3439 error = ieee80211_ioctl_setdefault(vap, ireq); 3440 break; 3441 } 3442 /* 3443 * The convention is that ENETRESET means an operation 3444 * requires a complete re-initialization of the device (e.g. 3445 * changing something that affects the association state). 3446 * ERESTART means the request may be handled with only a 3447 * reload of the hardware state. We hand ERESTART requests 3448 * to the iv_reset callback so the driver can decide. If 3449 * a device does not fillin iv_reset then it defaults to one 3450 * that returns ENETRESET. Otherwise a driver may return 3451 * ENETRESET (in which case a full reset will be done) or 3452 * 0 to mean there's no need to do anything (e.g. when the 3453 * change has no effect on the driver/device). 3454 */ 3455 if (error == ERESTART) 3456 error = IFNET_IS_UP_RUNNING(vap->iv_ifp) ? 3457 vap->iv_reset(vap, ireq->i_type) : 0; 3458 if (error == ENETRESET) { 3459 /* XXX need to re-think AUTO handling */ 3460 if (IS_UP_AUTO(vap)) 3461 ieee80211_init(vap); 3462 error = 0; 3463 } 3464 return error; 3465 } 3466 3467 int 3468 ieee80211_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) 3469 { 3470 struct ieee80211vap *vap = ifp->if_softc; 3471 struct ieee80211com *ic = vap->iv_ic; 3472 int error = 0, wait = 0; 3473 struct ifreq *ifr; 3474 struct ifaddr *ifa; /* XXX */ 3475 3476 switch (cmd) { 3477 case SIOCSIFFLAGS: 3478 IEEE80211_LOCK(ic); 3479 if ((ifp->if_flags ^ vap->iv_ifflags) & IFF_PROMISC) { 3480 /* 3481 * Enable promiscuous mode when: 3482 * 1. Interface is not a member of bridge, or 3483 * 2. Requested by user, or 3484 * 3. In monitor (or adhoc-demo) mode. 3485 */ 3486 if (ifp->if_bridge == NULL || 3487 (ifp->if_flags & IFF_PPROMISC) != 0 || 3488 vap->iv_opmode == IEEE80211_M_MONITOR || 3489 (vap->iv_opmode == IEEE80211_M_AHDEMO && 3490 (vap->iv_caps & IEEE80211_C_TDMA) == 0)) { 3491 ieee80211_promisc(vap, 3492 ifp->if_flags & IFF_PROMISC); 3493 vap->iv_ifflags ^= IFF_PROMISC; 3494 } 3495 } 3496 if ((ifp->if_flags ^ vap->iv_ifflags) & IFF_ALLMULTI) { 3497 ieee80211_allmulti(vap, ifp->if_flags & IFF_ALLMULTI); 3498 vap->iv_ifflags ^= IFF_ALLMULTI; 3499 } 3500 if (ifp->if_flags & IFF_UP) { 3501 /* 3502 * Bring ourself up unless we're already operational. 3503 * If we're the first vap and the parent is not up 3504 * then it will automatically be brought up as a 3505 * side-effect of bringing ourself up. 3506 */ 3507 if (vap->iv_state == IEEE80211_S_INIT) { 3508 if (ic->ic_nrunning == 0) 3509 wait = 1; 3510 ieee80211_start_locked(vap); 3511 } 3512 } else if (ifp->if_drv_flags & IFF_DRV_RUNNING) { 3513 /* 3514 * Stop ourself. If we are the last vap to be 3515 * marked down the parent will also be taken down. 3516 */ 3517 if (ic->ic_nrunning == 1) 3518 wait = 1; 3519 ieee80211_stop_locked(vap); 3520 } 3521 IEEE80211_UNLOCK(ic); 3522 /* Wait for parent ioctl handler if it was queued */ 3523 if (wait) { 3524 ieee80211_waitfor_parent(ic); 3525 3526 /* 3527 * Check if the MAC address was changed 3528 * via SIOCSIFLLADDR ioctl. 3529 */ 3530 if_addr_rlock(ifp); 3531 if ((ifp->if_flags & IFF_UP) == 0 && 3532 !IEEE80211_ADDR_EQ(vap->iv_myaddr, IF_LLADDR(ifp))) 3533 IEEE80211_ADDR_COPY(vap->iv_myaddr, 3534 IF_LLADDR(ifp)); 3535 if_addr_runlock(ifp); 3536 } 3537 break; 3538 case SIOCADDMULTI: 3539 case SIOCDELMULTI: 3540 ieee80211_runtask(ic, &ic->ic_mcast_task); 3541 break; 3542 case SIOCSIFMEDIA: 3543 case SIOCGIFMEDIA: 3544 ifr = (struct ifreq *)data; 3545 error = ifmedia_ioctl(ifp, ifr, &vap->iv_media, cmd); 3546 break; 3547 case SIOCG80211: 3548 error = ieee80211_ioctl_get80211(vap, cmd, 3549 (struct ieee80211req *) data); 3550 break; 3551 case SIOCS80211: 3552 error = priv_check(curthread, PRIV_NET80211_MANAGE); 3553 if (error == 0) 3554 error = ieee80211_ioctl_set80211(vap, cmd, 3555 (struct ieee80211req *) data); 3556 break; 3557 case SIOCG80211STATS: 3558 ifr = (struct ifreq *)data; 3559 copyout(&vap->iv_stats, ifr->ifr_data, sizeof (vap->iv_stats)); 3560 break; 3561 case SIOCSIFMTU: 3562 ifr = (struct ifreq *)data; 3563 if (!(IEEE80211_MTU_MIN <= ifr->ifr_mtu && 3564 ifr->ifr_mtu <= IEEE80211_MTU_MAX)) 3565 error = EINVAL; 3566 else 3567 ifp->if_mtu = ifr->ifr_mtu; 3568 break; 3569 case SIOCSIFADDR: 3570 /* 3571 * XXX Handle this directly so we can suppress if_init calls. 3572 * XXX This should be done in ether_ioctl but for the moment 3573 * XXX there are too many other parts of the system that 3574 * XXX set IFF_UP and so suppress if_init being called when 3575 * XXX it should be. 3576 */ 3577 ifa = (struct ifaddr *) data; 3578 switch (ifa->ifa_addr->sa_family) { 3579 #ifdef INET 3580 case AF_INET: 3581 if ((ifp->if_flags & IFF_UP) == 0) { 3582 ifp->if_flags |= IFF_UP; 3583 ifp->if_init(ifp->if_softc); 3584 } 3585 arp_ifinit(ifp, ifa); 3586 break; 3587 #endif 3588 default: 3589 if ((ifp->if_flags & IFF_UP) == 0) { 3590 ifp->if_flags |= IFF_UP; 3591 ifp->if_init(ifp->if_softc); 3592 } 3593 break; 3594 } 3595 break; 3596 default: 3597 /* 3598 * Pass unknown ioctls first to the driver, and if it 3599 * returns ENOTTY, then to the generic Ethernet handler. 3600 */ 3601 if (ic->ic_ioctl != NULL && 3602 (error = ic->ic_ioctl(ic, cmd, data)) != ENOTTY) 3603 break; 3604 error = ether_ioctl(ifp, cmd, data); 3605 break; 3606 } 3607 return (error); 3608 } 3609