11a1e1d21SSam Leffler /*-
24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3fe267a55SPedro F. Giffuni *
47535e66aSSam Leffler * Copyright (c) 2001 Atsushi Onoe
510ad9a77SSam Leffler * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
61a1e1d21SSam Leffler * All rights reserved.
71a1e1d21SSam Leffler *
81a1e1d21SSam Leffler * Redistribution and use in source and binary forms, with or without
91a1e1d21SSam Leffler * modification, are permitted provided that the following conditions
101a1e1d21SSam Leffler * are met:
111a1e1d21SSam Leffler * 1. Redistributions of source code must retain the above copyright
127535e66aSSam Leffler * notice, this list of conditions and the following disclaimer.
137535e66aSSam Leffler * 2. Redistributions in binary form must reproduce the above copyright
147535e66aSSam Leffler * notice, this list of conditions and the following disclaimer in the
157535e66aSSam Leffler * documentation and/or other materials provided with the distribution.
161a1e1d21SSam Leffler *
177535e66aSSam Leffler * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
187535e66aSSam Leffler * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
197535e66aSSam Leffler * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
207535e66aSSam Leffler * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
217535e66aSSam Leffler * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
227535e66aSSam Leffler * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
237535e66aSSam Leffler * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
247535e66aSSam Leffler * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257535e66aSSam Leffler * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
267535e66aSSam Leffler * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271a1e1d21SSam Leffler */
281a1e1d21SSam Leffler
291a1e1d21SSam Leffler #include <sys/cdefs.h>
301a1e1d21SSam Leffler /*
311a1e1d21SSam Leffler * IEEE 802.11 ioctl support (FreeBSD-specific)
321a1e1d21SSam Leffler */
331a1e1d21SSam Leffler
34b2e95691SSam Leffler #include "opt_inet.h"
35b032f27cSSam Leffler #include "opt_wlan.h"
36b2e95691SSam Leffler
371a1e1d21SSam Leffler #include <sys/endian.h>
381a1e1d21SSam Leffler #include <sys/param.h>
391a1e1d21SSam Leffler #include <sys/kernel.h>
408ec07310SGleb Smirnoff #include <sys/malloc.h>
411a1e1d21SSam Leffler #include <sys/socket.h>
421a1e1d21SSam Leffler #include <sys/sockio.h>
431a1e1d21SSam Leffler #include <sys/systm.h>
441a1e1d21SSam Leffler
451a1e1d21SSam Leffler #include <net/if.h>
4676039bc8SGleb Smirnoff #include <net/if_var.h>
474a0d6638SRuslan Ermilov #include <net/if_dl.h>
481a1e1d21SSam Leffler #include <net/if_media.h>
493d0d5b21SJustin Hibbits #include <net/if_private.h>
501a1e1d21SSam Leffler #include <net/ethernet.h>
511a1e1d21SSam Leffler
52b2e95691SSam Leffler #ifdef INET
53b2e95691SSam Leffler #include <netinet/in.h>
54b2e95691SSam Leffler #include <netinet/if_ether.h>
55b2e95691SSam Leffler #endif
56b2e95691SSam Leffler
571a1e1d21SSam Leffler #include <net80211/ieee80211_var.h>
581a1e1d21SSam Leffler #include <net80211/ieee80211_ioctl.h>
59b032f27cSSam Leffler #include <net80211/ieee80211_regdomain.h>
60b032f27cSSam Leffler #include <net80211/ieee80211_input.h>
611a1e1d21SSam Leffler
62b032f27cSSam Leffler #define IS_UP_AUTO(_vap) \
633cdd9880SSam Leffler (IFNET_IS_UP_RUNNING((_vap)->iv_ifp) && \
64b032f27cSSam Leffler (_vap)->iv_roaming == IEEE80211_ROAMING_AUTO)
658a1b9b6aSSam Leffler
66b032f27cSSam Leffler static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
6768e8e04eSSam Leffler static struct ieee80211_channel *findchannel(struct ieee80211com *,
6868e8e04eSSam Leffler int ieee, int mode);
69632ee7e3SBernhard Schmidt static int ieee80211_scanreq(struct ieee80211vap *,
70632ee7e3SBernhard Schmidt struct ieee80211_scan_req *);
711a1e1d21SSam Leffler
7274bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getkey(u_long cmd,struct ieee80211vap * vap,struct ieee80211req * ireq)7301e57940SBjoern A. Zeeb ieee80211_ioctl_getkey(u_long cmd, struct ieee80211vap *vap,
7401e57940SBjoern A. Zeeb struct ieee80211req *ireq)
758a1b9b6aSSam Leffler {
76b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
778a1b9b6aSSam Leffler struct ieee80211_node *ni;
788a1b9b6aSSam Leffler struct ieee80211req_key ik;
798a1b9b6aSSam Leffler struct ieee80211_key *wk;
808a1b9b6aSSam Leffler const struct ieee80211_cipher *cip;
818a1b9b6aSSam Leffler u_int kid;
828a1b9b6aSSam Leffler int error;
838a1b9b6aSSam Leffler
848a1b9b6aSSam Leffler if (ireq->i_len != sizeof(ik))
858a1b9b6aSSam Leffler return EINVAL;
868a1b9b6aSSam Leffler error = copyin(ireq->i_data, &ik, sizeof(ik));
878a1b9b6aSSam Leffler if (error)
888a1b9b6aSSam Leffler return error;
898a1b9b6aSSam Leffler kid = ik.ik_keyix;
908a1b9b6aSSam Leffler if (kid == IEEE80211_KEYIX_NONE) {
91b032f27cSSam Leffler ni = ieee80211_find_vap_node(&ic->ic_sta, vap, ik.ik_macaddr);
928a1b9b6aSSam Leffler if (ni == NULL)
93b032f27cSSam Leffler return ENOENT;
948a1b9b6aSSam Leffler wk = &ni->ni_ucastkey;
958a1b9b6aSSam Leffler } else {
968a1b9b6aSSam Leffler if (kid >= IEEE80211_WEP_NKID)
978a1b9b6aSSam Leffler return EINVAL;
98b032f27cSSam Leffler wk = &vap->iv_nw_keys[kid];
99b032f27cSSam Leffler IEEE80211_ADDR_COPY(&ik.ik_macaddr, vap->iv_bss->ni_macaddr);
1008a1b9b6aSSam Leffler ni = NULL;
1018a1b9b6aSSam Leffler }
1028a1b9b6aSSam Leffler cip = wk->wk_cipher;
1038a1b9b6aSSam Leffler ik.ik_type = cip->ic_cipher;
1048a1b9b6aSSam Leffler ik.ik_keylen = wk->wk_keylen;
1058a1b9b6aSSam Leffler ik.ik_flags = wk->wk_flags & (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV);
106b032f27cSSam Leffler if (wk->wk_keyix == vap->iv_def_txkey)
1078a1b9b6aSSam Leffler ik.ik_flags |= IEEE80211_KEY_DEFAULT;
10801e57940SBjoern A. Zeeb if (ieee80211_priv_check_vap_getkey(cmd, vap, NULL) == 0) {
1098a1b9b6aSSam Leffler /* NB: only root can read key data */
110b032f27cSSam Leffler ik.ik_keyrsc = wk->wk_keyrsc[IEEE80211_NONQOS_TID];
1118a1b9b6aSSam Leffler ik.ik_keytsc = wk->wk_keytsc;
1128a1b9b6aSSam Leffler memcpy(ik.ik_keydata, wk->wk_key, wk->wk_keylen);
1138a1b9b6aSSam Leffler if (cip->ic_cipher == IEEE80211_CIPHER_TKIP) {
1148a1b9b6aSSam Leffler memcpy(ik.ik_keydata+wk->wk_keylen,
1158a1b9b6aSSam Leffler wk->wk_key + IEEE80211_KEYBUF_SIZE,
1168a1b9b6aSSam Leffler IEEE80211_MICBUF_SIZE);
1178a1b9b6aSSam Leffler ik.ik_keylen += IEEE80211_MICBUF_SIZE;
1188a1b9b6aSSam Leffler }
1198a1b9b6aSSam Leffler } else {
1208a1b9b6aSSam Leffler ik.ik_keyrsc = 0;
1218a1b9b6aSSam Leffler ik.ik_keytsc = 0;
1228a1b9b6aSSam Leffler memset(ik.ik_keydata, 0, sizeof(ik.ik_keydata));
1238a1b9b6aSSam Leffler }
1248a1b9b6aSSam Leffler if (ni != NULL)
1258a1b9b6aSSam Leffler ieee80211_free_node(ni);
1268a1b9b6aSSam Leffler return copyout(&ik, ireq->i_data, sizeof(ik));
1278a1b9b6aSSam Leffler }
1288a1b9b6aSSam Leffler
12974bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getchanlist(struct ieee80211vap * vap,struct ieee80211req * ireq)130b032f27cSSam Leffler ieee80211_ioctl_getchanlist(struct ieee80211vap *vap, struct ieee80211req *ireq)
1318a1b9b6aSSam Leffler {
132b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
1338a1b9b6aSSam Leffler
134e55e5e42SSam Leffler if (sizeof(ic->ic_chan_active) < ireq->i_len)
1358a1b9b6aSSam Leffler ireq->i_len = sizeof(ic->ic_chan_active);
1368a1b9b6aSSam Leffler return copyout(&ic->ic_chan_active, ireq->i_data, ireq->i_len);
1378a1b9b6aSSam Leffler }
1388a1b9b6aSSam Leffler
13974bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getchaninfo(struct ieee80211vap * vap,struct ieee80211req * ireq)140b032f27cSSam Leffler ieee80211_ioctl_getchaninfo(struct ieee80211vap *vap, struct ieee80211req *ireq)
1418a1b9b6aSSam Leffler {
142b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
143db9ff08bSKevin Lo uint32_t space;
1448a1b9b6aSSam Leffler
1458a1b9b6aSSam Leffler space = __offsetof(struct ieee80211req_chaninfo,
14668e8e04eSSam Leffler ic_chans[ic->ic_nchans]);
1478a1b9b6aSSam Leffler if (space > ireq->i_len)
1488a1b9b6aSSam Leffler space = ireq->i_len;
14968e8e04eSSam Leffler /* XXX assumes compatible layout */
15068e8e04eSSam Leffler return copyout(&ic->ic_nchans, ireq->i_data, space);
1518a1b9b6aSSam Leffler }
1528a1b9b6aSSam Leffler
15374bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getwpaie(struct ieee80211vap * vap,struct ieee80211req * ireq,int req)154b032f27cSSam Leffler ieee80211_ioctl_getwpaie(struct ieee80211vap *vap,
155b032f27cSSam Leffler struct ieee80211req *ireq, int req)
1568a1b9b6aSSam Leffler {
1578a1b9b6aSSam Leffler struct ieee80211_node *ni;
15874bdb731SAndriy Voskoboinyk struct ieee80211req_wpaie2 *wpaie;
1598a1b9b6aSSam Leffler int error;
1608a1b9b6aSSam Leffler
1618a1b9b6aSSam Leffler if (ireq->i_len < IEEE80211_ADDR_LEN)
1628a1b9b6aSSam Leffler return EINVAL;
16374bdb731SAndriy Voskoboinyk wpaie = IEEE80211_MALLOC(sizeof(*wpaie), M_TEMP,
16474bdb731SAndriy Voskoboinyk IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
16574bdb731SAndriy Voskoboinyk if (wpaie == NULL)
16674bdb731SAndriy Voskoboinyk return ENOMEM;
16774bdb731SAndriy Voskoboinyk error = copyin(ireq->i_data, wpaie->wpa_macaddr, IEEE80211_ADDR_LEN);
1688a1b9b6aSSam Leffler if (error != 0)
16974bdb731SAndriy Voskoboinyk goto bad;
17074bdb731SAndriy Voskoboinyk ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, wpaie->wpa_macaddr);
17174bdb731SAndriy Voskoboinyk if (ni == NULL) {
17274bdb731SAndriy Voskoboinyk error = ENOENT;
17374bdb731SAndriy Voskoboinyk goto bad;
17474bdb731SAndriy Voskoboinyk }
175b032f27cSSam Leffler if (ni->ni_ies.wpa_ie != NULL) {
176b032f27cSSam Leffler int ielen = ni->ni_ies.wpa_ie[1] + 2;
17774bdb731SAndriy Voskoboinyk if (ielen > sizeof(wpaie->wpa_ie))
17874bdb731SAndriy Voskoboinyk ielen = sizeof(wpaie->wpa_ie);
17974bdb731SAndriy Voskoboinyk memcpy(wpaie->wpa_ie, ni->ni_ies.wpa_ie, ielen);
1808a1b9b6aSSam Leffler }
18168e8e04eSSam Leffler if (req == IEEE80211_IOC_WPAIE2) {
182b032f27cSSam Leffler if (ni->ni_ies.rsn_ie != NULL) {
183b032f27cSSam Leffler int ielen = ni->ni_ies.rsn_ie[1] + 2;
18474bdb731SAndriy Voskoboinyk if (ielen > sizeof(wpaie->rsn_ie))
18574bdb731SAndriy Voskoboinyk ielen = sizeof(wpaie->rsn_ie);
18674bdb731SAndriy Voskoboinyk memcpy(wpaie->rsn_ie, ni->ni_ies.rsn_ie, ielen);
18768e8e04eSSam Leffler }
18868e8e04eSSam Leffler if (ireq->i_len > sizeof(struct ieee80211req_wpaie2))
18968e8e04eSSam Leffler ireq->i_len = sizeof(struct ieee80211req_wpaie2);
19068e8e04eSSam Leffler } else {
19168e8e04eSSam Leffler /* compatibility op, may overwrite wpa ie */
19268e8e04eSSam Leffler /* XXX check ic_flags? */
193b032f27cSSam Leffler if (ni->ni_ies.rsn_ie != NULL) {
194b032f27cSSam Leffler int ielen = ni->ni_ies.rsn_ie[1] + 2;
19574bdb731SAndriy Voskoboinyk if (ielen > sizeof(wpaie->wpa_ie))
19674bdb731SAndriy Voskoboinyk ielen = sizeof(wpaie->wpa_ie);
19774bdb731SAndriy Voskoboinyk memcpy(wpaie->wpa_ie, ni->ni_ies.rsn_ie, ielen);
19868e8e04eSSam Leffler }
19968e8e04eSSam Leffler if (ireq->i_len > sizeof(struct ieee80211req_wpaie))
20068e8e04eSSam Leffler ireq->i_len = sizeof(struct ieee80211req_wpaie);
20168e8e04eSSam Leffler }
2028a1b9b6aSSam Leffler ieee80211_free_node(ni);
20374bdb731SAndriy Voskoboinyk error = copyout(wpaie, ireq->i_data, ireq->i_len);
20474bdb731SAndriy Voskoboinyk bad:
20574bdb731SAndriy Voskoboinyk IEEE80211_FREE(wpaie, M_TEMP);
20674bdb731SAndriy Voskoboinyk return error;
2078a1b9b6aSSam Leffler }
2088a1b9b6aSSam Leffler
20974bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getstastats(struct ieee80211vap * vap,struct ieee80211req * ireq)210b032f27cSSam Leffler ieee80211_ioctl_getstastats(struct ieee80211vap *vap, struct ieee80211req *ireq)
2118a1b9b6aSSam Leffler {
2128a1b9b6aSSam Leffler struct ieee80211_node *ni;
21368e8e04eSSam Leffler uint8_t macaddr[IEEE80211_ADDR_LEN];
214db9ff08bSKevin Lo const size_t off = __offsetof(struct ieee80211req_sta_stats, is_stats);
2158a1b9b6aSSam Leffler int error;
2168a1b9b6aSSam Leffler
2178a1b9b6aSSam Leffler if (ireq->i_len < off)
2188a1b9b6aSSam Leffler return EINVAL;
2198a1b9b6aSSam Leffler error = copyin(ireq->i_data, macaddr, IEEE80211_ADDR_LEN);
2208a1b9b6aSSam Leffler if (error != 0)
2218a1b9b6aSSam Leffler return error;
222b032f27cSSam Leffler ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, macaddr);
22368e8e04eSSam Leffler if (ni == NULL)
224b032f27cSSam Leffler return ENOENT;
2258a1b9b6aSSam Leffler if (ireq->i_len > sizeof(struct ieee80211req_sta_stats))
2268a1b9b6aSSam Leffler ireq->i_len = sizeof(struct ieee80211req_sta_stats);
2278a1b9b6aSSam Leffler /* NB: copy out only the statistics */
22868e8e04eSSam Leffler error = copyout(&ni->ni_stats, (uint8_t *) ireq->i_data + off,
2298a1b9b6aSSam Leffler ireq->i_len - off);
2308a1b9b6aSSam Leffler ieee80211_free_node(ni);
2318a1b9b6aSSam Leffler return error;
2328a1b9b6aSSam Leffler }
2338a1b9b6aSSam Leffler
23468e8e04eSSam Leffler struct scanreq {
23568e8e04eSSam Leffler struct ieee80211req_scan_result *sr;
23668e8e04eSSam Leffler size_t space;
23768e8e04eSSam Leffler };
23868e8e04eSSam Leffler
23968e8e04eSSam Leffler static size_t
scan_space(const struct ieee80211_scan_entry * se,int * ielen)24068e8e04eSSam Leffler scan_space(const struct ieee80211_scan_entry *se, int *ielen)
24168e8e04eSSam Leffler {
24268e8e04eSSam Leffler size_t len;
24368e8e04eSSam Leffler
244b032f27cSSam Leffler *ielen = se->se_ies.len;
24568e8e04eSSam Leffler /*
24668e8e04eSSam Leffler * NB: ie's can be no more than 255 bytes and the max 802.11
24768e8e04eSSam Leffler * packet is <3Kbytes so we are sure this doesn't overflow
24868e8e04eSSam Leffler * 16-bits; if this is a concern we can drop the ie's.
24968e8e04eSSam Leffler */
25059aa14a9SRui Paulo len = sizeof(struct ieee80211req_scan_result) + se->se_ssid[1] +
25159aa14a9SRui Paulo se->se_meshid[1] + *ielen;
25268e8e04eSSam Leffler return roundup(len, sizeof(uint32_t));
25368e8e04eSSam Leffler }
25468e8e04eSSam Leffler
25568e8e04eSSam Leffler static void
get_scan_space(void * arg,const struct ieee80211_scan_entry * se)25668e8e04eSSam Leffler get_scan_space(void *arg, const struct ieee80211_scan_entry *se)
25768e8e04eSSam Leffler {
25868e8e04eSSam Leffler struct scanreq *req = arg;
25968e8e04eSSam Leffler int ielen;
26068e8e04eSSam Leffler
26168e8e04eSSam Leffler req->space += scan_space(se, &ielen);
26268e8e04eSSam Leffler }
26368e8e04eSSam Leffler
26474bdb731SAndriy Voskoboinyk static void
get_scan_result(void * arg,const struct ieee80211_scan_entry * se)26568e8e04eSSam Leffler get_scan_result(void *arg, const struct ieee80211_scan_entry *se)
26668e8e04eSSam Leffler {
26768e8e04eSSam Leffler struct scanreq *req = arg;
26868e8e04eSSam Leffler struct ieee80211req_scan_result *sr;
26968e8e04eSSam Leffler int ielen, len, nr, nxr;
27068e8e04eSSam Leffler uint8_t *cp;
27168e8e04eSSam Leffler
27268e8e04eSSam Leffler len = scan_space(se, &ielen);
27368e8e04eSSam Leffler if (len > req->space)
27468e8e04eSSam Leffler return;
27568e8e04eSSam Leffler
27668e8e04eSSam Leffler sr = req->sr;
27768e8e04eSSam Leffler KASSERT(len <= 65535 && ielen <= 65535,
27868e8e04eSSam Leffler ("len %u ssid %u ie %u", len, se->se_ssid[1], ielen));
279b032f27cSSam Leffler sr->isr_len = len;
28068e8e04eSSam Leffler sr->isr_ie_off = sizeof(struct ieee80211req_scan_result);
28168e8e04eSSam Leffler sr->isr_ie_len = ielen;
28268e8e04eSSam Leffler sr->isr_freq = se->se_chan->ic_freq;
28368e8e04eSSam Leffler sr->isr_flags = se->se_chan->ic_flags;
28468e8e04eSSam Leffler sr->isr_rssi = se->se_rssi;
28568e8e04eSSam Leffler sr->isr_noise = se->se_noise;
28668e8e04eSSam Leffler sr->isr_intval = se->se_intval;
28768e8e04eSSam Leffler sr->isr_capinfo = se->se_capinfo;
28868e8e04eSSam Leffler sr->isr_erp = se->se_erp;
28968e8e04eSSam Leffler IEEE80211_ADDR_COPY(sr->isr_bssid, se->se_bssid);
29068e8e04eSSam Leffler nr = min(se->se_rates[1], IEEE80211_RATE_MAXSIZE);
29168e8e04eSSam Leffler memcpy(sr->isr_rates, se->se_rates+2, nr);
29268e8e04eSSam Leffler nxr = min(se->se_xrates[1], IEEE80211_RATE_MAXSIZE - nr);
29368e8e04eSSam Leffler memcpy(sr->isr_rates+nr, se->se_xrates+2, nxr);
29468e8e04eSSam Leffler sr->isr_nrates = nr + nxr;
29568e8e04eSSam Leffler
29659aa14a9SRui Paulo /* copy SSID */
29768e8e04eSSam Leffler sr->isr_ssid_len = se->se_ssid[1];
29868e8e04eSSam Leffler cp = ((uint8_t *)sr) + sr->isr_ie_off;
29968e8e04eSSam Leffler memcpy(cp, se->se_ssid+2, sr->isr_ssid_len);
30068e8e04eSSam Leffler
30159aa14a9SRui Paulo /* copy mesh id */
30268e8e04eSSam Leffler cp += sr->isr_ssid_len;
30359aa14a9SRui Paulo sr->isr_meshid_len = se->se_meshid[1];
30459aa14a9SRui Paulo memcpy(cp, se->se_meshid+2, sr->isr_meshid_len);
30559aa14a9SRui Paulo cp += sr->isr_meshid_len;
30659aa14a9SRui Paulo
30759aa14a9SRui Paulo if (ielen)
308b032f27cSSam Leffler memcpy(cp, se->se_ies.data, ielen);
30968e8e04eSSam Leffler
31068e8e04eSSam Leffler req->space -= len;
31168e8e04eSSam Leffler req->sr = (struct ieee80211req_scan_result *)(((uint8_t *)sr) + len);
31268e8e04eSSam Leffler }
31368e8e04eSSam Leffler
31474bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getscanresults(struct ieee80211vap * vap,struct ieee80211req * ireq)315b032f27cSSam Leffler ieee80211_ioctl_getscanresults(struct ieee80211vap *vap,
316b032f27cSSam Leffler struct ieee80211req *ireq)
31768e8e04eSSam Leffler {
31868e8e04eSSam Leffler struct scanreq req;
31968e8e04eSSam Leffler int error;
32068e8e04eSSam Leffler
321b032f27cSSam Leffler if (ireq->i_len < sizeof(struct scanreq))
32268e8e04eSSam Leffler return EFAULT;
32368e8e04eSSam Leffler
32468e8e04eSSam Leffler error = 0;
32568e8e04eSSam Leffler req.space = 0;
326b032f27cSSam Leffler ieee80211_scan_iterate(vap, get_scan_space, &req);
32768e8e04eSSam Leffler if (req.space > ireq->i_len)
32868e8e04eSSam Leffler req.space = ireq->i_len;
32968e8e04eSSam Leffler if (req.space > 0) {
330db9ff08bSKevin Lo uint32_t space;
33168e8e04eSSam Leffler void *p;
33268e8e04eSSam Leffler
33368e8e04eSSam Leffler space = req.space;
334bd29f817SBjoern A. Zeeb /* XXX IEEE80211_M_WAITOK after driver lock released */
335b9b53389SAdrian Chadd p = IEEE80211_MALLOC(space, M_TEMP,
336b9b53389SAdrian Chadd IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
33768e8e04eSSam Leffler if (p == NULL)
33868e8e04eSSam Leffler return ENOMEM;
33968e8e04eSSam Leffler req.sr = p;
340b032f27cSSam Leffler ieee80211_scan_iterate(vap, get_scan_result, &req);
341239cc3b6SSam Leffler ireq->i_len = space - req.space;
342239cc3b6SSam Leffler error = copyout(p, ireq->i_data, ireq->i_len);
343b9b53389SAdrian Chadd IEEE80211_FREE(p, M_TEMP);
344239cc3b6SSam Leffler } else
345239cc3b6SSam Leffler ireq->i_len = 0;
346239cc3b6SSam Leffler
347239cc3b6SSam Leffler return error;
348239cc3b6SSam Leffler }
3498a1b9b6aSSam Leffler
3502cab1d3dSSam Leffler struct stainforeq {
3512cab1d3dSSam Leffler struct ieee80211req_sta_info *si;
3522cab1d3dSSam Leffler size_t space;
3532cab1d3dSSam Leffler };
3548a1b9b6aSSam Leffler
3552cab1d3dSSam Leffler static size_t
sta_space(const struct ieee80211_node * ni,size_t * ielen)3562cab1d3dSSam Leffler sta_space(const struct ieee80211_node *ni, size_t *ielen)
3572cab1d3dSSam Leffler {
358b032f27cSSam Leffler *ielen = ni->ni_ies.len;
3592cab1d3dSSam Leffler return roundup(sizeof(struct ieee80211req_sta_info) + *ielen,
36068e8e04eSSam Leffler sizeof(uint32_t));
3612cab1d3dSSam Leffler }
3622cab1d3dSSam Leffler
3632cab1d3dSSam Leffler static void
get_sta_space(void * arg,struct ieee80211_node * ni)3642cab1d3dSSam Leffler get_sta_space(void *arg, struct ieee80211_node *ni)
3652cab1d3dSSam Leffler {
3662cab1d3dSSam Leffler struct stainforeq *req = arg;
3672cab1d3dSSam Leffler size_t ielen;
3682cab1d3dSSam Leffler
369b032f27cSSam Leffler if (ni->ni_vap->iv_opmode == IEEE80211_M_HOSTAP &&
3702cab1d3dSSam Leffler ni->ni_associd == 0) /* only associated stations */
3712cab1d3dSSam Leffler return;
3722cab1d3dSSam Leffler req->space += sta_space(ni, &ielen);
3732cab1d3dSSam Leffler }
3742cab1d3dSSam Leffler
37574bdb731SAndriy Voskoboinyk static void
get_sta_info(void * arg,struct ieee80211_node * ni)3762cab1d3dSSam Leffler get_sta_info(void *arg, struct ieee80211_node *ni)
3772cab1d3dSSam Leffler {
3782cab1d3dSSam Leffler struct stainforeq *req = arg;
379b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap;
3802cab1d3dSSam Leffler struct ieee80211req_sta_info *si;
3812cab1d3dSSam Leffler size_t ielen, len;
38268e8e04eSSam Leffler uint8_t *cp;
3832cab1d3dSSam Leffler
384b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_HOSTAP &&
3852cab1d3dSSam Leffler ni->ni_associd == 0) /* only associated stations */
3862cab1d3dSSam Leffler return;
3872cab1d3dSSam Leffler if (ni->ni_chan == IEEE80211_CHAN_ANYC) /* XXX bogus entry */
3882cab1d3dSSam Leffler return;
3892cab1d3dSSam Leffler len = sta_space(ni, &ielen);
3902cab1d3dSSam Leffler if (len > req->space)
3912cab1d3dSSam Leffler return;
3922cab1d3dSSam Leffler si = req->si;
3932cab1d3dSSam Leffler si->isi_len = len;
39468e8e04eSSam Leffler si->isi_ie_off = sizeof(struct ieee80211req_sta_info);
3952cab1d3dSSam Leffler si->isi_ie_len = ielen;
3968a1b9b6aSSam Leffler si->isi_freq = ni->ni_chan->ic_freq;
3978a1b9b6aSSam Leffler si->isi_flags = ni->ni_chan->ic_flags;
3988a1b9b6aSSam Leffler si->isi_state = ni->ni_flags;
3998a1b9b6aSSam Leffler si->isi_authmode = ni->ni_authmode;
400b032f27cSSam Leffler vap->iv_ic->ic_node_getsignal(ni, &si->isi_rssi, &si->isi_noise);
401b032f27cSSam Leffler vap->iv_ic->ic_node_getmimoinfo(ni, &si->isi_mimo);
4028a1b9b6aSSam Leffler si->isi_capinfo = ni->ni_capinfo;
4038a1b9b6aSSam Leffler si->isi_erp = ni->ni_erp;
4048a1b9b6aSSam Leffler IEEE80211_ADDR_COPY(si->isi_macaddr, ni->ni_macaddr);
4058a1b9b6aSSam Leffler si->isi_nrates = ni->ni_rates.rs_nrates;
4068a1b9b6aSSam Leffler if (si->isi_nrates > 15)
4078a1b9b6aSSam Leffler si->isi_nrates = 15;
4088a1b9b6aSSam Leffler memcpy(si->isi_rates, ni->ni_rates.rs_rates, si->isi_nrates);
4098a1b9b6aSSam Leffler si->isi_txrate = ni->ni_txrate;
410b032f27cSSam Leffler if (si->isi_txrate & IEEE80211_RATE_MCS) {
411b032f27cSSam Leffler const struct ieee80211_mcs_rates *mcs =
412b032f27cSSam Leffler &ieee80211_htrates[ni->ni_txrate &~ IEEE80211_RATE_MCS];
413b032f27cSSam Leffler if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) {
4146ac5ee4aSSam Leffler if (ni->ni_flags & IEEE80211_NODE_SGI40)
415b032f27cSSam Leffler si->isi_txmbps = mcs->ht40_rate_800ns;
416b032f27cSSam Leffler else
417b032f27cSSam Leffler si->isi_txmbps = mcs->ht40_rate_400ns;
418b032f27cSSam Leffler } else {
4196ac5ee4aSSam Leffler if (ni->ni_flags & IEEE80211_NODE_SGI20)
420b032f27cSSam Leffler si->isi_txmbps = mcs->ht20_rate_800ns;
421b032f27cSSam Leffler else
422b032f27cSSam Leffler si->isi_txmbps = mcs->ht20_rate_400ns;
423b032f27cSSam Leffler }
424b032f27cSSam Leffler } else
425b032f27cSSam Leffler si->isi_txmbps = si->isi_txrate;
4268a1b9b6aSSam Leffler si->isi_associd = ni->ni_associd;
4278a1b9b6aSSam Leffler si->isi_txpower = ni->ni_txpower;
4288a1b9b6aSSam Leffler si->isi_vlan = ni->ni_vlan;
4298a1b9b6aSSam Leffler if (ni->ni_flags & IEEE80211_NODE_QOS) {
4308a1b9b6aSSam Leffler memcpy(si->isi_txseqs, ni->ni_txseqs, sizeof(ni->ni_txseqs));
4318a1b9b6aSSam Leffler memcpy(si->isi_rxseqs, ni->ni_rxseqs, sizeof(ni->ni_rxseqs));
4328a1b9b6aSSam Leffler } else {
433801df4a5SSam Leffler si->isi_txseqs[0] = ni->ni_txseqs[IEEE80211_NONQOS_TID];
434801df4a5SSam Leffler si->isi_rxseqs[0] = ni->ni_rxseqs[IEEE80211_NONQOS_TID];
4358a1b9b6aSSam Leffler }
4362cab1d3dSSam Leffler /* NB: leave all cases in case we relax ni_associd == 0 check */
4372cab1d3dSSam Leffler if (ieee80211_node_is_authorized(ni))
438b032f27cSSam Leffler si->isi_inact = vap->iv_inact_run;
439b032f27cSSam Leffler else if (ni->ni_associd != 0 ||
440b032f27cSSam Leffler (vap->iv_opmode == IEEE80211_M_WDS &&
441b032f27cSSam Leffler (vap->iv_flags_ext & IEEE80211_FEXT_WDSLEGACY)))
442b032f27cSSam Leffler si->isi_inact = vap->iv_inact_auth;
4438a1b9b6aSSam Leffler else
444b032f27cSSam Leffler si->isi_inact = vap->iv_inact_init;
4458a1b9b6aSSam Leffler si->isi_inact = (si->isi_inact - ni->ni_inact) * IEEE80211_INACT_WAIT;
44659aa14a9SRui Paulo si->isi_localid = ni->ni_mllid;
44759aa14a9SRui Paulo si->isi_peerid = ni->ni_mlpid;
44859aa14a9SRui Paulo si->isi_peerstate = ni->ni_mlstate;
4498a1b9b6aSSam Leffler
45068e8e04eSSam Leffler if (ielen) {
45168e8e04eSSam Leffler cp = ((uint8_t *)si) + si->isi_ie_off;
452b032f27cSSam Leffler memcpy(cp, ni->ni_ies.data, ielen);
4538a1b9b6aSSam Leffler }
4542cab1d3dSSam Leffler
45568e8e04eSSam Leffler req->si = (struct ieee80211req_sta_info *)(((uint8_t *)si) + len);
4562cab1d3dSSam Leffler req->space -= len;
4578a1b9b6aSSam Leffler }
4582cab1d3dSSam Leffler
45974bdb731SAndriy Voskoboinyk static int
getstainfo_common(struct ieee80211vap * vap,struct ieee80211req * ireq,struct ieee80211_node * ni,size_t off)460b032f27cSSam Leffler getstainfo_common(struct ieee80211vap *vap, struct ieee80211req *ireq,
461db9ff08bSKevin Lo struct ieee80211_node *ni, size_t off)
4622cab1d3dSSam Leffler {
463b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
4642cab1d3dSSam Leffler struct stainforeq req;
465d1c85daeSSam Leffler size_t space;
466d1c85daeSSam Leffler void *p;
4672cab1d3dSSam Leffler int error;
4682cab1d3dSSam Leffler
4692cab1d3dSSam Leffler error = 0;
4702cab1d3dSSam Leffler req.space = 0;
4717db788c6SAndriy Voskoboinyk if (ni == NULL) {
4727db788c6SAndriy Voskoboinyk ieee80211_iterate_nodes_vap(&ic->ic_sta, vap, get_sta_space,
4737db788c6SAndriy Voskoboinyk &req);
4747db788c6SAndriy Voskoboinyk } else
475d1c85daeSSam Leffler get_sta_space(&req, ni);
4762cab1d3dSSam Leffler if (req.space > ireq->i_len)
4772cab1d3dSSam Leffler req.space = ireq->i_len;
4782cab1d3dSSam Leffler if (req.space > 0) {
4792cab1d3dSSam Leffler space = req.space;
480bd29f817SBjoern A. Zeeb /* XXX IEEE80211_M_WAITOK after driver lock released */
481b9b53389SAdrian Chadd p = IEEE80211_MALLOC(space, M_TEMP,
482b9b53389SAdrian Chadd IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
483d1c85daeSSam Leffler if (p == NULL) {
484d1c85daeSSam Leffler error = ENOMEM;
485d1c85daeSSam Leffler goto bad;
486d1c85daeSSam Leffler }
4872cab1d3dSSam Leffler req.si = p;
4887db788c6SAndriy Voskoboinyk if (ni == NULL) {
4897db788c6SAndriy Voskoboinyk ieee80211_iterate_nodes_vap(&ic->ic_sta, vap,
4907db788c6SAndriy Voskoboinyk get_sta_info, &req);
4917db788c6SAndriy Voskoboinyk } else
492d1c85daeSSam Leffler get_sta_info(&req, ni);
4932cab1d3dSSam Leffler ireq->i_len = space - req.space;
49468e8e04eSSam Leffler error = copyout(p, (uint8_t *) ireq->i_data+off, ireq->i_len);
495b9b53389SAdrian Chadd IEEE80211_FREE(p, M_TEMP);
4962cab1d3dSSam Leffler } else
4972cab1d3dSSam Leffler ireq->i_len = 0;
498d1c85daeSSam Leffler bad:
499d1c85daeSSam Leffler if (ni != NULL)
500d1c85daeSSam Leffler ieee80211_free_node(ni);
5018a1b9b6aSSam Leffler return error;
5028a1b9b6aSSam Leffler }
5038a1b9b6aSSam Leffler
50474bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getstainfo(struct ieee80211vap * vap,struct ieee80211req * ireq)505b032f27cSSam Leffler ieee80211_ioctl_getstainfo(struct ieee80211vap *vap, struct ieee80211req *ireq)
506d1c85daeSSam Leffler {
50768e8e04eSSam Leffler uint8_t macaddr[IEEE80211_ADDR_LEN];
508db9ff08bSKevin Lo const size_t off = __offsetof(struct ieee80211req_sta_req, info);
509d1c85daeSSam Leffler struct ieee80211_node *ni;
510d1c85daeSSam Leffler int error;
511d1c85daeSSam Leffler
512d1c85daeSSam Leffler if (ireq->i_len < sizeof(struct ieee80211req_sta_req))
513d1c85daeSSam Leffler return EFAULT;
514d1c85daeSSam Leffler error = copyin(ireq->i_data, macaddr, IEEE80211_ADDR_LEN);
515d1c85daeSSam Leffler if (error != 0)
516d1c85daeSSam Leffler return error;
517b032f27cSSam Leffler if (IEEE80211_ADDR_EQ(macaddr, vap->iv_ifp->if_broadcastaddr)) {
518d1c85daeSSam Leffler ni = NULL;
519d1c85daeSSam Leffler } else {
520b032f27cSSam Leffler ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, macaddr);
52168e8e04eSSam Leffler if (ni == NULL)
522b032f27cSSam Leffler return ENOENT;
523d1c85daeSSam Leffler }
524b032f27cSSam Leffler return getstainfo_common(vap, ireq, ni, off);
525d1c85daeSSam Leffler }
526d1c85daeSSam Leffler
52774bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getstatxpow(struct ieee80211vap * vap,struct ieee80211req * ireq)528b032f27cSSam Leffler ieee80211_ioctl_getstatxpow(struct ieee80211vap *vap, struct ieee80211req *ireq)
5298a1b9b6aSSam Leffler {
5308a1b9b6aSSam Leffler struct ieee80211_node *ni;
5318a1b9b6aSSam Leffler struct ieee80211req_sta_txpow txpow;
5328a1b9b6aSSam Leffler int error;
5338a1b9b6aSSam Leffler
5348a1b9b6aSSam Leffler if (ireq->i_len != sizeof(txpow))
5358a1b9b6aSSam Leffler return EINVAL;
5368a1b9b6aSSam Leffler error = copyin(ireq->i_data, &txpow, sizeof(txpow));
5378a1b9b6aSSam Leffler if (error != 0)
5388a1b9b6aSSam Leffler return error;
539b032f27cSSam Leffler ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, txpow.it_macaddr);
5408a1b9b6aSSam Leffler if (ni == NULL)
541b032f27cSSam Leffler return ENOENT;
5428a1b9b6aSSam Leffler txpow.it_txpow = ni->ni_txpower;
5438a1b9b6aSSam Leffler error = copyout(&txpow, ireq->i_data, sizeof(txpow));
5448a1b9b6aSSam Leffler ieee80211_free_node(ni);
5458a1b9b6aSSam Leffler return error;
5468a1b9b6aSSam Leffler }
5478a1b9b6aSSam Leffler
54874bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getwmeparam(struct ieee80211vap * vap,struct ieee80211req * ireq)549b032f27cSSam Leffler ieee80211_ioctl_getwmeparam(struct ieee80211vap *vap, struct ieee80211req *ireq)
5508a1b9b6aSSam Leffler {
551b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
5528a1b9b6aSSam Leffler struct ieee80211_wme_state *wme = &ic->ic_wme;
5538a1b9b6aSSam Leffler struct wmeParams *wmep;
5548a1b9b6aSSam Leffler int ac;
5558a1b9b6aSSam Leffler
5568a1b9b6aSSam Leffler if ((ic->ic_caps & IEEE80211_C_WME) == 0)
5578a1b9b6aSSam Leffler return EINVAL;
5588a1b9b6aSSam Leffler
5598a1b9b6aSSam Leffler ac = (ireq->i_len & IEEE80211_WMEPARAM_VAL);
5608a1b9b6aSSam Leffler if (ac >= WME_NUM_AC)
5618a1b9b6aSSam Leffler ac = WME_AC_BE;
5628a1b9b6aSSam Leffler if (ireq->i_len & IEEE80211_WMEPARAM_BSS)
5638a1b9b6aSSam Leffler wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac];
5648a1b9b6aSSam Leffler else
5658a1b9b6aSSam Leffler wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac];
5668a1b9b6aSSam Leffler switch (ireq->i_type) {
5678a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */
5688a1b9b6aSSam Leffler ireq->i_val = wmep->wmep_logcwmin;
5698a1b9b6aSSam Leffler break;
5708a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */
5718a1b9b6aSSam Leffler ireq->i_val = wmep->wmep_logcwmax;
5728a1b9b6aSSam Leffler break;
5738a1b9b6aSSam Leffler case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */
5748a1b9b6aSSam Leffler ireq->i_val = wmep->wmep_aifsn;
5758a1b9b6aSSam Leffler break;
5768a1b9b6aSSam Leffler case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */
5778a1b9b6aSSam Leffler ireq->i_val = wmep->wmep_txopLimit;
5788a1b9b6aSSam Leffler break;
5798a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */
5808a1b9b6aSSam Leffler wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac];
5818a1b9b6aSSam Leffler ireq->i_val = wmep->wmep_acm;
5828a1b9b6aSSam Leffler break;
5838a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only)*/
5848a1b9b6aSSam Leffler wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac];
5858a1b9b6aSSam Leffler ireq->i_val = !wmep->wmep_noackPolicy;
5868a1b9b6aSSam Leffler break;
5878a1b9b6aSSam Leffler }
5888a1b9b6aSSam Leffler return 0;
5898a1b9b6aSSam Leffler }
5908a1b9b6aSSam Leffler
59174bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getmaccmd(struct ieee80211vap * vap,struct ieee80211req * ireq)592b032f27cSSam Leffler ieee80211_ioctl_getmaccmd(struct ieee80211vap *vap, struct ieee80211req *ireq)
593188757f5SSam Leffler {
594b032f27cSSam Leffler const struct ieee80211_aclator *acl = vap->iv_acl;
595188757f5SSam Leffler
596b032f27cSSam Leffler return (acl == NULL ? EINVAL : acl->iac_getioctl(vap, ireq));
597188757f5SSam Leffler }
598188757f5SSam Leffler
59974bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getcurchan(struct ieee80211vap * vap,struct ieee80211req * ireq)600b032f27cSSam Leffler ieee80211_ioctl_getcurchan(struct ieee80211vap *vap, struct ieee80211req *ireq)
601b032f27cSSam Leffler {
602b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
603b032f27cSSam Leffler struct ieee80211_channel *c;
604b032f27cSSam Leffler
605b032f27cSSam Leffler if (ireq->i_len != sizeof(struct ieee80211_channel))
606b032f27cSSam Leffler return EINVAL;
607b032f27cSSam Leffler /*
608b032f27cSSam Leffler * vap's may have different operating channels when HT is
609b032f27cSSam Leffler * in use. When in RUN state report the vap-specific channel.
610b032f27cSSam Leffler * Otherwise return curchan.
611b032f27cSSam Leffler */
612daa96325SIan Lepore if (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP)
613b032f27cSSam Leffler c = vap->iv_bss->ni_chan;
614b032f27cSSam Leffler else
615b032f27cSSam Leffler c = ic->ic_curchan;
616b032f27cSSam Leffler return copyout(c, ireq->i_data, sizeof(*c));
61768e8e04eSSam Leffler }
61868e8e04eSSam Leffler
61968e8e04eSSam Leffler static int
getappie(const struct ieee80211_appie * aie,struct ieee80211req * ireq)620b032f27cSSam Leffler getappie(const struct ieee80211_appie *aie, struct ieee80211req *ireq)
62168e8e04eSSam Leffler {
622b032f27cSSam Leffler if (aie == NULL)
62368e8e04eSSam Leffler return EINVAL;
624b032f27cSSam Leffler /* NB: truncate, caller can check length */
625b032f27cSSam Leffler if (ireq->i_len > aie->ie_len)
626b032f27cSSam Leffler ireq->i_len = aie->ie_len;
627b032f27cSSam Leffler return copyout(aie->ie_data, ireq->i_data, ireq->i_len);
628b032f27cSSam Leffler }
629b032f27cSSam Leffler
630b032f27cSSam Leffler static int
ieee80211_ioctl_getappie(struct ieee80211vap * vap,struct ieee80211req * ireq)631b032f27cSSam Leffler ieee80211_ioctl_getappie(struct ieee80211vap *vap, struct ieee80211req *ireq)
632b032f27cSSam Leffler {
633b032f27cSSam Leffler uint8_t fc0;
634b032f27cSSam Leffler
635b032f27cSSam Leffler fc0 = ireq->i_val & 0xff;
636b032f27cSSam Leffler if ((fc0 & IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_MGT)
637b032f27cSSam Leffler return EINVAL;
638b032f27cSSam Leffler /* NB: could check iv_opmode and reject but hardly worth the effort */
639b032f27cSSam Leffler switch (fc0 & IEEE80211_FC0_SUBTYPE_MASK) {
640b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_BEACON:
641b032f27cSSam Leffler return getappie(vap->iv_appie_beacon, ireq);
642b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
643b032f27cSSam Leffler return getappie(vap->iv_appie_proberesp, ireq);
644b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
645b032f27cSSam Leffler return getappie(vap->iv_appie_assocresp, ireq);
646b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_PROBE_REQ:
647b032f27cSSam Leffler return getappie(vap->iv_appie_probereq, ireq);
648b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
649b032f27cSSam Leffler return getappie(vap->iv_appie_assocreq, ireq);
650b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_BEACON|IEEE80211_FC0_SUBTYPE_PROBE_RESP:
651b032f27cSSam Leffler return getappie(vap->iv_appie_wpa, ireq);
652b032f27cSSam Leffler }
653b032f27cSSam Leffler return EINVAL;
654b032f27cSSam Leffler }
655b032f27cSSam Leffler
65674bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getregdomain(struct ieee80211vap * vap,const struct ieee80211req * ireq)657b032f27cSSam Leffler ieee80211_ioctl_getregdomain(struct ieee80211vap *vap,
658b032f27cSSam Leffler const struct ieee80211req *ireq)
659b032f27cSSam Leffler {
660b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
661b032f27cSSam Leffler
662b032f27cSSam Leffler if (ireq->i_len != sizeof(ic->ic_regdomain))
663b032f27cSSam Leffler return EINVAL;
664b032f27cSSam Leffler return copyout(&ic->ic_regdomain, ireq->i_data,
665b032f27cSSam Leffler sizeof(ic->ic_regdomain));
666b032f27cSSam Leffler }
667b032f27cSSam Leffler
66874bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getroam(struct ieee80211vap * vap,const struct ieee80211req * ireq)669b032f27cSSam Leffler ieee80211_ioctl_getroam(struct ieee80211vap *vap,
670b032f27cSSam Leffler const struct ieee80211req *ireq)
671b032f27cSSam Leffler {
672cbb24c24SSam Leffler size_t len = ireq->i_len;
673cbb24c24SSam Leffler /* NB: accept short requests for backwards compat */
674cbb24c24SSam Leffler if (len > sizeof(vap->iv_roamparms))
675cbb24c24SSam Leffler len = sizeof(vap->iv_roamparms);
676cbb24c24SSam Leffler return copyout(vap->iv_roamparms, ireq->i_data, len);
677b032f27cSSam Leffler }
678b032f27cSSam Leffler
67974bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_gettxparams(struct ieee80211vap * vap,const struct ieee80211req * ireq)680b032f27cSSam Leffler ieee80211_ioctl_gettxparams(struct ieee80211vap *vap,
681b032f27cSSam Leffler const struct ieee80211req *ireq)
682b032f27cSSam Leffler {
683cbb24c24SSam Leffler size_t len = ireq->i_len;
684cbb24c24SSam Leffler /* NB: accept short requests for backwards compat */
685cbb24c24SSam Leffler if (len > sizeof(vap->iv_txparms))
686cbb24c24SSam Leffler len = sizeof(vap->iv_txparms);
687cbb24c24SSam Leffler return copyout(vap->iv_txparms, ireq->i_data, len);
688b032f27cSSam Leffler }
689b032f27cSSam Leffler
69074bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getdevcaps(struct ieee80211com * ic,const struct ieee80211req * ireq)691b032f27cSSam Leffler ieee80211_ioctl_getdevcaps(struct ieee80211com *ic,
692b032f27cSSam Leffler const struct ieee80211req *ireq)
693b032f27cSSam Leffler {
694b032f27cSSam Leffler struct ieee80211_devcaps_req *dc;
695b032f27cSSam Leffler struct ieee80211req_chaninfo *ci;
6968658b18bSSam Leffler int maxchans, error;
697b032f27cSSam Leffler
6988658b18bSSam Leffler maxchans = 1 + ((ireq->i_len - sizeof(struct ieee80211_devcaps_req)) /
6998658b18bSSam Leffler sizeof(struct ieee80211_channel));
7008658b18bSSam Leffler /* NB: require 1 so we know ic_nchans is accessible */
7018658b18bSSam Leffler if (maxchans < 1)
702b032f27cSSam Leffler return EINVAL;
7038658b18bSSam Leffler /* constrain max request size, 2K channels is ~24Kbytes */
7048658b18bSSam Leffler if (maxchans > 2048)
7058658b18bSSam Leffler maxchans = 2048;
7068658b18bSSam Leffler dc = (struct ieee80211_devcaps_req *)
707b9b53389SAdrian Chadd IEEE80211_MALLOC(IEEE80211_DEVCAPS_SIZE(maxchans), M_TEMP,
708b9b53389SAdrian Chadd IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
709b032f27cSSam Leffler if (dc == NULL)
710b032f27cSSam Leffler return ENOMEM;
711b032f27cSSam Leffler dc->dc_drivercaps = ic->ic_caps;
712*1116e8b9SAdrian Chadd /*
713*1116e8b9SAdrian Chadd * Announce the set of both hardware and software supported
714*1116e8b9SAdrian Chadd * ciphers.
715*1116e8b9SAdrian Chadd */
716*1116e8b9SAdrian Chadd dc->dc_cryptocaps = ic->ic_cryptocaps | ic->ic_sw_cryptocaps;
717b032f27cSSam Leffler dc->dc_htcaps = ic->ic_htcaps;
718562adbe1SBjoern A. Zeeb dc->dc_vhtcaps = ic->ic_vht_cap.vht_cap_info;
719b032f27cSSam Leffler ci = &dc->dc_chaninfo;
7208658b18bSSam Leffler ic->ic_getradiocaps(ic, maxchans, &ci->ic_nchans, ci->ic_chans);
721f8b1ea17SSam Leffler KASSERT(ci->ic_nchans <= maxchans,
722f8b1ea17SSam Leffler ("nchans %d maxchans %d", ci->ic_nchans, maxchans));
723b032f27cSSam Leffler ieee80211_sort_channels(ci->ic_chans, ci->ic_nchans);
7248658b18bSSam Leffler error = copyout(dc, ireq->i_data, IEEE80211_DEVCAPS_SPACE(dc));
725b9b53389SAdrian Chadd IEEE80211_FREE(dc, M_TEMP);
726b032f27cSSam Leffler return error;
727b032f27cSSam Leffler }
728b032f27cSSam Leffler
72974bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_getstavlan(struct ieee80211vap * vap,struct ieee80211req * ireq)730b032f27cSSam Leffler ieee80211_ioctl_getstavlan(struct ieee80211vap *vap, struct ieee80211req *ireq)
731b032f27cSSam Leffler {
732b032f27cSSam Leffler struct ieee80211_node *ni;
733b032f27cSSam Leffler struct ieee80211req_sta_vlan vlan;
734b032f27cSSam Leffler int error;
735b032f27cSSam Leffler
736b032f27cSSam Leffler if (ireq->i_len != sizeof(vlan))
737b032f27cSSam Leffler return EINVAL;
738b032f27cSSam Leffler error = copyin(ireq->i_data, &vlan, sizeof(vlan));
739b032f27cSSam Leffler if (error != 0)
740b032f27cSSam Leffler return error;
741b032f27cSSam Leffler if (!IEEE80211_ADDR_EQ(vlan.sv_macaddr, zerobssid)) {
742b032f27cSSam Leffler ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap,
743b032f27cSSam Leffler vlan.sv_macaddr);
744b032f27cSSam Leffler if (ni == NULL)
745b032f27cSSam Leffler return ENOENT;
746b032f27cSSam Leffler } else
747b032f27cSSam Leffler ni = ieee80211_ref_node(vap->iv_bss);
748b032f27cSSam Leffler vlan.sv_vlan = ni->ni_vlan;
749b032f27cSSam Leffler error = copyout(&vlan, ireq->i_data, sizeof(vlan));
750b032f27cSSam Leffler ieee80211_free_node(ni);
751b032f27cSSam Leffler return error;
75268e8e04eSSam Leffler }
75368e8e04eSSam Leffler
75468e8e04eSSam Leffler /*
7558c4e758aSSam Leffler * Dummy ioctl get handler so the linker set is defined.
7568c4e758aSSam Leffler */
7578c4e758aSSam Leffler static int
dummy_ioctl_get(struct ieee80211vap * vap,struct ieee80211req * ireq)7588c4e758aSSam Leffler dummy_ioctl_get(struct ieee80211vap *vap, struct ieee80211req *ireq)
7598c4e758aSSam Leffler {
7608c4e758aSSam Leffler return ENOSYS;
7618c4e758aSSam Leffler }
7628c4e758aSSam Leffler IEEE80211_IOCTL_GET(dummy, dummy_ioctl_get);
7638c4e758aSSam Leffler
7648c4e758aSSam Leffler static int
ieee80211_ioctl_getdefault(struct ieee80211vap * vap,struct ieee80211req * ireq)7658c4e758aSSam Leffler ieee80211_ioctl_getdefault(struct ieee80211vap *vap, struct ieee80211req *ireq)
7668c4e758aSSam Leffler {
7678c4e758aSSam Leffler ieee80211_ioctl_getfunc * const *get;
7688c4e758aSSam Leffler int error;
7698c4e758aSSam Leffler
7708c4e758aSSam Leffler SET_FOREACH(get, ieee80211_ioctl_getset) {
7718c4e758aSSam Leffler error = (*get)(vap, ireq);
7728c4e758aSSam Leffler if (error != ENOSYS)
7738c4e758aSSam Leffler return error;
7748c4e758aSSam Leffler }
7758c4e758aSSam Leffler return EINVAL;
7768c4e758aSSam Leffler }
7778c4e758aSSam Leffler
77874bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_get80211(struct ieee80211vap * vap,u_long cmd,struct ieee80211req * ireq)779b032f27cSSam Leffler ieee80211_ioctl_get80211(struct ieee80211vap *vap, u_long cmd,
780b032f27cSSam Leffler struct ieee80211req *ireq)
7818a1b9b6aSSam Leffler {
782b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
783b032f27cSSam Leffler u_int kid, len;
78468e8e04eSSam Leffler uint8_t tmpkey[IEEE80211_KEYBUF_SIZE];
7851a1e1d21SSam Leffler char tmpssid[IEEE80211_NWID_LEN];
786b032f27cSSam Leffler int error = 0;
7871a1e1d21SSam Leffler
7881a1e1d21SSam Leffler switch (ireq->i_type) {
7897d1d4407SBjoern A. Zeeb case IEEE80211_IOC_IC_NAME:
7907d1d4407SBjoern A. Zeeb len = strlen(ic->ic_name) + 1;
7917d1d4407SBjoern A. Zeeb if (len > ireq->i_len)
7927d1d4407SBjoern A. Zeeb return (EINVAL);
7937d1d4407SBjoern A. Zeeb ireq->i_len = len;
7947d1d4407SBjoern A. Zeeb error = copyout(ic->ic_name, ireq->i_data, ireq->i_len);
7957d1d4407SBjoern A. Zeeb break;
7961a1e1d21SSam Leffler case IEEE80211_IOC_SSID:
797b032f27cSSam Leffler switch (vap->iv_state) {
7981a1e1d21SSam Leffler case IEEE80211_S_INIT:
7991a1e1d21SSam Leffler case IEEE80211_S_SCAN:
800b032f27cSSam Leffler ireq->i_len = vap->iv_des_ssid[0].len;
801b032f27cSSam Leffler memcpy(tmpssid, vap->iv_des_ssid[0].ssid, ireq->i_len);
8021a1e1d21SSam Leffler break;
8031a1e1d21SSam Leffler default:
804b032f27cSSam Leffler ireq->i_len = vap->iv_bss->ni_esslen;
805b032f27cSSam Leffler memcpy(tmpssid, vap->iv_bss->ni_essid, ireq->i_len);
8061a1e1d21SSam Leffler break;
8071a1e1d21SSam Leffler }
8081a1e1d21SSam Leffler error = copyout(tmpssid, ireq->i_data, ireq->i_len);
8091a1e1d21SSam Leffler break;
8101a1e1d21SSam Leffler case IEEE80211_IOC_NUMSSIDS:
8111a1e1d21SSam Leffler ireq->i_val = 1;
8121a1e1d21SSam Leffler break;
8131a1e1d21SSam Leffler case IEEE80211_IOC_WEP:
814b032f27cSSam Leffler if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0)
8158a1b9b6aSSam Leffler ireq->i_val = IEEE80211_WEP_OFF;
816b032f27cSSam Leffler else if (vap->iv_flags & IEEE80211_F_DROPUNENC)
8178a1b9b6aSSam Leffler ireq->i_val = IEEE80211_WEP_ON;
8188a1b9b6aSSam Leffler else
8198a1b9b6aSSam Leffler ireq->i_val = IEEE80211_WEP_MIXED;
8201a1e1d21SSam Leffler break;
8211a1e1d21SSam Leffler case IEEE80211_IOC_WEPKEY:
8221a1e1d21SSam Leffler kid = (u_int) ireq->i_val;
8238a1b9b6aSSam Leffler if (kid >= IEEE80211_WEP_NKID)
8248a1b9b6aSSam Leffler return EINVAL;
825b032f27cSSam Leffler len = (u_int) vap->iv_nw_keys[kid].wk_keylen;
8261a1e1d21SSam Leffler /* NB: only root can read WEP keys */
82701e57940SBjoern A. Zeeb if (ieee80211_priv_check_vap_getkey(cmd, vap, NULL) == 0) {
828b032f27cSSam Leffler bcopy(vap->iv_nw_keys[kid].wk_key, tmpkey, len);
8291a1e1d21SSam Leffler } else {
8301a1e1d21SSam Leffler bzero(tmpkey, len);
8311a1e1d21SSam Leffler }
8321a1e1d21SSam Leffler ireq->i_len = len;
8331a1e1d21SSam Leffler error = copyout(tmpkey, ireq->i_data, len);
8341a1e1d21SSam Leffler break;
8351a1e1d21SSam Leffler case IEEE80211_IOC_NUMWEPKEYS:
8361a1e1d21SSam Leffler ireq->i_val = IEEE80211_WEP_NKID;
8371a1e1d21SSam Leffler break;
8381a1e1d21SSam Leffler case IEEE80211_IOC_WEPTXKEY:
839b032f27cSSam Leffler ireq->i_val = vap->iv_def_txkey;
8401a1e1d21SSam Leffler break;
8411a1e1d21SSam Leffler case IEEE80211_IOC_AUTHMODE:
842b032f27cSSam Leffler if (vap->iv_flags & IEEE80211_F_WPA)
8438a1b9b6aSSam Leffler ireq->i_val = IEEE80211_AUTH_WPA;
8448a1b9b6aSSam Leffler else
845b032f27cSSam Leffler ireq->i_val = vap->iv_bss->ni_authmode;
8461a1e1d21SSam Leffler break;
8471a1e1d21SSam Leffler case IEEE80211_IOC_CHANNEL:
848b5c99415SSam Leffler ireq->i_val = ieee80211_chan2ieee(ic, ic->ic_curchan);
8491a1e1d21SSam Leffler break;
8501a1e1d21SSam Leffler case IEEE80211_IOC_POWERSAVE:
851b032f27cSSam Leffler if (vap->iv_flags & IEEE80211_F_PMGTON)
8521a1e1d21SSam Leffler ireq->i_val = IEEE80211_POWERSAVE_ON;
8531a1e1d21SSam Leffler else
8541a1e1d21SSam Leffler ireq->i_val = IEEE80211_POWERSAVE_OFF;
8551a1e1d21SSam Leffler break;
8561a1e1d21SSam Leffler case IEEE80211_IOC_POWERSAVESLEEP:
8571a1e1d21SSam Leffler ireq->i_val = ic->ic_lintval;
8581a1e1d21SSam Leffler break;
85913604e6bSSam Leffler case IEEE80211_IOC_RTSTHRESHOLD:
860b032f27cSSam Leffler ireq->i_val = vap->iv_rtsthreshold;
8611a1e1d21SSam Leffler break;
8622e79ca97SSam Leffler case IEEE80211_IOC_PROTMODE:
863f1481c8dSAdrian Chadd ireq->i_val = vap->iv_protmode;
8642e79ca97SSam Leffler break;
8652e79ca97SSam Leffler case IEEE80211_IOC_TXPOWER:
866b032f27cSSam Leffler /*
867b032f27cSSam Leffler * Tx power limit is the min of max regulatory
868b032f27cSSam Leffler * power, any user-set limit, and the max the
869b032f27cSSam Leffler * radio can do.
870781487cfSAdrian Chadd *
871781487cfSAdrian Chadd * TODO: methodize this
872b032f27cSSam Leffler */
873b032f27cSSam Leffler ireq->i_val = 2*ic->ic_curchan->ic_maxregpower;
874b032f27cSSam Leffler if (ireq->i_val > ic->ic_txpowlimit)
8758a1b9b6aSSam Leffler ireq->i_val = ic->ic_txpowlimit;
876b032f27cSSam Leffler if (ireq->i_val > ic->ic_curchan->ic_maxpower)
877b032f27cSSam Leffler ireq->i_val = ic->ic_curchan->ic_maxpower;
8788a1b9b6aSSam Leffler break;
8798a1b9b6aSSam Leffler case IEEE80211_IOC_WPA:
880b032f27cSSam Leffler switch (vap->iv_flags & IEEE80211_F_WPA) {
8818a1b9b6aSSam Leffler case IEEE80211_F_WPA1:
8828a1b9b6aSSam Leffler ireq->i_val = 1;
8838a1b9b6aSSam Leffler break;
8848a1b9b6aSSam Leffler case IEEE80211_F_WPA2:
8858a1b9b6aSSam Leffler ireq->i_val = 2;
8868a1b9b6aSSam Leffler break;
8878a1b9b6aSSam Leffler case IEEE80211_F_WPA1 | IEEE80211_F_WPA2:
8888a1b9b6aSSam Leffler ireq->i_val = 3;
8898a1b9b6aSSam Leffler break;
8908a1b9b6aSSam Leffler default:
8918a1b9b6aSSam Leffler ireq->i_val = 0;
8928a1b9b6aSSam Leffler break;
8938a1b9b6aSSam Leffler }
8948a1b9b6aSSam Leffler break;
8958a1b9b6aSSam Leffler case IEEE80211_IOC_CHANLIST:
896b032f27cSSam Leffler error = ieee80211_ioctl_getchanlist(vap, ireq);
8978a1b9b6aSSam Leffler break;
8988a1b9b6aSSam Leffler case IEEE80211_IOC_ROAMING:
899b032f27cSSam Leffler ireq->i_val = vap->iv_roaming;
9008a1b9b6aSSam Leffler break;
9018a1b9b6aSSam Leffler case IEEE80211_IOC_PRIVACY:
902b032f27cSSam Leffler ireq->i_val = (vap->iv_flags & IEEE80211_F_PRIVACY) != 0;
9038a1b9b6aSSam Leffler break;
9048a1b9b6aSSam Leffler case IEEE80211_IOC_DROPUNENCRYPTED:
905b032f27cSSam Leffler ireq->i_val = (vap->iv_flags & IEEE80211_F_DROPUNENC) != 0;
9068a1b9b6aSSam Leffler break;
9078a1b9b6aSSam Leffler case IEEE80211_IOC_COUNTERMEASURES:
908b032f27cSSam Leffler ireq->i_val = (vap->iv_flags & IEEE80211_F_COUNTERM) != 0;
9098a1b9b6aSSam Leffler break;
9108a1b9b6aSSam Leffler case IEEE80211_IOC_WME:
911b032f27cSSam Leffler ireq->i_val = (vap->iv_flags & IEEE80211_F_WME) != 0;
9128a1b9b6aSSam Leffler break;
9138a1b9b6aSSam Leffler case IEEE80211_IOC_HIDESSID:
914b032f27cSSam Leffler ireq->i_val = (vap->iv_flags & IEEE80211_F_HIDESSID) != 0;
9158a1b9b6aSSam Leffler break;
9168a1b9b6aSSam Leffler case IEEE80211_IOC_APBRIDGE:
917b032f27cSSam Leffler ireq->i_val = (vap->iv_flags & IEEE80211_F_NOBRIDGE) == 0;
9188a1b9b6aSSam Leffler break;
9198a1b9b6aSSam Leffler case IEEE80211_IOC_WPAKEY:
92001e57940SBjoern A. Zeeb error = ieee80211_ioctl_getkey(cmd, vap, ireq);
9218a1b9b6aSSam Leffler break;
9228a1b9b6aSSam Leffler case IEEE80211_IOC_CHANINFO:
923b032f27cSSam Leffler error = ieee80211_ioctl_getchaninfo(vap, ireq);
9248a1b9b6aSSam Leffler break;
9258a1b9b6aSSam Leffler case IEEE80211_IOC_BSSID:
9268a1b9b6aSSam Leffler if (ireq->i_len != IEEE80211_ADDR_LEN)
9278a1b9b6aSSam Leffler return EINVAL;
9281b74d2a4SAdrian Chadd if (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP) {
9297cd89f64SSam Leffler error = copyout(vap->iv_opmode == IEEE80211_M_WDS ?
9307cd89f64SSam Leffler vap->iv_bss->ni_macaddr : vap->iv_bss->ni_bssid,
9318a1b9b6aSSam Leffler ireq->i_data, ireq->i_len);
9327cd89f64SSam Leffler } else
9337cd89f64SSam Leffler error = copyout(vap->iv_des_bssid, ireq->i_data,
9347cd89f64SSam Leffler ireq->i_len);
9358a1b9b6aSSam Leffler break;
9368a1b9b6aSSam Leffler case IEEE80211_IOC_WPAIE:
93768e8e04eSSam Leffler case IEEE80211_IOC_WPAIE2:
938b032f27cSSam Leffler error = ieee80211_ioctl_getwpaie(vap, ireq, ireq->i_type);
9398a1b9b6aSSam Leffler break;
9408a1b9b6aSSam Leffler case IEEE80211_IOC_SCAN_RESULTS:
941b032f27cSSam Leffler error = ieee80211_ioctl_getscanresults(vap, ireq);
9428a1b9b6aSSam Leffler break;
9438a1b9b6aSSam Leffler case IEEE80211_IOC_STA_STATS:
944b032f27cSSam Leffler error = ieee80211_ioctl_getstastats(vap, ireq);
9458a1b9b6aSSam Leffler break;
9468a1b9b6aSSam Leffler case IEEE80211_IOC_TXPOWMAX:
947b032f27cSSam Leffler ireq->i_val = vap->iv_bss->ni_txpower;
9488a1b9b6aSSam Leffler break;
9498a1b9b6aSSam Leffler case IEEE80211_IOC_STA_TXPOW:
950b032f27cSSam Leffler error = ieee80211_ioctl_getstatxpow(vap, ireq);
9518a1b9b6aSSam Leffler break;
9528a1b9b6aSSam Leffler case IEEE80211_IOC_STA_INFO:
953b032f27cSSam Leffler error = ieee80211_ioctl_getstainfo(vap, ireq);
9548a1b9b6aSSam Leffler break;
9558a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */
9568a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */
9578a1b9b6aSSam Leffler case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */
9588a1b9b6aSSam Leffler case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */
9598a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */
960fa46d9dbSAdrian Chadd case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only) */
961b032f27cSSam Leffler error = ieee80211_ioctl_getwmeparam(vap, ireq);
9628a1b9b6aSSam Leffler break;
9638a1b9b6aSSam Leffler case IEEE80211_IOC_DTIM_PERIOD:
964b032f27cSSam Leffler ireq->i_val = vap->iv_dtim_period;
9658a1b9b6aSSam Leffler break;
9668a1b9b6aSSam Leffler case IEEE80211_IOC_BEACON_INTERVAL:
9678a1b9b6aSSam Leffler /* NB: get from ic_bss for station mode */
968b032f27cSSam Leffler ireq->i_val = vap->iv_bss->ni_intval;
9692e79ca97SSam Leffler break;
970c4f040c3SSam Leffler case IEEE80211_IOC_PUREG:
971b032f27cSSam Leffler ireq->i_val = (vap->iv_flags & IEEE80211_F_PUREG) != 0;
972c4f040c3SSam Leffler break;
97332b0e64bSAdrian Chadd case IEEE80211_IOC_QUIET:
97432b0e64bSAdrian Chadd ireq->i_val = vap->iv_quiet;
97532b0e64bSAdrian Chadd break;
97632b0e64bSAdrian Chadd case IEEE80211_IOC_QUIET_COUNT:
97732b0e64bSAdrian Chadd ireq->i_val = vap->iv_quiet_count;
97832b0e64bSAdrian Chadd break;
97932b0e64bSAdrian Chadd case IEEE80211_IOC_QUIET_PERIOD:
98032b0e64bSAdrian Chadd ireq->i_val = vap->iv_quiet_period;
98132b0e64bSAdrian Chadd break;
98232b0e64bSAdrian Chadd case IEEE80211_IOC_QUIET_DUR:
98332b0e64bSAdrian Chadd ireq->i_val = vap->iv_quiet_duration;
98432b0e64bSAdrian Chadd break;
98532b0e64bSAdrian Chadd case IEEE80211_IOC_QUIET_OFFSET:
98632b0e64bSAdrian Chadd ireq->i_val = vap->iv_quiet_offset;
98732b0e64bSAdrian Chadd break;
98868e8e04eSSam Leffler case IEEE80211_IOC_BGSCAN:
989b032f27cSSam Leffler ireq->i_val = (vap->iv_flags & IEEE80211_F_BGSCAN) != 0;
99068e8e04eSSam Leffler break;
99168e8e04eSSam Leffler case IEEE80211_IOC_BGSCAN_IDLE:
992b032f27cSSam Leffler ireq->i_val = vap->iv_bgscanidle*hz/1000; /* ms */
99368e8e04eSSam Leffler break;
99468e8e04eSSam Leffler case IEEE80211_IOC_BGSCAN_INTERVAL:
995b032f27cSSam Leffler ireq->i_val = vap->iv_bgscanintvl/hz; /* seconds */
99668e8e04eSSam Leffler break;
99768e8e04eSSam Leffler case IEEE80211_IOC_SCANVALID:
998b032f27cSSam Leffler ireq->i_val = vap->iv_scanvalid/hz; /* seconds */
99964353cb0SSam Leffler break;
100070231e3dSSam Leffler case IEEE80211_IOC_FRAGTHRESHOLD:
1001b032f27cSSam Leffler ireq->i_val = vap->iv_fragthreshold;
100270231e3dSSam Leffler break;
1003188757f5SSam Leffler case IEEE80211_IOC_MACCMD:
1004b032f27cSSam Leffler error = ieee80211_ioctl_getmaccmd(vap, ireq);
1005188757f5SSam Leffler break;
1006c27e4e31SSam Leffler case IEEE80211_IOC_BURST:
1007b032f27cSSam Leffler ireq->i_val = (vap->iv_flags & IEEE80211_F_BURST) != 0;
1008c27e4e31SSam Leffler break;
1009546786c9SSam Leffler case IEEE80211_IOC_BMISSTHRESHOLD:
1010b032f27cSSam Leffler ireq->i_val = vap->iv_bmissthreshold;
1011546786c9SSam Leffler break;
101268e8e04eSSam Leffler case IEEE80211_IOC_CURCHAN:
1013b032f27cSSam Leffler error = ieee80211_ioctl_getcurchan(vap, ireq);
101468e8e04eSSam Leffler break;
101568e8e04eSSam Leffler case IEEE80211_IOC_SHORTGI:
101668e8e04eSSam Leffler ireq->i_val = 0;
10172bfc8a91SSam Leffler if (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI20)
101868e8e04eSSam Leffler ireq->i_val |= IEEE80211_HTCAP_SHORTGI20;
10192bfc8a91SSam Leffler if (vap->iv_flags_ht & IEEE80211_FHT_SHORTGI40)
102068e8e04eSSam Leffler ireq->i_val |= IEEE80211_HTCAP_SHORTGI40;
102168e8e04eSSam Leffler break;
102268e8e04eSSam Leffler case IEEE80211_IOC_AMPDU:
102368e8e04eSSam Leffler ireq->i_val = 0;
10242bfc8a91SSam Leffler if (vap->iv_flags_ht & IEEE80211_FHT_AMPDU_TX)
102568e8e04eSSam Leffler ireq->i_val |= 1;
10262bfc8a91SSam Leffler if (vap->iv_flags_ht & IEEE80211_FHT_AMPDU_RX)
102768e8e04eSSam Leffler ireq->i_val |= 2;
102868e8e04eSSam Leffler break;
102968e8e04eSSam Leffler case IEEE80211_IOC_AMPDU_LIMIT:
1030781487cfSAdrian Chadd /* XXX TODO: make this a per-node thing; and leave this as global */
1031b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_HOSTAP)
1032b032f27cSSam Leffler ireq->i_val = vap->iv_ampdu_rxmax;
10331b74d2a4SAdrian Chadd else if (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP)
1034cac03190SAdrian Chadd /*
1035cac03190SAdrian Chadd * XXX TODO: this isn't completely correct, as we've
1036cac03190SAdrian Chadd * negotiated the higher of the two.
1037cac03190SAdrian Chadd */
1038fe5ebb23SBjoern A. Zeeb ireq->i_val = _IEEE80211_MASKSHIFT( vap->iv_bss->ni_htparam,
1039b032f27cSSam Leffler IEEE80211_HTCAP_MAXRXAMPDU);
1040b032f27cSSam Leffler else
1041b032f27cSSam Leffler ireq->i_val = vap->iv_ampdu_limit;
104268e8e04eSSam Leffler break;
104368e8e04eSSam Leffler case IEEE80211_IOC_AMPDU_DENSITY:
1044781487cfSAdrian Chadd /* XXX TODO: make this a per-node thing; and leave this as global */
1045900de995SSam Leffler if (vap->iv_opmode == IEEE80211_M_STA &&
10461b74d2a4SAdrian Chadd (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP))
1047cac03190SAdrian Chadd /*
1048cac03190SAdrian Chadd * XXX TODO: this isn't completely correct, as we've
1049cac03190SAdrian Chadd * negotiated the higher of the two.
1050cac03190SAdrian Chadd */
1051fe5ebb23SBjoern A. Zeeb ireq->i_val = _IEEE80211_MASKSHIFT(vap->iv_bss->ni_htparam,
1052b032f27cSSam Leffler IEEE80211_HTCAP_MPDUDENSITY);
1053b032f27cSSam Leffler else
1054b032f27cSSam Leffler ireq->i_val = vap->iv_ampdu_density;
105568e8e04eSSam Leffler break;
105668e8e04eSSam Leffler case IEEE80211_IOC_AMSDU:
105768e8e04eSSam Leffler ireq->i_val = 0;
10582bfc8a91SSam Leffler if (vap->iv_flags_ht & IEEE80211_FHT_AMSDU_TX)
105968e8e04eSSam Leffler ireq->i_val |= 1;
10602bfc8a91SSam Leffler if (vap->iv_flags_ht & IEEE80211_FHT_AMSDU_RX)
106168e8e04eSSam Leffler ireq->i_val |= 2;
106268e8e04eSSam Leffler break;
106368e8e04eSSam Leffler case IEEE80211_IOC_AMSDU_LIMIT:
1064b032f27cSSam Leffler ireq->i_val = vap->iv_amsdu_limit; /* XXX truncation? */
106568e8e04eSSam Leffler break;
106668e8e04eSSam Leffler case IEEE80211_IOC_PUREN:
10672bfc8a91SSam Leffler ireq->i_val = (vap->iv_flags_ht & IEEE80211_FHT_PUREN) != 0;
106868e8e04eSSam Leffler break;
106968e8e04eSSam Leffler case IEEE80211_IOC_DOTH:
1070b032f27cSSam Leffler ireq->i_val = (vap->iv_flags & IEEE80211_F_DOTH) != 0;
1071b032f27cSSam Leffler break;
1072b032f27cSSam Leffler case IEEE80211_IOC_REGDOMAIN:
1073b032f27cSSam Leffler error = ieee80211_ioctl_getregdomain(vap, ireq);
1074b032f27cSSam Leffler break;
1075b032f27cSSam Leffler case IEEE80211_IOC_ROAM:
1076b032f27cSSam Leffler error = ieee80211_ioctl_getroam(vap, ireq);
1077b032f27cSSam Leffler break;
1078b032f27cSSam Leffler case IEEE80211_IOC_TXPARAMS:
1079b032f27cSSam Leffler error = ieee80211_ioctl_gettxparams(vap, ireq);
108068e8e04eSSam Leffler break;
108168e8e04eSSam Leffler case IEEE80211_IOC_HTCOMPAT:
10822bfc8a91SSam Leffler ireq->i_val = (vap->iv_flags_ht & IEEE80211_FHT_HTCOMPAT) != 0;
1083b032f27cSSam Leffler break;
1084b032f27cSSam Leffler case IEEE80211_IOC_DWDS:
1085b032f27cSSam Leffler ireq->i_val = (vap->iv_flags & IEEE80211_F_DWDS) != 0;
108668e8e04eSSam Leffler break;
1087c066143cSSam Leffler case IEEE80211_IOC_INACTIVITY:
1088b032f27cSSam Leffler ireq->i_val = (vap->iv_flags_ext & IEEE80211_FEXT_INACT) != 0;
1089b032f27cSSam Leffler break;
1090b032f27cSSam Leffler case IEEE80211_IOC_APPIE:
1091b032f27cSSam Leffler error = ieee80211_ioctl_getappie(vap, ireq);
1092b032f27cSSam Leffler break;
1093b032f27cSSam Leffler case IEEE80211_IOC_WPS:
1094b032f27cSSam Leffler ireq->i_val = (vap->iv_flags_ext & IEEE80211_FEXT_WPS) != 0;
1095b032f27cSSam Leffler break;
1096b032f27cSSam Leffler case IEEE80211_IOC_TSN:
1097b032f27cSSam Leffler ireq->i_val = (vap->iv_flags_ext & IEEE80211_FEXT_TSN) != 0;
1098b032f27cSSam Leffler break;
1099b032f27cSSam Leffler case IEEE80211_IOC_DFS:
1100b032f27cSSam Leffler ireq->i_val = (vap->iv_flags_ext & IEEE80211_FEXT_DFS) != 0;
1101b032f27cSSam Leffler break;
1102b032f27cSSam Leffler case IEEE80211_IOC_DOTD:
1103b032f27cSSam Leffler ireq->i_val = (vap->iv_flags_ext & IEEE80211_FEXT_DOTD) != 0;
1104b032f27cSSam Leffler break;
1105b032f27cSSam Leffler case IEEE80211_IOC_DEVCAPS:
1106b032f27cSSam Leffler error = ieee80211_ioctl_getdevcaps(ic, ireq);
1107c066143cSSam Leffler break;
11081b6167d2SSam Leffler case IEEE80211_IOC_HTPROTMODE:
1109f1481c8dSAdrian Chadd ireq->i_val = vap->iv_htprotmode;
11101b6167d2SSam Leffler break;
11111b6167d2SSam Leffler case IEEE80211_IOC_HTCONF:
11122bfc8a91SSam Leffler if (vap->iv_flags_ht & IEEE80211_FHT_HT) {
11131b6167d2SSam Leffler ireq->i_val = 1;
11142bfc8a91SSam Leffler if (vap->iv_flags_ht & IEEE80211_FHT_USEHT40)
11151b6167d2SSam Leffler ireq->i_val |= 2;
11161b6167d2SSam Leffler } else
11171b6167d2SSam Leffler ireq->i_val = 0;
11181b6167d2SSam Leffler break;
1119b032f27cSSam Leffler case IEEE80211_IOC_STA_VLAN:
1120b032f27cSSam Leffler error = ieee80211_ioctl_getstavlan(vap, ireq);
1121b032f27cSSam Leffler break;
11228c070d69SSam Leffler case IEEE80211_IOC_SMPS:
11238c070d69SSam Leffler if (vap->iv_opmode == IEEE80211_M_STA &&
11241b74d2a4SAdrian Chadd (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP)) {
11258c070d69SSam Leffler if (vap->iv_bss->ni_flags & IEEE80211_NODE_MIMO_RTS)
11268c070d69SSam Leffler ireq->i_val = IEEE80211_HTCAP_SMPS_DYNAMIC;
11278c070d69SSam Leffler else if (vap->iv_bss->ni_flags & IEEE80211_NODE_MIMO_PS)
11288c070d69SSam Leffler ireq->i_val = IEEE80211_HTCAP_SMPS_ENA;
11298c070d69SSam Leffler else
11308c070d69SSam Leffler ireq->i_val = IEEE80211_HTCAP_SMPS_OFF;
11318c070d69SSam Leffler } else
11328c070d69SSam Leffler ireq->i_val = vap->iv_htcaps & IEEE80211_HTCAP_SMPS;
11338c070d69SSam Leffler break;
113444f7a6edSSam Leffler case IEEE80211_IOC_RIFS:
113544f7a6edSSam Leffler if (vap->iv_opmode == IEEE80211_M_STA &&
11361b74d2a4SAdrian Chadd (vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP))
113744f7a6edSSam Leffler ireq->i_val =
113844f7a6edSSam Leffler (vap->iv_bss->ni_flags & IEEE80211_NODE_RIFS) != 0;
113944f7a6edSSam Leffler else
114044f7a6edSSam Leffler ireq->i_val =
11412bfc8a91SSam Leffler (vap->iv_flags_ht & IEEE80211_FHT_RIFS) != 0;
114244f7a6edSSam Leffler break;
1143ec3763bbSAdrian Chadd case IEEE80211_IOC_STBC:
1144ec3763bbSAdrian Chadd ireq->i_val = 0;
1145ec3763bbSAdrian Chadd if (vap->iv_flags_ht & IEEE80211_FHT_STBC_TX)
1146ec3763bbSAdrian Chadd ireq->i_val |= 1;
1147ec3763bbSAdrian Chadd if (vap->iv_flags_ht & IEEE80211_FHT_STBC_RX)
1148ec3763bbSAdrian Chadd ireq->i_val |= 2;
1149ec3763bbSAdrian Chadd break;
1150c5bba9daSAndriy Voskoboinyk case IEEE80211_IOC_LDPC:
1151c5bba9daSAndriy Voskoboinyk ireq->i_val = 0;
1152c5bba9daSAndriy Voskoboinyk if (vap->iv_flags_ht & IEEE80211_FHT_LDPC_TX)
1153c5bba9daSAndriy Voskoboinyk ireq->i_val |= 1;
1154c5bba9daSAndriy Voskoboinyk if (vap->iv_flags_ht & IEEE80211_FHT_LDPC_RX)
1155c5bba9daSAndriy Voskoboinyk ireq->i_val |= 2;
1156c5bba9daSAndriy Voskoboinyk break;
11578379e8dbSAdrian Chadd case IEEE80211_IOC_UAPSD:
11588379e8dbSAdrian Chadd ireq->i_val = 0;
11598379e8dbSAdrian Chadd if (vap->iv_flags_ext & IEEE80211_FEXT_UAPSD)
11608379e8dbSAdrian Chadd ireq->i_val = 1;
11618379e8dbSAdrian Chadd break;
116235bcfd1cSAdrian Chadd case IEEE80211_IOC_VHTCONF:
1163ef48d4faSBjoern A. Zeeb ireq->i_val = vap->iv_vht_flags & IEEE80211_FVHT_MASK;
116435bcfd1cSAdrian Chadd break;
11651a1e1d21SSam Leffler default:
11668c4e758aSSam Leffler error = ieee80211_ioctl_getdefault(vap, ireq);
1167b2e95691SSam Leffler break;
11681a1e1d21SSam Leffler }
11698a1b9b6aSSam Leffler return error;
11708a1b9b6aSSam Leffler }
11718a1b9b6aSSam Leffler
117274bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setkey(struct ieee80211vap * vap,struct ieee80211req * ireq)1173b032f27cSSam Leffler ieee80211_ioctl_setkey(struct ieee80211vap *vap, struct ieee80211req *ireq)
11748a1b9b6aSSam Leffler {
11758a1b9b6aSSam Leffler struct ieee80211req_key ik;
11768a1b9b6aSSam Leffler struct ieee80211_node *ni;
11778a1b9b6aSSam Leffler struct ieee80211_key *wk;
117868e8e04eSSam Leffler uint16_t kid;
1179b032f27cSSam Leffler int error, i;
11808a1b9b6aSSam Leffler
11818a1b9b6aSSam Leffler if (ireq->i_len != sizeof(ik))
11828a1b9b6aSSam Leffler return EINVAL;
11838a1b9b6aSSam Leffler error = copyin(ireq->i_data, &ik, sizeof(ik));
11841a1e1d21SSam Leffler if (error)
11858a1b9b6aSSam Leffler return error;
11868a1b9b6aSSam Leffler /* NB: cipher support is verified by ieee80211_crypt_newkey */
11878a1b9b6aSSam Leffler /* NB: this also checks ik->ik_keylen > sizeof(wk->wk_key) */
11888a1b9b6aSSam Leffler if (ik.ik_keylen > sizeof(ik.ik_keydata))
11898a1b9b6aSSam Leffler return E2BIG;
11908a1b9b6aSSam Leffler kid = ik.ik_keyix;
11918a1b9b6aSSam Leffler if (kid == IEEE80211_KEYIX_NONE) {
11928a1b9b6aSSam Leffler /* XXX unicast keys currently must be tx/rx */
11938a1b9b6aSSam Leffler if (ik.ik_flags != (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV))
11948a1b9b6aSSam Leffler return EINVAL;
1195b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_STA) {
1196b032f27cSSam Leffler ni = ieee80211_ref_node(vap->iv_bss);
1197b5d4660fSSam Leffler if (!IEEE80211_ADDR_EQ(ik.ik_macaddr, ni->ni_bssid)) {
1198b5d4660fSSam Leffler ieee80211_free_node(ni);
11998a1b9b6aSSam Leffler return EADDRNOTAVAIL;
1200b5d4660fSSam Leffler }
12018a1b9b6aSSam Leffler } else {
1202b032f27cSSam Leffler ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap,
1203b032f27cSSam Leffler ik.ik_macaddr);
12048a1b9b6aSSam Leffler if (ni == NULL)
12058a1b9b6aSSam Leffler return ENOENT;
12068a1b9b6aSSam Leffler }
12078a1b9b6aSSam Leffler wk = &ni->ni_ucastkey;
12088a1b9b6aSSam Leffler } else {
12098a1b9b6aSSam Leffler if (kid >= IEEE80211_WEP_NKID)
12108a1b9b6aSSam Leffler return EINVAL;
1211b032f27cSSam Leffler wk = &vap->iv_nw_keys[kid];
1212386d84f6SSam Leffler /*
1213386d84f6SSam Leffler * Global slots start off w/o any assigned key index.
1214386d84f6SSam Leffler * Force one here for consistency with IEEE80211_IOC_WEPKEY.
1215386d84f6SSam Leffler */
1216386d84f6SSam Leffler if (wk->wk_keyix == IEEE80211_KEYIX_NONE)
1217386d84f6SSam Leffler wk->wk_keyix = kid;
12188a1b9b6aSSam Leffler ni = NULL;
12198a1b9b6aSSam Leffler }
12208a1b9b6aSSam Leffler error = 0;
1221b032f27cSSam Leffler ieee80211_key_update_begin(vap);
1222b032f27cSSam Leffler if (ieee80211_crypto_newkey(vap, ik.ik_type, ik.ik_flags, wk)) {
12238a1b9b6aSSam Leffler wk->wk_keylen = ik.ik_keylen;
12248a1b9b6aSSam Leffler /* NB: MIC presence is implied by cipher type */
12258a1b9b6aSSam Leffler if (wk->wk_keylen > IEEE80211_KEYBUF_SIZE)
12268a1b9b6aSSam Leffler wk->wk_keylen = IEEE80211_KEYBUF_SIZE;
1227b032f27cSSam Leffler for (i = 0; i < IEEE80211_TID_SIZE; i++)
1228b032f27cSSam Leffler wk->wk_keyrsc[i] = ik.ik_keyrsc;
12298a1b9b6aSSam Leffler wk->wk_keytsc = 0; /* new key, reset */
12308a1b9b6aSSam Leffler memset(wk->wk_key, 0, sizeof(wk->wk_key));
12318a1b9b6aSSam Leffler memcpy(wk->wk_key, ik.ik_keydata, ik.ik_keylen);
123271fe06caSSam Leffler IEEE80211_ADDR_COPY(wk->wk_macaddr,
123371fe06caSSam Leffler ni != NULL ? ni->ni_macaddr : ik.ik_macaddr);
123471fe06caSSam Leffler if (!ieee80211_crypto_setkey(vap, wk))
12358a1b9b6aSSam Leffler error = EIO;
12368a1b9b6aSSam Leffler else if ((ik.ik_flags & IEEE80211_KEY_DEFAULT))
1237781487cfSAdrian Chadd /*
1238781487cfSAdrian Chadd * Inform the driver that this is the default
1239781487cfSAdrian Chadd * transmit key. Now, ideally we'd just set
1240781487cfSAdrian Chadd * a flag in the key update that would
1241781487cfSAdrian Chadd * say "yes, we're the default key", but
1242781487cfSAdrian Chadd * that currently isn't the way the ioctl ->
1243781487cfSAdrian Chadd * key interface works.
1244781487cfSAdrian Chadd */
1245781487cfSAdrian Chadd ieee80211_crypto_set_deftxkey(vap, kid);
12468a1b9b6aSSam Leffler } else
12478a1b9b6aSSam Leffler error = ENXIO;
1248b032f27cSSam Leffler ieee80211_key_update_end(vap);
12498a1b9b6aSSam Leffler if (ni != NULL)
12508a1b9b6aSSam Leffler ieee80211_free_node(ni);
12518a1b9b6aSSam Leffler return error;
12528a1b9b6aSSam Leffler }
12538a1b9b6aSSam Leffler
125474bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_delkey(struct ieee80211vap * vap,struct ieee80211req * ireq)1255b032f27cSSam Leffler ieee80211_ioctl_delkey(struct ieee80211vap *vap, struct ieee80211req *ireq)
12568a1b9b6aSSam Leffler {
12578a1b9b6aSSam Leffler struct ieee80211req_del_key dk;
12588a1b9b6aSSam Leffler int kid, error;
12598a1b9b6aSSam Leffler
12608a1b9b6aSSam Leffler if (ireq->i_len != sizeof(dk))
12618a1b9b6aSSam Leffler return EINVAL;
12628a1b9b6aSSam Leffler error = copyin(ireq->i_data, &dk, sizeof(dk));
12638a1b9b6aSSam Leffler if (error)
12648a1b9b6aSSam Leffler return error;
12658a1b9b6aSSam Leffler kid = dk.idk_keyix;
126668e8e04eSSam Leffler /* XXX uint8_t -> uint16_t */
126768e8e04eSSam Leffler if (dk.idk_keyix == (uint8_t) IEEE80211_KEYIX_NONE) {
12688a1b9b6aSSam Leffler struct ieee80211_node *ni;
12698a1b9b6aSSam Leffler
1270b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_STA) {
1271b032f27cSSam Leffler ni = ieee80211_ref_node(vap->iv_bss);
1272b5d4660fSSam Leffler if (!IEEE80211_ADDR_EQ(dk.idk_macaddr, ni->ni_bssid)) {
1273b5d4660fSSam Leffler ieee80211_free_node(ni);
1274b5d4660fSSam Leffler return EADDRNOTAVAIL;
1275b5d4660fSSam Leffler }
1276b5d4660fSSam Leffler } else {
1277b032f27cSSam Leffler ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap,
1278b032f27cSSam Leffler dk.idk_macaddr);
12798a1b9b6aSSam Leffler if (ni == NULL)
1280b5d4660fSSam Leffler return ENOENT;
1281b5d4660fSSam Leffler }
12828a1b9b6aSSam Leffler /* XXX error return */
1283c1225b52SSam Leffler ieee80211_node_delucastkey(ni);
12848a1b9b6aSSam Leffler ieee80211_free_node(ni);
12858a1b9b6aSSam Leffler } else {
12868a1b9b6aSSam Leffler if (kid >= IEEE80211_WEP_NKID)
12878a1b9b6aSSam Leffler return EINVAL;
12888a1b9b6aSSam Leffler /* XXX error return */
1289b032f27cSSam Leffler ieee80211_crypto_delkey(vap, &vap->iv_nw_keys[kid]);
12908a1b9b6aSSam Leffler }
12918a1b9b6aSSam Leffler return 0;
12928a1b9b6aSSam Leffler }
12938a1b9b6aSSam Leffler
1294b032f27cSSam Leffler struct mlmeop {
1295b032f27cSSam Leffler struct ieee80211vap *vap;
1296b032f27cSSam Leffler int op;
1297b032f27cSSam Leffler int reason;
1298b032f27cSSam Leffler };
1299b032f27cSSam Leffler
1300b032f27cSSam Leffler static void
mlmedebug(struct ieee80211vap * vap,const uint8_t mac[IEEE80211_ADDR_LEN],int op,int reason)1301b032f27cSSam Leffler mlmedebug(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN],
1302b032f27cSSam Leffler int op, int reason)
1303b032f27cSSam Leffler {
1304b032f27cSSam Leffler #ifdef IEEE80211_DEBUG
1305b032f27cSSam Leffler static const struct {
1306b032f27cSSam Leffler int mask;
1307b032f27cSSam Leffler const char *opstr;
1308b032f27cSSam Leffler } ops[] = {
1309b032f27cSSam Leffler { 0, "op#0" },
1310b032f27cSSam Leffler { IEEE80211_MSG_IOCTL | IEEE80211_MSG_STATE |
1311b032f27cSSam Leffler IEEE80211_MSG_ASSOC, "assoc" },
1312b032f27cSSam Leffler { IEEE80211_MSG_IOCTL | IEEE80211_MSG_STATE |
1313b032f27cSSam Leffler IEEE80211_MSG_ASSOC, "disassoc" },
1314b032f27cSSam Leffler { IEEE80211_MSG_IOCTL | IEEE80211_MSG_STATE |
1315b032f27cSSam Leffler IEEE80211_MSG_AUTH, "deauth" },
1316b032f27cSSam Leffler { IEEE80211_MSG_IOCTL | IEEE80211_MSG_STATE |
1317b032f27cSSam Leffler IEEE80211_MSG_AUTH, "authorize" },
1318b032f27cSSam Leffler { IEEE80211_MSG_IOCTL | IEEE80211_MSG_STATE |
1319b032f27cSSam Leffler IEEE80211_MSG_AUTH, "unauthorize" },
1320b032f27cSSam Leffler };
1321b032f27cSSam Leffler
1322b032f27cSSam Leffler if (op == IEEE80211_MLME_AUTH) {
1323b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_IOCTL |
1324b032f27cSSam Leffler IEEE80211_MSG_STATE | IEEE80211_MSG_AUTH, mac,
1325d72d72d3SAndriy Voskoboinyk "station authenticate %s via MLME (reason: %d (%s))",
1326b032f27cSSam Leffler reason == IEEE80211_STATUS_SUCCESS ? "ACCEPT" : "REJECT",
1327d72d72d3SAndriy Voskoboinyk reason, ieee80211_reason_to_string(reason));
1328b032f27cSSam Leffler } else if (!(IEEE80211_MLME_ASSOC <= op && op <= IEEE80211_MLME_AUTH)) {
1329b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_ANY, mac,
1330d72d72d3SAndriy Voskoboinyk "unknown MLME request %d (reason: %d (%s))", op, reason,
1331d72d72d3SAndriy Voskoboinyk ieee80211_reason_to_string(reason));
1332b032f27cSSam Leffler } else if (reason == IEEE80211_STATUS_SUCCESS) {
1333b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, ops[op].mask, mac,
1334b032f27cSSam Leffler "station %s via MLME", ops[op].opstr);
1335b032f27cSSam Leffler } else {
1336b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, ops[op].mask, mac,
1337d72d72d3SAndriy Voskoboinyk "station %s via MLME (reason: %d (%s))", ops[op].opstr,
1338d72d72d3SAndriy Voskoboinyk reason, ieee80211_reason_to_string(reason));
1339b032f27cSSam Leffler }
1340b032f27cSSam Leffler #endif /* IEEE80211_DEBUG */
1341b032f27cSSam Leffler }
1342b032f27cSSam Leffler
13438a1b9b6aSSam Leffler static void
domlme(void * arg,struct ieee80211_node * ni)13448a1b9b6aSSam Leffler domlme(void *arg, struct ieee80211_node *ni)
13458a1b9b6aSSam Leffler {
1346b032f27cSSam Leffler struct mlmeop *mop = arg;
1347b032f27cSSam Leffler struct ieee80211vap *vap = ni->ni_vap;
13488a1b9b6aSSam Leffler
1349b032f27cSSam Leffler if (vap != mop->vap)
1350b032f27cSSam Leffler return;
1351b032f27cSSam Leffler /*
1352b032f27cSSam Leffler * NB: if ni_associd is zero then the node is already cleaned
1353b032f27cSSam Leffler * up and we don't need to do this (we're safely holding a
1354b032f27cSSam Leffler * reference but should otherwise not modify it's state).
1355b032f27cSSam Leffler */
1356b032f27cSSam Leffler if (ni->ni_associd == 0)
1357b032f27cSSam Leffler return;
1358b032f27cSSam Leffler mlmedebug(vap, ni->ni_macaddr, mop->op, mop->reason);
1359b032f27cSSam Leffler if (mop->op == IEEE80211_MLME_DEAUTH) {
1360b032f27cSSam Leffler IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DEAUTH,
1361b032f27cSSam Leffler mop->reason);
1362b032f27cSSam Leffler } else {
1363b032f27cSSam Leffler IEEE80211_SEND_MGMT(ni, IEEE80211_FC0_SUBTYPE_DISASSOC,
1364b032f27cSSam Leffler mop->reason);
13658a1b9b6aSSam Leffler }
1366b032f27cSSam Leffler ieee80211_node_leave(ni);
1367b032f27cSSam Leffler }
1368b032f27cSSam Leffler
1369b032f27cSSam Leffler static int
setmlme_dropsta(struct ieee80211vap * vap,const uint8_t mac[IEEE80211_ADDR_LEN],struct mlmeop * mlmeop)1370b032f27cSSam Leffler setmlme_dropsta(struct ieee80211vap *vap,
1371b032f27cSSam Leffler const uint8_t mac[IEEE80211_ADDR_LEN], struct mlmeop *mlmeop)
1372b032f27cSSam Leffler {
13737a79cebfSGleb Smirnoff struct ieee80211_node_table *nt = &vap->iv_ic->ic_sta;
1374b032f27cSSam Leffler struct ieee80211_node *ni;
1375b032f27cSSam Leffler int error = 0;
1376b032f27cSSam Leffler
1377b032f27cSSam Leffler /* NB: the broadcast address means do 'em all */
13787a79cebfSGleb Smirnoff if (!IEEE80211_ADDR_EQ(mac, vap->iv_ifp->if_broadcastaddr)) {
1379b032f27cSSam Leffler IEEE80211_NODE_LOCK(nt);
1380b032f27cSSam Leffler ni = ieee80211_find_node_locked(nt, mac);
13819984c9baSAdrian Chadd IEEE80211_NODE_UNLOCK(nt);
13829984c9baSAdrian Chadd /*
13839984c9baSAdrian Chadd * Don't do the node update inside the node
13849984c9baSAdrian Chadd * table lock. This unfortunately causes LORs
13859984c9baSAdrian Chadd * with drivers and their TX paths.
13869984c9baSAdrian Chadd */
1387b032f27cSSam Leffler if (ni != NULL) {
1388b032f27cSSam Leffler domlme(mlmeop, ni);
1389b032f27cSSam Leffler ieee80211_free_node(ni);
1390b032f27cSSam Leffler } else
1391b032f27cSSam Leffler error = ENOENT;
1392b032f27cSSam Leffler } else {
1393b032f27cSSam Leffler ieee80211_iterate_nodes(nt, domlme, mlmeop);
1394b032f27cSSam Leffler }
1395b032f27cSSam Leffler return error;
1396b032f27cSSam Leffler }
1397b032f27cSSam Leffler
139874bdb731SAndriy Voskoboinyk static int
setmlme_common(struct ieee80211vap * vap,int op,const uint8_t mac[IEEE80211_ADDR_LEN],int reason)1399b032f27cSSam Leffler setmlme_common(struct ieee80211vap *vap, int op,
1400b032f27cSSam Leffler const uint8_t mac[IEEE80211_ADDR_LEN], int reason)
1401b032f27cSSam Leffler {
1402b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
1403b032f27cSSam Leffler struct ieee80211_node_table *nt = &ic->ic_sta;
1404b032f27cSSam Leffler struct ieee80211_node *ni;
1405b032f27cSSam Leffler struct mlmeop mlmeop;
1406b032f27cSSam Leffler int error;
1407b032f27cSSam Leffler
1408b032f27cSSam Leffler error = 0;
1409b032f27cSSam Leffler switch (op) {
1410b032f27cSSam Leffler case IEEE80211_MLME_DISASSOC:
1411b032f27cSSam Leffler case IEEE80211_MLME_DEAUTH:
1412b032f27cSSam Leffler switch (vap->iv_opmode) {
1413b032f27cSSam Leffler case IEEE80211_M_STA:
1414b032f27cSSam Leffler mlmedebug(vap, vap->iv_bss->ni_macaddr, op, reason);
1415b032f27cSSam Leffler /* XXX not quite right */
1416b032f27cSSam Leffler ieee80211_new_state(vap, IEEE80211_S_INIT, reason);
1417b032f27cSSam Leffler break;
1418b032f27cSSam Leffler case IEEE80211_M_HOSTAP:
1419b032f27cSSam Leffler mlmeop.vap = vap;
1420b032f27cSSam Leffler mlmeop.op = op;
1421b032f27cSSam Leffler mlmeop.reason = reason;
1422b032f27cSSam Leffler error = setmlme_dropsta(vap, mac, &mlmeop);
1423b032f27cSSam Leffler break;
1424b032f27cSSam Leffler case IEEE80211_M_WDS:
1425b032f27cSSam Leffler /* XXX user app should send raw frame? */
1426b032f27cSSam Leffler if (op != IEEE80211_MLME_DEAUTH) {
1427b032f27cSSam Leffler error = EINVAL;
1428b032f27cSSam Leffler break;
1429b032f27cSSam Leffler }
1430b032f27cSSam Leffler #if 0
1431b032f27cSSam Leffler /* XXX accept any address, simplifies user code */
1432b032f27cSSam Leffler if (!IEEE80211_ADDR_EQ(mac, vap->iv_bss->ni_macaddr)) {
1433b032f27cSSam Leffler error = EINVAL;
1434b032f27cSSam Leffler break;
1435b032f27cSSam Leffler }
1436b032f27cSSam Leffler #endif
1437b032f27cSSam Leffler mlmedebug(vap, vap->iv_bss->ni_macaddr, op, reason);
1438b032f27cSSam Leffler ni = ieee80211_ref_node(vap->iv_bss);
1439b032f27cSSam Leffler IEEE80211_SEND_MGMT(ni,
1440b032f27cSSam Leffler IEEE80211_FC0_SUBTYPE_DEAUTH, reason);
1441b032f27cSSam Leffler ieee80211_free_node(ni);
1442b032f27cSSam Leffler break;
1443136cb222SAdrian Chadd case IEEE80211_M_MBSS:
1444136cb222SAdrian Chadd IEEE80211_NODE_LOCK(nt);
1445136cb222SAdrian Chadd ni = ieee80211_find_node_locked(nt, mac);
14469984c9baSAdrian Chadd /*
14479984c9baSAdrian Chadd * Don't do the node update inside the node
14489984c9baSAdrian Chadd * table lock. This unfortunately causes LORs
14499984c9baSAdrian Chadd * with drivers and their TX paths.
14509984c9baSAdrian Chadd */
14519984c9baSAdrian Chadd IEEE80211_NODE_UNLOCK(nt);
1452136cb222SAdrian Chadd if (ni != NULL) {
1453136cb222SAdrian Chadd ieee80211_node_leave(ni);
1454136cb222SAdrian Chadd ieee80211_free_node(ni);
1455136cb222SAdrian Chadd } else {
1456136cb222SAdrian Chadd error = ENOENT;
1457136cb222SAdrian Chadd }
1458136cb222SAdrian Chadd break;
1459b032f27cSSam Leffler default:
1460b032f27cSSam Leffler error = EINVAL;
1461b032f27cSSam Leffler break;
1462b032f27cSSam Leffler }
1463b032f27cSSam Leffler break;
1464b032f27cSSam Leffler case IEEE80211_MLME_AUTHORIZE:
1465b032f27cSSam Leffler case IEEE80211_MLME_UNAUTHORIZE:
1466b032f27cSSam Leffler if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1467b032f27cSSam Leffler vap->iv_opmode != IEEE80211_M_WDS) {
1468b032f27cSSam Leffler error = EINVAL;
1469b032f27cSSam Leffler break;
1470b032f27cSSam Leffler }
1471b032f27cSSam Leffler IEEE80211_NODE_LOCK(nt);
1472b032f27cSSam Leffler ni = ieee80211_find_vap_node_locked(nt, vap, mac);
14739984c9baSAdrian Chadd /*
14749984c9baSAdrian Chadd * Don't do the node update inside the node
14759984c9baSAdrian Chadd * table lock. This unfortunately causes LORs
14769984c9baSAdrian Chadd * with drivers and their TX paths.
14779984c9baSAdrian Chadd */
14789984c9baSAdrian Chadd IEEE80211_NODE_UNLOCK(nt);
1479b032f27cSSam Leffler if (ni != NULL) {
1480b032f27cSSam Leffler mlmedebug(vap, mac, op, reason);
1481b032f27cSSam Leffler if (op == IEEE80211_MLME_AUTHORIZE)
1482b032f27cSSam Leffler ieee80211_node_authorize(ni);
1483b032f27cSSam Leffler else
1484b032f27cSSam Leffler ieee80211_node_unauthorize(ni);
1485b032f27cSSam Leffler ieee80211_free_node(ni);
1486b032f27cSSam Leffler } else
1487b032f27cSSam Leffler error = ENOENT;
1488b032f27cSSam Leffler break;
1489b032f27cSSam Leffler case IEEE80211_MLME_AUTH:
1490b032f27cSSam Leffler if (vap->iv_opmode != IEEE80211_M_HOSTAP) {
1491b032f27cSSam Leffler error = EINVAL;
1492b032f27cSSam Leffler break;
1493b032f27cSSam Leffler }
1494b032f27cSSam Leffler IEEE80211_NODE_LOCK(nt);
1495b032f27cSSam Leffler ni = ieee80211_find_vap_node_locked(nt, vap, mac);
14969984c9baSAdrian Chadd /*
14979984c9baSAdrian Chadd * Don't do the node update inside the node
14989984c9baSAdrian Chadd * table lock. This unfortunately causes LORs
14999984c9baSAdrian Chadd * with drivers and their TX paths.
15009984c9baSAdrian Chadd */
15019984c9baSAdrian Chadd IEEE80211_NODE_UNLOCK(nt);
1502b032f27cSSam Leffler if (ni != NULL) {
1503b032f27cSSam Leffler mlmedebug(vap, mac, op, reason);
1504b032f27cSSam Leffler if (reason == IEEE80211_STATUS_SUCCESS) {
1505b032f27cSSam Leffler IEEE80211_SEND_MGMT(ni,
1506b032f27cSSam Leffler IEEE80211_FC0_SUBTYPE_AUTH, 2);
1507b032f27cSSam Leffler /*
1508b032f27cSSam Leffler * For shared key auth, just continue the
1509b032f27cSSam Leffler * exchange. Otherwise when 802.1x is not in
1510b032f27cSSam Leffler * use mark the port authorized at this point
1511b032f27cSSam Leffler * so traffic can flow.
1512b032f27cSSam Leffler */
1513b032f27cSSam Leffler if (ni->ni_authmode != IEEE80211_AUTH_8021X &&
1514b032f27cSSam Leffler ni->ni_challenge == NULL)
1515b032f27cSSam Leffler ieee80211_node_authorize(ni);
1516b032f27cSSam Leffler } else {
1517b032f27cSSam Leffler vap->iv_stats.is_rx_acl++;
1518b032f27cSSam Leffler ieee80211_send_error(ni, ni->ni_macaddr,
1519b032f27cSSam Leffler IEEE80211_FC0_SUBTYPE_AUTH, 2|(reason<<16));
1520b032f27cSSam Leffler ieee80211_node_leave(ni);
1521b032f27cSSam Leffler }
1522b032f27cSSam Leffler ieee80211_free_node(ni);
1523b032f27cSSam Leffler } else
1524b032f27cSSam Leffler error = ENOENT;
1525b032f27cSSam Leffler break;
1526b032f27cSSam Leffler default:
1527b032f27cSSam Leffler error = EINVAL;
1528b032f27cSSam Leffler break;
1529b032f27cSSam Leffler }
1530b032f27cSSam Leffler return error;
15318a1b9b6aSSam Leffler }
15328a1b9b6aSSam Leffler
153368e8e04eSSam Leffler struct scanlookup {
153468e8e04eSSam Leffler const uint8_t *mac;
153568e8e04eSSam Leffler int esslen;
153668e8e04eSSam Leffler const uint8_t *essid;
153768e8e04eSSam Leffler const struct ieee80211_scan_entry *se;
153868e8e04eSSam Leffler };
153968e8e04eSSam Leffler
154068e8e04eSSam Leffler /*
154168e8e04eSSam Leffler * Match mac address and any ssid.
154268e8e04eSSam Leffler */
154368e8e04eSSam Leffler static void
mlmelookup(void * arg,const struct ieee80211_scan_entry * se)154468e8e04eSSam Leffler mlmelookup(void *arg, const struct ieee80211_scan_entry *se)
154568e8e04eSSam Leffler {
154668e8e04eSSam Leffler struct scanlookup *look = arg;
154768e8e04eSSam Leffler
154868e8e04eSSam Leffler if (!IEEE80211_ADDR_EQ(look->mac, se->se_macaddr))
154968e8e04eSSam Leffler return;
155068e8e04eSSam Leffler if (look->esslen != 0) {
155168e8e04eSSam Leffler if (se->se_ssid[1] != look->esslen)
155268e8e04eSSam Leffler return;
155368e8e04eSSam Leffler if (memcmp(look->essid, se->se_ssid+2, look->esslen))
155468e8e04eSSam Leffler return;
155568e8e04eSSam Leffler }
155668e8e04eSSam Leffler look->se = se;
155768e8e04eSSam Leffler }
155868e8e04eSSam Leffler
155974bdb731SAndriy Voskoboinyk static int
setmlme_assoc_sta(struct ieee80211vap * vap,const uint8_t mac[IEEE80211_ADDR_LEN],int ssid_len,const uint8_t ssid[IEEE80211_NWID_LEN])1560632ee7e3SBernhard Schmidt setmlme_assoc_sta(struct ieee80211vap *vap,
1561632ee7e3SBernhard Schmidt const uint8_t mac[IEEE80211_ADDR_LEN], int ssid_len,
1562632ee7e3SBernhard Schmidt const uint8_t ssid[IEEE80211_NWID_LEN])
1563b032f27cSSam Leffler {
1564b032f27cSSam Leffler struct scanlookup lookup;
1565b032f27cSSam Leffler
1566632ee7e3SBernhard Schmidt KASSERT(vap->iv_opmode == IEEE80211_M_STA,
1567632ee7e3SBernhard Schmidt ("expected opmode STA not %s",
1568632ee7e3SBernhard Schmidt ieee80211_opmode_name[vap->iv_opmode]));
1569b032f27cSSam Leffler
1570b032f27cSSam Leffler /* NB: this is racey if roaming is !manual */
1571b032f27cSSam Leffler lookup.se = NULL;
1572b032f27cSSam Leffler lookup.mac = mac;
1573b032f27cSSam Leffler lookup.esslen = ssid_len;
1574b032f27cSSam Leffler lookup.essid = ssid;
1575b032f27cSSam Leffler ieee80211_scan_iterate(vap, mlmelookup, &lookup);
1576b032f27cSSam Leffler if (lookup.se == NULL)
1577b032f27cSSam Leffler return ENOENT;
1578b032f27cSSam Leffler mlmedebug(vap, mac, IEEE80211_MLME_ASSOC, 0);
157910959256SSam Leffler if (!ieee80211_sta_join(vap, lookup.se->se_chan, lookup.se))
1580b032f27cSSam Leffler return EIO; /* XXX unique but could be better */
1581b032f27cSSam Leffler return 0;
1582b032f27cSSam Leffler }
1583b032f27cSSam Leffler
158474bdb731SAndriy Voskoboinyk static int
setmlme_assoc_adhoc(struct ieee80211vap * vap,const uint8_t mac[IEEE80211_ADDR_LEN],int ssid_len,const uint8_t ssid[IEEE80211_NWID_LEN])1585632ee7e3SBernhard Schmidt setmlme_assoc_adhoc(struct ieee80211vap *vap,
1586632ee7e3SBernhard Schmidt const uint8_t mac[IEEE80211_ADDR_LEN], int ssid_len,
1587632ee7e3SBernhard Schmidt const uint8_t ssid[IEEE80211_NWID_LEN])
1588632ee7e3SBernhard Schmidt {
158974bdb731SAndriy Voskoboinyk struct ieee80211_scan_req *sr;
159074bdb731SAndriy Voskoboinyk int error;
1591632ee7e3SBernhard Schmidt
1592632ee7e3SBernhard Schmidt KASSERT(vap->iv_opmode == IEEE80211_M_IBSS ||
1593632ee7e3SBernhard Schmidt vap->iv_opmode == IEEE80211_M_AHDEMO,
1594632ee7e3SBernhard Schmidt ("expected opmode IBSS or AHDEMO not %s",
1595632ee7e3SBernhard Schmidt ieee80211_opmode_name[vap->iv_opmode]));
1596632ee7e3SBernhard Schmidt
15970525ece3SBjoern A. Zeeb if (ssid_len == 0 || ssid_len > IEEE80211_NWID_LEN)
1598632ee7e3SBernhard Schmidt return EINVAL;
1599632ee7e3SBernhard Schmidt
160074bdb731SAndriy Voskoboinyk sr = IEEE80211_MALLOC(sizeof(*sr), M_TEMP,
160174bdb731SAndriy Voskoboinyk IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
160274bdb731SAndriy Voskoboinyk if (sr == NULL)
160374bdb731SAndriy Voskoboinyk return ENOMEM;
160474bdb731SAndriy Voskoboinyk
1605632ee7e3SBernhard Schmidt /* NB: IEEE80211_IOC_SSID call missing for ap_scan=2. */
1606632ee7e3SBernhard Schmidt memset(vap->iv_des_ssid[0].ssid, 0, IEEE80211_NWID_LEN);
1607632ee7e3SBernhard Schmidt vap->iv_des_ssid[0].len = ssid_len;
1608632ee7e3SBernhard Schmidt memcpy(vap->iv_des_ssid[0].ssid, ssid, ssid_len);
1609632ee7e3SBernhard Schmidt vap->iv_des_nssid = 1;
1610632ee7e3SBernhard Schmidt
161174bdb731SAndriy Voskoboinyk sr->sr_flags = IEEE80211_IOC_SCAN_ACTIVE | IEEE80211_IOC_SCAN_ONCE;
161274bdb731SAndriy Voskoboinyk sr->sr_duration = IEEE80211_IOC_SCAN_FOREVER;
161374bdb731SAndriy Voskoboinyk memcpy(sr->sr_ssid[0].ssid, ssid, ssid_len);
161474bdb731SAndriy Voskoboinyk sr->sr_ssid[0].len = ssid_len;
161574bdb731SAndriy Voskoboinyk sr->sr_nssid = 1;
1616632ee7e3SBernhard Schmidt
161774bdb731SAndriy Voskoboinyk error = ieee80211_scanreq(vap, sr);
161874bdb731SAndriy Voskoboinyk
161974bdb731SAndriy Voskoboinyk IEEE80211_FREE(sr, M_TEMP);
162074bdb731SAndriy Voskoboinyk return error;
1621632ee7e3SBernhard Schmidt }
1622632ee7e3SBernhard Schmidt
162374bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setmlme(struct ieee80211vap * vap,struct ieee80211req * ireq)1624b032f27cSSam Leffler ieee80211_ioctl_setmlme(struct ieee80211vap *vap, struct ieee80211req *ireq)
16258a1b9b6aSSam Leffler {
16268a1b9b6aSSam Leffler struct ieee80211req_mlme mlme;
16278a1b9b6aSSam Leffler int error;
16288a1b9b6aSSam Leffler
16298a1b9b6aSSam Leffler if (ireq->i_len != sizeof(mlme))
16308a1b9b6aSSam Leffler return EINVAL;
16318a1b9b6aSSam Leffler error = copyin(ireq->i_data, &mlme, sizeof(mlme));
16328a1b9b6aSSam Leffler if (error)
16338a1b9b6aSSam Leffler return error;
1634632ee7e3SBernhard Schmidt if (vap->iv_opmode == IEEE80211_M_STA &&
1635632ee7e3SBernhard Schmidt mlme.im_op == IEEE80211_MLME_ASSOC)
1636632ee7e3SBernhard Schmidt return setmlme_assoc_sta(vap, mlme.im_macaddr,
1637b032f27cSSam Leffler vap->iv_des_ssid[0].len, vap->iv_des_ssid[0].ssid);
1638edd39a8eSRui Paulo else if ((vap->iv_opmode == IEEE80211_M_IBSS ||
1639edd39a8eSRui Paulo vap->iv_opmode == IEEE80211_M_AHDEMO) &&
1640edd39a8eSRui Paulo mlme.im_op == IEEE80211_MLME_ASSOC)
1641632ee7e3SBernhard Schmidt return setmlme_assoc_adhoc(vap, mlme.im_macaddr,
1642632ee7e3SBernhard Schmidt mlme.im_ssid_len, mlme.im_ssid);
16438a1b9b6aSSam Leffler else
1644b032f27cSSam Leffler return setmlme_common(vap, mlme.im_op,
1645b032f27cSSam Leffler mlme.im_macaddr, mlme.im_reason);
16468a1b9b6aSSam Leffler }
16478a1b9b6aSSam Leffler
164874bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_macmac(struct ieee80211vap * vap,struct ieee80211req * ireq)1649b032f27cSSam Leffler ieee80211_ioctl_macmac(struct ieee80211vap *vap, struct ieee80211req *ireq)
16508a1b9b6aSSam Leffler {
165168e8e04eSSam Leffler uint8_t mac[IEEE80211_ADDR_LEN];
1652b032f27cSSam Leffler const struct ieee80211_aclator *acl = vap->iv_acl;
16538a1b9b6aSSam Leffler int error;
16548a1b9b6aSSam Leffler
16558a1b9b6aSSam Leffler if (ireq->i_len != sizeof(mac))
16568a1b9b6aSSam Leffler return EINVAL;
16578a1b9b6aSSam Leffler error = copyin(ireq->i_data, mac, ireq->i_len);
16588a1b9b6aSSam Leffler if (error)
16598a1b9b6aSSam Leffler return error;
16608a1b9b6aSSam Leffler if (acl == NULL) {
16618a1b9b6aSSam Leffler acl = ieee80211_aclator_get("mac");
1662b032f27cSSam Leffler if (acl == NULL || !acl->iac_attach(vap))
16638a1b9b6aSSam Leffler return EINVAL;
1664b032f27cSSam Leffler vap->iv_acl = acl;
16658a1b9b6aSSam Leffler }
16668a1b9b6aSSam Leffler if (ireq->i_type == IEEE80211_IOC_ADDMAC)
1667b032f27cSSam Leffler acl->iac_add(vap, mac);
16688a1b9b6aSSam Leffler else
1669b032f27cSSam Leffler acl->iac_remove(vap, mac);
16708a1b9b6aSSam Leffler return 0;
16718a1b9b6aSSam Leffler }
16728a1b9b6aSSam Leffler
167374bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setmaccmd(struct ieee80211vap * vap,struct ieee80211req * ireq)1674b032f27cSSam Leffler ieee80211_ioctl_setmaccmd(struct ieee80211vap *vap, struct ieee80211req *ireq)
16758a1b9b6aSSam Leffler {
1676b032f27cSSam Leffler const struct ieee80211_aclator *acl = vap->iv_acl;
16778a1b9b6aSSam Leffler
16788a1b9b6aSSam Leffler switch (ireq->i_val) {
16798a1b9b6aSSam Leffler case IEEE80211_MACCMD_POLICY_OPEN:
16808a1b9b6aSSam Leffler case IEEE80211_MACCMD_POLICY_ALLOW:
16818a1b9b6aSSam Leffler case IEEE80211_MACCMD_POLICY_DENY:
1682b032f27cSSam Leffler case IEEE80211_MACCMD_POLICY_RADIUS:
16838a1b9b6aSSam Leffler if (acl == NULL) {
16848a1b9b6aSSam Leffler acl = ieee80211_aclator_get("mac");
1685b032f27cSSam Leffler if (acl == NULL || !acl->iac_attach(vap))
16868a1b9b6aSSam Leffler return EINVAL;
1687b032f27cSSam Leffler vap->iv_acl = acl;
16888a1b9b6aSSam Leffler }
1689b032f27cSSam Leffler acl->iac_setpolicy(vap, ireq->i_val);
16908a1b9b6aSSam Leffler break;
16918a1b9b6aSSam Leffler case IEEE80211_MACCMD_FLUSH:
16928a1b9b6aSSam Leffler if (acl != NULL)
1693b032f27cSSam Leffler acl->iac_flush(vap);
16948a1b9b6aSSam Leffler /* NB: silently ignore when not in use */
16958a1b9b6aSSam Leffler break;
16968a1b9b6aSSam Leffler case IEEE80211_MACCMD_DETACH:
16978a1b9b6aSSam Leffler if (acl != NULL) {
1698b032f27cSSam Leffler vap->iv_acl = NULL;
1699b032f27cSSam Leffler acl->iac_detach(vap);
17008a1b9b6aSSam Leffler }
17018a1b9b6aSSam Leffler break;
17028a1b9b6aSSam Leffler default:
1703188757f5SSam Leffler if (acl == NULL)
17048a1b9b6aSSam Leffler return EINVAL;
1705188757f5SSam Leffler else
1706b032f27cSSam Leffler return acl->iac_setioctl(vap, ireq);
17078a1b9b6aSSam Leffler }
17088a1b9b6aSSam Leffler return 0;
17098a1b9b6aSSam Leffler }
17108a1b9b6aSSam Leffler
171174bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setchanlist(struct ieee80211vap * vap,struct ieee80211req * ireq)1712b032f27cSSam Leffler ieee80211_ioctl_setchanlist(struct ieee80211vap *vap, struct ieee80211req *ireq)
17138a1b9b6aSSam Leffler {
1714b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
17158658b18bSSam Leffler uint8_t *chanlist, *list;
17168658b18bSSam Leffler int i, nchan, maxchan, error;
17178a1b9b6aSSam Leffler
17188658b18bSSam Leffler if (ireq->i_len > sizeof(ic->ic_chan_active))
17198658b18bSSam Leffler ireq->i_len = sizeof(ic->ic_chan_active);
1720b9b53389SAdrian Chadd list = IEEE80211_MALLOC(ireq->i_len + IEEE80211_CHAN_BYTES, M_TEMP,
1721b9b53389SAdrian Chadd IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
17228658b18bSSam Leffler if (list == NULL)
17238658b18bSSam Leffler return ENOMEM;
17248658b18bSSam Leffler error = copyin(ireq->i_data, list, ireq->i_len);
17257b4d954cSRui Paulo if (error) {
1726b9b53389SAdrian Chadd IEEE80211_FREE(list, M_TEMP);
17278a1b9b6aSSam Leffler return error;
17287b4d954cSRui Paulo }
172968e8e04eSSam Leffler nchan = 0;
17308658b18bSSam Leffler chanlist = list + ireq->i_len; /* NB: zero'd already */
17318658b18bSSam Leffler maxchan = ireq->i_len * NBBY;
173231378b1cSSam Leffler for (i = 0; i < ic->ic_nchans; i++) {
173331378b1cSSam Leffler const struct ieee80211_channel *c = &ic->ic_channels[i];
17348a1b9b6aSSam Leffler /*
173531378b1cSSam Leffler * Calculate the intersection of the user list and the
173631378b1cSSam Leffler * available channels so users can do things like specify
173731378b1cSSam Leffler * 1-255 to get all available channels.
17388a1b9b6aSSam Leffler */
17398658b18bSSam Leffler if (c->ic_ieee < maxchan && isset(list, c->ic_ieee)) {
174031378b1cSSam Leffler setbit(chanlist, c->ic_ieee);
174168e8e04eSSam Leffler nchan++;
17428a1b9b6aSSam Leffler }
17438a1b9b6aSSam Leffler }
17447b4d954cSRui Paulo if (nchan == 0) {
1745b9b53389SAdrian Chadd IEEE80211_FREE(list, M_TEMP);
174668e8e04eSSam Leffler return EINVAL;
17477b4d954cSRui Paulo }
174868e8e04eSSam Leffler if (ic->ic_bsschan != IEEE80211_CHAN_ANYC && /* XXX */
174968e8e04eSSam Leffler isclr(chanlist, ic->ic_bsschan->ic_ieee))
175068e8e04eSSam Leffler ic->ic_bsschan = IEEE80211_CHAN_ANYC;
17518658b18bSSam Leffler memcpy(ic->ic_chan_active, chanlist, IEEE80211_CHAN_BYTES);
1752b032f27cSSam Leffler ieee80211_scan_flush(vap);
1753b9b53389SAdrian Chadd IEEE80211_FREE(list, M_TEMP);
1754b032f27cSSam Leffler return ENETRESET;
17558a1b9b6aSSam Leffler }
17568a1b9b6aSSam Leffler
175774bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setstastats(struct ieee80211vap * vap,struct ieee80211req * ireq)1758b032f27cSSam Leffler ieee80211_ioctl_setstastats(struct ieee80211vap *vap, struct ieee80211req *ireq)
175942568791SSam Leffler {
176042568791SSam Leffler struct ieee80211_node *ni;
176168e8e04eSSam Leffler uint8_t macaddr[IEEE80211_ADDR_LEN];
176242568791SSam Leffler int error;
176342568791SSam Leffler
176442568791SSam Leffler /*
176542568791SSam Leffler * NB: we could copyin ieee80211req_sta_stats so apps
176642568791SSam Leffler * could make selective changes but that's overkill;
176742568791SSam Leffler * just clear all stats for now.
176842568791SSam Leffler */
176942568791SSam Leffler if (ireq->i_len < IEEE80211_ADDR_LEN)
177042568791SSam Leffler return EINVAL;
177142568791SSam Leffler error = copyin(ireq->i_data, macaddr, IEEE80211_ADDR_LEN);
177242568791SSam Leffler if (error != 0)
177342568791SSam Leffler return error;
1774b032f27cSSam Leffler ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, macaddr);
177542568791SSam Leffler if (ni == NULL)
1776b032f27cSSam Leffler return ENOENT;
1777b032f27cSSam Leffler /* XXX require ni_vap == vap? */
177842568791SSam Leffler memset(&ni->ni_stats, 0, sizeof(ni->ni_stats));
177942568791SSam Leffler ieee80211_free_node(ni);
178042568791SSam Leffler return 0;
178142568791SSam Leffler }
178242568791SSam Leffler
178374bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setstatxpow(struct ieee80211vap * vap,struct ieee80211req * ireq)1784b032f27cSSam Leffler ieee80211_ioctl_setstatxpow(struct ieee80211vap *vap, struct ieee80211req *ireq)
17858a1b9b6aSSam Leffler {
17868a1b9b6aSSam Leffler struct ieee80211_node *ni;
17878a1b9b6aSSam Leffler struct ieee80211req_sta_txpow txpow;
17888a1b9b6aSSam Leffler int error;
17898a1b9b6aSSam Leffler
17908a1b9b6aSSam Leffler if (ireq->i_len != sizeof(txpow))
17918a1b9b6aSSam Leffler return EINVAL;
17928a1b9b6aSSam Leffler error = copyin(ireq->i_data, &txpow, sizeof(txpow));
17938a1b9b6aSSam Leffler if (error != 0)
17948a1b9b6aSSam Leffler return error;
1795b032f27cSSam Leffler ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap, txpow.it_macaddr);
17968a1b9b6aSSam Leffler if (ni == NULL)
1797b032f27cSSam Leffler return ENOENT;
17988a1b9b6aSSam Leffler ni->ni_txpower = txpow.it_txpow;
17998a1b9b6aSSam Leffler ieee80211_free_node(ni);
18008a1b9b6aSSam Leffler return error;
18018a1b9b6aSSam Leffler }
18028a1b9b6aSSam Leffler
180374bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setwmeparam(struct ieee80211vap * vap,struct ieee80211req * ireq)1804b032f27cSSam Leffler ieee80211_ioctl_setwmeparam(struct ieee80211vap *vap, struct ieee80211req *ireq)
18058a1b9b6aSSam Leffler {
1806b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
18078a1b9b6aSSam Leffler struct ieee80211_wme_state *wme = &ic->ic_wme;
18088a1b9b6aSSam Leffler struct wmeParams *wmep, *chanp;
1809fa46d9dbSAdrian Chadd int isbss, ac, aggrmode;
18108a1b9b6aSSam Leffler
18118a1b9b6aSSam Leffler if ((ic->ic_caps & IEEE80211_C_WME) == 0)
1812b032f27cSSam Leffler return EOPNOTSUPP;
18138a1b9b6aSSam Leffler
18148a1b9b6aSSam Leffler isbss = (ireq->i_len & IEEE80211_WMEPARAM_BSS);
18158a1b9b6aSSam Leffler ac = (ireq->i_len & IEEE80211_WMEPARAM_VAL);
1816fa46d9dbSAdrian Chadd aggrmode = (wme->wme_flags & WME_F_AGGRMODE);
18178a1b9b6aSSam Leffler if (ac >= WME_NUM_AC)
18188a1b9b6aSSam Leffler ac = WME_AC_BE;
18198a1b9b6aSSam Leffler if (isbss) {
18208a1b9b6aSSam Leffler chanp = &wme->wme_bssChanParams.cap_wmeParams[ac];
18218a1b9b6aSSam Leffler wmep = &wme->wme_wmeBssChanParams.cap_wmeParams[ac];
18228a1b9b6aSSam Leffler } else {
18238a1b9b6aSSam Leffler chanp = &wme->wme_chanParams.cap_wmeParams[ac];
18248a1b9b6aSSam Leffler wmep = &wme->wme_wmeChanParams.cap_wmeParams[ac];
18258a1b9b6aSSam Leffler }
18268a1b9b6aSSam Leffler switch (ireq->i_type) {
18278a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */
18288a1b9b6aSSam Leffler wmep->wmep_logcwmin = ireq->i_val;
1829fa46d9dbSAdrian Chadd if (!isbss || !aggrmode)
18308a1b9b6aSSam Leffler chanp->wmep_logcwmin = ireq->i_val;
18318a1b9b6aSSam Leffler break;
18328a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */
18338a1b9b6aSSam Leffler wmep->wmep_logcwmax = ireq->i_val;
1834fa46d9dbSAdrian Chadd if (!isbss || !aggrmode)
18358a1b9b6aSSam Leffler chanp->wmep_logcwmax = ireq->i_val;
18368a1b9b6aSSam Leffler break;
18378a1b9b6aSSam Leffler case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */
18388a1b9b6aSSam Leffler wmep->wmep_aifsn = ireq->i_val;
1839fa46d9dbSAdrian Chadd if (!isbss || !aggrmode)
18408a1b9b6aSSam Leffler chanp->wmep_aifsn = ireq->i_val;
18418a1b9b6aSSam Leffler break;
18428a1b9b6aSSam Leffler case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */
18438a1b9b6aSSam Leffler wmep->wmep_txopLimit = ireq->i_val;
1844fa46d9dbSAdrian Chadd if (!isbss || !aggrmode)
18458a1b9b6aSSam Leffler chanp->wmep_txopLimit = ireq->i_val;
18468a1b9b6aSSam Leffler break;
18478a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */
18488a1b9b6aSSam Leffler wmep->wmep_acm = ireq->i_val;
1849fa46d9dbSAdrian Chadd if (!aggrmode)
18508a1b9b6aSSam Leffler chanp->wmep_acm = ireq->i_val;
18518a1b9b6aSSam Leffler break;
18528a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only)*/
18538a1b9b6aSSam Leffler wmep->wmep_noackPolicy = chanp->wmep_noackPolicy =
18548a1b9b6aSSam Leffler (ireq->i_val) == 0;
18558a1b9b6aSSam Leffler break;
18568a1b9b6aSSam Leffler }
1857b032f27cSSam Leffler ieee80211_wme_updateparams(vap);
18588a1b9b6aSSam Leffler return 0;
18598a1b9b6aSSam Leffler }
18608a1b9b6aSSam Leffler
18618a1b9b6aSSam Leffler static int
find11gchannel(struct ieee80211com * ic,int start,int freq)186268e8e04eSSam Leffler find11gchannel(struct ieee80211com *ic, int start, int freq)
186368e8e04eSSam Leffler {
186468e8e04eSSam Leffler const struct ieee80211_channel *c;
186568e8e04eSSam Leffler int i;
186668e8e04eSSam Leffler
186768e8e04eSSam Leffler for (i = start+1; i < ic->ic_nchans; i++) {
186868e8e04eSSam Leffler c = &ic->ic_channels[i];
186968e8e04eSSam Leffler if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c))
187068e8e04eSSam Leffler return 1;
187168e8e04eSSam Leffler }
187268e8e04eSSam Leffler /* NB: should not be needed but in case things are mis-sorted */
187368e8e04eSSam Leffler for (i = 0; i < start; i++) {
187468e8e04eSSam Leffler c = &ic->ic_channels[i];
187568e8e04eSSam Leffler if (c->ic_freq == freq && IEEE80211_IS_CHAN_ANYG(c))
187668e8e04eSSam Leffler return 1;
187768e8e04eSSam Leffler }
187868e8e04eSSam Leffler return 0;
187968e8e04eSSam Leffler }
188068e8e04eSSam Leffler
188168e8e04eSSam Leffler static struct ieee80211_channel *
findchannel(struct ieee80211com * ic,int ieee,int mode)188268e8e04eSSam Leffler findchannel(struct ieee80211com *ic, int ieee, int mode)
188368e8e04eSSam Leffler {
188468e8e04eSSam Leffler static const u_int chanflags[IEEE80211_MODE_MAX] = {
1885be0df3e7SSam Leffler [IEEE80211_MODE_AUTO] = 0,
1886be0df3e7SSam Leffler [IEEE80211_MODE_11A] = IEEE80211_CHAN_A,
1887be0df3e7SSam Leffler [IEEE80211_MODE_11B] = IEEE80211_CHAN_B,
1888be0df3e7SSam Leffler [IEEE80211_MODE_11G] = IEEE80211_CHAN_G,
1889be0df3e7SSam Leffler [IEEE80211_MODE_FH] = IEEE80211_CHAN_FHSS,
1890be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_A] = IEEE80211_CHAN_108A,
1891be0df3e7SSam Leffler [IEEE80211_MODE_TURBO_G] = IEEE80211_CHAN_108G,
1892be0df3e7SSam Leffler [IEEE80211_MODE_STURBO_A] = IEEE80211_CHAN_STURBO,
18936a76ae21SSam Leffler [IEEE80211_MODE_HALF] = IEEE80211_CHAN_HALF,
18946a76ae21SSam Leffler [IEEE80211_MODE_QUARTER] = IEEE80211_CHAN_QUARTER,
189568e8e04eSSam Leffler /* NB: handled specially below */
1896be0df3e7SSam Leffler [IEEE80211_MODE_11NA] = IEEE80211_CHAN_A,
1897be0df3e7SSam Leffler [IEEE80211_MODE_11NG] = IEEE80211_CHAN_G,
189835bcfd1cSAdrian Chadd [IEEE80211_MODE_VHT_5GHZ] = IEEE80211_CHAN_A,
189935bcfd1cSAdrian Chadd [IEEE80211_MODE_VHT_2GHZ] = IEEE80211_CHAN_G,
190068e8e04eSSam Leffler };
190168e8e04eSSam Leffler u_int modeflags;
190268e8e04eSSam Leffler int i;
190368e8e04eSSam Leffler
190468e8e04eSSam Leffler modeflags = chanflags[mode];
190568e8e04eSSam Leffler for (i = 0; i < ic->ic_nchans; i++) {
190668e8e04eSSam Leffler struct ieee80211_channel *c = &ic->ic_channels[i];
190768e8e04eSSam Leffler
190868e8e04eSSam Leffler if (c->ic_ieee != ieee)
190968e8e04eSSam Leffler continue;
191068e8e04eSSam Leffler if (mode == IEEE80211_MODE_AUTO) {
191168e8e04eSSam Leffler /* ignore turbo channels for autoselect */
191268e8e04eSSam Leffler if (IEEE80211_IS_CHAN_TURBO(c))
191368e8e04eSSam Leffler continue;
191468e8e04eSSam Leffler /*
191568e8e04eSSam Leffler * XXX special-case 11b/g channels so we
191668e8e04eSSam Leffler * always select the g channel if both
191768e8e04eSSam Leffler * are present.
191868e8e04eSSam Leffler * XXX prefer HT to non-HT?
191968e8e04eSSam Leffler */
192068e8e04eSSam Leffler if (!IEEE80211_IS_CHAN_B(c) ||
192168e8e04eSSam Leffler !find11gchannel(ic, i, c->ic_freq))
192268e8e04eSSam Leffler return c;
192368e8e04eSSam Leffler } else {
192435bcfd1cSAdrian Chadd /* must check VHT specifically */
192535bcfd1cSAdrian Chadd if ((mode == IEEE80211_MODE_VHT_5GHZ ||
192635bcfd1cSAdrian Chadd mode == IEEE80211_MODE_VHT_2GHZ) &&
192735bcfd1cSAdrian Chadd !IEEE80211_IS_CHAN_VHT(c))
192835bcfd1cSAdrian Chadd continue;
192935bcfd1cSAdrian Chadd
193035bcfd1cSAdrian Chadd /*
193135bcfd1cSAdrian Chadd * Must check HT specially - only match on HT,
193235bcfd1cSAdrian Chadd * not HT+VHT channels
193335bcfd1cSAdrian Chadd */
193468e8e04eSSam Leffler if ((mode == IEEE80211_MODE_11NA ||
193568e8e04eSSam Leffler mode == IEEE80211_MODE_11NG) &&
193668e8e04eSSam Leffler !IEEE80211_IS_CHAN_HT(c))
193768e8e04eSSam Leffler continue;
193835bcfd1cSAdrian Chadd
193935bcfd1cSAdrian Chadd if ((mode == IEEE80211_MODE_11NA ||
194035bcfd1cSAdrian Chadd mode == IEEE80211_MODE_11NG) &&
194135bcfd1cSAdrian Chadd IEEE80211_IS_CHAN_VHT(c))
194235bcfd1cSAdrian Chadd continue;
194335bcfd1cSAdrian Chadd
194435bcfd1cSAdrian Chadd /* Check that the modeflags above match */
194568e8e04eSSam Leffler if ((c->ic_flags & modeflags) == modeflags)
194668e8e04eSSam Leffler return c;
194768e8e04eSSam Leffler }
194868e8e04eSSam Leffler }
194968e8e04eSSam Leffler return NULL;
195068e8e04eSSam Leffler }
195168e8e04eSSam Leffler
195268e8e04eSSam Leffler /*
195368e8e04eSSam Leffler * Check the specified against any desired mode (aka netband).
195468e8e04eSSam Leffler * This is only used (presently) when operating in hostap mode
195568e8e04eSSam Leffler * to enforce consistency.
195668e8e04eSSam Leffler */
195768e8e04eSSam Leffler static int
check_mode_consistency(const struct ieee80211_channel * c,int mode)195868e8e04eSSam Leffler check_mode_consistency(const struct ieee80211_channel *c, int mode)
195968e8e04eSSam Leffler {
196068e8e04eSSam Leffler KASSERT(c != IEEE80211_CHAN_ANYC, ("oops, no channel"));
196168e8e04eSSam Leffler
196268e8e04eSSam Leffler switch (mode) {
196368e8e04eSSam Leffler case IEEE80211_MODE_11B:
196468e8e04eSSam Leffler return (IEEE80211_IS_CHAN_B(c));
196568e8e04eSSam Leffler case IEEE80211_MODE_11G:
196668e8e04eSSam Leffler return (IEEE80211_IS_CHAN_ANYG(c) && !IEEE80211_IS_CHAN_HT(c));
196768e8e04eSSam Leffler case IEEE80211_MODE_11A:
196868e8e04eSSam Leffler return (IEEE80211_IS_CHAN_A(c) && !IEEE80211_IS_CHAN_HT(c));
196968e8e04eSSam Leffler case IEEE80211_MODE_STURBO_A:
197068e8e04eSSam Leffler return (IEEE80211_IS_CHAN_STURBO(c));
197168e8e04eSSam Leffler case IEEE80211_MODE_11NA:
197268e8e04eSSam Leffler return (IEEE80211_IS_CHAN_HTA(c));
197368e8e04eSSam Leffler case IEEE80211_MODE_11NG:
197468e8e04eSSam Leffler return (IEEE80211_IS_CHAN_HTG(c));
197568e8e04eSSam Leffler }
197668e8e04eSSam Leffler return 1;
197768e8e04eSSam Leffler
197868e8e04eSSam Leffler }
197968e8e04eSSam Leffler
198068e8e04eSSam Leffler /*
198168e8e04eSSam Leffler * Common code to set the current channel. If the device
198268e8e04eSSam Leffler * is up and running this may result in an immediate channel
198368e8e04eSSam Leffler * change or a kick of the state machine.
198468e8e04eSSam Leffler */
198568e8e04eSSam Leffler static int
setcurchan(struct ieee80211vap * vap,struct ieee80211_channel * c)1986b032f27cSSam Leffler setcurchan(struct ieee80211vap *vap, struct ieee80211_channel *c)
198768e8e04eSSam Leffler {
1988b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
198968e8e04eSSam Leffler int error;
199068e8e04eSSam Leffler
199168e8e04eSSam Leffler if (c != IEEE80211_CHAN_ANYC) {
1992b032f27cSSam Leffler if (IEEE80211_IS_CHAN_RADAR(c))
1993b032f27cSSam Leffler return EBUSY; /* XXX better code? */
1994b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1995b032f27cSSam Leffler if (IEEE80211_IS_CHAN_NOHOSTAP(c))
199668e8e04eSSam Leffler return EINVAL;
1997b032f27cSSam Leffler if (!check_mode_consistency(c, vap->iv_des_mode))
1998b032f27cSSam Leffler return EINVAL;
1999b032f27cSSam Leffler } else if (vap->iv_opmode == IEEE80211_M_IBSS) {
2000b032f27cSSam Leffler if (IEEE80211_IS_CHAN_NOADHOC(c))
2001b032f27cSSam Leffler return EINVAL;
2002b032f27cSSam Leffler }
20031b74d2a4SAdrian Chadd if ((vap->iv_state == IEEE80211_S_RUN || vap->iv_state == IEEE80211_S_SLEEP) &&
2004b032f27cSSam Leffler vap->iv_bss->ni_chan == c)
200568e8e04eSSam Leffler return 0; /* NB: nothing to do */
200668e8e04eSSam Leffler }
2007b032f27cSSam Leffler vap->iv_des_chan = c;
200868e8e04eSSam Leffler
200968e8e04eSSam Leffler error = 0;
2010b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_MONITOR &&
2011b032f27cSSam Leffler vap->iv_des_chan != IEEE80211_CHAN_ANYC) {
201268e8e04eSSam Leffler /*
2013b032f27cSSam Leffler * Monitor mode can switch directly.
201468e8e04eSSam Leffler */
2015b032f27cSSam Leffler if (IFNET_IS_UP_RUNNING(vap->iv_ifp)) {
2016b032f27cSSam Leffler /* XXX need state machine for other vap's to follow */
2017b032f27cSSam Leffler ieee80211_setcurchan(ic, vap->iv_des_chan);
2018b032f27cSSam Leffler vap->iv_bss->ni_chan = ic->ic_curchan;
2019d2ffc7afSPedro F. Giffuni } else {
2020b032f27cSSam Leffler ic->ic_curchan = vap->iv_des_chan;
202126d39e2cSSam Leffler ic->ic_rt = ieee80211_get_ratetable(ic->ic_curchan);
2022d2ffc7afSPedro F. Giffuni }
202368e8e04eSSam Leffler } else {
202468e8e04eSSam Leffler /*
202568e8e04eSSam Leffler * Need to go through the state machine in case we
202668e8e04eSSam Leffler * need to reassociate or the like. The state machine
202768e8e04eSSam Leffler * will pickup the desired channel and avoid scanning.
202868e8e04eSSam Leffler */
2029b032f27cSSam Leffler if (IS_UP_AUTO(vap))
2030b032f27cSSam Leffler ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
2031b032f27cSSam Leffler else if (vap->iv_des_chan != IEEE80211_CHAN_ANYC) {
203268e8e04eSSam Leffler /*
203368e8e04eSSam Leffler * When not up+running and a real channel has
203468e8e04eSSam Leffler * been specified fix the current channel so
203568e8e04eSSam Leffler * there is immediate feedback; e.g. via ifconfig.
203668e8e04eSSam Leffler */
2037b032f27cSSam Leffler ic->ic_curchan = vap->iv_des_chan;
203826d39e2cSSam Leffler ic->ic_rt = ieee80211_get_ratetable(ic->ic_curchan);
203968e8e04eSSam Leffler }
204068e8e04eSSam Leffler }
204168e8e04eSSam Leffler return error;
204268e8e04eSSam Leffler }
204368e8e04eSSam Leffler
204468e8e04eSSam Leffler /*
204568e8e04eSSam Leffler * Old api for setting the current channel; this is
204668e8e04eSSam Leffler * deprecated because channel numbers are ambiguous.
204768e8e04eSSam Leffler */
204874bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setchannel(struct ieee80211vap * vap,const struct ieee80211req * ireq)2049b032f27cSSam Leffler ieee80211_ioctl_setchannel(struct ieee80211vap *vap,
205068e8e04eSSam Leffler const struct ieee80211req *ireq)
205168e8e04eSSam Leffler {
2052b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
205368e8e04eSSam Leffler struct ieee80211_channel *c;
205468e8e04eSSam Leffler
205568e8e04eSSam Leffler /* XXX 0xffff overflows 16-bit signed */
205668e8e04eSSam Leffler if (ireq->i_val == 0 ||
205768e8e04eSSam Leffler ireq->i_val == (int16_t) IEEE80211_CHAN_ANY) {
205868e8e04eSSam Leffler c = IEEE80211_CHAN_ANYC;
205968e8e04eSSam Leffler } else {
206068e8e04eSSam Leffler struct ieee80211_channel *c2;
206168e8e04eSSam Leffler
2062b032f27cSSam Leffler c = findchannel(ic, ireq->i_val, vap->iv_des_mode);
206368e8e04eSSam Leffler if (c == NULL) {
206468e8e04eSSam Leffler c = findchannel(ic, ireq->i_val,
206568e8e04eSSam Leffler IEEE80211_MODE_AUTO);
206668e8e04eSSam Leffler if (c == NULL)
206768e8e04eSSam Leffler return EINVAL;
206868e8e04eSSam Leffler }
206935bcfd1cSAdrian Chadd
207068e8e04eSSam Leffler /*
207168e8e04eSSam Leffler * Fine tune channel selection based on desired mode:
207268e8e04eSSam Leffler * if 11b is requested, find the 11b version of any
207368e8e04eSSam Leffler * 11g channel returned,
207468e8e04eSSam Leffler * if static turbo, find the turbo version of any
207568e8e04eSSam Leffler * 11a channel return,
207668e8e04eSSam Leffler * if 11na is requested, find the ht version of any
207768e8e04eSSam Leffler * 11a channel returned,
207868e8e04eSSam Leffler * if 11ng is requested, find the ht version of any
207968e8e04eSSam Leffler * 11g channel returned,
208035bcfd1cSAdrian Chadd * if 11ac is requested, find the 11ac version
208135bcfd1cSAdrian Chadd * of any 11a/11na channel returned,
208235bcfd1cSAdrian Chadd * (TBD) 11acg (2GHz VHT)
208368e8e04eSSam Leffler * otherwise we should be ok with what we've got.
208468e8e04eSSam Leffler */
2085b032f27cSSam Leffler switch (vap->iv_des_mode) {
208668e8e04eSSam Leffler case IEEE80211_MODE_11B:
208768e8e04eSSam Leffler if (IEEE80211_IS_CHAN_ANYG(c)) {
208868e8e04eSSam Leffler c2 = findchannel(ic, ireq->i_val,
208968e8e04eSSam Leffler IEEE80211_MODE_11B);
209068e8e04eSSam Leffler /* NB: should not happen, =>'s 11g w/o 11b */
209168e8e04eSSam Leffler if (c2 != NULL)
209268e8e04eSSam Leffler c = c2;
209368e8e04eSSam Leffler }
209468e8e04eSSam Leffler break;
209568e8e04eSSam Leffler case IEEE80211_MODE_TURBO_A:
209668e8e04eSSam Leffler if (IEEE80211_IS_CHAN_A(c)) {
209768e8e04eSSam Leffler c2 = findchannel(ic, ireq->i_val,
209868e8e04eSSam Leffler IEEE80211_MODE_TURBO_A);
209968e8e04eSSam Leffler if (c2 != NULL)
210068e8e04eSSam Leffler c = c2;
210168e8e04eSSam Leffler }
210268e8e04eSSam Leffler break;
210368e8e04eSSam Leffler case IEEE80211_MODE_11NA:
210468e8e04eSSam Leffler if (IEEE80211_IS_CHAN_A(c)) {
210568e8e04eSSam Leffler c2 = findchannel(ic, ireq->i_val,
210668e8e04eSSam Leffler IEEE80211_MODE_11NA);
210768e8e04eSSam Leffler if (c2 != NULL)
210868e8e04eSSam Leffler c = c2;
210968e8e04eSSam Leffler }
211068e8e04eSSam Leffler break;
211168e8e04eSSam Leffler case IEEE80211_MODE_11NG:
211268e8e04eSSam Leffler if (IEEE80211_IS_CHAN_ANYG(c)) {
211368e8e04eSSam Leffler c2 = findchannel(ic, ireq->i_val,
211468e8e04eSSam Leffler IEEE80211_MODE_11NG);
211568e8e04eSSam Leffler if (c2 != NULL)
211668e8e04eSSam Leffler c = c2;
211768e8e04eSSam Leffler }
211868e8e04eSSam Leffler break;
211935bcfd1cSAdrian Chadd case IEEE80211_MODE_VHT_2GHZ:
212035bcfd1cSAdrian Chadd printf("%s: TBD\n", __func__);
212135bcfd1cSAdrian Chadd break;
212235bcfd1cSAdrian Chadd case IEEE80211_MODE_VHT_5GHZ:
212335bcfd1cSAdrian Chadd if (IEEE80211_IS_CHAN_A(c)) {
212435bcfd1cSAdrian Chadd c2 = findchannel(ic, ireq->i_val,
212535bcfd1cSAdrian Chadd IEEE80211_MODE_VHT_5GHZ);
212635bcfd1cSAdrian Chadd if (c2 != NULL)
212735bcfd1cSAdrian Chadd c = c2;
212835bcfd1cSAdrian Chadd }
212935bcfd1cSAdrian Chadd break;
213068e8e04eSSam Leffler default: /* NB: no static turboG */
213168e8e04eSSam Leffler break;
213268e8e04eSSam Leffler }
213368e8e04eSSam Leffler }
2134b032f27cSSam Leffler return setcurchan(vap, c);
213568e8e04eSSam Leffler }
213668e8e04eSSam Leffler
213768e8e04eSSam Leffler /*
213868e8e04eSSam Leffler * New/current api for setting the current channel; a complete
213968e8e04eSSam Leffler * channel description is provide so there is no ambiguity in
214068e8e04eSSam Leffler * identifying the channel.
214168e8e04eSSam Leffler */
214274bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setcurchan(struct ieee80211vap * vap,const struct ieee80211req * ireq)2143b032f27cSSam Leffler ieee80211_ioctl_setcurchan(struct ieee80211vap *vap,
214468e8e04eSSam Leffler const struct ieee80211req *ireq)
214568e8e04eSSam Leffler {
2146b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
214768e8e04eSSam Leffler struct ieee80211_channel chan, *c;
214868e8e04eSSam Leffler int error;
214968e8e04eSSam Leffler
215068e8e04eSSam Leffler if (ireq->i_len != sizeof(chan))
215168e8e04eSSam Leffler return EINVAL;
215268e8e04eSSam Leffler error = copyin(ireq->i_data, &chan, sizeof(chan));
215368e8e04eSSam Leffler if (error != 0)
215468e8e04eSSam Leffler return error;
215535bcfd1cSAdrian Chadd
215668e8e04eSSam Leffler /* XXX 0xffff overflows 16-bit signed */
215768e8e04eSSam Leffler if (chan.ic_freq == 0 || chan.ic_freq == IEEE80211_CHAN_ANY) {
215868e8e04eSSam Leffler c = IEEE80211_CHAN_ANYC;
215968e8e04eSSam Leffler } else {
216068e8e04eSSam Leffler c = ieee80211_find_channel(ic, chan.ic_freq, chan.ic_flags);
216168e8e04eSSam Leffler if (c == NULL)
216268e8e04eSSam Leffler return EINVAL;
216368e8e04eSSam Leffler }
2164b032f27cSSam Leffler return setcurchan(vap, c);
2165b032f27cSSam Leffler }
2166b032f27cSSam Leffler
216774bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setregdomain(struct ieee80211vap * vap,const struct ieee80211req * ireq)2168b032f27cSSam Leffler ieee80211_ioctl_setregdomain(struct ieee80211vap *vap,
2169b032f27cSSam Leffler const struct ieee80211req *ireq)
2170b032f27cSSam Leffler {
2171b032f27cSSam Leffler struct ieee80211_regdomain_req *reg;
21728658b18bSSam Leffler int nchans, error;
2173b032f27cSSam Leffler
21748658b18bSSam Leffler nchans = 1 + ((ireq->i_len - sizeof(struct ieee80211_regdomain_req)) /
21758658b18bSSam Leffler sizeof(struct ieee80211_channel));
21768658b18bSSam Leffler if (!(1 <= nchans && nchans <= IEEE80211_CHAN_MAX)) {
21778658b18bSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_IOCTL,
21788658b18bSSam Leffler "%s: bad # chans, i_len %d nchans %d\n", __func__,
21798658b18bSSam Leffler ireq->i_len, nchans);
2180b032f27cSSam Leffler return EINVAL;
21818658b18bSSam Leffler }
21828658b18bSSam Leffler reg = (struct ieee80211_regdomain_req *)
2183b9b53389SAdrian Chadd IEEE80211_MALLOC(IEEE80211_REGDOMAIN_SIZE(nchans), M_TEMP,
2184b9b53389SAdrian Chadd IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
21858658b18bSSam Leffler if (reg == NULL) {
21868658b18bSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_IOCTL,
21878658b18bSSam Leffler "%s: no memory, nchans %d\n", __func__, nchans);
2188b032f27cSSam Leffler return ENOMEM;
21898658b18bSSam Leffler }
21908658b18bSSam Leffler error = copyin(ireq->i_data, reg, IEEE80211_REGDOMAIN_SIZE(nchans));
21918658b18bSSam Leffler if (error == 0) {
21928658b18bSSam Leffler /* NB: validate inline channel count against storage size */
21938658b18bSSam Leffler if (reg->chaninfo.ic_nchans != nchans) {
21948658b18bSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_IOCTL,
21958658b18bSSam Leffler "%s: chan cnt mismatch, %d != %d\n", __func__,
21968658b18bSSam Leffler reg->chaninfo.ic_nchans, nchans);
21978658b18bSSam Leffler error = EINVAL;
21988658b18bSSam Leffler } else
2199b032f27cSSam Leffler error = ieee80211_setregdomain(vap, reg);
22008658b18bSSam Leffler }
2201b9b53389SAdrian Chadd IEEE80211_FREE(reg, M_TEMP);
2202b032f27cSSam Leffler
2203b032f27cSSam Leffler return (error == 0 ? ENETRESET : error);
220468e8e04eSSam Leffler }
220568e8e04eSSam Leffler
220668e8e04eSSam Leffler static int
checkrate(const struct ieee80211_rateset * rs,int rate)2207b032f27cSSam Leffler checkrate(const struct ieee80211_rateset *rs, int rate)
2208b032f27cSSam Leffler {
2209b032f27cSSam Leffler int i;
2210b032f27cSSam Leffler
2211b032f27cSSam Leffler if (rate == IEEE80211_FIXED_RATE_NONE)
2212b032f27cSSam Leffler return 1;
2213b032f27cSSam Leffler for (i = 0; i < rs->rs_nrates; i++)
2214b032f27cSSam Leffler if ((rs->rs_rates[i] & IEEE80211_RATE_VAL) == rate)
2215b032f27cSSam Leffler return 1;
2216b032f27cSSam Leffler return 0;
2217b032f27cSSam Leffler }
2218b032f27cSSam Leffler
2219b032f27cSSam Leffler static int
checkmcs(const struct ieee80211_htrateset * rs,int mcs)2220dfabbaa0SAndriy Voskoboinyk checkmcs(const struct ieee80211_htrateset *rs, int mcs)
2221b032f27cSSam Leffler {
2222dfabbaa0SAndriy Voskoboinyk int rate_val = IEEE80211_RV(mcs);
2223dfabbaa0SAndriy Voskoboinyk int i;
2224dfabbaa0SAndriy Voskoboinyk
2225b032f27cSSam Leffler if (mcs == IEEE80211_FIXED_RATE_NONE)
2226b032f27cSSam Leffler return 1;
2227b032f27cSSam Leffler if ((mcs & IEEE80211_RATE_MCS) == 0) /* MCS always have 0x80 set */
2228b032f27cSSam Leffler return 0;
2229dfabbaa0SAndriy Voskoboinyk for (i = 0; i < rs->rs_nrates; i++)
2230dfabbaa0SAndriy Voskoboinyk if (IEEE80211_RV(rs->rs_rates[i]) == rate_val)
2231dfabbaa0SAndriy Voskoboinyk return 1;
2232dfabbaa0SAndriy Voskoboinyk return 0;
2233b032f27cSSam Leffler }
2234b032f27cSSam Leffler
223574bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setroam(struct ieee80211vap * vap,const struct ieee80211req * ireq)2236545619f3SAndriy Voskoboinyk ieee80211_ioctl_setroam(struct ieee80211vap *vap,
2237545619f3SAndriy Voskoboinyk const struct ieee80211req *ireq)
2238545619f3SAndriy Voskoboinyk {
2239545619f3SAndriy Voskoboinyk struct ieee80211com *ic = vap->iv_ic;
2240545619f3SAndriy Voskoboinyk struct ieee80211_roamparams_req *parms;
2241545619f3SAndriy Voskoboinyk struct ieee80211_roamparam *src, *dst;
2242545619f3SAndriy Voskoboinyk const struct ieee80211_htrateset *rs_ht;
2243545619f3SAndriy Voskoboinyk const struct ieee80211_rateset *rs;
2244545619f3SAndriy Voskoboinyk int changed, error, mode, is11n, nmodes;
2245545619f3SAndriy Voskoboinyk
2246545619f3SAndriy Voskoboinyk if (ireq->i_len != sizeof(vap->iv_roamparms))
2247545619f3SAndriy Voskoboinyk return EINVAL;
2248545619f3SAndriy Voskoboinyk
2249545619f3SAndriy Voskoboinyk parms = IEEE80211_MALLOC(sizeof(*parms), M_TEMP,
2250545619f3SAndriy Voskoboinyk IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
2251545619f3SAndriy Voskoboinyk if (parms == NULL)
2252545619f3SAndriy Voskoboinyk return ENOMEM;
2253545619f3SAndriy Voskoboinyk
2254545619f3SAndriy Voskoboinyk error = copyin(ireq->i_data, parms, ireq->i_len);
2255545619f3SAndriy Voskoboinyk if (error != 0)
2256545619f3SAndriy Voskoboinyk goto fail;
2257545619f3SAndriy Voskoboinyk
2258545619f3SAndriy Voskoboinyk changed = 0;
2259545619f3SAndriy Voskoboinyk nmodes = IEEE80211_MODE_MAX;
2260545619f3SAndriy Voskoboinyk
2261545619f3SAndriy Voskoboinyk /* validate parameters and check if anything changed */
2262545619f3SAndriy Voskoboinyk for (mode = IEEE80211_MODE_11A; mode < nmodes; mode++) {
2263545619f3SAndriy Voskoboinyk if (isclr(ic->ic_modecaps, mode))
2264545619f3SAndriy Voskoboinyk continue;
2265545619f3SAndriy Voskoboinyk src = &parms->params[mode];
2266545619f3SAndriy Voskoboinyk dst = &vap->iv_roamparms[mode];
2267545619f3SAndriy Voskoboinyk rs = &ic->ic_sup_rates[mode]; /* NB: 11n maps to legacy */
2268545619f3SAndriy Voskoboinyk rs_ht = &ic->ic_sup_htrates;
2269545619f3SAndriy Voskoboinyk is11n = (mode == IEEE80211_MODE_11NA ||
2270545619f3SAndriy Voskoboinyk mode == IEEE80211_MODE_11NG);
2271545619f3SAndriy Voskoboinyk /* XXX TODO: 11ac */
2272545619f3SAndriy Voskoboinyk if (src->rate != dst->rate) {
2273545619f3SAndriy Voskoboinyk if (!checkrate(rs, src->rate) &&
2274545619f3SAndriy Voskoboinyk (!is11n || !checkmcs(rs_ht, src->rate))) {
2275545619f3SAndriy Voskoboinyk error = EINVAL;
2276545619f3SAndriy Voskoboinyk goto fail;
2277545619f3SAndriy Voskoboinyk }
2278545619f3SAndriy Voskoboinyk changed++;
2279545619f3SAndriy Voskoboinyk }
2280545619f3SAndriy Voskoboinyk if (src->rssi != dst->rssi)
2281545619f3SAndriy Voskoboinyk changed++;
2282545619f3SAndriy Voskoboinyk }
2283545619f3SAndriy Voskoboinyk if (changed) {
2284545619f3SAndriy Voskoboinyk /*
2285545619f3SAndriy Voskoboinyk * Copy new parameters in place and notify the
2286545619f3SAndriy Voskoboinyk * driver so it can push state to the device.
2287545619f3SAndriy Voskoboinyk */
2288545619f3SAndriy Voskoboinyk /* XXX locking? */
2289545619f3SAndriy Voskoboinyk for (mode = IEEE80211_MODE_11A; mode < nmodes; mode++) {
2290545619f3SAndriy Voskoboinyk if (isset(ic->ic_modecaps, mode))
2291545619f3SAndriy Voskoboinyk vap->iv_roamparms[mode] = parms->params[mode];
2292545619f3SAndriy Voskoboinyk }
2293545619f3SAndriy Voskoboinyk
2294545619f3SAndriy Voskoboinyk if (vap->iv_roaming == IEEE80211_ROAMING_DEVICE)
2295545619f3SAndriy Voskoboinyk error = ERESTART;
2296545619f3SAndriy Voskoboinyk }
2297545619f3SAndriy Voskoboinyk
2298545619f3SAndriy Voskoboinyk fail: IEEE80211_FREE(parms, M_TEMP);
2299545619f3SAndriy Voskoboinyk return error;
2300545619f3SAndriy Voskoboinyk }
2301545619f3SAndriy Voskoboinyk
2302545619f3SAndriy Voskoboinyk static int
ieee80211_ioctl_settxparams(struct ieee80211vap * vap,const struct ieee80211req * ireq)2303b032f27cSSam Leffler ieee80211_ioctl_settxparams(struct ieee80211vap *vap,
2304b032f27cSSam Leffler const struct ieee80211req *ireq)
2305b032f27cSSam Leffler {
2306b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
2307b032f27cSSam Leffler struct ieee80211_txparams_req parms; /* XXX stack use? */
2308b032f27cSSam Leffler struct ieee80211_txparam *src, *dst;
2309dfabbaa0SAndriy Voskoboinyk const struct ieee80211_htrateset *rs_ht;
2310b032f27cSSam Leffler const struct ieee80211_rateset *rs;
2311cbb24c24SSam Leffler int error, mode, changed, is11n, nmodes;
2312b032f27cSSam Leffler
2313cbb24c24SSam Leffler /* NB: accept short requests for backwards compat */
2314cbb24c24SSam Leffler if (ireq->i_len > sizeof(parms))
2315b032f27cSSam Leffler return EINVAL;
2316cbb24c24SSam Leffler error = copyin(ireq->i_data, &parms, ireq->i_len);
2317b032f27cSSam Leffler if (error != 0)
2318b032f27cSSam Leffler return error;
2319cbb24c24SSam Leffler nmodes = ireq->i_len / sizeof(struct ieee80211_txparam);
2320b032f27cSSam Leffler changed = 0;
2321b032f27cSSam Leffler /* validate parameters and check if anything changed */
2322cbb24c24SSam Leffler for (mode = IEEE80211_MODE_11A; mode < nmodes; mode++) {
2323cbb24c24SSam Leffler if (isclr(ic->ic_modecaps, mode))
2324b032f27cSSam Leffler continue;
2325cbb24c24SSam Leffler src = &parms.params[mode];
2326cbb24c24SSam Leffler dst = &vap->iv_txparms[mode];
2327cbb24c24SSam Leffler rs = &ic->ic_sup_rates[mode]; /* NB: 11n maps to legacy */
2328dfabbaa0SAndriy Voskoboinyk rs_ht = &ic->ic_sup_htrates;
2329cbb24c24SSam Leffler is11n = (mode == IEEE80211_MODE_11NA ||
2330cbb24c24SSam Leffler mode == IEEE80211_MODE_11NG);
2331b032f27cSSam Leffler if (src->ucastrate != dst->ucastrate) {
2332cbb24c24SSam Leffler if (!checkrate(rs, src->ucastrate) &&
2333dfabbaa0SAndriy Voskoboinyk (!is11n || !checkmcs(rs_ht, src->ucastrate)))
2334b032f27cSSam Leffler return EINVAL;
2335b032f27cSSam Leffler changed++;
2336b032f27cSSam Leffler }
2337b032f27cSSam Leffler if (src->mcastrate != dst->mcastrate) {
2338cbb24c24SSam Leffler if (!checkrate(rs, src->mcastrate) &&
2339dfabbaa0SAndriy Voskoboinyk (!is11n || !checkmcs(rs_ht, src->mcastrate)))
2340b032f27cSSam Leffler return EINVAL;
2341b032f27cSSam Leffler changed++;
2342b032f27cSSam Leffler }
2343b032f27cSSam Leffler if (src->mgmtrate != dst->mgmtrate) {
2344cbb24c24SSam Leffler if (!checkrate(rs, src->mgmtrate) &&
2345dfabbaa0SAndriy Voskoboinyk (!is11n || !checkmcs(rs_ht, src->mgmtrate)))
2346b032f27cSSam Leffler return EINVAL;
2347b032f27cSSam Leffler changed++;
2348b032f27cSSam Leffler }
2349b032f27cSSam Leffler if (src->maxretry != dst->maxretry) /* NB: no bounds */
2350b032f27cSSam Leffler changed++;
2351b032f27cSSam Leffler }
2352b032f27cSSam Leffler if (changed) {
2353b032f27cSSam Leffler /*
2354b032f27cSSam Leffler * Copy new parameters in place and notify the
2355b032f27cSSam Leffler * driver so it can push state to the device.
2356b032f27cSSam Leffler */
2357cbb24c24SSam Leffler for (mode = IEEE80211_MODE_11A; mode < nmodes; mode++) {
2358cbb24c24SSam Leffler if (isset(ic->ic_modecaps, mode))
2359cbb24c24SSam Leffler vap->iv_txparms[mode] = parms.params[mode];
2360b032f27cSSam Leffler }
2361b032f27cSSam Leffler /* XXX could be more intelligent,
2362b032f27cSSam Leffler e.g. don't reset if setting not being used */
2363b032f27cSSam Leffler return ENETRESET;
2364b032f27cSSam Leffler }
2365b032f27cSSam Leffler return 0;
2366b032f27cSSam Leffler }
2367b032f27cSSam Leffler
2368b032f27cSSam Leffler /*
2369b032f27cSSam Leffler * Application Information Element support.
2370b032f27cSSam Leffler */
2371b032f27cSSam Leffler static int
setappie(struct ieee80211_appie ** aie,const struct ieee80211req * ireq)2372b032f27cSSam Leffler setappie(struct ieee80211_appie **aie, const struct ieee80211req *ireq)
2373b032f27cSSam Leffler {
2374b032f27cSSam Leffler struct ieee80211_appie *app = *aie;
2375b032f27cSSam Leffler struct ieee80211_appie *napp;
2376b032f27cSSam Leffler int error;
2377b032f27cSSam Leffler
2378b032f27cSSam Leffler if (ireq->i_len == 0) { /* delete any existing ie */
2379b032f27cSSam Leffler if (app != NULL) {
2380b032f27cSSam Leffler *aie = NULL; /* XXX racey */
2381b9b53389SAdrian Chadd IEEE80211_FREE(app, M_80211_NODE_IE);
2382b032f27cSSam Leffler }
2383b032f27cSSam Leffler return 0;
2384b032f27cSSam Leffler }
2385b032f27cSSam Leffler if (!(2 <= ireq->i_len && ireq->i_len <= IEEE80211_MAX_APPIE))
2386b032f27cSSam Leffler return EINVAL;
2387b032f27cSSam Leffler /*
2388b032f27cSSam Leffler * Allocate a new appie structure and copy in the user data.
2389b032f27cSSam Leffler * When done swap in the new structure. Note that we do not
2390b032f27cSSam Leffler * guard against users holding a ref to the old structure;
2391b032f27cSSam Leffler * this must be handled outside this code.
2392b032f27cSSam Leffler *
2393b032f27cSSam Leffler * XXX bad bad bad
2394b032f27cSSam Leffler */
2395b9b53389SAdrian Chadd napp = (struct ieee80211_appie *) IEEE80211_MALLOC(
2396b9b53389SAdrian Chadd sizeof(struct ieee80211_appie) + ireq->i_len, M_80211_NODE_IE,
2397b9b53389SAdrian Chadd IEEE80211_M_NOWAIT);
2398b032f27cSSam Leffler if (napp == NULL)
2399b032f27cSSam Leffler return ENOMEM;
2400b032f27cSSam Leffler /* XXX holding ic lock */
2401b032f27cSSam Leffler error = copyin(ireq->i_data, napp->ie_data, ireq->i_len);
2402b032f27cSSam Leffler if (error) {
2403b9b53389SAdrian Chadd IEEE80211_FREE(napp, M_80211_NODE_IE);
2404b032f27cSSam Leffler return error;
2405b032f27cSSam Leffler }
2406b032f27cSSam Leffler napp->ie_len = ireq->i_len;
2407b032f27cSSam Leffler *aie = napp;
2408b032f27cSSam Leffler if (app != NULL)
2409b9b53389SAdrian Chadd IEEE80211_FREE(app, M_80211_NODE_IE);
2410b032f27cSSam Leffler return 0;
2411b032f27cSSam Leffler }
2412b032f27cSSam Leffler
2413b032f27cSSam Leffler static void
setwparsnie(struct ieee80211vap * vap,uint8_t * ie,int space)2414b032f27cSSam Leffler setwparsnie(struct ieee80211vap *vap, uint8_t *ie, int space)
2415b032f27cSSam Leffler {
2416b032f27cSSam Leffler /* validate data is present as best we can */
2417b032f27cSSam Leffler if (space == 0 || 2+ie[1] > space)
2418b032f27cSSam Leffler return;
2419b032f27cSSam Leffler if (ie[0] == IEEE80211_ELEMID_VENDOR)
2420b032f27cSSam Leffler vap->iv_wpa_ie = ie;
2421b032f27cSSam Leffler else if (ie[0] == IEEE80211_ELEMID_RSN)
2422b032f27cSSam Leffler vap->iv_rsn_ie = ie;
2423b032f27cSSam Leffler }
2424b032f27cSSam Leffler
242574bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setappie_locked(struct ieee80211vap * vap,const struct ieee80211req * ireq,int fc0)2426b032f27cSSam Leffler ieee80211_ioctl_setappie_locked(struct ieee80211vap *vap,
2427b032f27cSSam Leffler const struct ieee80211req *ireq, int fc0)
2428b032f27cSSam Leffler {
2429b032f27cSSam Leffler int error;
2430b032f27cSSam Leffler
2431b032f27cSSam Leffler IEEE80211_LOCK_ASSERT(vap->iv_ic);
2432b032f27cSSam Leffler
2433b032f27cSSam Leffler switch (fc0 & IEEE80211_FC0_SUBTYPE_MASK) {
2434b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_BEACON:
2435b032f27cSSam Leffler if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
2436b032f27cSSam Leffler vap->iv_opmode != IEEE80211_M_IBSS) {
2437b032f27cSSam Leffler error = EINVAL;
2438b032f27cSSam Leffler break;
2439b032f27cSSam Leffler }
2440b032f27cSSam Leffler error = setappie(&vap->iv_appie_beacon, ireq);
2441b032f27cSSam Leffler if (error == 0)
2442b032f27cSSam Leffler ieee80211_beacon_notify(vap, IEEE80211_BEACON_APPIE);
2443b032f27cSSam Leffler break;
2444b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
2445b032f27cSSam Leffler error = setappie(&vap->iv_appie_proberesp, ireq);
2446b032f27cSSam Leffler break;
2447b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
2448b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_HOSTAP)
2449b032f27cSSam Leffler error = setappie(&vap->iv_appie_assocresp, ireq);
2450b032f27cSSam Leffler else
2451b032f27cSSam Leffler error = EINVAL;
2452b032f27cSSam Leffler break;
2453b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_PROBE_REQ:
2454b032f27cSSam Leffler error = setappie(&vap->iv_appie_probereq, ireq);
2455b032f27cSSam Leffler break;
2456b032f27cSSam Leffler case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
2457b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_STA)
2458b032f27cSSam Leffler error = setappie(&vap->iv_appie_assocreq, ireq);
2459b032f27cSSam Leffler else
2460b032f27cSSam Leffler error = EINVAL;
2461b032f27cSSam Leffler break;
2462b032f27cSSam Leffler case (IEEE80211_APPIE_WPA & IEEE80211_FC0_SUBTYPE_MASK):
2463b032f27cSSam Leffler error = setappie(&vap->iv_appie_wpa, ireq);
2464b032f27cSSam Leffler if (error == 0) {
2465b032f27cSSam Leffler /*
2466b032f27cSSam Leffler * Must split single blob of data into separate
2467b032f27cSSam Leffler * WPA and RSN ie's because they go in different
2468b032f27cSSam Leffler * locations in the mgt frames.
2469b032f27cSSam Leffler * XXX use IEEE80211_IOC_WPA2 so user code does split
2470b032f27cSSam Leffler */
2471b032f27cSSam Leffler vap->iv_wpa_ie = NULL;
2472b032f27cSSam Leffler vap->iv_rsn_ie = NULL;
2473b032f27cSSam Leffler if (vap->iv_appie_wpa != NULL) {
2474b032f27cSSam Leffler struct ieee80211_appie *appie =
2475b032f27cSSam Leffler vap->iv_appie_wpa;
2476b032f27cSSam Leffler uint8_t *data = appie->ie_data;
2477b032f27cSSam Leffler
2478b032f27cSSam Leffler /* XXX ie length validate is painful, cheat */
2479b032f27cSSam Leffler setwparsnie(vap, data, appie->ie_len);
2480b032f27cSSam Leffler setwparsnie(vap, data + 2 + data[1],
2481b032f27cSSam Leffler appie->ie_len - (2 + data[1]));
2482b032f27cSSam Leffler }
2483b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_HOSTAP ||
2484b032f27cSSam Leffler vap->iv_opmode == IEEE80211_M_IBSS) {
2485b032f27cSSam Leffler /*
2486b032f27cSSam Leffler * Must rebuild beacon frame as the update
2487b032f27cSSam Leffler * mechanism doesn't handle WPA/RSN ie's.
2488b032f27cSSam Leffler * Could extend it but it doesn't normally
2489b032f27cSSam Leffler * change; this is just to deal with hostapd
2490b032f27cSSam Leffler * plumbing the ie after the interface is up.
2491b032f27cSSam Leffler */
2492b032f27cSSam Leffler error = ENETRESET;
2493b032f27cSSam Leffler }
2494b032f27cSSam Leffler }
2495b032f27cSSam Leffler break;
2496b032f27cSSam Leffler default:
2497b032f27cSSam Leffler error = EINVAL;
2498b032f27cSSam Leffler break;
2499b032f27cSSam Leffler }
2500b032f27cSSam Leffler return error;
2501b032f27cSSam Leffler }
2502b032f27cSSam Leffler
250374bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setappie(struct ieee80211vap * vap,const struct ieee80211req * ireq)2504b032f27cSSam Leffler ieee80211_ioctl_setappie(struct ieee80211vap *vap,
2505b032f27cSSam Leffler const struct ieee80211req *ireq)
2506b032f27cSSam Leffler {
2507b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
2508b032f27cSSam Leffler int error;
2509b032f27cSSam Leffler uint8_t fc0;
2510b032f27cSSam Leffler
2511b032f27cSSam Leffler fc0 = ireq->i_val & 0xff;
2512b032f27cSSam Leffler if ((fc0 & IEEE80211_FC0_TYPE_MASK) != IEEE80211_FC0_TYPE_MGT)
2513b032f27cSSam Leffler return EINVAL;
2514b032f27cSSam Leffler /* NB: could check iv_opmode and reject but hardly worth the effort */
2515b032f27cSSam Leffler IEEE80211_LOCK(ic);
2516b032f27cSSam Leffler error = ieee80211_ioctl_setappie_locked(vap, ireq, fc0);
2517b032f27cSSam Leffler IEEE80211_UNLOCK(ic);
2518b032f27cSSam Leffler return error;
2519b032f27cSSam Leffler }
2520b032f27cSSam Leffler
252174bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_chanswitch(struct ieee80211vap * vap,struct ieee80211req * ireq)2522b032f27cSSam Leffler ieee80211_ioctl_chanswitch(struct ieee80211vap *vap, struct ieee80211req *ireq)
2523b032f27cSSam Leffler {
2524b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
2525b032f27cSSam Leffler struct ieee80211_chanswitch_req csr;
2526b032f27cSSam Leffler struct ieee80211_channel *c;
2527b032f27cSSam Leffler int error;
2528b032f27cSSam Leffler
2529b032f27cSSam Leffler if (ireq->i_len != sizeof(csr))
2530b032f27cSSam Leffler return EINVAL;
2531b032f27cSSam Leffler error = copyin(ireq->i_data, &csr, sizeof(csr));
2532b032f27cSSam Leffler if (error != 0)
2533b032f27cSSam Leffler return error;
2534c70761e6SSam Leffler /* XXX adhoc mode not supported */
2535c70761e6SSam Leffler if (vap->iv_opmode != IEEE80211_M_HOSTAP ||
2536c70761e6SSam Leffler (vap->iv_flags & IEEE80211_F_DOTH) == 0)
2537c70761e6SSam Leffler return EOPNOTSUPP;
2538b032f27cSSam Leffler c = ieee80211_find_channel(ic,
2539b032f27cSSam Leffler csr.csa_chan.ic_freq, csr.csa_chan.ic_flags);
2540b032f27cSSam Leffler if (c == NULL)
2541b032f27cSSam Leffler return ENOENT;
2542b032f27cSSam Leffler IEEE80211_LOCK(ic);
2543b032f27cSSam Leffler if ((ic->ic_flags & IEEE80211_F_CSAPENDING) == 0)
2544b032f27cSSam Leffler ieee80211_csa_startswitch(ic, c, csr.csa_mode, csr.csa_count);
2545c70761e6SSam Leffler else if (csr.csa_count == 0)
2546c70761e6SSam Leffler ieee80211_csa_cancelswitch(ic);
2547b032f27cSSam Leffler else
2548b032f27cSSam Leffler error = EBUSY;
2549b032f27cSSam Leffler IEEE80211_UNLOCK(ic);
2550b032f27cSSam Leffler return error;
2551b032f27cSSam Leffler }
2552b032f27cSSam Leffler
2553632ee7e3SBernhard Schmidt static int
ieee80211_scanreq(struct ieee80211vap * vap,struct ieee80211_scan_req * sr)2554632ee7e3SBernhard Schmidt ieee80211_scanreq(struct ieee80211vap *vap, struct ieee80211_scan_req *sr)
2555b032f27cSSam Leffler {
2556b032f27cSSam Leffler #define IEEE80211_IOC_SCAN_FLAGS \
2557b032f27cSSam Leffler (IEEE80211_IOC_SCAN_NOPICK | IEEE80211_IOC_SCAN_ACTIVE | \
2558b032f27cSSam Leffler IEEE80211_IOC_SCAN_PICK1ST | IEEE80211_IOC_SCAN_BGSCAN | \
2559b032f27cSSam Leffler IEEE80211_IOC_SCAN_ONCE | IEEE80211_IOC_SCAN_NOBCAST | \
2560b032f27cSSam Leffler IEEE80211_IOC_SCAN_NOJOIN | IEEE80211_IOC_SCAN_FLUSH | \
2561b032f27cSSam Leffler IEEE80211_IOC_SCAN_CHECK)
2562b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
25637ca7a42cSBernhard Schmidt int error, i;
2564b032f27cSSam Leffler
2565b032f27cSSam Leffler /* convert duration */
2566632ee7e3SBernhard Schmidt if (sr->sr_duration == IEEE80211_IOC_SCAN_FOREVER)
2567632ee7e3SBernhard Schmidt sr->sr_duration = IEEE80211_SCAN_FOREVER;
2568b032f27cSSam Leffler else {
2569632ee7e3SBernhard Schmidt if (sr->sr_duration < IEEE80211_IOC_SCAN_DURATION_MIN ||
2570632ee7e3SBernhard Schmidt sr->sr_duration > IEEE80211_IOC_SCAN_DURATION_MAX)
2571b032f27cSSam Leffler return EINVAL;
2572632ee7e3SBernhard Schmidt sr->sr_duration = msecs_to_ticks(sr->sr_duration);
2573b032f27cSSam Leffler }
2574b032f27cSSam Leffler /* convert min/max channel dwell */
25759df9e936SAndriy Voskoboinyk if (sr->sr_mindwell != 0)
2576632ee7e3SBernhard Schmidt sr->sr_mindwell = msecs_to_ticks(sr->sr_mindwell);
25779df9e936SAndriy Voskoboinyk if (sr->sr_maxdwell != 0)
2578632ee7e3SBernhard Schmidt sr->sr_maxdwell = msecs_to_ticks(sr->sr_maxdwell);
2579b032f27cSSam Leffler /* NB: silently reduce ssid count to what is supported */
2580632ee7e3SBernhard Schmidt if (sr->sr_nssid > IEEE80211_SCAN_MAX_SSID)
2581632ee7e3SBernhard Schmidt sr->sr_nssid = IEEE80211_SCAN_MAX_SSID;
2582632ee7e3SBernhard Schmidt for (i = 0; i < sr->sr_nssid; i++)
2583632ee7e3SBernhard Schmidt if (sr->sr_ssid[i].len > IEEE80211_NWID_LEN)
2584b032f27cSSam Leffler return EINVAL;
2585b032f27cSSam Leffler /* cleanse flags just in case, could reject if invalid flags */
2586632ee7e3SBernhard Schmidt sr->sr_flags &= IEEE80211_IOC_SCAN_FLAGS;
2587b032f27cSSam Leffler /*
2588b032f27cSSam Leffler * Add an implicit NOPICK if the vap is not marked UP. This
2589b032f27cSSam Leffler * allows applications to scan without joining a bss (or picking
2590b032f27cSSam Leffler * a channel and setting up a bss) and without forcing manual
2591b032f27cSSam Leffler * roaming mode--you just need to mark the parent device UP.
2592b032f27cSSam Leffler */
2593b032f27cSSam Leffler if ((vap->iv_ifp->if_flags & IFF_UP) == 0)
2594632ee7e3SBernhard Schmidt sr->sr_flags |= IEEE80211_IOC_SCAN_NOPICK;
2595b032f27cSSam Leffler
2596b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN,
259733396ec2SBjoern A. Zeeb "%s: vap %p iv_state %#x (%s) flags 0x%x%s "
259833396ec2SBjoern A. Zeeb "duration 0x%x mindwell %u maxdwell %u nssid %d\n",
259933396ec2SBjoern A. Zeeb __func__, vap, vap->iv_state, ieee80211_state_name[vap->iv_state],
260033396ec2SBjoern A. Zeeb sr->sr_flags,
2601b032f27cSSam Leffler (vap->iv_ifp->if_flags & IFF_UP) == 0 ? " (!IFF_UP)" : "",
2602632ee7e3SBernhard Schmidt sr->sr_duration, sr->sr_mindwell, sr->sr_maxdwell, sr->sr_nssid);
2603b032f27cSSam Leffler /*
2604b032f27cSSam Leffler * If we are in INIT state then the driver has never had a chance
2605b032f27cSSam Leffler * to setup hardware state to do a scan; we must use the state
2606b032f27cSSam Leffler * machine to get us up to the SCAN state but once we reach SCAN
2607b032f27cSSam Leffler * state we then want to use the supplied params. Stash the
2608b032f27cSSam Leffler * parameters in the vap and mark IEEE80211_FEXT_SCANREQ; the
2609b032f27cSSam Leffler * state machines will recognize this and use the stashed params
2610b032f27cSSam Leffler * to issue the scan request.
2611b032f27cSSam Leffler *
2612b032f27cSSam Leffler * Otherwise just invoke the scan machinery directly.
2613b032f27cSSam Leffler */
2614b032f27cSSam Leffler IEEE80211_LOCK(ic);
2615f20503faSAndriy Voskoboinyk if (ic->ic_nrunning == 0) {
2616f20503faSAndriy Voskoboinyk IEEE80211_UNLOCK(ic);
2617f20503faSAndriy Voskoboinyk return ENXIO;
2618f20503faSAndriy Voskoboinyk }
2619f20503faSAndriy Voskoboinyk
2620b032f27cSSam Leffler if (vap->iv_state == IEEE80211_S_INIT) {
2621b032f27cSSam Leffler /* NB: clobbers previous settings */
2622632ee7e3SBernhard Schmidt vap->iv_scanreq_flags = sr->sr_flags;
2623632ee7e3SBernhard Schmidt vap->iv_scanreq_duration = sr->sr_duration;
2624632ee7e3SBernhard Schmidt vap->iv_scanreq_nssid = sr->sr_nssid;
2625632ee7e3SBernhard Schmidt for (i = 0; i < sr->sr_nssid; i++) {
2626632ee7e3SBernhard Schmidt vap->iv_scanreq_ssid[i].len = sr->sr_ssid[i].len;
2627632ee7e3SBernhard Schmidt memcpy(vap->iv_scanreq_ssid[i].ssid,
2628632ee7e3SBernhard Schmidt sr->sr_ssid[i].ssid, sr->sr_ssid[i].len);
2629b032f27cSSam Leffler }
2630b032f27cSSam Leffler vap->iv_flags_ext |= IEEE80211_FEXT_SCANREQ;
2631b032f27cSSam Leffler IEEE80211_UNLOCK(ic);
2632b032f27cSSam Leffler ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
2633b032f27cSSam Leffler } else {
2634b032f27cSSam Leffler vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANREQ;
2635b032f27cSSam Leffler IEEE80211_UNLOCK(ic);
2636632ee7e3SBernhard Schmidt if (sr->sr_flags & IEEE80211_IOC_SCAN_CHECK) {
26377ca7a42cSBernhard Schmidt error = ieee80211_check_scan(vap, sr->sr_flags,
2638632ee7e3SBernhard Schmidt sr->sr_duration, sr->sr_mindwell, sr->sr_maxdwell,
2639632ee7e3SBernhard Schmidt sr->sr_nssid,
2640b032f27cSSam Leffler /* NB: cheat, we assume structures are compatible */
2641632ee7e3SBernhard Schmidt (const struct ieee80211_scan_ssid *) &sr->sr_ssid[0]);
2642b032f27cSSam Leffler } else {
26437ca7a42cSBernhard Schmidt error = ieee80211_start_scan(vap, sr->sr_flags,
2644632ee7e3SBernhard Schmidt sr->sr_duration, sr->sr_mindwell, sr->sr_maxdwell,
2645632ee7e3SBernhard Schmidt sr->sr_nssid,
2646b032f27cSSam Leffler /* NB: cheat, we assume structures are compatible */
2647632ee7e3SBernhard Schmidt (const struct ieee80211_scan_ssid *) &sr->sr_ssid[0]);
2648b032f27cSSam Leffler }
26497ca7a42cSBernhard Schmidt if (error == 0)
26507ca7a42cSBernhard Schmidt return EINPROGRESS;
2651b032f27cSSam Leffler }
2652632ee7e3SBernhard Schmidt return 0;
2653b032f27cSSam Leffler #undef IEEE80211_IOC_SCAN_FLAGS
2654b032f27cSSam Leffler }
2655b032f27cSSam Leffler
265674bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_scanreq(struct ieee80211vap * vap,struct ieee80211req * ireq)2657632ee7e3SBernhard Schmidt ieee80211_ioctl_scanreq(struct ieee80211vap *vap, struct ieee80211req *ireq)
2658632ee7e3SBernhard Schmidt {
265974bdb731SAndriy Voskoboinyk struct ieee80211_scan_req *sr;
2660632ee7e3SBernhard Schmidt int error;
2661632ee7e3SBernhard Schmidt
266274bdb731SAndriy Voskoboinyk if (ireq->i_len != sizeof(*sr))
2663632ee7e3SBernhard Schmidt return EINVAL;
266474bdb731SAndriy Voskoboinyk sr = IEEE80211_MALLOC(sizeof(*sr), M_TEMP,
266574bdb731SAndriy Voskoboinyk IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
266674bdb731SAndriy Voskoboinyk if (sr == NULL)
266774bdb731SAndriy Voskoboinyk return ENOMEM;
266874bdb731SAndriy Voskoboinyk error = copyin(ireq->i_data, sr, sizeof(*sr));
2669632ee7e3SBernhard Schmidt if (error != 0)
267074bdb731SAndriy Voskoboinyk goto bad;
267174bdb731SAndriy Voskoboinyk error = ieee80211_scanreq(vap, sr);
267274bdb731SAndriy Voskoboinyk bad:
267374bdb731SAndriy Voskoboinyk IEEE80211_FREE(sr, M_TEMP);
2674632ee7e3SBernhard Schmidt return error;
2675632ee7e3SBernhard Schmidt }
2676632ee7e3SBernhard Schmidt
267774bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_setstavlan(struct ieee80211vap * vap,struct ieee80211req * ireq)2678b032f27cSSam Leffler ieee80211_ioctl_setstavlan(struct ieee80211vap *vap, struct ieee80211req *ireq)
2679b032f27cSSam Leffler {
2680b032f27cSSam Leffler struct ieee80211_node *ni;
2681b032f27cSSam Leffler struct ieee80211req_sta_vlan vlan;
2682b032f27cSSam Leffler int error;
2683b032f27cSSam Leffler
2684b032f27cSSam Leffler if (ireq->i_len != sizeof(vlan))
2685b032f27cSSam Leffler return EINVAL;
2686b032f27cSSam Leffler error = copyin(ireq->i_data, &vlan, sizeof(vlan));
2687b032f27cSSam Leffler if (error != 0)
2688b032f27cSSam Leffler return error;
2689b032f27cSSam Leffler if (!IEEE80211_ADDR_EQ(vlan.sv_macaddr, zerobssid)) {
2690b032f27cSSam Leffler ni = ieee80211_find_vap_node(&vap->iv_ic->ic_sta, vap,
2691b032f27cSSam Leffler vlan.sv_macaddr);
2692b032f27cSSam Leffler if (ni == NULL)
2693b032f27cSSam Leffler return ENOENT;
2694b032f27cSSam Leffler } else
2695b032f27cSSam Leffler ni = ieee80211_ref_node(vap->iv_bss);
2696b032f27cSSam Leffler ni->ni_vlan = vlan.sv_vlan;
2697b032f27cSSam Leffler ieee80211_free_node(ni);
2698b032f27cSSam Leffler return error;
2699b032f27cSSam Leffler }
2700b032f27cSSam Leffler
2701b032f27cSSam Leffler static int
isvap11g(const struct ieee80211vap * vap)2702b032f27cSSam Leffler isvap11g(const struct ieee80211vap *vap)
2703b032f27cSSam Leffler {
2704b032f27cSSam Leffler const struct ieee80211_node *bss = vap->iv_bss;
2705b032f27cSSam Leffler return bss->ni_chan != IEEE80211_CHAN_ANYC &&
2706b032f27cSSam Leffler IEEE80211_IS_CHAN_ANYG(bss->ni_chan);
2707b032f27cSSam Leffler }
2708b032f27cSSam Leffler
2709b032f27cSSam Leffler static int
isvapht(const struct ieee80211vap * vap)2710b032f27cSSam Leffler isvapht(const struct ieee80211vap *vap)
2711b032f27cSSam Leffler {
2712b032f27cSSam Leffler const struct ieee80211_node *bss = vap->iv_bss;
2713b032f27cSSam Leffler return bss->ni_chan != IEEE80211_CHAN_ANYC &&
2714b032f27cSSam Leffler IEEE80211_IS_CHAN_HT(bss->ni_chan);
2715b032f27cSSam Leffler }
2716b032f27cSSam Leffler
27178c4e758aSSam Leffler /*
27188c4e758aSSam Leffler * Dummy ioctl set handler so the linker set is defined.
27198c4e758aSSam Leffler */
27208c4e758aSSam Leffler static int
dummy_ioctl_set(struct ieee80211vap * vap,struct ieee80211req * ireq)27218c4e758aSSam Leffler dummy_ioctl_set(struct ieee80211vap *vap, struct ieee80211req *ireq)
27228c4e758aSSam Leffler {
27238c4e758aSSam Leffler return ENOSYS;
27248c4e758aSSam Leffler }
27258c4e758aSSam Leffler IEEE80211_IOCTL_SET(dummy, dummy_ioctl_set);
27268c4e758aSSam Leffler
27278c4e758aSSam Leffler static int
ieee80211_ioctl_setdefault(struct ieee80211vap * vap,struct ieee80211req * ireq)27288c4e758aSSam Leffler ieee80211_ioctl_setdefault(struct ieee80211vap *vap, struct ieee80211req *ireq)
27298c4e758aSSam Leffler {
27308c4e758aSSam Leffler ieee80211_ioctl_setfunc * const *set;
27318c4e758aSSam Leffler int error;
27328c4e758aSSam Leffler
27338c4e758aSSam Leffler SET_FOREACH(set, ieee80211_ioctl_setset) {
27348c4e758aSSam Leffler error = (*set)(vap, ireq);
27358c4e758aSSam Leffler if (error != ENOSYS)
27368c4e758aSSam Leffler return error;
27378c4e758aSSam Leffler }
27388c4e758aSSam Leffler return EINVAL;
27398c4e758aSSam Leffler }
27408c4e758aSSam Leffler
274174bdb731SAndriy Voskoboinyk static int
ieee80211_ioctl_set80211(struct ieee80211vap * vap,u_long cmd,struct ieee80211req * ireq)2742b032f27cSSam Leffler ieee80211_ioctl_set80211(struct ieee80211vap *vap, u_long cmd, struct ieee80211req *ireq)
2743b032f27cSSam Leffler {
2744b032f27cSSam Leffler struct ieee80211com *ic = vap->iv_ic;
27458a1b9b6aSSam Leffler int error;
27468a1b9b6aSSam Leffler const struct ieee80211_authenticator *auth;
274768e8e04eSSam Leffler uint8_t tmpkey[IEEE80211_KEYBUF_SIZE];
27488a1b9b6aSSam Leffler char tmpssid[IEEE80211_NWID_LEN];
274968e8e04eSSam Leffler uint8_t tmpbssid[IEEE80211_ADDR_LEN];
27508a1b9b6aSSam Leffler struct ieee80211_key *k;
27518a1b9b6aSSam Leffler u_int kid;
27523dfff737SWarner Losh uint32_t flags;
27538a1b9b6aSSam Leffler
27548a1b9b6aSSam Leffler error = 0;
27551a1e1d21SSam Leffler switch (ireq->i_type) {
27561a1e1d21SSam Leffler case IEEE80211_IOC_SSID:
27571a1e1d21SSam Leffler if (ireq->i_val != 0 ||
27588a1b9b6aSSam Leffler ireq->i_len > IEEE80211_NWID_LEN)
27598a1b9b6aSSam Leffler return EINVAL;
27601a1e1d21SSam Leffler error = copyin(ireq->i_data, tmpssid, ireq->i_len);
27611a1e1d21SSam Leffler if (error)
27621a1e1d21SSam Leffler break;
2763b032f27cSSam Leffler memset(vap->iv_des_ssid[0].ssid, 0, IEEE80211_NWID_LEN);
2764b032f27cSSam Leffler vap->iv_des_ssid[0].len = ireq->i_len;
2765b032f27cSSam Leffler memcpy(vap->iv_des_ssid[0].ssid, tmpssid, ireq->i_len);
2766b032f27cSSam Leffler vap->iv_des_nssid = (ireq->i_len > 0);
2767b032f27cSSam Leffler error = ENETRESET;
27681a1e1d21SSam Leffler break;
27691a1e1d21SSam Leffler case IEEE80211_IOC_WEP:
27708a1b9b6aSSam Leffler switch (ireq->i_val) {
27718a1b9b6aSSam Leffler case IEEE80211_WEP_OFF:
2772b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_PRIVACY;
2773b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_DROPUNENC;
27748a1b9b6aSSam Leffler break;
27758a1b9b6aSSam Leffler case IEEE80211_WEP_ON:
2776b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_PRIVACY;
2777b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_DROPUNENC;
27788a1b9b6aSSam Leffler break;
27798a1b9b6aSSam Leffler case IEEE80211_WEP_MIXED:
2780b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_PRIVACY;
2781b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_DROPUNENC;
27828a1b9b6aSSam Leffler break;
27831a1e1d21SSam Leffler }
2784b032f27cSSam Leffler error = ENETRESET;
27851a1e1d21SSam Leffler break;
27861a1e1d21SSam Leffler case IEEE80211_IOC_WEPKEY:
27871a1e1d21SSam Leffler kid = (u_int) ireq->i_val;
27888a1b9b6aSSam Leffler if (kid >= IEEE80211_WEP_NKID)
27898a1b9b6aSSam Leffler return EINVAL;
2790b032f27cSSam Leffler k = &vap->iv_nw_keys[kid];
27918a1b9b6aSSam Leffler if (ireq->i_len == 0) {
27928a1b9b6aSSam Leffler /* zero-len =>'s delete any existing key */
2793b032f27cSSam Leffler (void) ieee80211_crypto_delkey(vap, k);
27941a1e1d21SSam Leffler break;
27951a1e1d21SSam Leffler }
27968a1b9b6aSSam Leffler if (ireq->i_len > sizeof(tmpkey))
27978a1b9b6aSSam Leffler return EINVAL;
27981a1e1d21SSam Leffler memset(tmpkey, 0, sizeof(tmpkey));
27991a1e1d21SSam Leffler error = copyin(ireq->i_data, tmpkey, ireq->i_len);
28001a1e1d21SSam Leffler if (error)
28011a1e1d21SSam Leffler break;
2802b032f27cSSam Leffler ieee80211_key_update_begin(vap);
2803dd70e17bSSam Leffler k->wk_keyix = kid; /* NB: force fixed key id */
2804b032f27cSSam Leffler if (ieee80211_crypto_newkey(vap, IEEE80211_CIPHER_WEP,
2805dd70e17bSSam Leffler IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV, k)) {
28068a1b9b6aSSam Leffler k->wk_keylen = ireq->i_len;
28078a1b9b6aSSam Leffler memcpy(k->wk_key, tmpkey, sizeof(tmpkey));
280871fe06caSSam Leffler IEEE80211_ADDR_COPY(k->wk_macaddr, vap->iv_myaddr);
280971fe06caSSam Leffler if (!ieee80211_crypto_setkey(vap, k))
28108a1b9b6aSSam Leffler error = EINVAL;
28118a1b9b6aSSam Leffler } else
28128a1b9b6aSSam Leffler error = EINVAL;
2813b032f27cSSam Leffler ieee80211_key_update_end(vap);
28141a1e1d21SSam Leffler break;
28151a1e1d21SSam Leffler case IEEE80211_IOC_WEPTXKEY:
28161a1e1d21SSam Leffler kid = (u_int) ireq->i_val;
2817380c5fa9SSam Leffler if (kid >= IEEE80211_WEP_NKID &&
281868e8e04eSSam Leffler (uint16_t) kid != IEEE80211_KEYIX_NONE)
28198a1b9b6aSSam Leffler return EINVAL;
2820781487cfSAdrian Chadd /*
2821781487cfSAdrian Chadd * Firmware devices may need to be told about an explicit
2822781487cfSAdrian Chadd * key index here, versus just inferring it from the
2823781487cfSAdrian Chadd * key set / change. Since we may also need to pause
2824781487cfSAdrian Chadd * things like transmit before the key is updated,
2825781487cfSAdrian Chadd * give the driver a chance to flush things by tying
2826781487cfSAdrian Chadd * into key update begin/end.
2827781487cfSAdrian Chadd */
2828781487cfSAdrian Chadd ieee80211_key_update_begin(vap);
2829781487cfSAdrian Chadd ieee80211_crypto_set_deftxkey(vap, kid);
2830781487cfSAdrian Chadd ieee80211_key_update_end(vap);
28318a1b9b6aSSam Leffler break;
28328a1b9b6aSSam Leffler case IEEE80211_IOC_AUTHMODE:
28338a1b9b6aSSam Leffler switch (ireq->i_val) {
28348a1b9b6aSSam Leffler case IEEE80211_AUTH_WPA:
28358a1b9b6aSSam Leffler case IEEE80211_AUTH_8021X: /* 802.1x */
28368a1b9b6aSSam Leffler case IEEE80211_AUTH_OPEN: /* open */
28378a1b9b6aSSam Leffler case IEEE80211_AUTH_SHARED: /* shared-key */
28388a1b9b6aSSam Leffler case IEEE80211_AUTH_AUTO: /* auto */
28398a1b9b6aSSam Leffler auth = ieee80211_authenticator_get(ireq->i_val);
28408a1b9b6aSSam Leffler if (auth == NULL)
28418a1b9b6aSSam Leffler return EINVAL;
28428a1b9b6aSSam Leffler break;
28438a1b9b6aSSam Leffler default:
28448a1b9b6aSSam Leffler return EINVAL;
28458a1b9b6aSSam Leffler }
28468a1b9b6aSSam Leffler switch (ireq->i_val) {
28478a1b9b6aSSam Leffler case IEEE80211_AUTH_WPA: /* WPA w/ 802.1x */
2848b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_PRIVACY;
28498a1b9b6aSSam Leffler ireq->i_val = IEEE80211_AUTH_8021X;
28508a1b9b6aSSam Leffler break;
28518a1b9b6aSSam Leffler case IEEE80211_AUTH_OPEN: /* open */
2852b032f27cSSam Leffler vap->iv_flags &= ~(IEEE80211_F_WPA|IEEE80211_F_PRIVACY);
28538a1b9b6aSSam Leffler break;
28548a1b9b6aSSam Leffler case IEEE80211_AUTH_SHARED: /* shared-key */
28558a1b9b6aSSam Leffler case IEEE80211_AUTH_8021X: /* 802.1x */
2856b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_WPA;
28578a1b9b6aSSam Leffler /* both require a key so mark the PRIVACY capability */
2858b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_PRIVACY;
28598a1b9b6aSSam Leffler break;
28608a1b9b6aSSam Leffler case IEEE80211_AUTH_AUTO: /* auto */
2861b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_WPA;
28628a1b9b6aSSam Leffler /* XXX PRIVACY handling? */
28638a1b9b6aSSam Leffler /* XXX what's the right way to do this? */
28641a1e1d21SSam Leffler break;
28651a1e1d21SSam Leffler }
28668a1b9b6aSSam Leffler /* NB: authenticator attach/detach happens on state change */
2867b032f27cSSam Leffler vap->iv_bss->ni_authmode = ireq->i_val;
28688a1b9b6aSSam Leffler /* XXX mixed/mode/usage? */
2869b032f27cSSam Leffler vap->iv_auth = auth;
2870b032f27cSSam Leffler error = ENETRESET;
28711a1e1d21SSam Leffler break;
28721a1e1d21SSam Leffler case IEEE80211_IOC_CHANNEL:
2873b032f27cSSam Leffler error = ieee80211_ioctl_setchannel(vap, ireq);
28741a1e1d21SSam Leffler break;
28751a1e1d21SSam Leffler case IEEE80211_IOC_POWERSAVE:
28761a1e1d21SSam Leffler switch (ireq->i_val) {
28771a1e1d21SSam Leffler case IEEE80211_POWERSAVE_OFF:
2878b032f27cSSam Leffler if (vap->iv_flags & IEEE80211_F_PMGTON) {
2879b032f27cSSam Leffler ieee80211_syncflag(vap, -IEEE80211_F_PMGTON);
2880b032f27cSSam Leffler error = ERESTART;
28811a1e1d21SSam Leffler }
28821a1e1d21SSam Leffler break;
28831a1e1d21SSam Leffler case IEEE80211_POWERSAVE_ON:
2884b032f27cSSam Leffler if ((vap->iv_caps & IEEE80211_C_PMGT) == 0)
2885b032f27cSSam Leffler error = EOPNOTSUPP;
2886b032f27cSSam Leffler else if ((vap->iv_flags & IEEE80211_F_PMGTON) == 0) {
2887b032f27cSSam Leffler ieee80211_syncflag(vap, IEEE80211_F_PMGTON);
2888b032f27cSSam Leffler error = ERESTART;
28891a1e1d21SSam Leffler }
28901a1e1d21SSam Leffler break;
28911a1e1d21SSam Leffler default:
28921a1e1d21SSam Leffler error = EINVAL;
28931a1e1d21SSam Leffler break;
28941a1e1d21SSam Leffler }
28951a1e1d21SSam Leffler break;
28961a1e1d21SSam Leffler case IEEE80211_IOC_POWERSAVESLEEP:
28978a1b9b6aSSam Leffler if (ireq->i_val < 0)
28988a1b9b6aSSam Leffler return EINVAL;
28991a1e1d21SSam Leffler ic->ic_lintval = ireq->i_val;
2900b032f27cSSam Leffler error = ERESTART;
29011a1e1d21SSam Leffler break;
290213604e6bSSam Leffler case IEEE80211_IOC_RTSTHRESHOLD:
290370231e3dSSam Leffler if (!(IEEE80211_RTS_MIN <= ireq->i_val &&
290470231e3dSSam Leffler ireq->i_val <= IEEE80211_RTS_MAX))
29058a1b9b6aSSam Leffler return EINVAL;
2906b032f27cSSam Leffler vap->iv_rtsthreshold = ireq->i_val;
2907b032f27cSSam Leffler error = ERESTART;
29081a1e1d21SSam Leffler break;
29092e79ca97SSam Leffler case IEEE80211_IOC_PROTMODE:
29108a1b9b6aSSam Leffler if (ireq->i_val > IEEE80211_PROT_RTSCTS)
29118a1b9b6aSSam Leffler return EINVAL;
2912f1481c8dSAdrian Chadd vap->iv_protmode = (enum ieee80211_protmode)ireq->i_val;
29132e79ca97SSam Leffler /* NB: if not operating in 11g this can wait */
291468e8e04eSSam Leffler if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
291568e8e04eSSam Leffler IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
2916b032f27cSSam Leffler error = ERESTART;
2917f1481c8dSAdrian Chadd /* driver callback for protection mode update */
2918f1481c8dSAdrian Chadd ieee80211_vap_update_erp_protmode(vap);
29192e79ca97SSam Leffler break;
29202e79ca97SSam Leffler case IEEE80211_IOC_TXPOWER:
29218a1b9b6aSSam Leffler if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0)
2922b032f27cSSam Leffler return EOPNOTSUPP;
292368e8e04eSSam Leffler if (!(IEEE80211_TXPOWER_MIN <= ireq->i_val &&
292468e8e04eSSam Leffler ireq->i_val <= IEEE80211_TXPOWER_MAX))
29258a1b9b6aSSam Leffler return EINVAL;
29268a1b9b6aSSam Leffler ic->ic_txpowlimit = ireq->i_val;
2927b032f27cSSam Leffler error = ERESTART;
29288a1b9b6aSSam Leffler break;
29298a1b9b6aSSam Leffler case IEEE80211_IOC_ROAMING:
29308a1b9b6aSSam Leffler if (!(IEEE80211_ROAMING_DEVICE <= ireq->i_val &&
29318a1b9b6aSSam Leffler ireq->i_val <= IEEE80211_ROAMING_MANUAL))
29328a1b9b6aSSam Leffler return EINVAL;
2933fcd9500fSBernhard Schmidt vap->iv_roaming = (enum ieee80211_roamingmode)ireq->i_val;
29348a1b9b6aSSam Leffler /* XXXX reset? */
29358a1b9b6aSSam Leffler break;
29368a1b9b6aSSam Leffler case IEEE80211_IOC_PRIVACY:
29378a1b9b6aSSam Leffler if (ireq->i_val) {
29388a1b9b6aSSam Leffler /* XXX check for key state? */
2939b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_PRIVACY;
29408a1b9b6aSSam Leffler } else
2941b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_PRIVACY;
2942b032f27cSSam Leffler /* XXX ERESTART? */
29438a1b9b6aSSam Leffler break;
29448a1b9b6aSSam Leffler case IEEE80211_IOC_DROPUNENCRYPTED:
29458a1b9b6aSSam Leffler if (ireq->i_val)
2946b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_DROPUNENC;
29478a1b9b6aSSam Leffler else
2948b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_DROPUNENC;
2949b032f27cSSam Leffler /* XXX ERESTART? */
29508a1b9b6aSSam Leffler break;
29518a1b9b6aSSam Leffler case IEEE80211_IOC_WPAKEY:
2952b032f27cSSam Leffler error = ieee80211_ioctl_setkey(vap, ireq);
29538a1b9b6aSSam Leffler break;
29548a1b9b6aSSam Leffler case IEEE80211_IOC_DELKEY:
2955b032f27cSSam Leffler error = ieee80211_ioctl_delkey(vap, ireq);
29568a1b9b6aSSam Leffler break;
29578a1b9b6aSSam Leffler case IEEE80211_IOC_MLME:
2958b032f27cSSam Leffler error = ieee80211_ioctl_setmlme(vap, ireq);
29598a1b9b6aSSam Leffler break;
29608a1b9b6aSSam Leffler case IEEE80211_IOC_COUNTERMEASURES:
29618a1b9b6aSSam Leffler if (ireq->i_val) {
2962b032f27cSSam Leffler if ((vap->iv_flags & IEEE80211_F_WPA) == 0)
2963b032f27cSSam Leffler return EOPNOTSUPP;
2964b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_COUNTERM;
29658a1b9b6aSSam Leffler } else
2966b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_COUNTERM;
2967b032f27cSSam Leffler /* XXX ERESTART? */
29688a1b9b6aSSam Leffler break;
29698a1b9b6aSSam Leffler case IEEE80211_IOC_WPA:
29708a1b9b6aSSam Leffler if (ireq->i_val > 3)
29718a1b9b6aSSam Leffler return EINVAL;
29728a1b9b6aSSam Leffler /* XXX verify ciphers available */
29733dfff737SWarner Losh flags = vap->iv_flags & ~IEEE80211_F_WPA;
29748a1b9b6aSSam Leffler switch (ireq->i_val) {
297591356585SAdrian Chadd case 0:
297691356585SAdrian Chadd /* wpa_supplicant calls this to clear the WPA config */
297791356585SAdrian Chadd break;
29788a1b9b6aSSam Leffler case 1:
29793dfff737SWarner Losh if (!(vap->iv_caps & IEEE80211_C_WPA1))
29803dfff737SWarner Losh return EOPNOTSUPP;
29813dfff737SWarner Losh flags |= IEEE80211_F_WPA1;
29828a1b9b6aSSam Leffler break;
29838a1b9b6aSSam Leffler case 2:
29843dfff737SWarner Losh if (!(vap->iv_caps & IEEE80211_C_WPA2))
29853dfff737SWarner Losh return EOPNOTSUPP;
29863dfff737SWarner Losh flags |= IEEE80211_F_WPA2;
29878a1b9b6aSSam Leffler break;
29888a1b9b6aSSam Leffler case 3:
29893dfff737SWarner Losh if ((vap->iv_caps & IEEE80211_C_WPA) != IEEE80211_C_WPA)
29908d092df9SSam Leffler return EOPNOTSUPP;
29913dfff737SWarner Losh flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2;
29922e79ca97SSam Leffler break;
29933dfff737SWarner Losh default: /* Can't set any -> error */
29943dfff737SWarner Losh return EOPNOTSUPP;
29952e79ca97SSam Leffler }
29963dfff737SWarner Losh vap->iv_flags = flags;
2997b032f27cSSam Leffler error = ERESTART; /* NB: can change beacon frame */
29988a1b9b6aSSam Leffler break;
29998a1b9b6aSSam Leffler case IEEE80211_IOC_WME:
30008a1b9b6aSSam Leffler if (ireq->i_val) {
3001b032f27cSSam Leffler if ((vap->iv_caps & IEEE80211_C_WME) == 0)
3002b032f27cSSam Leffler return EOPNOTSUPP;
3003b032f27cSSam Leffler ieee80211_syncflag(vap, IEEE80211_F_WME);
30048a1b9b6aSSam Leffler } else
3005b032f27cSSam Leffler ieee80211_syncflag(vap, -IEEE80211_F_WME);
3006b032f27cSSam Leffler error = ERESTART; /* NB: can change beacon frame */
30078a1b9b6aSSam Leffler break;
30088a1b9b6aSSam Leffler case IEEE80211_IOC_HIDESSID:
30098a1b9b6aSSam Leffler if (ireq->i_val)
3010b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_HIDESSID;
30118a1b9b6aSSam Leffler else
3012b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_HIDESSID;
3013b032f27cSSam Leffler error = ERESTART; /* XXX ENETRESET? */
30142e79ca97SSam Leffler break;
30158a1b9b6aSSam Leffler case IEEE80211_IOC_APBRIDGE:
30168a1b9b6aSSam Leffler if (ireq->i_val == 0)
3017b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_NOBRIDGE;
30188a1b9b6aSSam Leffler else
3019b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_NOBRIDGE;
30208a1b9b6aSSam Leffler break;
30218a1b9b6aSSam Leffler case IEEE80211_IOC_BSSID:
30228a1b9b6aSSam Leffler if (ireq->i_len != sizeof(tmpbssid))
30238a1b9b6aSSam Leffler return EINVAL;
30248a1b9b6aSSam Leffler error = copyin(ireq->i_data, tmpbssid, ireq->i_len);
30258a1b9b6aSSam Leffler if (error)
30268a1b9b6aSSam Leffler break;
3027b032f27cSSam Leffler IEEE80211_ADDR_COPY(vap->iv_des_bssid, tmpbssid);
3028b032f27cSSam Leffler if (IEEE80211_ADDR_EQ(vap->iv_des_bssid, zerobssid))
3029b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_DESBSSID;
30308a1b9b6aSSam Leffler else
3031b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_DESBSSID;
3032b032f27cSSam Leffler error = ENETRESET;
30338a1b9b6aSSam Leffler break;
30348a1b9b6aSSam Leffler case IEEE80211_IOC_CHANLIST:
3035b032f27cSSam Leffler error = ieee80211_ioctl_setchanlist(vap, ireq);
30368a1b9b6aSSam Leffler break;
3037b032f27cSSam Leffler #define OLD_IEEE80211_IOC_SCAN_REQ 23
3038b032f27cSSam Leffler #ifdef OLD_IEEE80211_IOC_SCAN_REQ
3039b032f27cSSam Leffler case OLD_IEEE80211_IOC_SCAN_REQ:
3040b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN,
3041b032f27cSSam Leffler "%s: active scan request\n", __func__);
3042b032f27cSSam Leffler /*
3043b032f27cSSam Leffler * If we are in INIT state then the driver has never
3044b032f27cSSam Leffler * had a chance to setup hardware state to do a scan;
3045b032f27cSSam Leffler * use the state machine to get us up the SCAN state.
3046b032f27cSSam Leffler * Otherwise just invoke the scan machinery to start
3047b032f27cSSam Leffler * a one-time scan.
3048b032f27cSSam Leffler */
3049b032f27cSSam Leffler if (vap->iv_state == IEEE80211_S_INIT)
3050b032f27cSSam Leffler ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
3051b032f27cSSam Leffler else
3052b032f27cSSam Leffler (void) ieee80211_start_scan(vap,
305368e8e04eSSam Leffler IEEE80211_SCAN_ACTIVE |
305468e8e04eSSam Leffler IEEE80211_SCAN_NOPICK |
3055b032f27cSSam Leffler IEEE80211_SCAN_ONCE,
3056b032f27cSSam Leffler IEEE80211_SCAN_FOREVER, 0, 0,
305768e8e04eSSam Leffler /* XXX use ioctl params */
3058b032f27cSSam Leffler vap->iv_des_nssid, vap->iv_des_ssid);
3059b032f27cSSam Leffler break;
3060b032f27cSSam Leffler #endif /* OLD_IEEE80211_IOC_SCAN_REQ */
3061b032f27cSSam Leffler case IEEE80211_IOC_SCAN_REQ:
3062b032f27cSSam Leffler error = ieee80211_ioctl_scanreq(vap, ireq);
3063b032f27cSSam Leffler break;
3064b032f27cSSam Leffler case IEEE80211_IOC_SCAN_CANCEL:
3065b032f27cSSam Leffler IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN,
3066b032f27cSSam Leffler "%s: cancel scan\n", __func__);
3067b032f27cSSam Leffler ieee80211_cancel_scan(vap);
3068b032f27cSSam Leffler break;
3069b032f27cSSam Leffler case IEEE80211_IOC_HTCONF:
3070b032f27cSSam Leffler if (ireq->i_val & 1)
30712bfc8a91SSam Leffler ieee80211_syncflag_ht(vap, IEEE80211_FHT_HT);
3072b032f27cSSam Leffler else
30732bfc8a91SSam Leffler ieee80211_syncflag_ht(vap, -IEEE80211_FHT_HT);
3074b032f27cSSam Leffler if (ireq->i_val & 2)
30752bfc8a91SSam Leffler ieee80211_syncflag_ht(vap, IEEE80211_FHT_USEHT40);
3076b032f27cSSam Leffler else
30772bfc8a91SSam Leffler ieee80211_syncflag_ht(vap, -IEEE80211_FHT_USEHT40);
3078b032f27cSSam Leffler error = ENETRESET;
30798a1b9b6aSSam Leffler break;
30808a1b9b6aSSam Leffler case IEEE80211_IOC_ADDMAC:
30818a1b9b6aSSam Leffler case IEEE80211_IOC_DELMAC:
3082b032f27cSSam Leffler error = ieee80211_ioctl_macmac(vap, ireq);
30838a1b9b6aSSam Leffler break;
30848a1b9b6aSSam Leffler case IEEE80211_IOC_MACCMD:
3085b032f27cSSam Leffler error = ieee80211_ioctl_setmaccmd(vap, ireq);
30868a1b9b6aSSam Leffler break;
308742568791SSam Leffler case IEEE80211_IOC_STA_STATS:
3088b032f27cSSam Leffler error = ieee80211_ioctl_setstastats(vap, ireq);
308942568791SSam Leffler break;
30908a1b9b6aSSam Leffler case IEEE80211_IOC_STA_TXPOW:
3091b032f27cSSam Leffler error = ieee80211_ioctl_setstatxpow(vap, ireq);
30928a1b9b6aSSam Leffler break;
30938a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMIN: /* WME: CWmin */
30948a1b9b6aSSam Leffler case IEEE80211_IOC_WME_CWMAX: /* WME: CWmax */
30958a1b9b6aSSam Leffler case IEEE80211_IOC_WME_AIFS: /* WME: AIFS */
30968a1b9b6aSSam Leffler case IEEE80211_IOC_WME_TXOPLIMIT: /* WME: txops limit */
30978a1b9b6aSSam Leffler case IEEE80211_IOC_WME_ACM: /* WME: ACM (bss only) */
3098fa46d9dbSAdrian Chadd case IEEE80211_IOC_WME_ACKPOLICY: /* WME: ACK policy (!bss only) */
3099b032f27cSSam Leffler error = ieee80211_ioctl_setwmeparam(vap, ireq);
31008a1b9b6aSSam Leffler break;
31018a1b9b6aSSam Leffler case IEEE80211_IOC_DTIM_PERIOD:
3102b032f27cSSam Leffler if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
310359aa14a9SRui Paulo vap->iv_opmode != IEEE80211_M_MBSS &&
3104b032f27cSSam Leffler vap->iv_opmode != IEEE80211_M_IBSS)
31058a1b9b6aSSam Leffler return EINVAL;
31068a1b9b6aSSam Leffler if (IEEE80211_DTIM_MIN <= ireq->i_val &&
31078a1b9b6aSSam Leffler ireq->i_val <= IEEE80211_DTIM_MAX) {
3108b032f27cSSam Leffler vap->iv_dtim_period = ireq->i_val;
31098a1b9b6aSSam Leffler error = ENETRESET; /* requires restart */
31108a1b9b6aSSam Leffler } else
31118a1b9b6aSSam Leffler error = EINVAL;
31128a1b9b6aSSam Leffler break;
31138a1b9b6aSSam Leffler case IEEE80211_IOC_BEACON_INTERVAL:
3114b032f27cSSam Leffler if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
311559aa14a9SRui Paulo vap->iv_opmode != IEEE80211_M_MBSS &&
3116b032f27cSSam Leffler vap->iv_opmode != IEEE80211_M_IBSS)
31178a1b9b6aSSam Leffler return EINVAL;
31188a1b9b6aSSam Leffler if (IEEE80211_BINTVAL_MIN <= ireq->i_val &&
31198a1b9b6aSSam Leffler ireq->i_val <= IEEE80211_BINTVAL_MAX) {
3120d365f9c7SSam Leffler ic->ic_bintval = ireq->i_val;
31218a1b9b6aSSam Leffler error = ENETRESET; /* requires restart */
31228a1b9b6aSSam Leffler } else
31238a1b9b6aSSam Leffler error = EINVAL;
31248a1b9b6aSSam Leffler break;
3125c4f040c3SSam Leffler case IEEE80211_IOC_PUREG:
3126c4f040c3SSam Leffler if (ireq->i_val)
3127b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_PUREG;
3128c4f040c3SSam Leffler else
3129b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_PUREG;
3130c4f040c3SSam Leffler /* NB: reset only if we're operating on an 11g channel */
3131b032f27cSSam Leffler if (isvap11g(vap))
3132c4f040c3SSam Leffler error = ENETRESET;
3133c4f040c3SSam Leffler break;
313432b0e64bSAdrian Chadd case IEEE80211_IOC_QUIET:
313532b0e64bSAdrian Chadd vap->iv_quiet= ireq->i_val;
313632b0e64bSAdrian Chadd break;
313732b0e64bSAdrian Chadd case IEEE80211_IOC_QUIET_COUNT:
313832b0e64bSAdrian Chadd vap->iv_quiet_count=ireq->i_val;
313932b0e64bSAdrian Chadd break;
314032b0e64bSAdrian Chadd case IEEE80211_IOC_QUIET_PERIOD:
314132b0e64bSAdrian Chadd vap->iv_quiet_period=ireq->i_val;
314232b0e64bSAdrian Chadd break;
314332b0e64bSAdrian Chadd case IEEE80211_IOC_QUIET_OFFSET:
314432b0e64bSAdrian Chadd vap->iv_quiet_offset=ireq->i_val;
314532b0e64bSAdrian Chadd break;
314632b0e64bSAdrian Chadd case IEEE80211_IOC_QUIET_DUR:
314732b0e64bSAdrian Chadd if(ireq->i_val < vap->iv_bss->ni_intval)
314832b0e64bSAdrian Chadd vap->iv_quiet_duration = ireq->i_val;
314932b0e64bSAdrian Chadd else
315032b0e64bSAdrian Chadd error = EINVAL;
315132b0e64bSAdrian Chadd break;
315268e8e04eSSam Leffler case IEEE80211_IOC_BGSCAN:
315368e8e04eSSam Leffler if (ireq->i_val) {
3154b032f27cSSam Leffler if ((vap->iv_caps & IEEE80211_C_BGSCAN) == 0)
3155b032f27cSSam Leffler return EOPNOTSUPP;
3156b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_BGSCAN;
315768e8e04eSSam Leffler } else
3158b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_BGSCAN;
315968e8e04eSSam Leffler break;
316068e8e04eSSam Leffler case IEEE80211_IOC_BGSCAN_IDLE:
316168e8e04eSSam Leffler if (ireq->i_val >= IEEE80211_BGSCAN_IDLE_MIN)
3162b032f27cSSam Leffler vap->iv_bgscanidle = ireq->i_val*hz/1000;
316368e8e04eSSam Leffler else
316468e8e04eSSam Leffler error = EINVAL;
316568e8e04eSSam Leffler break;
316668e8e04eSSam Leffler case IEEE80211_IOC_BGSCAN_INTERVAL:
316768e8e04eSSam Leffler if (ireq->i_val >= IEEE80211_BGSCAN_INTVAL_MIN)
3168b032f27cSSam Leffler vap->iv_bgscanintvl = ireq->i_val*hz;
316968e8e04eSSam Leffler else
317068e8e04eSSam Leffler error = EINVAL;
317168e8e04eSSam Leffler break;
317268e8e04eSSam Leffler case IEEE80211_IOC_SCANVALID:
317368e8e04eSSam Leffler if (ireq->i_val >= IEEE80211_SCAN_VALID_MIN)
3174b032f27cSSam Leffler vap->iv_scanvalid = ireq->i_val*hz;
317568e8e04eSSam Leffler else
317668e8e04eSSam Leffler error = EINVAL;
317768e8e04eSSam Leffler break;
317870231e3dSSam Leffler case IEEE80211_IOC_FRAGTHRESHOLD:
3179b032f27cSSam Leffler if ((vap->iv_caps & IEEE80211_C_TXFRAG) == 0 &&
318070231e3dSSam Leffler ireq->i_val != IEEE80211_FRAG_MAX)
3181b032f27cSSam Leffler return EOPNOTSUPP;
318270231e3dSSam Leffler if (!(IEEE80211_FRAG_MIN <= ireq->i_val &&
318370231e3dSSam Leffler ireq->i_val <= IEEE80211_FRAG_MAX))
318470231e3dSSam Leffler return EINVAL;
3185b032f27cSSam Leffler vap->iv_fragthreshold = ireq->i_val;
3186b032f27cSSam Leffler error = ERESTART;
318770231e3dSSam Leffler break;
3188c27e4e31SSam Leffler case IEEE80211_IOC_BURST:
3189c27e4e31SSam Leffler if (ireq->i_val) {
3190b032f27cSSam Leffler if ((vap->iv_caps & IEEE80211_C_BURST) == 0)
3191b032f27cSSam Leffler return EOPNOTSUPP;
3192b032f27cSSam Leffler ieee80211_syncflag(vap, IEEE80211_F_BURST);
3193c27e4e31SSam Leffler } else
3194b032f27cSSam Leffler ieee80211_syncflag(vap, -IEEE80211_F_BURST);
3195b032f27cSSam Leffler error = ERESTART;
3196c27e4e31SSam Leffler break;
3197546786c9SSam Leffler case IEEE80211_IOC_BMISSTHRESHOLD:
3198546786c9SSam Leffler if (!(IEEE80211_HWBMISS_MIN <= ireq->i_val &&
3199546786c9SSam Leffler ireq->i_val <= IEEE80211_HWBMISS_MAX))
3200546786c9SSam Leffler return EINVAL;
3201b032f27cSSam Leffler vap->iv_bmissthreshold = ireq->i_val;
3202b032f27cSSam Leffler error = ERESTART;
3203546786c9SSam Leffler break;
320468e8e04eSSam Leffler case IEEE80211_IOC_CURCHAN:
3205b032f27cSSam Leffler error = ieee80211_ioctl_setcurchan(vap, ireq);
320668e8e04eSSam Leffler break;
320768e8e04eSSam Leffler case IEEE80211_IOC_SHORTGI:
320868e8e04eSSam Leffler if (ireq->i_val) {
320968e8e04eSSam Leffler #define IEEE80211_HTCAP_SHORTGI \
321068e8e04eSSam Leffler (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40)
3211b032f27cSSam Leffler if (((ireq->i_val ^ vap->iv_htcaps) & IEEE80211_HTCAP_SHORTGI) != 0)
321268e8e04eSSam Leffler return EINVAL;
321368e8e04eSSam Leffler if (ireq->i_val & IEEE80211_HTCAP_SHORTGI20)
32142bfc8a91SSam Leffler vap->iv_flags_ht |= IEEE80211_FHT_SHORTGI20;
321568e8e04eSSam Leffler if (ireq->i_val & IEEE80211_HTCAP_SHORTGI40)
32162bfc8a91SSam Leffler vap->iv_flags_ht |= IEEE80211_FHT_SHORTGI40;
321768e8e04eSSam Leffler #undef IEEE80211_HTCAP_SHORTGI
321868e8e04eSSam Leffler } else
32192bfc8a91SSam Leffler vap->iv_flags_ht &=
32202bfc8a91SSam Leffler ~(IEEE80211_FHT_SHORTGI20 | IEEE80211_FHT_SHORTGI40);
3221b032f27cSSam Leffler error = ERESTART;
322268e8e04eSSam Leffler break;
322368e8e04eSSam Leffler case IEEE80211_IOC_AMPDU:
3224b032f27cSSam Leffler if (ireq->i_val && (vap->iv_htcaps & IEEE80211_HTC_AMPDU) == 0)
322568e8e04eSSam Leffler return EINVAL;
322668e8e04eSSam Leffler if (ireq->i_val & 1)
32272bfc8a91SSam Leffler vap->iv_flags_ht |= IEEE80211_FHT_AMPDU_TX;
3228b032f27cSSam Leffler else
32292bfc8a91SSam Leffler vap->iv_flags_ht &= ~IEEE80211_FHT_AMPDU_TX;
323068e8e04eSSam Leffler if (ireq->i_val & 2)
32312bfc8a91SSam Leffler vap->iv_flags_ht |= IEEE80211_FHT_AMPDU_RX;
3232b032f27cSSam Leffler else
32332bfc8a91SSam Leffler vap->iv_flags_ht &= ~IEEE80211_FHT_AMPDU_RX;
323468e8e04eSSam Leffler /* NB: reset only if we're operating on an 11n channel */
3235b032f27cSSam Leffler if (isvapht(vap))
3236b032f27cSSam Leffler error = ERESTART;
323768e8e04eSSam Leffler break;
323868e8e04eSSam Leffler case IEEE80211_IOC_AMPDU_LIMIT:
3239781487cfSAdrian Chadd /* XXX TODO: figure out ampdu_limit versus ampdu_rxmax */
3240b032f27cSSam Leffler if (!(IEEE80211_HTCAP_MAXRXAMPDU_8K <= ireq->i_val &&
3241b032f27cSSam Leffler ireq->i_val <= IEEE80211_HTCAP_MAXRXAMPDU_64K))
3242b032f27cSSam Leffler return EINVAL;
3243b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_HOSTAP)
3244b032f27cSSam Leffler vap->iv_ampdu_rxmax = ireq->i_val;
3245b032f27cSSam Leffler else
3246b032f27cSSam Leffler vap->iv_ampdu_limit = ireq->i_val;
3247b032f27cSSam Leffler error = ERESTART;
324868e8e04eSSam Leffler break;
324968e8e04eSSam Leffler case IEEE80211_IOC_AMPDU_DENSITY:
3250b032f27cSSam Leffler if (!(IEEE80211_HTCAP_MPDUDENSITY_NA <= ireq->i_val &&
3251b032f27cSSam Leffler ireq->i_val <= IEEE80211_HTCAP_MPDUDENSITY_16))
3252b032f27cSSam Leffler return EINVAL;
3253b032f27cSSam Leffler vap->iv_ampdu_density = ireq->i_val;
3254b032f27cSSam Leffler error = ERESTART;
325568e8e04eSSam Leffler break;
325668e8e04eSSam Leffler case IEEE80211_IOC_AMSDU:
3257b032f27cSSam Leffler if (ireq->i_val && (vap->iv_htcaps & IEEE80211_HTC_AMSDU) == 0)
325868e8e04eSSam Leffler return EINVAL;
325968e8e04eSSam Leffler if (ireq->i_val & 1)
32602bfc8a91SSam Leffler vap->iv_flags_ht |= IEEE80211_FHT_AMSDU_TX;
3261b032f27cSSam Leffler else
32622bfc8a91SSam Leffler vap->iv_flags_ht &= ~IEEE80211_FHT_AMSDU_TX;
326368e8e04eSSam Leffler if (ireq->i_val & 2)
32642bfc8a91SSam Leffler vap->iv_flags_ht |= IEEE80211_FHT_AMSDU_RX;
3265b032f27cSSam Leffler else
32662bfc8a91SSam Leffler vap->iv_flags_ht &= ~IEEE80211_FHT_AMSDU_RX;
326768e8e04eSSam Leffler /* NB: reset only if we're operating on an 11n channel */
3268b032f27cSSam Leffler if (isvapht(vap))
3269b032f27cSSam Leffler error = ERESTART;
327068e8e04eSSam Leffler break;
327168e8e04eSSam Leffler case IEEE80211_IOC_AMSDU_LIMIT:
327268e8e04eSSam Leffler /* XXX validate */
3273b032f27cSSam Leffler vap->iv_amsdu_limit = ireq->i_val; /* XXX truncation? */
327468e8e04eSSam Leffler break;
327568e8e04eSSam Leffler case IEEE80211_IOC_PUREN:
327668e8e04eSSam Leffler if (ireq->i_val) {
32772bfc8a91SSam Leffler if ((vap->iv_flags_ht & IEEE80211_FHT_HT) == 0)
327868e8e04eSSam Leffler return EINVAL;
32792bfc8a91SSam Leffler vap->iv_flags_ht |= IEEE80211_FHT_PUREN;
328068e8e04eSSam Leffler } else
32812bfc8a91SSam Leffler vap->iv_flags_ht &= ~IEEE80211_FHT_PUREN;
328268e8e04eSSam Leffler /* NB: reset only if we're operating on an 11n channel */
3283b032f27cSSam Leffler if (isvapht(vap))
3284b032f27cSSam Leffler error = ERESTART;
328568e8e04eSSam Leffler break;
328668e8e04eSSam Leffler case IEEE80211_IOC_DOTH:
328768e8e04eSSam Leffler if (ireq->i_val) {
328868e8e04eSSam Leffler #if 0
328968e8e04eSSam Leffler /* XXX no capability */
3290b032f27cSSam Leffler if ((vap->iv_caps & IEEE80211_C_DOTH) == 0)
3291b032f27cSSam Leffler return EOPNOTSUPP;
329268e8e04eSSam Leffler #endif
3293b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_DOTH;
329468e8e04eSSam Leffler } else
3295b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_DOTH;
3296b032f27cSSam Leffler error = ENETRESET;
3297b032f27cSSam Leffler break;
3298b032f27cSSam Leffler case IEEE80211_IOC_REGDOMAIN:
3299b032f27cSSam Leffler error = ieee80211_ioctl_setregdomain(vap, ireq);
3300b032f27cSSam Leffler break;
3301b032f27cSSam Leffler case IEEE80211_IOC_ROAM:
3302b032f27cSSam Leffler error = ieee80211_ioctl_setroam(vap, ireq);
3303b032f27cSSam Leffler break;
3304b032f27cSSam Leffler case IEEE80211_IOC_TXPARAMS:
3305b032f27cSSam Leffler error = ieee80211_ioctl_settxparams(vap, ireq);
330668e8e04eSSam Leffler break;
330768e8e04eSSam Leffler case IEEE80211_IOC_HTCOMPAT:
330868e8e04eSSam Leffler if (ireq->i_val) {
33092bfc8a91SSam Leffler if ((vap->iv_flags_ht & IEEE80211_FHT_HT) == 0)
3310b032f27cSSam Leffler return EOPNOTSUPP;
33112bfc8a91SSam Leffler vap->iv_flags_ht |= IEEE80211_FHT_HTCOMPAT;
331268e8e04eSSam Leffler } else
33132bfc8a91SSam Leffler vap->iv_flags_ht &= ~IEEE80211_FHT_HTCOMPAT;
331468e8e04eSSam Leffler /* NB: reset only if we're operating on an 11n channel */
3315b032f27cSSam Leffler if (isvapht(vap))
3316b032f27cSSam Leffler error = ERESTART;
3317b032f27cSSam Leffler break;
3318b032f27cSSam Leffler case IEEE80211_IOC_DWDS:
3319b032f27cSSam Leffler if (ireq->i_val) {
3320b032f27cSSam Leffler /* NB: DWDS only makes sense for WDS-capable devices */
3321b032f27cSSam Leffler if ((ic->ic_caps & IEEE80211_C_WDS) == 0)
3322b032f27cSSam Leffler return EOPNOTSUPP;
3323b032f27cSSam Leffler /* NB: DWDS is used only with ap+sta vaps */
3324b032f27cSSam Leffler if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
3325b032f27cSSam Leffler vap->iv_opmode != IEEE80211_M_STA)
3326b032f27cSSam Leffler return EINVAL;
3327b032f27cSSam Leffler vap->iv_flags |= IEEE80211_F_DWDS;
3328f2a6a13cSSam Leffler if (vap->iv_opmode == IEEE80211_M_STA)
3329f2a6a13cSSam Leffler vap->iv_flags_ext |= IEEE80211_FEXT_4ADDR;
3330f2a6a13cSSam Leffler } else {
3331b032f27cSSam Leffler vap->iv_flags &= ~IEEE80211_F_DWDS;
3332f2a6a13cSSam Leffler if (vap->iv_opmode == IEEE80211_M_STA)
3333f2a6a13cSSam Leffler vap->iv_flags_ext &= ~IEEE80211_FEXT_4ADDR;
3334f2a6a13cSSam Leffler }
333568e8e04eSSam Leffler break;
3336c066143cSSam Leffler case IEEE80211_IOC_INACTIVITY:
3337c066143cSSam Leffler if (ireq->i_val)
3338b032f27cSSam Leffler vap->iv_flags_ext |= IEEE80211_FEXT_INACT;
3339c066143cSSam Leffler else
3340b032f27cSSam Leffler vap->iv_flags_ext &= ~IEEE80211_FEXT_INACT;
3341b032f27cSSam Leffler break;
3342b032f27cSSam Leffler case IEEE80211_IOC_APPIE:
3343b032f27cSSam Leffler error = ieee80211_ioctl_setappie(vap, ireq);
3344b032f27cSSam Leffler break;
3345b032f27cSSam Leffler case IEEE80211_IOC_WPS:
3346b032f27cSSam Leffler if (ireq->i_val) {
3347b032f27cSSam Leffler if ((vap->iv_caps & IEEE80211_C_WPA) == 0)
3348b032f27cSSam Leffler return EOPNOTSUPP;
3349b032f27cSSam Leffler vap->iv_flags_ext |= IEEE80211_FEXT_WPS;
3350b032f27cSSam Leffler } else
3351b032f27cSSam Leffler vap->iv_flags_ext &= ~IEEE80211_FEXT_WPS;
3352b032f27cSSam Leffler break;
3353b032f27cSSam Leffler case IEEE80211_IOC_TSN:
3354b032f27cSSam Leffler if (ireq->i_val) {
3355b032f27cSSam Leffler if ((vap->iv_caps & IEEE80211_C_WPA) == 0)
3356b032f27cSSam Leffler return EOPNOTSUPP;
3357b032f27cSSam Leffler vap->iv_flags_ext |= IEEE80211_FEXT_TSN;
3358b032f27cSSam Leffler } else
3359b032f27cSSam Leffler vap->iv_flags_ext &= ~IEEE80211_FEXT_TSN;
3360b032f27cSSam Leffler break;
3361b032f27cSSam Leffler case IEEE80211_IOC_CHANSWITCH:
3362b032f27cSSam Leffler error = ieee80211_ioctl_chanswitch(vap, ireq);
3363b032f27cSSam Leffler break;
3364b032f27cSSam Leffler case IEEE80211_IOC_DFS:
3365b032f27cSSam Leffler if (ireq->i_val) {
3366b032f27cSSam Leffler if ((vap->iv_caps & IEEE80211_C_DFS) == 0)
3367b032f27cSSam Leffler return EOPNOTSUPP;
3368b032f27cSSam Leffler /* NB: DFS requires 11h support */
3369b032f27cSSam Leffler if ((vap->iv_flags & IEEE80211_F_DOTH) == 0)
3370b032f27cSSam Leffler return EINVAL;
3371b032f27cSSam Leffler vap->iv_flags_ext |= IEEE80211_FEXT_DFS;
3372b032f27cSSam Leffler } else
3373b032f27cSSam Leffler vap->iv_flags_ext &= ~IEEE80211_FEXT_DFS;
3374b032f27cSSam Leffler break;
3375b032f27cSSam Leffler case IEEE80211_IOC_DOTD:
3376b032f27cSSam Leffler if (ireq->i_val)
3377b032f27cSSam Leffler vap->iv_flags_ext |= IEEE80211_FEXT_DOTD;
3378b032f27cSSam Leffler else
3379b032f27cSSam Leffler vap->iv_flags_ext &= ~IEEE80211_FEXT_DOTD;
3380b032f27cSSam Leffler if (vap->iv_opmode == IEEE80211_M_STA)
3381b032f27cSSam Leffler error = ENETRESET;
3382c066143cSSam Leffler break;
33831b6167d2SSam Leffler case IEEE80211_IOC_HTPROTMODE:
33841b6167d2SSam Leffler if (ireq->i_val > IEEE80211_PROT_RTSCTS)
33851b6167d2SSam Leffler return EINVAL;
3386f1481c8dSAdrian Chadd vap->iv_htprotmode = ireq->i_val ?
33871b6167d2SSam Leffler IEEE80211_PROT_RTSCTS : IEEE80211_PROT_NONE;
33881b6167d2SSam Leffler /* NB: if not operating in 11n this can wait */
3389b032f27cSSam Leffler if (isvapht(vap))
33901b6167d2SSam Leffler error = ERESTART;
3391f1481c8dSAdrian Chadd /* Notify driver layer of HT protmode changes */
3392f1481c8dSAdrian Chadd ieee80211_vap_update_ht_protmode(vap);
33931b6167d2SSam Leffler break;
3394b032f27cSSam Leffler case IEEE80211_IOC_STA_VLAN:
3395b032f27cSSam Leffler error = ieee80211_ioctl_setstavlan(vap, ireq);
33961b6167d2SSam Leffler break;
33978c070d69SSam Leffler case IEEE80211_IOC_SMPS:
33988c070d69SSam Leffler if ((ireq->i_val &~ IEEE80211_HTCAP_SMPS) != 0 ||
33998c070d69SSam Leffler ireq->i_val == 0x0008) /* value of 2 is reserved */
34008c070d69SSam Leffler return EINVAL;
34018c070d69SSam Leffler if (ireq->i_val != IEEE80211_HTCAP_SMPS_OFF &&
34028c070d69SSam Leffler (vap->iv_htcaps & IEEE80211_HTC_SMPS) == 0)
34038c070d69SSam Leffler return EOPNOTSUPP;
34048c070d69SSam Leffler vap->iv_htcaps = (vap->iv_htcaps &~ IEEE80211_HTCAP_SMPS) |
34058c070d69SSam Leffler ireq->i_val;
34068c070d69SSam Leffler /* NB: if not operating in 11n this can wait */
34078c070d69SSam Leffler if (isvapht(vap))
34088c070d69SSam Leffler error = ERESTART;
34098c070d69SSam Leffler break;
341044f7a6edSSam Leffler case IEEE80211_IOC_RIFS:
341144f7a6edSSam Leffler if (ireq->i_val != 0) {
341244f7a6edSSam Leffler if ((vap->iv_htcaps & IEEE80211_HTC_RIFS) == 0)
341344f7a6edSSam Leffler return EOPNOTSUPP;
34142bfc8a91SSam Leffler vap->iv_flags_ht |= IEEE80211_FHT_RIFS;
341544f7a6edSSam Leffler } else
34162bfc8a91SSam Leffler vap->iv_flags_ht &= ~IEEE80211_FHT_RIFS;
341744f7a6edSSam Leffler /* NB: if not operating in 11n this can wait */
341844f7a6edSSam Leffler if (isvapht(vap))
341944f7a6edSSam Leffler error = ERESTART;
342044f7a6edSSam Leffler break;
3421ec3763bbSAdrian Chadd case IEEE80211_IOC_STBC:
3422ec3763bbSAdrian Chadd /* Check if we can do STBC TX/RX before changing the setting */
3423ec3763bbSAdrian Chadd if ((ireq->i_val & 1) &&
3424ec3763bbSAdrian Chadd ((vap->iv_htcaps & IEEE80211_HTCAP_TXSTBC) == 0))
3425ec3763bbSAdrian Chadd return EOPNOTSUPP;
3426ec3763bbSAdrian Chadd if ((ireq->i_val & 2) &&
3427ec3763bbSAdrian Chadd ((vap->iv_htcaps & IEEE80211_HTCAP_RXSTBC) == 0))
3428ec3763bbSAdrian Chadd return EOPNOTSUPP;
3429ec3763bbSAdrian Chadd
3430ec3763bbSAdrian Chadd /* TX */
3431ec3763bbSAdrian Chadd if (ireq->i_val & 1)
3432ec3763bbSAdrian Chadd vap->iv_flags_ht |= IEEE80211_FHT_STBC_TX;
3433ec3763bbSAdrian Chadd else
3434ec3763bbSAdrian Chadd vap->iv_flags_ht &= ~IEEE80211_FHT_STBC_TX;
3435ec3763bbSAdrian Chadd
3436ec3763bbSAdrian Chadd /* RX */
3437ec3763bbSAdrian Chadd if (ireq->i_val & 2)
3438ec3763bbSAdrian Chadd vap->iv_flags_ht |= IEEE80211_FHT_STBC_RX;
3439ec3763bbSAdrian Chadd else
3440ec3763bbSAdrian Chadd vap->iv_flags_ht &= ~IEEE80211_FHT_STBC_RX;
3441ec3763bbSAdrian Chadd
3442ec3763bbSAdrian Chadd /* NB: reset only if we're operating on an 11n channel */
3443ec3763bbSAdrian Chadd if (isvapht(vap))
3444ec3763bbSAdrian Chadd error = ERESTART;
3445ec3763bbSAdrian Chadd break;
3446c5bba9daSAndriy Voskoboinyk case IEEE80211_IOC_LDPC:
3447c5bba9daSAndriy Voskoboinyk /* Check if we can do LDPC TX/RX before changing the setting */
3448c5bba9daSAndriy Voskoboinyk if ((ireq->i_val & 1) &&
3449c5bba9daSAndriy Voskoboinyk (vap->iv_htcaps & IEEE80211_HTC_TXLDPC) == 0)
3450c5bba9daSAndriy Voskoboinyk return EOPNOTSUPP;
3451c5bba9daSAndriy Voskoboinyk if ((ireq->i_val & 2) &&
3452c5bba9daSAndriy Voskoboinyk (vap->iv_htcaps & IEEE80211_HTCAP_LDPC) == 0)
3453c5bba9daSAndriy Voskoboinyk return EOPNOTSUPP;
3454c5bba9daSAndriy Voskoboinyk
3455c5bba9daSAndriy Voskoboinyk /* TX */
3456c5bba9daSAndriy Voskoboinyk if (ireq->i_val & 1)
3457c5bba9daSAndriy Voskoboinyk vap->iv_flags_ht |= IEEE80211_FHT_LDPC_TX;
3458c5bba9daSAndriy Voskoboinyk else
3459c5bba9daSAndriy Voskoboinyk vap->iv_flags_ht &= ~IEEE80211_FHT_LDPC_TX;
3460c5bba9daSAndriy Voskoboinyk
3461c5bba9daSAndriy Voskoboinyk /* RX */
3462c5bba9daSAndriy Voskoboinyk if (ireq->i_val & 2)
3463c5bba9daSAndriy Voskoboinyk vap->iv_flags_ht |= IEEE80211_FHT_LDPC_RX;
3464c5bba9daSAndriy Voskoboinyk else
3465c5bba9daSAndriy Voskoboinyk vap->iv_flags_ht &= ~IEEE80211_FHT_LDPC_RX;
3466c5bba9daSAndriy Voskoboinyk
3467c5bba9daSAndriy Voskoboinyk /* NB: reset only if we're operating on an 11n channel */
3468c5bba9daSAndriy Voskoboinyk if (isvapht(vap))
3469c5bba9daSAndriy Voskoboinyk error = ERESTART;
3470c5bba9daSAndriy Voskoboinyk break;
34718379e8dbSAdrian Chadd case IEEE80211_IOC_UAPSD:
34728379e8dbSAdrian Chadd if ((vap->iv_caps & IEEE80211_C_UAPSD) == 0)
34738379e8dbSAdrian Chadd return EOPNOTSUPP;
34748379e8dbSAdrian Chadd if (ireq->i_val == 0)
34758379e8dbSAdrian Chadd vap->iv_flags_ext &= ~IEEE80211_FEXT_UAPSD;
34768379e8dbSAdrian Chadd else if (ireq->i_val == 1)
34778379e8dbSAdrian Chadd vap->iv_flags_ext |= IEEE80211_FEXT_UAPSD;
34788379e8dbSAdrian Chadd else
34798379e8dbSAdrian Chadd return EINVAL;
34808379e8dbSAdrian Chadd break;
348135bcfd1cSAdrian Chadd
348235bcfd1cSAdrian Chadd /* VHT */
348335bcfd1cSAdrian Chadd case IEEE80211_IOC_VHTCONF:
348496811be2SBjoern A. Zeeb if (ireq->i_val & IEEE80211_FVHT_VHT)
348535bcfd1cSAdrian Chadd ieee80211_syncflag_vht(vap, IEEE80211_FVHT_VHT);
348635bcfd1cSAdrian Chadd else
348735bcfd1cSAdrian Chadd ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_VHT);
348835bcfd1cSAdrian Chadd
348996811be2SBjoern A. Zeeb if (ireq->i_val & IEEE80211_FVHT_USEVHT40)
349035bcfd1cSAdrian Chadd ieee80211_syncflag_vht(vap, IEEE80211_FVHT_USEVHT40);
349135bcfd1cSAdrian Chadd else
349235bcfd1cSAdrian Chadd ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_USEVHT40);
349335bcfd1cSAdrian Chadd
349496811be2SBjoern A. Zeeb if (ireq->i_val & IEEE80211_FVHT_USEVHT80)
349535bcfd1cSAdrian Chadd ieee80211_syncflag_vht(vap, IEEE80211_FVHT_USEVHT80);
349635bcfd1cSAdrian Chadd else
349735bcfd1cSAdrian Chadd ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_USEVHT80);
349835bcfd1cSAdrian Chadd
349996811be2SBjoern A. Zeeb if (ireq->i_val & IEEE80211_FVHT_USEVHT160)
350035bcfd1cSAdrian Chadd ieee80211_syncflag_vht(vap, IEEE80211_FVHT_USEVHT160);
350135bcfd1cSAdrian Chadd else
350235bcfd1cSAdrian Chadd ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_USEVHT160);
350335bcfd1cSAdrian Chadd
350496811be2SBjoern A. Zeeb if (ireq->i_val & IEEE80211_FVHT_USEVHT80P80)
350596811be2SBjoern A. Zeeb ieee80211_syncflag_vht(vap, IEEE80211_FVHT_USEVHT80P80);
350696811be2SBjoern A. Zeeb else
350796811be2SBjoern A. Zeeb ieee80211_syncflag_vht(vap, -IEEE80211_FVHT_USEVHT80P80);
350896811be2SBjoern A. Zeeb
350935bcfd1cSAdrian Chadd error = ENETRESET;
351035bcfd1cSAdrian Chadd break;
351135bcfd1cSAdrian Chadd
35121a1e1d21SSam Leffler default:
35138c4e758aSSam Leffler error = ieee80211_ioctl_setdefault(vap, ireq);
35141a1e1d21SSam Leffler break;
35151a1e1d21SSam Leffler }
3516b032f27cSSam Leffler /*
3517b032f27cSSam Leffler * The convention is that ENETRESET means an operation
3518b032f27cSSam Leffler * requires a complete re-initialization of the device (e.g.
3519b032f27cSSam Leffler * changing something that affects the association state).
3520b032f27cSSam Leffler * ERESTART means the request may be handled with only a
3521b032f27cSSam Leffler * reload of the hardware state. We hand ERESTART requests
3522b032f27cSSam Leffler * to the iv_reset callback so the driver can decide. If
3523b032f27cSSam Leffler * a device does not fillin iv_reset then it defaults to one
3524b032f27cSSam Leffler * that returns ENETRESET. Otherwise a driver may return
3525b032f27cSSam Leffler * ENETRESET (in which case a full reset will be done) or
3526b032f27cSSam Leffler * 0 to mean there's no need to do anything (e.g. when the
3527b032f27cSSam Leffler * change has no effect on the driver/device).
3528b032f27cSSam Leffler */
3529b032f27cSSam Leffler if (error == ERESTART)
3530b032f27cSSam Leffler error = IFNET_IS_UP_RUNNING(vap->iv_ifp) ?
3531b032f27cSSam Leffler vap->iv_reset(vap, ireq->i_type) : 0;
3532b032f27cSSam Leffler if (error == ENETRESET) {
3533b032f27cSSam Leffler /* XXX need to re-think AUTO handling */
3534b032f27cSSam Leffler if (IS_UP_AUTO(vap))
3535b032f27cSSam Leffler ieee80211_init(vap);
3536b032f27cSSam Leffler error = 0;
3537b032f27cSSam Leffler }
35388a1b9b6aSSam Leffler return error;
35398a1b9b6aSSam Leffler }
35408a1b9b6aSSam Leffler
3541b032f27cSSam Leffler int
ieee80211_ioctl(struct ifnet * ifp,u_long cmd,caddr_t data)3542b032f27cSSam Leffler ieee80211_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
3543b032f27cSSam Leffler {
35441da89db5SSam Leffler struct ieee80211vap *vap = ifp->if_softc;
35451da89db5SSam Leffler struct ieee80211com *ic = vap->iv_ic;
3546dab61567SAndriy Voskoboinyk int error = 0, wait = 0, ic_used;
35478a1b9b6aSSam Leffler struct ifreq *ifr;
35488a1b9b6aSSam Leffler struct ifaddr *ifa; /* XXX */
35498a1b9b6aSSam Leffler
3550dab61567SAndriy Voskoboinyk ic_used = (cmd != SIOCSIFMTU && cmd != SIOCG80211STATS);
3551dab61567SAndriy Voskoboinyk if (ic_used && (error = ieee80211_com_vincref(vap)) != 0)
3552dab61567SAndriy Voskoboinyk return (error);
3553dab61567SAndriy Voskoboinyk
35548a1b9b6aSSam Leffler switch (cmd) {
3555b032f27cSSam Leffler case SIOCSIFFLAGS:
3556b032f27cSSam Leffler IEEE80211_LOCK(ic);
35576459bd28SAndriy Voskoboinyk if ((ifp->if_flags ^ vap->iv_ifflags) & IFF_PROMISC) {
35586459bd28SAndriy Voskoboinyk /*
35596459bd28SAndriy Voskoboinyk * Enable promiscuous mode when:
35606459bd28SAndriy Voskoboinyk * 1. Interface is not a member of bridge, or
35616459bd28SAndriy Voskoboinyk * 2. Requested by user, or
35626459bd28SAndriy Voskoboinyk * 3. In monitor (or adhoc-demo) mode.
35636459bd28SAndriy Voskoboinyk */
35646459bd28SAndriy Voskoboinyk if (ifp->if_bridge == NULL ||
35656459bd28SAndriy Voskoboinyk (ifp->if_flags & IFF_PPROMISC) != 0 ||
35666459bd28SAndriy Voskoboinyk vap->iv_opmode == IEEE80211_M_MONITOR ||
35676459bd28SAndriy Voskoboinyk (vap->iv_opmode == IEEE80211_M_AHDEMO &&
35686459bd28SAndriy Voskoboinyk (vap->iv_caps & IEEE80211_C_TDMA) == 0)) {
35696459bd28SAndriy Voskoboinyk ieee80211_promisc(vap,
35706459bd28SAndriy Voskoboinyk ifp->if_flags & IFF_PROMISC);
35716459bd28SAndriy Voskoboinyk vap->iv_ifflags ^= IFF_PROMISC;
35726459bd28SAndriy Voskoboinyk }
35736459bd28SAndriy Voskoboinyk }
35746459bd28SAndriy Voskoboinyk if ((ifp->if_flags ^ vap->iv_ifflags) & IFF_ALLMULTI) {
35757a79cebfSGleb Smirnoff ieee80211_allmulti(vap, ifp->if_flags & IFF_ALLMULTI);
35766459bd28SAndriy Voskoboinyk vap->iv_ifflags ^= IFF_ALLMULTI;
35776459bd28SAndriy Voskoboinyk }
3578b032f27cSSam Leffler if (ifp->if_flags & IFF_UP) {
3579b032f27cSSam Leffler /*
3580b032f27cSSam Leffler * Bring ourself up unless we're already operational.
3581b032f27cSSam Leffler * If we're the first vap and the parent is not up
3582b032f27cSSam Leffler * then it will automatically be brought up as a
3583b032f27cSSam Leffler * side-effect of bringing ourself up.
3584b032f27cSSam Leffler */
358560d75eb6SAndriy Voskoboinyk if (vap->iv_state == IEEE80211_S_INIT) {
358660d75eb6SAndriy Voskoboinyk if (ic->ic_nrunning == 0)
358760d75eb6SAndriy Voskoboinyk wait = 1;
3588b032f27cSSam Leffler ieee80211_start_locked(vap);
358960d75eb6SAndriy Voskoboinyk }
3590b032f27cSSam Leffler } else if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
3591b032f27cSSam Leffler /*
3592b032f27cSSam Leffler * Stop ourself. If we are the last vap to be
3593b032f27cSSam Leffler * marked down the parent will also be taken down.
3594b032f27cSSam Leffler */
359560d75eb6SAndriy Voskoboinyk if (ic->ic_nrunning == 1)
359660d75eb6SAndriy Voskoboinyk wait = 1;
3597b032f27cSSam Leffler ieee80211_stop_locked(vap);
3598b032f27cSSam Leffler }
3599b032f27cSSam Leffler IEEE80211_UNLOCK(ic);
36008d9b29f3SAndrew Thompson /* Wait for parent ioctl handler if it was queued */
3601c6a35ee4SAndriy Voskoboinyk if (wait) {
36022b60ecf1SGleb Smirnoff struct epoch_tracker et;
36032b60ecf1SGleb Smirnoff
3604ae55932eSAndrew Thompson ieee80211_waitfor_parent(ic);
3605c6a35ee4SAndriy Voskoboinyk
3606c6a35ee4SAndriy Voskoboinyk /*
3607c6a35ee4SAndriy Voskoboinyk * Check if the MAC address was changed
3608c6a35ee4SAndriy Voskoboinyk * via SIOCSIFLLADDR ioctl.
36097071b803SAndriy Voskoboinyk *
36107071b803SAndriy Voskoboinyk * NB: device may be detached during initialization;
36117071b803SAndriy Voskoboinyk * use if_ioctl for existence check.
3612c6a35ee4SAndriy Voskoboinyk */
36132b60ecf1SGleb Smirnoff NET_EPOCH_ENTER(et);
36147071b803SAndriy Voskoboinyk if (ifp->if_ioctl == ieee80211_ioctl &&
36157071b803SAndriy Voskoboinyk (ifp->if_flags & IFF_UP) == 0 &&
3616c6a35ee4SAndriy Voskoboinyk !IEEE80211_ADDR_EQ(vap->iv_myaddr, IF_LLADDR(ifp)))
3617c6a35ee4SAndriy Voskoboinyk IEEE80211_ADDR_COPY(vap->iv_myaddr,
3618c6a35ee4SAndriy Voskoboinyk IF_LLADDR(ifp));
36192b60ecf1SGleb Smirnoff NET_EPOCH_EXIT(et);
3620c6a35ee4SAndriy Voskoboinyk }
3621b032f27cSSam Leffler break;
3622b032f27cSSam Leffler case SIOCADDMULTI:
3623b032f27cSSam Leffler case SIOCDELMULTI:
36247a79cebfSGleb Smirnoff ieee80211_runtask(ic, &ic->ic_mcast_task);
3625b032f27cSSam Leffler break;
36268a1b9b6aSSam Leffler case SIOCSIFMEDIA:
36278a1b9b6aSSam Leffler case SIOCGIFMEDIA:
3628b032f27cSSam Leffler ifr = (struct ifreq *)data;
3629b032f27cSSam Leffler error = ifmedia_ioctl(ifp, ifr, &vap->iv_media, cmd);
36308a1b9b6aSSam Leffler break;
36318a1b9b6aSSam Leffler case SIOCG80211:
3632b032f27cSSam Leffler error = ieee80211_ioctl_get80211(vap, cmd,
36338a1b9b6aSSam Leffler (struct ieee80211req *) data);
36348a1b9b6aSSam Leffler break;
36358a1b9b6aSSam Leffler case SIOCS80211:
363601e57940SBjoern A. Zeeb error = ieee80211_priv_check_vap_manage(cmd, vap, ifp);
36378a1b9b6aSSam Leffler if (error == 0)
3638b032f27cSSam Leffler error = ieee80211_ioctl_set80211(vap, cmd,
36398a1b9b6aSSam Leffler (struct ieee80211req *) data);
36401a1e1d21SSam Leffler break;
36411be50176SSam Leffler case SIOCG80211STATS:
36421be50176SSam Leffler ifr = (struct ifreq *)data;
3643d760d74dSMark Johnston error = copyout(&vap->iv_stats, ifr_data_get_ptr(ifr),
3644541d96aaSBrooks Davis sizeof(vap->iv_stats));
36451be50176SSam Leffler break;
36466f161f03SSam Leffler case SIOCSIFMTU:
36476f161f03SSam Leffler ifr = (struct ifreq *)data;
36486f161f03SSam Leffler if (!(IEEE80211_MTU_MIN <= ifr->ifr_mtu &&
36496f161f03SSam Leffler ifr->ifr_mtu <= IEEE80211_MTU_MAX))
36506f161f03SSam Leffler error = EINVAL;
36516f161f03SSam Leffler else
36526f161f03SSam Leffler ifp->if_mtu = ifr->ifr_mtu;
36536f161f03SSam Leffler break;
3654b2e95691SSam Leffler case SIOCSIFADDR:
3655b2e95691SSam Leffler /*
3656a4641f4eSPedro F. Giffuni * XXX Handle this directly so we can suppress if_init calls.
3657b2e95691SSam Leffler * XXX This should be done in ether_ioctl but for the moment
3658b2e95691SSam Leffler * XXX there are too many other parts of the system that
3659a4641f4eSPedro F. Giffuni * XXX set IFF_UP and so suppress if_init being called when
3660b2e95691SSam Leffler * XXX it should be.
3661b2e95691SSam Leffler */
3662b2e95691SSam Leffler ifa = (struct ifaddr *) data;
3663b2e95691SSam Leffler switch (ifa->ifa_addr->sa_family) {
3664b2e95691SSam Leffler #ifdef INET
3665b2e95691SSam Leffler case AF_INET:
3666b2e95691SSam Leffler if ((ifp->if_flags & IFF_UP) == 0) {
3667b2e95691SSam Leffler ifp->if_flags |= IFF_UP;
3668b2e95691SSam Leffler ifp->if_init(ifp->if_softc);
3669b2e95691SSam Leffler }
3670b2e95691SSam Leffler arp_ifinit(ifp, ifa);
3671b2e95691SSam Leffler break;
3672b2e95691SSam Leffler #endif
3673b2e95691SSam Leffler default:
3674b2e95691SSam Leffler if ((ifp->if_flags & IFF_UP) == 0) {
3675b2e95691SSam Leffler ifp->if_flags |= IFF_UP;
3676b2e95691SSam Leffler ifp->if_init(ifp->if_softc);
3677b2e95691SSam Leffler }
3678b2e95691SSam Leffler break;
3679b2e95691SSam Leffler }
3680b2e95691SSam Leffler break;
3681f7d38a13SAdrian Chadd case SIOCSIFLLADDR:
368201e57940SBjoern A. Zeeb error = ieee80211_priv_check_vap_setmac(cmd, vap, ifp);
3683f7d38a13SAdrian Chadd if (error == 0)
3684f7d38a13SAdrian Chadd break;
3685f7d38a13SAdrian Chadd /* Fallthrough */
3686ba2c1fbcSAdrian Chadd default:
36877a79cebfSGleb Smirnoff /*
36887a79cebfSGleb Smirnoff * Pass unknown ioctls first to the driver, and if it
36897a79cebfSGleb Smirnoff * returns ENOTTY, then to the generic Ethernet handler.
36907a79cebfSGleb Smirnoff */
36917a79cebfSGleb Smirnoff if (ic->ic_ioctl != NULL &&
36927a79cebfSGleb Smirnoff (error = ic->ic_ioctl(ic, cmd, data)) != ENOTTY)
36937a79cebfSGleb Smirnoff break;
36941a1e1d21SSam Leffler error = ether_ioctl(ifp, cmd, data);
36951a1e1d21SSam Leffler break;
36961a1e1d21SSam Leffler }
3697dab61567SAndriy Voskoboinyk
3698dab61567SAndriy Voskoboinyk if (ic_used)
3699dab61567SAndriy Voskoboinyk ieee80211_com_vdecref(vap);
3700dab61567SAndriy Voskoboinyk
37017a79cebfSGleb Smirnoff return (error);
37021a1e1d21SSam Leffler }
3703