blob: e4cc1ff0f8a7b480f6fdcdfe1183b40be839de4f [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 Priestley3ba09382013-10-15 21:41:38 +0100109static void s_vFillTxKey(struct vnt_private *pDevice,
110 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
111 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100112 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400113
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000114static void s_vSWencryption(struct vnt_private *pDevice,
115 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400116
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000117static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
118 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400119
Malcolm Priestley20338012014-03-18 19:25:08 +0000120static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100121 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400122
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100123static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100124 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
125 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400126
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100127static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100128 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500129 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400130
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000131static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100132 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400133
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000134static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000135 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
136 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400137
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000138static struct vnt_usb_send_context
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000139 *s_vGetFreeContext(struct vnt_private *priv)
Forest Bond92b96792009-06-13 07:38:31 -0400140{
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000141 struct vnt_usb_send_context *context = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000142 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400143
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000144 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
Forest Bond92b96792009-06-13 07:38:31 -0400145
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000146 for (ii = 0; ii < priv->cbTD; ii++) {
147 if (!priv->apTD[ii])
148 return NULL;
149
150 context = priv->apTD[ii];
Malcolm Priestley30a05b32014-05-15 22:49:11 +0100151 if (context->in_use == false) {
152 context->in_use = true;
153 memset(context->data, 0,
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000154 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100155
156 context->hdr = NULL;
157
Malcolm Priestleyb89f3b92013-11-26 19:16:59 +0000158 return context;
159 }
160 }
161
162 if (ii == priv->cbTD)
163 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
Malcolm Priestleyaceaf012013-11-26 19:06:35 +0000164
Malcolm Priestley5c851382013-11-26 19:12:38 +0000165 return NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400166}
167
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000168static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
169 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400170{
Malcolm Priestleyae27b142013-12-09 22:23:19 +0000171 struct net_device_stats *stats = &pDevice->stats;
Malcolm Priestley51934e72013-12-09 22:30:14 +0000172 struct vnt_tx_pkt_info *pkt_info = pDevice->pkt_info;
Forest Bond92b96792009-06-13 07:38:31 -0400173
Malcolm Priestley51934e72013-12-09 22:30:14 +0000174 pkt_info[byPktNum].fifo_ctl = wFIFOCtl;
175 memcpy(pkt_info[byPktNum].dest_addr, pbyDestAddr, ETH_ALEN);
Malcolm Priestleyae27b142013-12-09 22:23:19 +0000176
177 stats->tx_bytes += wPktLength;
Forest Bond92b96792009-06-13 07:38:31 -0400178}
179
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100180static void s_vFillTxKey(struct vnt_private *pDevice,
181 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
182 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
183 struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400184{
Malcolm Priestley3ba09382013-10-15 21:41:38 +0100185 u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0];
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);
Andres More1cac4a42013-03-18 20:33:50 -0500188 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000189 __le32 rev_iv_counter;
Forest Bond92b96792009-06-13 07:38:31 -0400190
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100191 /* Fill TXKEY */
192 if (pTransmitKey == NULL)
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100193 return;
Forest Bond92b96792009-06-13 07:38:31 -0400194
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000195 rev_iv_counter = cpu_to_le32(pDevice->dwIVCounter);
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000196 *pdwIV = cpu_to_le32(pDevice->dwIVCounter);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100197 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
Forest Bond92b96792009-06-13 07:38:31 -0400198
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100199 switch (pTransmitKey->byCipherSuite) {
200 case KEY_CTL_WEP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100201 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000202 memcpy(pDevice->abyPRNG, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100203 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
204 pTransmitKey->uKeyLength);
205 } else {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000206 memcpy(pbyBuf, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100207 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
208 pTransmitKey->uKeyLength);
209 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Malcolm Priestleyfbfaccf2014-03-22 09:01:23 +0000210 memcpy(pbyBuf+8, (u8 *)&rev_iv_counter, 3);
Malcolm Priestley5cb5bff72014-05-25 21:36:28 +0100211 memcpy(pbyBuf+11, pTransmitKey->abyKey,
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100212 pTransmitKey->uKeyLength);
213 }
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100214
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100215 memcpy(pDevice->abyPRNG, pbyBuf, 16);
216 }
217 /* Append IV after Mac Header */
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000218 *pdwIV &= cpu_to_le32(WEP_IV_MASK);
219 *pdwIV |= cpu_to_le32((u32)pDevice->byKeyIndex << 30);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100220
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100221 pDevice->dwIVCounter++;
222 if (pDevice->dwIVCounter > WEP_IV_MASK)
223 pDevice->dwIVCounter = 0;
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100224
225 break;
226 case KEY_CTL_TKIP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100227 pTransmitKey->wTSC15_0++;
228 if (pTransmitKey->wTSC15_0 == 0)
229 pTransmitKey->dwTSC47_16++;
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100230
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100231 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
232 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
233 pDevice->abyPRNG);
234 memcpy(pbyBuf, pDevice->abyPRNG, 16);
235
236 /* Make IV */
237 memcpy(pdwIV, pDevice->abyPRNG, 3);
238
239 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
240 0xc0) | 0x20);
241 /* Append IV&ExtIV after Mac Header */
242 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
243
244 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
245 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
246
Malcolm Priestleyf6804f32013-08-27 12:32:01 +0100247 break;
248 case KEY_CTL_CCMP:
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100249 pTransmitKey->wTSC15_0++;
250 if (pTransmitKey->wTSC15_0 == 0)
251 pTransmitKey->dwTSC47_16++;
252
253 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
254
255 /* Make IV */
256 *pdwIV = 0;
257 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
258 0xc0) | 0x20);
259
Malcolm Priestleyfb453db2014-03-22 09:01:24 +0000260 *pdwIV |= cpu_to_le32((u32)(pTransmitKey->wTSC15_0));
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100261
262 /* Append IV&ExtIV after Mac Header */
263 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
264
265 if (!mic_hdr)
266 return;
267
268 /* MICHDR0 */
269 mic_hdr->id = 0x59;
270 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
271 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
272
273 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
274 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
275
276 /* MICHDR1 */
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000277 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100278 mic_hdr->hlen = cpu_to_be16(28);
279 else
280 mic_hdr->hlen = cpu_to_be16(22);
281
282 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
283 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
284
285 /* MICHDR2 */
286 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
Malcolm Priestley5d4fe752014-03-22 09:01:26 +0000287 mic_hdr->frame_control = cpu_to_le16(
288 le16_to_cpu(pMACHeader->frame_control) & 0xc78f);
289 mic_hdr->seq_ctrl = cpu_to_le16(
290 le16_to_cpu(pMACHeader->seq_ctrl) & 0xf);
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100291
Malcolm Priestley078d0cf2013-11-25 22:14:16 +0000292 if (ieee80211_has_a4(pMACHeader->frame_control))
Malcolm Priestley95bfb1a2013-08-27 12:29:10 +0100293 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
294 }
Forest Bond92b96792009-06-13 07:38:31 -0400295}
296
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000297static void s_vSWencryption(struct vnt_private *pDevice,
298 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400299{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000300 u32 cbICVlen = 4;
301 u32 dwICV = 0xffffffff;
302 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400303
304 if (pTransmitKey == NULL)
305 return;
306
307 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
308 //=======================================================================
309 // Append ICV after payload
Malcolm Priestley929cb312014-05-21 21:09:42 +0100310 dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead);
Andres More52a7e642013-02-25 20:32:53 -0500311 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400312 // finally, we must invert dwCRC to get the correct answer
313 *pdwICV = cpu_to_le32(~dwICV);
314 // RC4 encryption
315 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
316 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
317 //=======================================================================
318 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
319 //=======================================================================
320 //Append ICV after payload
Malcolm Priestley929cb312014-05-21 21:09:42 +0100321 dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead);
Andres More52a7e642013-02-25 20:32:53 -0500322 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400323 // finally, we must invert dwCRC to get the correct answer
324 *pdwICV = cpu_to_le32(~dwICV);
325 // RC4 encryption
326 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
327 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
328 //=======================================================================
329 }
330}
331
Malcolm Priestleydab085b2014-03-18 19:25:03 +0000332static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100333{
334 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
335 [rate % MAX_RATE]);
336}
337
Forest Bond92b96792009-06-13 07:38:31 -0400338/*byPktType : PK_TYPE_11A 0
339 PK_TYPE_11B 1
340 PK_TYPE_11GB 2
341 PK_TYPE_11GA 3
342*/
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000343static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
344 u32 frame_length, u16 rate, int need_ack)
Forest Bond92b96792009-06-13 07:38:31 -0400345{
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000346 u32 data_time, ack_time;
Forest Bond92b96792009-06-13 07:38:31 -0400347
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000348 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
349 frame_length, rate);
Forest Bond92b96792009-06-13 07:38:31 -0400350
Malcolm Priestley3fd56202014-01-08 20:08:42 +0000351 if (pkt_type == PK_TYPE_11B)
352 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
353 (u16)priv->byTopCCKBasicRate);
354 else
355 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
356 (u16)priv->byTopOFDMBasicRate);
357
358 if (need_ack)
359 return data_time + priv->uSIFS + ack_time;
360
361 return data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400362}
363
Malcolm Priestley2075f652014-03-18 19:25:07 +0000364static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100365 u32 frame_length, u16 rate, int need_ack)
366{
367 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
368 frame_length, rate, need_ack));
369}
370
Forest Bond92b96792009-06-13 07:38:31 -0400371//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley20338012014-03-18 19:25:08 +0000372static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100373 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
Forest Bond92b96792009-06-13 07:38:31 -0400374{
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000375 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
Forest Bond92b96792009-06-13 07:38:31 -0400376
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000377 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400378
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000379 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
Malcolm Priestley3b6cee7be2014-05-25 21:36:27 +0100380 frame_length, current_rate);
Forest Bond92b96792009-06-13 07:38:31 -0400381
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000382 if (rsv_type == 0) {
383 rts_time = BBuGetFrameTime(priv->byPreambleType,
384 pkt_type, 20, priv->byTopCCKBasicRate);
385 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
386 pkt_type, 14, priv->byTopCCKBasicRate);
387 } else if (rsv_type == 1) {
388 rts_time = BBuGetFrameTime(priv->byPreambleType,
389 pkt_type, 20, priv->byTopCCKBasicRate);
390 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
391 14, priv->byTopCCKBasicRate);
392 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
393 14, priv->byTopOFDMBasicRate);
394 } else if (rsv_type == 2) {
395 rts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
396 20, priv->byTopOFDMBasicRate);
397 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
398 pkt_type, 14, priv->byTopOFDMBasicRate);
399 } else if (rsv_type == 3) {
400 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
401 14, priv->byTopCCKBasicRate);
402 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
403 14, priv->byTopOFDMBasicRate);
404
405 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
406
Malcolm Priestley20338012014-03-18 19:25:08 +0000407 return cpu_to_le16((u16)rrv_time);
Malcolm Priestley342e2e22014-01-08 20:13:29 +0000408 }
409
410 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
411
412 return cpu_to_le16((u16)rrv_time);
Forest Bond92b96792009-06-13 07:38:31 -0400413}
414
415//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley5abe3d62014-03-18 19:25:06 +0000416static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100417 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400418{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100419 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400420
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100421 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100422 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100423 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
424 byPktType, 14, pDevice->byTopCCKBasicRate);
425 else
426 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
427 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100428 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100429 }
Forest Bond92b96792009-06-13 07:38:31 -0400430
Forest Bond92b96792009-06-13 07:38:31 -0400431 return 0;
432}
433
Forest Bond92b96792009-06-13 07:38:31 -0400434//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestley7f591a12014-03-18 19:25:05 +0000435static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000436 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
437 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400438{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000439 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400440
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100441 switch (byDurType) {
442 case RTSDUR_BB:
443 case RTSDUR_BA:
444 case RTSDUR_BA_F0:
445 case RTSDUR_BA_F1:
446 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
447 14, pDevice->byTopCCKBasicRate);
448 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
449 s_uGetTxRsvTime(pDevice, byPktType,
450 cbFrameLength, wRate, bNeedAck);
451 break;
Forest Bond92b96792009-06-13 07:38:31 -0400452
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100453 case RTSDUR_AA:
454 case RTSDUR_AA_F0:
455 case RTSDUR_AA_F1:
456 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
457 14, pDevice->byTopOFDMBasicRate);
458 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
459 s_uGetTxRsvTime(pDevice, byPktType,
460 cbFrameLength, wRate, bNeedAck);
461 break;
Forest Bond92b96792009-06-13 07:38:31 -0400462
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100463 case CTSDUR_BA:
464 case CTSDUR_BA_F0:
465 case CTSDUR_BA_F1:
466 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100467 byPktType, cbFrameLength, wRate, bNeedAck);
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100468 break;
Forest Bond92b96792009-06-13 07:38:31 -0400469
Malcolm Priestleyecd80242013-10-15 21:05:02 +0100470 default:
471 break;
472 }
Forest Bond92b96792009-06-13 07:38:31 -0400473
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100474 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400475}
476
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100477static u16 vnt_mac_hdr_pos(struct vnt_usb_send_context *tx_context,
478 struct ieee80211_hdr *hdr)
479{
480 u8 *head = tx_context->data + offsetof(struct vnt_tx_buffer, fifo_head);
481 u8 *hdr_pos = (u8 *)hdr;
482
483 tx_context->hdr = hdr;
484 if (!tx_context->hdr)
485 return 0;
486
487 return (u16)(hdr_pos - head);
488}
489
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100490static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context,
491 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g *buf,
492 u32 frame_len, int need_ack)
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100493{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100494
495 struct vnt_private *priv = tx_context->priv;
496
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100497 /* Get SignalField,ServiceField,Length */
498 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
499 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
500 PK_TYPE_11B, &buf->b);
501
502 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000503 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
504 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100505
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000506 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
507 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100508 priv->byTopCCKBasicRate);
509
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100510 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
511
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000512 return le16_to_cpu(buf->duration_a);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100513}
514
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100515static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context,
516 u8 pkt_type, u16 rate, struct vnt_tx_datahead_g_fb *buf,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100517 u32 frame_len, int need_ack)
518{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100519 struct vnt_private *priv = tx_context->priv;
520
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100521 /* Get SignalField,ServiceField,Length */
522 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
523
524 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
525 PK_TYPE_11B, &buf->b);
526
527 /* Get Duration and TimeStamp */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000528 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
529 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100530
Malcolm Priestley4e011172014-03-18 19:24:55 +0000531 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
532 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100533
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000534 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
535 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100536 priv->byTopCCKBasicRate);
537
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100538 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
539
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000540 return le16_to_cpu(buf->duration_a);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100541}
542
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100543static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context,
544 u8 pkt_type, u16 rate, struct vnt_tx_datahead_a_fb *buf,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100545 u32 frame_len, int need_ack)
546{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100547 struct vnt_private *priv = tx_context->priv;
548
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100549 /* Get SignalField,ServiceField,Length */
550 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
551 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000552 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100553
Malcolm Priestley4e011172014-03-18 19:24:55 +0000554 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
555 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100556
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000557 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100558
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100559 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
560
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000561 return le16_to_cpu(buf->duration);
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100562}
563
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100564static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context,
565 u8 pkt_type, u16 rate, struct vnt_tx_datahead_ab *buf,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100566 u32 frame_len, int need_ack)
567{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100568 struct vnt_private *priv = tx_context->priv;
569
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100570 /* Get SignalField,ServiceField,Length */
571 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
572 /* Get Duration and TimeStampOff */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000573 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100574
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000575 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100576
Malcolm Priestley1622c8f2014-05-31 13:34:58 +0100577 tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr);
578
Malcolm Priestleyc4cf6df2014-03-18 19:25:04 +0000579 return le16_to_cpu(buf->duration);
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100580}
581
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100582static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
583 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
Malcolm Priestley10bb39a2014-03-18 19:25:01 +0000584 __le16 duration)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100585{
586 rts->duration = duration;
Malcolm Priestleyf4554d32014-03-22 09:01:31 +0000587 rts->frame_control =
588 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100589
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000590 if (priv->op_mode == NL80211_IFTYPE_ADHOC ||
591 priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100592 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
593 else
594 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
595
Malcolm Priestleya0ad2772014-02-15 21:56:20 +0000596 if (priv->op_mode == NL80211_IFTYPE_AP)
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100597 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
598 else
599 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
600
601 return 0;
602}
603
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100604static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100605 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
606 u8 pkt_type, u32 frame_len, int need_ack,
607 u16 current_rate, u8 fb_option)
608{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100609 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100610 u16 rts_frame_len = 20;
611
612 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
613 PK_TYPE_11B, &buf->b);
614 BBvCalculateParameter(priv, rts_frame_len,
615 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
616
Malcolm Priestley4e011172014-03-18 19:24:55 +0000617 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100618 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000619 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100620 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000621 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100622 pkt_type, current_rate, need_ack, fb_option);
623
Malcolm Priestley4e011172014-03-18 19:24:55 +0000624 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100625
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100626 return vnt_rxtx_datahead_g(tx_context, pkt_type, current_rate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100627 &buf->data_head, frame_len, need_ack);
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100628}
629
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100630static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100631 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
632 u8 pkt_type, u32 frame_len, int need_ack,
633 u16 current_rate, u8 fb_option)
634{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100635 struct vnt_private *priv = tx_context->priv;
Malcolm Priestleyec917132013-08-26 11:07:46 +0100636 u16 rts_frame_len = 20;
637
638 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
639 PK_TYPE_11B, &buf->b);
640 BBvCalculateParameter(priv, rts_frame_len,
641 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
642
643
Malcolm Priestley4e011172014-03-18 19:24:55 +0000644 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100645 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000646 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100647 pkt_type, current_rate, need_ack, fb_option);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000648 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100649 pkt_type, current_rate, need_ack, fb_option);
650
651
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000652 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100653 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000654 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100655 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000656 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100657 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000658 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100659 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100660
Malcolm Priestley4e011172014-03-18 19:24:55 +0000661 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100662
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100663 return vnt_rxtx_datahead_g_fb(tx_context, pkt_type, current_rate,
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100664 &buf->data_head, frame_len, need_ack);
Malcolm Priestleyec917132013-08-26 11:07:46 +0100665}
666
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100667static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley17126332013-08-26 11:09:38 +0100668 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
669 u8 pkt_type, u32 frame_len, int need_ack,
670 u16 current_rate, u8 fb_option)
671{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100672 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley17126332013-08-26 11:09:38 +0100673 u16 rts_frame_len = 20;
674
675 BBvCalculateParameter(priv, rts_frame_len,
676 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
677
Malcolm Priestley4e011172014-03-18 19:24:55 +0000678 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley17126332013-08-26 11:09:38 +0100679 pkt_type, current_rate, need_ack, fb_option);
680
Malcolm Priestley4e011172014-03-18 19:24:55 +0000681 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley17126332013-08-26 11:09:38 +0100682
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100683 return vnt_rxtx_datahead_ab(tx_context, pkt_type, current_rate,
Malcolm Priestley5634a5a2013-10-01 16:00:20 +0100684 &buf->data_head, frame_len, need_ack);
Malcolm Priestley17126332013-08-26 11:09:38 +0100685}
686
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100687static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100688 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
689 u8 pkt_type, u32 frame_len, int need_ack,
690 u16 current_rate, u8 fb_option)
691{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100692 struct vnt_private *priv = tx_context->priv;
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100693 u16 rts_frame_len = 20;
694
695 BBvCalculateParameter(priv, rts_frame_len,
696 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
697
Malcolm Priestley4e011172014-03-18 19:24:55 +0000698 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100699 pkt_type, current_rate, need_ack, fb_option);
700
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000701 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100702 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100703
Malcolm Priestleyfadc3bd2014-03-18 19:24:56 +0000704 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100705 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100706
Malcolm Priestley4e011172014-03-18 19:24:55 +0000707 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100708
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100709 return vnt_rxtx_datahead_a_fb(tx_context, pkt_type, current_rate,
Malcolm Priestleybd3f51f2013-10-01 15:56:48 +0100710 &buf->data_head, frame_len, need_ack);
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100711}
712
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100713static u16 s_vFillRTSHead(struct vnt_usb_send_context *tx_context, u8 byPktType,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100714 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500715 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400716{
Forest Bond92b96792009-06-13 07:38:31 -0400717
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100718 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100719 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400720
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100721 /* Note: So far RTSHead doesn't appear in ATIM
722 * & Beacom DMA, so we don't need to take them
723 * into account.
724 * Otherwise, we need to modified codes for them.
725 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100726 switch (byPktType) {
727 case PK_TYPE_11GB:
728 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100729 if (byFBOption == AUTO_FB_NONE)
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100730 return vnt_rxtx_rts_g_head(tx_context, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100731 psEthHeader, byPktType, cbFrameLength,
732 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100733 else
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100734 return vnt_rxtx_rts_g_fb_head(tx_context,
735 &head->rts_g_fb, psEthHeader, byPktType,
736 cbFrameLength, bNeedAck, wCurrentRate,
737 byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100738 break;
739 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100740 if (byFBOption) {
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100741 return vnt_rxtx_rts_a_fb_head(tx_context,
742 &head->rts_a_fb, psEthHeader, byPktType,
743 cbFrameLength, bNeedAck, wCurrentRate,
744 byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100745 break;
746 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100747 case PK_TYPE_11B:
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100748 return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100749 psEthHeader, byPktType, cbFrameLength,
750 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100751 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100752
753 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400754}
755
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100756static u16 s_vFillCTSHead(struct vnt_usb_send_context *tx_context,
Malcolm Priestley5fb8e412013-08-27 12:07:58 +0100757 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
758 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400759{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100760 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000761 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400762
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100763 if (!head)
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100764 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400765
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100766 if (byFBOption != AUTO_FB_NONE) {
767 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100768 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100769 /* Get SignalField,ServiceField,Length */
770 BBvCalculateParameter(pDevice, uCTSFrameLen,
771 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestley4e011172014-03-18 19:24:55 +0000772 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100773 cbFrameLength, byPktType,
774 wCurrentRate, bNeedAck, byFBOption);
775 /* Get CTSDuration_ba_f0 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000776 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100777 CTSDUR_BA_F0, cbFrameLength, byPktType,
778 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100779 /* Get CTSDuration_ba_f1 */
Malcolm Priestley7fd57472014-03-18 19:24:59 +0000780 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +0100781 CTSDUR_BA_F1, cbFrameLength, byPktType,
782 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100783 /* Get CTS Frame body */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000784 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000785 pBuf->data.frame_control =
786 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
787
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100788 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley5b852f52013-10-01 15:54:56 +0100789
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100790 return vnt_rxtx_datahead_g_fb(tx_context, byPktType,
791 wCurrentRate, &pBuf->data_head, cbFrameLength,
792 bNeedAck);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100793 } else {
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100794 struct vnt_cts *pBuf = &head->cts_g;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100795 /* Get SignalField,ServiceField,Length */
796 BBvCalculateParameter(pDevice, uCTSFrameLen,
797 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100798 /* Get CTSDuration_ba */
Malcolm Priestley4e011172014-03-18 19:24:55 +0000799 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100800 CTSDUR_BA, cbFrameLength, byPktType,
801 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100802 /*Get CTS Frame body*/
Malcolm Priestley4e011172014-03-18 19:24:55 +0000803 pBuf->data.duration = pBuf->duration_ba;
Malcolm Priestleyd9560ae2014-03-22 09:01:32 +0000804 pBuf->data.frame_control =
805 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
806
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100807 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100808
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100809 return vnt_rxtx_datahead_g(tx_context, byPktType, wCurrentRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +0100810 &pBuf->data_head, cbFrameLength, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400811 }
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100812
813 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400814}
815
Forest Bond92b96792009-06-13 07:38:31 -0400816/*+
817 *
818 * Description:
819 * Generate FIFO control for MAC & Baseband controller
820 *
821 * Parameters:
822 * In:
823 * pDevice - Pointer to adpater
824 * pTxDataHead - Transmit Data Buffer
825 * pTxBufHead - pTxBufHead
826 * pvRrvTime - pvRrvTime
827 * pvRTS - RTS Buffer
828 * pCTS - CTS Buffer
829 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
830 * bNeedACK - If need ACK
Forest Bond92b96792009-06-13 07:38:31 -0400831 * Out:
832 * none
833 *
834 * Return Value: none
835 *
836-*/
Andres Morecc856e62010-05-17 21:34:01 -0300837
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100838static u16 s_vGenerateTxParameter(struct vnt_usb_send_context *tx_context,
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100839 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
Malcolm Priestleyfa575602013-09-26 19:00:41 +0100840 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
Malcolm Priestley05cc6172014-04-30 21:31:12 +0100841 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400842{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100843 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestley8e344c82013-09-17 19:58:11 +0100844 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100845 union vnt_tx_data_head *head = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000846 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000847 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400848
Malcolm Priestley03a9cf32014-03-22 09:01:30 +0000849 pFifoHead->current_rate = cpu_to_le16(wCurrentRate);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100850 wFifoCtl = pFifoHead->wFIFOCtl;
Forest Bond92b96792009-06-13 07:38:31 -0400851
Malcolm Priestley92928f12013-10-07 20:14:01 +0100852 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
853 byFBOption = AUTO_FB_0;
854 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
855 byFBOption = AUTO_FB_1;
Forest Bond92b96792009-06-13 07:38:31 -0400856
Malcolm Priestley92928f12013-10-07 20:14:01 +0100857 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
858 if (need_rts) {
859 struct vnt_rrv_time_rts *pBuf =
860 &tx_buffer->tx_head.tx_rts.rts;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100861
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000862 pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100863 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000864 pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100865 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000866 pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100867 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100868
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000869 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100870 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000871 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100872 PK_TYPE_11B, cbFrameSize,
873 pDevice->byTopCCKBasicRate, bNeedACK);
874
875 if (need_mic) {
876 *mic_hdr = &tx_buffer->
877 tx_head.tx_rts.tx.mic.hdr;
878 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
879 } else {
880 head = &tx_buffer->tx_head.tx_rts.tx.head;
881 }
882
883 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100884 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100885 cbFrameSize, bNeedACK, psEthHeader,
886 wCurrentRate, byFBOption);
887
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100888 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100889 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
890 tx_head.tx_cts.cts;
891
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000892 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100893 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000894 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100895 PK_TYPE_11B, cbFrameSize,
896 pDevice->byTopCCKBasicRate, bNeedACK);
897
Malcolm Priestley372108e2014-03-18 19:25:00 +0000898 pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100899 byPktType, cbFrameSize, wCurrentRate);
900
901 if (need_mic) {
902 *mic_hdr = &tx_buffer->
903 tx_head.tx_cts.tx.mic.hdr;
904 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
905 } else {
906 head = &tx_buffer->tx_head.tx_cts.tx.head;
907 }
908
909 /* Fill CTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100910 return s_vFillCTSHead(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100911 head, cbFrameSize, bNeedACK, wCurrentRate,
912 byFBOption);
913 }
914 } else if (byPktType == PK_TYPE_11A) {
915 if (need_mic) {
916 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
917 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
918 } else {
919 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100920 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100921
Malcolm Priestley92928f12013-10-07 20:14:01 +0100922 if (need_rts) {
923 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
924 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +0100925
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000926 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100927 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100928
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000929 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100930 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
931
932 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100933 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100934 cbFrameSize, bNeedACK, psEthHeader,
935 wCurrentRate, byFBOption);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100936 } else {
Malcolm Priestley92928f12013-10-07 20:14:01 +0100937 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
938 tx_head.tx_ab.ab;
939
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000940 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100941 PK_TYPE_11A, cbFrameSize,
942 wCurrentRate, bNeedACK);
943
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100944 return vnt_rxtx_datahead_a_fb(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100945 wCurrentRate, &head->data_head_a_fb,
946 cbFrameSize, bNeedACK);
947 }
948 } else if (byPktType == PK_TYPE_11B) {
949 if (need_mic) {
950 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
951 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
952 } else {
953 head = &tx_buffer->tx_head.tx_ab.tx.head;
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100954 }
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +0100955
Malcolm Priestley92928f12013-10-07 20:14:01 +0100956 if (need_rts) {
957 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
958 tx_head.tx_ab.ab;
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100959
Malcolm Priestley85417bf2014-03-18 19:24:57 +0000960 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0,
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100961 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestleyb9cc2fc2013-09-26 18:57:34 +0100962
Malcolm Priestley5ff627a2014-03-18 19:24:58 +0000963 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100964 PK_TYPE_11B, cbFrameSize, wCurrentRate,
965 bNeedACK);
966
967 /* Fill RTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100968 return s_vFillRTSHead(tx_context, byPktType, head,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100969 cbFrameSize,
Malcolm Priestley351c7dc2013-08-27 12:02:54 +0100970 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestley92928f12013-10-07 20:14:01 +0100971 } else {
972 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
973 tx_head.tx_ab.ab;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +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,
977 wCurrentRate, bNeedACK);
Malcolm Priestleya90186e2013-10-01 15:58:54 +0100978
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100979 return vnt_rxtx_datahead_ab(tx_context, byPktType,
Malcolm Priestley92928f12013-10-07 20:14:01 +0100980 wCurrentRate, &head->data_head_ab,
981 cbFrameSize, bNeedACK);
982 }
Malcolm Priestleyc12dca02013-10-01 16:03:40 +0100983 }
984
Malcolm Priestley0a0f4b62013-10-01 15:50:24 +0100985 return 0;
Forest Bond92b96792009-06-13 07:38:31 -0400986}
987/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500988 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500989 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300990 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400991*/
992
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100993static int s_bPacketToWirelessUsb(struct vnt_usb_send_context *tx_context,
994 u8 byPktType, struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
Malcolm Priestley05cc6172014-04-30 21:31:12 +0100995 u32 uSkbPacketLen, struct ethhdr *psEthHeader,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100996 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
997 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400998{
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +0100999 struct vnt_private *pDevice = tx_context->priv;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001000 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001001 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001002 u32 cb802_1_H_len;
1003 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
1004 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001005 int bNeedACK;
1006 bool bRTS = false;
Malcolm Priestley1622c8f2014-05-31 13:34:58 +01001007 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001008 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1009 u8 abySNAP_Bridgetunnel[ETH_ALEN]
1010 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1011 u32 uDuration;
1012 u32 cbHeaderLength = 0, uPadding = 0;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001013 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001014 u8 byFBOption = AUTO_FB_NONE, byFragType;
Malcolm Priestley4235f722013-08-24 12:42:01 +01001015 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001016 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001017 int bSoftWEP = false;
Malcolm Priestley9e38a5c2013-09-26 18:47:25 +01001018
Malcolm Priestleyc545e6a2013-10-01 16:07:25 +01001019 pMICHDR = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001020
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001021 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001022 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1023 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001024 }
Forest Bond92b96792009-06-13 07:38:31 -04001025
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001026 /* Get pkt type */
1027 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
1028 cb802_1_H_len = 8;
1029 else
1030 cb802_1_H_len = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001031
Charles Clément21ec51f2010-05-18 10:08:14 -07001032 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001033
1034 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001035 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001036
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001037 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC ||
1038 pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001039 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001040 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001041 pTxBufHead->wFIFOCtl =
1042 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1043 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001044 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001045 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1046 }
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001047 } else {
1048 /* MSDUs in Infra mode always need ACK */
1049 bNeedACK = true;
1050 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1051 }
Forest Bond92b96792009-06-13 07:38:31 -04001052
Malcolm Priestley58462512014-03-22 09:01:27 +00001053 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001054
Forest Bond92b96792009-06-13 07:38:31 -04001055 //Set FRAGCTL_MACHDCNT
Malcolm Priestley078d0cf2013-11-25 22:14:16 +00001056 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1057
Andres More3eaca0d2013-02-25 20:32:52 -05001058 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001059
1060 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001061 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001062 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1063 }
1064
Malcolm Priestleyf84cdf62013-10-15 21:00:09 +01001065 /* Set Auto Fallback Ctl */
1066 if (wCurrentRate >= RATE_18M) {
1067 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1068 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1069
1070 pDevice->tx_rate_fb0 =
1071 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1072 pDevice->tx_rate_fb1 =
1073 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1074
1075 byFBOption = AUTO_FB_0;
1076 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1077 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1078 pDevice->tx_rate_fb0 =
1079 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1080 pDevice->tx_rate_fb1 =
1081 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1082
1083 byFBOption = AUTO_FB_1;
1084 }
1085 }
Forest Bond92b96792009-06-13 07:38:31 -04001086
Andres More4e9b5e22013-02-12 20:36:30 -05001087 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001088 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1089 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1090 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1091 }
1092 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1093 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1094 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1095 }
1096 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1097 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1098 }
1099 }
1100 }
1101
Forest Bond92b96792009-06-13 07:38:31 -04001102 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1103 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1104 cbIVlen = 4;
1105 cbICVlen = 4;
1106 }
1107 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1108 cbIVlen = 8;//IV+ExtIV
1109 cbMIClen = 8;
1110 cbICVlen = 4;
1111 }
1112 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1113 cbIVlen = 8;//RSN Header
1114 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001115 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001116 }
Andres Moree269fc22013-02-12 20:36:29 -05001117 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001118 //MAC Header should be padding 0 to DW alignment.
1119 uPadding = 4 - (cbMACHdLen%4);
1120 uPadding %= 4;
1121 }
1122 }
1123
1124 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1125
Andres Moree269fc22013-02-12 20:36:29 -05001126 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1127 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001128 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001129 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001130 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1131 }
1132
Forest Bond92b96792009-06-13 07:38:31 -04001133 //=========================
1134 // No Fragmentation
1135 //=========================
1136 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1137 byFragType = FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001138 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1139
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001140 /* Fill FIFO, RrvTime, RTS and CTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +01001141 uDuration = s_vGenerateTxParameter(tx_context, byPktType, wCurrentRate,
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001142 tx_buffer, &pMICHDR, cbMICHDR,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001143 cbFrameSize, bNeedACK, psEthHeader, bRTS);
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001144
Malcolm Priestley1622c8f2014-05-31 13:34:58 +01001145 cbHeaderLength = tx_context->tx_hdr_size;
1146 if (!cbHeaderLength)
1147 return false;
1148
1149 pbyMacHdr = (u8 *)tx_context->hdr;
1150 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1151 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1152
1153 /* Generate TX MAC Header */
1154 s_vGenerateMACHeader(pDevice, tx_context->hdr, (u16)uDuration,
1155 psEthHeader, bNeedEncryption, byFragType, 0);
Forest Bond92b96792009-06-13 07:38:31 -04001156
Andres More4e9b5e22013-02-12 20:36:30 -05001157 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001158 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001159 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001160 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001161 }
1162
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001163 /* 802.1H */
1164 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001165 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001166 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
Andres Moreb902fbf2013-02-25 20:32:51 -05001167 memcpy((u8 *) (pbyPayloadHead),
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001168 abySNAP_Bridgetunnel, 6);
1169 else
1170 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001171
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001172 pbyType = (u8 *) (pbyPayloadHead + 6);
Forest Bond92b96792009-06-13 07:38:31 -04001173
Malcolm Priestleyc47b0a32013-11-24 11:51:49 +00001174 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1175 }
Forest Bond92b96792009-06-13 07:38:31 -04001176
Forest Bond92b96792009-06-13 07:38:31 -04001177 if (pPacket != NULL) {
1178 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001179 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001180 (pPacket + ETH_HLEN),
1181 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001182 );
1183
1184 } else {
1185 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001186 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001187 }
1188
Andres More4e9b5e22013-02-12 20:36:30 -05001189 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001190
1191 ///////////////////////////////////////////////////////////////////
1192
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001193 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1194 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1195 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1196 }
Forest Bond92b96792009-06-13 07:38:31 -04001197 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001198 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1199 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001200 }
1201 else {
Andres More52a7e642013-02-25 20:32:53 -05001202 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1203 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001204 }
1205 // DO Software Michael
1206 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001207 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001208 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001209 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001210 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1211 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001212
1213 ///////////////////////////////////////////////////////////////////
1214
1215 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1216 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001217 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001218 //}
1219 //DBG_PRN_GRP12(("\n\n\n"));
1220
1221 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1222
Andres More52a7e642013-02-25 20:32:53 -05001223 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1224 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001225
1226 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1227 MIC_vUnInit();
1228
Andres More4e9b5e22013-02-12 20:36:30 -05001229 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001230 *pdwMIC_L = 0;
1231 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001232 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001233 }
1234 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1235 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1236 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1237 }
1238
Andres More4e9b5e22013-02-12 20:36:30 -05001239 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001240
Andres More3eaca0d2013-02-25 20:32:52 -05001241 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001242
Andres More4e9b5e22013-02-12 20:36:30 -05001243 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1244 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1245 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001246 cbFrameSize -= cbICVlen;
1247 }
1248
Forest Bond92b96792009-06-13 07:38:31 -04001249 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001250
1251 *pcbHeaderLen = cbHeaderLength;
1252 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1253
Forest Bond92b96792009-06-13 07:38:31 -04001254 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001255 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001256
Andres More4e9b5e22013-02-12 20:36:30 -05001257 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001258
1259}
1260
Forest Bond92b96792009-06-13 07:38:31 -04001261/*+
1262 *
1263 * Description:
1264 * Translate 802.3 to 802.11 header
1265 *
1266 * Parameters:
1267 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001268 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001269 * dwTxBufferAddr - Transmit Buffer
1270 * pPacket - Packet from upper layer
1271 * cbPacketSize - Transmit Data Length
1272 * Out:
1273 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1274 * pcbAppendPayload - size of append payload for 802.1H translation
1275 *
1276 * Return Value: none
1277 *
1278-*/
1279
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001280static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Malcolm Priestley1622c8f2014-05-31 13:34:58 +01001281 struct ieee80211_hdr *pMACHeader, u16 wDuration,
1282 struct ethhdr *psEthHeader, int bNeedEncrypt, u16 wFragType,
1283 u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001284{
Forest Bond92b96792009-06-13 07:38:31 -04001285
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001286 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001287
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001288 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001289 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001290 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001291 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001292 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1293 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001294 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001295 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001296 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001297 } else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001298 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001299 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001300 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001301 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001302 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001303 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001304 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001305 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001306 &(pDevice->abyBSSID[0]),
1307 ETH_ALEN);
1308 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001309 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001310 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001311 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001312 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001313 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001314 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001315 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001316 &(pDevice->abyBSSID[0]),
1317 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001318 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001319 }
1320 }
1321
1322 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001323 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001324
Andres More1cac4a42013-03-18 20:33:50 -05001325 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001326
Andres More1cac4a42013-03-18 20:33:50 -05001327 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001328
1329 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001330 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001331
1332 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1333 pDevice->wSeqCounter++;
1334 if (pDevice->wSeqCounter > 0x0fff)
1335 pDevice->wSeqCounter = 0;
1336 }
1337
1338 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001339 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001340 }
1341}
1342
Forest Bond92b96792009-06-13 07:38:31 -04001343/*+
1344 *
1345 * Description:
1346 * Request instructs a MAC to transmit a 802.11 management packet through
1347 * the adapter onto the medium.
1348 *
1349 * Parameters:
1350 * In:
1351 * hDeviceContext - Pointer to the adapter
1352 * pPacket - A pointer to a descriptor for the packet to transmit
1353 * Out:
1354 * none
1355 *
Andres Moree269fc22013-02-12 20:36:29 -05001356 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001357 *
1358-*/
1359
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001360CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1361 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001362{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001363 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001364 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001365 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001366 struct vnt_tx_fifo_head *pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001367 struct ieee80211_hdr *pMACHeader;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001368 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001369 u8 byPktType, *pbyTxBufferAddr;
Malcolm Priestleyf0e0d502013-09-26 18:52:10 +01001370 struct vnt_mic_hdr *pMICHDR = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001371 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001372 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001373 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1374 u32 uPadding = 0;
1375 u16 wTxBufSize;
1376 u32 cbMacHdLen;
1377 u16 wCurrentRate = RATE_1M;
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001378 unsigned long flags;
1379
1380 if (pDevice->byBBType == BB_TYPE_11A) {
1381 wCurrentRate = RATE_6M;
1382 byPktType = PK_TYPE_11A;
1383 } else {
1384 wCurrentRate = RATE_1M;
1385 byPktType = PK_TYPE_11B;
1386 }
1387
1388 if (pMgmt->eScanState != WMAC_NO_SCANNING)
Malcolm Priestley4f5290e2014-05-27 21:05:21 +01001389 vnt_rf_setpower(pDevice, wCurrentRate, pDevice->byCurrentCh);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001390 else
Malcolm Priestley4f5290e2014-05-27 21:05:21 +01001391 vnt_rf_setpower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001392
1393 pDevice->wCurrentRate = wCurrentRate;
1394
1395 spin_lock_irqsave(&pDevice->lock, flags);
Forest Bond92b96792009-06-13 07:38:31 -04001396
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001397 pContext = s_vGetFreeContext(pDevice);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001398 if (!pContext) {
1399 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1400 "ManagementSend TX...NO CONTEXT!\n");
1401 spin_unlock_irqrestore(&pDevice->lock, flags);
1402 return CMD_STATUS_RESOURCES;
1403 }
Forest Bond92b96792009-06-13 07:38:31 -04001404
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001405 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0];
Forest Bond92b96792009-06-13 07:38:31 -04001406 cbFrameBodySize = pPacket->cbPayloadLen;
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001407 pTxBufHead = &pTX_Buffer->fifo_head;
1408 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1409 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
Forest Bond92b96792009-06-13 07:38:31 -04001410
Forest Bond92b96792009-06-13 07:38:31 -04001411
Forest Bond92b96792009-06-13 07:38:31 -04001412 //Set packet type
1413 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1414 pTxBufHead->wFIFOCtl = 0;
1415 }
1416 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1417 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1418 }
1419 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1420 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1421 }
1422 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1423 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1424 }
1425
1426 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
Malcolm Priestley58462512014-03-22 09:01:27 +00001427 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
Forest Bond92b96792009-06-13 07:38:31 -04001428
Andres More22040bb2010-08-02 20:21:44 -03001429 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001430 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001431 }
1432 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001433 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001434 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1435 };
1436
1437 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1438 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1439
1440 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1441 //Set Preamble type always long
1442 //pDevice->byPreambleType = PREAMBLE_LONG;
1443 // probe-response don't retry
1444 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001445 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001446 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1447 //}
1448 }
1449
1450 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1451
1452 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001453 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001454 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1455 } else {
1456 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1457 }
1458
1459 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001460 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001461
1462 // Notes:
1463 // Although spec says MMPDU can be fragmented; In most case,
1464 // no one will send a MMPDU under fragmentation. With RTS may occur.
Forest Bond92b96792009-06-13 07:38:31 -04001465
1466 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1467 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1468 cbIVlen = 4;
1469 cbICVlen = 4;
1470 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1471 }
1472 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1473 cbIVlen = 8;//IV+ExtIV
1474 cbMIClen = 8;
1475 cbICVlen = 4;
1476 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1477 //We need to get seed here for filling TxKey entry.
1478 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1479 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1480 }
1481 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1482 cbIVlen = 8;//RSN Header
1483 cbICVlen = 8;//MIC
1484 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Forest Bond92b96792009-06-13 07:38:31 -04001485 }
1486 //MAC Header should be padding 0 to DW alignment.
1487 uPadding = 4 - (cbMacHdLen%4);
1488 uPadding %= 4;
1489 }
1490
1491 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1492
1493 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001494 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001495 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1496 }
1497 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1498
Andres Moreceb8c5d2013-03-18 20:33:49 -05001499 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001500 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1501 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001502 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001503 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1504 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001505 //=========================
1506 // No Fragmentation
1507 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001508 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001509
Malcolm Priestley351c7dc2013-08-27 12:02:54 +01001510 /* Fill FIFO,RrvTime,RTS,and CTS */
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +01001511 uDuration = s_vGenerateTxParameter(pContext, byPktType, wCurrentRate,
Malcolm Priestleyfa575602013-09-26 19:00:41 +01001512 pTX_Buffer, &pMICHDR, 0,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001513 cbFrameSize, bNeedACK, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001514
Malcolm Priestley1622c8f2014-05-31 13:34:58 +01001515 cbHeaderSize = pContext->tx_hdr_size;
1516 if (!cbHeaderSize) {
1517 pContext->in_use = false;
1518 return CMD_STATUS_RESOURCES;
1519 }
1520
1521 pMACHeader = pContext->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001522
1523 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1524
1525 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001526 u8 * pbyIVHead;
1527 u8 * pbyPayloadHead;
1528 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001529 PSKeyItem pTransmitKey = NULL;
1530
Andres Moreb902fbf2013-02-25 20:32:51 -05001531 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1532 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001533 do {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001534 if (pDevice->op_mode == NL80211_IFTYPE_STATION &&
1535 pDevice->bLinkPass == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001536 pbyBSSID = pDevice->abyBSSID;
1537 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001538 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001539 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001540 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001541 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1542 break;
1543 }
1544 } else {
1545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1546 break;
1547 }
1548 }
1549 // get group key
1550 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001551 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001552 pTransmitKey = NULL;
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001553 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->op_mode);
Forest Bond92b96792009-06-13 07:38:31 -04001554 } else {
1555 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1556 }
Andres Moree269fc22013-02-12 20:36:29 -05001557 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001558 //Fill TXKEY
Malcolm Priestley3ba09382013-10-15 21:41:38 +01001559 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001560 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001561
Jim Lieb3e362592009-08-12 14:54:11 -07001562 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001563 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001564 cbFrameBodySize);
1565 }
1566 else {
1567 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001568 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001569 }
1570
Andres More1cac4a42013-03-18 20:33:50 -05001571 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001572 pDevice->wSeqCounter++ ;
1573 if (pDevice->wSeqCounter > 0x0fff)
1574 pDevice->wSeqCounter = 0;
1575
1576 if (bIsPSPOLL) {
1577 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001578 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001579 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1580 // in the same place of other packet's Duration-field).
1581 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001582 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestley78363fd2013-10-01 15:52:16 +01001583 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1584 tx_cts.tx.head.cts_g.data_head;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001585 data_head->duration_a =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001586 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
Malcolm Priestley4e011172014-03-18 19:24:55 +00001587 data_head->duration_b =
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001588 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1589 } else {
Malcolm Priestleyc12dca02013-10-01 16:03:40 +01001590 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1591 tx_ab.tx.head.data_head_ab;
Malcolm Priestley4e011172014-03-18 19:24:55 +00001592 data_head->duration =
Malcolm Priestley558becf2013-08-16 23:50:32 +01001593 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1594 }
Forest Bond92b96792009-06-13 07:38:31 -04001595 }
1596
Malcolm Priestleyca347592014-03-22 09:01:28 +00001597 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001598 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001599 pTX_Buffer->byType = 0x00;
1600
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001601 pContext->skb = NULL;
1602 pContext->type = CONTEXT_MGMT_PACKET;
1603 pContext->buf_len = (u16)cbReqCount + 4; /* USB header */
Forest Bond92b96792009-06-13 07:38:31 -04001604
Andres More1cac4a42013-03-18 20:33:50 -05001605 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001606 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1607 &pMACHeader->addr1[0], (u16)cbFrameSize,
1608 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001609 }
1610 else {
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01001611 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1612 &pMACHeader->addr3[0], (u16)cbFrameSize,
1613 pTxBufHead->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001614 }
1615
1616 PIPEnsSendBulkOut(pDevice,pContext);
Malcolm Priestley931cb9f2014-05-15 22:49:15 +01001617
1618 spin_unlock_irqrestore(&pDevice->lock, flags);
1619
Forest Bond92b96792009-06-13 07:38:31 -04001620 return CMD_STATUS_PENDING;
1621}
1622
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001623CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1624 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001625{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001626 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001627 struct vnt_tx_short_buf_head *short_head;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001628 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1629 u32 cbHeaderSize = 0;
Andres More1cac4a42013-03-18 20:33:50 -05001630 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001631 u16 wCurrentRate;
1632 u32 cbFrameBodySize;
1633 u32 cbReqCount;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001634 struct vnt_usb_send_context *pContext;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001635 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001636
Malcolm Priestleyaceaf012013-11-26 19:06:35 +00001637 pContext = s_vGetFreeContext(pDevice);
Forest Bond92b96792009-06-13 07:38:31 -04001638 if (NULL == pContext) {
1639 status = CMD_STATUS_RESOURCES;
1640 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1641 return status ;
1642 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001643
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001644 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->data[0];
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001645 short_head = &pTX_Buffer->short_head;
Forest Bond92b96792009-06-13 07:38:31 -04001646
1647 cbFrameBodySize = pPacket->cbPayloadLen;
1648
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001649 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
Forest Bond92b96792009-06-13 07:38:31 -04001650
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001651 if (pDevice->byBBType == BB_TYPE_11A) {
1652 wCurrentRate = RATE_6M;
1653
1654 /* Get SignalField,ServiceField,Length */
1655 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1656 PK_TYPE_11A, &short_head->ab);
1657
1658 /* Get Duration and TimeStampOff */
1659 short_head->duration = s_uGetDataDuration(pDevice,
1660 PK_TYPE_11A, false);
1661 short_head->time_stamp_off =
1662 vnt_time_stamp_off(pDevice, wCurrentRate);
1663 } else {
1664 wCurrentRate = RATE_1M;
1665 short_head->fifo_ctl |= FIFOCTL_11B;
1666
1667 /* Get SignalField,ServiceField,Length */
1668 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1669 PK_TYPE_11B, &short_head->ab);
1670
1671 /* Get Duration and TimeStampOff */
1672 short_head->duration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001673 PK_TYPE_11B, false);
Malcolm Priestleyc7c57b22013-11-24 13:25:25 +00001674 short_head->time_stamp_off =
1675 vnt_time_stamp_off(pDevice, wCurrentRate);
1676 }
1677
Forest Bond92b96792009-06-13 07:38:31 -04001678
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001679 /* Generate Beacon Header */
1680 pMACHeader = &pTX_Buffer->hdr;
Forest Bond92b96792009-06-13 07:38:31 -04001681
Malcolm Priestley0b71fe32013-11-24 13:27:32 +00001682 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1683
1684 pMACHeader->duration_id = 0;
1685 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1686 pDevice->wSeqCounter++;
1687 if (pDevice->wSeqCounter > 0x0fff)
1688 pDevice->wSeqCounter = 0;
Forest Bond92b96792009-06-13 07:38:31 -04001689
1690 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1691
Malcolm Priestleyfad8e4a2014-03-22 09:01:29 +00001692 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)cbReqCount);
Andres Moreb902fbf2013-02-25 20:32:51 -05001693 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001694 pTX_Buffer->byType = 0x01;
1695
Malcolm Priestley30a05b32014-05-15 22:49:11 +01001696 pContext->skb = NULL;
1697 pContext->type = CONTEXT_MGMT_PACKET;
1698 pContext->buf_len = (u16)cbReqCount + 4; /* USB header */
Forest Bond92b96792009-06-13 07:38:31 -04001699
1700 PIPEnsSendBulkOut(pDevice,pContext);
1701 return CMD_STATUS_PENDING;
1702
1703}
1704
Forest Bond92b96792009-06-13 07:38:31 -04001705//TYPE_AC0DMA data tx
1706/*
1707 * Description:
1708 * Tx packet via AC0DMA(DMA1)
1709 *
1710 * Parameters:
1711 * In:
1712 * pDevice - Pointer to the adapter
1713 * skb - Pointer to tx skb packet
1714 * Out:
1715 * void
1716 *
1717 * Return Value: NULL
1718 */
1719
Malcolm Priestley05cc6172014-04-30 21:31:12 +01001720int nsDMA_tx_packet(struct vnt_private *pDevice, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04001721{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001722 struct net_device_stats *pStats = &pDevice->stats;
1723 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001724 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001725 u32 BytesToWrite = 0, uHeaderLen = 0;
1726 u32 uNodeIndex = 0;
1727 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1728 u16 wAID;
1729 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05001730 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001731 PSKeyItem pTransmitKey = NULL;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001732 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05001733 int bTKIP_UseGTK = false;
1734 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001735 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05001736 int bNodeExist = false;
Malcolm Priestleydcdf1d02013-08-27 12:41:50 +01001737 struct vnt_usb_send_context *pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05001738 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001739 u32 status;
1740 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05001741 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04001742
Forest Bond92b96792009-06-13 07:38:31 -04001743 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1744
1745 if (pDevice->uAssocCount == 0) {
1746 dev_kfree_skb_irq(skb);
1747 return 0;
1748 }
1749
Andres Moreb902fbf2013-02-25 20:32:51 -05001750 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04001751 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001752 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04001753 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1754
1755 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
1756 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1757 // set tx map
1758 pMgmt->abyPSTxMap[0] |= byMask[0];
1759 return 0;
1760 }
Masanari Iida93184692012-08-13 21:21:50 +09001761 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04001762
1763 if (pDevice->byBBType != BB_TYPE_11A)
1764 pDevice->wCurrentRate = RATE_2M;
1765 else
1766 pDevice->wCurrentRate = RATE_24M;
1767 // long preamble type
1768 pDevice->byPreambleType = PREAMBLE_SHORT;
1769
1770 }else {
1771
Andres Moreb902fbf2013-02-25 20:32:51 -05001772 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04001773
1774 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1775
1776 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1777
1778 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1779 // set tx map
1780 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1781 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1782 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
1783 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
1784
1785 return 0;
1786 }
1787 // AP rate decided from node
1788 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1789 // tx preamble decided from node
1790
1791 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
1792 pDevice->byPreambleType = pDevice->byShortPreamble;
1793
1794 }else {
1795 pDevice->byPreambleType = PREAMBLE_LONG;
1796 }
Andres More4e9b5e22013-02-12 20:36:30 -05001797 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04001798 }
1799 }
1800
Andres Moree269fc22013-02-12 20:36:29 -05001801 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001802 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
1803 dev_kfree_skb_irq(skb);
1804 return 0;
1805 }
1806 }
1807
Tobias Klauser838c2d62014-04-25 11:53:58 +02001808 memcpy(&pDevice->sTxEthHeader, skb->data, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001809
1810//mike add:station mode check eapol-key challenge--->
1811{
Andres Moreb902fbf2013-02-25 20:32:51 -05001812 u8 Protocol_Version; //802.1x Authentication
1813 u8 Packet_Type; //802.1x Authentication
1814 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05001815 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04001816
Charles Clément21ec51f2010-05-18 10:08:14 -07001817 Protocol_Version = skb->data[ETH_HLEN];
1818 Packet_Type = skb->data[ETH_HLEN+1];
1819 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
1820 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 -05001821 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001822 /* 802.1x OR eapol-key challenge frame transfer */
1823 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
1824 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05001825 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04001826 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
1827 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
1828 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05001829 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04001830 PRINT_K("WPA ");
1831 }
1832 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001833 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04001834 PRINT_K("WPA2(re-keying) ");
1835 }
1836 PRINT_K("Authentication completed!!\n");
1837 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001838 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04001839 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05001840 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04001841 PRINT_K("WPA2 Authentication completed!!\n");
1842 }
1843 }
1844 }
1845}
1846//mike add:station mode check eapol-key challenge<---
1847
Andres More4e9b5e22013-02-12 20:36:30 -05001848 if (pDevice->bEncryptionEnable == true) {
1849 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04001850 // get Transmit key
1851 do {
1852 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1853 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1854 pbyBSSID = pDevice->abyBSSID;
1855 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001856 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001857 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001858 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1859 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001860 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
1861 break;
1862 }
1863 } else {
1864 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
1865 break;
1866 }
1867 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001868 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
1869 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04001870 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
1871 for (ii = 0; ii< 6; ii++)
1872 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
1873 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
1874
1875 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05001876 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04001877 break;
1878 }
1879 // get group key
1880 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001881 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001882 pTransmitKey = NULL;
1883 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1884 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
1885 }
1886 else
1887 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
1888 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001889 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001890 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
1891 }
Andres Moree269fc22013-02-12 20:36:29 -05001892 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001893 }
1894
Andres Moreb902fbf2013-02-25 20:32:51 -05001895 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04001896
1897 if (pDevice->bFixRate) {
1898 if (pDevice->byBBType == BB_TYPE_11B) {
1899 if (pDevice->uConnectionRate >= RATE_11M) {
1900 pDevice->wCurrentRate = RATE_11M;
1901 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05001902 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04001903 }
1904 } else {
1905 if ((pDevice->byBBType == BB_TYPE_11A) &&
1906 (pDevice->uConnectionRate <= RATE_6M)) {
1907 pDevice->wCurrentRate = RATE_6M;
1908 } else {
1909 if (pDevice->uConnectionRate >= RATE_54M)
1910 pDevice->wCurrentRate = RATE_54M;
1911 else
Andres More3eaca0d2013-02-25 20:32:52 -05001912 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04001913 }
1914 }
1915 }
1916 else {
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001917 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
Forest Bond92b96792009-06-13 07:38:31 -04001918 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05001919 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04001920 // Multicast use highest data rate
1921 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
1922 // preamble type
1923 pDevice->byPreambleType = pDevice->byShortPreamble;
1924 }
1925 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001926 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04001927 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1928 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
1929 pDevice->byPreambleType = pDevice->byShortPreamble;
1930
1931 }
1932 else {
1933 pDevice->byPreambleType = PREAMBLE_LONG;
1934 }
1935 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
1936 }
1937 else {
1938 if (pDevice->byBBType != BB_TYPE_11A)
1939 pDevice->wCurrentRate = RATE_2M;
1940 else
1941 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
1942 // abyCurrExtSuppRates[]
1943 pDevice->byPreambleType = PREAMBLE_SHORT;
1944 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
1945 }
1946 }
1947 }
Malcolm Priestleya0ad2772014-02-15 21:56:20 +00001948 if (pDevice->op_mode == NL80211_IFTYPE_STATION) {
Forest Bond92b96792009-06-13 07:38:31 -04001949 // Infra STA rate decided from AP Node, index = 0
1950 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
1951 }
1952 }
1953
Andres Moreceb8c5d2013-03-18 20:33:49 -05001954 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001955 if (pDevice->byBBType != BB_TYPE_11A) {
1956 pDevice->wCurrentRate = RATE_1M;
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001957 pDevice->byTopCCKBasicRate = RATE_1M;
1958 pDevice->byTopOFDMBasicRate = RATE_6M;
1959 } else {
1960 pDevice->wCurrentRate = RATE_6M;
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01001961 pDevice->byTopCCKBasicRate = RATE_1M;
1962 pDevice->byTopOFDMBasicRate = RATE_6M;
1963 }
1964 }
Forest Bond92b96792009-06-13 07:38:31 -04001965
Andres More0cbd8d92010-05-06 20:34:29 -03001966 DBG_PRT(MSG_LEVEL_DEBUG,
1967 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
1968 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04001969
1970 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03001971 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001972 }
1973
1974 if (pDevice->wCurrentRate <= RATE_11M) {
1975 byPktType = PK_TYPE_11B;
1976 }
1977
Andres More4e9b5e22013-02-12 20:36:30 -05001978 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001979 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
1980 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05001981 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001982 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04001983 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1984 if (pTransmitKey == NULL) {
1985 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
1986 }
1987 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001988 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001989 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
1990 }
1991 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001992 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
1993 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05001994 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04001995 }
1996 }
1997 }
Forest Bond92b96792009-06-13 07:38:31 -04001998 }
1999 else {
2000
Forest Bond92b96792009-06-13 07:38:31 -04002001 if (pTransmitKey == NULL) {
2002 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2003 dev_kfree_skb_irq(skb);
2004 pStats->tx_dropped++;
2005 return STATUS_FAILURE;
2006 }
Forest Bond92b96792009-06-13 07:38:31 -04002007 }
2008 }
2009
Malcolm Priestleyb674ee12014-05-15 22:49:10 +01002010 pContext = s_vGetFreeContext(pDevice);
2011 if (!pContext) {
2012 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2013 dev_kfree_skb_irq(skb);
2014 return STATUS_RESOURCES;
2015 }
2016
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002017 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0];
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002018
Malcolm Priestleyc2c32da2014-05-31 13:34:57 +01002019 fConvertedPacket = s_bPacketToWirelessUsb(pContext, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002020 pTX_Buffer, bNeedEncryption,
Malcolm Priestley05cc6172014-04-30 21:31:12 +01002021 skb->len, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002022 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002023 pDevice->wCurrentRate,
2024 &uHeaderLen, &BytesToWrite
2025 );
2026
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002027 if (fConvertedPacket == false) {
2028 pContext->in_use = false;
2029 dev_kfree_skb_irq(skb);
2030 return STATUS_FAILURE;
2031 }
Forest Bond92b96792009-06-13 07:38:31 -04002032
Andres More4e9b5e22013-02-12 20:36:30 -05002033 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002034 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002035 bScheduleCommand((void *) pDevice,
2036 WLAN_CMD_MAC_DISPOWERSAVING,
2037 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002038 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002039 }
2040 }
2041
Andres Moreb902fbf2013-02-25 20:32:51 -05002042 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Malcolm Priestleyca347592014-03-22 09:01:28 +00002043 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)BytesToWrite);
Forest Bond92b96792009-06-13 07:38:31 -04002044
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002045 pContext->skb = skb;
2046 pContext->type = CONTEXT_DATA_PACKET;
2047 pContext->buf_len = (u16)BytesToWrite + 4 ; /* USB header */
Forest Bond92b96792009-06-13 07:38:31 -04002048
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002049 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
Malcolm Priestley81aec602014-02-27 23:06:11 +00002050 &pDevice->sTxEthHeader.h_dest[0],
Malcolm Priestleyd66caad2013-09-17 19:54:35 +01002051 (u16)(BytesToWrite-uHeaderLen),
2052 pTX_Buffer->fifo_head.wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002053
2054 status = PIPEnsSendBulkOut(pDevice,pContext);
2055
Andres More4e9b5e22013-02-12 20:36:30 -05002056 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002057 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002058
Andres Moreb902fbf2013-02-25 20:32:51 -05002059 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002060 }
2061
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002062 if (status != STATUS_PENDING) {
2063 pContext->in_use = false;
2064 dev_kfree_skb_irq(skb);
2065 return STATUS_FAILURE;
2066 }
Forest Bond92b96792009-06-13 07:38:31 -04002067
Malcolm Priestley30a05b32014-05-15 22:49:11 +01002068
2069 return 0;
Forest Bond92b96792009-06-13 07:38:31 -04002070}