zd_mac.h 7.0 KB

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