]>
Commit | Line | Data |
---|---|---|
92b96797 FB |
1 | /* |
2 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
92b96797 FB |
15 | * |
16 | * File: rxtx.c | |
17 | * | |
18 | * Purpose: handle WMAC/802.3/802.11 rx & tx functions | |
19 | * | |
20 | * Author: Lyndon Chen | |
21 | * | |
22 | * Date: May 20, 2003 | |
23 | * | |
24 | * Functions: | |
9ec7f2d8 | 25 | * vnt_generate_tx_parameter - Generate tx dma required parameter. |
435ae3be | 26 | * vnt_get_duration_le - get tx data required duration |
f2aabee6 | 27 | * vnt_get_rtscts_duration_le- get rtx/cts required duration |
aadf7d13 | 28 | * vnt_get_rtscts_rsvtime_le- get rts/cts reserved time |
3815a27b | 29 | * vnt_get_rsvtime- get frame reserved time |
4f31668f | 30 | * vnt_fill_cts_head- fulfill CTS ctl header |
92b96797 FB |
31 | * |
32 | * Revision History: | |
33 | * | |
34 | */ | |
35 | ||
ccc103f5 | 36 | #include <linux/etherdevice.h> |
92b96797 | 37 | #include "device.h" |
92b96797 | 38 | #include "rxtx.h" |
92b96797 | 39 | #include "card.h" |
92b96797 | 40 | #include "mac.h" |
92b96797 | 41 | #include "rf.h" |
92b96797 | 42 | #include "usbpipe.h" |
9d26d60f | 43 | |
1a4d4509 | 44 | static const u16 vnt_time_stampoff[2][MAX_RATE] = { |
943304b3 AKB |
45 | /* Long Preamble */ |
46 | {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, | |
47 | ||
48 | /* Short Preamble */ | |
49 | {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, | |
1a4d4509 | 50 | }; |
92b96797 | 51 | |
e3f31874 MP |
52 | static const u16 vnt_fb_opt0[2][5] = { |
53 | {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, /* fallback_rate0 */ | |
54 | {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, /* fallback_rate1 */ | |
55 | }; | |
56 | ||
2331ba42 MP |
57 | static const u16 vnt_fb_opt1[2][5] = { |
58 | {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, /* fallback_rate0 */ | |
73c4c6ee | 59 | {RATE_6M, RATE_6M, RATE_12M, RATE_12M, RATE_18M}, /* fallback_rate1 */ |
2331ba42 | 60 | }; |
92b96797 | 61 | |
92b96797 FB |
62 | #define RTSDUR_BB 0 |
63 | #define RTSDUR_BA 1 | |
64 | #define RTSDUR_AA 2 | |
65 | #define CTSDUR_BA 3 | |
66 | #define RTSDUR_BA_F0 4 | |
67 | #define RTSDUR_AA_F0 5 | |
68 | #define RTSDUR_BA_F1 6 | |
69 | #define RTSDUR_AA_F1 7 | |
70 | #define CTSDUR_BA_F0 8 | |
71 | #define CTSDUR_BA_F1 9 | |
72 | #define DATADUR_B 10 | |
73 | #define DATADUR_A 11 | |
74 | #define DATADUR_A_F0 12 | |
75 | #define DATADUR_A_F1 13 | |
76 | ||
aceaf018 | 77 | static struct vnt_usb_send_context |
a032b16c | 78 | *vnt_get_free_context(struct vnt_private *priv) |
92b96797 | 79 | { |
b89f3b94 | 80 | struct vnt_usb_send_context *context = NULL; |
d56131de | 81 | int ii; |
92b96797 | 82 | |
604631ff | 83 | dev_dbg(&priv->usb->dev, "%s\n", __func__); |
b89f3b94 | 84 | |
03b7e354 | 85 | for (ii = 0; ii < priv->num_tx_context; ii++) { |
f7e4a8f4 | 86 | if (!priv->tx_context[ii]) |
b89f3b94 MP |
87 | return NULL; |
88 | ||
f7e4a8f4 | 89 | context = priv->tx_context[ii]; |
5699c0f4 | 90 | if (!context->in_use) { |
30a05b39 MP |
91 | context->in_use = true; |
92 | memset(context->data, 0, | |
42aa03dc | 93 | MAX_TOTAL_SIZE_WITH_ALL_HEADERS); |
1622c8fc MP |
94 | |
95 | context->hdr = NULL; | |
96 | ||
b89f3b94 MP |
97 | return context; |
98 | } | |
99 | } | |
100 | ||
b914b494 | 101 | if (ii == priv->num_tx_context) { |
604631ff | 102 | dev_dbg(&priv->usb->dev, "%s No Free Tx Context\n", __func__); |
aceaf018 | 103 | |
b914b494 MP |
104 | ieee80211_stop_queues(priv->hw); |
105 | } | |
106 | ||
5c851383 | 107 | return NULL; |
92b96797 FB |
108 | } |
109 | ||
dab085b1 | 110 | static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate) |
f115e76a | 111 | { |
98e93fe5 | 112 | return cpu_to_le16(vnt_time_stampoff[priv->preamble_type % 2] |
f115e76a MP |
113 | [rate % MAX_RATE]); |
114 | } | |
115 | ||
3815a27b | 116 | static u32 vnt_get_rsvtime(struct vnt_private *priv, u8 pkt_type, |
a974fb37 | 117 | u32 frame_length, u16 rate, int need_ack) |
92b96797 | 118 | { |
3fd5620f | 119 | u32 data_time, ack_time; |
92b96797 | 120 | |
98e93fe5 | 121 | data_time = vnt_get_frame_time(priv->preamble_type, pkt_type, |
42aa03dc | 122 | frame_length, rate); |
92b96797 | 123 | |
3fd5620f | 124 | if (pkt_type == PK_TYPE_11B) |
98e93fe5 | 125 | ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type, |
42aa03dc | 126 | 14, (u16)priv->top_cck_basic_rate); |
3fd5620f | 127 | else |
98e93fe5 | 128 | ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type, |
42aa03dc | 129 | 14, (u16)priv->top_ofdm_basic_rate); |
3fd5620f MP |
130 | |
131 | if (need_ack) | |
ff5fee22 | 132 | return data_time + priv->sifs + ack_time; |
3fd5620f MP |
133 | |
134 | return data_time; | |
92b96797 FB |
135 | } |
136 | ||
2075f654 | 137 | static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type, |
a974fb37 | 138 | u32 frame_length, u16 rate, int need_ack) |
9c3806d5 | 139 | { |
3815a27b | 140 | return cpu_to_le16((u16)vnt_get_rsvtime(priv, pkt_type, |
9c3806d5 MP |
141 | frame_length, rate, need_ack)); |
142 | } | |
143 | ||
a974fb37 SB |
144 | static __le16 vnt_get_rtscts_rsvtime_le(struct vnt_private *priv, u8 rsv_type, |
145 | u8 pkt_type, u32 frame_length, | |
146 | u16 current_rate) | |
92b96797 | 147 | { |
342e2e20 | 148 | u32 rrv_time, rts_time, cts_time, ack_time, data_time; |
92b96797 | 149 | |
9df81ce9 JMTP |
150 | rrv_time = 0; |
151 | rts_time = 0; | |
152 | cts_time = 0; | |
153 | ack_time = 0; | |
92b96797 | 154 | |
98e93fe5 | 155 | data_time = vnt_get_frame_time(priv->preamble_type, pkt_type, |
42aa03dc | 156 | frame_length, current_rate); |
342e2e20 MP |
157 | |
158 | if (rsv_type == 0) { | |
a974fb37 SB |
159 | rts_time = vnt_get_frame_time(priv->preamble_type, pkt_type, |
160 | 20, priv->top_cck_basic_rate); | |
9df81ce9 JMTP |
161 | ack_time = vnt_get_frame_time(priv->preamble_type, |
162 | pkt_type, 14, | |
163 | priv->top_cck_basic_rate); | |
164 | cts_time = ack_time; | |
165 | ||
342e2e20 | 166 | } else if (rsv_type == 1) { |
a974fb37 SB |
167 | rts_time = vnt_get_frame_time(priv->preamble_type, pkt_type, |
168 | 20, priv->top_cck_basic_rate); | |
98e93fe5 | 169 | cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type, |
b1711c17 | 170 | 14, priv->top_cck_basic_rate); |
98e93fe5 | 171 | ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type, |
b1711c17 | 172 | 14, priv->top_ofdm_basic_rate); |
342e2e20 | 173 | } else if (rsv_type == 2) { |
98e93fe5 | 174 | rts_time = vnt_get_frame_time(priv->preamble_type, pkt_type, |
b1711c17 | 175 | 20, priv->top_ofdm_basic_rate); |
9df81ce9 JMTP |
176 | ack_time = vnt_get_frame_time(priv->preamble_type, |
177 | pkt_type, 14, | |
178 | priv->top_ofdm_basic_rate); | |
179 | cts_time = ack_time; | |
180 | ||
342e2e20 | 181 | } else if (rsv_type == 3) { |
98e93fe5 | 182 | cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type, |
b1711c17 | 183 | 14, priv->top_cck_basic_rate); |
98e93fe5 | 184 | ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type, |
b1711c17 | 185 | 14, priv->top_ofdm_basic_rate); |
342e2e20 | 186 | |
ff5fee22 | 187 | rrv_time = cts_time + ack_time + data_time + 2 * priv->sifs; |
342e2e20 | 188 | |
20338015 | 189 | return cpu_to_le16((u16)rrv_time); |
342e2e20 MP |
190 | } |
191 | ||
ff5fee22 | 192 | rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->sifs; |
92b96797 | 193 | |
342e2e20 | 194 | return cpu_to_le16((u16)rrv_time); |
92b96797 FB |
195 | } |
196 | ||
a974fb37 SB |
197 | static __le16 vnt_get_duration_le(struct vnt_private *priv, u8 pkt_type, |
198 | int need_ack) | |
92b96797 | 199 | { |
a4c2a8a4 | 200 | u32 ack_time = 0; |
92b96797 | 201 | |
a4c2a8a4 MP |
202 | if (need_ack) { |
203 | if (pkt_type == PK_TYPE_11B) | |
0871dc69 | 204 | ack_time = vnt_get_frame_time(priv->preamble_type, |
a974fb37 SB |
205 | pkt_type, 14, |
206 | priv->top_cck_basic_rate); | |
b02ccd59 | 207 | else |
0871dc69 | 208 | ack_time = vnt_get_frame_time(priv->preamble_type, |
a974fb37 SB |
209 | pkt_type, 14, |
210 | priv->top_ofdm_basic_rate); | |
a4c2a8a4 | 211 | |
0871dc69 | 212 | return cpu_to_le16((u16)(priv->sifs + ack_time)); |
b02ccd59 | 213 | } |
92b96797 | 214 | |
92b96797 FB |
215 | return 0; |
216 | } | |
217 | ||
cca48e3c MP |
218 | static __le16 vnt_get_rtscts_duration_le(struct vnt_usb_send_context *context, |
219 | u8 dur_type, u8 pkt_type, u16 rate) | |
92b96797 | 220 | { |
cca48e3c | 221 | struct vnt_private *priv = context->priv; |
7beae9a2 | 222 | u32 cts_time = 0, dur_time = 0; |
cca48e3c MP |
223 | u32 frame_length = context->frame_len; |
224 | u8 need_ack = context->need_ack; | |
92b96797 | 225 | |
7beae9a2 | 226 | switch (dur_type) { |
ecd80240 MP |
227 | case RTSDUR_BB: |
228 | case RTSDUR_BA: | |
229 | case RTSDUR_BA_F0: | |
230 | case RTSDUR_BA_F1: | |
a974fb37 SB |
231 | cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type, |
232 | 14, priv->top_cck_basic_rate); | |
ff5fee22 | 233 | dur_time = cts_time + 2 * priv->sifs + |
3815a27b | 234 | vnt_get_rsvtime(priv, pkt_type, |
42aa03dc | 235 | frame_length, rate, need_ack); |
ecd80240 | 236 | break; |
92b96797 | 237 | |
ecd80240 MP |
238 | case RTSDUR_AA: |
239 | case RTSDUR_AA_F0: | |
240 | case RTSDUR_AA_F1: | |
a974fb37 SB |
241 | cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type, |
242 | 14, priv->top_ofdm_basic_rate); | |
ff5fee22 | 243 | dur_time = cts_time + 2 * priv->sifs + |
3815a27b | 244 | vnt_get_rsvtime(priv, pkt_type, |
42aa03dc | 245 | frame_length, rate, need_ack); |
ecd80240 | 246 | break; |
92b96797 | 247 | |
ecd80240 MP |
248 | case CTSDUR_BA: |
249 | case CTSDUR_BA_F0: | |
250 | case CTSDUR_BA_F1: | |
ff5fee22 | 251 | dur_time = priv->sifs + vnt_get_rsvtime(priv, |
7beae9a2 | 252 | pkt_type, frame_length, rate, need_ack); |
ecd80240 | 253 | break; |
92b96797 | 254 | |
ecd80240 MP |
255 | default: |
256 | break; | |
257 | } | |
92b96797 | 258 | |
7beae9a2 | 259 | return cpu_to_le16((u16)dur_time); |
92b96797 FB |
260 | } |
261 | ||
1622c8fc | 262 | static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context, |
a974fb37 | 263 | struct ieee80211_hdr *hdr) |
1622c8fc MP |
264 | { |
265 | u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head); | |
266 | u8 *hdr_pos = (u8 *)hdr; | |
267 | ||
268 | tx_context->hdr = hdr; | |
269 | if (!tx_context->hdr) | |
270 | return 0; | |
271 | ||
272 | return (u16)(hdr_pos - head); | |
273 | } | |
274 | ||
c2c32da3 | 275 | static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context, |
798f0601 | 276 | struct vnt_tx_datahead_g *buf) |
78363fd1 | 277 | { |
c2c32da3 | 278 | struct vnt_private *priv = tx_context->priv; |
893cc709 MP |
279 | struct ieee80211_hdr *hdr = |
280 | (struct ieee80211_hdr *)tx_context->skb->data; | |
0f5567cb | 281 | u32 frame_len = tx_context->frame_len; |
798f0601 | 282 | u16 rate = tx_context->tx_rate; |
2eca8dbb | 283 | u8 need_ack = tx_context->need_ack; |
c2c32da3 | 284 | |
78363fd1 | 285 | /* Get SignalField,ServiceField,Length */ |
e8c9875c | 286 | vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a); |
d80bf43c | 287 | vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate, |
a974fb37 | 288 | PK_TYPE_11B, &buf->b); |
78363fd1 MP |
289 | |
290 | /* Get Duration and TimeStamp */ | |
893cc709 MP |
291 | if (ieee80211_is_pspoll(hdr->frame_control)) { |
292 | __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15)); | |
293 | ||
294 | buf->duration_a = dur; | |
295 | buf->duration_b = dur; | |
296 | } else { | |
e8c9875c MP |
297 | buf->duration_a = vnt_get_duration_le(priv, |
298 | tx_context->pkt_type, need_ack); | |
435ae3be | 299 | buf->duration_b = vnt_get_duration_le(priv, |
893cc709 MP |
300 | PK_TYPE_11B, need_ack); |
301 | } | |
78363fd1 | 302 | |
10bb39a0 MP |
303 | buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate); |
304 | buf->time_stamp_off_b = vnt_time_stamp_off(priv, | |
d80bf43c | 305 | priv->top_cck_basic_rate); |
78363fd1 | 306 | |
1622c8fc MP |
307 | tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); |
308 | ||
c4cf6dfb | 309 | return le16_to_cpu(buf->duration_a); |
78363fd1 MP |
310 | } |
311 | ||
c2c32da3 | 312 | static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context, |
798f0601 | 313 | struct vnt_tx_datahead_g_fb *buf) |
5b852f53 | 314 | { |
c2c32da3 | 315 | struct vnt_private *priv = tx_context->priv; |
0f5567cb | 316 | u32 frame_len = tx_context->frame_len; |
798f0601 | 317 | u16 rate = tx_context->tx_rate; |
2eca8dbb | 318 | u8 need_ack = tx_context->need_ack; |
c2c32da3 | 319 | |
5b852f53 | 320 | /* Get SignalField,ServiceField,Length */ |
e8c9875c | 321 | vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a); |
5b852f53 | 322 | |
d80bf43c | 323 | vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate, |
a974fb37 | 324 | PK_TYPE_11B, &buf->b); |
5b852f53 MP |
325 | |
326 | /* Get Duration and TimeStamp */ | |
e8c9875c MP |
327 | buf->duration_a = vnt_get_duration_le(priv, tx_context->pkt_type, |
328 | need_ack); | |
435ae3be | 329 | buf->duration_b = vnt_get_duration_le(priv, PK_TYPE_11B, need_ack); |
5b852f53 | 330 | |
e8c9875c MP |
331 | buf->duration_a_f0 = vnt_get_duration_le(priv, tx_context->pkt_type, |
332 | need_ack); | |
333 | buf->duration_a_f1 = vnt_get_duration_le(priv, tx_context->pkt_type, | |
334 | need_ack); | |
5b852f53 | 335 | |
10bb39a0 MP |
336 | buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate); |
337 | buf->time_stamp_off_b = vnt_time_stamp_off(priv, | |
d80bf43c | 338 | priv->top_cck_basic_rate); |
5b852f53 | 339 | |
1622c8fc MP |
340 | tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); |
341 | ||
c4cf6dfb | 342 | return le16_to_cpu(buf->duration_a); |
5b852f53 MP |
343 | } |
344 | ||
c2c32da3 | 345 | static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context, |
798f0601 | 346 | struct vnt_tx_datahead_a_fb *buf) |
bd3f51f1 | 347 | { |
c2c32da3 | 348 | struct vnt_private *priv = tx_context->priv; |
798f0601 | 349 | u16 rate = tx_context->tx_rate; |
e8c9875c | 350 | u8 pkt_type = tx_context->pkt_type; |
2eca8dbb | 351 | u8 need_ack = tx_context->need_ack; |
0f5567cb | 352 | u32 frame_len = tx_context->frame_len; |
c2c32da3 | 353 | |
bd3f51f1 | 354 | /* Get SignalField,ServiceField,Length */ |
205056f3 | 355 | vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a); |
bd3f51f1 | 356 | /* Get Duration and TimeStampOff */ |
435ae3be | 357 | buf->duration = vnt_get_duration_le(priv, pkt_type, need_ack); |
bd3f51f1 | 358 | |
435ae3be MP |
359 | buf->duration_f0 = vnt_get_duration_le(priv, pkt_type, need_ack); |
360 | buf->duration_f1 = vnt_get_duration_le(priv, pkt_type, need_ack); | |
bd3f51f1 | 361 | |
10bb39a0 | 362 | buf->time_stamp_off = vnt_time_stamp_off(priv, rate); |
bd3f51f1 | 363 | |
1622c8fc MP |
364 | tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); |
365 | ||
c4cf6dfb | 366 | return le16_to_cpu(buf->duration); |
bd3f51f1 MP |
367 | } |
368 | ||
c2c32da3 | 369 | static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context, |
798f0601 | 370 | struct vnt_tx_datahead_ab *buf) |
5634a5ab | 371 | { |
c2c32da3 | 372 | struct vnt_private *priv = tx_context->priv; |
893cc709 MP |
373 | struct ieee80211_hdr *hdr = |
374 | (struct ieee80211_hdr *)tx_context->skb->data; | |
0f5567cb | 375 | u32 frame_len = tx_context->frame_len; |
798f0601 | 376 | u16 rate = tx_context->tx_rate; |
2eca8dbb | 377 | u8 need_ack = tx_context->need_ack; |
c2c32da3 | 378 | |
5634a5ab | 379 | /* Get SignalField,ServiceField,Length */ |
e8c9875c MP |
380 | vnt_get_phy_field(priv, frame_len, rate, |
381 | tx_context->pkt_type, &buf->ab); | |
893cc709 | 382 | |
5634a5ab | 383 | /* Get Duration and TimeStampOff */ |
893cc709 MP |
384 | if (ieee80211_is_pspoll(hdr->frame_control)) { |
385 | __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15)); | |
386 | ||
387 | buf->duration = dur; | |
388 | } else { | |
e8c9875c MP |
389 | buf->duration = vnt_get_duration_le(priv, tx_context->pkt_type, |
390 | need_ack); | |
893cc709 | 391 | } |
5634a5ab | 392 | |
10bb39a0 | 393 | buf->time_stamp_off = vnt_time_stamp_off(priv, rate); |
5634a5ab | 394 | |
1622c8fc MP |
395 | tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); |
396 | ||
c4cf6dfb | 397 | return le16_to_cpu(buf->duration); |
5634a5ab MP |
398 | } |
399 | ||
d38b13aa | 400 | static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context, |
a974fb37 | 401 | struct ieee80211_rts *rts, __le16 duration) |
5e67ee49 | 402 | { |
d38b13aa MP |
403 | struct ieee80211_hdr *hdr = |
404 | (struct ieee80211_hdr *)tx_context->skb->data; | |
405 | ||
5e67ee49 | 406 | rts->duration = duration; |
f4554d3b MP |
407 | rts->frame_control = |
408 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS); | |
5e67ee49 | 409 | |
ccc103f5 KA |
410 | ether_addr_copy(rts->ra, hdr->addr1); |
411 | ether_addr_copy(rts->ta, hdr->addr2); | |
5e67ee49 MP |
412 | |
413 | return 0; | |
414 | } | |
415 | ||
c2c32da3 | 416 | static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context, |
798f0601 | 417 | struct vnt_rts_g *buf) |
5e67ee49 | 418 | { |
c2c32da3 | 419 | struct vnt_private *priv = tx_context->priv; |
5e67ee49 | 420 | u16 rts_frame_len = 20; |
798f0601 | 421 | u16 current_rate = tx_context->tx_rate; |
2eca8dbb | 422 | |
d80bf43c | 423 | vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate, |
b1711c17 | 424 | PK_TYPE_11B, &buf->b); |
e8c9875c MP |
425 | vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate, |
426 | tx_context->pkt_type, &buf->a); | |
5e67ee49 | 427 | |
cca48e3c MP |
428 | buf->duration_bb = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BB, |
429 | PK_TYPE_11B, | |
430 | priv->top_cck_basic_rate); | |
431 | buf->duration_aa = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA, | |
432 | tx_context->pkt_type, | |
433 | current_rate); | |
434 | buf->duration_ba = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA, | |
435 | tx_context->pkt_type, | |
436 | current_rate); | |
5e67ee49 | 437 | |
d38b13aa | 438 | vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa); |
5e67ee49 | 439 | |
798f0601 | 440 | return vnt_rxtx_datahead_g(tx_context, &buf->data_head); |
5e67ee49 MP |
441 | } |
442 | ||
c2c32da3 | 443 | static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context, |
798f0601 | 444 | struct vnt_rts_g_fb *buf) |
ec91713a | 445 | { |
c2c32da3 | 446 | struct vnt_private *priv = tx_context->priv; |
798f0601 | 447 | u16 current_rate = tx_context->tx_rate; |
ec91713a | 448 | u16 rts_frame_len = 20; |
2eca8dbb | 449 | |
d80bf43c | 450 | vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate, |
b1711c17 | 451 | PK_TYPE_11B, &buf->b); |
e8c9875c MP |
452 | vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate, |
453 | tx_context->pkt_type, &buf->a); | |
ec91713a | 454 | |
cca48e3c MP |
455 | buf->duration_bb = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BB, |
456 | PK_TYPE_11B, | |
457 | priv->top_cck_basic_rate); | |
458 | buf->duration_aa = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA, | |
459 | tx_context->pkt_type, | |
460 | current_rate); | |
461 | buf->duration_ba = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA, | |
462 | tx_context->pkt_type, | |
463 | current_rate); | |
464 | ||
465 | buf->rts_duration_ba_f0 = | |
466 | vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA_F0, | |
467 | tx_context->pkt_type, | |
468 | priv->tx_rate_fb0); | |
469 | buf->rts_duration_aa_f0 = | |
470 | vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F0, | |
471 | tx_context->pkt_type, | |
472 | priv->tx_rate_fb0); | |
473 | buf->rts_duration_ba_f1 = | |
474 | vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA_F1, | |
475 | tx_context->pkt_type, | |
476 | priv->tx_rate_fb1); | |
477 | buf->rts_duration_aa_f1 = | |
478 | vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F1, | |
479 | tx_context->pkt_type, | |
480 | priv->tx_rate_fb1); | |
ec91713a | 481 | |
d38b13aa | 482 | vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa); |
ec91713a | 483 | |
798f0601 | 484 | return vnt_rxtx_datahead_g_fb(tx_context, &buf->data_head); |
ec91713a MP |
485 | } |
486 | ||
c2c32da3 | 487 | static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context, |
798f0601 | 488 | struct vnt_rts_ab *buf) |
1712633d | 489 | { |
c2c32da3 | 490 | struct vnt_private *priv = tx_context->priv; |
798f0601 | 491 | u16 current_rate = tx_context->tx_rate; |
1712633d MP |
492 | u16 rts_frame_len = 20; |
493 | ||
e8c9875c MP |
494 | vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate, |
495 | tx_context->pkt_type, &buf->ab); | |
1712633d | 496 | |
cca48e3c | 497 | buf->duration = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA, |
e8c9875c | 498 | tx_context->pkt_type, |
cca48e3c | 499 | current_rate); |
1712633d | 500 | |
d38b13aa | 501 | vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration); |
1712633d | 502 | |
798f0601 | 503 | return vnt_rxtx_datahead_ab(tx_context, &buf->data_head); |
1712633d MP |
504 | } |
505 | ||
c2c32da3 | 506 | static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context, |
798f0601 | 507 | struct vnt_rts_a_fb *buf) |
9d2578c1 | 508 | { |
c2c32da3 | 509 | struct vnt_private *priv = tx_context->priv; |
798f0601 | 510 | u16 current_rate = tx_context->tx_rate; |
9d2578c1 | 511 | u16 rts_frame_len = 20; |
2eca8dbb | 512 | |
a974fb37 SB |
513 | vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate, |
514 | tx_context->pkt_type, &buf->a); | |
9d2578c1 | 515 | |
cca48e3c | 516 | buf->duration = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA, |
e8c9875c | 517 | tx_context->pkt_type, |
cca48e3c | 518 | current_rate); |
9d2578c1 | 519 | |
cca48e3c MP |
520 | buf->rts_duration_f0 = |
521 | vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F0, | |
522 | tx_context->pkt_type, | |
523 | priv->tx_rate_fb0); | |
9d2578c1 | 524 | |
cca48e3c MP |
525 | buf->rts_duration_f1 = |
526 | vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F1, | |
527 | tx_context->pkt_type, | |
528 | priv->tx_rate_fb1); | |
9d2578c1 | 529 | |
d38b13aa | 530 | vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration); |
9d2578c1 | 531 | |
798f0601 | 532 | return vnt_rxtx_datahead_a_fb(tx_context, &buf->data_head); |
9d2578c1 MP |
533 | } |
534 | ||
1bdee706 MP |
535 | static u16 vnt_fill_cts_fb_head(struct vnt_usb_send_context *tx_context, |
536 | union vnt_tx_data_head *head) | |
92b96797 | 537 | { |
ee16de8c | 538 | struct vnt_private *priv = tx_context->priv; |
1bdee706 | 539 | struct vnt_cts_fb *buf = &head->cts_g_fb; |
ee16de8c | 540 | u32 cts_frame_len = 14; |
798f0601 | 541 | u16 current_rate = tx_context->tx_rate; |
2eca8dbb | 542 | |
1bdee706 MP |
543 | /* Get SignalField,ServiceField,Length */ |
544 | vnt_get_phy_field(priv, cts_frame_len, priv->top_cck_basic_rate, | |
545 | PK_TYPE_11B, &buf->b); | |
d9560ae5 | 546 | |
1bdee706 MP |
547 | buf->duration_ba = |
548 | vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA, | |
549 | tx_context->pkt_type, | |
550 | current_rate); | |
551 | /* Get CTSDuration_ba_f0 */ | |
552 | buf->cts_duration_ba_f0 = | |
553 | vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA_F0, | |
554 | tx_context->pkt_type, | |
555 | priv->tx_rate_fb0); | |
556 | /* Get CTSDuration_ba_f1 */ | |
557 | buf->cts_duration_ba_f1 = | |
558 | vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA_F1, | |
559 | tx_context->pkt_type, | |
560 | priv->tx_rate_fb1); | |
561 | /* Get CTS Frame body */ | |
562 | buf->data.duration = buf->duration_ba; | |
563 | buf->data.frame_control = | |
564 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); | |
5b852f53 | 565 | |
1bdee706 MP |
566 | ether_addr_copy(buf->data.ra, priv->current_net_addr); |
567 | ||
568 | return vnt_rxtx_datahead_g_fb(tx_context, &buf->data_head); | |
569 | } | |
d9560ae5 | 570 | |
1bdee706 MP |
571 | static u16 vnt_fill_cts_head(struct vnt_usb_send_context *tx_context, |
572 | union vnt_tx_data_head *head) | |
573 | { | |
574 | struct vnt_private *priv = tx_context->priv; | |
575 | struct vnt_cts *buf = &head->cts_g; | |
576 | u32 cts_frame_len = 14; | |
577 | u16 current_rate = tx_context->tx_rate; | |
78363fd1 | 578 | |
1bdee706 MP |
579 | /* Get SignalField,ServiceField,Length */ |
580 | vnt_get_phy_field(priv, cts_frame_len, priv->top_cck_basic_rate, | |
581 | PK_TYPE_11B, &buf->b); | |
582 | /* Get CTSDuration_ba */ | |
583 | buf->duration_ba = | |
584 | vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA, | |
585 | tx_context->pkt_type, | |
586 | current_rate); | |
587 | /*Get CTS Frame body*/ | |
588 | buf->data.duration = buf->duration_ba; | |
589 | buf->data.frame_control = | |
590 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); | |
591 | ||
592 | ether_addr_copy(buf->data.ra, priv->current_net_addr); | |
593 | ||
594 | return vnt_rxtx_datahead_g(tx_context, &buf->data_head); | |
92b96797 FB |
595 | } |
596 | ||
24cdd90f | 597 | static u16 vnt_rxtx_rts(struct vnt_usb_send_context *tx_context, |
798f0601 | 598 | union vnt_tx_head *tx_head, bool need_mic) |
24cdd90f MP |
599 | { |
600 | struct vnt_private *priv = tx_context->priv; | |
601 | struct vnt_rrv_time_rts *buf = &tx_head->tx_rts.rts; | |
4f06c0dc | 602 | union vnt_tx_data_head *head = &tx_head->tx_rts.tx.head; |
0f5567cb | 603 | u32 frame_len = tx_context->frame_len; |
798f0601 | 604 | u16 current_rate = tx_context->tx_rate; |
2eca8dbb | 605 | u8 need_ack = tx_context->need_ack; |
24cdd90f | 606 | |
aadf7d13 | 607 | buf->rts_rrv_time_aa = vnt_get_rtscts_rsvtime_le(priv, 2, |
0f5567cb | 608 | tx_context->pkt_type, frame_len, current_rate); |
aadf7d13 | 609 | buf->rts_rrv_time_ba = vnt_get_rtscts_rsvtime_le(priv, 1, |
0f5567cb | 610 | tx_context->pkt_type, frame_len, current_rate); |
aadf7d13 | 611 | buf->rts_rrv_time_bb = vnt_get_rtscts_rsvtime_le(priv, 0, |
0f5567cb | 612 | tx_context->pkt_type, frame_len, current_rate); |
24cdd90f | 613 | |
e8c9875c | 614 | buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type, |
0f5567cb | 615 | frame_len, current_rate, |
e8c9875c | 616 | need_ack); |
0f5567cb | 617 | buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B, frame_len, |
d80bf43c | 618 | priv->top_cck_basic_rate, need_ack); |
24cdd90f | 619 | |
4f06c0dc MP |
620 | if (need_mic) |
621 | head = &tx_head->tx_rts.tx.mic.head; | |
622 | ||
623 | if (tx_context->fb_option) | |
798f0601 | 624 | return vnt_rxtx_rts_g_fb_head(tx_context, &head->rts_g_fb); |
4f06c0dc | 625 | |
798f0601 | 626 | return vnt_rxtx_rts_g_head(tx_context, &head->rts_g); |
24cdd90f MP |
627 | } |
628 | ||
bf9c0118 | 629 | static u16 vnt_rxtx_cts(struct vnt_usb_send_context *tx_context, |
798f0601 | 630 | union vnt_tx_head *tx_head, bool need_mic) |
bf9c0118 MP |
631 | { |
632 | struct vnt_private *priv = tx_context->priv; | |
633 | struct vnt_rrv_time_cts *buf = &tx_head->tx_cts.cts; | |
b00cb684 | 634 | union vnt_tx_data_head *head = &tx_head->tx_cts.tx.head; |
0f5567cb | 635 | u32 frame_len = tx_context->frame_len; |
798f0601 | 636 | u16 current_rate = tx_context->tx_rate; |
2eca8dbb MP |
637 | u8 need_ack = tx_context->need_ack; |
638 | ||
e8c9875c | 639 | buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type, |
0f5567cb | 640 | frame_len, current_rate, need_ack); |
bf9c0118 | 641 | buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B, |
0f5567cb | 642 | frame_len, priv->top_cck_basic_rate, need_ack); |
bf9c0118 | 643 | |
aadf7d13 | 644 | buf->cts_rrv_time_ba = vnt_get_rtscts_rsvtime_le(priv, 3, |
0f5567cb | 645 | tx_context->pkt_type, frame_len, current_rate); |
bf9c0118 | 646 | |
b00cb684 MP |
647 | if (need_mic) |
648 | head = &tx_head->tx_cts.tx.mic.head; | |
649 | ||
650 | /* Fill CTS */ | |
1bdee706 MP |
651 | if (tx_context->fb_option) |
652 | return vnt_fill_cts_fb_head(tx_context, head); | |
653 | ||
798f0601 | 654 | return vnt_fill_cts_head(tx_context, head); |
bf9c0118 MP |
655 | } |
656 | ||
3b03fea2 | 657 | static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context, |
798f0601 | 658 | union vnt_tx_head *tx_head, bool need_rts, bool need_mic) |
3b03fea2 MP |
659 | { |
660 | struct vnt_private *priv = tx_context->priv; | |
661 | struct vnt_rrv_time_ab *buf = &tx_head->tx_ab.ab; | |
681acf68 | 662 | union vnt_tx_data_head *head = &tx_head->tx_ab.tx.head; |
0f5567cb | 663 | u32 frame_len = tx_context->frame_len; |
798f0601 | 664 | u16 current_rate = tx_context->tx_rate; |
2eca8dbb | 665 | u8 need_ack = tx_context->need_ack; |
3b03fea2 | 666 | |
e8c9875c | 667 | buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type, |
0f5567cb | 668 | frame_len, current_rate, need_ack); |
3b03fea2 | 669 | |
681acf68 MP |
670 | if (need_mic) |
671 | head = &tx_head->tx_ab.tx.mic.head; | |
672 | ||
3b03fea2 | 673 | if (need_rts) { |
e8c9875c | 674 | if (tx_context->pkt_type == PK_TYPE_11B) |
aadf7d13 | 675 | buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 0, |
0f5567cb | 676 | tx_context->pkt_type, frame_len, current_rate); |
3b03fea2 | 677 | else /* PK_TYPE_11A */ |
aadf7d13 | 678 | buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 2, |
0f5567cb | 679 | tx_context->pkt_type, frame_len, current_rate); |
681acf68 | 680 | |
e8c9875c MP |
681 | if (tx_context->fb_option && |
682 | tx_context->pkt_type == PK_TYPE_11A) | |
681acf68 | 683 | return vnt_rxtx_rts_a_fb_head(tx_context, |
798f0601 | 684 | &head->rts_a_fb); |
681acf68 | 685 | |
798f0601 | 686 | return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab); |
3b03fea2 MP |
687 | } |
688 | ||
e8c9875c | 689 | if (tx_context->pkt_type == PK_TYPE_11A) |
798f0601 | 690 | return vnt_rxtx_datahead_a_fb(tx_context, |
0f5567cb | 691 | &head->data_head_a_fb); |
681acf68 | 692 | |
798f0601 | 693 | return vnt_rxtx_datahead_ab(tx_context, &head->data_head_ab); |
3b03fea2 MP |
694 | } |
695 | ||
9ec7f2d8 | 696 | static u16 vnt_generate_tx_parameter(struct vnt_usb_send_context *tx_context, |
a974fb37 SB |
697 | struct vnt_tx_buffer *tx_buffer, |
698 | struct vnt_mic_hdr **mic_hdr, u32 need_mic, | |
699 | bool need_rts) | |
92b96797 | 700 | { |
e8c9875c MP |
701 | if (tx_context->pkt_type == PK_TYPE_11GB || |
702 | tx_context->pkt_type == PK_TYPE_11GA) { | |
92928f13 | 703 | if (need_rts) { |
4f06c0dc | 704 | if (need_mic) |
dfbfa052 MH |
705 | *mic_hdr = |
706 | &tx_buffer->tx_head.tx_rts.tx.mic.hdr; | |
f0e0d505 | 707 | |
4f06c0dc | 708 | return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head, |
798f0601 | 709 | need_mic); |
92928f13 | 710 | } |
da9ef9f4 | 711 | |
681acf68 | 712 | if (need_mic) |
da9ef9f4 | 713 | *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr; |
c12dca09 | 714 | |
798f0601 | 715 | return vnt_rxtx_cts(tx_context, &tx_buffer->tx_head, need_mic); |
92928f13 | 716 | } |
0a0f4b69 | 717 | |
da9ef9f4 MP |
718 | if (need_mic) |
719 | *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr; | |
720 | ||
798f0601 | 721 | return vnt_rxtx_ab(tx_context, &tx_buffer->tx_head, need_rts, need_mic); |
92b96797 | 722 | } |
d38b13aa MP |
723 | |
724 | static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context, | |
a974fb37 SB |
725 | u8 *key_buffer, struct ieee80211_key_conf *tx_key, |
726 | struct sk_buff *skb, u16 payload_len, | |
727 | struct vnt_mic_hdr *mic_hdr) | |
d38b13aa MP |
728 | { |
729 | struct ieee80211_hdr *hdr = tx_context->hdr; | |
ca48ebbc | 730 | u64 pn64; |
d38b13aa MP |
731 | u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb)); |
732 | ||
733 | /* strip header and icv len from payload */ | |
734 | payload_len -= ieee80211_get_hdrlen_from_skb(skb); | |
735 | payload_len -= tx_key->icv_len; | |
736 | ||
737 | switch (tx_key->cipher) { | |
738 | case WLAN_CIPHER_SUITE_WEP40: | |
739 | case WLAN_CIPHER_SUITE_WEP104: | |
740 | memcpy(key_buffer, iv, 3); | |
741 | memcpy(key_buffer + 3, tx_key->key, tx_key->keylen); | |
742 | ||
743 | if (tx_key->keylen == WLAN_KEY_LEN_WEP40) { | |
744 | memcpy(key_buffer + 8, iv, 3); | |
745 | memcpy(key_buffer + 11, | |
42aa03dc | 746 | tx_key->key, WLAN_KEY_LEN_WEP40); |
d38b13aa MP |
747 | } |
748 | ||
749 | break; | |
750 | case WLAN_CIPHER_SUITE_TKIP: | |
751 | ieee80211_get_tkip_p2k(tx_key, skb, key_buffer); | |
752 | ||
753 | break; | |
754 | case WLAN_CIPHER_SUITE_CCMP: | |
755 | ||
756 | if (!mic_hdr) | |
757 | return; | |
758 | ||
759 | mic_hdr->id = 0x59; | |
760 | mic_hdr->payload_len = cpu_to_be16(payload_len); | |
48eaa7f5 | 761 | ether_addr_copy(mic_hdr->mic_addr2, hdr->addr2); |
d38b13aa | 762 | |
ca48ebbc EP |
763 | pn64 = atomic64_read(&tx_key->tx_pn); |
764 | mic_hdr->ccmp_pn[5] = pn64; | |
765 | mic_hdr->ccmp_pn[4] = pn64 >> 8; | |
766 | mic_hdr->ccmp_pn[3] = pn64 >> 16; | |
767 | mic_hdr->ccmp_pn[2] = pn64 >> 24; | |
768 | mic_hdr->ccmp_pn[1] = pn64 >> 32; | |
769 | mic_hdr->ccmp_pn[0] = pn64 >> 40; | |
d38b13aa MP |
770 | |
771 | if (ieee80211_has_a4(hdr->frame_control)) | |
772 | mic_hdr->hlen = cpu_to_be16(28); | |
773 | else | |
774 | mic_hdr->hlen = cpu_to_be16(22); | |
775 | ||
1aba0121 | 776 | ether_addr_copy(mic_hdr->addr1, hdr->addr1); |
777 | ether_addr_copy(mic_hdr->addr2, hdr->addr2); | |
778 | ether_addr_copy(mic_hdr->addr3, hdr->addr3); | |
d38b13aa MP |
779 | |
780 | mic_hdr->frame_control = cpu_to_le16( | |
781 | le16_to_cpu(hdr->frame_control) & 0xc78f); | |
782 | mic_hdr->seq_ctrl = cpu_to_le16( | |
783 | le16_to_cpu(hdr->seq_ctrl) & 0xf); | |
784 | ||
785 | if (ieee80211_has_a4(hdr->frame_control)) | |
1aba0121 | 786 | ether_addr_copy(mic_hdr->addr4, hdr->addr4); |
d38b13aa | 787 | |
d38b13aa MP |
788 | memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP); |
789 | ||
790 | break; | |
791 | default: | |
792 | break; | |
793 | } | |
d38b13aa MP |
794 | } |
795 | ||
796 | int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) | |
797 | { | |
798 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
799 | struct ieee80211_tx_rate *tx_rate = &info->control.rates[0]; | |
800 | struct ieee80211_rate *rate; | |
801 | struct ieee80211_key_conf *tx_key; | |
802 | struct ieee80211_hdr *hdr; | |
803 | struct vnt_mic_hdr *mic_hdr = NULL; | |
804 | struct vnt_tx_buffer *tx_buffer; | |
805 | struct vnt_tx_fifo_head *tx_buffer_head; | |
806 | struct vnt_usb_send_context *tx_context; | |
807 | unsigned long flags; | |
d38b13aa MP |
808 | u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id; |
809 | u8 pkt_type, fb_option = AUTO_FB_NONE; | |
2eca8dbb | 810 | bool need_rts = false, is_pspoll = false; |
d38b13aa MP |
811 | bool need_mic = false; |
812 | ||
813 | hdr = (struct ieee80211_hdr *)(skb->data); | |
814 | ||
815 | rate = ieee80211_get_tx_rate(priv->hw, info); | |
816 | ||
817 | current_rate = rate->hw_value; | |
8b84c1da | 818 | if (priv->current_rate != current_rate && |
a974fb37 | 819 | !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) { |
8b84c1da | 820 | priv->current_rate = current_rate; |
57981a65 | 821 | vnt_schedule_command(priv, WLAN_CMD_SETPOWER); |
d38b13aa MP |
822 | } |
823 | ||
b23f1430 | 824 | if (current_rate > RATE_11M) { |
57fbcce3 | 825 | if (info->band == NL80211_BAND_5GHZ) { |
b23f1430 MP |
826 | pkt_type = PK_TYPE_11A; |
827 | } else { | |
828 | if (tx_rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT) | |
829 | pkt_type = PK_TYPE_11GB; | |
830 | else | |
831 | pkt_type = PK_TYPE_11GA; | |
832 | } | |
833 | } else { | |
d38b13aa | 834 | pkt_type = PK_TYPE_11B; |
b23f1430 | 835 | } |
d38b13aa MP |
836 | |
837 | spin_lock_irqsave(&priv->lock, flags); | |
838 | ||
a032b16c | 839 | tx_context = vnt_get_free_context(priv); |
d38b13aa MP |
840 | if (!tx_context) { |
841 | dev_dbg(&priv->usb->dev, "%s No free context\n", __func__); | |
842 | spin_unlock_irqrestore(&priv->lock, flags); | |
843 | return -ENOMEM; | |
844 | } | |
845 | ||
846 | tx_context->skb = skb; | |
e8c9875c | 847 | tx_context->pkt_type = pkt_type; |
2eca8dbb | 848 | tx_context->need_ack = false; |
0f5567cb | 849 | tx_context->frame_len = skb->len + 4; |
798f0601 | 850 | tx_context->tx_rate = current_rate; |
d38b13aa MP |
851 | |
852 | spin_unlock_irqrestore(&priv->lock, flags); | |
853 | ||
854 | tx_buffer = (struct vnt_tx_buffer *)tx_context->data; | |
855 | tx_buffer_head = &tx_buffer->fifo_head; | |
856 | tx_body_size = skb->len; | |
857 | ||
d38b13aa MP |
858 | /*Set fifo controls */ |
859 | if (pkt_type == PK_TYPE_11A) | |
f0ff3fde | 860 | tx_buffer_head->fifo_ctl = 0; |
d38b13aa | 861 | else if (pkt_type == PK_TYPE_11B) |
47e08894 | 862 | tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11B); |
d38b13aa | 863 | else if (pkt_type == PK_TYPE_11GB) |
47e08894 | 864 | tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GB); |
d38b13aa | 865 | else if (pkt_type == PK_TYPE_11GA) |
47e08894 | 866 | tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GA); |
d38b13aa MP |
867 | |
868 | if (!ieee80211_is_data(hdr->frame_control)) { | |
47e08894 MP |
869 | tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT | |
870 | FIFOCTL_ISDMA0); | |
871 | tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_TMOEN); | |
d38b13aa MP |
872 | |
873 | tx_buffer_head->time_stamp = | |
874 | cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); | |
875 | } else { | |
876 | tx_buffer_head->time_stamp = | |
877 | cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us); | |
878 | } | |
879 | ||
880 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { | |
47e08894 | 881 | tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_NEEDACK); |
2eca8dbb | 882 | tx_context->need_ack = true; |
d38b13aa MP |
883 | } |
884 | ||
885 | if (ieee80211_has_retry(hdr->frame_control)) | |
47e08894 | 886 | tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LRETRY); |
d38b13aa MP |
887 | |
888 | if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) | |
98e93fe5 | 889 | priv->preamble_type = PREAMBLE_SHORT; |
d38b13aa | 890 | else |
98e93fe5 | 891 | priv->preamble_type = PREAMBLE_LONG; |
d38b13aa MP |
892 | |
893 | if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) { | |
894 | need_rts = true; | |
47e08894 | 895 | tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_RTS); |
d38b13aa MP |
896 | } |
897 | ||
898 | if (ieee80211_has_a4(hdr->frame_control)) | |
47e08894 | 899 | tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LHEAD); |
d38b13aa MP |
900 | |
901 | if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER) | |
902 | is_pspoll = true; | |
903 | ||
5deb1cfa MP |
904 | tx_buffer_head->frag_ctl = |
905 | cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10); | |
d38b13aa MP |
906 | |
907 | if (info->control.hw_key) { | |
908 | tx_key = info->control.hw_key; | |
909 | switch (info->control.hw_key->cipher) { | |
910 | case WLAN_CIPHER_SUITE_WEP40: | |
911 | case WLAN_CIPHER_SUITE_WEP104: | |
5deb1cfa | 912 | tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY); |
d38b13aa MP |
913 | break; |
914 | case WLAN_CIPHER_SUITE_TKIP: | |
5deb1cfa | 915 | tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP); |
d38b13aa MP |
916 | break; |
917 | case WLAN_CIPHER_SUITE_CCMP: | |
5deb1cfa | 918 | tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES); |
d38b13aa MP |
919 | need_mic = true; |
920 | default: | |
921 | break; | |
922 | } | |
0f5567cb | 923 | tx_context->frame_len += tx_key->icv_len; |
d38b13aa MP |
924 | } |
925 | ||
cb8ee9de MP |
926 | tx_buffer_head->current_rate = cpu_to_le16(current_rate); |
927 | ||
d38b13aa MP |
928 | /* legacy rates TODO use ieee80211_tx_rate */ |
929 | if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) { | |
a6177aef | 930 | if (priv->auto_fb_ctrl == AUTO_FB_0) { |
47e08894 MP |
931 | tx_buffer_head->fifo_ctl |= |
932 | cpu_to_le16(FIFOCTL_AUTO_FB_0); | |
d38b13aa MP |
933 | |
934 | priv->tx_rate_fb0 = | |
e3f31874 | 935 | vnt_fb_opt0[FB_RATE0][current_rate - RATE_18M]; |
d38b13aa | 936 | priv->tx_rate_fb1 = |
e3f31874 | 937 | vnt_fb_opt0[FB_RATE1][current_rate - RATE_18M]; |
d38b13aa MP |
938 | |
939 | fb_option = AUTO_FB_0; | |
a6177aef | 940 | } else if (priv->auto_fb_ctrl == AUTO_FB_1) { |
47e08894 MP |
941 | tx_buffer_head->fifo_ctl |= |
942 | cpu_to_le16(FIFOCTL_AUTO_FB_1); | |
d38b13aa MP |
943 | |
944 | priv->tx_rate_fb0 = | |
2331ba42 | 945 | vnt_fb_opt1[FB_RATE0][current_rate - RATE_18M]; |
d38b13aa | 946 | priv->tx_rate_fb1 = |
2331ba42 | 947 | vnt_fb_opt1[FB_RATE1][current_rate - RATE_18M]; |
d38b13aa MP |
948 | |
949 | fb_option = AUTO_FB_1; | |
950 | } | |
951 | } | |
952 | ||
71d764ae MP |
953 | tx_context->fb_option = fb_option; |
954 | ||
798f0601 MP |
955 | duration_id = vnt_generate_tx_parameter(tx_context, tx_buffer, &mic_hdr, |
956 | need_mic, need_rts); | |
d38b13aa MP |
957 | |
958 | tx_header_size = tx_context->tx_hdr_size; | |
959 | if (!tx_header_size) { | |
960 | tx_context->in_use = false; | |
961 | return -ENOMEM; | |
962 | } | |
963 | ||
5deb1cfa | 964 | tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG); |
d38b13aa MP |
965 | |
966 | tx_bytes = tx_header_size + tx_body_size; | |
967 | ||
968 | memcpy(tx_context->hdr, skb->data, tx_body_size); | |
969 | ||
970 | hdr->duration_id = cpu_to_le16(duration_id); | |
971 | ||
972 | if (info->control.hw_key) { | |
973 | tx_key = info->control.hw_key; | |
974 | if (tx_key->keylen > 0) | |
975 | vnt_fill_txkey(tx_context, tx_buffer_head->tx_key, | |
a974fb37 | 976 | tx_key, skb, tx_body_size, mic_hdr); |
d38b13aa MP |
977 | } |
978 | ||
1b2bc0aa | 979 | priv->seq_counter = (le16_to_cpu(hdr->seq_ctrl) & |
d38b13aa MP |
980 | IEEE80211_SCTL_SEQ) >> 4; |
981 | ||
982 | tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes); | |
d0335a03 | 983 | tx_buffer->pkt_no = tx_context->pkt_no; |
c8a3a4c0 | 984 | tx_buffer->type = 0x00; |
d38b13aa MP |
985 | |
986 | tx_bytes += 4; | |
987 | ||
988 | tx_context->type = CONTEXT_DATA_PACKET; | |
989 | tx_context->buf_len = tx_bytes; | |
990 | ||
991 | spin_lock_irqsave(&priv->lock, flags); | |
992 | ||
476e7d97 | 993 | if (vnt_tx_context(priv, tx_context) != STATUS_PENDING) { |
d38b13aa MP |
994 | spin_unlock_irqrestore(&priv->lock, flags); |
995 | return -EIO; | |
996 | } | |
997 | ||
998 | spin_unlock_irqrestore(&priv->lock, flags); | |
999 | ||
1000 | return 0; | |
1001 | } | |
1002 | ||
a974fb37 | 1003 | static int vnt_beacon_xmit(struct vnt_private *priv, struct sk_buff *skb) |
d38b13aa MP |
1004 | { |
1005 | struct vnt_beacon_buffer *beacon_buffer; | |
1006 | struct vnt_tx_short_buf_head *short_head; | |
1007 | struct ieee80211_tx_info *info; | |
1008 | struct vnt_usb_send_context *context; | |
1009 | struct ieee80211_mgmt *mgmt_hdr; | |
1010 | unsigned long flags; | |
1011 | u32 frame_size = skb->len + 4; | |
1012 | u16 current_rate, count; | |
1013 | ||
1014 | spin_lock_irqsave(&priv->lock, flags); | |
1015 | ||
a032b16c | 1016 | context = vnt_get_free_context(priv); |
d38b13aa MP |
1017 | if (!context) { |
1018 | dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__); | |
1019 | spin_unlock_irqrestore(&priv->lock, flags); | |
1020 | return -ENOMEM; | |
1021 | } | |
1022 | ||
1023 | context->skb = skb; | |
1024 | ||
1025 | spin_unlock_irqrestore(&priv->lock, flags); | |
1026 | ||
1027 | beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0]; | |
1028 | short_head = &beacon_buffer->short_head; | |
1029 | ||
65df77e2 | 1030 | if (priv->bb_type == BB_TYPE_11A) { |
d38b13aa MP |
1031 | current_rate = RATE_6M; |
1032 | ||
1033 | /* Get SignalField,ServiceField,Length */ | |
1034 | vnt_get_phy_field(priv, frame_size, current_rate, | |
b1711c17 | 1035 | PK_TYPE_11A, &short_head->ab); |
d38b13aa MP |
1036 | |
1037 | /* Get Duration and TimeStampOff */ | |
435ae3be | 1038 | short_head->duration = vnt_get_duration_le(priv, |
42aa03dc | 1039 | PK_TYPE_11A, false); |
d38b13aa MP |
1040 | short_head->time_stamp_off = |
1041 | vnt_time_stamp_off(priv, current_rate); | |
1042 | } else { | |
1043 | current_rate = RATE_1M; | |
14fb6ce8 | 1044 | short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_11B); |
d38b13aa MP |
1045 | |
1046 | /* Get SignalField,ServiceField,Length */ | |
1047 | vnt_get_phy_field(priv, frame_size, current_rate, | |
42aa03dc | 1048 | PK_TYPE_11B, &short_head->ab); |
d38b13aa MP |
1049 | |
1050 | /* Get Duration and TimeStampOff */ | |
435ae3be | 1051 | short_head->duration = vnt_get_duration_le(priv, |
d38b13aa MP |
1052 | PK_TYPE_11B, false); |
1053 | short_head->time_stamp_off = | |
1054 | vnt_time_stamp_off(priv, current_rate); | |
1055 | } | |
1056 | ||
1057 | /* Generate Beacon Header */ | |
1058 | mgmt_hdr = &beacon_buffer->mgmt_hdr; | |
1059 | memcpy(mgmt_hdr, skb->data, skb->len); | |
1060 | ||
1061 | /* time stamp always 0 */ | |
1062 | mgmt_hdr->u.beacon.timestamp = 0; | |
1063 | ||
1064 | info = IEEE80211_SKB_CB(skb); | |
1065 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { | |
1066 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr; | |
76be25ba | 1067 | |
d38b13aa | 1068 | hdr->duration_id = 0; |
1b2bc0aa | 1069 | hdr->seq_ctrl = cpu_to_le16(priv->seq_counter << 4); |
d38b13aa MP |
1070 | } |
1071 | ||
1b2bc0aa MP |
1072 | priv->seq_counter++; |
1073 | if (priv->seq_counter > 0x0fff) | |
1074 | priv->seq_counter = 0; | |
d38b13aa MP |
1075 | |
1076 | count = sizeof(struct vnt_tx_short_buf_head) + skb->len; | |
1077 | ||
1078 | beacon_buffer->tx_byte_count = cpu_to_le16(count); | |
af90ab39 | 1079 | beacon_buffer->pkt_no = context->pkt_no; |
1e00b449 | 1080 | beacon_buffer->type = 0x01; |
d38b13aa MP |
1081 | |
1082 | context->type = CONTEXT_BEACON_PACKET; | |
1083 | context->buf_len = count + 4; /* USB header */ | |
1084 | ||
1085 | spin_lock_irqsave(&priv->lock, flags); | |
1086 | ||
476e7d97 | 1087 | if (vnt_tx_context(priv, context) != STATUS_PENDING) |
d38b13aa MP |
1088 | ieee80211_free_txskb(priv->hw, context->skb); |
1089 | ||
1090 | spin_unlock_irqrestore(&priv->lock, flags); | |
1091 | ||
1092 | return 0; | |
1093 | } | |
1094 | ||
1095 | int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif) | |
1096 | { | |
1097 | struct sk_buff *beacon; | |
1098 | ||
1099 | beacon = ieee80211_beacon_get(priv->hw, vif); | |
1100 | if (!beacon) | |
1101 | return -ENOMEM; | |
1102 | ||
1103 | if (vnt_beacon_xmit(priv, beacon)) { | |
1104 | ieee80211_free_txskb(priv->hw, beacon); | |
1105 | return -ENODEV; | |
1106 | } | |
1107 | ||
1108 | return 0; | |
1109 | } | |
1110 | ||
1111 | int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif, | |
a974fb37 | 1112 | struct ieee80211_bss_conf *conf) |
d38b13aa | 1113 | { |
d38b13aa MP |
1114 | vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX); |
1115 | ||
1116 | vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); | |
1117 | ||
1118 | vnt_mac_set_beacon_interval(priv, conf->beacon_int); | |
1119 | ||
1120 | vnt_clear_current_tsf(priv); | |
1121 | ||
1122 | vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); | |
1123 | ||
1124 | vnt_reset_next_tbtt(priv, conf->beacon_int); | |
1125 | ||
eab4e78d | 1126 | return vnt_beacon_make(priv, vif); |
d38b13aa | 1127 | } |