Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 1 | /* zd_mac.h |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 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 | |
| 18 | #ifndef _ZD_MAC_H |
| 19 | #define _ZD_MAC_H |
| 20 | |
| 21 | #include <linux/wireless.h> |
| 22 | #include <linux/kernel.h> |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 23 | #include <linux/workqueue.h> |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 24 | #include <net/ieee80211.h> |
| 25 | #include <net/ieee80211softmac.h> |
| 26 | |
| 27 | #include "zd_chip.h" |
| 28 | #include "zd_netdev.h" |
| 29 | |
| 30 | struct zd_ctrlset { |
| 31 | u8 modulation; |
| 32 | __le16 tx_length; |
| 33 | u8 control; |
| 34 | /* stores only the difference to tx_length on ZD1211B */ |
| 35 | __le16 packet_length; |
| 36 | __le16 current_length; |
| 37 | u8 service; |
| 38 | __le16 next_frame_length; |
| 39 | } __attribute__((packed)); |
| 40 | |
| 41 | #define ZD_CS_RESERVED_SIZE 25 |
| 42 | |
| 43 | /* zd_crtlset field modulation */ |
| 44 | #define ZD_CS_RATE_MASK 0x0f |
| 45 | #define ZD_CS_TYPE_MASK 0x10 |
| 46 | #define ZD_CS_RATE(modulation) ((modulation) & ZD_CS_RATE_MASK) |
| 47 | #define ZD_CS_TYPE(modulation) ((modulation) & ZD_CS_TYPE_MASK) |
| 48 | |
| 49 | #define ZD_CS_CCK 0x00 |
| 50 | #define ZD_CS_OFDM 0x10 |
| 51 | |
Daniel Drake | b1cd8416 | 2006-11-22 00:06:38 +0000 | [diff] [blame] | 52 | /* These are referred to as zd_rates */ |
| 53 | #define ZD_CCK_RATE_1M 0x00 |
| 54 | #define ZD_CCK_RATE_2M 0x01 |
| 55 | #define ZD_CCK_RATE_5_5M 0x02 |
| 56 | #define ZD_CCK_RATE_11M 0x03 |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 57 | /* The rates for OFDM are encoded as in the PLCP header. Use ZD_OFDM_RATE_*. |
| 58 | */ |
| 59 | |
| 60 | /* bit 5 is preamble (when in CCK mode), or a/g selection (when in OFDM mode) */ |
| 61 | #define ZD_CS_CCK_PREA_LONG 0x00 |
| 62 | #define ZD_CS_CCK_PREA_SHORT 0x20 |
| 63 | #define ZD_CS_OFDM_MODE_11G 0x00 |
| 64 | #define ZD_CS_OFDM_MODE_11A 0x20 |
| 65 | |
| 66 | /* zd_ctrlset control field */ |
| 67 | #define ZD_CS_NEED_RANDOM_BACKOFF 0x01 |
| 68 | #define ZD_CS_MULTICAST 0x02 |
| 69 | |
| 70 | #define ZD_CS_FRAME_TYPE_MASK 0x0c |
| 71 | #define ZD_CS_DATA_FRAME 0x00 |
| 72 | #define ZD_CS_PS_POLL_FRAME 0x04 |
| 73 | #define ZD_CS_MANAGEMENT_FRAME 0x08 |
| 74 | #define ZD_CS_NO_SEQUENCE_CTL_FRAME 0x0c |
| 75 | |
| 76 | #define ZD_CS_WAKE_DESTINATION 0x10 |
| 77 | #define ZD_CS_RTS 0x20 |
| 78 | #define ZD_CS_ENCRYPT 0x40 |
| 79 | #define ZD_CS_SELF_CTS 0x80 |
| 80 | |
| 81 | /* Incoming frames are prepended by a PLCP header */ |
| 82 | #define ZD_PLCP_HEADER_SIZE 5 |
| 83 | |
| 84 | struct rx_length_info { |
| 85 | __le16 length[3]; |
| 86 | __le16 tag; |
John W. Linville | a88556a | 2006-11-28 14:16:37 -0500 | [diff] [blame] | 87 | } __attribute__((packed)); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 88 | |
| 89 | #define RX_LENGTH_INFO_TAG 0x697e |
| 90 | |
| 91 | struct rx_status { |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 92 | u8 signal_quality_cck; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 93 | /* rssi */ |
| 94 | u8 signal_strength; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 95 | u8 signal_quality_ofdm; |
| 96 | u8 decryption_type; |
| 97 | u8 frame_status; |
John W. Linville | a88556a | 2006-11-28 14:16:37 -0500 | [diff] [blame] | 98 | } __attribute__((packed)); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 99 | |
| 100 | /* rx_status field decryption_type */ |
| 101 | #define ZD_RX_NO_WEP 0 |
| 102 | #define ZD_RX_WEP64 1 |
| 103 | #define ZD_RX_TKIP 2 |
| 104 | #define ZD_RX_AES 4 |
| 105 | #define ZD_RX_WEP128 5 |
| 106 | #define ZD_RX_WEP256 6 |
| 107 | |
| 108 | /* rx_status field frame_status */ |
| 109 | #define ZD_RX_FRAME_MODULATION_MASK 0x01 |
| 110 | #define ZD_RX_CCK 0x00 |
| 111 | #define ZD_RX_OFDM 0x01 |
| 112 | |
| 113 | #define ZD_RX_TIMEOUT_ERROR 0x02 |
| 114 | #define ZD_RX_FIFO_OVERRUN_ERROR 0x04 |
| 115 | #define ZD_RX_DECRYPTION_ERROR 0x08 |
| 116 | #define ZD_RX_CRC32_ERROR 0x10 |
| 117 | #define ZD_RX_NO_ADDR1_MATCH_ERROR 0x20 |
| 118 | #define ZD_RX_CRC16_ERROR 0x40 |
| 119 | #define ZD_RX_ERROR 0x80 |
| 120 | |
Ulrich Kunitz | 583afd1e | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 121 | struct housekeeping { |
| 122 | struct work_struct link_led_work; |
| 123 | }; |
| 124 | |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 125 | #define ZD_MAC_STATS_BUFFER_SIZE 16 |
| 126 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 127 | struct zd_mac { |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 128 | struct zd_chip chip; |
| 129 | spinlock_t lock; |
Ulrich Kunitz | c48cf12 | 2006-08-12 18:00:17 +0100 | [diff] [blame] | 130 | struct net_device *netdev; |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 131 | |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 132 | /* Unlocked reading possible */ |
| 133 | struct iw_statistics iw_stats; |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 134 | |
Ulrich Kunitz | 583afd1e | 2006-09-13 02:42:38 +0100 | [diff] [blame] | 135 | struct housekeeping housekeeping; |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame^] | 136 | struct work_struct set_multicast_hash_work; |
| 137 | struct zd_mc_hash multicast_hash; |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 138 | struct work_struct set_rts_cts_work; |
| 139 | struct work_struct set_basic_rates_work; |
| 140 | |
Ulrich Kunitz | db888ae | 2006-08-29 23:50:29 +0100 | [diff] [blame] | 141 | unsigned int stats_count; |
| 142 | u8 qual_buffer[ZD_MAC_STATS_BUFFER_SIZE]; |
| 143 | u8 rssi_buffer[ZD_MAC_STATS_BUFFER_SIZE]; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 144 | u8 regdomain; |
| 145 | u8 default_regdomain; |
| 146 | u8 requested_channel; |
Daniel Drake | b1382ed | 2006-11-22 00:06:48 +0000 | [diff] [blame] | 147 | |
| 148 | /* A bitpattern of cr_rates */ |
| 149 | u16 basic_rates; |
| 150 | |
| 151 | /* A zd_rate */ |
| 152 | u8 rts_rate; |
| 153 | |
| 154 | /* Short preamble (used for RTS/CTS) */ |
| 155 | unsigned int short_preamble:1; |
| 156 | |
| 157 | /* flags to indicate update in progress */ |
| 158 | unsigned int updating_rts_rate:1; |
| 159 | unsigned int updating_basic_rates:1; |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | static inline struct ieee80211_device *zd_mac_to_ieee80211(struct zd_mac *mac) |
| 163 | { |
| 164 | return zd_netdev_ieee80211(mac->netdev); |
| 165 | } |
| 166 | |
| 167 | static inline struct zd_mac *zd_netdev_mac(struct net_device *netdev) |
| 168 | { |
| 169 | return ieee80211softmac_priv(netdev); |
| 170 | } |
| 171 | |
| 172 | static inline struct zd_mac *zd_chip_to_mac(struct zd_chip *chip) |
| 173 | { |
| 174 | return container_of(chip, struct zd_mac, chip); |
| 175 | } |
| 176 | |
| 177 | static inline struct zd_mac *zd_usb_to_mac(struct zd_usb *usb) |
| 178 | { |
| 179 | return zd_chip_to_mac(zd_usb_to_chip(usb)); |
| 180 | } |
| 181 | |
| 182 | #define zd_mac_dev(mac) (zd_chip_dev(&(mac)->chip)) |
| 183 | |
| 184 | int zd_mac_init(struct zd_mac *mac, |
| 185 | struct net_device *netdev, |
| 186 | struct usb_interface *intf); |
| 187 | void zd_mac_clear(struct zd_mac *mac); |
| 188 | |
| 189 | int zd_mac_init_hw(struct zd_mac *mac, u8 device_type); |
| 190 | |
| 191 | int zd_mac_open(struct net_device *netdev); |
| 192 | int zd_mac_stop(struct net_device *netdev); |
| 193 | int zd_mac_set_mac_address(struct net_device *dev, void *p); |
Ulrich Kunitz | 9cdac96 | 2006-12-01 00:58:07 +0000 | [diff] [blame^] | 194 | void zd_mac_set_multicast_list(struct net_device *netdev); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 195 | |
| 196 | int zd_mac_rx(struct zd_mac *mac, const u8 *buffer, unsigned int length); |
| 197 | |
| 198 | int zd_mac_set_regdomain(struct zd_mac *zd_mac, u8 regdomain); |
| 199 | u8 zd_mac_get_regdomain(struct zd_mac *zd_mac); |
| 200 | |
| 201 | int zd_mac_request_channel(struct zd_mac *mac, u8 channel); |
Daniel Drake | 84bc715 | 2006-11-22 00:05:30 +0000 | [diff] [blame] | 202 | u8 zd_mac_get_channel(struct zd_mac *mac); |
Daniel Drake | e85d091 | 2006-06-02 17:11:32 +0100 | [diff] [blame] | 203 | |
| 204 | int zd_mac_set_mode(struct zd_mac *mac, u32 mode); |
| 205 | int zd_mac_get_mode(struct zd_mac *mac, u32 *mode); |
| 206 | |
| 207 | int zd_mac_get_range(struct zd_mac *mac, struct iw_range *range); |
| 208 | |
| 209 | struct iw_statistics *zd_mac_get_wireless_stats(struct net_device *ndev); |
| 210 | |
| 211 | #ifdef DEBUG |
| 212 | void zd_dump_rx_status(const struct rx_status *status); |
| 213 | #else |
| 214 | #define zd_dump_rx_status(status) |
| 215 | #endif /* DEBUG */ |
| 216 | |
| 217 | #endif /* _ZD_MAC_H */ |