blob: e97bc4098f89d6a5ff335a51dcd4d3100bfab7bb [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 "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070064
Mariano Reingart4a499de2010-10-29 19:15:26 -030065static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040066
Andres More3eaca0d2013-02-25 20:32:52 -050067const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040068 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
69 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
70 };
71
Andres More3eaca0d2013-02-25 20:32:52 -050072const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040073 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
74 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
75 };
Andres More3eaca0d2013-02-25 20:32:52 -050076const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040077 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
78 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
79 };
80
Forest Bond92b96792009-06-13 07:38:31 -040081#define RTSDUR_BB 0
82#define RTSDUR_BA 1
83#define RTSDUR_AA 2
84#define CTSDUR_BA 3
85#define RTSDUR_BA_F0 4
86#define RTSDUR_AA_F0 5
87#define RTSDUR_BA_F1 6
88#define RTSDUR_AA_F1 7
89#define CTSDUR_BA_F0 8
90#define CTSDUR_BA_F1 9
91#define DATADUR_B 10
92#define DATADUR_A 11
93#define DATADUR_A_F0 12
94#define DATADUR_A_F1 13
95
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000096static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
97 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000099static void *s_vGetFreeContext(struct vnt_private *pDevice);
100
101static void s_vGenerateTxParameter(struct vnt_private *pDevice,
102 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
103 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500104 struct ethhdr *psEthHeader);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000105
106static u32 s_uFillDataHead(struct vnt_private *pDevice,
107 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100108 u32 uDMAIdx, int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400109
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000110static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500111 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000112 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400113
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000114static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
115 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100116 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000118static void s_vSWencryption(struct vnt_private *pDevice,
119 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400120
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000121static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
122 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100124static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000125 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400126
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000127static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
128 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100129 u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400130
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000131static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100132 void *pvRTS, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500133 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400134
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100135static u16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100136 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400137
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100138static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000139 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
140 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400141
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000142static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400143{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000144 PUSB_SEND_CONTEXT pContext = NULL;
145 PUSB_SEND_CONTEXT pReturnContext = NULL;
146 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400147
148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
149
150 for (ii = 0; ii < pDevice->cbTD; ii++) {
151 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500152 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500153 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100154 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400155 pReturnContext = pContext;
156 break;
157 }
158 }
159 if ( ii == pDevice->cbTD ) {
160 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
161 }
Andres More8611a292010-05-01 14:25:00 -0300162 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400163}
164
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000165static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
166 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400167{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000168 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400169
Andres More4b50fb42010-06-22 21:57:42 -0300170 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400171 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300172 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400173 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
174 else
175 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
176
177 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
178 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300179 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
180 pbyDestAddr,
181 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400182}
183
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000184static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
185 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100186 u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400187{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000188 u32 *pdwIV = (u32 *)pbyIVHead;
189 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500190 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000191 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400192
Forest Bond92b96792009-06-13 07:38:31 -0400193 //Fill TXKEY
194 if (pTransmitKey == NULL)
195 return;
196
197 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
198 *pdwIV = pDevice->dwIVCounter;
199 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
200
201 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
202 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
Andres Moreb902fbf2013-02-25 20:32:51 -0500203 memcpy(pDevice->abyPRNG, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700204 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400205 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500206 memcpy(pbyBuf, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700207 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400208 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500209 memcpy(pbyBuf+8, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700210 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400211 }
Jim Lieb3e362592009-08-12 14:54:11 -0700212 memcpy(pDevice->abyPRNG, pbyBuf, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400213 }
214 // Append IV after Mac Header
215 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
Malcolm Priestleyd5bbef72012-11-11 15:53:14 +0000216 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
Forest Bond92b96792009-06-13 07:38:31 -0400217 *pdwIV = cpu_to_le32(*pdwIV);
218 pDevice->dwIVCounter++;
219 if (pDevice->dwIVCounter > WEP_IV_MASK) {
220 pDevice->dwIVCounter = 0;
221 }
222 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
223 pTransmitKey->wTSC15_0++;
224 if (pTransmitKey->wTSC15_0 == 0) {
225 pTransmitKey->dwTSC47_16++;
226 }
227 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
228 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
Jim Lieb3e362592009-08-12 14:54:11 -0700229 memcpy(pbyBuf, pDevice->abyPRNG, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400230 // Make IV
Jim Lieb3e362592009-08-12 14:54:11 -0700231 memcpy(pdwIV, pDevice->abyPRNG, 3);
Forest Bond92b96792009-06-13 07:38:31 -0400232
Andres Moreb902fbf2013-02-25 20:32:51 -0500233 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Forest Bond92b96792009-06-13 07:38:31 -0400234 // Append IV&ExtIV after Mac Header
235 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +0000236 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %x\n",
237 *pdwExtIV);
Forest Bond92b96792009-06-13 07:38:31 -0400238
239 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
240 pTransmitKey->wTSC15_0++;
241 if (pTransmitKey->wTSC15_0 == 0) {
242 pTransmitKey->dwTSC47_16++;
243 }
Jim Lieb3e362592009-08-12 14:54:11 -0700244 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400245
246 // Make IV
247 *pdwIV = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -0500248 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Andres More3eaca0d2013-02-25 20:32:52 -0500249 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
Forest Bond92b96792009-06-13 07:38:31 -0400250 //Append IV&ExtIV after Mac Header
251 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
252
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100253 if (!mic_hdr)
254 return;
Forest Bond92b96792009-06-13 07:38:31 -0400255
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100256 /* MICHDR0 */
257 mic_hdr->id = 0x59;
258 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
259 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400260
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100261 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
262 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
263
264 /* MICHDR1 */
265 if (pDevice->bLongHeader)
266 mic_hdr->hlen = cpu_to_be16(28);
267 else
268 mic_hdr->hlen = cpu_to_be16(22);
269
270 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
271 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
272
273 /* MICHDR2 */
274 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
275 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
276 & 0xc78f);
277 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
278
279 if (pDevice->bLongHeader)
280 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400281 }
282}
283
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000284static void s_vSWencryption(struct vnt_private *pDevice,
285 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400286{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000287 u32 cbICVlen = 4;
288 u32 dwICV = 0xffffffff;
289 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400290
291 if (pTransmitKey == NULL)
292 return;
293
294 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
295 //=======================================================================
296 // Append ICV after payload
297 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500298 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400299 // finally, we must invert dwCRC to get the correct answer
300 *pdwICV = cpu_to_le32(~dwICV);
301 // RC4 encryption
302 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
303 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
304 //=======================================================================
305 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
306 //=======================================================================
307 //Append ICV after payload
308 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500309 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400310 // finally, we must invert dwCRC to get the correct answer
311 *pdwICV = cpu_to_le32(~dwICV);
312 // RC4 encryption
313 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
314 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
315 //=======================================================================
316 }
317}
318
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100319static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
320{
321 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
322 [rate % MAX_RATE]);
323}
324
Forest Bond92b96792009-06-13 07:38:31 -0400325/*byPktType : PK_TYPE_11A 0
326 PK_TYPE_11B 1
327 PK_TYPE_11GB 2
328 PK_TYPE_11GA 3
329*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000330static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
331 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400332{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000333 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400334
335 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
336 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500337 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400338 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500339 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400340 }
341
342 if (bNeedAck) {
343 return (uDataTime + pDevice->uSIFS + uAckTime);
344 }
345 else {
346 return uDataTime;
347 }
348}
349
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100350static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
351 u32 frame_length, u16 rate, int need_ack)
352{
353 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
354 frame_length, rate, need_ack));
355}
356
Forest Bond92b96792009-06-13 07:38:31 -0400357//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100358static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000359 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400360{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000361 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400362
363 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
364
Forest Bond92b96792009-06-13 07:38:31 -0400365 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
366 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
367 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
368 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
369 }
370 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
371 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
372 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
373 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
374 }
375 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
376 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
377 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
378 }
379 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
380 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
381 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
382 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
383 return uRrvTime;
384 }
385
386 //RTSRrvTime
387 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100388 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400389}
390
391//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100392static u16 s_uGetDataDuration(struct vnt_private *pDevice,
393 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400394{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100395 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400396
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100397 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100398 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100399 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
400 byPktType, 14, pDevice->byTopCCKBasicRate);
401 else
402 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
403 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100404 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100405 }
Forest Bond92b96792009-06-13 07:38:31 -0400406
Forest Bond92b96792009-06-13 07:38:31 -0400407 return 0;
408}
409
Forest Bond92b96792009-06-13 07:38:31 -0400410//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100411static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000412 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
413 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400414{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000415 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400416
Forest Bond92b96792009-06-13 07:38:31 -0400417 switch (byDurType) {
418
419 case RTSDUR_BB: //RTSDuration_bb
420 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
421 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
422 break;
423
424 case RTSDUR_BA: //RTSDuration_ba
425 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
426 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
427 break;
428
429 case RTSDUR_AA: //RTSDuration_aa
430 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
431 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
432 break;
433
434 case CTSDUR_BA: //CTSDuration_ba
435 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
436 break;
437
438 case RTSDUR_BA_F0: //RTSDuration_ba_f0
439 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
440 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
441 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
442 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
443 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
444 }
445 break;
446
447 case RTSDUR_AA_F0: //RTSDuration_aa_f0
448 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
449 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
450 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
451 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
452 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
453 }
454 break;
455
456 case RTSDUR_BA_F1: //RTSDuration_ba_f1
457 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
458 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
459 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
460 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
461 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
462 }
463 break;
464
465 case RTSDUR_AA_F1: //RTSDuration_aa_f1
466 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
467 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
468 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
469 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
470 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
471 }
472 break;
473
474 case CTSDUR_BA_F0: //CTSDuration_ba_f0
475 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
476 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
477 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
478 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
479 }
480 break;
481
482 case CTSDUR_BA_F1: //CTSDuration_ba_f1
483 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
484 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
485 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
486 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
487 }
488 break;
489
490 default:
491 break;
492 }
493
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100494 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400495}
496
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000497static u32 s_uFillDataHead(struct vnt_private *pDevice,
498 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100499 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400500{
501
502 if (pTxDataHead == NULL) {
503 return 0;
504 }
505
506 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Forest Bond92b96792009-06-13 07:38:31 -0400507 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +0100508 struct vnt_tx_datahead_g *pBuf =
509 (struct vnt_tx_datahead_g *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400510 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100511 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
512 byPktType, &pBuf->a);
513 BBvCalculateParameter(pDevice, cbFrameLength,
514 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400515 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100516 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100517 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100518 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100519 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400520
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100521 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
522 wCurrentRate);
523 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
524 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400525 return (pBuf->wDuration_a);
526 } else {
527 // Auto Fallback
Malcolm Priestley7c05c542013-08-16 23:49:15 +0100528 struct vnt_tx_datahead_g_fb *pBuf =
529 (struct vnt_tx_datahead_g_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400530 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100531 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
532 byPktType, &pBuf->a);
533 BBvCalculateParameter(pDevice, cbFrameLength,
534 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400535 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100536 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100537 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100538 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100539 PK_TYPE_11B, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100540 pBuf->wDuration_a_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100541 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100542 pBuf->wDuration_a_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100543 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100544 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
545 wCurrentRate);
546 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
547 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400548 return (pBuf->wDuration_a);
549 } //if (byFBOption == AUTO_FB_NONE)
Forest Bond92b96792009-06-13 07:38:31 -0400550 }
551 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100552 if (byFBOption != AUTO_FB_NONE) {
Malcolm Priestley1da4ee22013-08-16 23:51:38 +0100553 struct vnt_tx_datahead_a_fb *pBuf =
554 (struct vnt_tx_datahead_a_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400555 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100556 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
557 byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400558 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100559 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100560 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100561 pBuf->wDuration_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100562 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100563 pBuf->wDuration_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100564 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100565 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
566 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400567 return (pBuf->wDuration);
568 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100569 struct vnt_tx_datahead_ab *pBuf =
570 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400571 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100572 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
573 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400574 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100575 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100576 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100577 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
578 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400579 return (pBuf->wDuration);
580 }
581 }
582 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100583 struct vnt_tx_datahead_ab *pBuf =
584 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400585 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100586 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
587 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400588 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100589 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100590 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100591 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
592 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400593 return (pBuf->wDuration);
594 }
595 return 0;
596}
597
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100598static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
599 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
600 u16 duration)
601{
602 rts->duration = duration;
603 rts->frame_control = TYPE_CTL_RTS;
604
605 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
606 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
607 else
608 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
609
610 if (priv->eOPMode == OP_MODE_AP)
611 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
612 else
613 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
614
615 return 0;
616}
617
618static int vnt_rxtx_rts_g_head(struct vnt_private *priv,
619 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
620 u8 pkt_type, u32 frame_len, int need_ack,
621 u16 current_rate, u8 fb_option)
622{
623 u16 rts_frame_len = 20;
624
625 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
626 PK_TYPE_11B, &buf->b);
627 BBvCalculateParameter(priv, rts_frame_len,
628 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
629
630 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
631 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
632 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
633 pkt_type, current_rate, need_ack, fb_option);
634 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
635 pkt_type, current_rate, need_ack, fb_option);
636
637 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
638
639 return 0;
640}
641
Malcolm Priestleyec917132013-08-26 11:07:46 +0100642static int vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
643 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
644 u8 pkt_type, u32 frame_len, int need_ack,
645 u16 current_rate, u8 fb_option)
646{
647 u16 rts_frame_len = 20;
648
649 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
650 PK_TYPE_11B, &buf->b);
651 BBvCalculateParameter(priv, rts_frame_len,
652 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
653
654
655 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
656 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
657 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
658 pkt_type, current_rate, need_ack, fb_option);
659 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
660 pkt_type, current_rate, need_ack, fb_option);
661
662
663 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
664 frame_len, pkt_type, current_rate, need_ack, fb_option);
665 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
666 frame_len, pkt_type, current_rate, need_ack, fb_option);
667 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
668 frame_len, pkt_type, current_rate, need_ack, fb_option);
669 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
670 frame_len, pkt_type, current_rate, need_ack, fb_option);
671
672 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
673
674 return 0;
675}
676
Malcolm Priestley17126332013-08-26 11:09:38 +0100677static int vnt_rxtx_rts_ab_head(struct vnt_private *priv,
678 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
679 u8 pkt_type, u32 frame_len, int need_ack,
680 u16 current_rate, u8 fb_option)
681{
682 u16 rts_frame_len = 20;
683
684 BBvCalculateParameter(priv, rts_frame_len,
685 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
686
687 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
688 pkt_type, current_rate, need_ack, fb_option);
689
690 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
691
692 return 0;
693}
694
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100695static int vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
696 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
697 u8 pkt_type, u32 frame_len, int need_ack,
698 u16 current_rate, u8 fb_option)
699{
700 u16 rts_frame_len = 20;
701
702 BBvCalculateParameter(priv, rts_frame_len,
703 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
704
705 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
706 pkt_type, current_rate, need_ack, fb_option);
707
708 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
709 frame_len, pkt_type, current_rate, need_ack, fb_option);
710
711 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
712 frame_len, pkt_type, current_rate, need_ack, fb_option);
713
714 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
715
716 return 0;
717}
718
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000719static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100720 void *pvRTS, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500721 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400722{
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100723 union vnt_tx_data_head *head = pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400724
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100725 if (!head)
726 return;
Forest Bond92b96792009-06-13 07:38:31 -0400727
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100728 /* Note: So far RTSHead doesn't appear in ATIM
729 * & Beacom DMA, so we don't need to take them
730 * into account.
731 * Otherwise, we need to modified codes for them.
732 */
733 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
734 if (byFBOption == AUTO_FB_NONE)
735 vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100736 psEthHeader, byPktType, cbFrameLength,
737 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100738 else
739 vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100740 psEthHeader, byPktType, cbFrameLength,
741 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100742 } else if (byPktType == PK_TYPE_11A) {
743 if (byFBOption == AUTO_FB_NONE)
744 vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
745 psEthHeader, byPktType, cbFrameLength,
746 bNeedAck, wCurrentRate, byFBOption);
747 else
748 vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
749 psEthHeader, byPktType, cbFrameLength,
750 bNeedAck, wCurrentRate, byFBOption);
751 } else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100752 vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100753 psEthHeader, byPktType, cbFrameLength,
754 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100755 }
Forest Bond92b96792009-06-13 07:38:31 -0400756}
757
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000758static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
759 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100760 u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400761{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000762 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400763
764 if (pvCTS == NULL) {
765 return;
766 }
767
Forest Bond92b96792009-06-13 07:38:31 -0400768 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100769 if (byFBOption != AUTO_FB_NONE) {
770 /* Auto Fall back */
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100771 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100772 /* Get SignalField,ServiceField,Length */
773 BBvCalculateParameter(pDevice, uCTSFrameLen,
774 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100775 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
776 cbFrameLength, byPktType,
777 wCurrentRate, bNeedAck, byFBOption);
778 /* Get CTSDuration_ba_f0 */
779 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
780 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
781 bNeedAck, byFBOption);
782 /* Get CTSDuration_ba_f1 */
783 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
784 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
785 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100786 /* Get CTS Frame body */
787 pBuf->data.duration = pBuf->wDuration_ba;
788 pBuf->data.frame_control = TYPE_CTL_CTS;
789 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100790 } else {
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100791 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100792 /* Get SignalField,ServiceField,Length */
793 BBvCalculateParameter(pDevice, uCTSFrameLen,
794 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100795 /* Get CTSDuration_ba */
796 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
797 CTSDUR_BA, cbFrameLength, byPktType,
798 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100799 /*Get CTS Frame body*/
800 pBuf->data.duration = pBuf->wDuration_ba;
801 pBuf->data.frame_control = TYPE_CTL_CTS;
802 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400803 }
804 }
805}
806
Forest Bond92b96792009-06-13 07:38:31 -0400807/*+
808 *
809 * Description:
810 * Generate FIFO control for MAC & Baseband controller
811 *
812 * Parameters:
813 * In:
814 * pDevice - Pointer to adpater
815 * pTxDataHead - Transmit Data Buffer
816 * pTxBufHead - pTxBufHead
817 * pvRrvTime - pvRrvTime
818 * pvRTS - RTS Buffer
819 * pCTS - CTS Buffer
820 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
821 * bNeedACK - If need ACK
822 * uDMAIdx - DMA Index
823 * Out:
824 * none
825 *
826 * Return Value: none
827 *
828-*/
Andres Morecc856e62010-05-17 21:34:01 -0300829
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000830static void s_vGenerateTxParameter(struct vnt_private *pDevice,
831 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
832 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500833 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400834{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000835 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
836 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000837 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400838
839 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
840 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
841 pFifoHead->wReserved = wCurrentRate;
842 wFifoCtl = pFifoHead->wFIFOCtl;
843
Forest Bond92b96792009-06-13 07:38:31 -0400844 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
845 byFBOption = AUTO_FB_0;
846 }
847 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
848 byFBOption = AUTO_FB_1;
849 }
850
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100851 if (!pvRrvTime)
852 return;
853
Forest Bond92b96792009-06-13 07:38:31 -0400854 if (pDevice->bLongHeader)
855 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
856
857 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
858
859 if (pvRTS != NULL) { //RTS_need
860 //Fill RsvTime
Malcolm Priestley6398a592013-08-16 21:26:55 +0100861 struct vnt_rrv_time_rts *pBuf =
862 (struct vnt_rrv_time_rts *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100863 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
864 byPktType, cbFrameSize, wCurrentRate);
865 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
866 byPktType, cbFrameSize, wCurrentRate);
867 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
868 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100869 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
870 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
871 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
872 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
873 bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400874 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100875 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
876 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400877 }
878 else {//RTS_needless, PCF mode
Forest Bond92b96792009-06-13 07:38:31 -0400879 //Fill RsvTime
Malcolm Priestley4f990052013-08-16 23:38:57 +0100880 struct vnt_rrv_time_cts *pBuf =
881 (struct vnt_rrv_time_cts *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100882 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
883 cbFrameSize, wCurrentRate, bNeedACK);
884 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
885 PK_TYPE_11B, cbFrameSize,
886 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100887 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
888 byPktType, cbFrameSize, wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400889 //Fill CTS
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100890 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize,
891 bNeedACK, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400892 }
893 }
894 else if (byPktType == PK_TYPE_11A) {
895
896 if (pvRTS != NULL) {//RTS_need, non PCF mode
897 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100898 struct vnt_rrv_time_ab *pBuf =
899 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100900 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
901 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100902 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
903 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400904 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100905 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
906 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400907 }
908 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
909 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100910 struct vnt_rrv_time_ab *pBuf =
911 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100912 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
913 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400914 }
915 }
916 else if (byPktType == PK_TYPE_11B) {
917
918 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
919 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100920 struct vnt_rrv_time_ab *pBuf =
921 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100922 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
923 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100924 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
925 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400926 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100927 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
928 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400929 }
930 else { //RTS_needless, non PCF mode
931 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100932 struct vnt_rrv_time_ab *pBuf =
933 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100934 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
935 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400936 }
937 }
938 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
939}
940/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500941 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500942 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300943 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400944*/
945
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000946static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100947 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
948 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
949 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
950 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400951{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000952 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
953 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000954 u32 cb802_1_H_len;
955 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
956 u32 cbFCSlen = 4, cbMICHDR = 0;
957 int bNeedACK, bRTS;
958 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
959 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
960 u8 abySNAP_Bridgetunnel[ETH_ALEN]
961 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
962 u32 uDuration;
963 u32 cbHeaderLength = 0, uPadding = 0;
964 void *pvRrvTime;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100965 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000966 void *pvRTS;
967 void *pvCTS;
968 void *pvTxDataHd;
969 u8 byFBOption = AUTO_FB_NONE, byFragType;
970 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100971 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000972 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500973 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -0400974
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000975 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400976
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000977 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500978 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
979 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000980 }
Forest Bond92b96792009-06-13 07:38:31 -0400981
Forest Bond92b96792009-06-13 07:38:31 -0400982 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -0500983 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -0400984 if (pDevice->dwDiagRefCount == 0) {
985 cb802_1_H_len = 8;
986 } else {
987 cb802_1_H_len = 2;
988 }
989 } else {
990 cb802_1_H_len = 0;
991 }
992
Charles Clément21ec51f2010-05-18 10:08:14 -0700993 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400994
995 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500996 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400997
998 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -0500999 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001000 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1001 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001002 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1003 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001004 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001005 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001006 pTxBufHead->wFIFOCtl =
1007 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1008 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001009 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001010 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1011 }
Forest Bond92b96792009-06-13 07:38:31 -04001012 }
1013 else {
1014 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001015 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001016 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1017 }
1018 } //if (pDevice->dwDiagRefCount != 0) {
1019
1020 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1021
1022 //Set FIFOCTL_LHEAD
1023 if (pDevice->bLongHeader)
1024 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1025
Forest Bond92b96792009-06-13 07:38:31 -04001026 //Set FRAGCTL_MACHDCNT
1027 if (pDevice->bLongHeader) {
1028 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1029 } else {
1030 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1031 }
Andres More3eaca0d2013-02-25 20:32:52 -05001032 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001033
1034 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001035 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001036 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1037 }
1038
1039 //Set Auto Fallback Ctl
1040 if (wCurrentRate >= RATE_18M) {
1041 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1042 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1043 byFBOption = AUTO_FB_0;
1044 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1045 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1046 byFBOption = AUTO_FB_1;
1047 }
1048 }
1049
Andres More4e9b5e22013-02-12 20:36:30 -05001050 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001051 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1052 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1053 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1054 }
1055 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1056 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1057 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1058 }
1059 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1060 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1061 }
1062 }
1063 }
1064
Forest Bond92b96792009-06-13 07:38:31 -04001065 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1066 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1067 cbIVlen = 4;
1068 cbICVlen = 4;
1069 }
1070 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1071 cbIVlen = 8;//IV+ExtIV
1072 cbMIClen = 8;
1073 cbICVlen = 4;
1074 }
1075 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1076 cbIVlen = 8;//RSN Header
1077 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001078 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001079 }
Andres Moree269fc22013-02-12 20:36:29 -05001080 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001081 //MAC Header should be padding 0 to DW alignment.
1082 uPadding = 4 - (cbMACHdLen%4);
1083 uPadding %= 4;
1084 }
1085 }
1086
1087 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1088
Andres Moree269fc22013-02-12 20:36:29 -05001089 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1090 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001091 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001092 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001093 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1094 }
1095
Andres Moreb902fbf2013-02-25 20:32:51 -05001096 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001097 wTxBufSize = sizeof(STxBufHead);
1098 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1099 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001100 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001101 pvRrvTime = (struct vnt_rrv_time_rts *)
1102 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001103 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001104 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001105 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001106 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001107 pvCTS = NULL;
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001108 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1109 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1110 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001111 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001112 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001113 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001114 }
1115 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001116 pvRrvTime = (struct vnt_rrv_time_cts *)
1117 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001118 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001119 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001120 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001121 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001122 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001123 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1124 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1125 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001126 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1127 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001128 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001129 }
1130 } else {
1131 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001132 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001133 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1134 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001135 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001136 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001137 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001138 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001139 pvCTS = NULL;
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001140 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1141 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1142 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001143 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1144 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001145 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001146 }
Andres Moree269fc22013-02-12 20:36:29 -05001147 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001148 pvRrvTime = (struct vnt_rrv_time_cts *)
1149 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001150 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001151 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001152 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001153 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001154 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001155 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001156 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1157 cbMICHDR + sizeof(struct vnt_cts_fb));
1158 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001159 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001160 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001161 }
1162 } // Auto Fall Back
1163 }
1164 else {//802.11a/b packet
1165 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001166 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001167 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1168 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001169 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001170 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001171 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001172 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001173 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001174 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1175 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001176 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001177 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1178 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001179 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001180 }
Andres Moree269fc22013-02-12 20:36:29 -05001181 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001182 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1183 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001184 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001185 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001186 pvRTS = NULL;
1187 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001188 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1189 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001190 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001191 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001192 }
1193 } else {
1194 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001195 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001196 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1197 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001198 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001199 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001200 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001201 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001202 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001203 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1204 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001205 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001206 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1207 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001208 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001209 }
Andres Moree269fc22013-02-12 20:36:29 -05001210 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001211 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1212 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001213 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001214 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001215 pvRTS = NULL;
1216 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001217 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1218 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001219 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001220 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001221 }
1222 } // Auto Fall Back
1223 }
1224
Andres Moreb902fbf2013-02-25 20:32:51 -05001225 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1226 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1227 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001228
Forest Bond92b96792009-06-13 07:38:31 -04001229 //=========================
1230 // No Fragmentation
1231 //=========================
1232 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1233 byFragType = FRAGCTL_NONFRAG;
1234 //uDMAIdx = TYPE_AC0DMA;
1235 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1236
Forest Bond92b96792009-06-13 07:38:31 -04001237 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001238 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1239 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001240 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1241 //Fill DataHead
1242 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001243 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001244 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001245 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001246 byFragType, uDMAIdx, 0);
1247
Andres More4e9b5e22013-02-12 20:36:30 -05001248 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001249 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001250 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001251 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001252
1253 if (pDevice->bEnableHostWEP) {
1254 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1255 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1256 }
1257 }
1258
1259 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001260 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001261 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001262 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1263 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001264 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001265 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001266 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001267 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001268 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001269 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001270 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001271 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001272 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001273
1274 }
1275
1276 }
1277
Forest Bond92b96792009-06-13 07:38:31 -04001278 if (pPacket != NULL) {
1279 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001280 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001281 (pPacket + ETH_HLEN),
1282 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001283 );
1284
1285 } else {
1286 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001287 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001288 }
1289
Andres More4e9b5e22013-02-12 20:36:30 -05001290 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001291
1292 ///////////////////////////////////////////////////////////////////
1293
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001294 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1295 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1296 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1297 }
Forest Bond92b96792009-06-13 07:38:31 -04001298 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001299 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1300 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001301 }
1302 else {
Andres More52a7e642013-02-25 20:32:53 -05001303 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1304 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001305 }
1306 // DO Software Michael
1307 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001308 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001309 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001310 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001311 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1312 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001313
1314 ///////////////////////////////////////////////////////////////////
1315
1316 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1317 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001318 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001319 //}
1320 //DBG_PRN_GRP12(("\n\n\n"));
1321
1322 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1323
Andres More52a7e642013-02-25 20:32:53 -05001324 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1325 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001326
1327 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1328 MIC_vUnInit();
1329
Andres More4e9b5e22013-02-12 20:36:30 -05001330 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001331 *pdwMIC_L = 0;
1332 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001333 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001334 }
1335 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1336 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1337 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1338 }
1339
Andres More4e9b5e22013-02-12 20:36:30 -05001340 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001341
Andres More3eaca0d2013-02-25 20:32:52 -05001342 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001343
Andres More4e9b5e22013-02-12 20:36:30 -05001344 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1345 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1346 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001347 cbFrameSize -= cbICVlen;
1348 }
1349
Forest Bond92b96792009-06-13 07:38:31 -04001350 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001351
1352 *pcbHeaderLen = cbHeaderLength;
1353 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1354
Forest Bond92b96792009-06-13 07:38:31 -04001355 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001356 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001357
Andres More4e9b5e22013-02-12 20:36:30 -05001358 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001359
1360}
1361
Forest Bond92b96792009-06-13 07:38:31 -04001362/*+
1363 *
1364 * Description:
1365 * Translate 802.3 to 802.11 header
1366 *
1367 * Parameters:
1368 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001369 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001370 * dwTxBufferAddr - Transmit Buffer
1371 * pPacket - Packet from upper layer
1372 * cbPacketSize - Transmit Data Length
1373 * Out:
1374 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1375 * pcbAppendPayload - size of append payload for 802.1H translation
1376 *
1377 * Return Value: none
1378 *
1379-*/
1380
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001381static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001382 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001383 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001384{
Andres More1cac4a42013-03-18 20:33:50 -05001385 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001386
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001387 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001388
1389 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001390 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001391 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001392 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001393 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1394 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001395 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001396 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001397 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001398 } else {
1399 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001400 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001401 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001402 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001403 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001404 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001405 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001406 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001407 &(pDevice->abyBSSID[0]),
1408 ETH_ALEN);
1409 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001410 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001411 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001412 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001413 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001414 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001415 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001416 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001417 &(pDevice->abyBSSID[0]),
1418 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001419 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001420 }
1421 }
1422
1423 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001424 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001425
Andres More1cac4a42013-03-18 20:33:50 -05001426 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001427
1428 if (pDevice->bLongHeader) {
1429 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001430 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001431 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001432 }
Andres More1cac4a42013-03-18 20:33:50 -05001433 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001434
1435 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001436 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001437
1438 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1439 pDevice->wSeqCounter++;
1440 if (pDevice->wSeqCounter > 0x0fff)
1441 pDevice->wSeqCounter = 0;
1442 }
1443
1444 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001445 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001446 }
1447}
1448
Forest Bond92b96792009-06-13 07:38:31 -04001449/*+
1450 *
1451 * Description:
1452 * Request instructs a MAC to transmit a 802.11 management packet through
1453 * the adapter onto the medium.
1454 *
1455 * Parameters:
1456 * In:
1457 * hDeviceContext - Pointer to the adapter
1458 * pPacket - A pointer to a descriptor for the packet to transmit
1459 * Out:
1460 * none
1461 *
Andres Moree269fc22013-02-12 20:36:29 -05001462 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001463 *
1464-*/
1465
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001466CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1467 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001468{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001469 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001470 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001471 PSTxBufHead pTxBufHead;
1472 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001473 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001474 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001475 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001476 u8 byPktType, *pbyTxBufferAddr;
1477 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1478 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001479 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001480 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1481 u32 uPadding = 0;
1482 u16 wTxBufSize;
1483 u32 cbMacHdLen;
1484 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001485
Forest Bond92b96792009-06-13 07:38:31 -04001486 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1487
1488 if (NULL == pContext) {
1489 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1490 return CMD_STATUS_RESOURCES;
1491 }
1492
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001493 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001494 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001495 cbFrameBodySize = pPacket->cbPayloadLen;
1496 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1497 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001498
1499 if (pDevice->byBBType == BB_TYPE_11A) {
1500 wCurrentRate = RATE_6M;
1501 byPktType = PK_TYPE_11A;
1502 } else {
1503 wCurrentRate = RATE_1M;
1504 byPktType = PK_TYPE_11B;
1505 }
1506
1507 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1508 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1509 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1510 // to set power here.
1511 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1512 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1513 } else {
1514 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1515 }
1516 pDevice->wCurrentRate = wCurrentRate;
1517
Forest Bond92b96792009-06-13 07:38:31 -04001518 //Set packet type
1519 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1520 pTxBufHead->wFIFOCtl = 0;
1521 }
1522 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1523 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1524 }
1525 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1526 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1527 }
1528 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1529 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1530 }
1531
1532 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1533 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1534
Andres More22040bb2010-08-02 20:21:44 -03001535 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001536 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001537 }
1538 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001539 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001540 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1541 };
1542
1543 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1544 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1545
1546 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1547 //Set Preamble type always long
1548 //pDevice->byPreambleType = PREAMBLE_LONG;
1549 // probe-response don't retry
1550 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001551 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001552 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1553 //}
1554 }
1555
1556 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1557
1558 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001559 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001560 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1561 } else {
1562 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1563 }
1564
1565 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001566 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001567
1568 // Notes:
1569 // Although spec says MMPDU can be fragmented; In most case,
1570 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001571 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001572
1573 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1574 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1575 cbIVlen = 4;
1576 cbICVlen = 4;
1577 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1578 }
1579 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1580 cbIVlen = 8;//IV+ExtIV
1581 cbMIClen = 8;
1582 cbICVlen = 4;
1583 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1584 //We need to get seed here for filling TxKey entry.
1585 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1586 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1587 }
1588 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1589 cbIVlen = 8;//RSN Header
1590 cbICVlen = 8;//MIC
1591 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001592 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001593 }
1594 //MAC Header should be padding 0 to DW alignment.
1595 uPadding = 4 - (cbMacHdLen%4);
1596 uPadding %= 4;
1597 }
1598
1599 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1600
1601 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001602 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001603 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1604 }
1605 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1606
1607 //Set RrvTime/RTS/CTS Buffer
1608 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1609
Malcolm Priestley4f990052013-08-16 23:38:57 +01001610 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001611 pMICHDR = NULL;
1612 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001613 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001614 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001615 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001616 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1617 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001618 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001619 }
1620 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001621 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001622 pMICHDR = NULL;
1623 pvRTS = NULL;
1624 pCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001625 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1626 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001627 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001628 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001629 }
1630
Andres Moreceb8c5d2013-03-18 20:33:49 -05001631 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001632 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1633 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001634 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001635 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1636 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001637 //=========================
1638 // No Fragmentation
1639 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001640 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001641
Forest Bond92b96792009-06-13 07:38:31 -04001642 //Fill FIFO,RrvTime,RTS,and CTS
1643 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1644 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1645
1646 //Fill DataHead
1647 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001648 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001649
Andres More1cac4a42013-03-18 20:33:50 -05001650 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001651
1652 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1653
1654 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001655 u8 * pbyIVHead;
1656 u8 * pbyPayloadHead;
1657 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001658 PSKeyItem pTransmitKey = NULL;
1659
Andres Moreb902fbf2013-02-25 20:32:51 -05001660 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1661 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001662 do {
1663 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001664 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001665 pbyBSSID = pDevice->abyBSSID;
1666 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001667 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001668 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001669 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001670 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1671 break;
1672 }
1673 } else {
1674 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1675 break;
1676 }
1677 }
1678 // get group key
1679 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001680 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001681 pTransmitKey = NULL;
1682 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1683 } else {
1684 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1685 }
Andres Moree269fc22013-02-12 20:36:29 -05001686 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001687 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001688 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001689 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001690
Jim Lieb3e362592009-08-12 14:54:11 -07001691 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001692 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001693 cbFrameBodySize);
1694 }
1695 else {
1696 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001697 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001698 }
1699
Andres More1cac4a42013-03-18 20:33:50 -05001700 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001701 pDevice->wSeqCounter++ ;
1702 if (pDevice->wSeqCounter > 0x0fff)
1703 pDevice->wSeqCounter = 0;
1704
1705 if (bIsPSPOLL) {
1706 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001707 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001708 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1709 // in the same place of other packet's Duration-field).
1710 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001711 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1712 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1713 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1714 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1715 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1716 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001717 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1718 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1719 }
Forest Bond92b96792009-06-13 07:38:31 -04001720 }
1721
Andres More3eaca0d2013-02-25 20:32:52 -05001722 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001723 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001724 pTX_Buffer->byType = 0x00;
1725
1726 pContext->pPacket = NULL;
1727 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001728 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001729
Andres More1cac4a42013-03-18 20:33:50 -05001730 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1731 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001732 }
1733 else {
Andres More1cac4a42013-03-18 20:33:50 -05001734 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001735 }
1736
1737 PIPEnsSendBulkOut(pDevice,pContext);
1738 return CMD_STATUS_PENDING;
1739}
1740
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001741CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1742 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001743{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001744 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001745 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1746 u32 cbHeaderSize = 0;
1747 u16 wTxBufSize = sizeof(STxShortBufHead);
1748 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001749 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001750 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001751 u16 wCurrentRate;
1752 u32 cbFrameBodySize;
1753 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001754 u8 *pbyTxBufferAddr;
1755 PUSB_SEND_CONTEXT pContext;
1756 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001757
Forest Bond92b96792009-06-13 07:38:31 -04001758 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1759 if (NULL == pContext) {
1760 status = CMD_STATUS_RESOURCES;
1761 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1762 return status ;
1763 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001764
1765 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001766 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001767
1768 cbFrameBodySize = pPacket->cbPayloadLen;
1769
1770 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1771 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001772
1773 if (pDevice->byBBType == BB_TYPE_11A) {
1774 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001775 pTxDataHead = (struct vnt_tx_datahead_ab *)
1776 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001777 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001778 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1779 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001780 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001781 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001782 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001783 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001784 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001785 } else {
1786 wCurrentRate = RATE_1M;
1787 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001788 pTxDataHead = (struct vnt_tx_datahead_ab *)
1789 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001790 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001791 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1792 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001793 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001794 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001795 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001796 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001797 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001798 }
1799
1800 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001801 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001802 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001803
Andres More1cac4a42013-03-18 20:33:50 -05001804 pMACHeader->duration_id = 0;
1805 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001806 pDevice->wSeqCounter++ ;
1807 if (pDevice->wSeqCounter > 0x0fff)
1808 pDevice->wSeqCounter = 0;
1809
1810 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1811
Andres More3eaca0d2013-02-25 20:32:52 -05001812 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001813 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001814 pTX_Buffer->byType = 0x01;
1815
1816 pContext->pPacket = NULL;
1817 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001818 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001819
1820 PIPEnsSendBulkOut(pDevice,pContext);
1821 return CMD_STATUS_PENDING;
1822
1823}
1824
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001825void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1826{
1827 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001828 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001829 u8 byPktType;
1830 u8 *pbyTxBufferAddr;
1831 void *pvRTS, *pvCTS, *pvTxDataHd;
1832 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001833 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001834 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001835 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001836 PSTxBufHead pTxBufHead;
1837 u32 cbFrameSize;
1838 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1839 u32 uPadding = 0;
1840 u32 cbMICHDR = 0, uLength = 0;
1841 u32 dwMICKey0, dwMICKey1;
1842 u32 dwMIC_Priority;
1843 u32 *pdwMIC_L, *pdwMIC_R;
1844 u16 wTxBufSize;
1845 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001846 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001847 void *pvRrvTime, *pMICHDR;
1848 u32 wCurrentRate = RATE_1M;
1849 PUWLAN_80211HDR p80211Header;
1850 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001851 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001852 SKeyItem STempKey;
1853 PSKeyItem pTransmitKey = NULL;
1854 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1855 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001856 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001857
Forest Bond92b96792009-06-13 07:38:31 -04001858 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1859
1860 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1861 cbFrameBodySize = 0;
1862 }
1863 else {
1864 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1865 }
1866 p80211Header = (PUWLAN_80211HDR)skb->data;
1867
1868 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1869
1870 if (NULL == pContext) {
1871 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1872 dev_kfree_skb_irq(skb);
1873 return ;
1874 }
1875
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001876 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001877 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001878 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1879 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001880
1881 if (pDevice->byBBType == BB_TYPE_11A) {
1882 wCurrentRate = RATE_6M;
1883 byPktType = PK_TYPE_11A;
1884 } else {
1885 wCurrentRate = RATE_1M;
1886 byPktType = PK_TYPE_11B;
1887 }
1888
1889 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1890 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1891 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1892 // to set power here.
1893 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1894 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1895 } else {
1896 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1897 }
1898
1899 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1900
1901 //Set packet type
1902 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1903 pTxBufHead->wFIFOCtl = 0;
1904 }
1905 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1906 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1907 }
1908 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1909 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1910 }
1911 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1912 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1913 }
1914
1915 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1916 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1917
Andres More22040bb2010-08-02 20:21:44 -03001918 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001919 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001920 if (pDevice->bEnableHostWEP) {
1921 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001922 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001923 }
Forest Bond92b96792009-06-13 07:38:31 -04001924 }
1925 else {
1926 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001927 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001928 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001929 }
Andres More4e9b5e22013-02-12 20:36:30 -05001930 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001931 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1932 };
1933
1934 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1935 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1936
1937 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1938 //Set Preamble type always long
1939 //pDevice->byPreambleType = PREAMBLE_LONG;
1940
1941 // probe-response don't retry
1942 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001943 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001944 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1945 //}
1946 }
1947
1948 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1949
1950 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001951 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001952 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1953 } else {
1954 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1955 }
1956
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001957 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001958 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1959
1960 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1961 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1962 }
1963
1964 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1965 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1966 }
1967
1968 if (cbExtSuppRate >0) {
1969 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1970 }
1971 }
1972
Forest Bond92b96792009-06-13 07:38:31 -04001973 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001974 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001975
1976 // Notes:
1977 // Although spec says MMPDU can be fragmented; In most case,
1978 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001979 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001980
Forest Bond92b96792009-06-13 07:38:31 -04001981 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1982 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1983 cbIVlen = 4;
1984 cbICVlen = 4;
1985 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1986 }
1987 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1988 cbIVlen = 8;//IV+ExtIV
1989 cbMIClen = 8;
1990 cbICVlen = 4;
1991 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1992 //We need to get seed here for filling TxKey entry.
1993 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1994 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1995 }
1996 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1997 cbIVlen = 8;//RSN Header
1998 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001999 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04002000 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002001 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002002 }
2003 //MAC Header should be padding 0 to DW alignment.
2004 uPadding = 4 - (cbMacHdLen%4);
2005 uPadding %= 4;
2006 }
2007
2008 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2009
2010 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002011 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002012 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2013 }
2014 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2015
Forest Bond92b96792009-06-13 07:38:31 -04002016 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002017 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002018 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002019 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002020 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002021 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002022 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002023 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2024 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002025 sizeof(struct vnt_cts));
2026 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002027 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002028
2029 }
2030 else {//802.11a/b packet
2031
Malcolm Priestley976467d2013-08-16 23:44:04 +01002032 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002033 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01002034 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002035 pvRTS = NULL;
2036 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01002037 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2038 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002039 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002040 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002041 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002042 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002043 &(p80211Header->sA3.abyAddr1[0]),
2044 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002045 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002046 &(p80211Header->sA3.abyAddr2[0]),
2047 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002048 //=========================
2049 // No Fragmentation
2050 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002051 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002052
Forest Bond92b96792009-06-13 07:38:31 -04002053 //Fill FIFO,RrvTime,RTS,and CTS
2054 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2055 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2056
2057 //Fill DataHead
2058 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002059 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002060
Andres More1cac4a42013-03-18 20:33:50 -05002061 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002062
2063 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2064
Andres Moreb902fbf2013-02-25 20:32:51 -05002065 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2066 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2067 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002068
2069 // Copy the Packet into a tx Buffer
2070 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2071
2072 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002073 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002074 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2075
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002076 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002077 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2078 if (cbExtSuppRate != 0) {
2079 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2080 memcpy((pbyPayloadHead + cbFrameBodySize),
2081 pMgmt->abyCurrSuppRates,
2082 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2083 );
2084 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2085 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2086 pMgmt->abyCurrExtSuppRates,
2087 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2088 );
2089 }
2090 }
2091
2092 // Set wep
2093 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2094
2095 if (pDevice->bEnableHostWEP) {
2096 pTransmitKey = &STempKey;
2097 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2098 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2099 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2100 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2101 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2102 memcpy(pTransmitKey->abyKey,
2103 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2104 pTransmitKey->uKeyLength
2105 );
2106 }
2107
2108 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2109
Andres More52a7e642013-02-25 20:32:53 -05002110 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2111 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002112
2113 // DO Software Michael
2114 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002115 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002116 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002117 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002118 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2119 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002120
2121 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2122
2123 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2124
Andres More52a7e642013-02-25 20:32:53 -05002125 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2126 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002127
2128 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2129 MIC_vUnInit();
2130
Andres More4e9b5e22013-02-12 20:36:30 -05002131 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002132 *pdwMIC_L = 0;
2133 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002134 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002135 }
2136
2137 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2138 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002139 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2140 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002141
2142 }
2143
Andres Moreb902fbf2013-02-25 20:32:51 -05002144 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002145 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002146
2147 if (pDevice->bEnableHostWEP) {
2148 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2149 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2150 }
2151
2152 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002153 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002154 }
2155 }
2156
Andres More1cac4a42013-03-18 20:33:50 -05002157 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002158 pDevice->wSeqCounter++ ;
2159 if (pDevice->wSeqCounter > 0x0fff)
2160 pDevice->wSeqCounter = 0;
2161
Forest Bond92b96792009-06-13 07:38:31 -04002162 if (bIsPSPOLL) {
2163 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2164 // of FIFO control header.
2165 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2166 // in the same place of other packet's Duration-field).
2167 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002168 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2169 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2170 cpu_to_le16(p80211Header->sA2.wDurationID);
2171 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2172 cpu_to_le16(p80211Header->sA2.wDurationID);
2173 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002174 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2175 cpu_to_le16(p80211Header->sA2.wDurationID);
2176 }
Forest Bond92b96792009-06-13 07:38:31 -04002177 }
2178
Andres More3eaca0d2013-02-25 20:32:52 -05002179 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002180 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002181 pTX_Buffer->byType = 0x00;
2182
2183 pContext->pPacket = skb;
2184 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002185 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002186
Andres More1cac4a42013-03-18 20:33:50 -05002187 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2188 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002189 }
2190 else {
Andres More1cac4a42013-03-18 20:33:50 -05002191 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002192 }
2193 PIPEnsSendBulkOut(pDevice,pContext);
2194 return ;
2195
2196}
2197
Forest Bond92b96792009-06-13 07:38:31 -04002198//TYPE_AC0DMA data tx
2199/*
2200 * Description:
2201 * Tx packet via AC0DMA(DMA1)
2202 *
2203 * Parameters:
2204 * In:
2205 * pDevice - Pointer to the adapter
2206 * skb - Pointer to tx skb packet
2207 * Out:
2208 * void
2209 *
2210 * Return Value: NULL
2211 */
2212
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002213int nsDMA_tx_packet(struct vnt_private *pDevice,
2214 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002215{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002216 struct net_device_stats *pStats = &pDevice->stats;
2217 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002218 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002219 u32 BytesToWrite = 0, uHeaderLen = 0;
2220 u32 uNodeIndex = 0;
2221 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2222 u16 wAID;
2223 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002224 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002225 PSKeyItem pTransmitKey = NULL;
2226 SKeyItem STempKey;
2227 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002228 int bTKIP_UseGTK = false;
2229 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002230 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002231 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002232 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002233 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002234 u32 status;
2235 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002236 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002237
Forest Bond92b96792009-06-13 07:38:31 -04002238 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2239
2240 if (pDevice->uAssocCount == 0) {
2241 dev_kfree_skb_irq(skb);
2242 return 0;
2243 }
2244
Andres Moreb902fbf2013-02-25 20:32:51 -05002245 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002246 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002247 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002248 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2249
2250 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2251 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2252 // set tx map
2253 pMgmt->abyPSTxMap[0] |= byMask[0];
2254 return 0;
2255 }
Masanari Iida93184692012-08-13 21:21:50 +09002256 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002257
2258 if (pDevice->byBBType != BB_TYPE_11A)
2259 pDevice->wCurrentRate = RATE_2M;
2260 else
2261 pDevice->wCurrentRate = RATE_24M;
2262 // long preamble type
2263 pDevice->byPreambleType = PREAMBLE_SHORT;
2264
2265 }else {
2266
Andres Moreb902fbf2013-02-25 20:32:51 -05002267 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002268
2269 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2270
2271 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2272
2273 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2274 // set tx map
2275 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2276 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2277 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2278 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2279
2280 return 0;
2281 }
2282 // AP rate decided from node
2283 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2284 // tx preamble decided from node
2285
2286 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2287 pDevice->byPreambleType = pDevice->byShortPreamble;
2288
2289 }else {
2290 pDevice->byPreambleType = PREAMBLE_LONG;
2291 }
Andres More4e9b5e22013-02-12 20:36:30 -05002292 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002293 }
2294 }
2295
Andres Moree269fc22013-02-12 20:36:29 -05002296 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002297 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2298 dev_kfree_skb_irq(skb);
2299 return 0;
2300 }
2301 }
2302
2303 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2304
2305 if (pContext == NULL) {
2306 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2307 dev_kfree_skb_irq(skb);
2308 return STATUS_RESOURCES;
2309 }
2310
Andres Moreceb8c5d2013-03-18 20:33:49 -05002311 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002312
2313//mike add:station mode check eapol-key challenge--->
2314{
Andres Moreb902fbf2013-02-25 20:32:51 -05002315 u8 Protocol_Version; //802.1x Authentication
2316 u8 Packet_Type; //802.1x Authentication
2317 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002318 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002319
Charles Clément21ec51f2010-05-18 10:08:14 -07002320 Protocol_Version = skb->data[ETH_HLEN];
2321 Packet_Type = skb->data[ETH_HLEN+1];
2322 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2323 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 -05002324 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002325 /* 802.1x OR eapol-key challenge frame transfer */
2326 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2327 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002328 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002329 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2330 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2331 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002332 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002333 PRINT_K("WPA ");
2334 }
2335 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002336 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002337 PRINT_K("WPA2(re-keying) ");
2338 }
2339 PRINT_K("Authentication completed!!\n");
2340 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002341 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002342 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002343 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002344 PRINT_K("WPA2 Authentication completed!!\n");
2345 }
2346 }
2347 }
2348}
2349//mike add:station mode check eapol-key challenge<---
2350
Andres More4e9b5e22013-02-12 20:36:30 -05002351 if (pDevice->bEncryptionEnable == true) {
2352 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002353 // get Transmit key
2354 do {
2355 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2356 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2357 pbyBSSID = pDevice->abyBSSID;
2358 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002359 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002360 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002361 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2362 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002363 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2364 break;
2365 }
2366 } else {
2367 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2368 break;
2369 }
2370 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002371 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2372 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002373 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2374 for (ii = 0; ii< 6; ii++)
2375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2377
2378 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002379 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002380 break;
2381 }
2382 // get group key
2383 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002384 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002385 pTransmitKey = NULL;
2386 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2387 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2388 }
2389 else
2390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2391 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002392 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002393 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2394 }
Andres Moree269fc22013-02-12 20:36:29 -05002395 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002396 }
2397
2398 if (pDevice->bEnableHostWEP) {
2399 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002400 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002401 pTransmitKey = &STempKey;
2402 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2403 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2404 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2405 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2406 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2407 memcpy(pTransmitKey->abyKey,
2408 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2409 pTransmitKey->uKeyLength
2410 );
2411 }
2412 }
2413
Andres Moreb902fbf2013-02-25 20:32:51 -05002414 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002415
2416 if (pDevice->bFixRate) {
2417 if (pDevice->byBBType == BB_TYPE_11B) {
2418 if (pDevice->uConnectionRate >= RATE_11M) {
2419 pDevice->wCurrentRate = RATE_11M;
2420 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002421 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002422 }
2423 } else {
2424 if ((pDevice->byBBType == BB_TYPE_11A) &&
2425 (pDevice->uConnectionRate <= RATE_6M)) {
2426 pDevice->wCurrentRate = RATE_6M;
2427 } else {
2428 if (pDevice->uConnectionRate >= RATE_54M)
2429 pDevice->wCurrentRate = RATE_54M;
2430 else
Andres More3eaca0d2013-02-25 20:32:52 -05002431 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002432 }
2433 }
2434 }
2435 else {
2436 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2437 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002438 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002439 // Multicast use highest data rate
2440 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2441 // preamble type
2442 pDevice->byPreambleType = pDevice->byShortPreamble;
2443 }
2444 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002445 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002446 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2447 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2448 pDevice->byPreambleType = pDevice->byShortPreamble;
2449
2450 }
2451 else {
2452 pDevice->byPreambleType = PREAMBLE_LONG;
2453 }
2454 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2455 }
2456 else {
2457 if (pDevice->byBBType != BB_TYPE_11A)
2458 pDevice->wCurrentRate = RATE_2M;
2459 else
2460 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2461 // abyCurrExtSuppRates[]
2462 pDevice->byPreambleType = PREAMBLE_SHORT;
2463 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2464 }
2465 }
2466 }
2467 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2468 // Infra STA rate decided from AP Node, index = 0
2469 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2470 }
2471 }
2472
Andres Moreceb8c5d2013-03-18 20:33:49 -05002473 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002474 if (pDevice->byBBType != BB_TYPE_11A) {
2475 pDevice->wCurrentRate = RATE_1M;
2476 pDevice->byACKRate = RATE_1M;
2477 pDevice->byTopCCKBasicRate = RATE_1M;
2478 pDevice->byTopOFDMBasicRate = RATE_6M;
2479 } else {
2480 pDevice->wCurrentRate = RATE_6M;
2481 pDevice->byACKRate = RATE_6M;
2482 pDevice->byTopCCKBasicRate = RATE_1M;
2483 pDevice->byTopOFDMBasicRate = RATE_6M;
2484 }
2485 }
Forest Bond92b96792009-06-13 07:38:31 -04002486
Andres More0cbd8d92010-05-06 20:34:29 -03002487 DBG_PRT(MSG_LEVEL_DEBUG,
2488 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2489 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002490
2491 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002492 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002493 }
2494
2495 if (pDevice->wCurrentRate <= RATE_11M) {
2496 byPktType = PK_TYPE_11B;
2497 }
2498
Andres More4e9b5e22013-02-12 20:36:30 -05002499 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002500 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2501 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002502 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002503 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002504 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2505 if (pTransmitKey == NULL) {
2506 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2507 }
2508 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002509 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002510 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2511 }
2512 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002513 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2514 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002515 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002516 }
2517 }
2518 }
2519
Forest Bond92b96792009-06-13 07:38:31 -04002520 if (pDevice->bEnableHostWEP) {
2521 if ((uNodeIndex != 0) &&
2522 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002523 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2524 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002525 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002526 }
2527 }
2528 }
2529 else {
2530
Forest Bond92b96792009-06-13 07:38:31 -04002531 if (pTransmitKey == NULL) {
2532 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002533 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002534 dev_kfree_skb_irq(skb);
2535 pStats->tx_dropped++;
2536 return STATUS_FAILURE;
2537 }
Forest Bond92b96792009-06-13 07:38:31 -04002538 }
2539 }
2540
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002541 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2542
Forest Bond92b96792009-06-13 07:38:31 -04002543 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002544 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002545 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002546 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002547 pDevice->wCurrentRate,
2548 &uHeaderLen, &BytesToWrite
2549 );
2550
Andres Moree269fc22013-02-12 20:36:29 -05002551 if (fConvertedPacket == false) {
2552 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002553 dev_kfree_skb_irq(skb);
2554 return STATUS_FAILURE;
2555 }
2556
Andres More4e9b5e22013-02-12 20:36:30 -05002557 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002558 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002559 bScheduleCommand((void *) pDevice,
2560 WLAN_CMD_MAC_DISPOWERSAVING,
2561 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002562 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002563 }
2564 }
2565
Andres Moreb902fbf2013-02-25 20:32:51 -05002566 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002567 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002568
2569 pContext->pPacket = skb;
2570 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002571 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002572
Andres Moreceb8c5d2013-03-18 20:33:49 -05002573 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.h_dest[0]), (u16) (BytesToWrite-uHeaderLen), pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002574
2575 status = PIPEnsSendBulkOut(pDevice,pContext);
2576
Andres More4e9b5e22013-02-12 20:36:30 -05002577 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002578 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002579
Andres Moreb902fbf2013-02-25 20:32:51 -05002580 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002581 }
2582
2583 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002584 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002585 dev_kfree_skb_irq(skb);
2586 return STATUS_FAILURE;
2587 }
2588 else
2589 return 0;
2590
2591}
2592
Forest Bond92b96792009-06-13 07:38:31 -04002593/*
2594 * Description:
2595 * Relay packet send (AC1DMA) from rx dpc.
2596 *
2597 * Parameters:
2598 * In:
2599 * pDevice - Pointer to the adapter
2600 * pPacket - Pointer to rx packet
2601 * cbPacketSize - rx ethernet frame size
2602 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002603 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002604 *
Andres More4e9b5e22013-02-12 20:36:30 -05002605 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002606 */
2607
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002608int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2609 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002610{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002611 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002612 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002613 u32 BytesToWrite = 0, uHeaderLen = 0;
2614 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002615 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002616 SKeyItem STempKey;
2617 PSKeyItem pTransmitKey = NULL;
2618 u8 *pbyBSSID;
2619 PUSB_SEND_CONTEXT pContext;
2620 u8 byPktTyp;
2621 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002622 u32 status;
2623 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002624
Forest Bond92b96792009-06-13 07:38:31 -04002625 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2626
2627 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002628 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002629 }
2630
Andres Moreceb8c5d2013-03-18 20:33:49 -05002631 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002632
Andres More4e9b5e22013-02-12 20:36:30 -05002633 if (pDevice->bEncryptionEnable == true) {
2634 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002635 // get group key
2636 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002637 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002638 pTransmitKey = NULL;
2639 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2640 } else {
2641 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2642 }
2643 }
2644
2645 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002646 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002647 pTransmitKey = &STempKey;
2648 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2649 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2650 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2651 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2652 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2653 memcpy(pTransmitKey->abyKey,
2654 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2655 pTransmitKey->uKeyLength
2656 );
2657 }
2658 }
2659
2660 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002661 pContext->bBoolInUse = false;
2662 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002663 }
2664
Andres Moreb902fbf2013-02-25 20:32:51 -05002665 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002666
2667 if (pDevice->bFixRate) {
2668 if (pDevice->byBBType == BB_TYPE_11B) {
2669 if (pDevice->uConnectionRate >= RATE_11M) {
2670 pDevice->wCurrentRate = RATE_11M;
2671 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002672 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002673 }
2674 } else {
2675 if ((pDevice->byBBType == BB_TYPE_11A) &&
2676 (pDevice->uConnectionRate <= RATE_6M)) {
2677 pDevice->wCurrentRate = RATE_6M;
2678 } else {
2679 if (pDevice->uConnectionRate >= RATE_54M)
2680 pDevice->wCurrentRate = RATE_54M;
2681 else
Andres More3eaca0d2013-02-25 20:32:52 -05002682 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002683 }
2684 }
2685 }
2686 else {
2687 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2688 }
2689
Forest Bond92b96792009-06-13 07:38:31 -04002690 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002691 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002692 }
2693
2694 if (pDevice->wCurrentRate <= RATE_11M)
2695 byPktType = PK_TYPE_11B;
2696
Andres Moreabad19d2010-07-12 16:28:32 -03002697 BytesToWrite = uDataLen + ETH_FCS_LEN;
2698
Forest Bond92b96792009-06-13 07:38:31 -04002699 // Convert the packet to an usb frame and copy into our buffer
2700 // and send the irp.
2701
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002702 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2703
Forest Bond92b96792009-06-13 07:38:31 -04002704 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002705 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002706 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2707 pbySkbData, pTransmitKey, uNodeIndex,
2708 pDevice->wCurrentRate,
2709 &uHeaderLen, &BytesToWrite
2710 );
2711
Andres Moree269fc22013-02-12 20:36:29 -05002712 if (fConvertedPacket == false) {
2713 pContext->bBoolInUse = false;
2714 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002715 }
2716
Andres Moreb902fbf2013-02-25 20:32:51 -05002717 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002718 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002719
2720 pContext->pPacket = NULL;
2721 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002722 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002723
Andres Moreceb8c5d2013-03-18 20:33:49 -05002724 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.h_dest[0]), (u16) (BytesToWrite-uHeaderLen), pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002725
2726 status = PIPEnsSendBulkOut(pDevice,pContext);
2727
Andres More4e9b5e22013-02-12 20:36:30 -05002728 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002729}
2730