blob: 2fd71c3c06cb1116e109811ad8f486015a4b4831 [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,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100104 struct ethhdr *psEthHeader, bool need_rts);
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 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100733 switch (byPktType) {
734 case PK_TYPE_11GB:
735 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100736 if (byFBOption == AUTO_FB_NONE)
737 vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100738 psEthHeader, byPktType, cbFrameLength,
739 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100740 else
741 vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100742 psEthHeader, byPktType, cbFrameLength,
743 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100744 break;
745 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100746 if (byFBOption) {
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100747 vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
748 psEthHeader, byPktType, cbFrameLength,
749 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100750 break;
751 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100752 case PK_TYPE_11B:
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100753 vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100754 psEthHeader, byPktType, cbFrameLength,
755 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100756 }
Forest Bond92b96792009-06-13 07:38:31 -0400757}
758
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000759static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
760 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100761 u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400762{
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100763 union vnt_tx_data_head *head = pvCTS;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000764 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400765
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100766 if (!head)
767 return;
Forest Bond92b96792009-06-13 07:38:31 -0400768
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100769 if (byFBOption != AUTO_FB_NONE) {
770 /* Auto Fall back */
Malcolm Priestley27df3eb2013-08-27 11:48:34 +0100771 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
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 Priestley27df3eb2013-08-27 11:48:34 +0100791 struct vnt_cts *pBuf = &head->cts_g;
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 }
Forest Bond92b96792009-06-13 07:38:31 -0400804}
805
Forest Bond92b96792009-06-13 07:38:31 -0400806/*+
807 *
808 * Description:
809 * Generate FIFO control for MAC & Baseband controller
810 *
811 * Parameters:
812 * In:
813 * pDevice - Pointer to adpater
814 * pTxDataHead - Transmit Data Buffer
815 * pTxBufHead - pTxBufHead
816 * pvRrvTime - pvRrvTime
817 * pvRTS - RTS Buffer
818 * pCTS - CTS Buffer
819 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
820 * bNeedACK - If need ACK
821 * uDMAIdx - DMA Index
822 * Out:
823 * none
824 *
825 * Return Value: none
826 *
827-*/
Andres Morecc856e62010-05-17 21:34:01 -0300828
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000829static void s_vGenerateTxParameter(struct vnt_private *pDevice,
830 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
831 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100832 struct ethhdr *psEthHeader, bool need_rts)
Forest Bond92b96792009-06-13 07:38:31 -0400833{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000834 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
835 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000836 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400837
838 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
839 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
840 pFifoHead->wReserved = wCurrentRate;
841 wFifoCtl = pFifoHead->wFIFOCtl;
842
Forest Bond92b96792009-06-13 07:38:31 -0400843 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
844 byFBOption = AUTO_FB_0;
845 }
846 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
847 byFBOption = AUTO_FB_1;
848 }
849
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100850 if (!pvRrvTime)
851 return;
852
Forest Bond92b96792009-06-13 07:38:31 -0400853 if (pDevice->bLongHeader)
854 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
855
856 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100857 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400858 //Fill RsvTime
Malcolm Priestley6398a592013-08-16 21:26:55 +0100859 struct vnt_rrv_time_rts *pBuf =
860 (struct vnt_rrv_time_rts *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100861 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
862 byPktType, cbFrameSize, wCurrentRate);
863 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
864 byPktType, cbFrameSize, wCurrentRate);
865 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
866 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100867 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
868 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
869 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
870 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
871 bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400872 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100873 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
874 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400875 }
876 else {//RTS_needless, PCF mode
Forest Bond92b96792009-06-13 07:38:31 -0400877 //Fill RsvTime
Malcolm Priestley4f990052013-08-16 23:38:57 +0100878 struct vnt_rrv_time_cts *pBuf =
879 (struct vnt_rrv_time_cts *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100880 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
881 cbFrameSize, wCurrentRate, bNeedACK);
882 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
883 PK_TYPE_11B, cbFrameSize,
884 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100885 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
886 byPktType, cbFrameSize, wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400887 //Fill CTS
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100888 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize,
889 bNeedACK, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400890 }
891 }
892 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100893 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400894 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100895 struct vnt_rrv_time_ab *pBuf =
896 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100897 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
898 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100899 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
900 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400901 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100902 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
903 psEthHeader, wCurrentRate, byFBOption);
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100904 } else {
Forest Bond92b96792009-06-13 07:38:31 -0400905 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100906 struct vnt_rrv_time_ab *pBuf =
907 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100908 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
909 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400910 }
911 }
912 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100913 if (need_rts) {
Forest Bond92b96792009-06-13 07:38:31 -0400914 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100915 struct vnt_rrv_time_ab *pBuf =
916 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100917 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
918 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100919 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
920 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400921 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100922 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
923 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400924 }
925 else { //RTS_needless, non PCF mode
926 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100927 struct vnt_rrv_time_ab *pBuf =
928 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100929 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
930 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400931 }
932 }
933 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
934}
935/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500936 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500937 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300938 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400939*/
940
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000941static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100942 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
943 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
944 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
945 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400946{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000947 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
948 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000949 u32 cb802_1_H_len;
950 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
951 u32 cbFCSlen = 4, cbMICHDR = 0;
Malcolm Priestleyf46142b2013-08-27 11:56:33 +0100952 int bNeedACK;
953 bool bRTS = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000954 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
955 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
956 u8 abySNAP_Bridgetunnel[ETH_ALEN]
957 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
958 u32 uDuration;
959 u32 cbHeaderLength = 0, uPadding = 0;
960 void *pvRrvTime;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100961 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000962 void *pvRTS;
963 void *pvCTS;
964 void *pvTxDataHd;
965 u8 byFBOption = AUTO_FB_NONE, byFragType;
966 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100967 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000968 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500969 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -0400970
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000971 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400972
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000973 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500974 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
975 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000976 }
Forest Bond92b96792009-06-13 07:38:31 -0400977
Forest Bond92b96792009-06-13 07:38:31 -0400978 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -0500979 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -0400980 if (pDevice->dwDiagRefCount == 0) {
981 cb802_1_H_len = 8;
982 } else {
983 cb802_1_H_len = 2;
984 }
985 } else {
986 cb802_1_H_len = 0;
987 }
988
Charles Clément21ec51f2010-05-18 10:08:14 -0700989 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400990
991 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500992 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400993
994 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -0500995 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -0400996 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
997 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -0300998 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
999 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001000 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001001 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001002 pTxBufHead->wFIFOCtl =
1003 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1004 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001005 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001006 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1007 }
Forest Bond92b96792009-06-13 07:38:31 -04001008 }
1009 else {
1010 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001011 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001012 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1013 }
1014 } //if (pDevice->dwDiagRefCount != 0) {
1015
1016 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1017
1018 //Set FIFOCTL_LHEAD
1019 if (pDevice->bLongHeader)
1020 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1021
Forest Bond92b96792009-06-13 07:38:31 -04001022 //Set FRAGCTL_MACHDCNT
1023 if (pDevice->bLongHeader) {
1024 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1025 } else {
1026 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1027 }
Andres More3eaca0d2013-02-25 20:32:52 -05001028 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001029
1030 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001031 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001032 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1033 }
1034
1035 //Set Auto Fallback Ctl
1036 if (wCurrentRate >= RATE_18M) {
1037 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1038 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1039 byFBOption = AUTO_FB_0;
1040 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1041 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1042 byFBOption = AUTO_FB_1;
1043 }
1044 }
1045
Andres More4e9b5e22013-02-12 20:36:30 -05001046 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001047 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1048 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1049 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1050 }
1051 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1052 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1053 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1054 }
1055 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1056 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1057 }
1058 }
1059 }
1060
Forest Bond92b96792009-06-13 07:38:31 -04001061 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1062 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1063 cbIVlen = 4;
1064 cbICVlen = 4;
1065 }
1066 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1067 cbIVlen = 8;//IV+ExtIV
1068 cbMIClen = 8;
1069 cbICVlen = 4;
1070 }
1071 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1072 cbIVlen = 8;//RSN Header
1073 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001074 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001075 }
Andres Moree269fc22013-02-12 20:36:29 -05001076 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001077 //MAC Header should be padding 0 to DW alignment.
1078 uPadding = 4 - (cbMACHdLen%4);
1079 uPadding %= 4;
1080 }
1081 }
1082
1083 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1084
Andres Moree269fc22013-02-12 20:36:29 -05001085 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1086 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001087 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001088 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001089 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1090 }
1091
Andres Moreb902fbf2013-02-25 20:32:51 -05001092 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001093 wTxBufSize = sizeof(STxBufHead);
1094 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1095 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001096 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001097 pvRrvTime = (struct vnt_rrv_time_rts *)
1098 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001099 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001100 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001101 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001102 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001103 pvCTS = NULL;
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001104 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1105 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1106 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001107 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001108 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001109 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001110 }
1111 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001112 pvRrvTime = (struct vnt_rrv_time_cts *)
1113 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001114 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001115 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001116 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001117 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001118 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001119 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1120 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1121 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001122 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1123 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001124 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001125 }
1126 } else {
1127 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001128 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001129 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1130 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001131 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001132 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001133 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001134 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001135 pvCTS = NULL;
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001136 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1137 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1138 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001139 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1140 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001141 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001142 }
Andres Moree269fc22013-02-12 20:36:29 -05001143 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001144 pvRrvTime = (struct vnt_rrv_time_cts *)
1145 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001146 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001147 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001148 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001149 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001150 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001151 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001152 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1153 cbMICHDR + sizeof(struct vnt_cts_fb));
1154 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001155 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001156 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001157 }
1158 } // Auto Fall Back
1159 }
1160 else {//802.11a/b packet
1161 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001162 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001163 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1164 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001165 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001166 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001167 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001168 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001169 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001170 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1171 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001172 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001173 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1174 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001175 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001176 }
Andres Moree269fc22013-02-12 20:36:29 -05001177 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001178 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1179 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001180 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001181 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001182 pvRTS = NULL;
1183 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001184 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1185 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001186 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001187 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001188 }
1189 } else {
1190 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001191 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001192 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1193 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001194 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001195 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001196 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001197 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001198 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001199 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1200 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001201 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001202 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1203 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001204 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001205 }
Andres Moree269fc22013-02-12 20:36:29 -05001206 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001207 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1208 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001209 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001210 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001211 pvRTS = NULL;
1212 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001213 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1214 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001215 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001216 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001217 }
1218 } // Auto Fall Back
1219 }
1220
Andres Moreb902fbf2013-02-25 20:32:51 -05001221 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1222 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1223 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001224
Forest Bond92b96792009-06-13 07:38:31 -04001225 //=========================
1226 // No Fragmentation
1227 //=========================
1228 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1229 byFragType = FRAGCTL_NONFRAG;
1230 //uDMAIdx = TYPE_AC0DMA;
1231 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1232
Forest Bond92b96792009-06-13 07:38:31 -04001233 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001234 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1235 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001236 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
Forest Bond92b96792009-06-13 07:38:31 -04001237 //Fill DataHead
1238 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001239 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001240 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001241 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001242 byFragType, uDMAIdx, 0);
1243
Andres More4e9b5e22013-02-12 20:36:30 -05001244 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001245 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001246 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001247 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001248
1249 if (pDevice->bEnableHostWEP) {
1250 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1251 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1252 }
1253 }
1254
1255 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001256 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001257 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001258 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1259 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001260 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001261 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001262 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001263 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001264 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001265 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001266 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001267 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001268 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001269
1270 }
1271
1272 }
1273
Forest Bond92b96792009-06-13 07:38:31 -04001274 if (pPacket != NULL) {
1275 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001276 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001277 (pPacket + ETH_HLEN),
1278 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001279 );
1280
1281 } else {
1282 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001283 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001284 }
1285
Andres More4e9b5e22013-02-12 20:36:30 -05001286 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001287
1288 ///////////////////////////////////////////////////////////////////
1289
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001290 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1291 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1292 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1293 }
Forest Bond92b96792009-06-13 07:38:31 -04001294 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001295 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1296 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001297 }
1298 else {
Andres More52a7e642013-02-25 20:32:53 -05001299 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1300 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001301 }
1302 // DO Software Michael
1303 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001304 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001305 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001306 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001307 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1308 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001309
1310 ///////////////////////////////////////////////////////////////////
1311
1312 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1313 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001314 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001315 //}
1316 //DBG_PRN_GRP12(("\n\n\n"));
1317
1318 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1319
Andres More52a7e642013-02-25 20:32:53 -05001320 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1321 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001322
1323 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1324 MIC_vUnInit();
1325
Andres More4e9b5e22013-02-12 20:36:30 -05001326 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001327 *pdwMIC_L = 0;
1328 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001329 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001330 }
1331 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1332 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1333 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1334 }
1335
Andres More4e9b5e22013-02-12 20:36:30 -05001336 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001337
Andres More3eaca0d2013-02-25 20:32:52 -05001338 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001339
Andres More4e9b5e22013-02-12 20:36:30 -05001340 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1341 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1342 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001343 cbFrameSize -= cbICVlen;
1344 }
1345
Forest Bond92b96792009-06-13 07:38:31 -04001346 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001347
1348 *pcbHeaderLen = cbHeaderLength;
1349 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1350
Forest Bond92b96792009-06-13 07:38:31 -04001351 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001352 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001353
Andres More4e9b5e22013-02-12 20:36:30 -05001354 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001355
1356}
1357
Forest Bond92b96792009-06-13 07:38:31 -04001358/*+
1359 *
1360 * Description:
1361 * Translate 802.3 to 802.11 header
1362 *
1363 * Parameters:
1364 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001365 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001366 * dwTxBufferAddr - Transmit Buffer
1367 * pPacket - Packet from upper layer
1368 * cbPacketSize - Transmit Data Length
1369 * Out:
1370 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1371 * pcbAppendPayload - size of append payload for 802.1H translation
1372 *
1373 * Return Value: none
1374 *
1375-*/
1376
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001377static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001378 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001379 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001380{
Andres More1cac4a42013-03-18 20:33:50 -05001381 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001382
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001383 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001384
1385 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001386 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001387 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001388 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001389 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1390 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001391 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001392 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001393 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001394 } else {
1395 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001396 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001397 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001398 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001399 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001400 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001401 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001402 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001403 &(pDevice->abyBSSID[0]),
1404 ETH_ALEN);
1405 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001406 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001407 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001408 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001409 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001410 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001411 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001412 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001413 &(pDevice->abyBSSID[0]),
1414 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001415 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001416 }
1417 }
1418
1419 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001420 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001421
Andres More1cac4a42013-03-18 20:33:50 -05001422 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001423
1424 if (pDevice->bLongHeader) {
1425 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001426 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001427 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001428 }
Andres More1cac4a42013-03-18 20:33:50 -05001429 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001430
1431 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001432 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001433
1434 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1435 pDevice->wSeqCounter++;
1436 if (pDevice->wSeqCounter > 0x0fff)
1437 pDevice->wSeqCounter = 0;
1438 }
1439
1440 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001441 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001442 }
1443}
1444
Forest Bond92b96792009-06-13 07:38:31 -04001445/*+
1446 *
1447 * Description:
1448 * Request instructs a MAC to transmit a 802.11 management packet through
1449 * the adapter onto the medium.
1450 *
1451 * Parameters:
1452 * In:
1453 * hDeviceContext - Pointer to the adapter
1454 * pPacket - A pointer to a descriptor for the packet to transmit
1455 * Out:
1456 * none
1457 *
Andres Moree269fc22013-02-12 20:36:29 -05001458 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001459 *
1460-*/
1461
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001462CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1463 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001464{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001465 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001466 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001467 PSTxBufHead pTxBufHead;
1468 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001469 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001470 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001471 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001472 u8 byPktType, *pbyTxBufferAddr;
1473 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1474 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001475 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001476 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1477 u32 uPadding = 0;
1478 u16 wTxBufSize;
1479 u32 cbMacHdLen;
1480 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001481
Forest Bond92b96792009-06-13 07:38:31 -04001482 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1483
1484 if (NULL == pContext) {
1485 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1486 return CMD_STATUS_RESOURCES;
1487 }
1488
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001489 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001490 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001491 cbFrameBodySize = pPacket->cbPayloadLen;
1492 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1493 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001494
1495 if (pDevice->byBBType == BB_TYPE_11A) {
1496 wCurrentRate = RATE_6M;
1497 byPktType = PK_TYPE_11A;
1498 } else {
1499 wCurrentRate = RATE_1M;
1500 byPktType = PK_TYPE_11B;
1501 }
1502
1503 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1504 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1505 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1506 // to set power here.
1507 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1508 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1509 } else {
1510 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1511 }
1512 pDevice->wCurrentRate = wCurrentRate;
1513
Forest Bond92b96792009-06-13 07:38:31 -04001514 //Set packet type
1515 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1516 pTxBufHead->wFIFOCtl = 0;
1517 }
1518 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1519 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1520 }
1521 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1522 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1523 }
1524 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1525 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1526 }
1527
1528 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1529 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1530
Andres More22040bb2010-08-02 20:21:44 -03001531 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001532 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001533 }
1534 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001535 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001536 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1537 };
1538
1539 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1540 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1541
1542 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1543 //Set Preamble type always long
1544 //pDevice->byPreambleType = PREAMBLE_LONG;
1545 // probe-response don't retry
1546 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001547 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001548 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1549 //}
1550 }
1551
1552 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1553
1554 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001555 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001556 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1557 } else {
1558 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1559 }
1560
1561 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001562 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001563
1564 // Notes:
1565 // Although spec says MMPDU can be fragmented; In most case,
1566 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001567 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001568
1569 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1570 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1571 cbIVlen = 4;
1572 cbICVlen = 4;
1573 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1574 }
1575 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1576 cbIVlen = 8;//IV+ExtIV
1577 cbMIClen = 8;
1578 cbICVlen = 4;
1579 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1580 //We need to get seed here for filling TxKey entry.
1581 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1582 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1583 }
1584 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1585 cbIVlen = 8;//RSN Header
1586 cbICVlen = 8;//MIC
1587 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001588 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001589 }
1590 //MAC Header should be padding 0 to DW alignment.
1591 uPadding = 4 - (cbMacHdLen%4);
1592 uPadding %= 4;
1593 }
1594
1595 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1596
1597 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001598 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001599 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1600 }
1601 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1602
1603 //Set RrvTime/RTS/CTS Buffer
1604 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1605
Malcolm Priestley4f990052013-08-16 23:38:57 +01001606 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001607 pMICHDR = NULL;
1608 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001609 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001610 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001611 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001612 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1613 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001614 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001615 }
1616 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001617 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001618 pMICHDR = NULL;
1619 pvRTS = NULL;
1620 pCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001621 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1622 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001623 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001624 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001625 }
1626
Andres Moreceb8c5d2013-03-18 20:33:49 -05001627 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001628 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1629 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001630 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001631 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1632 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001633 //=========================
1634 // No Fragmentation
1635 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001636 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001637
Forest Bond92b96792009-06-13 07:38:31 -04001638 //Fill FIFO,RrvTime,RTS,and CTS
1639 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01001640 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04001641
1642 //Fill DataHead
1643 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001644 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001645
Andres More1cac4a42013-03-18 20:33:50 -05001646 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001647
1648 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1649
1650 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001651 u8 * pbyIVHead;
1652 u8 * pbyPayloadHead;
1653 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001654 PSKeyItem pTransmitKey = NULL;
1655
Andres Moreb902fbf2013-02-25 20:32:51 -05001656 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1657 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001658 do {
1659 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001660 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001661 pbyBSSID = pDevice->abyBSSID;
1662 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001663 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001664 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001665 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001666 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1667 break;
1668 }
1669 } else {
1670 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1671 break;
1672 }
1673 }
1674 // get group key
1675 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001676 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001677 pTransmitKey = NULL;
1678 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1679 } else {
1680 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1681 }
Andres Moree269fc22013-02-12 20:36:29 -05001682 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001683 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001684 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001685 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001686
Jim Lieb3e362592009-08-12 14:54:11 -07001687 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001688 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001689 cbFrameBodySize);
1690 }
1691 else {
1692 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001693 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001694 }
1695
Andres More1cac4a42013-03-18 20:33:50 -05001696 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001697 pDevice->wSeqCounter++ ;
1698 if (pDevice->wSeqCounter > 0x0fff)
1699 pDevice->wSeqCounter = 0;
1700
1701 if (bIsPSPOLL) {
1702 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001703 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001704 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1705 // in the same place of other packet's Duration-field).
1706 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001707 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1708 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1709 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1710 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1711 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1712 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001713 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1714 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1715 }
Forest Bond92b96792009-06-13 07:38:31 -04001716 }
1717
Andres More3eaca0d2013-02-25 20:32:52 -05001718 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001719 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001720 pTX_Buffer->byType = 0x00;
1721
1722 pContext->pPacket = NULL;
1723 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001724 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001725
Andres More1cac4a42013-03-18 20:33:50 -05001726 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1727 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001728 }
1729 else {
Andres More1cac4a42013-03-18 20:33:50 -05001730 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001731 }
1732
1733 PIPEnsSendBulkOut(pDevice,pContext);
1734 return CMD_STATUS_PENDING;
1735}
1736
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001737CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1738 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001739{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001740 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001741 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1742 u32 cbHeaderSize = 0;
1743 u16 wTxBufSize = sizeof(STxShortBufHead);
1744 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001745 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001746 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001747 u16 wCurrentRate;
1748 u32 cbFrameBodySize;
1749 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001750 u8 *pbyTxBufferAddr;
1751 PUSB_SEND_CONTEXT pContext;
1752 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001753
Forest Bond92b96792009-06-13 07:38:31 -04001754 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1755 if (NULL == pContext) {
1756 status = CMD_STATUS_RESOURCES;
1757 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1758 return status ;
1759 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001760
1761 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001762 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001763
1764 cbFrameBodySize = pPacket->cbPayloadLen;
1765
1766 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1767 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001768
1769 if (pDevice->byBBType == BB_TYPE_11A) {
1770 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001771 pTxDataHead = (struct vnt_tx_datahead_ab *)
1772 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001773 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001774 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1775 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001776 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001777 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001778 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001779 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001780 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001781 } else {
1782 wCurrentRate = RATE_1M;
1783 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001784 pTxDataHead = (struct vnt_tx_datahead_ab *)
1785 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001786 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001787 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1788 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001789 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001790 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001791 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001792 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001793 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001794 }
1795
1796 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001797 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001798 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001799
Andres More1cac4a42013-03-18 20:33:50 -05001800 pMACHeader->duration_id = 0;
1801 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001802 pDevice->wSeqCounter++ ;
1803 if (pDevice->wSeqCounter > 0x0fff)
1804 pDevice->wSeqCounter = 0;
1805
1806 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1807
Andres More3eaca0d2013-02-25 20:32:52 -05001808 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001809 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001810 pTX_Buffer->byType = 0x01;
1811
1812 pContext->pPacket = NULL;
1813 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001814 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001815
1816 PIPEnsSendBulkOut(pDevice,pContext);
1817 return CMD_STATUS_PENDING;
1818
1819}
1820
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001821void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1822{
1823 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001824 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001825 u8 byPktType;
1826 u8 *pbyTxBufferAddr;
1827 void *pvRTS, *pvCTS, *pvTxDataHd;
1828 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001829 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001830 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001831 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001832 PSTxBufHead pTxBufHead;
1833 u32 cbFrameSize;
1834 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1835 u32 uPadding = 0;
1836 u32 cbMICHDR = 0, uLength = 0;
1837 u32 dwMICKey0, dwMICKey1;
1838 u32 dwMIC_Priority;
1839 u32 *pdwMIC_L, *pdwMIC_R;
1840 u16 wTxBufSize;
1841 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001842 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001843 void *pvRrvTime, *pMICHDR;
1844 u32 wCurrentRate = RATE_1M;
1845 PUWLAN_80211HDR p80211Header;
1846 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001847 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001848 SKeyItem STempKey;
1849 PSKeyItem pTransmitKey = NULL;
1850 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1851 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001852 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001853
Forest Bond92b96792009-06-13 07:38:31 -04001854 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1855
1856 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1857 cbFrameBodySize = 0;
1858 }
1859 else {
1860 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1861 }
1862 p80211Header = (PUWLAN_80211HDR)skb->data;
1863
1864 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1865
1866 if (NULL == pContext) {
1867 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1868 dev_kfree_skb_irq(skb);
1869 return ;
1870 }
1871
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001872 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001873 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001874 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1875 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001876
1877 if (pDevice->byBBType == BB_TYPE_11A) {
1878 wCurrentRate = RATE_6M;
1879 byPktType = PK_TYPE_11A;
1880 } else {
1881 wCurrentRate = RATE_1M;
1882 byPktType = PK_TYPE_11B;
1883 }
1884
1885 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1886 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1887 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1888 // to set power here.
1889 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1890 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1891 } else {
1892 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1893 }
1894
1895 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1896
1897 //Set packet type
1898 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1899 pTxBufHead->wFIFOCtl = 0;
1900 }
1901 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1902 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1903 }
1904 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1905 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1906 }
1907 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1908 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1909 }
1910
1911 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1912 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1913
Andres More22040bb2010-08-02 20:21:44 -03001914 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001915 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001916 if (pDevice->bEnableHostWEP) {
1917 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001918 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001919 }
Forest Bond92b96792009-06-13 07:38:31 -04001920 }
1921 else {
1922 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001923 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001924 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001925 }
Andres More4e9b5e22013-02-12 20:36:30 -05001926 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001927 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1928 };
1929
1930 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1931 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1932
1933 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1934 //Set Preamble type always long
1935 //pDevice->byPreambleType = PREAMBLE_LONG;
1936
1937 // probe-response don't retry
1938 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001939 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001940 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1941 //}
1942 }
1943
1944 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1945
1946 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001947 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001948 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1949 } else {
1950 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1951 }
1952
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001953 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001954 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1955
1956 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1957 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1958 }
1959
1960 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1961 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1962 }
1963
1964 if (cbExtSuppRate >0) {
1965 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1966 }
1967 }
1968
Forest Bond92b96792009-06-13 07:38:31 -04001969 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001970 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001971
1972 // Notes:
1973 // Although spec says MMPDU can be fragmented; In most case,
1974 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001975 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001976
Forest Bond92b96792009-06-13 07:38:31 -04001977 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1978 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1979 cbIVlen = 4;
1980 cbICVlen = 4;
1981 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1982 }
1983 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1984 cbIVlen = 8;//IV+ExtIV
1985 cbMIClen = 8;
1986 cbICVlen = 4;
1987 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1988 //We need to get seed here for filling TxKey entry.
1989 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1990 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1991 }
1992 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1993 cbIVlen = 8;//RSN Header
1994 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001995 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001996 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001997 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001998 }
1999 //MAC Header should be padding 0 to DW alignment.
2000 uPadding = 4 - (cbMacHdLen%4);
2001 uPadding %= 4;
2002 }
2003
2004 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2005
2006 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002007 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002008 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2009 }
2010 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2011
Forest Bond92b96792009-06-13 07:38:31 -04002012 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002013 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002014 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002015 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002016 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002017 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002018 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002019 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2020 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002021 sizeof(struct vnt_cts));
2022 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002023 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002024
2025 }
2026 else {//802.11a/b packet
2027
Malcolm Priestley976467d2013-08-16 23:44:04 +01002028 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002029 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01002030 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002031 pvRTS = NULL;
2032 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01002033 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2034 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002035 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002036 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002037 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002038 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002039 &(p80211Header->sA3.abyAddr1[0]),
2040 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002041 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002042 &(p80211Header->sA3.abyAddr2[0]),
2043 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002044 //=========================
2045 // No Fragmentation
2046 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002047 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002048
Forest Bond92b96792009-06-13 07:38:31 -04002049 //Fill FIFO,RrvTime,RTS,and CTS
2050 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Malcolm Priestleyf46142b2013-08-27 11:56:33 +01002051 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
Forest Bond92b96792009-06-13 07:38:31 -04002052
2053 //Fill DataHead
2054 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002055 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002056
Andres More1cac4a42013-03-18 20:33:50 -05002057 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002058
2059 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2060
Andres Moreb902fbf2013-02-25 20:32:51 -05002061 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2062 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2063 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002064
2065 // Copy the Packet into a tx Buffer
2066 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2067
2068 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002069 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002070 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2071
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002072 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002073 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2074 if (cbExtSuppRate != 0) {
2075 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2076 memcpy((pbyPayloadHead + cbFrameBodySize),
2077 pMgmt->abyCurrSuppRates,
2078 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2079 );
2080 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2081 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2082 pMgmt->abyCurrExtSuppRates,
2083 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2084 );
2085 }
2086 }
2087
2088 // Set wep
2089 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2090
2091 if (pDevice->bEnableHostWEP) {
2092 pTransmitKey = &STempKey;
2093 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2094 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2095 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2096 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2097 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2098 memcpy(pTransmitKey->abyKey,
2099 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2100 pTransmitKey->uKeyLength
2101 );
2102 }
2103
2104 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2105
Andres More52a7e642013-02-25 20:32:53 -05002106 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2107 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002108
2109 // DO Software Michael
2110 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002111 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002112 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002113 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002114 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2115 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002116
2117 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2118
2119 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2120
Andres More52a7e642013-02-25 20:32:53 -05002121 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2122 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002123
2124 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2125 MIC_vUnInit();
2126
Andres More4e9b5e22013-02-12 20:36:30 -05002127 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002128 *pdwMIC_L = 0;
2129 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002130 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002131 }
2132
2133 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2134 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002135 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2136 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002137
2138 }
2139
Andres Moreb902fbf2013-02-25 20:32:51 -05002140 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002141 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002142
2143 if (pDevice->bEnableHostWEP) {
2144 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2145 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2146 }
2147
2148 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002149 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002150 }
2151 }
2152
Andres More1cac4a42013-03-18 20:33:50 -05002153 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002154 pDevice->wSeqCounter++ ;
2155 if (pDevice->wSeqCounter > 0x0fff)
2156 pDevice->wSeqCounter = 0;
2157
Forest Bond92b96792009-06-13 07:38:31 -04002158 if (bIsPSPOLL) {
2159 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2160 // of FIFO control header.
2161 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2162 // in the same place of other packet's Duration-field).
2163 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002164 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2165 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2166 cpu_to_le16(p80211Header->sA2.wDurationID);
2167 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2168 cpu_to_le16(p80211Header->sA2.wDurationID);
2169 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002170 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2171 cpu_to_le16(p80211Header->sA2.wDurationID);
2172 }
Forest Bond92b96792009-06-13 07:38:31 -04002173 }
2174
Andres More3eaca0d2013-02-25 20:32:52 -05002175 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002176 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002177 pTX_Buffer->byType = 0x00;
2178
2179 pContext->pPacket = skb;
2180 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002181 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002182
Andres More1cac4a42013-03-18 20:33:50 -05002183 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2184 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002185 }
2186 else {
Andres More1cac4a42013-03-18 20:33:50 -05002187 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002188 }
2189 PIPEnsSendBulkOut(pDevice,pContext);
2190 return ;
2191
2192}
2193
Forest Bond92b96792009-06-13 07:38:31 -04002194//TYPE_AC0DMA data tx
2195/*
2196 * Description:
2197 * Tx packet via AC0DMA(DMA1)
2198 *
2199 * Parameters:
2200 * In:
2201 * pDevice - Pointer to the adapter
2202 * skb - Pointer to tx skb packet
2203 * Out:
2204 * void
2205 *
2206 * Return Value: NULL
2207 */
2208
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002209int nsDMA_tx_packet(struct vnt_private *pDevice,
2210 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002211{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002212 struct net_device_stats *pStats = &pDevice->stats;
2213 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002214 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002215 u32 BytesToWrite = 0, uHeaderLen = 0;
2216 u32 uNodeIndex = 0;
2217 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2218 u16 wAID;
2219 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002220 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002221 PSKeyItem pTransmitKey = NULL;
2222 SKeyItem STempKey;
2223 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002224 int bTKIP_UseGTK = false;
2225 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002226 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002227 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002228 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002229 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002230 u32 status;
2231 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002232 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002233
Forest Bond92b96792009-06-13 07:38:31 -04002234 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2235
2236 if (pDevice->uAssocCount == 0) {
2237 dev_kfree_skb_irq(skb);
2238 return 0;
2239 }
2240
Andres Moreb902fbf2013-02-25 20:32:51 -05002241 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002242 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002243 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002244 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2245
2246 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2247 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2248 // set tx map
2249 pMgmt->abyPSTxMap[0] |= byMask[0];
2250 return 0;
2251 }
Masanari Iida93184692012-08-13 21:21:50 +09002252 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002253
2254 if (pDevice->byBBType != BB_TYPE_11A)
2255 pDevice->wCurrentRate = RATE_2M;
2256 else
2257 pDevice->wCurrentRate = RATE_24M;
2258 // long preamble type
2259 pDevice->byPreambleType = PREAMBLE_SHORT;
2260
2261 }else {
2262
Andres Moreb902fbf2013-02-25 20:32:51 -05002263 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002264
2265 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2266
2267 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2268
2269 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2270 // set tx map
2271 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2272 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2273 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2274 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2275
2276 return 0;
2277 }
2278 // AP rate decided from node
2279 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2280 // tx preamble decided from node
2281
2282 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2283 pDevice->byPreambleType = pDevice->byShortPreamble;
2284
2285 }else {
2286 pDevice->byPreambleType = PREAMBLE_LONG;
2287 }
Andres More4e9b5e22013-02-12 20:36:30 -05002288 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002289 }
2290 }
2291
Andres Moree269fc22013-02-12 20:36:29 -05002292 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002293 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2294 dev_kfree_skb_irq(skb);
2295 return 0;
2296 }
2297 }
2298
2299 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2300
2301 if (pContext == NULL) {
2302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2303 dev_kfree_skb_irq(skb);
2304 return STATUS_RESOURCES;
2305 }
2306
Andres Moreceb8c5d2013-03-18 20:33:49 -05002307 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002308
2309//mike add:station mode check eapol-key challenge--->
2310{
Andres Moreb902fbf2013-02-25 20:32:51 -05002311 u8 Protocol_Version; //802.1x Authentication
2312 u8 Packet_Type; //802.1x Authentication
2313 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002314 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002315
Charles Clément21ec51f2010-05-18 10:08:14 -07002316 Protocol_Version = skb->data[ETH_HLEN];
2317 Packet_Type = skb->data[ETH_HLEN+1];
2318 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2319 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 -05002320 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002321 /* 802.1x OR eapol-key challenge frame transfer */
2322 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2323 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002324 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002325 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2326 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2327 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002328 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002329 PRINT_K("WPA ");
2330 }
2331 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002332 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002333 PRINT_K("WPA2(re-keying) ");
2334 }
2335 PRINT_K("Authentication completed!!\n");
2336 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002337 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002338 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002339 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002340 PRINT_K("WPA2 Authentication completed!!\n");
2341 }
2342 }
2343 }
2344}
2345//mike add:station mode check eapol-key challenge<---
2346
Andres More4e9b5e22013-02-12 20:36:30 -05002347 if (pDevice->bEncryptionEnable == true) {
2348 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002349 // get Transmit key
2350 do {
2351 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2352 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2353 pbyBSSID = pDevice->abyBSSID;
2354 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002355 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002356 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002357 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2358 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002359 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2360 break;
2361 }
2362 } else {
2363 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2364 break;
2365 }
2366 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002367 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2368 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002369 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2370 for (ii = 0; ii< 6; ii++)
2371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2372 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2373
2374 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002375 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002376 break;
2377 }
2378 // get group key
2379 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002380 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002381 pTransmitKey = NULL;
2382 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2383 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2384 }
2385 else
2386 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2387 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002388 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002389 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2390 }
Andres Moree269fc22013-02-12 20:36:29 -05002391 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002392 }
2393
2394 if (pDevice->bEnableHostWEP) {
2395 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002396 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002397 pTransmitKey = &STempKey;
2398 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2399 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2400 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2401 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2402 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2403 memcpy(pTransmitKey->abyKey,
2404 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2405 pTransmitKey->uKeyLength
2406 );
2407 }
2408 }
2409
Andres Moreb902fbf2013-02-25 20:32:51 -05002410 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002411
2412 if (pDevice->bFixRate) {
2413 if (pDevice->byBBType == BB_TYPE_11B) {
2414 if (pDevice->uConnectionRate >= RATE_11M) {
2415 pDevice->wCurrentRate = RATE_11M;
2416 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002417 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002418 }
2419 } else {
2420 if ((pDevice->byBBType == BB_TYPE_11A) &&
2421 (pDevice->uConnectionRate <= RATE_6M)) {
2422 pDevice->wCurrentRate = RATE_6M;
2423 } else {
2424 if (pDevice->uConnectionRate >= RATE_54M)
2425 pDevice->wCurrentRate = RATE_54M;
2426 else
Andres More3eaca0d2013-02-25 20:32:52 -05002427 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002428 }
2429 }
2430 }
2431 else {
2432 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2433 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002434 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002435 // Multicast use highest data rate
2436 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2437 // preamble type
2438 pDevice->byPreambleType = pDevice->byShortPreamble;
2439 }
2440 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002441 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002442 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2443 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2444 pDevice->byPreambleType = pDevice->byShortPreamble;
2445
2446 }
2447 else {
2448 pDevice->byPreambleType = PREAMBLE_LONG;
2449 }
2450 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2451 }
2452 else {
2453 if (pDevice->byBBType != BB_TYPE_11A)
2454 pDevice->wCurrentRate = RATE_2M;
2455 else
2456 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2457 // abyCurrExtSuppRates[]
2458 pDevice->byPreambleType = PREAMBLE_SHORT;
2459 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2460 }
2461 }
2462 }
2463 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2464 // Infra STA rate decided from AP Node, index = 0
2465 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2466 }
2467 }
2468
Andres Moreceb8c5d2013-03-18 20:33:49 -05002469 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002470 if (pDevice->byBBType != BB_TYPE_11A) {
2471 pDevice->wCurrentRate = RATE_1M;
2472 pDevice->byACKRate = RATE_1M;
2473 pDevice->byTopCCKBasicRate = RATE_1M;
2474 pDevice->byTopOFDMBasicRate = RATE_6M;
2475 } else {
2476 pDevice->wCurrentRate = RATE_6M;
2477 pDevice->byACKRate = RATE_6M;
2478 pDevice->byTopCCKBasicRate = RATE_1M;
2479 pDevice->byTopOFDMBasicRate = RATE_6M;
2480 }
2481 }
Forest Bond92b96792009-06-13 07:38:31 -04002482
Andres More0cbd8d92010-05-06 20:34:29 -03002483 DBG_PRT(MSG_LEVEL_DEBUG,
2484 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2485 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002486
2487 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002488 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002489 }
2490
2491 if (pDevice->wCurrentRate <= RATE_11M) {
2492 byPktType = PK_TYPE_11B;
2493 }
2494
Andres More4e9b5e22013-02-12 20:36:30 -05002495 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002496 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2497 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002498 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002499 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002500 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2501 if (pTransmitKey == NULL) {
2502 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2503 }
2504 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002505 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002506 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2507 }
2508 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002509 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2510 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002511 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002512 }
2513 }
2514 }
2515
Forest Bond92b96792009-06-13 07:38:31 -04002516 if (pDevice->bEnableHostWEP) {
2517 if ((uNodeIndex != 0) &&
2518 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002519 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2520 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002521 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002522 }
2523 }
2524 }
2525 else {
2526
Forest Bond92b96792009-06-13 07:38:31 -04002527 if (pTransmitKey == NULL) {
2528 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002529 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002530 dev_kfree_skb_irq(skb);
2531 pStats->tx_dropped++;
2532 return STATUS_FAILURE;
2533 }
Forest Bond92b96792009-06-13 07:38:31 -04002534 }
2535 }
2536
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002537 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2538
Forest Bond92b96792009-06-13 07:38:31 -04002539 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002540 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002541 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002542 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002543 pDevice->wCurrentRate,
2544 &uHeaderLen, &BytesToWrite
2545 );
2546
Andres Moree269fc22013-02-12 20:36:29 -05002547 if (fConvertedPacket == false) {
2548 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002549 dev_kfree_skb_irq(skb);
2550 return STATUS_FAILURE;
2551 }
2552
Andres More4e9b5e22013-02-12 20:36:30 -05002553 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002554 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002555 bScheduleCommand((void *) pDevice,
2556 WLAN_CMD_MAC_DISPOWERSAVING,
2557 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002558 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002559 }
2560 }
2561
Andres Moreb902fbf2013-02-25 20:32:51 -05002562 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002563 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002564
2565 pContext->pPacket = skb;
2566 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002567 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002568
Andres Moreceb8c5d2013-03-18 20:33:49 -05002569 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 -04002570
2571 status = PIPEnsSendBulkOut(pDevice,pContext);
2572
Andres More4e9b5e22013-02-12 20:36:30 -05002573 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002574 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002575
Andres Moreb902fbf2013-02-25 20:32:51 -05002576 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002577 }
2578
2579 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002580 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002581 dev_kfree_skb_irq(skb);
2582 return STATUS_FAILURE;
2583 }
2584 else
2585 return 0;
2586
2587}
2588
Forest Bond92b96792009-06-13 07:38:31 -04002589/*
2590 * Description:
2591 * Relay packet send (AC1DMA) from rx dpc.
2592 *
2593 * Parameters:
2594 * In:
2595 * pDevice - Pointer to the adapter
2596 * pPacket - Pointer to rx packet
2597 * cbPacketSize - rx ethernet frame size
2598 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002599 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002600 *
Andres More4e9b5e22013-02-12 20:36:30 -05002601 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002602 */
2603
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002604int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2605 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002606{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002607 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002608 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002609 u32 BytesToWrite = 0, uHeaderLen = 0;
2610 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002611 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002612 SKeyItem STempKey;
2613 PSKeyItem pTransmitKey = NULL;
2614 u8 *pbyBSSID;
2615 PUSB_SEND_CONTEXT pContext;
2616 u8 byPktTyp;
2617 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002618 u32 status;
2619 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002620
Forest Bond92b96792009-06-13 07:38:31 -04002621 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2622
2623 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002624 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002625 }
2626
Andres Moreceb8c5d2013-03-18 20:33:49 -05002627 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002628
Andres More4e9b5e22013-02-12 20:36:30 -05002629 if (pDevice->bEncryptionEnable == true) {
2630 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002631 // get group key
2632 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002633 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002634 pTransmitKey = NULL;
2635 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2636 } else {
2637 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2638 }
2639 }
2640
2641 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002642 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002643 pTransmitKey = &STempKey;
2644 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2645 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2646 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2647 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2648 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2649 memcpy(pTransmitKey->abyKey,
2650 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2651 pTransmitKey->uKeyLength
2652 );
2653 }
2654 }
2655
2656 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002657 pContext->bBoolInUse = false;
2658 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002659 }
2660
Andres Moreb902fbf2013-02-25 20:32:51 -05002661 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002662
2663 if (pDevice->bFixRate) {
2664 if (pDevice->byBBType == BB_TYPE_11B) {
2665 if (pDevice->uConnectionRate >= RATE_11M) {
2666 pDevice->wCurrentRate = RATE_11M;
2667 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002668 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002669 }
2670 } else {
2671 if ((pDevice->byBBType == BB_TYPE_11A) &&
2672 (pDevice->uConnectionRate <= RATE_6M)) {
2673 pDevice->wCurrentRate = RATE_6M;
2674 } else {
2675 if (pDevice->uConnectionRate >= RATE_54M)
2676 pDevice->wCurrentRate = RATE_54M;
2677 else
Andres More3eaca0d2013-02-25 20:32:52 -05002678 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002679 }
2680 }
2681 }
2682 else {
2683 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2684 }
2685
Forest Bond92b96792009-06-13 07:38:31 -04002686 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002687 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002688 }
2689
2690 if (pDevice->wCurrentRate <= RATE_11M)
2691 byPktType = PK_TYPE_11B;
2692
Andres Moreabad19d2010-07-12 16:28:32 -03002693 BytesToWrite = uDataLen + ETH_FCS_LEN;
2694
Forest Bond92b96792009-06-13 07:38:31 -04002695 // Convert the packet to an usb frame and copy into our buffer
2696 // and send the irp.
2697
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002698 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2699
Forest Bond92b96792009-06-13 07:38:31 -04002700 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002701 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002702 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2703 pbySkbData, pTransmitKey, uNodeIndex,
2704 pDevice->wCurrentRate,
2705 &uHeaderLen, &BytesToWrite
2706 );
2707
Andres Moree269fc22013-02-12 20:36:29 -05002708 if (fConvertedPacket == false) {
2709 pContext->bBoolInUse = false;
2710 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002711 }
2712
Andres Moreb902fbf2013-02-25 20:32:51 -05002713 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002714 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002715
2716 pContext->pPacket = NULL;
2717 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002718 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002719
Andres Moreceb8c5d2013-03-18 20:33:49 -05002720 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 -04002721
2722 status = PIPEnsSendBulkOut(pDevice,pContext);
2723
Andres More4e9b5e22013-02-12 20:36:30 -05002724 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002725}
2726