at76c50x-usb.h 11 KB

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