2 * Copyright (c) 2002,2003 Oliver Kurth
3 * (c) 2003,2004 Joerg Albert <joerg.albert@gmx.de>
4 * (c) 2007 Guido Guenther <agx@sigxcpu.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This driver was based on information from the Sourceforge driver
12 * released and maintained by Atmel:
14 * http://sourceforge.net/projects/atmelwlandriver/
16 * Although the code was completely re-written,
17 * it would have been impossible without Atmel's decision to
18 * release an Open Source driver (unfortunately the firmware was
19 * kept binary only). Thanks for that decision to Atmel!
27 BOARD_503_ISL3861 = 1,
28 BOARD_503_ISL3863 = 2,
37 /* our private ioctl's */
38 /* preamble length (0 - long, 1 - short, 2 - auto) */
39 #define AT76_SET_SHORT_PREAMBLE (SIOCIWFIRSTPRIV + 0)
40 #define AT76_GET_SHORT_PREAMBLE (SIOCIWFIRSTPRIV + 1)
41 /* which debug channels are enabled */
42 #define AT76_SET_DEBUG (SIOCIWFIRSTPRIV + 2)
43 #define AT76_GET_DEBUG (SIOCIWFIRSTPRIV + 3)
44 /* power save mode (incl. the Atmel proprietary smart save mode) */
45 #define AT76_SET_POWERSAVE_MODE (SIOCIWFIRSTPRIV + 4)
46 #define AT76_GET_POWERSAVE_MODE (SIOCIWFIRSTPRIV + 5)
47 /* min and max channel times for scan */
48 #define AT76_SET_SCAN_TIMES (SIOCIWFIRSTPRIV + 6)
49 #define AT76_GET_SCAN_TIMES (SIOCIWFIRSTPRIV + 7)
50 /* scan mode (0 - active, 1 - passive) */
51 #define AT76_SET_SCAN_MODE (SIOCIWFIRSTPRIV + 8)
52 #define AT76_GET_SCAN_MODE (SIOCIWFIRSTPRIV + 9)
54 #define CMD_STATUS_IDLE 0x00
55 #define CMD_STATUS_COMPLETE 0x01
56 #define CMD_STATUS_UNKNOWN 0x02
57 #define CMD_STATUS_INVALID_PARAMETER 0x03
58 #define CMD_STATUS_FUNCTION_NOT_SUPPORTED 0x04
59 #define CMD_STATUS_TIME_OUT 0x07
60 #define CMD_STATUS_IN_PROGRESS 0x08
61 #define CMD_STATUS_HOST_FAILURE 0xff
62 #define CMD_STATUS_SCAN_FAILED 0xf0
64 /* answers to get op mode */
65 #define OPMODE_NONE 0x00
66 #define OPMODE_NORMAL_NIC_WITH_FLASH 0x01
67 #define OPMODE_HW_CONFIG_MODE 0x02
68 #define OPMODE_DFU_MODE_WITH_FLASH 0x03
69 #define OPMODE_NORMAL_NIC_WITHOUT_FLASH 0x04
71 #define CMD_SET_MIB 0x01
72 #define CMD_GET_MIB 0x02
75 #define CMD_START_IBSS 0x05
76 #define CMD_RADIO_ON 0x06
77 #define CMD_RADIO_OFF 0x07
78 #define CMD_STARTUP 0x0B
80 #define MIB_LOCAL 0x01
81 #define MIB_MAC_ADDR 0x02
83 #define MIB_MAC_MGMT 0x05
84 #define MIB_MAC_WEP 0x06
86 #define MIB_FW_VERSION 0x08
87 #define MIB_MDOMAIN 0x09
90 #define INFRASTRUCTURE_MODE 2
92 /* values for struct mib_local, field preamble_type */
93 #define PREAMBLE_TYPE_LONG 0
94 #define PREAMBLE_TYPE_SHORT 1
95 #define PREAMBLE_TYPE_AUTO 2
97 /* values for tx_rate */
98 #define TX_RATE_1MBIT 0
99 #define TX_RATE_2MBIT 1
100 #define TX_RATE_5_5MBIT 2
101 #define TX_RATE_11MBIT 3
102 #define TX_RATE_AUTO 4
104 /* power management modes */
105 #define AT76_PM_OFF 1
107 #define AT76_PM_SMART 3
114 u8 mac_addr[ETH_ALEN];
115 u8 regulatory_domain;
119 } __attribute__((packed));
126 u8 mac_addr[ETH_ALEN];
127 u8 regulatory_domain;
128 u8 low_power_values[14];
129 u8 normal_power_values[14];
131 } __attribute__((packed));
133 struct hwcfg_intersil {
134 u8 mac_addr[ETH_ALEN];
138 u8 regulatory_domain;
140 } __attribute__((packed));
143 struct hwcfg_intersil i;
144 struct hwcfg_rfmd r3;
145 struct hwcfg_r505 r5;
148 #define WEP_SMALL_KEY_LEN (40 / 8)
149 #define WEP_LARGE_KEY_LEN (104 / 8)
151 struct at76_card_config {
152 u8 exclude_unencrypted;
154 u8 short_retry_limit;
156 __le16 rts_threshold;
157 __le16 fragmentation_threshold; /* 256..2346 */
158 u8 basic_rate_set[4];
159 u8 auto_rate_fallback; /* 0,1 */
162 u8 wep_default_key_id; /* 0..3 */
164 u8 wep_default_key_value[4][WEP_KEY_LEN];
167 __le16 beacon_period;
168 } __attribute__((packed));
170 struct at76_command {
175 } __attribute__((packed));
177 /* Length of Atmel-specific Rx header before 802.11 frame */
178 #define AT76_RX_HDRLEN offsetof(struct at76_rx_buffer, packet)
180 struct at76_rx_buffer {
189 u8 packet[IEEE80211_FRAME_LEN + IEEE80211_FCS_LEN];
190 } __attribute__((packed));
192 /* Length of Atmel-specific Tx header before 802.11 frame */
193 #define AT76_TX_HDRLEN offsetof(struct at76_tx_buffer, packet)
195 struct at76_tx_buffer {
200 u8 packet[IEEE80211_FRAME_LEN + IEEE80211_FCS_LEN];
201 } __attribute__((packed));
203 /* defines for scan_type below */
204 #define SCAN_TYPE_ACTIVE 0
205 #define SCAN_TYPE_PASSIVE 1
207 struct at76_req_scan {
213 __le16 min_channel_time;
214 __le16 max_channel_time;
216 u8 international_scan;
217 } __attribute__((packed));
219 struct at76_req_ibss {
226 } __attribute__((packed));
228 struct at76_req_join {
236 } __attribute__((packed));
238 struct set_mib_buffer {
248 } __attribute__((packed));
253 u8 txautorate_fallback;
260 } __attribute__((packed));
262 struct mib_mac_addr {
263 u8 mac_addr[ETH_ALEN];
265 u8 group_addr[4][ETH_ALEN];
266 u8 group_addr_status[4];
267 } __attribute__((packed));
270 __le32 max_tx_msdu_lifetime;
271 __le32 max_rx_lifetime;
272 __le16 frag_threshold;
273 __le16 rts_threshold;
278 u8 scan_type; /* active or passive */
280 __le16 probe_delay; /* delay before ProbeReq in active scan, RO */
281 __le16 min_channel_time;
282 __le16 max_channel_time;
283 __le16 listen_interval;
285 u8 desired_bssid[ETH_ALEN];
286 u8 desired_bsstype; /* ad-hoc or infrastructure */
288 } __attribute__((packed));
290 struct mib_mac_mgmt {
291 __le16 beacon_period;
292 __le16 CFP_max_duration;
293 __le16 medium_occupancy_limit;
294 __le16 station_id; /* assoc id */
297 u8 privacy_option_implemented;
300 u8 current_bssid[ETH_ALEN];
301 u8 current_essid[32];
307 u8 multi_domain_capability_implemented;
308 u8 multi_domain_capability_enabled;
309 u8 country_string[3];
311 } __attribute__((packed));
314 u8 privacy_invoked; /* 0 disable encr., 1 enable encr */
315 u8 wep_default_key_id;
316 u8 wep_key_mapping_len;
317 u8 exclude_unencrypted;
318 __le32 wep_icv_error_count;
319 __le32 wep_excluded_count;
320 u8 wep_default_keyvalue[WEP_KEYS][WEP_KEY_LEN];
321 u8 encryption_level; /* 1 for 40bit, 2 for 104bit encryption */
322 } __attribute__((packed));
329 __le16 preamble_length;
330 __le16 plcp_header_length;
331 __le16 mpdu_max_length;
332 __le16 cca_mode_supported;
334 u8 operation_rate_set[4];
338 u8 current_reg_domain;
339 } __attribute__((packed));
341 struct mib_fw_version {
346 } __attribute__((packed));
349 u8 tx_powerlevel[14];
350 u8 channel_list[14]; /* 0 for invalid channels */
351 } __attribute__((packed));
353 struct at76_fw_header {
354 __le32 crc; /* CRC32 of the whole image */
355 __le32 board_type; /* firmware compatibility code */
356 u8 build; /* firmware build number */
357 u8 patch; /* firmware patch level */
358 u8 minor; /* firmware minor version */
359 u8 major; /* firmware major version */
360 __le32 str_offset; /* offset of the copyright string */
361 __le32 int_fw_offset; /* internal firmware image offset */
362 __le32 int_fw_len; /* internal firmware image length */
363 __le32 ext_fw_offset; /* external firmware image offset */
364 __le32 ext_fw_len; /* external firmware image length */
365 } __attribute__((packed));
377 /* a description of a regulatory domain and the allowed channels */
381 u32 channel_map; /* if bit N is set, channel (N+1) is allowed */
384 /* how long do we keep a (I)BSS in the bss_list in jiffies
385 this should be long enough for the user to retrieve the table
386 (by iwlist ?) after the device started, because all entries from
387 other channels than the one the device locks on get removed, too */
388 #define BSS_LIST_TIMEOUT (120 * HZ)
389 /* struct to store BSS info found during scan */
390 #define BSS_LIST_MAX_RATE_LEN 32 /* 32 rates should be enough ... */
393 struct list_head list;
395 u8 bssid[ETH_ALEN]; /* bssid */
396 u8 ssid[IW_ESSID_MAX_SIZE]; /* essid */
397 u8 ssid_len; /* length of ssid above */
399 u16 capa; /* BSS capabilities */
400 u16 beacon_interval; /* beacon interval, Kus (1024 microseconds) */
401 u8 rates[BSS_LIST_MAX_RATE_LEN]; /* supported rates in units of
402 500 kbps, ORed with 0x80 for
406 /* quality of received beacon */
411 unsigned long last_rx; /* time (jiffies) of last beacon received */
414 /* a rx data buffer to collect rx fragments */
416 u8 sender[ETH_ALEN]; /* sender address */
417 u16 seqnr; /* sequence number */
418 u16 fragnr; /* last fragment received */
419 unsigned long last_rx; /* jiffies of last rx */
420 struct sk_buff *skb; /* == NULL if entry is free */
423 #define NR_RX_DATA_BUF 8
425 /* Data for one loaded firmware file */
427 const char *const fwname;
428 const struct firmware *fw;
431 /* pointer to loaded firmware, no need to free */
432 u8 *extfw; /* external firmware, extfw_size bytes long */
433 u8 *intfw; /* internal firmware, intfw_size bytes long */
434 enum board_type board_type; /* board type */
435 struct mib_fw_version fw_version;
436 int loaded; /* Loaded and parsed successfully */
440 struct usb_device *udev; /* USB device pointer */
441 struct net_device *netdev; /* net device pointer */
442 struct net_device_stats stats; /* net device stats */
443 struct iw_statistics wstats; /* wireless stats */
445 struct sk_buff *rx_skb; /* skbuff for receiving data */
446 void *bulk_out_buffer; /* buffer for sending data */
448 struct urb *tx_urb; /* URB for sending data */
449 struct urb *rx_urb; /* URB for receiving data */
451 unsigned int tx_pipe; /* bulk out pipe */
452 unsigned int rx_pipe; /* bulk in pipe */
454 struct mutex mtx; /* locks this structure */
457 struct work_struct work_assoc_done;
458 struct work_struct work_join;
459 struct work_struct work_new_bss;
460 struct work_struct work_start_scan;
461 struct work_struct work_set_promisc;
462 struct work_struct work_submit_rx;
463 struct delayed_work dwork_restart;
464 struct delayed_work dwork_get_scan;
465 struct delayed_work dwork_beacon;
466 struct delayed_work dwork_auth;
467 struct delayed_work dwork_assoc;
469 struct tasklet_struct rx_tasklet;
472 int wep_enabled; /* 1 if WEP is enabled */
473 int wep_key_id; /* key id to be used */
474 u8 wep_keys[WEP_KEYS][WEP_KEY_LEN]; /* the four WEP keys,
475 5 or 13 bytes are used */
476 u8 wep_keys_len[WEP_KEYS]; /* the length of the above keys */
481 u8 essid[IW_ESSID_MAX_SIZE];
486 int preamble_type; /* 0 - long, 1 - short, 2 - auto */
487 int auth_mode; /* authentication type: 0 open, 1 shared key */
488 int txrate; /* 0,1,2,3 = 1,2,5.5,11 Mbps, 4 is auto */
489 int frag_threshold; /* threshold for fragmentation of tx packets */
490 int rts_threshold; /* threshold for RTS mechanism */
491 int short_retry_limit;
493 int scan_min_time; /* scan min channel time */
494 int scan_max_time; /* scan max channel time */
495 int scan_mode; /* SCAN_TYPE_ACTIVE, SCAN_TYPE_PASSIVE */
496 int scan_need_any; /* if set, need to scan for any ESSID */
498 /* the list we got from scanning */
499 spinlock_t bss_list_spinlock; /* protects bss_list operations */
500 struct list_head bss_list; /* list of BSS we got beacons from */
501 struct timer_list bss_list_timer; /* timer to purge old entries
503 struct bss_info *curr_bss; /* current BSS */
504 u16 assoc_id; /* current association ID, if associated */
506 u8 wanted_bssid[ETH_ALEN];
507 int wanted_bssid_valid; /* != 0 if wanted_bssid is to be used */
509 /* some data for infrastructure mode only */
510 spinlock_t mgmt_spinlock; /* this spinlock protects access to
513 struct at76_tx_buffer *next_mgmt_bulk; /* pending management msg to
515 enum mac_state mac_state;
523 int retries; /* remaining retries in case of timeout when
524 * sending AuthReq or AssocReq */
525 u8 pm_mode; /* power management mode */
526 u32 pm_period; /* power management period in microseconds */
528 struct reg_domain const *domain; /* reg domain description */
531 spinlock_t spy_spinlock;
532 struct iw_spy_data spy_data;
534 struct iw_public_data wireless_data;
536 /* These fields contain HW config provided by the device (not all of
537 * these fields are used by all board types) */
538 u8 mac_addr[ETH_ALEN];
539 u8 regulatory_domain;
541 struct at76_card_config card_config;
543 /* store rx fragments until complete */
544 struct rx_data_buf rx_data[NR_RX_DATA_BUF];
546 enum board_type board_type;
547 struct mib_fw_version fw_version;
549 unsigned int device_unplugged:1;
550 unsigned int netdev_registered:1;
551 struct set_mib_buffer mib_buf; /* global buffer for set_mib calls */
553 /* beacon counting */
554 int beacon_period; /* period of mgmt beacons, Kus */
555 int beacons_received;
556 unsigned long beacons_last_qual; /* time we restarted counting
560 struct at76_rx_radiotap {
561 struct ieee80211_radiotap_header rt_hdr;
569 #define AT76_RX_RADIOTAP_PRESENT \
570 ((1 << IEEE80211_RADIOTAP_TSFT) | \
571 (1 << IEEE80211_RADIOTAP_FLAGS) | \
572 (1 << IEEE80211_RADIOTAP_RATE) | \
573 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
574 (1 << IEEE80211_RADIOTAP_DB_ANTNOISE))
576 #define BEACON_MAX_DATA_LENGTH 1500
578 /* the maximum size of an AssocReq packet */
579 #define ASSOCREQ_MAX_SIZE \
580 (AT76_TX_HDRLEN + sizeof(struct ieee80211_assoc_request) + \
581 1 + 1 + IW_ESSID_MAX_SIZE + 1 + 1 + 4)
583 /* for shared secret auth, add the challenge text size */
584 #define AUTH_FRAME_SIZE (AT76_TX_HDRLEN + sizeof(struct ieee80211_auth))
586 /* Maximal number of AuthReq retries */
587 #define AUTH_RETRIES 3
589 /* Maximal number of AssocReq retries */
590 #define ASSOC_RETRIES 3
592 /* Beacon timeout in managed mode when we are connected */
593 #define BEACON_TIMEOUT (10 * HZ)
595 /* Timeout for authentication response */
596 #define AUTH_TIMEOUT (1 * HZ)
598 /* Timeout for association response */
599 #define ASSOC_TIMEOUT (1 * HZ)
601 /* Polling interval when scan is running */
602 #define SCAN_POLL_INTERVAL (HZ / 4)
604 /* Command completion timeout */
605 #define CMD_COMPLETION_TIMEOUT (5 * HZ)
607 #define DEF_RTS_THRESHOLD 1536
608 #define DEF_FRAG_THRESHOLD 1536
609 #define DEF_SHORT_RETRY_LIMIT 8
610 #define DEF_CHANNEL 10
611 #define DEF_SCAN_MIN_TIME 10
612 #define DEF_SCAN_MAX_TIME 120
614 #define MAX_RTS_THRESHOLD (MAX_FRAG_THRESHOLD + 1)
616 /* the max padding size for tx in bytes (see calc_padding) */
617 #define MAX_PADDING_SIZE 53
619 #endif /* _AT76_USB_H */