1 /*-
2  * SPDX-License-Identifier: BSD-4-Clause
3  *
4  * Copyright (c) 2002
5  *	M Warner Losh <imp@freebsd.org>.  All rights reserved.
6  * Copyright (c) 1997, 1998, 1999
7  *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed by Bill Paul.
20  * 4. Neither the name of the author nor the names of any co-contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34  * THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $FreeBSD: stable/12/sys/dev/wi/if_wivar.h 325966 2017-11-18 14:26:50Z pfg $
37  */
38 
39 /*
40  * Encryption controls. We can enable or disable encryption as
41  * well as specify up to 4 encryption keys. We can also specify
42  * which of the four keys will be used for transmit encryption.
43  */
44 #define WI_RID_ENCRYPTION	0xFC20
45 #define WI_RID_AUTHTYPE		0xFC21
46 #define WI_RID_DEFLT_CRYPT_KEYS	0xFCB0
47 #define WI_RID_TX_CRYPT_KEY	0xFCB1
48 #define WI_RID_WEP_AVAIL	0xFD4F
49 #define WI_RID_P2_TX_CRYPT_KEY	0xFC23
50 #define WI_RID_P2_CRYPT_KEY0	0xFC24
51 #define WI_RID_P2_CRYPT_KEY1	0xFC25
52 #define WI_RID_MICROWAVE_OVEN	0xFC25
53 #define WI_RID_P2_CRYPT_KEY2	0xFC26
54 #define WI_RID_P2_CRYPT_KEY3	0xFC27
55 #define WI_RID_P2_ENCRYPTION	0xFC28
56 #define WI_RID_ROAMING_MODE	0xFC2D
57 #define WI_RID_CUR_TX_RATE	0xFD44 /* current TX rate */
58 
59 #define	WI_MAX_AID		256	/* max stations for ap operation */
60 
61 struct wi_vap {
62 	struct ieee80211vap	wv_vap;
63 
64 	void		(*wv_recv_mgmt)(struct ieee80211_node *, struct mbuf *,
65 			    int, const struct ieee80211_rx_stats *rxs, int, int);
66 	int		(*wv_newstate)(struct ieee80211vap *,
67 			    enum ieee80211_state, int);
68 };
69 #define	WI_VAP(vap)		((struct wi_vap *)(vap))
70 
71 struct wi_softc	{
72 	struct ieee80211com	sc_ic;
73 	struct mbufq		sc_snd;
74 	device_t		sc_dev;
75 	struct mtx		sc_mtx;
76 	struct callout		sc_watchdog;
77 	int			sc_unit;
78 	int			wi_gone;
79 	int			sc_enabled;
80 	int			sc_reset;
81 	int			sc_firmware_type;
82 #define WI_NOTYPE	0
83 #define	WI_LUCENT	1
84 #define	WI_INTERSIL	2
85 #define	WI_SYMBOL	3
86 	int			sc_pri_firmware_ver;	/* Primary firmware */
87 	int			sc_sta_firmware_ver;	/* Station firmware */
88 	unsigned int		sc_nic_id;		/* Type of NIC */
89 	char *			sc_nic_name;
90 
91 	int			wi_bus_type;	/* Bus attachment type */
92 	struct resource *	local;
93 	int			local_rid;
94 	struct resource *	iobase;
95 	int			iobase_rid;
96 	struct resource *	irq;
97 	int			irq_rid;
98 	struct resource *	mem;
99 	int			mem_rid;
100 	bus_space_handle_t	wi_localhandle;
101 	bus_space_tag_t		wi_localtag;
102 	bus_space_handle_t	wi_bhandle;
103 	bus_space_tag_t		wi_btag;
104 	bus_space_handle_t	wi_bmemhandle;
105 	bus_space_tag_t		wi_bmemtag;
106 	void *			wi_intrhand;
107 	struct ieee80211_channel *wi_channel;
108 	int			wi_io_addr;
109 	int			wi_cmd_count;
110 
111 	int			sc_flags;
112 	int			sc_bap_id;
113 	int			sc_bap_off;
114 
115 	int			sc_porttype;
116 	u_int16_t		sc_portnum;
117 	u_int16_t		sc_encryption;
118 	u_int16_t		sc_monitor_port;
119 	u_int16_t		sc_chanmask;
120 
121 	/* RSSI interpretation */
122 	u_int16_t		sc_min_rssi;	/* clamp sc_min_rssi < RSSI */
123 	u_int16_t		sc_max_rssi;	/* clamp RSSI < sc_max_rssi */
124 	u_int16_t		sc_dbm_offset;	/* dBm ~ RSSI - sc_dbm_offset */
125 
126 	int			sc_buflen;		/* TX buffer size */
127 	int			sc_ntxbuf;
128 #define	WI_NTXBUF	3
129 	struct {
130 		int		d_fid;
131 		int		d_len;
132 	}			sc_txd[WI_NTXBUF];	/* TX buffers */
133 	int			sc_txnext;		/* index of next TX */
134 	int			sc_txcur;		/* index of current TX*/
135 	int			sc_tx_timer;
136 
137 	struct wi_counters	sc_stats;
138 	u_int16_t		sc_ibss_port;
139 
140 	struct timeval		sc_last_syn;
141 	int			sc_false_syns;
142 
143 	u_int16_t		sc_txbuf[IEEE80211_MAX_LEN/2];
144 
145 	struct wi_tx_radiotap_header sc_tx_th;
146 	struct wi_rx_radiotap_header sc_rx_th;
147 };
148 
149 /* maximum consecutive false change-of-BSSID indications */
150 #define	WI_MAX_FALSE_SYNS		10
151 
152 #define	WI_FLAGS_HAS_ENHSECURITY	0x0001
153 #define	WI_FLAGS_HAS_WPASUPPORT		0x0002
154 #define	WI_FLAGS_HAS_ROAMING		0x0020
155 #define	WI_FLAGS_HAS_FRAGTHR		0x0200
156 #define	WI_FLAGS_HAS_DBMADJUST		0x0400
157 #define	WI_FLAGS_RUNNING		0x0800
158 #define	WI_FLAGS_PROMISC		0x1000
159 
160 struct wi_card_ident {
161 	u_int16_t	card_id;
162 	char		*card_name;
163 	u_int8_t	firm_type;
164 };
165 
166 #define	WI_PRISM_MIN_RSSI	0x1b
167 #define	WI_PRISM_MAX_RSSI	0x9a
168 #define	WI_PRISM_DBM_OFFSET	100 /* XXX */
169 
170 #define	WI_LUCENT_MIN_RSSI	47
171 #define	WI_LUCENT_MAX_RSSI	138
172 #define	WI_LUCENT_DBM_OFFSET	149
173 
174 #define	WI_RSSI_TO_DBM(sc, rssi) (MIN((sc)->sc_max_rssi, \
175     MAX((sc)->sc_min_rssi, (rssi))) - (sc)->sc_dbm_offset)
176 
177 #define	WI_LOCK(_sc) 		mtx_lock(&(_sc)->sc_mtx)
178 #define	WI_UNLOCK(_sc)		mtx_unlock(&(_sc)->sc_mtx)
179 #define	WI_LOCK_ASSERT(_sc)	mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
180 
181 int	wi_attach(device_t);
182 int	wi_detach(device_t);
183 int	wi_shutdown(device_t);
184 int	wi_alloc(device_t, int);
185 void	wi_free(device_t);
186 extern devclass_t wi_devclass;
187 void	wi_intr(void *);
188 int	wi_mgmt_xmit(struct wi_softc *, caddr_t, int);
189 void	wi_stop(struct wi_softc *, int);
190 void	wi_init(struct wi_softc *);
191