blob: f6c2cf8590c4811471a88c9e82be1d4151a11618 [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.
Malcolm Priestley435ae3b2014-07-11 01:08:22 +010029 * vnt_get_duration_le - get tx data required duration
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +010030 * vnt_get_rtscts_duration_le- get rtx/cts required duration
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +010031 * vnt_get_rtscts_rsvtime_le- get rts/cts reserved time
Malcolm Priestley3815a272014-07-11 01:08:24 +010032 * vnt_get_rsvtime- get frame reserved time
Malcolm Priestley4f316682014-07-10 19:56:17 +010033 * vnt_fill_cts_head- fulfill CTS ctl header
Forest Bond92b96792009-06-13 07:38:31 -040034 *
35 * Revision History:
36 *
37 */
38
Krzysztof Adamskiccc103f2014-12-08 12:13:41 +010039#include <linux/etherdevice.h>
Forest Bond92b96792009-06-13 07:38:31 -040040#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040041#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040042#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040043#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040044#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040045#include "usbpipe.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070046
Malcolm Priestley1a4d45092014-07-11 01:08:25 +010047static const u16 vnt_time_stampoff[2][MAX_RATE] = {
48 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23},/* Long Preamble */
49 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23},/* Short Preamble */
50};
Forest Bond92b96792009-06-13 07:38:31 -040051
Malcolm Priestleye3f31872014-07-11 01:08:26 +010052static const u16 vnt_fb_opt0[2][5] = {
53 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, /* fallback_rate0 */
54 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, /* fallback_rate1 */
55};
56
Malcolm Priestley2331ba42014-07-11 01:08:27 +010057static const u16 vnt_fb_opt1[2][5] = {
58 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, /* fallback_rate0 */
Krzysztof Adamski73c4c6e2014-12-10 18:05:31 +010059 {RATE_6M, RATE_6M, RATE_12M, RATE_12M, RATE_18M}, /* fallback_rate1 */
Malcolm Priestley2331ba42014-07-11 01:08:27 +010060};
Forest Bond92b96792009-06-13 07:38:31 -040061
Forest Bond92b96792009-06-13 07:38:31 -040062#define RTSDUR_BB 0
63#define RTSDUR_BA 1
64#define RTSDUR_AA 2
65#define CTSDUR_BA 3
66#define RTSDUR_BA_F0 4
67#define RTSDUR_AA_F0 5
68#define RTSDUR_BA_F1 6
69#define RTSDUR_AA_F1 7
70#define CTSDUR_BA_F0 8
71#define CTSDUR_BA_F1 9
72#define DATADUR_B 10
73#define DATADUR_A 11
74#define DATADUR_A_F0 12
75#define DATADUR_A_F1 13
76
Malcolm Priestleyaceaf012013-11-26 19:06:35 +000077static struct vnt_usb_send_context
Malcolm Priestleya032b162014-07-11 01:08:28 +010078 *vnt_get_free_context(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -040079{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000080 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000081 int ii;
Forest Bond92b96792009-06-13 07:38:31 -040082
Malcolm Priestley604631f2014-07-11 01:08:31 +010083 dev_dbg(&priv->usb->dev, "%s\n", __func__);
Forest Bond92b96792009-06-13 07:38:31 -040084
Malcolm Priestley03b7e352014-07-19 12:30:04 +010085 for (ii = 0; ii < priv->num_tx_context; ii++) {
Malcolm Priestleyf7e4a8f2014-07-18 06:36:16 +010086 if (!priv->tx_context[ii])
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000087 return NULL;
88
Malcolm Priestleyf7e4a8f2014-07-18 06:36:16 +010089 context = priv->tx_context[ii];
Malcolm Priestley30a05b32014-05-15 22:49:11 +010090 if (context->in_use == false) {
91 context->in_use = true;
92 memset(context->data, 0,
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000093 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Malcolm Priestley1622c8f2014-05-31 13:34:58 +010094
95 context->hdr = NULL;
96
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000097 return context;
98 }
99 }
100
Malcolm Priestley03b7e352014-07-19 12:30:04 +0100101 if (ii == priv->num_tx_context)
Malcolm Priestley604631f2014-07-11 01:08:31 +0100102 dev_dbg(&priv->usb->dev, "%s No Free Tx Context\n", __func__);
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000103
Malcolm Priestley5c851382013-11-26 19:12:38 +0000104 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400105}
106
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000107static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100108{
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100109 return cpu_to_le16(vnt_time_stampoff[priv->preamble_type % 2]
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100110 [rate % MAX_RATE]);
111}
112
Malcolm Priestley3815a272014-07-11 01:08:24 +0100113static u32 vnt_get_rsvtime(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000114 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400115{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000116 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100118 data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000119 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400120
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000121 if (pkt_type == PK_TYPE_11B)
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100122 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100123 14, (u16)priv->top_cck_basic_rate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000124 else
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100125 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100126 14, (u16)priv->top_ofdm_basic_rate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000127
128 if (need_ack)
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100129 return data_time + priv->sifs + ack_time;
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000130
131 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400132}
133
Malcolm Priestley2075f652014-03-18 19:25:07 +0000134static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100135 u32 frame_length, u16 rate, int need_ack)
136{
Malcolm Priestley3815a272014-07-11 01:08:24 +0100137 return cpu_to_le16((u16)vnt_get_rsvtime(priv, pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100138 frame_length, rate, need_ack));
139}
140
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100141static __le16 vnt_get_rtscts_rsvtime_le(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100142 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400143{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000144 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400145
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000146 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400147
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100148 data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100149 frame_length, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400150
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000151 if (rsv_type == 0) {
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100152 rts_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100153 pkt_type, 20, priv->top_cck_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100154 cts_time = ack_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100155 pkt_type, 14, priv->top_cck_basic_rate);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000156 } else if (rsv_type == 1) {
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100157 rts_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100158 pkt_type, 20, priv->top_cck_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100159 cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100160 14, priv->top_cck_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100161 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100162 14, priv->top_ofdm_basic_rate);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000163 } else if (rsv_type == 2) {
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100164 rts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100165 20, priv->top_ofdm_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100166 cts_time = ack_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100167 pkt_type, 14, priv->top_ofdm_basic_rate);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000168 } else if (rsv_type == 3) {
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100169 cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100170 14, priv->top_cck_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100171 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100172 14, priv->top_ofdm_basic_rate);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000173
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100174 rrv_time = cts_time + ack_time + data_time + 2 * priv->sifs;
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000175
Malcolm Priestley20338012014-03-18 19:25:08 +0000176 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000177 }
178
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100179 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->sifs;
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000180
181 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400182}
183
Malcolm Priestley0871dc62014-07-20 15:33:30 +0100184static __le16 vnt_get_duration_le(struct vnt_private *priv,
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100185 u8 pkt_type, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400186{
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100187 u32 ack_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400188
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100189 if (need_ack) {
190 if (pkt_type == PK_TYPE_11B)
Malcolm Priestley0871dc62014-07-20 15:33:30 +0100191 ack_time = vnt_get_frame_time(priv->preamble_type,
192 pkt_type, 14, priv->top_cck_basic_rate);
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100193 else
Malcolm Priestley0871dc62014-07-20 15:33:30 +0100194 ack_time = vnt_get_frame_time(priv->preamble_type,
195 pkt_type, 14, priv->top_ofdm_basic_rate);
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100196
Malcolm Priestley0871dc62014-07-20 15:33:30 +0100197 return cpu_to_le16((u16)(priv->sifs + ack_time));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100198 }
Forest Bond92b96792009-06-13 07:38:31 -0400199
Forest Bond92b96792009-06-13 07:38:31 -0400200 return 0;
201}
202
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100203static __le16 vnt_get_rtscts_duration_le(struct vnt_usb_send_context *context,
204 u8 dur_type, u8 pkt_type, u16 rate)
Forest Bond92b96792009-06-13 07:38:31 -0400205{
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100206 struct vnt_private *priv = context->priv;
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100207 u32 cts_time = 0, dur_time = 0;
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100208 u32 frame_length = context->frame_len;
209 u8 need_ack = context->need_ack;
Forest Bond92b96792009-06-13 07:38:31 -0400210
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100211 switch (dur_type) {
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100212 case RTSDUR_BB:
213 case RTSDUR_BA:
214 case RTSDUR_BA_F0:
215 case RTSDUR_BA_F1:
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100216 cts_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100217 pkt_type, 14, priv->top_cck_basic_rate);
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100218 dur_time = cts_time + 2 * priv->sifs +
Malcolm Priestley3815a272014-07-11 01:08:24 +0100219 vnt_get_rsvtime(priv, pkt_type,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100220 frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100221 break;
Forest Bond92b96792009-06-13 07:38:31 -0400222
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100223 case RTSDUR_AA:
224 case RTSDUR_AA_F0:
225 case RTSDUR_AA_F1:
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100226 cts_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100227 pkt_type, 14, priv->top_ofdm_basic_rate);
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100228 dur_time = cts_time + 2 * priv->sifs +
Malcolm Priestley3815a272014-07-11 01:08:24 +0100229 vnt_get_rsvtime(priv, pkt_type,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100230 frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100231 break;
Forest Bond92b96792009-06-13 07:38:31 -0400232
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100233 case CTSDUR_BA:
234 case CTSDUR_BA_F0:
235 case CTSDUR_BA_F1:
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100236 dur_time = priv->sifs + vnt_get_rsvtime(priv,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100237 pkt_type, frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100238 break;
Forest Bond92b96792009-06-13 07:38:31 -0400239
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100240 default:
241 break;
242 }
Forest Bond92b96792009-06-13 07:38:31 -0400243
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100244 return cpu_to_le16((u16)dur_time);
Forest Bond92b96792009-06-13 07:38:31 -0400245}
246
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100247static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
248 struct ieee80211_hdr *hdr)
249{
250 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
251 u8 *hdr_pos = (u8 *)hdr;
252
253 tx_context->hdr = hdr;
254 if (!tx_context->hdr)
255 return 0;
256
257 return (u16)(hdr_pos - head);
258}
259
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100260static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100261 struct vnt_tx_datahead_g *buf)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100262{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100263
264 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100265 struct ieee80211_hdr *hdr =
266 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100267 u32 frame_len = tx_context->frame_len;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100268 u16 rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100269 u8 need_ack = tx_context->need_ack;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100270
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100271 /* Get SignalField,ServiceField,Length */
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100272 vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a);
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100273 vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100274 PK_TYPE_11B, &buf->b);
275
276 /* Get Duration and TimeStamp */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100277 if (ieee80211_is_pspoll(hdr->frame_control)) {
278 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
279
280 buf->duration_a = dur;
281 buf->duration_b = dur;
282 } else {
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100283 buf->duration_a = vnt_get_duration_le(priv,
284 tx_context->pkt_type, need_ack);
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100285 buf->duration_b = vnt_get_duration_le(priv,
Malcolm Priestley893cc702014-06-25 21:14:38 +0100286 PK_TYPE_11B, need_ack);
287 }
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100288
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000289 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
290 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100291 priv->top_cck_basic_rate);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100292
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100293 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
294
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000295 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100296}
297
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100298static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100299 struct vnt_tx_datahead_g_fb *buf)
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100300{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100301 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100302 u32 frame_len = tx_context->frame_len;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100303 u16 rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100304 u8 need_ack = tx_context->need_ack;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100305
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100306 /* Get SignalField,ServiceField,Length */
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100307 vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100308
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100309 vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100310 PK_TYPE_11B, &buf->b);
311
312 /* Get Duration and TimeStamp */
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100313 buf->duration_a = vnt_get_duration_le(priv, tx_context->pkt_type,
314 need_ack);
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100315 buf->duration_b = vnt_get_duration_le(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100316
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100317 buf->duration_a_f0 = vnt_get_duration_le(priv, tx_context->pkt_type,
318 need_ack);
319 buf->duration_a_f1 = vnt_get_duration_le(priv, tx_context->pkt_type,
320 need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100321
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000322 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
323 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100324 priv->top_cck_basic_rate);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100325
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100326 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
327
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000328 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100329}
330
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100331static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100332 struct vnt_tx_datahead_a_fb *buf)
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100333{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100334 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100335 u16 rate = tx_context->tx_rate;
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100336 u8 pkt_type = tx_context->pkt_type;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100337 u8 need_ack = tx_context->need_ack;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100338 u32 frame_len = tx_context->frame_len;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100339
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100340 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100341 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100342 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100343 buf->duration = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100344
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100345 buf->duration_f0 = vnt_get_duration_le(priv, pkt_type, need_ack);
346 buf->duration_f1 = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100347
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000348 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100349
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100350 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
351
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000352 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100353}
354
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100355static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100356 struct vnt_tx_datahead_ab *buf)
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100357{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100358 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100359 struct ieee80211_hdr *hdr =
360 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100361 u32 frame_len = tx_context->frame_len;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100362 u16 rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100363 u8 need_ack = tx_context->need_ack;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100364
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100365 /* Get SignalField,ServiceField,Length */
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100366 vnt_get_phy_field(priv, frame_len, rate,
367 tx_context->pkt_type, &buf->ab);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100368
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100369 /* Get Duration and TimeStampOff */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100370 if (ieee80211_is_pspoll(hdr->frame_control)) {
371 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
372
373 buf->duration = dur;
374 } else {
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100375 buf->duration = vnt_get_duration_le(priv, tx_context->pkt_type,
376 need_ack);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100377 }
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100378
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000379 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100380
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100381 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
382
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000383 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100384}
385
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100386static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
387 struct ieee80211_rts *rts, __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100388{
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100389 struct ieee80211_hdr *hdr =
390 (struct ieee80211_hdr *)tx_context->skb->data;
391
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100392 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000393 rts->frame_control =
394 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100395
Krzysztof Adamskiccc103f2014-12-08 12:13:41 +0100396 ether_addr_copy(rts->ra, hdr->addr1);
397 ether_addr_copy(rts->ta, hdr->addr2);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100398
399 return 0;
400}
401
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100402static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100403 struct vnt_rts_g *buf)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100404{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100405 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100406 u16 rts_frame_len = 20;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100407 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100408
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100409 vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100410 PK_TYPE_11B, &buf->b);
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100411 vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
412 tx_context->pkt_type, &buf->a);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100413
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100414 buf->duration_bb = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BB,
415 PK_TYPE_11B,
416 priv->top_cck_basic_rate);
417 buf->duration_aa = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA,
418 tx_context->pkt_type,
419 current_rate);
420 buf->duration_ba = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA,
421 tx_context->pkt_type,
422 current_rate);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100423
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100424 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100425
Malcolm Priestley798f0602014-07-20 15:33:34 +0100426 return vnt_rxtx_datahead_g(tx_context, &buf->data_head);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100427}
428
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100429static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100430 struct vnt_rts_g_fb *buf)
Malcolm Priestleyec917132013-08-26 11:07:46 +0100431{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100432 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100433 u16 current_rate = tx_context->tx_rate;
Malcolm Priestleyec917132013-08-26 11:07:46 +0100434 u16 rts_frame_len = 20;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100435
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100436 vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100437 PK_TYPE_11B, &buf->b);
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100438 vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
439 tx_context->pkt_type, &buf->a);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100440
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100441 buf->duration_bb = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BB,
442 PK_TYPE_11B,
443 priv->top_cck_basic_rate);
444 buf->duration_aa = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA,
445 tx_context->pkt_type,
446 current_rate);
447 buf->duration_ba = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA,
448 tx_context->pkt_type,
449 current_rate);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100450
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100451 buf->rts_duration_ba_f0 =
452 vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA_F0,
453 tx_context->pkt_type,
454 priv->tx_rate_fb0);
455 buf->rts_duration_aa_f0 =
456 vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F0,
457 tx_context->pkt_type,
458 priv->tx_rate_fb0);
459 buf->rts_duration_ba_f1 =
460 vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA_F1,
461 tx_context->pkt_type,
462 priv->tx_rate_fb1);
463 buf->rts_duration_aa_f1 =
464 vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F1,
465 tx_context->pkt_type,
466 priv->tx_rate_fb1);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100467
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100468 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100469
Malcolm Priestley798f0602014-07-20 15:33:34 +0100470 return vnt_rxtx_datahead_g_fb(tx_context, &buf->data_head);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100471}
472
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100473static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100474 struct vnt_rts_ab *buf)
Malcolm Priestley17126332013-08-26 11:09:38 +0100475{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100476 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100477 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley17126332013-08-26 11:09:38 +0100478 u16 rts_frame_len = 20;
479
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100480 vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
481 tx_context->pkt_type, &buf->ab);
Malcolm Priestley17126332013-08-26 11:09:38 +0100482
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100483 buf->duration = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100484 tx_context->pkt_type,
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100485 current_rate);
Malcolm Priestley17126332013-08-26 11:09:38 +0100486
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100487 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100488
Malcolm Priestley798f0602014-07-20 15:33:34 +0100489 return vnt_rxtx_datahead_ab(tx_context, &buf->data_head);
Malcolm Priestley17126332013-08-26 11:09:38 +0100490}
491
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100492static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100493 struct vnt_rts_a_fb *buf)
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100494{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100495 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100496 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100497 u16 rts_frame_len = 20;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100498
Malcolm Priestley205056f2014-06-04 18:25:34 +0100499 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100500 priv->top_ofdm_basic_rate, tx_context->pkt_type, &buf->a);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100501
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100502 buf->duration = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100503 tx_context->pkt_type,
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100504 current_rate);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100505
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100506 buf->rts_duration_f0 =
507 vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F0,
508 tx_context->pkt_type,
509 priv->tx_rate_fb0);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100510
Malcolm Priestleycca48e32014-07-20 15:33:35 +0100511 buf->rts_duration_f1 =
512 vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F1,
513 tx_context->pkt_type,
514 priv->tx_rate_fb1);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100515
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100516 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100517
Malcolm Priestley798f0602014-07-20 15:33:34 +0100518 return vnt_rxtx_datahead_a_fb(tx_context, &buf->data_head);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100519}
520
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000521static u16 vnt_fill_cts_fb_head(struct vnt_usb_send_context *tx_context,
522 union vnt_tx_data_head *head)
Forest Bond92b96792009-06-13 07:38:31 -0400523{
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100524 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000525 struct vnt_cts_fb *buf = &head->cts_g_fb;
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100526 u32 cts_frame_len = 14;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100527 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100528
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000529 /* Get SignalField,ServiceField,Length */
530 vnt_get_phy_field(priv, cts_frame_len, priv->top_cck_basic_rate,
531 PK_TYPE_11B, &buf->b);
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000532
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000533 buf->duration_ba =
534 vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA,
535 tx_context->pkt_type,
536 current_rate);
537 /* Get CTSDuration_ba_f0 */
538 buf->cts_duration_ba_f0 =
539 vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA_F0,
540 tx_context->pkt_type,
541 priv->tx_rate_fb0);
542 /* Get CTSDuration_ba_f1 */
543 buf->cts_duration_ba_f1 =
544 vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA_F1,
545 tx_context->pkt_type,
546 priv->tx_rate_fb1);
547 /* Get CTS Frame body */
548 buf->data.duration = buf->duration_ba;
549 buf->data.frame_control =
550 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100551
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000552 ether_addr_copy(buf->data.ra, priv->current_net_addr);
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000553
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000554 return vnt_rxtx_datahead_g_fb(tx_context, &buf->data_head);
555}
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100556
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000557static u16 vnt_fill_cts_head(struct vnt_usb_send_context *tx_context,
558 union vnt_tx_data_head *head)
559{
560 struct vnt_private *priv = tx_context->priv;
561 struct vnt_cts *buf = &head->cts_g;
562 u32 cts_frame_len = 14;
563 u16 current_rate = tx_context->tx_rate;
564
565 /* Get SignalField,ServiceField,Length */
566 vnt_get_phy_field(priv, cts_frame_len, priv->top_cck_basic_rate,
567 PK_TYPE_11B, &buf->b);
568 /* Get CTSDuration_ba */
569 buf->duration_ba =
570 vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA,
571 tx_context->pkt_type,
572 current_rate);
573 /*Get CTS Frame body*/
574 buf->data.duration = buf->duration_ba;
575 buf->data.frame_control =
576 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
577
578 ether_addr_copy(buf->data.ra, priv->current_net_addr);
579
580 return vnt_rxtx_datahead_g(tx_context, &buf->data_head);
Forest Bond92b96792009-06-13 07:38:31 -0400581}
582
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100583static u16 vnt_rxtx_rts(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100584 union vnt_tx_head *tx_head, bool need_mic)
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100585{
586 struct vnt_private *priv = tx_context->priv;
587 struct vnt_rrv_time_rts *buf = &tx_head->tx_rts.rts;
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100588 union vnt_tx_data_head *head = &tx_head->tx_rts.tx.head;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100589 u32 frame_len = tx_context->frame_len;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100590 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100591 u8 need_ack = tx_context->need_ack;
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100592
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100593 buf->rts_rrv_time_aa = vnt_get_rtscts_rsvtime_le(priv, 2,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100594 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100595 buf->rts_rrv_time_ba = vnt_get_rtscts_rsvtime_le(priv, 1,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100596 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100597 buf->rts_rrv_time_bb = vnt_get_rtscts_rsvtime_le(priv, 0,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100598 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100599
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100600 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100601 frame_len, current_rate,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100602 need_ack);
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100603 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B, frame_len,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100604 priv->top_cck_basic_rate, need_ack);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100605
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100606 if (need_mic)
607 head = &tx_head->tx_rts.tx.mic.head;
608
609 if (tx_context->fb_option)
Malcolm Priestley798f0602014-07-20 15:33:34 +0100610 return vnt_rxtx_rts_g_fb_head(tx_context, &head->rts_g_fb);
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100611
Malcolm Priestley798f0602014-07-20 15:33:34 +0100612 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100613}
614
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100615static u16 vnt_rxtx_cts(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100616 union vnt_tx_head *tx_head, bool need_mic)
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100617{
618 struct vnt_private *priv = tx_context->priv;
619 struct vnt_rrv_time_cts *buf = &tx_head->tx_cts.cts;
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100620 union vnt_tx_data_head *head = &tx_head->tx_cts.tx.head;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100621 u32 frame_len = tx_context->frame_len;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100622 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100623 u8 need_ack = tx_context->need_ack;
624
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100625 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100626 frame_len, current_rate, need_ack);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100627 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100628 frame_len, priv->top_cck_basic_rate, need_ack);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100629
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100630 buf->cts_rrv_time_ba = vnt_get_rtscts_rsvtime_le(priv, 3,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100631 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100632
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100633 if (need_mic)
634 head = &tx_head->tx_cts.tx.mic.head;
635
636 /* Fill CTS */
Malcolm Priestley1bdee702015-02-01 11:59:43 +0000637 if (tx_context->fb_option)
638 return vnt_fill_cts_fb_head(tx_context, head);
639
Malcolm Priestley798f0602014-07-20 15:33:34 +0100640 return vnt_fill_cts_head(tx_context, head);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100641}
642
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100643static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100644 union vnt_tx_head *tx_head, bool need_rts, bool need_mic)
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100645{
646 struct vnt_private *priv = tx_context->priv;
647 struct vnt_rrv_time_ab *buf = &tx_head->tx_ab.ab;
Malcolm Priestley681acf62014-07-10 19:56:12 +0100648 union vnt_tx_data_head *head = &tx_head->tx_ab.tx.head;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100649 u32 frame_len = tx_context->frame_len;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100650 u16 current_rate = tx_context->tx_rate;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100651 u8 need_ack = tx_context->need_ack;
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100652
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100653 buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100654 frame_len, current_rate, need_ack);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100655
Malcolm Priestley681acf62014-07-10 19:56:12 +0100656 if (need_mic)
657 head = &tx_head->tx_ab.tx.mic.head;
658
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100659 if (need_rts) {
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100660 if (tx_context->pkt_type == PK_TYPE_11B)
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100661 buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 0,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100662 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100663 else /* PK_TYPE_11A */
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100664 buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 2,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100665 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100666
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100667 if (tx_context->fb_option &&
668 tx_context->pkt_type == PK_TYPE_11A)
Malcolm Priestley681acf62014-07-10 19:56:12 +0100669 return vnt_rxtx_rts_a_fb_head(tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100670 &head->rts_a_fb);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100671
Malcolm Priestley798f0602014-07-20 15:33:34 +0100672 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100673 }
674
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100675 if (tx_context->pkt_type == PK_TYPE_11A)
Malcolm Priestley798f0602014-07-20 15:33:34 +0100676 return vnt_rxtx_datahead_a_fb(tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100677 &head->data_head_a_fb);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100678
Malcolm Priestley798f0602014-07-20 15:33:34 +0100679 return vnt_rxtx_datahead_ab(tx_context, &head->data_head_ab);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100680}
681
Malcolm Priestley9ec7f2d2014-07-10 19:56:15 +0100682static u16 vnt_generate_tx_parameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100683 struct vnt_tx_buffer *tx_buffer,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100684 struct vnt_mic_hdr **mic_hdr, u32 need_mic,
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100685 bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400686{
Forest Bond92b96792009-06-13 07:38:31 -0400687
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100688 if (tx_context->pkt_type == PK_TYPE_11GB ||
689 tx_context->pkt_type == PK_TYPE_11GA) {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100690 if (need_rts) {
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100691 if (need_mic)
Malcolm Priestley92928f12013-10-07 20:14:01 +0100692 *mic_hdr = &tx_buffer->
693 tx_head.tx_rts.tx.mic.hdr;
Malcolm Priestley92928f12013-10-07 20:14:01 +0100694
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100695 return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head,
Malcolm Priestley798f0602014-07-20 15:33:34 +0100696 need_mic);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100697 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100698
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100699 if (need_mic)
700 *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr;
701
Malcolm Priestley798f0602014-07-20 15:33:34 +0100702 return vnt_rxtx_cts(tx_context, &tx_buffer->tx_head, need_mic);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100703 }
704
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100705 if (need_mic)
706 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
707
Malcolm Priestley798f0602014-07-20 15:33:34 +0100708 return vnt_rxtx_ab(tx_context, &tx_buffer->tx_head, need_rts, need_mic);
Forest Bond92b96792009-06-13 07:38:31 -0400709}
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100710
711static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
712 u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
713 u16 payload_len, struct vnt_mic_hdr *mic_hdr)
714{
715 struct ieee80211_hdr *hdr = tx_context->hdr;
716 struct ieee80211_key_seq seq;
717 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
718
719 /* strip header and icv len from payload */
720 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
721 payload_len -= tx_key->icv_len;
722
723 switch (tx_key->cipher) {
724 case WLAN_CIPHER_SUITE_WEP40:
725 case WLAN_CIPHER_SUITE_WEP104:
726 memcpy(key_buffer, iv, 3);
727 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
728
729 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
730 memcpy(key_buffer + 8, iv, 3);
731 memcpy(key_buffer + 11,
732 tx_key->key, WLAN_KEY_LEN_WEP40);
733 }
734
735 break;
736 case WLAN_CIPHER_SUITE_TKIP:
737 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
738
739 break;
740 case WLAN_CIPHER_SUITE_CCMP:
741
742 if (!mic_hdr)
743 return;
744
745 mic_hdr->id = 0x59;
746 mic_hdr->payload_len = cpu_to_be16(payload_len);
Heba Aamer48eaa7f2015-01-21 13:08:48 +0200747 ether_addr_copy(mic_hdr->mic_addr2, hdr->addr2);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100748
749 ieee80211_get_key_tx_seq(tx_key, &seq);
750
Malcolm Priestley79f976d2014-06-28 23:55:39 +0100751 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100752
753 if (ieee80211_has_a4(hdr->frame_control))
754 mic_hdr->hlen = cpu_to_be16(28);
755 else
756 mic_hdr->hlen = cpu_to_be16(22);
757
aybuke ozdemir1aba0122015-02-22 15:27:56 +0200758 ether_addr_copy(mic_hdr->addr1, hdr->addr1);
759 ether_addr_copy(mic_hdr->addr2, hdr->addr2);
760 ether_addr_copy(mic_hdr->addr3, hdr->addr3);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100761
762 mic_hdr->frame_control = cpu_to_le16(
763 le16_to_cpu(hdr->frame_control) & 0xc78f);
764 mic_hdr->seq_ctrl = cpu_to_le16(
765 le16_to_cpu(hdr->seq_ctrl) & 0xf);
766
767 if (ieee80211_has_a4(hdr->frame_control))
aybuke ozdemir1aba0122015-02-22 15:27:56 +0200768 ether_addr_copy(mic_hdr->addr4, hdr->addr4);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100769
770
771 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
772
773 break;
774 default:
775 break;
776 }
777
778}
779
780int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
781{
782 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
783 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
784 struct ieee80211_rate *rate;
785 struct ieee80211_key_conf *tx_key;
786 struct ieee80211_hdr *hdr;
787 struct vnt_mic_hdr *mic_hdr = NULL;
788 struct vnt_tx_buffer *tx_buffer;
789 struct vnt_tx_fifo_head *tx_buffer_head;
790 struct vnt_usb_send_context *tx_context;
791 unsigned long flags;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100792 u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
793 u8 pkt_type, fb_option = AUTO_FB_NONE;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100794 bool need_rts = false, is_pspoll = false;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100795 bool need_mic = false;
796
797 hdr = (struct ieee80211_hdr *)(skb->data);
798
799 rate = ieee80211_get_tx_rate(priv->hw, info);
800
801 current_rate = rate->hw_value;
Malcolm Priestley8b84c1d2014-07-20 15:33:19 +0100802 if (priv->current_rate != current_rate &&
Malcolm Priestley5091d962014-07-05 19:24:23 +0100803 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
Malcolm Priestley8b84c1d2014-07-20 15:33:19 +0100804 priv->current_rate = current_rate;
Malcolm Priestley57981a62014-07-13 10:42:50 +0100805 vnt_schedule_command(priv, WLAN_CMD_SETPOWER);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100806 }
807
808 if (current_rate > RATE_11M)
Malcolm Priestleye12471d2014-07-20 15:33:12 +0100809 pkt_type = priv->packet_type;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100810 else
811 pkt_type = PK_TYPE_11B;
812
813 spin_lock_irqsave(&priv->lock, flags);
814
Malcolm Priestleya032b162014-07-11 01:08:28 +0100815 tx_context = vnt_get_free_context(priv);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100816 if (!tx_context) {
817 dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
818 spin_unlock_irqrestore(&priv->lock, flags);
819 return -ENOMEM;
820 }
821
822 tx_context->skb = skb;
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100823 tx_context->pkt_type = pkt_type;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100824 tx_context->need_ack = false;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100825 tx_context->frame_len = skb->len + 4;
Malcolm Priestley798f0602014-07-20 15:33:34 +0100826 tx_context->tx_rate = current_rate;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100827
828 spin_unlock_irqrestore(&priv->lock, flags);
829
830 tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
831 tx_buffer_head = &tx_buffer->fifo_head;
832 tx_body_size = skb->len;
833
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100834 /*Set fifo controls */
835 if (pkt_type == PK_TYPE_11A)
Malcolm Priestleyf0ff3fd2014-07-22 22:49:43 +0100836 tx_buffer_head->fifo_ctl = 0;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100837 else if (pkt_type == PK_TYPE_11B)
Malcolm Priestley47e08892014-07-22 22:49:48 +0100838 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11B);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100839 else if (pkt_type == PK_TYPE_11GB)
Malcolm Priestley47e08892014-07-22 22:49:48 +0100840 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GB);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100841 else if (pkt_type == PK_TYPE_11GA)
Malcolm Priestley47e08892014-07-22 22:49:48 +0100842 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GA);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100843
844 if (!ieee80211_is_data(hdr->frame_control)) {
Malcolm Priestley47e08892014-07-22 22:49:48 +0100845 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT |
846 FIFOCTL_ISDMA0);
847 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_TMOEN);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100848
849 tx_buffer_head->time_stamp =
850 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
851 } else {
852 tx_buffer_head->time_stamp =
853 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
854 }
855
856 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Malcolm Priestley47e08892014-07-22 22:49:48 +0100857 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_NEEDACK);
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100858 tx_context->need_ack = true;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100859 }
860
861 if (ieee80211_has_retry(hdr->frame_control))
Malcolm Priestley47e08892014-07-22 22:49:48 +0100862 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LRETRY);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100863
864 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100865 priv->preamble_type = PREAMBLE_SHORT;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100866 else
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100867 priv->preamble_type = PREAMBLE_LONG;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100868
869 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
870 need_rts = true;
Malcolm Priestley47e08892014-07-22 22:49:48 +0100871 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_RTS);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100872 }
873
874 if (ieee80211_has_a4(hdr->frame_control))
Malcolm Priestley47e08892014-07-22 22:49:48 +0100875 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LHEAD);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100876
877 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
878 is_pspoll = true;
879
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100880 tx_buffer_head->frag_ctl =
881 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100882
883 if (info->control.hw_key) {
884 tx_key = info->control.hw_key;
885 switch (info->control.hw_key->cipher) {
886 case WLAN_CIPHER_SUITE_WEP40:
887 case WLAN_CIPHER_SUITE_WEP104:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100888 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100889 break;
890 case WLAN_CIPHER_SUITE_TKIP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100891 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100892 break;
893 case WLAN_CIPHER_SUITE_CCMP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100894 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100895 need_mic = true;
896 default:
897 break;
898 }
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100899 tx_context->frame_len += tx_key->icv_len;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100900 }
901
Malcolm Priestleycb8ee9de2014-07-10 19:56:05 +0100902 tx_buffer_head->current_rate = cpu_to_le16(current_rate);
903
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100904 /* legacy rates TODO use ieee80211_tx_rate */
905 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
Malcolm Priestleya6177ae2014-07-20 15:33:24 +0100906 if (priv->auto_fb_ctrl == AUTO_FB_0) {
Malcolm Priestley47e08892014-07-22 22:49:48 +0100907 tx_buffer_head->fifo_ctl |=
908 cpu_to_le16(FIFOCTL_AUTO_FB_0);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100909
910 priv->tx_rate_fb0 =
Malcolm Priestleye3f31872014-07-11 01:08:26 +0100911 vnt_fb_opt0[FB_RATE0][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100912 priv->tx_rate_fb1 =
Malcolm Priestleye3f31872014-07-11 01:08:26 +0100913 vnt_fb_opt0[FB_RATE1][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100914
915 fb_option = AUTO_FB_0;
Malcolm Priestleya6177ae2014-07-20 15:33:24 +0100916 } else if (priv->auto_fb_ctrl == AUTO_FB_1) {
Malcolm Priestley47e08892014-07-22 22:49:48 +0100917 tx_buffer_head->fifo_ctl |=
918 cpu_to_le16(FIFOCTL_AUTO_FB_1);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100919
920 priv->tx_rate_fb0 =
Malcolm Priestley2331ba42014-07-11 01:08:27 +0100921 vnt_fb_opt1[FB_RATE0][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100922 priv->tx_rate_fb1 =
Malcolm Priestley2331ba42014-07-11 01:08:27 +0100923 vnt_fb_opt1[FB_RATE1][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100924
925 fb_option = AUTO_FB_1;
926 }
927 }
928
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100929 tx_context->fb_option = fb_option;
930
Malcolm Priestley798f0602014-07-20 15:33:34 +0100931 duration_id = vnt_generate_tx_parameter(tx_context, tx_buffer, &mic_hdr,
932 need_mic, need_rts);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100933
934 tx_header_size = tx_context->tx_hdr_size;
935 if (!tx_header_size) {
936 tx_context->in_use = false;
937 return -ENOMEM;
938 }
939
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100940 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100941
942 tx_bytes = tx_header_size + tx_body_size;
943
944 memcpy(tx_context->hdr, skb->data, tx_body_size);
945
946 hdr->duration_id = cpu_to_le16(duration_id);
947
948 if (info->control.hw_key) {
949 tx_key = info->control.hw_key;
950 if (tx_key->keylen > 0)
951 vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
952 tx_key, skb, tx_body_size, mic_hdr);
953 }
954
Malcolm Priestley1b2bc0a2014-07-20 15:33:23 +0100955 priv->seq_counter = (le16_to_cpu(hdr->seq_ctrl) &
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100956 IEEE80211_SCTL_SEQ) >> 4;
957
958 tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
Malcolm Priestleyd0335a02014-07-22 22:49:44 +0100959 tx_buffer->pkt_no = tx_context->pkt_no;
Malcolm Priestleyc8a3a4c2014-07-22 22:49:46 +0100960 tx_buffer->type = 0x00;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100961
962 tx_bytes += 4;
963
964 tx_context->type = CONTEXT_DATA_PACKET;
965 tx_context->buf_len = tx_bytes;
966
967 spin_lock_irqsave(&priv->lock, flags);
968
Malcolm Priestley476e7d92014-07-15 19:54:39 +0100969 if (vnt_tx_context(priv, tx_context) != STATUS_PENDING) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100970 spin_unlock_irqrestore(&priv->lock, flags);
971 return -EIO;
972 }
973
974 spin_unlock_irqrestore(&priv->lock, flags);
975
976 return 0;
977}
978
979static int vnt_beacon_xmit(struct vnt_private *priv,
980 struct sk_buff *skb)
981{
982 struct vnt_beacon_buffer *beacon_buffer;
983 struct vnt_tx_short_buf_head *short_head;
984 struct ieee80211_tx_info *info;
985 struct vnt_usb_send_context *context;
986 struct ieee80211_mgmt *mgmt_hdr;
987 unsigned long flags;
988 u32 frame_size = skb->len + 4;
989 u16 current_rate, count;
990
991 spin_lock_irqsave(&priv->lock, flags);
992
Malcolm Priestleya032b162014-07-11 01:08:28 +0100993 context = vnt_get_free_context(priv);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100994 if (!context) {
995 dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
996 spin_unlock_irqrestore(&priv->lock, flags);
997 return -ENOMEM;
998 }
999
1000 context->skb = skb;
1001
1002 spin_unlock_irqrestore(&priv->lock, flags);
1003
1004 beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
1005 short_head = &beacon_buffer->short_head;
1006
Malcolm Priestley65df77e2014-07-20 15:33:11 +01001007 if (priv->bb_type == BB_TYPE_11A) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001008 current_rate = RATE_6M;
1009
1010 /* Get SignalField,ServiceField,Length */
1011 vnt_get_phy_field(priv, frame_size, current_rate,
1012 PK_TYPE_11A, &short_head->ab);
1013
1014 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +01001015 short_head->duration = vnt_get_duration_le(priv,
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001016 PK_TYPE_11A, false);
1017 short_head->time_stamp_off =
1018 vnt_time_stamp_off(priv, current_rate);
1019 } else {
1020 current_rate = RATE_1M;
Malcolm Priestley14fb6ce2014-07-22 22:49:49 +01001021 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_11B);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001022
1023 /* Get SignalField,ServiceField,Length */
1024 vnt_get_phy_field(priv, frame_size, current_rate,
1025 PK_TYPE_11B, &short_head->ab);
1026
1027 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +01001028 short_head->duration = vnt_get_duration_le(priv,
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001029 PK_TYPE_11B, false);
1030 short_head->time_stamp_off =
1031 vnt_time_stamp_off(priv, current_rate);
1032 }
1033
1034 /* Generate Beacon Header */
1035 mgmt_hdr = &beacon_buffer->mgmt_hdr;
1036 memcpy(mgmt_hdr, skb->data, skb->len);
1037
1038 /* time stamp always 0 */
1039 mgmt_hdr->u.beacon.timestamp = 0;
1040
1041 info = IEEE80211_SKB_CB(skb);
1042 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1043 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
Ragnar B. Johannsson76be25b2014-08-10 22:23:50 +00001044
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001045 hdr->duration_id = 0;
Malcolm Priestley1b2bc0a2014-07-20 15:33:23 +01001046 hdr->seq_ctrl = cpu_to_le16(priv->seq_counter << 4);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001047 }
1048
Malcolm Priestley1b2bc0a2014-07-20 15:33:23 +01001049 priv->seq_counter++;
1050 if (priv->seq_counter > 0x0fff)
1051 priv->seq_counter = 0;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001052
1053 count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
1054
1055 beacon_buffer->tx_byte_count = cpu_to_le16(count);
Malcolm Priestleyaf90ab32014-07-22 22:49:45 +01001056 beacon_buffer->pkt_no = context->pkt_no;
Malcolm Priestley1e00b442014-07-22 22:49:47 +01001057 beacon_buffer->type = 0x01;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001058
1059 context->type = CONTEXT_BEACON_PACKET;
1060 context->buf_len = count + 4; /* USB header */
1061
1062 spin_lock_irqsave(&priv->lock, flags);
1063
Malcolm Priestley476e7d92014-07-15 19:54:39 +01001064 if (vnt_tx_context(priv, context) != STATUS_PENDING)
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001065 ieee80211_free_txskb(priv->hw, context->skb);
1066
1067 spin_unlock_irqrestore(&priv->lock, flags);
1068
1069 return 0;
1070}
1071
1072int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1073{
1074 struct sk_buff *beacon;
1075
1076 beacon = ieee80211_beacon_get(priv->hw, vif);
1077 if (!beacon)
1078 return -ENOMEM;
1079
1080 if (vnt_beacon_xmit(priv, beacon)) {
1081 ieee80211_free_txskb(priv->hw, beacon);
1082 return -ENODEV;
1083 }
1084
1085 return 0;
1086}
1087
1088int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1089 struct ieee80211_bss_conf *conf)
1090{
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001091 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1092
1093 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1094
1095 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
1096
1097 vnt_clear_current_tsf(priv);
1098
1099 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1100
1101 vnt_reset_next_tbtt(priv, conf->beacon_int);
1102
Mahati Chamarthyeab4e782014-09-21 20:54:52 +05301103 return vnt_beacon_make(priv, vif);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001104}