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