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