ieee80211.c revision 1.25 1 /* $NetBSD: ieee80211.c,v 1.25 2004/07/23 06:44:55 mycroft Exp $ */
2 /*-
3 * Copyright (c) 2001 Atsushi Onoe
4 * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * Alternatively, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") version 2 as published by the Free
20 * Software Foundation.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/cdefs.h>
35 #ifdef __FreeBSD__
36 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211.c,v 1.11 2004/04/02 20:19:20 sam Exp $");
37 #else
38 __KERNEL_RCSID(0, "$NetBSD: ieee80211.c,v 1.25 2004/07/23 06:44:55 mycroft Exp $");
39 #endif
40
41 /*
42 * IEEE 802.11 generic handler
43 */
44
45 #include "opt_inet.h"
46 #include "bpfilter.h"
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/mbuf.h>
51 #include <sys/malloc.h>
52 #include <sys/kernel.h>
53 #include <sys/socket.h>
54 #include <sys/sockio.h>
55 #include <sys/endian.h>
56 #include <sys/errno.h>
57 #ifdef __FreeBSD__
58 #include <sys/bus.h>
59 #endif
60 #include <sys/proc.h>
61 #include <sys/sysctl.h>
62
63 #ifdef __FreeBSD__
64 #include <machine/atomic.h>
65 #endif
66
67 #include <net/if.h>
68 #include <net/if_dl.h>
69 #include <net/if_media.h>
70 #include <net/if_arp.h>
71 #ifdef __FreeBSD__
72 #include <net/ethernet.h>
73 #else
74 #include <net/if_ether.h>
75 #endif
76 #include <net/if_llc.h>
77
78 #include <net80211/ieee80211_var.h>
79 #include <net80211/ieee80211_compat.h>
80 #include <net80211/ieee80211_sysctl.h>
81
82 #include <net/bpf.h>
83
84 #ifdef INET
85 #include <netinet/in.h>
86 #ifdef __FreeBSD__
87 #include <netinet/if_ether.h>
88 #else
89 #include <net/if_ether.h>
90 #endif
91 #endif
92
93 #ifdef IEEE80211_DEBUG
94 int ieee80211_debug = 0;
95 #ifdef __NetBSD__
96 static int ieee80211_debug_nodenum;
97 #endif /* __NetBSD__ */
98
99 #ifdef __FreeBSD__
100 SYSCTL_INT(_debug, OID_AUTO, ieee80211, CTLFLAG_RW, &ieee80211_debug,
101 0, "IEEE 802.11 media debugging printfs");
102 #endif
103 #endif
104
105 int ieee80211_inact_max = IEEE80211_INACT_MAX;
106 static int ieee80211_inact_max_nodenum;
107
108 struct ieee80211com_head ieee80211com_head =
109 LIST_HEAD_INITIALIZER(ieee80211com_head);
110
111 static void ieee80211_setbasicrates(struct ieee80211com *);
112
113 #ifdef __NetBSD__
114 static void sysctl_ieee80211_fill_node(struct ieee80211_node *,
115 struct ieee80211_node_sysctl *, int, struct ieee80211_channel *, int);
116 static struct ieee80211_node *ieee80211_node_walknext(
117 struct ieee80211_node_walk *);
118 static struct ieee80211_node *ieee80211_node_walkfirst(
119 struct ieee80211_node_walk *, u_short);
120 static int sysctl_ieee80211_verify(SYSCTLFN_ARGS);
121 static int sysctl_ieee80211_node(SYSCTLFN_ARGS);
122 #endif /* __NetBSD__ */
123
124 #define LOGICALLY_EQUAL(x, y) (!(x) == !(y))
125
126 static const char *ieee80211_phymode_name[] = {
127 "auto", /* IEEE80211_MODE_AUTO */
128 "11a", /* IEEE80211_MODE_11A */
129 "11b", /* IEEE80211_MODE_11B */
130 "11g", /* IEEE80211_MODE_11G */
131 "FH", /* IEEE80211_MODE_FH */
132 "turbo", /* IEEE80211_MODE_TURBO */
133 };
134
135 void
136 ieee80211_ifattach(struct ifnet *ifp)
137 {
138 struct ieee80211com *ic = (void *)ifp;
139 struct ieee80211_channel *c;
140 int i;
141
142 ether_ifattach(ifp, ic->ic_myaddr);
143 #if NBPFILTER > 0
144 bpfattach2(ifp, DLT_IEEE802_11,
145 sizeof(struct ieee80211_frame_addr4), &ic->ic_rawbpf);
146 #endif
147 ieee80211_crypto_attach(ifp);
148
149 /*
150 * Fill in 802.11 available channel set, mark
151 * all available channels as active, and pick
152 * a default channel if not already specified.
153 */
154 memset(ic->ic_chan_avail, 0, sizeof(ic->ic_chan_avail));
155 ic->ic_modecaps |= 1<<IEEE80211_MODE_AUTO;
156 for (i = 0; i <= IEEE80211_CHAN_MAX; i++) {
157 c = &ic->ic_channels[i];
158 if (c->ic_flags) {
159 /*
160 * Verify driver passed us valid data.
161 */
162 if (i != ieee80211_chan2ieee(ic, c)) {
163 if_printf(ifp, "bad channel ignored; "
164 "freq %u flags %x number %u\n",
165 c->ic_freq, c->ic_flags, i);
166 c->ic_flags = 0; /* NB: remove */
167 continue;
168 }
169 setbit(ic->ic_chan_avail, i);
170 /*
171 * Identify mode capabilities.
172 */
173 if (IEEE80211_IS_CHAN_A(c))
174 ic->ic_modecaps |= 1<<IEEE80211_MODE_11A;
175 if (IEEE80211_IS_CHAN_B(c))
176 ic->ic_modecaps |= 1<<IEEE80211_MODE_11B;
177 if (IEEE80211_IS_CHAN_PUREG(c))
178 ic->ic_modecaps |= 1<<IEEE80211_MODE_11G;
179 if (IEEE80211_IS_CHAN_FHSS(c))
180 ic->ic_modecaps |= 1<<IEEE80211_MODE_FH;
181 if (IEEE80211_IS_CHAN_T(c))
182 ic->ic_modecaps |= 1<<IEEE80211_MODE_TURBO;
183 }
184 }
185 /* validate ic->ic_curmode */
186 if ((ic->ic_modecaps & (1<<ic->ic_curmode)) == 0)
187 ic->ic_curmode = IEEE80211_MODE_AUTO;
188 ic->ic_des_chan = IEEE80211_CHAN_ANYC; /* any channel is ok */
189
190 ieee80211_setbasicrates(ic);
191 (void) ieee80211_setmode(ic, ic->ic_curmode);
192
193 if (ic->ic_lintval == 0)
194 ic->ic_lintval = 100; /* default sleep */
195 ic->ic_bmisstimeout = 7*ic->ic_lintval; /* default 7 beacons */
196
197 LIST_INSERT_HEAD(&ieee80211com_head, ic, ic_list);
198 ieee80211_node_attach(ifp);
199 ieee80211_proto_attach(ifp);
200 }
201
202 void
203 ieee80211_ifdetach(struct ifnet *ifp)
204 {
205 struct ieee80211com *ic = (void *)ifp;
206
207 ieee80211_proto_detach(ifp);
208 ieee80211_crypto_detach(ifp);
209 ieee80211_node_detach(ifp);
210 LIST_REMOVE(ic, ic_list);
211 #ifdef __FreeBSD__
212 ifmedia_removeall(&ic->ic_media);
213 #else
214 ifmedia_delete_instance(&ic->ic_media, IFM_INST_ANY);
215 #endif
216 #if NBPFILTER > 0
217 bpfdetach(ifp);
218 #endif
219 ether_ifdetach(ifp);
220 }
221
222 /*
223 * Convert MHz frequency to IEEE channel number.
224 */
225 u_int
226 ieee80211_mhz2ieee(u_int freq, u_int flags)
227 {
228 if (flags & IEEE80211_CHAN_2GHZ) { /* 2GHz band */
229 if (freq == 2484)
230 return 14;
231 if (freq < 2484)
232 return (freq - 2407) / 5;
233 else
234 return 15 + ((freq - 2512) / 20);
235 } else if (flags & IEEE80211_CHAN_5GHZ) { /* 5Ghz band */
236 return (freq - 5000) / 5;
237 } else { /* either, guess */
238 if (freq == 2484)
239 return 14;
240 if (freq < 2484)
241 return (freq - 2407) / 5;
242 if (freq < 5000)
243 return 15 + ((freq - 2512) / 20);
244 return (freq - 5000) / 5;
245 }
246 }
247
248 /*
249 * Convert channel to IEEE channel number.
250 */
251 u_int
252 ieee80211_chan2ieee(struct ieee80211com *ic, struct ieee80211_channel *c)
253 {
254 if (ic->ic_channels <= c && c <= &ic->ic_channels[IEEE80211_CHAN_MAX])
255 return c - ic->ic_channels;
256 else if (c == IEEE80211_CHAN_ANYC)
257 return IEEE80211_CHAN_ANY;
258 else if (c != NULL) {
259 if_printf(&ic->ic_if, "invalid channel freq %u flags %x\n",
260 c->ic_freq, c->ic_flags);
261 return 0; /* XXX */
262 } else {
263 if_printf(&ic->ic_if, "invalid channel (NULL)\n");
264 return 0; /* XXX */
265 }
266 }
267
268 /*
269 * Convert IEEE channel number to MHz frequency.
270 */
271 u_int
272 ieee80211_ieee2mhz(u_int chan, u_int flags)
273 {
274 if (flags & IEEE80211_CHAN_2GHZ) { /* 2GHz band */
275 if (chan == 14)
276 return 2484;
277 if (chan < 14)
278 return 2407 + chan*5;
279 else
280 return 2512 + ((chan-15)*20);
281 } else if (flags & IEEE80211_CHAN_5GHZ) {/* 5Ghz band */
282 return 5000 + (chan*5);
283 } else { /* either, guess */
284 if (chan == 14)
285 return 2484;
286 if (chan < 14) /* 0-13 */
287 return 2407 + chan*5;
288 if (chan < 27) /* 15-26 */
289 return 2512 + ((chan-15)*20);
290 return 5000 + (chan*5);
291 }
292 }
293
294 /*
295 * Setup the media data structures according to the channel and
296 * rate tables. This must be called by the driver after
297 * ieee80211_attach and before most anything else.
298 */
299 void
300 ieee80211_media_init(struct ifnet *ifp,
301 ifm_change_cb_t media_change, ifm_stat_cb_t media_stat)
302 {
303 #define ADD(_ic, _s, _o) \
304 ifmedia_add(&(_ic)->ic_media, \
305 IFM_MAKEWORD(IFM_IEEE80211, (_s), (_o), 0), 0, NULL)
306 struct ieee80211com *ic = (void *)ifp;
307 struct ifmediareq imr;
308 int i, j, mode, rate, maxrate, mword, mopt, r;
309 struct ieee80211_rateset *rs;
310 struct ieee80211_rateset allrates;
311
312 /*
313 * Do late attach work that must wait for any subclass
314 * (i.e. driver) work such as overriding methods.
315 */
316 ieee80211_node_lateattach(ifp);
317
318 /*
319 * Fill in media characteristics.
320 */
321 ifmedia_init(&ic->ic_media, 0, media_change, media_stat);
322 maxrate = 0;
323 memset(&allrates, 0, sizeof(allrates));
324 for (mode = IEEE80211_MODE_AUTO; mode < IEEE80211_MODE_MAX; mode++) {
325 static const u_int mopts[] = {
326 IFM_AUTO,
327 IFM_IEEE80211_11A,
328 IFM_IEEE80211_11B,
329 IFM_IEEE80211_11G,
330 IFM_IEEE80211_FH,
331 IFM_IEEE80211_11A | IFM_IEEE80211_TURBO,
332 };
333 if ((ic->ic_modecaps & (1<<mode)) == 0)
334 continue;
335 mopt = mopts[mode];
336 ADD(ic, IFM_AUTO, mopt); /* e.g. 11a auto */
337 if (ic->ic_caps & IEEE80211_C_IBSS)
338 ADD(ic, IFM_AUTO, mopt | IFM_IEEE80211_ADHOC);
339 if (ic->ic_caps & IEEE80211_C_HOSTAP)
340 ADD(ic, IFM_AUTO, mopt | IFM_IEEE80211_HOSTAP);
341 if (ic->ic_caps & IEEE80211_C_AHDEMO)
342 ADD(ic, IFM_AUTO, mopt | IFM_IEEE80211_ADHOC | IFM_FLAG0);
343 if (ic->ic_caps & IEEE80211_C_MONITOR)
344 ADD(ic, IFM_AUTO, mopt | IFM_IEEE80211_MONITOR);
345 if (mode == IEEE80211_MODE_AUTO)
346 continue;
347 if_printf(ifp, "%s rates: ", ieee80211_phymode_name[mode]);
348 rs = &ic->ic_sup_rates[mode];
349 for (i = 0; i < rs->rs_nrates; i++) {
350 rate = rs->rs_rates[i];
351 mword = ieee80211_rate2media(ic, rate, mode);
352 if (mword == 0)
353 continue;
354 printf("%s%d%sMbps", (i != 0 ? " " : ""),
355 (rate & IEEE80211_RATE_VAL) / 2,
356 ((rate & 0x1) != 0 ? ".5" : ""));
357 ADD(ic, mword, mopt);
358 if (ic->ic_caps & IEEE80211_C_IBSS)
359 ADD(ic, mword, mopt | IFM_IEEE80211_ADHOC);
360 if (ic->ic_caps & IEEE80211_C_HOSTAP)
361 ADD(ic, mword, mopt | IFM_IEEE80211_HOSTAP);
362 if (ic->ic_caps & IEEE80211_C_AHDEMO)
363 ADD(ic, mword, mopt | IFM_IEEE80211_ADHOC | IFM_FLAG0);
364 if (ic->ic_caps & IEEE80211_C_MONITOR)
365 ADD(ic, mword, mopt | IFM_IEEE80211_MONITOR);
366 /*
367 * Add rate to the collection of all rates.
368 */
369 r = rate & IEEE80211_RATE_VAL;
370 for (j = 0; j < allrates.rs_nrates; j++)
371 if (allrates.rs_rates[j] == r)
372 break;
373 if (j == allrates.rs_nrates) {
374 /* unique, add to the set */
375 allrates.rs_rates[j] = r;
376 allrates.rs_nrates++;
377 }
378 rate = (rate & IEEE80211_RATE_VAL) / 2;
379 if (rate > maxrate)
380 maxrate = rate;
381 }
382 printf("\n");
383 }
384 for (i = 0; i < allrates.rs_nrates; i++) {
385 mword = ieee80211_rate2media(ic, allrates.rs_rates[i],
386 IEEE80211_MODE_AUTO);
387 if (mword == 0)
388 continue;
389 mword = IFM_SUBTYPE(mword); /* remove media options */
390 ADD(ic, mword, 0);
391 if (ic->ic_caps & IEEE80211_C_IBSS)
392 ADD(ic, mword, IFM_IEEE80211_ADHOC);
393 if (ic->ic_caps & IEEE80211_C_HOSTAP)
394 ADD(ic, mword, IFM_IEEE80211_HOSTAP);
395 if (ic->ic_caps & IEEE80211_C_AHDEMO)
396 ADD(ic, mword, IFM_IEEE80211_ADHOC | IFM_FLAG0);
397 if (ic->ic_caps & IEEE80211_C_MONITOR)
398 ADD(ic, mword, IFM_IEEE80211_MONITOR);
399 }
400 ieee80211_media_status(ifp, &imr);
401 ifmedia_set(&ic->ic_media, imr.ifm_active);
402
403 if (maxrate)
404 ifp->if_baudrate = IF_Mbps(maxrate);
405
406 if (ic->ic_max_aid == 0)
407 ic->ic_max_aid = IEEE80211_AID_MAX;
408
409 #undef ADD
410 }
411
412 static int
413 findrate(struct ieee80211com *ic, enum ieee80211_phymode mode, int rate)
414 {
415 #define IEEERATE(_ic,_m,_i) \
416 ((_ic)->ic_sup_rates[_m].rs_rates[_i] & IEEE80211_RATE_VAL)
417 int i, nrates = ic->ic_sup_rates[mode].rs_nrates;
418 for (i = 0; i < nrates; i++)
419 if (IEEERATE(ic, mode, i) == rate)
420 return i;
421 return -1;
422 #undef IEEERATE
423 }
424
425 /*
426 * Handle a media change request.
427 */
428 int
429 ieee80211_media_change(struct ifnet *ifp)
430 {
431 struct ieee80211com *ic = (void *)ifp;
432 struct ifmedia_entry *ime;
433 enum ieee80211_opmode newopmode;
434 enum ieee80211_phymode newphymode;
435 int i, j, newrate, error = 0;
436
437 ime = ic->ic_media.ifm_cur;
438 /*
439 * First, identify the phy mode.
440 */
441 switch (IFM_MODE(ime->ifm_media)) {
442 case IFM_IEEE80211_11A:
443 newphymode = IEEE80211_MODE_11A;
444 break;
445 case IFM_IEEE80211_11B:
446 newphymode = IEEE80211_MODE_11B;
447 break;
448 case IFM_IEEE80211_11G:
449 newphymode = IEEE80211_MODE_11G;
450 break;
451 case IFM_IEEE80211_FH:
452 newphymode = IEEE80211_MODE_FH;
453 break;
454 case IFM_AUTO:
455 newphymode = IEEE80211_MODE_AUTO;
456 break;
457 default:
458 return EINVAL;
459 }
460 /*
461 * Turbo mode is an ``option''. Eventually it
462 * needs to be applied to 11g too.
463 */
464 if (ime->ifm_media & IFM_IEEE80211_TURBO) {
465 if (newphymode != IEEE80211_MODE_11A)
466 return EINVAL;
467 newphymode = IEEE80211_MODE_TURBO;
468 }
469 /*
470 * Validate requested mode is available.
471 */
472 if ((ic->ic_modecaps & (1<<newphymode)) == 0)
473 return EINVAL;
474
475 /*
476 * Next, the fixed/variable rate.
477 */
478 i = -1;
479 if (IFM_SUBTYPE(ime->ifm_media) != IFM_AUTO) {
480 /*
481 * Convert media subtype to rate.
482 */
483 newrate = ieee80211_media2rate(ime->ifm_media);
484 if (newrate == 0)
485 return EINVAL;
486 /*
487 * Check the rate table for the specified/current phy.
488 */
489 if (newphymode == IEEE80211_MODE_AUTO) {
490 /*
491 * In autoselect mode search for the rate.
492 */
493 for (j = IEEE80211_MODE_11A;
494 j < IEEE80211_MODE_MAX; j++) {
495 if ((ic->ic_modecaps & (1<<j)) == 0)
496 continue;
497 i = findrate(ic, j, newrate);
498 if (i != -1) {
499 /* lock mode too */
500 newphymode = j;
501 break;
502 }
503 }
504 } else {
505 i = findrate(ic, newphymode, newrate);
506 }
507 if (i == -1) /* mode/rate mismatch */
508 return EINVAL;
509 }
510 /* NB: defer rate setting to later */
511
512 /*
513 * Deduce new operating mode but don't install it just yet.
514 */
515 if ((ime->ifm_media & (IFM_IEEE80211_ADHOC|IFM_FLAG0)) ==
516 (IFM_IEEE80211_ADHOC|IFM_FLAG0))
517 newopmode = IEEE80211_M_AHDEMO;
518 else if (ime->ifm_media & IFM_IEEE80211_HOSTAP)
519 newopmode = IEEE80211_M_HOSTAP;
520 else if (ime->ifm_media & IFM_IEEE80211_ADHOC)
521 newopmode = IEEE80211_M_IBSS;
522 else if (ime->ifm_media & IFM_IEEE80211_MONITOR)
523 newopmode = IEEE80211_M_MONITOR;
524 else
525 newopmode = IEEE80211_M_STA;
526
527 /*
528 * Autoselect doesn't make sense when operating as an AP.
529 * If no phy mode has been selected, pick one and lock it
530 * down so rate tables can be used in forming beacon frames
531 * and the like.
532 */
533 if (newopmode == IEEE80211_M_HOSTAP &&
534 newphymode == IEEE80211_MODE_AUTO) {
535 for (j = IEEE80211_MODE_11A; j < IEEE80211_MODE_MAX; j++)
536 if (ic->ic_modecaps & (1<<j)) {
537 newphymode = j;
538 break;
539 }
540 }
541
542 /*
543 * Handle phy mode change.
544 */
545 if (ic->ic_curmode != newphymode) { /* change phy mode */
546 error = ieee80211_setmode(ic, newphymode);
547 if (error != 0)
548 return error;
549 error = ENETRESET;
550 }
551
552 /*
553 * Committed to changes, install the rate setting.
554 */
555 if (ic->ic_fixed_rate != i) {
556 ic->ic_fixed_rate = i; /* set fixed tx rate */
557 error = ENETRESET;
558 }
559
560 /*
561 * Handle operating mode change.
562 */
563 if (ic->ic_opmode != newopmode) {
564 ic->ic_opmode = newopmode;
565 switch (newopmode) {
566 case IEEE80211_M_AHDEMO:
567 case IEEE80211_M_HOSTAP:
568 case IEEE80211_M_STA:
569 case IEEE80211_M_MONITOR:
570 ic->ic_flags &= ~IEEE80211_F_IBSSON;
571 break;
572 case IEEE80211_M_IBSS:
573 ic->ic_flags |= IEEE80211_F_IBSSON;
574 break;
575 }
576 error = ENETRESET;
577 }
578 #ifdef notdef
579 if (error == 0)
580 ifp->if_baudrate = ifmedia_baudrate(ime->ifm_media);
581 #endif
582 return error;
583 }
584
585 void
586 ieee80211_media_status(struct ifnet *ifp, struct ifmediareq *imr)
587 {
588 struct ieee80211com *ic = (void *)ifp;
589 struct ieee80211_node *ni = NULL;
590
591 imr->ifm_status = IFM_AVALID;
592 imr->ifm_active = IFM_IEEE80211;
593 if (ic->ic_state == IEEE80211_S_RUN)
594 imr->ifm_status |= IFM_ACTIVE;
595 imr->ifm_active |= IFM_AUTO;
596 switch (ic->ic_opmode) {
597 case IEEE80211_M_STA:
598 ni = ic->ic_bss;
599 /* calculate rate subtype */
600 imr->ifm_active |= ieee80211_rate2media(ic,
601 ni->ni_rates.rs_rates[ni->ni_txrate], ic->ic_curmode);
602 break;
603 case IEEE80211_M_IBSS:
604 imr->ifm_active |= IFM_IEEE80211_ADHOC;
605 break;
606 case IEEE80211_M_AHDEMO:
607 /* should not come here */
608 break;
609 case IEEE80211_M_HOSTAP:
610 imr->ifm_active |= IFM_IEEE80211_HOSTAP;
611 break;
612 case IEEE80211_M_MONITOR:
613 imr->ifm_active |= IFM_IEEE80211_MONITOR;
614 break;
615 }
616 switch (ic->ic_curmode) {
617 case IEEE80211_MODE_11A:
618 imr->ifm_active |= IFM_IEEE80211_11A;
619 break;
620 case IEEE80211_MODE_11B:
621 imr->ifm_active |= IFM_IEEE80211_11B;
622 break;
623 case IEEE80211_MODE_11G:
624 imr->ifm_active |= IFM_IEEE80211_11G;
625 break;
626 case IEEE80211_MODE_FH:
627 imr->ifm_active |= IFM_IEEE80211_FH;
628 break;
629 case IEEE80211_MODE_TURBO:
630 imr->ifm_active |= IFM_IEEE80211_11A
631 | IFM_IEEE80211_TURBO;
632 break;
633 }
634 }
635
636 void
637 ieee80211_watchdog(struct ifnet *ifp)
638 {
639 struct ieee80211com *ic = (void *)ifp;
640
641 if (ic->ic_mgt_timer && --ic->ic_mgt_timer == 0)
642 ieee80211_new_state(ic, IEEE80211_S_SCAN, -1);
643 if (ic->ic_inact_timer && --ic->ic_inact_timer == 0)
644 ieee80211_timeout_nodes(ic);
645
646 if (ic->ic_mgt_timer != 0 || ic->ic_inact_timer != 0)
647 ifp->if_timer = 1;
648 }
649
650 /*
651 * Mark the basic rates for the 11g rate table based on the
652 * operating mode. For real 11g we mark all the 11b rates
653 * and 6, 12, and 24 OFDM. For 11b compatibility we mark only
654 * 11b rates. There's also a pseudo 11a-mode used to mark only
655 * the basic OFDM rates.
656 */
657 static void
658 ieee80211_setbasicrates(struct ieee80211com *ic)
659 {
660 static const struct ieee80211_rateset basic[] = {
661 { 0 }, /* IEEE80211_MODE_AUTO */
662 { 3, { 12, 24, 48 } }, /* IEEE80211_MODE_11A */
663 { 2, { 2, 4 } }, /* IEEE80211_MODE_11B */
664 { 7, { 2, 4, 11, 22, 12, 24, 48 } },/* IEEE80211_MODE_11G */
665 { 2, { 2, 4 } }, /* IEEE80211_MODE_FH */
666 { 0 }, /* IEEE80211_MODE_TURBO */
667 };
668 enum ieee80211_phymode mode;
669 struct ieee80211_rateset *rs;
670 int i, j;
671
672 for (mode = 0; mode < IEEE80211_MODE_MAX; mode++) {
673 rs = &ic->ic_sup_rates[mode];
674 for (i = 0; i < rs->rs_nrates; i++) {
675 rs->rs_rates[i] &= IEEE80211_RATE_VAL;
676 for (j = 0; j < basic[mode].rs_nrates; j++)
677 if (basic[mode].rs_rates[j] == rs->rs_rates[i]) {
678 rs->rs_rates[i] |= IEEE80211_RATE_BASIC;
679 break;
680 }
681 }
682 }
683 }
684
685 /*
686 * Set the current phy mode and recalculate the active channel
687 * set based on the available channels for this mode. Also
688 * select a new default/current channel if the current one is
689 * inappropriate for this mode.
690 */
691 int
692 ieee80211_setmode(struct ieee80211com *ic, enum ieee80211_phymode mode)
693 {
694 #define N(a) (sizeof(a) / sizeof(a[0]))
695 static const u_int chanflags[] = {
696 0, /* IEEE80211_MODE_AUTO */
697 IEEE80211_CHAN_A, /* IEEE80211_MODE_11A */
698 IEEE80211_CHAN_B, /* IEEE80211_MODE_11B */
699 IEEE80211_CHAN_PUREG, /* IEEE80211_MODE_11G */
700 IEEE80211_CHAN_FHSS, /* IEEE80211_MODE_FH */
701 IEEE80211_CHAN_T, /* IEEE80211_MODE_TURBO */
702 };
703 struct ieee80211_channel *c;
704 u_int modeflags;
705 int i;
706
707 /* validate new mode */
708 if ((ic->ic_modecaps & (1<<mode)) == 0) {
709 IEEE80211_DPRINTF(ic, IEEE80211_MSG_ANY,
710 ("%s: mode %u not supported (caps 0x%x)\n",
711 __func__, mode, ic->ic_modecaps));
712 return EINVAL;
713 }
714
715 /*
716 * Verify at least one channel is present in the available
717 * channel list before committing to the new mode.
718 */
719 IASSERT(mode < N(chanflags), ("Unexpected mode %u", mode));
720 modeflags = chanflags[mode];
721 for (i = 0; i <= IEEE80211_CHAN_MAX; i++) {
722 c = &ic->ic_channels[i];
723 if (mode == IEEE80211_MODE_AUTO) {
724 /* ignore turbo channels for autoselect */
725 if ((c->ic_flags &~ IEEE80211_CHAN_TURBO) != 0)
726 break;
727 } else {
728 if ((c->ic_flags & modeflags) == modeflags)
729 break;
730 }
731 }
732 if (i > IEEE80211_CHAN_MAX) {
733 IEEE80211_DPRINTF(ic, IEEE80211_MSG_ANY,
734 ("%s: no channels found for mode %u\n", __func__, mode));
735 return EINVAL;
736 }
737
738 /*
739 * Calculate the active channel set.
740 */
741 memset(ic->ic_chan_active, 0, sizeof(ic->ic_chan_active));
742 for (i = 0; i <= IEEE80211_CHAN_MAX; i++) {
743 c = &ic->ic_channels[i];
744 if (mode == IEEE80211_MODE_AUTO) {
745 /* take anything but pure turbo channels */
746 if ((c->ic_flags &~ IEEE80211_CHAN_TURBO) != 0)
747 setbit(ic->ic_chan_active, i);
748 } else {
749 if ((c->ic_flags & modeflags) == modeflags)
750 setbit(ic->ic_chan_active, i);
751 }
752 }
753 /*
754 * If no current/default channel is setup or the current
755 * channel is wrong for the mode then pick the first
756 * available channel from the active list. This is likely
757 * not the right one.
758 */
759 if (ic->ic_ibss_chan == NULL ||
760 isclr(ic->ic_chan_active, ieee80211_chan2ieee(ic, ic->ic_ibss_chan))) {
761 for (i = 0; i <= IEEE80211_CHAN_MAX; i++)
762 if (isset(ic->ic_chan_active, i)) {
763 ic->ic_ibss_chan = &ic->ic_channels[i];
764 break;
765 }
766 IASSERT(ic->ic_ibss_chan != NULL &&
767 isset(ic->ic_chan_active,
768 ieee80211_chan2ieee(ic, ic->ic_ibss_chan)),
769 ("Bad IBSS channel %u\n",
770 ieee80211_chan2ieee(ic, ic->ic_ibss_chan)));
771 }
772
773 /*
774 * Set/reset state flags that influence beacon contents, etc.
775 *
776 * XXX what if we have stations already associated???
777 * XXX probably not right for autoselect?
778 */
779 if (ic->ic_caps & IEEE80211_C_SHPREAMBLE)
780 ic->ic_flags |= IEEE80211_F_SHPREAMBLE;
781 if (mode == IEEE80211_MODE_11G) {
782 if (ic->ic_caps & IEEE80211_C_SHSLOT)
783 ic->ic_flags |= IEEE80211_F_SHSLOT;
784 } else
785 ic->ic_flags &= ~IEEE80211_F_SHSLOT;
786
787 ic->ic_curmode = mode;
788 return 0;
789 #undef N
790 }
791
792 /*
793 * Return the phy mode for with the specified channel so the
794 * caller can select a rate set. This is problematic and the
795 * work here assumes how things work elsewhere in this code.
796 *
797 * XXX never returns turbo modes -dcy
798 */
799 enum ieee80211_phymode
800 ieee80211_chan2mode(struct ieee80211com *ic, struct ieee80211_channel *chan)
801 {
802 /*
803 * NB: this assumes the channel would not be supplied to us
804 * unless it was already compatible with the current mode.
805 */
806 if (ic->ic_curmode != IEEE80211_MODE_AUTO ||
807 chan == IEEE80211_CHAN_ANYC)
808 return ic->ic_curmode;
809 /*
810 * In autoselect mode; deduce a mode based on the channel
811 * characteristics. We assume that turbo-only channels
812 * are not considered when the channel set is constructed.
813 */
814 if (IEEE80211_IS_CHAN_5GHZ(chan))
815 return IEEE80211_MODE_11A;
816 else if (IEEE80211_IS_CHAN_FHSS(chan))
817 return IEEE80211_MODE_FH;
818 else if (chan->ic_flags & (IEEE80211_CHAN_OFDM|IEEE80211_CHAN_DYN))
819 return IEEE80211_MODE_11G;
820 else
821 return IEEE80211_MODE_11B;
822 }
823
824 /*
825 * convert IEEE80211 rate value to ifmedia subtype.
826 * ieee80211 rate is in unit of 0.5Mbps.
827 */
828 int
829 ieee80211_rate2media(struct ieee80211com *ic, int rate, enum ieee80211_phymode mode)
830 {
831 #define N(a) (sizeof(a) / sizeof(a[0]))
832 static const struct {
833 u_int m; /* rate + mode */
834 u_int r; /* if_media rate */
835 } rates[] = {
836 { 2 | IFM_IEEE80211_FH, IFM_IEEE80211_FH1 },
837 { 4 | IFM_IEEE80211_FH, IFM_IEEE80211_FH2 },
838 { 2 | IFM_IEEE80211_11B, IFM_IEEE80211_DS1 },
839 { 4 | IFM_IEEE80211_11B, IFM_IEEE80211_DS2 },
840 { 11 | IFM_IEEE80211_11B, IFM_IEEE80211_DS5 },
841 { 22 | IFM_IEEE80211_11B, IFM_IEEE80211_DS11 },
842 { 44 | IFM_IEEE80211_11B, IFM_IEEE80211_DS22 },
843 { 12 | IFM_IEEE80211_11A, IFM_IEEE80211_OFDM6 },
844 { 18 | IFM_IEEE80211_11A, IFM_IEEE80211_OFDM9 },
845 { 24 | IFM_IEEE80211_11A, IFM_IEEE80211_OFDM12 },
846 { 36 | IFM_IEEE80211_11A, IFM_IEEE80211_OFDM18 },
847 { 48 | IFM_IEEE80211_11A, IFM_IEEE80211_OFDM24 },
848 { 72 | IFM_IEEE80211_11A, IFM_IEEE80211_OFDM36 },
849 { 96 | IFM_IEEE80211_11A, IFM_IEEE80211_OFDM48 },
850 { 108 | IFM_IEEE80211_11A, IFM_IEEE80211_OFDM54 },
851 { 2 | IFM_IEEE80211_11G, IFM_IEEE80211_DS1 },
852 { 4 | IFM_IEEE80211_11G, IFM_IEEE80211_DS2 },
853 { 11 | IFM_IEEE80211_11G, IFM_IEEE80211_DS5 },
854 { 22 | IFM_IEEE80211_11G, IFM_IEEE80211_DS11 },
855 { 12 | IFM_IEEE80211_11G, IFM_IEEE80211_OFDM6 },
856 { 18 | IFM_IEEE80211_11G, IFM_IEEE80211_OFDM9 },
857 { 24 | IFM_IEEE80211_11G, IFM_IEEE80211_OFDM12 },
858 { 36 | IFM_IEEE80211_11G, IFM_IEEE80211_OFDM18 },
859 { 48 | IFM_IEEE80211_11G, IFM_IEEE80211_OFDM24 },
860 { 72 | IFM_IEEE80211_11G, IFM_IEEE80211_OFDM36 },
861 { 96 | IFM_IEEE80211_11G, IFM_IEEE80211_OFDM48 },
862 { 108 | IFM_IEEE80211_11G, IFM_IEEE80211_OFDM54 },
863 /* NB: OFDM72 doesn't realy exist so we don't handle it */
864 };
865 u_int mask, i;
866
867 mask = rate & IEEE80211_RATE_VAL;
868 switch (mode) {
869 case IEEE80211_MODE_11A:
870 case IEEE80211_MODE_TURBO:
871 mask |= IFM_IEEE80211_11A;
872 break;
873 case IEEE80211_MODE_11B:
874 mask |= IFM_IEEE80211_11B;
875 break;
876 case IEEE80211_MODE_FH:
877 mask |= IFM_IEEE80211_FH;
878 break;
879 case IEEE80211_MODE_AUTO:
880 /* NB: ic may be NULL for some drivers */
881 if (ic && ic->ic_phytype == IEEE80211_T_FH) {
882 mask |= IFM_IEEE80211_FH;
883 break;
884 }
885 /* NB: hack, 11g matches both 11b+11a rates */
886 /* fall thru... */
887 case IEEE80211_MODE_11G:
888 mask |= IFM_IEEE80211_11G;
889 break;
890 }
891 for (i = 0; i < N(rates); i++)
892 if (rates[i].m == mask)
893 return rates[i].r;
894 return IFM_AUTO;
895 #undef N
896 }
897
898 int
899 ieee80211_media2rate(int mword)
900 {
901 #define N(a) (sizeof(a) / sizeof(a[0]))
902 int i;
903 static const struct {
904 int subtype;
905 int rate;
906 } ieeerates[] = {
907 { IFM_AUTO, -1 },
908 { IFM_MANUAL, 0 },
909 { IFM_NONE, 0 },
910 { IFM_IEEE80211_FH1, 2 },
911 { IFM_IEEE80211_FH2, 4 },
912 { IFM_IEEE80211_DS1, 2 },
913 { IFM_IEEE80211_DS2, 4 },
914 { IFM_IEEE80211_DS5, 11 },
915 { IFM_IEEE80211_DS11, 22 },
916 { IFM_IEEE80211_DS22, 44 },
917 { IFM_IEEE80211_OFDM6, 12 },
918 { IFM_IEEE80211_OFDM9, 18 },
919 { IFM_IEEE80211_OFDM12, 24 },
920 { IFM_IEEE80211_OFDM18, 36 },
921 { IFM_IEEE80211_OFDM24, 48 },
922 { IFM_IEEE80211_OFDM36, 72 },
923 { IFM_IEEE80211_OFDM48, 96 },
924 { IFM_IEEE80211_OFDM54, 108 },
925 { IFM_IEEE80211_OFDM72, 144 },
926 };
927 for (i = 0; i < N(ieeerates); i++) {
928 if (ieeerates[i].subtype == IFM_SUBTYPE(mword))
929 return ieeerates[i].rate;
930 }
931 return 0;
932 #undef N
933 }
934
935 #ifdef __NetBSD__
936 /* TBD factor with sysctl_ath_verify. */
937 static int
938 sysctl_ieee80211_verify(SYSCTLFN_ARGS)
939 {
940 int error, t;
941 struct sysctlnode node;
942
943 node = *rnode;
944 t = *(int*)rnode->sysctl_data;
945 node.sysctl_data = &t;
946 error = sysctl_lookup(SYSCTLFN_CALL(&node));
947 if (error || newp == NULL)
948 return (error);
949
950 if (node.sysctl_num == ieee80211_inact_max_nodenum) {
951 if (t < 1)
952 return (EINVAL);
953 t = roundup(t, IEEE80211_INACT_WAIT) / IEEE80211_INACT_WAIT;
954 #ifdef IEEE80211_DEBUG
955 } else if (node.sysctl_num == ieee80211_debug_nodenum) {
956 if (t < 0 || t > 2)
957 return (EINVAL);
958 #endif /* IEEE80211_DEBUG */
959 } else
960 return (EINVAL);
961
962 *(int*)rnode->sysctl_data = t;
963
964 return (0);
965 }
966
967 /*
968 * Pointers for testing:
969 *
970 * If there are no interfaces, or else no 802.11 interfaces,
971 * ieee80211_node_walkfirst must return NULL.
972 *
973 * If there is any single 802.11 interface, ieee80211_node_walkfirst
974 * must not return NULL.
975 */
976 static struct ieee80211_node *
977 ieee80211_node_walkfirst(struct ieee80211_node_walk *nw,
978 u_short if_index)
979 {
980 struct ieee80211com *ic;
981 (void)memset(nw, 0, sizeof(*nw));
982
983 nw->nw_ifindex = if_index;
984
985 LIST_FOREACH(ic, &ieee80211com_head, ic_list) {
986 if (if_index != 0 && ic->ic_if.if_index != if_index)
987 continue;
988 nw->nw_ic = ic;
989 nw->nw_ni = ic->ic_bss;
990 break;
991 }
992
993 KASSERT(LOGICALLY_EQUAL(nw->nw_ni == NULL, nw->nw_ic == NULL));
994
995 return nw->nw_ni;
996 }
997
998 static struct ieee80211_node *
999 ieee80211_node_walknext(struct ieee80211_node_walk *nw)
1000 {
1001 KASSERT(LOGICALLY_EQUAL(nw->nw_ni == NULL, nw->nw_ic == NULL));
1002
1003 if (nw->nw_ic == NULL && nw->nw_ni == NULL)
1004 return NULL;
1005
1006 if (nw->nw_ni == nw->nw_ic->ic_bss)
1007 nw->nw_ni = TAILQ_FIRST(&nw->nw_ic->ic_node);
1008 else
1009 nw->nw_ni = TAILQ_NEXT(nw->nw_ni, ni_list);
1010
1011 if (nw->nw_ni == NULL) {
1012 if (nw->nw_ifindex != 0)
1013 return NULL;
1014
1015 nw->nw_ic = LIST_NEXT(nw->nw_ic, ic_list);
1016 if (nw->nw_ic == NULL)
1017 return NULL;
1018
1019 nw->nw_ni = nw->nw_ic->ic_bss;
1020 }
1021
1022 KASSERT(LOGICALLY_EQUAL(nw->nw_ni == NULL, nw->nw_ic == NULL));
1023
1024 return nw->nw_ni;
1025 }
1026
1027 static void
1028 sysctl_ieee80211_fill_node(struct ieee80211_node *ni,
1029 struct ieee80211_node_sysctl *ns, int ifindex,
1030 struct ieee80211_channel *chan0, int is_bss)
1031 {
1032 ns->ns_ifindex = ifindex;
1033 ns->ns_capinfo = ni->ni_capinfo;
1034 ns->ns_flags = (is_bss) ? IEEE80211_NODE_SYSCTL_F_BSS : 0;
1035 (void)memcpy(ns->ns_macaddr, ni->ni_macaddr, sizeof(ns->ns_macaddr));
1036 (void)memcpy(ns->ns_bssid, ni->ni_bssid, sizeof(ns->ns_bssid));
1037 if (ni->ni_chan != IEEE80211_CHAN_ANYC) {
1038 ns->ns_freq = ni->ni_chan->ic_freq;
1039 ns->ns_chanflags = ni->ni_chan->ic_flags;
1040 ns->ns_chanidx = ni->ni_chan - chan0;
1041 } else {
1042 ns->ns_freq = ns->ns_chanflags = 0;
1043 ns->ns_chanidx = 0;
1044 }
1045 ns->ns_rssi = ni->ni_rssi;
1046 ns->ns_esslen = ni->ni_esslen;
1047 (void)memcpy(ns->ns_essid, ni->ni_essid, sizeof(ns->ns_essid));
1048 ns->ns_pwrsave = ni->ni_pwrsave;
1049 ns->ns_erp = ni->ni_erp;
1050 ns->ns_associd = ni->ni_associd;
1051 ns->ns_inact = ni->ni_inact * IEEE80211_INACT_WAIT;
1052 ns->ns_rstamp = ni->ni_rstamp;
1053 ns->ns_rates = ni->ni_rates;
1054 ns->ns_txrate = ni->ni_txrate;
1055 ns->ns_intval = ni->ni_intval;
1056 (void)memcpy(ns->ns_tstamp, ni->ni_tstamp, sizeof(ns->ns_tstamp));
1057 ns->ns_txseq = ni->ni_txseq;
1058 ns->ns_rxseq = ni->ni_rxseq;
1059 ns->ns_fhdwell = ni->ni_fhdwell;
1060 ns->ns_fhindex = ni->ni_fhindex;
1061 ns->ns_fails = ni->ni_fails;
1062 }
1063
1064 /* Between two examinations of the sysctl tree, I expect each
1065 * interface to add no more than 5 nodes.
1066 */
1067 #define IEEE80211_SYSCTL_NODE_GROWTH 5
1068
1069 static int
1070 sysctl_ieee80211_node(SYSCTLFN_ARGS)
1071 {
1072 struct ieee80211_node_walk nw;
1073 struct ieee80211_node *ni;
1074 struct ieee80211_node_sysctl ns;
1075 char *dp;
1076 u_int cur_ifindex, ifcount, ifindex, last_ifindex, op, arg, hdr_type;
1077 size_t len, needed, eltsize, out_size;
1078 int error, s, nelt;
1079
1080 if (namelen == 1 && name[0] == CTL_QUERY)
1081 return (sysctl_query(SYSCTLFN_CALL(rnode)));
1082
1083 if (namelen != IEEE80211_SYSCTL_NODENAMELEN)
1084 return (EINVAL);
1085
1086 /* ifindex.op.arg.header-type.eltsize.nelt */
1087 dp = oldp;
1088 len = (oldp != NULL) ? *oldlenp : 0;
1089 ifindex = name[IEEE80211_SYSCTL_NODENAME_IF];
1090 op = name[IEEE80211_SYSCTL_NODENAME_OP];
1091 arg = name[IEEE80211_SYSCTL_NODENAME_ARG];
1092 hdr_type = name[IEEE80211_SYSCTL_NODENAME_TYPE];
1093 eltsize = name[IEEE80211_SYSCTL_NODENAME_ELTSIZE];
1094 nelt = name[IEEE80211_SYSCTL_NODENAME_ELTCOUNT];
1095 out_size = MIN(sizeof(ns), eltsize);
1096
1097 if (op != IEEE80211_SYSCTL_OP_ALL || arg != 0 ||
1098 hdr_type != IEEE80211_SYSCTL_T_NODE || eltsize < 1 || nelt < 0)
1099 return (EINVAL);
1100
1101 error = 0;
1102 needed = 0;
1103 ifcount = 0;
1104 last_ifindex = 0;
1105
1106 s = splnet();
1107
1108 for (ni = ieee80211_node_walkfirst(&nw, ifindex); ni != NULL;
1109 ni = ieee80211_node_walknext(&nw)) {
1110 struct ieee80211com *ic;
1111
1112 ic = nw.nw_ic;
1113 cur_ifindex = ic->ic_if.if_index;
1114
1115 if (cur_ifindex != last_ifindex) {
1116 ifcount++;
1117 last_ifindex = cur_ifindex;
1118 }
1119
1120 if (nelt <= 0)
1121 continue;
1122
1123 if (len >= eltsize) {
1124 sysctl_ieee80211_fill_node(ni, &ns, cur_ifindex,
1125 &ic->ic_channels[0], ni == ic->ic_bss);
1126 error = copyout(&ns, dp, out_size);
1127 if (error)
1128 goto cleanup;
1129 dp += eltsize;
1130 len -= eltsize;
1131 }
1132 needed += eltsize;
1133 if (nelt != INT_MAX)
1134 nelt--;
1135 }
1136 cleanup:
1137 splx(s);
1138
1139 *oldlenp = needed;
1140 if (oldp == NULL)
1141 *oldlenp += ifcount * IEEE80211_SYSCTL_NODE_GROWTH * eltsize;
1142
1143 return (error);
1144 }
1145
1146 /*
1147 * Setup sysctl(3) MIB, net.ieee80211.*
1148 *
1149 * TBD condition CTLFLAG_PERMANENT on being an LKM or not
1150 */
1151 SYSCTL_SETUP(sysctl_ieee80211, "sysctl ieee80211 subtree setup")
1152 {
1153 int rc;
1154 struct sysctlnode *cnode, *rnode;
1155
1156 if ((rc = sysctl_createv(clog, 0, NULL, &rnode,
1157 CTLFLAG_PERMANENT, CTLTYPE_NODE, "net", NULL,
1158 NULL, 0, NULL, 0, CTL_NET, CTL_EOL)) != 0)
1159 goto err;
1160
1161 if ((rc = sysctl_createv(clog, 0, &rnode, &rnode,
1162 CTLFLAG_PERMANENT, CTLTYPE_NODE, "link",
1163 "link-layer statistics and controls",
1164 NULL, 0, NULL, 0, PF_LINK, CTL_EOL)) != 0)
1165 goto err;
1166
1167 if ((rc = sysctl_createv(clog, 0, &rnode, &rnode,
1168 CTLFLAG_PERMANENT, CTLTYPE_NODE, "ieee80211",
1169 "IEEE 802.11 WLAN statistics and controls",
1170 NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
1171 goto err;
1172
1173 if ((rc = sysctl_createv(clog, 0, &rnode, NULL,
1174 CTLFLAG_PERMANENT, CTLTYPE_NODE, "nodes", "client/peer stations",
1175 sysctl_ieee80211_node, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
1176 goto err;
1177
1178 #ifdef IEEE80211_DEBUG
1179
1180 /* control debugging printfs */
1181 if ((rc = sysctl_createv(clog, 0, &rnode, &cnode,
1182 CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT,
1183 "debug", SYSCTL_DESCR("Enable IEEE 802.11 debugging output"),
1184 sysctl_ieee80211_verify, 0, &ieee80211_debug, 0,
1185 CTL_CREATE, CTL_EOL)) != 0)
1186 goto err;
1187
1188 ieee80211_debug_nodenum = cnode->sysctl_num;
1189
1190 #endif /* IEEE80211_DEBUG */
1191
1192 /* control inactivity timer */
1193 if ((rc = sysctl_createv(clog, 0, &rnode, &cnode,
1194 CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT,
1195 "maxinact", SYSCTL_DESCR("Station inactivity timeout"),
1196 sysctl_ieee80211_verify, 0, &ieee80211_inact_max,
1197 0, CTL_CREATE, CTL_EOL)) != 0)
1198 goto err;
1199
1200 ieee80211_inact_max_nodenum = cnode->sysctl_num;
1201
1202 return;
1203 err:
1204 printf("%s: sysctl_createv failed (rc = %d)\n", __func__, rc);
1205 }
1206 #endif /* __NetBSD__ */
1207
1208 #ifdef __FreeBSD__
1209 /*
1210 * Module glue.
1211 *
1212 * NB: the module name is "wlan" for compatibility with NetBSD.
1213 */
1214
1215 static int
1216 ieee80211_modevent(module_t mod, int type, void *unused)
1217 {
1218 switch (type) {
1219 case MOD_LOAD:
1220 if (bootverbose)
1221 printf("wlan: <802.11 Link Layer>\n");
1222 return 0;
1223 case MOD_UNLOAD:
1224 return 0;
1225 }
1226 return EINVAL;
1227 }
1228
1229 static moduledata_t ieee80211_mod = {
1230 "wlan",
1231 ieee80211_modevent,
1232 0
1233 };
1234 DECLARE_MODULE(wlan, ieee80211_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
1235 MODULE_VERSION(wlan, 1);
1236 MODULE_DEPEND(wlan, rc4, 1, 1, 1);
1237 MODULE_DEPEND(wlan, ether, 1, 1, 1);
1238 #endif
1239