ieee80211_ioctl.c revision 1.16.2.6 1 1.16.2.6 skrll /* $NetBSD: ieee80211_ioctl.c,v 1.16.2.6 2005/03/04 16:53:17 skrll Exp $ */
2 1.16.2.2 skrll /*-
3 1.16.2.2 skrll * Copyright (c) 2001 Atsushi Onoe
4 1.16.2.2 skrll * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
5 1.16.2.2 skrll * All rights reserved.
6 1.16.2.2 skrll *
7 1.16.2.2 skrll * Redistribution and use in source and binary forms, with or without
8 1.16.2.2 skrll * modification, are permitted provided that the following conditions
9 1.16.2.2 skrll * are met:
10 1.16.2.2 skrll * 1. Redistributions of source code must retain the above copyright
11 1.16.2.2 skrll * notice, this list of conditions and the following disclaimer.
12 1.16.2.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
13 1.16.2.2 skrll * notice, this list of conditions and the following disclaimer in the
14 1.16.2.2 skrll * documentation and/or other materials provided with the distribution.
15 1.16.2.2 skrll * 3. The name of the author may not be used to endorse or promote products
16 1.16.2.2 skrll * derived from this software without specific prior written permission.
17 1.16.2.2 skrll *
18 1.16.2.2 skrll * Alternatively, this software may be distributed under the terms of the
19 1.16.2.2 skrll * GNU General Public License ("GPL") version 2 as published by the Free
20 1.16.2.2 skrll * Software Foundation.
21 1.16.2.2 skrll *
22 1.16.2.2 skrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.16.2.2 skrll * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.16.2.2 skrll * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.16.2.2 skrll * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.16.2.2 skrll * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.16.2.2 skrll * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.16.2.2 skrll * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.16.2.2 skrll * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.16.2.2 skrll * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.16.2.2 skrll * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.16.2.2 skrll */
33 1.16.2.2 skrll
34 1.16.2.2 skrll #include <sys/cdefs.h>
35 1.16.2.2 skrll #ifdef __FreeBSD__
36 1.16.2.2 skrll __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_ioctl.c,v 1.13 2004/03/30 22:57:57 sam Exp $");
37 1.16.2.2 skrll #else
38 1.16.2.6 skrll __KERNEL_RCSID(0, "$NetBSD: ieee80211_ioctl.c,v 1.16.2.6 2005/03/04 16:53:17 skrll Exp $");
39 1.16.2.2 skrll #endif
40 1.16.2.2 skrll
41 1.16.2.2 skrll /*
42 1.16.2.2 skrll * IEEE 802.11 ioctl support (FreeBSD-specific)
43 1.16.2.2 skrll */
44 1.16.2.2 skrll
45 1.16.2.2 skrll #include "opt_inet.h"
46 1.16.2.2 skrll
47 1.16.2.2 skrll #include <sys/endian.h>
48 1.16.2.2 skrll #include <sys/param.h>
49 1.16.2.2 skrll #include <sys/kernel.h>
50 1.16.2.2 skrll #include <sys/socket.h>
51 1.16.2.2 skrll #include <sys/sockio.h>
52 1.16.2.2 skrll #include <sys/systm.h>
53 1.16.2.2 skrll #include <sys/proc.h>
54 1.16.2.6 skrll
55 1.16.2.2 skrll #include <net/if.h>
56 1.16.2.2 skrll #include <net/if_arp.h>
57 1.16.2.2 skrll #include <net/if_media.h>
58 1.16.2.2 skrll #ifdef __FreeBSD__
59 1.16.2.2 skrll #include <net/ethernet.h>
60 1.16.2.2 skrll #else
61 1.16.2.2 skrll #include <net/if_ether.h>
62 1.16.2.2 skrll #endif
63 1.16.2.2 skrll
64 1.16.2.2 skrll #ifdef INET
65 1.16.2.2 skrll #include <netinet/in.h>
66 1.16.2.2 skrll #ifdef __FreeBSD__
67 1.16.2.2 skrll #include <netinet/if_ether.h>
68 1.16.2.2 skrll #endif /* __FreeBSD__ */
69 1.16.2.2 skrll #include <netinet/if_inarp.h>
70 1.16.2.2 skrll #endif
71 1.16.2.2 skrll
72 1.16.2.2 skrll #include <net80211/ieee80211_var.h>
73 1.16.2.2 skrll #include <net80211/ieee80211_ioctl.h>
74 1.16.2.2 skrll
75 1.16.2.2 skrll #ifdef __FreeBSD__
76 1.16.2.2 skrll #include <dev/wi/if_wavelan_ieee.h>
77 1.16.2.2 skrll #else
78 1.16.2.2 skrll #include <dev/ic/wi_ieee.h>
79 1.16.2.2 skrll #endif
80 1.16.2.2 skrll
81 1.16.2.2 skrll /*
82 1.16.2.2 skrll * XXX
83 1.16.2.2 skrll * Wireless LAN specific configuration interface, which is compatible
84 1.16.2.2 skrll * with wicontrol(8).
85 1.16.2.2 skrll */
86 1.16.2.2 skrll
87 1.16.2.2 skrll int
88 1.16.2.2 skrll ieee80211_cfgget(struct ifnet *ifp, u_long cmd, caddr_t data)
89 1.16.2.2 skrll {
90 1.16.2.2 skrll struct ieee80211com *ic = (void *)ifp;
91 1.16.2.2 skrll int i, j, error;
92 1.16.2.2 skrll struct ifreq *ifr = (struct ifreq *)data;
93 1.16.2.2 skrll struct wi_req wreq;
94 1.16.2.2 skrll struct wi_ltv_keys *keys;
95 1.16.2.2 skrll struct wi_apinfo *ap;
96 1.16.2.2 skrll struct ieee80211_node *ni;
97 1.16.2.2 skrll struct ieee80211_rateset *rs;
98 1.16.2.2 skrll #ifdef WICACHE
99 1.16.2.2 skrll struct wi_sigcache wsc;
100 1.16.2.2 skrll #endif /* WICACHE */
101 1.16.2.2 skrll #if 0 /* TBD */
102 1.16.2.2 skrll struct wi_scan_p2_hdr *p2;
103 1.16.2.2 skrll struct wi_scan_res *res;
104 1.16.2.2 skrll #endif
105 1.16.2.2 skrll
106 1.16.2.2 skrll error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
107 1.16.2.2 skrll if (error)
108 1.16.2.2 skrll return error;
109 1.16.2.2 skrll wreq.wi_len = 0;
110 1.16.2.2 skrll switch (wreq.wi_type) {
111 1.16.2.2 skrll case WI_RID_SERIALNO:
112 1.16.2.2 skrll case WI_RID_STA_IDENTITY:
113 1.16.2.2 skrll /* nothing appropriate */
114 1.16.2.2 skrll break;
115 1.16.2.2 skrll case WI_RID_NODENAME:
116 1.16.2.2 skrll strlcpy((char *)&wreq.wi_val[1], hostname,
117 1.16.2.2 skrll sizeof(wreq.wi_val) - sizeof(wreq.wi_val[0]));
118 1.16.2.2 skrll wreq.wi_val[0] = htole16(strlen(hostname));
119 1.16.2.2 skrll wreq.wi_len = (1 + strlen(hostname) + 1) / 2;
120 1.16.2.2 skrll break;
121 1.16.2.2 skrll case WI_RID_CURRENT_SSID:
122 1.16.2.2 skrll if (ic->ic_state != IEEE80211_S_RUN) {
123 1.16.2.2 skrll wreq.wi_val[0] = 0;
124 1.16.2.2 skrll wreq.wi_len = 1;
125 1.16.2.2 skrll break;
126 1.16.2.2 skrll }
127 1.16.2.2 skrll wreq.wi_val[0] = htole16(ic->ic_bss->ni_esslen);
128 1.16.2.2 skrll memcpy(&wreq.wi_val[1], ic->ic_bss->ni_essid,
129 1.16.2.2 skrll ic->ic_bss->ni_esslen);
130 1.16.2.2 skrll wreq.wi_len = (1 + ic->ic_bss->ni_esslen + 1) / 2;
131 1.16.2.2 skrll break;
132 1.16.2.2 skrll case WI_RID_OWN_SSID:
133 1.16.2.2 skrll case WI_RID_DESIRED_SSID:
134 1.16.2.2 skrll wreq.wi_val[0] = htole16(ic->ic_des_esslen);
135 1.16.2.2 skrll memcpy(&wreq.wi_val[1], ic->ic_des_essid, ic->ic_des_esslen);
136 1.16.2.2 skrll wreq.wi_len = (1 + ic->ic_des_esslen + 1) / 2;
137 1.16.2.2 skrll break;
138 1.16.2.2 skrll case WI_RID_CURRENT_BSSID:
139 1.16.2.2 skrll if (ic->ic_state == IEEE80211_S_RUN)
140 1.16.2.2 skrll IEEE80211_ADDR_COPY(wreq.wi_val, ic->ic_bss->ni_bssid);
141 1.16.2.2 skrll else
142 1.16.2.2 skrll memset(wreq.wi_val, 0, IEEE80211_ADDR_LEN);
143 1.16.2.2 skrll wreq.wi_len = IEEE80211_ADDR_LEN / 2;
144 1.16.2.2 skrll break;
145 1.16.2.2 skrll case WI_RID_CHANNEL_LIST:
146 1.16.2.2 skrll memset(wreq.wi_val, 0, sizeof(wreq.wi_val));
147 1.16.2.2 skrll /*
148 1.16.2.2 skrll * Since channel 0 is not available for DS, channel 1
149 1.16.2.2 skrll * is assigned to LSB on WaveLAN.
150 1.16.2.2 skrll */
151 1.16.2.2 skrll if (ic->ic_phytype == IEEE80211_T_DS)
152 1.16.2.2 skrll i = 1;
153 1.16.2.2 skrll else
154 1.16.2.2 skrll i = 0;
155 1.16.2.2 skrll for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++)
156 1.16.2.2 skrll if (isset(ic->ic_chan_active, i)) {
157 1.16.2.2 skrll setbit((u_int8_t *)wreq.wi_val, j);
158 1.16.2.2 skrll wreq.wi_len = j / 16 + 1;
159 1.16.2.2 skrll }
160 1.16.2.2 skrll break;
161 1.16.2.2 skrll case WI_RID_OWN_CHNL:
162 1.16.2.2 skrll wreq.wi_val[0] = htole16(
163 1.16.2.2 skrll ieee80211_chan2ieee(ic, ic->ic_ibss_chan));
164 1.16.2.2 skrll wreq.wi_len = 1;
165 1.16.2.2 skrll break;
166 1.16.2.2 skrll case WI_RID_CURRENT_CHAN:
167 1.16.2.2 skrll wreq.wi_val[0] = htole16(
168 1.16.2.2 skrll ieee80211_chan2ieee(ic, ic->ic_bss->ni_chan));
169 1.16.2.2 skrll wreq.wi_len = 1;
170 1.16.2.2 skrll break;
171 1.16.2.2 skrll case WI_RID_COMMS_QUALITY:
172 1.16.2.2 skrll wreq.wi_val[0] = 0; /* quality */
173 1.16.2.2 skrll wreq.wi_val[1] =
174 1.16.2.2 skrll htole16((*ic->ic_node_getrssi)(ic, ic->ic_bss));
175 1.16.2.2 skrll wreq.wi_val[2] = 0; /* noise */
176 1.16.2.2 skrll wreq.wi_len = 3;
177 1.16.2.2 skrll break;
178 1.16.2.2 skrll case WI_RID_PROMISC:
179 1.16.2.2 skrll wreq.wi_val[0] = htole16((ifp->if_flags & IFF_PROMISC) ? 1 : 0);
180 1.16.2.2 skrll wreq.wi_len = 1;
181 1.16.2.2 skrll break;
182 1.16.2.2 skrll case WI_RID_PORTTYPE:
183 1.16.2.2 skrll wreq.wi_val[0] = htole16(ic->ic_opmode);
184 1.16.2.2 skrll wreq.wi_len = 1;
185 1.16.2.2 skrll break;
186 1.16.2.2 skrll case WI_RID_MAC_NODE:
187 1.16.2.2 skrll IEEE80211_ADDR_COPY(wreq.wi_val, ic->ic_myaddr);
188 1.16.2.2 skrll wreq.wi_len = IEEE80211_ADDR_LEN / 2;
189 1.16.2.2 skrll break;
190 1.16.2.2 skrll case WI_RID_TX_RATE:
191 1.16.2.2 skrll if (ic->ic_fixed_rate == -1)
192 1.16.2.2 skrll wreq.wi_val[0] = 0; /* auto */
193 1.16.2.2 skrll else
194 1.16.2.2 skrll wreq.wi_val[0] = htole16(
195 1.16.2.2 skrll (ic->ic_sup_rates[ic->ic_curmode].rs_rates[ic->ic_fixed_rate] &
196 1.16.2.2 skrll IEEE80211_RATE_VAL) / 2);
197 1.16.2.2 skrll wreq.wi_len = 1;
198 1.16.2.2 skrll break;
199 1.16.2.2 skrll case WI_RID_CUR_TX_RATE:
200 1.16.2.2 skrll wreq.wi_val[0] = htole16(
201 1.16.2.2 skrll (ic->ic_bss->ni_rates.rs_rates[ic->ic_bss->ni_txrate] &
202 1.16.2.2 skrll IEEE80211_RATE_VAL) / 2);
203 1.16.2.2 skrll wreq.wi_len = 1;
204 1.16.2.2 skrll break;
205 1.16.2.2 skrll case WI_RID_FRAG_THRESH:
206 1.16.2.2 skrll wreq.wi_val[0] = htole16(ic->ic_fragthreshold);
207 1.16.2.2 skrll wreq.wi_len = 1;
208 1.16.2.2 skrll break;
209 1.16.2.2 skrll case WI_RID_RTS_THRESH:
210 1.16.2.2 skrll wreq.wi_val[0] = htole16(ic->ic_rtsthreshold);
211 1.16.2.2 skrll wreq.wi_len = 1;
212 1.16.2.2 skrll break;
213 1.16.2.2 skrll case WI_RID_CREATE_IBSS:
214 1.16.2.2 skrll wreq.wi_val[0] =
215 1.16.2.2 skrll htole16((ic->ic_flags & IEEE80211_F_IBSSON) ? 1 : 0);
216 1.16.2.2 skrll wreq.wi_len = 1;
217 1.16.2.2 skrll break;
218 1.16.2.2 skrll case WI_RID_MICROWAVE_OVEN:
219 1.16.2.2 skrll wreq.wi_val[0] = 0; /* no ... not supported */
220 1.16.2.2 skrll wreq.wi_len = 1;
221 1.16.2.2 skrll break;
222 1.16.2.2 skrll case WI_RID_ROAMING_MODE:
223 1.16.2.2 skrll wreq.wi_val[0] = htole16(1); /* enabled ... not supported */
224 1.16.2.2 skrll wreq.wi_len = 1;
225 1.16.2.2 skrll break;
226 1.16.2.2 skrll case WI_RID_SYSTEM_SCALE:
227 1.16.2.2 skrll wreq.wi_val[0] = htole16(1); /* low density ... not supp */
228 1.16.2.2 skrll wreq.wi_len = 1;
229 1.16.2.2 skrll break;
230 1.16.2.2 skrll case WI_RID_PM_ENABLED:
231 1.16.2.2 skrll wreq.wi_val[0] =
232 1.16.2.2 skrll htole16((ic->ic_flags & IEEE80211_F_PMGTON) ? 1 : 0);
233 1.16.2.2 skrll wreq.wi_len = 1;
234 1.16.2.2 skrll break;
235 1.16.2.2 skrll case WI_RID_MAX_SLEEP:
236 1.16.2.2 skrll wreq.wi_val[0] = htole16(ic->ic_lintval);
237 1.16.2.2 skrll wreq.wi_len = 1;
238 1.16.2.2 skrll break;
239 1.16.2.2 skrll case WI_RID_CUR_BEACON_INT:
240 1.16.2.2 skrll wreq.wi_val[0] = htole16(ic->ic_bss->ni_intval);
241 1.16.2.2 skrll wreq.wi_len = 1;
242 1.16.2.2 skrll break;
243 1.16.2.2 skrll case WI_RID_WEP_AVAIL:
244 1.16.2.2 skrll wreq.wi_val[0] =
245 1.16.2.2 skrll htole16((ic->ic_caps & IEEE80211_C_WEP) ? 1 : 0);
246 1.16.2.2 skrll wreq.wi_len = 1;
247 1.16.2.2 skrll break;
248 1.16.2.2 skrll case WI_RID_CNFAUTHMODE:
249 1.16.2.2 skrll wreq.wi_val[0] = htole16(1); /* TODO: open system only */
250 1.16.2.2 skrll wreq.wi_len = 1;
251 1.16.2.2 skrll break;
252 1.16.2.2 skrll case WI_RID_ENCRYPTION:
253 1.16.2.2 skrll wreq.wi_val[0] =
254 1.16.2.2 skrll htole16((ic->ic_flags & IEEE80211_F_PRIVACY) ? 1 : 0);
255 1.16.2.2 skrll wreq.wi_len = 1;
256 1.16.2.2 skrll break;
257 1.16.2.2 skrll case WI_RID_TX_CRYPT_KEY:
258 1.16.2.2 skrll wreq.wi_val[0] = htole16(ic->ic_wep_txkey);
259 1.16.2.2 skrll wreq.wi_len = 1;
260 1.16.2.2 skrll break;
261 1.16.2.2 skrll case WI_RID_DEFLT_CRYPT_KEYS:
262 1.16.2.2 skrll keys = (struct wi_ltv_keys *)&wreq;
263 1.16.2.2 skrll /* do not show keys to non-root user */
264 1.16.2.2 skrll error = suser(curproc->p_ucred, &curproc->p_acflag);
265 1.16.2.2 skrll if (error) {
266 1.16.2.2 skrll memset(keys, 0, sizeof(*keys));
267 1.16.2.2 skrll error = 0;
268 1.16.2.2 skrll break;
269 1.16.2.2 skrll }
270 1.16.2.2 skrll for (i = 0; i < IEEE80211_WEP_NKID; i++) {
271 1.16.2.2 skrll keys->wi_keys[i].wi_keylen =
272 1.16.2.2 skrll htole16(ic->ic_nw_keys[i].wk_len);
273 1.16.2.2 skrll memcpy(keys->wi_keys[i].wi_keydat,
274 1.16.2.2 skrll ic->ic_nw_keys[i].wk_key, ic->ic_nw_keys[i].wk_len);
275 1.16.2.2 skrll }
276 1.16.2.2 skrll wreq.wi_len = sizeof(*keys) / 2;
277 1.16.2.2 skrll break;
278 1.16.2.2 skrll case WI_RID_MAX_DATALEN:
279 1.16.2.2 skrll wreq.wi_val[0] = htole16(IEEE80211_MAX_LEN); /* TODO: frag */
280 1.16.2.2 skrll wreq.wi_len = 1;
281 1.16.2.2 skrll break;
282 1.16.2.2 skrll case WI_RID_DBM_ADJUST:
283 1.16.2.2 skrll /* not supported, we just pass rssi value from driver. */
284 1.16.2.2 skrll break;
285 1.16.2.2 skrll case WI_RID_IFACE_STATS:
286 1.16.2.2 skrll /* XXX: should be implemented in lower drivers */
287 1.16.2.2 skrll break;
288 1.16.2.2 skrll case WI_RID_READ_APS:
289 1.16.2.2 skrll if (ic->ic_opmode != IEEE80211_M_HOSTAP) {
290 1.16.2.2 skrll /*
291 1.16.2.2 skrll * Don't return results until active scan completes.
292 1.16.2.2 skrll */
293 1.16.2.2 skrll if (ic->ic_state == IEEE80211_S_SCAN &&
294 1.16.2.2 skrll (ic->ic_flags & IEEE80211_F_ASCAN)) {
295 1.16.2.2 skrll error = EINPROGRESS;
296 1.16.2.2 skrll break;
297 1.16.2.2 skrll }
298 1.16.2.2 skrll }
299 1.16.2.2 skrll i = 0;
300 1.16.2.2 skrll ap = (void *)((char *)wreq.wi_val + sizeof(i));
301 1.16.2.2 skrll TAILQ_FOREACH(ni, &ic->ic_node, ni_list) {
302 1.16.2.2 skrll if ((caddr_t)(ap + 1) > (caddr_t)(&wreq + 1))
303 1.16.2.2 skrll break;
304 1.16.2.2 skrll memset(ap, 0, sizeof(*ap));
305 1.16.2.2 skrll if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
306 1.16.2.2 skrll IEEE80211_ADDR_COPY(ap->bssid, ni->ni_macaddr);
307 1.16.2.2 skrll ap->namelen = ic->ic_des_esslen;
308 1.16.2.2 skrll if (ic->ic_des_esslen)
309 1.16.2.2 skrll memcpy(ap->name, ic->ic_des_essid,
310 1.16.2.2 skrll ic->ic_des_esslen);
311 1.16.2.2 skrll } else {
312 1.16.2.2 skrll IEEE80211_ADDR_COPY(ap->bssid, ni->ni_bssid);
313 1.16.2.2 skrll ap->namelen = ni->ni_esslen;
314 1.16.2.2 skrll if (ni->ni_esslen)
315 1.16.2.2 skrll memcpy(ap->name, ni->ni_essid,
316 1.16.2.2 skrll ni->ni_esslen);
317 1.16.2.2 skrll }
318 1.16.2.2 skrll ap->channel = ieee80211_chan2ieee(ic, ni->ni_chan);
319 1.16.2.2 skrll ap->signal = (*ic->ic_node_getrssi)(ic, ni);
320 1.16.2.2 skrll ap->capinfo = ni->ni_capinfo;
321 1.16.2.2 skrll ap->interval = ni->ni_intval;
322 1.16.2.2 skrll rs = &ni->ni_rates;
323 1.16.2.2 skrll for (j = 0; j < rs->rs_nrates; j++) {
324 1.16.2.2 skrll if (rs->rs_rates[j] & IEEE80211_RATE_BASIC) {
325 1.16.2.2 skrll ap->rate = (rs->rs_rates[j] &
326 1.16.2.2 skrll IEEE80211_RATE_VAL) * 5; /* XXX */
327 1.16.2.2 skrll }
328 1.16.2.2 skrll }
329 1.16.2.2 skrll i++;
330 1.16.2.2 skrll ap++;
331 1.16.2.2 skrll }
332 1.16.2.2 skrll memcpy(wreq.wi_val, &i, sizeof(i));
333 1.16.2.2 skrll wreq.wi_len = (sizeof(int) + sizeof(*ap) * i) / 2;
334 1.16.2.2 skrll break;
335 1.16.2.2 skrll #if 0
336 1.16.2.2 skrll case WI_RID_PRISM2:
337 1.16.2.2 skrll wreq.wi_val[0] = 1; /* XXX lie so SCAN_RES can give rates */
338 1.16.2.2 skrll wreq.wi_len = sizeof(u_int16_t) / 2;
339 1.16.2.2 skrll break;
340 1.16.2.2 skrll case WI_RID_SCAN_RES: /* compatibility interface */
341 1.16.2.2 skrll if (ic->ic_opmode != IEEE80211_M_HOSTAP &&
342 1.16.2.2 skrll ic->ic_state == IEEE80211_S_SCAN &&
343 1.16.2.2 skrll (ic->ic_flags & IEEE80211_F_ASCAN)) {
344 1.16.2.2 skrll error = EINPROGRESS;
345 1.16.2.2 skrll break;
346 1.16.2.2 skrll }
347 1.16.2.2 skrll /* NB: we use the Prism2 format so we can return rate info */
348 1.16.2.2 skrll p2 = (struct wi_scan_p2_hdr *)wreq.wi_val;
349 1.16.2.2 skrll res = (void *)&p2[1];
350 1.16.2.2 skrll i = 0;
351 1.16.2.2 skrll TAILQ_FOREACH(ni, &ic->ic_node, ni_list) {
352 1.16.2.2 skrll if ((caddr_t)(res + 1) > (caddr_t)(&wreq + 1))
353 1.16.2.2 skrll break;
354 1.16.2.2 skrll res->wi_chan = ieee80211_chan2ieee(ic, ni->ni_chan);
355 1.16.2.2 skrll res->wi_noise = 0;
356 1.16.2.2 skrll res->wi_signal = (*ic->ic_node_getrssi)(ic, ni);
357 1.16.2.2 skrll IEEE80211_ADDR_COPY(res->wi_bssid, ni->ni_bssid);
358 1.16.2.2 skrll res->wi_interval = ni->ni_intval;
359 1.16.2.2 skrll res->wi_capinfo = ni->ni_capinfo;
360 1.16.2.2 skrll res->wi_ssid_len = ni->ni_esslen;
361 1.16.2.2 skrll memcpy(res->wi_ssid, ni->ni_essid, IEEE80211_NWID_LEN);
362 1.16.2.2 skrll /* NB: assumes wi_srates holds <= ni->ni_rates */
363 1.16.2.2 skrll memcpy(res->wi_srates, ni->ni_rates.rs_rates,
364 1.16.2.2 skrll sizeof(res->wi_srates));
365 1.16.2.2 skrll if (ni->ni_rates.rs_nrates < 10)
366 1.16.2.2 skrll res->wi_srates[ni->ni_rates.rs_nrates] = 0;
367 1.16.2.2 skrll res->wi_rate = ni->ni_rates.rs_rates[ni->ni_txrate];
368 1.16.2.2 skrll res->wi_rsvd = 0;
369 1.16.2.2 skrll res++, i++;
370 1.16.2.2 skrll }
371 1.16.2.2 skrll p2->wi_rsvd = 0;
372 1.16.2.2 skrll p2->wi_reason = i;
373 1.16.2.2 skrll wreq.wi_len = (sizeof(*p2) + sizeof(*res) * i) / 2;
374 1.16.2.2 skrll break;
375 1.16.2.2 skrll #endif /* 0 */
376 1.16.2.2 skrll #ifdef WICACHE
377 1.16.2.2 skrll case WI_RID_READ_CACHE:
378 1.16.2.2 skrll i = 0;
379 1.16.2.2 skrll TAILQ_FOREACH(ni, &ic->ic_node, ni_list) {
380 1.16.2.2 skrll if (i == (WI_MAX_DATALEN/sizeof(struct wi_sigcache))-1)
381 1.16.2.2 skrll break;
382 1.16.2.2 skrll IEEE80211_ADDR_COPY(wsc.macsrc, ni->ni_macaddr);
383 1.16.2.2 skrll memset(&wsc.ipsrc, 0, sizeof(wsc.ipsrc));
384 1.16.2.2 skrll wsc.signal = (*ic->ic_node_getrssi)(ic, ni);
385 1.16.2.2 skrll wsc.noise = 0;
386 1.16.2.2 skrll wsc.quality = 0;
387 1.16.2.2 skrll memcpy((caddr_t)wreq.wi_val + sizeof(wsc) * i,
388 1.16.2.2 skrll &wsc, sizeof(wsc));
389 1.16.2.2 skrll i++;
390 1.16.2.2 skrll }
391 1.16.2.2 skrll wreq.wi_len = sizeof(wsc) * i / 2;
392 1.16.2.2 skrll break;
393 1.16.2.2 skrll #endif /* WICACHE */
394 1.16.2.2 skrll case WI_RID_SCAN_APS:
395 1.16.2.2 skrll error = EINVAL;
396 1.16.2.2 skrll break;
397 1.16.2.2 skrll default:
398 1.16.2.2 skrll error = EINVAL;
399 1.16.2.2 skrll break;
400 1.16.2.2 skrll }
401 1.16.2.2 skrll if (error == 0) {
402 1.16.2.2 skrll wreq.wi_len++;
403 1.16.2.2 skrll error = copyout(&wreq, ifr->ifr_data, sizeof(wreq));
404 1.16.2.2 skrll }
405 1.16.2.2 skrll return error;
406 1.16.2.2 skrll }
407 1.16.2.2 skrll
408 1.16.2.2 skrll static int
409 1.16.2.2 skrll findrate(struct ieee80211com *ic, enum ieee80211_phymode mode, int rate)
410 1.16.2.2 skrll {
411 1.16.2.2 skrll #define IEEERATE(_ic,_m,_i) \
412 1.16.2.2 skrll ((_ic)->ic_sup_rates[_m].rs_rates[_i] & IEEE80211_RATE_VAL)
413 1.16.2.2 skrll int i, nrates = ic->ic_sup_rates[mode].rs_nrates;
414 1.16.2.2 skrll for (i = 0; i < nrates; i++)
415 1.16.2.2 skrll if (IEEERATE(ic, mode, i) == rate)
416 1.16.2.2 skrll return i;
417 1.16.2.2 skrll return -1;
418 1.16.2.2 skrll #undef IEEERATE
419 1.16.2.2 skrll }
420 1.16.2.2 skrll
421 1.16.2.2 skrll /*
422 1.16.2.2 skrll * Prepare to do a user-initiated scan for AP's. If no
423 1.16.2.2 skrll * current/default channel is setup or the current channel
424 1.16.2.2 skrll * is invalid then pick the first available channel from
425 1.16.2.2 skrll * the active list as the place to start the scan.
426 1.16.2.2 skrll */
427 1.16.2.2 skrll static int
428 1.16.2.2 skrll ieee80211_setupscan(struct ieee80211com *ic)
429 1.16.2.2 skrll {
430 1.16.2.2 skrll u_char *chanlist = ic->ic_chan_active;
431 1.16.2.2 skrll int i;
432 1.16.2.2 skrll
433 1.16.2.2 skrll if (ic->ic_ibss_chan == NULL ||
434 1.16.2.2 skrll isclr(chanlist, ieee80211_chan2ieee(ic, ic->ic_ibss_chan))) {
435 1.16.2.2 skrll for (i = 0; i <= IEEE80211_CHAN_MAX; i++)
436 1.16.2.2 skrll if (isset(chanlist, i)) {
437 1.16.2.2 skrll ic->ic_ibss_chan = &ic->ic_channels[i];
438 1.16.2.2 skrll goto found;
439 1.16.2.2 skrll }
440 1.16.2.2 skrll return EINVAL; /* no active channels */
441 1.16.2.2 skrll found:
442 1.16.2.2 skrll ;
443 1.16.2.2 skrll }
444 1.16.2.2 skrll if (ic->ic_bss->ni_chan == IEEE80211_CHAN_ANYC ||
445 1.16.2.2 skrll isclr(chanlist, ieee80211_chan2ieee(ic, ic->ic_bss->ni_chan)))
446 1.16.2.2 skrll ic->ic_bss->ni_chan = ic->ic_ibss_chan;
447 1.16.2.2 skrll /*
448 1.16.2.2 skrll * XXX don't permit a scan to be started unless we
449 1.16.2.2 skrll * know the device is ready. For the moment this means
450 1.16.2.2 skrll * the device is marked up as this is the required to
451 1.16.2.2 skrll * initialize the hardware. It would be better to permit
452 1.16.2.2 skrll * scanning prior to being up but that'll require some
453 1.16.2.2 skrll * changes to the infrastructure.
454 1.16.2.2 skrll */
455 1.16.2.2 skrll return (ic->ic_if.if_flags & IFF_UP) ? 0 : ENETRESET;
456 1.16.2.2 skrll }
457 1.16.2.2 skrll
458 1.16.2.2 skrll int
459 1.16.2.2 skrll ieee80211_cfgset(struct ifnet *ifp, u_long cmd, caddr_t data)
460 1.16.2.2 skrll {
461 1.16.2.2 skrll struct ieee80211com *ic = (void *)ifp;
462 1.16.2.2 skrll int i, j, len, error, rate;
463 1.16.2.2 skrll struct ifreq *ifr = (struct ifreq *)data;
464 1.16.2.2 skrll struct wi_ltv_keys *keys;
465 1.16.2.2 skrll struct wi_req wreq;
466 1.16.2.2 skrll u_char chanlist[roundup(IEEE80211_CHAN_MAX, NBBY)];
467 1.16.2.2 skrll
468 1.16.2.2 skrll error = copyin(ifr->ifr_data, &wreq, sizeof(wreq));
469 1.16.2.2 skrll if (error)
470 1.16.2.2 skrll return error;
471 1.16.2.2 skrll len = wreq.wi_len ? (wreq.wi_len - 1) * 2 : 0;
472 1.16.2.2 skrll switch (wreq.wi_type) {
473 1.16.2.2 skrll case WI_RID_SERIALNO:
474 1.16.2.2 skrll case WI_RID_NODENAME:
475 1.16.2.2 skrll return EPERM;
476 1.16.2.2 skrll case WI_RID_CURRENT_SSID:
477 1.16.2.2 skrll return EPERM;
478 1.16.2.2 skrll case WI_RID_OWN_SSID:
479 1.16.2.2 skrll case WI_RID_DESIRED_SSID:
480 1.16.2.2 skrll if (le16toh(wreq.wi_val[0]) * 2 > len ||
481 1.16.2.2 skrll le16toh(wreq.wi_val[0]) > IEEE80211_NWID_LEN) {
482 1.16.2.2 skrll error = ENOSPC;
483 1.16.2.2 skrll break;
484 1.16.2.2 skrll }
485 1.16.2.2 skrll memset(ic->ic_des_essid, 0, sizeof(ic->ic_des_essid));
486 1.16.2.2 skrll ic->ic_des_esslen = le16toh(wreq.wi_val[0]) * 2;
487 1.16.2.2 skrll memcpy(ic->ic_des_essid, &wreq.wi_val[1], ic->ic_des_esslen);
488 1.16.2.2 skrll error = ENETRESET;
489 1.16.2.2 skrll break;
490 1.16.2.2 skrll case WI_RID_CURRENT_BSSID:
491 1.16.2.2 skrll return EPERM;
492 1.16.2.2 skrll case WI_RID_OWN_CHNL:
493 1.16.2.2 skrll if (len != 2)
494 1.16.2.2 skrll return EINVAL;
495 1.16.2.2 skrll i = le16toh(wreq.wi_val[0]);
496 1.16.2.2 skrll if (i < 0 ||
497 1.16.2.2 skrll i > IEEE80211_CHAN_MAX ||
498 1.16.2.2 skrll isclr(ic->ic_chan_active, i))
499 1.16.2.2 skrll return EINVAL;
500 1.16.2.2 skrll ic->ic_ibss_chan = &ic->ic_channels[i];
501 1.16.2.2 skrll if (ic->ic_flags & IEEE80211_F_SIBSS)
502 1.16.2.2 skrll error = ENETRESET;
503 1.16.2.2 skrll break;
504 1.16.2.2 skrll case WI_RID_CURRENT_CHAN:
505 1.16.2.2 skrll return EPERM;
506 1.16.2.2 skrll case WI_RID_COMMS_QUALITY:
507 1.16.2.2 skrll return EPERM;
508 1.16.2.2 skrll case WI_RID_PROMISC:
509 1.16.2.2 skrll if (len != 2)
510 1.16.2.2 skrll return EINVAL;
511 1.16.2.2 skrll if (ifp->if_flags & IFF_PROMISC) {
512 1.16.2.2 skrll if (wreq.wi_val[0] == 0) {
513 1.16.2.2 skrll ifp->if_flags &= ~IFF_PROMISC;
514 1.16.2.2 skrll error = ENETRESET;
515 1.16.2.2 skrll }
516 1.16.2.2 skrll } else {
517 1.16.2.2 skrll if (wreq.wi_val[0] != 0) {
518 1.16.2.2 skrll ifp->if_flags |= IFF_PROMISC;
519 1.16.2.2 skrll error = ENETRESET;
520 1.16.2.2 skrll }
521 1.16.2.2 skrll }
522 1.16.2.2 skrll break;
523 1.16.2.2 skrll case WI_RID_PORTTYPE:
524 1.16.2.2 skrll if (len != 2)
525 1.16.2.2 skrll return EINVAL;
526 1.16.2.2 skrll switch (le16toh(wreq.wi_val[0])) {
527 1.16.2.2 skrll case IEEE80211_M_STA:
528 1.16.2.2 skrll break;
529 1.16.2.2 skrll case IEEE80211_M_IBSS:
530 1.16.2.2 skrll if (!(ic->ic_caps & IEEE80211_C_IBSS))
531 1.16.2.2 skrll return EINVAL;
532 1.16.2.2 skrll break;
533 1.16.2.2 skrll case IEEE80211_M_AHDEMO:
534 1.16.2.2 skrll if (ic->ic_phytype != IEEE80211_T_DS ||
535 1.16.2.2 skrll !(ic->ic_caps & IEEE80211_C_AHDEMO))
536 1.16.2.2 skrll return EINVAL;
537 1.16.2.2 skrll break;
538 1.16.2.2 skrll case IEEE80211_M_HOSTAP:
539 1.16.2.2 skrll if (!(ic->ic_caps & IEEE80211_C_HOSTAP))
540 1.16.2.2 skrll return EINVAL;
541 1.16.2.2 skrll break;
542 1.16.2.2 skrll default:
543 1.16.2.2 skrll return EINVAL;
544 1.16.2.2 skrll }
545 1.16.2.2 skrll if (le16toh(wreq.wi_val[0]) != ic->ic_opmode) {
546 1.16.2.2 skrll ic->ic_opmode = le16toh(wreq.wi_val[0]);
547 1.16.2.2 skrll error = ENETRESET;
548 1.16.2.2 skrll }
549 1.16.2.2 skrll break;
550 1.16.2.2 skrll #if 0
551 1.16.2.2 skrll case WI_RID_MAC_NODE:
552 1.16.2.2 skrll if (len != IEEE80211_ADDR_LEN)
553 1.16.2.2 skrll return EINVAL;
554 1.16.2.2 skrll IEEE80211_ADDR_COPY(LLADDR(ifp->if_sadl), wreq.wi_val);
555 1.16.2.2 skrll /* if_init will copy lladdr into ic_myaddr */
556 1.16.2.2 skrll error = ENETRESET;
557 1.16.2.2 skrll break;
558 1.16.2.2 skrll #endif
559 1.16.2.2 skrll case WI_RID_TX_RATE:
560 1.16.2.2 skrll if (len != 2)
561 1.16.2.2 skrll return EINVAL;
562 1.16.2.2 skrll if (wreq.wi_val[0] == 0) {
563 1.16.2.2 skrll /* auto */
564 1.16.2.2 skrll ic->ic_fixed_rate = -1;
565 1.16.2.2 skrll break;
566 1.16.2.2 skrll }
567 1.16.2.2 skrll rate = 2 * le16toh(wreq.wi_val[0]);
568 1.16.2.2 skrll if (ic->ic_curmode == IEEE80211_MODE_AUTO) {
569 1.16.2.2 skrll /*
570 1.16.2.2 skrll * In autoselect mode search for the rate. We take
571 1.16.2.2 skrll * the first instance which may not be right, but we
572 1.16.2.2 skrll * are limited by the interface. Note that we also
573 1.16.2.2 skrll * lock the mode to insure the rate is meaningful
574 1.16.2.2 skrll * when it is used.
575 1.16.2.2 skrll */
576 1.16.2.2 skrll for (j = IEEE80211_MODE_11A;
577 1.16.2.2 skrll j < IEEE80211_MODE_MAX; j++) {
578 1.16.2.2 skrll if ((ic->ic_modecaps & (1<<j)) == 0)
579 1.16.2.2 skrll continue;
580 1.16.2.2 skrll i = findrate(ic, j, rate);
581 1.16.2.2 skrll if (i != -1) {
582 1.16.2.2 skrll /* lock mode too */
583 1.16.2.2 skrll ic->ic_curmode = j;
584 1.16.2.2 skrll goto setrate;
585 1.16.2.2 skrll }
586 1.16.2.2 skrll }
587 1.16.2.2 skrll } else {
588 1.16.2.2 skrll i = findrate(ic, ic->ic_curmode, rate);
589 1.16.2.2 skrll if (i != -1)
590 1.16.2.2 skrll goto setrate;
591 1.16.2.2 skrll }
592 1.16.2.2 skrll return EINVAL;
593 1.16.2.2 skrll setrate:
594 1.16.2.2 skrll ic->ic_fixed_rate = i;
595 1.16.2.2 skrll error = ENETRESET;
596 1.16.2.2 skrll break;
597 1.16.2.2 skrll case WI_RID_CUR_TX_RATE:
598 1.16.2.2 skrll return EPERM;
599 1.16.2.2 skrll case WI_RID_FRAG_THRESH:
600 1.16.2.2 skrll if (len != 2)
601 1.16.2.2 skrll return EINVAL;
602 1.16.2.2 skrll ic->ic_fragthreshold = le16toh(wreq.wi_val[0]);
603 1.16.2.2 skrll error = ENETRESET;
604 1.16.2.2 skrll break;
605 1.16.2.2 skrll case WI_RID_RTS_THRESH:
606 1.16.2.2 skrll if (len != 2)
607 1.16.2.2 skrll return EINVAL;
608 1.16.2.2 skrll ic->ic_rtsthreshold = le16toh(wreq.wi_val[0]);
609 1.16.2.2 skrll error = ENETRESET;
610 1.16.2.2 skrll break;
611 1.16.2.2 skrll case WI_RID_CREATE_IBSS:
612 1.16.2.2 skrll if (len != 2)
613 1.16.2.2 skrll return EINVAL;
614 1.16.2.2 skrll if (wreq.wi_val[0] != 0) {
615 1.16.2.2 skrll if ((ic->ic_caps & IEEE80211_C_IBSS) == 0)
616 1.16.2.2 skrll return EINVAL;
617 1.16.2.2 skrll if ((ic->ic_flags & IEEE80211_F_IBSSON) == 0) {
618 1.16.2.2 skrll ic->ic_flags |= IEEE80211_F_IBSSON;
619 1.16.2.2 skrll if (ic->ic_opmode == IEEE80211_M_IBSS &&
620 1.16.2.2 skrll ic->ic_state == IEEE80211_S_SCAN)
621 1.16.2.2 skrll error = ENETRESET;
622 1.16.2.2 skrll }
623 1.16.2.2 skrll } else {
624 1.16.2.2 skrll if (ic->ic_flags & IEEE80211_F_IBSSON) {
625 1.16.2.2 skrll ic->ic_flags &= ~IEEE80211_F_IBSSON;
626 1.16.2.2 skrll if (ic->ic_flags & IEEE80211_F_SIBSS) {
627 1.16.2.2 skrll ic->ic_flags &= ~IEEE80211_F_SIBSS;
628 1.16.2.2 skrll error = ENETRESET;
629 1.16.2.2 skrll }
630 1.16.2.2 skrll }
631 1.16.2.2 skrll }
632 1.16.2.2 skrll break;
633 1.16.2.2 skrll case WI_RID_MICROWAVE_OVEN:
634 1.16.2.2 skrll if (len != 2)
635 1.16.2.2 skrll return EINVAL;
636 1.16.2.2 skrll if (wreq.wi_val[0] != 0)
637 1.16.2.2 skrll return EINVAL; /* not supported */
638 1.16.2.2 skrll break;
639 1.16.2.2 skrll case WI_RID_ROAMING_MODE:
640 1.16.2.2 skrll if (len != 2)
641 1.16.2.2 skrll return EINVAL;
642 1.16.2.2 skrll if (le16toh(wreq.wi_val[0]) != 1)
643 1.16.2.2 skrll return EINVAL; /* not supported */
644 1.16.2.2 skrll break;
645 1.16.2.2 skrll case WI_RID_SYSTEM_SCALE:
646 1.16.2.2 skrll if (len != 2)
647 1.16.2.2 skrll return EINVAL;
648 1.16.2.2 skrll if (le16toh(wreq.wi_val[0]) != 1)
649 1.16.2.2 skrll return EINVAL; /* not supported */
650 1.16.2.2 skrll break;
651 1.16.2.2 skrll case WI_RID_PM_ENABLED:
652 1.16.2.2 skrll if (len != 2)
653 1.16.2.2 skrll return EINVAL;
654 1.16.2.2 skrll if (wreq.wi_val[0] != 0) {
655 1.16.2.2 skrll if ((ic->ic_caps & IEEE80211_C_PMGT) == 0)
656 1.16.2.2 skrll return EINVAL;
657 1.16.2.2 skrll if ((ic->ic_flags & IEEE80211_F_PMGTON) == 0) {
658 1.16.2.2 skrll ic->ic_flags |= IEEE80211_F_PMGTON;
659 1.16.2.2 skrll error = ENETRESET;
660 1.16.2.2 skrll }
661 1.16.2.2 skrll } else {
662 1.16.2.2 skrll if (ic->ic_flags & IEEE80211_F_PMGTON) {
663 1.16.2.2 skrll ic->ic_flags &= ~IEEE80211_F_PMGTON;
664 1.16.2.2 skrll error = ENETRESET;
665 1.16.2.2 skrll }
666 1.16.2.2 skrll }
667 1.16.2.2 skrll break;
668 1.16.2.2 skrll case WI_RID_MAX_SLEEP:
669 1.16.2.2 skrll if (len != 2)
670 1.16.2.2 skrll return EINVAL;
671 1.16.2.2 skrll ic->ic_lintval = le16toh(wreq.wi_val[0]);
672 1.16.2.2 skrll if (ic->ic_flags & IEEE80211_F_PMGTON)
673 1.16.2.2 skrll error = ENETRESET;
674 1.16.2.2 skrll break;
675 1.16.2.2 skrll case WI_RID_CUR_BEACON_INT:
676 1.16.2.2 skrll return EPERM;
677 1.16.2.2 skrll case WI_RID_WEP_AVAIL:
678 1.16.2.2 skrll return EPERM;
679 1.16.2.2 skrll case WI_RID_CNFAUTHMODE:
680 1.16.2.2 skrll if (len != 2)
681 1.16.2.2 skrll return EINVAL;
682 1.16.2.2 skrll if (le16toh(wreq.wi_val[0]) != 1)
683 1.16.2.2 skrll return EINVAL; /* TODO: shared key auth */
684 1.16.2.2 skrll break;
685 1.16.2.2 skrll case WI_RID_ENCRYPTION:
686 1.16.2.2 skrll if (len != 2)
687 1.16.2.2 skrll return EINVAL;
688 1.16.2.2 skrll if (wreq.wi_val[0] != 0) {
689 1.16.2.2 skrll if ((ic->ic_caps & IEEE80211_C_WEP) == 0)
690 1.16.2.2 skrll return EINVAL;
691 1.16.2.2 skrll if ((ic->ic_flags & IEEE80211_F_PRIVACY) == 0) {
692 1.16.2.2 skrll ic->ic_flags |= IEEE80211_F_PRIVACY;
693 1.16.2.2 skrll error = ENETRESET;
694 1.16.2.2 skrll }
695 1.16.2.2 skrll } else {
696 1.16.2.2 skrll if (ic->ic_flags & IEEE80211_F_PRIVACY) {
697 1.16.2.2 skrll ic->ic_flags &= ~IEEE80211_F_PRIVACY;
698 1.16.2.2 skrll error = ENETRESET;
699 1.16.2.2 skrll }
700 1.16.2.2 skrll }
701 1.16.2.2 skrll break;
702 1.16.2.2 skrll case WI_RID_TX_CRYPT_KEY:
703 1.16.2.2 skrll if (len != 2)
704 1.16.2.2 skrll return EINVAL;
705 1.16.2.2 skrll i = le16toh(wreq.wi_val[0]);
706 1.16.2.2 skrll if (i >= IEEE80211_WEP_NKID)
707 1.16.2.2 skrll return EINVAL;
708 1.16.2.2 skrll ic->ic_wep_txkey = i;
709 1.16.2.2 skrll break;
710 1.16.2.2 skrll case WI_RID_DEFLT_CRYPT_KEYS:
711 1.16.2.2 skrll if (len != sizeof(struct wi_ltv_keys))
712 1.16.2.2 skrll return EINVAL;
713 1.16.2.2 skrll keys = (struct wi_ltv_keys *)&wreq;
714 1.16.2.2 skrll for (i = 0; i < IEEE80211_WEP_NKID; i++) {
715 1.16.2.2 skrll len = le16toh(keys->wi_keys[i].wi_keylen);
716 1.16.2.2 skrll if (len != 0 && len < IEEE80211_WEP_KEYLEN)
717 1.16.2.2 skrll return EINVAL;
718 1.16.2.2 skrll if (len > sizeof(ic->ic_nw_keys[i].wk_key))
719 1.16.2.2 skrll return EINVAL;
720 1.16.2.2 skrll }
721 1.16.2.2 skrll memset(ic->ic_nw_keys, 0, sizeof(ic->ic_nw_keys));
722 1.16.2.2 skrll for (i = 0; i < IEEE80211_WEP_NKID; i++) {
723 1.16.2.2 skrll len = le16toh(keys->wi_keys[i].wi_keylen);
724 1.16.2.2 skrll ic->ic_nw_keys[i].wk_len = len;
725 1.16.2.2 skrll memcpy(ic->ic_nw_keys[i].wk_key,
726 1.16.2.2 skrll keys->wi_keys[i].wi_keydat, len);
727 1.16.2.2 skrll }
728 1.16.2.2 skrll error = ENETRESET;
729 1.16.2.2 skrll break;
730 1.16.2.2 skrll case WI_RID_MAX_DATALEN:
731 1.16.2.2 skrll if (len != 2)
732 1.16.2.2 skrll return EINVAL;
733 1.16.2.2 skrll len = le16toh(wreq.wi_val[0]);
734 1.16.2.2 skrll if (len < 350 /* ? */ || len > IEEE80211_MAX_LEN)
735 1.16.2.2 skrll return EINVAL;
736 1.16.2.2 skrll if (len != IEEE80211_MAX_LEN)
737 1.16.2.2 skrll return EINVAL; /* TODO: fragment */
738 1.16.2.2 skrll ic->ic_fragthreshold = len;
739 1.16.2.2 skrll error = ENETRESET;
740 1.16.2.2 skrll break;
741 1.16.2.2 skrll case WI_RID_IFACE_STATS:
742 1.16.2.2 skrll error = EPERM;
743 1.16.2.2 skrll break;
744 1.16.2.2 skrll case WI_RID_SCAN_REQ: /* XXX wicontrol */
745 1.16.2.2 skrll if (ic->ic_opmode == IEEE80211_M_HOSTAP)
746 1.16.2.2 skrll break;
747 1.16.2.2 skrll error = ieee80211_setupscan(ic);
748 1.16.2.2 skrll if (error == 0)
749 1.16.2.2 skrll error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
750 1.16.2.2 skrll break;
751 1.16.2.2 skrll case WI_RID_SCAN_APS:
752 1.16.2.2 skrll if (ic->ic_opmode == IEEE80211_M_HOSTAP)
753 1.16.2.2 skrll break;
754 1.16.2.2 skrll len--; /* XXX: tx rate? */
755 1.16.2.2 skrll /* FALLTHRU */
756 1.16.2.2 skrll case WI_RID_CHANNEL_LIST:
757 1.16.2.2 skrll memset(chanlist, 0, sizeof(chanlist));
758 1.16.2.2 skrll /*
759 1.16.2.2 skrll * Since channel 0 is not available for DS, channel 1
760 1.16.2.2 skrll * is assigned to LSB on WaveLAN.
761 1.16.2.2 skrll */
762 1.16.2.2 skrll if (ic->ic_phytype == IEEE80211_T_DS)
763 1.16.2.2 skrll i = 1;
764 1.16.2.2 skrll else
765 1.16.2.2 skrll i = 0;
766 1.16.2.2 skrll for (j = 0; i <= IEEE80211_CHAN_MAX; i++, j++) {
767 1.16.2.2 skrll if ((j / 8) >= len)
768 1.16.2.2 skrll break;
769 1.16.2.2 skrll if (isclr((u_int8_t *)wreq.wi_val, j))
770 1.16.2.2 skrll continue;
771 1.16.2.2 skrll if (isclr(ic->ic_chan_active, i)) {
772 1.16.2.2 skrll if (wreq.wi_type != WI_RID_CHANNEL_LIST)
773 1.16.2.2 skrll continue;
774 1.16.2.2 skrll if (isclr(ic->ic_chan_avail, i))
775 1.16.2.2 skrll return EPERM;
776 1.16.2.2 skrll }
777 1.16.2.2 skrll setbit(chanlist, i);
778 1.16.2.2 skrll }
779 1.16.2.2 skrll memcpy(ic->ic_chan_active, chanlist,
780 1.16.2.2 skrll sizeof(ic->ic_chan_active));
781 1.16.2.2 skrll error = ieee80211_setupscan(ic);
782 1.16.2.2 skrll if (wreq.wi_type == WI_RID_CHANNEL_LIST) {
783 1.16.2.2 skrll /* NB: ignore error from ieee80211_setupscan */
784 1.16.2.2 skrll error = ENETRESET;
785 1.16.2.2 skrll } else if (error == 0)
786 1.16.2.2 skrll error = ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
787 1.16.2.2 skrll break;
788 1.16.2.2 skrll default:
789 1.16.2.2 skrll error = EINVAL;
790 1.16.2.2 skrll break;
791 1.16.2.2 skrll }
792 1.16.2.2 skrll return error;
793 1.16.2.2 skrll }
794 1.16.2.2 skrll
795 1.16.2.2 skrll #ifdef __FreeBSD__
796 1.16.2.2 skrll int
797 1.16.2.2 skrll ieee80211_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
798 1.16.2.2 skrll {
799 1.16.2.2 skrll struct ieee80211com *ic = (void *)ifp;
800 1.16.2.2 skrll int error = 0;
801 1.16.2.2 skrll u_int kid, len;
802 1.16.2.2 skrll struct ieee80211req *ireq;
803 1.16.2.2 skrll struct ifreq *ifr;
804 1.16.2.2 skrll u_int8_t tmpkey[IEEE80211_KEYBUF_SIZE];
805 1.16.2.2 skrll char tmpssid[IEEE80211_NWID_LEN];
806 1.16.2.2 skrll struct ieee80211_channel *chan;
807 1.16.2.2 skrll struct ifaddr *ifa; /* XXX */
808 1.16.2.2 skrll
809 1.16.2.2 skrll switch (cmd) {
810 1.16.2.2 skrll case SIOCSIFMEDIA:
811 1.16.2.2 skrll case SIOCGIFMEDIA:
812 1.16.2.2 skrll error = ifmedia_ioctl(ifp, (struct ifreq *) data,
813 1.16.2.2 skrll &ic->ic_media, cmd);
814 1.16.2.2 skrll break;
815 1.16.2.2 skrll case SIOCG80211:
816 1.16.2.2 skrll ireq = (struct ieee80211req *) data;
817 1.16.2.2 skrll switch (ireq->i_type) {
818 1.16.2.2 skrll case IEEE80211_IOC_SSID:
819 1.16.2.2 skrll switch (ic->ic_state) {
820 1.16.2.2 skrll case IEEE80211_S_INIT:
821 1.16.2.2 skrll case IEEE80211_S_SCAN:
822 1.16.2.2 skrll ireq->i_len = ic->ic_des_esslen;
823 1.16.2.2 skrll memcpy(tmpssid, ic->ic_des_essid, ireq->i_len);
824 1.16.2.2 skrll break;
825 1.16.2.2 skrll default:
826 1.16.2.2 skrll ireq->i_len = ic->ic_bss->ni_esslen;
827 1.16.2.2 skrll memcpy(tmpssid, ic->ic_bss->ni_essid,
828 1.16.2.2 skrll ireq->i_len);
829 1.16.2.2 skrll break;
830 1.16.2.2 skrll }
831 1.16.2.2 skrll error = copyout(tmpssid, ireq->i_data, ireq->i_len);
832 1.16.2.2 skrll break;
833 1.16.2.2 skrll case IEEE80211_IOC_NUMSSIDS:
834 1.16.2.2 skrll ireq->i_val = 1;
835 1.16.2.2 skrll break;
836 1.16.2.2 skrll case IEEE80211_IOC_WEP:
837 1.16.2.2 skrll if ((ic->ic_caps & IEEE80211_C_WEP) == 0) {
838 1.16.2.6 skrll ireq->i_val = IEEE80211_WEP_NOSUP;
839 1.16.2.2 skrll } else {
840 1.16.2.2 skrll if (ic->ic_flags & IEEE80211_F_PRIVACY) {
841 1.16.2.2 skrll ireq->i_val =
842 1.16.2.2 skrll IEEE80211_WEP_MIXED;
843 1.16.2.2 skrll } else {
844 1.16.2.2 skrll ireq->i_val =
845 1.16.2.2 skrll IEEE80211_WEP_OFF;
846 1.16.2.2 skrll }
847 1.16.2.2 skrll }
848 1.16.2.2 skrll break;
849 1.16.2.2 skrll case IEEE80211_IOC_WEPKEY:
850 1.16.2.2 skrll if ((ic->ic_caps & IEEE80211_C_WEP) == 0) {
851 1.16.2.2 skrll error = EINVAL;
852 1.16.2.2 skrll break;
853 1.16.2.2 skrll }
854 1.16.2.2 skrll kid = (u_int) ireq->i_val;
855 1.16.2.2 skrll if (kid >= IEEE80211_WEP_NKID) {
856 1.16.2.2 skrll error = EINVAL;
857 1.16.2.2 skrll break;
858 1.16.2.2 skrll }
859 1.16.2.2 skrll len = (u_int) ic->ic_nw_keys[kid].wk_len;
860 1.16.2.2 skrll /* NB: only root can read WEP keys */
861 1.16.2.2 skrll if (suser(curthread) == 0) {
862 1.16.2.2 skrll bcopy(ic->ic_nw_keys[kid].wk_key, tmpkey, len);
863 1.16.2.2 skrll } else {
864 1.16.2.2 skrll bzero(tmpkey, len);
865 1.16.2.2 skrll }
866 1.16.2.2 skrll ireq->i_len = len;
867 1.16.2.2 skrll error = copyout(tmpkey, ireq->i_data, len);
868 1.16.2.2 skrll break;
869 1.16.2.2 skrll case IEEE80211_IOC_NUMWEPKEYS:
870 1.16.2.2 skrll if ((ic->ic_caps & IEEE80211_C_WEP) == 0)
871 1.16.2.2 skrll error = EINVAL;
872 1.16.2.2 skrll else
873 1.16.2.2 skrll ireq->i_val = IEEE80211_WEP_NKID;
874 1.16.2.2 skrll break;
875 1.16.2.2 skrll case IEEE80211_IOC_WEPTXKEY:
876 1.16.2.2 skrll if ((ic->ic_caps & IEEE80211_C_WEP) == 0)
877 1.16.2.2 skrll error = EINVAL;
878 1.16.2.2 skrll else
879 1.16.2.2 skrll ireq->i_val = ic->ic_wep_txkey;
880 1.16.2.2 skrll break;
881 1.16.2.2 skrll case IEEE80211_IOC_AUTHMODE:
882 1.16.2.2 skrll ireq->i_val = IEEE80211_AUTH_OPEN;
883 1.16.2.2 skrll break;
884 1.16.2.2 skrll case IEEE80211_IOC_CHANNEL:
885 1.16.2.2 skrll switch (ic->ic_state) {
886 1.16.2.2 skrll case IEEE80211_S_INIT:
887 1.16.2.2 skrll case IEEE80211_S_SCAN:
888 1.16.2.2 skrll if (ic->ic_opmode == IEEE80211_M_STA)
889 1.16.2.2 skrll chan = ic->ic_des_chan;
890 1.16.2.2 skrll else
891 1.16.2.2 skrll chan = ic->ic_ibss_chan;
892 1.16.2.2 skrll break;
893 1.16.2.2 skrll default:
894 1.16.2.2 skrll chan = ic->ic_bss->ni_chan;
895 1.16.2.2 skrll break;
896 1.16.2.2 skrll }
897 1.16.2.2 skrll ireq->i_val = ieee80211_chan2ieee(ic, chan);
898 1.16.2.2 skrll break;
899 1.16.2.2 skrll case IEEE80211_IOC_POWERSAVE:
900 1.16.2.2 skrll if (ic->ic_flags & IEEE80211_F_PMGTON)
901 1.16.2.2 skrll ireq->i_val = IEEE80211_POWERSAVE_ON;
902 1.16.2.2 skrll else
903 1.16.2.2 skrll ireq->i_val = IEEE80211_POWERSAVE_OFF;
904 1.16.2.2 skrll break;
905 1.16.2.2 skrll case IEEE80211_IOC_POWERSAVESLEEP:
906 1.16.2.2 skrll ireq->i_val = ic->ic_lintval;
907 1.16.2.2 skrll break;
908 1.16.2.2 skrll case IEEE80211_IOC_RTSTHRESHOLD:
909 1.16.2.2 skrll ireq->i_val = ic->ic_rtsthreshold;
910 1.16.2.2 skrll break;
911 1.16.2.2 skrll case IEEE80211_IOC_PROTMODE:
912 1.16.2.2 skrll ireq->i_val = ic->ic_protmode;
913 1.16.2.2 skrll break;
914 1.16.2.2 skrll case IEEE80211_IOC_TXPOWER:
915 1.16.2.2 skrll if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0)
916 1.16.2.2 skrll error = EINVAL;
917 1.16.2.2 skrll else
918 1.16.2.2 skrll ireq->i_val = ic->ic_txpower;
919 1.16.2.2 skrll break;
920 1.16.2.2 skrll default:
921 1.16.2.2 skrll error = EINVAL;
922 1.16.2.2 skrll break;
923 1.16.2.2 skrll }
924 1.16.2.2 skrll break;
925 1.16.2.2 skrll case SIOCS80211:
926 1.16.2.2 skrll error = suser(curproc->p_ucred, &curproc->p_acflag);
927 1.16.2.2 skrll if (error)
928 1.16.2.2 skrll break;
929 1.16.2.2 skrll ireq = (struct ieee80211req *) data;
930 1.16.2.2 skrll switch (ireq->i_type) {
931 1.16.2.2 skrll case IEEE80211_IOC_SSID:
932 1.16.2.2 skrll if (ireq->i_val != 0 ||
933 1.16.2.2 skrll ireq->i_len > IEEE80211_NWID_LEN) {
934 1.16.2.2 skrll error = EINVAL;
935 1.16.2.2 skrll break;
936 1.16.2.2 skrll }
937 1.16.2.2 skrll error = copyin(ireq->i_data, tmpssid, ireq->i_len);
938 1.16.2.2 skrll if (error)
939 1.16.2.2 skrll break;
940 1.16.2.2 skrll memset(ic->ic_des_essid, 0, IEEE80211_NWID_LEN);
941 1.16.2.2 skrll ic->ic_des_esslen = ireq->i_len;
942 1.16.2.2 skrll memcpy(ic->ic_des_essid, tmpssid, ireq->i_len);
943 1.16.2.2 skrll error = ENETRESET;
944 1.16.2.2 skrll break;
945 1.16.2.2 skrll case IEEE80211_IOC_WEP:
946 1.16.2.2 skrll /*
947 1.16.2.2 skrll * These cards only support one mode so
948 1.16.2.2 skrll * we just turn wep on if what ever is
949 1.16.2.2 skrll * passed in is not OFF.
950 1.16.2.2 skrll */
951 1.16.2.2 skrll if (ireq->i_val == IEEE80211_WEP_OFF) {
952 1.16.2.2 skrll ic->ic_flags &= ~IEEE80211_F_PRIVACY;
953 1.16.2.2 skrll } else {
954 1.16.2.2 skrll ic->ic_flags |= IEEE80211_F_PRIVACY;
955 1.16.2.2 skrll }
956 1.16.2.2 skrll error = ENETRESET;
957 1.16.2.2 skrll break;
958 1.16.2.2 skrll case IEEE80211_IOC_WEPKEY:
959 1.16.2.2 skrll if ((ic->ic_caps & IEEE80211_C_WEP) == 0) {
960 1.16.2.2 skrll error = EINVAL;
961 1.16.2.2 skrll break;
962 1.16.2.2 skrll }
963 1.16.2.2 skrll kid = (u_int) ireq->i_val;
964 1.16.2.2 skrll if (kid >= IEEE80211_WEP_NKID) {
965 1.16.2.2 skrll error = EINVAL;
966 1.16.2.2 skrll break;
967 1.16.2.6 skrll }
968 1.16.2.2 skrll if (ireq->i_len > sizeof(tmpkey)) {
969 1.16.2.2 skrll error = EINVAL;
970 1.16.2.2 skrll break;
971 1.16.2.2 skrll }
972 1.16.2.2 skrll memset(tmpkey, 0, sizeof(tmpkey));
973 1.16.2.2 skrll error = copyin(ireq->i_data, tmpkey, ireq->i_len);
974 1.16.2.2 skrll if (error)
975 1.16.2.2 skrll break;
976 1.16.2.2 skrll memcpy(ic->ic_nw_keys[kid].wk_key, tmpkey,
977 1.16.2.2 skrll sizeof(tmpkey));
978 1.16.2.2 skrll ic->ic_nw_keys[kid].wk_len = ireq->i_len;
979 1.16.2.2 skrll error = ENETRESET;
980 1.16.2.2 skrll break;
981 1.16.2.2 skrll case IEEE80211_IOC_WEPTXKEY:
982 1.16.2.2 skrll kid = (u_int) ireq->i_val;
983 1.16.2.2 skrll if (kid >= IEEE80211_WEP_NKID) {
984 1.16.2.2 skrll error = EINVAL;
985 1.16.2.2 skrll break;
986 1.16.2.2 skrll }
987 1.16.2.2 skrll ic->ic_wep_txkey = kid;
988 1.16.2.2 skrll error = ENETRESET;
989 1.16.2.2 skrll break;
990 1.16.2.2 skrll #if 0
991 1.16.2.2 skrll case IEEE80211_IOC_AUTHMODE:
992 1.16.2.2 skrll sc->wi_authmode = ireq->i_val;
993 1.16.2.2 skrll break;
994 1.16.2.2 skrll #endif
995 1.16.2.2 skrll case IEEE80211_IOC_CHANNEL:
996 1.16.2.2 skrll /* XXX 0xffff overflows 16-bit signed */
997 1.16.2.2 skrll if (ireq->i_val == 0 ||
998 1.16.2.2 skrll ireq->i_val == (int16_t) IEEE80211_CHAN_ANY)
999 1.16.2.2 skrll ic->ic_des_chan = IEEE80211_CHAN_ANYC;
1000 1.16.2.2 skrll else if ((u_int) ireq->i_val > IEEE80211_CHAN_MAX ||
1001 1.16.2.2 skrll isclr(ic->ic_chan_active, ireq->i_val)) {
1002 1.16.2.2 skrll error = EINVAL;
1003 1.16.2.2 skrll break;
1004 1.16.2.2 skrll } else
1005 1.16.2.2 skrll ic->ic_ibss_chan = ic->ic_des_chan =
1006 1.16.2.2 skrll &ic->ic_channels[ireq->i_val];
1007 1.16.2.2 skrll switch (ic->ic_state) {
1008 1.16.2.2 skrll case IEEE80211_S_INIT:
1009 1.16.2.2 skrll case IEEE80211_S_SCAN:
1010 1.16.2.2 skrll error = ENETRESET;
1011 1.16.2.2 skrll break;
1012 1.16.2.2 skrll default:
1013 1.16.2.2 skrll if (ic->ic_opmode == IEEE80211_M_STA) {
1014 1.16.2.2 skrll if (ic->ic_des_chan != IEEE80211_CHAN_ANYC &&
1015 1.16.2.2 skrll ic->ic_bss->ni_chan != ic->ic_des_chan)
1016 1.16.2.2 skrll error = ENETRESET;
1017 1.16.2.2 skrll } else {
1018 1.16.2.2 skrll if (ic->ic_bss->ni_chan != ic->ic_ibss_chan)
1019 1.16.2.2 skrll error = ENETRESET;
1020 1.16.2.2 skrll }
1021 1.16.2.2 skrll break;
1022 1.16.2.2 skrll }
1023 1.16.2.2 skrll break;
1024 1.16.2.2 skrll case IEEE80211_IOC_POWERSAVE:
1025 1.16.2.2 skrll switch (ireq->i_val) {
1026 1.16.2.2 skrll case IEEE80211_POWERSAVE_OFF:
1027 1.16.2.2 skrll if (ic->ic_flags & IEEE80211_F_PMGTON) {
1028 1.16.2.2 skrll ic->ic_flags &= ~IEEE80211_F_PMGTON;
1029 1.16.2.2 skrll error = ENETRESET;
1030 1.16.2.2 skrll }
1031 1.16.2.2 skrll break;
1032 1.16.2.2 skrll case IEEE80211_POWERSAVE_ON:
1033 1.16.2.2 skrll if ((ic->ic_caps & IEEE80211_C_PMGT) == 0)
1034 1.16.2.2 skrll error = EINVAL;
1035 1.16.2.2 skrll else if ((ic->ic_flags & IEEE80211_F_PMGTON) == 0) {
1036 1.16.2.2 skrll ic->ic_flags |= IEEE80211_F_PMGTON;
1037 1.16.2.2 skrll error = ENETRESET;
1038 1.16.2.2 skrll }
1039 1.16.2.2 skrll break;
1040 1.16.2.2 skrll default:
1041 1.16.2.2 skrll error = EINVAL;
1042 1.16.2.2 skrll break;
1043 1.16.2.2 skrll }
1044 1.16.2.2 skrll break;
1045 1.16.2.2 skrll case IEEE80211_IOC_POWERSAVESLEEP:
1046 1.16.2.2 skrll if (ireq->i_val < 0) {
1047 1.16.2.2 skrll error = EINVAL;
1048 1.16.2.2 skrll break;
1049 1.16.2.2 skrll }
1050 1.16.2.2 skrll ic->ic_lintval = ireq->i_val;
1051 1.16.2.2 skrll error = ENETRESET;
1052 1.16.2.2 skrll break;
1053 1.16.2.2 skrll case IEEE80211_IOC_RTSTHRESHOLD:
1054 1.16.2.2 skrll if (!(IEEE80211_RTS_MIN < ireq->i_val &&
1055 1.16.2.2 skrll ireq->i_val <= IEEE80211_RTS_MAX + 1)) {
1056 1.16.2.2 skrll error = EINVAL;
1057 1.16.2.2 skrll break;
1058 1.16.2.2 skrll }
1059 1.16.2.2 skrll ic->ic_rtsthreshold = ireq->i_val;
1060 1.16.2.2 skrll error = ENETRESET;
1061 1.16.2.2 skrll break;
1062 1.16.2.2 skrll case IEEE80211_IOC_PROTMODE:
1063 1.16.2.2 skrll if (ireq->i_val > IEEE80211_PROT_RTSCTS) {
1064 1.16.2.2 skrll error = EINVAL;
1065 1.16.2.2 skrll break;
1066 1.16.2.2 skrll }
1067 1.16.2.2 skrll ic->ic_protmode = ireq->i_val;
1068 1.16.2.2 skrll /* NB: if not operating in 11g this can wait */
1069 1.16.2.2 skrll if (ic->ic_curmode == IEEE80211_MODE_11G)
1070 1.16.2.2 skrll error = ENETRESET;
1071 1.16.2.2 skrll break;
1072 1.16.2.2 skrll case IEEE80211_IOC_TXPOWER:
1073 1.16.2.2 skrll if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0) {
1074 1.16.2.2 skrll error = EINVAL;
1075 1.16.2.2 skrll break;
1076 1.16.2.2 skrll }
1077 1.16.2.2 skrll if (!(IEEE80211_TXPOWER_MIN < ireq->i_val &&
1078 1.16.2.2 skrll ireq->i_val < IEEE80211_TXPOWER_MAX)) {
1079 1.16.2.2 skrll error = EINVAL;
1080 1.16.2.2 skrll break;
1081 1.16.2.2 skrll }
1082 1.16.2.2 skrll ic->ic_txpower = ireq->i_val;
1083 1.16.2.2 skrll error = ENETRESET;
1084 1.16.2.2 skrll break;
1085 1.16.2.2 skrll default:
1086 1.16.2.2 skrll error = EINVAL;
1087 1.16.2.2 skrll break;
1088 1.16.2.2 skrll }
1089 1.16.2.2 skrll break;
1090 1.16.2.2 skrll case SIOCGIFGENERIC:
1091 1.16.2.2 skrll error = ieee80211_cfgget(ifp, cmd, data);
1092 1.16.2.2 skrll break;
1093 1.16.2.2 skrll case SIOCSIFGENERIC:
1094 1.16.2.2 skrll error = suser(curproc->p_ucred, &curproc->p_acflag);
1095 1.16.2.2 skrll if (error)
1096 1.16.2.2 skrll break;
1097 1.16.2.2 skrll error = ieee80211_cfgset(ifp, cmd, data);
1098 1.16.2.2 skrll break;
1099 1.16.2.2 skrll default:
1100 1.16.2.2 skrll error = ether_ioctl(ifp, cmd, data);
1101 1.16.2.2 skrll break;
1102 1.16.2.2 skrll }
1103 1.16.2.2 skrll return error;
1104 1.16.2.2 skrll }
1105 1.16.2.2 skrll #endif /* __FreeBSD__ */
1106 1.16.2.2 skrll
1107 1.16.2.2 skrll #ifdef __NetBSD__
1108 1.16.2.2 skrll int
1109 1.16.2.2 skrll ieee80211_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
1110 1.16.2.2 skrll {
1111 1.16.2.2 skrll struct ieee80211com *ic = (void *)ifp;
1112 1.16.2.2 skrll struct ifreq *ifr = (struct ifreq *)data;
1113 1.16.2.5 skrll int i, error = 0, s;
1114 1.16.2.2 skrll struct ieee80211_nwid nwid;
1115 1.16.2.2 skrll struct ieee80211_nwkey *nwkey;
1116 1.16.2.2 skrll struct ieee80211_power *power;
1117 1.16.2.2 skrll struct ieee80211_bssid *bssid;
1118 1.16.2.2 skrll struct ieee80211chanreq *chanreq;
1119 1.16.2.2 skrll struct ieee80211_channel *chan;
1120 1.16.2.2 skrll struct ieee80211_wepkey keys[IEEE80211_WEP_NKID];
1121 1.16.2.2 skrll static const u_int8_t empty_macaddr[IEEE80211_ADDR_LEN] = {
1122 1.16.2.2 skrll 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1123 1.16.2.2 skrll };
1124 1.16.2.2 skrll
1125 1.16.2.2 skrll switch (cmd) {
1126 1.16.2.2 skrll case SIOCSIFMEDIA:
1127 1.16.2.2 skrll case SIOCGIFMEDIA:
1128 1.16.2.2 skrll error = ifmedia_ioctl(ifp, ifr, &ic->ic_media, cmd);
1129 1.16.2.2 skrll break;
1130 1.16.2.2 skrll case SIOCS80211NWID:
1131 1.16.2.2 skrll if ((error = copyin(ifr->ifr_data, &nwid, sizeof(nwid))) != 0)
1132 1.16.2.2 skrll break;
1133 1.16.2.2 skrll if (nwid.i_len > IEEE80211_NWID_LEN) {
1134 1.16.2.2 skrll error = EINVAL;
1135 1.16.2.2 skrll break;
1136 1.16.2.2 skrll }
1137 1.16.2.2 skrll memset(ic->ic_des_essid, 0, IEEE80211_NWID_LEN);
1138 1.16.2.2 skrll ic->ic_des_esslen = nwid.i_len;
1139 1.16.2.2 skrll memcpy(ic->ic_des_essid, nwid.i_nwid, nwid.i_len);
1140 1.16.2.2 skrll error = ENETRESET;
1141 1.16.2.2 skrll break;
1142 1.16.2.2 skrll case SIOCG80211NWID:
1143 1.16.2.2 skrll memset(&nwid, 0, sizeof(nwid));
1144 1.16.2.2 skrll switch (ic->ic_state) {
1145 1.16.2.2 skrll case IEEE80211_S_INIT:
1146 1.16.2.2 skrll case IEEE80211_S_SCAN:
1147 1.16.2.2 skrll nwid.i_len = ic->ic_des_esslen;
1148 1.16.2.2 skrll memcpy(nwid.i_nwid, ic->ic_des_essid, nwid.i_len);
1149 1.16.2.2 skrll break;
1150 1.16.2.2 skrll default:
1151 1.16.2.2 skrll nwid.i_len = ic->ic_bss->ni_esslen;
1152 1.16.2.2 skrll memcpy(nwid.i_nwid, ic->ic_bss->ni_essid, nwid.i_len);
1153 1.16.2.2 skrll break;
1154 1.16.2.2 skrll }
1155 1.16.2.2 skrll error = copyout(&nwid, ifr->ifr_data, sizeof(nwid));
1156 1.16.2.2 skrll break;
1157 1.16.2.2 skrll case SIOCS80211NWKEY:
1158 1.16.2.2 skrll nwkey = (struct ieee80211_nwkey *)data;
1159 1.16.2.2 skrll if ((ic->ic_caps & IEEE80211_C_WEP) == 0 &&
1160 1.16.2.2 skrll nwkey->i_wepon != IEEE80211_NWKEY_OPEN) {
1161 1.16.2.2 skrll error = EINVAL;
1162 1.16.2.2 skrll break;
1163 1.16.2.2 skrll }
1164 1.16.2.2 skrll /* check and copy keys */
1165 1.16.2.2 skrll memset(keys, 0, sizeof(keys));
1166 1.16.2.2 skrll for (i = 0; i < IEEE80211_WEP_NKID; i++) {
1167 1.16.2.2 skrll keys[i].wk_len = nwkey->i_key[i].i_keylen;
1168 1.16.2.2 skrll if ((keys[i].wk_len > 0 &&
1169 1.16.2.2 skrll keys[i].wk_len < IEEE80211_WEP_KEYLEN) ||
1170 1.16.2.2 skrll keys[i].wk_len > sizeof(keys[i].wk_key)) {
1171 1.16.2.2 skrll error = EINVAL;
1172 1.16.2.2 skrll break;
1173 1.16.2.2 skrll }
1174 1.16.2.2 skrll if (keys[i].wk_len <= 0)
1175 1.16.2.2 skrll continue;
1176 1.16.2.2 skrll if ((error = copyin(nwkey->i_key[i].i_keydat,
1177 1.16.2.2 skrll keys[i].wk_key, keys[i].wk_len)) != 0)
1178 1.16.2.2 skrll break;
1179 1.16.2.2 skrll }
1180 1.16.2.2 skrll if (error)
1181 1.16.2.2 skrll break;
1182 1.16.2.2 skrll i = nwkey->i_defkid - 1;
1183 1.16.2.2 skrll if (i < 0 || i >= IEEE80211_WEP_NKID ||
1184 1.16.2.2 skrll keys[i].wk_len == 0 ||
1185 1.16.2.2 skrll (keys[i].wk_len == -1 && ic->ic_nw_keys[i].wk_len == 0)) {
1186 1.16.2.2 skrll if (nwkey->i_wepon != IEEE80211_NWKEY_OPEN) {
1187 1.16.2.2 skrll error = EINVAL;
1188 1.16.2.2 skrll break;
1189 1.16.2.2 skrll }
1190 1.16.2.2 skrll } else
1191 1.16.2.2 skrll ic->ic_wep_txkey = i;
1192 1.16.2.2 skrll /* save the key */
1193 1.16.2.2 skrll if (nwkey->i_wepon == IEEE80211_NWKEY_OPEN)
1194 1.16.2.2 skrll ic->ic_flags &= ~IEEE80211_F_PRIVACY;
1195 1.16.2.2 skrll else
1196 1.16.2.2 skrll ic->ic_flags |= IEEE80211_F_PRIVACY;
1197 1.16.2.2 skrll for (i = 0; i < IEEE80211_WEP_NKID; i++) {
1198 1.16.2.2 skrll if (keys[i].wk_len < 0)
1199 1.16.2.2 skrll continue;
1200 1.16.2.2 skrll ic->ic_nw_keys[i].wk_len = keys[i].wk_len;
1201 1.16.2.2 skrll memcpy(ic->ic_nw_keys[i].wk_key, keys[i].wk_key,
1202 1.16.2.2 skrll sizeof(keys[i].wk_key));
1203 1.16.2.2 skrll }
1204 1.16.2.2 skrll error = ENETRESET;
1205 1.16.2.2 skrll break;
1206 1.16.2.2 skrll case SIOCG80211NWKEY:
1207 1.16.2.2 skrll nwkey = (struct ieee80211_nwkey *)data;
1208 1.16.2.2 skrll if (ic->ic_flags & IEEE80211_F_PRIVACY)
1209 1.16.2.2 skrll nwkey->i_wepon = IEEE80211_NWKEY_WEP;
1210 1.16.2.2 skrll else
1211 1.16.2.2 skrll nwkey->i_wepon = IEEE80211_NWKEY_OPEN;
1212 1.16.2.2 skrll nwkey->i_defkid = ic->ic_wep_txkey + 1;
1213 1.16.2.2 skrll for (i = 0; i < IEEE80211_WEP_NKID; i++) {
1214 1.16.2.2 skrll if (nwkey->i_key[i].i_keydat == NULL)
1215 1.16.2.2 skrll continue;
1216 1.16.2.2 skrll /* do not show any keys to non-root user */
1217 1.16.2.2 skrll if ((error = suser(curproc->p_ucred,
1218 1.16.2.2 skrll &curproc->p_acflag)) != 0)
1219 1.16.2.2 skrll break;
1220 1.16.2.2 skrll nwkey->i_key[i].i_keylen = ic->ic_nw_keys[i].wk_len;
1221 1.16.2.2 skrll if ((error = copyout(ic->ic_nw_keys[i].wk_key,
1222 1.16.2.2 skrll nwkey->i_key[i].i_keydat,
1223 1.16.2.2 skrll ic->ic_nw_keys[i].wk_len)) != 0)
1224 1.16.2.2 skrll break;
1225 1.16.2.2 skrll }
1226 1.16.2.2 skrll break;
1227 1.16.2.2 skrll case SIOCS80211POWER:
1228 1.16.2.2 skrll power = (struct ieee80211_power *)data;
1229 1.16.2.2 skrll ic->ic_lintval = power->i_maxsleep;
1230 1.16.2.2 skrll if (power->i_enabled != 0) {
1231 1.16.2.2 skrll if ((ic->ic_caps & IEEE80211_C_PMGT) == 0)
1232 1.16.2.2 skrll error = EINVAL;
1233 1.16.2.2 skrll else if ((ic->ic_flags & IEEE80211_F_PMGTON) == 0) {
1234 1.16.2.2 skrll ic->ic_flags |= IEEE80211_F_PMGTON;
1235 1.16.2.2 skrll error = ENETRESET;
1236 1.16.2.2 skrll }
1237 1.16.2.2 skrll } else {
1238 1.16.2.2 skrll if (ic->ic_flags & IEEE80211_F_PMGTON) {
1239 1.16.2.2 skrll ic->ic_flags &= ~IEEE80211_F_PMGTON;
1240 1.16.2.2 skrll error = ENETRESET;
1241 1.16.2.2 skrll }
1242 1.16.2.2 skrll }
1243 1.16.2.2 skrll break;
1244 1.16.2.2 skrll case SIOCG80211POWER:
1245 1.16.2.2 skrll power = (struct ieee80211_power *)data;
1246 1.16.2.2 skrll power->i_enabled = (ic->ic_flags & IEEE80211_F_PMGTON) ? 1 : 0;
1247 1.16.2.2 skrll power->i_maxsleep = ic->ic_lintval;
1248 1.16.2.2 skrll break;
1249 1.16.2.2 skrll case SIOCS80211BSSID:
1250 1.16.2.2 skrll bssid = (struct ieee80211_bssid *)data;
1251 1.16.2.2 skrll if (IEEE80211_ADDR_EQ(bssid->i_bssid, empty_macaddr))
1252 1.16.2.2 skrll ic->ic_flags &= ~IEEE80211_F_DESBSSID;
1253 1.16.2.2 skrll else {
1254 1.16.2.2 skrll ic->ic_flags |= IEEE80211_F_DESBSSID;
1255 1.16.2.2 skrll IEEE80211_ADDR_COPY(ic->ic_des_bssid, bssid->i_bssid);
1256 1.16.2.2 skrll }
1257 1.16.2.2 skrll if (ic->ic_opmode == IEEE80211_M_HOSTAP)
1258 1.16.2.2 skrll break;
1259 1.16.2.2 skrll switch (ic->ic_state) {
1260 1.16.2.2 skrll case IEEE80211_S_INIT:
1261 1.16.2.2 skrll case IEEE80211_S_SCAN:
1262 1.16.2.2 skrll error = ENETRESET;
1263 1.16.2.2 skrll break;
1264 1.16.2.2 skrll default:
1265 1.16.2.2 skrll if ((ic->ic_flags & IEEE80211_F_DESBSSID) &&
1266 1.16.2.2 skrll !IEEE80211_ADDR_EQ(ic->ic_des_bssid,
1267 1.16.2.2 skrll ic->ic_bss->ni_bssid))
1268 1.16.2.2 skrll error = ENETRESET;
1269 1.16.2.2 skrll break;
1270 1.16.2.2 skrll }
1271 1.16.2.2 skrll break;
1272 1.16.2.2 skrll case SIOCG80211BSSID:
1273 1.16.2.2 skrll bssid = (struct ieee80211_bssid *)data;
1274 1.16.2.2 skrll switch (ic->ic_state) {
1275 1.16.2.2 skrll case IEEE80211_S_INIT:
1276 1.16.2.2 skrll case IEEE80211_S_SCAN:
1277 1.16.2.2 skrll if (ic->ic_opmode == IEEE80211_M_HOSTAP)
1278 1.16.2.2 skrll IEEE80211_ADDR_COPY(bssid->i_bssid,
1279 1.16.2.2 skrll ic->ic_myaddr);
1280 1.16.2.2 skrll else if (ic->ic_flags & IEEE80211_F_DESBSSID)
1281 1.16.2.2 skrll IEEE80211_ADDR_COPY(bssid->i_bssid,
1282 1.16.2.2 skrll ic->ic_des_bssid);
1283 1.16.2.2 skrll else
1284 1.16.2.2 skrll memset(bssid->i_bssid, 0, IEEE80211_ADDR_LEN);
1285 1.16.2.2 skrll break;
1286 1.16.2.2 skrll default:
1287 1.16.2.2 skrll IEEE80211_ADDR_COPY(bssid->i_bssid,
1288 1.16.2.2 skrll ic->ic_bss->ni_bssid);
1289 1.16.2.2 skrll break;
1290 1.16.2.2 skrll }
1291 1.16.2.2 skrll break;
1292 1.16.2.2 skrll case SIOCS80211CHANNEL:
1293 1.16.2.2 skrll chanreq = (struct ieee80211chanreq *)data;
1294 1.16.2.2 skrll if (chanreq->i_channel == IEEE80211_CHAN_ANY)
1295 1.16.2.2 skrll ic->ic_des_chan = IEEE80211_CHAN_ANYC;
1296 1.16.2.2 skrll else if (chanreq->i_channel > IEEE80211_CHAN_MAX ||
1297 1.16.2.2 skrll isclr(ic->ic_chan_active, chanreq->i_channel)) {
1298 1.16.2.2 skrll error = EINVAL;
1299 1.16.2.2 skrll break;
1300 1.16.2.2 skrll } else
1301 1.16.2.2 skrll ic->ic_ibss_chan = ic->ic_des_chan =
1302 1.16.2.2 skrll &ic->ic_channels[chanreq->i_channel];
1303 1.16.2.2 skrll switch (ic->ic_state) {
1304 1.16.2.2 skrll case IEEE80211_S_INIT:
1305 1.16.2.2 skrll case IEEE80211_S_SCAN:
1306 1.16.2.2 skrll error = ENETRESET;
1307 1.16.2.2 skrll break;
1308 1.16.2.2 skrll default:
1309 1.16.2.2 skrll if (ic->ic_opmode == IEEE80211_M_STA) {
1310 1.16.2.2 skrll if (ic->ic_des_chan != IEEE80211_CHAN_ANYC &&
1311 1.16.2.2 skrll ic->ic_bss->ni_chan != ic->ic_des_chan)
1312 1.16.2.2 skrll error = ENETRESET;
1313 1.16.2.2 skrll } else {
1314 1.16.2.2 skrll if (ic->ic_bss->ni_chan != ic->ic_ibss_chan)
1315 1.16.2.2 skrll error = ENETRESET;
1316 1.16.2.2 skrll }
1317 1.16.2.2 skrll break;
1318 1.16.2.2 skrll }
1319 1.16.2.2 skrll break;
1320 1.16.2.2 skrll case SIOCG80211CHANNEL:
1321 1.16.2.2 skrll chanreq = (struct ieee80211chanreq *)data;
1322 1.16.2.2 skrll switch (ic->ic_state) {
1323 1.16.2.2 skrll case IEEE80211_S_INIT:
1324 1.16.2.2 skrll case IEEE80211_S_SCAN:
1325 1.16.2.2 skrll if (ic->ic_opmode == IEEE80211_M_STA)
1326 1.16.2.2 skrll chan = ic->ic_des_chan;
1327 1.16.2.2 skrll else
1328 1.16.2.2 skrll chan = ic->ic_ibss_chan;
1329 1.16.2.2 skrll break;
1330 1.16.2.2 skrll default:
1331 1.16.2.2 skrll chan = ic->ic_bss->ni_chan;
1332 1.16.2.2 skrll break;
1333 1.16.2.2 skrll }
1334 1.16.2.2 skrll chanreq->i_channel = ieee80211_chan2ieee(ic, chan);
1335 1.16.2.2 skrll break;
1336 1.16.2.2 skrll case SIOCGIFGENERIC:
1337 1.16.2.2 skrll error = ieee80211_cfgget(ifp, cmd, data);
1338 1.16.2.2 skrll break;
1339 1.16.2.2 skrll case SIOCSIFGENERIC:
1340 1.16.2.2 skrll error = suser(curproc->p_ucred, &curproc->p_acflag);
1341 1.16.2.2 skrll if (error)
1342 1.16.2.2 skrll break;
1343 1.16.2.2 skrll error = ieee80211_cfgset(ifp, cmd, data);
1344 1.16.2.2 skrll break;
1345 1.16.2.5 skrll case SIOCG80211ZSTATS:
1346 1.16.2.2 skrll case SIOCG80211STATS:
1347 1.16.2.2 skrll ifr = (struct ifreq *)data;
1348 1.16.2.5 skrll s = splnet();
1349 1.16.2.2 skrll copyout(&ic->ic_stats, ifr->ifr_data, sizeof (ic->ic_stats));
1350 1.16.2.5 skrll if (cmd == SIOCG80211ZSTATS)
1351 1.16.2.5 skrll (void)memset(&ic->ic_stats, 0, sizeof(ic->ic_stats));
1352 1.16.2.5 skrll splx(s);
1353 1.16.2.2 skrll break;
1354 1.16.2.2 skrll case SIOCSIFMTU:
1355 1.16.2.2 skrll ifr = (struct ifreq *)data;
1356 1.16.2.2 skrll if (!(IEEE80211_MTU_MIN <= ifr->ifr_mtu &&
1357 1.16.2.2 skrll ifr->ifr_mtu <= IEEE80211_MTU_MAX))
1358 1.16.2.2 skrll error = EINVAL;
1359 1.16.2.2 skrll else
1360 1.16.2.2 skrll ifp->if_mtu = ifr->ifr_mtu;
1361 1.16.2.2 skrll break;
1362 1.16.2.2 skrll default:
1363 1.16.2.2 skrll error = ether_ioctl(ifp, cmd, data);
1364 1.16.2.2 skrll break;
1365 1.16.2.2 skrll }
1366 1.16.2.2 skrll return error;
1367 1.16.2.2 skrll }
1368 1.16.2.2 skrll #endif /* __NetBSD__ */
1369