xref: /netbsd/sys/dev/ic/wivar.h (revision 6550d01e)
1 /*	$NetBSD: wivar.h,v 1.64 2010/11/23 04:33:09 christos 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 /* Radio capture format for Prism. */
36 
37 #define WI_RX_RADIOTAP_PRESENT	((1 << IEEE80211_RADIOTAP_FLAGS) | \
38 				 (1 << IEEE80211_RADIOTAP_RATE) | \
39 				 (1 << IEEE80211_RADIOTAP_CHANNEL) | \
40 				 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
41 				 (1 << IEEE80211_RADIOTAP_DB_ANTNOISE))
42 
43 struct wi_rx_radiotap_header {
44 	struct ieee80211_radiotap_header	wr_ihdr;
45 	u_int8_t				wr_flags;
46 	u_int8_t				wr_rate;
47 	u_int16_t				wr_chan_freq;
48 	u_int16_t				wr_chan_flags;
49 	int8_t					wr_antsignal;
50 	int8_t					wr_antnoise;
51 } __packed;
52 
53 #define WI_TX_RADIOTAP_PRESENT	((1 << IEEE80211_RADIOTAP_FLAGS) | \
54 				 (1 << IEEE80211_RADIOTAP_RATE) | \
55 				 (1 << IEEE80211_RADIOTAP_CHANNEL))
56 
57 struct wi_tx_radiotap_header {
58 	struct ieee80211_radiotap_header	wt_ihdr;
59 	u_int8_t				wt_flags;
60 	u_int8_t				wt_rate;
61 	u_int16_t				wt_chan_freq;
62 	u_int16_t				wt_chan_flags;
63 } __packed;
64 
65 struct wi_rssdesc {
66 	struct ieee80211_rssdesc	rd_desc;
67 	SLIST_ENTRY(wi_rssdesc)		rd_next;
68 };
69 
70 typedef SLIST_HEAD(,wi_rssdesc) wi_rssdescq_t;
71 
72 /*
73  * FreeBSD driver ported to NetBSD by Bill Sommerfeld in the back of the
74  * Oslo IETF plenary meeting.
75  */
76 struct wi_softc	{
77 	device_t		sc_dev;
78 	struct ethercom		sc_ec;
79 	struct ieee80211com	sc_ic;
80 	u_int32_t		sc_ic_flags;	/* backup of ic->ic_flags */
81 	void			*sc_ih;		/* interrupt handler */
82 	int			(*sc_enable)(device_t, int);
83 	void			(*sc_reset)(struct wi_softc *);
84 
85 	int			(*sc_newstate)(struct ieee80211com *,
86 				    enum ieee80211_state, int);
87 	void			(*sc_set_tim)(struct ieee80211_node *, int);
88 
89 	int			sc_attached;
90 	int			sc_enabled;
91 	int			sc_invalid;
92 	int			sc_firmware_type;
93 #define	WI_NOTYPE	0
94 #define	WI_LUCENT	1
95 #define	WI_INTERSIL	2
96 #define	WI_SYMBOL	3
97 	int			sc_pri_firmware_ver;	/* Primary firm vers */
98 	int			sc_sta_firmware_ver;	/* Station firm vers */
99 	int			sc_pci;			/* attach to PCI-Bus */
100 
101 	bus_space_tag_t		sc_iot;			/* bus cookie */
102 	bus_space_handle_t	sc_ioh;			/* bus i/o handle */
103 
104 	struct bpf_if *		sc_drvbpf;
105 	int			sc_flags;
106 	int			sc_bap_id;
107 	int			sc_bap_off;
108 
109 	u_int16_t		sc_portnum;
110 
111 	/* RSSI interpretation */
112 	u_int16_t		sc_dbm_offset;	/* dBm ~ RSSI - sc_dbm_offset */
113 	u_int16_t		sc_max_datalen;
114 	u_int16_t		sc_frag_thresh;
115 	u_int16_t		sc_rts_thresh;
116 	u_int16_t		sc_system_scale;
117 	u_int16_t		sc_tx_rate;
118 	u_int16_t		sc_cnfauthmode;
119 	u_int16_t		sc_roaming_mode;
120 	u_int16_t		sc_microwave_oven;
121 
122 	int			sc_nodelen;
123 	char			sc_nodename[IEEE80211_NWID_LEN];
124 
125 	int			sc_buflen;
126 #define	WI_NTXBUF	3
127 #define	WI_NTXRSS	10
128 	struct {
129 		int				d_fid;
130 	}			sc_txd[WI_NTXBUF];
131 	int			sc_txalloc;	/* next FID to allocate */
132 	int			sc_txalloced;	/* FIDs currently allocated */
133 	int			sc_txqueue;	/* next FID to queue */
134 	int			sc_txqueued;	/* FIDs currently queued */
135 	int			sc_txstart;	/* next FID to start */
136 	int			sc_txstarted;	/* FIDs currently started */
137 	int			sc_txcmds;
138 
139 	int			sc_status;
140 
141 	struct wi_rssdesc 	sc_rssd[WI_NTXRSS];
142 	wi_rssdescq_t		sc_rssdfree;
143 	int			sc_tx_timer;
144 	int			sc_scan_timer;
145 	int			sc_syn_timer;
146 
147 	struct wi_counters	sc_stats;
148 	u_int16_t		sc_ibss_port;
149 
150 	struct wi_apinfo	sc_aps[MAXAPINFO];
151 	int 			sc_naps;
152 
153 	struct timeval		sc_last_syn;
154 	int			sc_false_syns;
155 	int			sc_alt_retry;
156 
157 	union {
158 		struct wi_rx_radiotap_header	tap;
159 		u_int8_t			pad[64];
160 	} sc_rxtapu;
161 	union {
162 		struct wi_tx_radiotap_header	tap;
163 		u_int8_t			pad[64];
164 	} sc_txtapu;
165 	u_int16_t		sc_txbuf[IEEE80211_MAX_LEN/2];
166 	/* number of transmissions pending at each data rate */
167 	u_int8_t		sc_txpending[IEEE80211_RATE_MAXSIZE];
168 	struct callout		sc_rssadapt_ch;
169 };
170 
171 #define	sc_if		sc_ec.ec_if
172 #define sc_rxtap	sc_rxtapu.tap
173 #define sc_txtap	sc_txtapu.tap
174 
175 struct wi_node {
176 	struct ieee80211_node		wn_node;
177 	struct ieee80211_rssadapt	wn_rssadapt;
178 };
179 
180 /* maximum false change-of-BSSID indications per second */
181 #define	WI_MAX_FALSE_SYNS		10
182 
183 #define	WI_PRISM_DBM_OFFSET	100	/* XXX */
184 
185 #define	WI_LUCENT_DBM_OFFSET	149
186 
187 #define	WI_SCAN_INQWAIT			3	/* wait sec before inquire */
188 #define	WI_SCAN_WAIT			5	/* maximum scan wait */
189 
190 /* Values for wi_flags. */
191 #define	WI_FLAGS_ATTACHED		0x0001
192 #define	WI_FLAGS_INITIALIZED		0x0002
193 #define	WI_FLAGS_OUTRANGE		0x0004
194 #define	WI_FLAGS_RSSADAPTSTA		0x0008
195 #define	WI_FLAGS_HAS_MOR		0x0010
196 #define	WI_FLAGS_HAS_ROAMING		0x0020
197 #define	WI_FLAGS_HAS_DIVERSITY		0x0040
198 #define	WI_FLAGS_HAS_SYSSCALE		0x0080
199 #define	WI_FLAGS_BUG_AUTOINC		0x0100
200 #define	WI_FLAGS_HAS_FRAGTHR		0x0200
201 #define	WI_FLAGS_HAS_DBMADJUST		0x0400
202 #define	WI_FLAGS_WEP_VALID		0x0800
203 
204 struct wi_card_ident {
205 	u_int16_t	card_id;
206 	const char	*card_name;
207 	u_int8_t	firm_type;
208 };
209 
210 /*
211  * register space access macros
212  */
213 #ifdef WI_AT_BIGENDIAN_BUS_HACK
214 	/*
215 	 * XXX - ugly hack for sparc bus_space_* macro deficiencies:
216 	 *       assume the bus we are accessing is big endian.
217 	 */
218 
219 #define CSR_WRITE_4(sc, reg, val)	\
220 	bus_space_write_4(sc->sc_iot, sc->sc_ioh,	\
221 			(sc->sc_pci? reg * 2: reg) , htole32(val))
222 #define CSR_WRITE_2(sc, reg, val)	\
223 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,	\
224 			(sc->sc_pci? reg * 2: reg), htole16(val))
225 #define CSR_WRITE_1(sc, reg, val)	\
226 	bus_space_write_1(sc->sc_iot, sc->sc_ioh,	\
227 			(sc->sc_pci? reg * 2: reg), val)
228 
229 #define CSR_READ_4(sc, reg)		\
230 	le32toh(bus_space_read_4(sc->sc_iot, sc->sc_ioh,	\
231 			(sc->sc_pci? reg * 2: reg)))
232 #define CSR_READ_2(sc, reg)		\
233 	le16toh(bus_space_read_2(sc->sc_iot, sc->sc_ioh,	\
234 			(sc->sc_pci? reg * 2: reg)))
235 #define CSR_READ_1(sc, reg)		\
236 	bus_space_read_1(sc->sc_iot, sc->sc_ioh,	\
237 			(sc->sc_pci? reg * 2: reg))
238 
239 #else
240 
241 #define CSR_WRITE_4(sc, reg, val)	\
242 	bus_space_write_4(sc->sc_iot, sc->sc_ioh,	\
243 			(sc->sc_pci? reg * 2: reg) , val)
244 #define CSR_WRITE_2(sc, reg, val)	\
245 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,	\
246 			(sc->sc_pci? reg * 2: reg), val)
247 #define CSR_WRITE_1(sc, reg, val)	\
248 	bus_space_write_1(sc->sc_iot, sc->sc_ioh,	\
249 			(sc->sc_pci? reg * 2: reg), val)
250 
251 #define CSR_READ_4(sc, reg)		\
252 	bus_space_read_4(sc->sc_iot, sc->sc_ioh,	\
253 			(sc->sc_pci? reg * 2: reg))
254 #define CSR_READ_2(sc, reg)		\
255 	bus_space_read_2(sc->sc_iot, sc->sc_ioh,	\
256 			(sc->sc_pci? reg * 2: reg))
257 #define CSR_READ_1(sc, reg)		\
258 	bus_space_read_1(sc->sc_iot, sc->sc_ioh,	\
259 			(sc->sc_pci? reg * 2: reg))
260 #endif
261 
262 #ifndef __BUS_SPACE_HAS_STREAM_METHODS
263 #define bus_space_write_stream_2	bus_space_write_2
264 #define bus_space_write_multi_stream_2	bus_space_write_multi_2
265 #define bus_space_read_stream_2		bus_space_read_2
266 #define bus_space_read_multi_stream_2		bus_space_read_multi_2
267 #endif
268 
269 #define CSR_WRITE_STREAM_2(sc, reg, val)	\
270 	bus_space_write_stream_2(sc->sc_iot, sc->sc_ioh,	\
271 			(sc->sc_pci? reg * 2: reg), val)
272 #define CSR_WRITE_MULTI_STREAM_2(sc, reg, val, count)	\
273 	bus_space_write_multi_stream_2(sc->sc_iot, sc->sc_ioh,	\
274 			(sc->sc_pci? reg * 2: reg), val, count)
275 #define CSR_READ_STREAM_2(sc, reg)		\
276 	bus_space_read_stream_2(sc->sc_iot, sc->sc_ioh,	\
277 			(sc->sc_pci? reg * 2: reg))
278 #define CSR_READ_MULTI_STREAM_2(sc, reg, buf, count)		\
279 	bus_space_read_multi_stream_2(sc->sc_iot, sc->sc_ioh,	\
280 			(sc->sc_pci? reg * 2: reg), buf, count)
281 
282 
283 int	wi_attach(struct wi_softc *, const u_int8_t *);
284 int	wi_detach(struct wi_softc *);
285 int	wi_activate(device_t, enum devact);
286 int	wi_intr(void *arg);
287