blob: 0e853c16b95e88ebf252a0df7be693c3ba39be20 [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
Malcolm Priestley4f316682014-07-10 19:56:17 +010036 * vnt_fill_cts_head- 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 Priestley5abe3d62014-03-18 19:25:06 +000092static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +010093 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -040094
Malcolm Priestley7beae9a22014-07-11 01:08:19 +010095static __le16 s_uGetRTSCTSDuration(struct vnt_private *priv,
96 u8 dur_type, u32 frame_length, u8 pkt_type, u16 rate,
97 int need_ack);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestleyaceaf012013-11-26 19:06:35 +000099static struct vnt_usb_send_context
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000100 *s_vGetFreeContext(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400101{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000102 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000103 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400104
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000105 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400106
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000107 for (ii = 0; ii < priv->cbTD; ii++) {
108 if (!priv->apTD[ii])
109 return NULL;
110
111 context = priv->apTD[ii];
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100112 if (context->in_use == false) {
113 context->in_use = true;
114 memset(context->data, 0,
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000115 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100116
117 context->hdr = NULL;
118
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000119 return context;
120 }
121 }
122
123 if (ii == priv->cbTD)
124 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000125
Malcolm Priestley5c851382013-11-26 19:12:38 +0000126 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400127}
128
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000129static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100130{
131 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
132 [rate % MAX_RATE]);
133}
134
Forest Bond92b96792009-06-13 07:38:31 -0400135/*byPktType : PK_TYPE_11A 0
136 PK_TYPE_11B 1
137 PK_TYPE_11GB 2
138 PK_TYPE_11GA 3
139*/
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000140static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
141 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400142{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000143 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400144
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100145 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000146 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400147
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000148 if (pkt_type == PK_TYPE_11B)
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100149 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
150 14, (u16)priv->byTopCCKBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000151 else
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100152 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
153 14, (u16)priv->byTopOFDMBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000154
155 if (need_ack)
156 return data_time + priv->uSIFS + ack_time;
157
158 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400159}
160
Malcolm Priestley2075f652014-03-18 19:25:07 +0000161static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100162 u32 frame_length, u16 rate, int need_ack)
163{
164 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
165 frame_length, rate, need_ack));
166}
167
Forest Bond92b96792009-06-13 07:38:31 -0400168//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley20338012014-03-18 19:25:08 +0000169static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100170 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400171{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000172 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400173
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000174 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400175
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100176 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100177 frame_length, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400178
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000179 if (rsv_type == 0) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100180 rts_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000181 pkt_type, 20, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100182 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000183 pkt_type, 14, priv->byTopCCKBasicRate);
184 } else if (rsv_type == 1) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100185 rts_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000186 pkt_type, 20, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100187 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000188 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100189 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000190 14, priv->byTopOFDMBasicRate);
191 } else if (rsv_type == 2) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100192 rts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000193 20, priv->byTopOFDMBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100194 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000195 pkt_type, 14, priv->byTopOFDMBasicRate);
196 } else if (rsv_type == 3) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100197 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000198 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100199 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000200 14, priv->byTopOFDMBasicRate);
201
202 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
203
Malcolm Priestley20338012014-03-18 19:25:08 +0000204 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000205 }
206
207 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
208
209 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400210}
211
212//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000213static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100214 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400215{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100216 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400217
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100218 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100219 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100220 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100221 byPktType, 14, pDevice->byTopCCKBasicRate);
222 else
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100223 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100224 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100225 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100226 }
Forest Bond92b96792009-06-13 07:38:31 -0400227
Forest Bond92b96792009-06-13 07:38:31 -0400228 return 0;
229}
230
Forest Bond92b96792009-06-13 07:38:31 -0400231//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100232static __le16 s_uGetRTSCTSDuration(struct vnt_private *priv, u8 dur_type,
233 u32 frame_length, u8 pkt_type, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400234{
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100235 u32 cts_time = 0, dur_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400236
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100237 switch (dur_type) {
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100238 case RTSDUR_BB:
239 case RTSDUR_BA:
240 case RTSDUR_BA_F0:
241 case RTSDUR_BA_F1:
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100242 cts_time = vnt_get_frame_time(priv->byPreambleType,
243 pkt_type, 14, priv->byTopCCKBasicRate);
244 dur_time = cts_time + 2 * priv->uSIFS +
245 s_uGetTxRsvTime(priv, pkt_type,
246 frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100247 break;
Forest Bond92b96792009-06-13 07:38:31 -0400248
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100249 case RTSDUR_AA:
250 case RTSDUR_AA_F0:
251 case RTSDUR_AA_F1:
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100252 cts_time = vnt_get_frame_time(priv->byPreambleType,
253 pkt_type, 14, priv->byTopOFDMBasicRate);
254 dur_time = cts_time + 2 * priv->uSIFS +
255 s_uGetTxRsvTime(priv, pkt_type,
256 frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100257 break;
Forest Bond92b96792009-06-13 07:38:31 -0400258
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100259 case CTSDUR_BA:
260 case CTSDUR_BA_F0:
261 case CTSDUR_BA_F1:
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100262 dur_time = priv->uSIFS + s_uGetTxRsvTime(priv,
263 pkt_type, frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100264 break;
Forest Bond92b96792009-06-13 07:38:31 -0400265
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100266 default:
267 break;
268 }
Forest Bond92b96792009-06-13 07:38:31 -0400269
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100270 return cpu_to_le16((u16)dur_time);
Forest Bond92b96792009-06-13 07:38:31 -0400271}
272
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100273static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
274 struct ieee80211_hdr *hdr)
275{
276 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
277 u8 *hdr_pos = (u8 *)hdr;
278
279 tx_context->hdr = hdr;
280 if (!tx_context->hdr)
281 return 0;
282
283 return (u16)(hdr_pos - head);
284}
285
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100286static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
287 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf,
288 u32 frame_len, int need_ack)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100289{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100290
291 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100292 struct ieee80211_hdr *hdr =
293 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100294
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100295 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100296 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
297 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100298 PK_TYPE_11B, &buf->b);
299
300 /* Get Duration and TimeStamp */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100301 if (ieee80211_is_pspoll(hdr->frame_control)) {
302 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
303
304 buf->duration_a = dur;
305 buf->duration_b = dur;
306 } else {
307 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
308 buf->duration_b = s_uGetDataDuration(priv,
309 PK_TYPE_11B, need_ack);
310 }
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100311
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000312 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
313 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100314 priv->byTopCCKBasicRate);
315
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100316 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
317
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000318 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100319}
320
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100321static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
322 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100323 u32 frame_len, int need_ack)
324{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100325 struct vnt_private *priv = tx_context->priv;
326
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100327 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100328 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100329
Malcolm Priestley205056f2014-06-04 18:25:34 +0100330 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100331 PK_TYPE_11B, &buf->b);
332
333 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000334 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
335 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100336
Malcolm Priestley4e011172014-03-18 19:24:55 +0000337 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
338 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100339
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000340 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
341 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100342 priv->byTopCCKBasicRate);
343
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100344 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
345
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000346 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100347}
348
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100349static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
350 u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100351 u32 frame_len, int need_ack)
352{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100353 struct vnt_private *priv = tx_context->priv;
354
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100355 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100356 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100357 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000358 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100359
Malcolm Priestley4e011172014-03-18 19:24:55 +0000360 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
361 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100362
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000363 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100364
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100365 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
366
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000367 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100368}
369
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100370static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
371 u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100372 u32 frame_len, int need_ack)
373{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100374 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100375 struct ieee80211_hdr *hdr =
376 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100377
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100378 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100379 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->ab);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100380
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100381 /* Get Duration and TimeStampOff */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100382 if (ieee80211_is_pspoll(hdr->frame_control)) {
383 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
384
385 buf->duration = dur;
386 } else {
387 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
388 }
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100389
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000390 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100391
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100392 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
393
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000394 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100395}
396
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100397static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
398 struct ieee80211_rts *rts, __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100399{
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100400 struct ieee80211_hdr *hdr =
401 (struct ieee80211_hdr *)tx_context->skb->data;
402
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100403 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000404 rts->frame_control =
405 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100406
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100407 memcpy(rts->ra, hdr->addr1, ETH_ALEN);
408 memcpy(rts->ta, hdr->addr2, ETH_ALEN);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100409
410 return 0;
411}
412
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100413static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100414 struct vnt_rts_g *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100415 u16 current_rate)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100416{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100417 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100418 u16 rts_frame_len = 20;
419
Malcolm Priestley205056f2014-06-04 18:25:34 +0100420 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100421 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100422 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100423 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
424
Malcolm Priestley4e011172014-03-18 19:24:55 +0000425 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100426 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000427 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100428 pkt_type, current_rate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000429 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100430 pkt_type, current_rate, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100431
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100432 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100433
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100434 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100435 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100436}
437
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100438static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100439 struct vnt_rts_g_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100440 u16 current_rate)
Malcolm Priestleyec917132013-08-26 11:07:46 +0100441{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100442 struct vnt_private *priv = tx_context->priv;
Malcolm Priestleyec917132013-08-26 11:07:46 +0100443 u16 rts_frame_len = 20;
444
Malcolm Priestley205056f2014-06-04 18:25:34 +0100445 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100446 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100447 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100448 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
449
450
Malcolm Priestley4e011172014-03-18 19:24:55 +0000451 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100452 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000453 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100454 pkt_type, current_rate, need_ack);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000455 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100456 pkt_type, current_rate, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100457
458
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000459 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100460 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000461 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100462 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000463 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100464 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000465 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100466 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100467
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100468 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100469
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100470 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100471 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100472}
473
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100474static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100475 struct vnt_rts_ab *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100476 u16 current_rate)
Malcolm Priestley17126332013-08-26 11:09:38 +0100477{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100478 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley17126332013-08-26 11:09:38 +0100479 u16 rts_frame_len = 20;
480
Malcolm Priestley205056f2014-06-04 18:25:34 +0100481 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100482 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
483
Malcolm Priestley4e011172014-03-18 19:24:55 +0000484 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100485 pkt_type, current_rate, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100486
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100487 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100488
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100489 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100490 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100491}
492
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100493static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100494 struct vnt_rts_a_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100495 u16 current_rate)
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100496{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100497 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100498 u16 rts_frame_len = 20;
499
Malcolm Priestley205056f2014-06-04 18:25:34 +0100500 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100501 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
502
Malcolm Priestley4e011172014-03-18 19:24:55 +0000503 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100504 pkt_type, current_rate, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100505
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000506 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100507 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100508
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000509 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100510 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100511
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100512 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100513
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100514 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100515 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100516}
517
Malcolm Priestley4f316682014-07-10 19:56:17 +0100518static u16 vnt_fill_cts_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100519 u8 pkt_type, union vnt_tx_data_head *head, u32 frame_len,
520 int need_ack, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400521{
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100522 struct vnt_private *priv = tx_context->priv;
523 u32 cts_frame_len = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400524
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100525 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100526 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400527
Malcolm Priestleyce7b0db2014-07-10 19:56:03 +0100528 if (tx_context->fb_option) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100529 /* Auto Fall back */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100530 struct vnt_cts_fb *buf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100531 /* Get SignalField,ServiceField,Length */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100532 vnt_get_phy_field(priv, cts_frame_len,
533 priv->byTopCCKBasicRate, PK_TYPE_11B, &buf->b);
534 buf->duration_ba = s_uGetRTSCTSDuration(priv, CTSDUR_BA,
535 frame_len, pkt_type,
536 current_rate, need_ack);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100537 /* Get CTSDuration_ba_f0 */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100538 buf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(priv,
539 CTSDUR_BA_F0, frame_len, pkt_type,
540 priv->tx_rate_fb0, need_ack);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100541 /* Get CTSDuration_ba_f1 */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100542 buf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(priv,
543 CTSDUR_BA_F1, frame_len, pkt_type,
544 priv->tx_rate_fb1, need_ack);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100545 /* Get CTS Frame body */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100546 buf->data.duration = buf->duration_ba;
547 buf->data.frame_control =
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000548 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
549
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100550 memcpy(buf->data.ra, priv->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100551
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100552 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type,
553 current_rate, &buf->data_head, frame_len,
554 need_ack);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100555 } else {
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100556 struct vnt_cts *buf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100557 /* Get SignalField,ServiceField,Length */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100558 vnt_get_phy_field(priv, cts_frame_len,
559 priv->byTopCCKBasicRate, PK_TYPE_11B, &buf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100560 /* Get CTSDuration_ba */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100561 buf->duration_ba = s_uGetRTSCTSDuration(priv,
562 CTSDUR_BA, frame_len, pkt_type,
563 current_rate, need_ack);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100564 /*Get CTS Frame body*/
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100565 buf->data.duration = buf->duration_ba;
566 buf->data.frame_control =
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000567 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
568
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100569 memcpy(buf->data.ra, priv->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100570
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100571 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
572 &buf->data_head, frame_len, need_ack);
Forest Bond92b96792009-06-13 07:38:31 -0400573 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100574
575 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400576}
577
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100578static u16 vnt_rxtx_rts(struct vnt_usb_send_context *tx_context,
579 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100580 int need_ack, u16 current_rate, bool need_mic)
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100581{
582 struct vnt_private *priv = tx_context->priv;
583 struct vnt_rrv_time_rts *buf = &tx_head->tx_rts.rts;
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100584 union vnt_tx_data_head *head = &tx_head->tx_rts.tx.head;
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100585
586 buf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(priv, 2,
587 pkt_type, frame_size, current_rate);
588 buf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(priv, 1,
589 pkt_type, frame_size, current_rate);
590 buf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(priv, 0,
591 pkt_type, frame_size, current_rate);
592
593 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, pkt_type, frame_size,
594 current_rate, need_ack);
595 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B, frame_size,
596 priv->byTopCCKBasicRate, need_ack);
597
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100598 if (need_mic)
599 head = &tx_head->tx_rts.tx.mic.head;
600
601 if (tx_context->fb_option)
602 return vnt_rxtx_rts_g_fb_head(tx_context, &head->rts_g_fb,
603 pkt_type, frame_size, need_ack, current_rate);
604
605 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g,
606 pkt_type, frame_size, need_ack, current_rate);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100607}
608
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100609static u16 vnt_rxtx_cts(struct vnt_usb_send_context *tx_context,
610 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100611 int need_ack, u16 current_rate, bool need_mic)
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100612{
613 struct vnt_private *priv = tx_context->priv;
614 struct vnt_rrv_time_cts *buf = &tx_head->tx_cts.cts;
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100615 union vnt_tx_data_head *head = &tx_head->tx_cts.tx.head;
616
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100617
618 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, pkt_type,
619 frame_size, current_rate, need_ack);
620 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B,
621 frame_size, priv->byTopCCKBasicRate, need_ack);
622
623 buf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(priv, 3,
624 pkt_type, frame_size, current_rate);
625
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100626 if (need_mic)
627 head = &tx_head->tx_cts.tx.mic.head;
628
629 /* Fill CTS */
Malcolm Priestley4f316682014-07-10 19:56:17 +0100630 return vnt_fill_cts_head(tx_context, pkt_type, head, frame_size,
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100631 need_ack, current_rate);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100632}
633
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100634static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context,
635 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestley681acf62014-07-10 19:56:12 +0100636 int need_ack, u16 current_rate, bool need_rts, bool need_mic)
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100637{
638 struct vnt_private *priv = tx_context->priv;
639 struct vnt_rrv_time_ab *buf = &tx_head->tx_ab.ab;
Malcolm Priestley681acf62014-07-10 19:56:12 +0100640 union vnt_tx_data_head *head = &tx_head->tx_ab.tx.head;
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100641
642 buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, pkt_type,
643 frame_size, current_rate, need_ack);
644
Malcolm Priestley681acf62014-07-10 19:56:12 +0100645 if (need_mic)
646 head = &tx_head->tx_ab.tx.mic.head;
647
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100648 if (need_rts) {
649 if (pkt_type == PK_TYPE_11B)
650 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(priv, 0,
651 pkt_type, frame_size, current_rate);
652 else /* PK_TYPE_11A */
653 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(priv, 2,
654 pkt_type, frame_size, current_rate);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100655
656 if (tx_context->fb_option && pkt_type == PK_TYPE_11A)
657 return vnt_rxtx_rts_a_fb_head(tx_context,
658 &head->rts_a_fb, pkt_type, frame_size,
659 need_ack, current_rate);
660
661 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab,
662 pkt_type, frame_size, need_ack, current_rate);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100663 }
664
Malcolm Priestley681acf62014-07-10 19:56:12 +0100665 if (pkt_type == PK_TYPE_11A)
666 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type,
667 current_rate, &head->data_head_a_fb,
668 frame_size, need_ack);
669
670 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
671 &head->data_head_ab, frame_size, need_ack);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100672}
673
Forest Bond92b96792009-06-13 07:38:31 -0400674/*+
675 *
676 * Description:
677 * Generate FIFO control for MAC & Baseband controller
678 *
679 * Parameters:
680 * In:
681 * pDevice - Pointer to adpater
682 * pTxDataHead - Transmit Data Buffer
683 * pTxBufHead - pTxBufHead
684 * pvRrvTime - pvRrvTime
685 * pvRTS - RTS Buffer
686 * pCTS - CTS Buffer
687 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
688 * bNeedACK - If need ACK
Forest Bond92b96792009-06-13 07:38:31 -0400689 * Out:
690 * none
691 *
692 * Return Value: none
693 *
694-*/
Andres Morecc856e62010-05-17 21:34:01 -0300695
Malcolm Priestley9ec7f2d2014-07-10 19:56:15 +0100696static u16 vnt_generate_tx_parameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley165ac772014-07-10 19:56:14 +0100697 u8 pkt_type, u16 current_rate, struct vnt_tx_buffer *tx_buffer,
698 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 frame_size,
699 int need_ack, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400700{
Forest Bond92b96792009-06-13 07:38:31 -0400701
Malcolm Priestley165ac772014-07-10 19:56:14 +0100702 if (pkt_type == PK_TYPE_11GB || pkt_type == PK_TYPE_11GA) {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100703 if (need_rts) {
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100704 if (need_mic)
Malcolm Priestley92928f12013-10-07 20:14:01 +0100705 *mic_hdr = &tx_buffer->
706 tx_head.tx_rts.tx.mic.hdr;
Malcolm Priestley92928f12013-10-07 20:14:01 +0100707
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100708 return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head,
Malcolm Priestley165ac772014-07-10 19:56:14 +0100709 pkt_type, frame_size, need_ack,
710 current_rate, need_mic);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100711 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100712
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100713 if (need_mic)
714 *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr;
715
Malcolm Priestley165ac772014-07-10 19:56:14 +0100716 return vnt_rxtx_cts(tx_context, &tx_buffer->tx_head, pkt_type,
717 frame_size, need_ack, current_rate, need_mic);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100718 }
719
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100720 if (need_mic)
721 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
722
Malcolm Priestley165ac772014-07-10 19:56:14 +0100723 return vnt_rxtx_ab(tx_context, &tx_buffer->tx_head, pkt_type,
724 frame_size, need_ack, current_rate, need_rts, need_mic);
Forest Bond92b96792009-06-13 07:38:31 -0400725}
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100726
727static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
728 u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
729 u16 payload_len, struct vnt_mic_hdr *mic_hdr)
730{
731 struct ieee80211_hdr *hdr = tx_context->hdr;
732 struct ieee80211_key_seq seq;
733 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
734
735 /* strip header and icv len from payload */
736 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
737 payload_len -= tx_key->icv_len;
738
739 switch (tx_key->cipher) {
740 case WLAN_CIPHER_SUITE_WEP40:
741 case WLAN_CIPHER_SUITE_WEP104:
742 memcpy(key_buffer, iv, 3);
743 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
744
745 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
746 memcpy(key_buffer + 8, iv, 3);
747 memcpy(key_buffer + 11,
748 tx_key->key, WLAN_KEY_LEN_WEP40);
749 }
750
751 break;
752 case WLAN_CIPHER_SUITE_TKIP:
753 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
754
755 break;
756 case WLAN_CIPHER_SUITE_CCMP:
757
758 if (!mic_hdr)
759 return;
760
761 mic_hdr->id = 0x59;
762 mic_hdr->payload_len = cpu_to_be16(payload_len);
763 memcpy(mic_hdr->mic_addr2, hdr->addr2, ETH_ALEN);
764
765 ieee80211_get_key_tx_seq(tx_key, &seq);
766
Malcolm Priestley79f976d2014-06-28 23:55:39 +0100767 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100768
769 if (ieee80211_has_a4(hdr->frame_control))
770 mic_hdr->hlen = cpu_to_be16(28);
771 else
772 mic_hdr->hlen = cpu_to_be16(22);
773
774 memcpy(mic_hdr->addr1, hdr->addr1, ETH_ALEN);
775 memcpy(mic_hdr->addr2, hdr->addr2, ETH_ALEN);
776 memcpy(mic_hdr->addr3, hdr->addr3, ETH_ALEN);
777
778 mic_hdr->frame_control = cpu_to_le16(
779 le16_to_cpu(hdr->frame_control) & 0xc78f);
780 mic_hdr->seq_ctrl = cpu_to_le16(
781 le16_to_cpu(hdr->seq_ctrl) & 0xf);
782
783 if (ieee80211_has_a4(hdr->frame_control))
784 memcpy(mic_hdr->addr4, hdr->addr4, ETH_ALEN);
785
786
787 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
788
789 break;
790 default:
791 break;
792 }
793
794}
795
796int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
797{
798 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
799 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
800 struct ieee80211_rate *rate;
801 struct ieee80211_key_conf *tx_key;
802 struct ieee80211_hdr *hdr;
803 struct vnt_mic_hdr *mic_hdr = NULL;
804 struct vnt_tx_buffer *tx_buffer;
805 struct vnt_tx_fifo_head *tx_buffer_head;
806 struct vnt_usb_send_context *tx_context;
807 unsigned long flags;
808 u32 frame_size = 0;
809 u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
810 u8 pkt_type, fb_option = AUTO_FB_NONE;
811 bool need_rts = false, need_ack = false, is_pspoll = false;
812 bool need_mic = false;
813
814 hdr = (struct ieee80211_hdr *)(skb->data);
815
816 rate = ieee80211_get_tx_rate(priv->hw, info);
817
818 current_rate = rate->hw_value;
Malcolm Priestley5091d962014-07-05 19:24:23 +0100819 if (priv->wCurrentRate != current_rate &&
820 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100821 priv->wCurrentRate = current_rate;
822 bScheduleCommand(priv, WLAN_CMD_SETPOWER, NULL);
823 }
824
825 if (current_rate > RATE_11M)
826 pkt_type = priv->byPacketType;
827 else
828 pkt_type = PK_TYPE_11B;
829
830 spin_lock_irqsave(&priv->lock, flags);
831
832 tx_context = s_vGetFreeContext(priv);
833 if (!tx_context) {
834 dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
835 spin_unlock_irqrestore(&priv->lock, flags);
836 return -ENOMEM;
837 }
838
839 tx_context->skb = skb;
840
841 spin_unlock_irqrestore(&priv->lock, flags);
842
843 tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
844 tx_buffer_head = &tx_buffer->fifo_head;
845 tx_body_size = skb->len;
846
847 frame_size = tx_body_size + 4;
848
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100849 /*Set fifo controls */
850 if (pkt_type == PK_TYPE_11A)
851 tx_buffer_head->wFIFOCtl = 0;
852 else if (pkt_type == PK_TYPE_11B)
853 tx_buffer_head->wFIFOCtl = FIFOCTL_11B;
854 else if (pkt_type == PK_TYPE_11GB)
855 tx_buffer_head->wFIFOCtl = FIFOCTL_11GB;
856 else if (pkt_type == PK_TYPE_11GA)
857 tx_buffer_head->wFIFOCtl = FIFOCTL_11GA;
858
859 if (!ieee80211_is_data(hdr->frame_control)) {
860 tx_buffer_head->wFIFOCtl |= (FIFOCTL_GENINT |
861 FIFOCTL_ISDMA0);
862 tx_buffer_head->wFIFOCtl |= FIFOCTL_TMOEN;
863
864 tx_buffer_head->time_stamp =
865 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
866 } else {
867 tx_buffer_head->time_stamp =
868 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
869 }
870
871 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
872 tx_buffer_head->wFIFOCtl |= FIFOCTL_NEEDACK;
873 need_ack = true;
874 }
875
876 if (ieee80211_has_retry(hdr->frame_control))
877 tx_buffer_head->wFIFOCtl |= FIFOCTL_LRETRY;
878
879 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
880 priv->byPreambleType = PREAMBLE_SHORT;
881 else
882 priv->byPreambleType = PREAMBLE_LONG;
883
884 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
885 need_rts = true;
886 tx_buffer_head->wFIFOCtl |= FIFOCTL_RTS;
887 }
888
889 if (ieee80211_has_a4(hdr->frame_control))
890 tx_buffer_head->wFIFOCtl |= FIFOCTL_LHEAD;
891
892 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
893 is_pspoll = true;
894
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100895 tx_buffer_head->frag_ctl =
896 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100897
898 if (info->control.hw_key) {
899 tx_key = info->control.hw_key;
900 switch (info->control.hw_key->cipher) {
901 case WLAN_CIPHER_SUITE_WEP40:
902 case WLAN_CIPHER_SUITE_WEP104:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100903 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100904 break;
905 case WLAN_CIPHER_SUITE_TKIP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100906 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100907 break;
908 case WLAN_CIPHER_SUITE_CCMP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100909 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100910 need_mic = true;
911 default:
912 break;
913 }
914 frame_size += tx_key->icv_len;
915 }
916
Malcolm Priestleycb8ee9de2014-07-10 19:56:05 +0100917 tx_buffer_head->current_rate = cpu_to_le16(current_rate);
918
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100919 /* legacy rates TODO use ieee80211_tx_rate */
920 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
921 if (priv->byAutoFBCtrl == AUTO_FB_0) {
922 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
923
924 priv->tx_rate_fb0 =
925 wFB_Opt0[FB_RATE0][current_rate - RATE_18M];
926 priv->tx_rate_fb1 =
927 wFB_Opt0[FB_RATE1][current_rate - RATE_18M];
928
929 fb_option = AUTO_FB_0;
930 } else if (priv->byAutoFBCtrl == AUTO_FB_1) {
931 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
932
933 priv->tx_rate_fb0 =
934 wFB_Opt1[FB_RATE0][current_rate - RATE_18M];
935 priv->tx_rate_fb1 =
936 wFB_Opt1[FB_RATE1][current_rate - RATE_18M];
937
938 fb_option = AUTO_FB_1;
939 }
940 }
941
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100942 tx_context->fb_option = fb_option;
943
Malcolm Priestley9ec7f2d2014-07-10 19:56:15 +0100944 duration_id = vnt_generate_tx_parameter(tx_context, pkt_type,
945 current_rate, tx_buffer, &mic_hdr, need_mic, frame_size,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100946 need_ack, need_rts);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100947
948 tx_header_size = tx_context->tx_hdr_size;
949 if (!tx_header_size) {
950 tx_context->in_use = false;
951 return -ENOMEM;
952 }
953
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100954 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100955
956 tx_bytes = tx_header_size + tx_body_size;
957
958 memcpy(tx_context->hdr, skb->data, tx_body_size);
959
960 hdr->duration_id = cpu_to_le16(duration_id);
961
962 if (info->control.hw_key) {
963 tx_key = info->control.hw_key;
964 if (tx_key->keylen > 0)
965 vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
966 tx_key, skb, tx_body_size, mic_hdr);
967 }
968
969 priv->wSeqCounter = (le16_to_cpu(hdr->seq_ctrl) &
970 IEEE80211_SCTL_SEQ) >> 4;
971
972 tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100973 tx_buffer->byPKTNO = tx_context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100974 tx_buffer->byType = 0x00;
975
976 tx_bytes += 4;
977
978 tx_context->type = CONTEXT_DATA_PACKET;
979 tx_context->buf_len = tx_bytes;
980
981 spin_lock_irqsave(&priv->lock, flags);
982
983 if (PIPEnsSendBulkOut(priv, tx_context) != STATUS_PENDING) {
984 spin_unlock_irqrestore(&priv->lock, flags);
985 return -EIO;
986 }
987
988 spin_unlock_irqrestore(&priv->lock, flags);
989
990 return 0;
991}
992
993static int vnt_beacon_xmit(struct vnt_private *priv,
994 struct sk_buff *skb)
995{
996 struct vnt_beacon_buffer *beacon_buffer;
997 struct vnt_tx_short_buf_head *short_head;
998 struct ieee80211_tx_info *info;
999 struct vnt_usb_send_context *context;
1000 struct ieee80211_mgmt *mgmt_hdr;
1001 unsigned long flags;
1002 u32 frame_size = skb->len + 4;
1003 u16 current_rate, count;
1004
1005 spin_lock_irqsave(&priv->lock, flags);
1006
1007 context = s_vGetFreeContext(priv);
1008 if (!context) {
1009 dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
1010 spin_unlock_irqrestore(&priv->lock, flags);
1011 return -ENOMEM;
1012 }
1013
1014 context->skb = skb;
1015
1016 spin_unlock_irqrestore(&priv->lock, flags);
1017
1018 beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
1019 short_head = &beacon_buffer->short_head;
1020
1021 if (priv->byBBType == BB_TYPE_11A) {
1022 current_rate = RATE_6M;
1023
1024 /* Get SignalField,ServiceField,Length */
1025 vnt_get_phy_field(priv, frame_size, current_rate,
1026 PK_TYPE_11A, &short_head->ab);
1027
1028 /* Get Duration and TimeStampOff */
1029 short_head->duration = s_uGetDataDuration(priv,
1030 PK_TYPE_11A, false);
1031 short_head->time_stamp_off =
1032 vnt_time_stamp_off(priv, current_rate);
1033 } else {
1034 current_rate = RATE_1M;
1035 short_head->fifo_ctl |= FIFOCTL_11B;
1036
1037 /* Get SignalField,ServiceField,Length */
1038 vnt_get_phy_field(priv, frame_size, current_rate,
1039 PK_TYPE_11B, &short_head->ab);
1040
1041 /* Get Duration and TimeStampOff */
1042 short_head->duration = s_uGetDataDuration(priv,
1043 PK_TYPE_11B, false);
1044 short_head->time_stamp_off =
1045 vnt_time_stamp_off(priv, current_rate);
1046 }
1047
1048 /* Generate Beacon Header */
1049 mgmt_hdr = &beacon_buffer->mgmt_hdr;
1050 memcpy(mgmt_hdr, skb->data, skb->len);
1051
1052 /* time stamp always 0 */
1053 mgmt_hdr->u.beacon.timestamp = 0;
1054
1055 info = IEEE80211_SKB_CB(skb);
1056 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1057 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
1058 hdr->duration_id = 0;
1059 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
1060 }
1061
1062 priv->wSeqCounter++;
1063 if (priv->wSeqCounter > 0x0fff)
1064 priv->wSeqCounter = 0;
1065
1066 count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
1067
1068 beacon_buffer->tx_byte_count = cpu_to_le16(count);
Malcolm Priestley71d764a2014-07-05 19:24:27 +01001069 beacon_buffer->byPKTNO = context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001070 beacon_buffer->byType = 0x01;
1071
1072 context->type = CONTEXT_BEACON_PACKET;
1073 context->buf_len = count + 4; /* USB header */
1074
1075 spin_lock_irqsave(&priv->lock, flags);
1076
1077 if (PIPEnsSendBulkOut(priv, context) != STATUS_PENDING)
1078 ieee80211_free_txskb(priv->hw, context->skb);
1079
1080 spin_unlock_irqrestore(&priv->lock, flags);
1081
1082 return 0;
1083}
1084
1085int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1086{
1087 struct sk_buff *beacon;
1088
1089 beacon = ieee80211_beacon_get(priv->hw, vif);
1090 if (!beacon)
1091 return -ENOMEM;
1092
1093 if (vnt_beacon_xmit(priv, beacon)) {
1094 ieee80211_free_txskb(priv->hw, beacon);
1095 return -ENODEV;
1096 }
1097
1098 return 0;
1099}
1100
1101int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1102 struct ieee80211_bss_conf *conf)
1103{
1104 int ret;
1105
1106 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1107
1108 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1109
1110 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
1111
1112 vnt_clear_current_tsf(priv);
1113
1114 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1115
1116 vnt_reset_next_tbtt(priv, conf->beacon_int);
1117
1118 ret = vnt_beacon_make(priv, vif);
1119
1120 return ret;
1121}