blob: ad1a1b6f4d6bb5e2bce34c04eb3b37ffe97726e8 [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:
Malcolm Priestley9ec7f2d2014-07-10 19:56:15 +010028 * vnt_generate_tx_parameter - 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 Priestleyd56131d2013-01-17 23:15:22 +000086static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
87 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -040088
Malcolm Priestley20338012014-03-18 19:25:08 +000089static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +010090 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate);
Forest Bond92b96792009-06-13 07:38:31 -040091
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +010092static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +010093 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
Malcolm Priestley26e73622014-07-10 19:56:04 +010094 int bNeedAck, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -040095
Malcolm Priestley5abe3d62014-03-18 19:25:06 +000096static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +010097 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestley7f591a12014-03-18 19:25:05 +000099static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000100 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100101 int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400102
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000103static struct vnt_usb_send_context
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000104 *s_vGetFreeContext(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400105{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000106 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000107 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400108
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000109 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400110
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000111 for (ii = 0; ii < priv->cbTD; ii++) {
112 if (!priv->apTD[ii])
113 return NULL;
114
115 context = priv->apTD[ii];
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100116 if (context->in_use == false) {
117 context->in_use = true;
118 memset(context->data, 0,
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000119 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100120
121 context->hdr = NULL;
122
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000123 return context;
124 }
125 }
126
127 if (ii == priv->cbTD)
128 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000129
Malcolm Priestley5c851382013-11-26 19:12:38 +0000130 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400131}
132
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000133static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100134{
135 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
136 [rate % MAX_RATE]);
137}
138
Forest Bond92b96792009-06-13 07:38:31 -0400139/*byPktType : PK_TYPE_11A 0
140 PK_TYPE_11B 1
141 PK_TYPE_11GB 2
142 PK_TYPE_11GA 3
143*/
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000144static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
145 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400146{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000147 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400148
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100149 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000150 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400151
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000152 if (pkt_type == PK_TYPE_11B)
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100153 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
154 14, (u16)priv->byTopCCKBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000155 else
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100156 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
157 14, (u16)priv->byTopOFDMBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000158
159 if (need_ack)
160 return data_time + priv->uSIFS + ack_time;
161
162 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400163}
164
Malcolm Priestley2075f652014-03-18 19:25:07 +0000165static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100166 u32 frame_length, u16 rate, int need_ack)
167{
168 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
169 frame_length, rate, need_ack));
170}
171
Forest Bond92b96792009-06-13 07:38:31 -0400172//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley20338012014-03-18 19:25:08 +0000173static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100174 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400175{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000176 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400177
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000178 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400179
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100180 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100181 frame_length, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400182
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000183 if (rsv_type == 0) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100184 rts_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000185 pkt_type, 20, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100186 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000187 pkt_type, 14, priv->byTopCCKBasicRate);
188 } else if (rsv_type == 1) {
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 = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000192 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100193 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000194 14, priv->byTopOFDMBasicRate);
195 } else if (rsv_type == 2) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100196 rts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000197 20, priv->byTopOFDMBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100198 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000199 pkt_type, 14, priv->byTopOFDMBasicRate);
200 } else if (rsv_type == 3) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100201 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000202 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100203 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000204 14, priv->byTopOFDMBasicRate);
205
206 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
207
Malcolm Priestley20338012014-03-18 19:25:08 +0000208 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000209 }
210
211 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
212
213 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400214}
215
216//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000217static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100218 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400219{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100220 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400221
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100222 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100223 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100224 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100225 byPktType, 14, pDevice->byTopCCKBasicRate);
226 else
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100227 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100228 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100229 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100230 }
Forest Bond92b96792009-06-13 07:38:31 -0400231
Forest Bond92b96792009-06-13 07:38:31 -0400232 return 0;
233}
234
Forest Bond92b96792009-06-13 07:38:31 -0400235//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000236static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100237 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400238{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000239 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400240
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100241 switch (byDurType) {
242 case RTSDUR_BB:
243 case RTSDUR_BA:
244 case RTSDUR_BA_F0:
245 case RTSDUR_BA_F1:
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100246 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
247 byPktType, 14, pDevice->byTopCCKBasicRate);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100248 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
249 s_uGetTxRsvTime(pDevice, byPktType,
250 cbFrameLength, wRate, bNeedAck);
251 break;
Forest Bond92b96792009-06-13 07:38:31 -0400252
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100253 case RTSDUR_AA:
254 case RTSDUR_AA_F0:
255 case RTSDUR_AA_F1:
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100256 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
257 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100258 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
259 s_uGetTxRsvTime(pDevice, byPktType,
260 cbFrameLength, wRate, bNeedAck);
261 break;
Forest Bond92b96792009-06-13 07:38:31 -0400262
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100263 case CTSDUR_BA:
264 case CTSDUR_BA_F0:
265 case CTSDUR_BA_F1:
266 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100267 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100268 break;
Forest Bond92b96792009-06-13 07:38:31 -0400269
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100270 default:
271 break;
272 }
Forest Bond92b96792009-06-13 07:38:31 -0400273
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100274 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400275}
276
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100277static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
278 struct ieee80211_hdr *hdr)
279{
280 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
281 u8 *hdr_pos = (u8 *)hdr;
282
283 tx_context->hdr = hdr;
284 if (!tx_context->hdr)
285 return 0;
286
287 return (u16)(hdr_pos - head);
288}
289
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100290static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
291 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf,
292 u32 frame_len, int need_ack)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100293{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100294
295 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100296 struct ieee80211_hdr *hdr =
297 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100298
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100299 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100300 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
301 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100302 PK_TYPE_11B, &buf->b);
303
304 /* Get Duration and TimeStamp */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100305 if (ieee80211_is_pspoll(hdr->frame_control)) {
306 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
307
308 buf->duration_a = dur;
309 buf->duration_b = dur;
310 } else {
311 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
312 buf->duration_b = s_uGetDataDuration(priv,
313 PK_TYPE_11B, need_ack);
314 }
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100315
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000316 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
317 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100318 priv->byTopCCKBasicRate);
319
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100320 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
321
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000322 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100323}
324
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100325static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
326 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100327 u32 frame_len, int need_ack)
328{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100329 struct vnt_private *priv = tx_context->priv;
330
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100331 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100332 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100333
Malcolm Priestley205056f2014-06-04 18:25:34 +0100334 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100335 PK_TYPE_11B, &buf->b);
336
337 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000338 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
339 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100340
Malcolm Priestley4e011172014-03-18 19:24:55 +0000341 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
342 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100343
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000344 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
345 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100346 priv->byTopCCKBasicRate);
347
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100348 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
349
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000350 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100351}
352
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100353static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
354 u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100355 u32 frame_len, int need_ack)
356{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100357 struct vnt_private *priv = tx_context->priv;
358
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100359 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100360 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100361 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000362 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100363
Malcolm Priestley4e011172014-03-18 19:24:55 +0000364 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
365 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100366
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000367 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100368
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100369 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
370
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000371 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100372}
373
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100374static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
375 u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100376 u32 frame_len, int need_ack)
377{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100378 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100379 struct ieee80211_hdr *hdr =
380 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100381
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100382 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100383 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->ab);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100384
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100385 /* Get Duration and TimeStampOff */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100386 if (ieee80211_is_pspoll(hdr->frame_control)) {
387 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
388
389 buf->duration = dur;
390 } else {
391 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
392 }
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100393
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000394 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100395
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100396 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
397
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000398 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100399}
400
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100401static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
402 struct ieee80211_rts *rts, __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100403{
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100404 struct ieee80211_hdr *hdr =
405 (struct ieee80211_hdr *)tx_context->skb->data;
406
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100407 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000408 rts->frame_control =
409 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100410
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100411 memcpy(rts->ra, hdr->addr1, ETH_ALEN);
412 memcpy(rts->ta, hdr->addr2, ETH_ALEN);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100413
414 return 0;
415}
416
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100417static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100418 struct vnt_rts_g *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100419 u16 current_rate)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100420{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100421 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100422 u16 rts_frame_len = 20;
423
Malcolm Priestley205056f2014-06-04 18:25:34 +0100424 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100425 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100426 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100427 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
428
Malcolm Priestley4e011172014-03-18 19:24:55 +0000429 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100430 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000431 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100432 pkt_type, current_rate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000433 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100434 pkt_type, current_rate, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100435
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100436 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100437
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100438 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100439 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100440}
441
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100442static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100443 struct vnt_rts_g_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100444 u16 current_rate)
Malcolm Priestleyec917132013-08-26 11:07:46 +0100445{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100446 struct vnt_private *priv = tx_context->priv;
Malcolm Priestleyec917132013-08-26 11:07:46 +0100447 u16 rts_frame_len = 20;
448
Malcolm Priestley205056f2014-06-04 18:25:34 +0100449 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100450 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100451 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100452 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
453
454
Malcolm Priestley4e011172014-03-18 19:24:55 +0000455 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100456 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000457 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100458 pkt_type, current_rate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000459 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100460 pkt_type, current_rate, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100461
462
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000463 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100464 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000465 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100466 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000467 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100468 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000469 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100470 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100471
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100472 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100473
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100474 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100475 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100476}
477
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100478static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100479 struct vnt_rts_ab *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100480 u16 current_rate)
Malcolm Priestley17126332013-08-26 11:09:38 +0100481{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100482 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley17126332013-08-26 11:09:38 +0100483 u16 rts_frame_len = 20;
484
Malcolm Priestley205056f2014-06-04 18:25:34 +0100485 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100486 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
487
Malcolm Priestley4e011172014-03-18 19:24:55 +0000488 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100489 pkt_type, current_rate, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100490
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100491 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100492
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100493 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100494 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100495}
496
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100497static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100498 struct vnt_rts_a_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100499 u16 current_rate)
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100500{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100501 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100502 u16 rts_frame_len = 20;
503
Malcolm Priestley205056f2014-06-04 18:25:34 +0100504 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100505 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
506
Malcolm Priestley4e011172014-03-18 19:24:55 +0000507 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100508 pkt_type, current_rate, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100509
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000510 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100511 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100512
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000513 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100514 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100515
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100516 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100517
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100518 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100519 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100520}
521
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100522static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100523 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100524 int bNeedAck, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400525{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100526 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000527 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400528
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100529 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100530 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400531
Malcolm Priestleyce7b0db2014-07-10 19:56:03 +0100532 if (tx_context->fb_option) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100533 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100534 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100535 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100536 vnt_get_phy_field(pDevice, uCTSFrameLen,
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100537 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000538 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100539 cbFrameLength, byPktType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100540 wCurrentRate, bNeedAck);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100541 /* Get CTSDuration_ba_f0 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000542 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100543 CTSDUR_BA_F0, cbFrameLength, byPktType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100544 pDevice->tx_rate_fb0, bNeedAck);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100545 /* Get CTSDuration_ba_f1 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000546 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100547 CTSDUR_BA_F1, cbFrameLength, byPktType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100548 pDevice->tx_rate_fb1, bNeedAck);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100549 /* Get CTS Frame body */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000550 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000551 pBuf->data.frame_control =
552 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
553
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100554 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100555
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100556 return vnt_rxtx_datahead_g_fb(tx_context, byPktType,
557 wCurrentRate, &pBuf->data_head, cbFrameLength,
558 bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100559 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100560 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100561 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100562 vnt_get_phy_field(pDevice, uCTSFrameLen,
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100563 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100564 /* Get CTSDuration_ba */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000565 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100566 CTSDUR_BA, cbFrameLength, byPktType,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100567 wCurrentRate, bNeedAck);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100568 /*Get CTS Frame body*/
Malcolm Priestley4e011172014-03-18 19:24:55 +0000569 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000570 pBuf->data.frame_control =
571 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
572
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100573 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100574
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100575 return vnt_rxtx_datahead_g(tx_context, byPktType, wCurrentRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100576 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400577 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100578
579 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400580}
581
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100582static u16 vnt_rxtx_rts(struct vnt_usb_send_context *tx_context,
583 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100584 int need_ack, u16 current_rate, bool need_mic)
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100585{
586 struct vnt_private *priv = tx_context->priv;
587 struct vnt_rrv_time_rts *buf = &tx_head->tx_rts.rts;
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100588 union vnt_tx_data_head *head = &tx_head->tx_rts.tx.head;
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100589
590 buf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(priv, 2,
591 pkt_type, frame_size, current_rate);
592 buf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(priv, 1,
593 pkt_type, frame_size, current_rate);
594 buf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(priv, 0,
595 pkt_type, frame_size, current_rate);
596
597 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, pkt_type, frame_size,
598 current_rate, need_ack);
599 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B, frame_size,
600 priv->byTopCCKBasicRate, need_ack);
601
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100602 if (need_mic)
603 head = &tx_head->tx_rts.tx.mic.head;
604
605 if (tx_context->fb_option)
606 return vnt_rxtx_rts_g_fb_head(tx_context, &head->rts_g_fb,
607 pkt_type, frame_size, need_ack, current_rate);
608
609 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g,
610 pkt_type, frame_size, need_ack, current_rate);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100611}
612
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100613static u16 vnt_rxtx_cts(struct vnt_usb_send_context *tx_context,
614 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100615 int need_ack, u16 current_rate, bool need_mic)
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100616{
617 struct vnt_private *priv = tx_context->priv;
618 struct vnt_rrv_time_cts *buf = &tx_head->tx_cts.cts;
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100619 union vnt_tx_data_head *head = &tx_head->tx_cts.tx.head;
620
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100621
622 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, pkt_type,
623 frame_size, current_rate, need_ack);
624 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B,
625 frame_size, priv->byTopCCKBasicRate, need_ack);
626
627 buf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(priv, 3,
628 pkt_type, frame_size, current_rate);
629
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100630 if (need_mic)
631 head = &tx_head->tx_cts.tx.mic.head;
632
633 /* Fill CTS */
634 return s_vFillCTSHead(tx_context, pkt_type, head, frame_size,
635 need_ack, current_rate);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100636}
637
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100638static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context,
639 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestley681acf62014-07-10 19:56:12 +0100640 int need_ack, u16 current_rate, bool need_rts, bool need_mic)
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100641{
642 struct vnt_private *priv = tx_context->priv;
643 struct vnt_rrv_time_ab *buf = &tx_head->tx_ab.ab;
Malcolm Priestley681acf62014-07-10 19:56:12 +0100644 union vnt_tx_data_head *head = &tx_head->tx_ab.tx.head;
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100645
646 buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, pkt_type,
647 frame_size, current_rate, need_ack);
648
Malcolm Priestley681acf62014-07-10 19:56:12 +0100649 if (need_mic)
650 head = &tx_head->tx_ab.tx.mic.head;
651
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100652 if (need_rts) {
653 if (pkt_type == PK_TYPE_11B)
654 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(priv, 0,
655 pkt_type, frame_size, current_rate);
656 else /* PK_TYPE_11A */
657 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(priv, 2,
658 pkt_type, frame_size, current_rate);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100659
660 if (tx_context->fb_option && pkt_type == PK_TYPE_11A)
661 return vnt_rxtx_rts_a_fb_head(tx_context,
662 &head->rts_a_fb, pkt_type, frame_size,
663 need_ack, current_rate);
664
665 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab,
666 pkt_type, frame_size, need_ack, current_rate);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100667 }
668
Malcolm Priestley681acf62014-07-10 19:56:12 +0100669 if (pkt_type == PK_TYPE_11A)
670 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type,
671 current_rate, &head->data_head_a_fb,
672 frame_size, need_ack);
673
674 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
675 &head->data_head_ab, frame_size, need_ack);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100676}
677
Forest Bond92b96792009-06-13 07:38:31 -0400678/*+
679 *
680 * Description:
681 * Generate FIFO control for MAC & Baseband controller
682 *
683 * Parameters:
684 * In:
685 * pDevice - Pointer to adpater
686 * pTxDataHead - Transmit Data Buffer
687 * pTxBufHead - pTxBufHead
688 * pvRrvTime - pvRrvTime
689 * pvRTS - RTS Buffer
690 * pCTS - CTS Buffer
691 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
692 * bNeedACK - If need ACK
Forest Bond92b96792009-06-13 07:38:31 -0400693 * Out:
694 * none
695 *
696 * Return Value: none
697 *
698-*/
Andres Morecc856e62010-05-17 21:34:01 -0300699
Malcolm Priestley9ec7f2d2014-07-10 19:56:15 +0100700static u16 vnt_generate_tx_parameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley165ac772014-07-10 19:56:14 +0100701 u8 pkt_type, u16 current_rate, struct vnt_tx_buffer *tx_buffer,
702 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 frame_size,
703 int need_ack, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400704{
Forest Bond92b96792009-06-13 07:38:31 -0400705
Malcolm Priestley165ac772014-07-10 19:56:14 +0100706 if (pkt_type == PK_TYPE_11GB || pkt_type == PK_TYPE_11GA) {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100707 if (need_rts) {
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100708 if (need_mic)
Malcolm Priestley92928f12013-10-07 20:14:01 +0100709 *mic_hdr = &tx_buffer->
710 tx_head.tx_rts.tx.mic.hdr;
Malcolm Priestley92928f12013-10-07 20:14:01 +0100711
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100712 return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head,
Malcolm Priestley165ac772014-07-10 19:56:14 +0100713 pkt_type, frame_size, need_ack,
714 current_rate, need_mic);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100715 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100716
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100717 if (need_mic)
718 *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr;
719
Malcolm Priestley165ac772014-07-10 19:56:14 +0100720 return vnt_rxtx_cts(tx_context, &tx_buffer->tx_head, pkt_type,
721 frame_size, need_ack, current_rate, need_mic);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100722 }
723
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100724 if (need_mic)
725 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
726
Malcolm Priestley165ac772014-07-10 19:56:14 +0100727 return vnt_rxtx_ab(tx_context, &tx_buffer->tx_head, pkt_type,
728 frame_size, need_ack, current_rate, need_rts, need_mic);
Forest Bond92b96792009-06-13 07:38:31 -0400729}
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100730
731static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
732 u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
733 u16 payload_len, struct vnt_mic_hdr *mic_hdr)
734{
735 struct ieee80211_hdr *hdr = tx_context->hdr;
736 struct ieee80211_key_seq seq;
737 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
738
739 /* strip header and icv len from payload */
740 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
741 payload_len -= tx_key->icv_len;
742
743 switch (tx_key->cipher) {
744 case WLAN_CIPHER_SUITE_WEP40:
745 case WLAN_CIPHER_SUITE_WEP104:
746 memcpy(key_buffer, iv, 3);
747 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
748
749 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
750 memcpy(key_buffer + 8, iv, 3);
751 memcpy(key_buffer + 11,
752 tx_key->key, WLAN_KEY_LEN_WEP40);
753 }
754
755 break;
756 case WLAN_CIPHER_SUITE_TKIP:
757 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
758
759 break;
760 case WLAN_CIPHER_SUITE_CCMP:
761
762 if (!mic_hdr)
763 return;
764
765 mic_hdr->id = 0x59;
766 mic_hdr->payload_len = cpu_to_be16(payload_len);
767 memcpy(mic_hdr->mic_addr2, hdr->addr2, ETH_ALEN);
768
769 ieee80211_get_key_tx_seq(tx_key, &seq);
770
Malcolm Priestley79f976d2014-06-28 23:55:39 +0100771 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100772
773 if (ieee80211_has_a4(hdr->frame_control))
774 mic_hdr->hlen = cpu_to_be16(28);
775 else
776 mic_hdr->hlen = cpu_to_be16(22);
777
778 memcpy(mic_hdr->addr1, hdr->addr1, ETH_ALEN);
779 memcpy(mic_hdr->addr2, hdr->addr2, ETH_ALEN);
780 memcpy(mic_hdr->addr3, hdr->addr3, ETH_ALEN);
781
782 mic_hdr->frame_control = cpu_to_le16(
783 le16_to_cpu(hdr->frame_control) & 0xc78f);
784 mic_hdr->seq_ctrl = cpu_to_le16(
785 le16_to_cpu(hdr->seq_ctrl) & 0xf);
786
787 if (ieee80211_has_a4(hdr->frame_control))
788 memcpy(mic_hdr->addr4, hdr->addr4, ETH_ALEN);
789
790
791 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
792
793 break;
794 default:
795 break;
796 }
797
798}
799
800int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
801{
802 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
803 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
804 struct ieee80211_rate *rate;
805 struct ieee80211_key_conf *tx_key;
806 struct ieee80211_hdr *hdr;
807 struct vnt_mic_hdr *mic_hdr = NULL;
808 struct vnt_tx_buffer *tx_buffer;
809 struct vnt_tx_fifo_head *tx_buffer_head;
810 struct vnt_usb_send_context *tx_context;
811 unsigned long flags;
812 u32 frame_size = 0;
813 u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
814 u8 pkt_type, fb_option = AUTO_FB_NONE;
815 bool need_rts = false, need_ack = false, is_pspoll = false;
816 bool need_mic = false;
817
818 hdr = (struct ieee80211_hdr *)(skb->data);
819
820 rate = ieee80211_get_tx_rate(priv->hw, info);
821
822 current_rate = rate->hw_value;
Malcolm Priestley5091d962014-07-05 19:24:23 +0100823 if (priv->wCurrentRate != current_rate &&
824 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100825 priv->wCurrentRate = current_rate;
826 bScheduleCommand(priv, WLAN_CMD_SETPOWER, NULL);
827 }
828
829 if (current_rate > RATE_11M)
830 pkt_type = priv->byPacketType;
831 else
832 pkt_type = PK_TYPE_11B;
833
834 spin_lock_irqsave(&priv->lock, flags);
835
836 tx_context = s_vGetFreeContext(priv);
837 if (!tx_context) {
838 dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
839 spin_unlock_irqrestore(&priv->lock, flags);
840 return -ENOMEM;
841 }
842
843 tx_context->skb = skb;
844
845 spin_unlock_irqrestore(&priv->lock, flags);
846
847 tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
848 tx_buffer_head = &tx_buffer->fifo_head;
849 tx_body_size = skb->len;
850
851 frame_size = tx_body_size + 4;
852
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100853 /*Set fifo controls */
854 if (pkt_type == PK_TYPE_11A)
855 tx_buffer_head->wFIFOCtl = 0;
856 else if (pkt_type == PK_TYPE_11B)
857 tx_buffer_head->wFIFOCtl = FIFOCTL_11B;
858 else if (pkt_type == PK_TYPE_11GB)
859 tx_buffer_head->wFIFOCtl = FIFOCTL_11GB;
860 else if (pkt_type == PK_TYPE_11GA)
861 tx_buffer_head->wFIFOCtl = FIFOCTL_11GA;
862
863 if (!ieee80211_is_data(hdr->frame_control)) {
864 tx_buffer_head->wFIFOCtl |= (FIFOCTL_GENINT |
865 FIFOCTL_ISDMA0);
866 tx_buffer_head->wFIFOCtl |= FIFOCTL_TMOEN;
867
868 tx_buffer_head->time_stamp =
869 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
870 } else {
871 tx_buffer_head->time_stamp =
872 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
873 }
874
875 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
876 tx_buffer_head->wFIFOCtl |= FIFOCTL_NEEDACK;
877 need_ack = true;
878 }
879
880 if (ieee80211_has_retry(hdr->frame_control))
881 tx_buffer_head->wFIFOCtl |= FIFOCTL_LRETRY;
882
883 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
884 priv->byPreambleType = PREAMBLE_SHORT;
885 else
886 priv->byPreambleType = PREAMBLE_LONG;
887
888 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
889 need_rts = true;
890 tx_buffer_head->wFIFOCtl |= FIFOCTL_RTS;
891 }
892
893 if (ieee80211_has_a4(hdr->frame_control))
894 tx_buffer_head->wFIFOCtl |= FIFOCTL_LHEAD;
895
896 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
897 is_pspoll = true;
898
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100899 tx_buffer_head->frag_ctl =
900 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100901
902 if (info->control.hw_key) {
903 tx_key = info->control.hw_key;
904 switch (info->control.hw_key->cipher) {
905 case WLAN_CIPHER_SUITE_WEP40:
906 case WLAN_CIPHER_SUITE_WEP104:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100907 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100908 break;
909 case WLAN_CIPHER_SUITE_TKIP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100910 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100911 break;
912 case WLAN_CIPHER_SUITE_CCMP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100913 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100914 need_mic = true;
915 default:
916 break;
917 }
918 frame_size += tx_key->icv_len;
919 }
920
Malcolm Priestleycb8ee9de2014-07-10 19:56:05 +0100921 tx_buffer_head->current_rate = cpu_to_le16(current_rate);
922
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100923 /* legacy rates TODO use ieee80211_tx_rate */
924 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
925 if (priv->byAutoFBCtrl == AUTO_FB_0) {
926 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
927
928 priv->tx_rate_fb0 =
929 wFB_Opt0[FB_RATE0][current_rate - RATE_18M];
930 priv->tx_rate_fb1 =
931 wFB_Opt0[FB_RATE1][current_rate - RATE_18M];
932
933 fb_option = AUTO_FB_0;
934 } else if (priv->byAutoFBCtrl == AUTO_FB_1) {
935 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
936
937 priv->tx_rate_fb0 =
938 wFB_Opt1[FB_RATE0][current_rate - RATE_18M];
939 priv->tx_rate_fb1 =
940 wFB_Opt1[FB_RATE1][current_rate - RATE_18M];
941
942 fb_option = AUTO_FB_1;
943 }
944 }
945
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100946 tx_context->fb_option = fb_option;
947
Malcolm Priestley9ec7f2d2014-07-10 19:56:15 +0100948 duration_id = vnt_generate_tx_parameter(tx_context, pkt_type,
949 current_rate, tx_buffer, &mic_hdr, need_mic, frame_size,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100950 need_ack, need_rts);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100951
952 tx_header_size = tx_context->tx_hdr_size;
953 if (!tx_header_size) {
954 tx_context->in_use = false;
955 return -ENOMEM;
956 }
957
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100958 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100959
960 tx_bytes = tx_header_size + tx_body_size;
961
962 memcpy(tx_context->hdr, skb->data, tx_body_size);
963
964 hdr->duration_id = cpu_to_le16(duration_id);
965
966 if (info->control.hw_key) {
967 tx_key = info->control.hw_key;
968 if (tx_key->keylen > 0)
969 vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
970 tx_key, skb, tx_body_size, mic_hdr);
971 }
972
973 priv->wSeqCounter = (le16_to_cpu(hdr->seq_ctrl) &
974 IEEE80211_SCTL_SEQ) >> 4;
975
976 tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100977 tx_buffer->byPKTNO = tx_context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100978 tx_buffer->byType = 0x00;
979
980 tx_bytes += 4;
981
982 tx_context->type = CONTEXT_DATA_PACKET;
983 tx_context->buf_len = tx_bytes;
984
985 spin_lock_irqsave(&priv->lock, flags);
986
987 if (PIPEnsSendBulkOut(priv, tx_context) != STATUS_PENDING) {
988 spin_unlock_irqrestore(&priv->lock, flags);
989 return -EIO;
990 }
991
992 spin_unlock_irqrestore(&priv->lock, flags);
993
994 return 0;
995}
996
997static int vnt_beacon_xmit(struct vnt_private *priv,
998 struct sk_buff *skb)
999{
1000 struct vnt_beacon_buffer *beacon_buffer;
1001 struct vnt_tx_short_buf_head *short_head;
1002 struct ieee80211_tx_info *info;
1003 struct vnt_usb_send_context *context;
1004 struct ieee80211_mgmt *mgmt_hdr;
1005 unsigned long flags;
1006 u32 frame_size = skb->len + 4;
1007 u16 current_rate, count;
1008
1009 spin_lock_irqsave(&priv->lock, flags);
1010
1011 context = s_vGetFreeContext(priv);
1012 if (!context) {
1013 dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
1014 spin_unlock_irqrestore(&priv->lock, flags);
1015 return -ENOMEM;
1016 }
1017
1018 context->skb = skb;
1019
1020 spin_unlock_irqrestore(&priv->lock, flags);
1021
1022 beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
1023 short_head = &beacon_buffer->short_head;
1024
1025 if (priv->byBBType == BB_TYPE_11A) {
1026 current_rate = RATE_6M;
1027
1028 /* Get SignalField,ServiceField,Length */
1029 vnt_get_phy_field(priv, frame_size, current_rate,
1030 PK_TYPE_11A, &short_head->ab);
1031
1032 /* Get Duration and TimeStampOff */
1033 short_head->duration = s_uGetDataDuration(priv,
1034 PK_TYPE_11A, false);
1035 short_head->time_stamp_off =
1036 vnt_time_stamp_off(priv, current_rate);
1037 } else {
1038 current_rate = RATE_1M;
1039 short_head->fifo_ctl |= FIFOCTL_11B;
1040
1041 /* Get SignalField,ServiceField,Length */
1042 vnt_get_phy_field(priv, frame_size, current_rate,
1043 PK_TYPE_11B, &short_head->ab);
1044
1045 /* Get Duration and TimeStampOff */
1046 short_head->duration = s_uGetDataDuration(priv,
1047 PK_TYPE_11B, false);
1048 short_head->time_stamp_off =
1049 vnt_time_stamp_off(priv, current_rate);
1050 }
1051
1052 /* Generate Beacon Header */
1053 mgmt_hdr = &beacon_buffer->mgmt_hdr;
1054 memcpy(mgmt_hdr, skb->data, skb->len);
1055
1056 /* time stamp always 0 */
1057 mgmt_hdr->u.beacon.timestamp = 0;
1058
1059 info = IEEE80211_SKB_CB(skb);
1060 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1061 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
1062 hdr->duration_id = 0;
1063 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
1064 }
1065
1066 priv->wSeqCounter++;
1067 if (priv->wSeqCounter > 0x0fff)
1068 priv->wSeqCounter = 0;
1069
1070 count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
1071
1072 beacon_buffer->tx_byte_count = cpu_to_le16(count);
Malcolm Priestley71d764a2014-07-05 19:24:27 +01001073 beacon_buffer->byPKTNO = context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001074 beacon_buffer->byType = 0x01;
1075
1076 context->type = CONTEXT_BEACON_PACKET;
1077 context->buf_len = count + 4; /* USB header */
1078
1079 spin_lock_irqsave(&priv->lock, flags);
1080
1081 if (PIPEnsSendBulkOut(priv, context) != STATUS_PENDING)
1082 ieee80211_free_txskb(priv->hw, context->skb);
1083
1084 spin_unlock_irqrestore(&priv->lock, flags);
1085
1086 return 0;
1087}
1088
1089int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1090{
1091 struct sk_buff *beacon;
1092
1093 beacon = ieee80211_beacon_get(priv->hw, vif);
1094 if (!beacon)
1095 return -ENOMEM;
1096
1097 if (vnt_beacon_xmit(priv, beacon)) {
1098 ieee80211_free_txskb(priv->hw, beacon);
1099 return -ENODEV;
1100 }
1101
1102 return 0;
1103}
1104
1105int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1106 struct ieee80211_bss_conf *conf)
1107{
1108 int ret;
1109
1110 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1111
1112 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1113
1114 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
1115
1116 vnt_clear_current_tsf(priv);
1117
1118 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1119
1120 vnt_reset_next_tbtt(priv, conf->beacon_int);
1121
1122 ret = vnt_beacon_make(priv, vif);
1123
1124 return ret;
1125}