2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * Alternatively, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2 as published by the Free
19 * Software Foundation.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * $FreeBSD: src/sys/net80211/ieee80211_ioctl.c,v 1.25.2.11 2006/02/28 02:02:43 sam Exp $
33 * $DragonFly: src/sys/netproto/802_11/wlan/ieee80211_ioctl.c,v 1.4 2006/09/05 00:55:48 dillon Exp $
37 * IEEE 802.11 ioctl support (DragonFlyBSD-specific)
43 #include <sys/endian.h>
44 #include <sys/param.h>
45 #include <sys/kernel.h>
47 #include <sys/socket.h>
48 #include <sys/sockio.h>
49 #include <sys/systm.h>
52 #include <net/if_arp.h>
53 #include <net/if_dl.h>
54 #include <net/if_media.h>
55 #include <net/ethernet.h>
58 #include <netinet/in.h>
59 #include <netinet/if_ether.h>
63 #include <netproto/ipx/ipx.h>
64 #include <netproto/ipx/ipx_if.h>
67 #include <netproto/802_11/ieee80211_var.h>
68 #include <netproto/802_11/ieee80211_ioctl.h>
70 #include <netproto/802_11/if_wavelan_ieee.h>
73 (((_ic)->ic_ifp->if_flags & (IFF_UP | IFF_RUNNING)) == \
74 (IFF_UP | IFF_RUNNING))
76 #define IS_UP_AUTO(_ic) \
77 (IS_UP(_ic) && (_ic)->ic_roaming == IEEE80211_ROAMING_AUTO)
81 * Wireless LAN specific configuration interface, which is compatible
85 struct wi_read_ap_args {
86 int i; /* result count */
87 struct wi_apinfo *ap; /* current entry in result buffer */
88 caddr_t max; /* result buffer bound */
92 wi_read_ap_result(void *arg, struct ieee80211_node *ni)
94 struct ieee80211com *ic = ni->ni_ic;
95 struct wi_read_ap_args *sa = arg;
96 struct wi_apinfo *ap = sa->ap;
97 struct ieee80211_rateset *rs;
100 if ((caddr_t)(ap + 1) > sa->max)
102 memset(ap, 0, sizeof(struct wi_apinfo));
103 if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
104 IEEE80211_ADDR_COPY(ap->bssid, ni->ni_macaddr);
105 ap->namelen = ic->ic_des_esslen;
106 if (ic->ic_des_esslen)
107 memcpy(ap->name, ic->ic_des_essid,
110 IEEE80211_ADDR_COPY(ap->bssid, ni->ni_bssid);
111 ap->namelen = ni->ni_esslen;
113 memcpy(ap->name, ni->ni_essid,
116 ap->channel = ieee80211_chan2ieee(ic, ni->ni_chan);
117 ap->signal = ic->ic_node_getrssi(ni);
118 ap->capinfo = ni->ni_capinfo;
119 ap->interval = ni->ni_intval;
121 for (j = 0; j < rs->rs_nrates; j++) {
122 if (rs->rs_rates[j] & IEEE80211_RATE_BASIC) {
123 ap->rate = (rs->rs_rates[j] &
124 IEEE80211_RATE_VAL) * 5; /* XXX */
131 struct wi_read_prism2_args {
132 int i; /* result count */
133 struct wi_scan_res *res;/* current entry in result buffer */
134 caddr_t max; /* result buffer bound */
138 wi_read_prism2_result(void *arg, struct ieee80211_node *ni)
140 struct ieee80211com *ic = ni->ni_ic;
141 struct wi_read_prism2_args *sa = arg;
142 struct wi_scan_res *res = sa->res;
144 if ((caddr_t)(res + 1) > sa->max)
146 res->wi_chan = ieee80211_chan2ieee(ic, ni->ni_chan);
148 res->wi_signal = ic->ic_node_getrssi(ni);
149 IEEE80211_ADDR_COPY(res->wi_bssid, ni->ni_bssid);
150 res->wi_interval = ni->ni_intval;
151 res->wi_capinfo = ni->ni_capinfo;
152 res->wi_ssid_len = ni->ni_esslen;
153 memcpy(res->wi_ssid, ni->ni_essid, IEEE80211_NWID_LEN);
154 /* NB: assumes wi_srates holds <= ni->ni_rates */
155 memcpy(res->wi_srates, ni->ni_rates.rs_rates,
156 sizeof(res->wi_srates));
157 if (ni->ni_rates.rs_nrates < 10)
158 res->wi_srates[ni->ni_rates.rs_nrates] = 0;
159 res->wi_rate = ni->ni_rates.rs_rates[ni->ni_txrate];
166 struct wi_read_sigcache_args {
167 int i; /* result count */
168 struct wi_sigcache *wsc;/* current entry in result buffer */
169 caddr_t max; /* result buffer bound */
173 wi_read_sigcache(void *arg, struct ieee80211_node *ni)
175 struct ieee80211com *ic = ni->ni_ic;
176 struct wi_read_sigcache_args *sa = arg;
177 struct wi_sigcache *wsc = sa->wsc;
179 if ((caddr_t)(wsc + 1) > sa->max)
181 memset(wsc, 0, sizeof(struct wi_sigcache));
182 IEEE80211_ADDR_COPY(wsc->macsrc, ni->ni_macaddr);
183 wsc->signal = ic->ic_node_getrssi(ni);
190 ieee80211_cfgget(struct ieee80211com *ic, u_long cmd, caddr_t data,
193 struct ifnet *ifp = ic->ic_ifp;
195 struct ifreq *ifr = (struct ifreq *)data;
197 struct wi_ltv_keys *keys;
199 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
203 switch (wreq.wi_type) {
204 case WI_RID_SERIALNO:
205 /* nothing appropriate */
207 case WI_RID_NODENAME:
208 strcpy((char *)&wreq.wi_val[1], hostname);
209 wreq.wi_val[0] = htole16(strlen(hostname));
210 wreq.wi_len = (1 + strlen(hostname) + 1) / 2;
212 case WI_RID_CURRENT_SSID:
213 if (ic->ic_state != IEEE80211_S_RUN) {
218 wreq.wi_val[0] = htole16(ic->ic_bss->ni_esslen);
219 memcpy(&wreq.wi_val[1], ic->ic_bss->ni_essid,
220 ic->ic_bss->ni_esslen);
221 wreq.wi_len = (1 + ic->ic_bss->ni_esslen + 1) / 2;
223 case WI_RID_OWN_SSID:
224 case WI_RID_DESIRED_SSID:
225 wreq.wi_val[0] = htole16(ic->ic_des_esslen);
226 memcpy(&wreq.wi_val[1], ic->ic_des_essid, ic->ic_des_esslen);
227 wreq.wi_len = (1 + ic->ic_des_esslen + 1) / 2;
229 case WI_RID_CURRENT_BSSID:
230 if (ic->ic_state == IEEE80211_S_RUN)
231 IEEE80211_ADDR_COPY(wreq.wi_val, ic->ic_bss->ni_bssid);
233 memset(wreq.wi_val, 0, IEEE80211_ADDR_LEN);
234 wreq.wi_len = IEEE80211_ADDR_LEN / 2;
236 case WI_RID_CHANNEL_LIST:
237 memset(wreq.wi_val, 0, sizeof(wreq.wi_val));
239 * Since channel 0 is not available for DS, channel 1
240 * is assigned to LSB on WaveLAN.
242 if (ic->ic_phytype == IEEE80211_T_DS)
246 for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++)
247 if (isset(ic->ic_chan_active, i)) {
248 setbit((uint8_t *)wreq.wi_val, j);
249 wreq.wi_len = j / 16 + 1;
252 case WI_RID_OWN_CHNL:
253 wreq.wi_val[0] = htole16(
254 ieee80211_chan2ieee(ic, ic->ic_ibss_chan));
257 case WI_RID_CURRENT_CHAN:
258 wreq.wi_val[0] = htole16(
259 ieee80211_chan2ieee(ic, ic->ic_curchan));
262 case WI_RID_COMMS_QUALITY:
263 wreq.wi_val[0] = 0; /* quality */
264 wreq.wi_val[1] = htole16(ic->ic_node_getrssi(ic->ic_bss));
265 wreq.wi_val[2] = 0; /* noise */
269 wreq.wi_val[0] = htole16((ifp->if_flags & IFF_PROMISC) ? 1 : 0);
272 case WI_RID_PORTTYPE:
273 wreq.wi_val[0] = htole16(ic->ic_opmode);
276 case WI_RID_MAC_NODE:
277 IEEE80211_ADDR_COPY(wreq.wi_val, ic->ic_myaddr);
278 wreq.wi_len = IEEE80211_ADDR_LEN / 2;
281 if (ic->ic_fixed_rate == IEEE80211_FIXED_RATE_NONE)
282 wreq.wi_val[0] = 0; /* auto */
284 wreq.wi_val[0] = htole16(
285 (ic->ic_sup_rates[ic->ic_curmode].rs_rates[ic->ic_fixed_rate] &
286 IEEE80211_RATE_VAL) / 2);
289 case WI_RID_CUR_TX_RATE:
290 wreq.wi_val[0] = htole16(
291 (ic->ic_bss->ni_rates.rs_rates[ic->ic_bss->ni_txrate] &
292 IEEE80211_RATE_VAL) / 2);
295 case WI_RID_RTS_THRESH:
296 wreq.wi_val[0] = htole16(ic->ic_rtsthreshold);
299 case WI_RID_CREATE_IBSS:
301 htole16((ic->ic_flags & IEEE80211_F_IBSSON) ? 1 : 0);
304 case WI_RID_MICROWAVE_OVEN:
305 wreq.wi_val[0] = 0; /* no ... not supported */
308 case WI_RID_ROAMING_MODE:
309 wreq.wi_val[0] = htole16(ic->ic_roaming); /* XXX map */
312 case WI_RID_SYSTEM_SCALE:
313 wreq.wi_val[0] = htole16(1); /* low density ... not supp */
316 case WI_RID_PM_ENABLED:
318 htole16((ic->ic_flags & IEEE80211_F_PMGTON) ? 1 : 0);
321 case WI_RID_MAX_SLEEP:
322 wreq.wi_val[0] = htole16(ic->ic_lintval);
325 case WI_RID_CUR_BEACON_INT:
326 wreq.wi_val[0] = htole16(ic->ic_bss->ni_intval);
329 case WI_RID_WEP_AVAIL:
330 wreq.wi_val[0] = htole16(1); /* always available */
333 case WI_RID_CNFAUTHMODE:
334 wreq.wi_val[0] = htole16(1); /* TODO: open system only */
337 case WI_RID_ENCRYPTION:
339 htole16((ic->ic_flags & IEEE80211_F_PRIVACY) ? 1 : 0);
342 case WI_RID_TX_CRYPT_KEY:
343 wreq.wi_val[0] = htole16(ic->ic_def_txkey);
346 case WI_RID_DEFLT_CRYPT_KEYS:
347 keys = (struct wi_ltv_keys *)&wreq;
348 /* do not show keys to non-root user */
349 error = suser_cred(cr, NULL_CRED_OKAY);
351 memset(keys, 0, sizeof(*keys));
355 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
356 keys->wi_keys[i].wi_keylen =
357 htole16(ic->ic_nw_keys[i].wk_keylen);
358 memcpy(keys->wi_keys[i].wi_keydat,
359 ic->ic_nw_keys[i].wk_key,
360 ic->ic_nw_keys[i].wk_keylen);
362 wreq.wi_len = sizeof(*keys) / 2;
364 case WI_RID_MAX_DATALEN:
365 wreq.wi_val[0] = htole16(ic->ic_fragthreshold);
368 case WI_RID_IFACE_STATS:
369 /* XXX: should be implemented in lower drivers */
371 case WI_RID_READ_APS:
373 * Don't return results until active scan completes.
375 if ((ic->ic_flags & (IEEE80211_F_SCAN|IEEE80211_F_ASCAN)) == 0) {
376 struct wi_read_ap_args args;
379 args.ap = (void *)((char *)wreq.wi_val + sizeof(i));
380 args.max = (void *)(&wreq + 1);
381 ieee80211_iterate_nodes(&ic->ic_scan,
382 wi_read_ap_result, &args);
383 memcpy(wreq.wi_val, &args.i, sizeof(args.i));
384 wreq.wi_len = (sizeof(int) +
385 sizeof(struct wi_apinfo) * args.i) / 2;
390 /* NB: we lie so WI_RID_SCAN_RES can include rates */
392 wreq.wi_len = sizeof(uint16_t) / 2;
394 case WI_RID_SCAN_RES: /* compatibility interface */
395 if ((ic->ic_flags & (IEEE80211_F_SCAN|IEEE80211_F_ASCAN)) == 0) {
396 struct wi_read_prism2_args args;
397 struct wi_scan_p2_hdr *p2;
399 /* NB: use Prism2 format so we can include rate info */
400 p2 = (struct wi_scan_p2_hdr *)wreq.wi_val;
402 args.res = (void *)&p2[1];
403 args.max = (void *)(&wreq + 1);
404 ieee80211_iterate_nodes(&ic->ic_scan,
405 wi_read_prism2_result, &args);
407 p2->wi_reason = args.i;
408 wreq.wi_len = (sizeof(*p2) +
409 sizeof(struct wi_scan_res) * args.i) / 2;
413 case WI_RID_READ_CACHE: {
414 struct wi_read_sigcache_args args;
416 args.wsc = (struct wi_sigcache *) wreq.wi_val;
417 args.max = (void *)(&wreq + 1);
418 ieee80211_iterate_nodes(&ic->ic_scan, wi_read_sigcache, &args);
419 wreq.wi_len = sizeof(struct wi_sigcache) * args.i / 2;
428 error = copyout(&wreq, ifr->ifr_data, sizeof(wreq));
434 findrate(struct ieee80211com *ic, enum ieee80211_phymode mode, int rate)
436 #define IEEERATE(_ic,_m,_i) \
437 ((_ic)->ic_sup_rates[_m].rs_rates[_i] & IEEE80211_RATE_VAL)
438 int i, nrates = ic->ic_sup_rates[mode].rs_nrates;
439 for (i = 0; i < nrates; i++)
440 if (IEEERATE(ic, mode, i) == rate)
447 * Prepare to do a user-initiated scan for AP's. If no
448 * current/default channel is setup or the current channel
449 * is invalid then pick the first available channel from
450 * the active list as the place to start the scan.
453 ieee80211_setupscan(struct ieee80211com *ic, const uint8_t chanlist[])
457 * XXX don't permit a scan to be started unless we
458 * know the device is ready. For the moment this means
459 * the device is marked up as this is the required to
460 * initialize the hardware. It would be better to permit
461 * scanning prior to being up but that'll require some
462 * changes to the infrastructure.
466 memcpy(ic->ic_chan_active, chanlist, sizeof(ic->ic_chan_active));
468 * We force the state to INIT before calling ieee80211_new_state
469 * to get ieee80211_begin_scan called. We really want to scan w/o
470 * altering the current state but that's not possible right now.
472 /* XXX handle proberequest case */
473 ic->ic_state = IEEE80211_S_INIT; /* XXX bypass state machine */
478 ieee80211_cfgset(struct ieee80211com *ic, u_long cmd, caddr_t data)
480 struct ifnet *ifp = ic->ic_ifp;
481 int i, j, len, error, rate;
482 struct ifreq *ifr = (struct ifreq *)data;
483 struct wi_ltv_keys *keys;
485 u_char chanlist[roundup(IEEE80211_CHAN_MAX, NBBY)];
487 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
490 len = wreq.wi_len ? (wreq.wi_len - 1) * 2 : 0;
491 switch (wreq.wi_type) {
492 case WI_RID_SERIALNO:
493 case WI_RID_NODENAME:
495 case WI_RID_CURRENT_SSID:
497 case WI_RID_OWN_SSID:
498 case WI_RID_DESIRED_SSID:
499 if (le16toh(wreq.wi_val[0]) * 2 > len ||
500 le16toh(wreq.wi_val[0]) > IEEE80211_NWID_LEN) {
504 memset(ic->ic_des_essid, 0, sizeof(ic->ic_des_essid));
505 ic->ic_des_esslen = le16toh(wreq.wi_val[0]) * 2;
506 memcpy(ic->ic_des_essid, &wreq.wi_val[1], ic->ic_des_esslen);
509 case WI_RID_CURRENT_BSSID:
511 case WI_RID_OWN_CHNL:
514 i = le16toh(wreq.wi_val[0]);
516 i > IEEE80211_CHAN_MAX ||
517 isclr(ic->ic_chan_active, i))
519 ic->ic_ibss_chan = &ic->ic_channels[i];
520 if (ic->ic_opmode == IEEE80211_M_MONITOR)
521 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
525 case WI_RID_CURRENT_CHAN:
527 case WI_RID_COMMS_QUALITY:
532 if (ifp->if_flags & IFF_PROMISC) {
533 if (wreq.wi_val[0] == 0) {
534 ifp->if_flags &= ~IFF_PROMISC;
538 if (wreq.wi_val[0] != 0) {
539 ifp->if_flags |= IFF_PROMISC;
544 case WI_RID_PORTTYPE:
547 switch (le16toh(wreq.wi_val[0])) {
548 case IEEE80211_M_STA:
550 case IEEE80211_M_IBSS:
551 if (!(ic->ic_caps & IEEE80211_C_IBSS))
554 case IEEE80211_M_AHDEMO:
555 if (ic->ic_phytype != IEEE80211_T_DS ||
556 !(ic->ic_caps & IEEE80211_C_AHDEMO))
559 case IEEE80211_M_HOSTAP:
560 if (!(ic->ic_caps & IEEE80211_C_HOSTAP))
566 if (le16toh(wreq.wi_val[0]) != ic->ic_opmode) {
567 ic->ic_opmode = le16toh(wreq.wi_val[0]);
568 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
572 case WI_RID_MAC_NODE:
573 if (len != IEEE80211_ADDR_LEN)
575 IEEE80211_ADDR_COPY(LLADDR(ifp->if_sadl), wreq.wi_val);
576 /* if_init will copy lladdr into ic_myaddr */
583 if (wreq.wi_val[0] == 0) {
585 ic->ic_fixed_rate = IEEE80211_FIXED_RATE_NONE;
588 rate = 2 * le16toh(wreq.wi_val[0]);
589 if (ic->ic_curmode == IEEE80211_MODE_AUTO) {
591 * In autoselect mode search for the rate. We take
592 * the first instance which may not be right, but we
593 * are limited by the interface. Note that we also
594 * lock the mode to insure the rate is meaningful
597 for (j = IEEE80211_MODE_11A;
598 j < IEEE80211_MODE_MAX; j++) {
599 if ((ic->ic_modecaps & (1<<j)) == 0)
601 i = findrate(ic, j, rate);
609 i = findrate(ic, ic->ic_curmode, rate);
615 ic->ic_fixed_rate = i;
616 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
618 case WI_RID_CUR_TX_RATE:
620 case WI_RID_RTS_THRESH:
623 if (le16toh(wreq.wi_val[0]) != IEEE80211_MAX_LEN)
624 return EINVAL; /* TODO: RTS */
626 case WI_RID_CREATE_IBSS:
629 if (wreq.wi_val[0] != 0) {
630 if ((ic->ic_caps & IEEE80211_C_IBSS) == 0)
632 if ((ic->ic_flags & IEEE80211_F_IBSSON) == 0) {
633 ic->ic_flags |= IEEE80211_F_IBSSON;
634 if (ic->ic_opmode == IEEE80211_M_IBSS &&
635 ic->ic_state == IEEE80211_S_SCAN)
636 error = IS_UP_AUTO(ic) ? ENETRESET : 0;
639 if (ic->ic_flags & IEEE80211_F_IBSSON) {
640 ic->ic_flags &= ~IEEE80211_F_IBSSON;
641 if (ic->ic_flags & IEEE80211_F_SIBSS) {
642 ic->ic_flags &= ~IEEE80211_F_SIBSS;
643 error = IS_UP_AUTO(ic) ? ENETRESET : 0;
648 case WI_RID_MICROWAVE_OVEN:
651 if (wreq.wi_val[0] != 0)
652 return EINVAL; /* not supported */
654 case WI_RID_ROAMING_MODE:
657 i = le16toh(wreq.wi_val[0]);
658 if (i > IEEE80211_ROAMING_MANUAL)
659 return EINVAL; /* not supported */
662 case WI_RID_SYSTEM_SCALE:
665 if (le16toh(wreq.wi_val[0]) != 1)
666 return EINVAL; /* not supported */
668 case WI_RID_PM_ENABLED:
671 if (wreq.wi_val[0] != 0) {
672 if ((ic->ic_caps & IEEE80211_C_PMGT) == 0)
674 if ((ic->ic_flags & IEEE80211_F_PMGTON) == 0) {
675 ic->ic_flags |= IEEE80211_F_PMGTON;
676 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
679 if (ic->ic_flags & IEEE80211_F_PMGTON) {
680 ic->ic_flags &= ~IEEE80211_F_PMGTON;
681 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
685 case WI_RID_MAX_SLEEP:
688 ic->ic_lintval = le16toh(wreq.wi_val[0]);
689 if (ic->ic_flags & IEEE80211_F_PMGTON)
690 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
692 case WI_RID_CUR_BEACON_INT:
694 case WI_RID_WEP_AVAIL:
696 case WI_RID_CNFAUTHMODE:
699 i = le16toh(wreq.wi_val[0]);
700 if (i > IEEE80211_AUTH_WPA)
702 ic->ic_bss->ni_authmode = i; /* XXX ENETRESET? */
705 case WI_RID_ENCRYPTION:
708 if (wreq.wi_val[0] != 0) {
709 if ((ic->ic_caps & IEEE80211_C_WEP) == 0)
711 if ((ic->ic_flags & IEEE80211_F_PRIVACY) == 0) {
712 ic->ic_flags |= IEEE80211_F_PRIVACY;
716 if (ic->ic_flags & IEEE80211_F_PRIVACY) {
717 ic->ic_flags &= ~IEEE80211_F_PRIVACY;
722 case WI_RID_TX_CRYPT_KEY:
725 i = le16toh(wreq.wi_val[0]);
726 if (i >= IEEE80211_WEP_NKID)
728 ic->ic_def_txkey = i;
729 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
731 case WI_RID_DEFLT_CRYPT_KEYS:
732 if (len != sizeof(struct wi_ltv_keys))
734 keys = (struct wi_ltv_keys *)&wreq;
735 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
736 len = le16toh(keys->wi_keys[i].wi_keylen);
737 if (len != 0 && len < IEEE80211_WEP_KEYLEN)
739 if (len > IEEE80211_KEYBUF_SIZE)
742 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
743 struct ieee80211_key *k = &ic->ic_nw_keys[i];
745 len = le16toh(keys->wi_keys[i].wi_keylen);
747 k->wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV;
748 memset(k->wk_key, 0, sizeof(k->wk_key));
749 memcpy(k->wk_key, keys->wi_keys[i].wi_keydat, len);
751 k->wk_type = IEEE80211_CIPHER_WEP;
756 case WI_RID_MAX_DATALEN:
759 len = le16toh(wreq.wi_val[0]);
760 if (len < 350 /* ? */ || len > IEEE80211_MAX_LEN)
762 ic->ic_fragthreshold = len;
763 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
765 case WI_RID_IFACE_STATS:
768 case WI_RID_SCAN_REQ: /* XXX wicontrol */
769 if (ic->ic_opmode == IEEE80211_M_HOSTAP)
771 error = ieee80211_setupscan(ic, ic->ic_chan_avail);
773 error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
775 case WI_RID_SCAN_APS:
776 if (ic->ic_opmode == IEEE80211_M_HOSTAP)
778 len--; /* XXX: tx rate? */
780 case WI_RID_CHANNEL_LIST:
781 memset(chanlist, 0, sizeof(chanlist));
783 * Since channel 0 is not available for DS, channel 1
784 * is assigned to LSB on WaveLAN.
786 if (ic->ic_phytype == IEEE80211_T_DS)
790 for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++) {
793 if (isclr((uint8_t *)wreq.wi_val, j))
795 if (isclr(ic->ic_chan_active, i)) {
796 if (wreq.wi_type != WI_RID_CHANNEL_LIST)
798 if (isclr(ic->ic_chan_avail, i))
803 error = ieee80211_setupscan(ic, chanlist);
804 if (wreq.wi_type == WI_RID_CHANNEL_LIST) {
805 /* NB: ignore error from ieee80211_setupscan */
807 } else if (error == 0)
808 error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
814 if (error == ENETRESET && !IS_UP_AUTO(ic))
823 case IEEE80211_C_WEP: return IEEE80211_CIPHER_WEP;
824 case IEEE80211_C_AES: return IEEE80211_CIPHER_AES_OCB;
825 case IEEE80211_C_AES_CCM: return IEEE80211_CIPHER_AES_CCM;
826 case IEEE80211_C_CKIP: return IEEE80211_CIPHER_CKIP;
827 case IEEE80211_C_TKIP: return IEEE80211_CIPHER_TKIP;
833 ieee80211_ioctl_getkey(struct ieee80211com *ic, struct ieee80211req *ireq,
836 struct ieee80211_node *ni;
837 struct ieee80211req_key ik;
838 struct ieee80211_key *wk;
839 const struct ieee80211_cipher *cip;
843 if (ireq->i_len != sizeof(ik))
845 error = copyin(ireq->i_data, &ik, sizeof(ik));
849 if (kid == IEEE80211_KEYIX_NONE) {
850 ni = ieee80211_find_node(&ic->ic_sta, ik.ik_macaddr);
852 return EINVAL; /* XXX */
853 wk = &ni->ni_ucastkey;
855 if (kid >= IEEE80211_WEP_NKID)
857 wk = &ic->ic_nw_keys[kid];
858 IEEE80211_ADDR_COPY(&ik.ik_macaddr, ic->ic_bss->ni_macaddr);
862 ik.ik_type = cip->ic_cipher;
863 ik.ik_keylen = wk->wk_keylen;
864 ik.ik_flags = wk->wk_flags & (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV);
865 if (wk->wk_keyix == ic->ic_def_txkey)
866 ik.ik_flags |= IEEE80211_KEY_DEFAULT;
867 if (suser_cred(cr, NULL_CRED_OKAY) == 0) {
868 /* NB: only root can read key data */
869 ik.ik_keyrsc = wk->wk_keyrsc;
870 ik.ik_keytsc = wk->wk_keytsc;
871 memcpy(ik.ik_keydata, wk->wk_key, wk->wk_keylen);
872 if (cip->ic_cipher == IEEE80211_CIPHER_TKIP) {
873 memcpy(ik.ik_keydata+wk->wk_keylen,
874 wk->wk_key + IEEE80211_KEYBUF_SIZE,
875 IEEE80211_MICBUF_SIZE);
876 ik.ik_keylen += IEEE80211_MICBUF_SIZE;
881 memset(ik.ik_keydata, 0, sizeof(ik.ik_keydata));
884 ieee80211_free_node(ni);
885 return copyout(&ik, ireq->i_data, sizeof(ik));
889 ieee80211_ioctl_getchanlist(struct ieee80211com *ic, struct ieee80211req *ireq)
892 if (sizeof(ic->ic_chan_active) < ireq->i_len)
893 ireq->i_len = sizeof(ic->ic_chan_active);
894 return copyout(&ic->ic_chan_active, ireq->i_data, ireq->i_len);
898 ieee80211_ioctl_getchaninfo(struct ieee80211com *ic, struct ieee80211req *ireq)
900 struct ieee80211req_chaninfo chans; /* XXX off stack? */
904 * Since channel 0 is not available for DS, channel 1
905 * is assigned to LSB on WaveLAN.
907 if (ic->ic_phytype == IEEE80211_T_DS)
911 memset(&chans, 0, sizeof(chans));
912 for (; i <= IEEE80211_CHAN_MAX; i++)
913 if (isset(ic->ic_chan_avail, i)) {
914 struct ieee80211_channel *c = &ic->ic_channels[i];
915 chans.ic_chans[chans.ic_nchans].ic_freq = c->ic_freq;
916 chans.ic_chans[chans.ic_nchans].ic_flags = c->ic_flags;
919 space = __offsetof(struct ieee80211req_chaninfo,
920 ic_chans[chans.ic_nchans]);
921 if (space > ireq->i_len)
923 return copyout(&chans, ireq->i_data, space);
927 ieee80211_ioctl_getwpaie(struct ieee80211com *ic, struct ieee80211req *ireq)
929 struct ieee80211_node *ni;
930 struct ieee80211req_wpaie wpaie;
933 if (ireq->i_len < IEEE80211_ADDR_LEN)
935 error = copyin(ireq->i_data, wpaie.wpa_macaddr, IEEE80211_ADDR_LEN);
938 ni = ieee80211_find_node(&ic->ic_sta, wpaie.wpa_macaddr);
940 return EINVAL; /* XXX */
941 memset(wpaie.wpa_ie, 0, sizeof(wpaie.wpa_ie));
942 if (ni->ni_wpa_ie != NULL) {
943 int ielen = ni->ni_wpa_ie[1] + 2;
944 if (ielen > sizeof(wpaie.wpa_ie))
945 ielen = sizeof(wpaie.wpa_ie);
946 memcpy(wpaie.wpa_ie, ni->ni_wpa_ie, ielen);
948 ieee80211_free_node(ni);
949 if (ireq->i_len > sizeof(wpaie))
950 ireq->i_len = sizeof(wpaie);
951 return copyout(&wpaie, ireq->i_data, ireq->i_len);
955 ieee80211_ioctl_getstastats(struct ieee80211com *ic, struct ieee80211req *ireq)
957 struct ieee80211_node *ni;
958 uint8_t macaddr[IEEE80211_ADDR_LEN];
959 const int off = __offsetof(struct ieee80211req_sta_stats, is_stats);
962 if (ireq->i_len < off)
964 error = copyin(ireq->i_data, macaddr, IEEE80211_ADDR_LEN);
967 ni = ieee80211_find_node(&ic->ic_sta, macaddr);
969 return EINVAL; /* XXX */
970 if (ireq->i_len > sizeof(struct ieee80211req_sta_stats))
971 ireq->i_len = sizeof(struct ieee80211req_sta_stats);
972 /* NB: copy out only the statistics */
973 error = copyout(&ni->ni_stats, (uint8_t *) ireq->i_data + off,
975 ieee80211_free_node(ni);
980 get_scan_result(struct ieee80211req_scan_result *sr,
981 const struct ieee80211_node *ni)
983 struct ieee80211com *ic = ni->ni_ic;
986 memset(sr, 0, sizeof(*sr));
987 sr->isr_ssid_len = ni->ni_esslen;
988 if (ni->ni_wpa_ie != NULL)
989 ielen += 2+ni->ni_wpa_ie[1];
990 if (ni->ni_wme_ie != NULL)
991 ielen += 2+ni->ni_wme_ie[1];
994 * The value sr->isr_ie_len is defined as a uint8_t, so we
995 * need to be careful to avoid an integer overflow. If the
996 * value would overflow, we will set isr_ie_len to zero, and
997 * ieee80211_ioctl_getscanresults (below) will avoid copying
998 * the (overflowing) data.
1002 sr->isr_ie_len = ielen;
1003 sr->isr_len = sizeof(*sr) + sr->isr_ssid_len + sr->isr_ie_len;
1004 sr->isr_len = roundup(sr->isr_len, sizeof(uint32_t));
1005 if (ni->ni_chan != IEEE80211_CHAN_ANYC) {
1006 sr->isr_freq = ni->ni_chan->ic_freq;
1007 sr->isr_flags = ni->ni_chan->ic_flags;
1009 sr->isr_rssi = ic->ic_node_getrssi(ni);
1010 sr->isr_intval = ni->ni_intval;
1011 sr->isr_capinfo = ni->ni_capinfo;
1012 sr->isr_erp = ni->ni_erp;
1013 IEEE80211_ADDR_COPY(sr->isr_bssid, ni->ni_bssid);
1014 sr->isr_nrates = ni->ni_rates.rs_nrates;
1015 if (sr->isr_nrates > 15)
1016 sr->isr_nrates = 15;
1017 memcpy(sr->isr_rates, ni->ni_rates.rs_rates, sr->isr_nrates);
1021 ieee80211_ioctl_getscanresults(struct ieee80211com *ic, struct ieee80211req *ireq)
1024 struct ieee80211req_scan_result res;
1025 char data[512]; /* XXX shrink? */
1027 struct ieee80211req_scan_result *sr = &u.res;
1028 struct ieee80211_node_table *nt;
1029 struct ieee80211_node *ni;
1034 space = ireq->i_len;
1038 TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
1039 /* NB: skip pre-scan node state */
1040 if (ni->ni_chan == IEEE80211_CHAN_ANYC)
1042 get_scan_result(sr, ni);
1043 if (sr->isr_len > sizeof(u))
1045 if (space < sr->isr_len)
1047 cp = (uint8_t *)(sr+1);
1048 memcpy(cp, ni->ni_essid, ni->ni_esslen);
1049 cp += ni->ni_esslen;
1050 if (sr->isr_ie_len > 0 && ni->ni_wpa_ie != NULL) {
1051 memcpy(cp, ni->ni_wpa_ie, 2+ni->ni_wpa_ie[1]);
1052 cp += 2+ni->ni_wpa_ie[1];
1054 if (sr->isr_ie_len > 0 && ni->ni_wme_ie != NULL) {
1055 memcpy(cp, ni->ni_wme_ie, 2+ni->ni_wme_ie[1]);
1056 cp += 2+ni->ni_wme_ie[1];
1058 error = copyout(sr, p, sr->isr_len);
1062 space -= sr->isr_len;
1064 ireq->i_len -= space;
1069 struct ieee80211com *ic;
1070 struct ieee80211req_sta_info *si;
1075 sta_space(const struct ieee80211_node *ni, size_t *ielen)
1078 if (ni->ni_wpa_ie != NULL)
1079 *ielen += 2+ni->ni_wpa_ie[1];
1080 if (ni->ni_wme_ie != NULL)
1081 *ielen += 2+ni->ni_wme_ie[1];
1082 return roundup(sizeof(struct ieee80211req_sta_info) + *ielen,
1087 get_sta_space(void *arg, struct ieee80211_node *ni)
1089 struct stainforeq *req = arg;
1090 struct ieee80211com *ic = ni->ni_ic;
1093 if (ic->ic_opmode == IEEE80211_M_HOSTAP &&
1094 ni->ni_associd == 0) /* only associated stations */
1096 req->space += sta_space(ni, &ielen);
1100 get_sta_info(void *arg, struct ieee80211_node *ni)
1102 struct stainforeq *req = arg;
1103 struct ieee80211com *ic = ni->ni_ic;
1104 struct ieee80211req_sta_info *si;
1108 if (ic->ic_opmode == IEEE80211_M_HOSTAP &&
1109 ni->ni_associd == 0) /* only associated stations */
1111 if (ni->ni_chan == IEEE80211_CHAN_ANYC) /* XXX bogus entry */
1113 len = sta_space(ni, &ielen);
1114 if (len > req->space)
1118 si->isi_ie_len = ielen;
1119 si->isi_freq = ni->ni_chan->ic_freq;
1120 si->isi_flags = ni->ni_chan->ic_flags;
1121 si->isi_state = ni->ni_flags;
1122 si->isi_authmode = ni->ni_authmode;
1123 si->isi_rssi = ic->ic_node_getrssi(ni);
1124 si->isi_capinfo = ni->ni_capinfo;
1125 si->isi_erp = ni->ni_erp;
1126 IEEE80211_ADDR_COPY(si->isi_macaddr, ni->ni_macaddr);
1127 si->isi_nrates = ni->ni_rates.rs_nrates;
1128 if (si->isi_nrates > 15)
1129 si->isi_nrates = 15;
1130 memcpy(si->isi_rates, ni->ni_rates.rs_rates, si->isi_nrates);
1131 si->isi_txrate = ni->ni_txrate;
1132 si->isi_associd = ni->ni_associd;
1133 si->isi_txpower = ni->ni_txpower;
1134 si->isi_vlan = ni->ni_vlan;
1135 if (ni->ni_flags & IEEE80211_NODE_QOS) {
1136 memcpy(si->isi_txseqs, ni->ni_txseqs, sizeof(ni->ni_txseqs));
1137 memcpy(si->isi_rxseqs, ni->ni_rxseqs, sizeof(ni->ni_rxseqs));
1139 si->isi_txseqs[0] = ni->ni_txseqs[0];
1140 si->isi_rxseqs[0] = ni->ni_rxseqs[0];
1142 /* NB: leave all cases in case we relax ni_associd == 0 check */
1143 if (ieee80211_node_is_authorized(ni))
1144 si->isi_inact = ic->ic_inact_run;
1145 else if (ni->ni_associd != 0)
1146 si->isi_inact = ic->ic_inact_auth;
1148 si->isi_inact = ic->ic_inact_init;
1149 si->isi_inact = (si->isi_inact - ni->ni_inact) * IEEE80211_INACT_WAIT;
1151 cp = (uint8_t *)(si+1);
1152 if (ni->ni_wpa_ie != NULL) {
1153 memcpy(cp, ni->ni_wpa_ie, 2+ni->ni_wpa_ie[1]);
1154 cp += 2+ni->ni_wpa_ie[1];
1156 if (ni->ni_wme_ie != NULL) {
1157 memcpy(cp, ni->ni_wme_ie, 2+ni->ni_wme_ie[1]);
1158 cp += 2+ni->ni_wme_ie[1];
1161 req->si = (struct ieee80211req_sta_info *)(((uint8_t *)si) + len);
1166 ieee80211_ioctl_getstainfo(struct ieee80211com *ic, struct ieee80211req *ireq)
1168 struct stainforeq req;
1171 if (ireq->i_len < sizeof(struct stainforeq))
1176 ieee80211_iterate_nodes(&ic->ic_sta, get_sta_space, &req);
1177 if (req.space > ireq->i_len)
1178 req.space = ireq->i_len;
1179 if (req.space > 0) {
1184 /* XXX M_WAITOK after driver lock released */
1185 p = kmalloc(space, M_TEMP, M_NOWAIT);
1189 ieee80211_iterate_nodes(&ic->ic_sta, get_sta_info, &req);
1190 ireq->i_len = space - req.space;
1191 error = copyout(p, ireq->i_data, ireq->i_len);
1200 ieee80211_ioctl_getstatxpow(struct ieee80211com *ic, struct ieee80211req *ireq)
1202 struct ieee80211_node *ni;
1203 struct ieee80211req_sta_txpow txpow;
1206 if (ireq->i_len != sizeof(txpow))
1208 error = copyin(ireq->i_data, &txpow, sizeof(txpow));
1211 ni = ieee80211_find_node(&ic->ic_sta, txpow.it_macaddr);
1213 return EINVAL; /* XXX */
1214 txpow.it_txpow = ni->ni_txpower;
1215 error = copyout(&txpow, ireq->i_data, sizeof(txpow));
1216 ieee80211_free_node(ni);
1221 ieee80211_ioctl_getwmeparam(struct ieee80211com *ic, struct ieee80211req *ireq)
1223 struct ieee80211_wme_state *wme = &ic->ic_wme;
1224 struct wmeParams *wmep;
1227 if ((ic->ic_caps & IEEE80211_C_WME) == 0)
1230 ac = (ireq->i_len & IEEE80211_WMEPARAM_VAL);
1231 if (ac >= WME_NUM_AC)
1233 if (ireq->i_len & IEEE80211_WMEPARAM_BSS)
1234 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac];
1236 wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac];
1237 switch (ireq->i_type) {
1238 case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */
1239 ireq->i_val = wmep->wmep_logcwmin;
1241 case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */
1242 ireq->i_val = wmep->wmep_logcwmax;
1244 case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */
1245 ireq->i_val = wmep->wmep_aifsn;
1247 case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */
1248 ireq->i_val = wmep->wmep_txopLimit;
1250 case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */
1251 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac];
1252 ireq->i_val = wmep->wmep_acm;
1254 case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only)*/
1255 wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac];
1256 ireq->i_val = !wmep->wmep_noackPolicy;
1263 ieee80211_ioctl_getmaccmd(struct ieee80211com *ic, struct ieee80211req *ireq)
1265 const struct ieee80211_aclator *acl = ic->ic_acl;
1267 return (acl == NULL ? EINVAL : acl->iac_getioctl(ic, ireq));
1271 * When building the kernel with -O2 on the i386 architecture, gcc
1272 * seems to want to inline this function into ieee80211_ioctl()
1273 * (which is the only routine that calls it). When this happens,
1274 * ieee80211_ioctl() ends up consuming an additional 2K of stack
1275 * space. (Exactly why it needs so much is unclear.) The problem
1276 * is that it's possible for ieee80211_ioctl() to invoke other
1277 * routines (including driver init functions) which could then find
1278 * themselves perilously close to exhausting the stack.
1280 * To avoid this, we deliberately prevent gcc from inlining this
1281 * routine. Another way to avoid this is to use less agressive
1282 * optimization when compiling this file (i.e. -O instead of -O2)
1283 * but special-casing the compilation of this one module in the
1284 * build system would be awkward.
1287 __attribute__ ((noinline))
1290 ieee80211_ioctl_get80211(struct ieee80211com *ic, u_long cmd,
1291 struct ieee80211req *ireq, struct ucred *cr)
1293 const struct ieee80211_rsnparms *rsn = &ic->ic_bss->ni_rsn;
1296 uint8_t tmpkey[IEEE80211_KEYBUF_SIZE];
1297 char tmpssid[IEEE80211_NWID_LEN];
1299 switch (ireq->i_type) {
1300 case IEEE80211_IOC_SSID:
1301 switch (ic->ic_state) {
1302 case IEEE80211_S_INIT:
1303 case IEEE80211_S_SCAN:
1304 ireq->i_len = ic->ic_des_esslen;
1305 memcpy(tmpssid, ic->ic_des_essid, ireq->i_len);
1308 ireq->i_len = ic->ic_bss->ni_esslen;
1309 memcpy(tmpssid, ic->ic_bss->ni_essid,
1313 error = copyout(tmpssid, ireq->i_data, ireq->i_len);
1315 case IEEE80211_IOC_NUMSSIDS:
1318 case IEEE80211_IOC_WEP:
1319 if ((ic->ic_flags & IEEE80211_F_PRIVACY) == 0)
1320 ireq->i_val = IEEE80211_WEP_OFF;
1321 else if (ic->ic_flags & IEEE80211_F_DROPUNENC)
1322 ireq->i_val = IEEE80211_WEP_ON;
1324 ireq->i_val = IEEE80211_WEP_MIXED;
1326 case IEEE80211_IOC_WEPKEY:
1327 kid = (u_int) ireq->i_val;
1328 if (kid >= IEEE80211_WEP_NKID)
1330 len = (u_int) ic->ic_nw_keys[kid].wk_keylen;
1331 /* NB: only root can read WEP keys */
1332 if (suser_cred(cr, NULL_CRED_OKAY) == 0) {
1333 bcopy(ic->ic_nw_keys[kid].wk_key, tmpkey, len);
1338 error = copyout(tmpkey, ireq->i_data, len);
1340 case IEEE80211_IOC_NUMWEPKEYS:
1341 ireq->i_val = IEEE80211_WEP_NKID;
1343 case IEEE80211_IOC_WEPTXKEY:
1344 ireq->i_val = ic->ic_def_txkey;
1346 case IEEE80211_IOC_AUTHMODE:
1347 if (ic->ic_flags & IEEE80211_F_WPA)
1348 ireq->i_val = IEEE80211_AUTH_WPA;
1350 ireq->i_val = ic->ic_bss->ni_authmode;
1352 case IEEE80211_IOC_CHANNEL:
1353 ireq->i_val = ieee80211_chan2ieee(ic, ic->ic_curchan);
1355 case IEEE80211_IOC_POWERSAVE:
1356 if (ic->ic_flags & IEEE80211_F_PMGTON)
1357 ireq->i_val = IEEE80211_POWERSAVE_ON;
1359 ireq->i_val = IEEE80211_POWERSAVE_OFF;
1361 case IEEE80211_IOC_POWERSAVESLEEP:
1362 ireq->i_val = ic->ic_lintval;
1364 case IEEE80211_IOC_RTSTHRESHOLD:
1365 ireq->i_val = ic->ic_rtsthreshold;
1367 case IEEE80211_IOC_PROTMODE:
1368 ireq->i_val = ic->ic_protmode;
1370 case IEEE80211_IOC_TXPOWER:
1371 if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0)
1373 ireq->i_val = ic->ic_txpowlimit;
1375 case IEEE80211_IOC_MCASTCIPHER:
1376 ireq->i_val = rsn->rsn_mcastcipher;
1378 case IEEE80211_IOC_MCASTKEYLEN:
1379 ireq->i_val = rsn->rsn_mcastkeylen;
1381 case IEEE80211_IOC_UCASTCIPHERS:
1383 for (m = 0x1; m != 0; m <<= 1)
1384 if (rsn->rsn_ucastcipherset & m)
1385 ireq->i_val |= 1<<cap2cipher(m);
1387 case IEEE80211_IOC_UCASTCIPHER:
1388 ireq->i_val = rsn->rsn_ucastcipher;
1390 case IEEE80211_IOC_UCASTKEYLEN:
1391 ireq->i_val = rsn->rsn_ucastkeylen;
1393 case IEEE80211_IOC_KEYMGTALGS:
1394 ireq->i_val = rsn->rsn_keymgmtset;
1396 case IEEE80211_IOC_RSNCAPS:
1397 ireq->i_val = rsn->rsn_caps;
1399 case IEEE80211_IOC_WPA:
1400 switch (ic->ic_flags & IEEE80211_F_WPA) {
1401 case IEEE80211_F_WPA1:
1404 case IEEE80211_F_WPA2:
1407 case IEEE80211_F_WPA1 | IEEE80211_F_WPA2:
1415 case IEEE80211_IOC_CHANLIST:
1416 error = ieee80211_ioctl_getchanlist(ic, ireq);
1418 case IEEE80211_IOC_ROAMING:
1419 ireq->i_val = ic->ic_roaming;
1421 case IEEE80211_IOC_PRIVACY:
1422 ireq->i_val = (ic->ic_flags & IEEE80211_F_PRIVACY) != 0;
1424 case IEEE80211_IOC_DROPUNENCRYPTED:
1425 ireq->i_val = (ic->ic_flags & IEEE80211_F_DROPUNENC) != 0;
1427 case IEEE80211_IOC_COUNTERMEASURES:
1428 ireq->i_val = (ic->ic_flags & IEEE80211_F_COUNTERM) != 0;
1430 case IEEE80211_IOC_DRIVER_CAPS:
1431 ireq->i_val = ic->ic_caps>>16;
1432 ireq->i_len = ic->ic_caps&0xffff;
1434 case IEEE80211_IOC_WME:
1435 ireq->i_val = (ic->ic_flags & IEEE80211_F_WME) != 0;
1437 case IEEE80211_IOC_HIDESSID:
1438 ireq->i_val = (ic->ic_flags & IEEE80211_F_HIDESSID) != 0;
1440 case IEEE80211_IOC_APBRIDGE:
1441 ireq->i_val = (ic->ic_flags & IEEE80211_F_NOBRIDGE) == 0;
1443 case IEEE80211_IOC_OPTIE:
1444 if (ic->ic_opt_ie == NULL)
1446 /* NB: truncate, caller can check length */
1447 if (ireq->i_len > ic->ic_opt_ie_len)
1448 ireq->i_len = ic->ic_opt_ie_len;
1449 error = copyout(ic->ic_opt_ie, ireq->i_data, ireq->i_len);
1451 case IEEE80211_IOC_WPAKEY:
1452 error = ieee80211_ioctl_getkey(ic, ireq, cr);
1454 case IEEE80211_IOC_CHANINFO:
1455 error = ieee80211_ioctl_getchaninfo(ic, ireq);
1457 case IEEE80211_IOC_BSSID:
1458 if (ireq->i_len != IEEE80211_ADDR_LEN)
1460 error = copyout(ic->ic_state == IEEE80211_S_RUN ?
1461 ic->ic_bss->ni_bssid :
1463 ireq->i_data, ireq->i_len);
1465 case IEEE80211_IOC_WPAIE:
1466 error = ieee80211_ioctl_getwpaie(ic, ireq);
1468 case IEEE80211_IOC_SCAN_RESULTS:
1469 error = ieee80211_ioctl_getscanresults(ic, ireq);
1471 case IEEE80211_IOC_STA_STATS:
1472 error = ieee80211_ioctl_getstastats(ic, ireq);
1474 case IEEE80211_IOC_TXPOWMAX:
1475 ireq->i_val = ic->ic_bss->ni_txpower;
1477 case IEEE80211_IOC_STA_TXPOW:
1478 error = ieee80211_ioctl_getstatxpow(ic, ireq);
1480 case IEEE80211_IOC_STA_INFO:
1481 error = ieee80211_ioctl_getstainfo(ic, ireq);
1483 case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */
1484 case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */
1485 case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */
1486 case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */
1487 case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */
1488 case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (bss only) */
1489 error = ieee80211_ioctl_getwmeparam(ic, ireq);
1491 case IEEE80211_IOC_DTIM_PERIOD:
1492 ireq->i_val = ic->ic_dtim_period;
1494 case IEEE80211_IOC_BEACON_INTERVAL:
1495 /* NB: get from ic_bss for station mode */
1496 ireq->i_val = ic->ic_bss->ni_intval;
1498 case IEEE80211_IOC_PUREG:
1499 ireq->i_val = (ic->ic_flags & IEEE80211_F_PUREG) != 0;
1501 case IEEE80211_IOC_MCAST_RATE:
1502 ireq->i_val = ic->ic_mcast_rate;
1504 case IEEE80211_IOC_FRAGTHRESHOLD:
1505 ireq->i_val = ic->ic_fragthreshold;
1507 case IEEE80211_IOC_MACCMD:
1508 error = ieee80211_ioctl_getmaccmd(ic, ireq);
1510 case IEEE80211_IOC_BURST:
1511 ireq->i_val = (ic->ic_flags & IEEE80211_F_BURST) != 0;
1513 case IEEE80211_IOC_RATECTL:
1514 ireq->i_val = ic->ic_ratectl.rc_st_ratectl;
1524 ieee80211_ioctl_setoptie(struct ieee80211com *ic, struct ieee80211req *ireq)
1530 * NB: Doing this for ap operation could be useful (e.g. for
1531 * WPA and/or WME) except that it typically is worthless
1532 * without being able to intervene when processing
1533 * association response frames--so disallow it for now.
1535 if (ic->ic_opmode != IEEE80211_M_STA)
1537 if (ireq->i_len > IEEE80211_MAX_OPT_IE)
1539 if (ireq->i_len > 0) {
1540 ie = kmalloc(ireq->i_len, M_DEVBUF, M_NOWAIT);
1543 error = copyin(ireq->i_data, ie, ireq->i_len);
1545 kfree(ie, M_DEVBUF);
1552 /* XXX sanity check data? */
1553 oie = ic->ic_opt_ie;
1555 ic->ic_opt_ie_len = ireq->i_len;
1557 kfree(oie, M_DEVBUF);
1562 ieee80211_ioctl_setkey(struct ieee80211com *ic, struct ieee80211req *ireq)
1564 struct ieee80211req_key ik;
1565 struct ieee80211_node *ni;
1566 struct ieee80211_key *wk;
1570 if (ireq->i_len != sizeof(ik))
1572 error = copyin(ireq->i_data, &ik, sizeof(ik));
1575 /* NB: cipher support is verified by ieee80211_crypt_newkey */
1576 /* NB: this also checks ik->ik_keylen > sizeof(wk->wk_key) */
1577 if (ik.ik_keylen > sizeof(ik.ik_keydata))
1580 if (kid == IEEE80211_KEYIX_NONE) {
1581 /* XXX unicast keys currently must be tx/rx */
1582 if (ik.ik_flags != (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV))
1584 if (ic->ic_opmode == IEEE80211_M_STA) {
1585 ni = ieee80211_ref_node(ic->ic_bss);
1586 if (!IEEE80211_ADDR_EQ(ik.ik_macaddr, ni->ni_bssid)) {
1587 ieee80211_free_node(ni);
1588 return EADDRNOTAVAIL;
1591 ni = ieee80211_find_node(&ic->ic_sta, ik.ik_macaddr);
1595 wk = &ni->ni_ucastkey;
1597 if (kid >= IEEE80211_WEP_NKID)
1599 wk = &ic->ic_nw_keys[kid];
1601 * Global slots start off w/o any assigned key index.
1602 * Force one here for consistency with IEEE80211_IOC_WEPKEY.
1604 if (wk->wk_keyix == IEEE80211_KEYIX_NONE)
1609 ieee80211_key_update_begin(ic);
1610 if (ieee80211_crypto_newkey(ic, ik.ik_type, ik.ik_flags, wk)) {
1611 wk->wk_keylen = ik.ik_keylen;
1612 /* NB: MIC presence is implied by cipher type */
1613 if (wk->wk_keylen > IEEE80211_KEYBUF_SIZE)
1614 wk->wk_keylen = IEEE80211_KEYBUF_SIZE;
1615 wk->wk_keyrsc = ik.ik_keyrsc;
1616 wk->wk_keytsc = 0; /* new key, reset */
1617 memset(wk->wk_key, 0, sizeof(wk->wk_key));
1618 memcpy(wk->wk_key, ik.ik_keydata, ik.ik_keylen);
1619 if (!ieee80211_crypto_setkey(ic, wk,
1620 ni != NULL ? ni->ni_macaddr : ik.ik_macaddr))
1622 else if ((ik.ik_flags & IEEE80211_KEY_DEFAULT))
1623 ic->ic_def_txkey = kid;
1626 ieee80211_key_update_end(ic);
1628 ieee80211_free_node(ni);
1633 ieee80211_ioctl_delkey(struct ieee80211com *ic, struct ieee80211req *ireq)
1635 struct ieee80211req_del_key dk;
1638 if (ireq->i_len != sizeof(dk))
1640 error = copyin(ireq->i_data, &dk, sizeof(dk));
1644 /* XXX uint8_t -> uint16_t */
1645 if (dk.idk_keyix == (uint8_t)IEEE80211_KEYIX_NONE) {
1646 struct ieee80211_node *ni;
1648 if (ic->ic_opmode == IEEE80211_M_STA) {
1649 ni = ieee80211_ref_node(ic->ic_bss);
1650 if (!IEEE80211_ADDR_EQ(dk.idk_macaddr, ni->ni_bssid)) {
1651 ieee80211_free_node(ni);
1652 return EADDRNOTAVAIL;
1655 ni = ieee80211_find_node(&ic->ic_sta, dk.idk_macaddr);
1659 /* XXX error return */
1660 ieee80211_node_delucastkey(ni);
1661 ieee80211_free_node(ni);
1663 if (kid >= IEEE80211_WEP_NKID)
1665 /* XXX error return */
1666 ieee80211_crypto_delkey(ic, &ic->ic_nw_keys[kid]);
1672 domlme(void *arg, struct ieee80211_node *ni)
1674 struct ieee80211com *ic = ni->ni_ic;
1675 struct ieee80211req_mlme *mlme = arg;
1677 if (ni->ni_associd != 0) {
1678 IEEE80211_SEND_MGMT(ic, ni,
1679 mlme->im_op == IEEE80211_MLME_DEAUTH ?
1680 IEEE80211_FC0_SUBTYPE_DEAUTH :
1681 IEEE80211_FC0_SUBTYPE_DISASSOC,
1684 ieee80211_node_leave(ic, ni);
1688 ieee80211_ioctl_setmlme(struct ieee80211com *ic, struct ieee80211req *ireq)
1690 struct ieee80211req_mlme mlme;
1691 struct ieee80211_node *ni;
1694 if (ireq->i_len != sizeof(mlme))
1696 error = copyin(ireq->i_data, &mlme, sizeof(mlme));
1699 switch (mlme.im_op) {
1700 case IEEE80211_MLME_ASSOC:
1701 if (ic->ic_opmode != IEEE80211_M_STA)
1703 /* XXX must be in S_SCAN state? */
1705 if (mlme.im_ssid_len != 0) {
1707 * Desired ssid specified; must match both bssid and
1708 * ssid to distinguish ap advertising multiple ssid's.
1710 ni = ieee80211_find_node_with_ssid(&ic->ic_scan,
1712 mlme.im_ssid_len, mlme.im_ssid);
1715 * Normal case; just match bssid.
1717 ni = ieee80211_find_node(&ic->ic_scan, mlme.im_macaddr);
1721 if (!ieee80211_sta_join(ic, ni)) {
1722 ieee80211_free_node(ni);
1726 case IEEE80211_MLME_DISASSOC:
1727 case IEEE80211_MLME_DEAUTH:
1728 switch (ic->ic_opmode) {
1729 case IEEE80211_M_STA:
1730 /* XXX not quite right */
1731 ieee80211_new_state(ic, IEEE80211_S_INIT,
1734 case IEEE80211_M_HOSTAP:
1735 /* NB: the broadcast address means do 'em all */
1736 if (!IEEE80211_ADDR_EQ(mlme.im_macaddr, ic->ic_ifp->if_broadcastaddr)) {
1737 if ((ni = ieee80211_find_node(&ic->ic_sta,
1738 mlme.im_macaddr)) == NULL)
1741 ieee80211_free_node(ni);
1743 ieee80211_iterate_nodes(&ic->ic_sta,
1751 case IEEE80211_MLME_AUTHORIZE:
1752 case IEEE80211_MLME_UNAUTHORIZE:
1753 if (ic->ic_opmode != IEEE80211_M_HOSTAP)
1755 ni = ieee80211_find_node(&ic->ic_sta, mlme.im_macaddr);
1758 if (mlme.im_op == IEEE80211_MLME_AUTHORIZE)
1759 ieee80211_node_authorize(ni);
1761 ieee80211_node_unauthorize(ni);
1762 ieee80211_free_node(ni);
1771 ieee80211_ioctl_macmac(struct ieee80211com *ic, struct ieee80211req *ireq)
1773 uint8_t mac[IEEE80211_ADDR_LEN];
1774 const struct ieee80211_aclator *acl = ic->ic_acl;
1777 if (ireq->i_len != sizeof(mac))
1779 error = copyin(ireq->i_data, mac, ireq->i_len);
1783 acl = ieee80211_aclator_get("mac");
1784 if (acl == NULL || !acl->iac_attach(ic))
1788 if (ireq->i_type == IEEE80211_IOC_ADDMAC)
1789 acl->iac_add(ic, mac);
1791 acl->iac_remove(ic, mac);
1796 ieee80211_ioctl_setmaccmd(struct ieee80211com *ic, struct ieee80211req *ireq)
1798 const struct ieee80211_aclator *acl = ic->ic_acl;
1800 switch (ireq->i_val) {
1801 case IEEE80211_MACCMD_POLICY_OPEN:
1802 case IEEE80211_MACCMD_POLICY_ALLOW:
1803 case IEEE80211_MACCMD_POLICY_DENY:
1805 acl = ieee80211_aclator_get("mac");
1806 if (acl == NULL || !acl->iac_attach(ic))
1810 acl->iac_setpolicy(ic, ireq->i_val);
1812 case IEEE80211_MACCMD_FLUSH:
1815 /* NB: silently ignore when not in use */
1817 case IEEE80211_MACCMD_DETACH:
1820 acl->iac_detach(ic);
1827 return acl->iac_setioctl(ic, ireq);
1833 ieee80211_ioctl_setchanlist(struct ieee80211com *ic, struct ieee80211req *ireq)
1835 struct ieee80211req_chanlist list;
1836 u_char chanlist[IEEE80211_CHAN_BYTES];
1839 if (ireq->i_len != sizeof(list))
1841 error = copyin(ireq->i_data, &list, sizeof(list));
1844 memset(chanlist, 0, sizeof(chanlist));
1846 * Since channel 0 is not available for DS, channel 1
1847 * is assigned to LSB on WaveLAN.
1849 if (ic->ic_phytype == IEEE80211_T_DS)
1853 for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++) {
1855 * NB: silently discard unavailable channels so users
1856 * can specify 1-255 to get all available channels.
1858 if (isset(list.ic_channels, j) && isset(ic->ic_chan_avail, i))
1859 setbit(chanlist, i);
1861 if (ic->ic_ibss_chan == NULL ||
1862 isclr(chanlist, ieee80211_chan2ieee(ic, ic->ic_ibss_chan))) {
1863 for (i = 0; i <= IEEE80211_CHAN_MAX; i++)
1864 if (isset(chanlist, i)) {
1865 ic->ic_ibss_chan = &ic->ic_channels[i];
1868 return EINVAL; /* no active channels */
1872 memcpy(ic->ic_chan_active, chanlist, sizeof(ic->ic_chan_active));
1873 return IS_UP_AUTO(ic) ? ENETRESET : 0;
1877 ieee80211_ioctl_setstatxpow(struct ieee80211com *ic, struct ieee80211req *ireq)
1879 struct ieee80211_node *ni;
1880 struct ieee80211req_sta_txpow txpow;
1883 if (ireq->i_len != sizeof(txpow))
1885 error = copyin(ireq->i_data, &txpow, sizeof(txpow));
1888 ni = ieee80211_find_node(&ic->ic_sta, txpow.it_macaddr);
1890 return EINVAL; /* XXX */
1891 ni->ni_txpower = txpow.it_txpow;
1892 ieee80211_free_node(ni);
1897 ieee80211_ioctl_setwmeparam(struct ieee80211com *ic, struct ieee80211req *ireq)
1899 struct ieee80211_wme_state *wme = &ic->ic_wme;
1900 struct wmeParams *wmep, *chanp;
1903 if ((ic->ic_caps & IEEE80211_C_WME) == 0)
1906 isbss = (ireq->i_len & IEEE80211_WMEPARAM_BSS);
1907 ac = (ireq->i_len & IEEE80211_WMEPARAM_VAL);
1908 if (ac >= WME_NUM_AC)
1911 chanp = &wme->wme_bssChanParams.cap_wmeParams[ac];
1912 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac];
1914 chanp = &wme->wme_chanParams.cap_wmeParams[ac];
1915 wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac];
1917 switch (ireq->i_type) {
1918 case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */
1920 wmep->wmep_logcwmin = ireq->i_val;
1921 if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
1922 chanp->wmep_logcwmin = ireq->i_val;
1924 wmep->wmep_logcwmin = chanp->wmep_logcwmin =
1928 case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */
1930 wmep->wmep_logcwmax = ireq->i_val;
1931 if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
1932 chanp->wmep_logcwmax = ireq->i_val;
1934 wmep->wmep_logcwmax = chanp->wmep_logcwmax =
1938 case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */
1940 wmep->wmep_aifsn = ireq->i_val;
1941 if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
1942 chanp->wmep_aifsn = ireq->i_val;
1944 wmep->wmep_aifsn = chanp->wmep_aifsn = ireq->i_val;
1947 case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */
1949 wmep->wmep_txopLimit = ireq->i_val;
1950 if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
1951 chanp->wmep_txopLimit = ireq->i_val;
1953 wmep->wmep_txopLimit = chanp->wmep_txopLimit =
1957 case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */
1958 wmep->wmep_acm = ireq->i_val;
1959 if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
1960 chanp->wmep_acm = ireq->i_val;
1962 case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only)*/
1963 wmep->wmep_noackPolicy = chanp->wmep_noackPolicy =
1967 ieee80211_wme_updateparams(ic);
1972 cipher2cap(int cipher)
1975 case IEEE80211_CIPHER_WEP: return IEEE80211_C_WEP;
1976 case IEEE80211_CIPHER_AES_OCB: return IEEE80211_C_AES;
1977 case IEEE80211_CIPHER_AES_CCM: return IEEE80211_C_AES_CCM;
1978 case IEEE80211_CIPHER_CKIP: return IEEE80211_C_CKIP;
1979 case IEEE80211_CIPHER_TKIP: return IEEE80211_C_TKIP;
1985 ieee80211_ioctl_set80211(struct ieee80211com *ic, u_long cmd, struct ieee80211req *ireq)
1987 static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
1988 struct ieee80211_rsnparms *rsn = &ic->ic_bss->ni_rsn;
1990 const struct ieee80211_authenticator *auth;
1991 uint8_t tmpkey[IEEE80211_KEYBUF_SIZE];
1992 char tmpssid[IEEE80211_NWID_LEN];
1993 uint8_t tmpbssid[IEEE80211_ADDR_LEN];
1994 struct ieee80211_key *k;
1999 switch (ireq->i_type) {
2000 case IEEE80211_IOC_SSID:
2001 if (ireq->i_val != 0 ||
2002 ireq->i_len > IEEE80211_NWID_LEN)
2004 error = copyin(ireq->i_data, tmpssid, ireq->i_len);
2007 memset(ic->ic_des_essid, 0, IEEE80211_NWID_LEN);
2008 ic->ic_des_esslen = ireq->i_len;
2009 memcpy(ic->ic_des_essid, tmpssid, ireq->i_len);
2012 case IEEE80211_IOC_WEP:
2013 switch (ireq->i_val) {
2014 case IEEE80211_WEP_OFF:
2015 ic->ic_flags &= ~IEEE80211_F_PRIVACY;
2016 ic->ic_flags &= ~IEEE80211_F_DROPUNENC;
2018 case IEEE80211_WEP_ON:
2019 ic->ic_flags |= IEEE80211_F_PRIVACY;
2020 ic->ic_flags |= IEEE80211_F_DROPUNENC;
2022 case IEEE80211_WEP_MIXED:
2023 ic->ic_flags |= IEEE80211_F_PRIVACY;
2024 ic->ic_flags &= ~IEEE80211_F_DROPUNENC;
2029 case IEEE80211_IOC_WEPKEY:
2030 kid = (u_int)ireq->i_val;
2031 if (kid >= IEEE80211_WEP_NKID)
2033 k = &ic->ic_nw_keys[kid];
2034 if (ireq->i_len == 0) {
2035 /* zero-len =>'s delete any existing key */
2036 ieee80211_crypto_delkey(ic, k);
2039 if (ireq->i_len > sizeof(tmpkey))
2041 memset(tmpkey, 0, sizeof(tmpkey));
2042 error = copyin(ireq->i_data, tmpkey, ireq->i_len);
2045 ieee80211_key_update_begin(ic);
2046 k->wk_keyix = kid; /* NB: force fixed key id */
2047 if (ieee80211_crypto_newkey(ic, IEEE80211_CIPHER_WEP,
2048 IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV, k)) {
2049 k->wk_keylen = ireq->i_len;
2050 memcpy(k->wk_key, tmpkey, sizeof(tmpkey));
2051 if (!ieee80211_crypto_setkey(ic, k, ic->ic_myaddr))
2055 ieee80211_key_update_end(ic);
2056 if (!error) /* NB: for compatibility */
2059 case IEEE80211_IOC_WEPTXKEY:
2060 kid = (u_int) ireq->i_val;
2061 if (kid >= IEEE80211_WEP_NKID &&
2062 (uint16_t) kid != IEEE80211_KEYIX_NONE)
2064 ic->ic_def_txkey = kid;
2065 error = ENETRESET; /* push to hardware */
2067 case IEEE80211_IOC_AUTHMODE:
2068 switch (ireq->i_val) {
2069 case IEEE80211_AUTH_WPA:
2070 case IEEE80211_AUTH_8021X: /* 802.1x */
2071 case IEEE80211_AUTH_OPEN: /* open */
2072 case IEEE80211_AUTH_SHARED: /* shared-key */
2073 case IEEE80211_AUTH_AUTO: /* auto */
2074 auth = ieee80211_authenticator_get(ireq->i_val);
2081 switch (ireq->i_val) {
2082 case IEEE80211_AUTH_WPA: /* WPA w/ 802.1x */
2083 ic->ic_flags |= IEEE80211_F_PRIVACY;
2084 ireq->i_val = IEEE80211_AUTH_8021X;
2086 case IEEE80211_AUTH_OPEN: /* open */
2087 ic->ic_flags &= ~(IEEE80211_F_WPA|IEEE80211_F_PRIVACY);
2089 case IEEE80211_AUTH_SHARED: /* shared-key */
2090 case IEEE80211_AUTH_8021X: /* 802.1x */
2091 ic->ic_flags &= ~IEEE80211_F_WPA;
2092 /* both require a key so mark the PRIVACY capability */
2093 ic->ic_flags |= IEEE80211_F_PRIVACY;
2095 case IEEE80211_AUTH_AUTO: /* auto */
2096 ic->ic_flags &= ~IEEE80211_F_WPA;
2097 /* XXX PRIVACY handling? */
2098 /* XXX what's the right way to do this? */
2101 /* NB: authenticator attach/detach happens on state change */
2102 ic->ic_bss->ni_authmode = ireq->i_val;
2103 /* XXX mixed/mode/usage? */
2107 case IEEE80211_IOC_CHANNEL:
2108 /* XXX 0xffff overflows 16-bit signed */
2109 if (ireq->i_val == 0 ||
2110 ireq->i_val == (int16_t) IEEE80211_CHAN_ANY)
2111 ic->ic_des_chan = IEEE80211_CHAN_ANYC;
2112 else if ((u_int) ireq->i_val > IEEE80211_CHAN_MAX ||
2113 isclr(ic->ic_chan_active, ireq->i_val)) {
2116 ic->ic_ibss_chan = ic->ic_des_chan =
2117 &ic->ic_channels[ireq->i_val];
2118 switch (ic->ic_state) {
2119 case IEEE80211_S_INIT:
2120 case IEEE80211_S_SCAN:
2125 * If the desired channel has changed (to something
2126 * other than any) and we're not already scanning,
2127 * then kick the state machine.
2129 if (ic->ic_des_chan != IEEE80211_CHAN_ANYC &&
2130 ic->ic_bss->ni_chan != ic->ic_des_chan &&
2131 (ic->ic_flags & IEEE80211_F_SCAN) == 0)
2135 if (error == ENETRESET &&
2136 ic->ic_opmode == IEEE80211_M_MONITOR) {
2139 * Monitor mode can switch directly.
2141 if (ic->ic_des_chan != IEEE80211_CHAN_ANYC)
2142 ic->ic_curchan = ic->ic_des_chan;
2143 error = ic->ic_reset(ic->ic_ifp);
2148 case IEEE80211_IOC_POWERSAVE:
2149 switch (ireq->i_val) {
2150 case IEEE80211_POWERSAVE_OFF:
2151 if (ic->ic_flags & IEEE80211_F_PMGTON) {
2152 ic->ic_flags &= ~IEEE80211_F_PMGTON;
2156 case IEEE80211_POWERSAVE_ON:
2157 if ((ic->ic_caps & IEEE80211_C_PMGT) == 0)
2159 else if ((ic->ic_flags & IEEE80211_F_PMGTON) == 0) {
2160 ic->ic_flags |= IEEE80211_F_PMGTON;
2169 case IEEE80211_IOC_POWERSAVESLEEP:
2170 if (ireq->i_val < 0)
2172 ic->ic_lintval = ireq->i_val;
2173 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
2175 case IEEE80211_IOC_RTSTHRESHOLD:
2176 if (!(IEEE80211_RTS_MIN <= ireq->i_val &&
2177 ireq->i_val <= IEEE80211_RTS_MAX))
2179 ic->ic_rtsthreshold = ireq->i_val;
2180 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
2182 case IEEE80211_IOC_PROTMODE:
2183 if (ireq->i_val > IEEE80211_PROT_RTSCTS)
2185 ic->ic_protmode = ireq->i_val;
2186 /* NB: if not operating in 11g this can wait */
2187 if (ic->ic_curmode == IEEE80211_MODE_11G)
2188 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
2190 case IEEE80211_IOC_TXPOWER:
2191 if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0)
2193 if (!(IEEE80211_TXPOWER_MIN < ireq->i_val &&
2194 ireq->i_val < IEEE80211_TXPOWER_MAX))
2196 ic->ic_txpowlimit = ireq->i_val;
2197 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
2199 case IEEE80211_IOC_ROAMING:
2200 if (!(IEEE80211_ROAMING_DEVICE <= ireq->i_val &&
2201 ireq->i_val <= IEEE80211_ROAMING_MANUAL))
2203 ic->ic_roaming = ireq->i_val;
2206 case IEEE80211_IOC_PRIVACY:
2208 /* XXX check for key state? */
2209 ic->ic_flags |= IEEE80211_F_PRIVACY;
2211 ic->ic_flags &= ~IEEE80211_F_PRIVACY;
2213 case IEEE80211_IOC_DROPUNENCRYPTED:
2215 ic->ic_flags |= IEEE80211_F_DROPUNENC;
2217 ic->ic_flags &= ~IEEE80211_F_DROPUNENC;
2219 case IEEE80211_IOC_WPAKEY:
2220 error = ieee80211_ioctl_setkey(ic, ireq);
2222 case IEEE80211_IOC_DELKEY:
2223 error = ieee80211_ioctl_delkey(ic, ireq);
2225 case IEEE80211_IOC_MLME:
2226 error = ieee80211_ioctl_setmlme(ic, ireq);
2228 case IEEE80211_IOC_OPTIE:
2229 error = ieee80211_ioctl_setoptie(ic, ireq);
2231 case IEEE80211_IOC_COUNTERMEASURES:
2233 if ((ic->ic_flags & IEEE80211_F_WPA) == 0)
2235 ic->ic_flags |= IEEE80211_F_COUNTERM;
2237 ic->ic_flags &= ~IEEE80211_F_COUNTERM;
2239 case IEEE80211_IOC_WPA:
2240 if (ireq->i_val > 3)
2242 /* XXX verify ciphers available */
2243 ic->ic_flags &= ~IEEE80211_F_WPA;
2244 switch (ireq->i_val) {
2246 ic->ic_flags |= IEEE80211_F_WPA1;
2249 ic->ic_flags |= IEEE80211_F_WPA2;
2252 ic->ic_flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2;
2255 error = ENETRESET; /* XXX? */
2257 case IEEE80211_IOC_WME:
2259 if ((ic->ic_caps & IEEE80211_C_WME) == 0)
2261 ic->ic_flags |= IEEE80211_F_WME;
2263 ic->ic_flags &= ~IEEE80211_F_WME;
2264 error = ENETRESET; /* XXX maybe not for station? */
2266 case IEEE80211_IOC_HIDESSID:
2268 ic->ic_flags |= IEEE80211_F_HIDESSID;
2270 ic->ic_flags &= ~IEEE80211_F_HIDESSID;
2273 case IEEE80211_IOC_APBRIDGE:
2274 if (ireq->i_val == 0)
2275 ic->ic_flags |= IEEE80211_F_NOBRIDGE;
2277 ic->ic_flags &= ~IEEE80211_F_NOBRIDGE;
2279 case IEEE80211_IOC_MCASTCIPHER:
2280 if ((ic->ic_caps & cipher2cap(ireq->i_val)) == 0 &&
2281 !ieee80211_crypto_available(ireq->i_val))
2283 rsn->rsn_mcastcipher = ireq->i_val;
2284 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
2286 case IEEE80211_IOC_MCASTKEYLEN:
2287 if (!(0 < ireq->i_val && ireq->i_val < IEEE80211_KEYBUF_SIZE))
2289 /* XXX no way to verify driver capability */
2290 rsn->rsn_mcastkeylen = ireq->i_val;
2291 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
2293 case IEEE80211_IOC_UCASTCIPHERS:
2295 * Convert user-specified cipher set to the set
2296 * we can support (via hardware or software).
2297 * NB: this logic intentionally ignores unknown and
2298 * unsupported ciphers so folks can specify 0xff or
2299 * similar and get all available ciphers.
2302 for (j = 1; j < 32; j++) /* NB: skip WEP */
2303 if ((ireq->i_val & (1<<j)) &&
2304 ((ic->ic_caps & cipher2cap(j)) ||
2305 ieee80211_crypto_available(j)))
2307 if (caps == 0) /* nothing available */
2309 /* XXX verify ciphers ok for unicast use? */
2310 /* XXX disallow if running as it'll have no effect */
2311 rsn->rsn_ucastcipherset = caps;
2312 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
2314 case IEEE80211_IOC_UCASTCIPHER:
2315 if ((rsn->rsn_ucastcipherset & cipher2cap(ireq->i_val)) == 0)
2317 rsn->rsn_ucastcipher = ireq->i_val;
2319 case IEEE80211_IOC_UCASTKEYLEN:
2320 if (!(0 < ireq->i_val && ireq->i_val < IEEE80211_KEYBUF_SIZE))
2322 /* XXX no way to verify driver capability */
2323 rsn->rsn_ucastkeylen = ireq->i_val;
2325 case IEEE80211_IOC_DRIVER_CAPS:
2326 /* NB: for testing */
2327 ic->ic_caps = (((uint16_t)ireq->i_val) << 16) |
2328 ((uint16_t)ireq->i_len);
2330 case IEEE80211_IOC_KEYMGTALGS:
2332 rsn->rsn_keymgmtset = ireq->i_val;
2333 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
2335 case IEEE80211_IOC_RSNCAPS:
2337 rsn->rsn_caps = ireq->i_val;
2338 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
2340 case IEEE80211_IOC_BSSID:
2341 if (ireq->i_len != sizeof(tmpbssid))
2343 error = copyin(ireq->i_data, tmpbssid, ireq->i_len);
2346 IEEE80211_ADDR_COPY(ic->ic_des_bssid, tmpbssid);
2347 if (IEEE80211_ADDR_EQ(ic->ic_des_bssid, zerobssid))
2348 ic->ic_flags &= ~IEEE80211_F_DESBSSID;
2350 ic->ic_flags |= IEEE80211_F_DESBSSID;
2353 case IEEE80211_IOC_CHANLIST:
2354 error = ieee80211_ioctl_setchanlist(ic, ireq);
2356 case IEEE80211_IOC_SCAN_REQ:
2357 if (ic->ic_opmode == IEEE80211_M_HOSTAP) /* XXX ignore */
2359 error = ieee80211_setupscan(ic, ic->ic_chan_avail);
2360 if (error == 0) /* XXX background scan */
2361 error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
2363 case IEEE80211_IOC_ADDMAC:
2364 case IEEE80211_IOC_DELMAC:
2365 error = ieee80211_ioctl_macmac(ic, ireq);
2367 case IEEE80211_IOC_MACCMD:
2368 error = ieee80211_ioctl_setmaccmd(ic, ireq);
2370 case IEEE80211_IOC_STA_TXPOW:
2371 error = ieee80211_ioctl_setstatxpow(ic, ireq);
2373 case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */
2374 case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */
2375 case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */
2376 case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */
2377 case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */
2378 case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (bss only) */
2379 error = ieee80211_ioctl_setwmeparam(ic, ireq);
2381 case IEEE80211_IOC_DTIM_PERIOD:
2382 if (ic->ic_opmode != IEEE80211_M_HOSTAP &&
2383 ic->ic_opmode != IEEE80211_M_IBSS)
2385 if (IEEE80211_DTIM_MIN <= ireq->i_val &&
2386 ireq->i_val <= IEEE80211_DTIM_MAX) {
2387 ic->ic_dtim_period = ireq->i_val;
2388 error = ENETRESET; /* requires restart */
2392 case IEEE80211_IOC_BEACON_INTERVAL:
2393 if (ic->ic_opmode != IEEE80211_M_HOSTAP &&
2394 ic->ic_opmode != IEEE80211_M_IBSS)
2396 if (IEEE80211_BINTVAL_MIN <= ireq->i_val &&
2397 ireq->i_val <= IEEE80211_BINTVAL_MAX) {
2398 ic->ic_bintval = ireq->i_val;
2399 error = ENETRESET; /* requires restart */
2403 case IEEE80211_IOC_PUREG:
2405 ic->ic_flags |= IEEE80211_F_PUREG;
2407 ic->ic_flags &= ~IEEE80211_F_PUREG;
2408 /* NB: reset only if we're operating on an 11g channel */
2409 if (ic->ic_curmode == IEEE80211_MODE_11G)
2412 case IEEE80211_IOC_MCAST_RATE:
2413 ic->ic_mcast_rate = ireq->i_val & IEEE80211_RATE_VAL;
2415 case IEEE80211_IOC_FRAGTHRESHOLD:
2416 if ((ic->ic_caps & IEEE80211_C_TXFRAG) == 0 &&
2417 ireq->i_val != IEEE80211_FRAG_MAX)
2419 if (!(IEEE80211_FRAG_MIN <= ireq->i_val &&
2420 ireq->i_val <= IEEE80211_FRAG_MAX))
2422 ic->ic_fragthreshold = ireq->i_val;
2423 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
2425 case IEEE80211_IOC_BURST:
2427 if ((ic->ic_caps & IEEE80211_C_BURST) == 0)
2429 ic->ic_flags |= IEEE80211_F_BURST;
2431 ic->ic_flags &= ~IEEE80211_F_BURST;
2432 error = ENETRESET; /* XXX maybe not for station? */
2434 case IEEE80211_IOC_RATECTL:
2435 if (ireq->i_val < 0 || ireq->i_val >= IEEE80211_RATECTL_MAX ||
2436 ireq->i_val == IEEE80211_RATECTL_NONE) {
2441 error = ieee80211_ratectl_change(ic, ireq->i_val);
2447 if (error == ENETRESET && !IS_UP_AUTO(ic))
2453 ieee80211_ioctl(struct ieee80211com *ic, u_long cmd, caddr_t data,
2456 struct ifnet *ifp = ic->ic_ifp;
2459 struct ifaddr *ifa; /* XXX */
2464 error = ifmedia_ioctl(ifp, (struct ifreq *) data,
2465 &ic->ic_media, cmd);
2468 error = ieee80211_ioctl_get80211(ic, cmd,
2469 (struct ieee80211req *) data, cr);
2472 error = suser_cred(cr, NULL_CRED_OKAY);
2474 error = ieee80211_ioctl_set80211(ic, cmd,
2475 (struct ieee80211req *) data);
2477 case SIOCGIFGENERIC:
2478 error = ieee80211_cfgget(ic, cmd, data, cr);
2480 case SIOCSIFGENERIC:
2481 error = suser_cred(cr, NULL_CRED_OKAY);
2484 error = ieee80211_cfgset(ic, cmd, data);
2486 case SIOCG80211STATS:
2487 ifr = (struct ifreq *)data;
2488 copyout(&ic->ic_stats, ifr->ifr_data, sizeof (ic->ic_stats));
2491 ifr = (struct ifreq *)data;
2492 if (!(IEEE80211_MTU_MIN <= ifr->ifr_mtu &&
2493 ifr->ifr_mtu <= IEEE80211_MTU_MAX))
2496 ifp->if_mtu = ifr->ifr_mtu;
2500 * XXX Handle this directly so we can supress if_init calls.
2501 * XXX This should be done in ether_ioctl but for the moment
2502 * XXX there are too many other parts of the system that
2503 * XXX set IFF_UP and so supress if_init being called when
2506 ifa = (struct ifaddr *) data;
2507 switch (ifa->ifa_addr->sa_family) {
2510 if ((ifp->if_flags & IFF_UP) == 0) {
2511 ifp->if_flags |= IFF_UP;
2512 ifp->if_init(ifp->if_softc);
2514 arp_ifinit(ifp, ifa);
2519 * XXX - This code is probably wrong,
2520 * but has been copied many times.
2523 struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
2525 if (ipx_nullhost(*ina)) {
2526 ina->x_host = *(union ipx_host *)
2529 bcopy(ina->x_host.c_host, IF_LLADDR(ifp),
2536 if ((ifp->if_flags & IFF_UP) == 0) {
2537 ifp->if_flags |= IFF_UP;
2538 ifp->if_init(ifp->if_softc);
2544 error = ether_ioctl(ifp, cmd, data);