1 /* ZD1211 USB-WLAN driver for Linux
3 * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
4 * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/kernel.h>
25 #include <net/mac80211.h>
33 /* stores only the difference to tx_length on ZD1211B */
35 __le16 current_length;
37 __le16 next_frame_length;
38 } __attribute__((packed));
40 #define ZD_CS_RESERVED_SIZE 25
42 /* The field modulation of struct zd_ctrlset controls the bit rate, the use
43 * of short or long preambles in 802.11b (CCK mode) or the use of 802.11a or
44 * 802.11g in OFDM mode.
46 * The term zd-rate is used for the combination of the modulation type flag
47 * and the "pure" rate value.
49 #define ZD_PURE_RATE_MASK 0x0f
50 #define ZD_MODULATION_TYPE_MASK 0x10
51 #define ZD_RATE_MASK (ZD_PURE_RATE_MASK|ZD_MODULATION_TYPE_MASK)
52 #define ZD_PURE_RATE(modulation) ((modulation) & ZD_PURE_RATE_MASK)
53 #define ZD_MODULATION_TYPE(modulation) ((modulation) & ZD_MODULATION_TYPE_MASK)
54 #define ZD_RATE(modulation) ((modulation) & ZD_RATE_MASK)
56 /* The two possible modulation types. Notify that 802.11b doesn't use the CCK
57 * codeing for the 1 and 2 MBit/s rate. We stay with the term here to remain
58 * consistent with uses the term at other places.
63 /* The ZD1211 firmware uses proprietary encodings of the 802.11b (CCK) rates.
64 * For OFDM the PLCP rate encodings are used. We combine these "pure" rates
65 * with the modulation type flag and call the resulting values zd-rates.
67 #define ZD_CCK_RATE_1M (ZD_CCK|0x00)
68 #define ZD_CCK_RATE_2M (ZD_CCK|0x01)
69 #define ZD_CCK_RATE_5_5M (ZD_CCK|0x02)
70 #define ZD_CCK_RATE_11M (ZD_CCK|0x03)
71 #define ZD_OFDM_RATE_6M (ZD_OFDM|ZD_OFDM_PLCP_RATE_6M)
72 #define ZD_OFDM_RATE_9M (ZD_OFDM|ZD_OFDM_PLCP_RATE_9M)
73 #define ZD_OFDM_RATE_12M (ZD_OFDM|ZD_OFDM_PLCP_RATE_12M)
74 #define ZD_OFDM_RATE_18M (ZD_OFDM|ZD_OFDM_PLCP_RATE_18M)
75 #define ZD_OFDM_RATE_24M (ZD_OFDM|ZD_OFDM_PLCP_RATE_24M)
76 #define ZD_OFDM_RATE_36M (ZD_OFDM|ZD_OFDM_PLCP_RATE_36M)
77 #define ZD_OFDM_RATE_48M (ZD_OFDM|ZD_OFDM_PLCP_RATE_48M)
78 #define ZD_OFDM_RATE_54M (ZD_OFDM|ZD_OFDM_PLCP_RATE_54M)
80 /* The bit 5 of the zd_ctrlset modulation field controls the preamble in CCK
81 * mode or the 802.11a/802.11g selection in OFDM mode.
83 #define ZD_CCK_PREA_LONG 0x00
84 #define ZD_CCK_PREA_SHORT 0x20
85 #define ZD_OFDM_MODE_11G 0x00
86 #define ZD_OFDM_MODE_11A 0x20
88 /* zd_ctrlset control field */
89 #define ZD_CS_NEED_RANDOM_BACKOFF 0x01
90 #define ZD_CS_MULTICAST 0x02
92 #define ZD_CS_FRAME_TYPE_MASK 0x0c
93 #define ZD_CS_DATA_FRAME 0x00
94 #define ZD_CS_PS_POLL_FRAME 0x04
95 #define ZD_CS_MANAGEMENT_FRAME 0x08
96 #define ZD_CS_NO_SEQUENCE_CTL_FRAME 0x0c
98 #define ZD_CS_WAKE_DESTINATION 0x10
99 #define ZD_CS_RTS 0x20
100 #define ZD_CS_ENCRYPT 0x40
101 #define ZD_CS_SELF_CTS 0x80
103 /* Incoming frames are prepended by a PLCP header */
104 #define ZD_PLCP_HEADER_SIZE 5
106 struct rx_length_info {
109 } __attribute__((packed));
111 #define RX_LENGTH_INFO_TAG 0x697e
114 u8 signal_quality_cck;
117 u8 signal_quality_ofdm;
120 } __attribute__((packed));
122 /* rx_status field decryption_type */
123 #define ZD_RX_NO_WEP 0
124 #define ZD_RX_WEP64 1
127 #define ZD_RX_WEP128 5
128 #define ZD_RX_WEP256 6
130 /* rx_status field frame_status */
131 #define ZD_RX_FRAME_MODULATION_MASK 0x01
132 #define ZD_RX_CCK 0x00
133 #define ZD_RX_OFDM 0x01
135 #define ZD_RX_TIMEOUT_ERROR 0x02
136 #define ZD_RX_FIFO_OVERRUN_ERROR 0x04
137 #define ZD_RX_DECRYPTION_ERROR 0x08
138 #define ZD_RX_CRC32_ERROR 0x10
139 #define ZD_RX_NO_ADDR1_MATCH_ERROR 0x20
140 #define ZD_RX_CRC16_ERROR 0x40
141 #define ZD_RX_ERROR 0x80
144 MAC_FIXED_CHANNEL = 0x01,
147 struct housekeeping {
148 struct delayed_work link_led_work;
151 #define ZD_MAC_STATS_BUFFER_SIZE 16
153 #define ZD_MAC_MAX_ACK_WAITERS 10
158 spinlock_t intr_lock;
159 struct ieee80211_hw *hw;
160 struct housekeeping housekeeping;
161 struct work_struct set_multicast_hash_work;
162 struct work_struct set_rts_cts_work;
163 struct work_struct set_rx_filter_work;
164 struct work_struct process_intr;
165 struct zd_mc_hash multicast_hash;
166 u8 intr_buffer[USB_MAX_EP_INT_BUFFER];
168 u8 default_regdomain;
171 struct sk_buff_head ack_wait_queue;
172 struct ieee80211_channel channels[14];
173 struct ieee80211_rate rates[12];
174 struct ieee80211_supported_band band;
176 /* Short preamble (used for RTS/CTS) */
177 unsigned int short_preamble:1;
179 /* flags to indicate update in progress */
180 unsigned int updating_rts_rate:1;
182 /* whether to pass frames with CRC errors to stack */
183 unsigned int pass_failed_fcs:1;
185 /* whether to pass control frames to stack */
186 unsigned int pass_ctrl:1;
189 #define ZD_REGDOMAIN_FCC 0x10
190 #define ZD_REGDOMAIN_IC 0x20
191 #define ZD_REGDOMAIN_ETSI 0x30
192 #define ZD_REGDOMAIN_SPAIN 0x31
193 #define ZD_REGDOMAIN_FRANCE 0x32
194 #define ZD_REGDOMAIN_JAPAN_ADD 0x40
195 #define ZD_REGDOMAIN_JAPAN 0x41
202 #define ZD_PLCP_SERVICE_LENGTH_EXTENSION 0x80
204 struct ofdm_plcp_header {
207 } __attribute__((packed));
209 static inline u8 zd_ofdm_plcp_header_rate(const struct ofdm_plcp_header *header)
211 return header->prefix[0] & 0xf;
214 /* The following defines give the encoding of the 4-bit rate field in the
215 * OFDM (802.11a/802.11g) PLCP header. Notify that these values are used to
216 * define the zd-rate values for OFDM.
218 * See the struct zd_ctrlset definition in zd_mac.h.
220 #define ZD_OFDM_PLCP_RATE_6M 0xb
221 #define ZD_OFDM_PLCP_RATE_9M 0xf
222 #define ZD_OFDM_PLCP_RATE_12M 0xa
223 #define ZD_OFDM_PLCP_RATE_18M 0xe
224 #define ZD_OFDM_PLCP_RATE_24M 0x9
225 #define ZD_OFDM_PLCP_RATE_36M 0xd
226 #define ZD_OFDM_PLCP_RATE_48M 0x8
227 #define ZD_OFDM_PLCP_RATE_54M 0xc
229 struct cck_plcp_header {
234 } __attribute__((packed));
236 static inline u8 zd_cck_plcp_header_signal(const struct cck_plcp_header *header)
238 return header->signal;
241 /* These defines give the encodings of the signal field in the 802.11b PLCP
242 * header. The signal field gives the bit rate of the following packet. Even
243 * if technically wrong we use CCK here also for the 1 MBit/s and 2 MBit/s
244 * rate to stay consistent with Zydas and our use of the term.
246 * Notify that these values are *not* used in the zd-rates.
248 #define ZD_CCK_PLCP_SIGNAL_1M 0x0a
249 #define ZD_CCK_PLCP_SIGNAL_2M 0x14
250 #define ZD_CCK_PLCP_SIGNAL_5M5 0x37
251 #define ZD_CCK_PLCP_SIGNAL_11M 0x6e
253 static inline struct zd_mac *zd_hw_mac(struct ieee80211_hw *hw)
258 static inline struct zd_mac *zd_chip_to_mac(struct zd_chip *chip)
260 return container_of(chip, struct zd_mac, chip);
263 static inline struct zd_mac *zd_usb_to_mac(struct zd_usb *usb)
265 return zd_chip_to_mac(zd_usb_to_chip(usb));
268 static inline u8 *zd_mac_get_perm_addr(struct zd_mac *mac)
270 return mac->hw->wiphy->perm_addr;
273 #define zd_mac_dev(mac) (zd_chip_dev(&(mac)->chip))
275 struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf);
276 void zd_mac_clear(struct zd_mac *mac);
278 int zd_mac_preinit_hw(struct ieee80211_hw *hw);
279 int zd_mac_init_hw(struct ieee80211_hw *hw);
281 int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length);
282 void zd_mac_tx_failed(struct ieee80211_hw *hw);
283 void zd_mac_tx_to_dev(struct sk_buff *skb, int error);
286 void zd_dump_rx_status(const struct rx_status *status);
288 #define zd_dump_rx_status(status)
291 #endif /* _ZD_MAC_H */