blob: c8a38c5172bf8e61cbbebda72577d1d2317685bb [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
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:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * 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
Gilles Espinassef77f13e2010-03-29 15:41:47 +020033 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040034 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
35 * s_uGetTxRsvTime- get frame reserved time
36 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020037 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040038 * s_vFillRTSHead- fulfill RTS ctl header
Forest Bond92b96792009-06-13 07:38:31 -040039 * vDMA0_tx_80211- tx 802.11 frame via dma0
40 * vGenerateFIFOHeader- Generate tx FIFO ctl header
41 *
42 * Revision History:
43 *
44 */
45
Forest Bond92b96792009-06-13 07:38:31 -040046#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040047#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040048#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040049#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "usbpipe.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070052
Mariano Reingart4a499de2010-10-29 19:15:26 -030053static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040054
Valentina Manea3b138852013-11-04 10:44:02 +020055static const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040056 {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
Valentina Manea3b138852013-11-04 10:44:02 +020060static const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040061 {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 };
Valentina Manea3b138852013-11-04 10:44:02 +020064static const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040065 {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
Forest Bond92b96792009-06-13 07:38:31 -040069#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
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000084static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000085
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +010086static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley8e344c82013-09-17 19:58:11 +010087 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +010088 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
Malcolm Priestley72bf8052014-07-10 19:56:02 +010089 int bNeedACK, bool need_rts);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000090
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000091static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
92 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -040093
Malcolm Priestley20338012014-03-18 19:25:08 +000094static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +010095 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate);
Forest Bond92b96792009-06-13 07:38:31 -040096
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +010097static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +010098 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
Malcolm Priestley26e73622014-07-10 19:56:04 +010099 int bNeedAck, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400100
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100101static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100102 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100103 u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400104
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000105static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100106 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400107
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000108static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000109 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100110 int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400111
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000112static struct vnt_usb_send_context
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000113 *s_vGetFreeContext(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400114{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000115 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000116 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000118 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400119
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000120 for (ii = 0; ii < priv->cbTD; ii++) {
121 if (!priv->apTD[ii])
122 return NULL;
123
124 context = priv->apTD[ii];
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100125 if (context->in_use == false) {
126 context->in_use = true;
127 memset(context->data, 0,
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000128 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100129
130 context->hdr = NULL;
131
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000132 return context;
133 }
134 }
135
136 if (ii == priv->cbTD)
137 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000138
Malcolm Priestley5c851382013-11-26 19:12:38 +0000139 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400140}
141
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000142static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100143{
144 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
145 [rate % MAX_RATE]);
146}
147
Forest Bond92b96792009-06-13 07:38:31 -0400148/*byPktType : PK_TYPE_11A 0
149 PK_TYPE_11B 1
150 PK_TYPE_11GB 2
151 PK_TYPE_11GA 3
152*/
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000153static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
154 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400155{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000156 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400157
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100158 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000159 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400160
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000161 if (pkt_type == PK_TYPE_11B)
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100162 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
163 14, (u16)priv->byTopCCKBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000164 else
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100165 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
166 14, (u16)priv->byTopOFDMBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000167
168 if (need_ack)
169 return data_time + priv->uSIFS + ack_time;
170
171 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400172}
173
Malcolm Priestley2075f652014-03-18 19:25:07 +0000174static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100175 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
Forest Bond92b96792009-06-13 07:38:31 -0400181//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley20338012014-03-18 19:25:08 +0000182static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100183 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400184{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000185 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400186
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000187 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400188
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100189 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100190 frame_length, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400191
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000192 if (rsv_type == 0) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100193 rts_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000194 pkt_type, 20, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100195 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000196 pkt_type, 14, priv->byTopCCKBasicRate);
197 } else if (rsv_type == 1) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100198 rts_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000199 pkt_type, 20, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100200 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000201 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100202 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000203 14, priv->byTopOFDMBasicRate);
204 } else if (rsv_type == 2) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100205 rts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000206 20, priv->byTopOFDMBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100207 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000208 pkt_type, 14, priv->byTopOFDMBasicRate);
209 } else if (rsv_type == 3) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100210 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000211 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100212 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000213 14, priv->byTopOFDMBasicRate);
214
215 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
216
Malcolm Priestley20338012014-03-18 19:25:08 +0000217 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000218 }
219
220 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
221
222 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400223}
224
225//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000226static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100227 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400228{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100229 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400230
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100231 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100232 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100233 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100234 byPktType, 14, pDevice->byTopCCKBasicRate);
235 else
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100236 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100237 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100238 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100239 }
Forest Bond92b96792009-06-13 07:38:31 -0400240
Forest Bond92b96792009-06-13 07:38:31 -0400241 return 0;
242}
243
Forest Bond92b96792009-06-13 07:38:31 -0400244//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000245static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100246 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400247{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000248 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400249
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100250 switch (byDurType) {
251 case RTSDUR_BB:
252 case RTSDUR_BA:
253 case RTSDUR_BA_F0:
254 case RTSDUR_BA_F1:
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100255 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
256 byPktType, 14, pDevice->byTopCCKBasicRate);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100257 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
258 s_uGetTxRsvTime(pDevice, byPktType,
259 cbFrameLength, wRate, bNeedAck);
260 break;
Forest Bond92b96792009-06-13 07:38:31 -0400261
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100262 case RTSDUR_AA:
263 case RTSDUR_AA_F0:
264 case RTSDUR_AA_F1:
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100265 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
266 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100267 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
268 s_uGetTxRsvTime(pDevice, byPktType,
269 cbFrameLength, wRate, bNeedAck);
270 break;
Forest Bond92b96792009-06-13 07:38:31 -0400271
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100272 case CTSDUR_BA:
273 case CTSDUR_BA_F0:
274 case CTSDUR_BA_F1:
275 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100276 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100277 break;
Forest Bond92b96792009-06-13 07:38:31 -0400278
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100279 default:
280 break;
281 }
Forest Bond92b96792009-06-13 07:38:31 -0400282
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100283 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400284}
285
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100286static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
287 struct ieee80211_hdr *hdr)
288{
289 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
290 u8 *hdr_pos = (u8 *)hdr;
291
292 tx_context->hdr = hdr;
293 if (!tx_context->hdr)
294 return 0;
295
296 return (u16)(hdr_pos - head);
297}
298
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100299static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
300 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf,
301 u32 frame_len, int need_ack)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100302{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100303
304 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100305 struct ieee80211_hdr *hdr =
306 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100307
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100308 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100309 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
310 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100311 PK_TYPE_11B, &buf->b);
312
313 /* Get Duration and TimeStamp */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100314 if (ieee80211_is_pspoll(hdr->frame_control)) {
315 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
316
317 buf->duration_a = dur;
318 buf->duration_b = dur;
319 } else {
320 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
321 buf->duration_b = s_uGetDataDuration(priv,
322 PK_TYPE_11B, need_ack);
323 }
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100324
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000325 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
326 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100327 priv->byTopCCKBasicRate);
328
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100329 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
330
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000331 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100332}
333
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100334static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
335 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100336 u32 frame_len, int need_ack)
337{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100338 struct vnt_private *priv = tx_context->priv;
339
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100340 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100341 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100342
Malcolm Priestley205056f2014-06-04 18:25:34 +0100343 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100344 PK_TYPE_11B, &buf->b);
345
346 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000347 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
348 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100349
Malcolm Priestley4e011172014-03-18 19:24:55 +0000350 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
351 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100352
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000353 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
354 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100355 priv->byTopCCKBasicRate);
356
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100357 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
358
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000359 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100360}
361
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100362static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
363 u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100364 u32 frame_len, int need_ack)
365{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100366 struct vnt_private *priv = tx_context->priv;
367
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100368 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100369 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100370 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000371 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100372
Malcolm Priestley4e011172014-03-18 19:24:55 +0000373 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
374 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100375
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000376 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100377
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100378 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
379
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000380 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100381}
382
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100383static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
384 u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100385 u32 frame_len, int need_ack)
386{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100387 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100388 struct ieee80211_hdr *hdr =
389 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100390
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100391 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100392 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->ab);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100393
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100394 /* Get Duration and TimeStampOff */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100395 if (ieee80211_is_pspoll(hdr->frame_control)) {
396 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
397
398 buf->duration = dur;
399 } else {
400 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
401 }
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100402
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000403 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100404
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100405 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
406
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000407 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100408}
409
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100410static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
411 struct ieee80211_rts *rts, __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100412{
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100413 struct ieee80211_hdr *hdr =
414 (struct ieee80211_hdr *)tx_context->skb->data;
415
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100416 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000417 rts->frame_control =
418 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100419
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100420 memcpy(rts->ra, hdr->addr1, ETH_ALEN);
421 memcpy(rts->ta, hdr->addr2, ETH_ALEN);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100422
423 return 0;
424}
425
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100426static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100427 struct vnt_rts_g *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100428 u16 current_rate)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100429{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100430 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100431 u16 rts_frame_len = 20;
432
Malcolm Priestley205056f2014-06-04 18:25:34 +0100433 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100434 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100435 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100436 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
437
Malcolm Priestley4e011172014-03-18 19:24:55 +0000438 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100439 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000440 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100441 pkt_type, current_rate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000442 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100443 pkt_type, current_rate, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100444
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100445 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100446
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100447 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100448 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100449}
450
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100451static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100452 struct vnt_rts_g_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100453 u16 current_rate)
Malcolm Priestleyec917132013-08-26 11:07:46 +0100454{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100455 struct vnt_private *priv = tx_context->priv;
Malcolm Priestleyec917132013-08-26 11:07:46 +0100456 u16 rts_frame_len = 20;
457
Malcolm Priestley205056f2014-06-04 18:25:34 +0100458 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100459 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100460 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100461 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
462
463
Malcolm Priestley4e011172014-03-18 19:24:55 +0000464 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100465 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000466 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100467 pkt_type, current_rate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000468 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100469 pkt_type, current_rate, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100470
471
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000472 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100473 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000474 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100475 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000476 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100477 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000478 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100479 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100480
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100481 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100482
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100483 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100484 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100485}
486
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100487static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100488 struct vnt_rts_ab *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100489 u16 current_rate)
Malcolm Priestley17126332013-08-26 11:09:38 +0100490{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100491 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley17126332013-08-26 11:09:38 +0100492 u16 rts_frame_len = 20;
493
Malcolm Priestley205056f2014-06-04 18:25:34 +0100494 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100495 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
496
Malcolm Priestley4e011172014-03-18 19:24:55 +0000497 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100498 pkt_type, current_rate, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100499
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100500 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100501
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100502 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100503 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100504}
505
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100506static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100507 struct vnt_rts_a_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100508 u16 current_rate)
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100509{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100510 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100511 u16 rts_frame_len = 20;
512
Malcolm Priestley205056f2014-06-04 18:25:34 +0100513 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100514 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
515
Malcolm Priestley4e011172014-03-18 19:24:55 +0000516 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100517 pkt_type, current_rate, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100518
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000519 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100520 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100521
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000522 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100523 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100524
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100525 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100526
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100527 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100528 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100529}
530
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100531static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100532 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100533 u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400534{
Forest Bond92b96792009-06-13 07:38:31 -0400535
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100536 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100537 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400538
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100539 /* Note: So far RTSHead doesn't appear in ATIM
540 * & Beacom DMA, so we don't need to take them
541 * into account.
542 * Otherwise, we need to modified codes for them.
543 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100544 switch (byPktType) {
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100545 case PK_TYPE_11A:
Malcolm Priestleyce7b0db2014-07-10 19:56:03 +0100546 if (tx_context->fb_option) {
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100547 return vnt_rxtx_rts_a_fb_head(tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100548 &head->rts_a_fb, byPktType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100549 cbFrameLength, bNeedAck, wCurrentRate);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100550 break;
551 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100552 case PK_TYPE_11B:
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100553 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100554 byPktType, cbFrameLength, bNeedAck,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100555 wCurrentRate);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100556 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100557
558 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400559}
560
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100561static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100562 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100563 int bNeedAck, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400564{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100565 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000566 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400567
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100568 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100569 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400570
Malcolm Priestleyce7b0db2014-07-10 19:56:03 +0100571 if (tx_context->fb_option) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100572 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100573 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100574 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100575 vnt_get_phy_field(pDevice, uCTSFrameLen,
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100576 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000577 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100578 cbFrameLength, byPktType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100579 wCurrentRate, bNeedAck);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100580 /* Get CTSDuration_ba_f0 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000581 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100582 CTSDUR_BA_F0, cbFrameLength, byPktType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100583 pDevice->tx_rate_fb0, bNeedAck);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100584 /* Get CTSDuration_ba_f1 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000585 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100586 CTSDUR_BA_F1, cbFrameLength, byPktType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100587 pDevice->tx_rate_fb1, bNeedAck);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100588 /* Get CTS Frame body */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000589 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000590 pBuf->data.frame_control =
591 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
592
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100593 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100594
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100595 return vnt_rxtx_datahead_g_fb(tx_context, byPktType,
596 wCurrentRate, &pBuf->data_head, cbFrameLength,
597 bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100598 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100599 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100600 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100601 vnt_get_phy_field(pDevice, uCTSFrameLen,
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100602 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100603 /* Get CTSDuration_ba */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000604 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100605 CTSDUR_BA, cbFrameLength, byPktType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100606 wCurrentRate, bNeedAck);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100607 /*Get CTS Frame body*/
Malcolm Priestley4e011172014-03-18 19:24:55 +0000608 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000609 pBuf->data.frame_control =
610 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
611
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100612 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100613
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100614 return vnt_rxtx_datahead_g(tx_context, byPktType, wCurrentRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100615 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400616 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100617
618 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400619}
620
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100621static u16 vnt_rxtx_rts(struct vnt_usb_send_context *tx_context,
622 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100623 int need_ack, u16 current_rate, bool need_mic)
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100624{
625 struct vnt_private *priv = tx_context->priv;
626 struct vnt_rrv_time_rts *buf = &tx_head->tx_rts.rts;
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100627 union vnt_tx_data_head *head = &tx_head->tx_rts.tx.head;
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100628
629 buf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(priv, 2,
630 pkt_type, frame_size, current_rate);
631 buf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(priv, 1,
632 pkt_type, frame_size, current_rate);
633 buf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(priv, 0,
634 pkt_type, frame_size, current_rate);
635
636 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, pkt_type, frame_size,
637 current_rate, need_ack);
638 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B, frame_size,
639 priv->byTopCCKBasicRate, need_ack);
640
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100641 if (need_mic)
642 head = &tx_head->tx_rts.tx.mic.head;
643
644 if (tx_context->fb_option)
645 return vnt_rxtx_rts_g_fb_head(tx_context, &head->rts_g_fb,
646 pkt_type, frame_size, need_ack, current_rate);
647
648 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g,
649 pkt_type, frame_size, need_ack, current_rate);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100650}
651
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100652static u16 vnt_rxtx_cts(struct vnt_usb_send_context *tx_context,
653 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100654 int need_ack, u16 current_rate, bool need_mic)
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100655{
656 struct vnt_private *priv = tx_context->priv;
657 struct vnt_rrv_time_cts *buf = &tx_head->tx_cts.cts;
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100658 union vnt_tx_data_head *head = &tx_head->tx_cts.tx.head;
659
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100660
661 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, pkt_type,
662 frame_size, current_rate, need_ack);
663 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B,
664 frame_size, priv->byTopCCKBasicRate, need_ack);
665
666 buf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(priv, 3,
667 pkt_type, frame_size, current_rate);
668
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100669 if (need_mic)
670 head = &tx_head->tx_cts.tx.mic.head;
671
672 /* Fill CTS */
673 return s_vFillCTSHead(tx_context, pkt_type, head, frame_size,
674 need_ack, current_rate);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100675}
676
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100677static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context,
678 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
679 int need_ack, u16 current_rate, bool need_rts)
680{
681 struct vnt_private *priv = tx_context->priv;
682 struct vnt_rrv_time_ab *buf = &tx_head->tx_ab.ab;
683
684 buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, pkt_type,
685 frame_size, current_rate, need_ack);
686
687 if (need_rts) {
688 if (pkt_type == PK_TYPE_11B)
689 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(priv, 0,
690 pkt_type, frame_size, current_rate);
691 else /* PK_TYPE_11A */
692 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(priv, 2,
693 pkt_type, frame_size, current_rate);
694 }
695
696 return 0;
697}
698
Forest Bond92b96792009-06-13 07:38:31 -0400699/*+
700 *
701 * Description:
702 * Generate FIFO control for MAC & Baseband controller
703 *
704 * Parameters:
705 * In:
706 * pDevice - Pointer to adpater
707 * pTxDataHead - Transmit Data Buffer
708 * pTxBufHead - pTxBufHead
709 * pvRrvTime - pvRrvTime
710 * pvRTS - RTS Buffer
711 * pCTS - CTS Buffer
712 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
713 * bNeedACK - If need ACK
Forest Bond92b96792009-06-13 07:38:31 -0400714 * Out:
715 * none
716 *
717 * Return Value: none
718 *
719-*/
Andres Morecc856e62010-05-17 21:34:01 -0300720
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100721static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100722 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100723 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100724 int bNeedACK, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400725{
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100726 union vnt_tx_data_head *head = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400727
Malcolm Priestley92928f12013-10-07 20:14:01 +0100728 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
729 if (need_rts) {
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100730 if (need_mic)
Malcolm Priestley92928f12013-10-07 20:14:01 +0100731 *mic_hdr = &tx_buffer->
732 tx_head.tx_rts.tx.mic.hdr;
Malcolm Priestley92928f12013-10-07 20:14:01 +0100733
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100734 return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head,
735 byPktType, cbFrameSize, bNeedACK,
736 wCurrentRate, need_mic);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100737 } else {
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100738 if (need_mic)
Malcolm Priestley92928f12013-10-07 20:14:01 +0100739 *mic_hdr = &tx_buffer->
740 tx_head.tx_cts.tx.mic.hdr;
Malcolm Priestley92928f12013-10-07 20:14:01 +0100741
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100742 return vnt_rxtx_cts(tx_context, &tx_buffer->tx_head,
743 byPktType, cbFrameSize, bNeedACK,
744 wCurrentRate, need_mic);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100745 }
746 } else if (byPktType == PK_TYPE_11A) {
747 if (need_mic) {
748 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
749 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
750 } else {
751 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100752 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100753
Malcolm Priestley92928f12013-10-07 20:14:01 +0100754 if (need_rts) {
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100755 vnt_rxtx_ab(tx_context, &tx_buffer->tx_head, byPktType,
756 cbFrameSize, bNeedACK, wCurrentRate, need_rts);
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100757
Malcolm Priestley92928f12013-10-07 20:14:01 +0100758
759 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100760 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100761 cbFrameSize, bNeedACK,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100762 wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100763 } else {
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100764 vnt_rxtx_ab(tx_context, &tx_buffer->tx_head, byPktType,
765 cbFrameSize, bNeedACK, wCurrentRate, need_rts);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100766
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100767 return vnt_rxtx_datahead_a_fb(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100768 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;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100777 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100778
Malcolm Priestley92928f12013-10-07 20:14:01 +0100779 if (need_rts) {
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100780 vnt_rxtx_ab(tx_context, &tx_buffer->tx_head, byPktType,
781 cbFrameSize, bNeedACK, wCurrentRate, need_rts);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100782
783 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100784 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100785 cbFrameSize, bNeedACK,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100786 wCurrentRate);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100787 } else {
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100788 vnt_rxtx_ab(tx_context, &tx_buffer->tx_head, byPktType,
789 cbFrameSize, bNeedACK, wCurrentRate, need_rts);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100790
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100791 return vnt_rxtx_datahead_ab(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100792 wCurrentRate, &head->data_head_ab,
793 cbFrameSize, bNeedACK);
794 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100795 }
796
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100797 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400798}
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100799
800static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
801 u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
802 u16 payload_len, struct vnt_mic_hdr *mic_hdr)
803{
804 struct ieee80211_hdr *hdr = tx_context->hdr;
805 struct ieee80211_key_seq seq;
806 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
807
808 /* strip header and icv len from payload */
809 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
810 payload_len -= tx_key->icv_len;
811
812 switch (tx_key->cipher) {
813 case WLAN_CIPHER_SUITE_WEP40:
814 case WLAN_CIPHER_SUITE_WEP104:
815 memcpy(key_buffer, iv, 3);
816 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
817
818 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
819 memcpy(key_buffer + 8, iv, 3);
820 memcpy(key_buffer + 11,
821 tx_key->key, WLAN_KEY_LEN_WEP40);
822 }
823
824 break;
825 case WLAN_CIPHER_SUITE_TKIP:
826 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
827
828 break;
829 case WLAN_CIPHER_SUITE_CCMP:
830
831 if (!mic_hdr)
832 return;
833
834 mic_hdr->id = 0x59;
835 mic_hdr->payload_len = cpu_to_be16(payload_len);
836 memcpy(mic_hdr->mic_addr2, hdr->addr2, ETH_ALEN);
837
838 ieee80211_get_key_tx_seq(tx_key, &seq);
839
Malcolm Priestley79f976d2014-06-28 23:55:39 +0100840 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100841
842 if (ieee80211_has_a4(hdr->frame_control))
843 mic_hdr->hlen = cpu_to_be16(28);
844 else
845 mic_hdr->hlen = cpu_to_be16(22);
846
847 memcpy(mic_hdr->addr1, hdr->addr1, ETH_ALEN);
848 memcpy(mic_hdr->addr2, hdr->addr2, ETH_ALEN);
849 memcpy(mic_hdr->addr3, hdr->addr3, ETH_ALEN);
850
851 mic_hdr->frame_control = cpu_to_le16(
852 le16_to_cpu(hdr->frame_control) & 0xc78f);
853 mic_hdr->seq_ctrl = cpu_to_le16(
854 le16_to_cpu(hdr->seq_ctrl) & 0xf);
855
856 if (ieee80211_has_a4(hdr->frame_control))
857 memcpy(mic_hdr->addr4, hdr->addr4, ETH_ALEN);
858
859
860 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
861
862 break;
863 default:
864 break;
865 }
866
867}
868
869int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
870{
871 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
872 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
873 struct ieee80211_rate *rate;
874 struct ieee80211_key_conf *tx_key;
875 struct ieee80211_hdr *hdr;
876 struct vnt_mic_hdr *mic_hdr = NULL;
877 struct vnt_tx_buffer *tx_buffer;
878 struct vnt_tx_fifo_head *tx_buffer_head;
879 struct vnt_usb_send_context *tx_context;
880 unsigned long flags;
881 u32 frame_size = 0;
882 u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
883 u8 pkt_type, fb_option = AUTO_FB_NONE;
884 bool need_rts = false, need_ack = false, is_pspoll = false;
885 bool need_mic = false;
886
887 hdr = (struct ieee80211_hdr *)(skb->data);
888
889 rate = ieee80211_get_tx_rate(priv->hw, info);
890
891 current_rate = rate->hw_value;
Malcolm Priestley5091d962014-07-05 19:24:23 +0100892 if (priv->wCurrentRate != current_rate &&
893 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100894 priv->wCurrentRate = current_rate;
895 bScheduleCommand(priv, WLAN_CMD_SETPOWER, NULL);
896 }
897
898 if (current_rate > RATE_11M)
899 pkt_type = priv->byPacketType;
900 else
901 pkt_type = PK_TYPE_11B;
902
903 spin_lock_irqsave(&priv->lock, flags);
904
905 tx_context = s_vGetFreeContext(priv);
906 if (!tx_context) {
907 dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
908 spin_unlock_irqrestore(&priv->lock, flags);
909 return -ENOMEM;
910 }
911
912 tx_context->skb = skb;
913
914 spin_unlock_irqrestore(&priv->lock, flags);
915
916 tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
917 tx_buffer_head = &tx_buffer->fifo_head;
918 tx_body_size = skb->len;
919
920 frame_size = tx_body_size + 4;
921
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100922 /*Set fifo controls */
923 if (pkt_type == PK_TYPE_11A)
924 tx_buffer_head->wFIFOCtl = 0;
925 else if (pkt_type == PK_TYPE_11B)
926 tx_buffer_head->wFIFOCtl = FIFOCTL_11B;
927 else if (pkt_type == PK_TYPE_11GB)
928 tx_buffer_head->wFIFOCtl = FIFOCTL_11GB;
929 else if (pkt_type == PK_TYPE_11GA)
930 tx_buffer_head->wFIFOCtl = FIFOCTL_11GA;
931
932 if (!ieee80211_is_data(hdr->frame_control)) {
933 tx_buffer_head->wFIFOCtl |= (FIFOCTL_GENINT |
934 FIFOCTL_ISDMA0);
935 tx_buffer_head->wFIFOCtl |= FIFOCTL_TMOEN;
936
937 tx_buffer_head->time_stamp =
938 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
939 } else {
940 tx_buffer_head->time_stamp =
941 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
942 }
943
944 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
945 tx_buffer_head->wFIFOCtl |= FIFOCTL_NEEDACK;
946 need_ack = true;
947 }
948
949 if (ieee80211_has_retry(hdr->frame_control))
950 tx_buffer_head->wFIFOCtl |= FIFOCTL_LRETRY;
951
952 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
953 priv->byPreambleType = PREAMBLE_SHORT;
954 else
955 priv->byPreambleType = PREAMBLE_LONG;
956
957 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
958 need_rts = true;
959 tx_buffer_head->wFIFOCtl |= FIFOCTL_RTS;
960 }
961
962 if (ieee80211_has_a4(hdr->frame_control))
963 tx_buffer_head->wFIFOCtl |= FIFOCTL_LHEAD;
964
965 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
966 is_pspoll = true;
967
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100968 tx_buffer_head->frag_ctl =
969 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100970
971 if (info->control.hw_key) {
972 tx_key = info->control.hw_key;
973 switch (info->control.hw_key->cipher) {
974 case WLAN_CIPHER_SUITE_WEP40:
975 case WLAN_CIPHER_SUITE_WEP104:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100976 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100977 break;
978 case WLAN_CIPHER_SUITE_TKIP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100979 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100980 break;
981 case WLAN_CIPHER_SUITE_CCMP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100982 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100983 need_mic = true;
984 default:
985 break;
986 }
987 frame_size += tx_key->icv_len;
988 }
989
Malcolm Priestleycb8ee9de2014-07-10 19:56:05 +0100990 tx_buffer_head->current_rate = cpu_to_le16(current_rate);
991
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100992 /* legacy rates TODO use ieee80211_tx_rate */
993 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
994 if (priv->byAutoFBCtrl == AUTO_FB_0) {
995 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
996
997 priv->tx_rate_fb0 =
998 wFB_Opt0[FB_RATE0][current_rate - RATE_18M];
999 priv->tx_rate_fb1 =
1000 wFB_Opt0[FB_RATE1][current_rate - RATE_18M];
1001
1002 fb_option = AUTO_FB_0;
1003 } else if (priv->byAutoFBCtrl == AUTO_FB_1) {
1004 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1005
1006 priv->tx_rate_fb0 =
1007 wFB_Opt1[FB_RATE0][current_rate - RATE_18M];
1008 priv->tx_rate_fb1 =
1009 wFB_Opt1[FB_RATE1][current_rate - RATE_18M];
1010
1011 fb_option = AUTO_FB_1;
1012 }
1013 }
1014
Malcolm Priestley71d764a2014-07-05 19:24:27 +01001015 tx_context->fb_option = fb_option;
1016
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001017 duration_id = s_vGenerateTxParameter(tx_context, pkt_type, current_rate,
1018 tx_buffer, &mic_hdr, need_mic, frame_size,
Malcolm Priestley72bf8052014-07-10 19:56:02 +01001019 need_ack, need_rts);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001020
1021 tx_header_size = tx_context->tx_hdr_size;
1022 if (!tx_header_size) {
1023 tx_context->in_use = false;
1024 return -ENOMEM;
1025 }
1026
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +01001027 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001028
1029 tx_bytes = tx_header_size + tx_body_size;
1030
1031 memcpy(tx_context->hdr, skb->data, tx_body_size);
1032
1033 hdr->duration_id = cpu_to_le16(duration_id);
1034
1035 if (info->control.hw_key) {
1036 tx_key = info->control.hw_key;
1037 if (tx_key->keylen > 0)
1038 vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
1039 tx_key, skb, tx_body_size, mic_hdr);
1040 }
1041
1042 priv->wSeqCounter = (le16_to_cpu(hdr->seq_ctrl) &
1043 IEEE80211_SCTL_SEQ) >> 4;
1044
1045 tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
Malcolm Priestley71d764a2014-07-05 19:24:27 +01001046 tx_buffer->byPKTNO = tx_context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001047 tx_buffer->byType = 0x00;
1048
1049 tx_bytes += 4;
1050
1051 tx_context->type = CONTEXT_DATA_PACKET;
1052 tx_context->buf_len = tx_bytes;
1053
1054 spin_lock_irqsave(&priv->lock, flags);
1055
1056 if (PIPEnsSendBulkOut(priv, tx_context) != STATUS_PENDING) {
1057 spin_unlock_irqrestore(&priv->lock, flags);
1058 return -EIO;
1059 }
1060
1061 spin_unlock_irqrestore(&priv->lock, flags);
1062
1063 return 0;
1064}
1065
1066static int vnt_beacon_xmit(struct vnt_private *priv,
1067 struct sk_buff *skb)
1068{
1069 struct vnt_beacon_buffer *beacon_buffer;
1070 struct vnt_tx_short_buf_head *short_head;
1071 struct ieee80211_tx_info *info;
1072 struct vnt_usb_send_context *context;
1073 struct ieee80211_mgmt *mgmt_hdr;
1074 unsigned long flags;
1075 u32 frame_size = skb->len + 4;
1076 u16 current_rate, count;
1077
1078 spin_lock_irqsave(&priv->lock, flags);
1079
1080 context = s_vGetFreeContext(priv);
1081 if (!context) {
1082 dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
1083 spin_unlock_irqrestore(&priv->lock, flags);
1084 return -ENOMEM;
1085 }
1086
1087 context->skb = skb;
1088
1089 spin_unlock_irqrestore(&priv->lock, flags);
1090
1091 beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
1092 short_head = &beacon_buffer->short_head;
1093
1094 if (priv->byBBType == BB_TYPE_11A) {
1095 current_rate = RATE_6M;
1096
1097 /* Get SignalField,ServiceField,Length */
1098 vnt_get_phy_field(priv, frame_size, current_rate,
1099 PK_TYPE_11A, &short_head->ab);
1100
1101 /* Get Duration and TimeStampOff */
1102 short_head->duration = s_uGetDataDuration(priv,
1103 PK_TYPE_11A, false);
1104 short_head->time_stamp_off =
1105 vnt_time_stamp_off(priv, current_rate);
1106 } else {
1107 current_rate = RATE_1M;
1108 short_head->fifo_ctl |= FIFOCTL_11B;
1109
1110 /* Get SignalField,ServiceField,Length */
1111 vnt_get_phy_field(priv, frame_size, current_rate,
1112 PK_TYPE_11B, &short_head->ab);
1113
1114 /* Get Duration and TimeStampOff */
1115 short_head->duration = s_uGetDataDuration(priv,
1116 PK_TYPE_11B, false);
1117 short_head->time_stamp_off =
1118 vnt_time_stamp_off(priv, current_rate);
1119 }
1120
1121 /* Generate Beacon Header */
1122 mgmt_hdr = &beacon_buffer->mgmt_hdr;
1123 memcpy(mgmt_hdr, skb->data, skb->len);
1124
1125 /* time stamp always 0 */
1126 mgmt_hdr->u.beacon.timestamp = 0;
1127
1128 info = IEEE80211_SKB_CB(skb);
1129 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1130 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
1131 hdr->duration_id = 0;
1132 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
1133 }
1134
1135 priv->wSeqCounter++;
1136 if (priv->wSeqCounter > 0x0fff)
1137 priv->wSeqCounter = 0;
1138
1139 count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
1140
1141 beacon_buffer->tx_byte_count = cpu_to_le16(count);
Malcolm Priestley71d764a2014-07-05 19:24:27 +01001142 beacon_buffer->byPKTNO = context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001143 beacon_buffer->byType = 0x01;
1144
1145 context->type = CONTEXT_BEACON_PACKET;
1146 context->buf_len = count + 4; /* USB header */
1147
1148 spin_lock_irqsave(&priv->lock, flags);
1149
1150 if (PIPEnsSendBulkOut(priv, context) != STATUS_PENDING)
1151 ieee80211_free_txskb(priv->hw, context->skb);
1152
1153 spin_unlock_irqrestore(&priv->lock, flags);
1154
1155 return 0;
1156}
1157
1158int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1159{
1160 struct sk_buff *beacon;
1161
1162 beacon = ieee80211_beacon_get(priv->hw, vif);
1163 if (!beacon)
1164 return -ENOMEM;
1165
1166 if (vnt_beacon_xmit(priv, beacon)) {
1167 ieee80211_free_txskb(priv->hw, beacon);
1168 return -ENODEV;
1169 }
1170
1171 return 0;
1172}
1173
1174int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1175 struct ieee80211_bss_conf *conf)
1176{
1177 int ret;
1178
1179 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1180
1181 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1182
1183 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
1184
1185 vnt_clear_current_tsf(priv);
1186
1187 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1188
1189 vnt_reset_next_tbtt(priv, conf->beacon_int);
1190
1191 ret = vnt_beacon_make(priv, vif);
1192
1193 return ret;
1194}