blob: 61138079eacb77dcca12c4b09e7d637468a3f050 [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 Priestley5abe3d62014-03-18 19:25:06 +0000101static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100102 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400103
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000104static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000105 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100106 int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400107
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000108static struct vnt_usb_send_context
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000109 *s_vGetFreeContext(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400110{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000111 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000112 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400113
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000114 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400115
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000116 for (ii = 0; ii < priv->cbTD; ii++) {
117 if (!priv->apTD[ii])
118 return NULL;
119
120 context = priv->apTD[ii];
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100121 if (context->in_use == false) {
122 context->in_use = true;
123 memset(context->data, 0,
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000124 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100125
126 context->hdr = NULL;
127
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000128 return context;
129 }
130 }
131
132 if (ii == priv->cbTD)
133 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000134
Malcolm Priestley5c851382013-11-26 19:12:38 +0000135 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400136}
137
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000138static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100139{
140 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
141 [rate % MAX_RATE]);
142}
143
Forest Bond92b96792009-06-13 07:38:31 -0400144/*byPktType : PK_TYPE_11A 0
145 PK_TYPE_11B 1
146 PK_TYPE_11GB 2
147 PK_TYPE_11GA 3
148*/
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000149static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
150 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400151{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000152 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400153
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100154 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000155 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400156
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000157 if (pkt_type == PK_TYPE_11B)
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100158 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
159 14, (u16)priv->byTopCCKBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000160 else
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100161 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
162 14, (u16)priv->byTopOFDMBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000163
164 if (need_ack)
165 return data_time + priv->uSIFS + ack_time;
166
167 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400168}
169
Malcolm Priestley2075f652014-03-18 19:25:07 +0000170static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100171 u32 frame_length, u16 rate, int need_ack)
172{
173 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
174 frame_length, rate, need_ack));
175}
176
Forest Bond92b96792009-06-13 07:38:31 -0400177//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley20338012014-03-18 19:25:08 +0000178static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100179 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400180{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000181 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400182
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000183 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400184
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100185 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100186 frame_length, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400187
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000188 if (rsv_type == 0) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100189 rts_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000190 pkt_type, 20, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100191 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000192 pkt_type, 14, priv->byTopCCKBasicRate);
193 } else if (rsv_type == 1) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100194 rts_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000195 pkt_type, 20, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100196 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000197 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100198 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000199 14, priv->byTopOFDMBasicRate);
200 } else if (rsv_type == 2) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100201 rts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000202 20, priv->byTopOFDMBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100203 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000204 pkt_type, 14, priv->byTopOFDMBasicRate);
205 } else if (rsv_type == 3) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100206 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000207 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100208 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000209 14, priv->byTopOFDMBasicRate);
210
211 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
212
Malcolm Priestley20338012014-03-18 19:25:08 +0000213 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000214 }
215
216 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
217
218 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400219}
220
221//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000222static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100223 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400224{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100225 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400226
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100227 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100228 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100229 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100230 byPktType, 14, pDevice->byTopCCKBasicRate);
231 else
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100232 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100233 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100234 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100235 }
Forest Bond92b96792009-06-13 07:38:31 -0400236
Forest Bond92b96792009-06-13 07:38:31 -0400237 return 0;
238}
239
Forest Bond92b96792009-06-13 07:38:31 -0400240//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000241static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100242 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400243{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000244 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400245
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100246 switch (byDurType) {
247 case RTSDUR_BB:
248 case RTSDUR_BA:
249 case RTSDUR_BA_F0:
250 case RTSDUR_BA_F1:
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100251 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
252 byPktType, 14, pDevice->byTopCCKBasicRate);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100253 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
254 s_uGetTxRsvTime(pDevice, byPktType,
255 cbFrameLength, wRate, bNeedAck);
256 break;
Forest Bond92b96792009-06-13 07:38:31 -0400257
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100258 case RTSDUR_AA:
259 case RTSDUR_AA_F0:
260 case RTSDUR_AA_F1:
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100261 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
262 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100263 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
264 s_uGetTxRsvTime(pDevice, byPktType,
265 cbFrameLength, wRate, bNeedAck);
266 break;
Forest Bond92b96792009-06-13 07:38:31 -0400267
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100268 case CTSDUR_BA:
269 case CTSDUR_BA_F0:
270 case CTSDUR_BA_F1:
271 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100272 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100273 break;
Forest Bond92b96792009-06-13 07:38:31 -0400274
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100275 default:
276 break;
277 }
Forest Bond92b96792009-06-13 07:38:31 -0400278
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100279 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400280}
281
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100282static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
283 struct ieee80211_hdr *hdr)
284{
285 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
286 u8 *hdr_pos = (u8 *)hdr;
287
288 tx_context->hdr = hdr;
289 if (!tx_context->hdr)
290 return 0;
291
292 return (u16)(hdr_pos - head);
293}
294
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100295static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
296 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf,
297 u32 frame_len, int need_ack)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100298{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100299
300 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100301 struct ieee80211_hdr *hdr =
302 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100303
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100304 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100305 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
306 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100307 PK_TYPE_11B, &buf->b);
308
309 /* Get Duration and TimeStamp */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100310 if (ieee80211_is_pspoll(hdr->frame_control)) {
311 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
312
313 buf->duration_a = dur;
314 buf->duration_b = dur;
315 } else {
316 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
317 buf->duration_b = s_uGetDataDuration(priv,
318 PK_TYPE_11B, need_ack);
319 }
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100320
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000321 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
322 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100323 priv->byTopCCKBasicRate);
324
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100325 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
326
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000327 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100328}
329
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100330static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
331 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100332 u32 frame_len, int need_ack)
333{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100334 struct vnt_private *priv = tx_context->priv;
335
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100336 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100337 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100338
Malcolm Priestley205056f2014-06-04 18:25:34 +0100339 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100340 PK_TYPE_11B, &buf->b);
341
342 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000343 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
344 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100345
Malcolm Priestley4e011172014-03-18 19:24:55 +0000346 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
347 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100348
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000349 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
350 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100351 priv->byTopCCKBasicRate);
352
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100353 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
354
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000355 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100356}
357
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100358static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
359 u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100360 u32 frame_len, int need_ack)
361{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100362 struct vnt_private *priv = tx_context->priv;
363
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100364 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100365 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100366 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000367 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100368
Malcolm Priestley4e011172014-03-18 19:24:55 +0000369 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
370 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100371
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000372 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100373
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100374 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
375
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000376 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100377}
378
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100379static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
380 u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100381 u32 frame_len, int need_ack)
382{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100383 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100384 struct ieee80211_hdr *hdr =
385 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100386
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100387 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100388 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->ab);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100389
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100390 /* Get Duration and TimeStampOff */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100391 if (ieee80211_is_pspoll(hdr->frame_control)) {
392 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
393
394 buf->duration = dur;
395 } else {
396 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
397 }
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100398
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000399 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100400
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100401 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
402
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000403 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100404}
405
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100406static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
407 struct ieee80211_rts *rts, __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100408{
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100409 struct ieee80211_hdr *hdr =
410 (struct ieee80211_hdr *)tx_context->skb->data;
411
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100412 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000413 rts->frame_control =
414 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100415
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100416 memcpy(rts->ra, hdr->addr1, ETH_ALEN);
417 memcpy(rts->ta, hdr->addr2, ETH_ALEN);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100418
419 return 0;
420}
421
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100422static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100423 struct vnt_rts_g *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100424 u16 current_rate)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100425{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100426 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100427 u16 rts_frame_len = 20;
428
Malcolm Priestley205056f2014-06-04 18:25:34 +0100429 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100430 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100431 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100432 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
433
Malcolm Priestley4e011172014-03-18 19:24:55 +0000434 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100435 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000436 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100437 pkt_type, current_rate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000438 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100439 pkt_type, current_rate, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100440
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100441 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100442
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100443 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100444 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100445}
446
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100447static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100448 struct vnt_rts_g_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100449 u16 current_rate)
Malcolm Priestleyec917132013-08-26 11:07:46 +0100450{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100451 struct vnt_private *priv = tx_context->priv;
Malcolm Priestleyec917132013-08-26 11:07:46 +0100452 u16 rts_frame_len = 20;
453
Malcolm Priestley205056f2014-06-04 18:25:34 +0100454 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100455 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100456 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100457 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
458
459
Malcolm Priestley4e011172014-03-18 19:24:55 +0000460 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100461 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000462 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100463 pkt_type, current_rate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000464 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100465 pkt_type, current_rate, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100466
467
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000468 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100469 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000470 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100471 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000472 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100473 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000474 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100475 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100476
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100477 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100478
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100479 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100480 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100481}
482
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100483static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100484 struct vnt_rts_ab *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100485 u16 current_rate)
Malcolm Priestley17126332013-08-26 11:09:38 +0100486{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100487 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley17126332013-08-26 11:09:38 +0100488 u16 rts_frame_len = 20;
489
Malcolm Priestley205056f2014-06-04 18:25:34 +0100490 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100491 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
492
Malcolm Priestley4e011172014-03-18 19:24:55 +0000493 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100494 pkt_type, current_rate, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100495
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100496 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100497
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100498 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100499 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100500}
501
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100502static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100503 struct vnt_rts_a_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100504 u16 current_rate)
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100505{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100506 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100507 u16 rts_frame_len = 20;
508
Malcolm Priestley205056f2014-06-04 18:25:34 +0100509 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100510 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
511
Malcolm Priestley4e011172014-03-18 19:24:55 +0000512 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100513 pkt_type, current_rate, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100514
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000515 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100516 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100517
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000518 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100519 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100520
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100521 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100522
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100523 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100524 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100525}
526
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100527static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100528 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100529 int bNeedAck, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400530{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100531 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000532 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400533
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100534 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100535 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400536
Malcolm Priestleyce7b0db2014-07-10 19:56:03 +0100537 if (tx_context->fb_option) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100538 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100539 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100540 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100541 vnt_get_phy_field(pDevice, uCTSFrameLen,
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100542 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000543 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100544 cbFrameLength, byPktType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100545 wCurrentRate, bNeedAck);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100546 /* Get CTSDuration_ba_f0 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000547 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100548 CTSDUR_BA_F0, cbFrameLength, byPktType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100549 pDevice->tx_rate_fb0, bNeedAck);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100550 /* Get CTSDuration_ba_f1 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000551 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100552 CTSDUR_BA_F1, cbFrameLength, byPktType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100553 pDevice->tx_rate_fb1, bNeedAck);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100554 /* Get CTS Frame body */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000555 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000556 pBuf->data.frame_control =
557 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
558
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100559 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100560
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100561 return vnt_rxtx_datahead_g_fb(tx_context, byPktType,
562 wCurrentRate, &pBuf->data_head, cbFrameLength,
563 bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100564 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100565 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100566 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100567 vnt_get_phy_field(pDevice, uCTSFrameLen,
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100568 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100569 /* Get CTSDuration_ba */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000570 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100571 CTSDUR_BA, cbFrameLength, byPktType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100572 wCurrentRate, bNeedAck);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100573 /*Get CTS Frame body*/
Malcolm Priestley4e011172014-03-18 19:24:55 +0000574 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000575 pBuf->data.frame_control =
576 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
577
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100578 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100579
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100580 return vnt_rxtx_datahead_g(tx_context, byPktType, wCurrentRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100581 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400582 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100583
584 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400585}
586
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100587static u16 vnt_rxtx_rts(struct vnt_usb_send_context *tx_context,
588 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100589 int need_ack, u16 current_rate, bool need_mic)
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100590{
591 struct vnt_private *priv = tx_context->priv;
592 struct vnt_rrv_time_rts *buf = &tx_head->tx_rts.rts;
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100593 union vnt_tx_data_head *head = &tx_head->tx_rts.tx.head;
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100594
595 buf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(priv, 2,
596 pkt_type, frame_size, current_rate);
597 buf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(priv, 1,
598 pkt_type, frame_size, current_rate);
599 buf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(priv, 0,
600 pkt_type, frame_size, current_rate);
601
602 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, pkt_type, frame_size,
603 current_rate, need_ack);
604 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B, frame_size,
605 priv->byTopCCKBasicRate, need_ack);
606
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100607 if (need_mic)
608 head = &tx_head->tx_rts.tx.mic.head;
609
610 if (tx_context->fb_option)
611 return vnt_rxtx_rts_g_fb_head(tx_context, &head->rts_g_fb,
612 pkt_type, frame_size, need_ack, current_rate);
613
614 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g,
615 pkt_type, frame_size, need_ack, current_rate);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100616}
617
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100618static u16 vnt_rxtx_cts(struct vnt_usb_send_context *tx_context,
619 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100620 int need_ack, u16 current_rate, bool need_mic)
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100621{
622 struct vnt_private *priv = tx_context->priv;
623 struct vnt_rrv_time_cts *buf = &tx_head->tx_cts.cts;
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100624 union vnt_tx_data_head *head = &tx_head->tx_cts.tx.head;
625
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100626
627 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, pkt_type,
628 frame_size, current_rate, need_ack);
629 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B,
630 frame_size, priv->byTopCCKBasicRate, need_ack);
631
632 buf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(priv, 3,
633 pkt_type, frame_size, current_rate);
634
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100635 if (need_mic)
636 head = &tx_head->tx_cts.tx.mic.head;
637
638 /* Fill CTS */
639 return s_vFillCTSHead(tx_context, pkt_type, head, frame_size,
640 need_ack, current_rate);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100641}
642
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100643static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context,
644 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestley681acf62014-07-10 19:56:12 +0100645 int need_ack, u16 current_rate, bool need_rts, bool need_mic)
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100646{
647 struct vnt_private *priv = tx_context->priv;
648 struct vnt_rrv_time_ab *buf = &tx_head->tx_ab.ab;
Malcolm Priestley681acf62014-07-10 19:56:12 +0100649 union vnt_tx_data_head *head = &tx_head->tx_ab.tx.head;
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100650
651 buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, pkt_type,
652 frame_size, current_rate, need_ack);
653
Malcolm Priestley681acf62014-07-10 19:56:12 +0100654 if (need_mic)
655 head = &tx_head->tx_ab.tx.mic.head;
656
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100657 if (need_rts) {
658 if (pkt_type == PK_TYPE_11B)
659 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(priv, 0,
660 pkt_type, frame_size, current_rate);
661 else /* PK_TYPE_11A */
662 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(priv, 2,
663 pkt_type, frame_size, current_rate);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100664
665 if (tx_context->fb_option && pkt_type == PK_TYPE_11A)
666 return vnt_rxtx_rts_a_fb_head(tx_context,
667 &head->rts_a_fb, pkt_type, frame_size,
668 need_ack, current_rate);
669
670 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab,
671 pkt_type, frame_size, need_ack, current_rate);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100672 }
673
Malcolm Priestley681acf62014-07-10 19:56:12 +0100674 if (pkt_type == PK_TYPE_11A)
675 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type,
676 current_rate, &head->data_head_a_fb,
677 frame_size, need_ack);
678
679 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
680 &head->data_head_ab, frame_size, need_ack);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100681}
682
Forest Bond92b96792009-06-13 07:38:31 -0400683/*+
684 *
685 * Description:
686 * Generate FIFO control for MAC & Baseband controller
687 *
688 * Parameters:
689 * In:
690 * pDevice - Pointer to adpater
691 * pTxDataHead - Transmit Data Buffer
692 * pTxBufHead - pTxBufHead
693 * pvRrvTime - pvRrvTime
694 * pvRTS - RTS Buffer
695 * pCTS - CTS Buffer
696 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
697 * bNeedACK - If need ACK
Forest Bond92b96792009-06-13 07:38:31 -0400698 * Out:
699 * none
700 *
701 * Return Value: none
702 *
703-*/
Andres Morecc856e62010-05-17 21:34:01 -0300704
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100705static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100706 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100707 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100708 int bNeedACK, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400709{
Forest Bond92b96792009-06-13 07:38:31 -0400710
Malcolm Priestley92928f12013-10-07 20:14:01 +0100711 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
712 if (need_rts) {
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100713 if (need_mic)
Malcolm Priestley92928f12013-10-07 20:14:01 +0100714 *mic_hdr = &tx_buffer->
715 tx_head.tx_rts.tx.mic.hdr;
Malcolm Priestley92928f12013-10-07 20:14:01 +0100716
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100717 return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head,
718 byPktType, cbFrameSize, bNeedACK,
719 wCurrentRate, need_mic);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100720 } else {
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100721 if (need_mic)
Malcolm Priestley92928f12013-10-07 20:14:01 +0100722 *mic_hdr = &tx_buffer->
723 tx_head.tx_cts.tx.mic.hdr;
Malcolm Priestley92928f12013-10-07 20:14:01 +0100724
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100725 return vnt_rxtx_cts(tx_context, &tx_buffer->tx_head,
726 byPktType, cbFrameSize, bNeedACK,
727 wCurrentRate, need_mic);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100728 }
Malcolm Priestley681acf62014-07-10 19:56:12 +0100729 } else {
730 if (need_mic)
Malcolm Priestley92928f12013-10-07 20:14:01 +0100731 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100732
Malcolm Priestley681acf62014-07-10 19:56:12 +0100733 return vnt_rxtx_ab(tx_context, &tx_buffer->tx_head,
734 byPktType, cbFrameSize, bNeedACK,
735 wCurrentRate, need_rts, need_mic);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100736 }
737
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100738 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400739}
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100740
741static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
742 u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
743 u16 payload_len, struct vnt_mic_hdr *mic_hdr)
744{
745 struct ieee80211_hdr *hdr = tx_context->hdr;
746 struct ieee80211_key_seq seq;
747 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
748
749 /* strip header and icv len from payload */
750 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
751 payload_len -= tx_key->icv_len;
752
753 switch (tx_key->cipher) {
754 case WLAN_CIPHER_SUITE_WEP40:
755 case WLAN_CIPHER_SUITE_WEP104:
756 memcpy(key_buffer, iv, 3);
757 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
758
759 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
760 memcpy(key_buffer + 8, iv, 3);
761 memcpy(key_buffer + 11,
762 tx_key->key, WLAN_KEY_LEN_WEP40);
763 }
764
765 break;
766 case WLAN_CIPHER_SUITE_TKIP:
767 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
768
769 break;
770 case WLAN_CIPHER_SUITE_CCMP:
771
772 if (!mic_hdr)
773 return;
774
775 mic_hdr->id = 0x59;
776 mic_hdr->payload_len = cpu_to_be16(payload_len);
777 memcpy(mic_hdr->mic_addr2, hdr->addr2, ETH_ALEN);
778
779 ieee80211_get_key_tx_seq(tx_key, &seq);
780
Malcolm Priestley79f976d2014-06-28 23:55:39 +0100781 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100782
783 if (ieee80211_has_a4(hdr->frame_control))
784 mic_hdr->hlen = cpu_to_be16(28);
785 else
786 mic_hdr->hlen = cpu_to_be16(22);
787
788 memcpy(mic_hdr->addr1, hdr->addr1, ETH_ALEN);
789 memcpy(mic_hdr->addr2, hdr->addr2, ETH_ALEN);
790 memcpy(mic_hdr->addr3, hdr->addr3, ETH_ALEN);
791
792 mic_hdr->frame_control = cpu_to_le16(
793 le16_to_cpu(hdr->frame_control) & 0xc78f);
794 mic_hdr->seq_ctrl = cpu_to_le16(
795 le16_to_cpu(hdr->seq_ctrl) & 0xf);
796
797 if (ieee80211_has_a4(hdr->frame_control))
798 memcpy(mic_hdr->addr4, hdr->addr4, ETH_ALEN);
799
800
801 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
802
803 break;
804 default:
805 break;
806 }
807
808}
809
810int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
811{
812 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
813 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
814 struct ieee80211_rate *rate;
815 struct ieee80211_key_conf *tx_key;
816 struct ieee80211_hdr *hdr;
817 struct vnt_mic_hdr *mic_hdr = NULL;
818 struct vnt_tx_buffer *tx_buffer;
819 struct vnt_tx_fifo_head *tx_buffer_head;
820 struct vnt_usb_send_context *tx_context;
821 unsigned long flags;
822 u32 frame_size = 0;
823 u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
824 u8 pkt_type, fb_option = AUTO_FB_NONE;
825 bool need_rts = false, need_ack = false, is_pspoll = false;
826 bool need_mic = false;
827
828 hdr = (struct ieee80211_hdr *)(skb->data);
829
830 rate = ieee80211_get_tx_rate(priv->hw, info);
831
832 current_rate = rate->hw_value;
Malcolm Priestley5091d962014-07-05 19:24:23 +0100833 if (priv->wCurrentRate != current_rate &&
834 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100835 priv->wCurrentRate = current_rate;
836 bScheduleCommand(priv, WLAN_CMD_SETPOWER, NULL);
837 }
838
839 if (current_rate > RATE_11M)
840 pkt_type = priv->byPacketType;
841 else
842 pkt_type = PK_TYPE_11B;
843
844 spin_lock_irqsave(&priv->lock, flags);
845
846 tx_context = s_vGetFreeContext(priv);
847 if (!tx_context) {
848 dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
849 spin_unlock_irqrestore(&priv->lock, flags);
850 return -ENOMEM;
851 }
852
853 tx_context->skb = skb;
854
855 spin_unlock_irqrestore(&priv->lock, flags);
856
857 tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
858 tx_buffer_head = &tx_buffer->fifo_head;
859 tx_body_size = skb->len;
860
861 frame_size = tx_body_size + 4;
862
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100863 /*Set fifo controls */
864 if (pkt_type == PK_TYPE_11A)
865 tx_buffer_head->wFIFOCtl = 0;
866 else if (pkt_type == PK_TYPE_11B)
867 tx_buffer_head->wFIFOCtl = FIFOCTL_11B;
868 else if (pkt_type == PK_TYPE_11GB)
869 tx_buffer_head->wFIFOCtl = FIFOCTL_11GB;
870 else if (pkt_type == PK_TYPE_11GA)
871 tx_buffer_head->wFIFOCtl = FIFOCTL_11GA;
872
873 if (!ieee80211_is_data(hdr->frame_control)) {
874 tx_buffer_head->wFIFOCtl |= (FIFOCTL_GENINT |
875 FIFOCTL_ISDMA0);
876 tx_buffer_head->wFIFOCtl |= FIFOCTL_TMOEN;
877
878 tx_buffer_head->time_stamp =
879 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
880 } else {
881 tx_buffer_head->time_stamp =
882 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
883 }
884
885 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
886 tx_buffer_head->wFIFOCtl |= FIFOCTL_NEEDACK;
887 need_ack = true;
888 }
889
890 if (ieee80211_has_retry(hdr->frame_control))
891 tx_buffer_head->wFIFOCtl |= FIFOCTL_LRETRY;
892
893 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
894 priv->byPreambleType = PREAMBLE_SHORT;
895 else
896 priv->byPreambleType = PREAMBLE_LONG;
897
898 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
899 need_rts = true;
900 tx_buffer_head->wFIFOCtl |= FIFOCTL_RTS;
901 }
902
903 if (ieee80211_has_a4(hdr->frame_control))
904 tx_buffer_head->wFIFOCtl |= FIFOCTL_LHEAD;
905
906 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
907 is_pspoll = true;
908
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100909 tx_buffer_head->frag_ctl =
910 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100911
912 if (info->control.hw_key) {
913 tx_key = info->control.hw_key;
914 switch (info->control.hw_key->cipher) {
915 case WLAN_CIPHER_SUITE_WEP40:
916 case WLAN_CIPHER_SUITE_WEP104:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100917 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100918 break;
919 case WLAN_CIPHER_SUITE_TKIP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100920 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100921 break;
922 case WLAN_CIPHER_SUITE_CCMP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100923 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100924 need_mic = true;
925 default:
926 break;
927 }
928 frame_size += tx_key->icv_len;
929 }
930
Malcolm Priestleycb8ee9de2014-07-10 19:56:05 +0100931 tx_buffer_head->current_rate = cpu_to_le16(current_rate);
932
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100933 /* legacy rates TODO use ieee80211_tx_rate */
934 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
935 if (priv->byAutoFBCtrl == AUTO_FB_0) {
936 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
937
938 priv->tx_rate_fb0 =
939 wFB_Opt0[FB_RATE0][current_rate - RATE_18M];
940 priv->tx_rate_fb1 =
941 wFB_Opt0[FB_RATE1][current_rate - RATE_18M];
942
943 fb_option = AUTO_FB_0;
944 } else if (priv->byAutoFBCtrl == AUTO_FB_1) {
945 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
946
947 priv->tx_rate_fb0 =
948 wFB_Opt1[FB_RATE0][current_rate - RATE_18M];
949 priv->tx_rate_fb1 =
950 wFB_Opt1[FB_RATE1][current_rate - RATE_18M];
951
952 fb_option = AUTO_FB_1;
953 }
954 }
955
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100956 tx_context->fb_option = fb_option;
957
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100958 duration_id = s_vGenerateTxParameter(tx_context, pkt_type, current_rate,
959 tx_buffer, &mic_hdr, need_mic, frame_size,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100960 need_ack, need_rts);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100961
962 tx_header_size = tx_context->tx_hdr_size;
963 if (!tx_header_size) {
964 tx_context->in_use = false;
965 return -ENOMEM;
966 }
967
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100968 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100969
970 tx_bytes = tx_header_size + tx_body_size;
971
972 memcpy(tx_context->hdr, skb->data, tx_body_size);
973
974 hdr->duration_id = cpu_to_le16(duration_id);
975
976 if (info->control.hw_key) {
977 tx_key = info->control.hw_key;
978 if (tx_key->keylen > 0)
979 vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
980 tx_key, skb, tx_body_size, mic_hdr);
981 }
982
983 priv->wSeqCounter = (le16_to_cpu(hdr->seq_ctrl) &
984 IEEE80211_SCTL_SEQ) >> 4;
985
986 tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100987 tx_buffer->byPKTNO = tx_context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100988 tx_buffer->byType = 0x00;
989
990 tx_bytes += 4;
991
992 tx_context->type = CONTEXT_DATA_PACKET;
993 tx_context->buf_len = tx_bytes;
994
995 spin_lock_irqsave(&priv->lock, flags);
996
997 if (PIPEnsSendBulkOut(priv, tx_context) != STATUS_PENDING) {
998 spin_unlock_irqrestore(&priv->lock, flags);
999 return -EIO;
1000 }
1001
1002 spin_unlock_irqrestore(&priv->lock, flags);
1003
1004 return 0;
1005}
1006
1007static int vnt_beacon_xmit(struct vnt_private *priv,
1008 struct sk_buff *skb)
1009{
1010 struct vnt_beacon_buffer *beacon_buffer;
1011 struct vnt_tx_short_buf_head *short_head;
1012 struct ieee80211_tx_info *info;
1013 struct vnt_usb_send_context *context;
1014 struct ieee80211_mgmt *mgmt_hdr;
1015 unsigned long flags;
1016 u32 frame_size = skb->len + 4;
1017 u16 current_rate, count;
1018
1019 spin_lock_irqsave(&priv->lock, flags);
1020
1021 context = s_vGetFreeContext(priv);
1022 if (!context) {
1023 dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
1024 spin_unlock_irqrestore(&priv->lock, flags);
1025 return -ENOMEM;
1026 }
1027
1028 context->skb = skb;
1029
1030 spin_unlock_irqrestore(&priv->lock, flags);
1031
1032 beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
1033 short_head = &beacon_buffer->short_head;
1034
1035 if (priv->byBBType == BB_TYPE_11A) {
1036 current_rate = RATE_6M;
1037
1038 /* Get SignalField,ServiceField,Length */
1039 vnt_get_phy_field(priv, frame_size, current_rate,
1040 PK_TYPE_11A, &short_head->ab);
1041
1042 /* Get Duration and TimeStampOff */
1043 short_head->duration = s_uGetDataDuration(priv,
1044 PK_TYPE_11A, false);
1045 short_head->time_stamp_off =
1046 vnt_time_stamp_off(priv, current_rate);
1047 } else {
1048 current_rate = RATE_1M;
1049 short_head->fifo_ctl |= FIFOCTL_11B;
1050
1051 /* Get SignalField,ServiceField,Length */
1052 vnt_get_phy_field(priv, frame_size, current_rate,
1053 PK_TYPE_11B, &short_head->ab);
1054
1055 /* Get Duration and TimeStampOff */
1056 short_head->duration = s_uGetDataDuration(priv,
1057 PK_TYPE_11B, false);
1058 short_head->time_stamp_off =
1059 vnt_time_stamp_off(priv, current_rate);
1060 }
1061
1062 /* Generate Beacon Header */
1063 mgmt_hdr = &beacon_buffer->mgmt_hdr;
1064 memcpy(mgmt_hdr, skb->data, skb->len);
1065
1066 /* time stamp always 0 */
1067 mgmt_hdr->u.beacon.timestamp = 0;
1068
1069 info = IEEE80211_SKB_CB(skb);
1070 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1071 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
1072 hdr->duration_id = 0;
1073 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
1074 }
1075
1076 priv->wSeqCounter++;
1077 if (priv->wSeqCounter > 0x0fff)
1078 priv->wSeqCounter = 0;
1079
1080 count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
1081
1082 beacon_buffer->tx_byte_count = cpu_to_le16(count);
Malcolm Priestley71d764a2014-07-05 19:24:27 +01001083 beacon_buffer->byPKTNO = context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001084 beacon_buffer->byType = 0x01;
1085
1086 context->type = CONTEXT_BEACON_PACKET;
1087 context->buf_len = count + 4; /* USB header */
1088
1089 spin_lock_irqsave(&priv->lock, flags);
1090
1091 if (PIPEnsSendBulkOut(priv, context) != STATUS_PENDING)
1092 ieee80211_free_txskb(priv->hw, context->skb);
1093
1094 spin_unlock_irqrestore(&priv->lock, flags);
1095
1096 return 0;
1097}
1098
1099int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1100{
1101 struct sk_buff *beacon;
1102
1103 beacon = ieee80211_beacon_get(priv->hw, vif);
1104 if (!beacon)
1105 return -ENOMEM;
1106
1107 if (vnt_beacon_xmit(priv, beacon)) {
1108 ieee80211_free_txskb(priv->hw, beacon);
1109 return -ENODEV;
1110 }
1111
1112 return 0;
1113}
1114
1115int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1116 struct ieee80211_bss_conf *conf)
1117{
1118 int ret;
1119
1120 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1121
1122 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1123
1124 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
1125
1126 vnt_clear_current_tsf(priv);
1127
1128 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1129
1130 vnt_reset_next_tbtt(priv, conf->beacon_int);
1131
1132 ret = vnt_beacon_make(priv, vif);
1133
1134 return ret;
1135}