| 1 | /* $NetBSD: wivar.h,v 1.65 2011/08/15 18:24:34 dyoung Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 1997, 1998, 1999 |
| 5 | * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. All advertising materials mentioning features or use of this software |
| 16 | * must display the following acknowledgement: |
| 17 | * This product includes software developed by Bill Paul. |
| 18 | * 4. Neither the name of the author nor the names of any co-contributors |
| 19 | * may be used to endorse or promote products derived from this software |
| 20 | * without specific prior written permission. |
| 21 | * |
| 22 | * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND |
| 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 25 | * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD |
| 26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 32 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | */ |
| 34 | |
| 35 | #include <sys/mutex.h> |
| 36 | #include <sys/condvar.h> |
| 37 | #include <sys/lwp.h> |
| 38 | |
| 39 | /* Radio capture format for Prism. */ |
| 40 | |
| 41 | #define WI_RX_RADIOTAP_PRESENT ((1 << IEEE80211_RADIOTAP_FLAGS) | \ |
| 42 | (1 << IEEE80211_RADIOTAP_RATE) | \ |
| 43 | (1 << IEEE80211_RADIOTAP_CHANNEL) | \ |
| 44 | (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \ |
| 45 | (1 << IEEE80211_RADIOTAP_DB_ANTNOISE)) |
| 46 | |
| 47 | struct { |
| 48 | struct ieee80211_radiotap_header ; |
| 49 | u_int8_t ; |
| 50 | u_int8_t ; |
| 51 | u_int16_t ; |
| 52 | u_int16_t ; |
| 53 | int8_t ; |
| 54 | int8_t ; |
| 55 | } __packed; |
| 56 | |
| 57 | #define WI_TX_RADIOTAP_PRESENT ((1 << IEEE80211_RADIOTAP_FLAGS) | \ |
| 58 | (1 << IEEE80211_RADIOTAP_RATE) | \ |
| 59 | (1 << IEEE80211_RADIOTAP_CHANNEL)) |
| 60 | |
| 61 | struct { |
| 62 | struct ieee80211_radiotap_header ; |
| 63 | u_int8_t ; |
| 64 | u_int8_t ; |
| 65 | u_int16_t ; |
| 66 | u_int16_t ; |
| 67 | } __packed; |
| 68 | |
| 69 | struct { |
| 70 | struct ieee80211_rssdesc ; |
| 71 | SLIST_ENTRY(wi_rssdesc) ; |
| 72 | }; |
| 73 | |
| 74 | typedef SLIST_HEAD(,wi_rssdesc) ; |
| 75 | |
| 76 | /* |
| 77 | * FreeBSD driver ported to NetBSD by Bill Sommerfeld in the back of the |
| 78 | * Oslo IETF plenary meeting. |
| 79 | */ |
| 80 | struct wi_softc { |
| 81 | device_t sc_dev; |
| 82 | struct ethercom sc_ec; |
| 83 | struct ieee80211com sc_ic; |
| 84 | u_int32_t sc_ic_flags; /* backup of ic->ic_flags */ |
| 85 | void *sc_ih; /* interrupt handler */ |
| 86 | int (*sc_enable)(device_t, int); |
| 87 | void (*sc_reset)(struct wi_softc *); |
| 88 | |
| 89 | int (*sc_newstate)(struct ieee80211com *, |
| 90 | enum ieee80211_state, int); |
| 91 | void (*sc_set_tim)(struct ieee80211_node *, int); |
| 92 | |
| 93 | int sc_attached; |
| 94 | int sc_enabled; |
| 95 | int sc_invalid; |
| 96 | int sc_firmware_type; |
| 97 | #define WI_NOTYPE 0 |
| 98 | #define WI_LUCENT 1 |
| 99 | #define WI_INTERSIL 2 |
| 100 | #define WI_SYMBOL 3 |
| 101 | int sc_pri_firmware_ver; /* Primary firm vers */ |
| 102 | int sc_sta_firmware_ver; /* Station firm vers */ |
| 103 | int sc_pci; /* attach to PCI-Bus */ |
| 104 | |
| 105 | bus_space_tag_t sc_iot; /* bus cookie */ |
| 106 | bus_space_handle_t sc_ioh; /* bus i/o handle */ |
| 107 | |
| 108 | struct bpf_if * sc_drvbpf; |
| 109 | int sc_flags; |
| 110 | int sc_bap_id; |
| 111 | int sc_bap_off; |
| 112 | |
| 113 | u_int16_t sc_portnum; |
| 114 | |
| 115 | /* RSSI interpretation */ |
| 116 | u_int16_t sc_dbm_offset; /* dBm ~ RSSI - sc_dbm_offset */ |
| 117 | u_int16_t sc_max_datalen; |
| 118 | u_int16_t sc_frag_thresh; |
| 119 | u_int16_t sc_rts_thresh; |
| 120 | u_int16_t sc_system_scale; |
| 121 | u_int16_t sc_tx_rate; |
| 122 | u_int16_t sc_cnfauthmode; |
| 123 | u_int16_t sc_roaming_mode; |
| 124 | u_int16_t sc_microwave_oven; |
| 125 | |
| 126 | int sc_nodelen; |
| 127 | char sc_nodename[IEEE80211_NWID_LEN]; |
| 128 | |
| 129 | int sc_buflen; |
| 130 | #define WI_NTXBUF 3 |
| 131 | #define 10 |
| 132 | struct { |
| 133 | int d_fid; |
| 134 | } sc_txd[WI_NTXBUF]; |
| 135 | int sc_txalloc; /* next FID to allocate */ |
| 136 | int sc_txalloced; /* FIDs currently allocated */ |
| 137 | int sc_txqueue; /* next FID to queue */ |
| 138 | int sc_txqueued; /* FIDs currently queued */ |
| 139 | int sc_txstart; /* next FID to start */ |
| 140 | int sc_txstarted; /* FIDs currently started */ |
| 141 | int sc_txcmds; |
| 142 | |
| 143 | int sc_status; |
| 144 | |
| 145 | struct wi_rssdesc [WI_NTXRSS]; |
| 146 | wi_rssdescq_t ; |
| 147 | int sc_tx_timer; |
| 148 | int sc_scan_timer; |
| 149 | int sc_syn_timer; |
| 150 | |
| 151 | struct wi_counters sc_stats; |
| 152 | u_int16_t sc_ibss_port; |
| 153 | |
| 154 | struct wi_apinfo sc_aps[MAXAPINFO]; |
| 155 | int sc_naps; |
| 156 | |
| 157 | struct timeval sc_last_syn; |
| 158 | int sc_false_syns; |
| 159 | int sc_alt_retry; |
| 160 | |
| 161 | union { |
| 162 | struct wi_rx_radiotap_header tap; |
| 163 | u_int8_t pad[64]; |
| 164 | } sc_rxtapu; |
| 165 | union { |
| 166 | struct wi_tx_radiotap_header tap; |
| 167 | u_int8_t pad[64]; |
| 168 | } sc_txtapu; |
| 169 | u_int16_t sc_txbuf[IEEE80211_MAX_LEN/2]; |
| 170 | /* number of transmissions pending at each data rate */ |
| 171 | u_int8_t sc_txpending[IEEE80211_RATE_MAXSIZE]; |
| 172 | struct callout ; |
| 173 | kmutex_t sc_ioctl_mtx; |
| 174 | kcondvar_t sc_ioctl_cv; |
| 175 | bool sc_ioctl_gone; |
| 176 | unsigned int sc_ioctl_nwait; |
| 177 | unsigned int sc_ioctl_depth; |
| 178 | lwp_t *sc_ioctl_lwp; |
| 179 | }; |
| 180 | |
| 181 | #define sc_if sc_ec.ec_if |
| 182 | #define sc_rxtap sc_rxtapu.tap |
| 183 | #define sc_txtap sc_txtapu.tap |
| 184 | |
| 185 | struct wi_node { |
| 186 | struct ieee80211_node wn_node; |
| 187 | struct ieee80211_rssadapt ; |
| 188 | }; |
| 189 | |
| 190 | /* maximum false change-of-BSSID indications per second */ |
| 191 | #define WI_MAX_FALSE_SYNS 10 |
| 192 | |
| 193 | #define WI_PRISM_DBM_OFFSET 100 /* XXX */ |
| 194 | |
| 195 | #define WI_LUCENT_DBM_OFFSET 149 |
| 196 | |
| 197 | #define WI_SCAN_INQWAIT 3 /* wait sec before inquire */ |
| 198 | #define WI_SCAN_WAIT 5 /* maximum scan wait */ |
| 199 | |
| 200 | /* Values for wi_flags. */ |
| 201 | #define WI_FLAGS_ATTACHED 0x0001 |
| 202 | #define WI_FLAGS_INITIALIZED 0x0002 |
| 203 | #define WI_FLAGS_OUTRANGE 0x0004 |
| 204 | #define 0x0008 |
| 205 | #define WI_FLAGS_HAS_MOR 0x0010 |
| 206 | #define WI_FLAGS_HAS_ROAMING 0x0020 |
| 207 | #define WI_FLAGS_HAS_DIVERSITY 0x0040 |
| 208 | #define WI_FLAGS_HAS_SYSSCALE 0x0080 |
| 209 | #define WI_FLAGS_BUG_AUTOINC 0x0100 |
| 210 | #define WI_FLAGS_HAS_FRAGTHR 0x0200 |
| 211 | #define WI_FLAGS_HAS_DBMADJUST 0x0400 |
| 212 | #define WI_FLAGS_WEP_VALID 0x0800 |
| 213 | |
| 214 | struct wi_card_ident { |
| 215 | u_int16_t card_id; |
| 216 | const char *card_name; |
| 217 | u_int8_t firm_type; |
| 218 | }; |
| 219 | |
| 220 | /* |
| 221 | * register space access macros |
| 222 | */ |
| 223 | #ifdef WI_AT_BIGENDIAN_BUS_HACK |
| 224 | /* |
| 225 | * XXX - ugly hack for sparc bus_space_* macro deficiencies: |
| 226 | * assume the bus we are accessing is big endian. |
| 227 | */ |
| 228 | |
| 229 | #define CSR_WRITE_4(sc, reg, val) \ |
| 230 | bus_space_write_4(sc->sc_iot, sc->sc_ioh, \ |
| 231 | (sc->sc_pci? reg * 2: reg) , htole32(val)) |
| 232 | #define CSR_WRITE_2(sc, reg, val) \ |
| 233 | bus_space_write_2(sc->sc_iot, sc->sc_ioh, \ |
| 234 | (sc->sc_pci? reg * 2: reg), htole16(val)) |
| 235 | #define CSR_WRITE_1(sc, reg, val) \ |
| 236 | bus_space_write_1(sc->sc_iot, sc->sc_ioh, \ |
| 237 | (sc->sc_pci? reg * 2: reg), val) |
| 238 | |
| 239 | #define CSR_READ_4(sc, reg) \ |
| 240 | le32toh(bus_space_read_4(sc->sc_iot, sc->sc_ioh, \ |
| 241 | (sc->sc_pci? reg * 2: reg))) |
| 242 | #define CSR_READ_2(sc, reg) \ |
| 243 | le16toh(bus_space_read_2(sc->sc_iot, sc->sc_ioh, \ |
| 244 | (sc->sc_pci? reg * 2: reg))) |
| 245 | #define CSR_READ_1(sc, reg) \ |
| 246 | bus_space_read_1(sc->sc_iot, sc->sc_ioh, \ |
| 247 | (sc->sc_pci? reg * 2: reg)) |
| 248 | |
| 249 | #else |
| 250 | |
| 251 | #define CSR_WRITE_4(sc, reg, val) \ |
| 252 | bus_space_write_4(sc->sc_iot, sc->sc_ioh, \ |
| 253 | (sc->sc_pci? reg * 2: reg) , val) |
| 254 | #define CSR_WRITE_2(sc, reg, val) \ |
| 255 | bus_space_write_2(sc->sc_iot, sc->sc_ioh, \ |
| 256 | (sc->sc_pci? reg * 2: reg), val) |
| 257 | #define CSR_WRITE_1(sc, reg, val) \ |
| 258 | bus_space_write_1(sc->sc_iot, sc->sc_ioh, \ |
| 259 | (sc->sc_pci? reg * 2: reg), val) |
| 260 | |
| 261 | #define CSR_READ_4(sc, reg) \ |
| 262 | bus_space_read_4(sc->sc_iot, sc->sc_ioh, \ |
| 263 | (sc->sc_pci? reg * 2: reg)) |
| 264 | #define CSR_READ_2(sc, reg) \ |
| 265 | bus_space_read_2(sc->sc_iot, sc->sc_ioh, \ |
| 266 | (sc->sc_pci? reg * 2: reg)) |
| 267 | #define CSR_READ_1(sc, reg) \ |
| 268 | bus_space_read_1(sc->sc_iot, sc->sc_ioh, \ |
| 269 | (sc->sc_pci? reg * 2: reg)) |
| 270 | #endif |
| 271 | |
| 272 | #ifndef __BUS_SPACE_HAS_STREAM_METHODS |
| 273 | #define bus_space_write_stream_2 bus_space_write_2 |
| 274 | #define bus_space_write_multi_stream_2 bus_space_write_multi_2 |
| 275 | #define bus_space_read_stream_2 bus_space_read_2 |
| 276 | #define bus_space_read_multi_stream_2 bus_space_read_multi_2 |
| 277 | #endif |
| 278 | |
| 279 | #define CSR_WRITE_STREAM_2(sc, reg, val) \ |
| 280 | bus_space_write_stream_2(sc->sc_iot, sc->sc_ioh, \ |
| 281 | (sc->sc_pci? reg * 2: reg), val) |
| 282 | #define CSR_WRITE_MULTI_STREAM_2(sc, reg, val, count) \ |
| 283 | bus_space_write_multi_stream_2(sc->sc_iot, sc->sc_ioh, \ |
| 284 | (sc->sc_pci? reg * 2: reg), val, count) |
| 285 | #define CSR_READ_STREAM_2(sc, reg) \ |
| 286 | bus_space_read_stream_2(sc->sc_iot, sc->sc_ioh, \ |
| 287 | (sc->sc_pci? reg * 2: reg)) |
| 288 | #define CSR_READ_MULTI_STREAM_2(sc, reg, buf, count) \ |
| 289 | bus_space_read_multi_stream_2(sc->sc_iot, sc->sc_ioh, \ |
| 290 | (sc->sc_pci? reg * 2: reg), buf, count) |
| 291 | |
| 292 | |
| 293 | int wi_attach(struct wi_softc *, const u_int8_t *); |
| 294 | int wi_detach(struct wi_softc *); |
| 295 | int wi_activate(device_t, enum devact); |
| 296 | int wi_intr(void *arg); |
| 297 | |