wivar.h revision 1.52 1 /* $NetBSD: wivar.h,v 1.52 2004/09/28 00:42:11 dyoung Exp $ */
2
3 /*
4 * Copyright (c) 1997, 1998, 1999
5 * Bill Paul <wpaul (at) 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 } __attribute__((__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 } __attribute__((__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 struct device sc_dev;
78 struct ieee80211com sc_ic;
79 void *sc_ih; /* interrupt handler */
80 int (*sc_enable)(struct wi_softc *);
81 void (*sc_disable)(struct wi_softc *);
82 void (*sc_reset)(struct wi_softc *);
83
84 int (*sc_newstate)(struct ieee80211com *,
85 enum ieee80211_state, int);
86
87 int sc_attached;
88 int sc_enabled;
89 int sc_invalid;
90 int sc_firmware_type;
91 #define WI_NOTYPE 0
92 #define WI_LUCENT 1
93 #define WI_INTERSIL 2
94 #define WI_SYMBOL 3
95 int sc_pri_firmware_ver; /* Primary firm vers */
96 int sc_sta_firmware_ver; /* Station firm vers */
97 int sc_pci; /* attach to PCI-Bus */
98
99 bus_space_tag_t sc_iot; /* bus cookie */
100 bus_space_handle_t sc_ioh; /* bus i/o handle */
101
102 caddr_t sc_drvbpf;
103 int sc_flags;
104 int sc_bap_id;
105 int sc_bap_off;
106
107 u_int16_t sc_portnum;
108
109 /* RSSI interpretation */
110 u_int16_t sc_dbm_offset; /* dBm ~ RSSI - sc_dbm_offset */
111 u_int16_t sc_max_datalen;
112 u_int16_t sc_frag_thresh;
113 u_int16_t sc_rts_thresh;
114 u_int16_t sc_system_scale;
115 u_int16_t sc_tx_rate;
116 u_int16_t sc_cnfauthmode;
117 u_int16_t sc_roaming_mode;
118 u_int16_t sc_microwave_oven;
119
120 int sc_nodelen;
121 char sc_nodename[IEEE80211_NWID_LEN];
122
123 int sc_buflen;
124 #define WI_NTXBUF 3
125 #define WI_NTXRSS 10
126 struct {
127 int d_fid;
128 } sc_txd[WI_NTXBUF];
129 int sc_txalloc; /* next FID to allocate */
130 int sc_txalloced; /* FIDs currently allocated */
131 int sc_txqueue; /* next FID to queue */
132 int sc_txqueued; /* FIDs currently queued */
133 int sc_txstart; /* next FID to start */
134 int sc_txstarted; /* FIDs currently started */
135 struct wi_rssdesc sc_rssd[WI_NTXRSS];
136 wi_rssdescq_t sc_rssdfree;
137 int sc_tx_timer;
138 int sc_scan_timer;
139 int sc_syn_timer;
140
141 struct wi_counters sc_stats;
142 u_int16_t sc_ibss_port;
143
144 struct wi_apinfo sc_aps[MAXAPINFO];
145 int sc_naps;
146
147 struct timeval sc_last_syn;
148 int sc_false_syns;
149 int sc_alt_retry;
150
151 union {
152 struct wi_rx_radiotap_header tap;
153 u_int8_t pad[64];
154 } sc_rxtapu;
155 union {
156 struct wi_tx_radiotap_header tap;
157 u_int8_t pad[64];
158 } sc_txtapu;
159 u_int16_t sc_txbuf[IEEE80211_MAX_LEN/2];
160 /* number of transmissions pending at each data rate */
161 u_int8_t sc_txpending[IEEE80211_RATE_MAXSIZE];
162 struct callout sc_rssadapt_ch;
163 };
164
165 #define sc_rxtap sc_rxtapu.tap
166 #define sc_txtap sc_txtapu.tap
167
168 #define sc_if sc_ic.ic_if
169
170 struct wi_node {
171 struct ieee80211_node wn_node;
172 struct ieee80211_rssadapt wn_rssadapt;
173 };
174
175 /* maximum false change-of-BSSID indications per second */
176 #define WI_MAX_FALSE_SYNS 10
177
178 #define WI_PRISM_DBM_OFFSET 100 /* XXX */
179
180 #define WI_LUCENT_DBM_OFFSET 149
181
182 #define WI_SCAN_INQWAIT 3 /* wait sec before inquire */
183 #define WI_SCAN_WAIT 5 /* maximum scan wait */
184
185 /* Values for wi_flags. */
186 #define WI_FLAGS_ATTACHED 0x0001
187 #define WI_FLAGS_INITIALIZED 0x0002
188 #define WI_FLAGS_OUTRANGE 0x0004
189 #define WI_FLAGS_RSSADAPTSTA 0x0008
190 #define WI_FLAGS_HAS_MOR 0x0010
191 #define WI_FLAGS_HAS_ROAMING 0x0020
192 #define WI_FLAGS_HAS_DIVERSITY 0x0040
193 #define WI_FLAGS_HAS_SYSSCALE 0x0080
194 #define WI_FLAGS_BUG_AUTOINC 0x0100
195 #define WI_FLAGS_HAS_FRAGTHR 0x0200
196 #define WI_FLAGS_HAS_DBMADJUST 0x0400
197
198 struct wi_card_ident {
199 u_int16_t card_id;
200 char *card_name;
201 u_int8_t firm_type;
202 };
203
204 /*
205 * register space access macros
206 */
207 #ifdef WI_AT_BIGENDIAN_BUS_HACK
208 /*
209 * XXX - ugly hack for sparc bus_space_* macro deficiencies:
210 * assume the bus we are accessing is big endian.
211 */
212
213 #define CSR_WRITE_4(sc, reg, val) \
214 bus_space_write_4(sc->sc_iot, sc->sc_ioh, \
215 (sc->sc_pci? reg * 2: reg) , htole32(val))
216 #define CSR_WRITE_2(sc, reg, val) \
217 bus_space_write_2(sc->sc_iot, sc->sc_ioh, \
218 (sc->sc_pci? reg * 2: reg), htole16(val))
219 #define CSR_WRITE_1(sc, reg, val) \
220 bus_space_write_1(sc->sc_iot, sc->sc_ioh, \
221 (sc->sc_pci? reg * 2: reg), val)
222
223 #define CSR_READ_4(sc, reg) \
224 le32toh(bus_space_read_4(sc->sc_iot, sc->sc_ioh, \
225 (sc->sc_pci? reg * 2: reg)))
226 #define CSR_READ_2(sc, reg) \
227 le16toh(bus_space_read_2(sc->sc_iot, sc->sc_ioh, \
228 (sc->sc_pci? reg * 2: reg)))
229 #define CSR_READ_1(sc, reg) \
230 bus_space_read_1(sc->sc_iot, sc->sc_ioh, \
231 (sc->sc_pci? reg * 2: reg))
232
233 #else
234
235 #define CSR_WRITE_4(sc, reg, val) \
236 bus_space_write_4(sc->sc_iot, sc->sc_ioh, \
237 (sc->sc_pci? reg * 2: reg) , val)
238 #define CSR_WRITE_2(sc, reg, val) \
239 bus_space_write_2(sc->sc_iot, sc->sc_ioh, \
240 (sc->sc_pci? reg * 2: reg), val)
241 #define CSR_WRITE_1(sc, reg, val) \
242 bus_space_write_1(sc->sc_iot, sc->sc_ioh, \
243 (sc->sc_pci? reg * 2: reg), val)
244
245 #define CSR_READ_4(sc, reg) \
246 bus_space_read_4(sc->sc_iot, sc->sc_ioh, \
247 (sc->sc_pci? reg * 2: reg))
248 #define CSR_READ_2(sc, reg) \
249 bus_space_read_2(sc->sc_iot, sc->sc_ioh, \
250 (sc->sc_pci? reg * 2: reg))
251 #define CSR_READ_1(sc, reg) \
252 bus_space_read_1(sc->sc_iot, sc->sc_ioh, \
253 (sc->sc_pci? reg * 2: reg))
254 #endif
255
256 #ifndef __BUS_SPACE_HAS_STREAM_METHODS
257 #define bus_space_write_stream_2 bus_space_write_2
258 #define bus_space_write_multi_stream_2 bus_space_write_multi_2
259 #define bus_space_read_stream_2 bus_space_read_2
260 #define bus_space_read_multi_stream_2 bus_space_read_multi_2
261 #endif
262
263 #define CSR_WRITE_STREAM_2(sc, reg, val) \
264 bus_space_write_stream_2(sc->sc_iot, sc->sc_ioh, \
265 (sc->sc_pci? reg * 2: reg), val)
266 #define CSR_WRITE_MULTI_STREAM_2(sc, reg, val, count) \
267 bus_space_write_multi_stream_2(sc->sc_iot, sc->sc_ioh, \
268 (sc->sc_pci? reg * 2: reg), val, count)
269 #define CSR_READ_STREAM_2(sc, reg) \
270 bus_space_read_stream_2(sc->sc_iot, sc->sc_ioh, \
271 (sc->sc_pci? reg * 2: reg))
272 #define CSR_READ_MULTI_STREAM_2(sc, reg, buf, count) \
273 bus_space_read_multi_stream_2(sc->sc_iot, sc->sc_ioh, \
274 (sc->sc_pci? reg * 2: reg), buf, count)
275
276
277 int wi_attach(struct wi_softc *, const u_int8_t *);
278 int wi_detach(struct wi_softc *);
279 int wi_activate(struct device *, enum devact);
280 int wi_intr(void *arg);
281 void wi_power(struct wi_softc *, int);
282 void wi_shutdown(struct wi_softc *);
283