zd_mac.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /* ZD1211 USB-WLAN driver for Linux
  2. *
  3. * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
  4. * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #ifndef _ZD_MAC_H
  21. #define _ZD_MAC_H
  22. #include <linux/kernel.h>
  23. #include <net/mac80211.h>
  24. #include "zd_chip.h"
  25. struct zd_ctrlset {
  26. u8 modulation;
  27. __le16 tx_length;
  28. u8 control;
  29. /* stores only the difference to tx_length on ZD1211B */
  30. __le16 packet_length;
  31. __le16 current_length;
  32. u8 service;
  33. __le16 next_frame_length;
  34. } __packed;
  35. #define ZD_CS_RESERVED_SIZE 25
  36. /* The field modulation of struct zd_ctrlset controls the bit rate, the use
  37. * of short or long preambles in 802.11b (CCK mode) or the use of 802.11a or
  38. * 802.11g in OFDM mode.
  39. *
  40. * The term zd-rate is used for the combination of the modulation type flag
  41. * and the "pure" rate value.
  42. */
  43. #define ZD_PURE_RATE_MASK 0x0f
  44. #define ZD_MODULATION_TYPE_MASK 0x10
  45. #define ZD_RATE_MASK (ZD_PURE_RATE_MASK|ZD_MODULATION_TYPE_MASK)
  46. #define ZD_PURE_RATE(modulation) ((modulation) & ZD_PURE_RATE_MASK)
  47. #define ZD_MODULATION_TYPE(modulation) ((modulation) & ZD_MODULATION_TYPE_MASK)
  48. #define ZD_RATE(modulation) ((modulation) & ZD_RATE_MASK)
  49. /* The two possible modulation types. Notify that 802.11b doesn't use the CCK
  50. * codeing for the 1 and 2 MBit/s rate. We stay with the term here to remain
  51. * consistent with uses the term at other places.
  52. */
  53. #define ZD_CCK 0x00
  54. #define ZD_OFDM 0x10
  55. /* The ZD1211 firmware uses proprietary encodings of the 802.11b (CCK) rates.
  56. * For OFDM the PLCP rate encodings are used. We combine these "pure" rates
  57. * with the modulation type flag and call the resulting values zd-rates.
  58. */
  59. #define ZD_CCK_RATE_1M (ZD_CCK|0x00)
  60. #define ZD_CCK_RATE_2M (ZD_CCK|0x01)
  61. #define ZD_CCK_RATE_5_5M (ZD_CCK|0x02)
  62. #define ZD_CCK_RATE_11M (ZD_CCK|0x03)
  63. #define ZD_OFDM_RATE_6M (ZD_OFDM|ZD_OFDM_PLCP_RATE_6M)
  64. #define ZD_OFDM_RATE_9M (ZD_OFDM|ZD_OFDM_PLCP_RATE_9M)
  65. #define ZD_OFDM_RATE_12M (ZD_OFDM|ZD_OFDM_PLCP_RATE_12M)
  66. #define ZD_OFDM_RATE_18M (ZD_OFDM|ZD_OFDM_PLCP_RATE_18M)
  67. #define ZD_OFDM_RATE_24M (ZD_OFDM|ZD_OFDM_PLCP_RATE_24M)
  68. #define ZD_OFDM_RATE_36M (ZD_OFDM|ZD_OFDM_PLCP_RATE_36M)
  69. #define ZD_OFDM_RATE_48M (ZD_OFDM|ZD_OFDM_PLCP_RATE_48M)
  70. #define ZD_OFDM_RATE_54M (ZD_OFDM|ZD_OFDM_PLCP_RATE_54M)
  71. /* The bit 5 of the zd_ctrlset modulation field controls the preamble in CCK
  72. * mode or the 802.11a/802.11g selection in OFDM mode.
  73. */
  74. #define ZD_CCK_PREA_LONG 0x00
  75. #define ZD_CCK_PREA_SHORT 0x20
  76. #define ZD_OFDM_MODE_11G 0x00
  77. #define ZD_OFDM_MODE_11A 0x20
  78. /* zd_ctrlset control field */
  79. #define ZD_CS_NEED_RANDOM_BACKOFF 0x01
  80. #define ZD_CS_NO_ACK 0x02
  81. #define ZD_CS_FRAME_TYPE_MASK 0x0c
  82. #define ZD_CS_DATA_FRAME 0x00
  83. #define ZD_CS_PS_POLL_FRAME 0x04
  84. #define ZD_CS_MANAGEMENT_FRAME 0x08
  85. #define ZD_CS_NO_SEQUENCE_CTL_FRAME 0x0c
  86. #define ZD_CS_WAKE_DESTINATION 0x10
  87. #define ZD_CS_RTS 0x20
  88. #define ZD_CS_ENCRYPT 0x40
  89. #define ZD_CS_SELF_CTS 0x80
  90. /* Incoming frames are prepended by a PLCP header */
  91. #define ZD_PLCP_HEADER_SIZE 5
  92. struct rx_length_info {
  93. __le16 length[3];
  94. __le16 tag;
  95. } __packed;
  96. #define RX_LENGTH_INFO_TAG 0x697e
  97. struct rx_status {
  98. u8 signal_quality_cck;
  99. /* rssi */
  100. u8 signal_strength;
  101. u8 signal_quality_ofdm;
  102. u8 decryption_type;
  103. u8 frame_status;
  104. } __packed;
  105. /* rx_status field decryption_type */
  106. #define ZD_RX_NO_WEP 0
  107. #define ZD_RX_WEP64 1
  108. #define ZD_RX_TKIP 2
  109. #define ZD_RX_AES 4
  110. #define ZD_RX_WEP128 5
  111. #define ZD_RX_WEP256 6
  112. /* rx_status field frame_status */
  113. #define ZD_RX_FRAME_MODULATION_MASK 0x01
  114. #define ZD_RX_CCK 0x00
  115. #define ZD_RX_OFDM 0x01
  116. #define ZD_RX_TIMEOUT_ERROR 0x02
  117. #define ZD_RX_FIFO_OVERRUN_ERROR 0x04
  118. #define ZD_RX_DECRYPTION_ERROR 0x08
  119. #define ZD_RX_CRC32_ERROR 0x10
  120. #define ZD_RX_NO_ADDR1_MATCH_ERROR 0x20
  121. #define ZD_RX_CRC16_ERROR 0x40
  122. #define ZD_RX_ERROR 0x80
  123. struct tx_retry_rate {
  124. int count; /* number of valid element in rate[] array */
  125. int rate[10]; /* retry rates, described by an index in zd_rates[] */
  126. };
  127. struct tx_status {
  128. u8 type; /* must always be 0x01 : USB_INT_TYPE */
  129. u8 id; /* must always be 0xa0 : USB_INT_ID_RETRY_FAILED */
  130. u8 rate;
  131. u8 pad;
  132. u8 mac[ETH_ALEN];
  133. u8 retry;
  134. u8 failure;
  135. } __packed;
  136. enum mac_flags {
  137. MAC_FIXED_CHANNEL = 0x01,
  138. };
  139. struct housekeeping {
  140. struct delayed_work link_led_work;
  141. };
  142. struct beacon {
  143. struct delayed_work watchdog_work;
  144. struct sk_buff *cur_beacon;
  145. unsigned long last_update;
  146. u16 interval;
  147. u8 period;
  148. };
  149. enum zd_device_flags {
  150. ZD_DEVICE_RUNNING,
  151. };
  152. #define ZD_MAC_STATS_BUFFER_SIZE 16
  153. #define ZD_MAC_MAX_ACK_WAITERS 50
  154. struct zd_mac {
  155. struct zd_chip chip;
  156. spinlock_t lock;
  157. spinlock_t intr_lock;
  158. struct ieee80211_hw *hw;
  159. struct ieee80211_vif *vif;
  160. struct housekeeping housekeeping;
  161. struct beacon beacon;
  162. struct work_struct set_rts_cts_work;
  163. struct work_struct process_intr;
  164. struct zd_mc_hash multicast_hash;
  165. u8 intr_buffer[USB_MAX_EP_INT_BUFFER];
  166. u8 regdomain;
  167. u8 default_regdomain;
  168. u8 channel;
  169. int type;
  170. int associated;
  171. unsigned long flags;
  172. struct sk_buff_head ack_wait_queue;
  173. struct ieee80211_channel channels[14];
  174. struct ieee80211_rate rates[12];
  175. struct ieee80211_supported_band band;
  176. /* Short preamble (used for RTS/CTS) */
  177. unsigned int short_preamble:1;
  178. /* whether to pass frames with CRC errors to stack */
  179. unsigned int pass_failed_fcs:1;
  180. /* whether to pass control frames to stack */
  181. unsigned int pass_ctrl:1;
  182. /* whether we have received a 802.11 ACK that is pending */
  183. unsigned int ack_pending:1;
  184. /* signal strength of the last 802.11 ACK received */
  185. int ack_signal;
  186. };
  187. #define ZD_REGDOMAIN_FCC 0x10
  188. #define ZD_REGDOMAIN_IC 0x20
  189. #define ZD_REGDOMAIN_ETSI 0x30
  190. #define ZD_REGDOMAIN_SPAIN 0x31
  191. #define ZD_REGDOMAIN_FRANCE 0x32
  192. #define ZD_REGDOMAIN_JAPAN_2 0x40
  193. #define ZD_REGDOMAIN_JAPAN 0x41
  194. #define ZD_REGDOMAIN_JAPAN_3 0x49
  195. enum {
  196. MIN_CHANNEL24 = 1,
  197. MAX_CHANNEL24 = 14,
  198. };
  199. #define ZD_PLCP_SERVICE_LENGTH_EXTENSION 0x80
  200. struct ofdm_plcp_header {
  201. u8 prefix[3];
  202. __le16 service;
  203. } __packed;
  204. static inline u8 zd_ofdm_plcp_header_rate(const struct ofdm_plcp_header *header)
  205. {
  206. return header->prefix[0] & 0xf;
  207. }
  208. /* The following defines give the encoding of the 4-bit rate field in the
  209. * OFDM (802.11a/802.11g) PLCP header. Notify that these values are used to
  210. * define the zd-rate values for OFDM.
  211. *
  212. * See the struct zd_ctrlset definition in zd_mac.h.
  213. */
  214. #define ZD_OFDM_PLCP_RATE_6M 0xb
  215. #define ZD_OFDM_PLCP_RATE_9M 0xf
  216. #define ZD_OFDM_PLCP_RATE_12M 0xa
  217. #define ZD_OFDM_PLCP_RATE_18M 0xe
  218. #define ZD_OFDM_PLCP_RATE_24M 0x9
  219. #define ZD_OFDM_PLCP_RATE_36M 0xd
  220. #define ZD_OFDM_PLCP_RATE_48M 0x8
  221. #define ZD_OFDM_PLCP_RATE_54M 0xc
  222. struct cck_plcp_header {
  223. u8 signal;
  224. u8 service;
  225. __le16 length;
  226. __le16 crc16;
  227. } __packed;
  228. static inline u8 zd_cck_plcp_header_signal(const struct cck_plcp_header *header)
  229. {
  230. return header->signal;
  231. }
  232. /* These defines give the encodings of the signal field in the 802.11b PLCP
  233. * header. The signal field gives the bit rate of the following packet. Even
  234. * if technically wrong we use CCK here also for the 1 MBit/s and 2 MBit/s
  235. * rate to stay consistent with Zydas and our use of the term.
  236. *
  237. * Notify that these values are *not* used in the zd-rates.
  238. */
  239. #define ZD_CCK_PLCP_SIGNAL_1M 0x0a
  240. #define ZD_CCK_PLCP_SIGNAL_2M 0x14
  241. #define ZD_CCK_PLCP_SIGNAL_5M5 0x37
  242. #define ZD_CCK_PLCP_SIGNAL_11M 0x6e
  243. static inline struct zd_mac *zd_hw_mac(struct ieee80211_hw *hw)
  244. {
  245. return hw->priv;
  246. }
  247. static inline struct zd_mac *zd_chip_to_mac(struct zd_chip *chip)
  248. {
  249. return container_of(chip, struct zd_mac, chip);
  250. }
  251. static inline struct zd_mac *zd_usb_to_mac(struct zd_usb *usb)
  252. {
  253. return zd_chip_to_mac(zd_usb_to_chip(usb));
  254. }
  255. static inline u8 *zd_mac_get_perm_addr(struct zd_mac *mac)
  256. {
  257. return mac->hw->wiphy->perm_addr;
  258. }
  259. #define zd_mac_dev(mac) (zd_chip_dev(&(mac)->chip))
  260. struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf);
  261. void zd_mac_clear(struct zd_mac *mac);
  262. int zd_mac_preinit_hw(struct ieee80211_hw *hw);
  263. int zd_mac_init_hw(struct ieee80211_hw *hw);
  264. int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length);
  265. void zd_mac_tx_failed(struct urb *urb);
  266. void zd_mac_tx_to_dev(struct sk_buff *skb, int error);
  267. int zd_op_start(struct ieee80211_hw *hw);
  268. void zd_op_stop(struct ieee80211_hw *hw);
  269. int zd_restore_settings(struct zd_mac *mac);
  270. #ifdef DEBUG
  271. void zd_dump_rx_status(const struct rx_status *status);
  272. #else
  273. #define zd_dump_rx_status(status)
  274. #endif /* DEBUG */
  275. #endif /* _ZD_MAC_H */