zd_mac.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. #include "zd_ieee80211.h"
  26. struct zd_ctrlset {
  27. u8 modulation;
  28. __le16 tx_length;
  29. u8 control;
  30. /* stores only the difference to tx_length on ZD1211B */
  31. __le16 packet_length;
  32. __le16 current_length;
  33. u8 service;
  34. __le16 next_frame_length;
  35. } __attribute__((packed));
  36. #define ZD_CS_RESERVED_SIZE 25
  37. /* The field modulation of struct zd_ctrlset controls the bit rate, the use
  38. * of short or long preambles in 802.11b (CCK mode) or the use of 802.11a or
  39. * 802.11g in OFDM mode.
  40. *
  41. * The term zd-rate is used for the combination of the modulation type flag
  42. * and the "pure" rate value.
  43. */
  44. #define ZD_PURE_RATE_MASK 0x0f
  45. #define ZD_MODULATION_TYPE_MASK 0x10
  46. #define ZD_RATE_MASK (ZD_PURE_RATE_MASK|ZD_MODULATION_TYPE_MASK)
  47. #define ZD_PURE_RATE(modulation) ((modulation) & ZD_PURE_RATE_MASK)
  48. #define ZD_MODULATION_TYPE(modulation) ((modulation) & ZD_MODULATION_TYPE_MASK)
  49. #define ZD_RATE(modulation) ((modulation) & ZD_RATE_MASK)
  50. /* The two possible modulation types. Notify that 802.11b doesn't use the CCK
  51. * codeing for the 1 and 2 MBit/s rate. We stay with the term here to remain
  52. * consistent with uses the term at other places.
  53. */
  54. #define ZD_CCK 0x00
  55. #define ZD_OFDM 0x10
  56. /* The ZD1211 firmware uses proprietary encodings of the 802.11b (CCK) rates.
  57. * For OFDM the PLCP rate encodings are used. We combine these "pure" rates
  58. * with the modulation type flag and call the resulting values zd-rates.
  59. */
  60. #define ZD_CCK_RATE_1M (ZD_CCK|0x00)
  61. #define ZD_CCK_RATE_2M (ZD_CCK|0x01)
  62. #define ZD_CCK_RATE_5_5M (ZD_CCK|0x02)
  63. #define ZD_CCK_RATE_11M (ZD_CCK|0x03)
  64. #define ZD_OFDM_RATE_6M (ZD_OFDM|ZD_OFDM_PLCP_RATE_6M)
  65. #define ZD_OFDM_RATE_9M (ZD_OFDM|ZD_OFDM_PLCP_RATE_9M)
  66. #define ZD_OFDM_RATE_12M (ZD_OFDM|ZD_OFDM_PLCP_RATE_12M)
  67. #define ZD_OFDM_RATE_18M (ZD_OFDM|ZD_OFDM_PLCP_RATE_18M)
  68. #define ZD_OFDM_RATE_24M (ZD_OFDM|ZD_OFDM_PLCP_RATE_24M)
  69. #define ZD_OFDM_RATE_36M (ZD_OFDM|ZD_OFDM_PLCP_RATE_36M)
  70. #define ZD_OFDM_RATE_48M (ZD_OFDM|ZD_OFDM_PLCP_RATE_48M)
  71. #define ZD_OFDM_RATE_54M (ZD_OFDM|ZD_OFDM_PLCP_RATE_54M)
  72. /* The bit 5 of the zd_ctrlset modulation field controls the preamble in CCK
  73. * mode or the 802.11a/802.11g selection in OFDM mode.
  74. */
  75. #define ZD_CCK_PREA_LONG 0x00
  76. #define ZD_CCK_PREA_SHORT 0x20
  77. #define ZD_OFDM_MODE_11G 0x00
  78. #define ZD_OFDM_MODE_11A 0x20
  79. /* zd_ctrlset control field */
  80. #define ZD_CS_NEED_RANDOM_BACKOFF 0x01
  81. #define ZD_CS_MULTICAST 0x02
  82. #define ZD_CS_FRAME_TYPE_MASK 0x0c
  83. #define ZD_CS_DATA_FRAME 0x00
  84. #define ZD_CS_PS_POLL_FRAME 0x04
  85. #define ZD_CS_MANAGEMENT_FRAME 0x08
  86. #define ZD_CS_NO_SEQUENCE_CTL_FRAME 0x0c
  87. #define ZD_CS_WAKE_DESTINATION 0x10
  88. #define ZD_CS_RTS 0x20
  89. #define ZD_CS_ENCRYPT 0x40
  90. #define ZD_CS_SELF_CTS 0x80
  91. /* Incoming frames are prepended by a PLCP header */
  92. #define ZD_PLCP_HEADER_SIZE 5
  93. struct rx_length_info {
  94. __le16 length[3];
  95. __le16 tag;
  96. } __attribute__((packed));
  97. #define RX_LENGTH_INFO_TAG 0x697e
  98. struct rx_status {
  99. u8 signal_quality_cck;
  100. /* rssi */
  101. u8 signal_strength;
  102. u8 signal_quality_ofdm;
  103. u8 decryption_type;
  104. u8 frame_status;
  105. } __attribute__((packed));
  106. /* rx_status field decryption_type */
  107. #define ZD_RX_NO_WEP 0
  108. #define ZD_RX_WEP64 1
  109. #define ZD_RX_TKIP 2
  110. #define ZD_RX_AES 4
  111. #define ZD_RX_WEP128 5
  112. #define ZD_RX_WEP256 6
  113. /* rx_status field frame_status */
  114. #define ZD_RX_FRAME_MODULATION_MASK 0x01
  115. #define ZD_RX_CCK 0x00
  116. #define ZD_RX_OFDM 0x01
  117. #define ZD_RX_TIMEOUT_ERROR 0x02
  118. #define ZD_RX_FIFO_OVERRUN_ERROR 0x04
  119. #define ZD_RX_DECRYPTION_ERROR 0x08
  120. #define ZD_RX_CRC32_ERROR 0x10
  121. #define ZD_RX_NO_ADDR1_MATCH_ERROR 0x20
  122. #define ZD_RX_CRC16_ERROR 0x40
  123. #define ZD_RX_ERROR 0x80
  124. enum mac_flags {
  125. MAC_FIXED_CHANNEL = 0x01,
  126. };
  127. struct housekeeping {
  128. struct delayed_work link_led_work;
  129. };
  130. /**
  131. * struct zd_tx_skb_control_block - control block for tx skbuffs
  132. * @control: &struct ieee80211_tx_control pointer
  133. * @context: context pointer
  134. *
  135. * This structure is used to fill the cb field in an &sk_buff to transmit.
  136. * The control field is NULL, if there is no requirement from the mac80211
  137. * stack to report about the packet ACK. This is the case if the flag
  138. * IEEE80211_TXCTL_NO_ACK is not set in &struct ieee80211_tx_control.
  139. */
  140. struct zd_tx_skb_control_block {
  141. struct ieee80211_tx_control *control;
  142. struct ieee80211_hw *hw;
  143. void *context;
  144. };
  145. #define ZD_MAC_STATS_BUFFER_SIZE 16
  146. #define ZD_MAC_MAX_ACK_WAITERS 10
  147. struct zd_mac {
  148. struct zd_chip chip;
  149. spinlock_t lock;
  150. spinlock_t intr_lock;
  151. struct ieee80211_hw *hw;
  152. struct housekeeping housekeeping;
  153. struct work_struct set_multicast_hash_work;
  154. struct work_struct set_rts_cts_work;
  155. struct work_struct set_rx_filter_work;
  156. struct work_struct process_intr;
  157. struct zd_mc_hash multicast_hash;
  158. u8 intr_buffer[USB_MAX_EP_INT_BUFFER];
  159. u8 regdomain;
  160. u8 default_regdomain;
  161. int type;
  162. int associated;
  163. struct sk_buff_head ack_wait_queue;
  164. struct ieee80211_channel channels[14];
  165. struct ieee80211_rate rates[12];
  166. struct ieee80211_supported_band band;
  167. /* Short preamble (used for RTS/CTS) */
  168. unsigned int short_preamble:1;
  169. /* flags to indicate update in progress */
  170. unsigned int updating_rts_rate:1;
  171. /* whether to pass frames with CRC errors to stack */
  172. unsigned int pass_failed_fcs:1;
  173. /* whether to pass control frames to stack */
  174. unsigned int pass_ctrl:1;
  175. };
  176. static inline struct zd_mac *zd_hw_mac(struct ieee80211_hw *hw)
  177. {
  178. return hw->priv;
  179. }
  180. static inline struct zd_mac *zd_chip_to_mac(struct zd_chip *chip)
  181. {
  182. return container_of(chip, struct zd_mac, chip);
  183. }
  184. static inline struct zd_mac *zd_usb_to_mac(struct zd_usb *usb)
  185. {
  186. return zd_chip_to_mac(zd_usb_to_chip(usb));
  187. }
  188. static inline u8 *zd_mac_get_perm_addr(struct zd_mac *mac)
  189. {
  190. return mac->hw->wiphy->perm_addr;
  191. }
  192. #define zd_mac_dev(mac) (zd_chip_dev(&(mac)->chip))
  193. struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf);
  194. void zd_mac_clear(struct zd_mac *mac);
  195. int zd_mac_preinit_hw(struct ieee80211_hw *hw);
  196. int zd_mac_init_hw(struct ieee80211_hw *hw);
  197. int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length);
  198. void zd_mac_tx_failed(struct ieee80211_hw *hw);
  199. void zd_mac_tx_to_dev(struct sk_buff *skb, int error);
  200. #ifdef DEBUG
  201. void zd_dump_rx_status(const struct rx_status *status);
  202. #else
  203. #define zd_dump_rx_status(status)
  204. #endif /* DEBUG */
  205. #endif /* _ZD_MAC_H */