xref: /freebsd/sys/dev/wtap/if_wtap.c (revision e17f5b1d)
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 static void
452 wtap_rx_proc(void *arg, int npending)
453 {
454 	struct epoch_tracker et;
455 	struct wtap_softc *sc = (struct wtap_softc *)arg;
456 	struct ieee80211com *ic = &sc->sc_ic;
457 	struct mbuf *m;
458 	struct ieee80211_node *ni;
459 	int type;
460 	struct wtap_buf *bf;
461 
462 #if 0
463 	DWTAP_PRINTF("%s\n", __func__);
464 #endif
465 
466 	for(;;) {
467 		mtx_lock(&sc->sc_mtx);
468 		bf = STAILQ_FIRST(&sc->sc_rxbuf);
469 		if (bf == NULL) {
470 			mtx_unlock(&sc->sc_mtx);
471 			return;
472 		}
473 		STAILQ_REMOVE_HEAD(&sc->sc_rxbuf, bf_list);
474 		mtx_unlock(&sc->sc_mtx);
475 		KASSERT(bf != NULL, ("wtap_buf is NULL\n"));
476 		m = bf->m;
477 		DWTAP_PRINTF("[%d] receiving m=%p\n", sc->id, bf->m);
478 		if (m == NULL) {		/* NB: shouldn't happen */
479 			ic_printf(ic, "%s: no mbuf!\n", __func__);
480 			free(bf, M_WTAP_RXBUF);
481 			return;
482 		}
483 #if 0
484 		ieee80211_dump_pkt(ic, mtod(m, caddr_t), 0,0,0);
485 #endif
486 
487 		/*
488 		 * Locate the node for sender, track state, and then
489 		 * pass the (referenced) node up to the 802.11 layer
490 		 * for its use.
491 		 */
492 		ni = ieee80211_find_rxnode_withkey(ic,
493 		    mtod(m, const struct ieee80211_frame_min *),
494 		    IEEE80211_KEYIX_NONE);
495 		NET_EPOCH_ENTER(et);
496 		if (ni != NULL) {
497 			/*
498 			 * Sending station is known, dispatch directly.
499 			 */
500 			type = ieee80211_input(ni, m, 1<<7, 10);
501 			ieee80211_free_node(ni);
502 		} else {
503 			type = ieee80211_input_all(ic, m, 1<<7, 10);
504 		}
505 		NET_EPOCH_EXIT(et);
506 
507 		/* The mbufs are freed by the Net80211 stack */
508 		free(bf, M_WTAP_RXBUF);
509 	}
510 }
511 
512 static void
513 wtap_newassoc(struct ieee80211_node *ni, int isnew)
514 {
515 
516 	DWTAP_PRINTF("%s\n", __func__);
517 }
518 
519 /*
520  * Callback from the 802.11 layer to update WME parameters.
521  */
522 static int
523 wtap_wme_update(struct ieee80211com *ic)
524 {
525 
526 	DWTAP_PRINTF("%s\n", __func__);
527 	return 0;
528 }
529 
530 static void
531 wtap_update_mcast(struct ieee80211com *ic)
532 {
533 
534 	DWTAP_PRINTF("%s\n", __func__);
535 }
536 
537 static void
538 wtap_update_promisc(struct ieee80211com *ic)
539 {
540 
541 	DWTAP_PRINTF("%s\n", __func__);
542 }
543 
544 static int
545 wtap_transmit(struct ieee80211com *ic, struct mbuf *m)
546 {
547 	struct ieee80211_node *ni =
548 	    (struct ieee80211_node *) m->m_pkthdr.rcvif;
549 	struct ieee80211vap *vap = ni->ni_vap;
550 	struct wtap_vap *avp = WTAP_VAP(vap);
551 
552 	if(ni == NULL){
553 		printf("m->m_pkthdr.rcvif is NULL we cant radiotap_tx\n");
554 	}else{
555 		if (ieee80211_radiotap_active_vap(vap))
556 			ieee80211_radiotap_tx(vap, m);
557 	}
558 	if (m->m_flags & M_TXCB)
559 		ieee80211_process_callback(ni, m, 0);
560 	ieee80211_free_node(ni);
561 	return wtap_medium_enqueue(avp, m);
562 }
563 
564 static struct ieee80211_node *
565 wtap_node_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN])
566 {
567 	struct ieee80211_node *ni;
568 
569 	DWTAP_PRINTF("%s\n", __func__);
570 
571 	ni = malloc(sizeof(struct ieee80211_node), M_80211_NODE,
572 	    M_NOWAIT|M_ZERO);
573 	if (ni == NULL)
574 		return (NULL);
575 
576 	ni->ni_txrate = 130;
577 	return ni;
578 }
579 
580 static void
581 wtap_node_free(struct ieee80211_node *ni)
582 {
583 	struct ieee80211com *ic = ni->ni_ic;
584 	struct wtap_softc *sc = ic->ic_softc;
585 
586 	DWTAP_PRINTF("%s\n", __func__);
587 	sc->sc_node_free(ni);
588 }
589 
590 int32_t
591 wtap_attach(struct wtap_softc *sc, const uint8_t *macaddr)
592 {
593 	struct ieee80211com *ic = &sc->sc_ic;
594 
595 	DWTAP_PRINTF("%s\n", __func__);
596 
597 	sc->up = 0;
598 	STAILQ_INIT(&sc->sc_rxbuf);
599 	sc->sc_tq = taskqueue_create("wtap_taskq", M_NOWAIT | M_ZERO,
600 	    taskqueue_thread_enqueue, &sc->sc_tq);
601 	taskqueue_start_threads(&sc->sc_tq, 1, PI_SOFT, "%s taskQ", sc->name);
602 	NET_TASK_INIT(&sc->sc_rxtask, 0, wtap_rx_proc, sc);
603 
604 	ic->ic_softc = sc;
605 	ic->ic_name = sc->name;
606 	ic->ic_phytype = IEEE80211_T_DS;
607 	ic->ic_opmode = IEEE80211_M_MBSS;
608 	ic->ic_caps = IEEE80211_C_MBSS;
609 
610 	ic->ic_max_keyix = 128; /* A value read from Atheros ATH_KEYMAX */
611 
612 	ic->ic_regdomain.regdomain = SKU_ETSI;
613 	ic->ic_regdomain.country = CTRY_SWEDEN;
614 	ic->ic_regdomain.location = 1; /* Indoors */
615 	ic->ic_regdomain.isocc[0] = 'S';
616 	ic->ic_regdomain.isocc[1] = 'E';
617 
618 	ic->ic_nchans = 1;
619 	ic->ic_channels[0].ic_flags = IEEE80211_CHAN_B;
620 	ic->ic_channels[0].ic_freq = 2412;
621 
622 	IEEE80211_ADDR_COPY(ic->ic_macaddr, macaddr);
623 	ieee80211_ifattach(ic);
624 
625 	/* override default methods */
626 	ic->ic_newassoc = wtap_newassoc;
627 	ic->ic_wme.wme_update = wtap_wme_update;
628 	ic->ic_vap_create = wtap_vap_create;
629 	ic->ic_vap_delete = wtap_vap_delete;
630 	ic->ic_raw_xmit = wtap_raw_xmit;
631 	ic->ic_update_mcast = wtap_update_mcast;
632 	ic->ic_update_promisc = wtap_update_promisc;
633 	ic->ic_transmit = wtap_transmit;
634 	ic->ic_parent = wtap_parent;
635 
636 	sc->sc_node_alloc = ic->ic_node_alloc;
637 	ic->ic_node_alloc = wtap_node_alloc;
638 	sc->sc_node_free = ic->ic_node_free;
639 	ic->ic_node_free = wtap_node_free;
640 
641 	ic->ic_scan_start = wtap_scan_start;
642 	ic->ic_scan_end = wtap_scan_end;
643 	ic->ic_set_channel = wtap_set_channel;
644 
645 	ieee80211_radiotap_attach(ic,
646 	    &sc->sc_tx_th.wt_ihdr, sizeof(sc->sc_tx_th),
647 	    WTAP_TX_RADIOTAP_PRESENT,
648 	    &sc->sc_rx_th.wr_ihdr, sizeof(sc->sc_rx_th),
649 	    WTAP_RX_RADIOTAP_PRESENT);
650 
651 	/* Work here, we must find a way to populate the rate table */
652 #if 0
653 	if(ic->ic_rt == NULL){
654 		printf("no table for ic_curchan\n");
655 		ic->ic_rt = ieee80211_get_ratetable(&ic->ic_channels[0]);
656 	}
657 	printf("ic->ic_rt =%p\n", ic->ic_rt);
658 	printf("rate count %d\n", ic->ic_rt->rateCount);
659 
660 	uint8_t code = ic->ic_rt->info[0].dot11Rate;
661 	uint8_t cix = ic->ic_rt->info[0].ctlRateIndex;
662 	uint8_t ctl_rate = ic->ic_rt->info[cix].dot11Rate;
663 	printf("code=%d, cix=%d, ctl_rate=%d\n", code, cix, ctl_rate);
664 
665 	uint8_t rix0 = ic->ic_rt->rateCodeToIndex[130];
666 	uint8_t rix1 = ic->ic_rt->rateCodeToIndex[132];
667 	uint8_t rix2 = ic->ic_rt->rateCodeToIndex[139];
668 	uint8_t rix3 = ic->ic_rt->rateCodeToIndex[150];
669 	printf("rix0 %u,rix1 %u,rix2 %u,rix3 %u\n", rix0,rix1,rix2,rix3);
670 	printf("lpAckDuration=%u\n", ic->ic_rt->info[0].lpAckDuration);
671 	printf("rate=%d\n", ic->ic_rt->info[0].rateKbps);
672 #endif
673 	return 0;
674 }
675 
676 int32_t
677 wtap_detach(struct wtap_softc *sc)
678 {
679 	struct ieee80211com *ic = &sc->sc_ic;
680 
681 	DWTAP_PRINTF("%s\n", __func__);
682 	ieee80211_ageq_drain(&ic->ic_stageq);
683 	ieee80211_ifdetach(ic);
684 	return 0;
685 }
686 
687 void
688 wtap_resume(struct wtap_softc *sc)
689 {
690 
691 	DWTAP_PRINTF("%s\n", __func__);
692 }
693 
694 void
695 wtap_suspend(struct wtap_softc *sc)
696 {
697 
698 	DWTAP_PRINTF("%s\n", __func__);
699 }
700 
701 void
702 wtap_shutdown(struct wtap_softc *sc)
703 {
704 
705 	DWTAP_PRINTF("%s\n", __func__);
706 }
707 
708 void
709 wtap_intr(struct wtap_softc *sc)
710 {
711 
712 	DWTAP_PRINTF("%s\n", __func__);
713 }
714