]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/staging/vt6656/rxtx.c
staging: vt6656: vnt_rf_setpower rate <= RATE_11M check array bound
[mirror_ubuntu-hirsute-kernel.git] / drivers / staging / vt6656 / rxtx.c
CommitLineData
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:
f77f13e2 28 * s_vGenerateTxParameter - Generate tx dma required parameter.
92b96797
FB
29 * csBeacon_xmit - beacon tx function
30 * csMgmt_xmit - management tx function
31 * s_uGetDataDuration - get tx data required duration
32 * s_uFillDataHead- fulfill tx data duration header
f77f13e2 33 * s_uGetRTSCTSDuration- get rtx/cts required duration
92b96797
FB
34 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
35 * s_uGetTxRsvTime- get frame reserved time
36 * s_vFillCTSHead- fulfill CTS ctl header
f77f13e2 37 * s_vFillFragParameter- Set fragment ctl parameter.
92b96797 38 * s_vFillRTSHead- fulfill RTS ctl header
92b96797
FB
39 * vDMA0_tx_80211- tx 802.11 frame via dma0
40 * vGenerateFIFOHeader- Generate tx FIFO ctl header
41 *
42 * Revision History:
43 *
44 */
45
92b96797 46#include "device.h"
92b96797 47#include "rxtx.h"
92b96797 48#include "card.h"
92b96797 49#include "mac.h"
92b96797 50#include "rf.h"
92b96797 51#include "usbpipe.h"
9d26d60f 52
4a499de2 53static int msglevel = MSG_LEVEL_INFO;
92b96797 54
3b138851 55static const u16 wTimeStampOff[2][MAX_RATE] = {
92b96797
FB
56 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
57 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
58 };
59
3b138851 60static const u16 wFB_Opt0[2][5] = {
92b96797
FB
61 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
62 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
63 };
3b138851 64static const u16 wFB_Opt1[2][5] = {
92b96797
FB
65 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
66 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
67 };
68
92b96797
FB
69#define RTSDUR_BB 0
70#define RTSDUR_BA 1
71#define RTSDUR_AA 2
72#define CTSDUR_BA 3
73#define RTSDUR_BA_F0 4
74#define RTSDUR_AA_F0 5
75#define RTSDUR_BA_F1 6
76#define RTSDUR_AA_F1 7
77#define CTSDUR_BA_F0 8
78#define CTSDUR_BA_F1 9
79#define DATADUR_B 10
80#define DATADUR_A 11
81#define DATADUR_A_F0 12
82#define DATADUR_A_F1 13
83
b89f3b94 84static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *);
d56131de 85
c2c32da3 86static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
8e344c88 87 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
fa57560c 88 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
05cc617b 89 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts);
d56131de 90
d56131de
MP
91static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
92 u32 cbFrameLength, u16 wRate, int bNeedAck);
93
20338015 94static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
3b6cee7b 95 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate);
d56131de 96
c2c32da3 97static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
5fb8e412
MP
98 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
99 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
d56131de 100
c2c32da3 101static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
5fb8e412 102 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
ceb8c5da 103 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
d56131de 104
5abe3d63 105static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
3ed210ef 106 u8 byPktType, int bNeedAck);
d56131de 107
7f591a11 108static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
d56131de
MP
109 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
110 int bNeedAck, u8 byFBOption);
92b96797 111
aceaf018 112static struct vnt_usb_send_context
b89f3b94 113 *s_vGetFreeContext(struct vnt_private *priv)
92b96797 114{
b89f3b94 115 struct vnt_usb_send_context *context = NULL;
d56131de 116 int ii;
92b96797 117
b89f3b94
MP
118 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
119
120 for (ii = 0; ii < priv->cbTD; ii++) {
121 if (!priv->apTD[ii])
122 return NULL;
123
124 context = priv->apTD[ii];
30a05b39
MP
125 if (context->in_use == false) {
126 context->in_use = true;
127 memset(context->data, 0,
b89f3b94 128 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
1622c8fc
MP
129
130 context->hdr = NULL;
131
b89f3b94
MP
132 return context;
133 }
134 }
135
136 if (ii == priv->cbTD)
137 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
aceaf018 138
5c851383 139 return NULL;
92b96797
FB
140}
141
dab085b1 142static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
f115e76a
MP
143{
144 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
145 [rate % MAX_RATE]);
146}
147
92b96797
FB
148/*byPktType : PK_TYPE_11A 0
149 PK_TYPE_11B 1
150 PK_TYPE_11GB 2
151 PK_TYPE_11GA 3
152*/
3fd5620f
MP
153static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
154 u32 frame_length, u16 rate, int need_ack)
92b96797 155{
3fd5620f 156 u32 data_time, ack_time;
92b96797 157
d38ee5b2 158 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
3fd5620f 159 frame_length, rate);
92b96797 160
3fd5620f 161 if (pkt_type == PK_TYPE_11B)
d38ee5b2
MP
162 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
163 14, (u16)priv->byTopCCKBasicRate);
3fd5620f 164 else
d38ee5b2
MP
165 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
166 14, (u16)priv->byTopOFDMBasicRate);
3fd5620f
MP
167
168 if (need_ack)
169 return data_time + priv->uSIFS + ack_time;
170
171 return data_time;
92b96797
FB
172}
173
2075f654 174static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
9c3806d5
MP
175 u32 frame_length, u16 rate, int need_ack)
176{
177 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
178 frame_length, rate, need_ack));
179}
180
92b96797 181//byFreqType: 0=>5GHZ 1=>2.4GHZ
20338015 182static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
3b6cee7b 183 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
92b96797 184{
342e2e20 185 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
92b96797 186
342e2e20 187 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
92b96797 188
d38ee5b2 189 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
3b6cee7b 190 frame_length, current_rate);
342e2e20
MP
191
192 if (rsv_type == 0) {
d38ee5b2 193 rts_time = vnt_get_frame_time(priv->byPreambleType,
342e2e20 194 pkt_type, 20, priv->byTopCCKBasicRate);
d38ee5b2 195 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
342e2e20
MP
196 pkt_type, 14, priv->byTopCCKBasicRate);
197 } else if (rsv_type == 1) {
d38ee5b2 198 rts_time = vnt_get_frame_time(priv->byPreambleType,
342e2e20 199 pkt_type, 20, priv->byTopCCKBasicRate);
d38ee5b2 200 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
342e2e20 201 14, priv->byTopCCKBasicRate);
d38ee5b2 202 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
342e2e20
MP
203 14, priv->byTopOFDMBasicRate);
204 } else if (rsv_type == 2) {
d38ee5b2 205 rts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
342e2e20 206 20, priv->byTopOFDMBasicRate);
d38ee5b2 207 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
342e2e20
MP
208 pkt_type, 14, priv->byTopOFDMBasicRate);
209 } else if (rsv_type == 3) {
d38ee5b2 210 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
342e2e20 211 14, priv->byTopCCKBasicRate);
d38ee5b2 212 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
342e2e20
MP
213 14, priv->byTopOFDMBasicRate);
214
215 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
216
20338015 217 return cpu_to_le16((u16)rrv_time);
342e2e20
MP
218 }
219
220 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
92b96797 221
342e2e20 222 return cpu_to_le16((u16)rrv_time);
92b96797
FB
223}
224
225//byFreqType 0: 5GHz, 1:2.4Ghz
5abe3d63 226static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
6b5ad9d2 227 u8 byPktType, int bNeedAck)
92b96797 228{
0005cb00 229 u32 uAckTime = 0;
92b96797 230
b02ccd59 231 if (bNeedAck) {
6b5ad9d2 232 if (byPktType == PK_TYPE_11B)
d38ee5b2 233 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
b02ccd59
MP
234 byPktType, 14, pDevice->byTopCCKBasicRate);
235 else
d38ee5b2 236 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
b02ccd59 237 byPktType, 14, pDevice->byTopOFDMBasicRate);
d5005955 238 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
b02ccd59 239 }
92b96797 240
92b96797
FB
241 return 0;
242}
243
92b96797 244//byFreqType: 0=>5GHZ 1=>2.4GHZ
7f591a11 245static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
d56131de
MP
246 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
247 u8 byFBOption)
92b96797 248{
d56131de 249 u32 uCTSTime = 0, uDurTime = 0;
92b96797 250
ecd80240
MP
251 switch (byDurType) {
252 case RTSDUR_BB:
253 case RTSDUR_BA:
254 case RTSDUR_BA_F0:
255 case RTSDUR_BA_F1:
d38ee5b2
MP
256 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
257 byPktType, 14, pDevice->byTopCCKBasicRate);
ecd80240
MP
258 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
259 s_uGetTxRsvTime(pDevice, byPktType,
260 cbFrameLength, wRate, bNeedAck);
261 break;
92b96797 262
ecd80240
MP
263 case RTSDUR_AA:
264 case RTSDUR_AA_F0:
265 case RTSDUR_AA_F1:
d38ee5b2
MP
266 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
267 byPktType, 14, pDevice->byTopOFDMBasicRate);
ecd80240
MP
268 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
269 s_uGetTxRsvTime(pDevice, byPktType,
270 cbFrameLength, wRate, bNeedAck);
271 break;
92b96797 272
ecd80240
MP
273 case CTSDUR_BA:
274 case CTSDUR_BA_F0:
275 case CTSDUR_BA_F1:
276 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
f84cdf65 277 byPktType, cbFrameLength, wRate, bNeedAck);
ecd80240 278 break;
92b96797 279
ecd80240
MP
280 default:
281 break;
282 }
92b96797 283
e34f9dbe 284 return cpu_to_le16((u16)uDurTime);
92b96797
FB
285}
286
1622c8fc
MP
287static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
288 struct ieee80211_hdr *hdr)
289{
290 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
291 u8 *hdr_pos = (u8 *)hdr;
292
293 tx_context->hdr = hdr;
294 if (!tx_context->hdr)
295 return 0;
296
297 return (u16)(hdr_pos - head);
298}
299
c2c32da3
MP
300static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
301 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf,
302 u32 frame_len, int need_ack)
78363fd1 303{
c2c32da3
MP
304
305 struct vnt_private *priv = tx_context->priv;
893cc709
MP
306 struct ieee80211_hdr *hdr =
307 (struct ieee80211_hdr *)tx_context->skb->data;
c2c32da3 308
78363fd1 309 /* Get SignalField,ServiceField,Length */
205056f3
MP
310 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
311 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
78363fd1
MP
312 PK_TYPE_11B, &buf->b);
313
314 /* Get Duration and TimeStamp */
893cc709
MP
315 if (ieee80211_is_pspoll(hdr->frame_control)) {
316 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
317
318 buf->duration_a = dur;
319 buf->duration_b = dur;
320 } else {
321 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
322 buf->duration_b = s_uGetDataDuration(priv,
323 PK_TYPE_11B, need_ack);
324 }
78363fd1 325
10bb39a0
MP
326 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
327 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
78363fd1
MP
328 priv->byTopCCKBasicRate);
329
1622c8fc
MP
330 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
331
c4cf6dfb 332 return le16_to_cpu(buf->duration_a);
78363fd1
MP
333}
334
c2c32da3
MP
335static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
336 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf,
5b852f53
MP
337 u32 frame_len, int need_ack)
338{
c2c32da3
MP
339 struct vnt_private *priv = tx_context->priv;
340
5b852f53 341 /* Get SignalField,ServiceField,Length */
205056f3 342 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
5b852f53 343
205056f3 344 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
5b852f53
MP
345 PK_TYPE_11B, &buf->b);
346
347 /* Get Duration and TimeStamp */
4e01117c
MP
348 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
349 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
5b852f53 350
4e01117c
MP
351 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
352 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
5b852f53 353
10bb39a0
MP
354 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
355 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
5b852f53
MP
356 priv->byTopCCKBasicRate);
357
1622c8fc
MP
358 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
359
c4cf6dfb 360 return le16_to_cpu(buf->duration_a);
5b852f53
MP
361}
362
c2c32da3
MP
363static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
364 u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf,
bd3f51f1
MP
365 u32 frame_len, int need_ack)
366{
c2c32da3
MP
367 struct vnt_private *priv = tx_context->priv;
368
bd3f51f1 369 /* Get SignalField,ServiceField,Length */
205056f3 370 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
bd3f51f1 371 /* Get Duration and TimeStampOff */
4e01117c 372 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
bd3f51f1 373
4e01117c
MP
374 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
375 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
bd3f51f1 376
10bb39a0 377 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
bd3f51f1 378
1622c8fc
MP
379 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
380
c4cf6dfb 381 return le16_to_cpu(buf->duration);
bd3f51f1
MP
382}
383
c2c32da3
MP
384static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
385 u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf,
5634a5ab
MP
386 u32 frame_len, int need_ack)
387{
c2c32da3 388 struct vnt_private *priv = tx_context->priv;
893cc709
MP
389 struct ieee80211_hdr *hdr =
390 (struct ieee80211_hdr *)tx_context->skb->data;
c2c32da3 391
5634a5ab 392 /* Get SignalField,ServiceField,Length */
205056f3 393 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->ab);
893cc709 394
5634a5ab 395 /* Get Duration and TimeStampOff */
893cc709
MP
396 if (ieee80211_is_pspoll(hdr->frame_control)) {
397 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
398
399 buf->duration = dur;
400 } else {
401 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
402 }
5634a5ab 403
10bb39a0 404 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
5634a5ab 405
1622c8fc
MP
406 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
407
c4cf6dfb 408 return le16_to_cpu(buf->duration);
5634a5ab
MP
409}
410
d38b13aa
MP
411static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
412 struct ieee80211_rts *rts, __le16 duration)
5e67ee49 413{
d38b13aa
MP
414 struct ieee80211_hdr *hdr =
415 (struct ieee80211_hdr *)tx_context->skb->data;
416
5e67ee49 417 rts->duration = duration;
f4554d3b
MP
418 rts->frame_control =
419 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
5e67ee49 420
d38b13aa
MP
421 memcpy(rts->ra, hdr->addr1, ETH_ALEN);
422 memcpy(rts->ta, hdr->addr2, ETH_ALEN);
5e67ee49
MP
423
424 return 0;
425}
426
c2c32da3 427static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
5e67ee49
MP
428 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
429 u8 pkt_type, u32 frame_len, int need_ack,
430 u16 current_rate, u8 fb_option)
431{
c2c32da3 432 struct vnt_private *priv = tx_context->priv;
5e67ee49
MP
433 u16 rts_frame_len = 20;
434
205056f3 435 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
5e67ee49 436 PK_TYPE_11B, &buf->b);
205056f3 437 vnt_get_phy_field(priv, rts_frame_len,
5e67ee49
MP
438 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
439
4e01117c 440 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
5e67ee49 441 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
4e01117c 442 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
5e67ee49 443 pkt_type, current_rate, need_ack, fb_option);
4e01117c 444 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
5e67ee49
MP
445 pkt_type, current_rate, need_ack, fb_option);
446
d38b13aa 447 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
5e67ee49 448
c2c32da3 449 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
78363fd1 450 &buf->data_head, frame_len, need_ack);
5e67ee49
MP
451}
452
c2c32da3 453static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
ec91713a
MP
454 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
455 u8 pkt_type, u32 frame_len, int need_ack,
456 u16 current_rate, u8 fb_option)
457{
c2c32da3 458 struct vnt_private *priv = tx_context->priv;
ec91713a
MP
459 u16 rts_frame_len = 20;
460
205056f3 461 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
ec91713a 462 PK_TYPE_11B, &buf->b);
205056f3 463 vnt_get_phy_field(priv, rts_frame_len,
ec91713a
MP
464 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
465
466
4e01117c 467 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
ec91713a 468 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
4e01117c 469 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
ec91713a 470 pkt_type, current_rate, need_ack, fb_option);
4e01117c 471 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
ec91713a
MP
472 pkt_type, current_rate, need_ack, fb_option);
473
474
fadc3bdf 475 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
f84cdf65 476 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
fadc3bdf 477 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
f84cdf65 478 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
fadc3bdf 479 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
f84cdf65 480 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
fadc3bdf 481 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
f84cdf65 482 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
ec91713a 483
d38b13aa 484 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
ec91713a 485
c2c32da3 486 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate,
5b852f53 487 &buf->data_head, frame_len, need_ack);
ec91713a
MP
488}
489
c2c32da3 490static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
1712633d
MP
491 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
492 u8 pkt_type, u32 frame_len, int need_ack,
493 u16 current_rate, u8 fb_option)
494{
c2c32da3 495 struct vnt_private *priv = tx_context->priv;
1712633d
MP
496 u16 rts_frame_len = 20;
497
205056f3 498 vnt_get_phy_field(priv, rts_frame_len,
1712633d
MP
499 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
500
4e01117c 501 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
1712633d
MP
502 pkt_type, current_rate, need_ack, fb_option);
503
d38b13aa 504 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
1712633d 505
c2c32da3 506 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
5634a5ab 507 &buf->data_head, frame_len, need_ack);
1712633d
MP
508}
509
c2c32da3 510static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
9d2578c1
MP
511 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
512 u8 pkt_type, u32 frame_len, int need_ack,
513 u16 current_rate, u8 fb_option)
514{
c2c32da3 515 struct vnt_private *priv = tx_context->priv;
9d2578c1
MP
516 u16 rts_frame_len = 20;
517
205056f3 518 vnt_get_phy_field(priv, rts_frame_len,
9d2578c1
MP
519 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
520
4e01117c 521 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
9d2578c1
MP
522 pkt_type, current_rate, need_ack, fb_option);
523
fadc3bdf 524 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
f84cdf65 525 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
9d2578c1 526
fadc3bdf 527 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
f84cdf65 528 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
9d2578c1 529
d38b13aa 530 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
9d2578c1 531
c2c32da3 532 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate,
bd3f51f1 533 &buf->data_head, frame_len, need_ack);
9d2578c1
MP
534}
535
c2c32da3 536static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
5fb8e412 537 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
ceb8c5da 538 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
92b96797 539{
92b96797 540
13fe62ae 541 if (!head)
0a0f4b69 542 return 0;
92b96797 543
9d5829bf
MP
544 /* Note: So far RTSHead doesn't appear in ATIM
545 * & Beacom DMA, so we don't need to take them
546 * into account.
547 * Otherwise, we need to modified codes for them.
548 */
0bddd303
MP
549 switch (byPktType) {
550 case PK_TYPE_11GB:
551 case PK_TYPE_11GA:
9d5829bf 552 if (byFBOption == AUTO_FB_NONE)
c2c32da3 553 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g,
5e67ee49
MP
554 psEthHeader, byPktType, cbFrameLength,
555 bNeedAck, wCurrentRate, byFBOption);
9d5829bf 556 else
c2c32da3
MP
557 return vnt_rxtx_rts_g_fb_head(tx_context,
558 &head->rts_g_fb, psEthHeader, byPktType,
559 cbFrameLength, bNeedAck, wCurrentRate,
560 byFBOption);
0bddd303
MP
561 break;
562 case PK_TYPE_11A:
2b83ebd0 563 if (byFBOption) {
c2c32da3
MP
564 return vnt_rxtx_rts_a_fb_head(tx_context,
565 &head->rts_a_fb, psEthHeader, byPktType,
566 cbFrameLength, bNeedAck, wCurrentRate,
567 byFBOption);
2b83ebd0
MP
568 break;
569 }
0bddd303 570 case PK_TYPE_11B:
c2c32da3 571 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab,
1712633d
MP
572 psEthHeader, byPktType, cbFrameLength,
573 bNeedAck, wCurrentRate, byFBOption);
9d5829bf 574 }
0a0f4b69
MP
575
576 return 0;
92b96797
FB
577}
578
c2c32da3 579static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
5fb8e412
MP
580 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
581 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
92b96797 582{
c2c32da3 583 struct vnt_private *pDevice = tx_context->priv;
d56131de 584 u32 uCTSFrameLen = 14;
92b96797 585
27df3ebf 586 if (!head)
0a0f4b69 587 return 0;
92b96797 588
c921cc8c
MP
589 if (byFBOption != AUTO_FB_NONE) {
590 /* Auto Fall back */
27df3ebf 591 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
aed387c7 592 /* Get SignalField,ServiceField,Length */
205056f3 593 vnt_get_phy_field(pDevice, uCTSFrameLen,
aed387c7 594 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
4e01117c 595 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
e34f9dbe
MP
596 cbFrameLength, byPktType,
597 wCurrentRate, bNeedAck, byFBOption);
598 /* Get CTSDuration_ba_f0 */
7fd5747f 599 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
f84cdf65
MP
600 CTSDUR_BA_F0, cbFrameLength, byPktType,
601 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
e34f9dbe 602 /* Get CTSDuration_ba_f1 */
7fd5747f 603 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
f84cdf65
MP
604 CTSDUR_BA_F1, cbFrameLength, byPktType,
605 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
14840cdd 606 /* Get CTS Frame body */
4e01117c 607 pBuf->data.duration = pBuf->duration_ba;
d9560ae5
MP
608 pBuf->data.frame_control =
609 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
610
14840cdd 611 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
5b852f53 612
c2c32da3
MP
613 return vnt_rxtx_datahead_g_fb(tx_context, byPktType,
614 wCurrentRate, &pBuf->data_head, cbFrameLength,
615 bNeedAck);
c921cc8c 616 } else {
27df3ebf 617 struct vnt_cts *pBuf = &head->cts_g;
aed387c7 618 /* Get SignalField,ServiceField,Length */
205056f3 619 vnt_get_phy_field(pDevice, uCTSFrameLen,
aed387c7 620 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
e34f9dbe 621 /* Get CTSDuration_ba */
4e01117c 622 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
e34f9dbe
MP
623 CTSDUR_BA, cbFrameLength, byPktType,
624 wCurrentRate, bNeedAck, byFBOption);
14840cdd 625 /*Get CTS Frame body*/
4e01117c 626 pBuf->data.duration = pBuf->duration_ba;
d9560ae5
MP
627 pBuf->data.frame_control =
628 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
629
14840cdd 630 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
78363fd1 631
c2c32da3 632 return vnt_rxtx_datahead_g(tx_context, byPktType, wCurrentRate,
78363fd1 633 &pBuf->data_head, cbFrameLength, bNeedAck);
92b96797 634 }
0a0f4b69
MP
635
636 return 0;
92b96797
FB
637}
638
92b96797
FB
639/*+
640 *
641 * Description:
642 * Generate FIFO control for MAC & Baseband controller
643 *
644 * Parameters:
645 * In:
646 * pDevice - Pointer to adpater
647 * pTxDataHead - Transmit Data Buffer
648 * pTxBufHead - pTxBufHead
649 * pvRrvTime - pvRrvTime
650 * pvRTS - RTS Buffer
651 * pCTS - CTS Buffer
652 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
653 * bNeedACK - If need ACK
92b96797
FB
654 * Out:
655 * none
656 *
657 * Return Value: none
658 *
659-*/
cc856e61 660
c2c32da3 661static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
8e344c88 662 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
fa57560c 663 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
05cc617b 664 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts)
92b96797 665{
c2c32da3 666 struct vnt_private *pDevice = tx_context->priv;
8e344c88 667 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
b9cc2fc0 668 union vnt_tx_data_head *head = NULL;
d56131de 669 u16 wFifoCtl;
d56131de 670 u8 byFBOption = AUTO_FB_NONE;
92b96797 671
03a9cf34 672 pFifoHead->current_rate = cpu_to_le16(wCurrentRate);
92928f13 673 wFifoCtl = pFifoHead->wFIFOCtl;
92b96797 674
92928f13
MP
675 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
676 byFBOption = AUTO_FB_0;
677 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
678 byFBOption = AUTO_FB_1;
92b96797 679
92928f13
MP
680 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
681 if (need_rts) {
682 struct vnt_rrv_time_rts *pBuf =
683 &tx_buffer->tx_head.tx_rts.rts;
9e38a5c1 684
85417bf0 685 pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
92928f13 686 byPktType, cbFrameSize, wCurrentRate);
85417bf0 687 pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
92928f13 688 byPktType, cbFrameSize, wCurrentRate);
85417bf0 689 pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
cfabe4b4 690 byPktType, cbFrameSize, wCurrentRate);
b9cc2fc0 691
5ff627ae 692 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
92928f13 693 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
5ff627ae 694 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
695 PK_TYPE_11B, cbFrameSize,
696 pDevice->byTopCCKBasicRate, bNeedACK);
697
698 if (need_mic) {
699 *mic_hdr = &tx_buffer->
700 tx_head.tx_rts.tx.mic.hdr;
701 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
702 } else {
703 head = &tx_buffer->tx_head.tx_rts.tx.head;
704 }
f0e0d505 705
92928f13 706 /* Fill RTS */
c2c32da3 707 return s_vFillRTSHead(tx_context, byPktType, head,
92928f13
MP
708 cbFrameSize, bNeedACK, psEthHeader,
709 wCurrentRate, byFBOption);
f0e0d505 710
92928f13
MP
711 } else {
712 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
713 tx_head.tx_cts.cts;
714
5ff627ae 715 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
92928f13 716 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
5ff627ae 717 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
718 PK_TYPE_11B, cbFrameSize,
719 pDevice->byTopCCKBasicRate, bNeedACK);
720
372108e7 721 pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
92928f13
MP
722 byPktType, cbFrameSize, wCurrentRate);
723
724 if (need_mic) {
725 *mic_hdr = &tx_buffer->
726 tx_head.tx_cts.tx.mic.hdr;
727 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
728 } else {
729 head = &tx_buffer->tx_head.tx_cts.tx.head;
730 }
731
732 /* Fill CTS */
c2c32da3 733 return s_vFillCTSHead(tx_context, byPktType,
92928f13
MP
734 head, cbFrameSize, bNeedACK, wCurrentRate,
735 byFBOption);
736 }
737 } else if (byPktType == PK_TYPE_11A) {
b9cc2fc0 738 if (need_mic) {
92928f13
MP
739 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
740 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
b9cc2fc0 741 } else {
92928f13 742 head = &tx_buffer->tx_head.tx_ab.tx.head;
b9cc2fc0 743 }
f0e0d505 744
92928f13
MP
745 if (need_rts) {
746 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
747 tx_head.tx_ab.ab;
9e38a5c1 748
85417bf0 749 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2,
cfabe4b4 750 byPktType, cbFrameSize, wCurrentRate);
b9cc2fc0 751
5ff627ae 752 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
92928f13 753 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
9e38a5c1 754
92928f13 755 /* Fill RTS */
c2c32da3 756 return s_vFillRTSHead(tx_context, byPktType, head,
92928f13
MP
757 cbFrameSize, bNeedACK, psEthHeader,
758 wCurrentRate, byFBOption);
759 } else {
760 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
761 tx_head.tx_ab.ab;
a90186e4 762
5ff627ae 763 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
764 PK_TYPE_11A, cbFrameSize,
765 wCurrentRate, bNeedACK);
c12dca09 766
c2c32da3 767 return vnt_rxtx_datahead_a_fb(tx_context, byPktType,
92928f13
MP
768 wCurrentRate, &head->data_head_a_fb,
769 cbFrameSize, bNeedACK);
770 }
771 } else if (byPktType == PK_TYPE_11B) {
772 if (need_mic) {
773 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
774 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
775 } else {
776 head = &tx_buffer->tx_head.tx_ab.tx.head;
777 }
778
779 if (need_rts) {
780 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
781 tx_head.tx_ab.ab;
9e38a5c1 782
85417bf0 783 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0,
cfabe4b4 784 byPktType, cbFrameSize, wCurrentRate);
f0e0d505 785
5ff627ae 786 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
787 PK_TYPE_11B, cbFrameSize, wCurrentRate,
788 bNeedACK);
789
790 /* Fill RTS */
c2c32da3 791 return s_vFillRTSHead(tx_context, byPktType, head,
92928f13 792 cbFrameSize,
351c7dc3 793 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
92928f13
MP
794 } else {
795 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
796 tx_head.tx_ab.ab;
9e38a5c1 797
5ff627ae 798 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
799 PK_TYPE_11B, cbFrameSize,
800 wCurrentRate, bNeedACK);
c12dca09 801
c2c32da3 802 return vnt_rxtx_datahead_ab(tx_context, byPktType,
92928f13
MP
803 wCurrentRate, &head->data_head_ab,
804 cbFrameSize, bNeedACK);
805 }
806 }
0a0f4b69 807
30a05b39 808 return 0;
92b96797 809}
d38b13aa
MP
810
811static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
812 u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
813 u16 payload_len, struct vnt_mic_hdr *mic_hdr)
814{
815 struct ieee80211_hdr *hdr = tx_context->hdr;
816 struct ieee80211_key_seq seq;
817 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
818
819 /* strip header and icv len from payload */
820 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
821 payload_len -= tx_key->icv_len;
822
823 switch (tx_key->cipher) {
824 case WLAN_CIPHER_SUITE_WEP40:
825 case WLAN_CIPHER_SUITE_WEP104:
826 memcpy(key_buffer, iv, 3);
827 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
828
829 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
830 memcpy(key_buffer + 8, iv, 3);
831 memcpy(key_buffer + 11,
832 tx_key->key, WLAN_KEY_LEN_WEP40);
833 }
834
835 break;
836 case WLAN_CIPHER_SUITE_TKIP:
837 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
838
839 break;
840 case WLAN_CIPHER_SUITE_CCMP:
841
842 if (!mic_hdr)
843 return;
844
845 mic_hdr->id = 0x59;
846 mic_hdr->payload_len = cpu_to_be16(payload_len);
847 memcpy(mic_hdr->mic_addr2, hdr->addr2, ETH_ALEN);
848
849 ieee80211_get_key_tx_seq(tx_key, &seq);
850
79f976dc 851 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
d38b13aa
MP
852
853 if (ieee80211_has_a4(hdr->frame_control))
854 mic_hdr->hlen = cpu_to_be16(28);
855 else
856 mic_hdr->hlen = cpu_to_be16(22);
857
858 memcpy(mic_hdr->addr1, hdr->addr1, ETH_ALEN);
859 memcpy(mic_hdr->addr2, hdr->addr2, ETH_ALEN);
860 memcpy(mic_hdr->addr3, hdr->addr3, ETH_ALEN);
861
862 mic_hdr->frame_control = cpu_to_le16(
863 le16_to_cpu(hdr->frame_control) & 0xc78f);
864 mic_hdr->seq_ctrl = cpu_to_le16(
865 le16_to_cpu(hdr->seq_ctrl) & 0xf);
866
867 if (ieee80211_has_a4(hdr->frame_control))
868 memcpy(mic_hdr->addr4, hdr->addr4, ETH_ALEN);
869
870
871 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
872
873 break;
874 default:
875 break;
876 }
877
878}
879
880int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
881{
882 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
883 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
884 struct ieee80211_rate *rate;
885 struct ieee80211_key_conf *tx_key;
886 struct ieee80211_hdr *hdr;
887 struct vnt_mic_hdr *mic_hdr = NULL;
888 struct vnt_tx_buffer *tx_buffer;
889 struct vnt_tx_fifo_head *tx_buffer_head;
890 struct vnt_usb_send_context *tx_context;
891 unsigned long flags;
892 u32 frame_size = 0;
893 u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
894 u8 pkt_type, fb_option = AUTO_FB_NONE;
895 bool need_rts = false, need_ack = false, is_pspoll = false;
896 bool need_mic = false;
897
898 hdr = (struct ieee80211_hdr *)(skb->data);
899
900 rate = ieee80211_get_tx_rate(priv->hw, info);
901
902 current_rate = rate->hw_value;
903 if (priv->wCurrentRate != current_rate) {
904 priv->wCurrentRate = current_rate;
905 bScheduleCommand(priv, WLAN_CMD_SETPOWER, NULL);
906 }
907
908 if (current_rate > RATE_11M)
909 pkt_type = priv->byPacketType;
910 else
911 pkt_type = PK_TYPE_11B;
912
913 spin_lock_irqsave(&priv->lock, flags);
914
915 tx_context = s_vGetFreeContext(priv);
916 if (!tx_context) {
917 dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
918 spin_unlock_irqrestore(&priv->lock, flags);
919 return -ENOMEM;
920 }
921
922 tx_context->skb = skb;
923
924 spin_unlock_irqrestore(&priv->lock, flags);
925
926 tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
927 tx_buffer_head = &tx_buffer->fifo_head;
928 tx_body_size = skb->len;
929
930 frame_size = tx_body_size + 4;
931
d38b13aa
MP
932 /*Set fifo controls */
933 if (pkt_type == PK_TYPE_11A)
934 tx_buffer_head->wFIFOCtl = 0;
935 else if (pkt_type == PK_TYPE_11B)
936 tx_buffer_head->wFIFOCtl = FIFOCTL_11B;
937 else if (pkt_type == PK_TYPE_11GB)
938 tx_buffer_head->wFIFOCtl = FIFOCTL_11GB;
939 else if (pkt_type == PK_TYPE_11GA)
940 tx_buffer_head->wFIFOCtl = FIFOCTL_11GA;
941
942 if (!ieee80211_is_data(hdr->frame_control)) {
943 tx_buffer_head->wFIFOCtl |= (FIFOCTL_GENINT |
944 FIFOCTL_ISDMA0);
945 tx_buffer_head->wFIFOCtl |= FIFOCTL_TMOEN;
946
947 tx_buffer_head->time_stamp =
948 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
949 } else {
950 tx_buffer_head->time_stamp =
951 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
952 }
953
954 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
955 tx_buffer_head->wFIFOCtl |= FIFOCTL_NEEDACK;
956 need_ack = true;
957 }
958
959 if (ieee80211_has_retry(hdr->frame_control))
960 tx_buffer_head->wFIFOCtl |= FIFOCTL_LRETRY;
961
962 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
963 priv->byPreambleType = PREAMBLE_SHORT;
964 else
965 priv->byPreambleType = PREAMBLE_LONG;
966
967 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
968 need_rts = true;
969 tx_buffer_head->wFIFOCtl |= FIFOCTL_RTS;
970 }
971
972 if (ieee80211_has_a4(hdr->frame_control))
973 tx_buffer_head->wFIFOCtl |= FIFOCTL_LHEAD;
974
975 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
976 is_pspoll = true;
977
5deb1cfa
MP
978 tx_buffer_head->frag_ctl =
979 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
d38b13aa
MP
980
981 if (info->control.hw_key) {
982 tx_key = info->control.hw_key;
983 switch (info->control.hw_key->cipher) {
984 case WLAN_CIPHER_SUITE_WEP40:
985 case WLAN_CIPHER_SUITE_WEP104:
5deb1cfa 986 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
d38b13aa
MP
987 break;
988 case WLAN_CIPHER_SUITE_TKIP:
5deb1cfa 989 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
d38b13aa
MP
990 break;
991 case WLAN_CIPHER_SUITE_CCMP:
5deb1cfa 992 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
d38b13aa
MP
993 need_mic = true;
994 default:
995 break;
996 }
997 frame_size += tx_key->icv_len;
998 }
999
1000 /* legacy rates TODO use ieee80211_tx_rate */
1001 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
1002 if (priv->byAutoFBCtrl == AUTO_FB_0) {
1003 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1004
1005 priv->tx_rate_fb0 =
1006 wFB_Opt0[FB_RATE0][current_rate - RATE_18M];
1007 priv->tx_rate_fb1 =
1008 wFB_Opt0[FB_RATE1][current_rate - RATE_18M];
1009
1010 fb_option = AUTO_FB_0;
1011 } else if (priv->byAutoFBCtrl == AUTO_FB_1) {
1012 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1013
1014 priv->tx_rate_fb0 =
1015 wFB_Opt1[FB_RATE0][current_rate - RATE_18M];
1016 priv->tx_rate_fb1 =
1017 wFB_Opt1[FB_RATE1][current_rate - RATE_18M];
1018
1019 fb_option = AUTO_FB_1;
1020 }
1021 }
1022
1023 duration_id = s_vGenerateTxParameter(tx_context, pkt_type, current_rate,
1024 tx_buffer, &mic_hdr, need_mic, frame_size,
1025 need_ack, NULL, need_rts);
1026
1027 tx_header_size = tx_context->tx_hdr_size;
1028 if (!tx_header_size) {
1029 tx_context->in_use = false;
1030 return -ENOMEM;
1031 }
1032
5deb1cfa 1033 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
d38b13aa
MP
1034
1035 tx_bytes = tx_header_size + tx_body_size;
1036
1037 memcpy(tx_context->hdr, skb->data, tx_body_size);
1038
1039 hdr->duration_id = cpu_to_le16(duration_id);
1040
1041 if (info->control.hw_key) {
1042 tx_key = info->control.hw_key;
1043 if (tx_key->keylen > 0)
1044 vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
1045 tx_key, skb, tx_body_size, mic_hdr);
1046 }
1047
1048 priv->wSeqCounter = (le16_to_cpu(hdr->seq_ctrl) &
1049 IEEE80211_SCTL_SEQ) >> 4;
1050
1051 tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
1052 tx_buffer->byPKTNO = (u8)(((current_rate << 4) & 0xf0) |
1053 (priv->wSeqCounter & 0xf));
1054 tx_buffer->byType = 0x00;
1055
1056 tx_bytes += 4;
1057
1058 tx_context->type = CONTEXT_DATA_PACKET;
1059 tx_context->buf_len = tx_bytes;
1060
1061 spin_lock_irqsave(&priv->lock, flags);
1062
1063 if (PIPEnsSendBulkOut(priv, tx_context) != STATUS_PENDING) {
1064 spin_unlock_irqrestore(&priv->lock, flags);
1065 return -EIO;
1066 }
1067
1068 spin_unlock_irqrestore(&priv->lock, flags);
1069
1070 return 0;
1071}
1072
1073static int vnt_beacon_xmit(struct vnt_private *priv,
1074 struct sk_buff *skb)
1075{
1076 struct vnt_beacon_buffer *beacon_buffer;
1077 struct vnt_tx_short_buf_head *short_head;
1078 struct ieee80211_tx_info *info;
1079 struct vnt_usb_send_context *context;
1080 struct ieee80211_mgmt *mgmt_hdr;
1081 unsigned long flags;
1082 u32 frame_size = skb->len + 4;
1083 u16 current_rate, count;
1084
1085 spin_lock_irqsave(&priv->lock, flags);
1086
1087 context = s_vGetFreeContext(priv);
1088 if (!context) {
1089 dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
1090 spin_unlock_irqrestore(&priv->lock, flags);
1091 return -ENOMEM;
1092 }
1093
1094 context->skb = skb;
1095
1096 spin_unlock_irqrestore(&priv->lock, flags);
1097
1098 beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
1099 short_head = &beacon_buffer->short_head;
1100
1101 if (priv->byBBType == BB_TYPE_11A) {
1102 current_rate = RATE_6M;
1103
1104 /* Get SignalField,ServiceField,Length */
1105 vnt_get_phy_field(priv, frame_size, current_rate,
1106 PK_TYPE_11A, &short_head->ab);
1107
1108 /* Get Duration and TimeStampOff */
1109 short_head->duration = s_uGetDataDuration(priv,
1110 PK_TYPE_11A, false);
1111 short_head->time_stamp_off =
1112 vnt_time_stamp_off(priv, current_rate);
1113 } else {
1114 current_rate = RATE_1M;
1115 short_head->fifo_ctl |= FIFOCTL_11B;
1116
1117 /* Get SignalField,ServiceField,Length */
1118 vnt_get_phy_field(priv, frame_size, current_rate,
1119 PK_TYPE_11B, &short_head->ab);
1120
1121 /* Get Duration and TimeStampOff */
1122 short_head->duration = s_uGetDataDuration(priv,
1123 PK_TYPE_11B, false);
1124 short_head->time_stamp_off =
1125 vnt_time_stamp_off(priv, current_rate);
1126 }
1127
1128 /* Generate Beacon Header */
1129 mgmt_hdr = &beacon_buffer->mgmt_hdr;
1130 memcpy(mgmt_hdr, skb->data, skb->len);
1131
1132 /* time stamp always 0 */
1133 mgmt_hdr->u.beacon.timestamp = 0;
1134
1135 info = IEEE80211_SKB_CB(skb);
1136 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1137 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
1138 hdr->duration_id = 0;
1139 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
1140 }
1141
1142 priv->wSeqCounter++;
1143 if (priv->wSeqCounter > 0x0fff)
1144 priv->wSeqCounter = 0;
1145
1146 count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
1147
1148 beacon_buffer->tx_byte_count = cpu_to_le16(count);
1149 beacon_buffer->byPKTNO = (u8)(((current_rate << 4) & 0xf0) |
1150 ((priv->wSeqCounter - 1) & 0x000f));
1151 beacon_buffer->byType = 0x01;
1152
1153 context->type = CONTEXT_BEACON_PACKET;
1154 context->buf_len = count + 4; /* USB header */
1155
1156 spin_lock_irqsave(&priv->lock, flags);
1157
1158 if (PIPEnsSendBulkOut(priv, context) != STATUS_PENDING)
1159 ieee80211_free_txskb(priv->hw, context->skb);
1160
1161 spin_unlock_irqrestore(&priv->lock, flags);
1162
1163 return 0;
1164}
1165
1166int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1167{
1168 struct sk_buff *beacon;
1169
1170 beacon = ieee80211_beacon_get(priv->hw, vif);
1171 if (!beacon)
1172 return -ENOMEM;
1173
1174 if (vnt_beacon_xmit(priv, beacon)) {
1175 ieee80211_free_txskb(priv->hw, beacon);
1176 return -ENODEV;
1177 }
1178
1179 return 0;
1180}
1181
1182int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1183 struct ieee80211_bss_conf *conf)
1184{
1185 int ret;
1186
1187 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1188
1189 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1190
1191 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
1192
1193 vnt_clear_current_tsf(priv);
1194
1195 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1196
1197 vnt_reset_next_tbtt(priv, conf->beacon_int);
1198
1199 ret = vnt_beacon_make(priv, vif);
1200
1201 return ret;
1202}