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!
26 * ieee80211 definitions copied from net/ieee80211.h
29 #define WEP_KEY_LEN 13
32 #define IEEE80211_DATA_LEN 2304
33 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
36 The figure in section 7.1.2 suggests a body size of up to 2312
37 bytes is allowed, which is a bit confusing, I suspect this
38 represents the 2304 bytes of real data, plus a possible 8 bytes of
39 WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
41 #define IEEE80211_1ADDR_LEN 10
42 #define IEEE80211_2ADDR_LEN 16
43 #define IEEE80211_3ADDR_LEN 24
44 #define IEEE80211_4ADDR_LEN 30
45 #define IEEE80211_FCS_LEN 4
46 #define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
47 #define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
49 #define MIN_FRAG_THRESHOLD 256U
50 #define MAX_FRAG_THRESHOLD 2346U
52 struct ieee80211_info_element
{
56 } __attribute__ ((packed
));
58 struct ieee80211_hdr_3addr
{
66 } __attribute__ ((packed
));
68 struct ieee80211_auth
{
69 struct ieee80211_hdr_3addr header
;
74 struct ieee80211_info_element info_element
[0];
75 } __attribute__ ((packed
));
77 struct ieee80211_assoc_request
{
78 struct ieee80211_hdr_3addr header
;
80 __le16 listen_interval
;
81 /* SSID, supported rates, RSN */
82 struct ieee80211_info_element info_element
[0];
83 } __attribute__ ((packed
));
85 struct ieee80211_probe_response
{
86 struct ieee80211_hdr_3addr header
;
88 __le16 beacon_interval
;
90 /* SSID, supported rates, FH params, DS params,
91 * CF params, IBSS params, TIM (if beacon), RSN */
92 struct ieee80211_info_element info_element
[0];
93 } __attribute__ ((packed
));
95 /* Alias beacon for probe_response */
96 #define ieee80211_beacon ieee80211_probe_response
98 struct ieee80211_assoc_response
{
99 struct ieee80211_hdr_3addr header
;
103 /* supported rates */
104 struct ieee80211_info_element info_element
[0];
105 } __attribute__ ((packed
));
107 struct ieee80211_disassoc
{
108 struct ieee80211_hdr_3addr header
;
110 } __attribute__ ((packed
));
114 BOARD_503_ISL3861
= 1,
115 BOARD_503_ISL3863
= 2,
124 /* our private ioctl's */
125 /* preamble length (0 - long, 1 - short, 2 - auto) */
126 #define AT76_SET_SHORT_PREAMBLE (SIOCIWFIRSTPRIV + 0)
127 #define AT76_GET_SHORT_PREAMBLE (SIOCIWFIRSTPRIV + 1)
128 /* which debug channels are enabled */
129 #define AT76_SET_DEBUG (SIOCIWFIRSTPRIV + 2)
130 #define AT76_GET_DEBUG (SIOCIWFIRSTPRIV + 3)
131 /* power save mode (incl. the Atmel proprietary smart save mode) */
132 #define AT76_SET_POWERSAVE_MODE (SIOCIWFIRSTPRIV + 4)
133 #define AT76_GET_POWERSAVE_MODE (SIOCIWFIRSTPRIV + 5)
134 /* min and max channel times for scan */
135 #define AT76_SET_SCAN_TIMES (SIOCIWFIRSTPRIV + 6)
136 #define AT76_GET_SCAN_TIMES (SIOCIWFIRSTPRIV + 7)
137 /* scan mode (0 - active, 1 - passive) */
138 #define AT76_SET_SCAN_MODE (SIOCIWFIRSTPRIV + 8)
139 #define AT76_GET_SCAN_MODE (SIOCIWFIRSTPRIV + 9)
141 #define CMD_STATUS_IDLE 0x00
142 #define CMD_STATUS_COMPLETE 0x01
143 #define CMD_STATUS_UNKNOWN 0x02
144 #define CMD_STATUS_INVALID_PARAMETER 0x03
145 #define CMD_STATUS_FUNCTION_NOT_SUPPORTED 0x04
146 #define CMD_STATUS_TIME_OUT 0x07
147 #define CMD_STATUS_IN_PROGRESS 0x08
148 #define CMD_STATUS_HOST_FAILURE 0xff
149 #define CMD_STATUS_SCAN_FAILED 0xf0
151 /* answers to get op mode */
152 #define OPMODE_NONE 0x00
153 #define OPMODE_NORMAL_NIC_WITH_FLASH 0x01
154 #define OPMODE_HW_CONFIG_MODE 0x02
155 #define OPMODE_DFU_MODE_WITH_FLASH 0x03
156 #define OPMODE_NORMAL_NIC_WITHOUT_FLASH 0x04
158 #define CMD_SET_MIB 0x01
159 #define CMD_GET_MIB 0x02
160 #define CMD_SCAN 0x03
161 #define CMD_JOIN 0x04
162 #define CMD_START_IBSS 0x05
163 #define CMD_RADIO_ON 0x06
164 #define CMD_RADIO_OFF 0x07
165 #define CMD_STARTUP 0x0B
167 #define MIB_LOCAL 0x01
168 #define MIB_MAC_ADDR 0x02
170 #define MIB_MAC_MGMT 0x05
171 #define MIB_MAC_WEP 0x06
173 #define MIB_FW_VERSION 0x08
174 #define MIB_MDOMAIN 0x09
177 #define INFRASTRUCTURE_MODE 2
179 /* values for struct mib_local, field preamble_type */
180 #define PREAMBLE_TYPE_LONG 0
181 #define PREAMBLE_TYPE_SHORT 1
182 #define PREAMBLE_TYPE_AUTO 2
184 /* values for tx_rate */
185 #define TX_RATE_1MBIT 0
186 #define TX_RATE_2MBIT 1
187 #define TX_RATE_5_5MBIT 2
188 #define TX_RATE_11MBIT 3
189 #define TX_RATE_AUTO 4
191 /* power management modes */
192 #define AT76_PM_OFF 1
194 #define AT76_PM_SMART 3
201 u8 mac_addr
[ETH_ALEN
];
202 u8 regulatory_domain
;
206 } __attribute__((packed
));
213 u8 mac_addr
[ETH_ALEN
];
214 u8 regulatory_domain
;
215 u8 low_power_values
[14];
216 u8 normal_power_values
[14];
218 } __attribute__((packed
));
220 struct hwcfg_intersil
{
221 u8 mac_addr
[ETH_ALEN
];
225 u8 regulatory_domain
;
227 } __attribute__((packed
));
230 struct hwcfg_intersil i
;
231 struct hwcfg_rfmd r3
;
232 struct hwcfg_r505 r5
;
235 #define WEP_SMALL_KEY_LEN (40 / 8)
236 #define WEP_LARGE_KEY_LEN (104 / 8)
238 struct at76_card_config
{
239 u8 exclude_unencrypted
;
241 u8 short_retry_limit
;
243 __le16 rts_threshold
;
244 __le16 fragmentation_threshold
; /* 256..2346 */
245 u8 basic_rate_set
[4];
246 u8 auto_rate_fallback
; /* 0,1 */
249 u8 wep_default_key_id
; /* 0..3 */
251 u8 wep_default_key_value
[4][WEP_KEY_LEN
];
254 __le16 beacon_period
;
255 } __attribute__((packed
));
257 struct at76_command
{
262 } __attribute__((packed
));
264 /* Length of Atmel-specific Rx header before 802.11 frame */
265 #define AT76_RX_HDRLEN offsetof(struct at76_rx_buffer, packet)
267 struct at76_rx_buffer
{
276 u8 packet
[IEEE80211_FRAME_LEN
+ IEEE80211_FCS_LEN
];
277 } __attribute__((packed
));
279 /* Length of Atmel-specific Tx header before 802.11 frame */
280 #define AT76_TX_HDRLEN offsetof(struct at76_tx_buffer, packet)
282 struct at76_tx_buffer
{
287 u8 packet
[IEEE80211_FRAME_LEN
+ IEEE80211_FCS_LEN
];
288 } __attribute__((packed
));
290 /* defines for scan_type below */
291 #define SCAN_TYPE_ACTIVE 0
292 #define SCAN_TYPE_PASSIVE 1
294 struct at76_req_scan
{
300 __le16 min_channel_time
;
301 __le16 max_channel_time
;
303 u8 international_scan
;
304 } __attribute__((packed
));
306 struct at76_req_ibss
{
313 } __attribute__((packed
));
315 struct at76_req_join
{
323 } __attribute__((packed
));
325 struct set_mib_buffer
{
335 } __attribute__((packed
));
340 u8 txautorate_fallback
;
347 } __attribute__((packed
));
349 struct mib_mac_addr
{
350 u8 mac_addr
[ETH_ALEN
];
352 u8 group_addr
[4][ETH_ALEN
];
353 u8 group_addr_status
[4];
354 } __attribute__((packed
));
357 __le32 max_tx_msdu_lifetime
;
358 __le32 max_rx_lifetime
;
359 __le16 frag_threshold
;
360 __le16 rts_threshold
;
365 u8 scan_type
; /* active or passive */
367 __le16 probe_delay
; /* delay before ProbeReq in active scan, RO */
368 __le16 min_channel_time
;
369 __le16 max_channel_time
;
370 __le16 listen_interval
;
372 u8 desired_bssid
[ETH_ALEN
];
373 u8 desired_bsstype
; /* ad-hoc or infrastructure */
375 } __attribute__((packed
));
377 struct mib_mac_mgmt
{
378 __le16 beacon_period
;
379 __le16 CFP_max_duration
;
380 __le16 medium_occupancy_limit
;
381 __le16 station_id
; /* assoc id */
384 u8 privacy_option_implemented
;
387 u8 current_bssid
[ETH_ALEN
];
388 u8 current_essid
[32];
394 u8 multi_domain_capability_implemented
;
395 u8 multi_domain_capability_enabled
;
396 u8 country_string
[3];
398 } __attribute__((packed
));
401 u8 privacy_invoked
; /* 0 disable encr., 1 enable encr */
402 u8 wep_default_key_id
;
403 u8 wep_key_mapping_len
;
404 u8 exclude_unencrypted
;
405 __le32 wep_icv_error_count
;
406 __le32 wep_excluded_count
;
407 u8 wep_default_keyvalue
[WEP_KEYS
][WEP_KEY_LEN
];
408 u8 encryption_level
; /* 1 for 40bit, 2 for 104bit encryption */
409 } __attribute__((packed
));
416 __le16 preamble_length
;
417 __le16 plcp_header_length
;
418 __le16 mpdu_max_length
;
419 __le16 cca_mode_supported
;
421 u8 operation_rate_set
[4];
425 u8 current_reg_domain
;
426 } __attribute__((packed
));
428 struct mib_fw_version
{
433 } __attribute__((packed
));
436 u8 tx_powerlevel
[14];
437 u8 channel_list
[14]; /* 0 for invalid channels */
438 } __attribute__((packed
));
440 struct at76_fw_header
{
441 __le32 crc
; /* CRC32 of the whole image */
442 __le32 board_type
; /* firmware compatibility code */
443 u8 build
; /* firmware build number */
444 u8 patch
; /* firmware patch level */
445 u8 minor
; /* firmware minor version */
446 u8 major
; /* firmware major version */
447 __le32 str_offset
; /* offset of the copyright string */
448 __le32 int_fw_offset
; /* internal firmware image offset */
449 __le32 int_fw_len
; /* internal firmware image length */
450 __le32 ext_fw_offset
; /* external firmware image offset */
451 __le32 ext_fw_len
; /* external firmware image length */
452 } __attribute__((packed
));
464 /* a description of a regulatory domain and the allowed channels */
468 u32 channel_map
; /* if bit N is set, channel (N+1) is allowed */
471 /* how long do we keep a (I)BSS in the bss_list in jiffies
472 this should be long enough for the user to retrieve the table
473 (by iwlist ?) after the device started, because all entries from
474 other channels than the one the device locks on get removed, too */
475 #define BSS_LIST_TIMEOUT (120 * HZ)
476 /* struct to store BSS info found during scan */
477 #define BSS_LIST_MAX_RATE_LEN 32 /* 32 rates should be enough ... */
480 struct list_head list
;
482 u8 bssid
[ETH_ALEN
]; /* bssid */
483 u8 ssid
[IW_ESSID_MAX_SIZE
]; /* essid */
484 u8 ssid_len
; /* length of ssid above */
486 u16 capa
; /* BSS capabilities */
487 u16 beacon_interval
; /* beacon interval, Kus (1024 microseconds) */
488 u8 rates
[BSS_LIST_MAX_RATE_LEN
]; /* supported rates in units of
489 500 kbps, ORed with 0x80 for
493 /* quality of received beacon */
498 unsigned long last_rx
; /* time (jiffies) of last beacon received */
501 /* a rx data buffer to collect rx fragments */
503 u8 sender
[ETH_ALEN
]; /* sender address */
504 u16 seqnr
; /* sequence number */
505 u16 fragnr
; /* last fragment received */
506 unsigned long last_rx
; /* jiffies of last rx */
507 struct sk_buff
*skb
; /* == NULL if entry is free */
510 #define NR_RX_DATA_BUF 8
512 /* Data for one loaded firmware file */
514 const char *const fwname
;
515 const struct firmware
*fw
;
518 /* pointer to loaded firmware, no need to free */
519 u8
*extfw
; /* external firmware, extfw_size bytes long */
520 u8
*intfw
; /* internal firmware, intfw_size bytes long */
521 enum board_type board_type
; /* board type */
522 struct mib_fw_version fw_version
;
523 int loaded
; /* Loaded and parsed successfully */
527 struct usb_device
*udev
; /* USB device pointer */
528 struct net_device
*netdev
; /* net device pointer */
529 struct net_device_stats stats
; /* net device stats */
530 struct iw_statistics wstats
; /* wireless stats */
532 struct sk_buff
*rx_skb
; /* skbuff for receiving data */
533 void *bulk_out_buffer
; /* buffer for sending data */
535 struct urb
*tx_urb
; /* URB for sending data */
536 struct urb
*rx_urb
; /* URB for receiving data */
538 unsigned int tx_pipe
; /* bulk out pipe */
539 unsigned int rx_pipe
; /* bulk in pipe */
541 struct mutex mtx
; /* locks this structure */
544 struct work_struct work_assoc_done
;
545 struct work_struct work_join
;
546 struct work_struct work_new_bss
;
547 struct work_struct work_start_scan
;
548 struct work_struct work_set_promisc
;
549 struct work_struct work_submit_rx
;
550 struct delayed_work dwork_restart
;
551 struct delayed_work dwork_get_scan
;
552 struct delayed_work dwork_beacon
;
553 struct delayed_work dwork_auth
;
554 struct delayed_work dwork_assoc
;
556 struct tasklet_struct rx_tasklet
;
559 int wep_enabled
; /* 1 if WEP is enabled */
560 int wep_key_id
; /* key id to be used */
561 u8 wep_keys
[WEP_KEYS
][WEP_KEY_LEN
]; /* the four WEP keys,
562 5 or 13 bytes are used */
563 u8 wep_keys_len
[WEP_KEYS
]; /* the length of the above keys */
568 u8 essid
[IW_ESSID_MAX_SIZE
];
573 int preamble_type
; /* 0 - long, 1 - short, 2 - auto */
574 int auth_mode
; /* authentication type: 0 open, 1 shared key */
575 int txrate
; /* 0,1,2,3 = 1,2,5.5,11 Mbps, 4 is auto */
576 int frag_threshold
; /* threshold for fragmentation of tx packets */
577 int rts_threshold
; /* threshold for RTS mechanism */
578 int short_retry_limit
;
580 int scan_min_time
; /* scan min channel time */
581 int scan_max_time
; /* scan max channel time */
582 int scan_mode
; /* SCAN_TYPE_ACTIVE, SCAN_TYPE_PASSIVE */
583 int scan_need_any
; /* if set, need to scan for any ESSID */
585 /* the list we got from scanning */
586 spinlock_t bss_list_spinlock
; /* protects bss_list operations */
587 struct list_head bss_list
; /* list of BSS we got beacons from */
588 struct timer_list bss_list_timer
; /* timer to purge old entries
590 struct bss_info
*curr_bss
; /* current BSS */
591 u16 assoc_id
; /* current association ID, if associated */
593 u8 wanted_bssid
[ETH_ALEN
];
594 int wanted_bssid_valid
; /* != 0 if wanted_bssid is to be used */
596 /* some data for infrastructure mode only */
597 spinlock_t mgmt_spinlock
; /* this spinlock protects access to
600 struct at76_tx_buffer
*next_mgmt_bulk
; /* pending management msg to
602 enum mac_state mac_state
;
610 int retries
; /* remaining retries in case of timeout when
611 * sending AuthReq or AssocReq */
612 u8 pm_mode
; /* power management mode */
613 u32 pm_period
; /* power management period in microseconds */
615 struct reg_domain
const *domain
; /* reg domain description */
618 spinlock_t spy_spinlock
;
619 struct iw_spy_data spy_data
;
621 struct iw_public_data wireless_data
;
623 /* These fields contain HW config provided by the device (not all of
624 * these fields are used by all board types) */
625 u8 mac_addr
[ETH_ALEN
];
626 u8 regulatory_domain
;
628 struct at76_card_config card_config
;
630 /* store rx fragments until complete */
631 struct rx_data_buf rx_data
[NR_RX_DATA_BUF
];
633 enum board_type board_type
;
634 struct mib_fw_version fw_version
;
636 unsigned int device_unplugged
:1;
637 unsigned int netdev_registered
:1;
638 struct set_mib_buffer mib_buf
; /* global buffer for set_mib calls */
640 /* beacon counting */
641 int beacon_period
; /* period of mgmt beacons, Kus */
642 int beacons_received
;
643 unsigned long beacons_last_qual
; /* time we restarted counting
647 struct at76_rx_radiotap
{
648 struct ieee80211_radiotap_header rt_hdr
;
656 #define AT76_RX_RADIOTAP_PRESENT \
657 ((1 << IEEE80211_RADIOTAP_TSFT) | \
658 (1 << IEEE80211_RADIOTAP_FLAGS) | \
659 (1 << IEEE80211_RADIOTAP_RATE) | \
660 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | \
661 (1 << IEEE80211_RADIOTAP_DB_ANTNOISE))
663 #define BEACON_MAX_DATA_LENGTH 1500
665 /* the maximum size of an AssocReq packet */
666 #define ASSOCREQ_MAX_SIZE \
667 (AT76_TX_HDRLEN + sizeof(struct ieee80211_assoc_request) + \
668 1 + 1 + IW_ESSID_MAX_SIZE + 1 + 1 + 4)
670 /* for shared secret auth, add the challenge text size */
671 #define AUTH_FRAME_SIZE (AT76_TX_HDRLEN + sizeof(struct ieee80211_auth))
673 /* Maximal number of AuthReq retries */
674 #define AUTH_RETRIES 3
676 /* Maximal number of AssocReq retries */
677 #define ASSOC_RETRIES 3
679 /* Beacon timeout in managed mode when we are connected */
680 #define BEACON_TIMEOUT (10 * HZ)
682 /* Timeout for authentication response */
683 #define AUTH_TIMEOUT (1 * HZ)
685 /* Timeout for association response */
686 #define ASSOC_TIMEOUT (1 * HZ)
688 /* Polling interval when scan is running */
689 #define SCAN_POLL_INTERVAL (HZ / 4)
691 /* Command completion timeout */
692 #define CMD_COMPLETION_TIMEOUT (5 * HZ)
694 #define DEF_RTS_THRESHOLD 1536
695 #define DEF_FRAG_THRESHOLD 1536
696 #define DEF_SHORT_RETRY_LIMIT 8
697 #define DEF_CHANNEL 10
698 #define DEF_SCAN_MIN_TIME 10
699 #define DEF_SCAN_MAX_TIME 120
701 #define MAX_RTS_THRESHOLD (MAX_FRAG_THRESHOLD + 1)
703 /* the max padding size for tx in bytes (see calc_padding) */
704 #define MAX_PADDING_SIZE 53
706 #endif /* _AT76_USB_H */