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