awi.c revision 1.27.2.5 1 1.27.2.5 bouyer /* $NetBSD: awi.c,v 1.27.2.5 2001/01/05 17:35:34 bouyer Exp $ */
2 1.27.2.2 bouyer
3 1.27.2.2 bouyer /*-
4 1.27.2.2 bouyer * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.27.2.2 bouyer * All rights reserved.
6 1.27.2.2 bouyer *
7 1.27.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.27.2.2 bouyer * by Bill Sommerfeld
9 1.27.2.2 bouyer *
10 1.27.2.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.27.2.2 bouyer * modification, are permitted provided that the following conditions
12 1.27.2.2 bouyer * are met:
13 1.27.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.27.2.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.27.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.27.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.27.2.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.27.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.27.2.2 bouyer * must display the following acknowledgement:
20 1.27.2.2 bouyer * This product includes software developed by the NetBSD
21 1.27.2.2 bouyer * Foundation, Inc. and its contributors.
22 1.27.2.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.27.2.2 bouyer * contributors may be used to endorse or promote products derived
24 1.27.2.2 bouyer * from this software without specific prior written permission.
25 1.27.2.2 bouyer *
26 1.27.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.27.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.27.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.27.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.27.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.27.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.27.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.27.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.27.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.27.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.27.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.27.2.2 bouyer */
38 1.27.2.2 bouyer /*
39 1.27.2.2 bouyer * Driver for AMD 802.11 firmware.
40 1.27.2.2 bouyer * Uses am79c930 chip driver to talk to firmware running on the am79c930.
41 1.27.2.2 bouyer *
42 1.27.2.2 bouyer * More-or-less a generic ethernet-like if driver, with 802.11 gorp added.
43 1.27.2.2 bouyer */
44 1.27.2.2 bouyer
45 1.27.2.2 bouyer /*
46 1.27.2.2 bouyer * todo:
47 1.27.2.2 bouyer * - flush tx queue on resynch.
48 1.27.2.2 bouyer * - clear oactive on "down".
49 1.27.2.2 bouyer * - rewrite copy-into-mbuf code
50 1.27.2.2 bouyer * - mgmt state machine gets stuck retransmitting assoc requests.
51 1.27.2.2 bouyer * - multicast filter.
52 1.27.2.2 bouyer * - fix device reset so it's more likely to work
53 1.27.2.2 bouyer * - show status goo through ifmedia.
54 1.27.2.2 bouyer *
55 1.27.2.2 bouyer * more todo:
56 1.27.2.2 bouyer * - deal with more 802.11 frames.
57 1.27.2.2 bouyer * - send reassoc request
58 1.27.2.2 bouyer * - deal with reassoc response
59 1.27.2.2 bouyer * - send/deal with disassociation
60 1.27.2.2 bouyer * - deal with "full" access points (no room for me).
61 1.27.2.2 bouyer * - power save mode
62 1.27.2.2 bouyer *
63 1.27.2.2 bouyer * later:
64 1.27.2.2 bouyer * - SSID preferences
65 1.27.2.2 bouyer * - need ioctls for poking at the MIBs
66 1.27.2.2 bouyer * - implement ad-hoc mode (including bss creation).
67 1.27.2.2 bouyer * - decide when to do "ad hoc" vs. infrastructure mode (IFF_LINK flags?)
68 1.27.2.2 bouyer * (focus on inf. mode since that will be needed for ietf)
69 1.27.2.2 bouyer * - deal with DH vs. FH versions of the card
70 1.27.2.2 bouyer * - deal with faster cards (2mb/s)
71 1.27.2.2 bouyer * - ?WEP goo (mmm, rc4) (it looks not particularly useful).
72 1.27.2.2 bouyer * - ifmedia revision.
73 1.27.2.2 bouyer * - common 802.11 mibish things.
74 1.27.2.2 bouyer * - common 802.11 media layer.
75 1.27.2.2 bouyer */
76 1.27.2.2 bouyer
77 1.27.2.2 bouyer /*
78 1.27.2.2 bouyer * Driver for AMD 802.11 PCnetMobile firmware.
79 1.27.2.2 bouyer * Uses am79c930 chip driver to talk to firmware running on the am79c930.
80 1.27.2.2 bouyer *
81 1.27.2.2 bouyer * The initial version of the driver was written by
82 1.27.2.2 bouyer * Bill Sommerfeld <sommerfeld (at) netbsd.org>.
83 1.27.2.2 bouyer * Then the driver module completely rewritten to support cards with DS phy
84 1.27.2.2 bouyer * and to support adhoc mode by Atsushi Onoe <onoe (at) netbsd.org>
85 1.27.2.2 bouyer */
86 1.27.2.2 bouyer
87 1.27.2.2 bouyer #include "opt_inet.h"
88 1.27.2.2 bouyer #if defined(__FreeBSD__) && __FreeBSD__ >= 4
89 1.27.2.2 bouyer #define NBPFILTER 1
90 1.27.2.2 bouyer #elif defined(__FreeBSD__) && __FreeBSD__ >= 3
91 1.27.2.2 bouyer #include "bpf.h"
92 1.27.2.2 bouyer #define NBPFILTER NBPF
93 1.27.2.2 bouyer #else
94 1.27.2.2 bouyer #include "bpfilter.h"
95 1.27.2.2 bouyer #endif
96 1.27.2.2 bouyer
97 1.27.2.2 bouyer #include <sys/param.h>
98 1.27.2.2 bouyer #include <sys/systm.h>
99 1.27.2.2 bouyer #include <sys/kernel.h>
100 1.27.2.2 bouyer #include <sys/mbuf.h>
101 1.27.2.2 bouyer #include <sys/malloc.h>
102 1.27.2.2 bouyer #include <sys/proc.h>
103 1.27.2.2 bouyer #include <sys/socket.h>
104 1.27.2.2 bouyer #include <sys/sockio.h>
105 1.27.2.2 bouyer #include <sys/errno.h>
106 1.27.2.2 bouyer #include <sys/syslog.h>
107 1.27.2.2 bouyer #if defined(__FreeBSD__) && __FreeBSD__ >= 4
108 1.27.2.2 bouyer #include <sys/bus.h>
109 1.27.2.2 bouyer #else
110 1.27.2.2 bouyer #include <sys/device.h>
111 1.27.2.2 bouyer #endif
112 1.27.2.2 bouyer
113 1.27.2.2 bouyer #include <net/if.h>
114 1.27.2.2 bouyer #include <net/if_dl.h>
115 1.27.2.2 bouyer #ifdef __FreeBSD__
116 1.27.2.2 bouyer #include <net/ethernet.h>
117 1.27.2.2 bouyer #else
118 1.27.2.2 bouyer #include <net/if_ether.h>
119 1.27.2.2 bouyer #endif
120 1.27.2.2 bouyer #include <net/if_media.h>
121 1.27.2.2 bouyer #include <net/if_llc.h>
122 1.27.2.2 bouyer #include <net/if_ieee80211.h>
123 1.27.2.2 bouyer
124 1.27.2.2 bouyer #ifdef INET
125 1.27.2.2 bouyer #include <netinet/in.h>
126 1.27.2.2 bouyer #include <netinet/in_systm.h>
127 1.27.2.2 bouyer #include <netinet/in_var.h>
128 1.27.2.2 bouyer #include <netinet/ip.h>
129 1.27.2.2 bouyer #ifdef __NetBSD__
130 1.27.2.2 bouyer #include <netinet/if_inarp.h>
131 1.27.2.2 bouyer #else
132 1.27.2.2 bouyer #include <netinet/if_ether.h>
133 1.27.2.2 bouyer #endif
134 1.27.2.2 bouyer #endif
135 1.27.2.2 bouyer
136 1.27.2.2 bouyer #if NBPFILTER > 0
137 1.27.2.2 bouyer #include <net/bpf.h>
138 1.27.2.2 bouyer #include <net/bpfdesc.h>
139 1.27.2.2 bouyer #endif
140 1.27.2.2 bouyer
141 1.27.2.2 bouyer #include <machine/cpu.h>
142 1.27.2.2 bouyer #include <machine/bus.h>
143 1.27.2.2 bouyer #ifdef __NetBSD__
144 1.27.2.2 bouyer #include <machine/intr.h>
145 1.27.2.2 bouyer #endif
146 1.27.2.2 bouyer #ifdef __FreeBSD__
147 1.27.2.2 bouyer #include <machine/clock.h>
148 1.27.2.2 bouyer #endif
149 1.27.2.2 bouyer
150 1.27.2.2 bouyer #ifdef __NetBSD__
151 1.27.2.2 bouyer #include <dev/ic/am79c930reg.h>
152 1.27.2.2 bouyer #include <dev/ic/am79c930var.h>
153 1.27.2.2 bouyer #include <dev/ic/awireg.h>
154 1.27.2.2 bouyer #include <dev/ic/awivar.h>
155 1.27.2.2 bouyer #endif
156 1.27.2.2 bouyer #ifdef __FreeBSD__
157 1.27.2.2 bouyer #include <dev/awi/am79c930reg.h>
158 1.27.2.2 bouyer #include <dev/awi/am79c930var.h>
159 1.27.2.2 bouyer #include <dev/awi/awireg.h>
160 1.27.2.2 bouyer #include <dev/awi/awivar.h>
161 1.27.2.2 bouyer #endif
162 1.27.2.2 bouyer
163 1.27.2.2 bouyer static int awi_ioctl __P((struct ifnet *ifp, u_long cmd, caddr_t data));
164 1.27.2.2 bouyer #ifdef IFM_IEEE80211
165 1.27.2.2 bouyer static int awi_media_rate2opt __P((struct awi_softc *sc, int rate));
166 1.27.2.2 bouyer static int awi_media_opt2rate __P((struct awi_softc *sc, int opt));
167 1.27.2.2 bouyer static int awi_media_change __P((struct ifnet *ifp));
168 1.27.2.2 bouyer static void awi_media_status __P((struct ifnet *ifp, struct ifmediareq *imr));
169 1.27.2.2 bouyer #endif
170 1.27.2.2 bouyer static void awi_watchdog __P((struct ifnet *ifp));
171 1.27.2.2 bouyer static void awi_start __P((struct ifnet *ifp));
172 1.27.2.2 bouyer static void awi_txint __P((struct awi_softc *sc));
173 1.27.2.2 bouyer static struct mbuf * awi_fix_txhdr __P((struct awi_softc *sc, struct mbuf *m0));
174 1.27.2.2 bouyer static struct mbuf * awi_fix_rxhdr __P((struct awi_softc *sc, struct mbuf *m0));
175 1.27.2.2 bouyer static void awi_input __P((struct awi_softc *sc, struct mbuf *m, u_int32_t rxts, u_int8_t rssi));
176 1.27.2.2 bouyer static void awi_rxint __P((struct awi_softc *sc));
177 1.27.2.2 bouyer static struct mbuf * awi_devget __P((struct awi_softc *sc, u_int32_t off, u_int16_t len));
178 1.27.2.2 bouyer static int awi_init_hw __P((struct awi_softc *sc));
179 1.27.2.2 bouyer static int awi_init_mibs __P((struct awi_softc *sc));
180 1.27.2.2 bouyer static int awi_init_txrx __P((struct awi_softc *sc));
181 1.27.2.2 bouyer static void awi_stop_txrx __P((struct awi_softc *sc));
182 1.27.2.2 bouyer static int awi_start_scan __P((struct awi_softc *sc));
183 1.27.2.2 bouyer static int awi_next_scan __P((struct awi_softc *sc));
184 1.27.2.2 bouyer static void awi_stop_scan __P((struct awi_softc *sc));
185 1.27.2.2 bouyer static void awi_recv_beacon __P((struct awi_softc *sc, struct mbuf *m0, u_int32_t rxts, u_int8_t rssi));
186 1.27.2.2 bouyer static int awi_set_ss __P((struct awi_softc *sc));
187 1.27.2.2 bouyer static void awi_try_sync __P((struct awi_softc *sc));
188 1.27.2.2 bouyer static void awi_sync_done __P((struct awi_softc *sc));
189 1.27.2.2 bouyer static void awi_send_deauth __P((struct awi_softc *sc));
190 1.27.2.2 bouyer static void awi_send_auth __P((struct awi_softc *sc, int seq));
191 1.27.2.2 bouyer static void awi_recv_auth __P((struct awi_softc *sc, struct mbuf *m0));
192 1.27.2.2 bouyer static void awi_send_asreq __P((struct awi_softc *sc, int reassoc));
193 1.27.2.2 bouyer static void awi_recv_asresp __P((struct awi_softc *sc, struct mbuf *m0));
194 1.27.2.2 bouyer static int awi_mib __P((struct awi_softc *sc, u_int8_t cmd, u_int8_t mib));
195 1.27.2.2 bouyer static int awi_cmd_scan __P((struct awi_softc *sc));
196 1.27.2.2 bouyer static int awi_cmd __P((struct awi_softc *sc, u_int8_t cmd));
197 1.27.2.2 bouyer static void awi_cmd_done __P((struct awi_softc *sc));
198 1.27.2.2 bouyer static int awi_next_txd __P((struct awi_softc *sc, int len, u_int32_t *framep, u_int32_t*ntxdp));
199 1.27.2.2 bouyer static int awi_lock __P((struct awi_softc *sc));
200 1.27.2.2 bouyer static void awi_unlock __P((struct awi_softc *sc));
201 1.27.2.2 bouyer static int awi_intr_lock __P((struct awi_softc *sc));
202 1.27.2.2 bouyer static void awi_intr_unlock __P((struct awi_softc *sc));
203 1.27.2.2 bouyer static int awi_cmd_wait __P((struct awi_softc *sc));
204 1.27.2.2 bouyer static void awi_print_essid __P((u_int8_t *essid));
205 1.27.2.2 bouyer
206 1.27.2.2 bouyer #ifdef AWI_DEBUG
207 1.27.2.2 bouyer static void awi_dump_pkt __P((struct awi_softc *sc, struct mbuf *m, int rssi));
208 1.27.2.2 bouyer int awi_verbose = 0;
209 1.27.2.2 bouyer int awi_dump = 0;
210 1.27.2.2 bouyer #define AWI_DUMP_MASK(fc0) (1 << (((fc0) & IEEE80211_FC0_SUBTYPE_MASK) >> 4))
211 1.27.2.2 bouyer int awi_dump_mask = AWI_DUMP_MASK(IEEE80211_FC0_SUBTYPE_BEACON);
212 1.27.2.2 bouyer int awi_dump_hdr = 0;
213 1.27.2.2 bouyer int awi_dump_len = 28;
214 1.27.2.2 bouyer #endif
215 1.27.2.2 bouyer
216 1.27.2.2 bouyer #if NBPFILTER > 0
217 1.27.2.2 bouyer #define AWI_BPF_NORM 0
218 1.27.2.2 bouyer #define AWI_BPF_RAW 1
219 1.27.2.2 bouyer #ifdef __FreeBSD__
220 1.27.2.2 bouyer #define AWI_BPF_MTAP(sc, m, raw) do { \
221 1.27.2.2 bouyer if ((sc)->sc_ifp->if_bpf && (sc)->sc_rawbpf == (raw)) \
222 1.27.2.2 bouyer bpf_mtap((sc)->sc_ifp, (m)); \
223 1.27.2.2 bouyer } while (0);
224 1.27.2.2 bouyer #else
225 1.27.2.2 bouyer #define AWI_BPF_MTAP(sc, m, raw) do { \
226 1.27.2.2 bouyer if ((sc)->sc_ifp->if_bpf && (sc)->sc_rawbpf == (raw)) \
227 1.27.2.2 bouyer bpf_mtap((sc)->sc_ifp->if_bpf, (m)); \
228 1.27.2.2 bouyer } while (0);
229 1.27.2.2 bouyer #endif
230 1.27.2.2 bouyer #else
231 1.27.2.2 bouyer #define AWI_BPF_MTAP(sc, m, raw)
232 1.27.2.2 bouyer #endif
233 1.27.2.2 bouyer
234 1.27.2.2 bouyer #ifndef llc_snap
235 1.27.2.2 bouyer #define llc_snap llc_un.type_snap
236 1.27.2.2 bouyer #endif
237 1.27.2.2 bouyer
238 1.27.2.2 bouyer #ifdef __FreeBSD__
239 1.27.2.2 bouyer #if __FreeBSD__ >= 4
240 1.27.2.2 bouyer devclass_t awi_devclass;
241 1.27.2.2 bouyer #endif
242 1.27.2.2 bouyer
243 1.27.2.2 bouyer /* NetBSD compatible functions */
244 1.27.2.2 bouyer static char * ether_sprintf __P((u_int8_t *));
245 1.27.2.2 bouyer
246 1.27.2.2 bouyer static char *
247 1.27.2.2 bouyer ether_sprintf(enaddr)
248 1.27.2.2 bouyer u_int8_t *enaddr;
249 1.27.2.2 bouyer {
250 1.27.2.2 bouyer static char strbuf[18];
251 1.27.2.2 bouyer
252 1.27.2.2 bouyer sprintf(strbuf, "%6D", enaddr, ":");
253 1.27.2.2 bouyer return strbuf;
254 1.27.2.2 bouyer }
255 1.27.2.2 bouyer #endif
256 1.27.2.2 bouyer
257 1.27.2.2 bouyer int
258 1.27.2.2 bouyer awi_attach(sc)
259 1.27.2.2 bouyer struct awi_softc *sc;
260 1.27.2.2 bouyer {
261 1.27.2.2 bouyer struct ifnet *ifp = sc->sc_ifp;
262 1.27.2.2 bouyer int s;
263 1.27.2.2 bouyer int error;
264 1.27.2.2 bouyer #ifdef IFM_IEEE80211
265 1.27.2.2 bouyer int i;
266 1.27.2.2 bouyer u_int8_t *phy_rates;
267 1.27.2.2 bouyer int mword;
268 1.27.2.2 bouyer struct ifmediareq imr;
269 1.27.2.2 bouyer #endif
270 1.27.2.2 bouyer
271 1.27.2.2 bouyer s = splnet();
272 1.27.2.2 bouyer /*
273 1.27.2.2 bouyer * Even if we can sleep in initialization state,
274 1.27.2.2 bouyer * all other processes (e.g. ifconfig) have to wait for
275 1.27.2.2 bouyer * completion of attaching interface.
276 1.27.2.2 bouyer */
277 1.27.2.2 bouyer sc->sc_busy = 1;
278 1.27.2.2 bouyer sc->sc_status = AWI_ST_INIT;
279 1.27.2.2 bouyer TAILQ_INIT(&sc->sc_scan);
280 1.27.2.2 bouyer error = awi_init_hw(sc);
281 1.27.2.2 bouyer if (error) {
282 1.27.2.2 bouyer sc->sc_invalid = 1;
283 1.27.2.2 bouyer splx(s);
284 1.27.2.2 bouyer return error;
285 1.27.2.2 bouyer }
286 1.27.2.2 bouyer error = awi_init_mibs(sc);
287 1.27.2.2 bouyer splx(s);
288 1.27.2.2 bouyer if (error) {
289 1.27.2.2 bouyer sc->sc_invalid = 1;
290 1.27.2.2 bouyer return error;
291 1.27.2.2 bouyer }
292 1.27.2.2 bouyer
293 1.27.2.2 bouyer ifp->if_softc = sc;
294 1.27.2.2 bouyer ifp->if_start = awi_start;
295 1.27.2.2 bouyer ifp->if_ioctl = awi_ioctl;
296 1.27.2.2 bouyer ifp->if_watchdog = awi_watchdog;
297 1.27.2.2 bouyer ifp->if_mtu = ETHERMTU;
298 1.27.2.2 bouyer ifp->if_hdrlen = sizeof(struct ieee80211_frame) +
299 1.27.2.2 bouyer sizeof(struct ether_header);
300 1.27.2.2 bouyer ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
301 1.27.2.2 bouyer #ifdef IFF_NOTRAILERS
302 1.27.2.2 bouyer ifp->if_flags |= IFF_NOTRAILERS;
303 1.27.2.2 bouyer #endif
304 1.27.2.2 bouyer #ifdef __NetBSD__
305 1.27.2.2 bouyer memcpy(ifp->if_xname, sc->sc_dev.dv_xname, IFNAMSIZ);
306 1.27.2.2 bouyer #endif
307 1.27.2.2 bouyer #ifdef __FreeBSD__
308 1.27.2.2 bouyer ifp->if_output = ether_output;
309 1.27.2.2 bouyer ifp->if_snd.ifq_maxlen = ifqmaxlen;
310 1.27.2.2 bouyer memcpy(sc->sc_ec.ac_enaddr, sc->sc_mib_addr.aMAC_Address,
311 1.27.2.2 bouyer ETHER_ADDR_LEN);
312 1.27.2.2 bouyer #endif
313 1.27.2.5 bouyer IFQ_SET_READY(&ifp->if_snd);
314 1.27.2.2 bouyer
315 1.27.2.2 bouyer printf("%s: IEEE802.11 %s %dMbps (firmware %s)\n",
316 1.27.2.2 bouyer sc->sc_dev.dv_xname,
317 1.27.2.2 bouyer sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH ? "FH" : "DS",
318 1.27.2.2 bouyer sc->sc_tx_rate / 10, sc->sc_banner);
319 1.27.2.2 bouyer printf("%s: address %s\n",
320 1.27.2.2 bouyer sc->sc_dev.dv_xname, ether_sprintf(sc->sc_mib_addr.aMAC_Address));
321 1.27.2.2 bouyer if_attach(ifp);
322 1.27.2.2 bouyer #ifdef __FreeBSD__
323 1.27.2.2 bouyer ether_ifattach(ifp);
324 1.27.2.2 bouyer #if NBPFILTER > 0
325 1.27.2.2 bouyer bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
326 1.27.2.2 bouyer #endif
327 1.27.2.2 bouyer #else
328 1.27.2.2 bouyer ether_ifattach(ifp, sc->sc_mib_addr.aMAC_Address);
329 1.27.2.2 bouyer #endif
330 1.27.2.2 bouyer
331 1.27.2.2 bouyer #ifdef IFM_IEEE80211
332 1.27.2.2 bouyer ifmedia_init(&sc->sc_media, 0, awi_media_change, awi_media_status);
333 1.27.2.2 bouyer phy_rates = sc->sc_mib_phy.aSuprt_Data_Rates;
334 1.27.2.2 bouyer for (i = 0; i < phy_rates[1]; i++) {
335 1.27.2.2 bouyer mword = awi_media_rate2opt(sc, AWI_80211_RATE(phy_rates[2 + i]));
336 1.27.2.2 bouyer if (mword == 0)
337 1.27.2.2 bouyer continue;
338 1.27.2.2 bouyer mword |= IFM_IEEE80211;
339 1.27.2.2 bouyer ifmedia_add(&sc->sc_media, mword, 0, NULL);
340 1.27.2.2 bouyer ifmedia_add(&sc->sc_media,
341 1.27.2.2 bouyer mword | IFM_IEEE80211_ADHOC, 0, NULL);
342 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type != AWI_PHY_TYPE_FH)
343 1.27.2.2 bouyer ifmedia_add(&sc->sc_media,
344 1.27.2.2 bouyer mword | IFM_IEEE80211_ADHOC | IFM_FLAG0, 0, NULL);
345 1.27.2.2 bouyer }
346 1.27.2.2 bouyer awi_media_status(ifp, &imr);
347 1.27.2.2 bouyer ifmedia_set(&sc->sc_media, imr.ifm_active);
348 1.27.2.2 bouyer #endif
349 1.27.2.2 bouyer
350 1.27.2.2 bouyer /* ready to accept ioctl */
351 1.27.2.2 bouyer awi_unlock(sc);
352 1.27.2.2 bouyer
353 1.27.2.2 bouyer /* Attach is successful. */
354 1.27.2.2 bouyer sc->sc_attached = 1;
355 1.27.2.2 bouyer return 0;
356 1.27.2.2 bouyer }
357 1.27.2.2 bouyer
358 1.27.2.2 bouyer #ifdef __NetBSD__
359 1.27.2.2 bouyer int
360 1.27.2.2 bouyer awi_detach(sc)
361 1.27.2.2 bouyer struct awi_softc *sc;
362 1.27.2.2 bouyer {
363 1.27.2.2 bouyer struct ifnet *ifp = sc->sc_ifp;
364 1.27.2.2 bouyer int s;
365 1.27.2.2 bouyer
366 1.27.2.2 bouyer /* Succeed if there is no work to do. */
367 1.27.2.2 bouyer if (!sc->sc_attached)
368 1.27.2.2 bouyer return (0);
369 1.27.2.2 bouyer
370 1.27.2.2 bouyer s = splnet();
371 1.27.2.2 bouyer sc->sc_invalid = 1;
372 1.27.2.2 bouyer awi_stop(sc);
373 1.27.2.2 bouyer while (sc->sc_sleep_cnt > 0) {
374 1.27.2.2 bouyer wakeup(sc);
375 1.27.2.2 bouyer (void)tsleep(sc, PWAIT, "awidet", 1);
376 1.27.2.2 bouyer }
377 1.27.2.2 bouyer if (sc->sc_wep_ctx != NULL)
378 1.27.2.2 bouyer free(sc->sc_wep_ctx, M_DEVBUF);
379 1.27.2.2 bouyer #ifdef IFM_IEEE80211
380 1.27.2.2 bouyer ifmedia_delete_instance(&sc->sc_media, IFM_INST_ANY);
381 1.27.2.2 bouyer #endif
382 1.27.2.2 bouyer ether_ifdetach(ifp);
383 1.27.2.2 bouyer if_detach(ifp);
384 1.27.2.2 bouyer if (sc->sc_enabled) {
385 1.27.2.2 bouyer if (sc->sc_disable)
386 1.27.2.2 bouyer (*sc->sc_disable)(sc);
387 1.27.2.2 bouyer sc->sc_enabled = 0;
388 1.27.2.2 bouyer }
389 1.27.2.2 bouyer splx(s);
390 1.27.2.2 bouyer return 0;
391 1.27.2.2 bouyer }
392 1.27.2.2 bouyer
393 1.27.2.2 bouyer int
394 1.27.2.2 bouyer awi_activate(self, act)
395 1.27.2.2 bouyer struct device *self;
396 1.27.2.2 bouyer enum devact act;
397 1.27.2.2 bouyer {
398 1.27.2.2 bouyer struct awi_softc *sc = (struct awi_softc *)self;
399 1.27.2.2 bouyer int s, error = 0;
400 1.27.2.2 bouyer
401 1.27.2.2 bouyer s = splnet();
402 1.27.2.2 bouyer switch (act) {
403 1.27.2.2 bouyer case DVACT_ACTIVATE:
404 1.27.2.2 bouyer error = EOPNOTSUPP;
405 1.27.2.2 bouyer break;
406 1.27.2.2 bouyer
407 1.27.2.2 bouyer case DVACT_DEACTIVATE:
408 1.27.2.2 bouyer sc->sc_invalid = 1;
409 1.27.2.2 bouyer if (sc->sc_ifp)
410 1.27.2.2 bouyer if_deactivate(sc->sc_ifp);
411 1.27.2.2 bouyer break;
412 1.27.2.2 bouyer }
413 1.27.2.2 bouyer splx(s);
414 1.27.2.2 bouyer
415 1.27.2.2 bouyer return error;
416 1.27.2.2 bouyer }
417 1.27.2.2 bouyer
418 1.27.2.2 bouyer void
419 1.27.2.2 bouyer awi_power(sc, why)
420 1.27.2.2 bouyer struct awi_softc *sc;
421 1.27.2.2 bouyer int why;
422 1.27.2.2 bouyer {
423 1.27.2.2 bouyer int s;
424 1.27.2.2 bouyer int ocansleep;
425 1.27.2.2 bouyer
426 1.27.2.2 bouyer if (!sc->sc_enabled)
427 1.27.2.2 bouyer return;
428 1.27.2.2 bouyer
429 1.27.2.2 bouyer s = splnet();
430 1.27.2.2 bouyer ocansleep = sc->sc_cansleep;
431 1.27.2.2 bouyer sc->sc_cansleep = 0;
432 1.27.2.2 bouyer #ifdef needtobefixed /*ONOE*/
433 1.27.2.4 bouyer switch (why) {
434 1.27.2.4 bouyer case PWR_SUSPEND:
435 1.27.2.4 bouyer case PWR_STANDBY:
436 1.27.2.2 bouyer awi_stop(sc);
437 1.27.2.2 bouyer if (sc->sc_disable)
438 1.27.2.2 bouyer (*sc->sc_disable)(sc);
439 1.27.2.4 bouyer break;
440 1.27.2.4 bouyer case PWR_RESUME:
441 1.27.2.4 bouyer sc->sc_enabled = 0;
442 1.27.2.4 bouyer awi_init(sc);
443 1.27.2.4 bouyer (void)awi_intr(sc);
444 1.27.2.4 bouyer break;
445 1.27.2.4 bouyer case PWR_SOFTSUSPEND:
446 1.27.2.4 bouyer case PWR_SOFTSTANDBY:
447 1.27.2.4 bouyer case PWR_SOFTRESUME:
448 1.27.2.4 bouyer break;
449 1.27.2.2 bouyer }
450 1.27.2.2 bouyer #endif
451 1.27.2.2 bouyer sc->sc_cansleep = ocansleep;
452 1.27.2.2 bouyer splx(s);
453 1.27.2.2 bouyer }
454 1.27.2.2 bouyer #endif /* __NetBSD__ */
455 1.27.2.2 bouyer
456 1.27.2.2 bouyer static int
457 1.27.2.2 bouyer awi_ioctl(ifp, cmd, data)
458 1.27.2.2 bouyer struct ifnet *ifp;
459 1.27.2.2 bouyer u_long cmd;
460 1.27.2.2 bouyer caddr_t data;
461 1.27.2.2 bouyer {
462 1.27.2.2 bouyer struct awi_softc *sc = ifp->if_softc;
463 1.27.2.2 bouyer struct ifreq *ifr = (struct ifreq *)data;
464 1.27.2.2 bouyer struct ifaddr *ifa = (struct ifaddr *)data;
465 1.27.2.2 bouyer int s, error;
466 1.27.2.2 bouyer struct ieee80211_nwid nwid;
467 1.27.2.2 bouyer u_int8_t *p;
468 1.27.2.2 bouyer
469 1.27.2.2 bouyer s = splnet();
470 1.27.2.2 bouyer
471 1.27.2.2 bouyer /* serialize ioctl */
472 1.27.2.2 bouyer error = awi_lock(sc);
473 1.27.2.2 bouyer if (error)
474 1.27.2.2 bouyer goto cantlock;
475 1.27.2.2 bouyer switch (cmd) {
476 1.27.2.2 bouyer case SIOCSIFADDR:
477 1.27.2.2 bouyer ifp->if_flags |= IFF_UP;
478 1.27.2.2 bouyer switch (ifa->ifa_addr->sa_family) {
479 1.27.2.2 bouyer #ifdef INET
480 1.27.2.2 bouyer case AF_INET:
481 1.27.2.2 bouyer arp_ifinit((void *)ifp, ifa);
482 1.27.2.2 bouyer break;
483 1.27.2.2 bouyer #endif
484 1.27.2.2 bouyer }
485 1.27.2.2 bouyer /* FALLTHROUGH */
486 1.27.2.2 bouyer case SIOCSIFFLAGS:
487 1.27.2.2 bouyer sc->sc_format_llc = !(ifp->if_flags & IFF_LINK0);
488 1.27.2.2 bouyer if (!(ifp->if_flags & IFF_UP)) {
489 1.27.2.2 bouyer if (sc->sc_enabled) {
490 1.27.2.2 bouyer awi_stop(sc);
491 1.27.2.2 bouyer if (sc->sc_disable)
492 1.27.2.2 bouyer (*sc->sc_disable)(sc);
493 1.27.2.2 bouyer sc->sc_enabled = 0;
494 1.27.2.2 bouyer }
495 1.27.2.2 bouyer break;
496 1.27.2.2 bouyer }
497 1.27.2.2 bouyer error = awi_init(sc);
498 1.27.2.2 bouyer break;
499 1.27.2.2 bouyer
500 1.27.2.2 bouyer case SIOCADDMULTI:
501 1.27.2.2 bouyer case SIOCDELMULTI:
502 1.27.2.2 bouyer #ifdef __FreeBSD__
503 1.27.2.2 bouyer error = ENETRESET; /*XXX*/
504 1.27.2.2 bouyer #else
505 1.27.2.2 bouyer error = (cmd == SIOCADDMULTI) ?
506 1.27.2.2 bouyer ether_addmulti(ifr, &sc->sc_ec) :
507 1.27.2.2 bouyer ether_delmulti(ifr, &sc->sc_ec);
508 1.27.2.2 bouyer #endif
509 1.27.2.2 bouyer /*
510 1.27.2.2 bouyer * Do not rescan BSS. Rather, just reset multicast filter.
511 1.27.2.2 bouyer */
512 1.27.2.2 bouyer if (error == ENETRESET) {
513 1.27.2.2 bouyer if (sc->sc_enabled)
514 1.27.2.2 bouyer error = awi_init(sc);
515 1.27.2.2 bouyer else
516 1.27.2.2 bouyer error = 0;
517 1.27.2.2 bouyer }
518 1.27.2.2 bouyer break;
519 1.27.2.2 bouyer case SIOCSIFMTU:
520 1.27.2.2 bouyer if (ifr->ifr_mtu > ETHERMTU)
521 1.27.2.2 bouyer error = EINVAL;
522 1.27.2.2 bouyer else
523 1.27.2.2 bouyer ifp->if_mtu = ifr->ifr_mtu;
524 1.27.2.2 bouyer break;
525 1.27.2.2 bouyer case SIOCS80211NWID:
526 1.27.2.2 bouyer error = copyin(ifr->ifr_data, &nwid, sizeof(nwid));
527 1.27.2.2 bouyer if (error)
528 1.27.2.2 bouyer break;
529 1.27.2.2 bouyer if (nwid.i_len > IEEE80211_NWID_LEN) {
530 1.27.2.2 bouyer error = EINVAL;
531 1.27.2.2 bouyer break;
532 1.27.2.2 bouyer }
533 1.27.2.2 bouyer if (sc->sc_mib_mac.aDesired_ESS_ID[1] == nwid.i_len &&
534 1.27.2.2 bouyer memcmp(&sc->sc_mib_mac.aDesired_ESS_ID[2], nwid.i_nwid,
535 1.27.2.2 bouyer nwid.i_len) == 0)
536 1.27.2.2 bouyer break;
537 1.27.2.2 bouyer memset(sc->sc_mib_mac.aDesired_ESS_ID, 0, AWI_ESS_ID_SIZE);
538 1.27.2.2 bouyer sc->sc_mib_mac.aDesired_ESS_ID[0] = IEEE80211_ELEMID_SSID;
539 1.27.2.2 bouyer sc->sc_mib_mac.aDesired_ESS_ID[1] = nwid.i_len;
540 1.27.2.2 bouyer memcpy(&sc->sc_mib_mac.aDesired_ESS_ID[2], nwid.i_nwid,
541 1.27.2.2 bouyer nwid.i_len);
542 1.27.2.2 bouyer if (sc->sc_enabled) {
543 1.27.2.2 bouyer awi_stop(sc);
544 1.27.2.2 bouyer error = awi_init(sc);
545 1.27.2.2 bouyer }
546 1.27.2.2 bouyer break;
547 1.27.2.2 bouyer case SIOCG80211NWID:
548 1.27.2.2 bouyer if (ifp->if_flags & IFF_RUNNING)
549 1.27.2.2 bouyer p = sc->sc_bss.essid;
550 1.27.2.2 bouyer else
551 1.27.2.2 bouyer p = sc->sc_mib_mac.aDesired_ESS_ID;
552 1.27.2.2 bouyer error = copyout(p + 1, ifr->ifr_data, 1 + IEEE80211_NWID_LEN);
553 1.27.2.2 bouyer break;
554 1.27.2.2 bouyer case SIOCS80211NWKEY:
555 1.27.2.2 bouyer error = awi_wep_setnwkey(sc, (struct ieee80211_nwkey *)data);
556 1.27.2.2 bouyer break;
557 1.27.2.2 bouyer case SIOCG80211NWKEY:
558 1.27.2.2 bouyer error = awi_wep_getnwkey(sc, (struct ieee80211_nwkey *)data);
559 1.27.2.2 bouyer break;
560 1.27.2.2 bouyer #ifdef IFM_IEEE80211
561 1.27.2.2 bouyer case SIOCSIFMEDIA:
562 1.27.2.2 bouyer case SIOCGIFMEDIA:
563 1.27.2.2 bouyer error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
564 1.27.2.2 bouyer break;
565 1.27.2.2 bouyer #endif
566 1.27.2.2 bouyer default:
567 1.27.2.2 bouyer error = awi_wicfg(ifp, cmd, data);
568 1.27.2.2 bouyer break;
569 1.27.2.2 bouyer }
570 1.27.2.2 bouyer awi_unlock(sc);
571 1.27.2.2 bouyer cantlock:
572 1.27.2.2 bouyer splx(s);
573 1.27.2.2 bouyer return error;
574 1.27.2.2 bouyer }
575 1.27.2.2 bouyer
576 1.27.2.2 bouyer #ifdef IFM_IEEE80211
577 1.27.2.2 bouyer static int
578 1.27.2.2 bouyer awi_media_rate2opt(sc, rate)
579 1.27.2.2 bouyer struct awi_softc *sc;
580 1.27.2.2 bouyer int rate;
581 1.27.2.2 bouyer {
582 1.27.2.2 bouyer int mword;
583 1.27.2.2 bouyer
584 1.27.2.2 bouyer mword = 0;
585 1.27.2.2 bouyer switch (rate) {
586 1.27.2.2 bouyer case 10:
587 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH)
588 1.27.2.2 bouyer mword = IFM_IEEE80211_FH1;
589 1.27.2.2 bouyer else
590 1.27.2.2 bouyer mword = IFM_IEEE80211_DS1;
591 1.27.2.2 bouyer break;
592 1.27.2.2 bouyer case 20:
593 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH)
594 1.27.2.2 bouyer mword = IFM_IEEE80211_FH2;
595 1.27.2.2 bouyer else
596 1.27.2.2 bouyer mword = IFM_IEEE80211_DS2;
597 1.27.2.2 bouyer break;
598 1.27.2.2 bouyer case 55:
599 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_DS)
600 1.27.2.2 bouyer mword = IFM_IEEE80211_DS5;
601 1.27.2.2 bouyer break;
602 1.27.2.2 bouyer case 110:
603 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_DS)
604 1.27.2.2 bouyer mword = IFM_IEEE80211_DS11;
605 1.27.2.2 bouyer break;
606 1.27.2.2 bouyer }
607 1.27.2.2 bouyer return mword;
608 1.27.2.2 bouyer }
609 1.27.2.2 bouyer
610 1.27.2.2 bouyer static int
611 1.27.2.2 bouyer awi_media_opt2rate(sc, opt)
612 1.27.2.2 bouyer struct awi_softc *sc;
613 1.27.2.2 bouyer int opt;
614 1.27.2.2 bouyer {
615 1.27.2.2 bouyer int rate;
616 1.27.2.2 bouyer
617 1.27.2.2 bouyer rate = 0;
618 1.27.2.2 bouyer switch (IFM_SUBTYPE(opt)) {
619 1.27.2.2 bouyer case IFM_IEEE80211_FH1:
620 1.27.2.2 bouyer case IFM_IEEE80211_FH2:
621 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type != AWI_PHY_TYPE_FH)
622 1.27.2.2 bouyer return 0;
623 1.27.2.2 bouyer break;
624 1.27.2.2 bouyer case IFM_IEEE80211_DS1:
625 1.27.2.2 bouyer case IFM_IEEE80211_DS2:
626 1.27.2.2 bouyer case IFM_IEEE80211_DS5:
627 1.27.2.2 bouyer case IFM_IEEE80211_DS11:
628 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type != AWI_PHY_TYPE_DS)
629 1.27.2.2 bouyer return 0;
630 1.27.2.2 bouyer break;
631 1.27.2.2 bouyer }
632 1.27.2.2 bouyer
633 1.27.2.2 bouyer switch (IFM_SUBTYPE(opt)) {
634 1.27.2.2 bouyer case IFM_IEEE80211_FH1:
635 1.27.2.2 bouyer case IFM_IEEE80211_DS1:
636 1.27.2.2 bouyer rate = 10;
637 1.27.2.2 bouyer break;
638 1.27.2.2 bouyer case IFM_IEEE80211_FH2:
639 1.27.2.2 bouyer case IFM_IEEE80211_DS2:
640 1.27.2.2 bouyer rate = 20;
641 1.27.2.2 bouyer break;
642 1.27.2.2 bouyer case IFM_IEEE80211_DS5:
643 1.27.2.2 bouyer rate = 55;
644 1.27.2.2 bouyer break;
645 1.27.2.2 bouyer case IFM_IEEE80211_DS11:
646 1.27.2.2 bouyer rate = 110;
647 1.27.2.2 bouyer break;
648 1.27.2.2 bouyer }
649 1.27.2.2 bouyer return rate;
650 1.27.2.2 bouyer }
651 1.27.2.2 bouyer
652 1.27.2.2 bouyer /*
653 1.27.2.2 bouyer * Called from ifmedia_ioctl via awi_ioctl with lock obtained.
654 1.27.2.2 bouyer */
655 1.27.2.2 bouyer static int
656 1.27.2.2 bouyer awi_media_change(ifp)
657 1.27.2.2 bouyer struct ifnet *ifp;
658 1.27.2.2 bouyer {
659 1.27.2.2 bouyer struct awi_softc *sc = ifp->if_softc;
660 1.27.2.2 bouyer struct ifmedia_entry *ime;
661 1.27.2.2 bouyer u_int8_t *phy_rates;
662 1.27.2.2 bouyer int i, rate, error;
663 1.27.2.2 bouyer
664 1.27.2.2 bouyer error = 0;
665 1.27.2.2 bouyer ime = sc->sc_media.ifm_cur;
666 1.27.2.2 bouyer rate = awi_media_opt2rate(sc, ime->ifm_media);
667 1.27.2.2 bouyer if (rate == 0)
668 1.27.2.2 bouyer return EINVAL;
669 1.27.2.2 bouyer if (rate != sc->sc_tx_rate) {
670 1.27.2.2 bouyer phy_rates = sc->sc_mib_phy.aSuprt_Data_Rates;
671 1.27.2.2 bouyer for (i = 0; i < phy_rates[1]; i++) {
672 1.27.2.2 bouyer if (rate == AWI_80211_RATE(phy_rates[2 + i]))
673 1.27.2.2 bouyer break;
674 1.27.2.2 bouyer }
675 1.27.2.2 bouyer if (i == phy_rates[1])
676 1.27.2.2 bouyer return EINVAL;
677 1.27.2.2 bouyer }
678 1.27.2.2 bouyer if (ime->ifm_media & IFM_IEEE80211_ADHOC) {
679 1.27.2.2 bouyer sc->sc_mib_local.Network_Mode = 0;
680 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH)
681 1.27.2.2 bouyer sc->sc_no_bssid = 0;
682 1.27.2.2 bouyer else
683 1.27.2.2 bouyer sc->sc_no_bssid = (ime->ifm_media & IFM_FLAG0) ? 1 : 0;
684 1.27.2.2 bouyer } else {
685 1.27.2.2 bouyer sc->sc_mib_local.Network_Mode = 1;
686 1.27.2.2 bouyer }
687 1.27.2.2 bouyer if (sc->sc_enabled) {
688 1.27.2.2 bouyer awi_stop(sc);
689 1.27.2.2 bouyer error = awi_init(sc);
690 1.27.2.2 bouyer }
691 1.27.2.2 bouyer return error;
692 1.27.2.2 bouyer }
693 1.27.2.2 bouyer
694 1.27.2.2 bouyer static void
695 1.27.2.2 bouyer awi_media_status(ifp, imr)
696 1.27.2.2 bouyer struct ifnet *ifp;
697 1.27.2.2 bouyer struct ifmediareq *imr;
698 1.27.2.2 bouyer {
699 1.27.2.2 bouyer struct awi_softc *sc = ifp->if_softc;
700 1.27.2.2 bouyer
701 1.27.2.2 bouyer imr->ifm_status = IFM_AVALID;
702 1.27.2.2 bouyer if (ifp->if_flags & IFF_RUNNING)
703 1.27.2.2 bouyer imr->ifm_status |= IFM_ACTIVE;
704 1.27.2.2 bouyer imr->ifm_active = IFM_IEEE80211;
705 1.27.2.2 bouyer imr->ifm_active |= awi_media_rate2opt(sc, sc->sc_tx_rate);
706 1.27.2.2 bouyer if (sc->sc_mib_local.Network_Mode == 0) {
707 1.27.2.2 bouyer imr->ifm_active |= IFM_IEEE80211_ADHOC;
708 1.27.2.2 bouyer if (sc->sc_no_bssid)
709 1.27.2.2 bouyer imr->ifm_active |= IFM_FLAG0;
710 1.27.2.2 bouyer }
711 1.27.2.2 bouyer }
712 1.27.2.2 bouyer #endif /* IFM_IEEE80211 */
713 1.27.2.2 bouyer
714 1.27.2.2 bouyer int
715 1.27.2.2 bouyer awi_intr(arg)
716 1.27.2.2 bouyer void *arg;
717 1.27.2.2 bouyer {
718 1.27.2.2 bouyer struct awi_softc *sc = arg;
719 1.27.2.2 bouyer u_int16_t status;
720 1.27.2.2 bouyer int error, handled = 0, ocansleep;
721 1.27.2.2 bouyer
722 1.27.2.2 bouyer if (!sc->sc_enabled || !sc->sc_enab_intr || sc->sc_invalid)
723 1.27.2.2 bouyer return 0;
724 1.27.2.2 bouyer
725 1.27.2.2 bouyer am79c930_gcr_setbits(&sc->sc_chip,
726 1.27.2.2 bouyer AM79C930_GCR_DISPWDN | AM79C930_GCR_ECINT);
727 1.27.2.2 bouyer awi_write_1(sc, AWI_DIS_PWRDN, 1);
728 1.27.2.2 bouyer ocansleep = sc->sc_cansleep;
729 1.27.2.2 bouyer sc->sc_cansleep = 0;
730 1.27.2.2 bouyer
731 1.27.2.2 bouyer for (;;) {
732 1.27.2.2 bouyer error = awi_intr_lock(sc);
733 1.27.2.2 bouyer if (error)
734 1.27.2.2 bouyer break;
735 1.27.2.2 bouyer status = awi_read_1(sc, AWI_INTSTAT);
736 1.27.2.2 bouyer awi_write_1(sc, AWI_INTSTAT, 0);
737 1.27.2.2 bouyer awi_write_1(sc, AWI_INTSTAT, 0);
738 1.27.2.2 bouyer status |= awi_read_1(sc, AWI_INTSTAT2) << 8;
739 1.27.2.2 bouyer awi_write_1(sc, AWI_INTSTAT2, 0);
740 1.27.2.2 bouyer DELAY(10);
741 1.27.2.2 bouyer awi_intr_unlock(sc);
742 1.27.2.2 bouyer if (!sc->sc_cmd_inprog)
743 1.27.2.2 bouyer status &= ~AWI_INT_CMD; /* make sure */
744 1.27.2.2 bouyer if (status == 0)
745 1.27.2.2 bouyer break;
746 1.27.2.2 bouyer handled = 1;
747 1.27.2.2 bouyer if (status & AWI_INT_RX)
748 1.27.2.2 bouyer awi_rxint(sc);
749 1.27.2.2 bouyer if (status & AWI_INT_TX)
750 1.27.2.2 bouyer awi_txint(sc);
751 1.27.2.2 bouyer if (status & AWI_INT_CMD)
752 1.27.2.2 bouyer awi_cmd_done(sc);
753 1.27.2.2 bouyer if (status & AWI_INT_SCAN_CMPLT) {
754 1.27.2.2 bouyer if (sc->sc_status == AWI_ST_SCAN &&
755 1.27.2.2 bouyer sc->sc_mgt_timer > 0)
756 1.27.2.2 bouyer (void)awi_next_scan(sc);
757 1.27.2.2 bouyer }
758 1.27.2.2 bouyer }
759 1.27.2.2 bouyer sc->sc_cansleep = ocansleep;
760 1.27.2.2 bouyer am79c930_gcr_clearbits(&sc->sc_chip, AM79C930_GCR_DISPWDN);
761 1.27.2.2 bouyer awi_write_1(sc, AWI_DIS_PWRDN, 0);
762 1.27.2.2 bouyer return handled;
763 1.27.2.2 bouyer }
764 1.27.2.2 bouyer
765 1.27.2.2 bouyer int
766 1.27.2.2 bouyer awi_init(sc)
767 1.27.2.2 bouyer struct awi_softc *sc;
768 1.27.2.2 bouyer {
769 1.27.2.2 bouyer int error, ostatus;
770 1.27.2.2 bouyer int n;
771 1.27.2.2 bouyer struct ifnet *ifp = sc->sc_ifp;
772 1.27.2.2 bouyer #ifdef __FreeBSD__
773 1.27.2.2 bouyer struct ifmultiaddr *ifma;
774 1.27.2.2 bouyer #else
775 1.27.2.2 bouyer struct ether_multi *enm;
776 1.27.2.2 bouyer struct ether_multistep step;
777 1.27.2.2 bouyer #endif
778 1.27.2.2 bouyer
779 1.27.2.2 bouyer /* reinitialize muticast filter */
780 1.27.2.2 bouyer n = 0;
781 1.27.2.2 bouyer ifp->if_flags |= IFF_ALLMULTI;
782 1.27.2.2 bouyer sc->sc_mib_local.Accept_All_Multicast_Dis = 0;
783 1.27.2.2 bouyer if (ifp->if_flags & IFF_PROMISC) {
784 1.27.2.2 bouyer sc->sc_mib_mac.aPromiscuous_Enable = 1;
785 1.27.2.2 bouyer goto set_mib;
786 1.27.2.2 bouyer }
787 1.27.2.2 bouyer sc->sc_mib_mac.aPromiscuous_Enable = 0;
788 1.27.2.2 bouyer #ifdef __FreeBSD__
789 1.27.2.2 bouyer if (ifp->if_amcount != 0)
790 1.27.2.2 bouyer goto set_mib;
791 1.27.2.2 bouyer for (ifma = LIST_FIRST(&ifp->if_multiaddrs); ifma != NULL;
792 1.27.2.2 bouyer ifma = LIST_NEXT(ifma, ifma_link)) {
793 1.27.2.2 bouyer if (ifma->ifma_addr->sa_family != AF_LINK)
794 1.27.2.2 bouyer continue;
795 1.27.2.2 bouyer if (n == AWI_GROUP_ADDR_SIZE)
796 1.27.2.2 bouyer goto set_mib;
797 1.27.2.2 bouyer memcpy(sc->sc_mib_addr.aGroup_Addresses[n],
798 1.27.2.2 bouyer LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
799 1.27.2.2 bouyer ETHER_ADDR_LEN);
800 1.27.2.2 bouyer n++;
801 1.27.2.2 bouyer }
802 1.27.2.2 bouyer #else
803 1.27.2.2 bouyer ETHER_FIRST_MULTI(step, &sc->sc_ec, enm);
804 1.27.2.2 bouyer while (enm != NULL) {
805 1.27.2.2 bouyer if (n == AWI_GROUP_ADDR_SIZE ||
806 1.27.2.2 bouyer memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)
807 1.27.2.2 bouyer != 0)
808 1.27.2.2 bouyer goto set_mib;
809 1.27.2.2 bouyer memcpy(sc->sc_mib_addr.aGroup_Addresses[n], enm->enm_addrlo,
810 1.27.2.2 bouyer ETHER_ADDR_LEN);
811 1.27.2.2 bouyer n++;
812 1.27.2.2 bouyer ETHER_NEXT_MULTI(step, enm);
813 1.27.2.2 bouyer }
814 1.27.2.2 bouyer #endif
815 1.27.2.2 bouyer for (; n < AWI_GROUP_ADDR_SIZE; n++)
816 1.27.2.2 bouyer memset(sc->sc_mib_addr.aGroup_Addresses[n], 0, ETHER_ADDR_LEN);
817 1.27.2.2 bouyer ifp->if_flags &= ~IFF_ALLMULTI;
818 1.27.2.2 bouyer sc->sc_mib_local.Accept_All_Multicast_Dis = 1;
819 1.27.2.2 bouyer
820 1.27.2.2 bouyer set_mib:
821 1.27.2.2 bouyer #ifdef notdef /* allow non-encrypted frame for receiving. */
822 1.27.2.2 bouyer sc->sc_mib_mgt.Wep_Required = sc->sc_wep_algo != NULL ? 1 : 0;
823 1.27.2.2 bouyer #endif
824 1.27.2.2 bouyer if (!sc->sc_enabled) {
825 1.27.2.2 bouyer sc->sc_enabled = 1;
826 1.27.2.2 bouyer if (sc->sc_enable)
827 1.27.2.2 bouyer (*sc->sc_enable)(sc);
828 1.27.2.2 bouyer sc->sc_status = AWI_ST_INIT;
829 1.27.2.2 bouyer error = awi_init_hw(sc);
830 1.27.2.2 bouyer if (error)
831 1.27.2.2 bouyer return error;
832 1.27.2.2 bouyer }
833 1.27.2.2 bouyer ostatus = sc->sc_status;
834 1.27.2.2 bouyer sc->sc_status = AWI_ST_INIT;
835 1.27.2.2 bouyer if ((error = awi_mib(sc, AWI_CMD_SET_MIB, AWI_MIB_LOCAL)) != 0 ||
836 1.27.2.2 bouyer (error = awi_mib(sc, AWI_CMD_SET_MIB, AWI_MIB_ADDR)) != 0 ||
837 1.27.2.2 bouyer (error = awi_mib(sc, AWI_CMD_SET_MIB, AWI_MIB_MAC)) != 0 ||
838 1.27.2.2 bouyer (error = awi_mib(sc, AWI_CMD_SET_MIB, AWI_MIB_MGT)) != 0 ||
839 1.27.2.2 bouyer (error = awi_mib(sc, AWI_CMD_SET_MIB, AWI_MIB_PHY)) != 0) {
840 1.27.2.2 bouyer awi_stop(sc);
841 1.27.2.2 bouyer return error;
842 1.27.2.2 bouyer }
843 1.27.2.2 bouyer if (ifp->if_flags & IFF_RUNNING)
844 1.27.2.2 bouyer sc->sc_status = AWI_ST_RUNNING;
845 1.27.2.2 bouyer else {
846 1.27.2.2 bouyer if (ostatus == AWI_ST_INIT) {
847 1.27.2.2 bouyer error = awi_init_txrx(sc);
848 1.27.2.2 bouyer if (error)
849 1.27.2.2 bouyer return error;
850 1.27.2.2 bouyer }
851 1.27.2.2 bouyer error = awi_start_scan(sc);
852 1.27.2.2 bouyer }
853 1.27.2.2 bouyer return error;
854 1.27.2.2 bouyer }
855 1.27.2.2 bouyer
856 1.27.2.2 bouyer void
857 1.27.2.2 bouyer awi_stop(sc)
858 1.27.2.2 bouyer struct awi_softc *sc;
859 1.27.2.2 bouyer {
860 1.27.2.2 bouyer struct ifnet *ifp = sc->sc_ifp;
861 1.27.2.2 bouyer struct awi_bss *bp;
862 1.27.2.2 bouyer
863 1.27.2.2 bouyer sc->sc_status = AWI_ST_INIT;
864 1.27.2.2 bouyer if (!sc->sc_invalid) {
865 1.27.2.2 bouyer (void)awi_cmd_wait(sc);
866 1.27.2.2 bouyer if (sc->sc_mib_local.Network_Mode &&
867 1.27.2.2 bouyer sc->sc_status > AWI_ST_AUTH)
868 1.27.2.2 bouyer awi_send_deauth(sc);
869 1.27.2.2 bouyer awi_stop_txrx(sc);
870 1.27.2.2 bouyer }
871 1.27.2.2 bouyer ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
872 1.27.2.2 bouyer ifp->if_timer = 0;
873 1.27.2.2 bouyer sc->sc_tx_timer = sc->sc_rx_timer = sc->sc_mgt_timer = 0;
874 1.27.2.5 bouyer IF_PURGE(&sc->sc_mgtq);
875 1.27.2.5 bouyer IFQ_PURGE(&ifp->if_snd);
876 1.27.2.2 bouyer while ((bp = TAILQ_FIRST(&sc->sc_scan)) != NULL) {
877 1.27.2.2 bouyer TAILQ_REMOVE(&sc->sc_scan, bp, list);
878 1.27.2.2 bouyer free(bp, M_DEVBUF);
879 1.27.2.2 bouyer }
880 1.27.2.2 bouyer }
881 1.27.2.2 bouyer
882 1.27.2.2 bouyer static void
883 1.27.2.2 bouyer awi_watchdog(ifp)
884 1.27.2.2 bouyer struct ifnet *ifp;
885 1.27.2.2 bouyer {
886 1.27.2.2 bouyer struct awi_softc *sc = ifp->if_softc;
887 1.27.2.2 bouyer int ocansleep;
888 1.27.2.2 bouyer
889 1.27.2.2 bouyer if (sc->sc_invalid) {
890 1.27.2.2 bouyer ifp->if_timer = 0;
891 1.27.2.2 bouyer return;
892 1.27.2.2 bouyer }
893 1.27.2.2 bouyer
894 1.27.2.2 bouyer ocansleep = sc->sc_cansleep;
895 1.27.2.2 bouyer sc->sc_cansleep = 0;
896 1.27.2.2 bouyer if (sc->sc_tx_timer && --sc->sc_tx_timer == 0) {
897 1.27.2.2 bouyer printf("%s: transmit timeout\n", sc->sc_dev.dv_xname);
898 1.27.2.2 bouyer awi_txint(sc);
899 1.27.2.2 bouyer }
900 1.27.2.2 bouyer if (sc->sc_rx_timer && --sc->sc_rx_timer == 0) {
901 1.27.2.2 bouyer if (ifp->if_flags & IFF_DEBUG) {
902 1.27.2.2 bouyer printf("%s: no recent beacons from %s; rescanning\n",
903 1.27.2.2 bouyer sc->sc_dev.dv_xname,
904 1.27.2.2 bouyer ether_sprintf(sc->sc_bss.bssid));
905 1.27.2.2 bouyer }
906 1.27.2.2 bouyer ifp->if_flags &= ~IFF_RUNNING;
907 1.27.2.2 bouyer awi_start_scan(sc);
908 1.27.2.2 bouyer }
909 1.27.2.2 bouyer if (sc->sc_mgt_timer && --sc->sc_mgt_timer == 0) {
910 1.27.2.2 bouyer switch (sc->sc_status) {
911 1.27.2.2 bouyer case AWI_ST_SCAN:
912 1.27.2.2 bouyer awi_stop_scan(sc);
913 1.27.2.2 bouyer break;
914 1.27.2.2 bouyer case AWI_ST_AUTH:
915 1.27.2.2 bouyer case AWI_ST_ASSOC:
916 1.27.2.2 bouyer /* restart scan */
917 1.27.2.2 bouyer awi_start_scan(sc);
918 1.27.2.2 bouyer break;
919 1.27.2.2 bouyer default:
920 1.27.2.2 bouyer break;
921 1.27.2.2 bouyer }
922 1.27.2.2 bouyer }
923 1.27.2.2 bouyer
924 1.27.2.2 bouyer if (sc->sc_tx_timer == 0 && sc->sc_rx_timer == 0 &&
925 1.27.2.2 bouyer sc->sc_mgt_timer == 0)
926 1.27.2.2 bouyer ifp->if_timer = 0;
927 1.27.2.2 bouyer else
928 1.27.2.2 bouyer ifp->if_timer = 1;
929 1.27.2.2 bouyer sc->sc_cansleep = ocansleep;
930 1.27.2.2 bouyer }
931 1.27.2.2 bouyer
932 1.27.2.2 bouyer static void
933 1.27.2.2 bouyer awi_start(ifp)
934 1.27.2.2 bouyer struct ifnet *ifp;
935 1.27.2.2 bouyer {
936 1.27.2.2 bouyer struct awi_softc *sc = ifp->if_softc;
937 1.27.2.2 bouyer struct mbuf *m0, *m;
938 1.27.2.2 bouyer u_int32_t txd, frame, ntxd;
939 1.27.2.2 bouyer u_int8_t rate;
940 1.27.2.2 bouyer int len, sent = 0;
941 1.27.2.2 bouyer
942 1.27.2.2 bouyer for (;;) {
943 1.27.2.2 bouyer txd = sc->sc_txnext;
944 1.27.2.5 bouyer IF_POLL(&sc->sc_mgtq, m0);
945 1.27.2.2 bouyer if (m0 != NULL) {
946 1.27.2.2 bouyer if (awi_next_txd(sc, m0->m_pkthdr.len, &frame, &ntxd)) {
947 1.27.2.2 bouyer ifp->if_flags |= IFF_OACTIVE;
948 1.27.2.2 bouyer break;
949 1.27.2.2 bouyer }
950 1.27.2.5 bouyer IF_DEQUEUE(&sc->sc_mgtq, m0);
951 1.27.2.2 bouyer } else {
952 1.27.2.2 bouyer if (!(ifp->if_flags & IFF_RUNNING))
953 1.27.2.2 bouyer break;
954 1.27.2.5 bouyer IFQ_POLL(&ifp->if_snd, m0);
955 1.27.2.2 bouyer if (m0 == NULL)
956 1.27.2.2 bouyer break;
957 1.27.2.2 bouyer len = m0->m_pkthdr.len + sizeof(struct ieee80211_frame);
958 1.27.2.2 bouyer if (sc->sc_format_llc)
959 1.27.2.2 bouyer len += sizeof(struct llc) -
960 1.27.2.2 bouyer sizeof(struct ether_header);
961 1.27.2.2 bouyer if (sc->sc_wep_algo != NULL)
962 1.27.2.2 bouyer len += IEEE80211_WEP_IVLEN +
963 1.27.2.2 bouyer IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN;
964 1.27.2.2 bouyer if (awi_next_txd(sc, len, &frame, &ntxd)) {
965 1.27.2.2 bouyer ifp->if_flags |= IFF_OACTIVE;
966 1.27.2.2 bouyer break;
967 1.27.2.2 bouyer }
968 1.27.2.5 bouyer IFQ_DEQUEUE(&ifp->if_snd, m0);
969 1.27.2.2 bouyer AWI_BPF_MTAP(sc, m0, AWI_BPF_NORM);
970 1.27.2.2 bouyer m0 = awi_fix_txhdr(sc, m0);
971 1.27.2.2 bouyer if (sc->sc_wep_algo != NULL && m0 != NULL)
972 1.27.2.2 bouyer m0 = awi_wep_encrypt(sc, m0, 1);
973 1.27.2.2 bouyer if (m0 == NULL) {
974 1.27.2.2 bouyer ifp->if_oerrors++;
975 1.27.2.2 bouyer continue;
976 1.27.2.2 bouyer }
977 1.27.2.2 bouyer ifp->if_opackets++;
978 1.27.2.2 bouyer }
979 1.27.2.2 bouyer #ifdef AWI_DEBUG
980 1.27.2.2 bouyer if (awi_dump)
981 1.27.2.2 bouyer awi_dump_pkt(sc, m0, -1);
982 1.27.2.2 bouyer #endif
983 1.27.2.2 bouyer AWI_BPF_MTAP(sc, m0, AWI_BPF_RAW);
984 1.27.2.2 bouyer len = 0;
985 1.27.2.2 bouyer for (m = m0; m != NULL; m = m->m_next) {
986 1.27.2.2 bouyer awi_write_bytes(sc, frame + len, mtod(m, u_int8_t *),
987 1.27.2.2 bouyer m->m_len);
988 1.27.2.2 bouyer len += m->m_len;
989 1.27.2.2 bouyer }
990 1.27.2.2 bouyer m_freem(m0);
991 1.27.2.2 bouyer rate = sc->sc_tx_rate; /*XXX*/
992 1.27.2.2 bouyer awi_write_1(sc, ntxd + AWI_TXD_STATE, 0);
993 1.27.2.2 bouyer awi_write_4(sc, txd + AWI_TXD_START, frame);
994 1.27.2.2 bouyer awi_write_4(sc, txd + AWI_TXD_NEXT, ntxd);
995 1.27.2.2 bouyer awi_write_4(sc, txd + AWI_TXD_LENGTH, len);
996 1.27.2.2 bouyer awi_write_1(sc, txd + AWI_TXD_RATE, rate);
997 1.27.2.2 bouyer awi_write_4(sc, txd + AWI_TXD_NDA, 0);
998 1.27.2.2 bouyer awi_write_4(sc, txd + AWI_TXD_NRA, 0);
999 1.27.2.2 bouyer awi_write_1(sc, txd + AWI_TXD_STATE, AWI_TXD_ST_OWN);
1000 1.27.2.2 bouyer sc->sc_txnext = ntxd;
1001 1.27.2.2 bouyer sent++;
1002 1.27.2.2 bouyer }
1003 1.27.2.2 bouyer if (sent) {
1004 1.27.2.2 bouyer if (sc->sc_tx_timer == 0)
1005 1.27.2.2 bouyer sc->sc_tx_timer = 5;
1006 1.27.2.2 bouyer ifp->if_timer = 1;
1007 1.27.2.2 bouyer #ifdef AWI_DEBUG
1008 1.27.2.2 bouyer if (awi_verbose)
1009 1.27.2.2 bouyer printf("awi_start: sent %d txdone %d txnext %d txbase %d txend %d\n", sent, sc->sc_txdone, sc->sc_txnext, sc->sc_txbase, sc->sc_txend);
1010 1.27.2.2 bouyer #endif
1011 1.27.2.2 bouyer }
1012 1.27.2.2 bouyer }
1013 1.27.2.2 bouyer
1014 1.27.2.2 bouyer static void
1015 1.27.2.2 bouyer awi_txint(sc)
1016 1.27.2.2 bouyer struct awi_softc *sc;
1017 1.27.2.2 bouyer {
1018 1.27.2.2 bouyer struct ifnet *ifp = sc->sc_ifp;
1019 1.27.2.2 bouyer u_int8_t flags;
1020 1.27.2.2 bouyer
1021 1.27.2.2 bouyer while (sc->sc_txdone != sc->sc_txnext) {
1022 1.27.2.2 bouyer flags = awi_read_1(sc, sc->sc_txdone + AWI_TXD_STATE);
1023 1.27.2.2 bouyer if ((flags & AWI_TXD_ST_OWN) || !(flags & AWI_TXD_ST_DONE))
1024 1.27.2.2 bouyer break;
1025 1.27.2.2 bouyer if (flags & AWI_TXD_ST_ERROR)
1026 1.27.2.2 bouyer ifp->if_oerrors++;
1027 1.27.2.2 bouyer sc->sc_txdone = awi_read_4(sc, sc->sc_txdone + AWI_TXD_NEXT) &
1028 1.27.2.2 bouyer 0x7fff;
1029 1.27.2.2 bouyer }
1030 1.27.2.2 bouyer sc->sc_tx_timer = 0;
1031 1.27.2.2 bouyer ifp->if_flags &= ~IFF_OACTIVE;
1032 1.27.2.2 bouyer #ifdef AWI_DEBUG
1033 1.27.2.2 bouyer if (awi_verbose)
1034 1.27.2.2 bouyer printf("awi_txint: txdone %d txnext %d txbase %d txend %d\n",
1035 1.27.2.2 bouyer sc->sc_txdone, sc->sc_txnext, sc->sc_txbase, sc->sc_txend);
1036 1.27.2.2 bouyer #endif
1037 1.27.2.2 bouyer awi_start(ifp);
1038 1.27.2.2 bouyer }
1039 1.27.2.2 bouyer
1040 1.27.2.2 bouyer static struct mbuf *
1041 1.27.2.2 bouyer awi_fix_txhdr(sc, m0)
1042 1.27.2.2 bouyer struct awi_softc *sc;
1043 1.27.2.2 bouyer struct mbuf *m0;
1044 1.27.2.2 bouyer {
1045 1.27.2.2 bouyer struct ether_header eh;
1046 1.27.2.2 bouyer struct ieee80211_frame *wh;
1047 1.27.2.2 bouyer struct llc *llc;
1048 1.27.2.2 bouyer
1049 1.27.2.2 bouyer if (m0->m_len < sizeof(eh)) {
1050 1.27.2.2 bouyer m0 = m_pullup(m0, sizeof(eh));
1051 1.27.2.2 bouyer if (m0 == NULL)
1052 1.27.2.2 bouyer return NULL;
1053 1.27.2.2 bouyer }
1054 1.27.2.2 bouyer memcpy(&eh, mtod(m0, caddr_t), sizeof(eh));
1055 1.27.2.2 bouyer if (sc->sc_format_llc) {
1056 1.27.2.2 bouyer m_adj(m0, sizeof(struct ether_header) - sizeof(struct llc));
1057 1.27.2.2 bouyer llc = mtod(m0, struct llc *);
1058 1.27.2.2 bouyer llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
1059 1.27.2.2 bouyer llc->llc_control = LLC_UI;
1060 1.27.2.2 bouyer llc->llc_snap.org_code[0] = llc->llc_snap.org_code[1] =
1061 1.27.2.2 bouyer llc->llc_snap.org_code[2] = 0;
1062 1.27.2.2 bouyer llc->llc_snap.ether_type = eh.ether_type;
1063 1.27.2.2 bouyer }
1064 1.27.2.2 bouyer M_PREPEND(m0, sizeof(struct ieee80211_frame), M_DONTWAIT);
1065 1.27.2.2 bouyer if (m0 == NULL)
1066 1.27.2.2 bouyer return NULL;
1067 1.27.2.2 bouyer wh = mtod(m0, struct ieee80211_frame *);
1068 1.27.2.2 bouyer
1069 1.27.2.2 bouyer wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_DATA;
1070 1.27.2.2 bouyer LE_WRITE_2(wh->i_dur, 0);
1071 1.27.2.2 bouyer LE_WRITE_2(wh->i_seq, 0);
1072 1.27.2.2 bouyer if (sc->sc_mib_local.Network_Mode) {
1073 1.27.2.2 bouyer wh->i_fc[1] = IEEE80211_FC1_DIR_TODS;
1074 1.27.2.2 bouyer memcpy(wh->i_addr1, sc->sc_bss.bssid, ETHER_ADDR_LEN);
1075 1.27.2.2 bouyer memcpy(wh->i_addr2, eh.ether_shost, ETHER_ADDR_LEN);
1076 1.27.2.2 bouyer memcpy(wh->i_addr3, eh.ether_dhost, ETHER_ADDR_LEN);
1077 1.27.2.2 bouyer } else {
1078 1.27.2.2 bouyer wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
1079 1.27.2.2 bouyer memcpy(wh->i_addr1, eh.ether_dhost, ETHER_ADDR_LEN);
1080 1.27.2.2 bouyer memcpy(wh->i_addr2, eh.ether_shost, ETHER_ADDR_LEN);
1081 1.27.2.2 bouyer memcpy(wh->i_addr3, sc->sc_bss.bssid, ETHER_ADDR_LEN);
1082 1.27.2.2 bouyer }
1083 1.27.2.2 bouyer return m0;
1084 1.27.2.2 bouyer }
1085 1.27.2.2 bouyer
1086 1.27.2.2 bouyer static struct mbuf *
1087 1.27.2.2 bouyer awi_fix_rxhdr(sc, m0)
1088 1.27.2.2 bouyer struct awi_softc *sc;
1089 1.27.2.2 bouyer struct mbuf *m0;
1090 1.27.2.2 bouyer {
1091 1.27.2.2 bouyer struct ieee80211_frame wh;
1092 1.27.2.2 bouyer struct ether_header *eh;
1093 1.27.2.2 bouyer struct llc *llc;
1094 1.27.2.2 bouyer
1095 1.27.2.2 bouyer if (m0->m_len < sizeof(wh)) {
1096 1.27.2.2 bouyer m_freem(m0);
1097 1.27.2.2 bouyer return NULL;
1098 1.27.2.2 bouyer }
1099 1.27.2.2 bouyer llc = (struct llc *)(mtod(m0, caddr_t) + sizeof(wh));
1100 1.27.2.2 bouyer if (llc->llc_dsap == LLC_SNAP_LSAP &&
1101 1.27.2.2 bouyer llc->llc_ssap == LLC_SNAP_LSAP &&
1102 1.27.2.2 bouyer llc->llc_control == LLC_UI &&
1103 1.27.2.2 bouyer llc->llc_snap.org_code[0] == 0 &&
1104 1.27.2.2 bouyer llc->llc_snap.org_code[1] == 0 &&
1105 1.27.2.2 bouyer llc->llc_snap.org_code[2] == 0) {
1106 1.27.2.2 bouyer memcpy(&wh, mtod(m0, caddr_t), sizeof(wh));
1107 1.27.2.2 bouyer m_adj(m0, sizeof(wh) + sizeof(*llc) - sizeof(*eh));
1108 1.27.2.2 bouyer eh = mtod(m0, struct ether_header *);
1109 1.27.2.2 bouyer switch (wh.i_fc[1] & IEEE80211_FC1_DIR_MASK) {
1110 1.27.2.2 bouyer case IEEE80211_FC1_DIR_NODS:
1111 1.27.2.2 bouyer memcpy(eh->ether_dhost, wh.i_addr1, ETHER_ADDR_LEN);
1112 1.27.2.2 bouyer memcpy(eh->ether_shost, wh.i_addr2, ETHER_ADDR_LEN);
1113 1.27.2.2 bouyer break;
1114 1.27.2.2 bouyer case IEEE80211_FC1_DIR_TODS:
1115 1.27.2.2 bouyer memcpy(eh->ether_dhost, wh.i_addr3, ETHER_ADDR_LEN);
1116 1.27.2.2 bouyer memcpy(eh->ether_shost, wh.i_addr2, ETHER_ADDR_LEN);
1117 1.27.2.2 bouyer break;
1118 1.27.2.2 bouyer case IEEE80211_FC1_DIR_FROMDS:
1119 1.27.2.2 bouyer memcpy(eh->ether_dhost, wh.i_addr1, ETHER_ADDR_LEN);
1120 1.27.2.2 bouyer memcpy(eh->ether_shost, wh.i_addr3, ETHER_ADDR_LEN);
1121 1.27.2.2 bouyer break;
1122 1.27.2.2 bouyer case IEEE80211_FC1_DIR_DSTODS:
1123 1.27.2.2 bouyer m_freem(m0);
1124 1.27.2.2 bouyer return NULL;
1125 1.27.2.2 bouyer }
1126 1.27.2.2 bouyer } else {
1127 1.27.2.2 bouyer /* assuming ethernet encapsulation, just strip 802.11 header */
1128 1.27.2.2 bouyer m_adj(m0, sizeof(wh));
1129 1.27.2.2 bouyer }
1130 1.27.2.2 bouyer if (ALIGN(mtod(m0, caddr_t) + sizeof(struct ether_header)) !=
1131 1.27.2.2 bouyer (u_int)(mtod(m0, caddr_t) + sizeof(struct ether_header))) {
1132 1.27.2.2 bouyer /* XXX: we loose to estimate the type of encapsulation */
1133 1.27.2.2 bouyer struct mbuf *n, *n0, **np;
1134 1.27.2.2 bouyer caddr_t newdata;
1135 1.27.2.2 bouyer int off;
1136 1.27.2.2 bouyer
1137 1.27.2.2 bouyer n0 = NULL;
1138 1.27.2.2 bouyer np = &n0;
1139 1.27.2.2 bouyer off = 0;
1140 1.27.2.2 bouyer while (m0->m_pkthdr.len > off) {
1141 1.27.2.2 bouyer if (n0 == NULL) {
1142 1.27.2.2 bouyer MGETHDR(n, M_DONTWAIT, MT_DATA);
1143 1.27.2.2 bouyer if (n == NULL) {
1144 1.27.2.2 bouyer m_freem(m0);
1145 1.27.2.2 bouyer return NULL;
1146 1.27.2.2 bouyer }
1147 1.27.2.2 bouyer M_COPY_PKTHDR(n, m0);
1148 1.27.2.2 bouyer n->m_len = MHLEN;
1149 1.27.2.2 bouyer } else {
1150 1.27.2.2 bouyer MGET(n, M_DONTWAIT, MT_DATA);
1151 1.27.2.2 bouyer if (n == NULL) {
1152 1.27.2.2 bouyer m_freem(m0);
1153 1.27.2.2 bouyer m_freem(n0);
1154 1.27.2.2 bouyer return NULL;
1155 1.27.2.2 bouyer }
1156 1.27.2.2 bouyer n->m_len = MLEN;
1157 1.27.2.2 bouyer }
1158 1.27.2.2 bouyer if (m0->m_pkthdr.len - off >= MINCLSIZE) {
1159 1.27.2.2 bouyer MCLGET(n, M_DONTWAIT);
1160 1.27.2.2 bouyer if (n->m_flags & M_EXT)
1161 1.27.2.2 bouyer n->m_len = n->m_ext.ext_size;
1162 1.27.2.2 bouyer }
1163 1.27.2.2 bouyer if (n0 == NULL) {
1164 1.27.2.2 bouyer newdata = (caddr_t)
1165 1.27.2.2 bouyer ALIGN(n->m_data
1166 1.27.2.2 bouyer + sizeof(struct ether_header))
1167 1.27.2.2 bouyer - sizeof(struct ether_header);
1168 1.27.2.2 bouyer n->m_len -= newdata - n->m_data;
1169 1.27.2.2 bouyer n->m_data = newdata;
1170 1.27.2.2 bouyer }
1171 1.27.2.2 bouyer if (n->m_len > m0->m_pkthdr.len - off)
1172 1.27.2.2 bouyer n->m_len = m0->m_pkthdr.len - off;
1173 1.27.2.2 bouyer m_copydata(m0, off, n->m_len, mtod(n, caddr_t));
1174 1.27.2.2 bouyer off += n->m_len;
1175 1.27.2.2 bouyer *np = n;
1176 1.27.2.2 bouyer np = &n->m_next;
1177 1.27.2.2 bouyer }
1178 1.27.2.2 bouyer m_freem(m0);
1179 1.27.2.2 bouyer m0 = n0;
1180 1.27.2.2 bouyer }
1181 1.27.2.2 bouyer return m0;
1182 1.27.2.2 bouyer }
1183 1.27.2.2 bouyer
1184 1.27.2.2 bouyer static void
1185 1.27.2.2 bouyer awi_input(sc, m, rxts, rssi)
1186 1.27.2.2 bouyer struct awi_softc *sc;
1187 1.27.2.2 bouyer struct mbuf *m;
1188 1.27.2.2 bouyer u_int32_t rxts;
1189 1.27.2.2 bouyer u_int8_t rssi;
1190 1.27.2.2 bouyer {
1191 1.27.2.2 bouyer struct ifnet *ifp = sc->sc_ifp;
1192 1.27.2.2 bouyer struct ieee80211_frame *wh;
1193 1.27.2.2 bouyer #ifndef __NetBSD__
1194 1.27.2.2 bouyer struct ether_header *eh;
1195 1.27.2.2 bouyer #endif
1196 1.27.2.2 bouyer
1197 1.27.2.2 bouyer /* trim CRC here for WEP can find its own CRC at the end of packet. */
1198 1.27.2.2 bouyer m_adj(m, -ETHER_CRC_LEN);
1199 1.27.2.2 bouyer AWI_BPF_MTAP(sc, m, AWI_BPF_RAW);
1200 1.27.2.2 bouyer wh = mtod(m, struct ieee80211_frame *);
1201 1.27.2.2 bouyer if ((wh->i_fc[0] & IEEE80211_FC0_VERSION_MASK) !=
1202 1.27.2.2 bouyer IEEE80211_FC0_VERSION_0) {
1203 1.27.2.2 bouyer printf("%s; receive packet with wrong version: %x\n",
1204 1.27.2.2 bouyer sc->sc_dev.dv_xname, wh->i_fc[0]);
1205 1.27.2.2 bouyer m_freem(m);
1206 1.27.2.2 bouyer ifp->if_ierrors++;
1207 1.27.2.2 bouyer return;
1208 1.27.2.2 bouyer }
1209 1.27.2.2 bouyer if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
1210 1.27.2.2 bouyer m = awi_wep_encrypt(sc, m, 0);
1211 1.27.2.2 bouyer if (m == NULL) {
1212 1.27.2.2 bouyer ifp->if_ierrors++;
1213 1.27.2.2 bouyer return;
1214 1.27.2.2 bouyer }
1215 1.27.2.2 bouyer wh = mtod(m, struct ieee80211_frame *);
1216 1.27.2.2 bouyer }
1217 1.27.2.2 bouyer #ifdef AWI_DEBUG
1218 1.27.2.2 bouyer if (awi_dump)
1219 1.27.2.2 bouyer awi_dump_pkt(sc, m, rssi);
1220 1.27.2.2 bouyer #endif
1221 1.27.2.2 bouyer
1222 1.27.2.2 bouyer if ((sc->sc_mib_local.Network_Mode || !sc->sc_no_bssid) &&
1223 1.27.2.2 bouyer sc->sc_status == AWI_ST_RUNNING) {
1224 1.27.2.2 bouyer if (memcmp(wh->i_addr2, sc->sc_bss.bssid, ETHER_ADDR_LEN) == 0) {
1225 1.27.2.2 bouyer sc->sc_rx_timer = 10;
1226 1.27.2.2 bouyer sc->sc_bss.rssi = rssi;
1227 1.27.2.2 bouyer }
1228 1.27.2.2 bouyer }
1229 1.27.2.2 bouyer switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) {
1230 1.27.2.2 bouyer case IEEE80211_FC0_TYPE_DATA:
1231 1.27.2.2 bouyer if (sc->sc_mib_local.Network_Mode) {
1232 1.27.2.2 bouyer if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) !=
1233 1.27.2.2 bouyer IEEE80211_FC1_DIR_FROMDS) {
1234 1.27.2.2 bouyer m_freem(m);
1235 1.27.2.2 bouyer return;
1236 1.27.2.2 bouyer }
1237 1.27.2.2 bouyer } else {
1238 1.27.2.2 bouyer if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) !=
1239 1.27.2.2 bouyer IEEE80211_FC1_DIR_NODS) {
1240 1.27.2.2 bouyer m_freem(m);
1241 1.27.2.2 bouyer return;
1242 1.27.2.2 bouyer }
1243 1.27.2.2 bouyer }
1244 1.27.2.2 bouyer m = awi_fix_rxhdr(sc, m);
1245 1.27.2.2 bouyer if (m == NULL) {
1246 1.27.2.2 bouyer ifp->if_ierrors++;
1247 1.27.2.2 bouyer break;
1248 1.27.2.2 bouyer }
1249 1.27.2.2 bouyer ifp->if_ipackets++;
1250 1.27.2.2 bouyer #if !(defined(__FreeBSD__) && __FreeBSD__ >= 4)
1251 1.27.2.2 bouyer AWI_BPF_MTAP(sc, m, AWI_BPF_NORM);
1252 1.27.2.2 bouyer #endif
1253 1.27.2.2 bouyer #ifdef __NetBSD__
1254 1.27.2.2 bouyer (*ifp->if_input)(ifp, m);
1255 1.27.2.2 bouyer #else
1256 1.27.2.2 bouyer eh = mtod(m, struct ether_header *);
1257 1.27.2.2 bouyer m_adj(m, sizeof(*eh));
1258 1.27.2.2 bouyer ether_input(ifp, eh, m);
1259 1.27.2.2 bouyer #endif
1260 1.27.2.2 bouyer break;
1261 1.27.2.2 bouyer case IEEE80211_FC0_TYPE_MGT:
1262 1.27.2.2 bouyer if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) !=
1263 1.27.2.2 bouyer IEEE80211_FC1_DIR_NODS) {
1264 1.27.2.2 bouyer m_freem(m);
1265 1.27.2.2 bouyer return;
1266 1.27.2.2 bouyer }
1267 1.27.2.2 bouyer switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
1268 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
1269 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_BEACON:
1270 1.27.2.2 bouyer awi_recv_beacon(sc, m, rxts, rssi);
1271 1.27.2.2 bouyer break;
1272 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_AUTH:
1273 1.27.2.2 bouyer awi_recv_auth(sc, m);
1274 1.27.2.2 bouyer break;
1275 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
1276 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_REASSOC_RESP:
1277 1.27.2.2 bouyer awi_recv_asresp(sc, m);
1278 1.27.2.2 bouyer break;
1279 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_DEAUTH:
1280 1.27.2.2 bouyer if (sc->sc_mib_local.Network_Mode)
1281 1.27.2.2 bouyer awi_send_auth(sc, 1);
1282 1.27.2.2 bouyer break;
1283 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_DISASSOC:
1284 1.27.2.2 bouyer if (sc->sc_mib_local.Network_Mode)
1285 1.27.2.2 bouyer awi_send_asreq(sc, 1);
1286 1.27.2.2 bouyer break;
1287 1.27.2.2 bouyer }
1288 1.27.2.2 bouyer m_freem(m);
1289 1.27.2.2 bouyer break;
1290 1.27.2.2 bouyer case IEEE80211_FC0_TYPE_CTL:
1291 1.27.2.2 bouyer default:
1292 1.27.2.2 bouyer /* should not come here */
1293 1.27.2.2 bouyer m_freem(m);
1294 1.27.2.2 bouyer break;
1295 1.27.2.2 bouyer }
1296 1.27.2.2 bouyer }
1297 1.27.2.2 bouyer
1298 1.27.2.2 bouyer static void
1299 1.27.2.2 bouyer awi_rxint(sc)
1300 1.27.2.2 bouyer struct awi_softc *sc;
1301 1.27.2.2 bouyer {
1302 1.27.2.2 bouyer u_int8_t state, rate, rssi;
1303 1.27.2.2 bouyer u_int16_t len;
1304 1.27.2.2 bouyer u_int32_t frame, next, rxts, rxoff;
1305 1.27.2.2 bouyer struct mbuf *m;
1306 1.27.2.2 bouyer
1307 1.27.2.2 bouyer rxoff = sc->sc_rxdoff;
1308 1.27.2.2 bouyer for (;;) {
1309 1.27.2.2 bouyer state = awi_read_1(sc, rxoff + AWI_RXD_HOST_DESC_STATE);
1310 1.27.2.2 bouyer if (state & AWI_RXD_ST_OWN)
1311 1.27.2.2 bouyer break;
1312 1.27.2.2 bouyer if (!(state & AWI_RXD_ST_CONSUMED)) {
1313 1.27.2.2 bouyer if (state & AWI_RXD_ST_RXERROR)
1314 1.27.2.2 bouyer sc->sc_ifp->if_ierrors++;
1315 1.27.2.2 bouyer else {
1316 1.27.2.2 bouyer len = awi_read_2(sc, rxoff + AWI_RXD_LEN);
1317 1.27.2.2 bouyer rate = awi_read_1(sc, rxoff + AWI_RXD_RATE);
1318 1.27.2.2 bouyer rssi = awi_read_1(sc, rxoff + AWI_RXD_RSSI);
1319 1.27.2.2 bouyer frame = awi_read_4(sc, rxoff + AWI_RXD_START_FRAME) & 0x7fff;
1320 1.27.2.2 bouyer rxts = awi_read_4(sc, rxoff + AWI_RXD_LOCALTIME);
1321 1.27.2.2 bouyer m = awi_devget(sc, frame, len);
1322 1.27.2.2 bouyer if (state & AWI_RXD_ST_LF)
1323 1.27.2.2 bouyer awi_input(sc, m, rxts, rssi);
1324 1.27.2.2 bouyer else
1325 1.27.2.2 bouyer sc->sc_rxpend = m;
1326 1.27.2.2 bouyer }
1327 1.27.2.2 bouyer state |= AWI_RXD_ST_CONSUMED;
1328 1.27.2.2 bouyer awi_write_1(sc, rxoff + AWI_RXD_HOST_DESC_STATE, state);
1329 1.27.2.2 bouyer }
1330 1.27.2.2 bouyer next = awi_read_4(sc, rxoff + AWI_RXD_NEXT);
1331 1.27.2.2 bouyer if (next & AWI_RXD_NEXT_LAST)
1332 1.27.2.2 bouyer break;
1333 1.27.2.2 bouyer /* make sure the next pointer is correct */
1334 1.27.2.2 bouyer if (next != awi_read_4(sc, rxoff + AWI_RXD_NEXT))
1335 1.27.2.2 bouyer break;
1336 1.27.2.2 bouyer state |= AWI_RXD_ST_OWN;
1337 1.27.2.2 bouyer awi_write_1(sc, rxoff + AWI_RXD_HOST_DESC_STATE, state);
1338 1.27.2.2 bouyer rxoff = next & 0x7fff;
1339 1.27.2.2 bouyer }
1340 1.27.2.2 bouyer sc->sc_rxdoff = rxoff;
1341 1.27.2.2 bouyer }
1342 1.27.2.2 bouyer
1343 1.27.2.2 bouyer static struct mbuf *
1344 1.27.2.2 bouyer awi_devget(sc, off, len)
1345 1.27.2.2 bouyer struct awi_softc *sc;
1346 1.27.2.2 bouyer u_int32_t off;
1347 1.27.2.2 bouyer u_int16_t len;
1348 1.27.2.2 bouyer {
1349 1.27.2.2 bouyer struct mbuf *m;
1350 1.27.2.2 bouyer struct mbuf *top, **mp;
1351 1.27.2.2 bouyer u_int tlen;
1352 1.27.2.2 bouyer
1353 1.27.2.2 bouyer top = sc->sc_rxpend;
1354 1.27.2.2 bouyer mp = ⊤
1355 1.27.2.2 bouyer if (top != NULL) {
1356 1.27.2.2 bouyer sc->sc_rxpend = NULL;
1357 1.27.2.2 bouyer top->m_pkthdr.len += len;
1358 1.27.2.2 bouyer m = top;
1359 1.27.2.2 bouyer while (*mp != NULL) {
1360 1.27.2.2 bouyer m = *mp;
1361 1.27.2.2 bouyer mp = &m->m_next;
1362 1.27.2.2 bouyer }
1363 1.27.2.2 bouyer if (m->m_flags & M_EXT)
1364 1.27.2.2 bouyer tlen = m->m_ext.ext_size;
1365 1.27.2.2 bouyer else if (m->m_flags & M_PKTHDR)
1366 1.27.2.2 bouyer tlen = MHLEN;
1367 1.27.2.2 bouyer else
1368 1.27.2.2 bouyer tlen = MLEN;
1369 1.27.2.2 bouyer tlen -= m->m_len;
1370 1.27.2.2 bouyer if (tlen > len)
1371 1.27.2.2 bouyer tlen = len;
1372 1.27.2.2 bouyer awi_read_bytes(sc, off, mtod(m, u_int8_t *) + m->m_len, tlen);
1373 1.27.2.2 bouyer off += tlen;
1374 1.27.2.2 bouyer len -= tlen;
1375 1.27.2.2 bouyer }
1376 1.27.2.2 bouyer
1377 1.27.2.2 bouyer while (len > 0) {
1378 1.27.2.2 bouyer if (top == NULL) {
1379 1.27.2.2 bouyer MGETHDR(m, M_DONTWAIT, MT_DATA);
1380 1.27.2.2 bouyer if (m == NULL)
1381 1.27.2.2 bouyer return NULL;
1382 1.27.2.2 bouyer m->m_pkthdr.rcvif = sc->sc_ifp;
1383 1.27.2.2 bouyer m->m_pkthdr.len = len;
1384 1.27.2.2 bouyer m->m_len = MHLEN;
1385 1.27.2.2 bouyer } else {
1386 1.27.2.2 bouyer MGET(m, M_DONTWAIT, MT_DATA);
1387 1.27.2.2 bouyer if (m == NULL) {
1388 1.27.2.2 bouyer m_freem(top);
1389 1.27.2.2 bouyer return NULL;
1390 1.27.2.2 bouyer }
1391 1.27.2.2 bouyer m->m_len = MLEN;
1392 1.27.2.2 bouyer }
1393 1.27.2.2 bouyer if (len >= MINCLSIZE) {
1394 1.27.2.2 bouyer MCLGET(m, M_DONTWAIT);
1395 1.27.2.2 bouyer if (m->m_flags & M_EXT)
1396 1.27.2.2 bouyer m->m_len = m->m_ext.ext_size;
1397 1.27.2.2 bouyer }
1398 1.27.2.2 bouyer if (top == NULL) {
1399 1.27.2.2 bouyer int hdrlen = sizeof(struct ieee80211_frame) +
1400 1.27.2.2 bouyer (sc->sc_format_llc ? sizeof(struct llc) :
1401 1.27.2.2 bouyer sizeof(struct ether_header));
1402 1.27.2.2 bouyer caddr_t newdata = (caddr_t)
1403 1.27.2.2 bouyer ALIGN(m->m_data + hdrlen) - hdrlen;
1404 1.27.2.2 bouyer m->m_len -= newdata - m->m_data;
1405 1.27.2.2 bouyer m->m_data = newdata;
1406 1.27.2.2 bouyer }
1407 1.27.2.2 bouyer if (m->m_len > len)
1408 1.27.2.2 bouyer m->m_len = len;
1409 1.27.2.2 bouyer awi_read_bytes(sc, off, mtod(m, u_int8_t *), m->m_len);
1410 1.27.2.2 bouyer off += m->m_len;
1411 1.27.2.2 bouyer len -= m->m_len;
1412 1.27.2.2 bouyer *mp = m;
1413 1.27.2.2 bouyer mp = &m->m_next;
1414 1.27.2.2 bouyer }
1415 1.27.2.2 bouyer return top;
1416 1.27.2.2 bouyer }
1417 1.27.2.2 bouyer
1418 1.27.2.2 bouyer /*
1419 1.27.2.2 bouyer * Initialize hardware and start firmware to accept commands.
1420 1.27.2.2 bouyer * Called everytime after power on firmware.
1421 1.27.2.2 bouyer */
1422 1.27.2.2 bouyer
1423 1.27.2.2 bouyer static int
1424 1.27.2.2 bouyer awi_init_hw(sc)
1425 1.27.2.2 bouyer struct awi_softc *sc;
1426 1.27.2.2 bouyer {
1427 1.27.2.2 bouyer u_int8_t status;
1428 1.27.2.2 bouyer u_int16_t intmask;
1429 1.27.2.2 bouyer int i, error;
1430 1.27.2.2 bouyer
1431 1.27.2.2 bouyer sc->sc_enab_intr = 0;
1432 1.27.2.2 bouyer sc->sc_invalid = 0; /* XXX: really? */
1433 1.27.2.2 bouyer awi_drvstate(sc, AWI_DRV_RESET);
1434 1.27.2.2 bouyer
1435 1.27.2.2 bouyer /* reset firmware */
1436 1.27.2.2 bouyer am79c930_gcr_setbits(&sc->sc_chip, AM79C930_GCR_CORESET);
1437 1.27.2.2 bouyer DELAY(100);
1438 1.27.2.2 bouyer awi_write_1(sc, AWI_SELFTEST, 0);
1439 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD, 0);
1440 1.27.2.2 bouyer awi_write_1(sc, AWI_BANNER, 0);
1441 1.27.2.2 bouyer am79c930_gcr_clearbits(&sc->sc_chip, AM79C930_GCR_CORESET);
1442 1.27.2.2 bouyer DELAY(100);
1443 1.27.2.2 bouyer
1444 1.27.2.2 bouyer /* wait for selftest completion */
1445 1.27.2.2 bouyer for (i = 0; ; i++) {
1446 1.27.2.2 bouyer if (i >= AWI_SELFTEST_TIMEOUT*hz/1000) {
1447 1.27.2.2 bouyer printf("%s: failed to complete selftest (timeout)\n",
1448 1.27.2.2 bouyer sc->sc_dev.dv_xname);
1449 1.27.2.2 bouyer return ENXIO;
1450 1.27.2.2 bouyer }
1451 1.27.2.2 bouyer status = awi_read_1(sc, AWI_SELFTEST);
1452 1.27.2.2 bouyer if ((status & 0xf0) == 0xf0)
1453 1.27.2.2 bouyer break;
1454 1.27.2.2 bouyer if (sc->sc_cansleep) {
1455 1.27.2.2 bouyer sc->sc_sleep_cnt++;
1456 1.27.2.2 bouyer (void)tsleep(sc, PWAIT, "awitst", 1);
1457 1.27.2.2 bouyer sc->sc_sleep_cnt--;
1458 1.27.2.2 bouyer } else {
1459 1.27.2.2 bouyer DELAY(1000*1000/hz);
1460 1.27.2.2 bouyer }
1461 1.27.2.2 bouyer }
1462 1.27.2.2 bouyer if (status != AWI_SELFTEST_PASSED) {
1463 1.27.2.2 bouyer printf("%s: failed to complete selftest (code %x)\n",
1464 1.27.2.2 bouyer sc->sc_dev.dv_xname, status);
1465 1.27.2.2 bouyer return ENXIO;
1466 1.27.2.2 bouyer }
1467 1.27.2.2 bouyer
1468 1.27.2.2 bouyer /* check banner to confirm firmware write it */
1469 1.27.2.2 bouyer awi_read_bytes(sc, AWI_BANNER, sc->sc_banner, AWI_BANNER_LEN);
1470 1.27.2.2 bouyer if (memcmp(sc->sc_banner, "PCnetMobile:", 12) != 0) {
1471 1.27.2.2 bouyer printf("%s: failed to complete selftest (bad banner)\n",
1472 1.27.2.2 bouyer sc->sc_dev.dv_xname);
1473 1.27.2.2 bouyer for (i = 0; i < AWI_BANNER_LEN; i++)
1474 1.27.2.2 bouyer printf("%s%02x", i ? ":" : "\t", sc->sc_banner[i]);
1475 1.27.2.2 bouyer printf("\n");
1476 1.27.2.2 bouyer return ENXIO;
1477 1.27.2.2 bouyer }
1478 1.27.2.2 bouyer
1479 1.27.2.2 bouyer /* initializing interrupt */
1480 1.27.2.2 bouyer sc->sc_enab_intr = 1;
1481 1.27.2.2 bouyer error = awi_intr_lock(sc);
1482 1.27.2.2 bouyer if (error)
1483 1.27.2.2 bouyer return error;
1484 1.27.2.2 bouyer intmask = AWI_INT_GROGGY | AWI_INT_SCAN_CMPLT |
1485 1.27.2.2 bouyer AWI_INT_TX | AWI_INT_RX | AWI_INT_CMD;
1486 1.27.2.2 bouyer awi_write_1(sc, AWI_INTMASK, ~intmask & 0xff);
1487 1.27.2.2 bouyer awi_write_1(sc, AWI_INTMASK2, 0);
1488 1.27.2.2 bouyer awi_write_1(sc, AWI_INTSTAT, 0);
1489 1.27.2.2 bouyer awi_write_1(sc, AWI_INTSTAT2, 0);
1490 1.27.2.2 bouyer awi_intr_unlock(sc);
1491 1.27.2.2 bouyer am79c930_gcr_setbits(&sc->sc_chip, AM79C930_GCR_ENECINT);
1492 1.27.2.2 bouyer
1493 1.27.2.2 bouyer /* issueing interface test command */
1494 1.27.2.2 bouyer error = awi_cmd(sc, AWI_CMD_NOP);
1495 1.27.2.2 bouyer if (error) {
1496 1.27.2.2 bouyer printf("%s: failed to complete selftest", sc->sc_dev.dv_xname);
1497 1.27.2.2 bouyer if (error == ENXIO)
1498 1.27.2.2 bouyer printf(" (no hardware)\n");
1499 1.27.2.2 bouyer else if (error != EWOULDBLOCK)
1500 1.27.2.2 bouyer printf(" (error %d)\n", error);
1501 1.27.2.2 bouyer else if (sc->sc_cansleep)
1502 1.27.2.2 bouyer printf(" (lost interrupt)\n");
1503 1.27.2.2 bouyer else
1504 1.27.2.2 bouyer printf(" (command timeout)\n");
1505 1.27.2.2 bouyer }
1506 1.27.2.2 bouyer return error;
1507 1.27.2.2 bouyer }
1508 1.27.2.2 bouyer
1509 1.27.2.2 bouyer /*
1510 1.27.2.2 bouyer * Extract the factory default MIB value from firmware and assign the driver
1511 1.27.2.2 bouyer * default value.
1512 1.27.2.2 bouyer * Called once at attaching the interface.
1513 1.27.2.2 bouyer */
1514 1.27.2.2 bouyer
1515 1.27.2.2 bouyer static int
1516 1.27.2.2 bouyer awi_init_mibs(sc)
1517 1.27.2.2 bouyer struct awi_softc *sc;
1518 1.27.2.2 bouyer {
1519 1.27.2.2 bouyer int i, error;
1520 1.27.2.2 bouyer u_int8_t *rate;
1521 1.27.2.2 bouyer
1522 1.27.2.2 bouyer if ((error = awi_mib(sc, AWI_CMD_GET_MIB, AWI_MIB_LOCAL)) != 0 ||
1523 1.27.2.2 bouyer (error = awi_mib(sc, AWI_CMD_GET_MIB, AWI_MIB_ADDR)) != 0 ||
1524 1.27.2.2 bouyer (error = awi_mib(sc, AWI_CMD_GET_MIB, AWI_MIB_MAC)) != 0 ||
1525 1.27.2.2 bouyer (error = awi_mib(sc, AWI_CMD_GET_MIB, AWI_MIB_MGT)) != 0 ||
1526 1.27.2.2 bouyer (error = awi_mib(sc, AWI_CMD_GET_MIB, AWI_MIB_PHY)) != 0) {
1527 1.27.2.2 bouyer printf("%s: failed to get default mib value (error %d)\n",
1528 1.27.2.2 bouyer sc->sc_dev.dv_xname, error);
1529 1.27.2.2 bouyer return error;
1530 1.27.2.2 bouyer }
1531 1.27.2.2 bouyer
1532 1.27.2.2 bouyer rate = sc->sc_mib_phy.aSuprt_Data_Rates;
1533 1.27.2.2 bouyer sc->sc_tx_rate = AWI_RATE_1MBIT;
1534 1.27.2.2 bouyer for (i = 0; i < rate[1]; i++) {
1535 1.27.2.2 bouyer if (AWI_80211_RATE(rate[2 + i]) > sc->sc_tx_rate)
1536 1.27.2.2 bouyer sc->sc_tx_rate = AWI_80211_RATE(rate[2 + i]);
1537 1.27.2.2 bouyer }
1538 1.27.2.2 bouyer awi_init_region(sc);
1539 1.27.2.2 bouyer memset(&sc->sc_mib_mac.aDesired_ESS_ID, 0, AWI_ESS_ID_SIZE);
1540 1.27.2.2 bouyer sc->sc_mib_mac.aDesired_ESS_ID[0] = IEEE80211_ELEMID_SSID;
1541 1.27.2.2 bouyer sc->sc_mib_local.Fragmentation_Dis = 1;
1542 1.27.2.2 bouyer sc->sc_mib_local.Accept_All_Multicast_Dis = 1;
1543 1.27.2.2 bouyer sc->sc_mib_local.Power_Saving_Mode_Dis = 1;
1544 1.27.2.2 bouyer
1545 1.27.2.2 bouyer /* allocate buffers */
1546 1.27.2.2 bouyer sc->sc_txbase = AWI_BUFFERS;
1547 1.27.2.2 bouyer sc->sc_txend = sc->sc_txbase +
1548 1.27.2.2 bouyer (AWI_TXD_SIZE + sizeof(struct ieee80211_frame) +
1549 1.27.2.2 bouyer sizeof(struct ether_header) + ETHERMTU) * AWI_NTXBUFS;
1550 1.27.2.2 bouyer LE_WRITE_4(&sc->sc_mib_local.Tx_Buffer_Offset, sc->sc_txbase);
1551 1.27.2.2 bouyer LE_WRITE_4(&sc->sc_mib_local.Tx_Buffer_Size,
1552 1.27.2.2 bouyer sc->sc_txend - sc->sc_txbase);
1553 1.27.2.2 bouyer LE_WRITE_4(&sc->sc_mib_local.Rx_Buffer_Offset, sc->sc_txend);
1554 1.27.2.2 bouyer LE_WRITE_4(&sc->sc_mib_local.Rx_Buffer_Size,
1555 1.27.2.2 bouyer AWI_BUFFERS_END - sc->sc_txend);
1556 1.27.2.2 bouyer sc->sc_mib_local.Network_Mode = 1;
1557 1.27.2.2 bouyer sc->sc_mib_local.Acting_as_AP = 0;
1558 1.27.2.2 bouyer return 0;
1559 1.27.2.2 bouyer }
1560 1.27.2.2 bouyer
1561 1.27.2.2 bouyer /*
1562 1.27.2.2 bouyer * Start transmitter and receiver of firmware
1563 1.27.2.2 bouyer * Called after awi_init_hw() to start operation.
1564 1.27.2.2 bouyer */
1565 1.27.2.2 bouyer
1566 1.27.2.2 bouyer static int
1567 1.27.2.2 bouyer awi_init_txrx(sc)
1568 1.27.2.2 bouyer struct awi_softc *sc;
1569 1.27.2.2 bouyer {
1570 1.27.2.2 bouyer int error;
1571 1.27.2.2 bouyer
1572 1.27.2.2 bouyer /* start transmitter */
1573 1.27.2.2 bouyer sc->sc_txdone = sc->sc_txnext = sc->sc_txbase;
1574 1.27.2.2 bouyer awi_write_4(sc, sc->sc_txbase + AWI_TXD_START, 0);
1575 1.27.2.2 bouyer awi_write_4(sc, sc->sc_txbase + AWI_TXD_NEXT, 0);
1576 1.27.2.2 bouyer awi_write_4(sc, sc->sc_txbase + AWI_TXD_LENGTH, 0);
1577 1.27.2.2 bouyer awi_write_1(sc, sc->sc_txbase + AWI_TXD_RATE, 0);
1578 1.27.2.2 bouyer awi_write_4(sc, sc->sc_txbase + AWI_TXD_NDA, 0);
1579 1.27.2.2 bouyer awi_write_4(sc, sc->sc_txbase + AWI_TXD_NRA, 0);
1580 1.27.2.2 bouyer awi_write_1(sc, sc->sc_txbase + AWI_TXD_STATE, 0);
1581 1.27.2.2 bouyer awi_write_4(sc, AWI_CMD_PARAMS+AWI_CA_TX_DATA, sc->sc_txbase);
1582 1.27.2.2 bouyer awi_write_4(sc, AWI_CMD_PARAMS+AWI_CA_TX_MGT, 0);
1583 1.27.2.2 bouyer awi_write_4(sc, AWI_CMD_PARAMS+AWI_CA_TX_BCAST, 0);
1584 1.27.2.2 bouyer awi_write_4(sc, AWI_CMD_PARAMS+AWI_CA_TX_PS, 0);
1585 1.27.2.2 bouyer awi_write_4(sc, AWI_CMD_PARAMS+AWI_CA_TX_CF, 0);
1586 1.27.2.2 bouyer error = awi_cmd(sc, AWI_CMD_INIT_TX);
1587 1.27.2.2 bouyer if (error)
1588 1.27.2.2 bouyer return error;
1589 1.27.2.2 bouyer
1590 1.27.2.2 bouyer /* start receiver */
1591 1.27.2.2 bouyer if (sc->sc_rxpend) {
1592 1.27.2.2 bouyer m_freem(sc->sc_rxpend);
1593 1.27.2.2 bouyer sc->sc_rxpend = NULL;
1594 1.27.2.2 bouyer }
1595 1.27.2.2 bouyer error = awi_cmd(sc, AWI_CMD_INIT_RX);
1596 1.27.2.2 bouyer if (error)
1597 1.27.2.2 bouyer return error;
1598 1.27.2.2 bouyer sc->sc_rxdoff = awi_read_4(sc, AWI_CMD_PARAMS+AWI_CA_IRX_DATA_DESC);
1599 1.27.2.2 bouyer sc->sc_rxmoff = awi_read_4(sc, AWI_CMD_PARAMS+AWI_CA_IRX_PS_DESC);
1600 1.27.2.2 bouyer return 0;
1601 1.27.2.2 bouyer }
1602 1.27.2.2 bouyer
1603 1.27.2.2 bouyer static void
1604 1.27.2.2 bouyer awi_stop_txrx(sc)
1605 1.27.2.2 bouyer struct awi_softc *sc;
1606 1.27.2.2 bouyer {
1607 1.27.2.2 bouyer
1608 1.27.2.2 bouyer if (sc->sc_cmd_inprog)
1609 1.27.2.2 bouyer (void)awi_cmd_wait(sc);
1610 1.27.2.2 bouyer (void)awi_cmd(sc, AWI_CMD_KILL_RX);
1611 1.27.2.2 bouyer (void)awi_cmd_wait(sc);
1612 1.27.2.2 bouyer sc->sc_cmd_inprog = AWI_CMD_FLUSH_TX;
1613 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_FTX_DATA, 1);
1614 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_FTX_MGT, 0);
1615 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_FTX_BCAST, 0);
1616 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_FTX_PS, 0);
1617 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_FTX_CF, 0);
1618 1.27.2.2 bouyer (void)awi_cmd(sc, AWI_CMD_FLUSH_TX);
1619 1.27.2.2 bouyer (void)awi_cmd_wait(sc);
1620 1.27.2.2 bouyer }
1621 1.27.2.2 bouyer
1622 1.27.2.2 bouyer int
1623 1.27.2.2 bouyer awi_init_region(sc)
1624 1.27.2.2 bouyer struct awi_softc *sc;
1625 1.27.2.2 bouyer {
1626 1.27.2.2 bouyer
1627 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH) {
1628 1.27.2.2 bouyer switch (sc->sc_mib_phy.aCurrent_Reg_Domain) {
1629 1.27.2.2 bouyer case AWI_REG_DOMAIN_US:
1630 1.27.2.2 bouyer case AWI_REG_DOMAIN_CA:
1631 1.27.2.2 bouyer case AWI_REG_DOMAIN_EU:
1632 1.27.2.2 bouyer sc->sc_scan_min = 0;
1633 1.27.2.2 bouyer sc->sc_scan_max = 77;
1634 1.27.2.2 bouyer break;
1635 1.27.2.2 bouyer case AWI_REG_DOMAIN_ES:
1636 1.27.2.2 bouyer sc->sc_scan_min = 0;
1637 1.27.2.2 bouyer sc->sc_scan_max = 26;
1638 1.27.2.2 bouyer break;
1639 1.27.2.2 bouyer case AWI_REG_DOMAIN_FR:
1640 1.27.2.2 bouyer sc->sc_scan_min = 0;
1641 1.27.2.2 bouyer sc->sc_scan_max = 32;
1642 1.27.2.2 bouyer break;
1643 1.27.2.2 bouyer case AWI_REG_DOMAIN_JP:
1644 1.27.2.2 bouyer sc->sc_scan_min = 6;
1645 1.27.2.2 bouyer sc->sc_scan_max = 17;
1646 1.27.2.2 bouyer break;
1647 1.27.2.2 bouyer default:
1648 1.27.2.2 bouyer return EINVAL;
1649 1.27.2.2 bouyer }
1650 1.27.2.2 bouyer sc->sc_scan_set = sc->sc_scan_cur % 3 + 1;
1651 1.27.2.2 bouyer } else {
1652 1.27.2.2 bouyer switch (sc->sc_mib_phy.aCurrent_Reg_Domain) {
1653 1.27.2.2 bouyer case AWI_REG_DOMAIN_US:
1654 1.27.2.2 bouyer case AWI_REG_DOMAIN_CA:
1655 1.27.2.2 bouyer sc->sc_scan_min = 1;
1656 1.27.2.2 bouyer sc->sc_scan_max = 11;
1657 1.27.2.2 bouyer sc->sc_scan_cur = 3;
1658 1.27.2.2 bouyer break;
1659 1.27.2.2 bouyer case AWI_REG_DOMAIN_EU:
1660 1.27.2.2 bouyer sc->sc_scan_min = 1;
1661 1.27.2.2 bouyer sc->sc_scan_max = 13;
1662 1.27.2.2 bouyer sc->sc_scan_cur = 3;
1663 1.27.2.2 bouyer break;
1664 1.27.2.2 bouyer case AWI_REG_DOMAIN_ES:
1665 1.27.2.2 bouyer sc->sc_scan_min = 10;
1666 1.27.2.2 bouyer sc->sc_scan_max = 11;
1667 1.27.2.2 bouyer sc->sc_scan_cur = 10;
1668 1.27.2.2 bouyer break;
1669 1.27.2.2 bouyer case AWI_REG_DOMAIN_FR:
1670 1.27.2.2 bouyer sc->sc_scan_min = 10;
1671 1.27.2.2 bouyer sc->sc_scan_max = 13;
1672 1.27.2.2 bouyer sc->sc_scan_cur = 10;
1673 1.27.2.2 bouyer break;
1674 1.27.2.2 bouyer case AWI_REG_DOMAIN_JP:
1675 1.27.2.2 bouyer sc->sc_scan_min = 14;
1676 1.27.2.2 bouyer sc->sc_scan_max = 14;
1677 1.27.2.2 bouyer sc->sc_scan_cur = 14;
1678 1.27.2.2 bouyer break;
1679 1.27.2.2 bouyer default:
1680 1.27.2.2 bouyer return EINVAL;
1681 1.27.2.2 bouyer }
1682 1.27.2.2 bouyer }
1683 1.27.2.2 bouyer sc->sc_ownch = sc->sc_scan_cur;
1684 1.27.2.2 bouyer return 0;
1685 1.27.2.2 bouyer }
1686 1.27.2.2 bouyer
1687 1.27.2.2 bouyer static int
1688 1.27.2.2 bouyer awi_start_scan(sc)
1689 1.27.2.2 bouyer struct awi_softc *sc;
1690 1.27.2.2 bouyer {
1691 1.27.2.2 bouyer int error = 0;
1692 1.27.2.2 bouyer struct awi_bss *bp;
1693 1.27.2.2 bouyer
1694 1.27.2.2 bouyer while ((bp = TAILQ_FIRST(&sc->sc_scan)) != NULL) {
1695 1.27.2.2 bouyer TAILQ_REMOVE(&sc->sc_scan, bp, list);
1696 1.27.2.2 bouyer free(bp, M_DEVBUF);
1697 1.27.2.2 bouyer }
1698 1.27.2.2 bouyer if (!sc->sc_mib_local.Network_Mode && sc->sc_no_bssid) {
1699 1.27.2.2 bouyer memset(&sc->sc_bss, 0, sizeof(sc->sc_bss));
1700 1.27.2.2 bouyer sc->sc_bss.essid[0] = IEEE80211_ELEMID_SSID;
1701 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH) {
1702 1.27.2.2 bouyer sc->sc_bss.chanset = sc->sc_ownch % 3 + 1;
1703 1.27.2.2 bouyer sc->sc_bss.pattern = sc->sc_ownch;
1704 1.27.2.2 bouyer sc->sc_bss.index = 1;
1705 1.27.2.2 bouyer sc->sc_bss.dwell_time = 200; /*XXX*/
1706 1.27.2.2 bouyer } else
1707 1.27.2.2 bouyer sc->sc_bss.chanset = sc->sc_ownch;
1708 1.27.2.2 bouyer sc->sc_status = AWI_ST_SETSS;
1709 1.27.2.2 bouyer error = awi_set_ss(sc);
1710 1.27.2.2 bouyer } else {
1711 1.27.2.2 bouyer if (sc->sc_mib_local.Network_Mode)
1712 1.27.2.2 bouyer awi_drvstate(sc, AWI_DRV_INFSC);
1713 1.27.2.2 bouyer else
1714 1.27.2.2 bouyer awi_drvstate(sc, AWI_DRV_ADHSC);
1715 1.27.2.2 bouyer sc->sc_start_bss = 0;
1716 1.27.2.2 bouyer sc->sc_active_scan = 1;
1717 1.27.2.2 bouyer sc->sc_mgt_timer = AWI_ASCAN_WAIT / 1000;
1718 1.27.2.2 bouyer sc->sc_ifp->if_timer = 1;
1719 1.27.2.2 bouyer sc->sc_status = AWI_ST_SCAN;
1720 1.27.2.2 bouyer error = awi_cmd_scan(sc);
1721 1.27.2.2 bouyer }
1722 1.27.2.2 bouyer return error;
1723 1.27.2.2 bouyer }
1724 1.27.2.2 bouyer
1725 1.27.2.2 bouyer static int
1726 1.27.2.2 bouyer awi_next_scan(sc)
1727 1.27.2.2 bouyer struct awi_softc *sc;
1728 1.27.2.2 bouyer {
1729 1.27.2.2 bouyer int error;
1730 1.27.2.2 bouyer
1731 1.27.2.2 bouyer for (;;) {
1732 1.27.2.2 bouyer /*
1733 1.27.2.2 bouyer * The pattern parameter for FH phy should be incremented
1734 1.27.2.2 bouyer * by 3. But BayStack 650 Access Points apparently always
1735 1.27.2.2 bouyer * assign hop pattern set parameter to 1 for any pattern.
1736 1.27.2.2 bouyer * So we try all combinations of pattern/set parameters.
1737 1.27.2.2 bouyer * Since this causes no error, it may be a bug of
1738 1.27.2.2 bouyer * PCnetMobile firmware.
1739 1.27.2.2 bouyer */
1740 1.27.2.2 bouyer sc->sc_scan_cur++;
1741 1.27.2.2 bouyer if (sc->sc_scan_cur > sc->sc_scan_max) {
1742 1.27.2.2 bouyer sc->sc_scan_cur = sc->sc_scan_min;
1743 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH)
1744 1.27.2.2 bouyer sc->sc_scan_set = sc->sc_scan_set % 3 + 1;
1745 1.27.2.2 bouyer }
1746 1.27.2.2 bouyer error = awi_cmd_scan(sc);
1747 1.27.2.2 bouyer if (error != EINVAL)
1748 1.27.2.2 bouyer break;
1749 1.27.2.2 bouyer }
1750 1.27.2.2 bouyer return error;
1751 1.27.2.2 bouyer }
1752 1.27.2.2 bouyer
1753 1.27.2.2 bouyer static void
1754 1.27.2.2 bouyer awi_stop_scan(sc)
1755 1.27.2.2 bouyer struct awi_softc *sc;
1756 1.27.2.2 bouyer {
1757 1.27.2.2 bouyer struct ifnet *ifp = sc->sc_ifp;
1758 1.27.2.2 bouyer struct awi_bss *bp, *sbp;
1759 1.27.2.2 bouyer int fail;
1760 1.27.2.2 bouyer
1761 1.27.2.2 bouyer bp = TAILQ_FIRST(&sc->sc_scan);
1762 1.27.2.2 bouyer if (bp == NULL) {
1763 1.27.2.2 bouyer notfound:
1764 1.27.2.2 bouyer if (sc->sc_active_scan) {
1765 1.27.2.2 bouyer if (ifp->if_flags & IFF_DEBUG)
1766 1.27.2.2 bouyer printf("%s: entering passive scan mode\n",
1767 1.27.2.2 bouyer sc->sc_dev.dv_xname);
1768 1.27.2.2 bouyer sc->sc_active_scan = 0;
1769 1.27.2.2 bouyer }
1770 1.27.2.2 bouyer sc->sc_mgt_timer = AWI_PSCAN_WAIT / 1000;
1771 1.27.2.2 bouyer ifp->if_timer = 1;
1772 1.27.2.2 bouyer (void)awi_next_scan(sc);
1773 1.27.2.2 bouyer return;
1774 1.27.2.2 bouyer }
1775 1.27.2.2 bouyer sbp = NULL;
1776 1.27.2.2 bouyer if (ifp->if_flags & IFF_DEBUG)
1777 1.27.2.2 bouyer printf("%s:\tmacaddr ch/pat sig flag wep essid\n",
1778 1.27.2.2 bouyer sc->sc_dev.dv_xname);
1779 1.27.2.2 bouyer for (; bp != NULL; bp = TAILQ_NEXT(bp, list)) {
1780 1.27.2.2 bouyer if (bp->fails) {
1781 1.27.2.2 bouyer /*
1782 1.27.2.2 bouyer * The configuration of the access points may change
1783 1.27.2.2 bouyer * during my scan. So we retries to associate with
1784 1.27.2.2 bouyer * it unless there are any suitable AP.
1785 1.27.2.2 bouyer */
1786 1.27.2.2 bouyer if (bp->fails++ < 3)
1787 1.27.2.2 bouyer continue;
1788 1.27.2.2 bouyer bp->fails = 0;
1789 1.27.2.2 bouyer }
1790 1.27.2.2 bouyer fail = 0;
1791 1.27.2.2 bouyer /*
1792 1.27.2.2 bouyer * Since the firmware apparently scans not only the specified
1793 1.27.2.2 bouyer * channel of SCAN command but all available channel within
1794 1.27.2.2 bouyer * the region, we should filter out unnecessary responses here.
1795 1.27.2.2 bouyer */
1796 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH) {
1797 1.27.2.2 bouyer if (bp->pattern < sc->sc_scan_min ||
1798 1.27.2.2 bouyer bp->pattern > sc->sc_scan_max)
1799 1.27.2.2 bouyer fail |= 0x01;
1800 1.27.2.2 bouyer } else {
1801 1.27.2.2 bouyer if (bp->chanset < sc->sc_scan_min ||
1802 1.27.2.2 bouyer bp->chanset > sc->sc_scan_max)
1803 1.27.2.2 bouyer fail |= 0x01;
1804 1.27.2.2 bouyer }
1805 1.27.2.2 bouyer if (sc->sc_mib_local.Network_Mode) {
1806 1.27.2.2 bouyer if (!(bp->capinfo & IEEE80211_CAPINFO_ESS) ||
1807 1.27.2.2 bouyer (bp->capinfo & IEEE80211_CAPINFO_IBSS))
1808 1.27.2.2 bouyer fail |= 0x02;
1809 1.27.2.2 bouyer } else {
1810 1.27.2.2 bouyer if ((bp->capinfo & IEEE80211_CAPINFO_ESS) ||
1811 1.27.2.2 bouyer !(bp->capinfo & IEEE80211_CAPINFO_IBSS))
1812 1.27.2.2 bouyer fail |= 0x02;
1813 1.27.2.2 bouyer }
1814 1.27.2.2 bouyer if (sc->sc_wep_algo == NULL) {
1815 1.27.2.2 bouyer if (bp->capinfo & IEEE80211_CAPINFO_PRIVACY)
1816 1.27.2.2 bouyer fail |= 0x04;
1817 1.27.2.2 bouyer } else {
1818 1.27.2.2 bouyer if (!(bp->capinfo & IEEE80211_CAPINFO_PRIVACY))
1819 1.27.2.2 bouyer fail |= 0x04;
1820 1.27.2.2 bouyer }
1821 1.27.2.2 bouyer if (sc->sc_mib_mac.aDesired_ESS_ID[1] != 0 &&
1822 1.27.2.2 bouyer memcmp(&sc->sc_mib_mac.aDesired_ESS_ID, bp->essid,
1823 1.27.2.2 bouyer sizeof(bp->essid)) != 0)
1824 1.27.2.2 bouyer fail |= 0x08;
1825 1.27.2.2 bouyer if (ifp->if_flags & IFF_DEBUG) {
1826 1.27.2.2 bouyer printf(" %c %s", fail ? '-' : '+',
1827 1.27.2.2 bouyer ether_sprintf(bp->esrc));
1828 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH)
1829 1.27.2.2 bouyer printf(" %2d/%d%c", bp->pattern, bp->chanset,
1830 1.27.2.2 bouyer fail & 0x01 ? '!' : ' ');
1831 1.27.2.2 bouyer else
1832 1.27.2.2 bouyer printf(" %4d%c", bp->chanset,
1833 1.27.2.2 bouyer fail & 0x01 ? '!' : ' ');
1834 1.27.2.2 bouyer printf(" %+4d", bp->rssi);
1835 1.27.2.2 bouyer printf(" %4s%c",
1836 1.27.2.2 bouyer (bp->capinfo & IEEE80211_CAPINFO_ESS) ? "ess" :
1837 1.27.2.2 bouyer (bp->capinfo & IEEE80211_CAPINFO_IBSS) ? "ibss" :
1838 1.27.2.2 bouyer "????",
1839 1.27.2.2 bouyer fail & 0x02 ? '!' : ' ');
1840 1.27.2.2 bouyer printf(" %3s%c ",
1841 1.27.2.2 bouyer (bp->capinfo & IEEE80211_CAPINFO_PRIVACY) ? "wep" :
1842 1.27.2.2 bouyer "no",
1843 1.27.2.2 bouyer fail & 0x04 ? '!' : ' ');
1844 1.27.2.2 bouyer awi_print_essid(bp->essid);
1845 1.27.2.2 bouyer printf("%s\n", fail & 0x08 ? "!" : "");
1846 1.27.2.2 bouyer }
1847 1.27.2.2 bouyer if (!fail) {
1848 1.27.2.2 bouyer if (sbp == NULL || bp->rssi > sbp->rssi)
1849 1.27.2.2 bouyer sbp = bp;
1850 1.27.2.2 bouyer }
1851 1.27.2.2 bouyer }
1852 1.27.2.2 bouyer if (sbp == NULL)
1853 1.27.2.2 bouyer goto notfound;
1854 1.27.2.2 bouyer sc->sc_bss = *sbp;
1855 1.27.2.2 bouyer (void)awi_set_ss(sc);
1856 1.27.2.2 bouyer }
1857 1.27.2.2 bouyer
1858 1.27.2.2 bouyer static void
1859 1.27.2.2 bouyer awi_recv_beacon(sc, m0, rxts, rssi)
1860 1.27.2.2 bouyer struct awi_softc *sc;
1861 1.27.2.2 bouyer struct mbuf *m0;
1862 1.27.2.2 bouyer u_int32_t rxts;
1863 1.27.2.2 bouyer u_int8_t rssi;
1864 1.27.2.2 bouyer {
1865 1.27.2.2 bouyer struct ieee80211_frame *wh;
1866 1.27.2.2 bouyer struct awi_bss *bp;
1867 1.27.2.2 bouyer u_int8_t *frame, *eframe;
1868 1.27.2.2 bouyer u_int8_t *tstamp, *bintval, *capinfo, *ssid, *rates, *parms;
1869 1.27.2.2 bouyer
1870 1.27.2.2 bouyer if (sc->sc_status != AWI_ST_SCAN)
1871 1.27.2.2 bouyer return;
1872 1.27.2.2 bouyer wh = mtod(m0, struct ieee80211_frame *);
1873 1.27.2.2 bouyer
1874 1.27.2.2 bouyer frame = (u_int8_t *)&wh[1];
1875 1.27.2.2 bouyer eframe = mtod(m0, u_int8_t *) + m0->m_len;
1876 1.27.2.2 bouyer /*
1877 1.27.2.2 bouyer * XXX:
1878 1.27.2.2 bouyer * timestamp [8]
1879 1.27.2.2 bouyer * beacon interval [2]
1880 1.27.2.2 bouyer * capability information [2]
1881 1.27.2.2 bouyer * ssid [tlv]
1882 1.27.2.2 bouyer * supported rates [tlv]
1883 1.27.2.2 bouyer * parameter set [tlv]
1884 1.27.2.2 bouyer * ...
1885 1.27.2.2 bouyer */
1886 1.27.2.2 bouyer if (frame + 12 > eframe) {
1887 1.27.2.2 bouyer #ifdef AWI_DEBUG
1888 1.27.2.2 bouyer if (awi_verbose)
1889 1.27.2.2 bouyer printf("awi_recv_beacon: frame too short \n");
1890 1.27.2.2 bouyer #endif
1891 1.27.2.2 bouyer return;
1892 1.27.2.2 bouyer }
1893 1.27.2.2 bouyer tstamp = frame;
1894 1.27.2.2 bouyer frame += 8;
1895 1.27.2.2 bouyer bintval = frame;
1896 1.27.2.2 bouyer frame += 2;
1897 1.27.2.2 bouyer capinfo = frame;
1898 1.27.2.2 bouyer frame += 2;
1899 1.27.2.2 bouyer
1900 1.27.2.2 bouyer ssid = rates = parms = NULL;
1901 1.27.2.2 bouyer while (frame < eframe) {
1902 1.27.2.2 bouyer switch (*frame) {
1903 1.27.2.2 bouyer case IEEE80211_ELEMID_SSID:
1904 1.27.2.2 bouyer ssid = frame;
1905 1.27.2.2 bouyer break;
1906 1.27.2.2 bouyer case IEEE80211_ELEMID_RATES:
1907 1.27.2.2 bouyer rates = frame;
1908 1.27.2.2 bouyer break;
1909 1.27.2.2 bouyer case IEEE80211_ELEMID_FHPARMS:
1910 1.27.2.2 bouyer case IEEE80211_ELEMID_DSPARMS:
1911 1.27.2.2 bouyer parms = frame;
1912 1.27.2.2 bouyer break;
1913 1.27.2.2 bouyer }
1914 1.27.2.2 bouyer frame += frame[1] + 2;
1915 1.27.2.2 bouyer }
1916 1.27.2.2 bouyer if (ssid == NULL || rates == NULL || parms == NULL) {
1917 1.27.2.2 bouyer #ifdef AWI_DEBUG
1918 1.27.2.2 bouyer if (awi_verbose)
1919 1.27.2.2 bouyer printf("awi_recv_beacon: ssid=%p, rates=%p, parms=%p\n",
1920 1.27.2.2 bouyer ssid, rates, parms);
1921 1.27.2.2 bouyer #endif
1922 1.27.2.2 bouyer return;
1923 1.27.2.2 bouyer }
1924 1.27.2.2 bouyer if (ssid[1] > IEEE80211_NWID_LEN) {
1925 1.27.2.2 bouyer #ifdef AWI_DEBUG
1926 1.27.2.2 bouyer if (awi_verbose)
1927 1.27.2.2 bouyer printf("awi_recv_beacon: bad ssid len: %d from %s\n",
1928 1.27.2.2 bouyer ssid[1], ether_sprintf(wh->i_addr2));
1929 1.27.2.2 bouyer #endif
1930 1.27.2.2 bouyer return;
1931 1.27.2.2 bouyer }
1932 1.27.2.2 bouyer
1933 1.27.2.2 bouyer for (bp = TAILQ_FIRST(&sc->sc_scan); bp != NULL;
1934 1.27.2.2 bouyer bp = TAILQ_NEXT(bp, list)) {
1935 1.27.2.2 bouyer if (memcmp(bp->esrc, wh->i_addr2, ETHER_ADDR_LEN) == 0 &&
1936 1.27.2.2 bouyer memcmp(bp->bssid, wh->i_addr3, ETHER_ADDR_LEN) == 0)
1937 1.27.2.2 bouyer break;
1938 1.27.2.2 bouyer }
1939 1.27.2.2 bouyer if (bp == NULL) {
1940 1.27.2.2 bouyer bp = malloc(sizeof(struct awi_bss), M_DEVBUF, M_NOWAIT);
1941 1.27.2.2 bouyer if (bp == NULL)
1942 1.27.2.2 bouyer return;
1943 1.27.2.2 bouyer TAILQ_INSERT_TAIL(&sc->sc_scan, bp, list);
1944 1.27.2.2 bouyer memcpy(bp->esrc, wh->i_addr2, ETHER_ADDR_LEN);
1945 1.27.2.2 bouyer memcpy(bp->bssid, wh->i_addr3, ETHER_ADDR_LEN);
1946 1.27.2.2 bouyer memset(bp->essid, 0, sizeof(bp->essid));
1947 1.27.2.2 bouyer memcpy(bp->essid, ssid, 2 + ssid[1]);
1948 1.27.2.2 bouyer }
1949 1.27.2.2 bouyer bp->rssi = rssi;
1950 1.27.2.2 bouyer bp->rxtime = rxts;
1951 1.27.2.2 bouyer memcpy(bp->timestamp, tstamp, sizeof(bp->timestamp));
1952 1.27.2.2 bouyer bp->interval = LE_READ_2(bintval);
1953 1.27.2.2 bouyer bp->capinfo = LE_READ_2(capinfo);
1954 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH) {
1955 1.27.2.2 bouyer bp->chanset = parms[4];
1956 1.27.2.2 bouyer bp->pattern = parms[5];
1957 1.27.2.2 bouyer bp->index = parms[6];
1958 1.27.2.2 bouyer bp->dwell_time = LE_READ_2(parms + 2);
1959 1.27.2.2 bouyer } else {
1960 1.27.2.2 bouyer bp->chanset = parms[2];
1961 1.27.2.2 bouyer bp->pattern = 0;
1962 1.27.2.2 bouyer bp->index = 0;
1963 1.27.2.2 bouyer bp->dwell_time = 0;
1964 1.27.2.2 bouyer }
1965 1.27.2.2 bouyer if (sc->sc_mgt_timer == 0)
1966 1.27.2.2 bouyer awi_stop_scan(sc);
1967 1.27.2.2 bouyer }
1968 1.27.2.2 bouyer
1969 1.27.2.2 bouyer static int
1970 1.27.2.2 bouyer awi_set_ss(sc)
1971 1.27.2.2 bouyer struct awi_softc *sc;
1972 1.27.2.2 bouyer {
1973 1.27.2.2 bouyer struct ifnet *ifp = sc->sc_ifp;
1974 1.27.2.2 bouyer struct awi_bss *bp;
1975 1.27.2.2 bouyer int error;
1976 1.27.2.2 bouyer
1977 1.27.2.2 bouyer sc->sc_status = AWI_ST_SETSS;
1978 1.27.2.2 bouyer bp = &sc->sc_bss;
1979 1.27.2.2 bouyer if (ifp->if_flags & IFF_DEBUG) {
1980 1.27.2.2 bouyer printf("%s: ch %d pat %d id %d dw %d iv %d bss %s ssid ",
1981 1.27.2.2 bouyer sc->sc_dev.dv_xname, bp->chanset,
1982 1.27.2.2 bouyer bp->pattern, bp->index, bp->dwell_time, bp->interval,
1983 1.27.2.2 bouyer ether_sprintf(bp->bssid));
1984 1.27.2.2 bouyer awi_print_essid(bp->essid);
1985 1.27.2.2 bouyer printf("\n");
1986 1.27.2.2 bouyer }
1987 1.27.2.2 bouyer memcpy(&sc->sc_mib_mgt.aCurrent_BSS_ID, bp->bssid, ETHER_ADDR_LEN);
1988 1.27.2.2 bouyer memcpy(&sc->sc_mib_mgt.aCurrent_ESS_ID, bp->essid,
1989 1.27.2.2 bouyer AWI_ESS_ID_SIZE);
1990 1.27.2.2 bouyer LE_WRITE_2(&sc->sc_mib_mgt.aBeacon_Period, bp->interval);
1991 1.27.2.2 bouyer error = awi_mib(sc, AWI_CMD_SET_MIB, AWI_MIB_MGT);
1992 1.27.2.2 bouyer return error;
1993 1.27.2.2 bouyer }
1994 1.27.2.2 bouyer
1995 1.27.2.2 bouyer static void
1996 1.27.2.2 bouyer awi_try_sync(sc)
1997 1.27.2.2 bouyer struct awi_softc *sc;
1998 1.27.2.2 bouyer {
1999 1.27.2.2 bouyer struct awi_bss *bp;
2000 1.27.2.2 bouyer
2001 1.27.2.2 bouyer sc->sc_status = AWI_ST_SYNC;
2002 1.27.2.2 bouyer bp = &sc->sc_bss;
2003 1.27.2.2 bouyer
2004 1.27.2.2 bouyer if (sc->sc_cmd_inprog) {
2005 1.27.2.2 bouyer if (awi_cmd_wait(sc))
2006 1.27.2.2 bouyer return;
2007 1.27.2.2 bouyer }
2008 1.27.2.2 bouyer sc->sc_cmd_inprog = AWI_CMD_SYNC;
2009 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_SYNC_SET, bp->chanset);
2010 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_SYNC_PATTERN, bp->pattern);
2011 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_SYNC_IDX, bp->index);
2012 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_SYNC_STARTBSS,
2013 1.27.2.2 bouyer sc->sc_start_bss ? 1 : 0);
2014 1.27.2.2 bouyer awi_write_2(sc, AWI_CMD_PARAMS+AWI_CA_SYNC_DWELL, bp->dwell_time);
2015 1.27.2.2 bouyer awi_write_2(sc, AWI_CMD_PARAMS+AWI_CA_SYNC_MBZ, 0);
2016 1.27.2.2 bouyer awi_write_bytes(sc, AWI_CMD_PARAMS+AWI_CA_SYNC_TIMESTAMP,
2017 1.27.2.2 bouyer bp->timestamp, 8);
2018 1.27.2.2 bouyer awi_write_4(sc, AWI_CMD_PARAMS+AWI_CA_SYNC_REFTIME, bp->rxtime);
2019 1.27.2.2 bouyer (void)awi_cmd(sc, AWI_CMD_SYNC);
2020 1.27.2.2 bouyer }
2021 1.27.2.2 bouyer
2022 1.27.2.2 bouyer static void
2023 1.27.2.2 bouyer awi_sync_done(sc)
2024 1.27.2.2 bouyer struct awi_softc *sc;
2025 1.27.2.2 bouyer {
2026 1.27.2.2 bouyer struct ifnet *ifp = sc->sc_ifp;
2027 1.27.2.2 bouyer
2028 1.27.2.2 bouyer if (sc->sc_mib_local.Network_Mode) {
2029 1.27.2.2 bouyer awi_drvstate(sc, AWI_DRV_INFSY);
2030 1.27.2.2 bouyer awi_send_auth(sc, 1);
2031 1.27.2.2 bouyer } else {
2032 1.27.2.2 bouyer if (ifp->if_flags & IFF_DEBUG) {
2033 1.27.2.2 bouyer printf("%s: synced with", sc->sc_dev.dv_xname);
2034 1.27.2.2 bouyer if (sc->sc_no_bssid)
2035 1.27.2.2 bouyer printf(" no-bssid");
2036 1.27.2.2 bouyer else {
2037 1.27.2.2 bouyer printf(" %s ssid ",
2038 1.27.2.2 bouyer ether_sprintf(sc->sc_bss.bssid));
2039 1.27.2.2 bouyer awi_print_essid(sc->sc_bss.essid);
2040 1.27.2.2 bouyer }
2041 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH)
2042 1.27.2.2 bouyer printf(" at chanset %d pattern %d\n",
2043 1.27.2.2 bouyer sc->sc_bss.chanset, sc->sc_bss.pattern);
2044 1.27.2.2 bouyer else
2045 1.27.2.2 bouyer printf(" at channel %d\n", sc->sc_bss.chanset);
2046 1.27.2.2 bouyer }
2047 1.27.2.2 bouyer awi_drvstate(sc, AWI_DRV_ADHSY);
2048 1.27.2.2 bouyer sc->sc_status = AWI_ST_RUNNING;
2049 1.27.2.2 bouyer ifp->if_flags |= IFF_RUNNING;
2050 1.27.2.2 bouyer awi_start(ifp);
2051 1.27.2.2 bouyer }
2052 1.27.2.2 bouyer }
2053 1.27.2.2 bouyer
2054 1.27.2.2 bouyer static void
2055 1.27.2.2 bouyer awi_send_deauth(sc)
2056 1.27.2.2 bouyer struct awi_softc *sc;
2057 1.27.2.2 bouyer {
2058 1.27.2.2 bouyer struct ifnet *ifp = sc->sc_ifp;
2059 1.27.2.2 bouyer struct mbuf *m;
2060 1.27.2.2 bouyer struct ieee80211_frame *wh;
2061 1.27.2.2 bouyer u_int8_t *deauth;
2062 1.27.2.2 bouyer
2063 1.27.2.2 bouyer MGETHDR(m, M_DONTWAIT, MT_DATA);
2064 1.27.2.2 bouyer if (m == NULL)
2065 1.27.2.2 bouyer return;
2066 1.27.2.2 bouyer if (ifp->if_flags & IFF_DEBUG)
2067 1.27.2.2 bouyer printf("%s: sending deauth to %s\n", sc->sc_dev.dv_xname,
2068 1.27.2.2 bouyer ether_sprintf(sc->sc_bss.bssid));
2069 1.27.2.2 bouyer
2070 1.27.2.2 bouyer wh = mtod(m, struct ieee80211_frame *);
2071 1.27.2.2 bouyer wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT |
2072 1.27.2.2 bouyer IEEE80211_FC0_SUBTYPE_AUTH;
2073 1.27.2.2 bouyer wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
2074 1.27.2.2 bouyer LE_WRITE_2(wh->i_dur, 0);
2075 1.27.2.2 bouyer LE_WRITE_2(wh->i_seq, 0);
2076 1.27.2.2 bouyer memcpy(wh->i_addr1, sc->sc_bss.bssid, ETHER_ADDR_LEN);
2077 1.27.2.2 bouyer memcpy(wh->i_addr2, sc->sc_mib_addr.aMAC_Address, ETHER_ADDR_LEN);
2078 1.27.2.2 bouyer memcpy(wh->i_addr3, sc->sc_bss.bssid, ETHER_ADDR_LEN);
2079 1.27.2.2 bouyer
2080 1.27.2.2 bouyer deauth = (u_int8_t *)&wh[1];
2081 1.27.2.2 bouyer LE_WRITE_2(deauth, IEEE80211_REASON_AUTH_LEAVE);
2082 1.27.2.2 bouyer deauth += 2;
2083 1.27.2.2 bouyer
2084 1.27.2.2 bouyer m->m_pkthdr.len = m->m_len = deauth - mtod(m, u_int8_t *);
2085 1.27.2.2 bouyer IF_ENQUEUE(&sc->sc_mgtq, m);
2086 1.27.2.2 bouyer awi_start(ifp);
2087 1.27.2.2 bouyer awi_drvstate(sc, AWI_DRV_INFTOSS);
2088 1.27.2.2 bouyer }
2089 1.27.2.2 bouyer
2090 1.27.2.2 bouyer static void
2091 1.27.2.2 bouyer awi_send_auth(sc, seq)
2092 1.27.2.2 bouyer struct awi_softc *sc;
2093 1.27.2.2 bouyer int seq;
2094 1.27.2.2 bouyer {
2095 1.27.2.2 bouyer struct ifnet *ifp = sc->sc_ifp;
2096 1.27.2.2 bouyer struct mbuf *m;
2097 1.27.2.2 bouyer struct ieee80211_frame *wh;
2098 1.27.2.2 bouyer u_int8_t *auth;
2099 1.27.2.2 bouyer
2100 1.27.2.2 bouyer MGETHDR(m, M_DONTWAIT, MT_DATA);
2101 1.27.2.2 bouyer if (m == NULL)
2102 1.27.2.2 bouyer return;
2103 1.27.2.2 bouyer sc->sc_status = AWI_ST_AUTH;
2104 1.27.2.2 bouyer if (ifp->if_flags & IFF_DEBUG)
2105 1.27.2.2 bouyer printf("%s: sending auth to %s\n", sc->sc_dev.dv_xname,
2106 1.27.2.2 bouyer ether_sprintf(sc->sc_bss.bssid));
2107 1.27.2.2 bouyer
2108 1.27.2.2 bouyer wh = mtod(m, struct ieee80211_frame *);
2109 1.27.2.2 bouyer wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT |
2110 1.27.2.2 bouyer IEEE80211_FC0_SUBTYPE_AUTH;
2111 1.27.2.2 bouyer wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
2112 1.27.2.2 bouyer LE_WRITE_2(wh->i_dur, 0);
2113 1.27.2.2 bouyer LE_WRITE_2(wh->i_seq, 0);
2114 1.27.2.2 bouyer memcpy(wh->i_addr1, sc->sc_bss.esrc, ETHER_ADDR_LEN);
2115 1.27.2.2 bouyer memcpy(wh->i_addr2, sc->sc_mib_addr.aMAC_Address, ETHER_ADDR_LEN);
2116 1.27.2.2 bouyer memcpy(wh->i_addr3, sc->sc_bss.bssid, ETHER_ADDR_LEN);
2117 1.27.2.2 bouyer
2118 1.27.2.2 bouyer auth = (u_int8_t *)&wh[1];
2119 1.27.2.2 bouyer /* algorithm number */
2120 1.27.2.2 bouyer LE_WRITE_2(auth, IEEE80211_AUTH_ALG_OPEN);
2121 1.27.2.2 bouyer auth += 2;
2122 1.27.2.2 bouyer /* sequence number */
2123 1.27.2.2 bouyer LE_WRITE_2(auth, seq);
2124 1.27.2.2 bouyer auth += 2;
2125 1.27.2.2 bouyer /* status */
2126 1.27.2.2 bouyer LE_WRITE_2(auth, 0);
2127 1.27.2.2 bouyer auth += 2;
2128 1.27.2.2 bouyer
2129 1.27.2.2 bouyer m->m_pkthdr.len = m->m_len = auth - mtod(m, u_int8_t *);
2130 1.27.2.2 bouyer IF_ENQUEUE(&sc->sc_mgtq, m);
2131 1.27.2.2 bouyer awi_start(ifp);
2132 1.27.2.2 bouyer
2133 1.27.2.2 bouyer sc->sc_mgt_timer = AWI_TRANS_TIMEOUT / 1000;
2134 1.27.2.2 bouyer ifp->if_timer = 1;
2135 1.27.2.2 bouyer }
2136 1.27.2.2 bouyer
2137 1.27.2.2 bouyer static void
2138 1.27.2.2 bouyer awi_recv_auth(sc, m0)
2139 1.27.2.2 bouyer struct awi_softc *sc;
2140 1.27.2.2 bouyer struct mbuf *m0;
2141 1.27.2.2 bouyer {
2142 1.27.2.2 bouyer struct ieee80211_frame *wh;
2143 1.27.2.2 bouyer u_int8_t *auth, *eframe;
2144 1.27.2.2 bouyer struct awi_bss *bp;
2145 1.27.2.2 bouyer u_int16_t status;
2146 1.27.2.2 bouyer
2147 1.27.2.2 bouyer wh = mtod(m0, struct ieee80211_frame *);
2148 1.27.2.2 bouyer auth = (u_int8_t *)&wh[1];
2149 1.27.2.2 bouyer eframe = mtod(m0, u_int8_t *) + m0->m_len;
2150 1.27.2.2 bouyer if (sc->sc_ifp->if_flags & IFF_DEBUG)
2151 1.27.2.2 bouyer printf("%s: receive auth from %s\n", sc->sc_dev.dv_xname,
2152 1.27.2.2 bouyer ether_sprintf(wh->i_addr2));
2153 1.27.2.2 bouyer
2154 1.27.2.2 bouyer /* algorithm number */
2155 1.27.2.2 bouyer if (LE_READ_2(auth) != IEEE80211_AUTH_ALG_OPEN)
2156 1.27.2.2 bouyer return;
2157 1.27.2.2 bouyer auth += 2;
2158 1.27.2.2 bouyer if (!sc->sc_mib_local.Network_Mode) {
2159 1.27.2.2 bouyer if (sc->sc_status != AWI_ST_RUNNING)
2160 1.27.2.2 bouyer return;
2161 1.27.2.2 bouyer if (LE_READ_2(auth) == 1)
2162 1.27.2.2 bouyer awi_send_auth(sc, 2);
2163 1.27.2.2 bouyer return;
2164 1.27.2.2 bouyer }
2165 1.27.2.2 bouyer if (sc->sc_status != AWI_ST_AUTH)
2166 1.27.2.2 bouyer return;
2167 1.27.2.2 bouyer /* sequence number */
2168 1.27.2.2 bouyer if (LE_READ_2(auth) != 2)
2169 1.27.2.2 bouyer return;
2170 1.27.2.2 bouyer auth += 2;
2171 1.27.2.2 bouyer /* status */
2172 1.27.2.2 bouyer status = LE_READ_2(auth);
2173 1.27.2.2 bouyer if (status != 0) {
2174 1.27.2.2 bouyer printf("%s: authentication failed (reason %d)\n",
2175 1.27.2.2 bouyer sc->sc_dev.dv_xname, status);
2176 1.27.2.2 bouyer for (bp = TAILQ_FIRST(&sc->sc_scan); bp != NULL;
2177 1.27.2.2 bouyer bp = TAILQ_NEXT(bp, list)) {
2178 1.27.2.2 bouyer if (memcmp(bp->esrc, sc->sc_bss.esrc, ETHER_ADDR_LEN)
2179 1.27.2.2 bouyer == 0) {
2180 1.27.2.2 bouyer bp->fails++;
2181 1.27.2.2 bouyer break;
2182 1.27.2.2 bouyer }
2183 1.27.2.2 bouyer }
2184 1.27.2.2 bouyer return;
2185 1.27.2.2 bouyer }
2186 1.27.2.2 bouyer sc->sc_mgt_timer = 0;
2187 1.27.2.2 bouyer awi_drvstate(sc, AWI_DRV_INFAUTH);
2188 1.27.2.2 bouyer awi_send_asreq(sc, 0);
2189 1.27.2.2 bouyer }
2190 1.27.2.2 bouyer
2191 1.27.2.2 bouyer static void
2192 1.27.2.2 bouyer awi_send_asreq(sc, reassoc)
2193 1.27.2.2 bouyer struct awi_softc *sc;
2194 1.27.2.2 bouyer int reassoc;
2195 1.27.2.2 bouyer {
2196 1.27.2.2 bouyer struct ifnet *ifp = sc->sc_ifp;
2197 1.27.2.2 bouyer struct mbuf *m;
2198 1.27.2.2 bouyer struct ieee80211_frame *wh;
2199 1.27.2.2 bouyer u_int16_t lintval;
2200 1.27.2.2 bouyer u_int8_t *asreq;
2201 1.27.2.2 bouyer
2202 1.27.2.2 bouyer MGETHDR(m, M_DONTWAIT, MT_DATA);
2203 1.27.2.2 bouyer if (m == NULL)
2204 1.27.2.2 bouyer return;
2205 1.27.2.2 bouyer sc->sc_status = AWI_ST_ASSOC;
2206 1.27.2.2 bouyer if (ifp->if_flags & IFF_DEBUG)
2207 1.27.2.2 bouyer printf("%s: sending %sassoc req to %s\n", sc->sc_dev.dv_xname,
2208 1.27.2.2 bouyer reassoc ? "re" : "",
2209 1.27.2.2 bouyer ether_sprintf(sc->sc_bss.bssid));
2210 1.27.2.2 bouyer
2211 1.27.2.2 bouyer wh = mtod(m, struct ieee80211_frame *);
2212 1.27.2.2 bouyer wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT;
2213 1.27.2.2 bouyer if (reassoc)
2214 1.27.2.2 bouyer wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_REASSOC_REQ;
2215 1.27.2.2 bouyer else
2216 1.27.2.2 bouyer wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_ASSOC_REQ;
2217 1.27.2.2 bouyer wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
2218 1.27.2.2 bouyer LE_WRITE_2(wh->i_dur, 0);
2219 1.27.2.2 bouyer LE_WRITE_2(wh->i_seq, 0);
2220 1.27.2.2 bouyer memcpy(wh->i_addr1, sc->sc_bss.esrc, ETHER_ADDR_LEN);
2221 1.27.2.2 bouyer memcpy(wh->i_addr2, sc->sc_mib_addr.aMAC_Address, ETHER_ADDR_LEN);
2222 1.27.2.2 bouyer memcpy(wh->i_addr3, sc->sc_bss.bssid, ETHER_ADDR_LEN);
2223 1.27.2.2 bouyer
2224 1.27.2.2 bouyer asreq = (u_int8_t *)&wh[1];
2225 1.27.2.2 bouyer
2226 1.27.2.2 bouyer /* capability info */
2227 1.27.2.2 bouyer if (sc->sc_wep_algo == NULL)
2228 1.27.2.2 bouyer LE_WRITE_2(asreq, IEEE80211_CAPINFO_CF_POLLABLE);
2229 1.27.2.2 bouyer else
2230 1.27.2.2 bouyer LE_WRITE_2(asreq,
2231 1.27.2.2 bouyer IEEE80211_CAPINFO_CF_POLLABLE | IEEE80211_CAPINFO_PRIVACY);
2232 1.27.2.2 bouyer asreq += 2;
2233 1.27.2.2 bouyer /* listen interval */
2234 1.27.2.2 bouyer lintval = LE_READ_2(&sc->sc_mib_mgt.aListen_Interval);
2235 1.27.2.2 bouyer LE_WRITE_2(asreq, lintval);
2236 1.27.2.2 bouyer asreq += 2;
2237 1.27.2.2 bouyer if (reassoc) {
2238 1.27.2.2 bouyer /* current AP address */
2239 1.27.2.2 bouyer memcpy(asreq, sc->sc_bss.bssid, ETHER_ADDR_LEN);
2240 1.27.2.2 bouyer asreq += ETHER_ADDR_LEN;
2241 1.27.2.2 bouyer }
2242 1.27.2.2 bouyer /* ssid */
2243 1.27.2.2 bouyer memcpy(asreq, sc->sc_bss.essid, 2 + sc->sc_bss.essid[1]);
2244 1.27.2.2 bouyer asreq += 2 + asreq[1];
2245 1.27.2.2 bouyer /* supported rates */
2246 1.27.2.2 bouyer memcpy(asreq, &sc->sc_mib_phy.aSuprt_Data_Rates, 4);
2247 1.27.2.2 bouyer asreq += 2 + asreq[1];
2248 1.27.2.2 bouyer
2249 1.27.2.2 bouyer m->m_pkthdr.len = m->m_len = asreq - mtod(m, u_int8_t *);
2250 1.27.2.2 bouyer IF_ENQUEUE(&sc->sc_mgtq, m);
2251 1.27.2.2 bouyer awi_start(ifp);
2252 1.27.2.2 bouyer
2253 1.27.2.2 bouyer sc->sc_mgt_timer = AWI_TRANS_TIMEOUT / 1000;
2254 1.27.2.2 bouyer ifp->if_timer = 1;
2255 1.27.2.2 bouyer }
2256 1.27.2.2 bouyer
2257 1.27.2.2 bouyer static void
2258 1.27.2.2 bouyer awi_recv_asresp(sc, m0)
2259 1.27.2.2 bouyer struct awi_softc *sc;
2260 1.27.2.2 bouyer struct mbuf *m0;
2261 1.27.2.2 bouyer {
2262 1.27.2.2 bouyer struct ieee80211_frame *wh;
2263 1.27.2.2 bouyer u_int8_t *asresp, *eframe;
2264 1.27.2.2 bouyer u_int16_t status;
2265 1.27.2.2 bouyer u_int8_t rate, *phy_rates;
2266 1.27.2.2 bouyer struct awi_bss *bp;
2267 1.27.2.2 bouyer int i, j;
2268 1.27.2.2 bouyer
2269 1.27.2.2 bouyer wh = mtod(m0, struct ieee80211_frame *);
2270 1.27.2.2 bouyer asresp = (u_int8_t *)&wh[1];
2271 1.27.2.2 bouyer eframe = mtod(m0, u_int8_t *) + m0->m_len;
2272 1.27.2.2 bouyer if (sc->sc_ifp->if_flags & IFF_DEBUG)
2273 1.27.2.2 bouyer printf("%s: receive assoc resp from %s\n", sc->sc_dev.dv_xname,
2274 1.27.2.2 bouyer ether_sprintf(wh->i_addr2));
2275 1.27.2.2 bouyer
2276 1.27.2.2 bouyer if (!sc->sc_mib_local.Network_Mode)
2277 1.27.2.2 bouyer return;
2278 1.27.2.2 bouyer
2279 1.27.2.2 bouyer if (sc->sc_status != AWI_ST_ASSOC)
2280 1.27.2.2 bouyer return;
2281 1.27.2.2 bouyer /* capability info */
2282 1.27.2.2 bouyer asresp += 2;
2283 1.27.2.2 bouyer /* status */
2284 1.27.2.2 bouyer status = LE_READ_2(asresp);
2285 1.27.2.2 bouyer if (status != 0) {
2286 1.27.2.2 bouyer printf("%s: association failed (reason %d)\n",
2287 1.27.2.2 bouyer sc->sc_dev.dv_xname, status);
2288 1.27.2.2 bouyer for (bp = TAILQ_FIRST(&sc->sc_scan); bp != NULL;
2289 1.27.2.2 bouyer bp = TAILQ_NEXT(bp, list)) {
2290 1.27.2.2 bouyer if (memcmp(bp->esrc, sc->sc_bss.esrc, ETHER_ADDR_LEN)
2291 1.27.2.2 bouyer == 0) {
2292 1.27.2.2 bouyer bp->fails++;
2293 1.27.2.2 bouyer break;
2294 1.27.2.2 bouyer }
2295 1.27.2.2 bouyer }
2296 1.27.2.2 bouyer return;
2297 1.27.2.2 bouyer }
2298 1.27.2.2 bouyer asresp += 2;
2299 1.27.2.2 bouyer /* association id */
2300 1.27.2.2 bouyer asresp += 2;
2301 1.27.2.2 bouyer /* supported rates */
2302 1.27.2.2 bouyer rate = AWI_RATE_1MBIT;
2303 1.27.2.2 bouyer for (i = 0; i < asresp[1]; i++) {
2304 1.27.2.2 bouyer if (AWI_80211_RATE(asresp[2 + i]) <= rate)
2305 1.27.2.2 bouyer continue;
2306 1.27.2.2 bouyer phy_rates = sc->sc_mib_phy.aSuprt_Data_Rates;
2307 1.27.2.2 bouyer for (j = 0; j < phy_rates[1]; j++) {
2308 1.27.2.2 bouyer if (AWI_80211_RATE(asresp[2 + i]) ==
2309 1.27.2.2 bouyer AWI_80211_RATE(phy_rates[2 + j]))
2310 1.27.2.2 bouyer rate = AWI_80211_RATE(asresp[2 + i]);
2311 1.27.2.2 bouyer }
2312 1.27.2.2 bouyer }
2313 1.27.2.2 bouyer if (sc->sc_ifp->if_flags & IFF_DEBUG) {
2314 1.27.2.2 bouyer printf("%s: associated with %s ssid ",
2315 1.27.2.2 bouyer sc->sc_dev.dv_xname, ether_sprintf(sc->sc_bss.bssid));
2316 1.27.2.2 bouyer awi_print_essid(sc->sc_bss.essid);
2317 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH)
2318 1.27.2.2 bouyer printf(" chanset %d pattern %d\n",
2319 1.27.2.2 bouyer sc->sc_bss.chanset, sc->sc_bss.pattern);
2320 1.27.2.2 bouyer else
2321 1.27.2.2 bouyer printf(" channel %d\n", sc->sc_bss.chanset);
2322 1.27.2.2 bouyer }
2323 1.27.2.2 bouyer sc->sc_tx_rate = rate;
2324 1.27.2.2 bouyer sc->sc_mgt_timer = 0;
2325 1.27.2.2 bouyer sc->sc_rx_timer = 10;
2326 1.27.2.2 bouyer sc->sc_ifp->if_timer = 1;
2327 1.27.2.2 bouyer sc->sc_status = AWI_ST_RUNNING;
2328 1.27.2.2 bouyer sc->sc_ifp->if_flags |= IFF_RUNNING;
2329 1.27.2.2 bouyer awi_drvstate(sc, AWI_DRV_INFASSOC);
2330 1.27.2.2 bouyer awi_start(sc->sc_ifp);
2331 1.27.2.2 bouyer }
2332 1.27.2.2 bouyer
2333 1.27.2.2 bouyer static int
2334 1.27.2.2 bouyer awi_mib(sc, cmd, mib)
2335 1.27.2.2 bouyer struct awi_softc *sc;
2336 1.27.2.2 bouyer u_int8_t cmd;
2337 1.27.2.2 bouyer u_int8_t mib;
2338 1.27.2.2 bouyer {
2339 1.27.2.2 bouyer int error;
2340 1.27.2.2 bouyer u_int8_t size, *ptr;
2341 1.27.2.2 bouyer
2342 1.27.2.2 bouyer switch (mib) {
2343 1.27.2.2 bouyer case AWI_MIB_LOCAL:
2344 1.27.2.2 bouyer ptr = (u_int8_t *)&sc->sc_mib_local;
2345 1.27.2.2 bouyer size = sizeof(sc->sc_mib_local);
2346 1.27.2.2 bouyer break;
2347 1.27.2.2 bouyer case AWI_MIB_ADDR:
2348 1.27.2.2 bouyer ptr = (u_int8_t *)&sc->sc_mib_addr;
2349 1.27.2.2 bouyer size = sizeof(sc->sc_mib_addr);
2350 1.27.2.2 bouyer break;
2351 1.27.2.2 bouyer case AWI_MIB_MAC:
2352 1.27.2.2 bouyer ptr = (u_int8_t *)&sc->sc_mib_mac;
2353 1.27.2.2 bouyer size = sizeof(sc->sc_mib_mac);
2354 1.27.2.2 bouyer break;
2355 1.27.2.2 bouyer case AWI_MIB_STAT:
2356 1.27.2.2 bouyer ptr = (u_int8_t *)&sc->sc_mib_stat;
2357 1.27.2.2 bouyer size = sizeof(sc->sc_mib_stat);
2358 1.27.2.2 bouyer break;
2359 1.27.2.2 bouyer case AWI_MIB_MGT:
2360 1.27.2.2 bouyer ptr = (u_int8_t *)&sc->sc_mib_mgt;
2361 1.27.2.2 bouyer size = sizeof(sc->sc_mib_mgt);
2362 1.27.2.2 bouyer break;
2363 1.27.2.2 bouyer case AWI_MIB_PHY:
2364 1.27.2.2 bouyer ptr = (u_int8_t *)&sc->sc_mib_phy;
2365 1.27.2.2 bouyer size = sizeof(sc->sc_mib_phy);
2366 1.27.2.2 bouyer break;
2367 1.27.2.2 bouyer default:
2368 1.27.2.2 bouyer return EINVAL;
2369 1.27.2.2 bouyer }
2370 1.27.2.2 bouyer if (sc->sc_cmd_inprog) {
2371 1.27.2.2 bouyer error = awi_cmd_wait(sc);
2372 1.27.2.2 bouyer if (error) {
2373 1.27.2.2 bouyer if (error == EWOULDBLOCK)
2374 1.27.2.2 bouyer printf("awi_mib: cmd %d inprog",
2375 1.27.2.2 bouyer sc->sc_cmd_inprog);
2376 1.27.2.2 bouyer return error;
2377 1.27.2.2 bouyer }
2378 1.27.2.2 bouyer }
2379 1.27.2.2 bouyer sc->sc_cmd_inprog = cmd;
2380 1.27.2.2 bouyer if (cmd == AWI_CMD_SET_MIB)
2381 1.27.2.2 bouyer awi_write_bytes(sc, AWI_CMD_PARAMS+AWI_CA_MIB_DATA, ptr, size);
2382 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_MIB_TYPE, mib);
2383 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_MIB_SIZE, size);
2384 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_MIB_INDEX, 0);
2385 1.27.2.2 bouyer error = awi_cmd(sc, cmd);
2386 1.27.2.2 bouyer if (error)
2387 1.27.2.2 bouyer return error;
2388 1.27.2.2 bouyer if (cmd == AWI_CMD_GET_MIB) {
2389 1.27.2.2 bouyer awi_read_bytes(sc, AWI_CMD_PARAMS+AWI_CA_MIB_DATA, ptr, size);
2390 1.27.2.2 bouyer #ifdef AWI_DEBUG
2391 1.27.2.2 bouyer if (awi_verbose) {
2392 1.27.2.2 bouyer int i;
2393 1.27.2.2 bouyer
2394 1.27.2.2 bouyer printf("awi_mib: #%d:", mib);
2395 1.27.2.2 bouyer for (i = 0; i < size; i++)
2396 1.27.2.2 bouyer printf(" %02x", ptr[i]);
2397 1.27.2.2 bouyer printf("\n");
2398 1.27.2.2 bouyer }
2399 1.27.2.2 bouyer #endif
2400 1.27.2.2 bouyer }
2401 1.27.2.2 bouyer return 0;
2402 1.27.2.2 bouyer }
2403 1.27.2.2 bouyer
2404 1.27.2.2 bouyer static int
2405 1.27.2.2 bouyer awi_cmd_scan(sc)
2406 1.27.2.2 bouyer struct awi_softc *sc;
2407 1.27.2.2 bouyer {
2408 1.27.2.2 bouyer int error;
2409 1.27.2.2 bouyer u_int8_t scan_mode;
2410 1.27.2.2 bouyer
2411 1.27.2.2 bouyer if (sc->sc_active_scan)
2412 1.27.2.2 bouyer scan_mode = AWI_SCAN_ACTIVE;
2413 1.27.2.2 bouyer else
2414 1.27.2.2 bouyer scan_mode = AWI_SCAN_PASSIVE;
2415 1.27.2.2 bouyer if (sc->sc_mib_mgt.aScan_Mode != scan_mode) {
2416 1.27.2.2 bouyer sc->sc_mib_mgt.aScan_Mode = scan_mode;
2417 1.27.2.2 bouyer error = awi_mib(sc, AWI_CMD_SET_MIB, AWI_MIB_MGT);
2418 1.27.2.2 bouyer return error;
2419 1.27.2.2 bouyer }
2420 1.27.2.2 bouyer
2421 1.27.2.2 bouyer if (sc->sc_cmd_inprog) {
2422 1.27.2.2 bouyer error = awi_cmd_wait(sc);
2423 1.27.2.2 bouyer if (error)
2424 1.27.2.2 bouyer return error;
2425 1.27.2.2 bouyer }
2426 1.27.2.2 bouyer sc->sc_cmd_inprog = AWI_CMD_SCAN;
2427 1.27.2.2 bouyer awi_write_2(sc, AWI_CMD_PARAMS+AWI_CA_SCAN_DURATION,
2428 1.27.2.2 bouyer sc->sc_active_scan ? AWI_ASCAN_DURATION : AWI_PSCAN_DURATION);
2429 1.27.2.2 bouyer if (sc->sc_mib_phy.IEEE_PHY_Type == AWI_PHY_TYPE_FH) {
2430 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_SCAN_SET,
2431 1.27.2.2 bouyer sc->sc_scan_set);
2432 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_SCAN_PATTERN,
2433 1.27.2.2 bouyer sc->sc_scan_cur);
2434 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_SCAN_IDX, 1);
2435 1.27.2.2 bouyer } else {
2436 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_SCAN_SET,
2437 1.27.2.2 bouyer sc->sc_scan_cur);
2438 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_SCAN_PATTERN, 0);
2439 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_SCAN_IDX, 0);
2440 1.27.2.2 bouyer }
2441 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_PARAMS+AWI_CA_SCAN_SUSP, 0);
2442 1.27.2.2 bouyer return awi_cmd(sc, AWI_CMD_SCAN);
2443 1.27.2.2 bouyer }
2444 1.27.2.2 bouyer
2445 1.27.2.2 bouyer static int
2446 1.27.2.2 bouyer awi_cmd(sc, cmd)
2447 1.27.2.2 bouyer struct awi_softc *sc;
2448 1.27.2.2 bouyer u_int8_t cmd;
2449 1.27.2.2 bouyer {
2450 1.27.2.2 bouyer u_int8_t status;
2451 1.27.2.2 bouyer int error = 0;
2452 1.27.2.2 bouyer
2453 1.27.2.2 bouyer sc->sc_cmd_inprog = cmd;
2454 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD_STATUS, AWI_STAT_IDLE);
2455 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD, cmd);
2456 1.27.2.2 bouyer if (sc->sc_status != AWI_ST_INIT)
2457 1.27.2.2 bouyer return 0;
2458 1.27.2.2 bouyer error = awi_cmd_wait(sc);
2459 1.27.2.2 bouyer if (error)
2460 1.27.2.2 bouyer return error;
2461 1.27.2.2 bouyer status = awi_read_1(sc, AWI_CMD_STATUS);
2462 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD, 0);
2463 1.27.2.2 bouyer switch (status) {
2464 1.27.2.2 bouyer case AWI_STAT_OK:
2465 1.27.2.2 bouyer break;
2466 1.27.2.2 bouyer case AWI_STAT_BADPARM:
2467 1.27.2.2 bouyer return EINVAL;
2468 1.27.2.2 bouyer default:
2469 1.27.2.2 bouyer printf("%s: command %d failed %x\n",
2470 1.27.2.2 bouyer sc->sc_dev.dv_xname, cmd, status);
2471 1.27.2.2 bouyer return ENXIO;
2472 1.27.2.2 bouyer }
2473 1.27.2.2 bouyer return 0;
2474 1.27.2.2 bouyer }
2475 1.27.2.2 bouyer
2476 1.27.2.2 bouyer static void
2477 1.27.2.2 bouyer awi_cmd_done(sc)
2478 1.27.2.2 bouyer struct awi_softc *sc;
2479 1.27.2.2 bouyer {
2480 1.27.2.2 bouyer u_int8_t cmd, status;
2481 1.27.2.2 bouyer
2482 1.27.2.2 bouyer status = awi_read_1(sc, AWI_CMD_STATUS);
2483 1.27.2.2 bouyer if (status == AWI_STAT_IDLE)
2484 1.27.2.2 bouyer return; /* stray interrupt */
2485 1.27.2.2 bouyer
2486 1.27.2.2 bouyer cmd = sc->sc_cmd_inprog;
2487 1.27.2.2 bouyer sc->sc_cmd_inprog = 0;
2488 1.27.2.2 bouyer if (sc->sc_status == AWI_ST_INIT) {
2489 1.27.2.2 bouyer wakeup(sc);
2490 1.27.2.2 bouyer return;
2491 1.27.2.2 bouyer }
2492 1.27.2.2 bouyer awi_write_1(sc, AWI_CMD, 0);
2493 1.27.2.2 bouyer
2494 1.27.2.2 bouyer if (status != AWI_STAT_OK) {
2495 1.27.2.2 bouyer printf("%s: command %d failed %x\n",
2496 1.27.2.2 bouyer sc->sc_dev.dv_xname, cmd, status);
2497 1.27.2.2 bouyer return;
2498 1.27.2.2 bouyer }
2499 1.27.2.2 bouyer switch (sc->sc_status) {
2500 1.27.2.2 bouyer case AWI_ST_SCAN:
2501 1.27.2.2 bouyer if (cmd == AWI_CMD_SET_MIB)
2502 1.27.2.2 bouyer awi_cmd_scan(sc); /* retry */
2503 1.27.2.2 bouyer break;
2504 1.27.2.2 bouyer case AWI_ST_SETSS:
2505 1.27.2.2 bouyer awi_try_sync(sc);
2506 1.27.2.2 bouyer break;
2507 1.27.2.2 bouyer case AWI_ST_SYNC:
2508 1.27.2.2 bouyer awi_sync_done(sc);
2509 1.27.2.2 bouyer break;
2510 1.27.2.2 bouyer default:
2511 1.27.2.2 bouyer break;
2512 1.27.2.2 bouyer }
2513 1.27.2.2 bouyer }
2514 1.27.2.2 bouyer
2515 1.27.2.2 bouyer static int
2516 1.27.2.2 bouyer awi_next_txd(sc, len, framep, ntxdp)
2517 1.27.2.2 bouyer struct awi_softc *sc;
2518 1.27.2.2 bouyer int len;
2519 1.27.2.2 bouyer u_int32_t *framep, *ntxdp;
2520 1.27.2.2 bouyer {
2521 1.27.2.2 bouyer u_int32_t txd, ntxd, frame;
2522 1.27.2.2 bouyer
2523 1.27.2.2 bouyer txd = sc->sc_txnext;
2524 1.27.2.2 bouyer frame = txd + AWI_TXD_SIZE;
2525 1.27.2.2 bouyer if (frame + len > sc->sc_txend)
2526 1.27.2.2 bouyer frame = sc->sc_txbase;
2527 1.27.2.2 bouyer ntxd = frame + len;
2528 1.27.2.2 bouyer if (ntxd + AWI_TXD_SIZE > sc->sc_txend)
2529 1.27.2.2 bouyer ntxd = sc->sc_txbase;
2530 1.27.2.2 bouyer *framep = frame;
2531 1.27.2.2 bouyer *ntxdp = ntxd;
2532 1.27.2.2 bouyer /*
2533 1.27.2.2 bouyer * Determine if there are any room in ring buffer.
2534 1.27.2.2 bouyer * --- send wait, === new data, +++ conflict (ENOBUFS)
2535 1.27.2.2 bouyer * base........................end
2536 1.27.2.2 bouyer * done----txd=====ntxd OK
2537 1.27.2.2 bouyer * --txd=====done++++ntxd-- full
2538 1.27.2.2 bouyer * --txd=====ntxd done-- OK
2539 1.27.2.2 bouyer * ==ntxd done----txd=== OK
2540 1.27.2.2 bouyer * ==done++++ntxd----txd=== full
2541 1.27.2.2 bouyer * ++ntxd txd=====done++ full
2542 1.27.2.2 bouyer */
2543 1.27.2.2 bouyer if (txd < ntxd) {
2544 1.27.2.2 bouyer if (txd < sc->sc_txdone && ntxd + AWI_TXD_SIZE > sc->sc_txdone)
2545 1.27.2.2 bouyer return ENOBUFS;
2546 1.27.2.2 bouyer } else {
2547 1.27.2.2 bouyer if (txd < sc->sc_txdone || ntxd + AWI_TXD_SIZE > sc->sc_txdone)
2548 1.27.2.2 bouyer return ENOBUFS;
2549 1.27.2.2 bouyer }
2550 1.27.2.2 bouyer return 0;
2551 1.27.2.2 bouyer }
2552 1.27.2.2 bouyer
2553 1.27.2.2 bouyer static int
2554 1.27.2.2 bouyer awi_lock(sc)
2555 1.27.2.2 bouyer struct awi_softc *sc;
2556 1.27.2.2 bouyer {
2557 1.27.2.2 bouyer int error = 0;
2558 1.27.2.2 bouyer
2559 1.27.2.2 bouyer if (curproc == NULL) {
2560 1.27.2.2 bouyer /*
2561 1.27.2.2 bouyer * XXX
2562 1.27.2.2 bouyer * Though driver ioctl should be called with context,
2563 1.27.2.2 bouyer * KAME ipv6 stack calls ioctl in interrupt for now.
2564 1.27.2.2 bouyer * We simply abort the request if there are other
2565 1.27.2.2 bouyer * ioctl requests in progress.
2566 1.27.2.2 bouyer */
2567 1.27.2.2 bouyer if (sc->sc_busy) {
2568 1.27.2.2 bouyer return EWOULDBLOCK;
2569 1.27.2.2 bouyer if (sc->sc_invalid)
2570 1.27.2.2 bouyer return ENXIO;
2571 1.27.2.2 bouyer }
2572 1.27.2.2 bouyer sc->sc_busy = 1;
2573 1.27.2.2 bouyer sc->sc_cansleep = 0;
2574 1.27.2.2 bouyer return 0;
2575 1.27.2.2 bouyer }
2576 1.27.2.2 bouyer while (sc->sc_busy) {
2577 1.27.2.2 bouyer if (sc->sc_invalid)
2578 1.27.2.2 bouyer return ENXIO;
2579 1.27.2.2 bouyer sc->sc_sleep_cnt++;
2580 1.27.2.2 bouyer error = tsleep(sc, PWAIT | PCATCH, "awilck", 0);
2581 1.27.2.2 bouyer sc->sc_sleep_cnt--;
2582 1.27.2.2 bouyer if (error)
2583 1.27.2.2 bouyer return error;
2584 1.27.2.2 bouyer }
2585 1.27.2.2 bouyer sc->sc_busy = 1;
2586 1.27.2.2 bouyer sc->sc_cansleep = 1;
2587 1.27.2.2 bouyer return 0;
2588 1.27.2.2 bouyer }
2589 1.27.2.2 bouyer
2590 1.27.2.2 bouyer static void
2591 1.27.2.2 bouyer awi_unlock(sc)
2592 1.27.2.2 bouyer struct awi_softc *sc;
2593 1.27.2.2 bouyer {
2594 1.27.2.2 bouyer sc->sc_busy = 0;
2595 1.27.2.2 bouyer sc->sc_cansleep = 0;
2596 1.27.2.2 bouyer if (sc->sc_sleep_cnt)
2597 1.27.2.2 bouyer wakeup(sc);
2598 1.27.2.2 bouyer }
2599 1.27.2.2 bouyer
2600 1.27.2.2 bouyer static int
2601 1.27.2.2 bouyer awi_intr_lock(sc)
2602 1.27.2.2 bouyer struct awi_softc *sc;
2603 1.27.2.2 bouyer {
2604 1.27.2.2 bouyer u_int8_t status;
2605 1.27.2.2 bouyer int i, retry;
2606 1.27.2.2 bouyer
2607 1.27.2.2 bouyer status = 1;
2608 1.27.2.2 bouyer for (retry = 0; retry < 10; retry++) {
2609 1.27.2.2 bouyer for (i = 0; i < AWI_LOCKOUT_TIMEOUT*1000/5; i++) {
2610 1.27.2.2 bouyer status = awi_read_1(sc, AWI_LOCKOUT_HOST);
2611 1.27.2.2 bouyer if (status == 0)
2612 1.27.2.2 bouyer break;
2613 1.27.2.2 bouyer DELAY(5);
2614 1.27.2.2 bouyer }
2615 1.27.2.2 bouyer if (status != 0)
2616 1.27.2.2 bouyer break;
2617 1.27.2.2 bouyer awi_write_1(sc, AWI_LOCKOUT_MAC, 1);
2618 1.27.2.2 bouyer status = awi_read_1(sc, AWI_LOCKOUT_HOST);
2619 1.27.2.2 bouyer if (status == 0)
2620 1.27.2.2 bouyer break;
2621 1.27.2.2 bouyer awi_write_1(sc, AWI_LOCKOUT_MAC, 0);
2622 1.27.2.2 bouyer }
2623 1.27.2.2 bouyer if (status != 0) {
2624 1.27.2.2 bouyer printf("%s: failed to lock interrupt\n",
2625 1.27.2.2 bouyer sc->sc_dev.dv_xname);
2626 1.27.2.2 bouyer return ENXIO;
2627 1.27.2.2 bouyer }
2628 1.27.2.2 bouyer return 0;
2629 1.27.2.2 bouyer }
2630 1.27.2.2 bouyer
2631 1.27.2.2 bouyer static void
2632 1.27.2.2 bouyer awi_intr_unlock(sc)
2633 1.27.2.2 bouyer struct awi_softc *sc;
2634 1.27.2.2 bouyer {
2635 1.27.2.2 bouyer
2636 1.27.2.2 bouyer awi_write_1(sc, AWI_LOCKOUT_MAC, 0);
2637 1.27.2.2 bouyer }
2638 1.27.2.2 bouyer
2639 1.27.2.2 bouyer static int
2640 1.27.2.2 bouyer awi_cmd_wait(sc)
2641 1.27.2.2 bouyer struct awi_softc *sc;
2642 1.27.2.2 bouyer {
2643 1.27.2.2 bouyer int i, error = 0;
2644 1.27.2.2 bouyer
2645 1.27.2.2 bouyer i = 0;
2646 1.27.2.2 bouyer while (sc->sc_cmd_inprog) {
2647 1.27.2.2 bouyer if (sc->sc_invalid)
2648 1.27.2.2 bouyer return ENXIO;
2649 1.27.2.2 bouyer if (awi_read_1(sc, AWI_CMD) != sc->sc_cmd_inprog) {
2650 1.27.2.2 bouyer printf("%s: failed to access hardware\n",
2651 1.27.2.2 bouyer sc->sc_dev.dv_xname);
2652 1.27.2.2 bouyer sc->sc_invalid = 1;
2653 1.27.2.2 bouyer return ENXIO;
2654 1.27.2.2 bouyer }
2655 1.27.2.2 bouyer if (sc->sc_cansleep) {
2656 1.27.2.2 bouyer sc->sc_sleep_cnt++;
2657 1.27.2.2 bouyer error = tsleep(sc, PWAIT, "awicmd",
2658 1.27.2.2 bouyer AWI_CMD_TIMEOUT*hz/1000);
2659 1.27.2.2 bouyer sc->sc_sleep_cnt--;
2660 1.27.2.2 bouyer } else {
2661 1.27.2.2 bouyer if (awi_read_1(sc, AWI_CMD_STATUS) != AWI_STAT_IDLE) {
2662 1.27.2.2 bouyer awi_cmd_done(sc);
2663 1.27.2.2 bouyer break;
2664 1.27.2.2 bouyer }
2665 1.27.2.2 bouyer if (i++ >= AWI_CMD_TIMEOUT*1000/10)
2666 1.27.2.2 bouyer error = EWOULDBLOCK;
2667 1.27.2.2 bouyer else
2668 1.27.2.2 bouyer DELAY(10);
2669 1.27.2.2 bouyer }
2670 1.27.2.2 bouyer if (error)
2671 1.27.2.2 bouyer break;
2672 1.27.2.2 bouyer }
2673 1.27.2.2 bouyer return error;
2674 1.27.2.2 bouyer }
2675 1.27.2.2 bouyer
2676 1.27.2.2 bouyer static void
2677 1.27.2.2 bouyer awi_print_essid(essid)
2678 1.27.2.2 bouyer u_int8_t *essid;
2679 1.27.2.2 bouyer {
2680 1.27.2.2 bouyer int i, len;
2681 1.27.2.2 bouyer u_int8_t *p;
2682 1.27.2.2 bouyer
2683 1.27.2.2 bouyer len = essid[1];
2684 1.27.2.2 bouyer if (len > IEEE80211_NWID_LEN)
2685 1.27.2.2 bouyer len = IEEE80211_NWID_LEN; /*XXX*/
2686 1.27.2.2 bouyer /* determine printable or not */
2687 1.27.2.2 bouyer for (i = 0, p = essid + 2; i < len; i++, p++) {
2688 1.27.2.2 bouyer if (*p < ' ' || *p > 0x7e)
2689 1.27.2.2 bouyer break;
2690 1.27.2.2 bouyer }
2691 1.27.2.2 bouyer if (i == len) {
2692 1.27.2.2 bouyer printf("\"");
2693 1.27.2.2 bouyer for (i = 0, p = essid + 2; i < len; i++, p++)
2694 1.27.2.2 bouyer printf("%c", *p);
2695 1.27.2.2 bouyer printf("\"");
2696 1.27.2.2 bouyer } else {
2697 1.27.2.2 bouyer printf("0x");
2698 1.27.2.2 bouyer for (i = 0, p = essid + 2; i < len; i++, p++)
2699 1.27.2.2 bouyer printf("%02x", *p);
2700 1.27.2.2 bouyer }
2701 1.27.2.2 bouyer }
2702 1.27.2.2 bouyer
2703 1.27.2.2 bouyer #ifdef AWI_DEBUG
2704 1.27.2.2 bouyer static void
2705 1.27.2.2 bouyer awi_dump_pkt(sc, m, rssi)
2706 1.27.2.2 bouyer struct awi_softc *sc;
2707 1.27.2.2 bouyer struct mbuf *m;
2708 1.27.2.2 bouyer int rssi;
2709 1.27.2.2 bouyer {
2710 1.27.2.2 bouyer struct ieee80211_frame *wh;
2711 1.27.2.2 bouyer int i, l;
2712 1.27.2.2 bouyer
2713 1.27.2.2 bouyer wh = mtod(m, struct ieee80211_frame *);
2714 1.27.2.2 bouyer
2715 1.27.2.2 bouyer if (awi_dump_mask != 0 &&
2716 1.27.2.2 bouyer ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK)==IEEE80211_FC1_DIR_NODS) &&
2717 1.27.2.2 bouyer ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK)==IEEE80211_FC0_TYPE_MGT)) {
2718 1.27.2.2 bouyer if ((AWI_DUMP_MASK(wh->i_fc[0]) & awi_dump_mask) != 0)
2719 1.27.2.2 bouyer return;
2720 1.27.2.2 bouyer }
2721 1.27.2.2 bouyer if (awi_dump_mask < 0 &&
2722 1.27.2.2 bouyer (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK)==IEEE80211_FC0_TYPE_DATA)
2723 1.27.2.2 bouyer return;
2724 1.27.2.2 bouyer
2725 1.27.2.2 bouyer if (rssi < 0)
2726 1.27.2.2 bouyer printf("tx: ");
2727 1.27.2.2 bouyer else
2728 1.27.2.2 bouyer printf("rx: ");
2729 1.27.2.2 bouyer switch (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) {
2730 1.27.2.2 bouyer case IEEE80211_FC1_DIR_NODS:
2731 1.27.2.2 bouyer printf("NODS %s", ether_sprintf(wh->i_addr2));
2732 1.27.2.2 bouyer printf("->%s", ether_sprintf(wh->i_addr1));
2733 1.27.2.2 bouyer printf("(%s)", ether_sprintf(wh->i_addr3));
2734 1.27.2.2 bouyer break;
2735 1.27.2.2 bouyer case IEEE80211_FC1_DIR_TODS:
2736 1.27.2.2 bouyer printf("TODS %s", ether_sprintf(wh->i_addr2));
2737 1.27.2.2 bouyer printf("->%s", ether_sprintf(wh->i_addr3));
2738 1.27.2.2 bouyer printf("(%s)", ether_sprintf(wh->i_addr1));
2739 1.27.2.2 bouyer break;
2740 1.27.2.2 bouyer case IEEE80211_FC1_DIR_FROMDS:
2741 1.27.2.2 bouyer printf("FRDS %s", ether_sprintf(wh->i_addr3));
2742 1.27.2.2 bouyer printf("->%s", ether_sprintf(wh->i_addr1));
2743 1.27.2.2 bouyer printf("(%s)", ether_sprintf(wh->i_addr2));
2744 1.27.2.2 bouyer break;
2745 1.27.2.2 bouyer case IEEE80211_FC1_DIR_DSTODS:
2746 1.27.2.2 bouyer printf("DSDS %s", ether_sprintf((u_int8_t *)&wh[1]));
2747 1.27.2.2 bouyer printf("->%s", ether_sprintf(wh->i_addr3));
2748 1.27.2.2 bouyer printf("(%s", ether_sprintf(wh->i_addr2));
2749 1.27.2.2 bouyer printf("->%s)", ether_sprintf(wh->i_addr1));
2750 1.27.2.2 bouyer break;
2751 1.27.2.2 bouyer }
2752 1.27.2.2 bouyer switch (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) {
2753 1.27.2.2 bouyer case IEEE80211_FC0_TYPE_DATA:
2754 1.27.2.2 bouyer printf(" data");
2755 1.27.2.2 bouyer break;
2756 1.27.2.2 bouyer case IEEE80211_FC0_TYPE_MGT:
2757 1.27.2.2 bouyer switch (wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) {
2758 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_PROBE_REQ:
2759 1.27.2.2 bouyer printf(" probe_req");
2760 1.27.2.2 bouyer break;
2761 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
2762 1.27.2.2 bouyer printf(" probe_resp");
2763 1.27.2.2 bouyer break;
2764 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_BEACON:
2765 1.27.2.2 bouyer printf(" beacon");
2766 1.27.2.2 bouyer break;
2767 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_AUTH:
2768 1.27.2.2 bouyer printf(" auth");
2769 1.27.2.2 bouyer break;
2770 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_ASSOC_REQ:
2771 1.27.2.2 bouyer printf(" assoc_req");
2772 1.27.2.2 bouyer break;
2773 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_ASSOC_RESP:
2774 1.27.2.2 bouyer printf(" assoc_resp");
2775 1.27.2.2 bouyer break;
2776 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_REASSOC_REQ:
2777 1.27.2.2 bouyer printf(" reassoc_req");
2778 1.27.2.2 bouyer break;
2779 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_REASSOC_RESP:
2780 1.27.2.2 bouyer printf(" reassoc_resp");
2781 1.27.2.2 bouyer break;
2782 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_DEAUTH:
2783 1.27.2.2 bouyer printf(" deauth");
2784 1.27.2.2 bouyer break;
2785 1.27.2.2 bouyer case IEEE80211_FC0_SUBTYPE_DISASSOC:
2786 1.27.2.2 bouyer printf(" disassoc");
2787 1.27.2.2 bouyer break;
2788 1.27.2.2 bouyer default:
2789 1.27.2.2 bouyer printf(" mgt#%d",
2790 1.27.2.2 bouyer wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK);
2791 1.27.2.2 bouyer break;
2792 1.27.2.2 bouyer }
2793 1.27.2.2 bouyer break;
2794 1.27.2.2 bouyer default:
2795 1.27.2.2 bouyer printf(" type#%d",
2796 1.27.2.2 bouyer wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK);
2797 1.27.2.2 bouyer break;
2798 1.27.2.2 bouyer }
2799 1.27.2.2 bouyer if (wh->i_fc[1] & IEEE80211_FC1_WEP)
2800 1.27.2.2 bouyer printf(" WEP");
2801 1.27.2.2 bouyer if (rssi >= 0)
2802 1.27.2.2 bouyer printf(" +%d", rssi);
2803 1.27.2.2 bouyer printf("\n");
2804 1.27.2.2 bouyer if (awi_dump_len > 0) {
2805 1.27.2.2 bouyer l = m->m_len;
2806 1.27.2.2 bouyer if (l > awi_dump_len + sizeof(*wh))
2807 1.27.2.2 bouyer l = awi_dump_len + sizeof(*wh);
2808 1.27.2.2 bouyer i = sizeof(*wh);
2809 1.27.2.2 bouyer if (awi_dump_hdr)
2810 1.27.2.2 bouyer i = 0;
2811 1.27.2.2 bouyer for (; i < l; i++) {
2812 1.27.2.2 bouyer if ((i & 1) == 0)
2813 1.27.2.2 bouyer printf(" ");
2814 1.27.2.2 bouyer printf("%02x", mtod(m, u_int8_t *)[i]);
2815 1.27.2.2 bouyer }
2816 1.27.2.2 bouyer printf("\n");
2817 1.27.2.2 bouyer }
2818 1.27.2.2 bouyer }
2819 1.27.2.2 bouyer #endif
2820