Home | History | Annotate | Line # | Download | only in ic
wivar.h revision 1.40
      1 /*	$NetBSD: wivar.h,v 1.40 2003/12/07 04:49:17 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_DBM_ANTSIGNAL) | \
     41 				 (1 << IEEE80211_RADIOTAP_DBM_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 /*
     66  * FreeBSD driver ported to NetBSD by Bill Sommerfeld in the back of the
     67  * Oslo IETF plenary meeting.
     68  */
     69 struct wi_softc	{
     70 	struct device		sc_dev;
     71 	struct ieee80211com	sc_ic;
     72 	void			*sc_ih;		/* interrupt handler */
     73 	int			(*sc_enable)(struct wi_softc *);
     74 	void			(*sc_disable)(struct wi_softc *);
     75 	void			(*sc_reset)(struct wi_softc *);
     76 
     77 	int			(*sc_newstate)(struct ieee80211com *,
     78 				    enum ieee80211_state, int);
     79 
     80 	int			sc_attached;
     81 	int			sc_enabled;
     82 	int			sc_invalid;
     83 	int			sc_firmware_type;
     84 #define	WI_NOTYPE	0
     85 #define	WI_LUCENT	1
     86 #define	WI_INTERSIL	2
     87 #define	WI_SYMBOL	3
     88 	int			sc_pri_firmware_ver;	/* Primary firm vers */
     89 	int			sc_sta_firmware_ver;	/* Station firm vers */
     90 	int			sc_pci;			/* attach to PCI-Bus */
     91 
     92 	bus_space_tag_t		sc_iot;			/* bus cookie */
     93 	bus_space_handle_t	sc_ioh;			/* bus i/o handle */
     94 
     95 	caddr_t			sc_drvbpf;
     96 	int			sc_flags;
     97 	int			sc_bap_id;
     98 	int			sc_bap_off;
     99 
    100 	u_int16_t		sc_portnum;
    101 
    102 	/* RSSI interpretation */
    103 	u_int16_t		sc_dbm_offset;	/* dBm ~ RSSI - sc_dbm_offset */
    104 	u_int16_t		sc_max_datalen;
    105 	u_int16_t		sc_frag_thresh;
    106 	u_int16_t		sc_rts_thresh;
    107 	u_int16_t		sc_system_scale;
    108 	u_int16_t		sc_tx_rate;
    109 	u_int16_t		sc_cnfauthmode;
    110 	u_int16_t		sc_roaming_mode;
    111 	u_int16_t		sc_microwave_oven;
    112 
    113 	int			sc_nodelen;
    114 	char			sc_nodename[IEEE80211_NWID_LEN];
    115 
    116 	int			sc_buflen;
    117 #define	WI_NTXBUF	3
    118 	struct sc_txdesc {
    119 		int		d_fid;
    120 		int		d_len;
    121 	}			sc_txd[WI_NTXBUF];
    122 	int			sc_txnext;
    123 	int			sc_txcur;
    124 	int			sc_tx_timer;
    125 	int			sc_scan_timer;
    126 	int			sc_syn_timer;
    127 
    128 	struct wi_counters	sc_stats;
    129 	u_int16_t		sc_ibss_port;
    130 
    131 	struct wi_apinfo	sc_aps[MAXAPINFO];
    132 	int 			sc_naps;
    133 
    134 	int			sc_false_syns;
    135 
    136 	union {
    137 		struct wi_rx_radiotap_header	tap;
    138 		u_int8_t			pad[64];
    139 	} sc_rxtapu;
    140 	union {
    141 		struct wi_tx_radiotap_header	tap;
    142 		u_int8_t			pad[64];
    143 	} sc_txtapu;
    144 	u_int16_t		sc_txbuf[IEEE80211_MAX_LEN/2];
    145 };
    146 
    147 #define sc_rxtap	sc_rxtapu.tap
    148 #define sc_txtap	sc_txtapu.tap
    149 
    150 #define	sc_if			sc_ic.ic_if
    151 
    152 /* maximum consecutive false change-of-BSSID indications */
    153 #define	WI_MAX_FALSE_SYNS		10
    154 
    155 #define	WI_PRISM_DBM_OFFSET	100	/* XXX */
    156 
    157 #define	WI_LUCENT_DBM_OFFSET	149
    158 
    159 #define	WI_RSSI_TO_DBM(sc, rssi) ((rssi) - (sc)->sc_dbm_offset)
    160 
    161 #define	WI_SCAN_INQWAIT			3	/* wait sec before inquire */
    162 #define	WI_SCAN_WAIT			5	/* maximum scan wait */
    163 
    164 /* Values for wi_flags. */
    165 #define	WI_FLAGS_ATTACHED		0x0001
    166 #define	WI_FLAGS_INITIALIZED		0x0002
    167 #define	WI_FLAGS_OUTRANGE		0x0004
    168 #define	WI_FLAGS_HAS_MOR		0x0010
    169 #define	WI_FLAGS_HAS_ROAMING		0x0020
    170 #define	WI_FLAGS_HAS_DIVERSITY		0x0040
    171 #define	WI_FLAGS_HAS_SYSSCALE		0x0080
    172 #define	WI_FLAGS_BUG_AUTOINC		0x0100
    173 #define	WI_FLAGS_HAS_FRAGTHR		0x0200
    174 #define	WI_FLAGS_HAS_DBMADJUST		0x0400
    175 
    176 struct wi_card_ident {
    177 	u_int16_t	card_id;
    178 	char		*card_name;
    179 	u_int8_t	firm_type;
    180 };
    181 
    182 /*
    183  * register space access macros
    184  */
    185 #ifdef WI_AT_BIGENDIAN_BUS_HACK
    186 	/*
    187 	 * XXX - ugly hack for sparc bus_space_* macro deficiencies:
    188 	 *       assume the bus we are accessing is big endian.
    189 	 */
    190 
    191 #define CSR_WRITE_4(sc, reg, val)	\
    192 	bus_space_write_4(sc->sc_iot, sc->sc_ioh,	\
    193 			(sc->sc_pci? reg * 2: reg) , htole32(val))
    194 #define CSR_WRITE_2(sc, reg, val)	\
    195 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,	\
    196 			(sc->sc_pci? reg * 2: reg), htole16(val))
    197 #define CSR_WRITE_1(sc, reg, val)	\
    198 	bus_space_write_1(sc->sc_iot, sc->sc_ioh,	\
    199 			(sc->sc_pci? reg * 2: reg), val)
    200 
    201 #define CSR_READ_4(sc, reg)		\
    202 	le32toh(bus_space_read_4(sc->sc_iot, sc->sc_ioh,	\
    203 			(sc->sc_pci? reg * 2: reg)))
    204 #define CSR_READ_2(sc, reg)		\
    205 	le16toh(bus_space_read_2(sc->sc_iot, sc->sc_ioh,	\
    206 			(sc->sc_pci? reg * 2: reg)))
    207 #define CSR_READ_1(sc, reg)		\
    208 	bus_space_read_1(sc->sc_iot, sc->sc_ioh,	\
    209 			(sc->sc_pci? reg * 2: reg))
    210 
    211 #else
    212 
    213 #define CSR_WRITE_4(sc, reg, val)	\
    214 	bus_space_write_4(sc->sc_iot, sc->sc_ioh,	\
    215 			(sc->sc_pci? reg * 2: reg) , val)
    216 #define CSR_WRITE_2(sc, reg, val)	\
    217 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,	\
    218 			(sc->sc_pci? reg * 2: reg), val)
    219 #define CSR_WRITE_1(sc, reg, val)	\
    220 	bus_space_write_1(sc->sc_iot, sc->sc_ioh,	\
    221 			(sc->sc_pci? reg * 2: reg), val)
    222 
    223 #define CSR_READ_4(sc, reg)		\
    224 	bus_space_read_4(sc->sc_iot, sc->sc_ioh,	\
    225 			(sc->sc_pci? reg * 2: reg))
    226 #define CSR_READ_2(sc, reg)		\
    227 	bus_space_read_2(sc->sc_iot, sc->sc_ioh,	\
    228 			(sc->sc_pci? reg * 2: reg))
    229 #define CSR_READ_1(sc, reg)		\
    230 	bus_space_read_1(sc->sc_iot, sc->sc_ioh,	\
    231 			(sc->sc_pci? reg * 2: reg))
    232 #endif
    233 
    234 #ifndef __BUS_SPACE_HAS_STREAM_METHODS
    235 #define bus_space_write_stream_2	bus_space_write_2
    236 #define bus_space_write_multi_stream_2	bus_space_write_multi_2
    237 #define bus_space_read_stream_2		bus_space_read_2
    238 #define bus_space_read_multi_stream_2		bus_space_read_multi_2
    239 #endif
    240 
    241 #define CSR_WRITE_STREAM_2(sc, reg, val)	\
    242 	bus_space_write_stream_2(sc->sc_iot, sc->sc_ioh,	\
    243 			(sc->sc_pci? reg * 2: reg), val)
    244 #define CSR_WRITE_MULTI_STREAM_2(sc, reg, val, count)	\
    245 	bus_space_write_multi_stream_2(sc->sc_iot, sc->sc_ioh,	\
    246 			(sc->sc_pci? reg * 2: reg), val, count)
    247 #define CSR_READ_STREAM_2(sc, reg)		\
    248 	bus_space_read_stream_2(sc->sc_iot, sc->sc_ioh,	\
    249 			(sc->sc_pci? reg * 2: reg))
    250 #define CSR_READ_MULTI_STREAM_2(sc, reg, buf, count)		\
    251 	bus_space_read_multi_stream_2(sc->sc_iot, sc->sc_ioh,	\
    252 			(sc->sc_pci? reg * 2: reg), buf, count)
    253 
    254 
    255 int	wi_attach(struct wi_softc *);
    256 int	wi_detach(struct wi_softc *);
    257 int	wi_activate(struct device *, enum devact);
    258 int	wi_intr(void *arg);
    259 void	wi_power(struct wi_softc *, int);
    260 void	wi_shutdown(struct wi_softc *);
    261