blob: c3d47789c2afe23cac0748b26bc2f795113ae140 [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:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020034 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040035 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020038 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040039 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
44 *
45 * Revision History:
46 *
47 */
48
Forest Bond92b96792009-06-13 07:38:31 -040049#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "tether.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070062
Mariano Reingart4a499de2010-10-29 19:15:26 -030063static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040064
Valentina Manea3b138852013-11-04 10:44:02 +020065static const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040066 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
67 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
68 };
69
Valentina Manea3b138852013-11-04 10:44:02 +020070static const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040071 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
72 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
73 };
Valentina Manea3b138852013-11-04 10:44:02 +020074static const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040075 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
76 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
77 };
78
Forest Bond92b96792009-06-13 07:38:31 -040079#define RTSDUR_BB 0
80#define RTSDUR_BA 1
81#define RTSDUR_AA 2
82#define CTSDUR_BA 3
83#define RTSDUR_BA_F0 4
84#define RTSDUR_AA_F0 5
85#define RTSDUR_BA_F1 6
86#define RTSDUR_AA_F1 7
87#define CTSDUR_BA_F0 8
88#define CTSDUR_BA_F1 9
89#define DATADUR_B 10
90#define DATADUR_A 11
91#define DATADUR_A_F0 12
92#define DATADUR_A_F1 13
93
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000094static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
95 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040096
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +000097static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000098
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +010099static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100100 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100101 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
Malcolm Priestley05cc6172014-04-30 21:31:12 +0100102 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000103
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000104static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100105 struct ieee80211_hdr *pMACHeader, u16 wDuration,
106 struct ethhdr *psEthHeader, int bNeedEncrypt, u16 wFragType,
107 u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400108
Malcolm Priestley3695c462014-05-31 13:34:59 +0100109static void s_vFillTxKey(struct vnt_usb_send_context *tx_context,
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100110 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
Malcolm Priestley3695c462014-05-31 13:34:59 +0100111 PSKeyItem pTransmitKey, u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400112
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000113static void s_vSWencryption(struct vnt_private *pDevice,
114 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400115
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000116static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
117 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400118
Malcolm Priestley20338012014-03-18 19:25:08 +0000119static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100120 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400121
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100122static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100123 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
124 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400125
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100126static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100127 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500128 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400129
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000130static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100131 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400132
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000133static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000134 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
135 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400136
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000137static struct vnt_usb_send_context
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000138 *s_vGetFreeContext(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400139{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000140 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000141 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400142
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000143 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400144
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000145 for (ii = 0; ii < priv->cbTD; ii++) {
146 if (!priv->apTD[ii])
147 return NULL;
148
149 context = priv->apTD[ii];
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100150 if (context->in_use == false) {
151 context->in_use = true;
152 memset(context->data, 0,
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000153 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100154
155 context->hdr = NULL;
156
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000157 return context;
158 }
159 }
160
161 if (ii == priv->cbTD)
162 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000163
Malcolm Priestley5c851382013-11-26 19:12:38 +0000164 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400165}
166
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000167static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
168 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400169{
Malcolm Priestleyae27b142013-12-09 22:23:19 +0000170 struct net_device_stats *stats = &pDevice->stats;
Malcolm Priestley51934e72013-12-09 22:30:14 +0000171 struct vnt_tx_pkt_info *pkt_info = pDevice->pkt_info;
Forest Bond92b96792009-06-13 07:38:31 -0400172
Malcolm Priestley51934e72013-12-09 22:30:14 +0000173 pkt_info[byPktNum].fifo_ctl = wFIFOCtl;
174 memcpy(pkt_info[byPktNum].dest_addr, pbyDestAddr, ETH_ALEN);
Malcolm Priestleyae27b142013-12-09 22:23:19 +0000175
176 stats->tx_bytes += wPktLength;
Forest Bond92b96792009-06-13 07:38:31 -0400177}
178
Malcolm Priestley3695c462014-05-31 13:34:59 +0100179static void s_vFillTxKey(struct vnt_usb_send_context *tx_context,
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100180 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
Malcolm Priestley3695c462014-05-31 13:34:59 +0100181 PSKeyItem pTransmitKey, u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400182{
Malcolm Priestley3695c462014-05-31 13:34:59 +0100183 struct vnt_private *pDevice = tx_context->priv;
184 struct ieee80211_hdr *pMACHeader = tx_context->hdr;
Malcolm Priestleyab51f512014-05-31 13:35:00 +0100185 u8 *pbyBuf = fifo_head->tx_key;
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000186 __le32 *pdwIV = (__le32 *)pbyIVHead;
Malcolm Priestley2fbb2302014-03-22 09:01:25 +0000187 __le32 *pdwExtIV = (__le32 *)((u8 *)pbyIVHead + 4);
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000188 __le32 rev_iv_counter;
Forest Bond92b96792009-06-13 07:38:31 -0400189
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100190 /* Fill TXKEY */
191 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100192 return;
Forest Bond92b96792009-06-13 07:38:31 -0400193
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000194 rev_iv_counter = cpu_to_le32(pDevice->dwIVCounter);
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000195 *pdwIV = cpu_to_le32(pDevice->dwIVCounter);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100196 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400197
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100198 switch (pTransmitKey->byCipherSuite) {
199 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100200 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000201 memcpy(pDevice->abyPRNG, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100202 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
203 pTransmitKey->uKeyLength);
204 } else {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000205 memcpy(pbyBuf, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100206 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
207 pTransmitKey->uKeyLength);
208 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000209 memcpy(pbyBuf+8, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley5cb5bff72014-05-25 21:36:28 +0100210 memcpy(pbyBuf+11, pTransmitKey->abyKey,
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100211 pTransmitKey->uKeyLength);
212 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100213
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100214 memcpy(pDevice->abyPRNG, pbyBuf, 16);
215 }
216 /* Append IV after Mac Header */
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000217 *pdwIV &= cpu_to_le32(WEP_IV_MASK);
218 *pdwIV |= cpu_to_le32((u32)pDevice->byKeyIndex << 30);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100219
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100220 pDevice->dwIVCounter++;
221 if (pDevice->dwIVCounter > WEP_IV_MASK)
222 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100223
224 break;
225 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100226 pTransmitKey->wTSC15_0++;
227 if (pTransmitKey->wTSC15_0 == 0)
228 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100229
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100230 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
231 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
232 pDevice->abyPRNG);
233 memcpy(pbyBuf, pDevice->abyPRNG, 16);
234
235 /* Make IV */
236 memcpy(pdwIV, pDevice->abyPRNG, 3);
237
238 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
239 0xc0) | 0x20);
240 /* Append IV&ExtIV after Mac Header */
241 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
242
243 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
244 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
245
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100246 break;
247 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100248 pTransmitKey->wTSC15_0++;
249 if (pTransmitKey->wTSC15_0 == 0)
250 pTransmitKey->dwTSC47_16++;
251
252 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
253
254 /* Make IV */
255 *pdwIV = 0;
256 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
257 0xc0) | 0x20);
258
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000259 *pdwIV |= cpu_to_le32((u32)(pTransmitKey->wTSC15_0));
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100260
261 /* Append IV&ExtIV after Mac Header */
262 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
263
264 if (!mic_hdr)
265 return;
266
267 /* MICHDR0 */
268 mic_hdr->id = 0x59;
269 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
270 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
271
272 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
273 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
274
275 /* MICHDR1 */
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000276 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100277 mic_hdr->hlen = cpu_to_be16(28);
278 else
279 mic_hdr->hlen = cpu_to_be16(22);
280
281 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
282 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
283
284 /* MICHDR2 */
285 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
Malcolm Priestley5d4fe752014-03-22 09:01:26 +0000286 mic_hdr->frame_control = cpu_to_le16(
287 le16_to_cpu(pMACHeader->frame_control) & 0xc78f);
288 mic_hdr->seq_ctrl = cpu_to_le16(
289 le16_to_cpu(pMACHeader->seq_ctrl) & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100290
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000291 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100292 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
293 }
Forest Bond92b96792009-06-13 07:38:31 -0400294}
295
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000296static void s_vSWencryption(struct vnt_private *pDevice,
297 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400298{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000299 u32 cbICVlen = 4;
300 u32 dwICV = 0xffffffff;
301 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400302
303 if (pTransmitKey == NULL)
304 return;
305
306 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
307 //=======================================================================
308 // Append ICV after payload
Malcolm Priestley929cb312014-05-21 21:09:42 +0100309 dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead);
Andres More52a7e642013-02-25 20:32:53 -0500310 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400311 // finally, we must invert dwCRC to get the correct answer
312 *pdwICV = cpu_to_le32(~dwICV);
313 // RC4 encryption
314 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
315 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
316 //=======================================================================
317 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
318 //=======================================================================
319 //Append ICV after payload
Malcolm Priestley929cb312014-05-21 21:09:42 +0100320 dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead);
Andres More52a7e642013-02-25 20:32:53 -0500321 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400322 // finally, we must invert dwCRC to get the correct answer
323 *pdwICV = cpu_to_le32(~dwICV);
324 // RC4 encryption
325 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
326 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
327 //=======================================================================
328 }
329}
330
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000331static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100332{
333 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
334 [rate % MAX_RATE]);
335}
336
Forest Bond92b96792009-06-13 07:38:31 -0400337/*byPktType : PK_TYPE_11A 0
338 PK_TYPE_11B 1
339 PK_TYPE_11GB 2
340 PK_TYPE_11GA 3
341*/
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000342static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
343 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400344{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000345 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400346
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100347 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000348 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400349
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000350 if (pkt_type == PK_TYPE_11B)
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100351 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
352 14, (u16)priv->byTopCCKBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000353 else
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100354 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
355 14, (u16)priv->byTopOFDMBasicRate);
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000356
357 if (need_ack)
358 return data_time + priv->uSIFS + ack_time;
359
360 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400361}
362
Malcolm Priestley2075f652014-03-18 19:25:07 +0000363static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100364 u32 frame_length, u16 rate, int need_ack)
365{
366 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
367 frame_length, rate, need_ack));
368}
369
Forest Bond92b96792009-06-13 07:38:31 -0400370//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley20338012014-03-18 19:25:08 +0000371static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100372 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400373{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000374 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400375
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000376 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400377
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100378 data_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100379 frame_length, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400380
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000381 if (rsv_type == 0) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100382 rts_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000383 pkt_type, 20, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100384 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000385 pkt_type, 14, priv->byTopCCKBasicRate);
386 } else if (rsv_type == 1) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100387 rts_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000388 pkt_type, 20, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100389 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000390 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100391 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000392 14, priv->byTopOFDMBasicRate);
393 } else if (rsv_type == 2) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100394 rts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000395 20, priv->byTopOFDMBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100396 cts_time = ack_time = vnt_get_frame_time(priv->byPreambleType,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000397 pkt_type, 14, priv->byTopOFDMBasicRate);
398 } else if (rsv_type == 3) {
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100399 cts_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000400 14, priv->byTopCCKBasicRate);
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100401 ack_time = vnt_get_frame_time(priv->byPreambleType, pkt_type,
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000402 14, priv->byTopOFDMBasicRate);
403
404 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
405
Malcolm Priestley20338012014-03-18 19:25:08 +0000406 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000407 }
408
409 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
410
411 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400412}
413
414//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000415static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100416 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400417{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100418 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400419
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100420 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100421 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100422 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100423 byPktType, 14, pDevice->byTopCCKBasicRate);
424 else
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100425 uAckTime = vnt_get_frame_time(pDevice->byPreambleType,
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100426 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100427 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100428 }
Forest Bond92b96792009-06-13 07:38:31 -0400429
Forest Bond92b96792009-06-13 07:38:31 -0400430 return 0;
431}
432
Forest Bond92b96792009-06-13 07:38:31 -0400433//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000434static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000435 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
436 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400437{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000438 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400439
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100440 switch (byDurType) {
441 case RTSDUR_BB:
442 case RTSDUR_BA:
443 case RTSDUR_BA_F0:
444 case RTSDUR_BA_F1:
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100445 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
446 byPktType, 14, pDevice->byTopCCKBasicRate);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100447 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
448 s_uGetTxRsvTime(pDevice, byPktType,
449 cbFrameLength, wRate, bNeedAck);
450 break;
Forest Bond92b96792009-06-13 07:38:31 -0400451
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100452 case RTSDUR_AA:
453 case RTSDUR_AA_F0:
454 case RTSDUR_AA_F1:
Malcolm Priestleyd38ee5b2014-06-04 18:25:35 +0100455 uCTSTime = vnt_get_frame_time(pDevice->byPreambleType,
456 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100457 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
458 s_uGetTxRsvTime(pDevice, byPktType,
459 cbFrameLength, wRate, bNeedAck);
460 break;
Forest Bond92b96792009-06-13 07:38:31 -0400461
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100462 case CTSDUR_BA:
463 case CTSDUR_BA_F0:
464 case CTSDUR_BA_F1:
465 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100466 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100467 break;
Forest Bond92b96792009-06-13 07:38:31 -0400468
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100469 default:
470 break;
471 }
Forest Bond92b96792009-06-13 07:38:31 -0400472
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100473 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400474}
475
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100476static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
477 struct ieee80211_hdr *hdr)
478{
479 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
480 u8 *hdr_pos = (u8 *)hdr;
481
482 tx_context->hdr = hdr;
483 if (!tx_context->hdr)
484 return 0;
485
486 return (u16)(hdr_pos - head);
487}
488
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100489static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
490 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf,
491 u32 frame_len, int need_ack)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100492{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100493
494 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100495 struct ieee80211_hdr *hdr =
496 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100497
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100498 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100499 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
500 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100501 PK_TYPE_11B, &buf->b);
502
503 /* Get Duration and TimeStamp */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100504 if (ieee80211_is_pspoll(hdr->frame_control)) {
505 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
506
507 buf->duration_a = dur;
508 buf->duration_b = dur;
509 } else {
510 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
511 buf->duration_b = s_uGetDataDuration(priv,
512 PK_TYPE_11B, need_ack);
513 }
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100514
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000515 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
516 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100517 priv->byTopCCKBasicRate);
518
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100519 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
520
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000521 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100522}
523
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100524static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
525 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100526 u32 frame_len, int need_ack)
527{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100528 struct vnt_private *priv = tx_context->priv;
529
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100530 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100531 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100532
Malcolm Priestley205056f2014-06-04 18:25:34 +0100533 vnt_get_phy_field(priv, frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100534 PK_TYPE_11B, &buf->b);
535
536 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000537 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
538 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100539
Malcolm Priestley4e011172014-03-18 19:24:55 +0000540 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
541 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100542
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000543 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
544 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100545 priv->byTopCCKBasicRate);
546
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100547 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
548
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000549 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100550}
551
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100552static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
553 u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100554 u32 frame_len, int need_ack)
555{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100556 struct vnt_private *priv = tx_context->priv;
557
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100558 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100559 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100560 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000561 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100562
Malcolm Priestley4e011172014-03-18 19:24:55 +0000563 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
564 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100565
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000566 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100567
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100568 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
569
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000570 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100571}
572
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100573static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
574 u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100575 u32 frame_len, int need_ack)
576{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100577 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley893cc702014-06-25 21:14:38 +0100578 struct ieee80211_hdr *hdr =
579 (struct ieee80211_hdr *)tx_context->skb->data;
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100580
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100581 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100582 vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->ab);
Malcolm Priestley893cc702014-06-25 21:14:38 +0100583
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100584 /* Get Duration and TimeStampOff */
Malcolm Priestley893cc702014-06-25 21:14:38 +0100585 if (ieee80211_is_pspoll(hdr->frame_control)) {
586 __le16 dur = cpu_to_le16(priv->current_aid | BIT(14) | BIT(15));
587
588 buf->duration = dur;
589 } else {
590 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
591 }
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100592
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000593 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100594
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100595 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
596
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000597 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100598}
599
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100600static int vnt_fill_ieee80211_rts(struct vnt_usb_send_context *tx_context,
601 struct ieee80211_rts *rts, __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100602{
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100603 struct ieee80211_hdr *hdr =
604 (struct ieee80211_hdr *)tx_context->skb->data;
605
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100606 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000607 rts->frame_control =
608 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100609
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100610 memcpy(rts->ra, hdr->addr1, ETH_ALEN);
611 memcpy(rts->ta, hdr->addr2, ETH_ALEN);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100612
613 return 0;
614}
615
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100616static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100617 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
618 u8 pkt_type, u32 frame_len, int need_ack,
619 u16 current_rate, u8 fb_option)
620{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100621 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100622 u16 rts_frame_len = 20;
623
Malcolm Priestley205056f2014-06-04 18:25:34 +0100624 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100625 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100626 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100627 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
628
Malcolm Priestley4e011172014-03-18 19:24:55 +0000629 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100630 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000631 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100632 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000633 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100634 pkt_type, current_rate, need_ack, fb_option);
635
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100636 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100637
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100638 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100639 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100640}
641
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100642static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100643 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
644 u8 pkt_type, u32 frame_len, int need_ack,
645 u16 current_rate, u8 fb_option)
646{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100647 struct vnt_private *priv = tx_context->priv;
Malcolm Priestleyec917132013-08-26 11:07:46 +0100648 u16 rts_frame_len = 20;
649
Malcolm Priestley205056f2014-06-04 18:25:34 +0100650 vnt_get_phy_field(priv, rts_frame_len, priv->byTopCCKBasicRate,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100651 PK_TYPE_11B, &buf->b);
Malcolm Priestley205056f2014-06-04 18:25:34 +0100652 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100653 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
654
655
Malcolm Priestley4e011172014-03-18 19:24:55 +0000656 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100657 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000658 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100659 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000660 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100661 pkt_type, current_rate, need_ack, fb_option);
662
663
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000664 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100665 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000666 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100667 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000668 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100669 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000670 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100671 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100672
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100673 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100674
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100675 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100676 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100677}
678
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100679static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley17126332013-08-26 11:09:38 +0100680 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
681 u8 pkt_type, u32 frame_len, int need_ack,
682 u16 current_rate, u8 fb_option)
683{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100684 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley17126332013-08-26 11:09:38 +0100685 u16 rts_frame_len = 20;
686
Malcolm Priestley205056f2014-06-04 18:25:34 +0100687 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100688 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
689
Malcolm Priestley4e011172014-03-18 19:24:55 +0000690 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100691 pkt_type, current_rate, need_ack, fb_option);
692
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100693 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100694
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100695 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100696 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100697}
698
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100699static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100700 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
701 u8 pkt_type, u32 frame_len, int need_ack,
702 u16 current_rate, u8 fb_option)
703{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100704 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100705 u16 rts_frame_len = 20;
706
Malcolm Priestley205056f2014-06-04 18:25:34 +0100707 vnt_get_phy_field(priv, rts_frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100708 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
709
Malcolm Priestley4e011172014-03-18 19:24:55 +0000710 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100711 pkt_type, current_rate, need_ack, fb_option);
712
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000713 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100714 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100715
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000716 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100717 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100718
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +0100719 vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100720
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100721 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100722 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100723}
724
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100725static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100726 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500727 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400728{
Forest Bond92b96792009-06-13 07:38:31 -0400729
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100730 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100731 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400732
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100733 /* Note: So far RTSHead doesn't appear in ATIM
734 * & Beacom DMA, so we don't need to take them
735 * into account.
736 * Otherwise, we need to modified codes for them.
737 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100738 switch (byPktType) {
739 case PK_TYPE_11GB:
740 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100741 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100742 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100743 psEthHeader, byPktType, cbFrameLength,
744 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100745 else
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100746 return vnt_rxtx_rts_g_fb_head(tx_context,
747 &head->rts_g_fb, psEthHeader, byPktType,
748 cbFrameLength, bNeedAck, wCurrentRate,
749 byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100750 break;
751 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100752 if (byFBOption) {
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100753 return vnt_rxtx_rts_a_fb_head(tx_context,
754 &head->rts_a_fb, psEthHeader, byPktType,
755 cbFrameLength, bNeedAck, wCurrentRate,
756 byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100757 break;
758 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100759 case PK_TYPE_11B:
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100760 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100761 psEthHeader, byPktType, cbFrameLength,
762 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100763 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100764
765 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400766}
767
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100768static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100769 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
770 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400771{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100772 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000773 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400774
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100775 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100776 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400777
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100778 if (byFBOption != AUTO_FB_NONE) {
779 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100780 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100781 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100782 vnt_get_phy_field(pDevice, uCTSFrameLen,
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100783 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000784 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100785 cbFrameLength, byPktType,
786 wCurrentRate, bNeedAck, byFBOption);
787 /* Get CTSDuration_ba_f0 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000788 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100789 CTSDUR_BA_F0, cbFrameLength, byPktType,
790 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100791 /* Get CTSDuration_ba_f1 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000792 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100793 CTSDUR_BA_F1, cbFrameLength, byPktType,
794 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100795 /* Get CTS Frame body */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000796 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000797 pBuf->data.frame_control =
798 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
799
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100800 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100801
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100802 return vnt_rxtx_datahead_g_fb(tx_context, byPktType,
803 wCurrentRate, &pBuf->data_head, cbFrameLength,
804 bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100805 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100806 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100807 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +0100808 vnt_get_phy_field(pDevice, uCTSFrameLen,
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100809 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100810 /* Get CTSDuration_ba */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000811 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100812 CTSDUR_BA, cbFrameLength, byPktType,
813 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100814 /*Get CTS Frame body*/
Malcolm Priestley4e011172014-03-18 19:24:55 +0000815 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000816 pBuf->data.frame_control =
817 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
818
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100819 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100820
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100821 return vnt_rxtx_datahead_g(tx_context, byPktType, wCurrentRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100822 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400823 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100824
825 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400826}
827
Forest Bond92b96792009-06-13 07:38:31 -0400828/*+
829 *
830 * Description:
831 * Generate FIFO control for MAC & Baseband controller
832 *
833 * Parameters:
834 * In:
835 * pDevice - Pointer to adpater
836 * pTxDataHead - Transmit Data Buffer
837 * pTxBufHead - pTxBufHead
838 * pvRrvTime - pvRrvTime
839 * pvRTS - RTS Buffer
840 * pCTS - CTS Buffer
841 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
842 * bNeedACK - If need ACK
Forest Bond92b96792009-06-13 07:38:31 -0400843 * Out:
844 * none
845 *
846 * Return Value: none
847 *
848-*/
Andres Morecc856e62010-05-17 21:34:01 -0300849
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100850static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100851 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100852 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
Malcolm Priestley05cc6172014-04-30 21:31:12 +0100853 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400854{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100855 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100856 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100857 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000858 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000859 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400860
Malcolm Priestley03a9cf32014-03-22 09:01:30 +0000861 pFifoHead->current_rate = cpu_to_le16(wCurrentRate);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100862 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400863
Malcolm Priestley92928f12013-10-07 20:14:01 +0100864 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
865 byFBOption = AUTO_FB_0;
866 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
867 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400868
Malcolm Priestley92928f12013-10-07 20:14:01 +0100869 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
870 if (need_rts) {
871 struct vnt_rrv_time_rts *pBuf =
872 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100873
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000874 pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100875 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000876 pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100877 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000878 pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100879 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100880
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000881 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100882 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000883 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100884 PK_TYPE_11B, cbFrameSize,
885 pDevice->byTopCCKBasicRate, bNeedACK);
886
887 if (need_mic) {
888 *mic_hdr = &tx_buffer->
889 tx_head.tx_rts.tx.mic.hdr;
890 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
891 } else {
892 head = &tx_buffer->tx_head.tx_rts.tx.head;
893 }
894
895 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100896 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100897 cbFrameSize, bNeedACK, psEthHeader,
898 wCurrentRate, byFBOption);
899
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100900 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100901 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
902 tx_head.tx_cts.cts;
903
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000904 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100905 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000906 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100907 PK_TYPE_11B, cbFrameSize,
908 pDevice->byTopCCKBasicRate, bNeedACK);
909
Malcolm Priestley372108e2014-03-18 19:25:00 +0000910 pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100911 byPktType, cbFrameSize, wCurrentRate);
912
913 if (need_mic) {
914 *mic_hdr = &tx_buffer->
915 tx_head.tx_cts.tx.mic.hdr;
916 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
917 } else {
918 head = &tx_buffer->tx_head.tx_cts.tx.head;
919 }
920
921 /* Fill CTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100922 return s_vFillCTSHead(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100923 head, cbFrameSize, bNeedACK, wCurrentRate,
924 byFBOption);
925 }
926 } else if (byPktType == PK_TYPE_11A) {
927 if (need_mic) {
928 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
929 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
930 } else {
931 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100932 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100933
Malcolm Priestley92928f12013-10-07 20:14:01 +0100934 if (need_rts) {
935 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
936 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100937
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000938 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100939 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100940
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000941 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100942 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
943
944 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100945 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100946 cbFrameSize, bNeedACK, psEthHeader,
947 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100948 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100949 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
950 tx_head.tx_ab.ab;
951
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000952 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100953 PK_TYPE_11A, cbFrameSize,
954 wCurrentRate, bNeedACK);
955
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100956 return vnt_rxtx_datahead_a_fb(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100957 wCurrentRate, &head->data_head_a_fb,
958 cbFrameSize, bNeedACK);
959 }
960 } else if (byPktType == PK_TYPE_11B) {
961 if (need_mic) {
962 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
963 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
964 } else {
965 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100966 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100967
Malcolm Priestley92928f12013-10-07 20:14:01 +0100968 if (need_rts) {
969 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
970 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100971
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000972 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100973 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100974
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000975 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100976 PK_TYPE_11B, cbFrameSize, wCurrentRate,
977 bNeedACK);
978
979 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100980 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100981 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100982 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100983 } else {
984 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
985 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100986
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000987 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100988 PK_TYPE_11B, cbFrameSize,
989 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100990
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100991 return vnt_rxtx_datahead_ab(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100992 wCurrentRate, &head->data_head_ab,
993 cbFrameSize, bNeedACK);
994 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100995 }
996
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100997 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400998}
999/*
Andres Moreb902fbf2013-02-25 20:32:51 -05001000 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -05001001 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -03001002 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -04001003*/
1004
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +01001005static int s_bPacketToWirelessUsb(struct vnt_usb_send_context *tx_context,
1006 u8 byPktType, struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001007 u32 uSkbPacketLen, struct ethhdr *psEthHeader,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01001008 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
1009 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -04001010{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +01001011 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001012 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001013 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001014 u32 cb802_1_H_len;
1015 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
1016 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001017 int bNeedACK;
1018 bool bRTS = false;
Malcolm Priestley1622c8f2014-05-31 13:34:58 +01001019 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001020 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1021 u8 abySNAP_Bridgetunnel[ETH_ALEN]
1022 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1023 u32 uDuration;
1024 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001025 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001026 u8 byFBOption = AUTO_FB_NONE, byFragType;
Malcolm Priestley4235f722013-08-24 12:42:01 +01001027 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001028 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001029 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001030
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001031 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001032
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001033 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001034 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1035 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001036 }
Forest Bond92b96792009-06-13 07:38:31 -04001037
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001038 /* Get pkt type */
1039 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
1040 cb802_1_H_len = 8;
1041 else
1042 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001043
Charles Clément21ec51f2010-05-18 10:08:14 -07001044 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001045
1046 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001047 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001048
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001049 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC ||
1050 pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001051 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001052 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001053 pTxBufHead->wFIFOCtl =
1054 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1055 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001056 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001057 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1058 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001059 } else {
1060 /* MSDUs in Infra mode always need ACK */
1061 bNeedACK = true;
1062 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1063 }
Forest Bond92b96792009-06-13 07:38:31 -04001064
Malcolm Priestley58462512014-03-22 09:01:27 +00001065 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001066
Forest Bond92b96792009-06-13 07:38:31 -04001067 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001068 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1069
Andres More3eaca0d2013-02-25 20:32:52 -05001070 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001071
1072 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001073 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001074 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1075 }
1076
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001077 /* Set Auto Fallback Ctl */
1078 if (wCurrentRate >= RATE_18M) {
1079 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1080 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1081
1082 pDevice->tx_rate_fb0 =
1083 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1084 pDevice->tx_rate_fb1 =
1085 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1086
1087 byFBOption = AUTO_FB_0;
1088 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1089 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1090 pDevice->tx_rate_fb0 =
1091 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1092 pDevice->tx_rate_fb1 =
1093 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1094
1095 byFBOption = AUTO_FB_1;
1096 }
1097 }
Forest Bond92b96792009-06-13 07:38:31 -04001098
Andres More4e9b5e22013-02-12 20:36:30 -05001099 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001100 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1101 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1102 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1103 }
1104 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1105 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1106 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1107 }
1108 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1109 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1110 }
1111 }
1112 }
1113
Forest Bond92b96792009-06-13 07:38:31 -04001114 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1115 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1116 cbIVlen = 4;
1117 cbICVlen = 4;
1118 }
1119 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1120 cbIVlen = 8;//IV+ExtIV
1121 cbMIClen = 8;
1122 cbICVlen = 4;
1123 }
1124 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1125 cbIVlen = 8;//RSN Header
1126 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001127 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001128 }
Andres Moree269fc22013-02-12 20:36:29 -05001129 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001130 //MAC Header should be padding 0 to DW alignment.
1131 uPadding = 4 - (cbMACHdLen%4);
1132 uPadding %= 4;
1133 }
1134 }
1135
1136 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1137
Andres Moree269fc22013-02-12 20:36:29 -05001138 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1139 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001140 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001141 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001142 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1143 }
1144
Forest Bond92b96792009-06-13 07:38:31 -04001145 //=========================
1146 // No Fragmentation
1147 //=========================
1148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1149 byFragType = FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001150 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1151
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001152 /* Fill FIFO, RrvTime, RTS and CTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +01001153 uDuration = s_vGenerateTxParameter(tx_context, byPktType, wCurrentRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001154 tx_buffer, &pMICHDR, cbMICHDR,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001155 cbFrameSize, bNeedACK, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001156
Malcolm Priestley1622c8f2014-05-31 13:34:58 +01001157 cbHeaderLength = tx_context->tx_hdr_size;
1158 if (!cbHeaderLength)
1159 return false;
1160
1161 pbyMacHdr = (u8 *)tx_context->hdr;
1162 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1163 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1164
1165 /* Generate TX MAC Header */
1166 s_vGenerateMACHeader(pDevice, tx_context->hdr, (u16)uDuration,
1167 psEthHeader, bNeedEncryption, byFragType, 0);
Forest Bond92b96792009-06-13 07:38:31 -04001168
Andres More4e9b5e22013-02-12 20:36:30 -05001169 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001170 //Fill TXKEY
Malcolm Priestley3695c462014-05-31 13:34:59 +01001171 s_vFillTxKey(tx_context, pTxBufHead, pbyIVHead, pTransmitKey,
1172 (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001173 }
1174
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001175 /* 802.1H */
1176 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001177 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001178 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001179 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001180 abySNAP_Bridgetunnel, 6);
1181 else
1182 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001183
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001184 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001185
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001186 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1187 }
Forest Bond92b96792009-06-13 07:38:31 -04001188
Forest Bond92b96792009-06-13 07:38:31 -04001189 if (pPacket != NULL) {
1190 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001191 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001192 (pPacket + ETH_HLEN),
1193 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001194 );
1195
1196 } else {
1197 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001198 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001199 }
1200
Andres More4e9b5e22013-02-12 20:36:30 -05001201 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001202
1203 ///////////////////////////////////////////////////////////////////
1204
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001205 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1206 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1207 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1208 }
Forest Bond92b96792009-06-13 07:38:31 -04001209 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001210 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1211 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001212 }
1213 else {
Andres More52a7e642013-02-25 20:32:53 -05001214 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1215 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001216 }
1217 // DO Software Michael
1218 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001219 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001220 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001221 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001222 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1223 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001224
1225 ///////////////////////////////////////////////////////////////////
1226
1227 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1228 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001229 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001230 //}
1231 //DBG_PRN_GRP12(("\n\n\n"));
1232
1233 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1234
Andres More52a7e642013-02-25 20:32:53 -05001235 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1236 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001237
1238 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1239 MIC_vUnInit();
1240
Andres More4e9b5e22013-02-12 20:36:30 -05001241 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001242 *pdwMIC_L = 0;
1243 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001244 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001245 }
1246 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1247 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1248 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1249 }
1250
Andres More4e9b5e22013-02-12 20:36:30 -05001251 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001252
Andres More3eaca0d2013-02-25 20:32:52 -05001253 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001254
Andres More4e9b5e22013-02-12 20:36:30 -05001255 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1256 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1257 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001258 cbFrameSize -= cbICVlen;
1259 }
1260
Forest Bond92b96792009-06-13 07:38:31 -04001261 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001262
1263 *pcbHeaderLen = cbHeaderLength;
1264 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1265
Forest Bond92b96792009-06-13 07:38:31 -04001266 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001267 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001268
Andres More4e9b5e22013-02-12 20:36:30 -05001269 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001270
1271}
1272
Forest Bond92b96792009-06-13 07:38:31 -04001273/*+
1274 *
1275 * Description:
1276 * Translate 802.3 to 802.11 header
1277 *
1278 * Parameters:
1279 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001280 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001281 * dwTxBufferAddr - Transmit Buffer
1282 * pPacket - Packet from upper layer
1283 * cbPacketSize - Transmit Data Length
1284 * Out:
1285 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1286 * pcbAppendPayload - size of append payload for 802.1H translation
1287 *
1288 * Return Value: none
1289 *
1290-*/
1291
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001292static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Malcolm Priestley1622c8f2014-05-31 13:34:58 +01001293 struct ieee80211_hdr *pMACHeader, u16 wDuration,
1294 struct ethhdr *psEthHeader, int bNeedEncrypt, u16 wFragType,
1295 u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001296{
Forest Bond92b96792009-06-13 07:38:31 -04001297
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001298 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001299
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001300 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001301 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001302 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001303 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001304 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1305 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001306 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001307 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001308 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001309 } else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001310 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001311 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001312 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001313 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001314 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001315 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001316 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001317 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001318 &(pDevice->abyBSSID[0]),
1319 ETH_ALEN);
1320 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001321 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001322 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001323 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001324 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001325 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001326 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001327 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001328 &(pDevice->abyBSSID[0]),
1329 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001330 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001331 }
1332 }
1333
1334 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001335 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001336
Andres More1cac4a42013-03-18 20:33:50 -05001337 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001338
Andres More1cac4a42013-03-18 20:33:50 -05001339 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001340
1341 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001342 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001343
1344 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1345 pDevice->wSeqCounter++;
1346 if (pDevice->wSeqCounter > 0x0fff)
1347 pDevice->wSeqCounter = 0;
1348 }
1349
1350 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001351 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001352 }
1353}
1354
Forest Bond92b96792009-06-13 07:38:31 -04001355/*+
1356 *
1357 * Description:
1358 * Request instructs a MAC to transmit a 802.11 management packet through
1359 * the adapter onto the medium.
1360 *
1361 * Parameters:
1362 * In:
1363 * hDeviceContext - Pointer to the adapter
1364 * pPacket - A pointer to a descriptor for the packet to transmit
1365 * Out:
1366 * none
1367 *
Andres Moree269fc22013-02-12 20:36:29 -05001368 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001369 *
1370-*/
1371
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001372CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1373 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001374{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001375 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001376 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001377 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001378 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001379 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001380 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001381 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001382 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001383 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001384 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001385 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1386 u32 uPadding = 0;
1387 u16 wTxBufSize;
1388 u32 cbMacHdLen;
1389 u16 wCurrentRate = RATE_1M;
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001390 unsigned long flags;
1391
1392 if (pDevice->byBBType == BB_TYPE_11A) {
1393 wCurrentRate = RATE_6M;
1394 byPktType = PK_TYPE_11A;
1395 } else {
1396 wCurrentRate = RATE_1M;
1397 byPktType = PK_TYPE_11B;
1398 }
1399
1400 if (pMgmt->eScanState != WMAC_NO_SCANNING)
Malcolm Priestley4f5290e2014-05-27 21:05:21 +01001401 vnt_rf_setpower(pDevice, wCurrentRate, pDevice->byCurrentCh);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001402 else
Malcolm Priestley4f5290e2014-05-27 21:05:21 +01001403 vnt_rf_setpower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001404
1405 pDevice->wCurrentRate = wCurrentRate;
1406
1407 spin_lock_irqsave(&pDevice->lock, flags);
Forest Bond92b96792009-06-13 07:38:31 -04001408
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001409 pContext = s_vGetFreeContext(pDevice);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001410 if (!pContext) {
1411 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1412 "ManagementSend TX...NO CONTEXT!\n");
1413 spin_unlock_irqrestore(&pDevice->lock, flags);
1414 return CMD_STATUS_RESOURCES;
1415 }
Forest Bond92b96792009-06-13 07:38:31 -04001416
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001417 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001418 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001419 pTxBufHead = &pTX_Buffer->fifo_head;
Malcolm Priestleyab51f512014-05-31 13:35:00 +01001420 pbyTxBufferAddr = (u8 *)pTxBufHead;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001421 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001422
Forest Bond92b96792009-06-13 07:38:31 -04001423
Forest Bond92b96792009-06-13 07:38:31 -04001424 //Set packet type
1425 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1426 pTxBufHead->wFIFOCtl = 0;
1427 }
1428 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1429 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1430 }
1431 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1432 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1433 }
1434 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1435 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1436 }
1437
1438 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
Malcolm Priestley58462512014-03-22 09:01:27 +00001439 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001440
Andres More22040bb2010-08-02 20:21:44 -03001441 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001442 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001443 }
1444 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001445 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001446 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1447 };
1448
1449 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1450 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1451
1452 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1453 //Set Preamble type always long
1454 //pDevice->byPreambleType = PREAMBLE_LONG;
1455 // probe-response don't retry
1456 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001457 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001458 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1459 //}
1460 }
1461
1462 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1463
1464 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001465 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001466 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1467 } else {
1468 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1469 }
1470
1471 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001472 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001473
1474 // Notes:
1475 // Although spec says MMPDU can be fragmented; In most case,
1476 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001477
1478 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1479 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1480 cbIVlen = 4;
1481 cbICVlen = 4;
1482 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1483 }
1484 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1485 cbIVlen = 8;//IV+ExtIV
1486 cbMIClen = 8;
1487 cbICVlen = 4;
1488 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1489 //We need to get seed here for filling TxKey entry.
1490 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1491 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1492 }
1493 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1494 cbIVlen = 8;//RSN Header
1495 cbICVlen = 8;//MIC
1496 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001497 }
1498 //MAC Header should be padding 0 to DW alignment.
1499 uPadding = 4 - (cbMacHdLen%4);
1500 uPadding %= 4;
1501 }
1502
1503 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1504
1505 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001506 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001507 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1508 }
1509 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1510
Andres Moreceb8c5d2013-03-18 20:33:49 -05001511 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001512 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1513 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001514 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001515 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1516 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001517 //=========================
1518 // No Fragmentation
1519 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001520 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001521
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001522 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +01001523 uDuration = s_vGenerateTxParameter(pContext, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001524 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001525 cbFrameSize, bNeedACK, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001526
Malcolm Priestley1622c8f2014-05-31 13:34:58 +01001527 cbHeaderSize = pContext->tx_hdr_size;
1528 if (!cbHeaderSize) {
1529 pContext->in_use = false;
1530 return CMD_STATUS_RESOURCES;
1531 }
1532
1533 pMACHeader = pContext->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001534
1535 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1536
1537 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001538 u8 * pbyIVHead;
1539 u8 * pbyPayloadHead;
1540 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001541 PSKeyItem pTransmitKey = NULL;
1542
Andres Moreb902fbf2013-02-25 20:32:51 -05001543 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1544 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001545 do {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001546 if (pDevice->op_mode == NL80211_IFTYPE_STATION &&
1547 pDevice->bLinkPass == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001548 pbyBSSID = pDevice->abyBSSID;
1549 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001550 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001551 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001552 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001553 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1554 break;
1555 }
1556 } else {
1557 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1558 break;
1559 }
1560 }
1561 // get group key
1562 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001563 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001564 pTransmitKey = NULL;
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001565 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->op_mode);
Forest Bond92b96792009-06-13 07:38:31 -04001566 } else {
1567 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1568 }
Andres Moree269fc22013-02-12 20:36:29 -05001569 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001570 //Fill TXKEY
Malcolm Priestley3695c462014-05-31 13:34:59 +01001571 s_vFillTxKey(pContext, pTxBufHead, pbyIVHead, pTransmitKey,
1572 (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001573
Jim Lieb3e362592009-08-12 14:54:11 -07001574 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001575 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001576 cbFrameBodySize);
1577 }
1578 else {
1579 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001580 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001581 }
1582
Andres More1cac4a42013-03-18 20:33:50 -05001583 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001584 pDevice->wSeqCounter++ ;
1585 if (pDevice->wSeqCounter > 0x0fff)
1586 pDevice->wSeqCounter = 0;
1587
1588 if (bIsPSPOLL) {
1589 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001590 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001591 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1592 // in the same place of other packet's Duration-field).
1593 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001594 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001595 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1596 tx_cts.tx.head.cts_g.data_head;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001597 data_head->duration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001598 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley4e011172014-03-18 19:24:55 +00001599 data_head->duration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001600 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1601 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001602 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1603 tx_ab.tx.head.data_head_ab;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001604 data_head->duration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001605 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1606 }
Forest Bond92b96792009-06-13 07:38:31 -04001607 }
1608
Malcolm Priestleyca347592014-03-22 09:01:28 +00001609 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001610 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001611 pTX_Buffer->byType = 0x00;
1612
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001613 pContext->skb = NULL;
1614 pContext->type = CONTEXT_MGMT_PACKET;
1615 pContext->buf_len = (u16)cbReqCount + 4; /* USB header */
Forest Bond92b96792009-06-13 07:38:31 -04001616
Andres More1cac4a42013-03-18 20:33:50 -05001617 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001618 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1619 &pMACHeader->addr1[0], (u16)cbFrameSize,
1620 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001621 }
1622 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001623 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1624 &pMACHeader->addr3[0], (u16)cbFrameSize,
1625 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001626 }
1627
1628 PIPEnsSendBulkOut(pDevice,pContext);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001629
1630 spin_unlock_irqrestore(&pDevice->lock, flags);
1631
Forest Bond92b96792009-06-13 07:38:31 -04001632 return CMD_STATUS_PENDING;
1633}
1634
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001635CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1636 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001637{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001638 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001639 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001640 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1641 u32 cbHeaderSize = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001642 u16 wCurrentRate;
1643 u32 cbFrameBodySize;
1644 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001645 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001646 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001647
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001648 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001649 if (NULL == pContext) {
1650 status = CMD_STATUS_RESOURCES;
1651 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1652 return status ;
1653 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001654
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001655 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001656 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001657
1658 cbFrameBodySize = pPacket->cbPayloadLen;
1659
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001660 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001661
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001662 if (pDevice->byBBType == BB_TYPE_11A) {
1663 wCurrentRate = RATE_6M;
1664
1665 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +01001666 vnt_get_phy_field(pDevice, cbFrameSize, wCurrentRate,
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001667 PK_TYPE_11A, &short_head->ab);
1668
1669 /* Get Duration and TimeStampOff */
1670 short_head->duration = s_uGetDataDuration(pDevice,
1671 PK_TYPE_11A, false);
1672 short_head->time_stamp_off =
1673 vnt_time_stamp_off(pDevice, wCurrentRate);
1674 } else {
1675 wCurrentRate = RATE_1M;
1676 short_head->fifo_ctl |= FIFOCTL_11B;
1677
1678 /* Get SignalField,ServiceField,Length */
Malcolm Priestley205056f2014-06-04 18:25:34 +01001679 vnt_get_phy_field(pDevice, cbFrameSize, wCurrentRate,
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001680 PK_TYPE_11B, &short_head->ab);
1681
1682 /* Get Duration and TimeStampOff */
1683 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001684 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001685 short_head->time_stamp_off =
1686 vnt_time_stamp_off(pDevice, wCurrentRate);
1687 }
1688
Forest Bond92b96792009-06-13 07:38:31 -04001689
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001690 /* Generate Beacon Header */
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001691 pDevice->wSeqCounter++;
1692 if (pDevice->wSeqCounter > 0x0fff)
1693 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001694
1695 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1696
Malcolm Priestleyfad8e4a2014-03-22 09:01:29 +00001697 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)cbReqCount);
Andres Moreb902fbf2013-02-25 20:32:51 -05001698 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001699 pTX_Buffer->byType = 0x01;
1700
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001701 pContext->skb = NULL;
1702 pContext->type = CONTEXT_MGMT_PACKET;
1703 pContext->buf_len = (u16)cbReqCount + 4; /* USB header */
Forest Bond92b96792009-06-13 07:38:31 -04001704
1705 PIPEnsSendBulkOut(pDevice,pContext);
1706 return CMD_STATUS_PENDING;
1707
1708}
1709
Forest Bond92b96792009-06-13 07:38:31 -04001710//TYPE_AC0DMA data tx
1711/*
1712 * Description:
1713 * Tx packet via AC0DMA(DMA1)
1714 *
1715 * Parameters:
1716 * In:
1717 * pDevice - Pointer to the adapter
1718 * skb - Pointer to tx skb packet
1719 * Out:
1720 * void
1721 *
1722 * Return Value: NULL
1723 */
1724
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001725int nsDMA_tx_packet(struct vnt_private *pDevice, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04001726{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001727 struct net_device_stats *pStats = &pDevice->stats;
1728 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001729 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001730 u32 BytesToWrite = 0, uHeaderLen = 0;
1731 u32 uNodeIndex = 0;
1732 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1733 u16 wAID;
1734 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05001735 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001736 PSKeyItem pTransmitKey = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001737 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05001738 int bTKIP_UseGTK = false;
1739 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001740 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05001741 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001742 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05001743 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001744 u32 status;
1745 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05001746 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04001747
Forest Bond92b96792009-06-13 07:38:31 -04001748 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1749
1750 if (pDevice->uAssocCount == 0) {
1751 dev_kfree_skb_irq(skb);
1752 return 0;
1753 }
1754
Andres Moreb902fbf2013-02-25 20:32:51 -05001755 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04001756 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001757 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04001758 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1759
1760 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
1761 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1762 // set tx map
1763 pMgmt->abyPSTxMap[0] |= byMask[0];
1764 return 0;
1765 }
Masanari Iida93184692012-08-13 21:21:50 +09001766 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04001767
1768 if (pDevice->byBBType != BB_TYPE_11A)
1769 pDevice->wCurrentRate = RATE_2M;
1770 else
1771 pDevice->wCurrentRate = RATE_24M;
1772 // long preamble type
1773 pDevice->byPreambleType = PREAMBLE_SHORT;
1774
1775 }else {
1776
Andres Moreb902fbf2013-02-25 20:32:51 -05001777 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04001778
1779 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1780
1781 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1782
1783 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1784 // set tx map
1785 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1786 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1787 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
1788 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
1789
1790 return 0;
1791 }
1792 // AP rate decided from node
1793 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1794 // tx preamble decided from node
1795
1796 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
1797 pDevice->byPreambleType = pDevice->byShortPreamble;
1798
1799 }else {
1800 pDevice->byPreambleType = PREAMBLE_LONG;
1801 }
Andres More4e9b5e22013-02-12 20:36:30 -05001802 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04001803 }
1804 }
1805
Andres Moree269fc22013-02-12 20:36:29 -05001806 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001807 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
1808 dev_kfree_skb_irq(skb);
1809 return 0;
1810 }
1811 }
1812
Tobias Klauser838c2d62014-04-25 11:53:58 +02001813 memcpy(&pDevice->sTxEthHeader, skb->data, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001814
1815//mike add:station mode check eapol-key challenge--->
1816{
Andres Moreb902fbf2013-02-25 20:32:51 -05001817 u8 Protocol_Version; //802.1x Authentication
1818 u8 Packet_Type; //802.1x Authentication
1819 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05001820 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04001821
Charles Clément21ec51f2010-05-18 10:08:14 -07001822 Protocol_Version = skb->data[ETH_HLEN];
1823 Packet_Type = skb->data[ETH_HLEN+1];
1824 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
1825 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001826 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001827 /* 802.1x OR eapol-key challenge frame transfer */
1828 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
1829 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05001830 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04001831 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
1832 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
1833 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05001834 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04001835 PRINT_K("WPA ");
1836 }
1837 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001838 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04001839 PRINT_K("WPA2(re-keying) ");
1840 }
1841 PRINT_K("Authentication completed!!\n");
1842 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001843 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04001844 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05001845 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04001846 PRINT_K("WPA2 Authentication completed!!\n");
1847 }
1848 }
1849 }
1850}
1851//mike add:station mode check eapol-key challenge<---
1852
Andres More4e9b5e22013-02-12 20:36:30 -05001853 if (pDevice->bEncryptionEnable == true) {
1854 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04001855 // get Transmit key
1856 do {
1857 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1858 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1859 pbyBSSID = pDevice->abyBSSID;
1860 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001861 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001862 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001863 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1864 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001865 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
1866 break;
1867 }
1868 } else {
1869 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
1870 break;
1871 }
1872 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001873 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
1874 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04001875 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
1876 for (ii = 0; ii< 6; ii++)
1877 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
1878 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
1879
1880 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05001881 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04001882 break;
1883 }
1884 // get group key
1885 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001886 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001887 pTransmitKey = NULL;
1888 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1889 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
1890 }
1891 else
1892 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
1893 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001894 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001895 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
1896 }
Andres Moree269fc22013-02-12 20:36:29 -05001897 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001898 }
1899
Andres Moreb902fbf2013-02-25 20:32:51 -05001900 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04001901
1902 if (pDevice->bFixRate) {
1903 if (pDevice->byBBType == BB_TYPE_11B) {
1904 if (pDevice->uConnectionRate >= RATE_11M) {
1905 pDevice->wCurrentRate = RATE_11M;
1906 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05001907 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04001908 }
1909 } else {
1910 if ((pDevice->byBBType == BB_TYPE_11A) &&
1911 (pDevice->uConnectionRate <= RATE_6M)) {
1912 pDevice->wCurrentRate = RATE_6M;
1913 } else {
1914 if (pDevice->uConnectionRate >= RATE_54M)
1915 pDevice->wCurrentRate = RATE_54M;
1916 else
Andres More3eaca0d2013-02-25 20:32:52 -05001917 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04001918 }
1919 }
1920 }
1921 else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001922 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Forest Bond92b96792009-06-13 07:38:31 -04001923 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05001924 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04001925 // Multicast use highest data rate
1926 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
1927 // preamble type
1928 pDevice->byPreambleType = pDevice->byShortPreamble;
1929 }
1930 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001931 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04001932 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1933 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
1934 pDevice->byPreambleType = pDevice->byShortPreamble;
1935
1936 }
1937 else {
1938 pDevice->byPreambleType = PREAMBLE_LONG;
1939 }
1940 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
1941 }
1942 else {
1943 if (pDevice->byBBType != BB_TYPE_11A)
1944 pDevice->wCurrentRate = RATE_2M;
1945 else
1946 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
1947 // abyCurrExtSuppRates[]
1948 pDevice->byPreambleType = PREAMBLE_SHORT;
1949 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
1950 }
1951 }
1952 }
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001953 if (pDevice->op_mode == NL80211_IFTYPE_STATION) {
Forest Bond92b96792009-06-13 07:38:31 -04001954 // Infra STA rate decided from AP Node, index = 0
1955 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
1956 }
1957 }
1958
Andres Moreceb8c5d2013-03-18 20:33:49 -05001959 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001960 if (pDevice->byBBType != BB_TYPE_11A) {
1961 pDevice->wCurrentRate = RATE_1M;
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001962 pDevice->byTopCCKBasicRate = RATE_1M;
1963 pDevice->byTopOFDMBasicRate = RATE_6M;
1964 } else {
1965 pDevice->wCurrentRate = RATE_6M;
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001966 pDevice->byTopCCKBasicRate = RATE_1M;
1967 pDevice->byTopOFDMBasicRate = RATE_6M;
1968 }
1969 }
Forest Bond92b96792009-06-13 07:38:31 -04001970
Andres More0cbd8d92010-05-06 20:34:29 -03001971 DBG_PRT(MSG_LEVEL_DEBUG,
1972 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
1973 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04001974
1975 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03001976 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001977 }
1978
1979 if (pDevice->wCurrentRate <= RATE_11M) {
1980 byPktType = PK_TYPE_11B;
1981 }
1982
Andres More4e9b5e22013-02-12 20:36:30 -05001983 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001984 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
1985 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05001986 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001987 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04001988 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1989 if (pTransmitKey == NULL) {
1990 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
1991 }
1992 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001993 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001994 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
1995 }
1996 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001997 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
1998 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05001999 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002000 }
2001 }
2002 }
Forest Bond92b96792009-06-13 07:38:31 -04002003 }
2004 else {
2005
Forest Bond92b96792009-06-13 07:38:31 -04002006 if (pTransmitKey == NULL) {
2007 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2008 dev_kfree_skb_irq(skb);
2009 pStats->tx_dropped++;
2010 return STATUS_FAILURE;
2011 }
Forest Bond92b96792009-06-13 07:38:31 -04002012 }
2013 }
2014
Malcolm Priestleyb674ee12014-05-15 22:49:10 +01002015 pContext = s_vGetFreeContext(pDevice);
2016 if (!pContext) {
2017 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2018 dev_kfree_skb_irq(skb);
2019 return STATUS_RESOURCES;
2020 }
2021
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002022 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0];
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002023
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +01002024 fConvertedPacket = s_bPacketToWirelessUsb(pContext, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002025 pTX_Buffer, bNeedEncryption,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01002026 skb->len, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002027 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002028 pDevice->wCurrentRate,
2029 &uHeaderLen, &BytesToWrite
2030 );
2031
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002032 if (fConvertedPacket == false) {
2033 pContext->in_use = false;
2034 dev_kfree_skb_irq(skb);
2035 return STATUS_FAILURE;
2036 }
Forest Bond92b96792009-06-13 07:38:31 -04002037
Andres More4e9b5e22013-02-12 20:36:30 -05002038 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002039 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002040 bScheduleCommand((void *) pDevice,
2041 WLAN_CMD_MAC_DISPOWERSAVING,
2042 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002043 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002044 }
2045 }
2046
Andres Moreb902fbf2013-02-25 20:32:51 -05002047 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Malcolm Priestleyca347592014-03-22 09:01:28 +00002048 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)BytesToWrite);
Forest Bond92b96792009-06-13 07:38:31 -04002049
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002050 pContext->skb = skb;
2051 pContext->type = CONTEXT_DATA_PACKET;
2052 pContext->buf_len = (u16)BytesToWrite + 4 ; /* USB header */
Forest Bond92b96792009-06-13 07:38:31 -04002053
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002054 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
Malcolm Priestley81aec602014-02-27 23:06:11 +00002055 &pDevice->sTxEthHeader.h_dest[0],
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002056 (u16)(BytesToWrite-uHeaderLen),
2057 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002058
2059 status = PIPEnsSendBulkOut(pDevice,pContext);
2060
Andres More4e9b5e22013-02-12 20:36:30 -05002061 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002062 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002063
Andres Moreb902fbf2013-02-25 20:32:51 -05002064 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002065 }
2066
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002067 if (status != STATUS_PENDING) {
2068 pContext->in_use = false;
2069 dev_kfree_skb_irq(skb);
2070 return STATUS_FAILURE;
2071 }
Forest Bond92b96792009-06-13 07:38:31 -04002072
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002073
2074 return 0;
Forest Bond92b96792009-06-13 07:38:31 -04002075}
Malcolm Priestleyd38b13a2014-06-25 21:14:23 +01002076
2077static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
2078 u8 *key_buffer, struct ieee80211_key_conf *tx_key, struct sk_buff *skb,
2079 u16 payload_len, struct vnt_mic_hdr *mic_hdr)
2080{
2081 struct ieee80211_hdr *hdr = tx_context->hdr;
2082 struct ieee80211_key_seq seq;
2083 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
2084
2085 /* strip header and icv len from payload */
2086 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
2087 payload_len -= tx_key->icv_len;
2088
2089 switch (tx_key->cipher) {
2090 case WLAN_CIPHER_SUITE_WEP40:
2091 case WLAN_CIPHER_SUITE_WEP104:
2092 memcpy(key_buffer, iv, 3);
2093 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
2094
2095 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
2096 memcpy(key_buffer + 8, iv, 3);
2097 memcpy(key_buffer + 11,
2098 tx_key->key, WLAN_KEY_LEN_WEP40);
2099 }
2100
2101 break;
2102 case WLAN_CIPHER_SUITE_TKIP:
2103 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
2104
2105 break;
2106 case WLAN_CIPHER_SUITE_CCMP:
2107
2108 if (!mic_hdr)
2109 return;
2110
2111 mic_hdr->id = 0x59;
2112 mic_hdr->payload_len = cpu_to_be16(payload_len);
2113 memcpy(mic_hdr->mic_addr2, hdr->addr2, ETH_ALEN);
2114
2115 ieee80211_get_key_tx_seq(tx_key, &seq);
2116
2117 mic_hdr->tsc_47_16 = cpu_to_be32((u32)seq.ccmp.pn[3] |
2118 ((u32)seq.ccmp.pn[2] << 8) |
2119 ((u32)seq.ccmp.pn[1] << 16) |
2120 ((u32)seq.ccmp.pn[0] << 24));
2121
2122 mic_hdr->tsc_15_0 = cpu_to_be16((u16)seq.ccmp.pn[5] |
2123 ((u16)seq.ccmp.pn[4] << 8));
2124
2125 if (ieee80211_has_a4(hdr->frame_control))
2126 mic_hdr->hlen = cpu_to_be16(28);
2127 else
2128 mic_hdr->hlen = cpu_to_be16(22);
2129
2130 memcpy(mic_hdr->addr1, hdr->addr1, ETH_ALEN);
2131 memcpy(mic_hdr->addr2, hdr->addr2, ETH_ALEN);
2132 memcpy(mic_hdr->addr3, hdr->addr3, ETH_ALEN);
2133
2134 mic_hdr->frame_control = cpu_to_le16(
2135 le16_to_cpu(hdr->frame_control) & 0xc78f);
2136 mic_hdr->seq_ctrl = cpu_to_le16(
2137 le16_to_cpu(hdr->seq_ctrl) & 0xf);
2138
2139 if (ieee80211_has_a4(hdr->frame_control))
2140 memcpy(mic_hdr->addr4, hdr->addr4, ETH_ALEN);
2141
2142
2143 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
2144
2145 break;
2146 default:
2147 break;
2148 }
2149
2150}
2151
2152int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
2153{
2154 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2155 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
2156 struct ieee80211_rate *rate;
2157 struct ieee80211_key_conf *tx_key;
2158 struct ieee80211_hdr *hdr;
2159 struct vnt_mic_hdr *mic_hdr = NULL;
2160 struct vnt_tx_buffer *tx_buffer;
2161 struct vnt_tx_fifo_head *tx_buffer_head;
2162 struct vnt_usb_send_context *tx_context;
2163 unsigned long flags;
2164 u32 frame_size = 0;
2165 u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id;
2166 u8 pkt_type, fb_option = AUTO_FB_NONE;
2167 bool need_rts = false, need_ack = false, is_pspoll = false;
2168 bool need_mic = false;
2169
2170 hdr = (struct ieee80211_hdr *)(skb->data);
2171
2172 rate = ieee80211_get_tx_rate(priv->hw, info);
2173
2174 current_rate = rate->hw_value;
2175 if (priv->wCurrentRate != current_rate) {
2176 priv->wCurrentRate = current_rate;
2177 bScheduleCommand(priv, WLAN_CMD_SETPOWER, NULL);
2178 }
2179
2180 if (current_rate > RATE_11M)
2181 pkt_type = priv->byPacketType;
2182 else
2183 pkt_type = PK_TYPE_11B;
2184
2185 spin_lock_irqsave(&priv->lock, flags);
2186
2187 tx_context = s_vGetFreeContext(priv);
2188 if (!tx_context) {
2189 dev_dbg(&priv->usb->dev, "%s No free context\n", __func__);
2190 spin_unlock_irqrestore(&priv->lock, flags);
2191 return -ENOMEM;
2192 }
2193
2194 tx_context->skb = skb;
2195
2196 spin_unlock_irqrestore(&priv->lock, flags);
2197
2198 tx_buffer = (struct vnt_tx_buffer *)tx_context->data;
2199 tx_buffer_head = &tx_buffer->fifo_head;
2200 tx_body_size = skb->len;
2201
2202 frame_size = tx_body_size + 4;
2203
2204 /* Set time stamp */
2205 tx_buffer_head->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2206
2207 /*Set fifo controls */
2208 if (pkt_type == PK_TYPE_11A)
2209 tx_buffer_head->wFIFOCtl = 0;
2210 else if (pkt_type == PK_TYPE_11B)
2211 tx_buffer_head->wFIFOCtl = FIFOCTL_11B;
2212 else if (pkt_type == PK_TYPE_11GB)
2213 tx_buffer_head->wFIFOCtl = FIFOCTL_11GB;
2214 else if (pkt_type == PK_TYPE_11GA)
2215 tx_buffer_head->wFIFOCtl = FIFOCTL_11GA;
2216
2217 if (!ieee80211_is_data(hdr->frame_control)) {
2218 tx_buffer_head->wFIFOCtl |= (FIFOCTL_GENINT |
2219 FIFOCTL_ISDMA0);
2220 tx_buffer_head->wFIFOCtl |= FIFOCTL_TMOEN;
2221
2222 tx_buffer_head->time_stamp =
2223 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2224 } else {
2225 tx_buffer_head->time_stamp =
2226 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
2227 }
2228
2229 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
2230 tx_buffer_head->wFIFOCtl |= FIFOCTL_NEEDACK;
2231 need_ack = true;
2232 }
2233
2234 if (ieee80211_has_retry(hdr->frame_control))
2235 tx_buffer_head->wFIFOCtl |= FIFOCTL_LRETRY;
2236
2237 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
2238 priv->byPreambleType = PREAMBLE_SHORT;
2239 else
2240 priv->byPreambleType = PREAMBLE_LONG;
2241
2242 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) {
2243 need_rts = true;
2244 tx_buffer_head->wFIFOCtl |= FIFOCTL_RTS;
2245 }
2246
2247 if (ieee80211_has_a4(hdr->frame_control))
2248 tx_buffer_head->wFIFOCtl |= FIFOCTL_LHEAD;
2249
2250 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
2251 is_pspoll = true;
2252
2253 tx_buffer_head->wFragCtl =
2254 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb)) << 10;
2255
2256 if (info->control.hw_key) {
2257 tx_key = info->control.hw_key;
2258 switch (info->control.hw_key->cipher) {
2259 case WLAN_CIPHER_SUITE_WEP40:
2260 case WLAN_CIPHER_SUITE_WEP104:
2261 tx_buffer_head->wFragCtl |= FRAGCTL_LEGACY;
2262 break;
2263 case WLAN_CIPHER_SUITE_TKIP:
2264 tx_buffer_head->wFragCtl |= FRAGCTL_TKIP;
2265 break;
2266 case WLAN_CIPHER_SUITE_CCMP:
2267 tx_buffer_head->wFragCtl |= FRAGCTL_AES;
2268 need_mic = true;
2269 default:
2270 break;
2271 }
2272 frame_size += tx_key->icv_len;
2273 }
2274
2275 /* legacy rates TODO use ieee80211_tx_rate */
2276 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
2277 if (priv->byAutoFBCtrl == AUTO_FB_0) {
2278 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
2279
2280 priv->tx_rate_fb0 =
2281 wFB_Opt0[FB_RATE0][current_rate - RATE_18M];
2282 priv->tx_rate_fb1 =
2283 wFB_Opt0[FB_RATE1][current_rate - RATE_18M];
2284
2285 fb_option = AUTO_FB_0;
2286 } else if (priv->byAutoFBCtrl == AUTO_FB_1) {
2287 tx_buffer_head->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
2288
2289 priv->tx_rate_fb0 =
2290 wFB_Opt1[FB_RATE0][current_rate - RATE_18M];
2291 priv->tx_rate_fb1 =
2292 wFB_Opt1[FB_RATE1][current_rate - RATE_18M];
2293
2294 fb_option = AUTO_FB_1;
2295 }
2296 }
2297
2298 duration_id = s_vGenerateTxParameter(tx_context, pkt_type, current_rate,
2299 tx_buffer, &mic_hdr, need_mic, frame_size,
2300 need_ack, NULL, need_rts);
2301
2302 tx_header_size = tx_context->tx_hdr_size;
2303 if (!tx_header_size) {
2304 tx_context->in_use = false;
2305 return -ENOMEM;
2306 }
2307
2308 tx_buffer_head->wFragCtl |= (u16)FRAGCTL_NONFRAG;
2309
2310 tx_bytes = tx_header_size + tx_body_size;
2311
2312 memcpy(tx_context->hdr, skb->data, tx_body_size);
2313
2314 hdr->duration_id = cpu_to_le16(duration_id);
2315
2316 if (info->control.hw_key) {
2317 tx_key = info->control.hw_key;
2318 if (tx_key->keylen > 0)
2319 vnt_fill_txkey(tx_context, tx_buffer_head->tx_key,
2320 tx_key, skb, tx_body_size, mic_hdr);
2321 }
2322
2323 priv->wSeqCounter = (le16_to_cpu(hdr->seq_ctrl) &
2324 IEEE80211_SCTL_SEQ) >> 4;
2325
2326 tx_buffer->tx_byte_count = cpu_to_le16(tx_bytes);
2327 tx_buffer->byPKTNO = (u8)(((current_rate << 4) & 0xf0) |
2328 (priv->wSeqCounter & 0xf));
2329 tx_buffer->byType = 0x00;
2330
2331 tx_bytes += 4;
2332
2333 tx_context->type = CONTEXT_DATA_PACKET;
2334 tx_context->buf_len = tx_bytes;
2335
2336 spin_lock_irqsave(&priv->lock, flags);
2337
2338 if (PIPEnsSendBulkOut(priv, tx_context) != STATUS_PENDING) {
2339 spin_unlock_irqrestore(&priv->lock, flags);
2340 return -EIO;
2341 }
2342
2343 spin_unlock_irqrestore(&priv->lock, flags);
2344
2345 return 0;
2346}
2347
2348static int vnt_beacon_xmit(struct vnt_private *priv,
2349 struct sk_buff *skb)
2350{
2351 struct vnt_beacon_buffer *beacon_buffer;
2352 struct vnt_tx_short_buf_head *short_head;
2353 struct ieee80211_tx_info *info;
2354 struct vnt_usb_send_context *context;
2355 struct ieee80211_mgmt *mgmt_hdr;
2356 unsigned long flags;
2357 u32 frame_size = skb->len + 4;
2358 u16 current_rate, count;
2359
2360 spin_lock_irqsave(&priv->lock, flags);
2361
2362 context = s_vGetFreeContext(priv);
2363 if (!context) {
2364 dev_dbg(&priv->usb->dev, "%s No free context!\n", __func__);
2365 spin_unlock_irqrestore(&priv->lock, flags);
2366 return -ENOMEM;
2367 }
2368
2369 context->skb = skb;
2370
2371 spin_unlock_irqrestore(&priv->lock, flags);
2372
2373 beacon_buffer = (struct vnt_beacon_buffer *)&context->data[0];
2374 short_head = &beacon_buffer->short_head;
2375
2376 if (priv->byBBType == BB_TYPE_11A) {
2377 current_rate = RATE_6M;
2378
2379 /* Get SignalField,ServiceField,Length */
2380 vnt_get_phy_field(priv, frame_size, current_rate,
2381 PK_TYPE_11A, &short_head->ab);
2382
2383 /* Get Duration and TimeStampOff */
2384 short_head->duration = s_uGetDataDuration(priv,
2385 PK_TYPE_11A, false);
2386 short_head->time_stamp_off =
2387 vnt_time_stamp_off(priv, current_rate);
2388 } else {
2389 current_rate = RATE_1M;
2390 short_head->fifo_ctl |= FIFOCTL_11B;
2391
2392 /* Get SignalField,ServiceField,Length */
2393 vnt_get_phy_field(priv, frame_size, current_rate,
2394 PK_TYPE_11B, &short_head->ab);
2395
2396 /* Get Duration and TimeStampOff */
2397 short_head->duration = s_uGetDataDuration(priv,
2398 PK_TYPE_11B, false);
2399 short_head->time_stamp_off =
2400 vnt_time_stamp_off(priv, current_rate);
2401 }
2402
2403 /* Generate Beacon Header */
2404 mgmt_hdr = &beacon_buffer->mgmt_hdr;
2405 memcpy(mgmt_hdr, skb->data, skb->len);
2406
2407 /* time stamp always 0 */
2408 mgmt_hdr->u.beacon.timestamp = 0;
2409
2410 info = IEEE80211_SKB_CB(skb);
2411 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
2412 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
2413 hdr->duration_id = 0;
2414 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
2415 }
2416
2417 priv->wSeqCounter++;
2418 if (priv->wSeqCounter > 0x0fff)
2419 priv->wSeqCounter = 0;
2420
2421 count = sizeof(struct vnt_tx_short_buf_head) + skb->len;
2422
2423 beacon_buffer->tx_byte_count = cpu_to_le16(count);
2424 beacon_buffer->byPKTNO = (u8)(((current_rate << 4) & 0xf0) |
2425 ((priv->wSeqCounter - 1) & 0x000f));
2426 beacon_buffer->byType = 0x01;
2427
2428 context->type = CONTEXT_BEACON_PACKET;
2429 context->buf_len = count + 4; /* USB header */
2430
2431 spin_lock_irqsave(&priv->lock, flags);
2432
2433 if (PIPEnsSendBulkOut(priv, context) != STATUS_PENDING)
2434 ieee80211_free_txskb(priv->hw, context->skb);
2435
2436 spin_unlock_irqrestore(&priv->lock, flags);
2437
2438 return 0;
2439}
2440
2441int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
2442{
2443 struct sk_buff *beacon;
2444
2445 beacon = ieee80211_beacon_get(priv->hw, vif);
2446 if (!beacon)
2447 return -ENOMEM;
2448
2449 if (vnt_beacon_xmit(priv, beacon)) {
2450 ieee80211_free_txskb(priv->hw, beacon);
2451 return -ENODEV;
2452 }
2453
2454 return 0;
2455}
2456
2457int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
2458 struct ieee80211_bss_conf *conf)
2459{
2460 int ret;
2461
2462 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
2463
2464 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
2465
2466 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
2467
2468 vnt_clear_current_tsf(priv);
2469
2470 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
2471
2472 vnt_reset_next_tbtt(priv, conf->beacon_int);
2473
2474 ret = vnt_beacon_make(priv, vif);
2475
2476 return ret;
2477}