11a1e1d21SSam Leffler /*- 27535e66aSSam Leffler * Copyright (c) 2001 Atsushi Onoe 31f1d7810SSam Leffler * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting 41a1e1d21SSam Leffler * All rights reserved. 51a1e1d21SSam Leffler * 61a1e1d21SSam Leffler * Redistribution and use in source and binary forms, with or without 71a1e1d21SSam Leffler * modification, are permitted provided that the following conditions 81a1e1d21SSam Leffler * are met: 91a1e1d21SSam Leffler * 1. Redistributions of source code must retain the above copyright 107535e66aSSam Leffler * notice, this list of conditions and the following disclaimer. 117535e66aSSam Leffler * 2. Redistributions in binary form must reproduce the above copyright 127535e66aSSam Leffler * notice, this list of conditions and the following disclaimer in the 137535e66aSSam Leffler * documentation and/or other materials provided with the distribution. 147535e66aSSam Leffler * 3. The name of the author may not be used to endorse or promote products 157535e66aSSam Leffler * derived from this software without specific prior written permission. 161a1e1d21SSam Leffler * 171a1e1d21SSam Leffler * Alternatively, this software may be distributed under the terms of the 181a1e1d21SSam Leffler * GNU General Public License ("GPL") version 2 as published by the Free 191a1e1d21SSam Leffler * Software Foundation. 201a1e1d21SSam Leffler * 217535e66aSSam Leffler * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 227535e66aSSam Leffler * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 237535e66aSSam Leffler * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 247535e66aSSam Leffler * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 257535e66aSSam Leffler * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 267535e66aSSam Leffler * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 277535e66aSSam Leffler * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 287535e66aSSam Leffler * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 297535e66aSSam Leffler * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 307535e66aSSam Leffler * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 311a1e1d21SSam Leffler */ 321a1e1d21SSam Leffler 331a1e1d21SSam Leffler #include <sys/cdefs.h> 341a1e1d21SSam Leffler __FBSDID("$FreeBSD$"); 351a1e1d21SSam Leffler 361a1e1d21SSam Leffler /* 371a1e1d21SSam Leffler * IEEE 802.11 ioctl support (FreeBSD-specific) 381a1e1d21SSam Leffler */ 391a1e1d21SSam Leffler 40b2e95691SSam Leffler #include "opt_inet.h" 41b2e95691SSam Leffler #include "opt_ipx.h" 42b2e95691SSam Leffler 431a1e1d21SSam Leffler #include <sys/endian.h> 441a1e1d21SSam Leffler #include <sys/param.h> 451a1e1d21SSam Leffler #include <sys/kernel.h> 461a1e1d21SSam Leffler #include <sys/socket.h> 471a1e1d21SSam Leffler #include <sys/sockio.h> 481a1e1d21SSam Leffler #include <sys/systm.h> 491a1e1d21SSam Leffler 501a1e1d21SSam Leffler #include <net/if.h> 511a1e1d21SSam Leffler #include <net/if_arp.h> 521a1e1d21SSam Leffler #include <net/if_media.h> 531a1e1d21SSam Leffler #include <net/ethernet.h> 541a1e1d21SSam Leffler 55b2e95691SSam Leffler #ifdef INET 56b2e95691SSam Leffler #include <netinet/in.h> 57b2e95691SSam Leffler #include <netinet/if_ether.h> 58b2e95691SSam Leffler #endif 59b2e95691SSam Leffler 60b2e95691SSam Leffler #ifdef IPX 61b2e95691SSam Leffler #include <netipx/ipx.h> 62b2e95691SSam Leffler #include <netipx/ipx_if.h> 63b2e95691SSam Leffler #endif 64b2e95691SSam Leffler 651a1e1d21SSam Leffler #include <net80211/ieee80211_var.h> 661a1e1d21SSam Leffler #include <net80211/ieee80211_ioctl.h> 671a1e1d21SSam Leffler 681a1e1d21SSam Leffler #include <dev/wi/if_wavelan_ieee.h> 691a1e1d21SSam Leffler 708a1b9b6aSSam Leffler #define IS_UP(_ic) \ 7113f4c340SRobert Watson (((_ic)->ic_ifp->if_flags & IFF_UP) && \ 7213f4c340SRobert Watson ((_ic)->ic_ifp->if_drv_flags & IFF_DRV_RUNNING)) 738a1b9b6aSSam Leffler #define IS_UP_AUTO(_ic) \ 748a1b9b6aSSam Leffler (IS_UP(_ic) && (_ic)->ic_roaming == IEEE80211_ROAMING_AUTO) 758a1b9b6aSSam Leffler 761a1e1d21SSam Leffler /* 771a1e1d21SSam Leffler * XXX 781a1e1d21SSam Leffler * Wireless LAN specific configuration interface, which is compatible 791a1e1d21SSam Leffler * with wicontrol(8). 801a1e1d21SSam Leffler */ 811a1e1d21SSam Leffler 828a1b9b6aSSam Leffler struct wi_read_ap_args { 838a1b9b6aSSam Leffler int i; /* result count */ 848a1b9b6aSSam Leffler struct wi_apinfo *ap; /* current entry in result buffer */ 858a1b9b6aSSam Leffler caddr_t max; /* result buffer bound */ 868a1b9b6aSSam Leffler }; 878a1b9b6aSSam Leffler 888a1b9b6aSSam Leffler static void 898a1b9b6aSSam Leffler wi_read_ap_result(void *arg, struct ieee80211_node *ni) 901a1e1d21SSam Leffler { 918a1b9b6aSSam Leffler struct ieee80211com *ic = ni->ni_ic; 928a1b9b6aSSam Leffler struct wi_read_ap_args *sa = arg; 938a1b9b6aSSam Leffler struct wi_apinfo *ap = sa->ap; 948a1b9b6aSSam Leffler struct ieee80211_rateset *rs; 958a1b9b6aSSam Leffler int j; 968a1b9b6aSSam Leffler 978a1b9b6aSSam Leffler if ((caddr_t)(ap + 1) > sa->max) 988a1b9b6aSSam Leffler return; 998a1b9b6aSSam Leffler memset(ap, 0, sizeof(struct wi_apinfo)); 1008a1b9b6aSSam Leffler if (ic->ic_opmode == IEEE80211_M_HOSTAP) { 1018a1b9b6aSSam Leffler IEEE80211_ADDR_COPY(ap->bssid, ni->ni_macaddr); 1028a1b9b6aSSam Leffler ap->namelen = ic->ic_des_esslen; 1038a1b9b6aSSam Leffler if (ic->ic_des_esslen) 1048a1b9b6aSSam Leffler memcpy(ap->name, ic->ic_des_essid, 1058a1b9b6aSSam Leffler ic->ic_des_esslen); 1068a1b9b6aSSam Leffler } else { 1078a1b9b6aSSam Leffler IEEE80211_ADDR_COPY(ap->bssid, ni->ni_bssid); 1088a1b9b6aSSam Leffler ap->namelen = ni->ni_esslen; 1098a1b9b6aSSam Leffler if (ni->ni_esslen) 1108a1b9b6aSSam Leffler memcpy(ap->name, ni->ni_essid, 1118a1b9b6aSSam Leffler ni->ni_esslen); 1128a1b9b6aSSam Leffler } 1138a1b9b6aSSam Leffler ap->channel = ieee80211_chan2ieee(ic, ni->ni_chan); 1148a1b9b6aSSam Leffler ap->signal = ic->ic_node_getrssi(ni); 1158a1b9b6aSSam Leffler ap->capinfo = ni->ni_capinfo; 1168a1b9b6aSSam Leffler ap->interval = ni->ni_intval; 1178a1b9b6aSSam Leffler rs = &ni->ni_rates; 1188a1b9b6aSSam Leffler for (j = 0; j < rs->rs_nrates; j++) { 1198a1b9b6aSSam Leffler if (rs->rs_rates[j] & IEEE80211_RATE_BASIC) { 1208a1b9b6aSSam Leffler ap->rate = (rs->rs_rates[j] & 1218a1b9b6aSSam Leffler IEEE80211_RATE_VAL) * 5; /* XXX */ 1228a1b9b6aSSam Leffler } 1238a1b9b6aSSam Leffler } 1248a1b9b6aSSam Leffler sa->i++; 1258a1b9b6aSSam Leffler sa->ap++; 1268a1b9b6aSSam Leffler } 1278a1b9b6aSSam Leffler 1288a1b9b6aSSam Leffler struct wi_read_prism2_args { 1298a1b9b6aSSam Leffler int i; /* result count */ 1308a1b9b6aSSam Leffler struct wi_scan_res *res;/* current entry in result buffer */ 1318a1b9b6aSSam Leffler caddr_t max; /* result buffer bound */ 1328a1b9b6aSSam Leffler }; 1338a1b9b6aSSam Leffler 1348a1b9b6aSSam Leffler static void 1358a1b9b6aSSam Leffler wi_read_prism2_result(void *arg, struct ieee80211_node *ni) 1368a1b9b6aSSam Leffler { 1378a1b9b6aSSam Leffler struct ieee80211com *ic = ni->ni_ic; 1388a1b9b6aSSam Leffler struct wi_read_prism2_args *sa = arg; 1398a1b9b6aSSam Leffler struct wi_scan_res *res = sa->res; 1408a1b9b6aSSam Leffler 1418a1b9b6aSSam Leffler if ((caddr_t)(res + 1) > sa->max) 1428a1b9b6aSSam Leffler return; 1438a1b9b6aSSam Leffler res->wi_chan = ieee80211_chan2ieee(ic, ni->ni_chan); 1448a1b9b6aSSam Leffler res->wi_noise = 0; 1458a1b9b6aSSam Leffler res->wi_signal = ic->ic_node_getrssi(ni); 1468a1b9b6aSSam Leffler IEEE80211_ADDR_COPY(res->wi_bssid, ni->ni_bssid); 1478a1b9b6aSSam Leffler res->wi_interval = ni->ni_intval; 1488a1b9b6aSSam Leffler res->wi_capinfo = ni->ni_capinfo; 1498a1b9b6aSSam Leffler res->wi_ssid_len = ni->ni_esslen; 1508a1b9b6aSSam Leffler memcpy(res->wi_ssid, ni->ni_essid, IEEE80211_NWID_LEN); 1518a1b9b6aSSam Leffler /* NB: assumes wi_srates holds <= ni->ni_rates */ 1528a1b9b6aSSam Leffler memcpy(res->wi_srates, ni->ni_rates.rs_rates, 1538a1b9b6aSSam Leffler sizeof(res->wi_srates)); 1548a1b9b6aSSam Leffler if (ni->ni_rates.rs_nrates < 10) 1558a1b9b6aSSam Leffler res->wi_srates[ni->ni_rates.rs_nrates] = 0; 1568a1b9b6aSSam Leffler res->wi_rate = ni->ni_rates.rs_rates[ni->ni_txrate]; 1578a1b9b6aSSam Leffler res->wi_rsvd = 0; 1588a1b9b6aSSam Leffler 1598a1b9b6aSSam Leffler sa->i++; 1608a1b9b6aSSam Leffler sa->res++; 1618a1b9b6aSSam Leffler } 1628a1b9b6aSSam Leffler 1638a1b9b6aSSam Leffler struct wi_read_sigcache_args { 1648a1b9b6aSSam Leffler int i; /* result count */ 1658a1b9b6aSSam Leffler struct wi_sigcache *wsc;/* current entry in result buffer */ 1668a1b9b6aSSam Leffler caddr_t max; /* result buffer bound */ 1678a1b9b6aSSam Leffler }; 1688a1b9b6aSSam Leffler 1698a1b9b6aSSam Leffler static void 1708a1b9b6aSSam Leffler wi_read_sigcache(void *arg, struct ieee80211_node *ni) 1718a1b9b6aSSam Leffler { 1728a1b9b6aSSam Leffler struct ieee80211com *ic = ni->ni_ic; 1738a1b9b6aSSam Leffler struct wi_read_sigcache_args *sa = arg; 1748a1b9b6aSSam Leffler struct wi_sigcache *wsc = sa->wsc; 1758a1b9b6aSSam Leffler 1768a1b9b6aSSam Leffler if ((caddr_t)(wsc + 1) > sa->max) 1778a1b9b6aSSam Leffler return; 1788a1b9b6aSSam Leffler memset(wsc, 0, sizeof(struct wi_sigcache)); 1798a1b9b6aSSam Leffler IEEE80211_ADDR_COPY(wsc->macsrc, ni->ni_macaddr); 1808a1b9b6aSSam Leffler wsc->signal = ic->ic_node_getrssi(ni); 1818a1b9b6aSSam Leffler 1828a1b9b6aSSam Leffler sa->wsc++; 1838a1b9b6aSSam Leffler sa->i++; 1848a1b9b6aSSam Leffler } 1858a1b9b6aSSam Leffler 1868a1b9b6aSSam Leffler int 1878a1b9b6aSSam Leffler ieee80211_cfgget(struct ieee80211com *ic, u_long cmd, caddr_t data) 1888a1b9b6aSSam Leffler { 1898a1b9b6aSSam Leffler struct ifnet *ifp = ic->ic_ifp; 1901a1e1d21SSam Leffler int i, j, error; 1911a1e1d21SSam Leffler struct ifreq *ifr = (struct ifreq *)data; 1921a1e1d21SSam Leffler struct wi_req wreq; 1931a1e1d21SSam Leffler struct wi_ltv_keys *keys; 1941a1e1d21SSam Leffler 1951a1e1d21SSam Leffler error = copyin(ifr->ifr_data, &wreq, sizeof(wreq)); 1961a1e1d21SSam Leffler if (error) 1971a1e1d21SSam Leffler return error; 1981a1e1d21SSam Leffler wreq.wi_len = 0; 1991a1e1d21SSam Leffler switch (wreq.wi_type) { 2001a1e1d21SSam Leffler case WI_RID_SERIALNO: 2011a1e1d21SSam Leffler /* nothing appropriate */ 2021a1e1d21SSam Leffler break; 2031a1e1d21SSam Leffler case WI_RID_NODENAME: 2041a1e1d21SSam Leffler strcpy((char *)&wreq.wi_val[1], hostname); 2051a1e1d21SSam Leffler wreq.wi_val[0] = htole16(strlen(hostname)); 2061a1e1d21SSam Leffler wreq.wi_len = (1 + strlen(hostname) + 1) / 2; 2071a1e1d21SSam Leffler break; 2081a1e1d21SSam Leffler case WI_RID_CURRENT_SSID: 2091a1e1d21SSam Leffler if (ic->ic_state != IEEE80211_S_RUN) { 2101a1e1d21SSam Leffler wreq.wi_val[0] = 0; 2111a1e1d21SSam Leffler wreq.wi_len = 1; 2121a1e1d21SSam Leffler break; 2131a1e1d21SSam Leffler } 2141a1e1d21SSam Leffler wreq.wi_val[0] = htole16(ic->ic_bss->ni_esslen); 2151a1e1d21SSam Leffler memcpy(&wreq.wi_val[1], ic->ic_bss->ni_essid, 2161a1e1d21SSam Leffler ic->ic_bss->ni_esslen); 2171a1e1d21SSam Leffler wreq.wi_len = (1 + ic->ic_bss->ni_esslen + 1) / 2; 2181a1e1d21SSam Leffler break; 2191a1e1d21SSam Leffler case WI_RID_OWN_SSID: 2201a1e1d21SSam Leffler case WI_RID_DESIRED_SSID: 2211a1e1d21SSam Leffler wreq.wi_val[0] = htole16(ic->ic_des_esslen); 2221a1e1d21SSam Leffler memcpy(&wreq.wi_val[1], ic->ic_des_essid, ic->ic_des_esslen); 2231a1e1d21SSam Leffler wreq.wi_len = (1 + ic->ic_des_esslen + 1) / 2; 2241a1e1d21SSam Leffler break; 2251a1e1d21SSam Leffler case WI_RID_CURRENT_BSSID: 2261a1e1d21SSam Leffler if (ic->ic_state == IEEE80211_S_RUN) 2271a1e1d21SSam Leffler IEEE80211_ADDR_COPY(wreq.wi_val, ic->ic_bss->ni_bssid); 2281a1e1d21SSam Leffler else 2291a1e1d21SSam Leffler memset(wreq.wi_val, 0, IEEE80211_ADDR_LEN); 2301a1e1d21SSam Leffler wreq.wi_len = IEEE80211_ADDR_LEN / 2; 2311a1e1d21SSam Leffler break; 2321a1e1d21SSam Leffler case WI_RID_CHANNEL_LIST: 2331a1e1d21SSam Leffler memset(wreq.wi_val, 0, sizeof(wreq.wi_val)); 2341a1e1d21SSam Leffler /* 2351a1e1d21SSam Leffler * Since channel 0 is not available for DS, channel 1 2361a1e1d21SSam Leffler * is assigned to LSB on WaveLAN. 2371a1e1d21SSam Leffler */ 2381a1e1d21SSam Leffler if (ic->ic_phytype == IEEE80211_T_DS) 2391a1e1d21SSam Leffler i = 1; 2401a1e1d21SSam Leffler else 2411a1e1d21SSam Leffler i = 0; 2421a1e1d21SSam Leffler for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++) 2431a1e1d21SSam Leffler if (isset(ic->ic_chan_active, i)) { 2441a1e1d21SSam Leffler setbit((u_int8_t *)wreq.wi_val, j); 2451a1e1d21SSam Leffler wreq.wi_len = j / 16 + 1; 2461a1e1d21SSam Leffler } 2471a1e1d21SSam Leffler break; 2481a1e1d21SSam Leffler case WI_RID_OWN_CHNL: 2491a1e1d21SSam Leffler wreq.wi_val[0] = htole16( 2501a1e1d21SSam Leffler ieee80211_chan2ieee(ic, ic->ic_ibss_chan)); 2511a1e1d21SSam Leffler wreq.wi_len = 1; 2521a1e1d21SSam Leffler break; 2531a1e1d21SSam Leffler case WI_RID_CURRENT_CHAN: 2541a1e1d21SSam Leffler wreq.wi_val[0] = htole16( 255b5c99415SSam Leffler ieee80211_chan2ieee(ic, ic->ic_curchan)); 2561a1e1d21SSam Leffler wreq.wi_len = 1; 2571a1e1d21SSam Leffler break; 2581a1e1d21SSam Leffler case WI_RID_COMMS_QUALITY: 2591a1e1d21SSam Leffler wreq.wi_val[0] = 0; /* quality */ 2608a1b9b6aSSam Leffler wreq.wi_val[1] = htole16(ic->ic_node_getrssi(ic->ic_bss)); 2611a1e1d21SSam Leffler wreq.wi_val[2] = 0; /* noise */ 2621a1e1d21SSam Leffler wreq.wi_len = 3; 2631a1e1d21SSam Leffler break; 2641a1e1d21SSam Leffler case WI_RID_PROMISC: 2651a1e1d21SSam Leffler wreq.wi_val[0] = htole16((ifp->if_flags & IFF_PROMISC) ? 1 : 0); 2661a1e1d21SSam Leffler wreq.wi_len = 1; 2671a1e1d21SSam Leffler break; 2681a1e1d21SSam Leffler case WI_RID_PORTTYPE: 2691a1e1d21SSam Leffler wreq.wi_val[0] = htole16(ic->ic_opmode); 2701a1e1d21SSam Leffler wreq.wi_len = 1; 2711a1e1d21SSam Leffler break; 2721a1e1d21SSam Leffler case WI_RID_MAC_NODE: 2731a1e1d21SSam Leffler IEEE80211_ADDR_COPY(wreq.wi_val, ic->ic_myaddr); 2741a1e1d21SSam Leffler wreq.wi_len = IEEE80211_ADDR_LEN / 2; 2751a1e1d21SSam Leffler break; 2761a1e1d21SSam Leffler case WI_RID_TX_RATE: 2772c39b32cSSam Leffler if (ic->ic_fixed_rate == IEEE80211_FIXED_RATE_NONE) 2781a1e1d21SSam Leffler wreq.wi_val[0] = 0; /* auto */ 2791a1e1d21SSam Leffler else 2801a1e1d21SSam Leffler wreq.wi_val[0] = htole16( 2811a1e1d21SSam Leffler (ic->ic_sup_rates[ic->ic_curmode].rs_rates[ic->ic_fixed_rate] & 2821a1e1d21SSam Leffler IEEE80211_RATE_VAL) / 2); 2831a1e1d21SSam Leffler wreq.wi_len = 1; 2841a1e1d21SSam Leffler break; 2851a1e1d21SSam Leffler case WI_RID_CUR_TX_RATE: 2861a1e1d21SSam Leffler wreq.wi_val[0] = htole16( 2871a1e1d21SSam Leffler (ic->ic_bss->ni_rates.rs_rates[ic->ic_bss->ni_txrate] & 2881a1e1d21SSam Leffler IEEE80211_RATE_VAL) / 2); 2891a1e1d21SSam Leffler wreq.wi_len = 1; 2901a1e1d21SSam Leffler break; 2911a1e1d21SSam Leffler case WI_RID_RTS_THRESH: 2921a1e1d21SSam Leffler wreq.wi_val[0] = htole16(ic->ic_rtsthreshold); 2931a1e1d21SSam Leffler wreq.wi_len = 1; 2941a1e1d21SSam Leffler break; 2951a1e1d21SSam Leffler case WI_RID_CREATE_IBSS: 2961a1e1d21SSam Leffler wreq.wi_val[0] = 2971a1e1d21SSam Leffler htole16((ic->ic_flags & IEEE80211_F_IBSSON) ? 1 : 0); 2981a1e1d21SSam Leffler wreq.wi_len = 1; 2991a1e1d21SSam Leffler break; 3001a1e1d21SSam Leffler case WI_RID_MICROWAVE_OVEN: 3011a1e1d21SSam Leffler wreq.wi_val[0] = 0; /* no ... not supported */ 3021a1e1d21SSam Leffler wreq.wi_len = 1; 3031a1e1d21SSam Leffler break; 3041a1e1d21SSam Leffler case WI_RID_ROAMING_MODE: 3058a1b9b6aSSam Leffler wreq.wi_val[0] = htole16(ic->ic_roaming); /* XXX map */ 3061a1e1d21SSam Leffler wreq.wi_len = 1; 3071a1e1d21SSam Leffler break; 3081a1e1d21SSam Leffler case WI_RID_SYSTEM_SCALE: 3091a1e1d21SSam Leffler wreq.wi_val[0] = htole16(1); /* low density ... not supp */ 3101a1e1d21SSam Leffler wreq.wi_len = 1; 3111a1e1d21SSam Leffler break; 3121a1e1d21SSam Leffler case WI_RID_PM_ENABLED: 3131a1e1d21SSam Leffler wreq.wi_val[0] = 3141a1e1d21SSam Leffler htole16((ic->ic_flags & IEEE80211_F_PMGTON) ? 1 : 0); 3151a1e1d21SSam Leffler wreq.wi_len = 1; 3161a1e1d21SSam Leffler break; 3171a1e1d21SSam Leffler case WI_RID_MAX_SLEEP: 3181a1e1d21SSam Leffler wreq.wi_val[0] = htole16(ic->ic_lintval); 3191a1e1d21SSam Leffler wreq.wi_len = 1; 3201a1e1d21SSam Leffler break; 3211a1e1d21SSam Leffler case WI_RID_CUR_BEACON_INT: 3221a1e1d21SSam Leffler wreq.wi_val[0] = htole16(ic->ic_bss->ni_intval); 3231a1e1d21SSam Leffler wreq.wi_len = 1; 3241a1e1d21SSam Leffler break; 3251a1e1d21SSam Leffler case WI_RID_WEP_AVAIL: 3268a1b9b6aSSam Leffler wreq.wi_val[0] = htole16(1); /* always available */ 3271a1e1d21SSam Leffler wreq.wi_len = 1; 3281a1e1d21SSam Leffler break; 3291a1e1d21SSam Leffler case WI_RID_CNFAUTHMODE: 3301a1e1d21SSam Leffler wreq.wi_val[0] = htole16(1); /* TODO: open system only */ 3311a1e1d21SSam Leffler wreq.wi_len = 1; 3321a1e1d21SSam Leffler break; 3331a1e1d21SSam Leffler case WI_RID_ENCRYPTION: 3341a1e1d21SSam Leffler wreq.wi_val[0] = 3358a1b9b6aSSam Leffler htole16((ic->ic_flags & IEEE80211_F_PRIVACY) ? 1 : 0); 3361a1e1d21SSam Leffler wreq.wi_len = 1; 3371a1e1d21SSam Leffler break; 3381a1e1d21SSam Leffler case WI_RID_TX_CRYPT_KEY: 3398a1b9b6aSSam Leffler wreq.wi_val[0] = htole16(ic->ic_def_txkey); 3401a1e1d21SSam Leffler wreq.wi_len = 1; 3411a1e1d21SSam Leffler break; 3421a1e1d21SSam Leffler case WI_RID_DEFLT_CRYPT_KEYS: 3431a1e1d21SSam Leffler keys = (struct wi_ltv_keys *)&wreq; 3441a1e1d21SSam Leffler /* do not show keys to non-root user */ 3451a1e1d21SSam Leffler error = suser(curthread); 3461a1e1d21SSam Leffler if (error) { 3471a1e1d21SSam Leffler memset(keys, 0, sizeof(*keys)); 3481a1e1d21SSam Leffler error = 0; 3491a1e1d21SSam Leffler break; 3501a1e1d21SSam Leffler } 3511a1e1d21SSam Leffler for (i = 0; i < IEEE80211_WEP_NKID; i++) { 3521a1e1d21SSam Leffler keys->wi_keys[i].wi_keylen = 3538a1b9b6aSSam Leffler htole16(ic->ic_nw_keys[i].wk_keylen); 3541a1e1d21SSam Leffler memcpy(keys->wi_keys[i].wi_keydat, 3558a1b9b6aSSam Leffler ic->ic_nw_keys[i].wk_key, 3568a1b9b6aSSam Leffler ic->ic_nw_keys[i].wk_keylen); 3571a1e1d21SSam Leffler } 3581a1e1d21SSam Leffler wreq.wi_len = sizeof(*keys) / 2; 3591a1e1d21SSam Leffler break; 3601a1e1d21SSam Leffler case WI_RID_MAX_DATALEN: 3618a1b9b6aSSam Leffler wreq.wi_val[0] = htole16(ic->ic_fragthreshold); 3621a1e1d21SSam Leffler wreq.wi_len = 1; 3631a1e1d21SSam Leffler break; 3641a1e1d21SSam Leffler case WI_RID_IFACE_STATS: 3651a1e1d21SSam Leffler /* XXX: should be implemented in lower drivers */ 3661a1e1d21SSam Leffler break; 3671a1e1d21SSam Leffler case WI_RID_READ_APS: 3681a1e1d21SSam Leffler /* 3691a1e1d21SSam Leffler * Don't return results until active scan completes. 3701a1e1d21SSam Leffler */ 3718a1b9b6aSSam Leffler if ((ic->ic_flags & (IEEE80211_F_SCAN|IEEE80211_F_ASCAN)) == 0) { 3728a1b9b6aSSam Leffler struct wi_read_ap_args args; 3738a1b9b6aSSam Leffler 3748a1b9b6aSSam Leffler args.i = 0; 3758a1b9b6aSSam Leffler args.ap = (void *)((char *)wreq.wi_val + sizeof(i)); 3768a1b9b6aSSam Leffler args.max = (void *)(&wreq + 1); 3778a1b9b6aSSam Leffler ieee80211_iterate_nodes(&ic->ic_scan, 3788a1b9b6aSSam Leffler wi_read_ap_result, &args); 3798a1b9b6aSSam Leffler memcpy(wreq.wi_val, &args.i, sizeof(args.i)); 3808a1b9b6aSSam Leffler wreq.wi_len = (sizeof(int) + 3818a1b9b6aSSam Leffler sizeof(struct wi_apinfo) * args.i) / 2; 3828a1b9b6aSSam Leffler } else 3831a1e1d21SSam Leffler error = EINPROGRESS; 3841a1e1d21SSam Leffler break; 3851a1e1d21SSam Leffler case WI_RID_PRISM2: 3868a1b9b6aSSam Leffler /* NB: we lie so WI_RID_SCAN_RES can include rates */ 3878a1b9b6aSSam Leffler wreq.wi_val[0] = 1; 3881a1e1d21SSam Leffler wreq.wi_len = sizeof(u_int16_t) / 2; 3891a1e1d21SSam Leffler break; 3901a1e1d21SSam Leffler case WI_RID_SCAN_RES: /* compatibility interface */ 3918a1b9b6aSSam Leffler if ((ic->ic_flags & (IEEE80211_F_SCAN|IEEE80211_F_ASCAN)) == 0) { 3928a1b9b6aSSam Leffler struct wi_read_prism2_args args; 3938a1b9b6aSSam Leffler struct wi_scan_p2_hdr *p2; 3948a1b9b6aSSam Leffler 3958a1b9b6aSSam Leffler /* NB: use Prism2 format so we can include rate info */ 3968a1b9b6aSSam Leffler p2 = (struct wi_scan_p2_hdr *)wreq.wi_val; 3978a1b9b6aSSam Leffler args.i = 0; 3988a1b9b6aSSam Leffler args.res = (void *)&p2[1]; 3998a1b9b6aSSam Leffler args.max = (void *)(&wreq + 1); 4008a1b9b6aSSam Leffler ieee80211_iterate_nodes(&ic->ic_scan, 4018a1b9b6aSSam Leffler wi_read_prism2_result, &args); 4028a1b9b6aSSam Leffler p2->wi_rsvd = 0; 4038a1b9b6aSSam Leffler p2->wi_reason = args.i; 4048a1b9b6aSSam Leffler wreq.wi_len = (sizeof(*p2) + 4058a1b9b6aSSam Leffler sizeof(struct wi_scan_res) * args.i) / 2; 4068a1b9b6aSSam Leffler } else 4071a1e1d21SSam Leffler error = EINPROGRESS; 4081a1e1d21SSam Leffler break; 4098a1b9b6aSSam Leffler case WI_RID_READ_CACHE: { 4108a1b9b6aSSam Leffler struct wi_read_sigcache_args args; 4118a1b9b6aSSam Leffler args.i = 0; 4128a1b9b6aSSam Leffler args.wsc = (struct wi_sigcache *) wreq.wi_val; 4138a1b9b6aSSam Leffler args.max = (void *)(&wreq + 1); 4148a1b9b6aSSam Leffler ieee80211_iterate_nodes(&ic->ic_scan, wi_read_sigcache, &args); 4158a1b9b6aSSam Leffler wreq.wi_len = sizeof(struct wi_sigcache) * args.i / 2; 4168a1b9b6aSSam Leffler break; 4171a1e1d21SSam Leffler } 4181a1e1d21SSam Leffler default: 4191a1e1d21SSam Leffler error = EINVAL; 4201a1e1d21SSam Leffler break; 4211a1e1d21SSam Leffler } 4221a1e1d21SSam Leffler if (error == 0) { 4231a1e1d21SSam Leffler wreq.wi_len++; 4241a1e1d21SSam Leffler error = copyout(&wreq, ifr->ifr_data, sizeof(wreq)); 4251a1e1d21SSam Leffler } 4261a1e1d21SSam Leffler return error; 4271a1e1d21SSam Leffler } 4281a1e1d21SSam Leffler 4291a1e1d21SSam Leffler static int 4301a1e1d21SSam Leffler findrate(struct ieee80211com *ic, enum ieee80211_phymode mode, int rate) 4311a1e1d21SSam Leffler { 4321a1e1d21SSam Leffler #define IEEERATE(_ic,_m,_i) \ 4331a1e1d21SSam Leffler ((_ic)->ic_sup_rates[_m].rs_rates[_i] & IEEE80211_RATE_VAL) 4341a1e1d21SSam Leffler int i, nrates = ic->ic_sup_rates[mode].rs_nrates; 4351a1e1d21SSam Leffler for (i = 0; i < nrates; i++) 4361a1e1d21SSam Leffler if (IEEERATE(ic, mode, i) == rate) 4371a1e1d21SSam Leffler return i; 4381a1e1d21SSam Leffler return -1; 4391a1e1d21SSam Leffler #undef IEEERATE 4401a1e1d21SSam Leffler } 4411a1e1d21SSam Leffler 44293685685SSam Leffler /* 44393685685SSam Leffler * Prepare to do a user-initiated scan for AP's. If no 44493685685SSam Leffler * current/default channel is setup or the current channel 44593685685SSam Leffler * is invalid then pick the first available channel from 44693685685SSam Leffler * the active list as the place to start the scan. 44793685685SSam Leffler */ 44893685685SSam Leffler static int 4498a1b9b6aSSam Leffler ieee80211_setupscan(struct ieee80211com *ic, const u_int8_t chanlist[]) 45093685685SSam Leffler { 45193685685SSam Leffler 4528a1b9b6aSSam Leffler /* 4538a1b9b6aSSam Leffler * XXX don't permit a scan to be started unless we 4548a1b9b6aSSam Leffler * know the device is ready. For the moment this means 4558a1b9b6aSSam Leffler * the device is marked up as this is the required to 4568a1b9b6aSSam Leffler * initialize the hardware. It would be better to permit 4578a1b9b6aSSam Leffler * scanning prior to being up but that'll require some 4588a1b9b6aSSam Leffler * changes to the infrastructure. 4598a1b9b6aSSam Leffler */ 4608a1b9b6aSSam Leffler if (!IS_UP(ic)) 4618a1b9b6aSSam Leffler return EINVAL; 4628a1b9b6aSSam Leffler memcpy(ic->ic_chan_active, chanlist, sizeof(ic->ic_chan_active)); 46393685685SSam Leffler /* 4648a1b9b6aSSam Leffler * We force the state to INIT before calling ieee80211_new_state 4658a1b9b6aSSam Leffler * to get ieee80211_begin_scan called. We really want to scan w/o 4668a1b9b6aSSam Leffler * altering the current state but that's not possible right now. 46793685685SSam Leffler */ 4688a1b9b6aSSam Leffler /* XXX handle proberequest case */ 4698a1b9b6aSSam Leffler ic->ic_state = IEEE80211_S_INIT; /* XXX bypass state machine */ 4708a1b9b6aSSam Leffler return 0; 47193685685SSam Leffler } 47293685685SSam Leffler 4731a1e1d21SSam Leffler int 4748a1b9b6aSSam Leffler ieee80211_cfgset(struct ieee80211com *ic, u_long cmd, caddr_t data) 4751a1e1d21SSam Leffler { 4768a1b9b6aSSam Leffler struct ifnet *ifp = ic->ic_ifp; 4771a1e1d21SSam Leffler int i, j, len, error, rate; 4781a1e1d21SSam Leffler struct ifreq *ifr = (struct ifreq *)data; 4791a1e1d21SSam Leffler struct wi_ltv_keys *keys; 4801a1e1d21SSam Leffler struct wi_req wreq; 4811a1e1d21SSam Leffler u_char chanlist[roundup(IEEE80211_CHAN_MAX, NBBY)]; 4821a1e1d21SSam Leffler 4831a1e1d21SSam Leffler error = copyin(ifr->ifr_data, &wreq, sizeof(wreq)); 4841a1e1d21SSam Leffler if (error) 4851a1e1d21SSam Leffler return error; 4861a1e1d21SSam Leffler len = wreq.wi_len ? (wreq.wi_len - 1) * 2 : 0; 4871a1e1d21SSam Leffler switch (wreq.wi_type) { 4881a1e1d21SSam Leffler case WI_RID_SERIALNO: 4891a1e1d21SSam Leffler case WI_RID_NODENAME: 4901a1e1d21SSam Leffler return EPERM; 4911a1e1d21SSam Leffler case WI_RID_CURRENT_SSID: 4921a1e1d21SSam Leffler return EPERM; 4931a1e1d21SSam Leffler case WI_RID_OWN_SSID: 4941a1e1d21SSam Leffler case WI_RID_DESIRED_SSID: 4951a1e1d21SSam Leffler if (le16toh(wreq.wi_val[0]) * 2 > len || 4961a1e1d21SSam Leffler le16toh(wreq.wi_val[0]) > IEEE80211_NWID_LEN) { 4971a1e1d21SSam Leffler error = ENOSPC; 4981a1e1d21SSam Leffler break; 4991a1e1d21SSam Leffler } 5001a1e1d21SSam Leffler memset(ic->ic_des_essid, 0, sizeof(ic->ic_des_essid)); 5011a1e1d21SSam Leffler ic->ic_des_esslen = le16toh(wreq.wi_val[0]) * 2; 502b9ee58c4SSam Leffler memcpy(ic->ic_des_essid, &wreq.wi_val[1], ic->ic_des_esslen); 5031a1e1d21SSam Leffler error = ENETRESET; 5041a1e1d21SSam Leffler break; 5051a1e1d21SSam Leffler case WI_RID_CURRENT_BSSID: 5061a1e1d21SSam Leffler return EPERM; 5071a1e1d21SSam Leffler case WI_RID_OWN_CHNL: 5081a1e1d21SSam Leffler if (len != 2) 5091a1e1d21SSam Leffler return EINVAL; 5101a1e1d21SSam Leffler i = le16toh(wreq.wi_val[0]); 5111a1e1d21SSam Leffler if (i < 0 || 5121a1e1d21SSam Leffler i > IEEE80211_CHAN_MAX || 5131a1e1d21SSam Leffler isclr(ic->ic_chan_active, i)) 5141a1e1d21SSam Leffler return EINVAL; 5151a1e1d21SSam Leffler ic->ic_ibss_chan = &ic->ic_channels[i]; 5168a1b9b6aSSam Leffler if (ic->ic_opmode == IEEE80211_M_MONITOR) 5178a1b9b6aSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 5188a1b9b6aSSam Leffler else 5191a1e1d21SSam Leffler error = ENETRESET; 5201a1e1d21SSam Leffler break; 5211a1e1d21SSam Leffler case WI_RID_CURRENT_CHAN: 5221a1e1d21SSam Leffler return EPERM; 5231a1e1d21SSam Leffler case WI_RID_COMMS_QUALITY: 5241a1e1d21SSam Leffler return EPERM; 5251a1e1d21SSam Leffler case WI_RID_PROMISC: 5261a1e1d21SSam Leffler if (len != 2) 5271a1e1d21SSam Leffler return EINVAL; 5281a1e1d21SSam Leffler if (ifp->if_flags & IFF_PROMISC) { 5291a1e1d21SSam Leffler if (wreq.wi_val[0] == 0) { 5301a1e1d21SSam Leffler ifp->if_flags &= ~IFF_PROMISC; 5311a1e1d21SSam Leffler error = ENETRESET; 5321a1e1d21SSam Leffler } 5331a1e1d21SSam Leffler } else { 5341a1e1d21SSam Leffler if (wreq.wi_val[0] != 0) { 5351a1e1d21SSam Leffler ifp->if_flags |= IFF_PROMISC; 5361a1e1d21SSam Leffler error = ENETRESET; 5371a1e1d21SSam Leffler } 5381a1e1d21SSam Leffler } 5391a1e1d21SSam Leffler break; 5401a1e1d21SSam Leffler case WI_RID_PORTTYPE: 5411a1e1d21SSam Leffler if (len != 2) 5421a1e1d21SSam Leffler return EINVAL; 5431a1e1d21SSam Leffler switch (le16toh(wreq.wi_val[0])) { 5441a1e1d21SSam Leffler case IEEE80211_M_STA: 5451a1e1d21SSam Leffler break; 5461a1e1d21SSam Leffler case IEEE80211_M_IBSS: 5471a1e1d21SSam Leffler if (!(ic->ic_caps & IEEE80211_C_IBSS)) 5481a1e1d21SSam Leffler return EINVAL; 5491a1e1d21SSam Leffler break; 5501a1e1d21SSam Leffler case IEEE80211_M_AHDEMO: 5511a1e1d21SSam Leffler if (ic->ic_phytype != IEEE80211_T_DS || 5521a1e1d21SSam Leffler !(ic->ic_caps & IEEE80211_C_AHDEMO)) 5531a1e1d21SSam Leffler return EINVAL; 5541a1e1d21SSam Leffler break; 5551a1e1d21SSam Leffler case IEEE80211_M_HOSTAP: 5561a1e1d21SSam Leffler if (!(ic->ic_caps & IEEE80211_C_HOSTAP)) 5571a1e1d21SSam Leffler return EINVAL; 5581a1e1d21SSam Leffler break; 5591a1e1d21SSam Leffler default: 5601a1e1d21SSam Leffler return EINVAL; 5611a1e1d21SSam Leffler } 5621a1e1d21SSam Leffler if (le16toh(wreq.wi_val[0]) != ic->ic_opmode) { 5631a1e1d21SSam Leffler ic->ic_opmode = le16toh(wreq.wi_val[0]); 5648a1b9b6aSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 5651a1e1d21SSam Leffler } 5661a1e1d21SSam Leffler break; 5671a1e1d21SSam Leffler #if 0 5681a1e1d21SSam Leffler case WI_RID_MAC_NODE: 5691a1e1d21SSam Leffler if (len != IEEE80211_ADDR_LEN) 5701a1e1d21SSam Leffler return EINVAL; 5711a1e1d21SSam Leffler IEEE80211_ADDR_COPY(LLADDR(ifp->if_sadl), wreq.wi_val); 5721a1e1d21SSam Leffler /* if_init will copy lladdr into ic_myaddr */ 5731a1e1d21SSam Leffler error = ENETRESET; 5741a1e1d21SSam Leffler break; 5751a1e1d21SSam Leffler #endif 5761a1e1d21SSam Leffler case WI_RID_TX_RATE: 5771a1e1d21SSam Leffler if (len != 2) 5781a1e1d21SSam Leffler return EINVAL; 5791a1e1d21SSam Leffler if (wreq.wi_val[0] == 0) { 5801a1e1d21SSam Leffler /* auto */ 5812c39b32cSSam Leffler ic->ic_fixed_rate = IEEE80211_FIXED_RATE_NONE; 5821a1e1d21SSam Leffler break; 5831a1e1d21SSam Leffler } 5841a1e1d21SSam Leffler rate = 2 * le16toh(wreq.wi_val[0]); 5851a1e1d21SSam Leffler if (ic->ic_curmode == IEEE80211_MODE_AUTO) { 5861a1e1d21SSam Leffler /* 5871a1e1d21SSam Leffler * In autoselect mode search for the rate. We take 5881a1e1d21SSam Leffler * the first instance which may not be right, but we 5891a1e1d21SSam Leffler * are limited by the interface. Note that we also 5901a1e1d21SSam Leffler * lock the mode to insure the rate is meaningful 5911a1e1d21SSam Leffler * when it is used. 5921a1e1d21SSam Leffler */ 5931a1e1d21SSam Leffler for (j = IEEE80211_MODE_11A; 5941a1e1d21SSam Leffler j < IEEE80211_MODE_MAX; j++) { 5951a1e1d21SSam Leffler if ((ic->ic_modecaps & (1<<j)) == 0) 5961a1e1d21SSam Leffler continue; 5971a1e1d21SSam Leffler i = findrate(ic, j, rate); 5981a1e1d21SSam Leffler if (i != -1) { 5991a1e1d21SSam Leffler /* lock mode too */ 6001a1e1d21SSam Leffler ic->ic_curmode = j; 6011a1e1d21SSam Leffler goto setrate; 6021a1e1d21SSam Leffler } 6031a1e1d21SSam Leffler } 6041a1e1d21SSam Leffler } else { 6051a1e1d21SSam Leffler i = findrate(ic, ic->ic_curmode, rate); 6061a1e1d21SSam Leffler if (i != -1) 6071a1e1d21SSam Leffler goto setrate; 6081a1e1d21SSam Leffler } 6091a1e1d21SSam Leffler return EINVAL; 6101a1e1d21SSam Leffler setrate: 6111a1e1d21SSam Leffler ic->ic_fixed_rate = i; 6128a1b9b6aSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 6131a1e1d21SSam Leffler break; 6141a1e1d21SSam Leffler case WI_RID_CUR_TX_RATE: 6151a1e1d21SSam Leffler return EPERM; 6161a1e1d21SSam Leffler case WI_RID_RTS_THRESH: 6171a1e1d21SSam Leffler if (len != 2) 6181a1e1d21SSam Leffler return EINVAL; 6191a1e1d21SSam Leffler if (le16toh(wreq.wi_val[0]) != IEEE80211_MAX_LEN) 6201a1e1d21SSam Leffler return EINVAL; /* TODO: RTS */ 6211a1e1d21SSam Leffler break; 6221a1e1d21SSam Leffler case WI_RID_CREATE_IBSS: 6231a1e1d21SSam Leffler if (len != 2) 6241a1e1d21SSam Leffler return EINVAL; 6251a1e1d21SSam Leffler if (wreq.wi_val[0] != 0) { 6261a1e1d21SSam Leffler if ((ic->ic_caps & IEEE80211_C_IBSS) == 0) 6271a1e1d21SSam Leffler return EINVAL; 6281a1e1d21SSam Leffler if ((ic->ic_flags & IEEE80211_F_IBSSON) == 0) { 6291a1e1d21SSam Leffler ic->ic_flags |= IEEE80211_F_IBSSON; 6301a1e1d21SSam Leffler if (ic->ic_opmode == IEEE80211_M_IBSS && 6311a1e1d21SSam Leffler ic->ic_state == IEEE80211_S_SCAN) 6328a1b9b6aSSam Leffler error = IS_UP_AUTO(ic) ? ENETRESET : 0; 6331a1e1d21SSam Leffler } 6341a1e1d21SSam Leffler } else { 6351a1e1d21SSam Leffler if (ic->ic_flags & IEEE80211_F_IBSSON) { 6361a1e1d21SSam Leffler ic->ic_flags &= ~IEEE80211_F_IBSSON; 6371a1e1d21SSam Leffler if (ic->ic_flags & IEEE80211_F_SIBSS) { 6381a1e1d21SSam Leffler ic->ic_flags &= ~IEEE80211_F_SIBSS; 6398a1b9b6aSSam Leffler error = IS_UP_AUTO(ic) ? ENETRESET : 0; 6401a1e1d21SSam Leffler } 6411a1e1d21SSam Leffler } 6421a1e1d21SSam Leffler } 6431a1e1d21SSam Leffler break; 6441a1e1d21SSam Leffler case WI_RID_MICROWAVE_OVEN: 6451a1e1d21SSam Leffler if (len != 2) 6461a1e1d21SSam Leffler return EINVAL; 6471a1e1d21SSam Leffler if (wreq.wi_val[0] != 0) 6481a1e1d21SSam Leffler return EINVAL; /* not supported */ 6491a1e1d21SSam Leffler break; 6501a1e1d21SSam Leffler case WI_RID_ROAMING_MODE: 6511a1e1d21SSam Leffler if (len != 2) 6521a1e1d21SSam Leffler return EINVAL; 6538a1b9b6aSSam Leffler i = le16toh(wreq.wi_val[0]); 6548a1b9b6aSSam Leffler if (i > IEEE80211_ROAMING_MANUAL) 6551a1e1d21SSam Leffler return EINVAL; /* not supported */ 6568a1b9b6aSSam Leffler ic->ic_roaming = i; 6571a1e1d21SSam Leffler break; 6581a1e1d21SSam Leffler case WI_RID_SYSTEM_SCALE: 6591a1e1d21SSam Leffler if (len != 2) 6601a1e1d21SSam Leffler return EINVAL; 6611a1e1d21SSam Leffler if (le16toh(wreq.wi_val[0]) != 1) 6621a1e1d21SSam Leffler return EINVAL; /* not supported */ 6631a1e1d21SSam Leffler break; 6641a1e1d21SSam Leffler case WI_RID_PM_ENABLED: 6651a1e1d21SSam Leffler if (len != 2) 6661a1e1d21SSam Leffler return EINVAL; 6671a1e1d21SSam Leffler if (wreq.wi_val[0] != 0) { 6681a1e1d21SSam Leffler if ((ic->ic_caps & IEEE80211_C_PMGT) == 0) 6691a1e1d21SSam Leffler return EINVAL; 6701a1e1d21SSam Leffler if ((ic->ic_flags & IEEE80211_F_PMGTON) == 0) { 6711a1e1d21SSam Leffler ic->ic_flags |= IEEE80211_F_PMGTON; 6728a1b9b6aSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 6731a1e1d21SSam Leffler } 6741a1e1d21SSam Leffler } else { 6751a1e1d21SSam Leffler if (ic->ic_flags & IEEE80211_F_PMGTON) { 6761a1e1d21SSam Leffler ic->ic_flags &= ~IEEE80211_F_PMGTON; 6778a1b9b6aSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 6781a1e1d21SSam Leffler } 6791a1e1d21SSam Leffler } 6801a1e1d21SSam Leffler break; 6811a1e1d21SSam Leffler case WI_RID_MAX_SLEEP: 6821a1e1d21SSam Leffler if (len != 2) 6831a1e1d21SSam Leffler return EINVAL; 6841a1e1d21SSam Leffler ic->ic_lintval = le16toh(wreq.wi_val[0]); 6851a1e1d21SSam Leffler if (ic->ic_flags & IEEE80211_F_PMGTON) 6868a1b9b6aSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 6871a1e1d21SSam Leffler break; 6881a1e1d21SSam Leffler case WI_RID_CUR_BEACON_INT: 6891a1e1d21SSam Leffler return EPERM; 6901a1e1d21SSam Leffler case WI_RID_WEP_AVAIL: 6911a1e1d21SSam Leffler return EPERM; 6921a1e1d21SSam Leffler case WI_RID_CNFAUTHMODE: 6931a1e1d21SSam Leffler if (len != 2) 6941a1e1d21SSam Leffler return EINVAL; 6958a1b9b6aSSam Leffler i = le16toh(wreq.wi_val[0]); 6968a1b9b6aSSam Leffler if (i > IEEE80211_AUTH_WPA) 6978a1b9b6aSSam Leffler return EINVAL; 6988a1b9b6aSSam Leffler ic->ic_bss->ni_authmode = i; /* XXX ENETRESET? */ 6998a1b9b6aSSam Leffler error = ENETRESET; 7001a1e1d21SSam Leffler break; 7011a1e1d21SSam Leffler case WI_RID_ENCRYPTION: 7021a1e1d21SSam Leffler if (len != 2) 7031a1e1d21SSam Leffler return EINVAL; 7041a1e1d21SSam Leffler if (wreq.wi_val[0] != 0) { 7051a1e1d21SSam Leffler if ((ic->ic_caps & IEEE80211_C_WEP) == 0) 7061a1e1d21SSam Leffler return EINVAL; 7078a1b9b6aSSam Leffler if ((ic->ic_flags & IEEE80211_F_PRIVACY) == 0) { 7088a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_PRIVACY; 7091a1e1d21SSam Leffler error = ENETRESET; 7101a1e1d21SSam Leffler } 7111a1e1d21SSam Leffler } else { 7128a1b9b6aSSam Leffler if (ic->ic_flags & IEEE80211_F_PRIVACY) { 7138a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_PRIVACY; 7141a1e1d21SSam Leffler error = ENETRESET; 7151a1e1d21SSam Leffler } 7161a1e1d21SSam Leffler } 7171a1e1d21SSam Leffler break; 7181a1e1d21SSam Leffler case WI_RID_TX_CRYPT_KEY: 7191a1e1d21SSam Leffler if (len != 2) 7201a1e1d21SSam Leffler return EINVAL; 7211a1e1d21SSam Leffler i = le16toh(wreq.wi_val[0]); 7221a1e1d21SSam Leffler if (i >= IEEE80211_WEP_NKID) 7231a1e1d21SSam Leffler return EINVAL; 7248a1b9b6aSSam Leffler ic->ic_def_txkey = i; 7258a1b9b6aSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 7261a1e1d21SSam Leffler break; 7271a1e1d21SSam Leffler case WI_RID_DEFLT_CRYPT_KEYS: 7281a1e1d21SSam Leffler if (len != sizeof(struct wi_ltv_keys)) 7291a1e1d21SSam Leffler return EINVAL; 7301a1e1d21SSam Leffler keys = (struct wi_ltv_keys *)&wreq; 7311a1e1d21SSam Leffler for (i = 0; i < IEEE80211_WEP_NKID; i++) { 7321a1e1d21SSam Leffler len = le16toh(keys->wi_keys[i].wi_keylen); 7331a1e1d21SSam Leffler if (len != 0 && len < IEEE80211_WEP_KEYLEN) 7341a1e1d21SSam Leffler return EINVAL; 7358a1b9b6aSSam Leffler if (len > IEEE80211_KEYBUF_SIZE) 7361a1e1d21SSam Leffler return EINVAL; 7371a1e1d21SSam Leffler } 7381a1e1d21SSam Leffler for (i = 0; i < IEEE80211_WEP_NKID; i++) { 7398a1b9b6aSSam Leffler struct ieee80211_key *k = &ic->ic_nw_keys[i]; 7408a1b9b6aSSam Leffler 7411a1e1d21SSam Leffler len = le16toh(keys->wi_keys[i].wi_keylen); 7428a1b9b6aSSam Leffler k->wk_keylen = len; 7438a1b9b6aSSam Leffler k->wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV; 7448a1b9b6aSSam Leffler memset(k->wk_key, 0, sizeof(k->wk_key)); 7458a1b9b6aSSam Leffler memcpy(k->wk_key, keys->wi_keys[i].wi_keydat, len); 7468a1b9b6aSSam Leffler #if 0 7478a1b9b6aSSam Leffler k->wk_type = IEEE80211_CIPHER_WEP; 7488a1b9b6aSSam Leffler #endif 7491a1e1d21SSam Leffler } 7501a1e1d21SSam Leffler error = ENETRESET; 7511a1e1d21SSam Leffler break; 7521a1e1d21SSam Leffler case WI_RID_MAX_DATALEN: 7531a1e1d21SSam Leffler if (len != 2) 7541a1e1d21SSam Leffler return EINVAL; 7551a1e1d21SSam Leffler len = le16toh(wreq.wi_val[0]); 7561a1e1d21SSam Leffler if (len < 350 /* ? */ || len > IEEE80211_MAX_LEN) 7571a1e1d21SSam Leffler return EINVAL; 7581a1e1d21SSam Leffler ic->ic_fragthreshold = len; 7598a1b9b6aSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 7601a1e1d21SSam Leffler break; 7611a1e1d21SSam Leffler case WI_RID_IFACE_STATS: 7621a1e1d21SSam Leffler error = EPERM; 7631a1e1d21SSam Leffler break; 7641a1e1d21SSam Leffler case WI_RID_SCAN_REQ: /* XXX wicontrol */ 7651a1e1d21SSam Leffler if (ic->ic_opmode == IEEE80211_M_HOSTAP) 7661a1e1d21SSam Leffler break; 7678a1b9b6aSSam Leffler error = ieee80211_setupscan(ic, ic->ic_chan_avail); 76893685685SSam Leffler if (error == 0) 769a11c9a5cSSam Leffler error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); 7701a1e1d21SSam Leffler break; 7711a1e1d21SSam Leffler case WI_RID_SCAN_APS: 7721a1e1d21SSam Leffler if (ic->ic_opmode == IEEE80211_M_HOSTAP) 7731a1e1d21SSam Leffler break; 7741a1e1d21SSam Leffler len--; /* XXX: tx rate? */ 7751a1e1d21SSam Leffler /* FALLTHRU */ 7761a1e1d21SSam Leffler case WI_RID_CHANNEL_LIST: 7771a1e1d21SSam Leffler memset(chanlist, 0, sizeof(chanlist)); 7781a1e1d21SSam Leffler /* 7791a1e1d21SSam Leffler * Since channel 0 is not available for DS, channel 1 7801a1e1d21SSam Leffler * is assigned to LSB on WaveLAN. 7811a1e1d21SSam Leffler */ 7821a1e1d21SSam Leffler if (ic->ic_phytype == IEEE80211_T_DS) 7831a1e1d21SSam Leffler i = 1; 7841a1e1d21SSam Leffler else 7851a1e1d21SSam Leffler i = 0; 7861a1e1d21SSam Leffler for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++) { 7871a1e1d21SSam Leffler if ((j / 8) >= len) 7881a1e1d21SSam Leffler break; 7891a1e1d21SSam Leffler if (isclr((u_int8_t *)wreq.wi_val, j)) 7901a1e1d21SSam Leffler continue; 7911a1e1d21SSam Leffler if (isclr(ic->ic_chan_active, i)) { 7921a1e1d21SSam Leffler if (wreq.wi_type != WI_RID_CHANNEL_LIST) 7931a1e1d21SSam Leffler continue; 7941a1e1d21SSam Leffler if (isclr(ic->ic_chan_avail, i)) 7951a1e1d21SSam Leffler return EPERM; 7961a1e1d21SSam Leffler } 7971a1e1d21SSam Leffler setbit(chanlist, i); 7981a1e1d21SSam Leffler } 7998a1b9b6aSSam Leffler error = ieee80211_setupscan(ic, chanlist); 80093685685SSam Leffler if (wreq.wi_type == WI_RID_CHANNEL_LIST) { 80193685685SSam Leffler /* NB: ignore error from ieee80211_setupscan */ 8021a1e1d21SSam Leffler error = ENETRESET; 80393685685SSam Leffler } else if (error == 0) 804a11c9a5cSSam Leffler error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); 8051a1e1d21SSam Leffler break; 8061a1e1d21SSam Leffler default: 8071a1e1d21SSam Leffler error = EINVAL; 8081a1e1d21SSam Leffler break; 8091a1e1d21SSam Leffler } 8108a1b9b6aSSam Leffler if (error == ENETRESET && !IS_UP_AUTO(ic)) 8118a1b9b6aSSam Leffler error = 0; 8121a1e1d21SSam Leffler return error; 8131a1e1d21SSam Leffler } 8141a1e1d21SSam Leffler 8158a1b9b6aSSam Leffler static int 8168a1b9b6aSSam Leffler cap2cipher(int flag) 8178a1b9b6aSSam Leffler { 8188a1b9b6aSSam Leffler switch (flag) { 8198a1b9b6aSSam Leffler case IEEE80211_C_WEP: return IEEE80211_CIPHER_WEP; 8208a1b9b6aSSam Leffler case IEEE80211_C_AES: return IEEE80211_CIPHER_AES_OCB; 8218a1b9b6aSSam Leffler case IEEE80211_C_AES_CCM: return IEEE80211_CIPHER_AES_CCM; 8228a1b9b6aSSam Leffler case IEEE80211_C_CKIP: return IEEE80211_CIPHER_CKIP; 8238a1b9b6aSSam Leffler case IEEE80211_C_TKIP: return IEEE80211_CIPHER_TKIP; 8248a1b9b6aSSam Leffler } 8258a1b9b6aSSam Leffler return -1; 8268a1b9b6aSSam Leffler } 8278a1b9b6aSSam Leffler 8288a1b9b6aSSam Leffler static int 8298a1b9b6aSSam Leffler ieee80211_ioctl_getkey(struct ieee80211com *ic, struct ieee80211req *ireq) 8308a1b9b6aSSam Leffler { 8318a1b9b6aSSam Leffler struct ieee80211_node *ni; 8328a1b9b6aSSam Leffler struct ieee80211req_key ik; 8338a1b9b6aSSam Leffler struct ieee80211_key *wk; 8348a1b9b6aSSam Leffler const struct ieee80211_cipher *cip; 8358a1b9b6aSSam Leffler u_int kid; 8368a1b9b6aSSam Leffler int error; 8378a1b9b6aSSam Leffler 8388a1b9b6aSSam Leffler if (ireq->i_len != sizeof(ik)) 8398a1b9b6aSSam Leffler return EINVAL; 8408a1b9b6aSSam Leffler error = copyin(ireq->i_data, &ik, sizeof(ik)); 8418a1b9b6aSSam Leffler if (error) 8428a1b9b6aSSam Leffler return error; 8438a1b9b6aSSam Leffler kid = ik.ik_keyix; 8448a1b9b6aSSam Leffler if (kid == IEEE80211_KEYIX_NONE) { 845acc4f7f5SSam Leffler ni = ieee80211_find_node(&ic->ic_sta, ik.ik_macaddr); 8468a1b9b6aSSam Leffler if (ni == NULL) 8478a1b9b6aSSam Leffler return EINVAL; /* XXX */ 8488a1b9b6aSSam Leffler wk = &ni->ni_ucastkey; 8498a1b9b6aSSam Leffler } else { 8508a1b9b6aSSam Leffler if (kid >= IEEE80211_WEP_NKID) 8518a1b9b6aSSam Leffler return EINVAL; 8528a1b9b6aSSam Leffler wk = &ic->ic_nw_keys[kid]; 8538a1b9b6aSSam Leffler IEEE80211_ADDR_COPY(&ik.ik_macaddr, ic->ic_bss->ni_macaddr); 8548a1b9b6aSSam Leffler ni = NULL; 8558a1b9b6aSSam Leffler } 8568a1b9b6aSSam Leffler cip = wk->wk_cipher; 8578a1b9b6aSSam Leffler ik.ik_type = cip->ic_cipher; 8588a1b9b6aSSam Leffler ik.ik_keylen = wk->wk_keylen; 8598a1b9b6aSSam Leffler ik.ik_flags = wk->wk_flags & (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV); 8608a1b9b6aSSam Leffler if (wk->wk_keyix == ic->ic_def_txkey) 8618a1b9b6aSSam Leffler ik.ik_flags |= IEEE80211_KEY_DEFAULT; 8628a1b9b6aSSam Leffler if (suser(curthread) == 0) { 8638a1b9b6aSSam Leffler /* NB: only root can read key data */ 8648a1b9b6aSSam Leffler ik.ik_keyrsc = wk->wk_keyrsc; 8658a1b9b6aSSam Leffler ik.ik_keytsc = wk->wk_keytsc; 8668a1b9b6aSSam Leffler memcpy(ik.ik_keydata, wk->wk_key, wk->wk_keylen); 8678a1b9b6aSSam Leffler if (cip->ic_cipher == IEEE80211_CIPHER_TKIP) { 8688a1b9b6aSSam Leffler memcpy(ik.ik_keydata+wk->wk_keylen, 8698a1b9b6aSSam Leffler wk->wk_key + IEEE80211_KEYBUF_SIZE, 8708a1b9b6aSSam Leffler IEEE80211_MICBUF_SIZE); 8718a1b9b6aSSam Leffler ik.ik_keylen += IEEE80211_MICBUF_SIZE; 8728a1b9b6aSSam Leffler } 8738a1b9b6aSSam Leffler } else { 8748a1b9b6aSSam Leffler ik.ik_keyrsc = 0; 8758a1b9b6aSSam Leffler ik.ik_keytsc = 0; 8768a1b9b6aSSam Leffler memset(ik.ik_keydata, 0, sizeof(ik.ik_keydata)); 8778a1b9b6aSSam Leffler } 8788a1b9b6aSSam Leffler if (ni != NULL) 8798a1b9b6aSSam Leffler ieee80211_free_node(ni); 8808a1b9b6aSSam Leffler return copyout(&ik, ireq->i_data, sizeof(ik)); 8818a1b9b6aSSam Leffler } 8828a1b9b6aSSam Leffler 8838a1b9b6aSSam Leffler static int 8848a1b9b6aSSam Leffler ieee80211_ioctl_getchanlist(struct ieee80211com *ic, struct ieee80211req *ireq) 8858a1b9b6aSSam Leffler { 8868a1b9b6aSSam Leffler 8878a1b9b6aSSam Leffler if (sizeof(ic->ic_chan_active) > ireq->i_len) 8888a1b9b6aSSam Leffler ireq->i_len = sizeof(ic->ic_chan_active); 8898a1b9b6aSSam Leffler return copyout(&ic->ic_chan_active, ireq->i_data, ireq->i_len); 8908a1b9b6aSSam Leffler } 8918a1b9b6aSSam Leffler 8928a1b9b6aSSam Leffler static int 8938a1b9b6aSSam Leffler ieee80211_ioctl_getchaninfo(struct ieee80211com *ic, struct ieee80211req *ireq) 8948a1b9b6aSSam Leffler { 8958a1b9b6aSSam Leffler struct ieee80211req_chaninfo chans; /* XXX off stack? */ 8968a1b9b6aSSam Leffler int i, space; 8978a1b9b6aSSam Leffler 8988a1b9b6aSSam Leffler /* 8998a1b9b6aSSam Leffler * Since channel 0 is not available for DS, channel 1 9008a1b9b6aSSam Leffler * is assigned to LSB on WaveLAN. 9018a1b9b6aSSam Leffler */ 9028a1b9b6aSSam Leffler if (ic->ic_phytype == IEEE80211_T_DS) 9038a1b9b6aSSam Leffler i = 1; 9048a1b9b6aSSam Leffler else 9058a1b9b6aSSam Leffler i = 0; 9068a1b9b6aSSam Leffler memset(&chans, 0, sizeof(chans)); 9078a1b9b6aSSam Leffler for (; i <= IEEE80211_CHAN_MAX; i++) 9088a1b9b6aSSam Leffler if (isset(ic->ic_chan_avail, i)) { 9098a1b9b6aSSam Leffler struct ieee80211_channel *c = &ic->ic_channels[i]; 9108a1b9b6aSSam Leffler chans.ic_chans[chans.ic_nchans].ic_freq = c->ic_freq; 9118a1b9b6aSSam Leffler chans.ic_chans[chans.ic_nchans].ic_flags = c->ic_flags; 9128a1b9b6aSSam Leffler chans.ic_nchans++; 9138a1b9b6aSSam Leffler } 9148a1b9b6aSSam Leffler space = __offsetof(struct ieee80211req_chaninfo, 9158a1b9b6aSSam Leffler ic_chans[chans.ic_nchans]); 9168a1b9b6aSSam Leffler if (space > ireq->i_len) 9178a1b9b6aSSam Leffler space = ireq->i_len; 9188a1b9b6aSSam Leffler return copyout(&chans, ireq->i_data, space); 9198a1b9b6aSSam Leffler } 9208a1b9b6aSSam Leffler 9218a1b9b6aSSam Leffler static int 9228a1b9b6aSSam Leffler ieee80211_ioctl_getwpaie(struct ieee80211com *ic, struct ieee80211req *ireq) 9238a1b9b6aSSam Leffler { 9248a1b9b6aSSam Leffler struct ieee80211_node *ni; 9258a1b9b6aSSam Leffler struct ieee80211req_wpaie wpaie; 9268a1b9b6aSSam Leffler int error; 9278a1b9b6aSSam Leffler 9288a1b9b6aSSam Leffler if (ireq->i_len < IEEE80211_ADDR_LEN) 9298a1b9b6aSSam Leffler return EINVAL; 9308a1b9b6aSSam Leffler error = copyin(ireq->i_data, wpaie.wpa_macaddr, IEEE80211_ADDR_LEN); 9318a1b9b6aSSam Leffler if (error != 0) 9328a1b9b6aSSam Leffler return error; 933acc4f7f5SSam Leffler ni = ieee80211_find_node(&ic->ic_sta, wpaie.wpa_macaddr); 9348a1b9b6aSSam Leffler if (ni == NULL) 9358a1b9b6aSSam Leffler return EINVAL; /* XXX */ 9368a1b9b6aSSam Leffler memset(wpaie.wpa_ie, 0, sizeof(wpaie.wpa_ie)); 9378a1b9b6aSSam Leffler if (ni->ni_wpa_ie != NULL) { 9388a1b9b6aSSam Leffler int ielen = ni->ni_wpa_ie[1] + 2; 9398a1b9b6aSSam Leffler if (ielen > sizeof(wpaie.wpa_ie)) 9408a1b9b6aSSam Leffler ielen = sizeof(wpaie.wpa_ie); 9418a1b9b6aSSam Leffler memcpy(wpaie.wpa_ie, ni->ni_wpa_ie, ielen); 9428a1b9b6aSSam Leffler } 9438a1b9b6aSSam Leffler ieee80211_free_node(ni); 9448a1b9b6aSSam Leffler if (ireq->i_len > sizeof(wpaie)) 9458a1b9b6aSSam Leffler ireq->i_len = sizeof(wpaie); 9468a1b9b6aSSam Leffler return copyout(&wpaie, ireq->i_data, ireq->i_len); 9478a1b9b6aSSam Leffler } 9488a1b9b6aSSam Leffler 9498a1b9b6aSSam Leffler static int 9508a1b9b6aSSam Leffler ieee80211_ioctl_getstastats(struct ieee80211com *ic, struct ieee80211req *ireq) 9518a1b9b6aSSam Leffler { 9528a1b9b6aSSam Leffler struct ieee80211_node *ni; 9538a1b9b6aSSam Leffler u_int8_t macaddr[IEEE80211_ADDR_LEN]; 9548a1b9b6aSSam Leffler const int off = __offsetof(struct ieee80211req_sta_stats, is_stats); 9558a1b9b6aSSam Leffler int error; 9568a1b9b6aSSam Leffler 9578a1b9b6aSSam Leffler if (ireq->i_len < off) 9588a1b9b6aSSam Leffler return EINVAL; 9598a1b9b6aSSam Leffler error = copyin(ireq->i_data, macaddr, IEEE80211_ADDR_LEN); 9608a1b9b6aSSam Leffler if (error != 0) 9618a1b9b6aSSam Leffler return error; 962acc4f7f5SSam Leffler ni = ieee80211_find_node(&ic->ic_sta, macaddr); 9638a1b9b6aSSam Leffler if (ni == NULL) 9648a1b9b6aSSam Leffler return EINVAL; /* XXX */ 9658a1b9b6aSSam Leffler if (ireq->i_len > sizeof(struct ieee80211req_sta_stats)) 9668a1b9b6aSSam Leffler ireq->i_len = sizeof(struct ieee80211req_sta_stats); 9678a1b9b6aSSam Leffler /* NB: copy out only the statistics */ 9688a1b9b6aSSam Leffler error = copyout(&ni->ni_stats, (u_int8_t *) ireq->i_data + off, 9698a1b9b6aSSam Leffler ireq->i_len - off); 9708a1b9b6aSSam Leffler ieee80211_free_node(ni); 9718a1b9b6aSSam Leffler return error; 9728a1b9b6aSSam Leffler } 9738a1b9b6aSSam Leffler 9748a1b9b6aSSam Leffler static void 9758a1b9b6aSSam Leffler get_scan_result(struct ieee80211req_scan_result *sr, 9768a1b9b6aSSam Leffler const struct ieee80211_node *ni) 9778a1b9b6aSSam Leffler { 9788a1b9b6aSSam Leffler struct ieee80211com *ic = ni->ni_ic; 9798a1b9b6aSSam Leffler 9808a1b9b6aSSam Leffler memset(sr, 0, sizeof(*sr)); 9818a1b9b6aSSam Leffler sr->isr_ssid_len = ni->ni_esslen; 9828a1b9b6aSSam Leffler if (ni->ni_wpa_ie != NULL) 9838a1b9b6aSSam Leffler sr->isr_ie_len += 2+ni->ni_wpa_ie[1]; 9848a1b9b6aSSam Leffler if (ni->ni_wme_ie != NULL) 9858a1b9b6aSSam Leffler sr->isr_ie_len += 2+ni->ni_wme_ie[1]; 9868a1b9b6aSSam Leffler sr->isr_len = sizeof(*sr) + sr->isr_ssid_len + sr->isr_ie_len; 9878a1b9b6aSSam Leffler sr->isr_len = roundup(sr->isr_len, sizeof(u_int32_t)); 9888a1b9b6aSSam Leffler if (ni->ni_chan != IEEE80211_CHAN_ANYC) { 9898a1b9b6aSSam Leffler sr->isr_freq = ni->ni_chan->ic_freq; 9908a1b9b6aSSam Leffler sr->isr_flags = ni->ni_chan->ic_flags; 9918a1b9b6aSSam Leffler } 9928a1b9b6aSSam Leffler sr->isr_rssi = ic->ic_node_getrssi(ni); 9938a1b9b6aSSam Leffler sr->isr_intval = ni->ni_intval; 9948a1b9b6aSSam Leffler sr->isr_capinfo = ni->ni_capinfo; 9958a1b9b6aSSam Leffler sr->isr_erp = ni->ni_erp; 9968a1b9b6aSSam Leffler IEEE80211_ADDR_COPY(sr->isr_bssid, ni->ni_bssid); 9978a1b9b6aSSam Leffler sr->isr_nrates = ni->ni_rates.rs_nrates; 9988a1b9b6aSSam Leffler if (sr->isr_nrates > 15) 9998a1b9b6aSSam Leffler sr->isr_nrates = 15; 10008a1b9b6aSSam Leffler memcpy(sr->isr_rates, ni->ni_rates.rs_rates, sr->isr_nrates); 10018a1b9b6aSSam Leffler } 10028a1b9b6aSSam Leffler 10038a1b9b6aSSam Leffler static int 10048a1b9b6aSSam Leffler ieee80211_ioctl_getscanresults(struct ieee80211com *ic, struct ieee80211req *ireq) 10058a1b9b6aSSam Leffler { 10068a1b9b6aSSam Leffler union { 10078a1b9b6aSSam Leffler struct ieee80211req_scan_result res; 10088a1b9b6aSSam Leffler char data[512]; /* XXX shrink? */ 10098a1b9b6aSSam Leffler } u; 10108a1b9b6aSSam Leffler struct ieee80211req_scan_result *sr = &u.res; 10118a1b9b6aSSam Leffler struct ieee80211_node_table *nt; 10128a1b9b6aSSam Leffler struct ieee80211_node *ni; 10138a1b9b6aSSam Leffler int error, space; 10148a1b9b6aSSam Leffler u_int8_t *p, *cp; 10158a1b9b6aSSam Leffler 10168a1b9b6aSSam Leffler p = ireq->i_data; 10178a1b9b6aSSam Leffler space = ireq->i_len; 10188a1b9b6aSSam Leffler error = 0; 10198a1b9b6aSSam Leffler /* XXX locking */ 10208a1b9b6aSSam Leffler nt = &ic->ic_scan; 10218a1b9b6aSSam Leffler TAILQ_FOREACH(ni, &nt->nt_node, ni_list) { 10228a1b9b6aSSam Leffler /* NB: skip pre-scan node state */ 10238a1b9b6aSSam Leffler if (ni->ni_chan == IEEE80211_CHAN_ANYC) 10248a1b9b6aSSam Leffler continue; 10258a1b9b6aSSam Leffler get_scan_result(sr, ni); 10268a1b9b6aSSam Leffler if (sr->isr_len > sizeof(u)) 10278a1b9b6aSSam Leffler continue; /* XXX */ 10288a1b9b6aSSam Leffler if (space < sr->isr_len) 10298a1b9b6aSSam Leffler break; 10308a1b9b6aSSam Leffler cp = (u_int8_t *)(sr+1); 10318a1b9b6aSSam Leffler memcpy(cp, ni->ni_essid, ni->ni_esslen); 10328a1b9b6aSSam Leffler cp += ni->ni_esslen; 10338a1b9b6aSSam Leffler if (ni->ni_wpa_ie != NULL) { 10348a1b9b6aSSam Leffler memcpy(cp, ni->ni_wpa_ie, 2+ni->ni_wpa_ie[1]); 10358a1b9b6aSSam Leffler cp += 2+ni->ni_wpa_ie[1]; 10368a1b9b6aSSam Leffler } 10378a1b9b6aSSam Leffler if (ni->ni_wme_ie != NULL) { 10388a1b9b6aSSam Leffler memcpy(cp, ni->ni_wme_ie, 2+ni->ni_wme_ie[1]); 10398a1b9b6aSSam Leffler cp += 2+ni->ni_wme_ie[1]; 10408a1b9b6aSSam Leffler } 10418a1b9b6aSSam Leffler error = copyout(sr, p, sr->isr_len); 10428a1b9b6aSSam Leffler if (error) 10438a1b9b6aSSam Leffler break; 10448a1b9b6aSSam Leffler p += sr->isr_len; 10458a1b9b6aSSam Leffler space -= sr->isr_len; 10468a1b9b6aSSam Leffler } 10478a1b9b6aSSam Leffler ireq->i_len -= space; 10488a1b9b6aSSam Leffler return error; 10498a1b9b6aSSam Leffler } 10508a1b9b6aSSam Leffler 10512cab1d3dSSam Leffler struct stainforeq { 10522cab1d3dSSam Leffler struct ieee80211com *ic; 10532cab1d3dSSam Leffler struct ieee80211req_sta_info *si; 10542cab1d3dSSam Leffler size_t space; 10552cab1d3dSSam Leffler }; 10568a1b9b6aSSam Leffler 10572cab1d3dSSam Leffler static size_t 10582cab1d3dSSam Leffler sta_space(const struct ieee80211_node *ni, size_t *ielen) 10592cab1d3dSSam Leffler { 10602cab1d3dSSam Leffler *ielen = 0; 10618a1b9b6aSSam Leffler if (ni->ni_wpa_ie != NULL) 10622cab1d3dSSam Leffler *ielen += 2+ni->ni_wpa_ie[1]; 10638a1b9b6aSSam Leffler if (ni->ni_wme_ie != NULL) 10642cab1d3dSSam Leffler *ielen += 2+ni->ni_wme_ie[1]; 10652cab1d3dSSam Leffler return roundup(sizeof(struct ieee80211req_sta_info) + *ielen, 10662cab1d3dSSam Leffler sizeof(u_int32_t)); 10672cab1d3dSSam Leffler } 10682cab1d3dSSam Leffler 10692cab1d3dSSam Leffler static void 10702cab1d3dSSam Leffler get_sta_space(void *arg, struct ieee80211_node *ni) 10712cab1d3dSSam Leffler { 10722cab1d3dSSam Leffler struct stainforeq *req = arg; 10732cab1d3dSSam Leffler struct ieee80211com *ic = ni->ni_ic; 10742cab1d3dSSam Leffler size_t ielen; 10752cab1d3dSSam Leffler 10762cab1d3dSSam Leffler if (ic->ic_opmode == IEEE80211_M_HOSTAP && 10772cab1d3dSSam Leffler ni->ni_associd == 0) /* only associated stations */ 10782cab1d3dSSam Leffler return; 10792cab1d3dSSam Leffler req->space += sta_space(ni, &ielen); 10802cab1d3dSSam Leffler } 10812cab1d3dSSam Leffler 10822cab1d3dSSam Leffler static void 10832cab1d3dSSam Leffler get_sta_info(void *arg, struct ieee80211_node *ni) 10842cab1d3dSSam Leffler { 10852cab1d3dSSam Leffler struct stainforeq *req = arg; 10862cab1d3dSSam Leffler struct ieee80211com *ic = ni->ni_ic; 10872cab1d3dSSam Leffler struct ieee80211req_sta_info *si; 10882cab1d3dSSam Leffler size_t ielen, len; 10892cab1d3dSSam Leffler u_int8_t *cp; 10902cab1d3dSSam Leffler 10912cab1d3dSSam Leffler if (ic->ic_opmode == IEEE80211_M_HOSTAP && 10922cab1d3dSSam Leffler ni->ni_associd == 0) /* only associated stations */ 10932cab1d3dSSam Leffler return; 10942cab1d3dSSam Leffler if (ni->ni_chan == IEEE80211_CHAN_ANYC) /* XXX bogus entry */ 10952cab1d3dSSam Leffler return; 10962cab1d3dSSam Leffler len = sta_space(ni, &ielen); 10972cab1d3dSSam Leffler if (len > req->space) 10982cab1d3dSSam Leffler return; 10992cab1d3dSSam Leffler si = req->si; 11002cab1d3dSSam Leffler si->isi_len = len; 11012cab1d3dSSam Leffler si->isi_ie_len = ielen; 11028a1b9b6aSSam Leffler si->isi_freq = ni->ni_chan->ic_freq; 11038a1b9b6aSSam Leffler si->isi_flags = ni->ni_chan->ic_flags; 11048a1b9b6aSSam Leffler si->isi_state = ni->ni_flags; 11058a1b9b6aSSam Leffler si->isi_authmode = ni->ni_authmode; 11068a1b9b6aSSam Leffler si->isi_rssi = ic->ic_node_getrssi(ni); 11078a1b9b6aSSam Leffler si->isi_capinfo = ni->ni_capinfo; 11088a1b9b6aSSam Leffler si->isi_erp = ni->ni_erp; 11098a1b9b6aSSam Leffler IEEE80211_ADDR_COPY(si->isi_macaddr, ni->ni_macaddr); 11108a1b9b6aSSam Leffler si->isi_nrates = ni->ni_rates.rs_nrates; 11118a1b9b6aSSam Leffler if (si->isi_nrates > 15) 11128a1b9b6aSSam Leffler si->isi_nrates = 15; 11138a1b9b6aSSam Leffler memcpy(si->isi_rates, ni->ni_rates.rs_rates, si->isi_nrates); 11148a1b9b6aSSam Leffler si->isi_txrate = ni->ni_txrate; 11158a1b9b6aSSam Leffler si->isi_associd = ni->ni_associd; 11168a1b9b6aSSam Leffler si->isi_txpower = ni->ni_txpower; 11178a1b9b6aSSam Leffler si->isi_vlan = ni->ni_vlan; 11188a1b9b6aSSam Leffler if (ni->ni_flags & IEEE80211_NODE_QOS) { 11198a1b9b6aSSam Leffler memcpy(si->isi_txseqs, ni->ni_txseqs, sizeof(ni->ni_txseqs)); 11208a1b9b6aSSam Leffler memcpy(si->isi_rxseqs, ni->ni_rxseqs, sizeof(ni->ni_rxseqs)); 11218a1b9b6aSSam Leffler } else { 11228a1b9b6aSSam Leffler si->isi_txseqs[0] = ni->ni_txseqs[0]; 11238a1b9b6aSSam Leffler si->isi_rxseqs[0] = ni->ni_rxseqs[0]; 11248a1b9b6aSSam Leffler } 11252cab1d3dSSam Leffler /* NB: leave all cases in case we relax ni_associd == 0 check */ 11262cab1d3dSSam Leffler if (ieee80211_node_is_authorized(ni)) 11278a1b9b6aSSam Leffler si->isi_inact = ic->ic_inact_run; 11282cab1d3dSSam Leffler else if (ni->ni_associd != 0) 11298a1b9b6aSSam Leffler si->isi_inact = ic->ic_inact_auth; 11308a1b9b6aSSam Leffler else 11318a1b9b6aSSam Leffler si->isi_inact = ic->ic_inact_init; 11328a1b9b6aSSam Leffler si->isi_inact = (si->isi_inact - ni->ni_inact) * IEEE80211_INACT_WAIT; 11338a1b9b6aSSam Leffler 11348a1b9b6aSSam Leffler cp = (u_int8_t *)(si+1); 11358a1b9b6aSSam Leffler if (ni->ni_wpa_ie != NULL) { 11368a1b9b6aSSam Leffler memcpy(cp, ni->ni_wpa_ie, 2+ni->ni_wpa_ie[1]); 11378a1b9b6aSSam Leffler cp += 2+ni->ni_wpa_ie[1]; 11388a1b9b6aSSam Leffler } 11398a1b9b6aSSam Leffler if (ni->ni_wme_ie != NULL) { 11408a1b9b6aSSam Leffler memcpy(cp, ni->ni_wme_ie, 2+ni->ni_wme_ie[1]); 11418a1b9b6aSSam Leffler cp += 2+ni->ni_wme_ie[1]; 11428a1b9b6aSSam Leffler } 11432cab1d3dSSam Leffler 11442cab1d3dSSam Leffler req->si = (struct ieee80211req_sta_info *)(((u_int8_t *)si) + len); 11452cab1d3dSSam Leffler req->space -= len; 11468a1b9b6aSSam Leffler } 11472cab1d3dSSam Leffler 11482cab1d3dSSam Leffler static int 11492cab1d3dSSam Leffler ieee80211_ioctl_getstainfo(struct ieee80211com *ic, struct ieee80211req *ireq) 11502cab1d3dSSam Leffler { 11512cab1d3dSSam Leffler struct stainforeq req; 11522cab1d3dSSam Leffler int error; 11532cab1d3dSSam Leffler 11542cab1d3dSSam Leffler if (ireq->i_len < sizeof(struct stainforeq)) 11552cab1d3dSSam Leffler return EFAULT; 11562cab1d3dSSam Leffler 11572cab1d3dSSam Leffler error = 0; 11582cab1d3dSSam Leffler req.space = 0; 11592cab1d3dSSam Leffler ieee80211_iterate_nodes(&ic->ic_sta, get_sta_space, &req); 11602cab1d3dSSam Leffler if (req.space > ireq->i_len) 11612cab1d3dSSam Leffler req.space = ireq->i_len; 11622cab1d3dSSam Leffler if (req.space > 0) { 11632cab1d3dSSam Leffler size_t space; 11642cab1d3dSSam Leffler void *p; 11652cab1d3dSSam Leffler 11662cab1d3dSSam Leffler space = req.space; 11672cab1d3dSSam Leffler /* XXX M_WAITOK after driver lock released */ 11682cab1d3dSSam Leffler MALLOC(p, void *, space, M_TEMP, M_NOWAIT); 11692cab1d3dSSam Leffler if (p == NULL) 11702cab1d3dSSam Leffler return ENOMEM; 11712cab1d3dSSam Leffler req.si = p; 11722cab1d3dSSam Leffler ieee80211_iterate_nodes(&ic->ic_sta, get_sta_info, &req); 11732cab1d3dSSam Leffler ireq->i_len = space - req.space; 11742cab1d3dSSam Leffler error = copyout(p, ireq->i_data, ireq->i_len); 11752cab1d3dSSam Leffler FREE(p, M_TEMP); 11762cab1d3dSSam Leffler } else 11772cab1d3dSSam Leffler ireq->i_len = 0; 11782cab1d3dSSam Leffler 11798a1b9b6aSSam Leffler return error; 11808a1b9b6aSSam Leffler } 11818a1b9b6aSSam Leffler 11828a1b9b6aSSam Leffler static int 11838a1b9b6aSSam Leffler ieee80211_ioctl_getstatxpow(struct ieee80211com *ic, struct ieee80211req *ireq) 11848a1b9b6aSSam Leffler { 11858a1b9b6aSSam Leffler struct ieee80211_node *ni; 11868a1b9b6aSSam Leffler struct ieee80211req_sta_txpow txpow; 11878a1b9b6aSSam Leffler int error; 11888a1b9b6aSSam Leffler 11898a1b9b6aSSam Leffler if (ireq->i_len != sizeof(txpow)) 11908a1b9b6aSSam Leffler return EINVAL; 11918a1b9b6aSSam Leffler error = copyin(ireq->i_data, &txpow, sizeof(txpow)); 11928a1b9b6aSSam Leffler if (error != 0) 11938a1b9b6aSSam Leffler return error; 1194acc4f7f5SSam Leffler ni = ieee80211_find_node(&ic->ic_sta, txpow.it_macaddr); 11958a1b9b6aSSam Leffler if (ni == NULL) 11968a1b9b6aSSam Leffler return EINVAL; /* XXX */ 11978a1b9b6aSSam Leffler txpow.it_txpow = ni->ni_txpower; 11988a1b9b6aSSam Leffler error = copyout(&txpow, ireq->i_data, sizeof(txpow)); 11998a1b9b6aSSam Leffler ieee80211_free_node(ni); 12008a1b9b6aSSam Leffler return error; 12018a1b9b6aSSam Leffler } 12028a1b9b6aSSam Leffler 12038a1b9b6aSSam Leffler static int 12048a1b9b6aSSam Leffler ieee80211_ioctl_getwmeparam(struct ieee80211com *ic, struct ieee80211req *ireq) 12058a1b9b6aSSam Leffler { 12068a1b9b6aSSam Leffler struct ieee80211_wme_state *wme = &ic->ic_wme; 12078a1b9b6aSSam Leffler struct wmeParams *wmep; 12088a1b9b6aSSam Leffler int ac; 12098a1b9b6aSSam Leffler 12108a1b9b6aSSam Leffler if ((ic->ic_caps & IEEE80211_C_WME) == 0) 12118a1b9b6aSSam Leffler return EINVAL; 12128a1b9b6aSSam Leffler 12138a1b9b6aSSam Leffler ac = (ireq->i_len & IEEE80211_WMEPARAM_VAL); 12148a1b9b6aSSam Leffler if (ac >= WME_NUM_AC) 12158a1b9b6aSSam Leffler ac = WME_AC_BE; 12168a1b9b6aSSam Leffler if (ireq->i_len & IEEE80211_WMEPARAM_BSS) 12178a1b9b6aSSam Leffler wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac]; 12188a1b9b6aSSam Leffler else 12198a1b9b6aSSam Leffler wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac]; 12208a1b9b6aSSam Leffler switch (ireq->i_type) { 12218a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */ 12228a1b9b6aSSam Leffler ireq->i_val = wmep->wmep_logcwmin; 12238a1b9b6aSSam Leffler break; 12248a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */ 12258a1b9b6aSSam Leffler ireq->i_val = wmep->wmep_logcwmax; 12268a1b9b6aSSam Leffler break; 12278a1b9b6aSSam Leffler case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */ 12288a1b9b6aSSam Leffler ireq->i_val = wmep->wmep_aifsn; 12298a1b9b6aSSam Leffler break; 12308a1b9b6aSSam Leffler case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */ 12318a1b9b6aSSam Leffler ireq->i_val = wmep->wmep_txopLimit; 12328a1b9b6aSSam Leffler break; 12338a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */ 12348a1b9b6aSSam Leffler wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac]; 12358a1b9b6aSSam Leffler ireq->i_val = wmep->wmep_acm; 12368a1b9b6aSSam Leffler break; 12378a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only)*/ 12388a1b9b6aSSam Leffler wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac]; 12398a1b9b6aSSam Leffler ireq->i_val = !wmep->wmep_noackPolicy; 12408a1b9b6aSSam Leffler break; 12418a1b9b6aSSam Leffler } 12428a1b9b6aSSam Leffler return 0; 12438a1b9b6aSSam Leffler } 12448a1b9b6aSSam Leffler 1245188757f5SSam Leffler static int 1246188757f5SSam Leffler ieee80211_ioctl_getmaccmd(struct ieee80211com *ic, struct ieee80211req *ireq) 1247188757f5SSam Leffler { 1248188757f5SSam Leffler const struct ieee80211_aclator *acl = ic->ic_acl; 1249188757f5SSam Leffler 1250188757f5SSam Leffler return (acl == NULL ? EINVAL : acl->iac_getioctl(ic, ireq)); 1251188757f5SSam Leffler } 1252188757f5SSam Leffler 1253c788ca3eSBill Paul /* 1254c788ca3eSBill Paul * When building the kernel with -O2 on the i386 architecture, gcc 1255c788ca3eSBill Paul * seems to want to inline this function into ieee80211_ioctl() 1256c788ca3eSBill Paul * (which is the only routine that calls it). When this happens, 1257c788ca3eSBill Paul * ieee80211_ioctl() ends up consuming an additional 2K of stack 1258c788ca3eSBill Paul * space. (Exactly why it needs so much is unclear.) The problem 1259c788ca3eSBill Paul * is that it's possible for ieee80211_ioctl() to invoke other 1260c788ca3eSBill Paul * routines (including driver init functions) which could then find 1261c788ca3eSBill Paul * themselves perilously close to exhausting the stack. 1262c788ca3eSBill Paul * 1263c788ca3eSBill Paul * To avoid this, we deliberately prevent gcc from inlining this 1264c788ca3eSBill Paul * routine. Another way to avoid this is to use less agressive 1265c788ca3eSBill Paul * optimization when compiling this file (i.e. -O instead of -O2) 1266c788ca3eSBill Paul * but special-casing the compilation of this one module in the 1267c788ca3eSBill Paul * build system would be awkward. 1268c788ca3eSBill Paul */ 1269c788ca3eSBill Paul #ifdef __GNUC__ 1270c788ca3eSBill Paul __attribute__ ((noinline)) 1271c788ca3eSBill Paul #endif 12728a1b9b6aSSam Leffler static int 12738a1b9b6aSSam Leffler ieee80211_ioctl_get80211(struct ieee80211com *ic, u_long cmd, struct ieee80211req *ireq) 12748a1b9b6aSSam Leffler { 12758a1b9b6aSSam Leffler const struct ieee80211_rsnparms *rsn = &ic->ic_bss->ni_rsn; 12761a1e1d21SSam Leffler int error = 0; 12778a1b9b6aSSam Leffler u_int kid, len, m; 12781a1e1d21SSam Leffler u_int8_t tmpkey[IEEE80211_KEYBUF_SIZE]; 12791a1e1d21SSam Leffler char tmpssid[IEEE80211_NWID_LEN]; 12801a1e1d21SSam Leffler 12811a1e1d21SSam Leffler switch (ireq->i_type) { 12821a1e1d21SSam Leffler case IEEE80211_IOC_SSID: 12831a1e1d21SSam Leffler switch (ic->ic_state) { 12841a1e1d21SSam Leffler case IEEE80211_S_INIT: 12851a1e1d21SSam Leffler case IEEE80211_S_SCAN: 12861a1e1d21SSam Leffler ireq->i_len = ic->ic_des_esslen; 12871a1e1d21SSam Leffler memcpy(tmpssid, ic->ic_des_essid, ireq->i_len); 12881a1e1d21SSam Leffler break; 12891a1e1d21SSam Leffler default: 12901a1e1d21SSam Leffler ireq->i_len = ic->ic_bss->ni_esslen; 12911a1e1d21SSam Leffler memcpy(tmpssid, ic->ic_bss->ni_essid, 12921a1e1d21SSam Leffler ireq->i_len); 12931a1e1d21SSam Leffler break; 12941a1e1d21SSam Leffler } 12951a1e1d21SSam Leffler error = copyout(tmpssid, ireq->i_data, ireq->i_len); 12961a1e1d21SSam Leffler break; 12971a1e1d21SSam Leffler case IEEE80211_IOC_NUMSSIDS: 12981a1e1d21SSam Leffler ireq->i_val = 1; 12991a1e1d21SSam Leffler break; 13001a1e1d21SSam Leffler case IEEE80211_IOC_WEP: 13018a1b9b6aSSam Leffler if ((ic->ic_flags & IEEE80211_F_PRIVACY) == 0) 13028a1b9b6aSSam Leffler ireq->i_val = IEEE80211_WEP_OFF; 13038a1b9b6aSSam Leffler else if (ic->ic_flags & IEEE80211_F_DROPUNENC) 13048a1b9b6aSSam Leffler ireq->i_val = IEEE80211_WEP_ON; 13058a1b9b6aSSam Leffler else 13068a1b9b6aSSam Leffler ireq->i_val = IEEE80211_WEP_MIXED; 13071a1e1d21SSam Leffler break; 13081a1e1d21SSam Leffler case IEEE80211_IOC_WEPKEY: 13091a1e1d21SSam Leffler kid = (u_int) ireq->i_val; 13108a1b9b6aSSam Leffler if (kid >= IEEE80211_WEP_NKID) 13118a1b9b6aSSam Leffler return EINVAL; 13128a1b9b6aSSam Leffler len = (u_int) ic->ic_nw_keys[kid].wk_keylen; 13131a1e1d21SSam Leffler /* NB: only root can read WEP keys */ 13145c8bb90bSBrian Feldman if (suser(curthread) == 0) { 13151a1e1d21SSam Leffler bcopy(ic->ic_nw_keys[kid].wk_key, tmpkey, len); 13161a1e1d21SSam Leffler } else { 13171a1e1d21SSam Leffler bzero(tmpkey, len); 13181a1e1d21SSam Leffler } 13191a1e1d21SSam Leffler ireq->i_len = len; 13201a1e1d21SSam Leffler error = copyout(tmpkey, ireq->i_data, len); 13211a1e1d21SSam Leffler break; 13221a1e1d21SSam Leffler case IEEE80211_IOC_NUMWEPKEYS: 13231a1e1d21SSam Leffler ireq->i_val = IEEE80211_WEP_NKID; 13241a1e1d21SSam Leffler break; 13251a1e1d21SSam Leffler case IEEE80211_IOC_WEPTXKEY: 13268a1b9b6aSSam Leffler ireq->i_val = ic->ic_def_txkey; 13271a1e1d21SSam Leffler break; 13281a1e1d21SSam Leffler case IEEE80211_IOC_AUTHMODE: 13298a1b9b6aSSam Leffler if (ic->ic_flags & IEEE80211_F_WPA) 13308a1b9b6aSSam Leffler ireq->i_val = IEEE80211_AUTH_WPA; 13318a1b9b6aSSam Leffler else 13328a1b9b6aSSam Leffler ireq->i_val = ic->ic_bss->ni_authmode; 13331a1e1d21SSam Leffler break; 13341a1e1d21SSam Leffler case IEEE80211_IOC_CHANNEL: 1335b5c99415SSam Leffler ireq->i_val = ieee80211_chan2ieee(ic, ic->ic_curchan); 13361a1e1d21SSam Leffler break; 13371a1e1d21SSam Leffler case IEEE80211_IOC_POWERSAVE: 13381a1e1d21SSam Leffler if (ic->ic_flags & IEEE80211_F_PMGTON) 13391a1e1d21SSam Leffler ireq->i_val = IEEE80211_POWERSAVE_ON; 13401a1e1d21SSam Leffler else 13411a1e1d21SSam Leffler ireq->i_val = IEEE80211_POWERSAVE_OFF; 13421a1e1d21SSam Leffler break; 13431a1e1d21SSam Leffler case IEEE80211_IOC_POWERSAVESLEEP: 13441a1e1d21SSam Leffler ireq->i_val = ic->ic_lintval; 13451a1e1d21SSam Leffler break; 134613604e6bSSam Leffler case IEEE80211_IOC_RTSTHRESHOLD: 13471a1e1d21SSam Leffler ireq->i_val = ic->ic_rtsthreshold; 13481a1e1d21SSam Leffler break; 13492e79ca97SSam Leffler case IEEE80211_IOC_PROTMODE: 13502e79ca97SSam Leffler ireq->i_val = ic->ic_protmode; 13512e79ca97SSam Leffler break; 13522e79ca97SSam Leffler case IEEE80211_IOC_TXPOWER: 13532e79ca97SSam Leffler if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0) 13548a1b9b6aSSam Leffler return EINVAL; 13558a1b9b6aSSam Leffler ireq->i_val = ic->ic_txpowlimit; 13568a1b9b6aSSam Leffler break; 13578a1b9b6aSSam Leffler case IEEE80211_IOC_MCASTCIPHER: 13588a1b9b6aSSam Leffler ireq->i_val = rsn->rsn_mcastcipher; 13598a1b9b6aSSam Leffler break; 13608a1b9b6aSSam Leffler case IEEE80211_IOC_MCASTKEYLEN: 13618a1b9b6aSSam Leffler ireq->i_val = rsn->rsn_mcastkeylen; 13628a1b9b6aSSam Leffler break; 13638a1b9b6aSSam Leffler case IEEE80211_IOC_UCASTCIPHERS: 13648a1b9b6aSSam Leffler ireq->i_val = 0; 13658a1b9b6aSSam Leffler for (m = 0x1; m != 0; m <<= 1) 13668a1b9b6aSSam Leffler if (rsn->rsn_ucastcipherset & m) 13678a1b9b6aSSam Leffler ireq->i_val |= 1<<cap2cipher(m); 13688a1b9b6aSSam Leffler break; 13698a1b9b6aSSam Leffler case IEEE80211_IOC_UCASTCIPHER: 13708a1b9b6aSSam Leffler ireq->i_val = rsn->rsn_ucastcipher; 13718a1b9b6aSSam Leffler break; 13728a1b9b6aSSam Leffler case IEEE80211_IOC_UCASTKEYLEN: 13738a1b9b6aSSam Leffler ireq->i_val = rsn->rsn_ucastkeylen; 13748a1b9b6aSSam Leffler break; 13758a1b9b6aSSam Leffler case IEEE80211_IOC_KEYMGTALGS: 13768a1b9b6aSSam Leffler ireq->i_val = rsn->rsn_keymgmtset; 13778a1b9b6aSSam Leffler break; 13788a1b9b6aSSam Leffler case IEEE80211_IOC_RSNCAPS: 13798a1b9b6aSSam Leffler ireq->i_val = rsn->rsn_caps; 13808a1b9b6aSSam Leffler break; 13818a1b9b6aSSam Leffler case IEEE80211_IOC_WPA: 13828a1b9b6aSSam Leffler switch (ic->ic_flags & IEEE80211_F_WPA) { 13838a1b9b6aSSam Leffler case IEEE80211_F_WPA1: 13848a1b9b6aSSam Leffler ireq->i_val = 1; 13858a1b9b6aSSam Leffler break; 13868a1b9b6aSSam Leffler case IEEE80211_F_WPA2: 13878a1b9b6aSSam Leffler ireq->i_val = 2; 13888a1b9b6aSSam Leffler break; 13898a1b9b6aSSam Leffler case IEEE80211_F_WPA1 | IEEE80211_F_WPA2: 13908a1b9b6aSSam Leffler ireq->i_val = 3; 13918a1b9b6aSSam Leffler break; 13928a1b9b6aSSam Leffler default: 13938a1b9b6aSSam Leffler ireq->i_val = 0; 13948a1b9b6aSSam Leffler break; 13958a1b9b6aSSam Leffler } 13968a1b9b6aSSam Leffler break; 13978a1b9b6aSSam Leffler case IEEE80211_IOC_CHANLIST: 13988a1b9b6aSSam Leffler error = ieee80211_ioctl_getchanlist(ic, ireq); 13998a1b9b6aSSam Leffler break; 14008a1b9b6aSSam Leffler case IEEE80211_IOC_ROAMING: 14018a1b9b6aSSam Leffler ireq->i_val = ic->ic_roaming; 14028a1b9b6aSSam Leffler break; 14038a1b9b6aSSam Leffler case IEEE80211_IOC_PRIVACY: 14048a1b9b6aSSam Leffler ireq->i_val = (ic->ic_flags & IEEE80211_F_PRIVACY) != 0; 14058a1b9b6aSSam Leffler break; 14068a1b9b6aSSam Leffler case IEEE80211_IOC_DROPUNENCRYPTED: 14078a1b9b6aSSam Leffler ireq->i_val = (ic->ic_flags & IEEE80211_F_DROPUNENC) != 0; 14088a1b9b6aSSam Leffler break; 14098a1b9b6aSSam Leffler case IEEE80211_IOC_COUNTERMEASURES: 14108a1b9b6aSSam Leffler ireq->i_val = (ic->ic_flags & IEEE80211_F_COUNTERM) != 0; 14118a1b9b6aSSam Leffler break; 14128a1b9b6aSSam Leffler case IEEE80211_IOC_DRIVER_CAPS: 14138a1b9b6aSSam Leffler ireq->i_val = ic->ic_caps>>16; 14148a1b9b6aSSam Leffler ireq->i_len = ic->ic_caps&0xffff; 14158a1b9b6aSSam Leffler break; 14168a1b9b6aSSam Leffler case IEEE80211_IOC_WME: 14178a1b9b6aSSam Leffler ireq->i_val = (ic->ic_flags & IEEE80211_F_WME) != 0; 14188a1b9b6aSSam Leffler break; 14198a1b9b6aSSam Leffler case IEEE80211_IOC_HIDESSID: 14208a1b9b6aSSam Leffler ireq->i_val = (ic->ic_flags & IEEE80211_F_HIDESSID) != 0; 14218a1b9b6aSSam Leffler break; 14228a1b9b6aSSam Leffler case IEEE80211_IOC_APBRIDGE: 14238a1b9b6aSSam Leffler ireq->i_val = (ic->ic_flags & IEEE80211_F_NOBRIDGE) == 0; 14248a1b9b6aSSam Leffler break; 14258a1b9b6aSSam Leffler case IEEE80211_IOC_OPTIE: 14268a1b9b6aSSam Leffler if (ic->ic_opt_ie == NULL) 14278a1b9b6aSSam Leffler return EINVAL; 14288a1b9b6aSSam Leffler /* NB: truncate, caller can check length */ 14298a1b9b6aSSam Leffler if (ireq->i_len > ic->ic_opt_ie_len) 14308a1b9b6aSSam Leffler ireq->i_len = ic->ic_opt_ie_len; 14318a1b9b6aSSam Leffler error = copyout(ic->ic_opt_ie, ireq->i_data, ireq->i_len); 14328a1b9b6aSSam Leffler break; 14338a1b9b6aSSam Leffler case IEEE80211_IOC_WPAKEY: 14348a1b9b6aSSam Leffler error = ieee80211_ioctl_getkey(ic, ireq); 14358a1b9b6aSSam Leffler break; 14368a1b9b6aSSam Leffler case IEEE80211_IOC_CHANINFO: 14378a1b9b6aSSam Leffler error = ieee80211_ioctl_getchaninfo(ic, ireq); 14388a1b9b6aSSam Leffler break; 14398a1b9b6aSSam Leffler case IEEE80211_IOC_BSSID: 14408a1b9b6aSSam Leffler if (ireq->i_len != IEEE80211_ADDR_LEN) 14418a1b9b6aSSam Leffler return EINVAL; 14428a1b9b6aSSam Leffler error = copyout(ic->ic_state == IEEE80211_S_RUN ? 14438a1b9b6aSSam Leffler ic->ic_bss->ni_bssid : 14448a1b9b6aSSam Leffler ic->ic_des_bssid, 14458a1b9b6aSSam Leffler ireq->i_data, ireq->i_len); 14468a1b9b6aSSam Leffler break; 14478a1b9b6aSSam Leffler case IEEE80211_IOC_WPAIE: 14488a1b9b6aSSam Leffler error = ieee80211_ioctl_getwpaie(ic, ireq); 14498a1b9b6aSSam Leffler break; 14508a1b9b6aSSam Leffler case IEEE80211_IOC_SCAN_RESULTS: 14518a1b9b6aSSam Leffler error = ieee80211_ioctl_getscanresults(ic, ireq); 14528a1b9b6aSSam Leffler break; 14538a1b9b6aSSam Leffler case IEEE80211_IOC_STA_STATS: 14548a1b9b6aSSam Leffler error = ieee80211_ioctl_getstastats(ic, ireq); 14558a1b9b6aSSam Leffler break; 14568a1b9b6aSSam Leffler case IEEE80211_IOC_TXPOWMAX: 14578a1b9b6aSSam Leffler ireq->i_val = ic->ic_bss->ni_txpower; 14588a1b9b6aSSam Leffler break; 14598a1b9b6aSSam Leffler case IEEE80211_IOC_STA_TXPOW: 14608a1b9b6aSSam Leffler error = ieee80211_ioctl_getstatxpow(ic, ireq); 14618a1b9b6aSSam Leffler break; 14628a1b9b6aSSam Leffler case IEEE80211_IOC_STA_INFO: 14638a1b9b6aSSam Leffler error = ieee80211_ioctl_getstainfo(ic, ireq); 14648a1b9b6aSSam Leffler break; 14658a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */ 14668a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */ 14678a1b9b6aSSam Leffler case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */ 14688a1b9b6aSSam Leffler case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */ 14698a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */ 14708a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (bss only) */ 14718a1b9b6aSSam Leffler error = ieee80211_ioctl_getwmeparam(ic, ireq); 14728a1b9b6aSSam Leffler break; 14738a1b9b6aSSam Leffler case IEEE80211_IOC_DTIM_PERIOD: 14748a1b9b6aSSam Leffler ireq->i_val = ic->ic_dtim_period; 14758a1b9b6aSSam Leffler break; 14768a1b9b6aSSam Leffler case IEEE80211_IOC_BEACON_INTERVAL: 14778a1b9b6aSSam Leffler /* NB: get from ic_bss for station mode */ 14788a1b9b6aSSam Leffler ireq->i_val = ic->ic_bss->ni_intval; 14792e79ca97SSam Leffler break; 1480c4f040c3SSam Leffler case IEEE80211_IOC_PUREG: 1481c4f040c3SSam Leffler ireq->i_val = (ic->ic_flags & IEEE80211_F_PUREG) != 0; 1482c4f040c3SSam Leffler break; 148370231e3dSSam Leffler case IEEE80211_IOC_FRAGTHRESHOLD: 148470231e3dSSam Leffler ireq->i_val = ic->ic_fragthreshold; 148570231e3dSSam Leffler break; 1486188757f5SSam Leffler case IEEE80211_IOC_MACCMD: 1487188757f5SSam Leffler error = ieee80211_ioctl_getmaccmd(ic, ireq); 1488188757f5SSam Leffler break; 14891a1e1d21SSam Leffler default: 14901a1e1d21SSam Leffler error = EINVAL; 1491b2e95691SSam Leffler break; 14921a1e1d21SSam Leffler } 14938a1b9b6aSSam Leffler return error; 14948a1b9b6aSSam Leffler } 14958a1b9b6aSSam Leffler 14968a1b9b6aSSam Leffler static int 14978a1b9b6aSSam Leffler ieee80211_ioctl_setoptie(struct ieee80211com *ic, struct ieee80211req *ireq) 14988a1b9b6aSSam Leffler { 14998a1b9b6aSSam Leffler int error; 15008a1b9b6aSSam Leffler void *ie; 15018a1b9b6aSSam Leffler 15028a1b9b6aSSam Leffler /* 15038a1b9b6aSSam Leffler * NB: Doing this for ap operation could be useful (e.g. for 15048a1b9b6aSSam Leffler * WPA and/or WME) except that it typically is worthless 15058a1b9b6aSSam Leffler * without being able to intervene when processing 15068a1b9b6aSSam Leffler * association response frames--so disallow it for now. 15078a1b9b6aSSam Leffler */ 15088a1b9b6aSSam Leffler if (ic->ic_opmode != IEEE80211_M_STA) 15098a1b9b6aSSam Leffler return EINVAL; 15108a1b9b6aSSam Leffler if (ireq->i_len > IEEE80211_MAX_OPT_IE) 15118a1b9b6aSSam Leffler return EINVAL; 15128a1b9b6aSSam Leffler /* NB: data.length is validated by the wireless extensions code */ 15138a1b9b6aSSam Leffler MALLOC(ie, void *, ireq->i_len, M_DEVBUF, M_WAITOK); 15148a1b9b6aSSam Leffler if (ie == NULL) 15158a1b9b6aSSam Leffler return ENOMEM; 15168a1b9b6aSSam Leffler error = copyin(ireq->i_data, ie, ireq->i_len); 15178a1b9b6aSSam Leffler /* XXX sanity check data? */ 15188a1b9b6aSSam Leffler if (ic->ic_opt_ie != NULL) 15198a1b9b6aSSam Leffler FREE(ic->ic_opt_ie, M_DEVBUF); 15208a1b9b6aSSam Leffler ic->ic_opt_ie = ie; 15218a1b9b6aSSam Leffler ic->ic_opt_ie_len = ireq->i_len; 15228a1b9b6aSSam Leffler return 0; 15238a1b9b6aSSam Leffler } 15248a1b9b6aSSam Leffler 15258a1b9b6aSSam Leffler static int 15268a1b9b6aSSam Leffler ieee80211_ioctl_setkey(struct ieee80211com *ic, struct ieee80211req *ireq) 15278a1b9b6aSSam Leffler { 15288a1b9b6aSSam Leffler struct ieee80211req_key ik; 15298a1b9b6aSSam Leffler struct ieee80211_node *ni; 15308a1b9b6aSSam Leffler struct ieee80211_key *wk; 15318a1b9b6aSSam Leffler u_int16_t kid; 15328a1b9b6aSSam Leffler int error; 15338a1b9b6aSSam Leffler 15348a1b9b6aSSam Leffler if (ireq->i_len != sizeof(ik)) 15358a1b9b6aSSam Leffler return EINVAL; 15368a1b9b6aSSam Leffler error = copyin(ireq->i_data, &ik, sizeof(ik)); 15371a1e1d21SSam Leffler if (error) 15388a1b9b6aSSam Leffler return error; 15398a1b9b6aSSam Leffler /* NB: cipher support is verified by ieee80211_crypt_newkey */ 15408a1b9b6aSSam Leffler /* NB: this also checks ik->ik_keylen > sizeof(wk->wk_key) */ 15418a1b9b6aSSam Leffler if (ik.ik_keylen > sizeof(ik.ik_keydata)) 15428a1b9b6aSSam Leffler return E2BIG; 15438a1b9b6aSSam Leffler kid = ik.ik_keyix; 15448a1b9b6aSSam Leffler if (kid == IEEE80211_KEYIX_NONE) { 15458a1b9b6aSSam Leffler /* XXX unicast keys currently must be tx/rx */ 15468a1b9b6aSSam Leffler if (ik.ik_flags != (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV)) 15478a1b9b6aSSam Leffler return EINVAL; 15488a1b9b6aSSam Leffler if (ic->ic_opmode == IEEE80211_M_STA) { 1549b5d4660fSSam Leffler ni = ieee80211_ref_node(ic->ic_bss); 1550b5d4660fSSam Leffler if (!IEEE80211_ADDR_EQ(ik.ik_macaddr, ni->ni_bssid)) { 1551b5d4660fSSam Leffler ieee80211_free_node(ni); 15528a1b9b6aSSam Leffler return EADDRNOTAVAIL; 1553b5d4660fSSam Leffler } 15548a1b9b6aSSam Leffler } else { 1555acc4f7f5SSam Leffler ni = ieee80211_find_node(&ic->ic_sta, ik.ik_macaddr); 15568a1b9b6aSSam Leffler if (ni == NULL) 15578a1b9b6aSSam Leffler return ENOENT; 15588a1b9b6aSSam Leffler } 15598a1b9b6aSSam Leffler wk = &ni->ni_ucastkey; 15608a1b9b6aSSam Leffler } else { 15618a1b9b6aSSam Leffler if (kid >= IEEE80211_WEP_NKID) 15628a1b9b6aSSam Leffler return EINVAL; 15638a1b9b6aSSam Leffler wk = &ic->ic_nw_keys[kid]; 15648a1b9b6aSSam Leffler ni = NULL; 15658a1b9b6aSSam Leffler } 15668a1b9b6aSSam Leffler error = 0; 15678a1b9b6aSSam Leffler ieee80211_key_update_begin(ic); 1568dd70e17bSSam Leffler if (ieee80211_crypto_newkey(ic, ik.ik_type, ik.ik_flags, wk)) { 15698a1b9b6aSSam Leffler wk->wk_keylen = ik.ik_keylen; 15708a1b9b6aSSam Leffler /* NB: MIC presence is implied by cipher type */ 15718a1b9b6aSSam Leffler if (wk->wk_keylen > IEEE80211_KEYBUF_SIZE) 15728a1b9b6aSSam Leffler wk->wk_keylen = IEEE80211_KEYBUF_SIZE; 15738a1b9b6aSSam Leffler wk->wk_keyrsc = ik.ik_keyrsc; 15748a1b9b6aSSam Leffler wk->wk_keytsc = 0; /* new key, reset */ 15758a1b9b6aSSam Leffler memset(wk->wk_key, 0, sizeof(wk->wk_key)); 15768a1b9b6aSSam Leffler memcpy(wk->wk_key, ik.ik_keydata, ik.ik_keylen); 15778a1b9b6aSSam Leffler if (!ieee80211_crypto_setkey(ic, wk, 15788a1b9b6aSSam Leffler ni != NULL ? ni->ni_macaddr : ik.ik_macaddr)) 15798a1b9b6aSSam Leffler error = EIO; 15808a1b9b6aSSam Leffler else if ((ik.ik_flags & IEEE80211_KEY_DEFAULT)) 15818a1b9b6aSSam Leffler ic->ic_def_txkey = kid; 15828a1b9b6aSSam Leffler } else 15838a1b9b6aSSam Leffler error = ENXIO; 15848a1b9b6aSSam Leffler ieee80211_key_update_end(ic); 15858a1b9b6aSSam Leffler if (ni != NULL) 15868a1b9b6aSSam Leffler ieee80211_free_node(ni); 15878a1b9b6aSSam Leffler return error; 15888a1b9b6aSSam Leffler } 15898a1b9b6aSSam Leffler 15908a1b9b6aSSam Leffler static int 15918a1b9b6aSSam Leffler ieee80211_ioctl_delkey(struct ieee80211com *ic, struct ieee80211req *ireq) 15928a1b9b6aSSam Leffler { 15938a1b9b6aSSam Leffler struct ieee80211req_del_key dk; 15948a1b9b6aSSam Leffler int kid, error; 15958a1b9b6aSSam Leffler 15968a1b9b6aSSam Leffler if (ireq->i_len != sizeof(dk)) 15978a1b9b6aSSam Leffler return EINVAL; 15988a1b9b6aSSam Leffler error = copyin(ireq->i_data, &dk, sizeof(dk)); 15998a1b9b6aSSam Leffler if (error) 16008a1b9b6aSSam Leffler return error; 16018a1b9b6aSSam Leffler kid = dk.idk_keyix; 16028a1b9b6aSSam Leffler /* XXX u_int8_t -> u_int16_t */ 16038a1b9b6aSSam Leffler if (dk.idk_keyix == (u_int8_t) IEEE80211_KEYIX_NONE) { 16048a1b9b6aSSam Leffler struct ieee80211_node *ni; 16058a1b9b6aSSam Leffler 1606b5d4660fSSam Leffler if (ic->ic_opmode == IEEE80211_M_STA) { 1607b5d4660fSSam Leffler ni = ieee80211_ref_node(ic->ic_bss); 1608b5d4660fSSam Leffler if (!IEEE80211_ADDR_EQ(dk.idk_macaddr, ni->ni_bssid)) { 1609b5d4660fSSam Leffler ieee80211_free_node(ni); 1610b5d4660fSSam Leffler return EADDRNOTAVAIL; 1611b5d4660fSSam Leffler } 1612b5d4660fSSam Leffler } else { 1613acc4f7f5SSam Leffler ni = ieee80211_find_node(&ic->ic_sta, dk.idk_macaddr); 16148a1b9b6aSSam Leffler if (ni == NULL) 1615b5d4660fSSam Leffler return ENOENT; 1616b5d4660fSSam Leffler } 16178a1b9b6aSSam Leffler /* XXX error return */ 1618c1225b52SSam Leffler ieee80211_node_delucastkey(ni); 16198a1b9b6aSSam Leffler ieee80211_free_node(ni); 16208a1b9b6aSSam Leffler } else { 16218a1b9b6aSSam Leffler if (kid >= IEEE80211_WEP_NKID) 16228a1b9b6aSSam Leffler return EINVAL; 16238a1b9b6aSSam Leffler /* XXX error return */ 16248a1b9b6aSSam Leffler ieee80211_crypto_delkey(ic, &ic->ic_nw_keys[kid]); 16258a1b9b6aSSam Leffler } 16268a1b9b6aSSam Leffler return 0; 16278a1b9b6aSSam Leffler } 16288a1b9b6aSSam Leffler 16298a1b9b6aSSam Leffler static void 16308a1b9b6aSSam Leffler domlme(void *arg, struct ieee80211_node *ni) 16318a1b9b6aSSam Leffler { 16328a1b9b6aSSam Leffler struct ieee80211com *ic = ni->ni_ic; 16338a1b9b6aSSam Leffler struct ieee80211req_mlme *mlme = arg; 16348a1b9b6aSSam Leffler 16358a1b9b6aSSam Leffler if (ni->ni_associd != 0) { 16368a1b9b6aSSam Leffler IEEE80211_SEND_MGMT(ic, ni, 16378a1b9b6aSSam Leffler mlme->im_op == IEEE80211_MLME_DEAUTH ? 16388a1b9b6aSSam Leffler IEEE80211_FC0_SUBTYPE_DEAUTH : 16398a1b9b6aSSam Leffler IEEE80211_FC0_SUBTYPE_DISASSOC, 16408a1b9b6aSSam Leffler mlme->im_reason); 16418a1b9b6aSSam Leffler } 16428a1b9b6aSSam Leffler ieee80211_node_leave(ic, ni); 16438a1b9b6aSSam Leffler } 16448a1b9b6aSSam Leffler 16458a1b9b6aSSam Leffler static int 16468a1b9b6aSSam Leffler ieee80211_ioctl_setmlme(struct ieee80211com *ic, struct ieee80211req *ireq) 16478a1b9b6aSSam Leffler { 16488a1b9b6aSSam Leffler struct ieee80211req_mlme mlme; 16498a1b9b6aSSam Leffler struct ieee80211_node *ni; 16508a1b9b6aSSam Leffler int error; 16518a1b9b6aSSam Leffler 16528a1b9b6aSSam Leffler if (ireq->i_len != sizeof(mlme)) 16538a1b9b6aSSam Leffler return EINVAL; 16548a1b9b6aSSam Leffler error = copyin(ireq->i_data, &mlme, sizeof(mlme)); 16558a1b9b6aSSam Leffler if (error) 16568a1b9b6aSSam Leffler return error; 16578a1b9b6aSSam Leffler switch (mlme.im_op) { 16588a1b9b6aSSam Leffler case IEEE80211_MLME_ASSOC: 16598a1b9b6aSSam Leffler if (ic->ic_opmode != IEEE80211_M_STA) 16608a1b9b6aSSam Leffler return EINVAL; 16618a1b9b6aSSam Leffler /* XXX must be in S_SCAN state? */ 16628a1b9b6aSSam Leffler 1663f02a0bd2SSam Leffler if (mlme.im_ssid_len != 0) { 16648a1b9b6aSSam Leffler /* 16658a1b9b6aSSam Leffler * Desired ssid specified; must match both bssid and 16668a1b9b6aSSam Leffler * ssid to distinguish ap advertising multiple ssid's. 16678a1b9b6aSSam Leffler */ 16688a1b9b6aSSam Leffler ni = ieee80211_find_node_with_ssid(&ic->ic_scan, 16698a1b9b6aSSam Leffler mlme.im_macaddr, 1670f02a0bd2SSam Leffler mlme.im_ssid_len, mlme.im_ssid); 16718a1b9b6aSSam Leffler } else { 16728a1b9b6aSSam Leffler /* 16738a1b9b6aSSam Leffler * Normal case; just match bssid. 16748a1b9b6aSSam Leffler */ 16758a1b9b6aSSam Leffler ni = ieee80211_find_node(&ic->ic_scan, mlme.im_macaddr); 16768a1b9b6aSSam Leffler } 16778a1b9b6aSSam Leffler if (ni == NULL) 16788a1b9b6aSSam Leffler return EINVAL; 16798a1b9b6aSSam Leffler if (!ieee80211_sta_join(ic, ni)) { 16808a1b9b6aSSam Leffler ieee80211_free_node(ni); 16818a1b9b6aSSam Leffler return EINVAL; 16828a1b9b6aSSam Leffler } 16831a1e1d21SSam Leffler break; 16848a1b9b6aSSam Leffler case IEEE80211_MLME_DISASSOC: 16858a1b9b6aSSam Leffler case IEEE80211_MLME_DEAUTH: 16868a1b9b6aSSam Leffler switch (ic->ic_opmode) { 16878a1b9b6aSSam Leffler case IEEE80211_M_STA: 16888a1b9b6aSSam Leffler /* XXX not quite right */ 16898a1b9b6aSSam Leffler ieee80211_new_state(ic, IEEE80211_S_INIT, 16908a1b9b6aSSam Leffler mlme.im_reason); 16918a1b9b6aSSam Leffler break; 16928a1b9b6aSSam Leffler case IEEE80211_M_HOSTAP: 16938a1b9b6aSSam Leffler /* NB: the broadcast address means do 'em all */ 16948a1b9b6aSSam Leffler if (!IEEE80211_ADDR_EQ(mlme.im_macaddr, ic->ic_ifp->if_broadcastaddr)) { 1695acc4f7f5SSam Leffler if ((ni = ieee80211_find_node(&ic->ic_sta, 16968a1b9b6aSSam Leffler mlme.im_macaddr)) == NULL) 16978a1b9b6aSSam Leffler return EINVAL; 16988a1b9b6aSSam Leffler domlme(&mlme, ni); 16998a1b9b6aSSam Leffler ieee80211_free_node(ni); 17008a1b9b6aSSam Leffler } else { 1701acc4f7f5SSam Leffler ieee80211_iterate_nodes(&ic->ic_sta, 17028a1b9b6aSSam Leffler domlme, &mlme); 17038a1b9b6aSSam Leffler } 17048a1b9b6aSSam Leffler break; 17058a1b9b6aSSam Leffler default: 17068a1b9b6aSSam Leffler return EINVAL; 17078a1b9b6aSSam Leffler } 17088a1b9b6aSSam Leffler break; 17098a1b9b6aSSam Leffler case IEEE80211_MLME_AUTHORIZE: 17108a1b9b6aSSam Leffler case IEEE80211_MLME_UNAUTHORIZE: 17118a1b9b6aSSam Leffler if (ic->ic_opmode != IEEE80211_M_HOSTAP) 17128a1b9b6aSSam Leffler return EINVAL; 1713acc4f7f5SSam Leffler ni = ieee80211_find_node(&ic->ic_sta, mlme.im_macaddr); 17148a1b9b6aSSam Leffler if (ni == NULL) 17158a1b9b6aSSam Leffler return EINVAL; 17168a1b9b6aSSam Leffler if (mlme.im_op == IEEE80211_MLME_AUTHORIZE) 1717e4918ecdSSam Leffler ieee80211_node_authorize(ni); 17188a1b9b6aSSam Leffler else 1719e4918ecdSSam Leffler ieee80211_node_unauthorize(ni); 17208a1b9b6aSSam Leffler ieee80211_free_node(ni); 17218a1b9b6aSSam Leffler break; 17228a1b9b6aSSam Leffler default: 17238a1b9b6aSSam Leffler return EINVAL; 17248a1b9b6aSSam Leffler } 17258a1b9b6aSSam Leffler return 0; 17268a1b9b6aSSam Leffler } 17278a1b9b6aSSam Leffler 17288a1b9b6aSSam Leffler static int 17298a1b9b6aSSam Leffler ieee80211_ioctl_macmac(struct ieee80211com *ic, struct ieee80211req *ireq) 17308a1b9b6aSSam Leffler { 17318a1b9b6aSSam Leffler u_int8_t mac[IEEE80211_ADDR_LEN]; 17328a1b9b6aSSam Leffler const struct ieee80211_aclator *acl = ic->ic_acl; 17338a1b9b6aSSam Leffler int error; 17348a1b9b6aSSam Leffler 17358a1b9b6aSSam Leffler if (ireq->i_len != sizeof(mac)) 17368a1b9b6aSSam Leffler return EINVAL; 17378a1b9b6aSSam Leffler error = copyin(ireq->i_data, mac, ireq->i_len); 17388a1b9b6aSSam Leffler if (error) 17398a1b9b6aSSam Leffler return error; 17408a1b9b6aSSam Leffler if (acl == NULL) { 17418a1b9b6aSSam Leffler acl = ieee80211_aclator_get("mac"); 17428a1b9b6aSSam Leffler if (acl == NULL || !acl->iac_attach(ic)) 17438a1b9b6aSSam Leffler return EINVAL; 17448a1b9b6aSSam Leffler ic->ic_acl = acl; 17458a1b9b6aSSam Leffler } 17468a1b9b6aSSam Leffler if (ireq->i_type == IEEE80211_IOC_ADDMAC) 17478a1b9b6aSSam Leffler acl->iac_add(ic, mac); 17488a1b9b6aSSam Leffler else 17498a1b9b6aSSam Leffler acl->iac_remove(ic, mac); 17508a1b9b6aSSam Leffler return 0; 17518a1b9b6aSSam Leffler } 17528a1b9b6aSSam Leffler 17538a1b9b6aSSam Leffler static int 1754188757f5SSam Leffler ieee80211_ioctl_setmaccmd(struct ieee80211com *ic, struct ieee80211req *ireq) 17558a1b9b6aSSam Leffler { 17568a1b9b6aSSam Leffler const struct ieee80211_aclator *acl = ic->ic_acl; 17578a1b9b6aSSam Leffler 17588a1b9b6aSSam Leffler switch (ireq->i_val) { 17598a1b9b6aSSam Leffler case IEEE80211_MACCMD_POLICY_OPEN: 17608a1b9b6aSSam Leffler case IEEE80211_MACCMD_POLICY_ALLOW: 17618a1b9b6aSSam Leffler case IEEE80211_MACCMD_POLICY_DENY: 17628a1b9b6aSSam Leffler if (acl == NULL) { 17638a1b9b6aSSam Leffler acl = ieee80211_aclator_get("mac"); 17648a1b9b6aSSam Leffler if (acl == NULL || !acl->iac_attach(ic)) 17658a1b9b6aSSam Leffler return EINVAL; 17668a1b9b6aSSam Leffler ic->ic_acl = acl; 17678a1b9b6aSSam Leffler } 17688a1b9b6aSSam Leffler acl->iac_setpolicy(ic, ireq->i_val); 17698a1b9b6aSSam Leffler break; 17708a1b9b6aSSam Leffler case IEEE80211_MACCMD_FLUSH: 17718a1b9b6aSSam Leffler if (acl != NULL) 17728a1b9b6aSSam Leffler acl->iac_flush(ic); 17738a1b9b6aSSam Leffler /* NB: silently ignore when not in use */ 17748a1b9b6aSSam Leffler break; 17758a1b9b6aSSam Leffler case IEEE80211_MACCMD_DETACH: 17768a1b9b6aSSam Leffler if (acl != NULL) { 17778a1b9b6aSSam Leffler ic->ic_acl = NULL; 17788a1b9b6aSSam Leffler acl->iac_detach(ic); 17798a1b9b6aSSam Leffler } 17808a1b9b6aSSam Leffler break; 17818a1b9b6aSSam Leffler default: 1782188757f5SSam Leffler if (acl == NULL) 17838a1b9b6aSSam Leffler return EINVAL; 1784188757f5SSam Leffler else 1785188757f5SSam Leffler return acl->iac_setioctl(ic, ireq); 17868a1b9b6aSSam Leffler } 17878a1b9b6aSSam Leffler return 0; 17888a1b9b6aSSam Leffler } 17898a1b9b6aSSam Leffler 17908a1b9b6aSSam Leffler static int 17918a1b9b6aSSam Leffler ieee80211_ioctl_setchanlist(struct ieee80211com *ic, struct ieee80211req *ireq) 17928a1b9b6aSSam Leffler { 17938a1b9b6aSSam Leffler struct ieee80211req_chanlist list; 17948a1b9b6aSSam Leffler u_char chanlist[IEEE80211_CHAN_BYTES]; 17958a1b9b6aSSam Leffler int i, j, error; 17968a1b9b6aSSam Leffler 17978a1b9b6aSSam Leffler if (ireq->i_len != sizeof(list)) 17988a1b9b6aSSam Leffler return EINVAL; 17998a1b9b6aSSam Leffler error = copyin(ireq->i_data, &list, sizeof(list)); 18008a1b9b6aSSam Leffler if (error) 18018a1b9b6aSSam Leffler return error; 18028a1b9b6aSSam Leffler memset(chanlist, 0, sizeof(chanlist)); 18038a1b9b6aSSam Leffler /* 18048a1b9b6aSSam Leffler * Since channel 0 is not available for DS, channel 1 18058a1b9b6aSSam Leffler * is assigned to LSB on WaveLAN. 18068a1b9b6aSSam Leffler */ 18078a1b9b6aSSam Leffler if (ic->ic_phytype == IEEE80211_T_DS) 18088a1b9b6aSSam Leffler i = 1; 18098a1b9b6aSSam Leffler else 18108a1b9b6aSSam Leffler i = 0; 18118a1b9b6aSSam Leffler for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++) { 18128a1b9b6aSSam Leffler /* 18138a1b9b6aSSam Leffler * NB: silently discard unavailable channels so users 18148a1b9b6aSSam Leffler * can specify 1-255 to get all available channels. 18158a1b9b6aSSam Leffler */ 18168a1b9b6aSSam Leffler if (isset(list.ic_channels, j) && isset(ic->ic_chan_avail, i)) 18178a1b9b6aSSam Leffler setbit(chanlist, i); 18188a1b9b6aSSam Leffler } 18198a1b9b6aSSam Leffler if (ic->ic_ibss_chan == NULL || 18208a1b9b6aSSam Leffler isclr(chanlist, ieee80211_chan2ieee(ic, ic->ic_ibss_chan))) { 18218a1b9b6aSSam Leffler for (i = 0; i <= IEEE80211_CHAN_MAX; i++) 18228a1b9b6aSSam Leffler if (isset(chanlist, i)) { 18238a1b9b6aSSam Leffler ic->ic_ibss_chan = &ic->ic_channels[i]; 18248a1b9b6aSSam Leffler goto found; 18258a1b9b6aSSam Leffler } 18268a1b9b6aSSam Leffler return EINVAL; /* no active channels */ 18278a1b9b6aSSam Leffler found: 18288a1b9b6aSSam Leffler ; 18298a1b9b6aSSam Leffler } 18308a1b9b6aSSam Leffler memcpy(ic->ic_chan_active, chanlist, sizeof(ic->ic_chan_active)); 18318a1b9b6aSSam Leffler return IS_UP_AUTO(ic) ? ENETRESET : 0; 18328a1b9b6aSSam Leffler } 18338a1b9b6aSSam Leffler 18348a1b9b6aSSam Leffler static int 18358a1b9b6aSSam Leffler ieee80211_ioctl_setstatxpow(struct ieee80211com *ic, struct ieee80211req *ireq) 18368a1b9b6aSSam Leffler { 18378a1b9b6aSSam Leffler struct ieee80211_node *ni; 18388a1b9b6aSSam Leffler struct ieee80211req_sta_txpow txpow; 18398a1b9b6aSSam Leffler int error; 18408a1b9b6aSSam Leffler 18418a1b9b6aSSam Leffler if (ireq->i_len != sizeof(txpow)) 18428a1b9b6aSSam Leffler return EINVAL; 18438a1b9b6aSSam Leffler error = copyin(ireq->i_data, &txpow, sizeof(txpow)); 18448a1b9b6aSSam Leffler if (error != 0) 18458a1b9b6aSSam Leffler return error; 1846acc4f7f5SSam Leffler ni = ieee80211_find_node(&ic->ic_sta, txpow.it_macaddr); 18478a1b9b6aSSam Leffler if (ni == NULL) 18488a1b9b6aSSam Leffler return EINVAL; /* XXX */ 18498a1b9b6aSSam Leffler ni->ni_txpower = txpow.it_txpow; 18508a1b9b6aSSam Leffler ieee80211_free_node(ni); 18518a1b9b6aSSam Leffler return error; 18528a1b9b6aSSam Leffler } 18538a1b9b6aSSam Leffler 18548a1b9b6aSSam Leffler static int 18558a1b9b6aSSam Leffler ieee80211_ioctl_setwmeparam(struct ieee80211com *ic, struct ieee80211req *ireq) 18568a1b9b6aSSam Leffler { 18578a1b9b6aSSam Leffler struct ieee80211_wme_state *wme = &ic->ic_wme; 18588a1b9b6aSSam Leffler struct wmeParams *wmep, *chanp; 18598a1b9b6aSSam Leffler int isbss, ac; 18608a1b9b6aSSam Leffler 18618a1b9b6aSSam Leffler if ((ic->ic_caps & IEEE80211_C_WME) == 0) 18628a1b9b6aSSam Leffler return EINVAL; 18638a1b9b6aSSam Leffler 18648a1b9b6aSSam Leffler isbss = (ireq->i_len & IEEE80211_WMEPARAM_BSS); 18658a1b9b6aSSam Leffler ac = (ireq->i_len & IEEE80211_WMEPARAM_VAL); 18668a1b9b6aSSam Leffler if (ac >= WME_NUM_AC) 18678a1b9b6aSSam Leffler ac = WME_AC_BE; 18688a1b9b6aSSam Leffler if (isbss) { 18698a1b9b6aSSam Leffler chanp = &wme->wme_bssChanParams.cap_wmeParams[ac]; 18708a1b9b6aSSam Leffler wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac]; 18718a1b9b6aSSam Leffler } else { 18728a1b9b6aSSam Leffler chanp = &wme->wme_chanParams.cap_wmeParams[ac]; 18738a1b9b6aSSam Leffler wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac]; 18748a1b9b6aSSam Leffler } 18758a1b9b6aSSam Leffler switch (ireq->i_type) { 18768a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */ 18778a1b9b6aSSam Leffler if (isbss) { 18788a1b9b6aSSam Leffler wmep->wmep_logcwmin = ireq->i_val; 18798a1b9b6aSSam Leffler if ((wme->wme_flags & WME_F_AGGRMODE) == 0) 18808a1b9b6aSSam Leffler chanp->wmep_logcwmin = ireq->i_val; 18818a1b9b6aSSam Leffler } else { 18828a1b9b6aSSam Leffler wmep->wmep_logcwmin = chanp->wmep_logcwmin = 18838a1b9b6aSSam Leffler ireq->i_val; 18848a1b9b6aSSam Leffler } 18858a1b9b6aSSam Leffler break; 18868a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */ 18878a1b9b6aSSam Leffler if (isbss) { 18888a1b9b6aSSam Leffler wmep->wmep_logcwmax = ireq->i_val; 18898a1b9b6aSSam Leffler if ((wme->wme_flags & WME_F_AGGRMODE) == 0) 18908a1b9b6aSSam Leffler chanp->wmep_logcwmax = ireq->i_val; 18918a1b9b6aSSam Leffler } else { 18928a1b9b6aSSam Leffler wmep->wmep_logcwmax = chanp->wmep_logcwmax = 18938a1b9b6aSSam Leffler ireq->i_val; 18948a1b9b6aSSam Leffler } 18958a1b9b6aSSam Leffler break; 18968a1b9b6aSSam Leffler case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */ 18978a1b9b6aSSam Leffler if (isbss) { 18988a1b9b6aSSam Leffler wmep->wmep_aifsn = ireq->i_val; 18998a1b9b6aSSam Leffler if ((wme->wme_flags & WME_F_AGGRMODE) == 0) 19008a1b9b6aSSam Leffler chanp->wmep_aifsn = ireq->i_val; 19018a1b9b6aSSam Leffler } else { 19028a1b9b6aSSam Leffler wmep->wmep_aifsn = chanp->wmep_aifsn = ireq->i_val; 19038a1b9b6aSSam Leffler } 19048a1b9b6aSSam Leffler break; 19058a1b9b6aSSam Leffler case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */ 19068a1b9b6aSSam Leffler if (isbss) { 19078a1b9b6aSSam Leffler wmep->wmep_txopLimit = ireq->i_val; 19088a1b9b6aSSam Leffler if ((wme->wme_flags & WME_F_AGGRMODE) == 0) 19098a1b9b6aSSam Leffler chanp->wmep_txopLimit = ireq->i_val; 19108a1b9b6aSSam Leffler } else { 19118a1b9b6aSSam Leffler wmep->wmep_txopLimit = chanp->wmep_txopLimit = 19128a1b9b6aSSam Leffler ireq->i_val; 19138a1b9b6aSSam Leffler } 19148a1b9b6aSSam Leffler break; 19158a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */ 19168a1b9b6aSSam Leffler wmep->wmep_acm = ireq->i_val; 19178a1b9b6aSSam Leffler if ((wme->wme_flags & WME_F_AGGRMODE) == 0) 19188a1b9b6aSSam Leffler chanp->wmep_acm = ireq->i_val; 19198a1b9b6aSSam Leffler break; 19208a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only)*/ 19218a1b9b6aSSam Leffler wmep->wmep_noackPolicy = chanp->wmep_noackPolicy = 19228a1b9b6aSSam Leffler (ireq->i_val) == 0; 19238a1b9b6aSSam Leffler break; 19248a1b9b6aSSam Leffler } 19258a1b9b6aSSam Leffler ieee80211_wme_updateparams(ic); 19268a1b9b6aSSam Leffler return 0; 19278a1b9b6aSSam Leffler } 19288a1b9b6aSSam Leffler 19298a1b9b6aSSam Leffler static int 19308a1b9b6aSSam Leffler cipher2cap(int cipher) 19318a1b9b6aSSam Leffler { 19328a1b9b6aSSam Leffler switch (cipher) { 19338a1b9b6aSSam Leffler case IEEE80211_CIPHER_WEP: return IEEE80211_C_WEP; 19348a1b9b6aSSam Leffler case IEEE80211_CIPHER_AES_OCB: return IEEE80211_C_AES; 19358a1b9b6aSSam Leffler case IEEE80211_CIPHER_AES_CCM: return IEEE80211_C_AES_CCM; 19368a1b9b6aSSam Leffler case IEEE80211_CIPHER_CKIP: return IEEE80211_C_CKIP; 19378a1b9b6aSSam Leffler case IEEE80211_CIPHER_TKIP: return IEEE80211_C_TKIP; 19388a1b9b6aSSam Leffler } 19398a1b9b6aSSam Leffler return 0; 19408a1b9b6aSSam Leffler } 19418a1b9b6aSSam Leffler 19428a1b9b6aSSam Leffler static int 19438a1b9b6aSSam Leffler ieee80211_ioctl_set80211(struct ieee80211com *ic, u_long cmd, struct ieee80211req *ireq) 19448a1b9b6aSSam Leffler { 19458a1b9b6aSSam Leffler static const u_int8_t zerobssid[IEEE80211_ADDR_LEN]; 19468a1b9b6aSSam Leffler struct ieee80211_rsnparms *rsn = &ic->ic_bss->ni_rsn; 19478a1b9b6aSSam Leffler int error; 19488a1b9b6aSSam Leffler const struct ieee80211_authenticator *auth; 19498a1b9b6aSSam Leffler u_int8_t tmpkey[IEEE80211_KEYBUF_SIZE]; 19508a1b9b6aSSam Leffler char tmpssid[IEEE80211_NWID_LEN]; 19518a1b9b6aSSam Leffler u_int8_t tmpbssid[IEEE80211_ADDR_LEN]; 19528a1b9b6aSSam Leffler struct ieee80211_key *k; 19538a1b9b6aSSam Leffler int j, caps; 19548a1b9b6aSSam Leffler u_int kid; 19558a1b9b6aSSam Leffler 19568a1b9b6aSSam Leffler error = 0; 19571a1e1d21SSam Leffler switch (ireq->i_type) { 19581a1e1d21SSam Leffler case IEEE80211_IOC_SSID: 19591a1e1d21SSam Leffler if (ireq->i_val != 0 || 19608a1b9b6aSSam Leffler ireq->i_len > IEEE80211_NWID_LEN) 19618a1b9b6aSSam Leffler return EINVAL; 19621a1e1d21SSam Leffler error = copyin(ireq->i_data, tmpssid, ireq->i_len); 19631a1e1d21SSam Leffler if (error) 19641a1e1d21SSam Leffler break; 19651a1e1d21SSam Leffler memset(ic->ic_des_essid, 0, IEEE80211_NWID_LEN); 19661a1e1d21SSam Leffler ic->ic_des_esslen = ireq->i_len; 19671a1e1d21SSam Leffler memcpy(ic->ic_des_essid, tmpssid, ireq->i_len); 19681a1e1d21SSam Leffler error = ENETRESET; 19691a1e1d21SSam Leffler break; 19701a1e1d21SSam Leffler case IEEE80211_IOC_WEP: 19718a1b9b6aSSam Leffler switch (ireq->i_val) { 19728a1b9b6aSSam Leffler case IEEE80211_WEP_OFF: 19738a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_PRIVACY; 19748a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_DROPUNENC; 19758a1b9b6aSSam Leffler break; 19768a1b9b6aSSam Leffler case IEEE80211_WEP_ON: 19778a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_PRIVACY; 19788a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_DROPUNENC; 19798a1b9b6aSSam Leffler break; 19808a1b9b6aSSam Leffler case IEEE80211_WEP_MIXED: 19818a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_PRIVACY; 19828a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_DROPUNENC; 19838a1b9b6aSSam Leffler break; 19841a1e1d21SSam Leffler } 19851a1e1d21SSam Leffler error = ENETRESET; 19861a1e1d21SSam Leffler break; 19871a1e1d21SSam Leffler case IEEE80211_IOC_WEPKEY: 19881a1e1d21SSam Leffler kid = (u_int) ireq->i_val; 19898a1b9b6aSSam Leffler if (kid >= IEEE80211_WEP_NKID) 19908a1b9b6aSSam Leffler return EINVAL; 19918a1b9b6aSSam Leffler k = &ic->ic_nw_keys[kid]; 19928a1b9b6aSSam Leffler if (ireq->i_len == 0) { 19938a1b9b6aSSam Leffler /* zero-len =>'s delete any existing key */ 19948a1b9b6aSSam Leffler (void) ieee80211_crypto_delkey(ic, k); 19951a1e1d21SSam Leffler break; 19961a1e1d21SSam Leffler } 19978a1b9b6aSSam Leffler if (ireq->i_len > sizeof(tmpkey)) 19988a1b9b6aSSam Leffler return EINVAL; 19991a1e1d21SSam Leffler memset(tmpkey, 0, sizeof(tmpkey)); 20001a1e1d21SSam Leffler error = copyin(ireq->i_data, tmpkey, ireq->i_len); 20011a1e1d21SSam Leffler if (error) 20021a1e1d21SSam Leffler break; 20038a1b9b6aSSam Leffler ieee80211_key_update_begin(ic); 2004dd70e17bSSam Leffler k->wk_keyix = kid; /* NB: force fixed key id */ 2005dd70e17bSSam Leffler if (ieee80211_crypto_newkey(ic, IEEE80211_CIPHER_WEP, 2006dd70e17bSSam Leffler IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV, k)) { 20078a1b9b6aSSam Leffler k->wk_keylen = ireq->i_len; 20088a1b9b6aSSam Leffler memcpy(k->wk_key, tmpkey, sizeof(tmpkey)); 20098a1b9b6aSSam Leffler if (!ieee80211_crypto_setkey(ic, k, ic->ic_myaddr)) 20108a1b9b6aSSam Leffler error = EINVAL; 20118a1b9b6aSSam Leffler } else 20128a1b9b6aSSam Leffler error = EINVAL; 20138a1b9b6aSSam Leffler ieee80211_key_update_end(ic); 2014b5d4660fSSam Leffler if (!error) /* NB: for compatibility */ 2015b5d4660fSSam Leffler error = ENETRESET; 20161a1e1d21SSam Leffler break; 20171a1e1d21SSam Leffler case IEEE80211_IOC_WEPTXKEY: 20181a1e1d21SSam Leffler kid = (u_int) ireq->i_val; 2019380c5fa9SSam Leffler if (kid >= IEEE80211_WEP_NKID && 2020380c5fa9SSam Leffler (u_int16_t) kid != IEEE80211_KEYIX_NONE) 20218a1b9b6aSSam Leffler return EINVAL; 20228a1b9b6aSSam Leffler ic->ic_def_txkey = kid; 2023b8d2606bSSam Leffler error = ENETRESET; /* push to hardware */ 20248a1b9b6aSSam Leffler break; 20258a1b9b6aSSam Leffler case IEEE80211_IOC_AUTHMODE: 20268a1b9b6aSSam Leffler switch (ireq->i_val) { 20278a1b9b6aSSam Leffler case IEEE80211_AUTH_WPA: 20288a1b9b6aSSam Leffler case IEEE80211_AUTH_8021X: /* 802.1x */ 20298a1b9b6aSSam Leffler case IEEE80211_AUTH_OPEN: /* open */ 20308a1b9b6aSSam Leffler case IEEE80211_AUTH_SHARED: /* shared-key */ 20318a1b9b6aSSam Leffler case IEEE80211_AUTH_AUTO: /* auto */ 20328a1b9b6aSSam Leffler auth = ieee80211_authenticator_get(ireq->i_val); 20338a1b9b6aSSam Leffler if (auth == NULL) 20348a1b9b6aSSam Leffler return EINVAL; 20358a1b9b6aSSam Leffler break; 20368a1b9b6aSSam Leffler default: 20378a1b9b6aSSam Leffler return EINVAL; 20388a1b9b6aSSam Leffler } 20398a1b9b6aSSam Leffler switch (ireq->i_val) { 20408a1b9b6aSSam Leffler case IEEE80211_AUTH_WPA: /* WPA w/ 802.1x */ 20418a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_PRIVACY; 20428a1b9b6aSSam Leffler ireq->i_val = IEEE80211_AUTH_8021X; 20438a1b9b6aSSam Leffler break; 20448a1b9b6aSSam Leffler case IEEE80211_AUTH_OPEN: /* open */ 20458a1b9b6aSSam Leffler ic->ic_flags &= ~(IEEE80211_F_WPA|IEEE80211_F_PRIVACY); 20468a1b9b6aSSam Leffler break; 20478a1b9b6aSSam Leffler case IEEE80211_AUTH_SHARED: /* shared-key */ 20488a1b9b6aSSam Leffler case IEEE80211_AUTH_8021X: /* 802.1x */ 20498a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_WPA; 20508a1b9b6aSSam Leffler /* both require a key so mark the PRIVACY capability */ 20518a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_PRIVACY; 20528a1b9b6aSSam Leffler break; 20538a1b9b6aSSam Leffler case IEEE80211_AUTH_AUTO: /* auto */ 20548a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_WPA; 20558a1b9b6aSSam Leffler /* XXX PRIVACY handling? */ 20568a1b9b6aSSam Leffler /* XXX what's the right way to do this? */ 20571a1e1d21SSam Leffler break; 20581a1e1d21SSam Leffler } 20598a1b9b6aSSam Leffler /* NB: authenticator attach/detach happens on state change */ 20608a1b9b6aSSam Leffler ic->ic_bss->ni_authmode = ireq->i_val; 20618a1b9b6aSSam Leffler /* XXX mixed/mode/usage? */ 20628a1b9b6aSSam Leffler ic->ic_auth = auth; 20631a1e1d21SSam Leffler error = ENETRESET; 20641a1e1d21SSam Leffler break; 20651a1e1d21SSam Leffler case IEEE80211_IOC_CHANNEL: 20661a1e1d21SSam Leffler /* XXX 0xffff overflows 16-bit signed */ 20671a1e1d21SSam Leffler if (ireq->i_val == 0 || 20681a1e1d21SSam Leffler ireq->i_val == (int16_t) IEEE80211_CHAN_ANY) 20691a1e1d21SSam Leffler ic->ic_des_chan = IEEE80211_CHAN_ANYC; 20701a1e1d21SSam Leffler else if ((u_int) ireq->i_val > IEEE80211_CHAN_MAX || 20711a1e1d21SSam Leffler isclr(ic->ic_chan_active, ireq->i_val)) { 20728a1b9b6aSSam Leffler return EINVAL; 20731a1e1d21SSam Leffler } else 20741a1e1d21SSam Leffler ic->ic_ibss_chan = ic->ic_des_chan = 20751a1e1d21SSam Leffler &ic->ic_channels[ireq->i_val]; 20761a1e1d21SSam Leffler switch (ic->ic_state) { 20771a1e1d21SSam Leffler case IEEE80211_S_INIT: 20781a1e1d21SSam Leffler case IEEE80211_S_SCAN: 20791a1e1d21SSam Leffler error = ENETRESET; 20801a1e1d21SSam Leffler break; 20811a1e1d21SSam Leffler default: 20828a1b9b6aSSam Leffler /* 20838a1b9b6aSSam Leffler * If the desired channel has changed (to something 20848a1b9b6aSSam Leffler * other than any) and we're not already scanning, 20858a1b9b6aSSam Leffler * then kick the state machine. 20868a1b9b6aSSam Leffler */ 20871a1e1d21SSam Leffler if (ic->ic_des_chan != IEEE80211_CHAN_ANYC && 20888a1b9b6aSSam Leffler ic->ic_bss->ni_chan != ic->ic_des_chan && 20898a1b9b6aSSam Leffler (ic->ic_flags & IEEE80211_F_SCAN) == 0) 20901a1e1d21SSam Leffler error = ENETRESET; 20911a1e1d21SSam Leffler break; 20921a1e1d21SSam Leffler } 20938a1b9b6aSSam Leffler if (error == ENETRESET && ic->ic_opmode == IEEE80211_M_MONITOR) 20948a1b9b6aSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 20951a1e1d21SSam Leffler break; 20961a1e1d21SSam Leffler case IEEE80211_IOC_POWERSAVE: 20971a1e1d21SSam Leffler switch (ireq->i_val) { 20981a1e1d21SSam Leffler case IEEE80211_POWERSAVE_OFF: 20991a1e1d21SSam Leffler if (ic->ic_flags & IEEE80211_F_PMGTON) { 21001a1e1d21SSam Leffler ic->ic_flags &= ~IEEE80211_F_PMGTON; 21011a1e1d21SSam Leffler error = ENETRESET; 21021a1e1d21SSam Leffler } 21031a1e1d21SSam Leffler break; 21041a1e1d21SSam Leffler case IEEE80211_POWERSAVE_ON: 21051a1e1d21SSam Leffler if ((ic->ic_caps & IEEE80211_C_PMGT) == 0) 21061a1e1d21SSam Leffler error = EINVAL; 21071a1e1d21SSam Leffler else if ((ic->ic_flags & IEEE80211_F_PMGTON) == 0) { 21081a1e1d21SSam Leffler ic->ic_flags |= IEEE80211_F_PMGTON; 21091a1e1d21SSam Leffler error = ENETRESET; 21101a1e1d21SSam Leffler } 21111a1e1d21SSam Leffler break; 21121a1e1d21SSam Leffler default: 21131a1e1d21SSam Leffler error = EINVAL; 21141a1e1d21SSam Leffler break; 21151a1e1d21SSam Leffler } 21161a1e1d21SSam Leffler break; 21171a1e1d21SSam Leffler case IEEE80211_IOC_POWERSAVESLEEP: 21188a1b9b6aSSam Leffler if (ireq->i_val < 0) 21198a1b9b6aSSam Leffler return EINVAL; 21201a1e1d21SSam Leffler ic->ic_lintval = ireq->i_val; 21218a1b9b6aSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 21221a1e1d21SSam Leffler break; 212313604e6bSSam Leffler case IEEE80211_IOC_RTSTHRESHOLD: 212470231e3dSSam Leffler if (!(IEEE80211_RTS_MIN <= ireq->i_val && 212570231e3dSSam Leffler ireq->i_val <= IEEE80211_RTS_MAX)) 21268a1b9b6aSSam Leffler return EINVAL; 21271a1e1d21SSam Leffler ic->ic_rtsthreshold = ireq->i_val; 21288a1b9b6aSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 21291a1e1d21SSam Leffler break; 21302e79ca97SSam Leffler case IEEE80211_IOC_PROTMODE: 21318a1b9b6aSSam Leffler if (ireq->i_val > IEEE80211_PROT_RTSCTS) 21328a1b9b6aSSam Leffler return EINVAL; 21332e79ca97SSam Leffler ic->ic_protmode = ireq->i_val; 21342e79ca97SSam Leffler /* NB: if not operating in 11g this can wait */ 21352e79ca97SSam Leffler if (ic->ic_curmode == IEEE80211_MODE_11G) 21368a1b9b6aSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 21372e79ca97SSam Leffler break; 21382e79ca97SSam Leffler case IEEE80211_IOC_TXPOWER: 21398a1b9b6aSSam Leffler if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0) 21408a1b9b6aSSam Leffler return EINVAL; 21412e79ca97SSam Leffler if (!(IEEE80211_TXPOWER_MIN < ireq->i_val && 21428a1b9b6aSSam Leffler ireq->i_val < IEEE80211_TXPOWER_MAX)) 21438a1b9b6aSSam Leffler return EINVAL; 21448a1b9b6aSSam Leffler ic->ic_txpowlimit = ireq->i_val; 21458a1b9b6aSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 21468a1b9b6aSSam Leffler break; 21478a1b9b6aSSam Leffler case IEEE80211_IOC_ROAMING: 21488a1b9b6aSSam Leffler if (!(IEEE80211_ROAMING_DEVICE <= ireq->i_val && 21498a1b9b6aSSam Leffler ireq->i_val <= IEEE80211_ROAMING_MANUAL)) 21508a1b9b6aSSam Leffler return EINVAL; 21518a1b9b6aSSam Leffler ic->ic_roaming = ireq->i_val; 21528a1b9b6aSSam Leffler /* XXXX reset? */ 21538a1b9b6aSSam Leffler break; 21548a1b9b6aSSam Leffler case IEEE80211_IOC_PRIVACY: 21558a1b9b6aSSam Leffler if (ireq->i_val) { 21568a1b9b6aSSam Leffler /* XXX check for key state? */ 21578a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_PRIVACY; 21588a1b9b6aSSam Leffler } else 21598a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_PRIVACY; 21608a1b9b6aSSam Leffler break; 21618a1b9b6aSSam Leffler case IEEE80211_IOC_DROPUNENCRYPTED: 21628a1b9b6aSSam Leffler if (ireq->i_val) 21638a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_DROPUNENC; 21648a1b9b6aSSam Leffler else 21658a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_DROPUNENC; 21668a1b9b6aSSam Leffler break; 21678a1b9b6aSSam Leffler case IEEE80211_IOC_WPAKEY: 21688a1b9b6aSSam Leffler error = ieee80211_ioctl_setkey(ic, ireq); 21698a1b9b6aSSam Leffler break; 21708a1b9b6aSSam Leffler case IEEE80211_IOC_DELKEY: 21718a1b9b6aSSam Leffler error = ieee80211_ioctl_delkey(ic, ireq); 21728a1b9b6aSSam Leffler break; 21738a1b9b6aSSam Leffler case IEEE80211_IOC_MLME: 21748a1b9b6aSSam Leffler error = ieee80211_ioctl_setmlme(ic, ireq); 21758a1b9b6aSSam Leffler break; 21768a1b9b6aSSam Leffler case IEEE80211_IOC_OPTIE: 21778a1b9b6aSSam Leffler error = ieee80211_ioctl_setoptie(ic, ireq); 21788a1b9b6aSSam Leffler break; 21798a1b9b6aSSam Leffler case IEEE80211_IOC_COUNTERMEASURES: 21808a1b9b6aSSam Leffler if (ireq->i_val) { 21818a1b9b6aSSam Leffler if ((ic->ic_flags & IEEE80211_F_WPA) == 0) 21828a1b9b6aSSam Leffler return EINVAL; 21838a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_COUNTERM; 21848a1b9b6aSSam Leffler } else 21858a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_COUNTERM; 21868a1b9b6aSSam Leffler break; 21878a1b9b6aSSam Leffler case IEEE80211_IOC_WPA: 21888a1b9b6aSSam Leffler if (ireq->i_val > 3) 21898a1b9b6aSSam Leffler return EINVAL; 21908a1b9b6aSSam Leffler /* XXX verify ciphers available */ 21918a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_WPA; 21928a1b9b6aSSam Leffler switch (ireq->i_val) { 21938a1b9b6aSSam Leffler case 1: 21948a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_WPA1; 21958a1b9b6aSSam Leffler break; 21968a1b9b6aSSam Leffler case 2: 21978a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_WPA2; 21988a1b9b6aSSam Leffler break; 21998a1b9b6aSSam Leffler case 3: 22008a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2; 22012e79ca97SSam Leffler break; 22022e79ca97SSam Leffler } 22038a1b9b6aSSam Leffler error = ENETRESET; /* XXX? */ 22048a1b9b6aSSam Leffler break; 22058a1b9b6aSSam Leffler case IEEE80211_IOC_WME: 22068a1b9b6aSSam Leffler if (ireq->i_val) { 22078a1b9b6aSSam Leffler if ((ic->ic_caps & IEEE80211_C_WME) == 0) 22088a1b9b6aSSam Leffler return EINVAL; 22098a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_WME; 22108a1b9b6aSSam Leffler } else 22118a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_WME; 22128a1b9b6aSSam Leffler error = ENETRESET; /* XXX maybe not for station? */ 22138a1b9b6aSSam Leffler break; 22148a1b9b6aSSam Leffler case IEEE80211_IOC_HIDESSID: 22158a1b9b6aSSam Leffler if (ireq->i_val) 22168a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_HIDESSID; 22178a1b9b6aSSam Leffler else 22188a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_HIDESSID; 22192e79ca97SSam Leffler error = ENETRESET; 22202e79ca97SSam Leffler break; 22218a1b9b6aSSam Leffler case IEEE80211_IOC_APBRIDGE: 22228a1b9b6aSSam Leffler if (ireq->i_val == 0) 22238a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_NOBRIDGE; 22248a1b9b6aSSam Leffler else 22258a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_NOBRIDGE; 22268a1b9b6aSSam Leffler break; 22278a1b9b6aSSam Leffler case IEEE80211_IOC_MCASTCIPHER: 22288a1b9b6aSSam Leffler if ((ic->ic_caps & cipher2cap(ireq->i_val)) == 0 && 22298a1b9b6aSSam Leffler !ieee80211_crypto_available(ireq->i_val)) 22308a1b9b6aSSam Leffler return EINVAL; 22318a1b9b6aSSam Leffler rsn->rsn_mcastcipher = ireq->i_val; 22328a1b9b6aSSam Leffler error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0; 22338a1b9b6aSSam Leffler break; 22348a1b9b6aSSam Leffler case IEEE80211_IOC_MCASTKEYLEN: 22358a1b9b6aSSam Leffler if (!(0 < ireq->i_val && ireq->i_val < IEEE80211_KEYBUF_SIZE)) 22368a1b9b6aSSam Leffler return EINVAL; 22378a1b9b6aSSam Leffler /* XXX no way to verify driver capability */ 22388a1b9b6aSSam Leffler rsn->rsn_mcastkeylen = ireq->i_val; 22398a1b9b6aSSam Leffler error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0; 22408a1b9b6aSSam Leffler break; 22418a1b9b6aSSam Leffler case IEEE80211_IOC_UCASTCIPHERS: 22428a1b9b6aSSam Leffler /* 22438a1b9b6aSSam Leffler * Convert user-specified cipher set to the set 22448a1b9b6aSSam Leffler * we can support (via hardware or software). 22458a1b9b6aSSam Leffler * NB: this logic intentionally ignores unknown and 22468a1b9b6aSSam Leffler * unsupported ciphers so folks can specify 0xff or 22478a1b9b6aSSam Leffler * similar and get all available ciphers. 22488a1b9b6aSSam Leffler */ 22498a1b9b6aSSam Leffler caps = 0; 22508a1b9b6aSSam Leffler for (j = 1; j < 32; j++) /* NB: skip WEP */ 22518a1b9b6aSSam Leffler if ((ireq->i_val & (1<<j)) && 22528a1b9b6aSSam Leffler ((ic->ic_caps & cipher2cap(j)) || 22538a1b9b6aSSam Leffler ieee80211_crypto_available(j))) 22548a1b9b6aSSam Leffler caps |= 1<<j; 22558a1b9b6aSSam Leffler if (caps == 0) /* nothing available */ 22568a1b9b6aSSam Leffler return EINVAL; 22578a1b9b6aSSam Leffler /* XXX verify ciphers ok for unicast use? */ 22588a1b9b6aSSam Leffler /* XXX disallow if running as it'll have no effect */ 22598a1b9b6aSSam Leffler rsn->rsn_ucastcipherset = caps; 22608a1b9b6aSSam Leffler error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0; 22618a1b9b6aSSam Leffler break; 22628a1b9b6aSSam Leffler case IEEE80211_IOC_UCASTCIPHER: 22638a1b9b6aSSam Leffler if ((rsn->rsn_ucastcipherset & cipher2cap(ireq->i_val)) == 0) 22648a1b9b6aSSam Leffler return EINVAL; 22658a1b9b6aSSam Leffler rsn->rsn_ucastcipher = ireq->i_val; 22668a1b9b6aSSam Leffler break; 22678a1b9b6aSSam Leffler case IEEE80211_IOC_UCASTKEYLEN: 22688a1b9b6aSSam Leffler if (!(0 < ireq->i_val && ireq->i_val < IEEE80211_KEYBUF_SIZE)) 22698a1b9b6aSSam Leffler return EINVAL; 22708a1b9b6aSSam Leffler /* XXX no way to verify driver capability */ 22718a1b9b6aSSam Leffler rsn->rsn_ucastkeylen = ireq->i_val; 22728a1b9b6aSSam Leffler break; 22738a1b9b6aSSam Leffler case IEEE80211_IOC_DRIVER_CAPS: 22748a1b9b6aSSam Leffler /* NB: for testing */ 22758a1b9b6aSSam Leffler ic->ic_caps = (((u_int16_t) ireq->i_val) << 16) | 22768a1b9b6aSSam Leffler ((u_int16_t) ireq->i_len); 22778a1b9b6aSSam Leffler break; 22788a1b9b6aSSam Leffler case IEEE80211_IOC_KEYMGTALGS: 22798a1b9b6aSSam Leffler /* XXX check */ 22808a1b9b6aSSam Leffler rsn->rsn_keymgmtset = ireq->i_val; 22818a1b9b6aSSam Leffler error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0; 22828a1b9b6aSSam Leffler break; 22838a1b9b6aSSam Leffler case IEEE80211_IOC_RSNCAPS: 22848a1b9b6aSSam Leffler /* XXX check */ 22858a1b9b6aSSam Leffler rsn->rsn_caps = ireq->i_val; 22868a1b9b6aSSam Leffler error = (ic->ic_flags & IEEE80211_F_WPA) ? ENETRESET : 0; 22878a1b9b6aSSam Leffler break; 22888a1b9b6aSSam Leffler case IEEE80211_IOC_BSSID: 22898a1b9b6aSSam Leffler /* NB: should only be set when in STA mode */ 22908a1b9b6aSSam Leffler if (ic->ic_opmode != IEEE80211_M_STA) 22918a1b9b6aSSam Leffler return EINVAL; 22928a1b9b6aSSam Leffler if (ireq->i_len != sizeof(tmpbssid)) 22938a1b9b6aSSam Leffler return EINVAL; 22948a1b9b6aSSam Leffler error = copyin(ireq->i_data, tmpbssid, ireq->i_len); 22958a1b9b6aSSam Leffler if (error) 22968a1b9b6aSSam Leffler break; 22978a1b9b6aSSam Leffler IEEE80211_ADDR_COPY(ic->ic_des_bssid, tmpbssid); 22988a1b9b6aSSam Leffler if (IEEE80211_ADDR_EQ(ic->ic_des_bssid, zerobssid)) 22998a1b9b6aSSam Leffler ic->ic_flags &= ~IEEE80211_F_DESBSSID; 23008a1b9b6aSSam Leffler else 23018a1b9b6aSSam Leffler ic->ic_flags |= IEEE80211_F_DESBSSID; 23028a1b9b6aSSam Leffler error = ENETRESET; 23038a1b9b6aSSam Leffler break; 23048a1b9b6aSSam Leffler case IEEE80211_IOC_CHANLIST: 23058a1b9b6aSSam Leffler error = ieee80211_ioctl_setchanlist(ic, ireq); 23068a1b9b6aSSam Leffler break; 23078a1b9b6aSSam Leffler case IEEE80211_IOC_SCAN_REQ: 23088a1b9b6aSSam Leffler if (ic->ic_opmode == IEEE80211_M_HOSTAP) /* XXX ignore */ 23098a1b9b6aSSam Leffler break; 23108a1b9b6aSSam Leffler error = ieee80211_setupscan(ic, ic->ic_chan_avail); 23118a1b9b6aSSam Leffler if (error == 0) /* XXX background scan */ 23128a1b9b6aSSam Leffler error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1); 23138a1b9b6aSSam Leffler break; 23148a1b9b6aSSam Leffler case IEEE80211_IOC_ADDMAC: 23158a1b9b6aSSam Leffler case IEEE80211_IOC_DELMAC: 23168a1b9b6aSSam Leffler error = ieee80211_ioctl_macmac(ic, ireq); 23178a1b9b6aSSam Leffler break; 23188a1b9b6aSSam Leffler case IEEE80211_IOC_MACCMD: 2319188757f5SSam Leffler error = ieee80211_ioctl_setmaccmd(ic, ireq); 23208a1b9b6aSSam Leffler break; 23218a1b9b6aSSam Leffler case IEEE80211_IOC_STA_TXPOW: 23228a1b9b6aSSam Leffler error = ieee80211_ioctl_setstatxpow(ic, ireq); 23238a1b9b6aSSam Leffler break; 23248a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */ 23258a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */ 23268a1b9b6aSSam Leffler case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */ 23278a1b9b6aSSam Leffler case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */ 23288a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */ 23298a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (bss only) */ 23308a1b9b6aSSam Leffler error = ieee80211_ioctl_setwmeparam(ic, ireq); 23318a1b9b6aSSam Leffler break; 23328a1b9b6aSSam Leffler case IEEE80211_IOC_DTIM_PERIOD: 23338a1b9b6aSSam Leffler if (ic->ic_opmode != IEEE80211_M_HOSTAP && 23348a1b9b6aSSam Leffler ic->ic_opmode != IEEE80211_M_IBSS) 23358a1b9b6aSSam Leffler return EINVAL; 23368a1b9b6aSSam Leffler if (IEEE80211_DTIM_MIN <= ireq->i_val && 23378a1b9b6aSSam Leffler ireq->i_val <= IEEE80211_DTIM_MAX) { 23388a1b9b6aSSam Leffler ic->ic_dtim_period = ireq->i_val; 23398a1b9b6aSSam Leffler error = ENETRESET; /* requires restart */ 23408a1b9b6aSSam Leffler } else 23418a1b9b6aSSam Leffler error = EINVAL; 23428a1b9b6aSSam Leffler break; 23438a1b9b6aSSam Leffler case IEEE80211_IOC_BEACON_INTERVAL: 23448a1b9b6aSSam Leffler if (ic->ic_opmode != IEEE80211_M_HOSTAP && 23458a1b9b6aSSam Leffler ic->ic_opmode != IEEE80211_M_IBSS) 23468a1b9b6aSSam Leffler return EINVAL; 23478a1b9b6aSSam Leffler if (IEEE80211_BINTVAL_MIN <= ireq->i_val && 23488a1b9b6aSSam Leffler ireq->i_val <= IEEE80211_BINTVAL_MAX) { 2349d365f9c7SSam Leffler ic->ic_bintval = ireq->i_val; 23508a1b9b6aSSam Leffler error = ENETRESET; /* requires restart */ 23518a1b9b6aSSam Leffler } else 23528a1b9b6aSSam Leffler error = EINVAL; 23538a1b9b6aSSam Leffler break; 2354c4f040c3SSam Leffler case IEEE80211_IOC_PUREG: 2355c4f040c3SSam Leffler if (ireq->i_val) 2356c4f040c3SSam Leffler ic->ic_flags |= IEEE80211_F_PUREG; 2357c4f040c3SSam Leffler else 2358c4f040c3SSam Leffler ic->ic_flags &= ~IEEE80211_F_PUREG; 2359c4f040c3SSam Leffler /* NB: reset only if we're operating on an 11g channel */ 2360c4f040c3SSam Leffler if (ic->ic_curmode == IEEE80211_MODE_11G) 2361c4f040c3SSam Leffler error = ENETRESET; 2362c4f040c3SSam Leffler break; 236370231e3dSSam Leffler case IEEE80211_IOC_FRAGTHRESHOLD: 236470231e3dSSam Leffler if ((ic->ic_caps & IEEE80211_C_TXFRAG) == 0 && 236570231e3dSSam Leffler ireq->i_val != IEEE80211_FRAG_MAX) 236670231e3dSSam Leffler return EINVAL; 236770231e3dSSam Leffler if (!(IEEE80211_FRAG_MIN <= ireq->i_val && 236870231e3dSSam Leffler ireq->i_val <= IEEE80211_FRAG_MAX)) 236970231e3dSSam Leffler return EINVAL; 237070231e3dSSam Leffler ic->ic_fragthreshold = ireq->i_val; 237170231e3dSSam Leffler error = IS_UP(ic) ? ic->ic_reset(ic->ic_ifp) : 0; 237270231e3dSSam Leffler break; 23731a1e1d21SSam Leffler default: 23741a1e1d21SSam Leffler error = EINVAL; 23751a1e1d21SSam Leffler break; 23761a1e1d21SSam Leffler } 23778a1b9b6aSSam Leffler if (error == ENETRESET && !IS_UP_AUTO(ic)) 23788a1b9b6aSSam Leffler error = 0; 23798a1b9b6aSSam Leffler return error; 23808a1b9b6aSSam Leffler } 23818a1b9b6aSSam Leffler 23828a1b9b6aSSam Leffler int 23838a1b9b6aSSam Leffler ieee80211_ioctl(struct ieee80211com *ic, u_long cmd, caddr_t data) 23848a1b9b6aSSam Leffler { 23858a1b9b6aSSam Leffler struct ifnet *ifp = ic->ic_ifp; 23868a1b9b6aSSam Leffler int error = 0; 23878a1b9b6aSSam Leffler struct ifreq *ifr; 23888a1b9b6aSSam Leffler struct ifaddr *ifa; /* XXX */ 23898a1b9b6aSSam Leffler 23908a1b9b6aSSam Leffler switch (cmd) { 23918a1b9b6aSSam Leffler case SIOCSIFMEDIA: 23928a1b9b6aSSam Leffler case SIOCGIFMEDIA: 23938a1b9b6aSSam Leffler error = ifmedia_ioctl(ifp, (struct ifreq *) data, 23948a1b9b6aSSam Leffler &ic->ic_media, cmd); 23958a1b9b6aSSam Leffler break; 23968a1b9b6aSSam Leffler case SIOCG80211: 23978a1b9b6aSSam Leffler error = ieee80211_ioctl_get80211(ic, cmd, 23988a1b9b6aSSam Leffler (struct ieee80211req *) data); 23998a1b9b6aSSam Leffler break; 24008a1b9b6aSSam Leffler case SIOCS80211: 24018a1b9b6aSSam Leffler error = suser(curthread); 24028a1b9b6aSSam Leffler if (error == 0) 24038a1b9b6aSSam Leffler error = ieee80211_ioctl_set80211(ic, cmd, 24048a1b9b6aSSam Leffler (struct ieee80211req *) data); 24051a1e1d21SSam Leffler break; 24061a1e1d21SSam Leffler case SIOCGIFGENERIC: 24078a1b9b6aSSam Leffler error = ieee80211_cfgget(ic, cmd, data); 24081a1e1d21SSam Leffler break; 24091a1e1d21SSam Leffler case SIOCSIFGENERIC: 24101a1e1d21SSam Leffler error = suser(curthread); 24111a1e1d21SSam Leffler if (error) 24121a1e1d21SSam Leffler break; 24138a1b9b6aSSam Leffler error = ieee80211_cfgset(ic, cmd, data); 24141a1e1d21SSam Leffler break; 24151be50176SSam Leffler case SIOCG80211STATS: 24161be50176SSam Leffler ifr = (struct ifreq *)data; 24171be50176SSam Leffler copyout(&ic->ic_stats, ifr->ifr_data, sizeof (ic->ic_stats)); 24181be50176SSam Leffler break; 24196f161f03SSam Leffler case SIOCSIFMTU: 24206f161f03SSam Leffler ifr = (struct ifreq *)data; 24216f161f03SSam Leffler if (!(IEEE80211_MTU_MIN <= ifr->ifr_mtu && 24226f161f03SSam Leffler ifr->ifr_mtu <= IEEE80211_MTU_MAX)) 24236f161f03SSam Leffler error = EINVAL; 24246f161f03SSam Leffler else 24256f161f03SSam Leffler ifp->if_mtu = ifr->ifr_mtu; 24266f161f03SSam Leffler break; 2427b2e95691SSam Leffler case SIOCSIFADDR: 2428b2e95691SSam Leffler /* 2429b2e95691SSam Leffler * XXX Handle this directly so we can supress if_init calls. 2430b2e95691SSam Leffler * XXX This should be done in ether_ioctl but for the moment 2431b2e95691SSam Leffler * XXX there are too many other parts of the system that 2432b2e95691SSam Leffler * XXX set IFF_UP and so supress if_init being called when 2433b2e95691SSam Leffler * XXX it should be. 2434b2e95691SSam Leffler */ 2435b2e95691SSam Leffler ifa = (struct ifaddr *) data; 2436b2e95691SSam Leffler switch (ifa->ifa_addr->sa_family) { 2437b2e95691SSam Leffler #ifdef INET 2438b2e95691SSam Leffler case AF_INET: 2439b2e95691SSam Leffler if ((ifp->if_flags & IFF_UP) == 0) { 2440b2e95691SSam Leffler ifp->if_flags |= IFF_UP; 2441b2e95691SSam Leffler ifp->if_init(ifp->if_softc); 2442b2e95691SSam Leffler } 2443b2e95691SSam Leffler arp_ifinit(ifp, ifa); 2444b2e95691SSam Leffler break; 2445b2e95691SSam Leffler #endif 2446b2e95691SSam Leffler #ifdef IPX 2447b2e95691SSam Leffler /* 2448b2e95691SSam Leffler * XXX - This code is probably wrong, 2449b2e95691SSam Leffler * but has been copied many times. 2450b2e95691SSam Leffler */ 2451b2e95691SSam Leffler case AF_IPX: { 2452b2e95691SSam Leffler struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr); 2453b2e95691SSam Leffler 2454b2e95691SSam Leffler if (ipx_nullhost(*ina)) 2455fc74a9f9SBrooks Davis ina->x_host = *(union ipx_host *) 2456fc74a9f9SBrooks Davis IFP2ENADDR(ifp); 2457b2e95691SSam Leffler else 2458b2e95691SSam Leffler bcopy((caddr_t) ina->x_host.c_host, 2459fc74a9f9SBrooks Davis (caddr_t) IFP2ENADDR(ifp), 2460fc74a9f9SBrooks Davis ETHER_ADDR_LEN); 2461b2e95691SSam Leffler /* fall thru... */ 2462b2e95691SSam Leffler } 2463b2e95691SSam Leffler #endif 2464b2e95691SSam Leffler default: 2465b2e95691SSam Leffler if ((ifp->if_flags & IFF_UP) == 0) { 2466b2e95691SSam Leffler ifp->if_flags |= IFF_UP; 2467b2e95691SSam Leffler ifp->if_init(ifp->if_softc); 2468b2e95691SSam Leffler } 2469b2e95691SSam Leffler break; 2470b2e95691SSam Leffler } 2471b2e95691SSam Leffler break; 24721a1e1d21SSam Leffler default: 24731a1e1d21SSam Leffler error = ether_ioctl(ifp, cmd, data); 24741a1e1d21SSam Leffler break; 24751a1e1d21SSam Leffler } 24761a1e1d21SSam Leffler return error; 24771a1e1d21SSam Leffler } 2478