zd_mac.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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/wireless.h>
  20. #include <linux/kernel.h>
  21. #include <linux/workqueue.h>
  22. #include <net/ieee80211.h>
  23. #include <net/ieee80211softmac.h>
  24. #include "zd_chip.h"
  25. #include "zd_netdev.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. struct housekeeping {
  125. struct delayed_work link_led_work;
  126. };
  127. #define ZD_MAC_STATS_BUFFER_SIZE 16
  128. struct zd_mac {
  129. struct zd_chip chip;
  130. spinlock_t lock;
  131. struct net_device *netdev;
  132. /* Unlocked reading possible */
  133. struct iw_statistics iw_stats;
  134. struct housekeeping housekeeping;
  135. struct work_struct set_multicast_hash_work;
  136. struct zd_mc_hash multicast_hash;
  137. struct delayed_work set_rts_cts_work;
  138. struct delayed_work set_basic_rates_work;
  139. struct tasklet_struct rx_tasklet;
  140. struct sk_buff_head rx_queue;
  141. unsigned int stats_count;
  142. u8 qual_buffer[ZD_MAC_STATS_BUFFER_SIZE];
  143. u8 rssi_buffer[ZD_MAC_STATS_BUFFER_SIZE];
  144. u8 regdomain;
  145. u8 default_regdomain;
  146. u8 requested_channel;
  147. /* A bitpattern of cr_rates */
  148. u16 basic_rates;
  149. /* A zd_rate */
  150. u8 rts_rate;
  151. /* Short preamble (used for RTS/CTS) */
  152. unsigned int short_preamble:1;
  153. /* flags to indicate update in progress */
  154. unsigned int updating_rts_rate:1;
  155. unsigned int updating_basic_rates:1;
  156. };
  157. static inline struct ieee80211_device *zd_mac_to_ieee80211(struct zd_mac *mac)
  158. {
  159. return zd_netdev_ieee80211(mac->netdev);
  160. }
  161. static inline struct zd_mac *zd_netdev_mac(struct net_device *netdev)
  162. {
  163. return ieee80211softmac_priv(netdev);
  164. }
  165. static inline struct zd_mac *zd_chip_to_mac(struct zd_chip *chip)
  166. {
  167. return container_of(chip, struct zd_mac, chip);
  168. }
  169. static inline struct zd_mac *zd_usb_to_mac(struct zd_usb *usb)
  170. {
  171. return zd_chip_to_mac(zd_usb_to_chip(usb));
  172. }
  173. #define zd_mac_dev(mac) (zd_chip_dev(&(mac)->chip))
  174. int zd_mac_init(struct zd_mac *mac,
  175. struct net_device *netdev,
  176. struct usb_interface *intf);
  177. void zd_mac_clear(struct zd_mac *mac);
  178. int zd_mac_preinit_hw(struct zd_mac *mac);
  179. int zd_mac_init_hw(struct zd_mac *mac);
  180. int zd_mac_open(struct net_device *netdev);
  181. int zd_mac_stop(struct net_device *netdev);
  182. int zd_mac_set_mac_address(struct net_device *dev, void *p);
  183. void zd_mac_set_multicast_list(struct net_device *netdev);
  184. int zd_mac_rx_irq(struct zd_mac *mac, const u8 *buffer, unsigned int length);
  185. int zd_mac_set_regdomain(struct zd_mac *zd_mac, u8 regdomain);
  186. u8 zd_mac_get_regdomain(struct zd_mac *zd_mac);
  187. int zd_mac_request_channel(struct zd_mac *mac, u8 channel);
  188. u8 zd_mac_get_channel(struct zd_mac *mac);
  189. int zd_mac_set_mode(struct zd_mac *mac, u32 mode);
  190. int zd_mac_get_mode(struct zd_mac *mac, u32 *mode);
  191. int zd_mac_get_range(struct zd_mac *mac, struct iw_range *range);
  192. struct iw_statistics *zd_mac_get_wireless_stats(struct net_device *ndev);
  193. #ifdef DEBUG
  194. void zd_dump_rx_status(const struct rx_status *status);
  195. #else
  196. #define zd_dump_rx_status(status)
  197. #endif /* DEBUG */
  198. #endif /* _ZD_MAC_H */