Staging: at76_usb: update drivers/staging/at76_usb w/ mac80211 port
[safe/jmp/linux-2.6] / drivers / staging / at76_usb / at76_usb.h
1 /*
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>
5  *
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.
10  *
11  * This driver was based on information from the Sourceforge driver
12  * released and maintained by Atmel:
13  *
14  *  http://sourceforge.net/projects/atmelwlandriver/
15  *
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!
20  */
21
22 #ifndef _AT76_USB_H
23 #define _AT76_USB_H
24
25 /* Board types */
26 enum board_type {
27         BOARD_503_ISL3861 = 1,
28         BOARD_503_ISL3863 = 2,
29         BOARD_503 = 3,
30         BOARD_503_ACC = 4,
31         BOARD_505 = 5,
32         BOARD_505_2958 = 6,
33         BOARD_505A = 7,
34         BOARD_505AMX = 8
35 };
36
37 #define CMD_STATUS_IDLE                         0x00
38 #define CMD_STATUS_COMPLETE                     0x01
39 #define CMD_STATUS_UNKNOWN                      0x02
40 #define CMD_STATUS_INVALID_PARAMETER            0x03
41 #define CMD_STATUS_FUNCTION_NOT_SUPPORTED       0x04
42 #define CMD_STATUS_TIME_OUT                     0x07
43 #define CMD_STATUS_IN_PROGRESS                  0x08
44 #define CMD_STATUS_HOST_FAILURE                 0xff
45 #define CMD_STATUS_SCAN_FAILED                  0xf0
46
47 /* answers to get op mode */
48 #define OPMODE_NONE                             0x00
49 #define OPMODE_NORMAL_NIC_WITH_FLASH            0x01
50 #define OPMODE_HW_CONFIG_MODE                   0x02
51 #define OPMODE_DFU_MODE_WITH_FLASH              0x03
52 #define OPMODE_NORMAL_NIC_WITHOUT_FLASH         0x04
53
54 #define CMD_SET_MIB             0x01
55 #define CMD_GET_MIB             0x02
56 #define CMD_SCAN                0x03
57 #define CMD_JOIN                0x04
58 #define CMD_START_IBSS          0x05
59 #define CMD_RADIO_ON            0x06
60 #define CMD_RADIO_OFF           0x07
61 #define CMD_STARTUP             0x0B
62
63 #define MIB_LOCAL               0x01
64 #define MIB_MAC_ADDR            0x02
65 #define MIB_MAC                 0x03
66 #define MIB_MAC_MGMT            0x05
67 #define MIB_MAC_WEP             0x06
68 #define MIB_MAC_ENCRYPTION      0x06
69 #define MIB_PHY                 0x07
70 #define MIB_FW_VERSION          0x08
71 #define MIB_MDOMAIN             0x09
72
73 #define ADHOC_MODE              1
74 #define INFRASTRUCTURE_MODE     2
75
76 /* values for struct mib_local, field preamble_type */
77 #define PREAMBLE_TYPE_LONG      0
78 #define PREAMBLE_TYPE_SHORT     1
79 #define PREAMBLE_TYPE_AUTO      2
80
81 /* values for tx_rate */
82 #define TX_RATE_1MBIT           0
83 #define TX_RATE_2MBIT           1
84 #define TX_RATE_5_5MBIT         2
85 #define TX_RATE_11MBIT          3
86 #define TX_RATE_AUTO            4
87
88 /* power management modes */
89 #define AT76_PM_OFF             1
90 #define AT76_PM_ON              2
91 #define AT76_PM_SMART           3
92
93 /* cipher values for encryption keys */
94 #define CIPHER_NONE             0       /* this value is only guessed */
95 #define CIPHER_WEP64            1
96 #define CIPHER_TKIP             2
97 #define CIPHER_CCMP             3
98 #define CIPHER_CCX              4       /* for consistency sake only */
99 #define CIPHER_WEP128           5
100
101 /* bit flags key types for encryption keys */
102 #define KEY_PAIRWISE            2
103 #define KEY_TX                  4
104
105 #define CIPHER_KEYS             (4)
106 #define CIPHER_KEY_LEN          (40)
107
108 struct key_config {
109         u8 cipher;
110         u8 keylen;
111 };
112
113 struct hwcfg_r505 {
114         u8 cr39_values[14];
115         u8 reserved1[14];
116         u8 bb_cr[14];
117         u8 pidvid[4];
118         u8 mac_addr[ETH_ALEN];
119         u8 regulatory_domain;
120         u8 reserved2[14];
121         u8 cr15_values[14];
122         u8 reserved3[3];
123 } __attribute__((packed));
124
125 struct hwcfg_rfmd {
126         u8 cr20_values[14];
127         u8 cr21_values[14];
128         u8 bb_cr[14];
129         u8 pidvid[4];
130         u8 mac_addr[ETH_ALEN];
131         u8 regulatory_domain;
132         u8 low_power_values[14];
133         u8 normal_power_values[14];
134         u8 reserved1[3];
135 } __attribute__((packed));
136
137 struct hwcfg_intersil {
138         u8 mac_addr[ETH_ALEN];
139         u8 cr31_values[14];
140         u8 cr58_values[14];
141         u8 pidvid[4];
142         u8 regulatory_domain;
143         u8 reserved[1];
144 } __attribute__((packed));
145
146 union at76_hwcfg {
147         struct hwcfg_intersil i;
148         struct hwcfg_rfmd r3;
149         struct hwcfg_r505 r5;
150 };
151
152 #define WEP_SMALL_KEY_LEN       (40 / 8)
153 #define WEP_LARGE_KEY_LEN       (104 / 8)
154 #define WEP_KEYS                (4)
155
156
157
158 struct at76_card_config {
159         u8 exclude_unencrypted;
160         u8 promiscuous_mode;
161         u8 short_retry_limit;
162         u8 encryption_type;
163         __le16 rts_threshold;
164         __le16 fragmentation_threshold; /* 256..2346 */
165         u8 basic_rate_set[4];
166         u8 auto_rate_fallback;  /* 0,1 */
167         u8 channel;
168         u8 privacy_invoked;
169         u8 wep_default_key_id;  /* 0..3 */
170         u8 current_ssid[32];
171         u8 wep_default_key_value[4][WEP_LARGE_KEY_LEN];
172         u8 ssid_len;
173         u8 short_preamble;
174         __le16 beacon_period;
175 } __attribute__((packed));
176
177 struct at76_command {
178         u8 cmd;
179         u8 reserved;
180         __le16 size;
181         u8 data[0];
182 } __attribute__((packed));
183
184 /* Length of Atmel-specific Rx header before 802.11 frame */
185 #define AT76_RX_HDRLEN offsetof(struct at76_rx_buffer, packet)
186
187 struct at76_rx_buffer {
188         __le16 wlength;
189         u8 rx_rate;
190         u8 newbss;
191         u8 fragmentation;
192         u8 rssi;
193         u8 link_quality;
194         u8 noise_level;
195         __le32 rx_time;
196         u8 packet[IEEE80211_MAX_FRAG_THRESHOLD];
197 } __attribute__((packed));
198
199 /* Length of Atmel-specific Tx header before 802.11 frame */
200 #define AT76_TX_HDRLEN offsetof(struct at76_tx_buffer, packet)
201
202 struct at76_tx_buffer {
203         __le16 wlength;
204         u8 tx_rate;
205         u8 padding;
206         u8 key_id;
207         u8 cipher_type;
208         u8 cipher_length;
209         u8 reserved;
210         u8 packet[IEEE80211_MAX_FRAG_THRESHOLD];
211 } __attribute__((packed));
212
213 /* defines for scan_type below */
214 #define SCAN_TYPE_ACTIVE        0
215 #define SCAN_TYPE_PASSIVE       1
216
217 struct at76_req_scan {
218         u8 bssid[ETH_ALEN];
219         u8 essid[32];
220         u8 scan_type;
221         u8 channel;
222         __le16 probe_delay;
223         __le16 min_channel_time;
224         __le16 max_channel_time;
225         u8 essid_size;
226         u8 international_scan;
227 } __attribute__((packed));
228
229 struct at76_req_ibss {
230         u8 bssid[ETH_ALEN];
231         u8 essid[32];
232         u8 bss_type;
233         u8 channel;
234         u8 essid_size;
235         u8 reserved[3];
236 } __attribute__((packed));
237
238 struct at76_req_join {
239         u8 bssid[ETH_ALEN];
240         u8 essid[32];
241         u8 bss_type;
242         u8 channel;
243         __le16 timeout;
244         u8 essid_size;
245         u8 reserved;
246 } __attribute__((packed));
247
248 struct set_mib_buffer {
249         u8 type;
250         u8 size;
251         u8 index;
252         u8 reserved;
253         union {
254                 u8 byte;
255                 __le16 word;
256                 u8 addr[ETH_ALEN];
257                 u8 data[256];   /* we need more space for mib_mac_encryption */
258         } data;
259 } __attribute__((packed));
260
261 struct mib_local {
262         u16 reserved0;
263         u8 beacon_enable;
264         u8 txautorate_fallback;
265         u8 reserved1;
266         u8 ssid_size;
267         u8 promiscuous_mode;
268         u16 reserved2;
269         u8 preamble_type;
270         u16 reserved3;
271 } __attribute__((packed));
272
273 struct mib_mac_addr {
274         u8 mac_addr[ETH_ALEN];
275         u8 res[2];              /* ??? */
276         u8 group_addr[4][ETH_ALEN];
277         u8 group_addr_status[4];
278 } __attribute__((packed));
279
280 struct mib_mac {
281         __le32 max_tx_msdu_lifetime;
282         __le32 max_rx_lifetime;
283         __le16 frag_threshold;
284         __le16 rts_threshold;
285         __le16 cwmin;
286         __le16 cwmax;
287         u8 short_retry_time;
288         u8 long_retry_time;
289         u8 scan_type;           /* active or passive */
290         u8 scan_channel;
291         __le16 probe_delay;     /* delay before ProbeReq in active scan, RO */
292         __le16 min_channel_time;
293         __le16 max_channel_time;
294         __le16 listen_interval;
295         u8 desired_ssid[32];
296         u8 desired_bssid[ETH_ALEN];
297         u8 desired_bsstype;     /* ad-hoc or infrastructure */
298         u8 reserved2;
299 } __attribute__((packed));
300
301 struct mib_mac_mgmt {
302         __le16 beacon_period;
303         __le16 CFP_max_duration;
304         __le16 medium_occupancy_limit;
305         __le16 station_id;      /* assoc id */
306         __le16 ATIM_window;
307         u8 CFP_mode;
308         u8 privacy_option_implemented;
309         u8 DTIM_period;
310         u8 CFP_period;
311         u8 current_bssid[ETH_ALEN];
312         u8 current_essid[32];
313         u8 current_bss_type;
314         u8 power_mgmt_mode;
315         /* rfmd and 505 */
316         u8 ibss_change;
317         u8 res;
318         u8 multi_domain_capability_implemented;
319         u8 multi_domain_capability_enabled;
320         u8 country_string[3];
321         u8 reserved[3];
322 } __attribute__((packed));
323
324 struct mib_mac_wep {
325         u8 privacy_invoked;     /* 0 disable encr., 1 enable encr */
326         u8 wep_default_key_id;
327         u8 wep_key_mapping_len;
328         u8 exclude_unencrypted;
329         __le32 wep_icv_error_count;
330         __le32 wep_excluded_count;
331         u8 wep_default_keyvalue[WEP_KEYS][WEP_LARGE_KEY_LEN];
332         u8 encryption_level;    /* 1 for 40bit, 2 for 104bit encryption */
333 } __attribute__((packed));
334
335 struct mib_mac_encryption {
336         u8 cipher_default_keyvalue[CIPHER_KEYS][CIPHER_KEY_LEN];
337         u8 tkip_bssid[6];
338         u8 privacy_invoked;
339         u8 cipher_default_key_id;
340         u8 cipher_default_group_key_id;
341         u8 exclude_unencrypted;
342         u8 wep_encryption_type;
343         u8 ckip_key_permutation;        /* bool */
344         __le32 wep_icv_error_count;
345         __le32 wep_excluded_count;
346         u8 key_rsc[CIPHER_KEYS][8];
347 } __attribute__((packed));
348
349 struct mib_phy {
350         __le32 ed_threshold;
351
352         __le16 slot_time;
353         __le16 sifs_time;
354         __le16 preamble_length;
355         __le16 plcp_header_length;
356         __le16 mpdu_max_length;
357         __le16 cca_mode_supported;
358
359         u8 operation_rate_set[4];
360         u8 channel_id;
361         u8 current_cca_mode;
362         u8 phy_type;
363         u8 current_reg_domain;
364 } __attribute__((packed));
365
366 struct mib_fw_version {
367         u8 major;
368         u8 minor;
369         u8 patch;
370         u8 build;
371 } __attribute__((packed));
372
373 struct mib_mdomain {
374         u8 tx_powerlevel[14];
375         u8 channel_list[14];    /* 0 for invalid channels */
376 } __attribute__((packed));
377
378 struct at76_fw_header {
379         __le32 crc;             /* CRC32 of the whole image */
380         __le32 board_type;      /* firmware compatibility code */
381         u8 build;               /* firmware build number */
382         u8 patch;               /* firmware patch level */
383         u8 minor;               /* firmware minor version */
384         u8 major;               /* firmware major version */
385         __le32 str_offset;      /* offset of the copyright string */
386         __le32 int_fw_offset;   /* internal firmware image offset */
387         __le32 int_fw_len;      /* internal firmware image length */
388         __le32 ext_fw_offset;   /* external firmware image offset */
389         __le32 ext_fw_len;      /* external firmware image length */
390 } __attribute__((packed));
391
392 /* a description of a regulatory domain and the allowed channels */
393 struct reg_domain {
394         u16 code;
395         char const *name;
396         u32 channel_map;        /* if bit N is set, channel (N+1) is allowed */
397 };
398
399 /* Data for one loaded firmware file */
400 struct fwentry {
401         const char *const fwname;
402         const struct firmware *fw;
403         int extfw_size;
404         int intfw_size;
405         /* pointer to loaded firmware, no need to free */
406         u8 *extfw;              /* external firmware, extfw_size bytes long */
407         u8 *intfw;              /* internal firmware, intfw_size bytes long */
408         enum board_type board_type;     /* board type */
409         struct mib_fw_version fw_version;
410         int loaded;             /* Loaded and parsed successfully */
411 };
412
413 struct at76_priv {
414         struct usb_device *udev;        /* USB device pointer */
415
416         struct sk_buff *rx_skb; /* skbuff for receiving data */
417         struct sk_buff *tx_skb; /* skbuff for transmitting data */
418         void *bulk_out_buffer;  /* buffer for sending data */
419
420         struct urb *tx_urb;     /* URB for sending data */
421         struct urb *rx_urb;     /* URB for receiving data */
422
423         unsigned int tx_pipe;   /* bulk out pipe */
424         unsigned int rx_pipe;   /* bulk in pipe */
425
426         struct mutex mtx;       /* locks this structure */
427
428         /* work queues */
429         struct work_struct work_set_promisc;
430         struct work_struct work_submit_rx;
431         struct delayed_work dwork_hw_scan;
432
433         struct tasklet_struct rx_tasklet;
434
435         /* the WEP stuff */
436         int wep_enabled;        /* 1 if WEP is enabled */
437         int wep_key_id;         /* key id to be used */
438         u8 wep_keys[WEP_KEYS][WEP_LARGE_KEY_LEN];       /* WEP keys */
439         u8 wep_keys_len[WEP_KEYS];      /* length of WEP keys */
440
441         int channel;
442         int iw_mode;
443         u8 bssid[ETH_ALEN];
444         u8 essid[IW_ESSID_MAX_SIZE];
445         int essid_size;
446         int radio_on;
447         int promisc;
448
449         int preamble_type;      /* 0 - long, 1 - short, 2 - auto */
450         int auth_mode;          /* authentication type: 0 open, 1 shared key */
451         int txrate;             /* 0,1,2,3 = 1,2,5.5,11 Mbps, 4 is auto */
452         int frag_threshold;     /* threshold for fragmentation of tx packets */
453         int rts_threshold;      /* threshold for RTS mechanism */
454         int short_retry_limit;
455
456         int scan_min_time;      /* scan min channel time */
457         int scan_max_time;      /* scan max channel time */
458         int scan_mode;          /* SCAN_TYPE_ACTIVE, SCAN_TYPE_PASSIVE */
459         int scan_need_any;      /* if set, need to scan for any ESSID */
460
461         u16 assoc_id;           /* current association ID, if associated */
462
463         u8 pm_mode;             /* power management mode */
464         u32 pm_period;          /* power management period in microseconds */
465
466         struct reg_domain const *domain;        /* reg domain description */
467
468         /* These fields contain HW config provided by the device (not all of
469          * these fields are used by all board types) */
470         u8 mac_addr[ETH_ALEN];
471         u8 regulatory_domain;
472
473         struct at76_card_config card_config;
474
475         enum board_type board_type;
476         struct mib_fw_version fw_version;
477
478         unsigned int device_unplugged:1;
479         unsigned int netdev_registered:1;
480         struct set_mib_buffer mib_buf;  /* global buffer for set_mib calls */
481
482         int beacon_period;      /* period of mgmt beacons, Kus */
483
484         struct ieee80211_hw *hw;
485         int mac80211_registered;
486
487         struct key_config keys[4];      /* installed key types */
488         u8 default_pairwise_key;
489         u8 default_group_key;
490 };
491
492 #define AT76_SUPPORTED_FILTERS FIF_PROMISC_IN_BSS
493
494 #define SCAN_POLL_INTERVAL      (HZ / 4)
495
496 #define CMD_COMPLETION_TIMEOUT  (5 * HZ)
497
498 #define DEF_RTS_THRESHOLD       1536
499 #define DEF_FRAG_THRESHOLD      1536
500 #define DEF_SHORT_RETRY_LIMIT   8
501 #define DEF_CHANNEL             10
502 #define DEF_SCAN_MIN_TIME       10
503 #define DEF_SCAN_MAX_TIME       120
504
505 /* the max padding size for tx in bytes (see calc_padding) */
506 #define MAX_PADDING_SIZE        53
507
508 #endif                          /* _AT76_USB_H */