xref: /freebsd/sys/dev/wtap/if_wtapvar.h (revision fb1749cc6468220a69a8fdc7a2d0aac51ada598a)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
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 
32 #ifndef _DEV_WTAP_WTAPVAR_H
33 #define _DEV_WTAP_WTAPVAR_H
34 
35 #include <sys/param.h>
36 #include <sys/conf.h>
37 #include <sys/malloc.h>
38 
39 #include <sys/sockio.h>
40 #include <sys/socket.h>
41 
42 #include <net/if.h>
43 #include <net/if_media.h>
44 #include <net/ethernet.h>
45 
46 #include <net80211/ieee80211_var.h>
47 #include <net80211/ieee80211_regdomain.h>
48 
49 #if 0
50 #define DWTAP_PRINTF(...) printf(__VA_ARGS__)
51 #else
52 #define DWTAP_PRINTF(...)
53 #endif
54 
55 #include "if_wtapioctl.h"
56 
57 #define MAX_NBR_WTAP (64)
58 #define BEACON_INTRERVAL (1000)
59 
60 MALLOC_DECLARE(M_WTAP);
61 MALLOC_DECLARE(M_WTAP_PACKET);
62 MALLOC_DECLARE(M_WTAP_BEACON);
63 MALLOC_DECLARE(M_WTAP_RXBUF);
64 MALLOC_DECLARE(M_WTAP_PLUGIN);
65 
66 /* driver-specific node state */
67 struct wtap_node {
68 	struct ieee80211_node an_node;	/* base class */
69 	/* future addons */
70 };
71 #define	WTAP_NODE(ni)	((struct ath_node *)(ni))
72 #define	WTAP_NODE_CONST(ni)	((const struct ath_node *)(ni))
73 
74 struct wtap_buf {
75 	STAILQ_ENTRY(wtap_buf)	bf_list;
76 	struct mbuf		*m;	/* mbuf for buf */
77 };
78 typedef STAILQ_HEAD(, wtap_buf) wtap_bufhead;
79 
80 #define	WTAP_BUF_BUSY 0x00000002	/* (tx) desc owned by h/w */
81 
82 struct wtap_vap {
83 	struct ieee80211vap av_vap;		/* base class */
84 	int32_t			id;		/* wtap id */
85 	struct cdev 		*av_dev;	/* userspace injecting frames */
86 	struct wtap_medium	*av_md;		/* back pointer */
87 	struct mbuf *beacon;			/* beacon */
88 	struct ieee80211_node	*bf_node;	/* pointer to the node */
89 	struct callout		av_swba;	/* software beacon alert */
90 	uint32_t		av_bcinterval;	/* beacon interval */
91 	void (*av_recv_mgmt)(struct ieee80211_node *,
92 	    struct mbuf *, int, const struct ieee80211_rx_stats *, int, int);
93 	int (*av_newstate)(struct ieee80211vap *,
94 	    enum ieee80211_state, int);
95 	void (*av_bmiss)(struct ieee80211vap *);
96 };
97 #define	WTAP_VAP(vap)	((struct wtap_vap *)(vap))
98 
99 struct taskqueue;
100 
101 struct wtap_softc {
102 	struct ieee80211com	sc_ic;
103 	char 			name[7];	/* wtapXX\0 */
104 	int32_t			id;
105 	int32_t			up;
106 	struct wtap_medium	*sc_md;		/* interface medium */
107 	struct wtap_hal		*hal;
108 	struct ieee80211_node*	(* sc_node_alloc)
109 	    (struct ieee80211vap *, const uint8_t [IEEE80211_ADDR_LEN]);
110 	void (*sc_node_free)(struct ieee80211_node *);
111 	struct mtx		sc_mtx;		/* master lock (recursive) */
112 	struct taskqueue	*sc_tq;		/* private task queue */
113 	wtap_bufhead		sc_rxbuf;	/* receive buffer */
114 	struct task		sc_rxtask;	/* rx int processing */
115 	struct wtap_tx_radiotap_header sc_tx_th;
116 	int			sc_tx_th_len;
117 	struct wtap_rx_radiotap_header sc_rx_th;
118 	int			sc_rx_th_len;
119 };
120 
121 int32_t	wtap_attach(struct wtap_softc *, const uint8_t *macaddr);
122 int32_t	wtap_detach(struct wtap_softc *);
123 void	wtap_resume(struct wtap_softc *);
124 void	wtap_suspend(struct wtap_softc *);
125 void	wtap_shutdown(struct wtap_softc *);
126 void	wtap_intr(struct wtap_softc *);
127 void	wtap_inject(struct wtap_softc *, struct mbuf *);
128 
129 #endif
130