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