wivar.h revision 1.67
1/*	$NetBSD: wivar.h,v 1.67 2019/10/05 23:27:20 mrg Exp $	*/
2
3/*
4 * Copyright (c) 1997, 1998, 1999
5 *	Bill Paul <wpaul@ctr.columbia.edu>.  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 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *	This product includes software developed by Bill Paul.
18 * 4. Neither the name of the author nor the names of any co-contributors
19 *    may be used to endorse or promote products derived from this software
20 *    without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * 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 IN
30 * 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 DAMAGE.
33 */
34
35#include <sys/mutex.h>
36#include <sys/condvar.h>
37#include <sys/lwp.h>
38
39/* Radio capture format for Prism. */
40
41#define WI_RX_RADIOTAP_PRESENT	((1 << IEEE80211_RADIOTAP_FLAGS) | \
42				 (1 << IEEE80211_RADIOTAP_RATE) | \
43				 (1 << IEEE80211_RADIOTAP_CHANNEL) | \
44				 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
45				 (1 << IEEE80211_RADIOTAP_DB_ANTNOISE))
46
47struct wi_rx_radiotap_header {
48	struct ieee80211_radiotap_header	wr_ihdr;
49	u_int8_t				wr_flags;
50	u_int8_t				wr_rate;
51	u_int16_t				wr_chan_freq;
52	u_int16_t				wr_chan_flags;
53	int8_t					wr_antsignal;
54	int8_t					wr_antnoise;
55};
56
57#define WI_TX_RADIOTAP_PRESENT	((1 << IEEE80211_RADIOTAP_FLAGS) | \
58				 (1 << IEEE80211_RADIOTAP_RATE) | \
59				 (1 << IEEE80211_RADIOTAP_CHANNEL))
60
61struct wi_tx_radiotap_header {
62	struct ieee80211_radiotap_header	wt_ihdr;
63	u_int8_t				wt_flags;
64	u_int8_t				wt_rate;
65	u_int16_t				wt_chan_freq;
66	u_int16_t				wt_chan_flags;
67};
68
69struct wi_rssdesc {
70	struct ieee80211_rssdesc	rd_desc;
71	SLIST_ENTRY(wi_rssdesc)		rd_next;
72};
73
74typedef SLIST_HEAD(,wi_rssdesc) wi_rssdescq_t;
75
76/*
77 * FreeBSD driver ported to NetBSD by Bill Sommerfeld in the back of the
78 * Oslo IETF plenary meeting.
79 */
80struct wi_softc	{
81	device_t		sc_dev;
82	struct ethercom		sc_ec;
83	struct ieee80211com	sc_ic;
84	u_int32_t		sc_ic_flags;	/* backup of ic->ic_flags */
85	void			*sc_ih;		/* interrupt handler */
86	void			*sc_soft_ih;
87	int			(*sc_enable)(device_t, int);
88	void			(*sc_reset)(struct wi_softc *);
89
90	int			(*sc_newstate)(struct ieee80211com *,
91				    enum ieee80211_state, int);
92	void			(*sc_set_tim)(struct ieee80211_node *, int);
93
94	int			sc_attached;
95	int			sc_enabled;
96	int			sc_invalid;
97	int			sc_firmware_type;
98#define	WI_NOTYPE	0
99#define	WI_LUCENT	1
100#define	WI_INTERSIL	2
101#define	WI_SYMBOL	3
102	int			sc_pri_firmware_ver;	/* Primary firm vers */
103	int			sc_sta_firmware_ver;	/* Station firm vers */
104	int			sc_pci;			/* attach to PCI-Bus */
105
106	bus_space_tag_t		sc_iot;			/* bus cookie */
107	bus_space_handle_t	sc_ioh;			/* bus i/o handle */
108
109	struct bpf_if *		sc_drvbpf;
110	int			sc_flags;
111	int			sc_bap_id;
112	int			sc_bap_off;
113
114	u_int16_t		sc_portnum;
115
116	/* RSSI interpretation */
117	u_int16_t		sc_dbm_offset;	/* dBm ~ RSSI - sc_dbm_offset */
118	u_int16_t		sc_max_datalen;
119	u_int16_t		sc_frag_thresh;
120	u_int16_t		sc_rts_thresh;
121	u_int16_t		sc_system_scale;
122	u_int16_t		sc_tx_rate;
123	u_int16_t		sc_cnfauthmode;
124	u_int16_t		sc_roaming_mode;
125	u_int16_t		sc_microwave_oven;
126
127	int			sc_nodelen;
128	char			sc_nodename[IEEE80211_NWID_LEN];
129
130	int			sc_buflen;
131#define	WI_NTXBUF	3
132#define	WI_NTXRSS	10
133	struct {
134		int				d_fid;
135	}			sc_txd[WI_NTXBUF];
136	int			sc_txalloc;	/* next FID to allocate */
137	int			sc_txalloced;	/* FIDs currently allocated */
138	int			sc_txqueue;	/* next FID to queue */
139	int			sc_txqueued;	/* FIDs currently queued */
140	int			sc_txstart;	/* next FID to start */
141	int			sc_txstarted;	/* FIDs currently started */
142	int			sc_txcmds;
143
144	int			sc_status;
145
146	struct wi_rssdesc 	sc_rssd[WI_NTXRSS];
147	wi_rssdescq_t		sc_rssdfree;
148	int			sc_tx_timer;
149	int			sc_scan_timer;
150	int			sc_syn_timer;
151
152	struct wi_counters	sc_stats;
153	u_int16_t		sc_ibss_port;
154
155	struct wi_apinfo	sc_aps[MAXAPINFO];
156	int 			sc_naps;
157
158	struct timeval		sc_last_syn;
159	int			sc_false_syns;
160	int			sc_alt_retry;
161
162	union {
163		struct wi_rx_radiotap_header	tap;
164		u_int8_t			pad[64];
165	} sc_rxtapu;
166	union {
167		struct wi_tx_radiotap_header	tap;
168		u_int8_t			pad[64];
169	} sc_txtapu;
170	u_int16_t		sc_txbuf[IEEE80211_MAX_LEN/2];
171	/* number of transmissions pending at each data rate */
172	u_int8_t		sc_txpending[IEEE80211_RATE_MAXSIZE];
173	struct callout		sc_rssadapt_ch;
174	kmutex_t		sc_ioctl_mtx;
175	kcondvar_t		sc_ioctl_cv;
176	bool			sc_ioctl_gone;
177	unsigned int		sc_ioctl_nwait;
178	unsigned int		sc_ioctl_depth;
179	lwp_t			*sc_ioctl_lwp;
180};
181
182#define	sc_if		sc_ec.ec_if
183#define sc_rxtap	sc_rxtapu.tap
184#define sc_txtap	sc_txtapu.tap
185
186struct wi_node {
187	struct ieee80211_node		wn_node;
188	struct ieee80211_rssadapt	wn_rssadapt;
189};
190
191/* maximum false change-of-BSSID indications per second */
192#define	WI_MAX_FALSE_SYNS		10
193
194#define	WI_PRISM_DBM_OFFSET	100	/* XXX */
195
196#define	WI_LUCENT_DBM_OFFSET	149
197
198#define	WI_SCAN_INQWAIT			3	/* wait sec before inquire */
199#define	WI_SCAN_WAIT			5	/* maximum scan wait */
200
201/* Values for wi_flags. */
202#define	WI_FLAGS_ATTACHED		0x0001
203#define	WI_FLAGS_INITIALIZED		0x0002
204#define	WI_FLAGS_OUTRANGE		0x0004
205#define	WI_FLAGS_RSSADAPTSTA		0x0008
206#define	WI_FLAGS_HAS_MOR		0x0010
207#define	WI_FLAGS_HAS_ROAMING		0x0020
208#define	WI_FLAGS_HAS_DIVERSITY		0x0040
209#define	WI_FLAGS_HAS_SYSSCALE		0x0080
210#define	WI_FLAGS_BUG_AUTOINC		0x0100
211#define	WI_FLAGS_HAS_FRAGTHR		0x0200
212#define	WI_FLAGS_HAS_DBMADJUST		0x0400
213#define	WI_FLAGS_WEP_VALID		0x0800
214
215struct wi_card_ident {
216	u_int16_t	card_id;
217	const char	*card_name;
218	u_int8_t	firm_type;
219};
220
221/*
222 * register space access macros
223 */
224#ifdef WI_AT_BIGENDIAN_BUS_HACK
225	/*
226	 * XXX - ugly hack for sparc bus_space_* macro deficiencies:
227	 *       assume the bus we are accessing is big endian.
228	 */
229
230#define CSR_WRITE_4(sc, reg, val)	\
231	bus_space_write_4(sc->sc_iot, sc->sc_ioh,	\
232			(sc->sc_pci? reg * 2: reg) , htole32(val))
233#define CSR_WRITE_2(sc, reg, val)	\
234	bus_space_write_2(sc->sc_iot, sc->sc_ioh,	\
235			(sc->sc_pci? reg * 2: reg), htole16(val))
236#define CSR_WRITE_1(sc, reg, val)	\
237	bus_space_write_1(sc->sc_iot, sc->sc_ioh,	\
238			(sc->sc_pci? reg * 2: reg), val)
239
240#define CSR_READ_4(sc, reg)		\
241	le32toh(bus_space_read_4(sc->sc_iot, sc->sc_ioh,	\
242			(sc->sc_pci? reg * 2: reg)))
243#define CSR_READ_2(sc, reg)		\
244	le16toh(bus_space_read_2(sc->sc_iot, sc->sc_ioh,	\
245			(sc->sc_pci? reg * 2: reg)))
246#define CSR_READ_1(sc, reg)		\
247	bus_space_read_1(sc->sc_iot, sc->sc_ioh,	\
248			(sc->sc_pci? reg * 2: reg))
249
250#else
251
252#define CSR_WRITE_4(sc, reg, val)	\
253	bus_space_write_4(sc->sc_iot, sc->sc_ioh,	\
254			(sc->sc_pci? reg * 2: reg) , val)
255#define CSR_WRITE_2(sc, reg, val)	\
256	bus_space_write_2(sc->sc_iot, sc->sc_ioh,	\
257			(sc->sc_pci? reg * 2: reg), val)
258#define CSR_WRITE_1(sc, reg, val)	\
259	bus_space_write_1(sc->sc_iot, sc->sc_ioh,	\
260			(sc->sc_pci? reg * 2: reg), val)
261
262#define CSR_READ_4(sc, reg)		\
263	bus_space_read_4(sc->sc_iot, sc->sc_ioh,	\
264			(sc->sc_pci? reg * 2: reg))
265#define CSR_READ_2(sc, reg)		\
266	bus_space_read_2(sc->sc_iot, sc->sc_ioh,	\
267			(sc->sc_pci? reg * 2: reg))
268#define CSR_READ_1(sc, reg)		\
269	bus_space_read_1(sc->sc_iot, sc->sc_ioh,	\
270			(sc->sc_pci? reg * 2: reg))
271#endif
272
273#ifndef __BUS_SPACE_HAS_STREAM_METHODS
274#define bus_space_write_stream_2	bus_space_write_2
275#define bus_space_write_multi_stream_2	bus_space_write_multi_2
276#define bus_space_read_stream_2		bus_space_read_2
277#define bus_space_read_multi_stream_2		bus_space_read_multi_2
278#endif
279
280#define CSR_WRITE_STREAM_2(sc, reg, val)	\
281	bus_space_write_stream_2(sc->sc_iot, sc->sc_ioh,	\
282			(sc->sc_pci? reg * 2: reg), val)
283#define CSR_WRITE_MULTI_STREAM_2(sc, reg, val, count)	\
284	bus_space_write_multi_stream_2(sc->sc_iot, sc->sc_ioh,	\
285			(sc->sc_pci? reg * 2: reg), val, count)
286#define CSR_READ_STREAM_2(sc, reg)		\
287	bus_space_read_stream_2(sc->sc_iot, sc->sc_ioh,	\
288			(sc->sc_pci? reg * 2: reg))
289#define CSR_READ_MULTI_STREAM_2(sc, reg, buf, count)		\
290	bus_space_read_multi_stream_2(sc->sc_iot, sc->sc_ioh,	\
291			(sc->sc_pci? reg * 2: reg), buf, count)
292
293
294int	wi_attach(struct wi_softc *, const u_int8_t *);
295int	wi_detach(struct wi_softc *);
296int	wi_activate(device_t, enum devact);
297int	wi_intr(void *arg);
298