1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2010-2011 Monthadar Al Jaberi, TerraNet AB 5 * All rights reserved. 6 * 7 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer, 15 * without modification. 16 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 17 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 18 * redistribution must be conditioned upon including a substantially 19 * similar Disclaimer requirement for further binary redistribution. 20 * 21 * NO WARRANTY 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 25 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 26 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 27 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 30 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 32 * THE POSSIBILITY OF SUCH DAMAGES. 33 * 34 * $FreeBSD$ 35 */ 36 #include "if_wtapvar.h" 37 #include <sys/uio.h> /* uio struct */ 38 #include <sys/jail.h> 39 #include <net/if_var.h> 40 #include <net/vnet.h> 41 42 #include <net80211/ieee80211_ratectl.h> 43 #include "if_medium.h" 44 45 /* 46 * This _requires_ vimage to be useful. 47 */ 48 #ifndef VIMAGE 49 #error if_wtap requires VIMAGE. 50 #endif /* VIMAGE */ 51 52 /* device for IOCTL and read/write for debuggin purposes */ 53 /* Function prototypes */ 54 static d_open_t wtap_node_open; 55 static d_close_t wtap_node_close; 56 static d_write_t wtap_node_write; 57 static d_ioctl_t wtap_node_ioctl; 58 59 static struct cdevsw wtap_cdevsw = { 60 .d_version = D_VERSION, 61 .d_flags = 0, 62 .d_open = wtap_node_open, 63 .d_close = wtap_node_close, 64 .d_write = wtap_node_write, 65 .d_ioctl = wtap_node_ioctl, 66 .d_name = "wtapnode", 67 }; 68 69 static int 70 wtap_node_open(struct cdev *dev, int oflags, int devtype, struct thread *p) 71 { 72 73 int err = 0; 74 uprintf("Opened device \"echo\" successfully.\n"); 75 return(err); 76 } 77 78 static int 79 wtap_node_close(struct cdev *dev, int fflag, int devtype, struct thread *p) 80 { 81 82 uprintf("Closing device \"echo.\"\n"); 83 return(0); 84 } 85 86 static int 87 wtap_node_write(struct cdev *dev, struct uio *uio, int ioflag) 88 { 89 int err = 0; 90 struct mbuf *m; 91 struct ifnet *ifp; 92 struct wtap_softc *sc; 93 uint8_t buf[1024]; 94 struct epoch_tracker et; 95 int buf_len; 96 97 uprintf("write device %s \"echo.\"\n", devtoname(dev)); 98 buf_len = MIN(uio->uio_iov->iov_len, 1024); 99 err = copyin(uio->uio_iov->iov_base, buf, buf_len); 100 101 if (err != 0) { 102 uprintf("Write failed: bad address!\n"); 103 return (err); 104 } 105 106 MGETHDR(m, M_NOWAIT, MT_DATA); 107 m_copyback(m, 0, buf_len, buf); 108 109 CURVNET_SET(TD_TO_VNET(curthread)); 110 NET_EPOCH_ENTER(et); 111 112 CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) { 113 printf("ifp->if_xname = %s\n", ifp->if_xname); 114 if(strcmp(devtoname(dev), ifp->if_xname) == 0){ 115 printf("found match, correspoding wtap = %s\n", 116 ifp->if_xname); 117 sc = (struct wtap_softc *)ifp->if_softc; 118 printf("wtap id = %d\n", sc->id); 119 wtap_inject(sc, m); 120 } 121 } 122 123 NET_EPOCH_EXIT(et); 124 CURVNET_RESTORE(); 125 126 return(err); 127 } 128 129 int 130 wtap_node_ioctl(struct cdev *dev, u_long cmd, caddr_t data, 131 int fflag, struct thread *td) 132 { 133 int error = 0; 134 135 switch(cmd) { 136 default: 137 DWTAP_PRINTF("Unknown WTAP IOCTL\n"); 138 error = EINVAL; 139 } 140 return error; 141 } 142 143 static int wtap_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 144 const struct ieee80211_bpf_params *params); 145 146 static int 147 wtap_medium_enqueue(struct wtap_vap *avp, struct mbuf *m) 148 { 149 150 return medium_transmit(avp->av_md, avp->id, m); 151 } 152 153 static int 154 wtap_media_change(struct ifnet *ifp) 155 { 156 157 DWTAP_PRINTF("%s\n", __func__); 158 int error = ieee80211_media_change(ifp); 159 /* NB: only the fixed rate can change and that doesn't need a reset */ 160 return (error == ENETRESET ? 0 : error); 161 } 162 163 /* 164 * Intercept management frames to collect beacon rssi data 165 * and to do ibss merges. 166 */ 167 static void 168 wtap_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m, 169 int subtype, const struct ieee80211_rx_stats *stats, int rssi, int nf) 170 { 171 struct ieee80211vap *vap = ni->ni_vap; 172 #if 0 173 DWTAP_PRINTF("[%d] %s\n", myath_id(ni), __func__); 174 #endif 175 WTAP_VAP(vap)->av_recv_mgmt(ni, m, subtype, stats, rssi, nf); 176 } 177 178 static int 179 wtap_reset_vap(struct ieee80211vap *vap, u_long cmd) 180 { 181 182 DWTAP_PRINTF("%s\n", __func__); 183 return 0; 184 } 185 186 static void 187 wtap_beacon_update(struct ieee80211vap *vap, int item) 188 { 189 struct ieee80211_beacon_offsets *bo = &vap->iv_bcn_off; 190 191 DWTAP_PRINTF("%s\n", __func__); 192 setbit(bo->bo_flags, item); 193 } 194 195 /* 196 * Allocate and setup an initial beacon frame. 197 */ 198 static int 199 wtap_beacon_alloc(struct wtap_softc *sc, struct ieee80211_node *ni) 200 { 201 struct ieee80211vap *vap = ni->ni_vap; 202 struct wtap_vap *avp = WTAP_VAP(vap); 203 204 DWTAP_PRINTF("[%s] %s\n", ether_sprintf(ni->ni_macaddr), __func__); 205 206 /* 207 * NB: the beacon data buffer must be 32-bit aligned; 208 * we assume the mbuf routines will return us something 209 * with this alignment (perhaps should assert). 210 */ 211 avp->beacon = ieee80211_beacon_alloc(ni); 212 if (avp->beacon == NULL) { 213 printf("%s: cannot get mbuf\n", __func__); 214 return ENOMEM; 215 } 216 callout_init(&avp->av_swba, 0); 217 avp->bf_node = ieee80211_ref_node(ni); 218 219 return 0; 220 } 221 222 static void 223 wtap_beacon_config(struct wtap_softc *sc, struct ieee80211vap *vap) 224 { 225 226 DWTAP_PRINTF("%s\n", __func__); 227 } 228 229 static void 230 wtap_beacon_intrp(void *arg) 231 { 232 struct wtap_vap *avp = arg; 233 struct ieee80211vap *vap = arg; 234 struct mbuf *m; 235 236 if (vap->iv_state < IEEE80211_S_RUN) { 237 DWTAP_PRINTF("Skip beacon, not running, state %d", vap->iv_state); 238 return ; 239 } 240 DWTAP_PRINTF("[%d] beacon intrp\n", avp->id); //burst mode 241 /* 242 * Update dynamic beacon contents. If this returns 243 * non-zero then we need to remap the memory because 244 * the beacon frame changed size (probably because 245 * of the TIM bitmap). 246 */ 247 m = m_dup(avp->beacon, M_NOWAIT); 248 if (ieee80211_beacon_update(avp->bf_node, m, 0)) { 249 printf("%s, need to remap the memory because the beacon frame" 250 " changed size.\n",__func__); 251 } 252 253 if (ieee80211_radiotap_active_vap(vap)) 254 ieee80211_radiotap_tx(vap, m); 255 256 #if 0 257 medium_transmit(avp->av_md, avp->id, m); 258 #endif 259 wtap_medium_enqueue(avp, m); 260 callout_schedule(&avp->av_swba, avp->av_bcinterval); 261 } 262 263 static int 264 wtap_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 265 { 266 struct ieee80211com *ic = vap->iv_ic; 267 struct wtap_softc *sc = ic->ic_softc; 268 struct wtap_vap *avp = WTAP_VAP(vap); 269 struct ieee80211_node *ni = NULL; 270 int error; 271 272 DWTAP_PRINTF("%s\n", __func__); 273 274 ni = ieee80211_ref_node(vap->iv_bss); 275 /* 276 * Invoke the parent method to do net80211 work. 277 */ 278 error = avp->av_newstate(vap, nstate, arg); 279 if (error != 0) 280 goto bad; 281 282 if (nstate == IEEE80211_S_RUN) { 283 /* NB: collect bss node again, it may have changed */ 284 ieee80211_free_node(ni); 285 ni = ieee80211_ref_node(vap->iv_bss); 286 switch (vap->iv_opmode) { 287 case IEEE80211_M_MBSS: 288 error = wtap_beacon_alloc(sc, ni); 289 if (error != 0) 290 goto bad; 291 wtap_beacon_config(sc, vap); 292 callout_reset(&avp->av_swba, avp->av_bcinterval, 293 wtap_beacon_intrp, vap); 294 break; 295 default: 296 goto bad; 297 } 298 } else if (nstate == IEEE80211_S_INIT) { 299 callout_stop(&avp->av_swba); 300 } 301 ieee80211_free_node(ni); 302 return 0; 303 bad: 304 printf("%s: bad\n", __func__); 305 ieee80211_free_node(ni); 306 return error; 307 } 308 309 static void 310 wtap_bmiss(struct ieee80211vap *vap) 311 { 312 struct wtap_vap *avp = (struct wtap_vap *)vap; 313 314 DWTAP_PRINTF("%s\n", __func__); 315 avp->av_bmiss(vap); 316 } 317 318 static struct ieee80211vap * 319 wtap_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ], 320 int unit, enum ieee80211_opmode opmode, int flags, 321 const uint8_t bssid[IEEE80211_ADDR_LEN], 322 const uint8_t mac[IEEE80211_ADDR_LEN]) 323 { 324 struct wtap_softc *sc = ic->ic_softc; 325 struct ieee80211vap *vap; 326 struct wtap_vap *avp; 327 int error; 328 struct ieee80211_node *ni; 329 330 DWTAP_PRINTF("%s\n", __func__); 331 332 avp = malloc(sizeof(struct wtap_vap), M_80211_VAP, M_WAITOK | M_ZERO); 333 avp->id = sc->id; 334 avp->av_md = sc->sc_md; 335 avp->av_bcinterval = msecs_to_ticks(BEACON_INTRERVAL + 100*sc->id); 336 vap = (struct ieee80211vap *) avp; 337 error = ieee80211_vap_setup(ic, vap, name, unit, IEEE80211_M_MBSS, 338 flags | IEEE80211_CLONE_NOBEACONS, bssid); 339 if (error) { 340 free(avp, M_80211_VAP); 341 return (NULL); 342 } 343 344 /* override various methods */ 345 avp->av_recv_mgmt = vap->iv_recv_mgmt; 346 vap->iv_recv_mgmt = wtap_recv_mgmt; 347 vap->iv_reset = wtap_reset_vap; 348 vap->iv_update_beacon = wtap_beacon_update; 349 avp->av_newstate = vap->iv_newstate; 350 vap->iv_newstate = wtap_newstate; 351 avp->av_bmiss = vap->iv_bmiss; 352 vap->iv_bmiss = wtap_bmiss; 353 354 /* complete setup */ 355 ieee80211_vap_attach(vap, wtap_media_change, ieee80211_media_status, 356 mac); 357 avp->av_dev = make_dev(&wtap_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, 358 "%s", (const char *)sc->name); 359 360 /* TODO this is a hack to force it to choose the rate we want */ 361 ni = ieee80211_ref_node(vap->iv_bss); 362 ni->ni_txrate = 130; 363 ieee80211_free_node(ni); 364 return vap; 365 } 366 367 static void 368 wtap_vap_delete(struct ieee80211vap *vap) 369 { 370 struct wtap_vap *avp = WTAP_VAP(vap); 371 372 DWTAP_PRINTF("%s\n", __func__); 373 destroy_dev(avp->av_dev); 374 callout_stop(&avp->av_swba); 375 ieee80211_vap_detach(vap); 376 free(avp, M_80211_VAP); 377 } 378 379 static void 380 wtap_parent(struct ieee80211com *ic) 381 { 382 struct wtap_softc *sc = ic->ic_softc; 383 384 if (ic->ic_nrunning > 0) { 385 sc->up = 1; 386 ieee80211_start_all(ic); 387 } else 388 sc->up = 0; 389 } 390 391 static void 392 wtap_scan_start(struct ieee80211com *ic) 393 { 394 395 #if 0 396 DWTAP_PRINTF("%s\n", __func__); 397 #endif 398 } 399 400 static void 401 wtap_scan_end(struct ieee80211com *ic) 402 { 403 404 #if 0 405 DWTAP_PRINTF("%s\n", __func__); 406 #endif 407 } 408 409 static void 410 wtap_set_channel(struct ieee80211com *ic) 411 { 412 413 #if 0 414 DWTAP_PRINTF("%s\n", __func__); 415 #endif 416 } 417 418 static int 419 wtap_raw_xmit(struct ieee80211_node *ni, struct mbuf *m, 420 const struct ieee80211_bpf_params *params) 421 { 422 #if 0 423 DWTAP_PRINTF("%s, %p\n", __func__, m); 424 #endif 425 struct ieee80211vap *vap = ni->ni_vap; 426 struct wtap_vap *avp = WTAP_VAP(vap); 427 428 if (ieee80211_radiotap_active_vap(vap)) { 429 ieee80211_radiotap_tx(vap, m); 430 } 431 if (m->m_flags & M_TXCB) 432 ieee80211_process_callback(ni, m, 0); 433 ieee80211_free_node(ni); 434 return wtap_medium_enqueue(avp, m); 435 } 436 437 void 438 wtap_inject(struct wtap_softc *sc, struct mbuf *m) 439 { 440 struct wtap_buf *bf = (struct wtap_buf *)malloc(sizeof(struct wtap_buf), 441 M_WTAP_RXBUF, M_NOWAIT | M_ZERO); 442 KASSERT(bf != NULL, ("could not allocated a new wtap_buf\n")); 443 bf->m = m; 444 445 mtx_lock(&sc->sc_mtx); 446 STAILQ_INSERT_TAIL(&sc->sc_rxbuf, bf, bf_list); 447 taskqueue_enqueue(sc->sc_tq, &sc->sc_rxtask); 448 mtx_unlock(&sc->sc_mtx); 449 } 450 451 void 452 wtap_rx_deliver(struct wtap_softc *sc, struct mbuf *m) 453 { 454 struct epoch_tracker et; 455 struct ieee80211com *ic = &sc->sc_ic; 456 struct ieee80211_node *ni; 457 int type; 458 #if 0 459 DWTAP_PRINTF("%s\n", __func__); 460 #endif 461 462 DWTAP_PRINTF("[%d] receiving m=%p\n", sc->id, m); 463 if (m == NULL) { /* NB: shouldn't happen */ 464 ic_printf(ic, "%s: no mbuf!\n", __func__); 465 } 466 467 ieee80211_dump_pkt(ic, mtod(m, caddr_t), 0,0,0); 468 469 /* 470 * Locate the node for sender, track state, and then 471 * pass the (referenced) node up to the 802.11 layer 472 * for its use. 473 */ 474 ni = ieee80211_find_rxnode_withkey(ic, 475 mtod(m, const struct ieee80211_frame_min *),IEEE80211_KEYIX_NONE); 476 NET_EPOCH_ENTER(et); 477 if (ni != NULL) { 478 /* 479 * Sending station is known, dispatch directly. 480 */ 481 type = ieee80211_input(ni, m, 1<<7, 10); 482 ieee80211_free_node(ni); 483 } else { 484 type = ieee80211_input_all(ic, m, 1<<7, 10); 485 } 486 NET_EPOCH_EXIT(et); 487 } 488 489 static void 490 wtap_rx_proc(void *arg, int npending) 491 { 492 struct epoch_tracker et; 493 struct wtap_softc *sc = (struct wtap_softc *)arg; 494 struct ieee80211com *ic = &sc->sc_ic; 495 struct mbuf *m; 496 struct ieee80211_node *ni; 497 int type; 498 struct wtap_buf *bf; 499 500 #if 0 501 DWTAP_PRINTF("%s\n", __func__); 502 #endif 503 504 for(;;) { 505 mtx_lock(&sc->sc_mtx); 506 bf = STAILQ_FIRST(&sc->sc_rxbuf); 507 if (bf == NULL) { 508 mtx_unlock(&sc->sc_mtx); 509 return; 510 } 511 STAILQ_REMOVE_HEAD(&sc->sc_rxbuf, bf_list); 512 mtx_unlock(&sc->sc_mtx); 513 KASSERT(bf != NULL, ("wtap_buf is NULL\n")); 514 m = bf->m; 515 DWTAP_PRINTF("[%d] receiving m=%p\n", sc->id, bf->m); 516 if (m == NULL) { /* NB: shouldn't happen */ 517 ic_printf(ic, "%s: no mbuf!\n", __func__); 518 free(bf, M_WTAP_RXBUF); 519 return; 520 } 521 #if 0 522 ieee80211_dump_pkt(ic, mtod(m, caddr_t), 0,0,0); 523 #endif 524 525 /* 526 * Locate the node for sender, track state, and then 527 * pass the (referenced) node up to the 802.11 layer 528 * for its use. 529 */ 530 ni = ieee80211_find_rxnode_withkey(ic, 531 mtod(m, const struct ieee80211_frame_min *), 532 IEEE80211_KEYIX_NONE); 533 NET_EPOCH_ENTER(et); 534 if (ni != NULL) { 535 /* 536 * Sending station is known, dispatch directly. 537 */ 538 type = ieee80211_input(ni, m, 1<<7, 10); 539 ieee80211_free_node(ni); 540 } else { 541 type = ieee80211_input_all(ic, m, 1<<7, 10); 542 } 543 NET_EPOCH_EXIT(et); 544 545 /* The mbufs are freed by the Net80211 stack */ 546 free(bf, M_WTAP_RXBUF); 547 } 548 } 549 550 static void 551 wtap_newassoc(struct ieee80211_node *ni, int isnew) 552 { 553 554 DWTAP_PRINTF("%s\n", __func__); 555 } 556 557 /* 558 * Callback from the 802.11 layer to update WME parameters. 559 */ 560 static int 561 wtap_wme_update(struct ieee80211com *ic) 562 { 563 564 DWTAP_PRINTF("%s\n", __func__); 565 return 0; 566 } 567 568 static void 569 wtap_update_mcast(struct ieee80211com *ic) 570 { 571 572 DWTAP_PRINTF("%s\n", __func__); 573 } 574 575 static void 576 wtap_update_promisc(struct ieee80211com *ic) 577 { 578 579 DWTAP_PRINTF("%s\n", __func__); 580 } 581 582 static int 583 wtap_transmit(struct ieee80211com *ic, struct mbuf *m) 584 { 585 struct ieee80211_node *ni = 586 (struct ieee80211_node *) m->m_pkthdr.rcvif; 587 struct ieee80211vap *vap = ni->ni_vap; 588 struct wtap_vap *avp = WTAP_VAP(vap); 589 590 if(ni == NULL){ 591 printf("m->m_pkthdr.rcvif is NULL we cant radiotap_tx\n"); 592 }else{ 593 if (ieee80211_radiotap_active_vap(vap)) 594 ieee80211_radiotap_tx(vap, m); 595 } 596 if (m->m_flags & M_TXCB) 597 ieee80211_process_callback(ni, m, 0); 598 ieee80211_free_node(ni); 599 return wtap_medium_enqueue(avp, m); 600 } 601 602 static struct ieee80211_node * 603 wtap_node_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN]) 604 { 605 struct ieee80211_node *ni; 606 607 DWTAP_PRINTF("%s\n", __func__); 608 609 ni = malloc(sizeof(struct ieee80211_node), M_80211_NODE, 610 M_NOWAIT|M_ZERO); 611 if (ni == NULL) 612 return (NULL); 613 614 ni->ni_txrate = 130; 615 return ni; 616 } 617 618 static void 619 wtap_node_free(struct ieee80211_node *ni) 620 { 621 struct ieee80211com *ic = ni->ni_ic; 622 struct wtap_softc *sc = ic->ic_softc; 623 624 DWTAP_PRINTF("%s\n", __func__); 625 sc->sc_node_free(ni); 626 } 627 628 int32_t 629 wtap_attach(struct wtap_softc *sc, const uint8_t *macaddr) 630 { 631 struct ieee80211com *ic = &sc->sc_ic; 632 633 DWTAP_PRINTF("%s\n", __func__); 634 635 sc->up = 0; 636 STAILQ_INIT(&sc->sc_rxbuf); 637 sc->sc_tq = taskqueue_create("wtap_taskq", M_NOWAIT | M_ZERO, 638 taskqueue_thread_enqueue, &sc->sc_tq); 639 taskqueue_start_threads(&sc->sc_tq, 1, PI_SOFT, "%s taskQ", sc->name); 640 TASK_INIT(&sc->sc_rxtask, 0, wtap_rx_proc, sc); 641 642 ic->ic_softc = sc; 643 ic->ic_name = sc->name; 644 ic->ic_phytype = IEEE80211_T_DS; 645 ic->ic_opmode = IEEE80211_M_MBSS; 646 ic->ic_caps = IEEE80211_C_MBSS; 647 648 ic->ic_max_keyix = 128; /* A value read from Atheros ATH_KEYMAX */ 649 650 ic->ic_regdomain.regdomain = SKU_ETSI; 651 ic->ic_regdomain.country = CTRY_SWEDEN; 652 ic->ic_regdomain.location = 1; /* Indoors */ 653 ic->ic_regdomain.isocc[0] = 'S'; 654 ic->ic_regdomain.isocc[1] = 'E'; 655 656 ic->ic_nchans = 1; 657 ic->ic_channels[0].ic_flags = IEEE80211_CHAN_B; 658 ic->ic_channels[0].ic_freq = 2412; 659 660 IEEE80211_ADDR_COPY(ic->ic_macaddr, macaddr); 661 ieee80211_ifattach(ic); 662 663 /* override default methods */ 664 ic->ic_newassoc = wtap_newassoc; 665 ic->ic_wme.wme_update = wtap_wme_update; 666 ic->ic_vap_create = wtap_vap_create; 667 ic->ic_vap_delete = wtap_vap_delete; 668 ic->ic_raw_xmit = wtap_raw_xmit; 669 ic->ic_update_mcast = wtap_update_mcast; 670 ic->ic_update_promisc = wtap_update_promisc; 671 ic->ic_transmit = wtap_transmit; 672 ic->ic_parent = wtap_parent; 673 674 sc->sc_node_alloc = ic->ic_node_alloc; 675 ic->ic_node_alloc = wtap_node_alloc; 676 sc->sc_node_free = ic->ic_node_free; 677 ic->ic_node_free = wtap_node_free; 678 679 ic->ic_scan_start = wtap_scan_start; 680 ic->ic_scan_end = wtap_scan_end; 681 ic->ic_set_channel = wtap_set_channel; 682 683 ieee80211_radiotap_attach(ic, 684 &sc->sc_tx_th.wt_ihdr, sizeof(sc->sc_tx_th), 685 WTAP_TX_RADIOTAP_PRESENT, 686 &sc->sc_rx_th.wr_ihdr, sizeof(sc->sc_rx_th), 687 WTAP_RX_RADIOTAP_PRESENT); 688 689 /* Work here, we must find a way to populate the rate table */ 690 #if 0 691 if(ic->ic_rt == NULL){ 692 printf("no table for ic_curchan\n"); 693 ic->ic_rt = ieee80211_get_ratetable(&ic->ic_channels[0]); 694 } 695 printf("ic->ic_rt =%p\n", ic->ic_rt); 696 printf("rate count %d\n", ic->ic_rt->rateCount); 697 698 uint8_t code = ic->ic_rt->info[0].dot11Rate; 699 uint8_t cix = ic->ic_rt->info[0].ctlRateIndex; 700 uint8_t ctl_rate = ic->ic_rt->info[cix].dot11Rate; 701 printf("code=%d, cix=%d, ctl_rate=%d\n", code, cix, ctl_rate); 702 703 uint8_t rix0 = ic->ic_rt->rateCodeToIndex[130]; 704 uint8_t rix1 = ic->ic_rt->rateCodeToIndex[132]; 705 uint8_t rix2 = ic->ic_rt->rateCodeToIndex[139]; 706 uint8_t rix3 = ic->ic_rt->rateCodeToIndex[150]; 707 printf("rix0 %u,rix1 %u,rix2 %u,rix3 %u\n", rix0,rix1,rix2,rix3); 708 printf("lpAckDuration=%u\n", ic->ic_rt->info[0].lpAckDuration); 709 printf("rate=%d\n", ic->ic_rt->info[0].rateKbps); 710 #endif 711 return 0; 712 } 713 714 int32_t 715 wtap_detach(struct wtap_softc *sc) 716 { 717 struct ieee80211com *ic = &sc->sc_ic; 718 719 DWTAP_PRINTF("%s\n", __func__); 720 ieee80211_ageq_drain(&ic->ic_stageq); 721 ieee80211_ifdetach(ic); 722 return 0; 723 } 724 725 void 726 wtap_resume(struct wtap_softc *sc) 727 { 728 729 DWTAP_PRINTF("%s\n", __func__); 730 } 731 732 void 733 wtap_suspend(struct wtap_softc *sc) 734 { 735 736 DWTAP_PRINTF("%s\n", __func__); 737 } 738 739 void 740 wtap_shutdown(struct wtap_softc *sc) 741 { 742 743 DWTAP_PRINTF("%s\n", __func__); 744 } 745 746 void 747 wtap_intr(struct wtap_softc *sc) 748 { 749 750 DWTAP_PRINTF("%s\n", __func__); 751 } 752