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.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 * IEEE 802.11 ioctl support (FreeBSD-specific)
43 #include <sys/endian.h>
44 #include <sys/param.h>
45 #include <sys/kernel.h>
46 #include <sys/socket.h>
47 #include <sys/sockio.h>
48 #include <sys/systm.h>
51 #include <net/if_dl.h>
52 #include <net/if_media.h>
53 #include <net/ethernet.h>
56 #include <netinet/in.h>
57 #include <netinet/if_ether.h>
61 #include <netipx/ipx.h>
62 #include <netipx/ipx_if.h>
65 #include <net80211/ieee80211_var.h>
66 #include <net80211/ieee80211_ioctl.h>
68 #include <dev/wi/if_wavelan_ieee.h>
71 (((_ic)->ic_ifp->if_flags & IFF_UP) && \
72 ((_ic)->ic_ifp->if_drv_flags & IFF_DRV_RUNNING))
73 #define IS_UP_AUTO(_ic) \
74 (IS_UP(_ic) && (_ic)->ic_roaming == IEEE80211_ROAMING_AUTO)
78 * Wireless LAN specific configuration interface, which is compatible
82 struct wi_read_ap_args {
83 int i; /* result count */
84 struct wi_apinfo *ap; /* current entry in result buffer */
85 caddr_t max; /* result buffer bound */
89 wi_read_ap_result(void *arg, struct ieee80211_node *ni)
91 struct ieee80211com *ic = ni->ni_ic;
92 struct wi_read_ap_args *sa = arg;
93 struct wi_apinfo *ap = sa->ap;
94 struct ieee80211_rateset *rs;
97 if ((caddr_t)(ap + 1) > sa->max)
99 memset(ap, 0, sizeof(struct wi_apinfo));
100 if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
101 IEEE80211_ADDR_COPY(ap->bssid, ni->ni_macaddr);
102 ap->namelen = ic->ic_des_esslen;
103 if (ic->ic_des_esslen)
104 memcpy(ap->name, ic->ic_des_essid,
107 IEEE80211_ADDR_COPY(ap->bssid, ni->ni_bssid);
108 ap->namelen = ni->ni_esslen;
110 memcpy(ap->name, ni->ni_essid,
113 ap->channel = ieee80211_chan2ieee(ic, ni->ni_chan);
114 ap->signal = ic->ic_node_getrssi(ni);
115 ap->capinfo = ni->ni_capinfo;
116 ap->interval = ni->ni_intval;
118 for (j = 0; j < rs->rs_nrates; j++) {
119 if (rs->rs_rates[j] & IEEE80211_RATE_BASIC) {
120 ap->rate = (rs->rs_rates[j] &
121 IEEE80211_RATE_VAL) * 5; /* XXX */
128 struct wi_read_prism2_args {
129 int i; /* result count */
130 struct wi_scan_res *res;/* current entry in result buffer */
131 caddr_t max; /* result buffer bound */
135 wi_read_prism2_result(void *arg, struct ieee80211_node *ni)
137 struct ieee80211com *ic = ni->ni_ic;
138 struct wi_read_prism2_args *sa = arg;
139 struct wi_scan_res *res = sa->res;
141 if ((caddr_t)(res + 1) > sa->max)
143 res->wi_chan = ieee80211_chan2ieee(ic, ni->ni_chan);
145 res->wi_signal = ic->ic_node_getrssi(ni);
146 IEEE80211_ADDR_COPY(res->wi_bssid, ni->ni_bssid);
147 res->wi_interval = ni->ni_intval;
148 res->wi_capinfo = ni->ni_capinfo;
149 res->wi_ssid_len = ni->ni_esslen;
150 memcpy(res->wi_ssid, ni->ni_essid, IEEE80211_NWID_LEN);
151 /* NB: assumes wi_srates holds <= ni->ni_rates */
152 memcpy(res->wi_srates, ni->ni_rates.rs_rates,
153 sizeof(res->wi_srates));
154 if (ni->ni_rates.rs_nrates < 10)
155 res->wi_srates[ni->ni_rates.rs_nrates] = 0;
156 res->wi_rate = ni->ni_rates.rs_rates[ni->ni_txrate];
163 struct wi_read_sigcache_args {
164 int i; /* result count */
165 struct wi_sigcache *wsc;/* current entry in result buffer */
166 caddr_t max; /* result buffer bound */
170 wi_read_sigcache(void *arg, struct ieee80211_node *ni)
172 struct ieee80211com *ic = ni->ni_ic;
173 struct wi_read_sigcache_args *sa = arg;
174 struct wi_sigcache *wsc = sa->wsc;
176 if ((caddr_t)(wsc + 1) > sa->max)
178 memset(wsc, 0, sizeof(struct wi_sigcache));
179 IEEE80211_ADDR_COPY(wsc->macsrc, ni->ni_macaddr);
180 wsc->signal = ic->ic_node_getrssi(ni);
187 ieee80211_cfgget(struct ieee80211com *ic, u_long cmd, caddr_t data)
189 struct ifnet *ifp = ic->ic_ifp;
191 struct ifreq *ifr = (struct ifreq *)data;
193 struct wi_ltv_keys *keys;
195 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
199 switch (wreq.wi_type) {
200 case WI_RID_SERIALNO:
201 /* nothing appropriate */
203 case WI_RID_NODENAME:
204 strcpy((char *)&wreq.wi_val[1], hostname);
205 wreq.wi_val[0] = htole16(strlen(hostname));
206 wreq.wi_len = (1 + strlen(hostname) + 1) / 2;
208 case WI_RID_CURRENT_SSID:
209 if (ic->ic_state != IEEE80211_S_RUN) {
214 wreq.wi_val[0] = htole16(ic->ic_bss->ni_esslen);
215 memcpy(&wreq.wi_val[1], ic->ic_bss->ni_essid,
216 ic->ic_bss->ni_esslen);
217 wreq.wi_len = (1 + ic->ic_bss->ni_esslen + 1) / 2;
219 case WI_RID_OWN_SSID:
220 case WI_RID_DESIRED_SSID:
221 wreq.wi_val[0] = htole16(ic->ic_des_esslen);
222 memcpy(&wreq.wi_val[1], ic->ic_des_essid, ic->ic_des_esslen);
223 wreq.wi_len = (1 + ic->ic_des_esslen + 1) / 2;
225 case WI_RID_CURRENT_BSSID:
226 if (ic->ic_state == IEEE80211_S_RUN)
227 IEEE80211_ADDR_COPY(wreq.wi_val, ic->ic_bss->ni_bssid);
229 memset(wreq.wi_val, 0, IEEE80211_ADDR_LEN);
230 wreq.wi_len = IEEE80211_ADDR_LEN / 2;
232 case WI_RID_CHANNEL_LIST:
233 memset(wreq.wi_val, 0, sizeof(wreq.wi_val));
235 * Since channel 0 is not available for DS, channel 1
236 * is assigned to LSB on WaveLAN.
238 if (ic->ic_phytype == IEEE80211_T_DS)
242 for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++)
243 if (isset(ic->ic_chan_active, i)) {
244 setbit((u_int8_t *)wreq.wi_val, j);
245 wreq.wi_len = j / 16 + 1;
248 case WI_RID_OWN_CHNL:
249 wreq.wi_val[0] = htole16(
250 ieee80211_chan2ieee(ic, ic->ic_ibss_chan));
253 case WI_RID_CURRENT_CHAN:
254 wreq.wi_val[0] = htole16(
255 ieee80211_chan2ieee(ic, ic->ic_curchan));
258 case WI_RID_COMMS_QUALITY:
259 wreq.wi_val[0] = 0; /* quality */
260 wreq.wi_val[1] = htole16(ic->ic_node_getrssi(ic->ic_bss));
261 wreq.wi_val[2] = 0; /* noise */
265 wreq.wi_val[0] = htole16((ifp->if_flags & IFF_PROMISC) ? 1 : 0);
268 case WI_RID_PORTTYPE:
269 wreq.wi_val[0] = htole16(ic->ic_opmode);
272 case WI_RID_MAC_NODE:
273 IEEE80211_ADDR_COPY(wreq.wi_val, ic->ic_myaddr);
274 wreq.wi_len = IEEE80211_ADDR_LEN / 2;
277 if (ic->ic_fixed_rate == IEEE80211_FIXED_RATE_NONE)
278 wreq.wi_val[0] = 0; /* auto */
280 wreq.wi_val[0] = htole16(
281 (ic->ic_sup_rates[ic->ic_curmode].rs_rates[ic->ic_fixed_rate] &
282 IEEE80211_RATE_VAL) / 2);
285 case WI_RID_CUR_TX_RATE:
286 wreq.wi_val[0] = htole16(
287 (ic->ic_bss->ni_rates.rs_rates[ic->ic_bss->ni_txrate] &
288 IEEE80211_RATE_VAL) / 2);
291 case WI_RID_RTS_THRESH:
292 wreq.wi_val[0] = htole16(ic->ic_rtsthreshold);
295 case WI_RID_CREATE_IBSS:
297 htole16((ic->ic_flags & IEEE80211_F_IBSSON) ? 1 : 0);
300 case WI_RID_MICROWAVE_OVEN:
301 wreq.wi_val[0] = 0; /* no ... not supported */
304 case WI_RID_ROAMING_MODE:
305 wreq.wi_val[0] = htole16(ic->ic_roaming); /* XXX map */
308 case WI_RID_SYSTEM_SCALE:
309 wreq.wi_val[0] = htole16(1); /* low density ... not supp */
312 case WI_RID_PM_ENABLED:
314 htole16((ic->ic_flags & IEEE80211_F_PMGTON) ? 1 : 0);
317 case WI_RID_MAX_SLEEP:
318 wreq.wi_val[0] = htole16(ic->ic_lintval);
321 case WI_RID_CUR_BEACON_INT:
322 wreq.wi_val[0] = htole16(ic->ic_bss->ni_intval);
325 case WI_RID_WEP_AVAIL:
326 wreq.wi_val[0] = htole16(1); /* always available */
329 case WI_RID_CNFAUTHMODE:
330 wreq.wi_val[0] = htole16(1); /* TODO: open system only */
333 case WI_RID_ENCRYPTION:
335 htole16((ic->ic_flags & IEEE80211_F_PRIVACY) ? 1 : 0);
338 case WI_RID_TX_CRYPT_KEY:
339 wreq.wi_val[0] = htole16(ic->ic_def_txkey);
342 case WI_RID_DEFLT_CRYPT_KEYS:
343 keys = (struct wi_ltv_keys *)&wreq;
344 /* do not show keys to non-root user */
345 error = suser(curthread);
347 memset(keys, 0, sizeof(*keys));
351 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
352 keys->wi_keys[i].wi_keylen =
353 htole16(ic->ic_nw_keys[i].wk_keylen);
354 memcpy(keys->wi_keys[i].wi_keydat,
355 ic->ic_nw_keys[i].wk_key,
356 ic->ic_nw_keys[i].wk_keylen);
358 wreq.wi_len = sizeof(*keys) / 2;
360 case WI_RID_MAX_DATALEN:
361 wreq.wi_val[0] = htole16(ic->ic_fragthreshold);
364 case WI_RID_IFACE_STATS:
365 /* XXX: should be implemented in lower drivers */
367 case WI_RID_READ_APS:
369 * Don't return results until active scan completes.
371 if ((ic->ic_flags & (IEEE80211_F_SCAN|IEEE80211_F_ASCAN)) == 0) {
372 struct wi_read_ap_args args;
375 args.ap = (void *)((char *)wreq.wi_val + sizeof(i));
376 args.max = (void *)(&wreq + 1);
377 ieee80211_iterate_nodes(&ic->ic_scan,
378 wi_read_ap_result, &args);
379 memcpy(wreq.wi_val, &args.i, sizeof(args.i));
380 wreq.wi_len = (sizeof(int) +
381 sizeof(struct wi_apinfo) * args.i) / 2;
386 /* NB: we lie so WI_RID_SCAN_RES can include rates */
388 wreq.wi_len = sizeof(u_int16_t) / 2;
390 case WI_RID_SCAN_RES: /* compatibility interface */
391 if ((ic->ic_flags & (IEEE80211_F_SCAN|IEEE80211_F_ASCAN)) == 0) {
392 struct wi_read_prism2_args args;
393 struct wi_scan_p2_hdr *p2;
395 /* NB: use Prism2 format so we can include rate info */
396 p2 = (struct wi_scan_p2_hdr *)wreq.wi_val;
398 args.res = (void *)&p2[1];
399 args.max = (void *)(&wreq + 1);
400 ieee80211_iterate_nodes(&ic->ic_scan,
401 wi_read_prism2_result, &args);
403 p2->wi_reason = args.i;
404 wreq.wi_len = (sizeof(*p2) +
405 sizeof(struct wi_scan_res) * args.i) / 2;
409 case WI_RID_READ_CACHE: {
410 struct wi_read_sigcache_args args;
412 args.wsc = (struct wi_sigcache *) wreq.wi_val;
413 args.max = (void *)(&wreq + 1);
414 ieee80211_iterate_nodes(&ic->ic_scan, wi_read_sigcache, &args);
415 wreq.wi_len = sizeof(struct wi_sigcache) * args.i / 2;
424 error = copyout(&wreq, ifr->ifr_data, sizeof(wreq));
430 findrate(struct ieee80211com *ic, enum ieee80211_phymode mode, int rate)
432 #define IEEERATE(_ic,_m,_i) \
433 ((_ic)->ic_sup_rates[_m].rs_rates[_i] & IEEE80211_RATE_VAL)
434 int i, nrates = ic->ic_sup_rates[mode].rs_nrates;
435 for (i = 0; i < nrates; i++)
436 if (IEEERATE(ic, mode, i) == rate)
443 * Prepare to do a user-initiated scan for AP's. If no
444 * current/default channel is setup or the current channel
445 * is invalid then pick the first available channel from
446 * the active list as the place to start the scan.
449 ieee80211_setupscan(struct ieee80211com *ic, const u_int8_t chanlist[])
453 * XXX don't permit a scan to be started unless we
454 * know the device is ready. For the moment this means
455 * the device is marked up as this is the required to
456 * initialize the hardware. It would be better to permit
457 * scanning prior to being up but that'll require some
458 * changes to the infrastructure.
462 memcpy(ic->ic_chan_active, chanlist, sizeof(ic->ic_chan_active));
464 * We force the state to INIT before calling ieee80211_new_state
465 * to get ieee80211_begin_scan called. We really want to scan w/o
466 * altering the current state but that's not possible right now.
468 /* XXX handle proberequest case */
469 ic->ic_state = IEEE80211_S_INIT; /* XXX bypass state machine */
474 ieee80211_cfgset(struct ieee80211com *ic, u_long cmd, caddr_t data)
476 struct ifnet *ifp = ic->ic_ifp;
477 int i, j, len, error, rate;
478 struct ifreq *ifr = (struct ifreq *)data;
479 struct wi_ltv_keys *keys;
481 u_char chanlist[roundup(IEEE80211_CHAN_MAX, NBBY)];
483 error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
486 len = wreq.wi_len ? (wreq.wi_len - 1) * 2 : 0;
487 switch (wreq.wi_type) {
488 case WI_RID_SERIALNO:
489 case WI_RID_NODENAME:
491 case WI_RID_CURRENT_SSID:
493 case WI_RID_OWN_SSID:
494 case WI_RID_DESIRED_SSID:
495 if (le16toh(wreq.wi_val[0]) * 2 > len ||
496 le16toh(wreq.wi_val[0]) > IEEE80211_NWID_LEN) {
500 memset(ic->ic_des_essid, 0, sizeof(ic->ic_des_essid));
501 ic->ic_des_esslen = le16toh(wreq.wi_val[0]) * 2;
502 memcpy(ic->ic_des_essid, &wreq.wi_val[1], ic->ic_des_esslen);
505 case WI_RID_CURRENT_BSSID:
507 case WI_RID_OWN_CHNL:
510 i = le16toh(wreq.wi_val[0]);
512 i > IEEE80211_CHAN_MAX ||
513 isclr(ic->ic_chan_active, i))
515 ic->ic_ibss_chan = &ic->ic_channels[i];
516 if (ic->ic_opmode == IEEE80211_M_MONITOR)
517 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
521 case WI_RID_CURRENT_CHAN:
523 case WI_RID_COMMS_QUALITY:
528 if (ifp->if_flags & IFF_PROMISC) {
529 if (wreq.wi_val[0] == 0) {
530 ifp->if_flags &= ~IFF_PROMISC;
534 if (wreq.wi_val[0] != 0) {
535 ifp->if_flags |= IFF_PROMISC;
540 case WI_RID_PORTTYPE:
543 switch (le16toh(wreq.wi_val[0])) {
544 case IEEE80211_M_STA:
546 case IEEE80211_M_IBSS:
547 if (!(ic->ic_caps & IEEE80211_C_IBSS))
550 case IEEE80211_M_AHDEMO:
551 if (ic->ic_phytype != IEEE80211_T_DS ||
552 !(ic->ic_caps & IEEE80211_C_AHDEMO))
555 case IEEE80211_M_HOSTAP:
556 if (!(ic->ic_caps & IEEE80211_C_HOSTAP))
562 if (le16toh(wreq.wi_val[0]) != ic->ic_opmode) {
563 ic->ic_opmode = le16toh(wreq.wi_val[0]);
564 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
568 case WI_RID_MAC_NODE:
569 if (len != IEEE80211_ADDR_LEN)
571 IEEE80211_ADDR_COPY(LLADDR(ifp->if_sadl), wreq.wi_val);
572 /* if_init will copy lladdr into ic_myaddr */
579 if (wreq.wi_val[0] == 0) {
581 ic->ic_fixed_rate = IEEE80211_FIXED_RATE_NONE;
584 rate = 2 * le16toh(wreq.wi_val[0]);
585 if (ic->ic_curmode == IEEE80211_MODE_AUTO) {
587 * In autoselect mode search for the rate. We take
588 * the first instance which may not be right, but we
589 * are limited by the interface. Note that we also
590 * lock the mode to insure the rate is meaningful
593 for (j = IEEE80211_MODE_11A;
594 j < IEEE80211_MODE_MAX; j++) {
595 if ((ic->ic_modecaps & (1<<j)) == 0)
597 i = findrate(ic, j, rate);
605 i = findrate(ic, ic->ic_curmode, rate);
611 ic->ic_fixed_rate = i;
612 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
614 case WI_RID_CUR_TX_RATE:
616 case WI_RID_RTS_THRESH:
619 if (le16toh(wreq.wi_val[0]) != IEEE80211_MAX_LEN)
620 return EINVAL; /* TODO: RTS */
622 case WI_RID_CREATE_IBSS:
625 if (wreq.wi_val[0] != 0) {
626 if ((ic->ic_caps & IEEE80211_C_IBSS) == 0)
628 if ((ic->ic_flags & IEEE80211_F_IBSSON) == 0) {
629 ic->ic_flags |= IEEE80211_F_IBSSON;
630 if (ic->ic_opmode == IEEE80211_M_IBSS &&
631 ic->ic_state == IEEE80211_S_SCAN)
632 error = IS_UP_AUTO(ic) ? ENETRESET : 0;
635 if (ic->ic_flags & IEEE80211_F_IBSSON) {
636 ic->ic_flags &= ~IEEE80211_F_IBSSON;
637 if (ic->ic_flags & IEEE80211_F_SIBSS) {
638 ic->ic_flags &= ~IEEE80211_F_SIBSS;
639 error = IS_UP_AUTO(ic) ? ENETRESET : 0;
644 case WI_RID_MICROWAVE_OVEN:
647 if (wreq.wi_val[0] != 0)
648 return EINVAL; /* not supported */
650 case WI_RID_ROAMING_MODE:
653 i = le16toh(wreq.wi_val[0]);
654 if (i > IEEE80211_ROAMING_MANUAL)
655 return EINVAL; /* not supported */
658 case WI_RID_SYSTEM_SCALE:
661 if (le16toh(wreq.wi_val[0]) != 1)
662 return EINVAL; /* not supported */
664 case WI_RID_PM_ENABLED:
667 if (wreq.wi_val[0] != 0) {
668 if ((ic->ic_caps & IEEE80211_C_PMGT) == 0)
670 if ((ic->ic_flags & IEEE80211_F_PMGTON) == 0) {
671 ic->ic_flags |= IEEE80211_F_PMGTON;
672 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
675 if (ic->ic_flags & IEEE80211_F_PMGTON) {
676 ic->ic_flags &= ~IEEE80211_F_PMGTON;
677 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
681 case WI_RID_MAX_SLEEP:
684 ic->ic_lintval = le16toh(wreq.wi_val[0]);
685 if (ic->ic_flags & IEEE80211_F_PMGTON)
686 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
688 case WI_RID_CUR_BEACON_INT:
690 case WI_RID_WEP_AVAIL:
692 case WI_RID_CNFAUTHMODE:
695 i = le16toh(wreq.wi_val[0]);
696 if (i > IEEE80211_AUTH_WPA)
698 ic->ic_bss->ni_authmode = i; /* XXX ENETRESET? */
701 case WI_RID_ENCRYPTION:
704 if (wreq.wi_val[0] != 0) {
705 if ((ic->ic_caps & IEEE80211_C_WEP) == 0)
707 if ((ic->ic_flags & IEEE80211_F_PRIVACY) == 0) {
708 ic->ic_flags |= IEEE80211_F_PRIVACY;
712 if (ic->ic_flags & IEEE80211_F_PRIVACY) {
713 ic->ic_flags &= ~IEEE80211_F_PRIVACY;
718 case WI_RID_TX_CRYPT_KEY:
721 i = le16toh(wreq.wi_val[0]);
722 if (i >= IEEE80211_WEP_NKID)
724 ic->ic_def_txkey = i;
725 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
727 case WI_RID_DEFLT_CRYPT_KEYS:
728 if (len != sizeof(struct wi_ltv_keys))
730 keys = (struct wi_ltv_keys *)&wreq;
731 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
732 len = le16toh(keys->wi_keys[i].wi_keylen);
733 if (len != 0 && len < IEEE80211_WEP_KEYLEN)
735 if (len > IEEE80211_KEYBUF_SIZE)
738 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
739 struct ieee80211_key *k = &ic->ic_nw_keys[i];
741 len = le16toh(keys->wi_keys[i].wi_keylen);
743 k->wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV;
744 memset(k->wk_key, 0, sizeof(k->wk_key));
745 memcpy(k->wk_key, keys->wi_keys[i].wi_keydat, len);
747 k->wk_type = IEEE80211_CIPHER_WEP;
752 case WI_RID_MAX_DATALEN:
755 len = le16toh(wreq.wi_val[0]);
756 if (len < 350 /* ? */ || len > IEEE80211_MAX_LEN)
758 ic->ic_fragthreshold = len;
759 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
761 case WI_RID_IFACE_STATS:
764 case WI_RID_SCAN_REQ: /* XXX wicontrol */
765 if (ic->ic_opmode == IEEE80211_M_HOSTAP)
767 error = ieee80211_setupscan(ic, ic->ic_chan_avail);
769 error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
771 case WI_RID_SCAN_APS:
772 if (ic->ic_opmode == IEEE80211_M_HOSTAP)
774 len--; /* XXX: tx rate? */
776 case WI_RID_CHANNEL_LIST:
777 memset(chanlist, 0, sizeof(chanlist));
779 * Since channel 0 is not available for DS, channel 1
780 * is assigned to LSB on WaveLAN.
782 if (ic->ic_phytype == IEEE80211_T_DS)
786 for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++) {
789 if (isclr((u_int8_t *)wreq.wi_val, j))
791 if (isclr(ic->ic_chan_active, i)) {
792 if (wreq.wi_type != WI_RID_CHANNEL_LIST)
794 if (isclr(ic->ic_chan_avail, i))
799 error = ieee80211_setupscan(ic, chanlist);
800 if (wreq.wi_type == WI_RID_CHANNEL_LIST) {
801 /* NB: ignore error from ieee80211_setupscan */
803 } else if (error == 0)
804 error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
810 if (error == ENETRESET && !IS_UP_AUTO(ic))
819 case IEEE80211_C_WEP: return IEEE80211_CIPHER_WEP;
820 case IEEE80211_C_AES: return IEEE80211_CIPHER_AES_OCB;
821 case IEEE80211_C_AES_CCM: return IEEE80211_CIPHER_AES_CCM;
822 case IEEE80211_C_CKIP: return IEEE80211_CIPHER_CKIP;
823 case IEEE80211_C_TKIP: return IEEE80211_CIPHER_TKIP;
829 ieee80211_ioctl_getkey(struct ieee80211com *ic, struct ieee80211req *ireq)
831 struct ieee80211_node *ni;
832 struct ieee80211req_key ik;
833 struct ieee80211_key *wk;
834 const struct ieee80211_cipher *cip;
838 if (ireq->i_len != sizeof(ik))
840 error = copyin(ireq->i_data, &ik, sizeof(ik));
844 if (kid == IEEE80211_KEYIX_NONE) {
845 ni = ieee80211_find_node(&ic->ic_sta, ik.ik_macaddr);
847 return EINVAL; /* XXX */
848 wk = &ni->ni_ucastkey;
850 if (kid >= IEEE80211_WEP_NKID)
852 wk = &ic->ic_nw_keys[kid];
853 IEEE80211_ADDR_COPY(&ik.ik_macaddr, ic->ic_bss->ni_macaddr);
857 ik.ik_type = cip->ic_cipher;
858 ik.ik_keylen = wk->wk_keylen;
859 ik.ik_flags = wk->wk_flags & (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV);
860 if (wk->wk_keyix == ic->ic_def_txkey)
861 ik.ik_flags |= IEEE80211_KEY_DEFAULT;
862 if (suser(curthread) == 0) {
863 /* NB: only root can read key data */
864 ik.ik_keyrsc = wk->wk_keyrsc;
865 ik.ik_keytsc = wk->wk_keytsc;
866 memcpy(ik.ik_keydata, wk->wk_key, wk->wk_keylen);
867 if (cip->ic_cipher == IEEE80211_CIPHER_TKIP) {
868 memcpy(ik.ik_keydata+wk->wk_keylen,
869 wk->wk_key + IEEE80211_KEYBUF_SIZE,
870 IEEE80211_MICBUF_SIZE);
871 ik.ik_keylen += IEEE80211_MICBUF_SIZE;
876 memset(ik.ik_keydata, 0, sizeof(ik.ik_keydata));
879 ieee80211_free_node(ni);
880 return copyout(&ik, ireq->i_data, sizeof(ik));
884 ieee80211_ioctl_getchanlist(struct ieee80211com *ic, struct ieee80211req *ireq)
887 if (sizeof(ic->ic_chan_active) < ireq->i_len)
888 ireq->i_len = sizeof(ic->ic_chan_active);
889 return copyout(&ic->ic_chan_active, ireq->i_data, ireq->i_len);
893 ieee80211_ioctl_getchaninfo(struct ieee80211com *ic, struct ieee80211req *ireq)
895 struct ieee80211req_chaninfo chans; /* XXX off stack? */
899 * Since channel 0 is not available for DS, channel 1
900 * is assigned to LSB on WaveLAN.
902 if (ic->ic_phytype == IEEE80211_T_DS)
906 memset(&chans, 0, sizeof(chans));
907 for (; i <= IEEE80211_CHAN_MAX; i++)
908 if (isset(ic->ic_chan_avail, i)) {
909 struct ieee80211_channel *c = &ic->ic_channels[i];
910 chans.ic_chans[chans.ic_nchans].ic_freq = c->ic_freq;
911 chans.ic_chans[chans.ic_nchans].ic_flags = c->ic_flags;
914 space = __offsetof(struct ieee80211req_chaninfo,
915 ic_chans[chans.ic_nchans]);
916 if (space > ireq->i_len)
918 return copyout(&chans, ireq->i_data, space);
922 ieee80211_ioctl_getwpaie(struct ieee80211com *ic, struct ieee80211req *ireq)
924 struct ieee80211_node *ni;
925 struct ieee80211req_wpaie wpaie;
928 if (ireq->i_len < IEEE80211_ADDR_LEN)
930 error = copyin(ireq->i_data, wpaie.wpa_macaddr, IEEE80211_ADDR_LEN);
933 ni = ieee80211_find_node(&ic->ic_sta, wpaie.wpa_macaddr);
935 return EINVAL; /* XXX */
936 memset(wpaie.wpa_ie, 0, sizeof(wpaie.wpa_ie));
937 if (ni->ni_wpa_ie != NULL) {
938 int ielen = ni->ni_wpa_ie[1] + 2;
939 if (ielen > sizeof(wpaie.wpa_ie))
940 ielen = sizeof(wpaie.wpa_ie);
941 memcpy(wpaie.wpa_ie, ni->ni_wpa_ie, ielen);
943 ieee80211_free_node(ni);
944 if (ireq->i_len > sizeof(wpaie))
945 ireq->i_len = sizeof(wpaie);
946 return copyout(&wpaie, ireq->i_data, ireq->i_len);
950 ieee80211_ioctl_getstastats(struct ieee80211com *ic, struct ieee80211req *ireq)
952 struct ieee80211_node *ni;
953 u_int8_t macaddr[IEEE80211_ADDR_LEN];
954 const int off = __offsetof(struct ieee80211req_sta_stats, is_stats);
957 if (ireq->i_len < off)
959 error = copyin(ireq->i_data, macaddr, IEEE80211_ADDR_LEN);
962 ni = ieee80211_find_node(&ic->ic_sta, macaddr);
964 return EINVAL; /* XXX */
965 if (ireq->i_len > sizeof(struct ieee80211req_sta_stats))
966 ireq->i_len = sizeof(struct ieee80211req_sta_stats);
967 /* NB: copy out only the statistics */
968 error = copyout(&ni->ni_stats, (u_int8_t *) ireq->i_data + off,
970 ieee80211_free_node(ni);
975 get_scan_result(struct ieee80211req_scan_result *sr,
976 const struct ieee80211_node *ni)
978 struct ieee80211com *ic = ni->ni_ic;
981 memset(sr, 0, sizeof(*sr));
982 sr->isr_ssid_len = ni->ni_esslen;
983 if (ni->ni_wpa_ie != NULL)
984 ielen += 2+ni->ni_wpa_ie[1];
985 if (ni->ni_wme_ie != NULL)
986 ielen += 2+ni->ni_wme_ie[1];
989 * The value sr->isr_ie_len is defined as a uint8_t, so we
990 * need to be careful to avoid an integer overflow. If the
991 * value would overflow, we will set isr_ie_len to zero, and
992 * ieee80211_ioctl_getscanresults (below) will avoid copying
993 * the (overflowing) data.
997 sr->isr_ie_len = ielen;
998 sr->isr_len = sizeof(*sr) + sr->isr_ssid_len + sr->isr_ie_len;
999 sr->isr_len = roundup(sr->isr_len, sizeof(u_int32_t));
1000 if (ni->ni_chan != IEEE80211_CHAN_ANYC) {
1001 sr->isr_freq = ni->ni_chan->ic_freq;
1002 sr->isr_flags = ni->ni_chan->ic_flags;
1004 sr->isr_rssi = ic->ic_node_getrssi(ni);
1005 sr->isr_intval = ni->ni_intval;
1006 sr->isr_capinfo = ni->ni_capinfo;
1007 sr->isr_erp = ni->ni_erp;
1008 IEEE80211_ADDR_COPY(sr->isr_bssid, ni->ni_bssid);
1009 sr->isr_nrates = ni->ni_rates.rs_nrates;
1010 if (sr->isr_nrates > 15)
1011 sr->isr_nrates = 15;
1012 memcpy(sr->isr_rates, ni->ni_rates.rs_rates, sr->isr_nrates);
1016 ieee80211_ioctl_getscanresults(struct ieee80211com *ic, struct ieee80211req *ireq)
1019 struct ieee80211req_scan_result res;
1020 char data[512]; /* XXX shrink? */
1022 struct ieee80211req_scan_result *sr = &u.res;
1023 struct ieee80211_node_table *nt;
1024 struct ieee80211_node *ni;
1029 space = ireq->i_len;
1033 TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
1034 /* NB: skip pre-scan node state */
1035 if (ni->ni_chan == IEEE80211_CHAN_ANYC)
1037 get_scan_result(sr, ni);
1038 if (sr->isr_len > sizeof(u))
1040 if (space < sr->isr_len)
1042 cp = (u_int8_t *)(sr+1);
1043 memcpy(cp, ni->ni_essid, ni->ni_esslen);
1044 cp += ni->ni_esslen;
1045 if (sr->isr_ie_len > 0 && ni->ni_wpa_ie != NULL) {
1046 memcpy(cp, ni->ni_wpa_ie, 2+ni->ni_wpa_ie[1]);
1047 cp += 2+ni->ni_wpa_ie[1];
1049 if (sr->isr_ie_len > 0 && ni->ni_wme_ie != NULL) {
1050 memcpy(cp, ni->ni_wme_ie, 2+ni->ni_wme_ie[1]);
1051 cp += 2+ni->ni_wme_ie[1];
1053 error = copyout(sr, p, sr->isr_len);
1057 space -= sr->isr_len;
1059 ireq->i_len -= space;
1064 struct ieee80211com *ic;
1065 struct ieee80211req_sta_info *si;
1070 sta_space(const struct ieee80211_node *ni, size_t *ielen)
1073 if (ni->ni_wpa_ie != NULL)
1074 *ielen += 2+ni->ni_wpa_ie[1];
1075 if (ni->ni_wme_ie != NULL)
1076 *ielen += 2+ni->ni_wme_ie[1];
1077 return roundup(sizeof(struct ieee80211req_sta_info) + *ielen,
1082 get_sta_space(void *arg, struct ieee80211_node *ni)
1084 struct stainforeq *req = arg;
1085 struct ieee80211com *ic = ni->ni_ic;
1088 if (ic->ic_opmode == IEEE80211_M_HOSTAP &&
1089 ni->ni_associd == 0) /* only associated stations */
1091 req->space += sta_space(ni, &ielen);
1095 get_sta_info(void *arg, struct ieee80211_node *ni)
1097 struct stainforeq *req = arg;
1098 struct ieee80211com *ic = ni->ni_ic;
1099 struct ieee80211req_sta_info *si;
1103 if (ic->ic_opmode == IEEE80211_M_HOSTAP &&
1104 ni->ni_associd == 0) /* only associated stations */
1106 if (ni->ni_chan == IEEE80211_CHAN_ANYC) /* XXX bogus entry */
1108 len = sta_space(ni, &ielen);
1109 if (len > req->space)
1113 si->isi_ie_len = ielen;
1114 si->isi_freq = ni->ni_chan->ic_freq;
1115 si->isi_flags = ni->ni_chan->ic_flags;
1116 si->isi_state = ni->ni_flags;
1117 si->isi_authmode = ni->ni_authmode;
1118 si->isi_rssi = ic->ic_node_getrssi(ni);
1119 si->isi_capinfo = ni->ni_capinfo;
1120 si->isi_erp = ni->ni_erp;
1121 IEEE80211_ADDR_COPY(si->isi_macaddr, ni->ni_macaddr);
1122 si->isi_nrates = ni->ni_rates.rs_nrates;
1123 if (si->isi_nrates > 15)
1124 si->isi_nrates = 15;
1125 memcpy(si->isi_rates, ni->ni_rates.rs_rates, si->isi_nrates);
1126 si->isi_txrate = ni->ni_txrate;
1127 si->isi_associd = ni->ni_associd;
1128 si->isi_txpower = ni->ni_txpower;
1129 si->isi_vlan = ni->ni_vlan;
1130 if (ni->ni_flags & IEEE80211_NODE_QOS) {
1131 memcpy(si->isi_txseqs, ni->ni_txseqs, sizeof(ni->ni_txseqs));
1132 memcpy(si->isi_rxseqs, ni->ni_rxseqs, sizeof(ni->ni_rxseqs));
1134 si->isi_txseqs[0] = ni->ni_txseqs[0];
1135 si->isi_rxseqs[0] = ni->ni_rxseqs[0];
1137 /* NB: leave all cases in case we relax ni_associd == 0 check */
1138 if (ieee80211_node_is_authorized(ni))
1139 si->isi_inact = ic->ic_inact_run;
1140 else if (ni->ni_associd != 0)
1141 si->isi_inact = ic->ic_inact_auth;
1143 si->isi_inact = ic->ic_inact_init;
1144 si->isi_inact = (si->isi_inact - ni->ni_inact) * IEEE80211_INACT_WAIT;
1146 cp = (u_int8_t *)(si+1);
1147 if (ni->ni_wpa_ie != NULL) {
1148 memcpy(cp, ni->ni_wpa_ie, 2+ni->ni_wpa_ie[1]);
1149 cp += 2+ni->ni_wpa_ie[1];
1151 if (ni->ni_wme_ie != NULL) {
1152 memcpy(cp, ni->ni_wme_ie, 2+ni->ni_wme_ie[1]);
1153 cp += 2+ni->ni_wme_ie[1];
1156 req->si = (struct ieee80211req_sta_info *)(((u_int8_t *)si) + len);
1161 ieee80211_ioctl_getstainfo(struct ieee80211com *ic, struct ieee80211req *ireq)
1163 struct stainforeq req;
1166 if (ireq->i_len < sizeof(struct stainforeq))
1171 ieee80211_iterate_nodes(&ic->ic_sta, get_sta_space, &req);
1172 if (req.space > ireq->i_len)
1173 req.space = ireq->i_len;
1174 if (req.space > 0) {
1179 /* XXX M_WAITOK after driver lock released */
1180 MALLOC(p, void *, space, M_TEMP, M_NOWAIT);
1184 ieee80211_iterate_nodes(&ic->ic_sta, get_sta_info, &req);
1185 ireq->i_len = space - req.space;
1186 error = copyout(p, ireq->i_data, ireq->i_len);
1195 ieee80211_ioctl_getstatxpow(struct ieee80211com *ic, struct ieee80211req *ireq)
1197 struct ieee80211_node *ni;
1198 struct ieee80211req_sta_txpow txpow;
1201 if (ireq->i_len != sizeof(txpow))
1203 error = copyin(ireq->i_data, &txpow, sizeof(txpow));
1206 ni = ieee80211_find_node(&ic->ic_sta, txpow.it_macaddr);
1208 return EINVAL; /* XXX */
1209 txpow.it_txpow = ni->ni_txpower;
1210 error = copyout(&txpow, ireq->i_data, sizeof(txpow));
1211 ieee80211_free_node(ni);
1216 ieee80211_ioctl_getwmeparam(struct ieee80211com *ic, struct ieee80211req *ireq)
1218 struct ieee80211_wme_state *wme = &ic->ic_wme;
1219 struct wmeParams *wmep;
1222 if ((ic->ic_caps & IEEE80211_C_WME) == 0)
1225 ac = (ireq->i_len & IEEE80211_WMEPARAM_VAL);
1226 if (ac >= WME_NUM_AC)
1228 if (ireq->i_len & IEEE80211_WMEPARAM_BSS)
1229 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac];
1231 wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac];
1232 switch (ireq->i_type) {
1233 case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */
1234 ireq->i_val = wmep->wmep_logcwmin;
1236 case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */
1237 ireq->i_val = wmep->wmep_logcwmax;
1239 case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */
1240 ireq->i_val = wmep->wmep_aifsn;
1242 case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */
1243 ireq->i_val = wmep->wmep_txopLimit;
1245 case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */
1246 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac];
1247 ireq->i_val = wmep->wmep_acm;
1249 case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only)*/
1250 wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac];
1251 ireq->i_val = !wmep->wmep_noackPolicy;
1258 ieee80211_ioctl_getmaccmd(struct ieee80211com *ic, struct ieee80211req *ireq)
1260 const struct ieee80211_aclator *acl = ic->ic_acl;
1262 return (acl == NULL ? EINVAL : acl->iac_getioctl(ic, ireq));
1266 * When building the kernel with -O2 on the i386 architecture, gcc
1267 * seems to want to inline this function into ieee80211_ioctl()
1268 * (which is the only routine that calls it). When this happens,
1269 * ieee80211_ioctl() ends up consuming an additional 2K of stack
1270 * space. (Exactly why it needs so much is unclear.) The problem
1271 * is that it's possible for ieee80211_ioctl() to invoke other
1272 * routines (including driver init functions) which could then find
1273 * themselves perilously close to exhausting the stack.
1275 * To avoid this, we deliberately prevent gcc from inlining this
1276 * routine. Another way to avoid this is to use less agressive
1277 * optimization when compiling this file (i.e. -O instead of -O2)
1278 * but special-casing the compilation of this one module in the
1279 * build system would be awkward.
1282 __attribute__ ((noinline))
1285 ieee80211_ioctl_get80211(struct ieee80211com *ic, u_long cmd, struct ieee80211req *ireq)
1287 const struct ieee80211_rsnparms *rsn = &ic->ic_bss->ni_rsn;
1290 u_int8_t tmpkey[IEEE80211_KEYBUF_SIZE];
1291 char tmpssid[IEEE80211_NWID_LEN];
1293 switch (ireq->i_type) {
1294 case IEEE80211_IOC_SSID:
1295 switch (ic->ic_state) {
1296 case IEEE80211_S_INIT:
1297 case IEEE80211_S_SCAN:
1298 ireq->i_len = ic->ic_des_esslen;
1299 memcpy(tmpssid, ic->ic_des_essid, ireq->i_len);
1302 ireq->i_len = ic->ic_bss->ni_esslen;
1303 memcpy(tmpssid, ic->ic_bss->ni_essid,
1307 error = copyout(tmpssid, ireq->i_data, ireq->i_len);
1309 case IEEE80211_IOC_NUMSSIDS:
1312 case IEEE80211_IOC_WEP:
1313 if ((ic->ic_flags & IEEE80211_F_PRIVACY) == 0)
1314 ireq->i_val = IEEE80211_WEP_OFF;
1315 else if (ic->ic_flags & IEEE80211_F_DROPUNENC)
1316 ireq->i_val = IEEE80211_WEP_ON;
1318 ireq->i_val = IEEE80211_WEP_MIXED;
1320 case IEEE80211_IOC_WEPKEY:
1321 kid = (u_int) ireq->i_val;
1322 if (kid >= IEEE80211_WEP_NKID)
1324 len = (u_int) ic->ic_nw_keys[kid].wk_keylen;
1325 /* NB: only root can read WEP keys */
1326 if (suser(curthread) == 0) {
1327 bcopy(ic->ic_nw_keys[kid].wk_key, tmpkey, len);
1332 error = copyout(tmpkey, ireq->i_data, len);
1334 case IEEE80211_IOC_NUMWEPKEYS:
1335 ireq->i_val = IEEE80211_WEP_NKID;
1337 case IEEE80211_IOC_WEPTXKEY:
1338 ireq->i_val = ic->ic_def_txkey;
1340 case IEEE80211_IOC_AUTHMODE:
1341 if (ic->ic_flags & IEEE80211_F_WPA)
1342 ireq->i_val = IEEE80211_AUTH_WPA;
1344 ireq->i_val = ic->ic_bss->ni_authmode;
1346 case IEEE80211_IOC_CHANNEL:
1347 ireq->i_val = ieee80211_chan2ieee(ic, ic->ic_curchan);
1349 case IEEE80211_IOC_POWERSAVE:
1350 if (ic->ic_flags & IEEE80211_F_PMGTON)
1351 ireq->i_val = IEEE80211_POWERSAVE_ON;
1353 ireq->i_val = IEEE80211_POWERSAVE_OFF;
1355 case IEEE80211_IOC_POWERSAVESLEEP:
1356 ireq->i_val = ic->ic_lintval;
1358 case IEEE80211_IOC_RTSTHRESHOLD:
1359 ireq->i_val = ic->ic_rtsthreshold;
1361 case IEEE80211_IOC_PROTMODE:
1362 ireq->i_val = ic->ic_protmode;
1364 case IEEE80211_IOC_TXPOWER:
1365 if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0)
1367 ireq->i_val = ic->ic_txpowlimit;
1369 case IEEE80211_IOC_MCASTCIPHER:
1370 ireq->i_val = rsn->rsn_mcastcipher;
1372 case IEEE80211_IOC_MCASTKEYLEN:
1373 ireq->i_val = rsn->rsn_mcastkeylen;
1375 case IEEE80211_IOC_UCASTCIPHERS:
1377 for (m = 0x1; m != 0; m <<= 1)
1378 if (rsn->rsn_ucastcipherset & m)
1379 ireq->i_val |= 1<<cap2cipher(m);
1381 case IEEE80211_IOC_UCASTCIPHER:
1382 ireq->i_val = rsn->rsn_ucastcipher;
1384 case IEEE80211_IOC_UCASTKEYLEN:
1385 ireq->i_val = rsn->rsn_ucastkeylen;
1387 case IEEE80211_IOC_KEYMGTALGS:
1388 ireq->i_val = rsn->rsn_keymgmtset;
1390 case IEEE80211_IOC_RSNCAPS:
1391 ireq->i_val = rsn->rsn_caps;
1393 case IEEE80211_IOC_WPA:
1394 switch (ic->ic_flags & IEEE80211_F_WPA) {
1395 case IEEE80211_F_WPA1:
1398 case IEEE80211_F_WPA2:
1401 case IEEE80211_F_WPA1 | IEEE80211_F_WPA2:
1409 case IEEE80211_IOC_CHANLIST:
1410 error = ieee80211_ioctl_getchanlist(ic, ireq);
1412 case IEEE80211_IOC_ROAMING:
1413 ireq->i_val = ic->ic_roaming;
1415 case IEEE80211_IOC_PRIVACY:
1416 ireq->i_val = (ic->ic_flags & IEEE80211_F_PRIVACY) != 0;
1418 case IEEE80211_IOC_DROPUNENCRYPTED:
1419 ireq->i_val = (ic->ic_flags & IEEE80211_F_DROPUNENC) != 0;
1421 case IEEE80211_IOC_COUNTERMEASURES:
1422 ireq->i_val = (ic->ic_flags & IEEE80211_F_COUNTERM) != 0;
1424 case IEEE80211_IOC_DRIVER_CAPS:
1425 ireq->i_val = ic->ic_caps>>16;
1426 ireq->i_len = ic->ic_caps&0xffff;
1428 case IEEE80211_IOC_WME:
1429 ireq->i_val = (ic->ic_flags & IEEE80211_F_WME) != 0;
1431 case IEEE80211_IOC_HIDESSID:
1432 ireq->i_val = (ic->ic_flags & IEEE80211_F_HIDESSID) != 0;
1434 case IEEE80211_IOC_APBRIDGE:
1435 ireq->i_val = (ic->ic_flags & IEEE80211_F_NOBRIDGE) == 0;
1437 case IEEE80211_IOC_OPTIE:
1438 if (ic->ic_opt_ie == NULL)
1440 /* NB: truncate, caller can check length */
1441 if (ireq->i_len > ic->ic_opt_ie_len)
1442 ireq->i_len = ic->ic_opt_ie_len;
1443 error = copyout(ic->ic_opt_ie, ireq->i_data, ireq->i_len);
1445 case IEEE80211_IOC_WPAKEY:
1446 error = ieee80211_ioctl_getkey(ic, ireq);
1448 case IEEE80211_IOC_CHANINFO:
1449 error = ieee80211_ioctl_getchaninfo(ic, ireq);
1451 case IEEE80211_IOC_BSSID:
1452 if (ireq->i_len != IEEE80211_ADDR_LEN)
1454 error = copyout(ic->ic_state == IEEE80211_S_RUN ?
1455 ic->ic_bss->ni_bssid :
1457 ireq->i_data, ireq->i_len);
1459 case IEEE80211_IOC_WPAIE:
1460 error = ieee80211_ioctl_getwpaie(ic, ireq);
1462 case IEEE80211_IOC_SCAN_RESULTS:
1463 error = ieee80211_ioctl_getscanresults(ic, ireq);
1465 case IEEE80211_IOC_STA_STATS:
1466 error = ieee80211_ioctl_getstastats(ic, ireq);
1468 case IEEE80211_IOC_TXPOWMAX:
1469 ireq->i_val = ic->ic_bss->ni_txpower;
1471 case IEEE80211_IOC_STA_TXPOW:
1472 error = ieee80211_ioctl_getstatxpow(ic, ireq);
1474 case IEEE80211_IOC_STA_INFO:
1475 error = ieee80211_ioctl_getstainfo(ic, ireq);
1477 case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */
1478 case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */
1479 case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */
1480 case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */
1481 case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */
1482 case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (bss only) */
1483 error = ieee80211_ioctl_getwmeparam(ic, ireq);
1485 case IEEE80211_IOC_DTIM_PERIOD:
1486 ireq->i_val = ic->ic_dtim_period;
1488 case IEEE80211_IOC_BEACON_INTERVAL:
1489 /* NB: get from ic_bss for station mode */
1490 ireq->i_val = ic->ic_bss->ni_intval;
1492 case IEEE80211_IOC_PUREG:
1493 ireq->i_val = (ic->ic_flags & IEEE80211_F_PUREG) != 0;
1495 case IEEE80211_IOC_MCAST_RATE:
1496 ireq->i_val = ic->ic_mcast_rate;
1498 case IEEE80211_IOC_FRAGTHRESHOLD:
1499 ireq->i_val = ic->ic_fragthreshold;
1501 case IEEE80211_IOC_MACCMD:
1502 error = ieee80211_ioctl_getmaccmd(ic, ireq);
1504 case IEEE80211_IOC_BURST:
1505 ireq->i_val = (ic->ic_flags & IEEE80211_F_BURST) != 0;
1515 ieee80211_ioctl_setoptie(struct ieee80211com *ic, struct ieee80211req *ireq)
1521 * NB: Doing this for ap operation could be useful (e.g. for
1522 * WPA and/or WME) except that it typically is worthless
1523 * without being able to intervene when processing
1524 * association response frames--so disallow it for now.
1526 if (ic->ic_opmode != IEEE80211_M_STA)
1528 if (ireq->i_len > IEEE80211_MAX_OPT_IE)
1530 MALLOC(ie, void *, ireq->i_len, M_DEVBUF, M_NOWAIT);
1533 error = copyin(ireq->i_data, ie, ireq->i_len);
1534 /* XXX sanity check data? */
1535 if (ic->ic_opt_ie != NULL)
1536 FREE(ic->ic_opt_ie, M_DEVBUF);
1538 ic->ic_opt_ie_len = ireq->i_len;
1543 ieee80211_ioctl_setkey(struct ieee80211com *ic, struct ieee80211req *ireq)
1545 struct ieee80211req_key ik;
1546 struct ieee80211_node *ni;
1547 struct ieee80211_key *wk;
1551 if (ireq->i_len != sizeof(ik))
1553 error = copyin(ireq->i_data, &ik, sizeof(ik));
1556 /* NB: cipher support is verified by ieee80211_crypt_newkey */
1557 /* NB: this also checks ik->ik_keylen > sizeof(wk->wk_key) */
1558 if (ik.ik_keylen > sizeof(ik.ik_keydata))
1561 if (kid == IEEE80211_KEYIX_NONE) {
1562 /* XXX unicast keys currently must be tx/rx */
1563 if (ik.ik_flags != (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV))
1565 if (ic->ic_opmode == IEEE80211_M_STA) {
1566 ni = ieee80211_ref_node(ic->ic_bss);
1567 if (!IEEE80211_ADDR_EQ(ik.ik_macaddr, ni->ni_bssid)) {
1568 ieee80211_free_node(ni);
1569 return EADDRNOTAVAIL;
1572 ni = ieee80211_find_node(&ic->ic_sta, ik.ik_macaddr);
1576 wk = &ni->ni_ucastkey;
1578 if (kid >= IEEE80211_WEP_NKID)
1580 wk = &ic->ic_nw_keys[kid];
1584 ieee80211_key_update_begin(ic);
1585 if (ieee80211_crypto_newkey(ic, ik.ik_type, ik.ik_flags, wk)) {
1586 wk->wk_keylen = ik.ik_keylen;
1587 /* NB: MIC presence is implied by cipher type */
1588 if (wk->wk_keylen > IEEE80211_KEYBUF_SIZE)
1589 wk->wk_keylen = IEEE80211_KEYBUF_SIZE;
1590 wk->wk_keyrsc = ik.ik_keyrsc;
1591 wk->wk_keytsc = 0; /* new key, reset */
1592 memset(wk->wk_key, 0, sizeof(wk->wk_key));
1593 memcpy(wk->wk_key, ik.ik_keydata, ik.ik_keylen);
1594 if (!ieee80211_crypto_setkey(ic, wk,
1595 ni != NULL ? ni->ni_macaddr : ik.ik_macaddr))
1597 else if ((ik.ik_flags & IEEE80211_KEY_DEFAULT))
1598 ic->ic_def_txkey = kid;
1601 ieee80211_key_update_end(ic);
1603 ieee80211_free_node(ni);
1608 ieee80211_ioctl_delkey(struct ieee80211com *ic, struct ieee80211req *ireq)
1610 struct ieee80211req_del_key dk;
1613 if (ireq->i_len != sizeof(dk))
1615 error = copyin(ireq->i_data, &dk, sizeof(dk));
1619 /* XXX u_int8_t -> u_int16_t */
1620 if (dk.idk_keyix == (u_int8_t) IEEE80211_KEYIX_NONE) {
1621 struct ieee80211_node *ni;
1623 if (ic->ic_opmode == IEEE80211_M_STA) {
1624 ni = ieee80211_ref_node(ic->ic_bss);
1625 if (!IEEE80211_ADDR_EQ(dk.idk_macaddr, ni->ni_bssid)) {
1626 ieee80211_free_node(ni);
1627 return EADDRNOTAVAIL;
1630 ni = ieee80211_find_node(&ic->ic_sta, dk.idk_macaddr);
1634 /* XXX error return */
1635 ieee80211_node_delucastkey(ni);
1636 ieee80211_free_node(ni);
1638 if (kid >= IEEE80211_WEP_NKID)
1640 /* XXX error return */
1641 ieee80211_crypto_delkey(ic, &ic->ic_nw_keys[kid]);
1647 domlme(void *arg, struct ieee80211_node *ni)
1649 struct ieee80211com *ic = ni->ni_ic;
1650 struct ieee80211req_mlme *mlme = arg;
1652 if (ni->ni_associd != 0) {
1653 IEEE80211_SEND_MGMT(ic, ni,
1654 mlme->im_op == IEEE80211_MLME_DEAUTH ?
1655 IEEE80211_FC0_SUBTYPE_DEAUTH :
1656 IEEE80211_FC0_SUBTYPE_DISASSOC,
1659 ieee80211_node_leave(ic, ni);
1663 ieee80211_ioctl_setmlme(struct ieee80211com *ic, struct ieee80211req *ireq)
1665 struct ieee80211req_mlme mlme;
1666 struct ieee80211_node *ni;
1669 if (ireq->i_len != sizeof(mlme))
1671 error = copyin(ireq->i_data, &mlme, sizeof(mlme));
1674 switch (mlme.im_op) {
1675 case IEEE80211_MLME_ASSOC:
1676 if (ic->ic_opmode != IEEE80211_M_STA)
1678 /* XXX must be in S_SCAN state? */
1680 if (mlme.im_ssid_len != 0) {
1682 * Desired ssid specified; must match both bssid and
1683 * ssid to distinguish ap advertising multiple ssid's.
1685 ni = ieee80211_find_node_with_ssid(&ic->ic_scan,
1687 mlme.im_ssid_len, mlme.im_ssid);
1690 * Normal case; just match bssid.
1692 ni = ieee80211_find_node(&ic->ic_scan, mlme.im_macaddr);
1696 if (!ieee80211_sta_join(ic, ni)) {
1697 ieee80211_free_node(ni);
1701 case IEEE80211_MLME_DISASSOC:
1702 case IEEE80211_MLME_DEAUTH:
1703 switch (ic->ic_opmode) {
1704 case IEEE80211_M_STA:
1705 /* XXX not quite right */
1706 ieee80211_new_state(ic, IEEE80211_S_INIT,
1709 case IEEE80211_M_HOSTAP:
1710 /* NB: the broadcast address means do 'em all */
1711 if (!IEEE80211_ADDR_EQ(mlme.im_macaddr, ic->ic_ifp->if_broadcastaddr)) {
1712 if ((ni = ieee80211_find_node(&ic->ic_sta,
1713 mlme.im_macaddr)) == NULL)
1716 ieee80211_free_node(ni);
1718 ieee80211_iterate_nodes(&ic->ic_sta,
1726 case IEEE80211_MLME_AUTHORIZE:
1727 case IEEE80211_MLME_UNAUTHORIZE:
1728 if (ic->ic_opmode != IEEE80211_M_HOSTAP)
1730 ni = ieee80211_find_node(&ic->ic_sta, mlme.im_macaddr);
1733 if (mlme.im_op == IEEE80211_MLME_AUTHORIZE)
1734 ieee80211_node_authorize(ni);
1736 ieee80211_node_unauthorize(ni);
1737 ieee80211_free_node(ni);
1746 ieee80211_ioctl_macmac(struct ieee80211com *ic, struct ieee80211req *ireq)
1748 u_int8_t mac[IEEE80211_ADDR_LEN];
1749 const struct ieee80211_aclator *acl = ic->ic_acl;
1752 if (ireq->i_len != sizeof(mac))
1754 error = copyin(ireq->i_data, mac, ireq->i_len);
1758 acl = ieee80211_aclator_get("mac");
1759 if (acl == NULL || !acl->iac_attach(ic))
1763 if (ireq->i_type == IEEE80211_IOC_ADDMAC)
1764 acl->iac_add(ic, mac);
1766 acl->iac_remove(ic, mac);
1771 ieee80211_ioctl_setmaccmd(struct ieee80211com *ic, struct ieee80211req *ireq)
1773 const struct ieee80211_aclator *acl = ic->ic_acl;
1775 switch (ireq->i_val) {
1776 case IEEE80211_MACCMD_POLICY_OPEN:
1777 case IEEE80211_MACCMD_POLICY_ALLOW:
1778 case IEEE80211_MACCMD_POLICY_DENY:
1780 acl = ieee80211_aclator_get("mac");
1781 if (acl == NULL || !acl->iac_attach(ic))
1785 acl->iac_setpolicy(ic, ireq->i_val);
1787 case IEEE80211_MACCMD_FLUSH:
1790 /* NB: silently ignore when not in use */
1792 case IEEE80211_MACCMD_DETACH:
1795 acl->iac_detach(ic);
1802 return acl->iac_setioctl(ic, ireq);
1808 ieee80211_ioctl_setchanlist(struct ieee80211com *ic, struct ieee80211req *ireq)
1810 struct ieee80211req_chanlist list;
1811 u_char chanlist[IEEE80211_CHAN_BYTES];
1814 if (ireq->i_len != sizeof(list))
1816 error = copyin(ireq->i_data, &list, sizeof(list));
1819 memset(chanlist, 0, sizeof(chanlist));
1821 * Since channel 0 is not available for DS, channel 1
1822 * is assigned to LSB on WaveLAN.
1824 if (ic->ic_phytype == IEEE80211_T_DS)
1828 for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++) {
1830 * NB: silently discard unavailable channels so users
1831 * can specify 1-255 to get all available channels.
1833 if (isset(list.ic_channels, j) && isset(ic->ic_chan_avail, i))
1834 setbit(chanlist, i);
1836 if (ic->ic_ibss_chan == NULL ||
1837 isclr(chanlist, ieee80211_chan2ieee(ic, ic->ic_ibss_chan))) {
1838 for (i = 0; i <= IEEE80211_CHAN_MAX; i++)
1839 if (isset(chanlist, i)) {
1840 ic->ic_ibss_chan = &ic->ic_channels[i];
1843 return EINVAL; /* no active channels */
1847 memcpy(ic->ic_chan_active, chanlist, sizeof(ic->ic_chan_active));
1848 return IS_UP_AUTO(ic) ? ENETRESET : 0;
1852 ieee80211_ioctl_setstatxpow(struct ieee80211com *ic, struct ieee80211req *ireq)
1854 struct ieee80211_node *ni;
1855 struct ieee80211req_sta_txpow txpow;
1858 if (ireq->i_len != sizeof(txpow))
1860 error = copyin(ireq->i_data, &txpow, sizeof(txpow));
1863 ni = ieee80211_find_node(&ic->ic_sta, txpow.it_macaddr);
1865 return EINVAL; /* XXX */
1866 ni->ni_txpower = txpow.it_txpow;
1867 ieee80211_free_node(ni);
1872 ieee80211_ioctl_setwmeparam(struct ieee80211com *ic, struct ieee80211req *ireq)
1874 struct ieee80211_wme_state *wme = &ic->ic_wme;
1875 struct wmeParams *wmep, *chanp;
1878 if ((ic->ic_caps & IEEE80211_C_WME) == 0)
1881 isbss = (ireq->i_len & IEEE80211_WMEPARAM_BSS);
1882 ac = (ireq->i_len & IEEE80211_WMEPARAM_VAL);
1883 if (ac >= WME_NUM_AC)
1886 chanp = &wme->wme_bssChanParams.cap_wmeParams[ac];
1887 wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac];
1889 chanp = &wme->wme_chanParams.cap_wmeParams[ac];
1890 wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac];
1892 switch (ireq->i_type) {
1893 case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */
1895 wmep->wmep_logcwmin = ireq->i_val;
1896 if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
1897 chanp->wmep_logcwmin = ireq->i_val;
1899 wmep->wmep_logcwmin = chanp->wmep_logcwmin =
1903 case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */
1905 wmep->wmep_logcwmax = ireq->i_val;
1906 if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
1907 chanp->wmep_logcwmax = ireq->i_val;
1909 wmep->wmep_logcwmax = chanp->wmep_logcwmax =
1913 case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */
1915 wmep->wmep_aifsn = ireq->i_val;
1916 if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
1917 chanp->wmep_aifsn = ireq->i_val;
1919 wmep->wmep_aifsn = chanp->wmep_aifsn = ireq->i_val;
1922 case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */
1924 wmep->wmep_txopLimit = ireq->i_val;
1925 if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
1926 chanp->wmep_txopLimit = ireq->i_val;
1928 wmep->wmep_txopLimit = chanp->wmep_txopLimit =
1932 case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */
1933 wmep->wmep_acm = ireq->i_val;
1934 if ((wme->wme_flags & WME_F_AGGRMODE) == 0)
1935 chanp->wmep_acm = ireq->i_val;
1937 case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only)*/
1938 wmep->wmep_noackPolicy = chanp->wmep_noackPolicy =
1942 ieee80211_wme_updateparams(ic);
1947 cipher2cap(int cipher)
1950 case IEEE80211_CIPHER_WEP: return IEEE80211_C_WEP;
1951 case IEEE80211_CIPHER_AES_OCB: return IEEE80211_C_AES;
1952 case IEEE80211_CIPHER_AES_CCM: return IEEE80211_C_AES_CCM;
1953 case IEEE80211_CIPHER_CKIP: return IEEE80211_C_CKIP;
1954 case IEEE80211_CIPHER_TKIP: return IEEE80211_C_TKIP;
1960 ieee80211_ioctl_set80211(struct ieee80211com *ic, u_long cmd, struct ieee80211req *ireq)
1962 static const u_int8_t zerobssid[IEEE80211_ADDR_LEN];
1963 struct ieee80211_rsnparms *rsn = &ic->ic_bss->ni_rsn;
1965 const struct ieee80211_authenticator *auth;
1966 u_int8_t tmpkey[IEEE80211_KEYBUF_SIZE];
1967 char tmpssid[IEEE80211_NWID_LEN];
1968 u_int8_t tmpbssid[IEEE80211_ADDR_LEN];
1969 struct ieee80211_key *k;
1974 switch (ireq->i_type) {
1975 case IEEE80211_IOC_SSID:
1976 if (ireq->i_val != 0 ||
1977 ireq->i_len > IEEE80211_NWID_LEN)
1979 error = copyin(ireq->i_data, tmpssid, ireq->i_len);
1982 memset(ic->ic_des_essid, 0, IEEE80211_NWID_LEN);
1983 ic->ic_des_esslen = ireq->i_len;
1984 memcpy(ic->ic_des_essid, tmpssid, ireq->i_len);
1987 case IEEE80211_IOC_WEP:
1988 switch (ireq->i_val) {
1989 case IEEE80211_WEP_OFF:
1990 ic->ic_flags &= ~IEEE80211_F_PRIVACY;
1991 ic->ic_flags &= ~IEEE80211_F_DROPUNENC;
1993 case IEEE80211_WEP_ON:
1994 ic->ic_flags |= IEEE80211_F_PRIVACY;
1995 ic->ic_flags |= IEEE80211_F_DROPUNENC;
1997 case IEEE80211_WEP_MIXED:
1998 ic->ic_flags |= IEEE80211_F_PRIVACY;
1999 ic->ic_flags &= ~IEEE80211_F_DROPUNENC;
2004 case IEEE80211_IOC_WEPKEY:
2005 kid = (u_int) ireq->i_val;
2006 if (kid >= IEEE80211_WEP_NKID)
2008 k = &ic->ic_nw_keys[kid];
2009 if (ireq->i_len == 0) {
2010 /* zero-len =>'s delete any existing key */
2011 (void) ieee80211_crypto_delkey(ic, k);
2014 if (ireq->i_len > sizeof(tmpkey))
2016 memset(tmpkey, 0, sizeof(tmpkey));
2017 error = copyin(ireq->i_data, tmpkey, ireq->i_len);
2020 ieee80211_key_update_begin(ic);
2021 k->wk_keyix = kid; /* NB: force fixed key id */
2022 if (ieee80211_crypto_newkey(ic, IEEE80211_CIPHER_WEP,
2023 IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV, k)) {
2024 k->wk_keylen = ireq->i_len;
2025 memcpy(k->wk_key, tmpkey, sizeof(tmpkey));
2026 if (!ieee80211_crypto_setkey(ic, k, ic->ic_myaddr))
2030 ieee80211_key_update_end(ic);
2031 if (!error) /* NB: for compatibility */
2034 case IEEE80211_IOC_WEPTXKEY:
2035 kid = (u_int) ireq->i_val;
2036 if (kid >= IEEE80211_WEP_NKID &&
2037 (u_int16_t) kid != IEEE80211_KEYIX_NONE)
2039 ic->ic_def_txkey = kid;
2040 error = ENETRESET; /* push to hardware */
2042 case IEEE80211_IOC_AUTHMODE:
2043 switch (ireq->i_val) {
2044 case IEEE80211_AUTH_WPA:
2045 case IEEE80211_AUTH_8021X: /* 802.1x */
2046 case IEEE80211_AUTH_OPEN: /* open */
2047 case IEEE80211_AUTH_SHARED: /* shared-key */
2048 case IEEE80211_AUTH_AUTO: /* auto */
2049 auth = ieee80211_authenticator_get(ireq->i_val);
2056 switch (ireq->i_val) {
2057 case IEEE80211_AUTH_WPA: /* WPA w/ 802.1x */
2058 ic->ic_flags |= IEEE80211_F_PRIVACY;
2059 ireq->i_val = IEEE80211_AUTH_8021X;
2061 case IEEE80211_AUTH_OPEN: /* open */
2062 ic->ic_flags &= ~(IEEE80211_F_WPA|IEEE80211_F_PRIVACY);
2064 case IEEE80211_AUTH_SHARED: /* shared-key */
2065 case IEEE80211_AUTH_8021X: /* 802.1x */
2066 ic->ic_flags &= ~IEEE80211_F_WPA;
2067 /* both require a key so mark the PRIVACY capability */
2068 ic->ic_flags |= IEEE80211_F_PRIVACY;
2070 case IEEE80211_AUTH_AUTO: /* auto */
2071 ic->ic_flags &= ~IEEE80211_F_WPA;
2072 /* XXX PRIVACY handling? */
2073 /* XXX what's the right way to do this? */
2076 /* NB: authenticator attach/detach happens on state change */
2077 ic->ic_bss->ni_authmode = ireq->i_val;
2078 /* XXX mixed/mode/usage? */
2082 case IEEE80211_IOC_CHANNEL:
2083 /* XXX 0xffff overflows 16-bit signed */
2084 if (ireq->i_val == 0 ||
2085 ireq->i_val == (int16_t) IEEE80211_CHAN_ANY)
2086 ic->ic_des_chan = IEEE80211_CHAN_ANYC;
2087 else if ((u_int) ireq->i_val > IEEE80211_CHAN_MAX ||
2088 isclr(ic->ic_chan_active, ireq->i_val)) {
2091 ic->ic_ibss_chan = ic->ic_des_chan =
2092 &ic->ic_channels[ireq->i_val];
2093 switch (ic->ic_state) {
2094 case IEEE80211_S_INIT:
2095 case IEEE80211_S_SCAN:
2100 * If the desired channel has changed (to something
2101 * other than any) and we're not already scanning,
2102 * then kick the state machine.
2104 if (ic->ic_des_chan != IEEE80211_CHAN_ANYC &&
2105 ic->ic_bss->ni_chan != ic->ic_des_chan &&
2106 (ic->ic_flags & IEEE80211_F_SCAN) == 0)
2110 if (error == ENETRESET &&
2111 ic->ic_opmode == IEEE80211_M_MONITOR) {
2114 * Monitor mode can switch directly.
2116 if (ic->ic_des_chan != IEEE80211_CHAN_ANYC)
2117 ic->ic_curchan = ic->ic_des_chan;
2118 error = ic->ic_reset(ic->ic_ifp);
2123 case IEEE80211_IOC_POWERSAVE:
2124 switch (ireq->i_val) {
2125 case IEEE80211_POWERSAVE_OFF:
2126 if (ic->ic_flags & IEEE80211_F_PMGTON) {
2127 ic->ic_flags &= ~IEEE80211_F_PMGTON;
2131 case IEEE80211_POWERSAVE_ON:
2132 if ((ic->ic_caps & IEEE80211_C_PMGT) == 0)
2134 else if ((ic->ic_flags & IEEE80211_F_PMGTON) == 0) {
2135 ic->ic_flags |= IEEE80211_F_PMGTON;
2144 case IEEE80211_IOC_POWERSAVESLEEP:
2145 if (ireq->i_val < 0)
2147 ic->ic_lintval = ireq->i_val;
2148 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
2150 case IEEE80211_IOC_RTSTHRESHOLD:
2151 if (!(IEEE80211_RTS_MIN <= ireq->i_val &&
2152 ireq->i_val <= IEEE80211_RTS_MAX))
2154 ic->ic_rtsthreshold = ireq->i_val;
2155 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
2157 case IEEE80211_IOC_PROTMODE:
2158 if (ireq->i_val > IEEE80211_PROT_RTSCTS)
2160 ic->ic_protmode = ireq->i_val;
2161 /* NB: if not operating in 11g this can wait */
2162 if (ic->ic_curmode == IEEE80211_MODE_11G)
2163 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
2165 case IEEE80211_IOC_TXPOWER:
2166 if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0)
2168 if (!(IEEE80211_TXPOWER_MIN < ireq->i_val &&
2169 ireq->i_val < IEEE80211_TXPOWER_MAX))
2171 ic->ic_txpowlimit = ireq->i_val;
2172 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
2174 case IEEE80211_IOC_ROAMING:
2175 if (!(IEEE80211_ROAMING_DEVICE <= ireq->i_val &&
2176 ireq->i_val <= IEEE80211_ROAMING_MANUAL))
2178 ic->ic_roaming = ireq->i_val;
2181 case IEEE80211_IOC_PRIVACY:
2183 /* XXX check for key state? */
2184 ic->ic_flags |= IEEE80211_F_PRIVACY;
2186 ic->ic_flags &= ~IEEE80211_F_PRIVACY;
2188 case IEEE80211_IOC_DROPUNENCRYPTED:
2190 ic->ic_flags |= IEEE80211_F_DROPUNENC;
2192 ic->ic_flags &= ~IEEE80211_F_DROPUNENC;
2194 case IEEE80211_IOC_WPAKEY:
2195 error = ieee80211_ioctl_setkey(ic, ireq);
2197 case IEEE80211_IOC_DELKEY:
2198 error = ieee80211_ioctl_delkey(ic, ireq);
2200 case IEEE80211_IOC_MLME:
2201 error = ieee80211_ioctl_setmlme(ic, ireq);
2203 case IEEE80211_IOC_OPTIE:
2204 error = ieee80211_ioctl_setoptie(ic, ireq);
2206 case IEEE80211_IOC_COUNTERMEASURES:
2208 if ((ic->ic_flags & IEEE80211_F_WPA) == 0)
2210 ic->ic_flags |= IEEE80211_F_COUNTERM;
2212 ic->ic_flags &= ~IEEE80211_F_COUNTERM;
2214 case IEEE80211_IOC_WPA:
2215 if (ireq->i_val > 3)
2217 /* XXX verify ciphers available */
2218 ic->ic_flags &= ~IEEE80211_F_WPA;
2219 switch (ireq->i_val) {
2221 ic->ic_flags |= IEEE80211_F_WPA1;
2224 ic->ic_flags |= IEEE80211_F_WPA2;
2227 ic->ic_flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2;
2230 error = ENETRESET; /* XXX? */
2232 case IEEE80211_IOC_WME:
2234 if ((ic->ic_caps & IEEE80211_C_WME) == 0)
2236 ic->ic_flags |= IEEE80211_F_WME;
2238 ic->ic_flags &= ~IEEE80211_F_WME;
2239 error = ENETRESET; /* XXX maybe not for station? */
2241 case IEEE80211_IOC_HIDESSID:
2243 ic->ic_flags |= IEEE80211_F_HIDESSID;
2245 ic->ic_flags &= ~IEEE80211_F_HIDESSID;
2248 case IEEE80211_IOC_APBRIDGE:
2249 if (ireq->i_val == 0)
2250 ic->ic_flags |= IEEE80211_F_NOBRIDGE;
2252 ic->ic_flags &= ~IEEE80211_F_NOBRIDGE;
2254 case IEEE80211_IOC_MCASTCIPHER:
2255 if ((ic->ic_caps & cipher2cap(ireq->i_val)) == 0 &&
2256 !ieee80211_crypto_available(ireq->i_val))
2258 rsn->rsn_mcastcipher = ireq->i_val;
2259 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
2261 case IEEE80211_IOC_MCASTKEYLEN:
2262 if (!(0 < ireq->i_val && ireq->i_val < IEEE80211_KEYBUF_SIZE))
2264 /* XXX no way to verify driver capability */
2265 rsn->rsn_mcastkeylen = ireq->i_val;
2266 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
2268 case IEEE80211_IOC_UCASTCIPHERS:
2270 * Convert user-specified cipher set to the set
2271 * we can support (via hardware or software).
2272 * NB: this logic intentionally ignores unknown and
2273 * unsupported ciphers so folks can specify 0xff or
2274 * similar and get all available ciphers.
2277 for (j = 1; j < 32; j++) /* NB: skip WEP */
2278 if ((ireq->i_val & (1<<j)) &&
2279 ((ic->ic_caps & cipher2cap(j)) ||
2280 ieee80211_crypto_available(j)))
2282 if (caps == 0) /* nothing available */
2284 /* XXX verify ciphers ok for unicast use? */
2285 /* XXX disallow if running as it'll have no effect */
2286 rsn->rsn_ucastcipherset = caps;
2287 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
2289 case IEEE80211_IOC_UCASTCIPHER:
2290 if ((rsn->rsn_ucastcipherset & cipher2cap(ireq->i_val)) == 0)
2292 rsn->rsn_ucastcipher = ireq->i_val;
2294 case IEEE80211_IOC_UCASTKEYLEN:
2295 if (!(0 < ireq->i_val && ireq->i_val < IEEE80211_KEYBUF_SIZE))
2297 /* XXX no way to verify driver capability */
2298 rsn->rsn_ucastkeylen = ireq->i_val;
2300 case IEEE80211_IOC_DRIVER_CAPS:
2301 /* NB: for testing */
2302 ic->ic_caps = (((u_int16_t) ireq->i_val) << 16) |
2303 ((u_int16_t) ireq->i_len);
2305 case IEEE80211_IOC_KEYMGTALGS:
2307 rsn->rsn_keymgmtset = ireq->i_val;
2308 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
2310 case IEEE80211_IOC_RSNCAPS:
2312 rsn->rsn_caps = ireq->i_val;
2313 error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0;
2315 case IEEE80211_IOC_BSSID:
2316 if (ireq->i_len != sizeof(tmpbssid))
2318 error = copyin(ireq->i_data, tmpbssid, ireq->i_len);
2321 IEEE80211_ADDR_COPY(ic->ic_des_bssid, tmpbssid);
2322 if (IEEE80211_ADDR_EQ(ic->ic_des_bssid, zerobssid))
2323 ic->ic_flags &= ~IEEE80211_F_DESBSSID;
2325 ic->ic_flags |= IEEE80211_F_DESBSSID;
2328 case IEEE80211_IOC_CHANLIST:
2329 error = ieee80211_ioctl_setchanlist(ic, ireq);
2331 case IEEE80211_IOC_SCAN_REQ:
2332 if (ic->ic_opmode == IEEE80211_M_HOSTAP) /* XXX ignore */
2334 error = ieee80211_setupscan(ic, ic->ic_chan_avail);
2335 if (error == 0) /* XXX background scan */
2336 error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
2338 case IEEE80211_IOC_ADDMAC:
2339 case IEEE80211_IOC_DELMAC:
2340 error = ieee80211_ioctl_macmac(ic, ireq);
2342 case IEEE80211_IOC_MACCMD:
2343 error = ieee80211_ioctl_setmaccmd(ic, ireq);
2345 case IEEE80211_IOC_STA_TXPOW:
2346 error = ieee80211_ioctl_setstatxpow(ic, ireq);
2348 case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */
2349 case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */
2350 case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */
2351 case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */
2352 case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */
2353 case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (bss only) */
2354 error = ieee80211_ioctl_setwmeparam(ic, ireq);
2356 case IEEE80211_IOC_DTIM_PERIOD:
2357 if (ic->ic_opmode != IEEE80211_M_HOSTAP &&
2358 ic->ic_opmode != IEEE80211_M_IBSS)
2360 if (IEEE80211_DTIM_MIN <= ireq->i_val &&
2361 ireq->i_val <= IEEE80211_DTIM_MAX) {
2362 ic->ic_dtim_period = ireq->i_val;
2363 error = ENETRESET; /* requires restart */
2367 case IEEE80211_IOC_BEACON_INTERVAL:
2368 if (ic->ic_opmode != IEEE80211_M_HOSTAP &&
2369 ic->ic_opmode != IEEE80211_M_IBSS)
2371 if (IEEE80211_BINTVAL_MIN <= ireq->i_val &&
2372 ireq->i_val <= IEEE80211_BINTVAL_MAX) {
2373 ic->ic_bintval = ireq->i_val;
2374 error = ENETRESET; /* requires restart */
2378 case IEEE80211_IOC_PUREG:
2380 ic->ic_flags |= IEEE80211_F_PUREG;
2382 ic->ic_flags &= ~IEEE80211_F_PUREG;
2383 /* NB: reset only if we're operating on an 11g channel */
2384 if (ic->ic_curmode == IEEE80211_MODE_11G)
2387 case IEEE80211_IOC_MCAST_RATE:
2388 ic->ic_mcast_rate = ireq->i_val & IEEE80211_RATE_VAL;
2390 case IEEE80211_IOC_FRAGTHRESHOLD:
2391 if ((ic->ic_caps & IEEE80211_C_TXFRAG) == 0 &&
2392 ireq->i_val != IEEE80211_FRAG_MAX)
2394 if (!(IEEE80211_FRAG_MIN <= ireq->i_val &&
2395 ireq->i_val <= IEEE80211_FRAG_MAX))
2397 ic->ic_fragthreshold = ireq->i_val;
2398 error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0;
2400 case IEEE80211_IOC_BURST:
2402 if ((ic->ic_caps & IEEE80211_C_BURST) == 0)
2404 ic->ic_flags |= IEEE80211_F_BURST;
2406 ic->ic_flags &= ~IEEE80211_F_BURST;
2407 error = ENETRESET; /* XXX maybe not for station? */
2413 if (error == ENETRESET && !IS_UP_AUTO(ic))
2419 ieee80211_ioctl(struct ieee80211com *ic, u_long cmd, caddr_t data)
2421 struct ifnet *ifp = ic->ic_ifp;
2424 struct ifaddr *ifa; /* XXX */
2429 error = ifmedia_ioctl(ifp, (struct ifreq *) data,
2430 &ic->ic_media, cmd);
2433 error = ieee80211_ioctl_get80211(ic, cmd,
2434 (struct ieee80211req *) data);
2437 error = suser(curthread);
2439 error = ieee80211_ioctl_set80211(ic, cmd,
2440 (struct ieee80211req *) data);
2442 case SIOCGIFGENERIC:
2443 error = ieee80211_cfgget(ic, cmd, data);
2445 case SIOCSIFGENERIC:
2446 error = suser(curthread);
2449 error = ieee80211_cfgset(ic, cmd, data);
2451 case SIOCG80211STATS:
2452 ifr = (struct ifreq *)data;
2453 copyout(&ic->ic_stats, ifr->ifr_data, sizeof (ic->ic_stats));
2456 ifr = (struct ifreq *)data;
2457 if (!(IEEE80211_MTU_MIN <= ifr->ifr_mtu &&
2458 ifr->ifr_mtu <= IEEE80211_MTU_MAX))
2461 ifp->if_mtu = ifr->ifr_mtu;
2465 * XXX Handle this directly so we can supress if_init calls.
2466 * XXX This should be done in ether_ioctl but for the moment
2467 * XXX there are too many other parts of the system that
2468 * XXX set IFF_UP and so supress if_init being called when
2471 ifa = (struct ifaddr *) data;
2472 switch (ifa->ifa_addr->sa_family) {
2475 if ((ifp->if_flags & IFF_UP) == 0) {
2476 ifp->if_flags |= IFF_UP;
2477 ifp->if_init(ifp->if_softc);
2479 arp_ifinit(ifp, ifa);
2484 * XXX - This code is probably wrong,
2485 * but has been copied many times.
2488 struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
2490 if (ipx_nullhost(*ina))
2491 ina->x_host = *(union ipx_host *)
2494 bcopy((caddr_t) ina->x_host.c_host,
2495 (caddr_t) IF_LLADDR(ifp),
2501 if ((ifp->if_flags & IFF_UP) == 0) {
2502 ifp->if_flags |= IFF_UP;
2503 ifp->if_init(ifp->if_softc);
2509 error = ether_ioctl(ifp, cmd, data);