blob: 3c92360f1efa72f1858f37bb3c83b6c1e3036e82 [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
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 Priestley435ae3b2014-07-11 01:08:22 +010092static __le16 vnt_get_duration_le(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 Priestleyf2aabee2014-07-11 01:08:20 +010095static __le16 vnt_get_rtscts_duration_le(struct vnt_private *priv,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +010096 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 Priestley435ae3b2014-07-11 01:08:22 +0100213static __le16 vnt_get_duration_le(struct vnt_private *piv,
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100214 u8 pkt_type, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400215{
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100216 u32 ack_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400217
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100218 if (need_ack) {
219 if (pkt_type == PK_TYPE_11B)
220 ack_time = vnt_get_frame_time(piv->byPreambleType,
221 pkt_type, 14, piv->byTopCCKBasicRate);
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100222 else
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100223 ack_time = vnt_get_frame_time(piv->byPreambleType,
224 pkt_type, 14, piv->byTopOFDMBasicRate);
225
226 return cpu_to_le16((u16)(piv->uSIFS + ack_time));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100227 }
Forest Bond92b96792009-06-13 07:38:31 -0400228
Forest Bond92b96792009-06-13 07:38:31 -0400229 return 0;
230}
231
Forest Bond92b96792009-06-13 07:38:31 -0400232//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100233static __le16 vnt_get_rtscts_duration_le(struct vnt_private *priv, u8 dur_type,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100234 u32 frame_length, u8 pkt_type, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400235{
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100236 u32 cts_time = 0, dur_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400237
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100238 switch (dur_type) {
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100239 case RTSDUR_BB:
240 case RTSDUR_BA:
241 case RTSDUR_BA_F0:
242 case RTSDUR_BA_F1:
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100243 cts_time = vnt_get_frame_time(priv->byPreambleType,
244 pkt_type, 14, priv->byTopCCKBasicRate);
245 dur_time = cts_time + 2 * priv->uSIFS +
246 s_uGetTxRsvTime(priv, pkt_type,
247 frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100248 break;
Forest Bond92b96792009-06-13 07:38:31 -0400249
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100250 case RTSDUR_AA:
251 case RTSDUR_AA_F0:
252 case RTSDUR_AA_F1:
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100253 cts_time = vnt_get_frame_time(priv->byPreambleType,
254 pkt_type, 14, priv->byTopOFDMBasicRate);
255 dur_time = cts_time + 2 * priv->uSIFS +
256 s_uGetTxRsvTime(priv, pkt_type,
257 frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100258 break;
Forest Bond92b96792009-06-13 07:38:31 -0400259
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100260 case CTSDUR_BA:
261 case CTSDUR_BA_F0:
262 case CTSDUR_BA_F1:
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100263 dur_time = priv->uSIFS + s_uGetTxRsvTime(priv,
264 pkt_type, frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100265 break;
Forest Bond92b96792009-06-13 07:38:31 -0400266
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100267 default:
268 break;
269 }
Forest Bond92b96792009-06-13 07:38:31 -0400270
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100271 return cpu_to_le16((u16)dur_time);
Forest Bond92b96792009-06-13 07:38:31 -0400272}
273
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100274static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
275 struct ieee80211_hdr *hdr)
276{
277 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
278 u8 *hdr_pos = (u8 *)hdr;
279
280 tx_context->hdr = hdr;
281 if (!tx_context->hdr)
282 return 0;
283
284 return (u16)(hdr_pos - head);
285}
286
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100287static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
288 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf,
289 u32 frame_len, int need_ack)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100290{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100291
292 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100293 struct ieee80211_hdr *hdr =
294 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100295
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100296 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100297 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
298 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100299 PK_TYPE_11B, &buf->b);
300
301 /* Get Duration and TimeStamp */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100302 if (ieee80211_is_pspoll(hdr->frame_control)) {
303 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
304
305 buf->duration_a = dur;
306 buf->duration_b = dur;
307 } else {
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100308 buf->duration_a = vnt_get_duration_le(priv, pkt_type, need_ack);
309 buf->duration_b = vnt_get_duration_le(priv,
Malcolm Priestley893cc702014-06-25 21:14:38 +0100310 PK_TYPE_11B, need_ack);
311 }
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100312
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000313 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
314 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100315 priv->byTopCCKBasicRate);
316
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100317 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
318
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000319 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100320}
321
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100322static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
323 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100324 u32 frame_len, int need_ack)
325{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100326 struct vnt_private *priv = tx_context->priv;
327
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100328 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100329 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100330
Malcolm Priestley205056f2014-06-04 18:25:34 +0100331 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100332 PK_TYPE_11B, &buf->b);
333
334 /* Get Duration and TimeStamp */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100335 buf->duration_a = vnt_get_duration_le(priv, pkt_type, need_ack);
336 buf->duration_b = vnt_get_duration_le(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100337
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100338 buf->duration_a_f0 = vnt_get_duration_le(priv, pkt_type, need_ack);
339 buf->duration_a_f1 = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100340
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000341 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
342 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100343 priv->byTopCCKBasicRate);
344
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100345 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
346
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000347 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100348}
349
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100350static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
351 u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100352 u32 frame_len, int need_ack)
353{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100354 struct vnt_private *priv = tx_context->priv;
355
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100356 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100357 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100358 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100359 buf->duration = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100360
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100361 buf->duration_f0 = vnt_get_duration_le(priv, pkt_type, need_ack);
362 buf->duration_f1 = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100363
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000364 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100365
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100366 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
367
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000368 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100369}
370
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100371static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
372 u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100373 u32 frame_len, int need_ack)
374{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100375 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100376 struct ieee80211_hdr *hdr =
377 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100378
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100379 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100380 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->ab);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100381
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100382 /* Get Duration and TimeStampOff */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100383 if (ieee80211_is_pspoll(hdr->frame_control)) {
384 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
385
386 buf->duration = dur;
387 } else {
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100388 buf->duration = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100389 }
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100390
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000391 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100392
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100393 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
394
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000395 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100396}
397
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100398static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
399 struct ieee80211_rts *rts, __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100400{
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100401 struct ieee80211_hdr *hdr =
402 (struct ieee80211_hdr *)tx_context->skb->data;
403
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100404 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000405 rts->frame_control =
406 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100407
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100408 memcpy(rts->ra, hdr->addr1, ETH_ALEN);
409 memcpy(rts->ta, hdr->addr2, ETH_ALEN);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100410
411 return 0;
412}
413
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100414static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100415 struct vnt_rts_g *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100416 u16 current_rate)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100417{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100418 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100419 u16 rts_frame_len = 20;
420
Malcolm Priestley205056f2014-06-04 18:25:34 +0100421 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100422 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100423 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100424 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
425
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100426 buf->duration_bb = vnt_get_rtscts_duration_le(priv, RTSDUR_BB,
427 frame_len, PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
428 buf->duration_aa = vnt_get_rtscts_duration_le(priv, RTSDUR_AA,
429 frame_len, pkt_type, current_rate, need_ack);
430 buf->duration_ba = vnt_get_rtscts_duration_le(priv, RTSDUR_BA,
431 frame_len, pkt_type, current_rate, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100432
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100433 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100434
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100435 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100436 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100437}
438
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100439static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100440 struct vnt_rts_g_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100441 u16 current_rate)
Malcolm Priestleyec917132013-08-26 11:07:46 +0100442{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100443 struct vnt_private *priv = tx_context->priv;
Malcolm Priestleyec917132013-08-26 11:07:46 +0100444 u16 rts_frame_len = 20;
445
Malcolm Priestley205056f2014-06-04 18:25:34 +0100446 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100447 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100448 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100449 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
450
451
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100452 buf->duration_bb = vnt_get_rtscts_duration_le(priv, RTSDUR_BB,
453 frame_len, PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack);
454 buf->duration_aa = vnt_get_rtscts_duration_le(priv, RTSDUR_AA,
455 frame_len, pkt_type, current_rate, need_ack);
456 buf->duration_ba = vnt_get_rtscts_duration_le(priv, RTSDUR_BA,
457 frame_len, pkt_type, current_rate, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100458
459
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100460 buf->rts_duration_ba_f0 = vnt_get_rtscts_duration_le(priv, RTSDUR_BA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100461 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100462 buf->rts_duration_aa_f0 = vnt_get_rtscts_duration_le(priv, RTSDUR_AA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100463 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100464 buf->rts_duration_ba_f1 = vnt_get_rtscts_duration_le(priv, RTSDUR_BA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100465 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100466 buf->rts_duration_aa_f1 = vnt_get_rtscts_duration_le(priv, RTSDUR_AA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100467 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100468
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100469 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100470
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100471 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100472 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100473}
474
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100475static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100476 struct vnt_rts_ab *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100477 u16 current_rate)
Malcolm Priestley17126332013-08-26 11:09:38 +0100478{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100479 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley17126332013-08-26 11:09:38 +0100480 u16 rts_frame_len = 20;
481
Malcolm Priestley205056f2014-06-04 18:25:34 +0100482 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100483 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
484
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100485 buf->duration = vnt_get_rtscts_duration_le(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100486 pkt_type, current_rate, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100487
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100488 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100489
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100490 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100491 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100492}
493
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100494static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100495 struct vnt_rts_a_fb *buf, u8 pkt_type, u32 frame_len, int need_ack,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100496 u16 current_rate)
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100497{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100498 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100499 u16 rts_frame_len = 20;
500
Malcolm Priestley205056f2014-06-04 18:25:34 +0100501 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100502 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
503
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100504 buf->duration = vnt_get_rtscts_duration_le(priv, RTSDUR_AA, frame_len,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100505 pkt_type, current_rate, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100506
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100507 buf->rts_duration_f0 = vnt_get_rtscts_duration_le(priv, RTSDUR_AA_F0,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100508 frame_len, pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100509
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100510 buf->rts_duration_f1 = vnt_get_rtscts_duration_le(priv, RTSDUR_AA_F1,
Malcolm Priestley26e73622014-07-10 19:56:04 +0100511 frame_len, pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100512
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100513 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100514
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100515 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100516 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100517}
518
Malcolm Priestley4f316682014-07-10 19:56:17 +0100519static u16 vnt_fill_cts_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100520 u8 pkt_type, union vnt_tx_data_head *head, u32 frame_len,
521 int need_ack, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400522{
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100523 struct vnt_private *priv = tx_context->priv;
524 u32 cts_frame_len = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400525
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100526 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100527 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400528
Malcolm Priestleyce7b0db2014-07-10 19:56:03 +0100529 if (tx_context->fb_option) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100530 /* Auto Fall back */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100531 struct vnt_cts_fb *buf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100532 /* Get SignalField,ServiceField,Length */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100533 vnt_get_phy_field(priv, cts_frame_len,
534 priv->byTopCCKBasicRate, PK_TYPE_11B, &buf->b);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100535 buf->duration_ba = vnt_get_rtscts_duration_le(priv, CTSDUR_BA,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100536 frame_len, pkt_type,
537 current_rate, need_ack);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100538 /* Get CTSDuration_ba_f0 */
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100539 buf->cts_duration_ba_f0 = vnt_get_rtscts_duration_le(priv,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100540 CTSDUR_BA_F0, frame_len, pkt_type,
541 priv->tx_rate_fb0, need_ack);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100542 /* Get CTSDuration_ba_f1 */
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100543 buf->cts_duration_ba_f1 = vnt_get_rtscts_duration_le(priv,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100544 CTSDUR_BA_F1, frame_len, pkt_type,
545 priv->tx_rate_fb1, need_ack);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100546 /* Get CTS Frame body */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100547 buf->data.duration = buf->duration_ba;
548 buf->data.frame_control =
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000549 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
550
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100551 memcpy(buf->data.ra, priv->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100552
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100553 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type,
554 current_rate, &buf->data_head, frame_len,
555 need_ack);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100556 } else {
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100557 struct vnt_cts *buf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100558 /* Get SignalField,ServiceField,Length */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100559 vnt_get_phy_field(priv, cts_frame_len,
560 priv->byTopCCKBasicRate, PK_TYPE_11B, &buf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100561 /* Get CTSDuration_ba */
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100562 buf->duration_ba = vnt_get_rtscts_duration_le(priv,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100563 CTSDUR_BA, frame_len, pkt_type,
564 current_rate, need_ack);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100565 /*Get CTS Frame body*/
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100566 buf->data.duration = buf->duration_ba;
567 buf->data.frame_control =
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000568 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
569
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100570 memcpy(buf->data.ra, priv->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100571
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100572 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
573 &buf->data_head, frame_len, need_ack);
Forest Bond92b96792009-06-13 07:38:31 -0400574 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100575
576 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400577}
578
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100579static u16 vnt_rxtx_rts(struct vnt_usb_send_context *tx_context,
580 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100581 int need_ack, u16 current_rate, bool need_mic)
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100582{
583 struct vnt_private *priv = tx_context->priv;
584 struct vnt_rrv_time_rts *buf = &tx_head->tx_rts.rts;
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100585 union vnt_tx_data_head *head = &tx_head->tx_rts.tx.head;
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100586
587 buf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(priv, 2,
588 pkt_type, frame_size, current_rate);
589 buf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(priv, 1,
590 pkt_type, frame_size, current_rate);
591 buf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(priv, 0,
592 pkt_type, frame_size, current_rate);
593
594 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, pkt_type, frame_size,
595 current_rate, need_ack);
596 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B, frame_size,
597 priv->byTopCCKBasicRate, need_ack);
598
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100599 if (need_mic)
600 head = &tx_head->tx_rts.tx.mic.head;
601
602 if (tx_context->fb_option)
603 return vnt_rxtx_rts_g_fb_head(tx_context, &head->rts_g_fb,
604 pkt_type, frame_size, need_ack, current_rate);
605
606 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g,
607 pkt_type, frame_size, need_ack, current_rate);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100608}
609
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100610static u16 vnt_rxtx_cts(struct vnt_usb_send_context *tx_context,
611 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100612 int need_ack, u16 current_rate, bool need_mic)
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100613{
614 struct vnt_private *priv = tx_context->priv;
615 struct vnt_rrv_time_cts *buf = &tx_head->tx_cts.cts;
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100616 union vnt_tx_data_head *head = &tx_head->tx_cts.tx.head;
617
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100618
619 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, pkt_type,
620 frame_size, current_rate, need_ack);
621 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B,
622 frame_size, priv->byTopCCKBasicRate, need_ack);
623
624 buf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(priv, 3,
625 pkt_type, frame_size, current_rate);
626
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100627 if (need_mic)
628 head = &tx_head->tx_cts.tx.mic.head;
629
630 /* Fill CTS */
Malcolm Priestley4f316682014-07-10 19:56:17 +0100631 return vnt_fill_cts_head(tx_context, pkt_type, head, frame_size,
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100632 need_ack, current_rate);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100633}
634
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100635static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context,
636 union vnt_tx_head *tx_head, u8 pkt_type, u32 frame_size,
Malcolm Priestley681acf62014-07-10 19:56:12 +0100637 int need_ack, u16 current_rate, bool need_rts, bool need_mic)
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100638{
639 struct vnt_private *priv = tx_context->priv;
640 struct vnt_rrv_time_ab *buf = &tx_head->tx_ab.ab;
Malcolm Priestley681acf62014-07-10 19:56:12 +0100641 union vnt_tx_data_head *head = &tx_head->tx_ab.tx.head;
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100642
643 buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, pkt_type,
644 frame_size, current_rate, need_ack);
645
Malcolm Priestley681acf62014-07-10 19:56:12 +0100646 if (need_mic)
647 head = &tx_head->tx_ab.tx.mic.head;
648
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100649 if (need_rts) {
650 if (pkt_type == PK_TYPE_11B)
651 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(priv, 0,
652 pkt_type, frame_size, current_rate);
653 else /* PK_TYPE_11A */
654 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(priv, 2,
655 pkt_type, frame_size, current_rate);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100656
657 if (tx_context->fb_option && pkt_type == PK_TYPE_11A)
658 return vnt_rxtx_rts_a_fb_head(tx_context,
659 &head->rts_a_fb, pkt_type, frame_size,
660 need_ack, current_rate);
661
662 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab,
663 pkt_type, frame_size, need_ack, current_rate);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100664 }
665
Malcolm Priestley681acf62014-07-10 19:56:12 +0100666 if (pkt_type == PK_TYPE_11A)
667 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type,
668 current_rate, &head->data_head_a_fb,
669 frame_size, need_ack);
670
671 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
672 &head->data_head_ab, frame_size, need_ack);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100673}
674
Forest Bond92b96792009-06-13 07:38:31 -0400675/*+
676 *
677 * Description:
678 * Generate FIFO control for MAC & Baseband controller
679 *
680 * Parameters:
681 * In:
682 * pDevice - Pointer to adpater
683 * pTxDataHead - Transmit Data Buffer
684 * pTxBufHead - pTxBufHead
685 * pvRrvTime - pvRrvTime
686 * pvRTS - RTS Buffer
687 * pCTS - CTS Buffer
688 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
689 * bNeedACK - If need ACK
Forest Bond92b96792009-06-13 07:38:31 -0400690 * Out:
691 * none
692 *
693 * Return Value: none
694 *
695-*/
Andres Morecc856e62010-05-17 21:34:01 -0300696
Malcolm Priestley9ec7f2d2014-07-10 19:56:15 +0100697static u16 vnt_generate_tx_parameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley165ac772014-07-10 19:56:14 +0100698 u8 pkt_type, u16 current_rate, struct vnt_tx_buffer *tx_buffer,
699 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 frame_size,
700 int need_ack, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400701{
Forest Bond92b96792009-06-13 07:38:31 -0400702
Malcolm Priestley165ac772014-07-10 19:56:14 +0100703 if (pkt_type == PK_TYPE_11GB || pkt_type == PK_TYPE_11GA) {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100704 if (need_rts) {
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100705 if (need_mic)
Malcolm Priestley92928f12013-10-07 20:14:01 +0100706 *mic_hdr = &tx_buffer->
707 tx_head.tx_rts.tx.mic.hdr;
Malcolm Priestley92928f12013-10-07 20:14:01 +0100708
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100709 return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head,
Malcolm Priestley165ac772014-07-10 19:56:14 +0100710 pkt_type, frame_size, need_ack,
711 current_rate, need_mic);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100712 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100713
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100714 if (need_mic)
715 *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr;
716
Malcolm Priestley165ac772014-07-10 19:56:14 +0100717 return vnt_rxtx_cts(tx_context, &tx_buffer->tx_head, pkt_type,
718 frame_size, need_ack, current_rate, need_mic);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100719 }
720
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100721 if (need_mic)
722 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
723
Malcolm Priestley165ac772014-07-10 19:56:14 +0100724 return vnt_rxtx_ab(tx_context, &tx_buffer->tx_head, pkt_type,
725 frame_size, need_ack, current_rate, need_rts, need_mic);
Forest Bond92b96792009-06-13 07:38:31 -0400726}
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100727
728static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
729 u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
730 u16 payload_len, struct vnt_mic_hdr *mic_hdr)
731{
732 struct ieee80211_hdr *hdr = tx_context->hdr;
733 struct ieee80211_key_seq seq;
734 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
735
736 /* strip header and icv len from payload */
737 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
738 payload_len -= tx_key->icv_len;
739
740 switch (tx_key->cipher) {
741 case WLAN_CIPHER_SUITE_WEP40:
742 case WLAN_CIPHER_SUITE_WEP104:
743 memcpy(key_buffer, iv, 3);
744 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
745
746 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
747 memcpy(key_buffer + 8, iv, 3);
748 memcpy(key_buffer + 11,
749 tx_key->key, WLAN_KEY_LEN_WEP40);
750 }
751
752 break;
753 case WLAN_CIPHER_SUITE_TKIP:
754 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
755
756 break;
757 case WLAN_CIPHER_SUITE_CCMP:
758
759 if (!mic_hdr)
760 return;
761
762 mic_hdr->id = 0x59;
763 mic_hdr->payload_len = cpu_to_be16(payload_len);
764 memcpy(mic_hdr->mic_addr2, hdr->addr2, ETH_ALEN);
765
766 ieee80211_get_key_tx_seq(tx_key, &seq);
767
Malcolm Priestley79f976d2014-06-28 23:55:39 +0100768 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100769
770 if (ieee80211_has_a4(hdr->frame_control))
771 mic_hdr->hlen = cpu_to_be16(28);
772 else
773 mic_hdr->hlen = cpu_to_be16(22);
774
775 memcpy(mic_hdr->addr1, hdr->addr1, ETH_ALEN);
776 memcpy(mic_hdr->addr2, hdr->addr2, ETH_ALEN);
777 memcpy(mic_hdr->addr3, hdr->addr3, ETH_ALEN);
778
779 mic_hdr->frame_control = cpu_to_le16(
780 le16_to_cpu(hdr->frame_control) & 0xc78f);
781 mic_hdr->seq_ctrl = cpu_to_le16(
782 le16_to_cpu(hdr->seq_ctrl) & 0xf);
783
784 if (ieee80211_has_a4(hdr->frame_control))
785 memcpy(mic_hdr->addr4, hdr->addr4, ETH_ALEN);
786
787
788 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
789
790 break;
791 default:
792 break;
793 }
794
795}
796
797int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
798{
799 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
800 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
801 struct ieee80211_rate *rate;
802 struct ieee80211_key_conf *tx_key;
803 struct ieee80211_hdr *hdr;
804 struct vnt_mic_hdr *mic_hdr = NULL;
805 struct vnt_tx_buffer *tx_buffer;
806 struct vnt_tx_fifo_head *tx_buffer_head;
807 struct vnt_usb_send_context *tx_context;
808 unsigned long flags;
809 u32 frame_size = 0;
810 u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
811 u8 pkt_type, fb_option = AUTO_FB_NONE;
812 bool need_rts = false, need_ack = false, is_pspoll = false;
813 bool need_mic = false;
814
815 hdr = (struct ieee80211_hdr *)(skb->data);
816
817 rate = ieee80211_get_tx_rate(priv->hw, info);
818
819 current_rate = rate->hw_value;
Malcolm Priestley5091d962014-07-05 19:24:23 +0100820 if (priv->wCurrentRate != current_rate &&
821 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100822 priv->wCurrentRate = current_rate;
823 bScheduleCommand(priv, WLAN_CMD_SETPOWER, NULL);
824 }
825
826 if (current_rate > RATE_11M)
827 pkt_type = priv->byPacketType;
828 else
829 pkt_type = PK_TYPE_11B;
830
831 spin_lock_irqsave(&priv->lock, flags);
832
833 tx_context = s_vGetFreeContext(priv);
834 if (!tx_context) {
835 dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
836 spin_unlock_irqrestore(&priv->lock, flags);
837 return -ENOMEM;
838 }
839
840 tx_context->skb = skb;
841
842 spin_unlock_irqrestore(&priv->lock, flags);
843
844 tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
845 tx_buffer_head = &tx_buffer->fifo_head;
846 tx_body_size = skb->len;
847
848 frame_size = tx_body_size + 4;
849
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100850 /*Set fifo controls */
851 if (pkt_type == PK_TYPE_11A)
852 tx_buffer_head->wFIFOCtl = 0;
853 else if (pkt_type == PK_TYPE_11B)
854 tx_buffer_head->wFIFOCtl = FIFOCTL_11B;
855 else if (pkt_type == PK_TYPE_11GB)
856 tx_buffer_head->wFIFOCtl = FIFOCTL_11GB;
857 else if (pkt_type == PK_TYPE_11GA)
858 tx_buffer_head->wFIFOCtl = FIFOCTL_11GA;
859
860 if (!ieee80211_is_data(hdr->frame_control)) {
861 tx_buffer_head->wFIFOCtl |= (FIFOCTL_GENINT |
862 FIFOCTL_ISDMA0);
863 tx_buffer_head->wFIFOCtl |= FIFOCTL_TMOEN;
864
865 tx_buffer_head->time_stamp =
866 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
867 } else {
868 tx_buffer_head->time_stamp =
869 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
870 }
871
872 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
873 tx_buffer_head->wFIFOCtl |= FIFOCTL_NEEDACK;
874 need_ack = true;
875 }
876
877 if (ieee80211_has_retry(hdr->frame_control))
878 tx_buffer_head->wFIFOCtl |= FIFOCTL_LRETRY;
879
880 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
881 priv->byPreambleType = PREAMBLE_SHORT;
882 else
883 priv->byPreambleType = PREAMBLE_LONG;
884
885 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
886 need_rts = true;
887 tx_buffer_head->wFIFOCtl |= FIFOCTL_RTS;
888 }
889
890 if (ieee80211_has_a4(hdr->frame_control))
891 tx_buffer_head->wFIFOCtl |= FIFOCTL_LHEAD;
892
893 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
894 is_pspoll = true;
895
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100896 tx_buffer_head->frag_ctl =
897 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100898
899 if (info->control.hw_key) {
900 tx_key = info->control.hw_key;
901 switch (info->control.hw_key->cipher) {
902 case WLAN_CIPHER_SUITE_WEP40:
903 case WLAN_CIPHER_SUITE_WEP104:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100904 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100905 break;
906 case WLAN_CIPHER_SUITE_TKIP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100907 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100908 break;
909 case WLAN_CIPHER_SUITE_CCMP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100910 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100911 need_mic = true;
912 default:
913 break;
914 }
915 frame_size += tx_key->icv_len;
916 }
917
Malcolm Priestleycb8ee9de2014-07-10 19:56:05 +0100918 tx_buffer_head->current_rate = cpu_to_le16(current_rate);
919
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100920 /* legacy rates TODO use ieee80211_tx_rate */
921 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
922 if (priv->byAutoFBCtrl == AUTO_FB_0) {
923 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
924
925 priv->tx_rate_fb0 =
926 wFB_Opt0[FB_RATE0][current_rate - RATE_18M];
927 priv->tx_rate_fb1 =
928 wFB_Opt0[FB_RATE1][current_rate - RATE_18M];
929
930 fb_option = AUTO_FB_0;
931 } else if (priv->byAutoFBCtrl == AUTO_FB_1) {
932 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
933
934 priv->tx_rate_fb0 =
935 wFB_Opt1[FB_RATE0][current_rate - RATE_18M];
936 priv->tx_rate_fb1 =
937 wFB_Opt1[FB_RATE1][current_rate - RATE_18M];
938
939 fb_option = AUTO_FB_1;
940 }
941 }
942
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100943 tx_context->fb_option = fb_option;
944
Malcolm Priestley9ec7f2d2014-07-10 19:56:15 +0100945 duration_id = vnt_generate_tx_parameter(tx_context, pkt_type,
946 current_rate, tx_buffer, &mic_hdr, need_mic, frame_size,
Malcolm Priestley72bf8052014-07-10 19:56:02 +0100947 need_ack, need_rts);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100948
949 tx_header_size = tx_context->tx_hdr_size;
950 if (!tx_header_size) {
951 tx_context->in_use = false;
952 return -ENOMEM;
953 }
954
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100955 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100956
957 tx_bytes = tx_header_size + tx_body_size;
958
959 memcpy(tx_context->hdr, skb->data, tx_body_size);
960
961 hdr->duration_id = cpu_to_le16(duration_id);
962
963 if (info->control.hw_key) {
964 tx_key = info->control.hw_key;
965 if (tx_key->keylen > 0)
966 vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
967 tx_key, skb, tx_body_size, mic_hdr);
968 }
969
970 priv->wSeqCounter = (le16_to_cpu(hdr->seq_ctrl) &
971 IEEE80211_SCTL_SEQ) >> 4;
972
973 tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100974 tx_buffer->byPKTNO = tx_context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100975 tx_buffer->byType = 0x00;
976
977 tx_bytes += 4;
978
979 tx_context->type = CONTEXT_DATA_PACKET;
980 tx_context->buf_len = tx_bytes;
981
982 spin_lock_irqsave(&priv->lock, flags);
983
984 if (PIPEnsSendBulkOut(priv, tx_context) != STATUS_PENDING) {
985 spin_unlock_irqrestore(&priv->lock, flags);
986 return -EIO;
987 }
988
989 spin_unlock_irqrestore(&priv->lock, flags);
990
991 return 0;
992}
993
994static int vnt_beacon_xmit(struct vnt_private *priv,
995 struct sk_buff *skb)
996{
997 struct vnt_beacon_buffer *beacon_buffer;
998 struct vnt_tx_short_buf_head *short_head;
999 struct ieee80211_tx_info *info;
1000 struct vnt_usb_send_context *context;
1001 struct ieee80211_mgmt *mgmt_hdr;
1002 unsigned long flags;
1003 u32 frame_size = skb->len + 4;
1004 u16 current_rate, count;
1005
1006 spin_lock_irqsave(&priv->lock, flags);
1007
1008 context = s_vGetFreeContext(priv);
1009 if (!context) {
1010 dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
1011 spin_unlock_irqrestore(&priv->lock, flags);
1012 return -ENOMEM;
1013 }
1014
1015 context->skb = skb;
1016
1017 spin_unlock_irqrestore(&priv->lock, flags);
1018
1019 beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
1020 short_head = &beacon_buffer->short_head;
1021
1022 if (priv->byBBType == BB_TYPE_11A) {
1023 current_rate = RATE_6M;
1024
1025 /* Get SignalField,ServiceField,Length */
1026 vnt_get_phy_field(priv, frame_size, current_rate,
1027 PK_TYPE_11A, &short_head->ab);
1028
1029 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +01001030 short_head->duration = vnt_get_duration_le(priv,
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001031 PK_TYPE_11A, false);
1032 short_head->time_stamp_off =
1033 vnt_time_stamp_off(priv, current_rate);
1034 } else {
1035 current_rate = RATE_1M;
1036 short_head->fifo_ctl |= FIFOCTL_11B;
1037
1038 /* Get SignalField,ServiceField,Length */
1039 vnt_get_phy_field(priv, frame_size, current_rate,
1040 PK_TYPE_11B, &short_head->ab);
1041
1042 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +01001043 short_head->duration = vnt_get_duration_le(priv,
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001044 PK_TYPE_11B, false);
1045 short_head->time_stamp_off =
1046 vnt_time_stamp_off(priv, current_rate);
1047 }
1048
1049 /* Generate Beacon Header */
1050 mgmt_hdr = &beacon_buffer->mgmt_hdr;
1051 memcpy(mgmt_hdr, skb->data, skb->len);
1052
1053 /* time stamp always 0 */
1054 mgmt_hdr->u.beacon.timestamp = 0;
1055
1056 info = IEEE80211_SKB_CB(skb);
1057 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1058 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
1059 hdr->duration_id = 0;
1060 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
1061 }
1062
1063 priv->wSeqCounter++;
1064 if (priv->wSeqCounter > 0x0fff)
1065 priv->wSeqCounter = 0;
1066
1067 count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
1068
1069 beacon_buffer->tx_byte_count = cpu_to_le16(count);
Malcolm Priestley71d764a2014-07-05 19:24:27 +01001070 beacon_buffer->byPKTNO = context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001071 beacon_buffer->byType = 0x01;
1072
1073 context->type = CONTEXT_BEACON_PACKET;
1074 context->buf_len = count + 4; /* USB header */
1075
1076 spin_lock_irqsave(&priv->lock, flags);
1077
1078 if (PIPEnsSendBulkOut(priv, context) != STATUS_PENDING)
1079 ieee80211_free_txskb(priv->hw, context->skb);
1080
1081 spin_unlock_irqrestore(&priv->lock, flags);
1082
1083 return 0;
1084}
1085
1086int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1087{
1088 struct sk_buff *beacon;
1089
1090 beacon = ieee80211_beacon_get(priv->hw, vif);
1091 if (!beacon)
1092 return -ENOMEM;
1093
1094 if (vnt_beacon_xmit(priv, beacon)) {
1095 ieee80211_free_txskb(priv->hw, beacon);
1096 return -ENODEV;
1097 }
1098
1099 return 0;
1100}
1101
1102int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1103 struct ieee80211_bss_conf *conf)
1104{
1105 int ret;
1106
1107 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1108
1109 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1110
1111 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
1112
1113 vnt_clear_current_tsf(priv);
1114
1115 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1116
1117 vnt_reset_next_tbtt(priv, conf->beacon_int);
1118
1119 ret = vnt_beacon_make(priv, vif);
1120
1121 return ret;
1122}