at76c50x-usb.h 11 KB

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