blob: 1d0611ee7e0a25b4d9a6cedce9daafc13ddb5c39 [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020034 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040035 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020038 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040039 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
44 *
45 * Revision History:
46 *
47 */
48
Forest Bond92b96792009-06-13 07:38:31 -040049#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "tether.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070064
Mariano Reingart4a499de2010-10-29 19:15:26 -030065static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040066
Andres More3eaca0d2013-02-25 20:32:52 -050067const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040068 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
69 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
70 };
71
Andres More3eaca0d2013-02-25 20:32:52 -050072const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040073 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
74 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
75 };
Andres More3eaca0d2013-02-25 20:32:52 -050076const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040077 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
78 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
79 };
80
Forest Bond92b96792009-06-13 07:38:31 -040081#define RTSDUR_BB 0
82#define RTSDUR_BA 1
83#define RTSDUR_AA 2
84#define CTSDUR_BA 3
85#define RTSDUR_BA_F0 4
86#define RTSDUR_AA_F0 5
87#define RTSDUR_BA_F1 6
88#define RTSDUR_AA_F1 7
89#define CTSDUR_BA_F0 8
90#define CTSDUR_BA_F1 9
91#define DATADUR_B 10
92#define DATADUR_A 11
93#define DATADUR_A_F0 12
94#define DATADUR_A_F1 13
95
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000096static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
97 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000099static void *s_vGetFreeContext(struct vnt_private *pDevice);
100
101static void s_vGenerateTxParameter(struct vnt_private *pDevice,
102 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
103 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500104 struct ethhdr *psEthHeader);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000105
106static u32 s_uFillDataHead(struct vnt_private *pDevice,
107 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100108 u32 uDMAIdx, int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400109
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000110static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500111 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000112 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400113
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000114static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
115 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
116 u8 *pMICHDR);
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 Priestleyd56131d2013-01-17 23:15:22 +0000124static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
125 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,
129 int bDisCRC, 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,
132 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500133 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400134
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100135static u16 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
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,
186 u16 wPayloadLen, u8 *pMICHDR)
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);
190 u16 wValue;
Andres More1cac4a42013-03-18 20:33:50 -0500191 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000192 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400193
Forest Bond92b96792009-06-13 07:38:31 -0400194 //Fill TXKEY
195 if (pTransmitKey == NULL)
196 return;
197
198 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
199 *pdwIV = pDevice->dwIVCounter;
200 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
201
202 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
203 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
Andres Moreb902fbf2013-02-25 20:32:51 -0500204 memcpy(pDevice->abyPRNG, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700205 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400206 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500207 memcpy(pbyBuf, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700208 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400209 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500210 memcpy(pbyBuf+8, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700211 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400212 }
Jim Lieb3e362592009-08-12 14:54:11 -0700213 memcpy(pDevice->abyPRNG, pbyBuf, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400214 }
215 // Append IV after Mac Header
216 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
Malcolm Priestleyd5bbef72012-11-11 15:53:14 +0000217 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
Forest Bond92b96792009-06-13 07:38:31 -0400218 *pdwIV = cpu_to_le32(*pdwIV);
219 pDevice->dwIVCounter++;
220 if (pDevice->dwIVCounter > WEP_IV_MASK) {
221 pDevice->dwIVCounter = 0;
222 }
223 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
224 pTransmitKey->wTSC15_0++;
225 if (pTransmitKey->wTSC15_0 == 0) {
226 pTransmitKey->dwTSC47_16++;
227 }
228 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
229 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
Jim Lieb3e362592009-08-12 14:54:11 -0700230 memcpy(pbyBuf, pDevice->abyPRNG, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400231 // Make IV
Jim Lieb3e362592009-08-12 14:54:11 -0700232 memcpy(pdwIV, pDevice->abyPRNG, 3);
Forest Bond92b96792009-06-13 07:38:31 -0400233
Andres Moreb902fbf2013-02-25 20:32:51 -0500234 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Forest Bond92b96792009-06-13 07:38:31 -0400235 // Append IV&ExtIV after Mac Header
236 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +0000237 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %x\n",
238 *pdwExtIV);
Forest Bond92b96792009-06-13 07:38:31 -0400239
240 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
241 pTransmitKey->wTSC15_0++;
242 if (pTransmitKey->wTSC15_0 == 0) {
243 pTransmitKey->dwTSC47_16++;
244 }
Jim Lieb3e362592009-08-12 14:54:11 -0700245 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400246
247 // Make IV
248 *pdwIV = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -0500249 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Andres More3eaca0d2013-02-25 20:32:52 -0500250 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
Forest Bond92b96792009-06-13 07:38:31 -0400251 //Append IV&ExtIV after Mac Header
252 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
253
254 //Fill MICHDR0
255 *pMICHDR = 0x59;
Andres Moreb902fbf2013-02-25 20:32:51 -0500256 *((u8 *)(pMICHDR+1)) = 0; // TxPriority
Andres More1cac4a42013-03-18 20:33:50 -0500257 memcpy(pMICHDR+2, &(pMACHeader->addr2[0]), 6);
Andres Moreb902fbf2013-02-25 20:32:51 -0500258 *((u8 *)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
259 *((u8 *)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
260 *((u8 *)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
261 *((u8 *)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
262 *((u8 *)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
263 *((u8 *)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
264 *((u8 *)(pMICHDR+14)) = HIBYTE(wPayloadLen);
265 *((u8 *)(pMICHDR+15)) = LOBYTE(wPayloadLen);
Forest Bond92b96792009-06-13 07:38:31 -0400266
267 //Fill MICHDR1
Andres Moreb902fbf2013-02-25 20:32:51 -0500268 *((u8 *)(pMICHDR+16)) = 0; // HLEN[15:8]
Forest Bond92b96792009-06-13 07:38:31 -0400269 if (pDevice->bLongHeader) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500270 *((u8 *)(pMICHDR+17)) = 28; // HLEN[7:0]
Forest Bond92b96792009-06-13 07:38:31 -0400271 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500272 *((u8 *)(pMICHDR+17)) = 22; // HLEN[7:0]
Forest Bond92b96792009-06-13 07:38:31 -0400273 }
Andres More1cac4a42013-03-18 20:33:50 -0500274 wValue = cpu_to_le16(pMACHeader->frame_control & 0xC78F);
Andres Moreb902fbf2013-02-25 20:32:51 -0500275 memcpy(pMICHDR+18, (u8 *)&wValue, 2); // MSKFRACTL
Andres More1cac4a42013-03-18 20:33:50 -0500276 memcpy(pMICHDR+20, &(pMACHeader->addr1[0]), 6);
277 memcpy(pMICHDR+26, &(pMACHeader->addr2[0]), 6);
Forest Bond92b96792009-06-13 07:38:31 -0400278
279 //Fill MICHDR2
Andres More1cac4a42013-03-18 20:33:50 -0500280 memcpy(pMICHDR+32, &(pMACHeader->addr3[0]), 6);
281 wValue = pMACHeader->seq_ctrl;
Forest Bond92b96792009-06-13 07:38:31 -0400282 wValue &= 0x000F;
283 wValue = cpu_to_le16(wValue);
Andres Moreb902fbf2013-02-25 20:32:51 -0500284 memcpy(pMICHDR+38, (u8 *)&wValue, 2); // MSKSEQCTL
Forest Bond92b96792009-06-13 07:38:31 -0400285 if (pDevice->bLongHeader) {
Andres More1cac4a42013-03-18 20:33:50 -0500286 memcpy(pMICHDR+40, &(pMACHeader->addr4[0]), 6);
Forest Bond92b96792009-06-13 07:38:31 -0400287 }
288 }
289}
290
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000291static void s_vSWencryption(struct vnt_private *pDevice,
292 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400293{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000294 u32 cbICVlen = 4;
295 u32 dwICV = 0xffffffff;
296 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400297
298 if (pTransmitKey == NULL)
299 return;
300
301 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
302 //=======================================================================
303 // Append ICV after payload
304 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500305 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400306 // finally, we must invert dwCRC to get the correct answer
307 *pdwICV = cpu_to_le32(~dwICV);
308 // RC4 encryption
309 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
310 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
311 //=======================================================================
312 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
313 //=======================================================================
314 //Append ICV after payload
315 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500316 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400317 // finally, we must invert dwCRC to get the correct answer
318 *pdwICV = cpu_to_le32(~dwICV);
319 // RC4 encryption
320 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
321 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
322 //=======================================================================
323 }
324}
325
Forest Bond92b96792009-06-13 07:38:31 -0400326/*byPktType : PK_TYPE_11A 0
327 PK_TYPE_11B 1
328 PK_TYPE_11GB 2
329 PK_TYPE_11GA 3
330*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000331static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
332 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400333{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000334 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400335
336 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
337 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500338 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400339 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500340 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400341 }
342
343 if (bNeedAck) {
344 return (uDataTime + pDevice->uSIFS + uAckTime);
345 }
346 else {
347 return uDataTime;
348 }
349}
350
351//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000352static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
353 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400354{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000355 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400356
357 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
358
Forest Bond92b96792009-06-13 07:38:31 -0400359 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
360 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
361 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
362 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
363 }
364 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
365 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
366 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
367 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
368 }
369 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
370 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
371 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
372 }
373 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
374 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
375 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
376 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
377 return uRrvTime;
378 }
379
380 //RTSRrvTime
381 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
382 return uRrvTime;
383}
384
385//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100386static u16 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100387 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400388{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100389 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400390
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100391 if (bNeedAck) {
392 if (byDurType == DATADUR_B)
393 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
394 byPktType, 14, pDevice->byTopCCKBasicRate);
395 else
396 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
397 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100398 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100399 }
Forest Bond92b96792009-06-13 07:38:31 -0400400
Forest Bond92b96792009-06-13 07:38:31 -0400401 return 0;
402}
403
Forest Bond92b96792009-06-13 07:38:31 -0400404//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100405static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000406 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
407 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400408{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000409 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400410
Forest Bond92b96792009-06-13 07:38:31 -0400411 switch (byDurType) {
412
413 case RTSDUR_BB: //RTSDuration_bb
414 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
415 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
416 break;
417
418 case RTSDUR_BA: //RTSDuration_ba
419 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
420 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
421 break;
422
423 case RTSDUR_AA: //RTSDuration_aa
424 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
425 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
426 break;
427
428 case CTSDUR_BA: //CTSDuration_ba
429 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
430 break;
431
432 case RTSDUR_BA_F0: //RTSDuration_ba_f0
433 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
434 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
435 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
436 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
437 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
438 }
439 break;
440
441 case RTSDUR_AA_F0: //RTSDuration_aa_f0
442 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
443 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
444 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
445 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
446 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
447 }
448 break;
449
450 case RTSDUR_BA_F1: //RTSDuration_ba_f1
451 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
452 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
453 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
454 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
455 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
456 }
457 break;
458
459 case RTSDUR_AA_F1: //RTSDuration_aa_f1
460 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
461 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
462 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
463 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
464 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
465 }
466 break;
467
468 case CTSDUR_BA_F0: //CTSDuration_ba_f0
469 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
470 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
471 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
472 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
473 }
474 break;
475
476 case CTSDUR_BA_F1: //CTSDuration_ba_f1
477 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
478 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
479 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
480 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
481 }
482 break;
483
484 default:
485 break;
486 }
487
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100488 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400489}
490
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000491static u32 s_uFillDataHead(struct vnt_private *pDevice,
492 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100493 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400494{
495
496 if (pTxDataHead == NULL) {
497 return 0;
498 }
499
500 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Forest Bond92b96792009-06-13 07:38:31 -0400501 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +0100502 struct vnt_tx_datahead_g *pBuf =
503 (struct vnt_tx_datahead_g *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400504 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100505 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
506 byPktType, &pBuf->a);
507 BBvCalculateParameter(pDevice, cbFrameLength,
508 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400509 //Get Duration and TimeStamp
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100510 pBuf->wDuration_a = s_uGetDataDuration(pDevice, DATADUR_A,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100511 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100512 pBuf->wDuration_b = s_uGetDataDuration(pDevice, DATADUR_B,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100513 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400514
515 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
516 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
517 return (pBuf->wDuration_a);
518 } else {
519 // Auto Fallback
Malcolm Priestley7c05c542013-08-16 23:49:15 +0100520 struct vnt_tx_datahead_g_fb *pBuf =
521 (struct vnt_tx_datahead_g_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400522 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100523 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
524 byPktType, &pBuf->a);
525 BBvCalculateParameter(pDevice, cbFrameLength,
526 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400527 //Get Duration and TimeStamp
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100528 pBuf->wDuration_a = s_uGetDataDuration(pDevice, DATADUR_A,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100529 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100530 pBuf->wDuration_b = s_uGetDataDuration(pDevice, DATADUR_B,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100531 PK_TYPE_11B, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100532 pBuf->wDuration_a_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100533 DATADUR_A_F0, byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100534 pBuf->wDuration_a_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100535 DATADUR_A_F1, byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400536 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
537 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
538 return (pBuf->wDuration_a);
539 } //if (byFBOption == AUTO_FB_NONE)
Forest Bond92b96792009-06-13 07:38:31 -0400540 }
541 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100542 if (byFBOption != AUTO_FB_NONE) {
Malcolm Priestley1da4ee22013-08-16 23:51:38 +0100543 struct vnt_tx_datahead_a_fb *pBuf =
544 (struct vnt_tx_datahead_a_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400545 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100546 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
547 byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400548 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100549 pBuf->wDuration = s_uGetDataDuration(pDevice, DATADUR_A,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100550 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100551 pBuf->wDuration_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100552 DATADUR_A_F0, byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100553 pBuf->wDuration_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100554 DATADUR_A_F1, byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400555 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Forest Bond92b96792009-06-13 07:38:31 -0400556 return (pBuf->wDuration);
557 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100558 struct vnt_tx_datahead_ab *pBuf =
559 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400560 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100561 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
562 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400563 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100564 pBuf->wDuration = s_uGetDataDuration(pDevice, DATADUR_A,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100565 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400566 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100567
Forest Bond92b96792009-06-13 07:38:31 -0400568 return (pBuf->wDuration);
569 }
570 }
571 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100572 struct vnt_tx_datahead_ab *pBuf =
573 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400574 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100575 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
576 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400577 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100578 pBuf->wDuration = s_uGetDataDuration(pDevice, DATADUR_B,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100579 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400580 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100581
Forest Bond92b96792009-06-13 07:38:31 -0400582 return (pBuf->wDuration);
583 }
584 return 0;
585}
586
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000587static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
588 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500589 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400590{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000591 u32 uRTSFrameLen = 20;
Forest Bond92b96792009-06-13 07:38:31 -0400592
Forest Bond92b96792009-06-13 07:38:31 -0400593 if (pvRTS == NULL)
594 return;
595
596 if (bDisCRC) {
597 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
598 // in this case we need to decrease its length by 4.
599 uRTSFrameLen -= 4;
600 }
601
Masanari Iida93184692012-08-13 21:21:50 +0900602 // Note: So far RTSHead doesn't appear in ATIM & Beacom DMA, so we don't need to take them into account.
Forest Bond92b96792009-06-13 07:38:31 -0400603 // Otherwise, we need to modified codes for them.
604 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
605 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100606 struct vnt_rts_g *pBuf = (struct vnt_rts_g *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400607 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100608 BBvCalculateParameter(pDevice, uRTSFrameLen,
609 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
610 BBvCalculateParameter(pDevice, uRTSFrameLen,
611 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400612 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100613 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
614 cbFrameLength, PK_TYPE_11B,
615 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
616 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
617 cbFrameLength, byPktType,
618 wCurrentRate, bNeedAck, byFBOption);
619 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
620 cbFrameLength, byPktType,
621 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100622 pBuf->data.duration = pBuf->wDuration_aa;
623 /*Get RTS Frame body */
624 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400625
Malcolm Priestley07738932013-08-05 22:08:05 +0100626 if (pDevice->eOPMode == OP_MODE_ADHOC ||
627 pDevice->eOPMode == OP_MODE_AP)
628 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
629 else
630 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Andres More9a0e7562010-04-13 21:54:48 -0300631
Malcolm Priestley07738932013-08-05 22:08:05 +0100632 if (pDevice->eOPMode == OP_MODE_AP)
633 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
634 else
635 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400636 }
637 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100638 struct vnt_rts_g_fb *pBuf = (struct vnt_rts_g_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400639 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100640 BBvCalculateParameter(pDevice, uRTSFrameLen,
641 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
642 BBvCalculateParameter(pDevice, uRTSFrameLen,
643 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400644 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100645 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
646 cbFrameLength, PK_TYPE_11B,
647 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
648 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
649 cbFrameLength, byPktType,
650 wCurrentRate, bNeedAck, byFBOption);
651 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
652 cbFrameLength, byPktType,
653 wCurrentRate, bNeedAck, byFBOption);
654 pBuf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
655 RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
656 bNeedAck, byFBOption);
657 pBuf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(pDevice,
658 RTSDUR_AA_F0, cbFrameLength, byPktType,
659 wCurrentRate, bNeedAck, byFBOption);
660 pBuf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
661 RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
662 bNeedAck, byFBOption);
663 pBuf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(pDevice,
664 RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate,
665 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100666 pBuf->data.duration = pBuf->wDuration_aa;
667 /*Get RTS Frame body*/
668 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400669
Malcolm Priestley07738932013-08-05 22:08:05 +0100670 if (pDevice->eOPMode == OP_MODE_ADHOC ||
671 pDevice->eOPMode == OP_MODE_AP)
672 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
673 else
674 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400675
Malcolm Priestley07738932013-08-05 22:08:05 +0100676 if (pDevice->eOPMode == OP_MODE_AP)
677 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
678 else
679 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400680 } // if (byFBOption == AUTO_FB_NONE)
681 }
682 else if (byPktType == PK_TYPE_11A) {
683 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100684 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400685 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100686 BBvCalculateParameter(pDevice, uRTSFrameLen,
687 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400688 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100689 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
690 cbFrameLength, byPktType, wCurrentRate,
691 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100692 pBuf->data.duration = pBuf->wDuration;
693 /* Get RTS Frame body */
694 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400695
Malcolm Priestley07738932013-08-05 22:08:05 +0100696 if (pDevice->eOPMode == OP_MODE_ADHOC ||
697 pDevice->eOPMode == OP_MODE_AP)
698 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
699 else
700 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400701
Malcolm Priestley07738932013-08-05 22:08:05 +0100702 if (pDevice->eOPMode == OP_MODE_AP)
703 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
704 else
705 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400706 }
707 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100708 struct vnt_rts_a_fb *pBuf = (struct vnt_rts_a_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400709 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100710 BBvCalculateParameter(pDevice, uRTSFrameLen,
711 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400712 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100713 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
714 cbFrameLength, byPktType, wCurrentRate,
715 bNeedAck, byFBOption);
716 pBuf->wRTSDuration_f0 = s_uGetRTSCTSDuration(pDevice,
717 RTSDUR_AA_F0, cbFrameLength, byPktType,
718 wCurrentRate, bNeedAck, byFBOption);
719 pBuf->wRTSDuration_f1 = s_uGetRTSCTSDuration(pDevice,
720 RTSDUR_AA_F1, cbFrameLength, byPktType,
721 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100722 pBuf->data.duration = pBuf->wDuration;
723 /* Get RTS Frame body */
724 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400725
Malcolm Priestley07738932013-08-05 22:08:05 +0100726 if (pDevice->eOPMode == OP_MODE_ADHOC ||
727 pDevice->eOPMode == OP_MODE_AP)
728 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
729 else
730 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
731
732 if (pDevice->eOPMode == OP_MODE_AP)
733 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
734 else
735 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400736 }
737 }
738 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100739 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400740 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100741 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate,
742 PK_TYPE_11B, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400743 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100744 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
745 cbFrameLength, byPktType, wCurrentRate,
746 bNeedAck, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400747
Malcolm Priestley07738932013-08-05 22:08:05 +0100748 pBuf->data.duration = pBuf->wDuration;
749 /* Get RTS Frame body */
750 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400751
Malcolm Priestley07738932013-08-05 22:08:05 +0100752 if (pDevice->eOPMode == OP_MODE_ADHOC ||
753 pDevice->eOPMode == OP_MODE_AP)
754 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
755 else
756 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
757
758 if (pDevice->eOPMode == OP_MODE_AP)
759 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
760 else
761 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400762 }
763}
764
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000765static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
766 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
767 int bDisCRC, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400768{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000769 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400770
771 if (pvCTS == NULL) {
772 return;
773 }
774
775 if (bDisCRC) {
776 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
777 // in this case we need to decrease its length by 4.
778 uCTSFrameLen -= 4;
779 }
780
781 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100782 if (byFBOption != AUTO_FB_NONE) {
783 /* Auto Fall back */
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100784 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100785 /* Get SignalField,ServiceField,Length */
786 BBvCalculateParameter(pDevice, uCTSFrameLen,
787 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100788 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
789 cbFrameLength, byPktType,
790 wCurrentRate, bNeedAck, byFBOption);
791 /* Get CTSDuration_ba_f0 */
792 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
793 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
794 bNeedAck, byFBOption);
795 /* Get CTSDuration_ba_f1 */
796 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
797 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
798 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);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100803 } else {
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100804 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100805 /* Get SignalField,ServiceField,Length */
806 BBvCalculateParameter(pDevice, uCTSFrameLen,
807 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100808 /* Get CTSDuration_ba */
809 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
810 CTSDUR_BA, cbFrameLength, byPktType,
811 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100812 /*Get CTS Frame body*/
813 pBuf->data.duration = pBuf->wDuration_ba;
814 pBuf->data.frame_control = TYPE_CTL_CTS;
815 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400816 }
817 }
818}
819
Forest Bond92b96792009-06-13 07:38:31 -0400820/*+
821 *
822 * Description:
823 * Generate FIFO control for MAC & Baseband controller
824 *
825 * Parameters:
826 * In:
827 * pDevice - Pointer to adpater
828 * pTxDataHead - Transmit Data Buffer
829 * pTxBufHead - pTxBufHead
830 * pvRrvTime - pvRrvTime
831 * pvRTS - RTS Buffer
832 * pCTS - CTS Buffer
833 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
834 * bNeedACK - If need ACK
835 * uDMAIdx - DMA Index
836 * Out:
837 * none
838 *
839 * Return Value: none
840 *
841-*/
Andres Morecc856e62010-05-17 21:34:01 -0300842
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000843static void s_vGenerateTxParameter(struct vnt_private *pDevice,
844 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
845 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500846 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400847{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000848 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
849 u16 wFifoCtl;
Andres Moree269fc22013-02-12 20:36:29 -0500850 int bDisCRC = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000851 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400852
853 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
854 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
855 pFifoHead->wReserved = wCurrentRate;
856 wFifoCtl = pFifoHead->wFIFOCtl;
857
858 if (wFifoCtl & FIFOCTL_CRCDIS) {
Andres More4e9b5e22013-02-12 20:36:30 -0500859 bDisCRC = true;
Forest Bond92b96792009-06-13 07:38:31 -0400860 }
861
862 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
863 byFBOption = AUTO_FB_0;
864 }
865 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
866 byFBOption = AUTO_FB_1;
867 }
868
869 if (pDevice->bLongHeader)
870 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
871
872 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
873
874 if (pvRTS != NULL) { //RTS_need
875 //Fill RsvTime
876 if (pvRrvTime) {
Malcolm Priestley6398a592013-08-16 21:26:55 +0100877 struct vnt_rrv_time_rts *pBuf =
878 (struct vnt_rrv_time_rts *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500879 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
880 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
881 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
882 pBuf->wTxRrvTime_a = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
883 pBuf->wTxRrvTime_b = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400884 }
885 //Fill RTS
886 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
887 }
888 else {//RTS_needless, PCF mode
889
890 //Fill RsvTime
891 if (pvRrvTime) {
Malcolm Priestley4f990052013-08-16 23:38:57 +0100892 struct vnt_rrv_time_cts *pBuf =
893 (struct vnt_rrv_time_cts *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500894 pBuf->wTxRrvTime_a = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
895 pBuf->wTxRrvTime_b = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
896 pBuf->wCTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
Forest Bond92b96792009-06-13 07:38:31 -0400897 }
898 //Fill CTS
899 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
900 }
901 }
902 else if (byPktType == PK_TYPE_11A) {
903
904 if (pvRTS != NULL) {//RTS_need, non PCF mode
905 //Fill RsvTime
906 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100907 struct vnt_rrv_time_ab *pBuf =
908 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500909 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
910 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400911 }
912 //Fill RTS
913 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
914 }
915 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
916 //Fill RsvTime
917 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100918 struct vnt_rrv_time_ab *pBuf =
919 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500920 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400921 }
922 }
923 }
924 else if (byPktType == PK_TYPE_11B) {
925
926 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
927 //Fill RsvTime
928 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100929 struct vnt_rrv_time_ab *pBuf =
930 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500931 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
932 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400933 }
934 //Fill RTS
935 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
936 }
937 else { //RTS_needless, non PCF mode
938 //Fill RsvTime
939 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100940 struct vnt_rrv_time_ab *pBuf =
941 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500942 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400943 }
944 }
945 }
946 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
947}
948/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500949 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500950 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300951 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400952*/
953
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000954static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100955 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
956 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
957 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
958 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400959{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000960 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
961 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000962 u32 cb802_1_H_len;
963 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
964 u32 cbFCSlen = 4, cbMICHDR = 0;
965 int bNeedACK, bRTS;
966 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
967 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
968 u8 abySNAP_Bridgetunnel[ETH_ALEN]
969 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
970 u32 uDuration;
971 u32 cbHeaderLength = 0, uPadding = 0;
972 void *pvRrvTime;
973 PSMICHDRHead pMICHDR;
974 void *pvRTS;
975 void *pvCTS;
976 void *pvTxDataHd;
977 u8 byFBOption = AUTO_FB_NONE, byFragType;
978 u16 wTxBufSize;
979 u32 dwMICKey0, dwMICKey1, dwMIC_Priority, dwCRC;
980 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500981 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -0400982
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000983 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400984
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000985 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500986 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
987 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000988 }
Forest Bond92b96792009-06-13 07:38:31 -0400989
Forest Bond92b96792009-06-13 07:38:31 -0400990 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -0500991 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -0400992 if (pDevice->dwDiagRefCount == 0) {
993 cb802_1_H_len = 8;
994 } else {
995 cb802_1_H_len = 2;
996 }
997 } else {
998 cb802_1_H_len = 0;
999 }
1000
Charles Clément21ec51f2010-05-18 10:08:14 -07001001 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001002
1003 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001004 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001005
1006 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001007 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001008 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1009 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001010 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1011 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001012 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001013 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001014 pTxBufHead->wFIFOCtl =
1015 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1016 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001017 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001018 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1019 }
Forest Bond92b96792009-06-13 07:38:31 -04001020 }
1021 else {
1022 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001023 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001024 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1025 }
1026 } //if (pDevice->dwDiagRefCount != 0) {
1027
1028 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1029
1030 //Set FIFOCTL_LHEAD
1031 if (pDevice->bLongHeader)
1032 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1033
1034 if (pDevice->bSoftwareGenCrcErr) {
1035 pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS; // set tx descriptors to NO hardware CRC
1036 }
1037
1038 //Set FRAGCTL_MACHDCNT
1039 if (pDevice->bLongHeader) {
1040 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1041 } else {
1042 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1043 }
Andres More3eaca0d2013-02-25 20:32:52 -05001044 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001045
1046 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001047 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001048 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1049 }
1050
1051 //Set Auto Fallback Ctl
1052 if (wCurrentRate >= RATE_18M) {
1053 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1054 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1055 byFBOption = AUTO_FB_0;
1056 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1057 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1058 byFBOption = AUTO_FB_1;
1059 }
1060 }
1061
Andres More4e9b5e22013-02-12 20:36:30 -05001062 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001063 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1064 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1065 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1066 }
1067 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1068 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1069 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1070 }
1071 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1072 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1073 }
1074 }
1075 }
1076
Forest Bond92b96792009-06-13 07:38:31 -04001077 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1078 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1079 cbIVlen = 4;
1080 cbICVlen = 4;
1081 }
1082 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1083 cbIVlen = 8;//IV+ExtIV
1084 cbMIClen = 8;
1085 cbICVlen = 4;
1086 }
1087 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1088 cbIVlen = 8;//RSN Header
1089 cbICVlen = 8;//MIC
1090 cbMICHDR = sizeof(SMICHDRHead);
1091 }
Andres Moree269fc22013-02-12 20:36:29 -05001092 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001093 //MAC Header should be padding 0 to DW alignment.
1094 uPadding = 4 - (cbMACHdLen%4);
1095 uPadding %= 4;
1096 }
1097 }
1098
1099 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1100
Andres Moree269fc22013-02-12 20:36:29 -05001101 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1102 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001103 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001104 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001105 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1106 }
1107
Andres Moreb902fbf2013-02-25 20:32:51 -05001108 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001109 wTxBufSize = sizeof(STxBufHead);
1110 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1111 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001112 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001113 pvRrvTime = (struct vnt_rrv_time_rts *)
1114 (pbyTxBufferAddr + wTxBufSize);
1115 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1116 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001117 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001118 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001119 pvCTS = NULL;
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001120 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1121 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1122 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001123 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001124 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001125 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001126 }
1127 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001128 pvRrvTime = (struct vnt_rrv_time_cts *)
1129 (pbyTxBufferAddr + wTxBufSize);
1130 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1131 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001132 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001133 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001134 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001135 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1136 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1137 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001138 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1139 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001140 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001141 }
1142 } else {
1143 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001144 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001145 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1146 wTxBufSize);
1147 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1148 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001149 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001150 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001151 pvCTS = NULL;
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001152 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1153 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1154 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001155 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1156 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001157 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001158 }
Andres Moree269fc22013-02-12 20:36:29 -05001159 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001160 pvRrvTime = (struct vnt_rrv_time_cts *)
1161 (pbyTxBufferAddr + wTxBufSize);
1162 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1163 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001164 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001165 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001166 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001167 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001168 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1169 cbMICHDR + sizeof(struct vnt_cts_fb));
1170 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001171 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001172 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001173 }
1174 } // Auto Fall Back
1175 }
1176 else {//802.11a/b packet
1177 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001178 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001179 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1180 wTxBufSize);
1181 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1182 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001183 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001184 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001185 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001186 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1187 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001188 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001189 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1190 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001191 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001192 }
Andres Moree269fc22013-02-12 20:36:29 -05001193 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001194 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1195 wTxBufSize);
1196 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1197 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001198 pvRTS = NULL;
1199 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001200 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1201 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001202 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001203 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001204 }
1205 } else {
1206 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001207 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001208 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1209 wTxBufSize);
1210 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1211 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001212 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001213 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001214 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001215 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1216 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001217 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001218 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1219 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001220 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001221 }
Andres Moree269fc22013-02-12 20:36:29 -05001222 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001223 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1224 wTxBufSize);
1225 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1226 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001227 pvRTS = NULL;
1228 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001229 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1230 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001231 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001232 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001233 }
1234 } // Auto Fall Back
1235 }
1236
Andres Moreb902fbf2013-02-25 20:32:51 -05001237 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1238 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1239 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001240
Forest Bond92b96792009-06-13 07:38:31 -04001241 //=========================
1242 // No Fragmentation
1243 //=========================
1244 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1245 byFragType = FRAGCTL_NONFRAG;
1246 //uDMAIdx = TYPE_AC0DMA;
1247 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1248
Forest Bond92b96792009-06-13 07:38:31 -04001249 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001250 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1251 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001252 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1253 //Fill DataHead
1254 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001255 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001256 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001257 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001258 byFragType, uDMAIdx, 0);
1259
Andres More4e9b5e22013-02-12 20:36:30 -05001260 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001261 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001262 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001263 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001264
1265 if (pDevice->bEnableHostWEP) {
1266 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1267 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1268 }
1269 }
1270
1271 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001272 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001273 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001274 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1275 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001276 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001277 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001278 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001279 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001280 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001281 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001282 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001283 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001284 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001285
1286 }
1287
1288 }
1289
Forest Bond92b96792009-06-13 07:38:31 -04001290 if (pPacket != NULL) {
1291 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001292 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001293 (pPacket + ETH_HLEN),
1294 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001295 );
1296
1297 } else {
1298 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001299 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001300 }
1301
Andres More4e9b5e22013-02-12 20:36:30 -05001302 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001303
1304 ///////////////////////////////////////////////////////////////////
1305
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001306 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1307 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1308 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1309 }
Forest Bond92b96792009-06-13 07:38:31 -04001310 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001311 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1312 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001313 }
1314 else {
Andres More52a7e642013-02-25 20:32:53 -05001315 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1316 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001317 }
1318 // DO Software Michael
1319 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001320 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001321 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001322 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001323 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1324 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001325
1326 ///////////////////////////////////////////////////////////////////
1327
1328 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1329 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001330 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001331 //}
1332 //DBG_PRN_GRP12(("\n\n\n"));
1333
1334 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1335
Andres More52a7e642013-02-25 20:32:53 -05001336 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1337 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001338
1339 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1340 MIC_vUnInit();
1341
Andres More4e9b5e22013-02-12 20:36:30 -05001342 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001343 *pdwMIC_L = 0;
1344 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001345 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001346 }
1347 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1348 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1349 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1350 }
1351
Andres More4e9b5e22013-02-12 20:36:30 -05001352 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001353
Andres More3eaca0d2013-02-25 20:32:52 -05001354 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001355
Andres More4e9b5e22013-02-12 20:36:30 -05001356 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1357 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1358 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001359 cbFrameSize -= cbICVlen;
1360 }
1361
Andres More4e9b5e22013-02-12 20:36:30 -05001362 if (pDevice->bSoftwareGenCrcErr == true) {
Andres Morecc856e62010-05-17 21:34:01 -03001363 unsigned int cbLen;
Andres More52a7e642013-02-25 20:32:53 -05001364 u32 * pdwCRC;
Forest Bond92b96792009-06-13 07:38:31 -04001365
1366 dwCRC = 0xFFFFFFFFL;
1367 cbLen = cbFrameSize - cbFCSlen;
1368 // calculate CRC, and wrtie CRC value to end of TD
1369 dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
Andres More52a7e642013-02-25 20:32:53 -05001370 pdwCRC = (u32 *)(pbyMacHdr + cbLen);
Forest Bond92b96792009-06-13 07:38:31 -04001371 // finally, we must invert dwCRC to get the correct answer
1372 *pdwCRC = ~dwCRC;
1373 // Force Error
1374 *pdwCRC -= 1;
1375 } else {
1376 cbFrameSize -= cbFCSlen;
1377 }
1378
1379 *pcbHeaderLen = cbHeaderLength;
1380 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1381
Forest Bond92b96792009-06-13 07:38:31 -04001382 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001383 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001384
Andres More4e9b5e22013-02-12 20:36:30 -05001385 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001386
1387}
1388
Forest Bond92b96792009-06-13 07:38:31 -04001389/*+
1390 *
1391 * Description:
1392 * Translate 802.3 to 802.11 header
1393 *
1394 * Parameters:
1395 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001396 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001397 * dwTxBufferAddr - Transmit Buffer
1398 * pPacket - Packet from upper layer
1399 * cbPacketSize - Transmit Data Length
1400 * Out:
1401 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1402 * pcbAppendPayload - size of append payload for 802.1H translation
1403 *
1404 * Return Value: none
1405 *
1406-*/
1407
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001408static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001409 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001410 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001411{
Andres More1cac4a42013-03-18 20:33:50 -05001412 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001413
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001414 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001415
1416 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001417 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001418 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001419 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001420 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1421 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001422 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001423 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001424 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001425 } else {
1426 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001427 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001428 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001429 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001430 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001431 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001432 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001433 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001434 &(pDevice->abyBSSID[0]),
1435 ETH_ALEN);
1436 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001437 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001438 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001439 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001440 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001441 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001442 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001443 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001444 &(pDevice->abyBSSID[0]),
1445 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001446 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001447 }
1448 }
1449
1450 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001451 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001452
Andres More1cac4a42013-03-18 20:33:50 -05001453 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001454
1455 if (pDevice->bLongHeader) {
1456 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001457 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001458 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001459 }
Andres More1cac4a42013-03-18 20:33:50 -05001460 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001461
1462 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001463 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001464
1465 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1466 pDevice->wSeqCounter++;
1467 if (pDevice->wSeqCounter > 0x0fff)
1468 pDevice->wSeqCounter = 0;
1469 }
1470
1471 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001472 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001473 }
1474}
1475
Forest Bond92b96792009-06-13 07:38:31 -04001476/*+
1477 *
1478 * Description:
1479 * Request instructs a MAC to transmit a 802.11 management packet through
1480 * the adapter onto the medium.
1481 *
1482 * Parameters:
1483 * In:
1484 * hDeviceContext - Pointer to the adapter
1485 * pPacket - A pointer to a descriptor for the packet to transmit
1486 * Out:
1487 * none
1488 *
Andres Moree269fc22013-02-12 20:36:29 -05001489 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001490 *
1491-*/
1492
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001493CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1494 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001495{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001496 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001497 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001498 PSTxBufHead pTxBufHead;
1499 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001500 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001501 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001502 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001503 u8 byPktType, *pbyTxBufferAddr;
1504 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1505 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001506 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001507 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1508 u32 uPadding = 0;
1509 u16 wTxBufSize;
1510 u32 cbMacHdLen;
1511 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001512
Forest Bond92b96792009-06-13 07:38:31 -04001513 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1514
1515 if (NULL == pContext) {
1516 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1517 return CMD_STATUS_RESOURCES;
1518 }
1519
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001520 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001521 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001522 cbFrameBodySize = pPacket->cbPayloadLen;
1523 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1524 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001525
1526 if (pDevice->byBBType == BB_TYPE_11A) {
1527 wCurrentRate = RATE_6M;
1528 byPktType = PK_TYPE_11A;
1529 } else {
1530 wCurrentRate = RATE_1M;
1531 byPktType = PK_TYPE_11B;
1532 }
1533
1534 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1535 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1536 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1537 // to set power here.
1538 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1539 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1540 } else {
1541 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1542 }
1543 pDevice->wCurrentRate = wCurrentRate;
1544
Forest Bond92b96792009-06-13 07:38:31 -04001545 //Set packet type
1546 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1547 pTxBufHead->wFIFOCtl = 0;
1548 }
1549 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1550 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1551 }
1552 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1553 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1554 }
1555 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1556 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1557 }
1558
1559 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1560 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1561
Andres More22040bb2010-08-02 20:21:44 -03001562 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001563 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001564 }
1565 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001566 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001567 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1568 };
1569
1570 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1571 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1572
1573 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1574 //Set Preamble type always long
1575 //pDevice->byPreambleType = PREAMBLE_LONG;
1576 // probe-response don't retry
1577 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001578 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001579 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1580 //}
1581 }
1582
1583 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1584
1585 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001586 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001587 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1588 } else {
1589 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1590 }
1591
1592 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001593 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001594
1595 // Notes:
1596 // Although spec says MMPDU can be fragmented; In most case,
1597 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001598 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001599
1600 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1601 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1602 cbIVlen = 4;
1603 cbICVlen = 4;
1604 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1605 }
1606 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1607 cbIVlen = 8;//IV+ExtIV
1608 cbMIClen = 8;
1609 cbICVlen = 4;
1610 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1611 //We need to get seed here for filling TxKey entry.
1612 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1613 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1614 }
1615 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1616 cbIVlen = 8;//RSN Header
1617 cbICVlen = 8;//MIC
1618 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001619 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001620 }
1621 //MAC Header should be padding 0 to DW alignment.
1622 uPadding = 4 - (cbMacHdLen%4);
1623 uPadding %= 4;
1624 }
1625
1626 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1627
1628 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001629 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001630 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1631 }
1632 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1633
1634 //Set RrvTime/RTS/CTS Buffer
1635 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1636
Malcolm Priestley4f990052013-08-16 23:38:57 +01001637 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001638 pMICHDR = NULL;
1639 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001640 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001641 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001642 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001643 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1644 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001645 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001646 }
1647 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001648 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001649 pMICHDR = NULL;
1650 pvRTS = NULL;
1651 pCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001652 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1653 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001654 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001655 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001656 }
1657
Andres Moreceb8c5d2013-03-18 20:33:49 -05001658 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001659 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1660 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001661 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001662 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1663 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001664 //=========================
1665 // No Fragmentation
1666 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001667 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001668
Forest Bond92b96792009-06-13 07:38:31 -04001669 //Fill FIFO,RrvTime,RTS,and CTS
1670 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1671 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1672
1673 //Fill DataHead
1674 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001675 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001676
Andres More1cac4a42013-03-18 20:33:50 -05001677 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001678
1679 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1680
1681 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001682 u8 * pbyIVHead;
1683 u8 * pbyPayloadHead;
1684 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001685 PSKeyItem pTransmitKey = NULL;
1686
Andres Moreb902fbf2013-02-25 20:32:51 -05001687 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1688 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001689 do {
1690 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001691 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001692 pbyBSSID = pDevice->abyBSSID;
1693 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001694 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001695 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001696 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001697 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1698 break;
1699 }
1700 } else {
1701 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1702 break;
1703 }
1704 }
1705 // get group key
1706 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001707 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001708 pTransmitKey = NULL;
1709 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1710 } else {
1711 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1712 }
Andres Moree269fc22013-02-12 20:36:29 -05001713 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001714 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001715 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001716 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001717
Jim Lieb3e362592009-08-12 14:54:11 -07001718 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001719 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001720 cbFrameBodySize);
1721 }
1722 else {
1723 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001724 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001725 }
1726
Andres More1cac4a42013-03-18 20:33:50 -05001727 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001728 pDevice->wSeqCounter++ ;
1729 if (pDevice->wSeqCounter > 0x0fff)
1730 pDevice->wSeqCounter = 0;
1731
1732 if (bIsPSPOLL) {
1733 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001734 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001735 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1736 // in the same place of other packet's Duration-field).
1737 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001738 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1739 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1740 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1741 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1742 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1743 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001744 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1745 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1746 }
Forest Bond92b96792009-06-13 07:38:31 -04001747 }
1748
Andres More3eaca0d2013-02-25 20:32:52 -05001749 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001750 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001751 pTX_Buffer->byType = 0x00;
1752
1753 pContext->pPacket = NULL;
1754 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001755 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001756
Andres More1cac4a42013-03-18 20:33:50 -05001757 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1758 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001759 }
1760 else {
Andres More1cac4a42013-03-18 20:33:50 -05001761 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001762 }
1763
1764 PIPEnsSendBulkOut(pDevice,pContext);
1765 return CMD_STATUS_PENDING;
1766}
1767
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001768CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1769 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001770{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001771 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001772 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1773 u32 cbHeaderSize = 0;
1774 u16 wTxBufSize = sizeof(STxShortBufHead);
1775 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001776 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001777 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001778 u16 wCurrentRate;
1779 u32 cbFrameBodySize;
1780 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001781 u8 *pbyTxBufferAddr;
1782 PUSB_SEND_CONTEXT pContext;
1783 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001784
Forest Bond92b96792009-06-13 07:38:31 -04001785 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1786 if (NULL == pContext) {
1787 status = CMD_STATUS_RESOURCES;
1788 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1789 return status ;
1790 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001791
1792 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001793 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001794
1795 cbFrameBodySize = pPacket->cbPayloadLen;
1796
1797 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1798 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001799
1800 if (pDevice->byBBType == BB_TYPE_11A) {
1801 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001802 pTxDataHead = (struct vnt_tx_datahead_ab *)
1803 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001804 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001805 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1806 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001807 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001808 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
1809 DATADUR_A, PK_TYPE_11A, false);
Forest Bond92b96792009-06-13 07:38:31 -04001810 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestley558becf2013-08-16 23:50:32 +01001811 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001812 } else {
1813 wCurrentRate = RATE_1M;
1814 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001815 pTxDataHead = (struct vnt_tx_datahead_ab *)
1816 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001817 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001818 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1819 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001820 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001821 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
1822 DATADUR_B, PK_TYPE_11B, false);
Forest Bond92b96792009-06-13 07:38:31 -04001823 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestley558becf2013-08-16 23:50:32 +01001824 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001825 }
1826
1827 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001828 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001829 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001830
Andres More1cac4a42013-03-18 20:33:50 -05001831 pMACHeader->duration_id = 0;
1832 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001833 pDevice->wSeqCounter++ ;
1834 if (pDevice->wSeqCounter > 0x0fff)
1835 pDevice->wSeqCounter = 0;
1836
1837 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1838
Andres More3eaca0d2013-02-25 20:32:52 -05001839 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001840 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001841 pTX_Buffer->byType = 0x01;
1842
1843 pContext->pPacket = NULL;
1844 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001845 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001846
1847 PIPEnsSendBulkOut(pDevice,pContext);
1848 return CMD_STATUS_PENDING;
1849
1850}
1851
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001852void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1853{
1854 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001855 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001856 u8 byPktType;
1857 u8 *pbyTxBufferAddr;
1858 void *pvRTS, *pvCTS, *pvTxDataHd;
1859 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001860 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001861 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001862 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001863 PSTxBufHead pTxBufHead;
1864 u32 cbFrameSize;
1865 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1866 u32 uPadding = 0;
1867 u32 cbMICHDR = 0, uLength = 0;
1868 u32 dwMICKey0, dwMICKey1;
1869 u32 dwMIC_Priority;
1870 u32 *pdwMIC_L, *pdwMIC_R;
1871 u16 wTxBufSize;
1872 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001873 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001874 void *pvRrvTime, *pMICHDR;
1875 u32 wCurrentRate = RATE_1M;
1876 PUWLAN_80211HDR p80211Header;
1877 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001878 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001879 SKeyItem STempKey;
1880 PSKeyItem pTransmitKey = NULL;
1881 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1882 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001883 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001884
Forest Bond92b96792009-06-13 07:38:31 -04001885 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1886
1887 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1888 cbFrameBodySize = 0;
1889 }
1890 else {
1891 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1892 }
1893 p80211Header = (PUWLAN_80211HDR)skb->data;
1894
1895 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1896
1897 if (NULL == pContext) {
1898 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1899 dev_kfree_skb_irq(skb);
1900 return ;
1901 }
1902
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001903 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001904 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001905 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1906 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001907
1908 if (pDevice->byBBType == BB_TYPE_11A) {
1909 wCurrentRate = RATE_6M;
1910 byPktType = PK_TYPE_11A;
1911 } else {
1912 wCurrentRate = RATE_1M;
1913 byPktType = PK_TYPE_11B;
1914 }
1915
1916 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1917 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1918 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1919 // to set power here.
1920 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1921 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1922 } else {
1923 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1924 }
1925
1926 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1927
1928 //Set packet type
1929 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1930 pTxBufHead->wFIFOCtl = 0;
1931 }
1932 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1933 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1934 }
1935 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1936 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1937 }
1938 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1939 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1940 }
1941
1942 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1943 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1944
Andres More22040bb2010-08-02 20:21:44 -03001945 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001946 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001947 if (pDevice->bEnableHostWEP) {
1948 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001949 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001950 }
Forest Bond92b96792009-06-13 07:38:31 -04001951 }
1952 else {
1953 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001954 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001955 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001956 }
Andres More4e9b5e22013-02-12 20:36:30 -05001957 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001958 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1959 };
1960
1961 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1962 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1963
1964 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1965 //Set Preamble type always long
1966 //pDevice->byPreambleType = PREAMBLE_LONG;
1967
1968 // probe-response don't retry
1969 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001970 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001971 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1972 //}
1973 }
1974
1975 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1976
1977 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001978 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001979 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1980 } else {
1981 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1982 }
1983
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001984 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001985 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1986
1987 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1988 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1989 }
1990
1991 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1992 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1993 }
1994
1995 if (cbExtSuppRate >0) {
1996 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1997 }
1998 }
1999
Forest Bond92b96792009-06-13 07:38:31 -04002000 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05002001 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04002002
2003 // Notes:
2004 // Although spec says MMPDU can be fragmented; In most case,
2005 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05002006 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04002007
Forest Bond92b96792009-06-13 07:38:31 -04002008 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2009 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2010 cbIVlen = 4;
2011 cbICVlen = 4;
2012 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2013 }
2014 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2015 cbIVlen = 8;//IV+ExtIV
2016 cbMIClen = 8;
2017 cbICVlen = 4;
2018 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2019 //We need to get seed here for filling TxKey entry.
2020 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2021 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2022 }
2023 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2024 cbIVlen = 8;//RSN Header
2025 cbICVlen = 8;//MIC
2026 cbMICHDR = sizeof(SMICHDRHead);
2027 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002028 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002029 }
2030 //MAC Header should be padding 0 to DW alignment.
2031 uPadding = 4 - (cbMacHdLen%4);
2032 uPadding %= 4;
2033 }
2034
2035 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2036
2037 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002038 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002039 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2040 }
2041 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2042
Forest Bond92b96792009-06-13 07:38:31 -04002043 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002044 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
2045 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
2046 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002047 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002048 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002049 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002050 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2051 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002052 sizeof(struct vnt_cts));
2053 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002054 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002055
2056 }
2057 else {//802.11a/b packet
2058
Malcolm Priestley976467d2013-08-16 23:44:04 +01002059 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
2060 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
2061 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002062 pvRTS = NULL;
2063 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01002064 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2065 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002066 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002067 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002068 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002069 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002070 &(p80211Header->sA3.abyAddr1[0]),
2071 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002072 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002073 &(p80211Header->sA3.abyAddr2[0]),
2074 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002075 //=========================
2076 // No Fragmentation
2077 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002078 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002079
Forest Bond92b96792009-06-13 07:38:31 -04002080 //Fill FIFO,RrvTime,RTS,and CTS
2081 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2082 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2083
2084 //Fill DataHead
2085 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002086 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002087
Andres More1cac4a42013-03-18 20:33:50 -05002088 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002089
2090 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2091
Andres Moreb902fbf2013-02-25 20:32:51 -05002092 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2093 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2094 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002095
2096 // Copy the Packet into a tx Buffer
2097 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2098
2099 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002100 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002101 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2102
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002103 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002104 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2105 if (cbExtSuppRate != 0) {
2106 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2107 memcpy((pbyPayloadHead + cbFrameBodySize),
2108 pMgmt->abyCurrSuppRates,
2109 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2110 );
2111 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2112 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2113 pMgmt->abyCurrExtSuppRates,
2114 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2115 );
2116 }
2117 }
2118
2119 // Set wep
2120 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2121
2122 if (pDevice->bEnableHostWEP) {
2123 pTransmitKey = &STempKey;
2124 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2125 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2126 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2127 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2128 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2129 memcpy(pTransmitKey->abyKey,
2130 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2131 pTransmitKey->uKeyLength
2132 );
2133 }
2134
2135 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2136
Andres More52a7e642013-02-25 20:32:53 -05002137 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2138 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002139
2140 // DO Software Michael
2141 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002142 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002143 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002144 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2146 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002147
2148 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2149
2150 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2151
Andres More52a7e642013-02-25 20:32:53 -05002152 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2153 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002154
2155 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2156 MIC_vUnInit();
2157
Andres More4e9b5e22013-02-12 20:36:30 -05002158 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002159 *pdwMIC_L = 0;
2160 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002161 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002162 }
2163
2164 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2165 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002166 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2167 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002168
2169 }
2170
Andres Moreb902fbf2013-02-25 20:32:51 -05002171 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05002172 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002173
2174 if (pDevice->bEnableHostWEP) {
2175 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2176 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2177 }
2178
2179 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002180 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002181 }
2182 }
2183
Andres More1cac4a42013-03-18 20:33:50 -05002184 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002185 pDevice->wSeqCounter++ ;
2186 if (pDevice->wSeqCounter > 0x0fff)
2187 pDevice->wSeqCounter = 0;
2188
Forest Bond92b96792009-06-13 07:38:31 -04002189 if (bIsPSPOLL) {
2190 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2191 // of FIFO control header.
2192 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2193 // in the same place of other packet's Duration-field).
2194 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002195 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2196 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2197 cpu_to_le16(p80211Header->sA2.wDurationID);
2198 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2199 cpu_to_le16(p80211Header->sA2.wDurationID);
2200 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002201 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2202 cpu_to_le16(p80211Header->sA2.wDurationID);
2203 }
Forest Bond92b96792009-06-13 07:38:31 -04002204 }
2205
Andres More3eaca0d2013-02-25 20:32:52 -05002206 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002207 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002208 pTX_Buffer->byType = 0x00;
2209
2210 pContext->pPacket = skb;
2211 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002212 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002213
Andres More1cac4a42013-03-18 20:33:50 -05002214 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2215 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002216 }
2217 else {
Andres More1cac4a42013-03-18 20:33:50 -05002218 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002219 }
2220 PIPEnsSendBulkOut(pDevice,pContext);
2221 return ;
2222
2223}
2224
Forest Bond92b96792009-06-13 07:38:31 -04002225//TYPE_AC0DMA data tx
2226/*
2227 * Description:
2228 * Tx packet via AC0DMA(DMA1)
2229 *
2230 * Parameters:
2231 * In:
2232 * pDevice - Pointer to the adapter
2233 * skb - Pointer to tx skb packet
2234 * Out:
2235 * void
2236 *
2237 * Return Value: NULL
2238 */
2239
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002240int nsDMA_tx_packet(struct vnt_private *pDevice,
2241 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002242{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002243 struct net_device_stats *pStats = &pDevice->stats;
2244 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002245 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002246 u32 BytesToWrite = 0, uHeaderLen = 0;
2247 u32 uNodeIndex = 0;
2248 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2249 u16 wAID;
2250 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002251 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002252 PSKeyItem pTransmitKey = NULL;
2253 SKeyItem STempKey;
2254 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002255 int bTKIP_UseGTK = false;
2256 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002257 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002258 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002259 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002260 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002261 u32 status;
2262 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002263 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002264
Forest Bond92b96792009-06-13 07:38:31 -04002265 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2266
2267 if (pDevice->uAssocCount == 0) {
2268 dev_kfree_skb_irq(skb);
2269 return 0;
2270 }
2271
Andres Moreb902fbf2013-02-25 20:32:51 -05002272 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002273 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002274 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002275 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2276
2277 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2278 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2279 // set tx map
2280 pMgmt->abyPSTxMap[0] |= byMask[0];
2281 return 0;
2282 }
Masanari Iida93184692012-08-13 21:21:50 +09002283 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002284
2285 if (pDevice->byBBType != BB_TYPE_11A)
2286 pDevice->wCurrentRate = RATE_2M;
2287 else
2288 pDevice->wCurrentRate = RATE_24M;
2289 // long preamble type
2290 pDevice->byPreambleType = PREAMBLE_SHORT;
2291
2292 }else {
2293
Andres Moreb902fbf2013-02-25 20:32:51 -05002294 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002295
2296 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2297
2298 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2299
2300 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2301 // set tx map
2302 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2303 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2304 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2305 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2306
2307 return 0;
2308 }
2309 // AP rate decided from node
2310 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2311 // tx preamble decided from node
2312
2313 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2314 pDevice->byPreambleType = pDevice->byShortPreamble;
2315
2316 }else {
2317 pDevice->byPreambleType = PREAMBLE_LONG;
2318 }
Andres More4e9b5e22013-02-12 20:36:30 -05002319 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002320 }
2321 }
2322
Andres Moree269fc22013-02-12 20:36:29 -05002323 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002324 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2325 dev_kfree_skb_irq(skb);
2326 return 0;
2327 }
2328 }
2329
2330 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2331
2332 if (pContext == NULL) {
2333 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2334 dev_kfree_skb_irq(skb);
2335 return STATUS_RESOURCES;
2336 }
2337
Andres Moreceb8c5d2013-03-18 20:33:49 -05002338 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002339
2340//mike add:station mode check eapol-key challenge--->
2341{
Andres Moreb902fbf2013-02-25 20:32:51 -05002342 u8 Protocol_Version; //802.1x Authentication
2343 u8 Packet_Type; //802.1x Authentication
2344 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002345 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002346
Charles Clément21ec51f2010-05-18 10:08:14 -07002347 Protocol_Version = skb->data[ETH_HLEN];
2348 Packet_Type = skb->data[ETH_HLEN+1];
2349 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2350 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 -05002351 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002352 /* 802.1x OR eapol-key challenge frame transfer */
2353 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2354 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002355 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002356 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2357 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2358 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002359 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002360 PRINT_K("WPA ");
2361 }
2362 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002363 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002364 PRINT_K("WPA2(re-keying) ");
2365 }
2366 PRINT_K("Authentication completed!!\n");
2367 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002368 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002369 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002370 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002371 PRINT_K("WPA2 Authentication completed!!\n");
2372 }
2373 }
2374 }
2375}
2376//mike add:station mode check eapol-key challenge<---
2377
Andres More4e9b5e22013-02-12 20:36:30 -05002378 if (pDevice->bEncryptionEnable == true) {
2379 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002380 // get Transmit key
2381 do {
2382 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2383 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2384 pbyBSSID = pDevice->abyBSSID;
2385 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002386 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002387 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002388 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2389 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2391 break;
2392 }
2393 } else {
2394 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2395 break;
2396 }
2397 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002398 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2399 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002400 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2401 for (ii = 0; ii< 6; ii++)
2402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2403 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2404
2405 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002406 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002407 break;
2408 }
2409 // get group key
2410 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002411 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002412 pTransmitKey = NULL;
2413 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2414 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2415 }
2416 else
2417 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2418 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002419 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002420 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2421 }
Andres Moree269fc22013-02-12 20:36:29 -05002422 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002423 }
2424
2425 if (pDevice->bEnableHostWEP) {
2426 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002427 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002428 pTransmitKey = &STempKey;
2429 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2430 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2431 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2432 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2433 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2434 memcpy(pTransmitKey->abyKey,
2435 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2436 pTransmitKey->uKeyLength
2437 );
2438 }
2439 }
2440
Andres Moreb902fbf2013-02-25 20:32:51 -05002441 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002442
2443 if (pDevice->bFixRate) {
2444 if (pDevice->byBBType == BB_TYPE_11B) {
2445 if (pDevice->uConnectionRate >= RATE_11M) {
2446 pDevice->wCurrentRate = RATE_11M;
2447 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002448 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002449 }
2450 } else {
2451 if ((pDevice->byBBType == BB_TYPE_11A) &&
2452 (pDevice->uConnectionRate <= RATE_6M)) {
2453 pDevice->wCurrentRate = RATE_6M;
2454 } else {
2455 if (pDevice->uConnectionRate >= RATE_54M)
2456 pDevice->wCurrentRate = RATE_54M;
2457 else
Andres More3eaca0d2013-02-25 20:32:52 -05002458 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002459 }
2460 }
2461 }
2462 else {
2463 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2464 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002465 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002466 // Multicast use highest data rate
2467 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2468 // preamble type
2469 pDevice->byPreambleType = pDevice->byShortPreamble;
2470 }
2471 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002472 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002473 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2474 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2475 pDevice->byPreambleType = pDevice->byShortPreamble;
2476
2477 }
2478 else {
2479 pDevice->byPreambleType = PREAMBLE_LONG;
2480 }
2481 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2482 }
2483 else {
2484 if (pDevice->byBBType != BB_TYPE_11A)
2485 pDevice->wCurrentRate = RATE_2M;
2486 else
2487 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2488 // abyCurrExtSuppRates[]
2489 pDevice->byPreambleType = PREAMBLE_SHORT;
2490 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2491 }
2492 }
2493 }
2494 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2495 // Infra STA rate decided from AP Node, index = 0
2496 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2497 }
2498 }
2499
Andres Moreceb8c5d2013-03-18 20:33:49 -05002500 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002501 if (pDevice->byBBType != BB_TYPE_11A) {
2502 pDevice->wCurrentRate = RATE_1M;
2503 pDevice->byACKRate = RATE_1M;
2504 pDevice->byTopCCKBasicRate = RATE_1M;
2505 pDevice->byTopOFDMBasicRate = RATE_6M;
2506 } else {
2507 pDevice->wCurrentRate = RATE_6M;
2508 pDevice->byACKRate = RATE_6M;
2509 pDevice->byTopCCKBasicRate = RATE_1M;
2510 pDevice->byTopOFDMBasicRate = RATE_6M;
2511 }
2512 }
Forest Bond92b96792009-06-13 07:38:31 -04002513
Andres More0cbd8d92010-05-06 20:34:29 -03002514 DBG_PRT(MSG_LEVEL_DEBUG,
2515 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2516 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002517
2518 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002519 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002520 }
2521
2522 if (pDevice->wCurrentRate <= RATE_11M) {
2523 byPktType = PK_TYPE_11B;
2524 }
2525
Andres More4e9b5e22013-02-12 20:36:30 -05002526 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002527 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2528 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002529 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002530 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002531 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2532 if (pTransmitKey == NULL) {
2533 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2534 }
2535 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002536 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002537 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2538 }
2539 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002540 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2541 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002542 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002543 }
2544 }
2545 }
2546
Forest Bond92b96792009-06-13 07:38:31 -04002547 if (pDevice->bEnableHostWEP) {
2548 if ((uNodeIndex != 0) &&
2549 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002550 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2551 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002552 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002553 }
2554 }
2555 }
2556 else {
2557
Forest Bond92b96792009-06-13 07:38:31 -04002558 if (pTransmitKey == NULL) {
2559 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002560 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002561 dev_kfree_skb_irq(skb);
2562 pStats->tx_dropped++;
2563 return STATUS_FAILURE;
2564 }
Forest Bond92b96792009-06-13 07:38:31 -04002565 }
2566 }
2567
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002568 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2569
Forest Bond92b96792009-06-13 07:38:31 -04002570 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002571 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002572 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002573 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002574 pDevice->wCurrentRate,
2575 &uHeaderLen, &BytesToWrite
2576 );
2577
Andres Moree269fc22013-02-12 20:36:29 -05002578 if (fConvertedPacket == false) {
2579 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002580 dev_kfree_skb_irq(skb);
2581 return STATUS_FAILURE;
2582 }
2583
Andres More4e9b5e22013-02-12 20:36:30 -05002584 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002585 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002586 bScheduleCommand((void *) pDevice,
2587 WLAN_CMD_MAC_DISPOWERSAVING,
2588 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002589 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002590 }
2591 }
2592
Andres Moreb902fbf2013-02-25 20:32:51 -05002593 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002594 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002595
2596 pContext->pPacket = skb;
2597 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002598 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002599
Andres Moreceb8c5d2013-03-18 20:33:49 -05002600 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 -04002601
2602 status = PIPEnsSendBulkOut(pDevice,pContext);
2603
Andres More4e9b5e22013-02-12 20:36:30 -05002604 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002605 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002606
Andres Moreb902fbf2013-02-25 20:32:51 -05002607 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002608 }
2609
2610 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002611 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002612 dev_kfree_skb_irq(skb);
2613 return STATUS_FAILURE;
2614 }
2615 else
2616 return 0;
2617
2618}
2619
Forest Bond92b96792009-06-13 07:38:31 -04002620/*
2621 * Description:
2622 * Relay packet send (AC1DMA) from rx dpc.
2623 *
2624 * Parameters:
2625 * In:
2626 * pDevice - Pointer to the adapter
2627 * pPacket - Pointer to rx packet
2628 * cbPacketSize - rx ethernet frame size
2629 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002630 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002631 *
Andres More4e9b5e22013-02-12 20:36:30 -05002632 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002633 */
2634
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002635int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2636 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002637{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002638 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002639 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002640 u32 BytesToWrite = 0, uHeaderLen = 0;
2641 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002642 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002643 SKeyItem STempKey;
2644 PSKeyItem pTransmitKey = NULL;
2645 u8 *pbyBSSID;
2646 PUSB_SEND_CONTEXT pContext;
2647 u8 byPktTyp;
2648 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002649 u32 status;
2650 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002651
Forest Bond92b96792009-06-13 07:38:31 -04002652 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2653
2654 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002655 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002656 }
2657
Andres Moreceb8c5d2013-03-18 20:33:49 -05002658 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002659
Andres More4e9b5e22013-02-12 20:36:30 -05002660 if (pDevice->bEncryptionEnable == true) {
2661 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002662 // get group key
2663 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002664 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002665 pTransmitKey = NULL;
2666 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2667 } else {
2668 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2669 }
2670 }
2671
2672 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002673 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002674 pTransmitKey = &STempKey;
2675 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2676 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2677 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2678 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2679 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2680 memcpy(pTransmitKey->abyKey,
2681 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2682 pTransmitKey->uKeyLength
2683 );
2684 }
2685 }
2686
2687 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002688 pContext->bBoolInUse = false;
2689 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002690 }
2691
Andres Moreb902fbf2013-02-25 20:32:51 -05002692 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002693
2694 if (pDevice->bFixRate) {
2695 if (pDevice->byBBType == BB_TYPE_11B) {
2696 if (pDevice->uConnectionRate >= RATE_11M) {
2697 pDevice->wCurrentRate = RATE_11M;
2698 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002699 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002700 }
2701 } else {
2702 if ((pDevice->byBBType == BB_TYPE_11A) &&
2703 (pDevice->uConnectionRate <= RATE_6M)) {
2704 pDevice->wCurrentRate = RATE_6M;
2705 } else {
2706 if (pDevice->uConnectionRate >= RATE_54M)
2707 pDevice->wCurrentRate = RATE_54M;
2708 else
Andres More3eaca0d2013-02-25 20:32:52 -05002709 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002710 }
2711 }
2712 }
2713 else {
2714 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2715 }
2716
Forest Bond92b96792009-06-13 07:38:31 -04002717 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002718 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002719 }
2720
2721 if (pDevice->wCurrentRate <= RATE_11M)
2722 byPktType = PK_TYPE_11B;
2723
Andres Moreabad19d2010-07-12 16:28:32 -03002724 BytesToWrite = uDataLen + ETH_FCS_LEN;
2725
Forest Bond92b96792009-06-13 07:38:31 -04002726 // Convert the packet to an usb frame and copy into our buffer
2727 // and send the irp.
2728
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002729 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2730
Forest Bond92b96792009-06-13 07:38:31 -04002731 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002732 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002733 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2734 pbySkbData, pTransmitKey, uNodeIndex,
2735 pDevice->wCurrentRate,
2736 &uHeaderLen, &BytesToWrite
2737 );
2738
Andres Moree269fc22013-02-12 20:36:29 -05002739 if (fConvertedPacket == false) {
2740 pContext->bBoolInUse = false;
2741 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002742 }
2743
Andres Moreb902fbf2013-02-25 20:32:51 -05002744 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002745 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002746
2747 pContext->pPacket = NULL;
2748 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002749 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002750
Andres Moreceb8c5d2013-03-18 20:33:49 -05002751 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 -04002752
2753 status = PIPEnsSendBulkOut(pDevice,pContext);
2754
Andres More4e9b5e22013-02-12 20:36:30 -05002755 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002756}
2757