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