zd_mac.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 <net/ieee80211.h>
  22. #include <net/ieee80211softmac.h>
  23. #include "zd_chip.h"
  24. #include "zd_netdev.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. } __attribute__((packed));
  35. #define ZD_CS_RESERVED_SIZE 25
  36. /* zd_crtlset field modulation */
  37. #define ZD_CS_RATE_MASK 0x0f
  38. #define ZD_CS_TYPE_MASK 0x10
  39. #define ZD_CS_RATE(modulation) ((modulation) & ZD_CS_RATE_MASK)
  40. #define ZD_CS_TYPE(modulation) ((modulation) & ZD_CS_TYPE_MASK)
  41. #define ZD_CS_CCK 0x00
  42. #define ZD_CS_OFDM 0x10
  43. #define ZD_CS_CCK_RATE_1M 0x00
  44. #define ZD_CS_CCK_RATE_2M 0x01
  45. #define ZD_CS_CCK_RATE_5_5M 0x02
  46. #define ZD_CS_CCK_RATE_11M 0x03
  47. /* The rates for OFDM are encoded as in the PLCP header. Use ZD_OFDM_RATE_*.
  48. */
  49. /* bit 5 is preamble (when in CCK mode), or a/g selection (when in OFDM mode) */
  50. #define ZD_CS_CCK_PREA_LONG 0x00
  51. #define ZD_CS_CCK_PREA_SHORT 0x20
  52. #define ZD_CS_OFDM_MODE_11G 0x00
  53. #define ZD_CS_OFDM_MODE_11A 0x20
  54. /* zd_ctrlset control field */
  55. #define ZD_CS_NEED_RANDOM_BACKOFF 0x01
  56. #define ZD_CS_MULTICAST 0x02
  57. #define ZD_CS_FRAME_TYPE_MASK 0x0c
  58. #define ZD_CS_DATA_FRAME 0x00
  59. #define ZD_CS_PS_POLL_FRAME 0x04
  60. #define ZD_CS_MANAGEMENT_FRAME 0x08
  61. #define ZD_CS_NO_SEQUENCE_CTL_FRAME 0x0c
  62. #define ZD_CS_WAKE_DESTINATION 0x10
  63. #define ZD_CS_RTS 0x20
  64. #define ZD_CS_ENCRYPT 0x40
  65. #define ZD_CS_SELF_CTS 0x80
  66. /* Incoming frames are prepended by a PLCP header */
  67. #define ZD_PLCP_HEADER_SIZE 5
  68. struct rx_length_info {
  69. __le16 length[3];
  70. __le16 tag;
  71. };
  72. #define RX_LENGTH_INFO_TAG 0x697e
  73. struct rx_status {
  74. u8 signal_quality_cck;
  75. /* rssi */
  76. u8 signal_strength;
  77. u8 signal_quality_ofdm;
  78. u8 decryption_type;
  79. u8 frame_status;
  80. };
  81. /* rx_status field decryption_type */
  82. #define ZD_RX_NO_WEP 0
  83. #define ZD_RX_WEP64 1
  84. #define ZD_RX_TKIP 2
  85. #define ZD_RX_AES 4
  86. #define ZD_RX_WEP128 5
  87. #define ZD_RX_WEP256 6
  88. /* rx_status field frame_status */
  89. #define ZD_RX_FRAME_MODULATION_MASK 0x01
  90. #define ZD_RX_CCK 0x00
  91. #define ZD_RX_OFDM 0x01
  92. #define ZD_RX_TIMEOUT_ERROR 0x02
  93. #define ZD_RX_FIFO_OVERRUN_ERROR 0x04
  94. #define ZD_RX_DECRYPTION_ERROR 0x08
  95. #define ZD_RX_CRC32_ERROR 0x10
  96. #define ZD_RX_NO_ADDR1_MATCH_ERROR 0x20
  97. #define ZD_RX_CRC16_ERROR 0x40
  98. #define ZD_RX_ERROR 0x80
  99. enum mac_flags {
  100. MAC_FIXED_CHANNEL = 0x01,
  101. };
  102. struct housekeeping {
  103. struct work_struct link_led_work;
  104. };
  105. #define ZD_MAC_STATS_BUFFER_SIZE 16
  106. struct zd_mac {
  107. struct zd_chip chip;
  108. spinlock_t lock;
  109. struct net_device *netdev;
  110. /* Unlocked reading possible */
  111. struct iw_statistics iw_stats;
  112. struct housekeeping housekeeping;
  113. unsigned int stats_count;
  114. u8 qual_buffer[ZD_MAC_STATS_BUFFER_SIZE];
  115. u8 rssi_buffer[ZD_MAC_STATS_BUFFER_SIZE];
  116. u8 regdomain;
  117. u8 default_regdomain;
  118. u8 requested_channel;
  119. };
  120. static inline struct ieee80211_device *zd_mac_to_ieee80211(struct zd_mac *mac)
  121. {
  122. return zd_netdev_ieee80211(mac->netdev);
  123. }
  124. static inline struct zd_mac *zd_netdev_mac(struct net_device *netdev)
  125. {
  126. return ieee80211softmac_priv(netdev);
  127. }
  128. static inline struct zd_mac *zd_chip_to_mac(struct zd_chip *chip)
  129. {
  130. return container_of(chip, struct zd_mac, chip);
  131. }
  132. static inline struct zd_mac *zd_usb_to_mac(struct zd_usb *usb)
  133. {
  134. return zd_chip_to_mac(zd_usb_to_chip(usb));
  135. }
  136. #define zd_mac_dev(mac) (zd_chip_dev(&(mac)->chip))
  137. int zd_mac_init(struct zd_mac *mac,
  138. struct net_device *netdev,
  139. struct usb_interface *intf);
  140. void zd_mac_clear(struct zd_mac *mac);
  141. int zd_mac_init_hw(struct zd_mac *mac, u8 device_type);
  142. int zd_mac_open(struct net_device *netdev);
  143. int zd_mac_stop(struct net_device *netdev);
  144. int zd_mac_set_mac_address(struct net_device *dev, void *p);
  145. int zd_mac_rx(struct zd_mac *mac, const u8 *buffer, unsigned int length);
  146. int zd_mac_set_regdomain(struct zd_mac *zd_mac, u8 regdomain);
  147. u8 zd_mac_get_regdomain(struct zd_mac *zd_mac);
  148. int zd_mac_request_channel(struct zd_mac *mac, u8 channel);
  149. int zd_mac_get_channel(struct zd_mac *mac, u8 *channel, u8 *flags);
  150. int zd_mac_set_mode(struct zd_mac *mac, u32 mode);
  151. int zd_mac_get_mode(struct zd_mac *mac, u32 *mode);
  152. int zd_mac_get_range(struct zd_mac *mac, struct iw_range *range);
  153. struct iw_statistics *zd_mac_get_wireless_stats(struct net_device *ndev);
  154. #ifdef DEBUG
  155. void zd_dump_rx_status(const struct rx_status *status);
  156. #else
  157. #define zd_dump_rx_status(status)
  158. #endif /* DEBUG */
  159. #endif /* _ZD_MAC_H */