1 /*- 2 * Copyright (c) 2003-2008 Sam Leffler, Errno Consulting 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include <sys/cdefs.h> 27 __FBSDID("$FreeBSD$"); 28 29 /* 30 * IEEE 802.11 support (FreeBSD-specific code) 31 */ 32 #include "opt_wlan.h" 33 34 #include <sys/param.h> 35 #include <sys/kernel.h> 36 #include <sys/systm.h> 37 #include <sys/linker.h> 38 #include <sys/mbuf.h> 39 #include <sys/module.h> 40 #include <sys/proc.h> 41 #include <sys/sysctl.h> 42 43 #include <sys/socket.h> 44 45 #include <net/if.h> 46 #include <net/if_clone.h> 47 #include <net/if_media.h> 48 #include <net/if_types.h> 49 #include <net/ethernet.h> 50 #include <net/route.h> 51 52 #include <net80211/ieee80211_var.h> 53 54 SYSCTL_NODE(_net, OID_AUTO, wlan, CTLFLAG_RD, 0, "IEEE 80211 parameters"); 55 56 #ifdef IEEE80211_DEBUG 57 int ieee80211_debug = 0; 58 SYSCTL_INT(_net_wlan, OID_AUTO, debug, CTLFLAG_RW, &ieee80211_debug, 59 0, "debugging printfs"); 60 #endif 61 extern int ieee80211_recv_bar_ena; 62 SYSCTL_INT(_net_wlan, OID_AUTO, recv_bar, CTLFLAG_RW, &ieee80211_recv_bar_ena, 63 0, "BAR frame processing (ena/dis)"); 64 extern int ieee80211_nol_timeout; 65 SYSCTL_INT(_net_wlan, OID_AUTO, nol_timeout, CTLFLAG_RW, 66 &ieee80211_nol_timeout, 0, "NOL timeout (secs)"); 67 extern int ieee80211_cac_timeout; 68 SYSCTL_INT(_net_wlan, OID_AUTO, cac_timeout, CTLFLAG_RW, 69 &ieee80211_cac_timeout, 0, "CAC timeout (secs)"); 70 71 MALLOC_DEFINE(M_80211_COM, "80211com", "802.11 com state"); 72 73 /* 74 * Allocate/free com structure in conjunction with ifnet; 75 * these routines are registered with if_register_com_alloc 76 * below and are called automatically by the ifnet code 77 * when the ifnet of the parent device is created. 78 */ 79 static void * 80 wlan_alloc(u_char type, struct ifnet *ifp) 81 { 82 struct ieee80211com *ic; 83 84 ic = malloc(sizeof(struct ieee80211com), M_80211_COM, M_WAITOK|M_ZERO); 85 ic->ic_ifp = ifp; 86 87 return (ic); 88 } 89 90 static void 91 wlan_free(void *ic, u_char type) 92 { 93 free(ic, M_80211_COM); 94 } 95 96 static int 97 wlan_clone_create(struct if_clone *ifc, int unit, caddr_t params) 98 { 99 struct ieee80211_clone_params cp; 100 struct ieee80211vap *vap; 101 struct ieee80211com *ic; 102 struct ifnet *ifp; 103 int error; 104 105 error = copyin(params, &cp, sizeof(cp)); 106 if (error) 107 return error; 108 ifp = ifunit(cp.icp_parent); 109 if (ifp == NULL) 110 return ENXIO; 111 /* XXX move printfs to DIAGNOSTIC before release */ 112 if (ifp->if_type != IFT_IEEE80211) { 113 if_printf(ifp, "%s: reject, not an 802.11 device\n", __func__); 114 return ENXIO; 115 } 116 if (cp.icp_opmode >= IEEE80211_OPMODE_MAX) { 117 if_printf(ifp, "%s: invalid opmode %d\n", 118 __func__, cp.icp_opmode); 119 return EINVAL; 120 } 121 ic = ifp->if_l2com; 122 if ((ic->ic_caps & ieee80211_opcap[cp.icp_opmode]) == 0) { 123 if_printf(ifp, "%s mode not supported\n", 124 ieee80211_opmode_name[cp.icp_opmode]); 125 return EOPNOTSUPP; 126 } 127 vap = ic->ic_vap_create(ic, ifc->ifc_name, unit, 128 cp.icp_opmode, cp.icp_flags, cp.icp_bssid, 129 cp.icp_flags & IEEE80211_CLONE_MACADDR ? 130 cp.icp_macaddr : ic->ic_myaddr); 131 return (vap == NULL ? EIO : 0); 132 } 133 134 static void 135 wlan_clone_destroy(struct ifnet *ifp) 136 { 137 struct ieee80211vap *vap = ifp->if_softc; 138 struct ieee80211com *ic = vap->iv_ic; 139 140 ic->ic_vap_delete(vap); 141 } 142 IFC_SIMPLE_DECLARE(wlan, 0); 143 144 void 145 ieee80211_vap_destroy(struct ieee80211vap *vap) 146 { 147 if_clone_destroyif(&wlan_cloner, vap->iv_ifp); 148 } 149 150 static int 151 ieee80211_sysctl_msecs_ticks(SYSCTL_HANDLER_ARGS) 152 { 153 int msecs = ticks_to_msecs(*(int *)arg1); 154 int error, t; 155 156 error = sysctl_handle_int(oidp, &msecs, 0, req); 157 if (error || !req->newptr) 158 return error; 159 t = msecs_to_ticks(msecs); 160 *(int *)arg1 = (t < 1) ? 1 : t; 161 return 0; 162 } 163 164 #ifdef IEEE80211_AMPDU_AGE 165 extern int ieee80211_ampdu_age; 166 SYSCTL_PROC(_net_wlan, OID_AUTO, ampdu_age, CTLFLAG_RW, 167 &ieee80211_ampdu_age, 0, ieee80211_sysctl_msecs_ticks, "I", 168 "AMPDU max reorder age (ms)"); 169 #endif 170 extern int ieee80211_addba_timeout; 171 SYSCTL_PROC(_net_wlan, OID_AUTO, addba_timeout, CTLFLAG_RW, 172 &ieee80211_addba_timeout, 0, ieee80211_sysctl_msecs_ticks, "I", 173 "ADDBA request timeout (ms)"); 174 extern int ieee80211_addba_backoff; 175 SYSCTL_PROC(_net_wlan, OID_AUTO, addba_backoff, CTLFLAG_RW, 176 &ieee80211_addba_backoff, 0, ieee80211_sysctl_msecs_ticks, "I", 177 "ADDBA request backoff (ms)"); 178 extern int ieee80211_addba_maxtries; 179 SYSCTL_INT(_net_wlan, OID_AUTO, addba_maxtries, CTLFLAG_RW, 180 &ieee80211_addba_maxtries, 0, "max ADDBA requests sent before backoff"); 181 182 static int 183 ieee80211_sysctl_inact(SYSCTL_HANDLER_ARGS) 184 { 185 int inact = (*(int *)arg1) * IEEE80211_INACT_WAIT; 186 int error; 187 188 error = sysctl_handle_int(oidp, &inact, 0, req); 189 if (error || !req->newptr) 190 return error; 191 *(int *)arg1 = inact / IEEE80211_INACT_WAIT; 192 return 0; 193 } 194 195 static int 196 ieee80211_sysctl_parent(SYSCTL_HANDLER_ARGS) 197 { 198 struct ieee80211com *ic = arg1; 199 const char *name = ic->ic_ifp->if_xname; 200 201 return SYSCTL_OUT(req, name, strlen(name)); 202 } 203 204 static int 205 ieee80211_sysctl_radar(SYSCTL_HANDLER_ARGS) 206 { 207 struct ieee80211com *ic = arg1; 208 int t = 0, error; 209 210 error = sysctl_handle_int(oidp, &t, 0, req); 211 if (error || !req->newptr) 212 return error; 213 IEEE80211_LOCK(ic); 214 ieee80211_dfs_notify_radar(ic, ic->ic_curchan); 215 IEEE80211_UNLOCK(ic); 216 return 0; 217 } 218 219 void 220 ieee80211_sysctl_attach(struct ieee80211com *ic) 221 { 222 } 223 224 void 225 ieee80211_sysctl_detach(struct ieee80211com *ic) 226 { 227 } 228 229 void 230 ieee80211_sysctl_vattach(struct ieee80211vap *vap) 231 { 232 struct ifnet *ifp = vap->iv_ifp; 233 struct sysctl_ctx_list *ctx; 234 struct sysctl_oid *oid; 235 char num[14]; /* sufficient for 32 bits */ 236 237 MALLOC(ctx, struct sysctl_ctx_list *, sizeof(struct sysctl_ctx_list), 238 M_DEVBUF, M_NOWAIT | M_ZERO); 239 if (ctx == NULL) { 240 if_printf(ifp, "%s: cannot allocate sysctl context!\n", 241 __func__); 242 return; 243 } 244 sysctl_ctx_init(ctx); 245 snprintf(num, sizeof(num), "%u", ifp->if_dunit); 246 oid = SYSCTL_ADD_NODE(ctx, &SYSCTL_NODE_CHILDREN(_net, wlan), 247 OID_AUTO, num, CTLFLAG_RD, NULL, ""); 248 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, 249 "%parent", CTLFLAG_RD, vap->iv_ic, 0, 250 ieee80211_sysctl_parent, "A", "parent device"); 251 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, 252 "driver_caps", CTLFLAG_RW, &vap->iv_caps, 0, 253 "driver capabilities"); 254 #ifdef IEEE80211_DEBUG 255 vap->iv_debug = ieee80211_debug; 256 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, 257 "debug", CTLFLAG_RW, &vap->iv_debug, 0, 258 "control debugging printfs"); 259 #endif 260 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, 261 "bmiss_max", CTLFLAG_RW, &vap->iv_bmiss_max, 0, 262 "consecutive beacon misses before scanning"); 263 /* XXX inherit from tunables */ 264 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, 265 "inact_run", CTLTYPE_INT | CTLFLAG_RW, &vap->iv_inact_run, 0, 266 ieee80211_sysctl_inact, "I", 267 "station inactivity timeout (sec)"); 268 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, 269 "inact_probe", CTLTYPE_INT | CTLFLAG_RW, &vap->iv_inact_probe, 0, 270 ieee80211_sysctl_inact, "I", 271 "station inactivity probe timeout (sec)"); 272 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, 273 "inact_auth", CTLTYPE_INT | CTLFLAG_RW, &vap->iv_inact_auth, 0, 274 ieee80211_sysctl_inact, "I", 275 "station authentication timeout (sec)"); 276 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, 277 "inact_init", CTLTYPE_INT | CTLFLAG_RW, &vap->iv_inact_init, 0, 278 ieee80211_sysctl_inact, "I", 279 "station initial state timeout (sec)"); 280 if (vap->iv_htcaps & IEEE80211_HTC_HT) { 281 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, 282 "ampdu_mintraffic_bk", CTLFLAG_RW, 283 &vap->iv_ampdu_mintraffic[WME_AC_BK], 0, 284 "BK traffic tx aggr threshold (pps)"); 285 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, 286 "ampdu_mintraffic_be", CTLFLAG_RW, 287 &vap->iv_ampdu_mintraffic[WME_AC_BE], 0, 288 "BE traffic tx aggr threshold (pps)"); 289 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, 290 "ampdu_mintraffic_vo", CTLFLAG_RW, 291 &vap->iv_ampdu_mintraffic[WME_AC_VO], 0, 292 "VO traffic tx aggr threshold (pps)"); 293 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, 294 "ampdu_mintraffic_vi", CTLFLAG_RW, 295 &vap->iv_ampdu_mintraffic[WME_AC_VI], 0, 296 "VI traffic tx aggr threshold (pps)"); 297 } 298 if (vap->iv_caps & IEEE80211_C_DFS) { 299 SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO, 300 "radar", CTLTYPE_INT | CTLFLAG_RW, vap->iv_ic, 0, 301 ieee80211_sysctl_radar, "I", "simulare radar event"); 302 } 303 vap->iv_sysctl = ctx; 304 vap->iv_oid = oid; 305 } 306 307 void 308 ieee80211_sysctl_vdetach(struct ieee80211vap *vap) 309 { 310 311 if (vap->iv_sysctl != NULL) { 312 sysctl_ctx_free(vap->iv_sysctl); 313 FREE(vap->iv_sysctl, M_DEVBUF); 314 vap->iv_sysctl = NULL; 315 } 316 } 317 318 int 319 ieee80211_node_dectestref(struct ieee80211_node *ni) 320 { 321 /* XXX need equivalent of atomic_dec_and_test */ 322 atomic_subtract_int(&ni->ni_refcnt, 1); 323 return atomic_cmpset_int(&ni->ni_refcnt, 0, 1); 324 } 325 326 void 327 ieee80211_drain_ifq(struct ifqueue *ifq) 328 { 329 struct ieee80211_node *ni; 330 struct mbuf *m; 331 332 for (;;) { 333 IF_DEQUEUE(ifq, m); 334 if (m == NULL) 335 break; 336 337 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 338 KASSERT(ni != NULL, ("frame w/o node")); 339 ieee80211_free_node(ni); 340 m->m_pkthdr.rcvif = NULL; 341 342 m_freem(m); 343 } 344 } 345 346 void 347 ieee80211_flush_ifq(struct ifqueue *ifq, struct ieee80211vap *vap) 348 { 349 struct ieee80211_node *ni; 350 struct mbuf *m, **mprev; 351 352 IF_LOCK(ifq); 353 mprev = &ifq->ifq_head; 354 while ((m = *mprev) != NULL) { 355 ni = (struct ieee80211_node *)m->m_pkthdr.rcvif; 356 if (ni != NULL && ni->ni_vap == vap) { 357 *mprev = m->m_nextpkt; /* remove from list */ 358 ifq->ifq_len--; 359 360 m_freem(m); 361 ieee80211_free_node(ni); /* reclaim ref */ 362 } else 363 mprev = &m->m_nextpkt; 364 } 365 /* recalculate tail ptr */ 366 m = ifq->ifq_head; 367 for (; m != NULL && m->m_nextpkt != NULL; m = m->m_nextpkt) 368 ; 369 ifq->ifq_tail = m; 370 IF_UNLOCK(ifq); 371 } 372 373 /* 374 * As above, for mbufs allocated with m_gethdr/MGETHDR 375 * or initialized by M_COPY_PKTHDR. 376 */ 377 #define MC_ALIGN(m, len) \ 378 do { \ 379 (m)->m_data += (MCLBYTES - (len)) &~ (sizeof(long) - 1); \ 380 } while (/* CONSTCOND */ 0) 381 382 /* 383 * Allocate and setup a management frame of the specified 384 * size. We return the mbuf and a pointer to the start 385 * of the contiguous data area that's been reserved based 386 * on the packet length. The data area is forced to 32-bit 387 * alignment and the buffer length to a multiple of 4 bytes. 388 * This is done mainly so beacon frames (that require this) 389 * can use this interface too. 390 */ 391 struct mbuf * 392 ieee80211_getmgtframe(uint8_t **frm, int headroom, int pktlen) 393 { 394 struct mbuf *m; 395 u_int len; 396 397 /* 398 * NB: we know the mbuf routines will align the data area 399 * so we don't need to do anything special. 400 */ 401 len = roundup2(headroom + pktlen, 4); 402 KASSERT(len <= MCLBYTES, ("802.11 mgt frame too large: %u", len)); 403 if (len < MINCLSIZE) { 404 m = m_gethdr(M_NOWAIT, MT_DATA); 405 /* 406 * Align the data in case additional headers are added. 407 * This should only happen when a WEP header is added 408 * which only happens for shared key authentication mgt 409 * frames which all fit in MHLEN. 410 */ 411 if (m != NULL) 412 MH_ALIGN(m, len); 413 } else { 414 m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); 415 if (m != NULL) 416 MC_ALIGN(m, len); 417 } 418 if (m != NULL) { 419 m->m_data += headroom; 420 *frm = m->m_data; 421 } 422 return m; 423 } 424 425 int 426 ieee80211_add_callback(struct mbuf *m, 427 void (*func)(struct ieee80211_node *, void *, int), void *arg) 428 { 429 struct m_tag *mtag; 430 struct ieee80211_cb *cb; 431 432 mtag = m_tag_alloc(MTAG_ABI_NET80211, NET80211_TAG_CALLBACK, 433 sizeof(struct ieee80211_cb), M_NOWAIT); 434 if (mtag == NULL) 435 return 0; 436 437 cb = (struct ieee80211_cb *)(mtag+1); 438 cb->func = func; 439 cb->arg = arg; 440 m_tag_prepend(m, mtag); 441 m->m_flags |= M_TXCB; 442 return 1; 443 } 444 445 void 446 ieee80211_process_callback(struct ieee80211_node *ni, 447 struct mbuf *m, int status) 448 { 449 struct m_tag *mtag; 450 451 mtag = m_tag_locate(m, MTAG_ABI_NET80211, NET80211_TAG_CALLBACK, NULL); 452 if (mtag != NULL) { 453 struct ieee80211_cb *cb = (struct ieee80211_cb *)(mtag+1); 454 cb->func(ni, cb->arg, status); 455 } 456 } 457 458 #include <sys/libkern.h> 459 460 void 461 get_random_bytes(void *p, size_t n) 462 { 463 uint8_t *dp = p; 464 465 while (n > 0) { 466 uint32_t v = arc4random(); 467 size_t nb = n > sizeof(uint32_t) ? sizeof(uint32_t) : n; 468 bcopy(&v, dp, n > sizeof(uint32_t) ? sizeof(uint32_t) : n); 469 dp += sizeof(uint32_t), n -= nb; 470 } 471 } 472 473 /* 474 * Helper function for events that pass just a single mac address. 475 */ 476 static void 477 notify_macaddr(struct ifnet *ifp, int op, const uint8_t mac[IEEE80211_ADDR_LEN]) 478 { 479 struct ieee80211_join_event iev; 480 481 memset(&iev, 0, sizeof(iev)); 482 IEEE80211_ADDR_COPY(iev.iev_addr, mac); 483 rt_ieee80211msg(ifp, op, &iev, sizeof(iev)); 484 } 485 486 void 487 ieee80211_notify_node_join(struct ieee80211_node *ni, int newassoc) 488 { 489 struct ieee80211vap *vap = ni->ni_vap; 490 struct ifnet *ifp = vap->iv_ifp; 491 492 IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%snode join", 493 (ni == vap->iv_bss) ? "bss " : ""); 494 495 if (ni == vap->iv_bss) { 496 notify_macaddr(ifp, newassoc ? 497 RTM_IEEE80211_ASSOC : RTM_IEEE80211_REASSOC, ni->ni_bssid); 498 if_link_state_change(ifp, LINK_STATE_UP); 499 } else { 500 notify_macaddr(ifp, newassoc ? 501 RTM_IEEE80211_JOIN : RTM_IEEE80211_REJOIN, ni->ni_macaddr); 502 } 503 } 504 505 void 506 ieee80211_notify_node_leave(struct ieee80211_node *ni) 507 { 508 struct ieee80211vap *vap = ni->ni_vap; 509 struct ifnet *ifp = vap->iv_ifp; 510 511 IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%snode leave", 512 (ni == vap->iv_bss) ? "bss " : ""); 513 514 if (ni == vap->iv_bss) { 515 rt_ieee80211msg(ifp, RTM_IEEE80211_DISASSOC, NULL, 0); 516 if_link_state_change(ifp, LINK_STATE_DOWN); 517 } else { 518 /* fire off wireless event station leaving */ 519 notify_macaddr(ifp, RTM_IEEE80211_LEAVE, ni->ni_macaddr); 520 } 521 } 522 523 void 524 ieee80211_notify_scan_done(struct ieee80211vap *vap) 525 { 526 struct ifnet *ifp = vap->iv_ifp; 527 528 IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, "%s\n", "notify scan done"); 529 530 /* dispatch wireless event indicating scan completed */ 531 rt_ieee80211msg(ifp, RTM_IEEE80211_SCAN, NULL, 0); 532 } 533 534 void 535 ieee80211_notify_replay_failure(struct ieee80211vap *vap, 536 const struct ieee80211_frame *wh, const struct ieee80211_key *k, 537 u_int64_t rsc) 538 { 539 struct ifnet *ifp = vap->iv_ifp; 540 541 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2, 542 "%s replay detected <rsc %ju, csc %ju, keyix %u rxkeyix %u>", 543 k->wk_cipher->ic_name, (intmax_t) rsc, 544 (intmax_t) k->wk_keyrsc[IEEE80211_NONQOS_TID], 545 k->wk_keyix, k->wk_rxkeyix); 546 547 if (ifp != NULL) { /* NB: for cipher test modules */ 548 struct ieee80211_replay_event iev; 549 550 IEEE80211_ADDR_COPY(iev.iev_dst, wh->i_addr1); 551 IEEE80211_ADDR_COPY(iev.iev_src, wh->i_addr2); 552 iev.iev_cipher = k->wk_cipher->ic_cipher; 553 if (k->wk_rxkeyix != IEEE80211_KEYIX_NONE) 554 iev.iev_keyix = k->wk_rxkeyix; 555 else 556 iev.iev_keyix = k->wk_keyix; 557 iev.iev_keyrsc = k->wk_keyrsc[0]; /* XXX need tid */ 558 iev.iev_rsc = rsc; 559 rt_ieee80211msg(ifp, RTM_IEEE80211_REPLAY, &iev, sizeof(iev)); 560 } 561 } 562 563 void 564 ieee80211_notify_michael_failure(struct ieee80211vap *vap, 565 const struct ieee80211_frame *wh, u_int keyix) 566 { 567 struct ifnet *ifp = vap->iv_ifp; 568 569 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2, 570 "michael MIC verification failed <keyix %u>", keyix); 571 vap->iv_stats.is_rx_tkipmic++; 572 573 if (ifp != NULL) { /* NB: for cipher test modules */ 574 struct ieee80211_michael_event iev; 575 576 IEEE80211_ADDR_COPY(iev.iev_dst, wh->i_addr1); 577 IEEE80211_ADDR_COPY(iev.iev_src, wh->i_addr2); 578 iev.iev_cipher = IEEE80211_CIPHER_TKIP; 579 iev.iev_keyix = keyix; 580 rt_ieee80211msg(ifp, RTM_IEEE80211_MICHAEL, &iev, sizeof(iev)); 581 } 582 } 583 584 void 585 ieee80211_notify_wds_discover(struct ieee80211_node *ni) 586 { 587 struct ieee80211vap *vap = ni->ni_vap; 588 struct ifnet *ifp = vap->iv_ifp; 589 590 notify_macaddr(ifp, RTM_IEEE80211_WDS, ni->ni_macaddr); 591 } 592 593 void 594 ieee80211_notify_csa(struct ieee80211com *ic, 595 const struct ieee80211_channel *c, int mode, int count) 596 { 597 struct ifnet *ifp = ic->ic_ifp; 598 struct ieee80211_csa_event iev; 599 600 memset(&iev, 0, sizeof(iev)); 601 iev.iev_flags = c->ic_flags; 602 iev.iev_freq = c->ic_freq; 603 iev.iev_ieee = c->ic_ieee; 604 iev.iev_mode = mode; 605 iev.iev_count = count; 606 rt_ieee80211msg(ifp, RTM_IEEE80211_CSA, &iev, sizeof(iev)); 607 } 608 609 void 610 ieee80211_notify_radar(struct ieee80211com *ic, 611 const struct ieee80211_channel *c) 612 { 613 struct ifnet *ifp = ic->ic_ifp; 614 struct ieee80211_radar_event iev; 615 616 memset(&iev, 0, sizeof(iev)); 617 iev.iev_flags = c->ic_flags; 618 iev.iev_freq = c->ic_freq; 619 iev.iev_ieee = c->ic_ieee; 620 rt_ieee80211msg(ifp, RTM_IEEE80211_RADAR, &iev, sizeof(iev)); 621 } 622 623 void 624 ieee80211_notify_cac(struct ieee80211com *ic, 625 const struct ieee80211_channel *c, enum ieee80211_notify_cac_event type) 626 { 627 struct ifnet *ifp = ic->ic_ifp; 628 struct ieee80211_cac_event iev; 629 630 memset(&iev, 0, sizeof(iev)); 631 iev.iev_flags = c->ic_flags; 632 iev.iev_freq = c->ic_freq; 633 iev.iev_ieee = c->ic_ieee; 634 iev.iev_type = type; 635 rt_ieee80211msg(ifp, RTM_IEEE80211_CAC, &iev, sizeof(iev)); 636 } 637 638 void 639 ieee80211_notify_node_deauth(struct ieee80211_node *ni) 640 { 641 struct ieee80211vap *vap = ni->ni_vap; 642 struct ifnet *ifp = vap->iv_ifp; 643 644 IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%s", "node deauth"); 645 646 notify_macaddr(ifp, RTM_IEEE80211_DEAUTH, ni->ni_macaddr); 647 } 648 649 void 650 ieee80211_notify_node_auth(struct ieee80211_node *ni) 651 { 652 struct ieee80211vap *vap = ni->ni_vap; 653 struct ifnet *ifp = vap->iv_ifp; 654 655 IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%s", "node auth"); 656 657 notify_macaddr(ifp, RTM_IEEE80211_AUTH, ni->ni_macaddr); 658 } 659 660 void 661 ieee80211_notify_country(struct ieee80211vap *vap, 662 const uint8_t bssid[IEEE80211_ADDR_LEN], const uint8_t cc[2]) 663 { 664 struct ifnet *ifp = vap->iv_ifp; 665 struct ieee80211_country_event iev; 666 667 memset(&iev, 0, sizeof(iev)); 668 IEEE80211_ADDR_COPY(iev.iev_addr, bssid); 669 iev.iev_cc[0] = cc[0]; 670 iev.iev_cc[1] = cc[1]; 671 rt_ieee80211msg(ifp, RTM_IEEE80211_COUNTRY, &iev, sizeof(iev)); 672 } 673 674 void 675 ieee80211_notify_radio(struct ieee80211com *ic, int state) 676 { 677 struct ifnet *ifp = ic->ic_ifp; 678 struct ieee80211_radio_event iev; 679 680 memset(&iev, 0, sizeof(iev)); 681 iev.iev_state = state; 682 rt_ieee80211msg(ifp, RTM_IEEE80211_RADIO, &iev, sizeof(iev)); 683 } 684 685 void 686 ieee80211_load_module(const char *modname) 687 { 688 689 #ifdef notyet 690 (void)kern_kldload(curthread, modname, NULL); 691 #else 692 printf("%s: load the %s module by hand for now.\n", __func__, modname); 693 #endif 694 } 695 696 /* 697 * Module glue. 698 * 699 * NB: the module name is "wlan" for compatibility with NetBSD. 700 */ 701 static int 702 wlan_modevent(module_t mod, int type, void *unused) 703 { 704 switch (type) { 705 case MOD_LOAD: 706 if (bootverbose) 707 printf("wlan: <802.11 Link Layer>\n"); 708 if_clone_attach(&wlan_cloner); 709 if_register_com_alloc(IFT_IEEE80211, wlan_alloc, wlan_free); 710 return 0; 711 case MOD_UNLOAD: 712 if_deregister_com_alloc(IFT_IEEE80211); 713 if_clone_detach(&wlan_cloner); 714 return 0; 715 } 716 return EINVAL; 717 } 718 719 static moduledata_t wlan_mod = { 720 "wlan", 721 wlan_modevent, 722 0 723 }; 724 DECLARE_MODULE(wlan, wlan_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST); 725 MODULE_VERSION(wlan, 1); 726 MODULE_DEPEND(wlan, ether, 1, 1, 1); 727