xref: /freebsd/sys/dev/wtap/if_wtapvar.h (revision 568f01f6c3e51ef4b24abe532237081a35e585f6)
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  * 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  *    without modification.
13  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
15  *    redistribution must be conditioned upon including a substantially
16  *    similar Disclaimer requirement for further binary redistribution.
17  *
18  * NO WARRANTY
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
22  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
24  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29  * THE POSSIBILITY OF SUCH DAMAGES.
30  *
31  * $FreeBSD$
32  */
33 
34 #ifndef _DEV_WTAP_WTAPVAR_H
35 #define _DEV_WTAP_WTAPVAR_H
36 
37 #include <sys/param.h>
38 #include <sys/conf.h>
39 #include <sys/module.h>
40 #include <sys/kernel.h>
41 #include <sys/systm.h>
42 #include <sys/sysctl.h>
43 #include <sys/mbuf.h>
44 #include <sys/malloc.h>
45 #include <sys/lock.h>
46 #include <sys/mutex.h>
47 
48 #include <sys/sockio.h>
49 #include <sys/socket.h>
50 #include <sys/socketvar.h>
51 #include <sys/errno.h>
52 #include <sys/callout.h>
53 #include <sys/endian.h>
54 #include <sys/kthread.h>
55 #include <sys/taskqueue.h>
56 #include <sys/priv.h>
57 #include <sys/sysctl.h>
58 
59 #include <machine/bus.h>
60 
61 #include <net/if.h>
62 #include <net/if_dl.h>
63 #include <net/if_media.h>
64 #include <net/if_types.h>
65 #include <net/if_arp.h>
66 #include <net/ethernet.h>
67 #include <net/if_llc.h>
68 
69 #include <net80211/ieee80211_var.h>
70 #include <net80211/ieee80211_regdomain.h>
71 
72 #include <net/bpf.h>
73 
74 #include <net/vnet.h>
75 
76 #include <netinet/in.h>
77 #include <netinet/if_ether.h>
78 
79 #if 0
80 #define DWTAP_PRINTF(...) printf(__VA_ARGS__)
81 #else
82 #define DWTAP_PRINTF(...)
83 #endif
84 
85 #include "if_wtapioctl.h"
86 
87 #define MAX_NBR_WTAP (64)
88 #define BEACON_INTRERVAL (1000)
89 
90 MALLOC_DECLARE(M_WTAP);
91 MALLOC_DECLARE(M_WTAP_PACKET);
92 MALLOC_DECLARE(M_WTAP_BEACON);
93 MALLOC_DECLARE(M_WTAP_RXBUF);
94 MALLOC_DECLARE(M_WTAP_PLUGIN);
95 
96 /* driver-specific node state */
97 struct wtap_node {
98 	struct ieee80211_node an_node;	/* base class */
99 	/* future addons */
100 };
101 #define	WTAP_NODE(ni)	((struct ath_node *)(ni))
102 #define	WTAP_NODE_CONST(ni)	((const struct ath_node *)(ni))
103 
104 struct wtap_buf {
105 	STAILQ_ENTRY(wtap_buf)	bf_list;
106 	struct mbuf		*m;	/* mbuf for buf */
107 };
108 typedef STAILQ_HEAD(, wtap_buf) wtap_bufhead;
109 
110 #define	WTAP_BUF_BUSY 0x00000002	/* (tx) desc owned by h/w */
111 
112 struct wtap_vap {
113 	struct ieee80211vap av_vap;		/* base class */
114 	int32_t			id;		/* wtap id */
115 	struct cdev 		*av_dev;	/* userspace injecting frames */
116 	struct wtap_medium	*av_md;		/* back pointer */
117 	struct mbuf *beacon;			/* beacon */
118 	struct ieee80211_node	*bf_node;	/* pointer to the node */
119 	struct callout		av_swba;	/* software beacon alert */
120 	uint32_t		av_bcinterval;	/* beacon interval */
121 	void (*av_recv_mgmt)(struct ieee80211_node *,
122 	    struct mbuf *, int, const struct ieee80211_rx_stats *, int, int);
123 	int (*av_newstate)(struct ieee80211vap *,
124 	    enum ieee80211_state, int);
125 	void (*av_bmiss)(struct ieee80211vap *);
126 };
127 #define	WTAP_VAP(vap)	((struct wtap_vap *)(vap))
128 
129 struct taskqueue;
130 
131 struct wtap_softc {
132 	struct ieee80211com	sc_ic;
133 	char 			name[7];	/* wtapXX\0 */
134 	int32_t			id;
135 	int32_t			up;
136 	struct wtap_medium	*sc_md;		/* interface medium */
137 	struct ieee80211_node*	(* sc_node_alloc)
138 	    (struct ieee80211vap *, const uint8_t [IEEE80211_ADDR_LEN]);
139 	void (*sc_node_free)(struct ieee80211_node *);
140 	struct mtx		sc_mtx;		/* master lock (recursive) */
141 	struct taskqueue	*sc_tq;		/* private task queue */
142 	wtap_bufhead		sc_rxbuf;	/* receive buffer */
143 	struct task		sc_rxtask;	/* rx int processing */
144 	struct wtap_tx_radiotap_header sc_tx_th;
145 	int			sc_tx_th_len;
146 	struct wtap_rx_radiotap_header sc_rx_th;
147 	int			sc_rx_th_len;
148 };
149 
150 int32_t	wtap_attach(struct wtap_softc *, const uint8_t *macaddr);
151 int32_t	wtap_detach(struct wtap_softc *);
152 void	wtap_resume(struct wtap_softc *);
153 void	wtap_suspend(struct wtap_softc *);
154 void	wtap_shutdown(struct wtap_softc *);
155 void	wtap_intr(struct wtap_softc *);
156 void	wtap_inject(struct wtap_softc *, struct mbuf *);
157 
158 #endif
159