blob: 163bb1a551655719aa9625b8a6b32a2245eaded2 [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
Forest Bond92b96792009-06-13 07:38:31 -040039#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040040#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040041#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040042#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040043#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040044#include "usbpipe.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070045
Malcolm Priestley1a4d45092014-07-11 01:08:25 +010046static const u16 vnt_time_stampoff[2][MAX_RATE] = {
47 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23},/* Long Preamble */
48 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23},/* Short Preamble */
49};
Forest Bond92b96792009-06-13 07:38:31 -040050
Malcolm Priestleye3f31872014-07-11 01:08:26 +010051static const u16 vnt_fb_opt0[2][5] = {
52 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, /* fallback_rate0 */
53 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, /* fallback_rate1 */
54};
55
Malcolm Priestley2331ba42014-07-11 01:08:27 +010056static const u16 vnt_fb_opt1[2][5] = {
57 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, /* fallback_rate0 */
58 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, /* fallback_rate1 */
59};
Forest Bond92b96792009-06-13 07:38:31 -040060
Forest Bond92b96792009-06-13 07:38:31 -040061#define RTSDUR_BB 0
62#define RTSDUR_BA 1
63#define RTSDUR_AA 2
64#define CTSDUR_BA 3
65#define RTSDUR_BA_F0 4
66#define RTSDUR_AA_F0 5
67#define RTSDUR_BA_F1 6
68#define RTSDUR_AA_F1 7
69#define CTSDUR_BA_F0 8
70#define CTSDUR_BA_F1 9
71#define DATADUR_B 10
72#define DATADUR_A 11
73#define DATADUR_A_F0 12
74#define DATADUR_A_F1 13
75
Malcolm Priestleyaceaf012013-11-26 19:06:35 +000076static struct vnt_usb_send_context
Malcolm Priestleya032b162014-07-11 01:08:28 +010077 *vnt_get_free_context(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -040078{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000079 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000080 int ii;
Forest Bond92b96792009-06-13 07:38:31 -040081
Malcolm Priestley604631f2014-07-11 01:08:31 +010082 dev_dbg(&priv->usb->dev, "%s\n", __func__);
Forest Bond92b96792009-06-13 07:38:31 -040083
Malcolm Priestley03b7e352014-07-19 12:30:04 +010084 for (ii = 0; ii < priv->num_tx_context; ii++) {
Malcolm Priestleyf7e4a8f2014-07-18 06:36:16 +010085 if (!priv->tx_context[ii])
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000086 return NULL;
87
Malcolm Priestleyf7e4a8f2014-07-18 06:36:16 +010088 context = priv->tx_context[ii];
Malcolm Priestley30a05b32014-05-15 22:49:11 +010089 if (context->in_use == false) {
90 context->in_use = true;
91 memset(context->data, 0,
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000092 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Malcolm Priestley1622c8f2014-05-31 13:34:58 +010093
94 context->hdr = NULL;
95
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000096 return context;
97 }
98 }
99
Malcolm Priestley03b7e352014-07-19 12:30:04 +0100100 if (ii == priv->num_tx_context)
Malcolm Priestley604631f2014-07-11 01:08:31 +0100101 dev_dbg(&priv->usb->dev, "%s No Free Tx Context\n", __func__);
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000102
Malcolm Priestley5c851382013-11-26 19:12:38 +0000103 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400104}
105
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000106static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100107{
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100108 return cpu_to_le16(vnt_time_stampoff[priv->preamble_type % 2]
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100109 [rate % MAX_RATE]);
110}
111
Malcolm Priestley3815a272014-07-11 01:08:24 +0100112static u32 vnt_get_rsvtime(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000113 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400114{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000115 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400116
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100117 data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000118 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400119
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000120 if (pkt_type == PK_TYPE_11B)
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100121 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100122 14, (u16)priv->top_cck_basic_rate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000123 else
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100124 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100125 14, (u16)priv->top_ofdm_basic_rate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000126
127 if (need_ack)
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100128 return data_time + priv->sifs + ack_time;
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000129
130 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400131}
132
Malcolm Priestley2075f652014-03-18 19:25:07 +0000133static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100134 u32 frame_length, u16 rate, int need_ack)
135{
Malcolm Priestley3815a272014-07-11 01:08:24 +0100136 return cpu_to_le16((u16)vnt_get_rsvtime(priv, pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100137 frame_length, rate, need_ack));
138}
139
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100140static __le16 vnt_get_rtscts_rsvtime_le(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100141 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400142{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000143 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400144
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000145 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400146
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100147 data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100148 frame_length, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400149
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000150 if (rsv_type == 0) {
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100151 rts_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100152 pkt_type, 20, priv->top_cck_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100153 cts_time = ack_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100154 pkt_type, 14, priv->top_cck_basic_rate);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000155 } else if (rsv_type == 1) {
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100156 rts_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100157 pkt_type, 20, priv->top_cck_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100158 cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100159 14, priv->top_cck_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100160 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100161 14, priv->top_ofdm_basic_rate);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000162 } else if (rsv_type == 2) {
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100163 rts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100164 20, priv->top_ofdm_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100165 cts_time = ack_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100166 pkt_type, 14, priv->top_ofdm_basic_rate);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000167 } else if (rsv_type == 3) {
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100168 cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100169 14, priv->top_cck_basic_rate);
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100170 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100171 14, priv->top_ofdm_basic_rate);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000172
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100173 rrv_time = cts_time + ack_time + data_time + 2 * priv->sifs;
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000174
Malcolm Priestley20338012014-03-18 19:25:08 +0000175 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000176 }
177
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100178 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->sifs;
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000179
180 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400181}
182
Malcolm Priestley0871dc62014-07-20 15:33:30 +0100183static __le16 vnt_get_duration_le(struct vnt_private *priv,
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100184 u8 pkt_type, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400185{
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100186 u32 ack_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400187
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100188 if (need_ack) {
189 if (pkt_type == PK_TYPE_11B)
Malcolm Priestley0871dc62014-07-20 15:33:30 +0100190 ack_time = vnt_get_frame_time(priv->preamble_type,
191 pkt_type, 14, priv->top_cck_basic_rate);
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100192 else
Malcolm Priestley0871dc62014-07-20 15:33:30 +0100193 ack_time = vnt_get_frame_time(priv->preamble_type,
194 pkt_type, 14, priv->top_ofdm_basic_rate);
Malcolm Priestleya4c2a8a2014-07-11 01:08:21 +0100195
Malcolm Priestley0871dc62014-07-20 15:33:30 +0100196 return cpu_to_le16((u16)(priv->sifs + ack_time));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100197 }
Forest Bond92b96792009-06-13 07:38:31 -0400198
Forest Bond92b96792009-06-13 07:38:31 -0400199 return 0;
200}
201
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100202static __le16 vnt_get_rtscts_duration_le(struct vnt_private *priv, u8 dur_type,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100203 u32 frame_length, u8 pkt_type, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400204{
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100205 u32 cts_time = 0, dur_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400206
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100207 switch (dur_type) {
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100208 case RTSDUR_BB:
209 case RTSDUR_BA:
210 case RTSDUR_BA_F0:
211 case RTSDUR_BA_F1:
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100212 cts_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100213 pkt_type, 14, priv->top_cck_basic_rate);
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100214 dur_time = cts_time + 2 * priv->sifs +
Malcolm Priestley3815a272014-07-11 01:08:24 +0100215 vnt_get_rsvtime(priv, pkt_type,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100216 frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100217 break;
Forest Bond92b96792009-06-13 07:38:31 -0400218
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100219 case RTSDUR_AA:
220 case RTSDUR_AA_F0:
221 case RTSDUR_AA_F1:
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100222 cts_time = vnt_get_frame_time(priv->preamble_type,
Malcolm Priestley3c8a5b22014-07-20 15:33:14 +0100223 pkt_type, 14, priv->top_ofdm_basic_rate);
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100224 dur_time = cts_time + 2 * priv->sifs +
Malcolm Priestley3815a272014-07-11 01:08:24 +0100225 vnt_get_rsvtime(priv, pkt_type,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100226 frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100227 break;
Forest Bond92b96792009-06-13 07:38:31 -0400228
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100229 case CTSDUR_BA:
230 case CTSDUR_BA_F0:
231 case CTSDUR_BA_F1:
Malcolm Priestleyff5fee22014-07-19 12:30:18 +0100232 dur_time = priv->sifs + vnt_get_rsvtime(priv,
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100233 pkt_type, frame_length, rate, need_ack);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100234 break;
Forest Bond92b96792009-06-13 07:38:31 -0400235
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100236 default:
237 break;
238 }
Forest Bond92b96792009-06-13 07:38:31 -0400239
Malcolm Priestley7beae9a22014-07-11 01:08:19 +0100240 return cpu_to_le16((u16)dur_time);
Forest Bond92b96792009-06-13 07:38:31 -0400241}
242
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100243static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
244 struct ieee80211_hdr *hdr)
245{
246 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
247 u8 *hdr_pos = (u8 *)hdr;
248
249 tx_context->hdr = hdr;
250 if (!tx_context->hdr)
251 return 0;
252
253 return (u16)(hdr_pos - head);
254}
255
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100256static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100257 u16 rate, struct vnt_tx_datahead_g *buf)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100258{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100259
260 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100261 struct ieee80211_hdr *hdr =
262 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100263 u32 frame_len = tx_context->frame_len;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100264 u8 need_ack = tx_context->need_ack;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100265
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100266 /* Get SignalField,ServiceField,Length */
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100267 vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a);
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100268 vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100269 PK_TYPE_11B, &buf->b);
270
271 /* Get Duration and TimeStamp */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100272 if (ieee80211_is_pspoll(hdr->frame_control)) {
273 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
274
275 buf->duration_a = dur;
276 buf->duration_b = dur;
277 } else {
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100278 buf->duration_a = vnt_get_duration_le(priv,
279 tx_context->pkt_type, need_ack);
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100280 buf->duration_b = vnt_get_duration_le(priv,
Malcolm Priestley893cc702014-06-25 21:14:38 +0100281 PK_TYPE_11B, need_ack);
282 }
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100283
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000284 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
285 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100286 priv->top_cck_basic_rate);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100287
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100288 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
289
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000290 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100291}
292
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100293static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100294 u16 rate, struct vnt_tx_datahead_g_fb *buf)
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100295{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100296 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100297 u32 frame_len = tx_context->frame_len;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100298 u8 need_ack = tx_context->need_ack;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100299
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100300 /* Get SignalField,ServiceField,Length */
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100301 vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100302
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100303 vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100304 PK_TYPE_11B, &buf->b);
305
306 /* Get Duration and TimeStamp */
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100307 buf->duration_a = vnt_get_duration_le(priv, tx_context->pkt_type,
308 need_ack);
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100309 buf->duration_b = vnt_get_duration_le(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100310
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100311 buf->duration_a_f0 = vnt_get_duration_le(priv, tx_context->pkt_type,
312 need_ack);
313 buf->duration_a_f1 = vnt_get_duration_le(priv, tx_context->pkt_type,
314 need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100315
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000316 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
317 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100318 priv->top_cck_basic_rate);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100319
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100320 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
321
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000322 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100323}
324
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100325static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100326 u16 rate, struct vnt_tx_datahead_a_fb *buf)
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100327{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100328 struct vnt_private *priv = tx_context->priv;
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100329 u8 pkt_type = tx_context->pkt_type;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100330 u8 need_ack = tx_context->need_ack;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100331 u32 frame_len = tx_context->frame_len;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100332
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100333 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100334 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100335 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100336 buf->duration = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100337
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100338 buf->duration_f0 = vnt_get_duration_le(priv, pkt_type, need_ack);
339 buf->duration_f1 = vnt_get_duration_le(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100340
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000341 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100342
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100343 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
344
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000345 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100346}
347
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100348static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100349 u16 rate, struct vnt_tx_datahead_ab *buf)
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100350{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100351 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100352 struct ieee80211_hdr *hdr =
353 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100354 u32 frame_len = tx_context->frame_len;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100355 u8 need_ack = tx_context->need_ack;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100356
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100357 /* Get SignalField,ServiceField,Length */
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100358 vnt_get_phy_field(priv, frame_len, rate,
359 tx_context->pkt_type, &buf->ab);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100360
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100361 /* Get Duration and TimeStampOff */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100362 if (ieee80211_is_pspoll(hdr->frame_control)) {
363 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
364
365 buf->duration = dur;
366 } else {
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100367 buf->duration = vnt_get_duration_le(priv, tx_context->pkt_type,
368 need_ack);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100369 }
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100370
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000371 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100372
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100373 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
374
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000375 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100376}
377
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100378static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
379 struct ieee80211_rts *rts, __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100380{
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100381 struct ieee80211_hdr *hdr =
382 (struct ieee80211_hdr *)tx_context->skb->data;
383
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100384 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000385 rts->frame_control =
386 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100387
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100388 memcpy(rts->ra, hdr->addr1, ETH_ALEN);
389 memcpy(rts->ta, hdr->addr2, ETH_ALEN);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100390
391 return 0;
392}
393
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100394static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100395 struct vnt_rts_g *buf, u16 current_rate)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100396{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100397 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100398 u32 frame_len = tx_context->frame_len;
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100399 u16 rts_frame_len = 20;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100400 u8 need_ack = tx_context->need_ack;
401
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100402 vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100403 PK_TYPE_11B, &buf->b);
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100404 vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
405 tx_context->pkt_type, &buf->a);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100406
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100407 buf->duration_bb = vnt_get_rtscts_duration_le(priv, RTSDUR_BB,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100408 frame_len, PK_TYPE_11B, priv->top_cck_basic_rate, need_ack);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100409 buf->duration_aa = vnt_get_rtscts_duration_le(priv, RTSDUR_AA,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100410 frame_len, tx_context->pkt_type, current_rate, need_ack);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100411 buf->duration_ba = vnt_get_rtscts_duration_le(priv, RTSDUR_BA,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100412 frame_len, tx_context->pkt_type, current_rate, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100413
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100414 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100415
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100416 return vnt_rxtx_datahead_g(tx_context, current_rate, &buf->data_head);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100417}
418
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100419static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100420 struct vnt_rts_g_fb *buf, u16 current_rate)
Malcolm Priestleyec917132013-08-26 11:07:46 +0100421{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100422 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100423 u32 frame_len = tx_context->frame_len;
Malcolm Priestleyec917132013-08-26 11:07:46 +0100424 u16 rts_frame_len = 20;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100425 u8 need_ack = tx_context->need_ack;
426
Malcolm Priestleyec917132013-08-26 11:07:46 +0100427
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100428 vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100429 PK_TYPE_11B, &buf->b);
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100430 vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
431 tx_context->pkt_type, &buf->a);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100432
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100433 buf->duration_bb = vnt_get_rtscts_duration_le(priv, RTSDUR_BB,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100434 frame_len, PK_TYPE_11B, priv->top_cck_basic_rate, need_ack);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100435 buf->duration_aa = vnt_get_rtscts_duration_le(priv, RTSDUR_AA,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100436 frame_len, tx_context->pkt_type, current_rate, need_ack);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100437 buf->duration_ba = vnt_get_rtscts_duration_le(priv, RTSDUR_BA,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100438 frame_len, tx_context->pkt_type, current_rate, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100439
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100440 buf->rts_duration_ba_f0 = vnt_get_rtscts_duration_le(priv, RTSDUR_BA_F0,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100441 frame_len, tx_context->pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100442 buf->rts_duration_aa_f0 = vnt_get_rtscts_duration_le(priv, RTSDUR_AA_F0,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100443 frame_len, tx_context->pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100444 buf->rts_duration_ba_f1 = vnt_get_rtscts_duration_le(priv, RTSDUR_BA_F1,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100445 frame_len, tx_context->pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100446 buf->rts_duration_aa_f1 = vnt_get_rtscts_duration_le(priv, RTSDUR_AA_F1,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100447 frame_len, tx_context->pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100448
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100449 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100450
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100451 return vnt_rxtx_datahead_g_fb(tx_context,
452 current_rate, &buf->data_head);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100453}
454
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100455static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100456 struct vnt_rts_ab *buf, u16 current_rate)
Malcolm Priestley17126332013-08-26 11:09:38 +0100457{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100458 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100459 u32 frame_len = tx_context->frame_len;
Malcolm Priestley17126332013-08-26 11:09:38 +0100460 u16 rts_frame_len = 20;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100461 u8 need_ack = tx_context->need_ack;
462
Malcolm Priestley17126332013-08-26 11:09:38 +0100463
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100464 vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
465 tx_context->pkt_type, &buf->ab);
Malcolm Priestley17126332013-08-26 11:09:38 +0100466
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100467 buf->duration = vnt_get_rtscts_duration_le(priv, RTSDUR_AA, frame_len,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100468 tx_context->pkt_type,
469 current_rate, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100470
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100471 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100472
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100473 return vnt_rxtx_datahead_ab(tx_context, current_rate,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100474 &buf->data_head);
Malcolm Priestley17126332013-08-26 11:09:38 +0100475}
476
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100477static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100478 struct vnt_rts_a_fb *buf, u16 current_rate)
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100479{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100480 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100481 u32 frame_len = tx_context->frame_len;
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100482 u16 rts_frame_len = 20;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100483 u8 need_ack = tx_context->need_ack;
484
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100485
Malcolm Priestley205056f2014-06-04 18:25:34 +0100486 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100487 priv->top_ofdm_basic_rate, tx_context->pkt_type, &buf->a);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100488
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100489 buf->duration = vnt_get_rtscts_duration_le(priv, RTSDUR_AA, frame_len,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100490 tx_context->pkt_type,
491 current_rate, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100492
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100493 buf->rts_duration_f0 = vnt_get_rtscts_duration_le(priv, RTSDUR_AA_F0,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100494 frame_len, tx_context->pkt_type, priv->tx_rate_fb0, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100495
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100496 buf->rts_duration_f1 = vnt_get_rtscts_duration_le(priv, RTSDUR_AA_F1,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100497 frame_len, tx_context->pkt_type, priv->tx_rate_fb1, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100498
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100499 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100500
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100501 return vnt_rxtx_datahead_a_fb(tx_context,
502 current_rate, &buf->data_head);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100503}
504
Malcolm Priestley4f316682014-07-10 19:56:17 +0100505static u16 vnt_fill_cts_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100506 union vnt_tx_data_head *head, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400507{
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100508 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100509 u32 frame_len = tx_context->frame_len;
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100510 u32 cts_frame_len = 14;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100511 u8 need_ack = tx_context->need_ack;
512
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100513 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100514 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400515
Malcolm Priestleyce7b0db2014-07-10 19:56:03 +0100516 if (tx_context->fb_option) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100517 /* Auto Fall back */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100518 struct vnt_cts_fb *buf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100519 /* Get SignalField,ServiceField,Length */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100520 vnt_get_phy_field(priv, cts_frame_len,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100521 priv->top_cck_basic_rate, PK_TYPE_11B, &buf->b);
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100522 buf->duration_ba = vnt_get_rtscts_duration_le(priv, CTSDUR_BA,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100523 frame_len, tx_context->pkt_type,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100524 current_rate, need_ack);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100525 /* Get CTSDuration_ba_f0 */
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100526 buf->cts_duration_ba_f0 = vnt_get_rtscts_duration_le(priv,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100527 CTSDUR_BA_F0, frame_len, tx_context->pkt_type,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100528 priv->tx_rate_fb0, need_ack);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100529 /* Get CTSDuration_ba_f1 */
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100530 buf->cts_duration_ba_f1 = vnt_get_rtscts_duration_le(priv,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100531 CTSDUR_BA_F1, frame_len, tx_context->pkt_type,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100532 priv->tx_rate_fb1, need_ack);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100533 /* Get CTS Frame body */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100534 buf->data.duration = buf->duration_ba;
535 buf->data.frame_control =
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000536 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
537
Malcolm Priestleyebf9b312014-07-19 12:30:10 +0100538 memcpy(buf->data.ra, priv->current_net_addr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100539
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100540 return vnt_rxtx_datahead_g_fb(tx_context, current_rate,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100541 &buf->data_head);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100542 } else {
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100543 struct vnt_cts *buf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100544 /* Get SignalField,ServiceField,Length */
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100545 vnt_get_phy_field(priv, cts_frame_len,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100546 priv->top_cck_basic_rate, PK_TYPE_11B, &buf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100547 /* Get CTSDuration_ba */
Malcolm Priestleyf2aabee2014-07-11 01:08:20 +0100548 buf->duration_ba = vnt_get_rtscts_duration_le(priv,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100549 CTSDUR_BA, frame_len, tx_context->pkt_type,
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100550 current_rate, need_ack);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100551 /*Get CTS Frame body*/
Malcolm Priestleyee16de82014-07-10 19:56:16 +0100552 buf->data.duration = buf->duration_ba;
553 buf->data.frame_control =
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000554 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
555
Malcolm Priestleyebf9b312014-07-19 12:30:10 +0100556 memcpy(buf->data.ra, priv->current_net_addr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100557
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100558 return vnt_rxtx_datahead_g(tx_context, current_rate,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100559 &buf->data_head);
Forest Bond92b96792009-06-13 07:38:31 -0400560 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100561
562 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400563}
564
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100565static u16 vnt_rxtx_rts(struct vnt_usb_send_context *tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100566 union vnt_tx_head *tx_head,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100567 u16 current_rate, bool need_mic)
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100568{
569 struct vnt_private *priv = tx_context->priv;
570 struct vnt_rrv_time_rts *buf = &tx_head->tx_rts.rts;
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100571 union vnt_tx_data_head *head = &tx_head->tx_rts.tx.head;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100572 u32 frame_len = tx_context->frame_len;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100573 u8 need_ack = tx_context->need_ack;
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100574
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100575 buf->rts_rrv_time_aa = vnt_get_rtscts_rsvtime_le(priv, 2,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100576 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100577 buf->rts_rrv_time_ba = vnt_get_rtscts_rsvtime_le(priv, 1,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100578 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100579 buf->rts_rrv_time_bb = vnt_get_rtscts_rsvtime_le(priv, 0,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100580 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100581
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100582 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100583 frame_len, current_rate,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100584 need_ack);
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100585 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B, frame_len,
Malcolm Priestleyd80bf432014-07-20 15:33:15 +0100586 priv->top_cck_basic_rate, need_ack);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100587
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100588 if (need_mic)
589 head = &tx_head->tx_rts.tx.mic.head;
590
591 if (tx_context->fb_option)
592 return vnt_rxtx_rts_g_fb_head(tx_context, &head->rts_g_fb,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100593 current_rate);
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100594
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100595 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g, current_rate);
Malcolm Priestley24cdd902014-07-10 19:56:06 +0100596}
597
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100598static u16 vnt_rxtx_cts(struct vnt_usb_send_context *tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100599 union vnt_tx_head *tx_head, u16 current_rate, bool need_mic)
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100600{
601 struct vnt_private *priv = tx_context->priv;
602 struct vnt_rrv_time_cts *buf = &tx_head->tx_cts.cts;
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100603 union vnt_tx_data_head *head = &tx_head->tx_cts.tx.head;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100604 u32 frame_len = tx_context->frame_len;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100605 u8 need_ack = tx_context->need_ack;
606
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100607 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100608 frame_len, current_rate, need_ack);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100609 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(priv, PK_TYPE_11B,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100610 frame_len, priv->top_cck_basic_rate, need_ack);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100611
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100612 buf->cts_rrv_time_ba = vnt_get_rtscts_rsvtime_le(priv, 3,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100613 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100614
Malcolm Priestleyb00cb682014-07-10 19:56:11 +0100615 if (need_mic)
616 head = &tx_head->tx_cts.tx.mic.head;
617
618 /* Fill CTS */
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100619 return vnt_fill_cts_head(tx_context, head, current_rate);
Malcolm Priestleybf9c0112014-07-10 19:56:07 +0100620}
621
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100622static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100623 union vnt_tx_head *tx_head,
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100624 u16 current_rate, bool need_rts, bool need_mic)
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100625{
626 struct vnt_private *priv = tx_context->priv;
627 struct vnt_rrv_time_ab *buf = &tx_head->tx_ab.ab;
Malcolm Priestley681acf62014-07-10 19:56:12 +0100628 union vnt_tx_data_head *head = &tx_head->tx_ab.tx.head;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100629 u32 frame_len = tx_context->frame_len;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100630 u8 need_ack = tx_context->need_ack;
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100631
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100632 buf->rrv_time = vnt_rxtx_rsvtime_le16(priv, tx_context->pkt_type,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100633 frame_len, current_rate, need_ack);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100634
Malcolm Priestley681acf62014-07-10 19:56:12 +0100635 if (need_mic)
636 head = &tx_head->tx_ab.tx.mic.head;
637
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100638 if (need_rts) {
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100639 if (tx_context->pkt_type == PK_TYPE_11B)
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100640 buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 0,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100641 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100642 else /* PK_TYPE_11A */
Malcolm Priestleyaadf7d12014-07-11 01:08:23 +0100643 buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 2,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100644 tx_context->pkt_type, frame_len, current_rate);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100645
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100646 if (tx_context->fb_option &&
647 tx_context->pkt_type == PK_TYPE_11A)
Malcolm Priestley681acf62014-07-10 19:56:12 +0100648 return vnt_rxtx_rts_a_fb_head(tx_context,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100649 &head->rts_a_fb,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100650 current_rate);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100651
652 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100653 current_rate);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100654 }
655
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100656 if (tx_context->pkt_type == PK_TYPE_11A)
657 return vnt_rxtx_datahead_a_fb(tx_context, current_rate,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100658 &head->data_head_a_fb);
Malcolm Priestley681acf62014-07-10 19:56:12 +0100659
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100660 return vnt_rxtx_datahead_ab(tx_context, current_rate,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100661 &head->data_head_ab);
Malcolm Priestley3b03fea2014-07-10 19:56:09 +0100662}
663
Malcolm Priestley9ec7f2d2014-07-10 19:56:15 +0100664static u16 vnt_generate_tx_parameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100665 u16 current_rate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100666 struct vnt_mic_hdr **mic_hdr, u32 need_mic,
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100667 bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400668{
Forest Bond92b96792009-06-13 07:38:31 -0400669
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100670 if (tx_context->pkt_type == PK_TYPE_11GB ||
671 tx_context->pkt_type == PK_TYPE_11GA) {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100672 if (need_rts) {
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100673 if (need_mic)
Malcolm Priestley92928f12013-10-07 20:14:01 +0100674 *mic_hdr = &tx_buffer->
675 tx_head.tx_rts.tx.mic.hdr;
Malcolm Priestley92928f12013-10-07 20:14:01 +0100676
Malcolm Priestley4f06c0d2014-07-10 19:56:10 +0100677 return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100678 current_rate, need_mic);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100679 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100680
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100681 if (need_mic)
682 *mic_hdr = &tx_buffer->tx_head.tx_cts.tx.mic.hdr;
683
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100684 return vnt_rxtx_cts(tx_context, &tx_buffer->tx_head,
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100685 current_rate, need_mic);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100686 }
687
Malcolm Priestleyda9ef9f2014-07-10 19:56:13 +0100688 if (need_mic)
689 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
690
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100691 return vnt_rxtx_ab(tx_context, &tx_buffer->tx_head,
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100692 current_rate, need_rts, need_mic);
Forest Bond92b96792009-06-13 07:38:31 -0400693}
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100694
695static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
696 u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
697 u16 payload_len, struct vnt_mic_hdr *mic_hdr)
698{
699 struct ieee80211_hdr *hdr = tx_context->hdr;
700 struct ieee80211_key_seq seq;
701 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
702
703 /* strip header and icv len from payload */
704 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
705 payload_len -= tx_key->icv_len;
706
707 switch (tx_key->cipher) {
708 case WLAN_CIPHER_SUITE_WEP40:
709 case WLAN_CIPHER_SUITE_WEP104:
710 memcpy(key_buffer, iv, 3);
711 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
712
713 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
714 memcpy(key_buffer + 8, iv, 3);
715 memcpy(key_buffer + 11,
716 tx_key->key, WLAN_KEY_LEN_WEP40);
717 }
718
719 break;
720 case WLAN_CIPHER_SUITE_TKIP:
721 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
722
723 break;
724 case WLAN_CIPHER_SUITE_CCMP:
725
726 if (!mic_hdr)
727 return;
728
729 mic_hdr->id = 0x59;
730 mic_hdr->payload_len = cpu_to_be16(payload_len);
731 memcpy(mic_hdr->mic_addr2, hdr->addr2, ETH_ALEN);
732
733 ieee80211_get_key_tx_seq(tx_key, &seq);
734
Malcolm Priestley79f976d2014-06-28 23:55:39 +0100735 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100736
737 if (ieee80211_has_a4(hdr->frame_control))
738 mic_hdr->hlen = cpu_to_be16(28);
739 else
740 mic_hdr->hlen = cpu_to_be16(22);
741
742 memcpy(mic_hdr->addr1, hdr->addr1, ETH_ALEN);
743 memcpy(mic_hdr->addr2, hdr->addr2, ETH_ALEN);
744 memcpy(mic_hdr->addr3, hdr->addr3, ETH_ALEN);
745
746 mic_hdr->frame_control = cpu_to_le16(
747 le16_to_cpu(hdr->frame_control) & 0xc78f);
748 mic_hdr->seq_ctrl = cpu_to_le16(
749 le16_to_cpu(hdr->seq_ctrl) & 0xf);
750
751 if (ieee80211_has_a4(hdr->frame_control))
752 memcpy(mic_hdr->addr4, hdr->addr4, ETH_ALEN);
753
754
755 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
756
757 break;
758 default:
759 break;
760 }
761
762}
763
764int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
765{
766 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
767 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
768 struct ieee80211_rate *rate;
769 struct ieee80211_key_conf *tx_key;
770 struct ieee80211_hdr *hdr;
771 struct vnt_mic_hdr *mic_hdr = NULL;
772 struct vnt_tx_buffer *tx_buffer;
773 struct vnt_tx_fifo_head *tx_buffer_head;
774 struct vnt_usb_send_context *tx_context;
775 unsigned long flags;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100776 u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
777 u8 pkt_type, fb_option = AUTO_FB_NONE;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100778 bool need_rts = false, is_pspoll = false;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100779 bool need_mic = false;
780
781 hdr = (struct ieee80211_hdr *)(skb->data);
782
783 rate = ieee80211_get_tx_rate(priv->hw, info);
784
785 current_rate = rate->hw_value;
Malcolm Priestley8b84c1d2014-07-20 15:33:19 +0100786 if (priv->current_rate != current_rate &&
Malcolm Priestley5091d962014-07-05 19:24:23 +0100787 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
Malcolm Priestley8b84c1d2014-07-20 15:33:19 +0100788 priv->current_rate = current_rate;
Malcolm Priestley57981a62014-07-13 10:42:50 +0100789 vnt_schedule_command(priv, WLAN_CMD_SETPOWER);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100790 }
791
792 if (current_rate > RATE_11M)
Malcolm Priestleye12471d2014-07-20 15:33:12 +0100793 pkt_type = priv->packet_type;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100794 else
795 pkt_type = PK_TYPE_11B;
796
797 spin_lock_irqsave(&priv->lock, flags);
798
Malcolm Priestleya032b162014-07-11 01:08:28 +0100799 tx_context = vnt_get_free_context(priv);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100800 if (!tx_context) {
801 dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
802 spin_unlock_irqrestore(&priv->lock, flags);
803 return -ENOMEM;
804 }
805
806 tx_context->skb = skb;
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100807 tx_context->pkt_type = pkt_type;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100808 tx_context->need_ack = false;
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100809 tx_context->frame_len = skb->len + 4;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100810
811 spin_unlock_irqrestore(&priv->lock, flags);
812
813 tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
814 tx_buffer_head = &tx_buffer->fifo_head;
815 tx_body_size = skb->len;
816
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100817 /*Set fifo controls */
818 if (pkt_type == PK_TYPE_11A)
819 tx_buffer_head->wFIFOCtl = 0;
820 else if (pkt_type == PK_TYPE_11B)
821 tx_buffer_head->wFIFOCtl = FIFOCTL_11B;
822 else if (pkt_type == PK_TYPE_11GB)
823 tx_buffer_head->wFIFOCtl = FIFOCTL_11GB;
824 else if (pkt_type == PK_TYPE_11GA)
825 tx_buffer_head->wFIFOCtl = FIFOCTL_11GA;
826
827 if (!ieee80211_is_data(hdr->frame_control)) {
828 tx_buffer_head->wFIFOCtl |= (FIFOCTL_GENINT |
829 FIFOCTL_ISDMA0);
830 tx_buffer_head->wFIFOCtl |= FIFOCTL_TMOEN;
831
832 tx_buffer_head->time_stamp =
833 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
834 } else {
835 tx_buffer_head->time_stamp =
836 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
837 }
838
839 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
840 tx_buffer_head->wFIFOCtl |= FIFOCTL_NEEDACK;
Malcolm Priestley2eca8db2014-07-20 15:33:32 +0100841 tx_context->need_ack = true;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100842 }
843
844 if (ieee80211_has_retry(hdr->frame_control))
845 tx_buffer_head->wFIFOCtl |= FIFOCTL_LRETRY;
846
847 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100848 priv->preamble_type = PREAMBLE_SHORT;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100849 else
Malcolm Priestley98e93fe2014-07-20 15:33:17 +0100850 priv->preamble_type = PREAMBLE_LONG;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100851
852 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
853 need_rts = true;
854 tx_buffer_head->wFIFOCtl |= FIFOCTL_RTS;
855 }
856
857 if (ieee80211_has_a4(hdr->frame_control))
858 tx_buffer_head->wFIFOCtl |= FIFOCTL_LHEAD;
859
860 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
861 is_pspoll = true;
862
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100863 tx_buffer_head->frag_ctl =
864 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100865
866 if (info->control.hw_key) {
867 tx_key = info->control.hw_key;
868 switch (info->control.hw_key->cipher) {
869 case WLAN_CIPHER_SUITE_WEP40:
870 case WLAN_CIPHER_SUITE_WEP104:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100871 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100872 break;
873 case WLAN_CIPHER_SUITE_TKIP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100874 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100875 break;
876 case WLAN_CIPHER_SUITE_CCMP:
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100877 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100878 need_mic = true;
879 default:
880 break;
881 }
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100882 tx_context->frame_len += tx_key->icv_len;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100883 }
884
Malcolm Priestleycb8ee9de2014-07-10 19:56:05 +0100885 tx_buffer_head->current_rate = cpu_to_le16(current_rate);
886
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100887 /* legacy rates TODO use ieee80211_tx_rate */
888 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
Malcolm Priestleya6177ae2014-07-20 15:33:24 +0100889 if (priv->auto_fb_ctrl == AUTO_FB_0) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100890 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
891
892 priv->tx_rate_fb0 =
Malcolm Priestleye3f31872014-07-11 01:08:26 +0100893 vnt_fb_opt0[FB_RATE0][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100894 priv->tx_rate_fb1 =
Malcolm Priestleye3f31872014-07-11 01:08:26 +0100895 vnt_fb_opt0[FB_RATE1][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100896
897 fb_option = AUTO_FB_0;
Malcolm Priestleya6177ae2014-07-20 15:33:24 +0100898 } else if (priv->auto_fb_ctrl == AUTO_FB_1) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100899 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
900
901 priv->tx_rate_fb0 =
Malcolm Priestley2331ba42014-07-11 01:08:27 +0100902 vnt_fb_opt1[FB_RATE0][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100903 priv->tx_rate_fb1 =
Malcolm Priestley2331ba42014-07-11 01:08:27 +0100904 vnt_fb_opt1[FB_RATE1][current_rate - RATE_18M];
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100905
906 fb_option = AUTO_FB_1;
907 }
908 }
909
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100910 tx_context->fb_option = fb_option;
911
Malcolm Priestleye8c98752014-07-20 15:33:31 +0100912 duration_id = vnt_generate_tx_parameter(tx_context, current_rate,
913 tx_buffer, &mic_hdr, need_mic,
Malcolm Priestley0f5567c2014-07-20 15:33:33 +0100914 need_rts);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100915
916 tx_header_size = tx_context->tx_hdr_size;
917 if (!tx_header_size) {
918 tx_context->in_use = false;
919 return -ENOMEM;
920 }
921
Malcolm Priestley5deb1cf2014-06-28 23:55:40 +0100922 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100923
924 tx_bytes = tx_header_size + tx_body_size;
925
926 memcpy(tx_context->hdr, skb->data, tx_body_size);
927
928 hdr->duration_id = cpu_to_le16(duration_id);
929
930 if (info->control.hw_key) {
931 tx_key = info->control.hw_key;
932 if (tx_key->keylen > 0)
933 vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
934 tx_key, skb, tx_body_size, mic_hdr);
935 }
936
Malcolm Priestley1b2bc0a2014-07-20 15:33:23 +0100937 priv->seq_counter = (le16_to_cpu(hdr->seq_ctrl) &
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100938 IEEE80211_SCTL_SEQ) >> 4;
939
940 tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
Malcolm Priestley71d764a2014-07-05 19:24:27 +0100941 tx_buffer->byPKTNO = tx_context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100942 tx_buffer->byType = 0x00;
943
944 tx_bytes += 4;
945
946 tx_context->type = CONTEXT_DATA_PACKET;
947 tx_context->buf_len = tx_bytes;
948
949 spin_lock_irqsave(&priv->lock, flags);
950
Malcolm Priestley476e7d92014-07-15 19:54:39 +0100951 if (vnt_tx_context(priv, tx_context) != STATUS_PENDING) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100952 spin_unlock_irqrestore(&priv->lock, flags);
953 return -EIO;
954 }
955
956 spin_unlock_irqrestore(&priv->lock, flags);
957
958 return 0;
959}
960
961static int vnt_beacon_xmit(struct vnt_private *priv,
962 struct sk_buff *skb)
963{
964 struct vnt_beacon_buffer *beacon_buffer;
965 struct vnt_tx_short_buf_head *short_head;
966 struct ieee80211_tx_info *info;
967 struct vnt_usb_send_context *context;
968 struct ieee80211_mgmt *mgmt_hdr;
969 unsigned long flags;
970 u32 frame_size = skb->len + 4;
971 u16 current_rate, count;
972
973 spin_lock_irqsave(&priv->lock, flags);
974
Malcolm Priestleya032b162014-07-11 01:08:28 +0100975 context = vnt_get_free_context(priv);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100976 if (!context) {
977 dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
978 spin_unlock_irqrestore(&priv->lock, flags);
979 return -ENOMEM;
980 }
981
982 context->skb = skb;
983
984 spin_unlock_irqrestore(&priv->lock, flags);
985
986 beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
987 short_head = &beacon_buffer->short_head;
988
Malcolm Priestley65df77e2014-07-20 15:33:11 +0100989 if (priv->bb_type == BB_TYPE_11A) {
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100990 current_rate = RATE_6M;
991
992 /* Get SignalField,ServiceField,Length */
993 vnt_get_phy_field(priv, frame_size, current_rate,
994 PK_TYPE_11A, &short_head->ab);
995
996 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +0100997 short_head->duration = vnt_get_duration_le(priv,
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100998 PK_TYPE_11A, false);
999 short_head->time_stamp_off =
1000 vnt_time_stamp_off(priv, current_rate);
1001 } else {
1002 current_rate = RATE_1M;
1003 short_head->fifo_ctl |= FIFOCTL_11B;
1004
1005 /* Get SignalField,ServiceField,Length */
1006 vnt_get_phy_field(priv, frame_size, current_rate,
1007 PK_TYPE_11B, &short_head->ab);
1008
1009 /* Get Duration and TimeStampOff */
Malcolm Priestley435ae3b2014-07-11 01:08:22 +01001010 short_head->duration = vnt_get_duration_le(priv,
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001011 PK_TYPE_11B, false);
1012 short_head->time_stamp_off =
1013 vnt_time_stamp_off(priv, current_rate);
1014 }
1015
1016 /* Generate Beacon Header */
1017 mgmt_hdr = &beacon_buffer->mgmt_hdr;
1018 memcpy(mgmt_hdr, skb->data, skb->len);
1019
1020 /* time stamp always 0 */
1021 mgmt_hdr->u.beacon.timestamp = 0;
1022
1023 info = IEEE80211_SKB_CB(skb);
1024 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1025 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
1026 hdr->duration_id = 0;
Malcolm Priestley1b2bc0a2014-07-20 15:33:23 +01001027 hdr->seq_ctrl = cpu_to_le16(priv->seq_counter << 4);
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001028 }
1029
Malcolm Priestley1b2bc0a2014-07-20 15:33:23 +01001030 priv->seq_counter++;
1031 if (priv->seq_counter > 0x0fff)
1032 priv->seq_counter = 0;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001033
1034 count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
1035
1036 beacon_buffer->tx_byte_count = cpu_to_le16(count);
Malcolm Priestley71d764a2014-07-05 19:24:27 +01001037 beacon_buffer->byPKTNO = context->pkt_no;
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001038 beacon_buffer->byType = 0x01;
1039
1040 context->type = CONTEXT_BEACON_PACKET;
1041 context->buf_len = count + 4; /* USB header */
1042
1043 spin_lock_irqsave(&priv->lock, flags);
1044
Malcolm Priestley476e7d92014-07-15 19:54:39 +01001045 if (vnt_tx_context(priv, context) != STATUS_PENDING)
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01001046 ieee80211_free_txskb(priv->hw, context->skb);
1047
1048 spin_unlock_irqrestore(&priv->lock, flags);
1049
1050 return 0;
1051}
1052
1053int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1054{
1055 struct sk_buff *beacon;
1056
1057 beacon = ieee80211_beacon_get(priv->hw, vif);
1058 if (!beacon)
1059 return -ENOMEM;
1060
1061 if (vnt_beacon_xmit(priv, beacon)) {
1062 ieee80211_free_txskb(priv->hw, beacon);
1063 return -ENODEV;
1064 }
1065
1066 return 0;
1067}
1068
1069int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1070 struct ieee80211_bss_conf *conf)
1071{
1072 int ret;
1073
1074 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1075
1076 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1077
1078 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
1079
1080 vnt_clear_current_tsf(priv);
1081
1082 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1083
1084 vnt_reset_next_tbtt(priv, conf->beacon_int);
1085
1086 ret = vnt_beacon_make(priv, vif);
1087
1088 return ret;
1089}