awivar.h revision 1.7 1 /* $NetBSD: awivar.h,v 1.7 2000/03/27 12:55:00 onoe Exp $ */
2
3 /*
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Atsushi Onoe
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /* timer values in msec */
40 #define AWI_SELFTEST_TIMEOUT 5000
41 #define AWI_CMD_TIMEOUT 2000
42 #define AWI_LOCKOUT_TIMEOUT 50
43 #define AWI_ASCAN_DURATION 100
44 #define AWI_ASCAN_WAIT 3000
45 #define AWI_PSCAN_DURATION 200
46 #define AWI_PSCAN_WAIT 5000
47 #define AWI_TRANS_TIMEOUT 2000
48
49 #define AWI_NTXBUFS 4
50
51 enum awi_status {
52 AWI_ST_INIT,
53 AWI_ST_SCAN,
54 AWI_ST_SETSS,
55 AWI_ST_SYNC,
56 AWI_ST_AUTH,
57 AWI_ST_ASSOC,
58 AWI_ST_RUNNING
59 };
60
61 struct awi_bss
62 {
63 TAILQ_ENTRY(awi_bss) list;
64 u_int8_t esrc[ETHER_ADDR_LEN];
65 u_int8_t chanset; /* channel set to use */
66 u_int8_t pattern; /* hop pattern to use */
67 u_int8_t index; /* index to use */
68 u_int8_t rssi; /* strength of this beacon */
69 u_int16_t dwell_time; /* dwell time */
70 u_int8_t timestamp[8]; /* timestamp of this bss */
71 u_int8_t bssid[ETHER_ADDR_LEN];
72 u_int32_t rxtime; /* unit's local time */
73 u_int16_t interval; /* beacon interval */
74 u_int8_t txrate;
75 u_int8_t fails;
76 u_int8_t essid[IEEE80211_NWID_LEN + 2];
77 };
78
79 struct awi_softc
80 {
81 #ifdef __NetBSD__
82 struct device sc_dev;
83 struct ethercom sc_ec;
84 void *sc_ih; /* interrupt handler */
85 #endif
86 #ifdef __FreeBSD__
87 #if __FreeBSD__ >= 4
88 struct {
89 char dv_xname[64]; /*XXX*/
90 } sc_dev;
91 #else
92 struct device sc_dev;
93 #endif
94 struct arpcom sc_ec;
95 struct callout_handle sc_tohandle;
96 #endif
97 struct am79c930_softc sc_chip;
98 struct ifnet *sc_ifp;
99 int (*sc_enable) __P((struct awi_softc *));
100 void (*sc_disable) __P((struct awi_softc *));
101
102 struct ifmedia sc_media;
103 enum awi_status sc_status;
104 unsigned int sc_enabled:1,
105 sc_busy:1,
106 sc_cansleep:1,
107 sc_invalid:1,
108 sc_enab_intr:1,
109 sc_cmd_inprog:1,
110 sc_format_llc:1,
111 sc_start_bss:1,
112 sc_rawbpf:1,
113 sc_no_bssid:1,
114 sc_active_scan:1;
115 int sc_sleep_cnt;
116
117 int sc_mgt_timer;
118
119 TAILQ_HEAD(, awi_bss) sc_scan;
120 u_int8_t sc_scan_cur;
121 u_int8_t sc_scan_min;
122 u_int8_t sc_scan_max;
123 u_int8_t sc_scan_set;
124 struct awi_bss sc_bss;
125
126 int sc_rx_timer;
127 u_int32_t sc_rxdoff;
128 u_int32_t sc_rxmoff;
129 struct mbuf *sc_rxpend;
130
131 int sc_tx_timer;
132 u_int8_t sc_tx_rate;
133 struct ifqueue sc_mgtq;
134 u_int32_t sc_txbase;
135 u_int32_t sc_txend;
136 u_int32_t sc_txnext;
137 u_int32_t sc_txdone;
138
139 struct awi_mib_local sc_mib_local;
140 struct awi_mib_addr sc_mib_addr;
141 struct awi_mib_mac sc_mib_mac;
142 struct awi_mib_stat sc_mib_stat;
143 struct awi_mib_mgt sc_mib_mgt;
144 struct awi_mib_phy sc_mib_phy;
145 };
146
147 #define awi_read_1(sc, off) ((sc)->sc_chip.sc_ops->read_1)(&sc->sc_chip, off)
148 #define awi_read_2(sc, off) ((sc)->sc_chip.sc_ops->read_2)(&sc->sc_chip, off)
149 #define awi_read_4(sc, off) ((sc)->sc_chip.sc_ops->read_4)(&sc->sc_chip, off)
150 #define awi_read_bytes(sc, off, ptr, len) ((sc)->sc_chip.sc_ops->read_bytes)(&sc->sc_chip, off, ptr, len)
151
152 #define awi_write_1(sc, off, val) \
153 ((sc)->sc_chip.sc_ops->write_1)(&sc->sc_chip, off, val)
154 #define awi_write_2(sc, off, val) \
155 ((sc)->sc_chip.sc_ops->write_2)(&sc->sc_chip, off, val)
156 #define awi_write_4(sc, off, val) \
157 ((sc)->sc_chip.sc_ops->write_4)(&sc->sc_chip, off, val)
158 #define awi_write_bytes(sc, off, ptr, len) \
159 ((sc)->sc_chip.sc_ops->write_bytes)(&sc->sc_chip, off, ptr, len)
160
161 #define awi_drvstate(sc, state) \
162 awi_write_1(sc, AWI_DRIVERSTATE, \
163 ((state) | AWI_DRV_AUTORXLED|AWI_DRV_AUTOTXLED))
164
165 /* unalligned little endian access */
166 #define LE_READ_2(p) \
167 (((u_int8_t *)(p))[0] | (((u_int8_t *)(p))[1] << 8))
168 #define LE_READ_4(p) \
169 (((u_int8_t *)(p))[0] | (((u_int8_t *)(p))[1] << 8) | \
170 (((u_int8_t *)(p))[2] << 16) | (((u_int8_t *)(p))[3] << 24))
171 #define LE_WRITE_2(p, v) \
172 ((((u_int8_t *)(p))[0] = ((u_int32_t)(v) & 0xff)), \
173 (((u_int8_t *)(p))[1] = (((u_int32_t)(v) >> 8) & 0xff)))
174 #define LE_WRITE_4(p, v) \
175 ((((u_int8_t *)(p))[0] = ((u_int32_t)(v) & 0xff)), \
176 (((u_int8_t *)(p))[1] = (((u_int32_t)(v) >> 8) & 0xff)), \
177 (((u_int8_t *)(p))[2] = (((u_int32_t)(v) >> 16) & 0xff)), \
178 (((u_int8_t *)(p))[3] = (((u_int32_t)(v) >> 24) & 0xff)))
179
180 #define AWI_80211_RATE(rate) (((rate) & 0x7f) * 5)
181
182 int awi_attach __P((struct awi_softc *));
183 int awi_intr __P((void *));
184 void awi_reset __P((struct awi_softc *));
185 #ifdef __NetBSD__
186 int awi_activate __P((struct device *, enum devact));
187 int awi_detach __P((struct awi_softc *));
188 #endif
189