blob: 6ca2638056854c076107ddb3d5eacc9a9efd4ebf [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
Malcolm Priestley435ae3b2014-07-11 01:08:22 +010031 * vnt_get_duration_le - get tx data required duration
Forest Bond92b96792009-06-13 07:38:31 -040032 * s_uFillDataHead- fulfill tx data duration header
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +010033 * vnt_get_rtscts_duration_le- get rtx/cts required duration
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +010034 * vnt_get_rtscts_rsvtime_le- get rts/cts reserved time
Malcolm Priestley3815a272014-07-11 01:08:24 +010035 * vnt_get_rsvtime- 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
Malcolm Priestley1a4d45092014-07-11 01:08:25 +010055static const u16 vnt_time_stampoff[2][MAX_RATE] = {
56 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23},/* Long Preamble */
57 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23},/* Short Preamble */
58};
Forest Bond92b96792009-06-13 07:38:31 -040059
Malcolm Priestleye3f31872014-07-11 01:08:26 +010060static const u16 vnt_fb_opt0[2][5] = {
61 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, /* fallback_rate0 */
62 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, /* fallback_rate1 */
63};
64
Valentina Manea3b138852013-11-04 10:44:02 +020065static const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040066 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
67 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
68 };
69
Forest Bond92b96792009-06-13 07:38:31 -040070#define RTSDUR_BB 0
71#define RTSDUR_BA 1
72#define RTSDUR_AA 2
73#define CTSDUR_BA 3
74#define RTSDUR_BA_F0 4
75#define RTSDUR_AA_F0 5
76#define RTSDUR_BA_F1 6
77#define RTSDUR_AA_F1 7
78#define CTSDUR_BA_F0 8
79#define CTSDUR_BA_F1 9
80#define DATADUR_B 10
81#define DATADUR_A 11
82#define DATADUR_A_F0 12
83#define DATADUR_A_F1 13
84
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000085static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000086
Malcolm Priestley3815a272014-07-11 01:08:24 +010087static unsigned int vnt_get_rsvtime(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000088 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -040089
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +010090static __le16 vnt_get_rtscts_rsvtime_le(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +010091 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate);
Forest Bond92b96792009-06-13 07:38:31 -040092
Malcolm Priestley435ae3b2014-07-11 01:08:22 +010093static __le16 vnt_get_duration_le(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +010094 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -040095
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +010096static __le16 vnt_get_rtscts_duration_le(struct vnt_private *priv,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +010097 u8 dur_type, u32 frame_length, u8 pkt_type, u16 rate,
98 int need_ack);
Forest Bond92b96792009-06-13 07:38:31 -040099
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000100static struct vnt_usb_send_context
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000101 *s_vGetFreeContext(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400102{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000103 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000104 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400105
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000106 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400107
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000108 for (ii = 0; ii < priv->cbTD; ii++) {
109 if (!priv->apTD[ii])
110 return NULL;
111
112 context = priv->apTD[ii];
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100113 if (context->in_use == false) {
114 context->in_use = true;
115 memset(context->data, 0,
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000116 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100117
118 context->hdr = NULL;
119
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000120 return context;
121 }
122 }
123
124 if (ii == priv->cbTD)
125 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000126
Malcolm Priestley5c851382013-11-26 19:12:38 +0000127 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400128}
129
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000130static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100131{
Malcolm Priestley1a4d45092014-07-11 01:08:25 +0100132 return cpu_to_le16(vnt_time_stampoff[priv->byPreambleType % 2]
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100133 [rate % MAX_RATE]);
134}
135
Forest Bond92b96792009-06-13 07:38:31 -0400136/*byPktType : PK_TYPE_11A 0
137 PK_TYPE_11B 1
138 PK_TYPE_11GB 2
139 PK_TYPE_11GA 3
140*/
Malcolm Priestley3815a272014-07-11 01:08:24 +0100141static u32 vnt_get_rsvtime(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000142 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400143{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000144 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400145
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100146 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000147 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400148
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000149 if (pkt_type == PK_TYPE_11B)
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100150 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
151 14, (u16)priv->byTopCCKBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000152 else
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100153 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
154 14, (u16)priv->byTopOFDMBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000155
156 if (need_ack)
157 return data_time + priv->uSIFS + ack_time;
158
159 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400160}
161
Malcolm Priestley2075f652014-03-18 19:25:07 +0000162static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100163 u32 frame_length, u16 rate, int need_ack)
164{
Malcolm Priestley3815a272014-07-11 01:08:24 +0100165 return cpu_to_le16((u16)vnt_get_rsvtime(priv, pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100166 frame_length, rate, need_ack));
167}
168
Forest Bond92b96792009-06-13 07:38:31 -0400169//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100170static __le16 vnt_get_rtscts_rsvtime_le(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100171 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400172{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000173 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400174
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000175 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400176
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100177 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100178 frame_length, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400179
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000180 if (rsv_type == 0) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100181 rts_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000182 pkt_type, 20, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100183 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000184 pkt_type, 14, priv->byTopCCKBasicRate);
185 } else if (rsv_type == 1) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100186 rts_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000187 pkt_type, 20, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100188 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000189 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100190 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000191 14, priv->byTopOFDMBasicRate);
192 } else if (rsv_type == 2) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100193 rts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000194 20, priv->byTopOFDMBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100195 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000196 pkt_type, 14, priv->byTopOFDMBasicRate);
197 } else if (rsv_type == 3) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100198 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000199 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100200 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000201 14, priv->byTopOFDMBasicRate);
202
203 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
204
Malcolm Priestley20338012014-03-18 19:25:08 +0000205 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000206 }
207
208 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
209
210 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400211}
212
213//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100214static __le16 vnt_get_duration_le(struct vnt_private *piv,
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100215 u8 pkt_type, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400216{
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100217 u32 ack_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400218
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100219 if (need_ack) {
220 if (pkt_type == PK_TYPE_11B)
221 ack_time = vnt_get_frame_time(piv->byPreambleType,
222 pkt_type, 14, piv->byTopCCKBasicRate);
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100223 else
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100224 ack_time = vnt_get_frame_time(piv->byPreambleType,
225 pkt_type, 14, piv->byTopOFDMBasicRate);
226
227 return cpu_to_le16((u16)(piv->uSIFS + ack_time));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100228 }
Forest Bond92b96792009-06-13 07:38:31 -0400229
Forest Bond92b96792009-06-13 07:38:31 -0400230 return 0;
231}
232
Forest Bond92b96792009-06-13 07:38:31 -0400233//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100234static __le16 vnt_get_rtscts_duration_le(struct vnt_private *priv, u8 dur_type,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100235 u32 frame_length, u8 pkt_type, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400236{
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100237 u32 cts_time = 0, dur_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400238
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100239 switch (dur_type) {
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100240 case RTSDUR_BB:
241 case RTSDUR_BA:
242 case RTSDUR_BA_F0:
243 case RTSDUR_BA_F1:
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100244 cts_time = vnt_get_frame_time(priv->byPreambleType,
245 pkt_type, 14, priv->byTopCCKBasicRate);
246 dur_time = cts_time + 2 * priv->uSIFS +
Malcolm Priestley3815a272014-07-11 01:08:24 +0100247 vnt_get_rsvtime(priv, pkt_type,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100248 frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100249 break;
Forest Bond92b96792009-06-13 07:38:31 -0400250
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100251 case RTSDUR_AA:
252 case RTSDUR_AA_F0:
253 case RTSDUR_AA_F1:
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100254 cts_time = vnt_get_frame_time(priv->byPreambleType,
255 pkt_type, 14, priv->byTopOFDMBasicRate);
256 dur_time = cts_time + 2 * priv->uSIFS +
Malcolm Priestley3815a272014-07-11 01:08:24 +0100257 vnt_get_rsvtime(priv, pkt_type,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100258 frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100259 break;
Forest Bond92b96792009-06-13 07:38:31 -0400260
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100261 case CTSDUR_BA:
262 case CTSDUR_BA_F0:
263 case CTSDUR_BA_F1:
Malcolm Priestley3815a272014-07-11 01:08:24 +0100264 dur_time = priv->uSIFS + vnt_get_rsvtime(priv,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100265 pkt_type, frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100266 break;
Forest Bond92b96792009-06-13 07:38:31 -0400267
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100268 default:
269 break;
270 }
Forest Bond92b96792009-06-13 07:38:31 -0400271
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100272 return cpu_to_le16((u16)dur_time);
Forest Bond92b96792009-06-13 07:38:31 -0400273}
274
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100275static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
276 struct ieee80211_hdr *hdr)
277{
278 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
279 u8 *hdr_pos = (u8 *)hdr;
280
281 tx_context->hdr = hdr;
282 if (!tx_context->hdr)
283 return 0;
284
285 return (u16)(hdr_pos - head);
286}
287
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100288static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
289 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf,
290 u32 frame_len, int need_ack)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100291{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100292
293 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100294 struct ieee80211_hdr *hdr =
295 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100296
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100297 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100298 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
299 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100300 PK_TYPE_11B, &buf->b);
301
302 /* Get Duration and TimeStamp */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100303 if (ieee80211_is_pspoll(hdr->frame_control)) {
304 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
305
306 buf->duration_a = dur;
307 buf->duration_b = dur;
308 } else {
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100309 buf->duration_a = vnt_get_duration_le(priv, pkt_type, need_ack);
310 buf->duration_b = vnt_get_duration_le(priv,
Malcolm Priestley893cc702014-06-25 21:14:38 +0100311 PK_TYPE_11B, need_ack);
312 }
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100313
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000314 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
315 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100316 priv->byTopCCKBasicRate);
317
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100318 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
319
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000320 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100321}
322
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100323static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
324 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100325 u32 frame_len, int need_ack)
326{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100327 struct vnt_private *priv = tx_context->priv;
328
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100329 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100330 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100331
Malcolm Priestley205056f2014-06-04 18:25:34 +0100332 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100333 PK_TYPE_11B, &buf->b);
334
335 /* Get Duration and TimeStamp */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100336 buf->duration_a = vnt_get_duration_le(priv, pkt_type, need_ack);
337 buf->duration_b = vnt_get_duration_le(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100338
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100339 buf->duration_a_f0 = vnt_get_duration_le(priv, pkt_type, need_ack);
340 buf->duration_a_f1 = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100341
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000342 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
343 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100344 priv->byTopCCKBasicRate);
345
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100346 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
347
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000348 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100349}
350
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100351static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
352 u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100353 u32 frame_len, int need_ack)
354{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100355 struct vnt_private *priv = tx_context->priv;
356
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100357 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100358 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100359 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100360 buf->duration = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100361
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100362 buf->duration_f0 = vnt_get_duration_le(priv, pkt_type, need_ack);
363 buf->duration_f1 = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100364
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000365 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100366
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100367 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
368
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000369 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100370}
371
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100372static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
373 u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100374 u32 frame_len, int need_ack)
375{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100376 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100377 struct ieee80211_hdr *hdr =
378 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100379
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100380 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100381 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->ab);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100382
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100383 /* Get Duration and TimeStampOff */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100384 if (ieee80211_is_pspoll(hdr->frame_control)) {
385 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
386
387 buf->duration = dur;
388 } else {
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100389 buf->duration = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100390 }
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100391
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000392 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100393
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100394 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
395
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000396 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100397}
398
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100399static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
400 struct ieee80211_rts *rts, __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100401{
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100402 struct ieee80211_hdr *hdr =
403 (struct ieee80211_hdr *)tx_context->skb->data;
404
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100405 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000406 rts->frame_control =
407 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100408
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100409 memcpy(rts->ra, hdr->addr1, ETH_ALEN);
410 memcpy(rts->ta, hdr->addr2, ETH_ALEN);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100411
412 return 0;
413}
414
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100415static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100416 struct vnt_rts_g *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100417 u16 current_rate)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100418{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100419 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100420 u16 rts_frame_len = 20;
421
Malcolm Priestley205056f2014-06-04 18:25:34 +0100422 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100423 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100424 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100425 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
426
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100427 buf->duration_bb = vnt_get_rtscts_duration_le(priv, RTSDUR_BB,
428 frame_len, PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
429 buf->duration_aa = vnt_get_rtscts_duration_le(priv, RTSDUR_AA,
430 frame_len, pkt_type, current_rate, need_ack);
431 buf->duration_ba = vnt_get_rtscts_duration_le(priv, RTSDUR_BA,
432 frame_len, pkt_type, current_rate, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100433
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100434 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100435
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100436 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100437 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100438}
439
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100440static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100441 struct vnt_rts_g_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100442 u16 current_rate)
Malcolm Priestleyec917132013-08-26 11:07:46 +0100443{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100444 struct vnt_private *priv = tx_context->priv;
Malcolm Priestleyec917132013-08-26 11:07:46 +0100445 u16 rts_frame_len = 20;
446
Malcolm Priestley205056f2014-06-04 18:25:34 +0100447 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100448 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100449 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100450 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
451
452
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100453 buf->duration_bb = vnt_get_rtscts_duration_le(priv, RTSDUR_BB,
454 frame_len, PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
455 buf->duration_aa = vnt_get_rtscts_duration_le(priv, RTSDUR_AA,
456 frame_len, pkt_type, current_rate, need_ack);
457 buf->duration_ba = vnt_get_rtscts_duration_le(priv, RTSDUR_BA,
458 frame_len, pkt_type, current_rate, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100459
460
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100461 buf->rts_duration_ba_f0 = vnt_get_rtscts_duration_le(priv, RTSDUR_BA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100462 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100463 buf->rts_duration_aa_f0 = vnt_get_rtscts_duration_le(priv, RTSDUR_AA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100464 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100465 buf->rts_duration_ba_f1 = vnt_get_rtscts_duration_le(priv, RTSDUR_BA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100466 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100467 buf->rts_duration_aa_f1 = vnt_get_rtscts_duration_le(priv, RTSDUR_AA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100468 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100469
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100470 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100471
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100472 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100473 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100474}
475
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100476static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100477 struct vnt_rts_ab *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100478 u16 current_rate)
Malcolm Priestley17126332013-08-26 11:09:38 +0100479{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100480 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley17126332013-08-26 11:09:38 +0100481 u16 rts_frame_len = 20;
482
Malcolm Priestley205056f2014-06-04 18:25:34 +0100483 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100484 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
485
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100486 buf->duration = vnt_get_rtscts_duration_le(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100487 pkt_type, current_rate, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100488
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100489 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100490
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100491 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100492 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100493}
494
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100495static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100496 struct vnt_rts_a_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100497 u16 current_rate)
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100498{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100499 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100500 u16 rts_frame_len = 20;
501
Malcolm Priestley205056f2014-06-04 18:25:34 +0100502 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100503 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
504
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100505 buf->duration = vnt_get_rtscts_duration_le(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100506 pkt_type, current_rate, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100507
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100508 buf->rts_duration_f0 = vnt_get_rtscts_duration_le(priv, RTSDUR_AA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100509 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100510
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100511 buf->rts_duration_f1 = vnt_get_rtscts_duration_le(priv, RTSDUR_AA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100512 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100513
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100514 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100515
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100516 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100517 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100518}
519
Malcolm Priestley4f316682014-07-10 19:56:17 +0100520static u16 vnt_fill_cts_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100521 u8 pkt_type, union vnt_tx_data_head *head, u32 frame_len,
522 int need_ack, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400523{
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100524 struct vnt_private *priv = tx_context->priv;
525 u32 cts_frame_len = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400526
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100527 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100528 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400529
Malcolm Priestleyce7b0db2014-07-10 19:56:03 +0100530 if (tx_context->fb_option) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100531 /* Auto Fall back */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100532 struct vnt_cts_fb *buf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100533 /* Get SignalField,ServiceField,Length */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100534 vnt_get_phy_field(priv, cts_frame_len,
535 priv->byTopCCKBasicRate, PK_TYPE_11B, &buf->b);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100536 buf->duration_ba = vnt_get_rtscts_duration_le(priv, CTSDUR_BA,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100537 frame_len, pkt_type,
538 current_rate, need_ack);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100539 /* Get CTSDuration_ba_f0 */
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100540 buf->cts_duration_ba_f0 = vnt_get_rtscts_duration_le(priv,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100541 CTSDUR_BA_F0, frame_len, pkt_type,
542 priv->tx_rate_fb0, need_ack);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100543 /* Get CTSDuration_ba_f1 */
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100544 buf->cts_duration_ba_f1 = vnt_get_rtscts_duration_le(priv,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100545 CTSDUR_BA_F1, frame_len, pkt_type,
546 priv->tx_rate_fb1, need_ack);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100547 /* Get CTS Frame body */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100548 buf->data.duration = buf->duration_ba;
549 buf->data.frame_control =
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000550 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
551
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100552 memcpy(buf->data.ra, priv->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100553
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100554 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type,
555 current_rate, &buf->data_head, frame_len,
556 need_ack);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100557 } else {
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100558 struct vnt_cts *buf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100559 /* Get SignalField,ServiceField,Length */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100560 vnt_get_phy_field(priv, cts_frame_len,
561 priv->byTopCCKBasicRate, PK_TYPE_11B, &buf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100562 /* Get CTSDuration_ba */
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100563 buf->duration_ba = vnt_get_rtscts_duration_le(priv,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100564 CTSDUR_BA, frame_len, pkt_type,
565 current_rate, need_ack);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100566 /*Get CTS Frame body*/
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100567 buf->data.duration = buf->duration_ba;
568 buf->data.frame_control =
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000569 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
570
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100571 memcpy(buf->data.ra, priv->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100572
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100573 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
574 &buf->data_head, frame_len, need_ack);
Forest Bond92b96792009-06-13 07:38:31 -0400575 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100576
577 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400578}
579
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100580static u16 vnt_rxtx_rts(struct vnt_usb_send_context *tx_context,
581 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100582 int need_ack, u16 current_rate, bool need_mic)
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100583{
584 struct vnt_private *priv = tx_context->priv;
585 struct vnt_rrv_time_rts *buf = &tx_head->tx_rts.rts;
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100586 union vnt_tx_data_head *head = &tx_head->tx_rts.tx.head;
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100587
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100588 buf->rts_rrv_time_aa = vnt_get_rtscts_rsvtime_le(priv, 2,
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100589 pkt_type, frame_size, current_rate);
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100590 buf->rts_rrv_time_ba = vnt_get_rtscts_rsvtime_le(priv, 1,
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100591 pkt_type, frame_size, current_rate);
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100592 buf->rts_rrv_time_bb = vnt_get_rtscts_rsvtime_le(priv, 0,
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100593 pkt_type, frame_size, current_rate);
594
595 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, pkt_type, frame_size,
596 current_rate, need_ack);
597 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B, frame_size,
598 priv->byTopCCKBasicRate, need_ack);
599
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100600 if (need_mic)
601 head = &tx_head->tx_rts.tx.mic.head;
602
603 if (tx_context->fb_option)
604 return vnt_rxtx_rts_g_fb_head(tx_context, &head->rts_g_fb,
605 pkt_type, frame_size, need_ack, current_rate);
606
607 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g,
608 pkt_type, frame_size, need_ack, current_rate);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100609}
610
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100611static u16 vnt_rxtx_cts(struct vnt_usb_send_context *tx_context,
612 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100613 int need_ack, u16 current_rate, bool need_mic)
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100614{
615 struct vnt_private *priv = tx_context->priv;
616 struct vnt_rrv_time_cts *buf = &tx_head->tx_cts.cts;
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100617 union vnt_tx_data_head *head = &tx_head->tx_cts.tx.head;
618
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100619
620 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, pkt_type,
621 frame_size, current_rate, need_ack);
622 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B,
623 frame_size, priv->byTopCCKBasicRate, need_ack);
624
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100625 buf->cts_rrv_time_ba = vnt_get_rtscts_rsvtime_le(priv, 3,
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100626 pkt_type, frame_size, current_rate);
627
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100628 if (need_mic)
629 head = &tx_head->tx_cts.tx.mic.head;
630
631 /* Fill CTS */
Malcolm Priestley4f316682014-07-10 19:56:17 +0100632 return vnt_fill_cts_head(tx_context, pkt_type, head, frame_size,
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100633 need_ack, current_rate);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100634}
635
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100636static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context,
637 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestley681acf62014-07-10 19:56:12 +0100638 int need_ack, u16 current_rate, bool need_rts, bool need_mic)
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100639{
640 struct vnt_private *priv = tx_context->priv;
641 struct vnt_rrv_time_ab *buf = &tx_head->tx_ab.ab;
Malcolm Priestley681acf62014-07-10 19:56:12 +0100642 union vnt_tx_data_head *head = &tx_head->tx_ab.tx.head;
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100643
644 buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, pkt_type,
645 frame_size, current_rate, need_ack);
646
Malcolm Priestley681acf62014-07-10 19:56:12 +0100647 if (need_mic)
648 head = &tx_head->tx_ab.tx.mic.head;
649
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100650 if (need_rts) {
651 if (pkt_type == PK_TYPE_11B)
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100652 buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 0,
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100653 pkt_type, frame_size, current_rate);
654 else /* PK_TYPE_11A */
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100655 buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 2,
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100656 pkt_type, frame_size, current_rate);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100657
658 if (tx_context->fb_option && pkt_type == PK_TYPE_11A)
659 return vnt_rxtx_rts_a_fb_head(tx_context,
660 &head->rts_a_fb, pkt_type, frame_size,
661 need_ack, current_rate);
662
663 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab,
664 pkt_type, frame_size, need_ack, current_rate);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100665 }
666
Malcolm Priestley681acf62014-07-10 19:56:12 +0100667 if (pkt_type == PK_TYPE_11A)
668 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type,
669 current_rate, &head->data_head_a_fb,
670 frame_size, need_ack);
671
672 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
673 &head->data_head_ab, frame_size, need_ack);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100674}
675
Forest Bond92b96792009-06-13 07:38:31 -0400676/*+
677 *
678 * Description:
679 * Generate FIFO control for MAC & Baseband controller
680 *
681 * Parameters:
682 * In:
683 * pDevice - Pointer to adpater
684 * pTxDataHead - Transmit Data Buffer
685 * pTxBufHead - pTxBufHead
686 * pvRrvTime - pvRrvTime
687 * pvRTS - RTS Buffer
688 * pCTS - CTS Buffer
689 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
690 * bNeedACK - If need ACK
Forest Bond92b96792009-06-13 07:38:31 -0400691 * Out:
692 * none
693 *
694 * Return Value: none
695 *
696-*/
Andres Morecc856e62010-05-17 21:34:01 -0300697
Malcolm Priestley9ec7f2d2014-07-10 19:56:15 +0100698static u16 vnt_generate_tx_parameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley165ac772014-07-10 19:56:14 +0100699 u8 pkt_type, u16 current_rate, struct vnt_tx_buffer *tx_buffer,
700 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 frame_size,
701 int need_ack, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400702{
Forest Bond92b96792009-06-13 07:38:31 -0400703
Malcolm Priestley165ac772014-07-10 19:56:14 +0100704 if (pkt_type == PK_TYPE_11GB || pkt_type == PK_TYPE_11GA) {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100705 if (need_rts) {
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100706 if (need_mic)
Malcolm Priestley92928f12013-10-07 20:14:01 +0100707 *mic_hdr = &tx_buffer->
708 tx_head.tx_rts.tx.mic.hdr;
Malcolm Priestley92928f12013-10-07 20:14:01 +0100709
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100710 return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head,
Malcolm Priestley165ac772014-07-10 19:56:14 +0100711 pkt_type, frame_size, need_ack,
712 current_rate, need_mic);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100713 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100714
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100715 if (need_mic)
716 *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr;
717
Malcolm Priestley165ac772014-07-10 19:56:14 +0100718 return vnt_rxtx_cts(tx_context, &tx_buffer->tx_head, pkt_type,
719 frame_size, need_ack, current_rate, need_mic);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100720 }
721
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100722 if (need_mic)
723 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
724
Malcolm Priestley165ac772014-07-10 19:56:14 +0100725 return vnt_rxtx_ab(tx_context, &tx_buffer->tx_head, pkt_type,
726 frame_size, need_ack, current_rate, need_rts, need_mic);
Forest Bond92b96792009-06-13 07:38:31 -0400727}
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100728
729static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
730 u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
731 u16 payload_len, struct vnt_mic_hdr *mic_hdr)
732{
733 struct ieee80211_hdr *hdr = tx_context->hdr;
734 struct ieee80211_key_seq seq;
735 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
736
737 /* strip header and icv len from payload */
738 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
739 payload_len -= tx_key->icv_len;
740
741 switch (tx_key->cipher) {
742 case WLAN_CIPHER_SUITE_WEP40:
743 case WLAN_CIPHER_SUITE_WEP104:
744 memcpy(key_buffer, iv, 3);
745 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
746
747 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
748 memcpy(key_buffer + 8, iv, 3);
749 memcpy(key_buffer + 11,
750 tx_key->key, WLAN_KEY_LEN_WEP40);
751 }
752
753 break;
754 case WLAN_CIPHER_SUITE_TKIP:
755 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
756
757 break;
758 case WLAN_CIPHER_SUITE_CCMP:
759
760 if (!mic_hdr)
761 return;
762
763 mic_hdr->id = 0x59;
764 mic_hdr->payload_len = cpu_to_be16(payload_len);
765 memcpy(mic_hdr->mic_addr2, hdr->addr2, ETH_ALEN);
766
767 ieee80211_get_key_tx_seq(tx_key, &seq);
768
Malcolm Priestley79f976d2014-06-28 23:55:39 +0100769 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100770
771 if (ieee80211_has_a4(hdr->frame_control))
772 mic_hdr->hlen = cpu_to_be16(28);
773 else
774 mic_hdr->hlen = cpu_to_be16(22);
775
776 memcpy(mic_hdr->addr1, hdr->addr1, ETH_ALEN);
777 memcpy(mic_hdr->addr2, hdr->addr2, ETH_ALEN);
778 memcpy(mic_hdr->addr3, hdr->addr3, ETH_ALEN);
779
780 mic_hdr->frame_control = cpu_to_le16(
781 le16_to_cpu(hdr->frame_control) & 0xc78f);
782 mic_hdr->seq_ctrl = cpu_to_le16(
783 le16_to_cpu(hdr->seq_ctrl) & 0xf);
784
785 if (ieee80211_has_a4(hdr->frame_control))
786 memcpy(mic_hdr->addr4, hdr->addr4, ETH_ALEN);
787
788
789 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
790
791 break;
792 default:
793 break;
794 }
795
796}
797
798int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
799{
800 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
801 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
802 struct ieee80211_rate *rate;
803 struct ieee80211_key_conf *tx_key;
804 struct ieee80211_hdr *hdr;
805 struct vnt_mic_hdr *mic_hdr = NULL;
806 struct vnt_tx_buffer *tx_buffer;
807 struct vnt_tx_fifo_head *tx_buffer_head;
808 struct vnt_usb_send_context *tx_context;
809 unsigned long flags;
810 u32 frame_size = 0;
811 u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
812 u8 pkt_type, fb_option = AUTO_FB_NONE;
813 bool need_rts = false, need_ack = false, is_pspoll = false;
814 bool need_mic = false;
815
816 hdr = (struct ieee80211_hdr *)(skb->data);
817
818 rate = ieee80211_get_tx_rate(priv->hw, info);
819
820 current_rate = rate->hw_value;
Malcolm Priestley5091d962014-07-05 19:24:23 +0100821 if (priv->wCurrentRate != current_rate &&
822 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100823 priv->wCurrentRate = current_rate;
824 bScheduleCommand(priv, WLAN_CMD_SETPOWER, NULL);
825 }
826
827 if (current_rate > RATE_11M)
828 pkt_type = priv->byPacketType;
829 else
830 pkt_type = PK_TYPE_11B;
831
832 spin_lock_irqsave(&priv->lock, flags);
833
834 tx_context = s_vGetFreeContext(priv);
835 if (!tx_context) {
836 dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
837 spin_unlock_irqrestore(&priv->lock, flags);
838 return -ENOMEM;
839 }
840
841 tx_context->skb = skb;
842
843 spin_unlock_irqrestore(&priv->lock, flags);
844
845 tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
846 tx_buffer_head = &tx_buffer->fifo_head;
847 tx_body_size = skb->len;
848
849 frame_size = tx_body_size + 4;
850
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100851 /*Set fifo controls */
852 if (pkt_type == PK_TYPE_11A)
853 tx_buffer_head->wFIFOCtl = 0;
854 else if (pkt_type == PK_TYPE_11B)
855 tx_buffer_head->wFIFOCtl = FIFOCTL_11B;
856 else if (pkt_type == PK_TYPE_11GB)
857 tx_buffer_head->wFIFOCtl = FIFOCTL_11GB;
858 else if (pkt_type == PK_TYPE_11GA)
859 tx_buffer_head->wFIFOCtl = FIFOCTL_11GA;
860
861 if (!ieee80211_is_data(hdr->frame_control)) {
862 tx_buffer_head->wFIFOCtl |= (FIFOCTL_GENINT |
863 FIFOCTL_ISDMA0);
864 tx_buffer_head->wFIFOCtl |= FIFOCTL_TMOEN;
865
866 tx_buffer_head->time_stamp =
867 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
868 } else {
869 tx_buffer_head->time_stamp =
870 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
871 }
872
873 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
874 tx_buffer_head->wFIFOCtl |= FIFOCTL_NEEDACK;
875 need_ack = true;
876 }
877
878 if (ieee80211_has_retry(hdr->frame_control))
879 tx_buffer_head->wFIFOCtl |= FIFOCTL_LRETRY;
880
881 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
882 priv->byPreambleType = PREAMBLE_SHORT;
883 else
884 priv->byPreambleType = PREAMBLE_LONG;
885
886 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
887 need_rts = true;
888 tx_buffer_head->wFIFOCtl |= FIFOCTL_RTS;
889 }
890
891 if (ieee80211_has_a4(hdr->frame_control))
892 tx_buffer_head->wFIFOCtl |= FIFOCTL_LHEAD;
893
894 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
895 is_pspoll = true;
896
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100897 tx_buffer_head->frag_ctl =
898 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100899
900 if (info->control.hw_key) {
901 tx_key = info->control.hw_key;
902 switch (info->control.hw_key->cipher) {
903 case WLAN_CIPHER_SUITE_WEP40:
904 case WLAN_CIPHER_SUITE_WEP104:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100905 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100906 break;
907 case WLAN_CIPHER_SUITE_TKIP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100908 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100909 break;
910 case WLAN_CIPHER_SUITE_CCMP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100911 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100912 need_mic = true;
913 default:
914 break;
915 }
916 frame_size += tx_key->icv_len;
917 }
918
Malcolm Priestleycb8ee9de2014-07-10 19:56:05 +0100919 tx_buffer_head->current_rate = cpu_to_le16(current_rate);
920
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100921 /* legacy rates TODO use ieee80211_tx_rate */
922 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
923 if (priv->byAutoFBCtrl == AUTO_FB_0) {
924 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
925
926 priv->tx_rate_fb0 =
Malcolm Priestleye3f31872014-07-11 01:08:26 +0100927 vnt_fb_opt0[FB_RATE0][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100928 priv->tx_rate_fb1 =
Malcolm Priestleye3f31872014-07-11 01:08:26 +0100929 vnt_fb_opt0[FB_RATE1][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100930
931 fb_option = AUTO_FB_0;
932 } else if (priv->byAutoFBCtrl == AUTO_FB_1) {
933 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
934
935 priv->tx_rate_fb0 =
936 wFB_Opt1[FB_RATE0][current_rate - RATE_18M];
937 priv->tx_rate_fb1 =
938 wFB_Opt1[FB_RATE1][current_rate - RATE_18M];
939
940 fb_option = AUTO_FB_1;
941 }
942 }
943
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100944 tx_context->fb_option = fb_option;
945
Malcolm Priestley9ec7f2d2014-07-10 19:56:15 +0100946 duration_id = vnt_generate_tx_parameter(tx_context, pkt_type,
947 current_rate, tx_buffer, &mic_hdr, need_mic, frame_size,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100948 need_ack, need_rts);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100949
950 tx_header_size = tx_context->tx_hdr_size;
951 if (!tx_header_size) {
952 tx_context->in_use = false;
953 return -ENOMEM;
954 }
955
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100956 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100957
958 tx_bytes = tx_header_size + tx_body_size;
959
960 memcpy(tx_context->hdr, skb->data, tx_body_size);
961
962 hdr->duration_id = cpu_to_le16(duration_id);
963
964 if (info->control.hw_key) {
965 tx_key = info->control.hw_key;
966 if (tx_key->keylen > 0)
967 vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
968 tx_key, skb, tx_body_size, mic_hdr);
969 }
970
971 priv->wSeqCounter = (le16_to_cpu(hdr->seq_ctrl) &
972 IEEE80211_SCTL_SEQ) >> 4;
973
974 tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100975 tx_buffer->byPKTNO = tx_context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100976 tx_buffer->byType = 0x00;
977
978 tx_bytes += 4;
979
980 tx_context->type = CONTEXT_DATA_PACKET;
981 tx_context->buf_len = tx_bytes;
982
983 spin_lock_irqsave(&priv->lock, flags);
984
985 if (PIPEnsSendBulkOut(priv, tx_context) != STATUS_PENDING) {
986 spin_unlock_irqrestore(&priv->lock, flags);
987 return -EIO;
988 }
989
990 spin_unlock_irqrestore(&priv->lock, flags);
991
992 return 0;
993}
994
995static int vnt_beacon_xmit(struct vnt_private *priv,
996 struct sk_buff *skb)
997{
998 struct vnt_beacon_buffer *beacon_buffer;
999 struct vnt_tx_short_buf_head *short_head;
1000 struct ieee80211_tx_info *info;
1001 struct vnt_usb_send_context *context;
1002 struct ieee80211_mgmt *mgmt_hdr;
1003 unsigned long flags;
1004 u32 frame_size = skb->len + 4;
1005 u16 current_rate, count;
1006
1007 spin_lock_irqsave(&priv->lock, flags);
1008
1009 context = s_vGetFreeContext(priv);
1010 if (!context) {
1011 dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
1012 spin_unlock_irqrestore(&priv->lock, flags);
1013 return -ENOMEM;
1014 }
1015
1016 context->skb = skb;
1017
1018 spin_unlock_irqrestore(&priv->lock, flags);
1019
1020 beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
1021 short_head = &beacon_buffer->short_head;
1022
1023 if (priv->byBBType == BB_TYPE_11A) {
1024 current_rate = RATE_6M;
1025
1026 /* Get SignalField,ServiceField,Length */
1027 vnt_get_phy_field(priv, frame_size, current_rate,
1028 PK_TYPE_11A, &short_head->ab);
1029
1030 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +01001031 short_head->duration = vnt_get_duration_le(priv,
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001032 PK_TYPE_11A, false);
1033 short_head->time_stamp_off =
1034 vnt_time_stamp_off(priv, current_rate);
1035 } else {
1036 current_rate = RATE_1M;
1037 short_head->fifo_ctl |= FIFOCTL_11B;
1038
1039 /* Get SignalField,ServiceField,Length */
1040 vnt_get_phy_field(priv, frame_size, current_rate,
1041 PK_TYPE_11B, &short_head->ab);
1042
1043 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +01001044 short_head->duration = vnt_get_duration_le(priv,
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001045 PK_TYPE_11B, false);
1046 short_head->time_stamp_off =
1047 vnt_time_stamp_off(priv, current_rate);
1048 }
1049
1050 /* Generate Beacon Header */
1051 mgmt_hdr = &beacon_buffer->mgmt_hdr;
1052 memcpy(mgmt_hdr, skb->data, skb->len);
1053
1054 /* time stamp always 0 */
1055 mgmt_hdr->u.beacon.timestamp = 0;
1056
1057 info = IEEE80211_SKB_CB(skb);
1058 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1059 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
1060 hdr->duration_id = 0;
1061 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
1062 }
1063
1064 priv->wSeqCounter++;
1065 if (priv->wSeqCounter > 0x0fff)
1066 priv->wSeqCounter = 0;
1067
1068 count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
1069
1070 beacon_buffer->tx_byte_count = cpu_to_le16(count);
Malcolm Priestley71d764a2014-07-05 19:24:27 +01001071 beacon_buffer->byPKTNO = context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001072 beacon_buffer->byType = 0x01;
1073
1074 context->type = CONTEXT_BEACON_PACKET;
1075 context->buf_len = count + 4; /* USB header */
1076
1077 spin_lock_irqsave(&priv->lock, flags);
1078
1079 if (PIPEnsSendBulkOut(priv, context) != STATUS_PENDING)
1080 ieee80211_free_txskb(priv->hw, context->skb);
1081
1082 spin_unlock_irqrestore(&priv->lock, flags);
1083
1084 return 0;
1085}
1086
1087int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1088{
1089 struct sk_buff *beacon;
1090
1091 beacon = ieee80211_beacon_get(priv->hw, vif);
1092 if (!beacon)
1093 return -ENOMEM;
1094
1095 if (vnt_beacon_xmit(priv, beacon)) {
1096 ieee80211_free_txskb(priv->hw, beacon);
1097 return -ENODEV;
1098 }
1099
1100 return 0;
1101}
1102
1103int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1104 struct ieee80211_bss_conf *conf)
1105{
1106 int ret;
1107
1108 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1109
1110 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1111
1112 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
1113
1114 vnt_clear_current_tsf(priv);
1115
1116 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1117
1118 vnt_reset_next_tbtt(priv, conf->beacon_int);
1119
1120 ret = vnt_beacon_make(priv, vif);
1121
1122 return ret;
1123}