blob: b0354e5d2f618ffc33b4377f559032b02a6ffd2f [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 "baseband.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040064#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070065
Mariano Reingart4a499de2010-10-29 19:15:26 -030066static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040067
Andres More3eaca0d2013-02-25 20:32:52 -050068const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040069 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
70 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
71 };
72
Andres More3eaca0d2013-02-25 20:32:52 -050073const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040074 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
75 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
76 };
Andres More3eaca0d2013-02-25 20:32:52 -050077const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040078 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
79 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
80 };
81
Forest Bond92b96792009-06-13 07:38:31 -040082#define RTSDUR_BB 0
83#define RTSDUR_BA 1
84#define RTSDUR_AA 2
85#define CTSDUR_BA 3
86#define RTSDUR_BA_F0 4
87#define RTSDUR_AA_F0 5
88#define RTSDUR_BA_F1 6
89#define RTSDUR_AA_F1 7
90#define CTSDUR_BA_F0 8
91#define CTSDUR_BA_F1 9
92#define DATADUR_B 10
93#define DATADUR_A 11
94#define DATADUR_A_F0 12
95#define DATADUR_A_F1 13
96
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000097static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
98 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040099
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000100static void *s_vGetFreeContext(struct vnt_private *pDevice);
101
102static void s_vGenerateTxParameter(struct vnt_private *pDevice,
103 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
104 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500105 struct ethhdr *psEthHeader);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000106
107static u32 s_uFillDataHead(struct vnt_private *pDevice,
108 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
109 u32 uDMAIdx, int bNeedAck, u32 uFragIdx, u32 cbLastFragmentSize,
110 u32 uMACfragNum, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400111
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000112static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500113 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000114 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400115
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000116static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
117 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
118 u8 *pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -0400119
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000120static void s_vSWencryption(struct vnt_private *pDevice,
121 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400122
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000123static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
124 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400125
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000126static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
127 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400128
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000129static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
130 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
131 int bDisCRC, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400132
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000133static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
134 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500135 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400136
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000137static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
138 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
139 u32 uFragIdx, u32 cbLastFragmentSize, u32 uMACfragNum,
140 u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400141
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000142static unsigned int s_uGetRTSCTSDuration(struct vnt_private *pDevice,
143 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
144 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400145
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000146static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400147{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000148 PUSB_SEND_CONTEXT pContext = NULL;
149 PUSB_SEND_CONTEXT pReturnContext = NULL;
150 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400151
152 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
153
154 for (ii = 0; ii < pDevice->cbTD; ii++) {
155 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500156 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500157 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100158 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400159 pReturnContext = pContext;
160 break;
161 }
162 }
163 if ( ii == pDevice->cbTD ) {
164 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
165 }
Andres More8611a292010-05-01 14:25:00 -0300166 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400167}
168
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000169static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
170 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400171{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000172 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400173
Andres More4b50fb42010-06-22 21:57:42 -0300174 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400175 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300176 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400177 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
178 else
179 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
180
181 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
182 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300183 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
184 pbyDestAddr,
185 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400186}
187
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000188static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
189 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
190 u16 wPayloadLen, u8 *pMICHDR)
Forest Bond92b96792009-06-13 07:38:31 -0400191{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000192 u32 *pdwIV = (u32 *)pbyIVHead;
193 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
194 u16 wValue;
Andres More1cac4a42013-03-18 20:33:50 -0500195 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000196 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400197
Forest Bond92b96792009-06-13 07:38:31 -0400198 //Fill TXKEY
199 if (pTransmitKey == NULL)
200 return;
201
202 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
203 *pdwIV = pDevice->dwIVCounter;
204 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
205
206 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
207 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
Andres Moreb902fbf2013-02-25 20:32:51 -0500208 memcpy(pDevice->abyPRNG, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700209 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400210 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500211 memcpy(pbyBuf, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700212 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400213 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500214 memcpy(pbyBuf+8, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700215 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400216 }
Jim Lieb3e362592009-08-12 14:54:11 -0700217 memcpy(pDevice->abyPRNG, pbyBuf, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400218 }
219 // Append IV after Mac Header
220 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
Malcolm Priestleyd5bbef72012-11-11 15:53:14 +0000221 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
Forest Bond92b96792009-06-13 07:38:31 -0400222 *pdwIV = cpu_to_le32(*pdwIV);
223 pDevice->dwIVCounter++;
224 if (pDevice->dwIVCounter > WEP_IV_MASK) {
225 pDevice->dwIVCounter = 0;
226 }
227 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
228 pTransmitKey->wTSC15_0++;
229 if (pTransmitKey->wTSC15_0 == 0) {
230 pTransmitKey->dwTSC47_16++;
231 }
232 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
233 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
Jim Lieb3e362592009-08-12 14:54:11 -0700234 memcpy(pbyBuf, pDevice->abyPRNG, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400235 // Make IV
Jim Lieb3e362592009-08-12 14:54:11 -0700236 memcpy(pdwIV, pDevice->abyPRNG, 3);
Forest Bond92b96792009-06-13 07:38:31 -0400237
Andres Moreb902fbf2013-02-25 20:32:51 -0500238 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Forest Bond92b96792009-06-13 07:38:31 -0400239 // Append IV&ExtIV after Mac Header
240 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +0000241 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %x\n",
242 *pdwExtIV);
Forest Bond92b96792009-06-13 07:38:31 -0400243
244 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
245 pTransmitKey->wTSC15_0++;
246 if (pTransmitKey->wTSC15_0 == 0) {
247 pTransmitKey->dwTSC47_16++;
248 }
Jim Lieb3e362592009-08-12 14:54:11 -0700249 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400250
251 // Make IV
252 *pdwIV = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -0500253 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Andres More3eaca0d2013-02-25 20:32:52 -0500254 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
Forest Bond92b96792009-06-13 07:38:31 -0400255 //Append IV&ExtIV after Mac Header
256 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
257
258 //Fill MICHDR0
259 *pMICHDR = 0x59;
Andres Moreb902fbf2013-02-25 20:32:51 -0500260 *((u8 *)(pMICHDR+1)) = 0; // TxPriority
Andres More1cac4a42013-03-18 20:33:50 -0500261 memcpy(pMICHDR+2, &(pMACHeader->addr2[0]), 6);
Andres Moreb902fbf2013-02-25 20:32:51 -0500262 *((u8 *)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
263 *((u8 *)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
264 *((u8 *)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
265 *((u8 *)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
266 *((u8 *)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
267 *((u8 *)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
268 *((u8 *)(pMICHDR+14)) = HIBYTE(wPayloadLen);
269 *((u8 *)(pMICHDR+15)) = LOBYTE(wPayloadLen);
Forest Bond92b96792009-06-13 07:38:31 -0400270
271 //Fill MICHDR1
Andres Moreb902fbf2013-02-25 20:32:51 -0500272 *((u8 *)(pMICHDR+16)) = 0; // HLEN[15:8]
Forest Bond92b96792009-06-13 07:38:31 -0400273 if (pDevice->bLongHeader) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500274 *((u8 *)(pMICHDR+17)) = 28; // HLEN[7:0]
Forest Bond92b96792009-06-13 07:38:31 -0400275 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500276 *((u8 *)(pMICHDR+17)) = 22; // HLEN[7:0]
Forest Bond92b96792009-06-13 07:38:31 -0400277 }
Andres More1cac4a42013-03-18 20:33:50 -0500278 wValue = cpu_to_le16(pMACHeader->frame_control & 0xC78F);
Andres Moreb902fbf2013-02-25 20:32:51 -0500279 memcpy(pMICHDR+18, (u8 *)&wValue, 2); // MSKFRACTL
Andres More1cac4a42013-03-18 20:33:50 -0500280 memcpy(pMICHDR+20, &(pMACHeader->addr1[0]), 6);
281 memcpy(pMICHDR+26, &(pMACHeader->addr2[0]), 6);
Forest Bond92b96792009-06-13 07:38:31 -0400282
283 //Fill MICHDR2
Andres More1cac4a42013-03-18 20:33:50 -0500284 memcpy(pMICHDR+32, &(pMACHeader->addr3[0]), 6);
285 wValue = pMACHeader->seq_ctrl;
Forest Bond92b96792009-06-13 07:38:31 -0400286 wValue &= 0x000F;
287 wValue = cpu_to_le16(wValue);
Andres Moreb902fbf2013-02-25 20:32:51 -0500288 memcpy(pMICHDR+38, (u8 *)&wValue, 2); // MSKSEQCTL
Forest Bond92b96792009-06-13 07:38:31 -0400289 if (pDevice->bLongHeader) {
Andres More1cac4a42013-03-18 20:33:50 -0500290 memcpy(pMICHDR+40, &(pMACHeader->addr4[0]), 6);
Forest Bond92b96792009-06-13 07:38:31 -0400291 }
292 }
293}
294
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000295static void s_vSWencryption(struct vnt_private *pDevice,
296 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400297{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000298 u32 cbICVlen = 4;
299 u32 dwICV = 0xffffffff;
300 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400301
302 if (pTransmitKey == NULL)
303 return;
304
305 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
306 //=======================================================================
307 // Append ICV after payload
308 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500309 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400310 // finally, we must invert dwCRC to get the correct answer
311 *pdwICV = cpu_to_le32(~dwICV);
312 // RC4 encryption
313 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
314 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
315 //=======================================================================
316 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
317 //=======================================================================
318 //Append ICV after payload
319 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500320 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400321 // finally, we must invert dwCRC to get the correct answer
322 *pdwICV = cpu_to_le32(~dwICV);
323 // RC4 encryption
324 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
325 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
326 //=======================================================================
327 }
328}
329
Forest Bond92b96792009-06-13 07:38:31 -0400330/*byPktType : PK_TYPE_11A 0
331 PK_TYPE_11B 1
332 PK_TYPE_11GB 2
333 PK_TYPE_11GA 3
334*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000335static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
336 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400337{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000338 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400339
340 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
341 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500342 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400343 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500344 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400345 }
346
347 if (bNeedAck) {
348 return (uDataTime + pDevice->uSIFS + uAckTime);
349 }
350 else {
351 return uDataTime;
352 }
353}
354
355//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000356static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
357 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400358{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000359 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400360
361 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
362
Forest Bond92b96792009-06-13 07:38:31 -0400363 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
364 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
365 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
366 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
367 }
368 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
369 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
370 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
371 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
372 }
373 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
374 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
375 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
376 }
377 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
378 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
379 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
380 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
381 return uRrvTime;
382 }
383
384 //RTSRrvTime
385 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
386 return uRrvTime;
387}
388
389//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000390static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
391 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
392 u32 uFragIdx, u32 cbLastFragmentSize, u32 uMACfragNum,
393 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400394{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100395 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400396
397 switch (byDurType) {
398
399 case DATADUR_B: //DATADUR_B
Forest Bond92b96792009-06-13 07:38:31 -0400400 if (bNeedAck) {
401 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
402 return (pDevice->uSIFS + uAckTime);
403 } else {
404 return 0;
405 }
Forest Bond92b96792009-06-13 07:38:31 -0400406 break;
407
Forest Bond92b96792009-06-13 07:38:31 -0400408 case DATADUR_A: //DATADUR_A
Forest Bond92b96792009-06-13 07:38:31 -0400409 if(bNeedAck){
410 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
411 return (pDevice->uSIFS + uAckTime);
412 } else {
413 return 0;
414 }
Forest Bond92b96792009-06-13 07:38:31 -0400415 break;
416
417 case DATADUR_A_F0: //DATADUR_A_F0
Forest Bond92b96792009-06-13 07:38:31 -0400418 if(bNeedAck){
419 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
420 return (pDevice->uSIFS + uAckTime);
421 } else {
422 return 0;
423 }
Forest Bond92b96792009-06-13 07:38:31 -0400424 break;
425
426 case DATADUR_A_F1: //DATADUR_A_F1
Forest Bond92b96792009-06-13 07:38:31 -0400427 if(bNeedAck){
428 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
429 return (pDevice->uSIFS + uAckTime);
430 } else {
431 return 0;
432 }
Forest Bond92b96792009-06-13 07:38:31 -0400433 break;
434
435 default:
436 break;
437 }
438
Forest Bond92b96792009-06-13 07:38:31 -0400439 return 0;
440}
441
Forest Bond92b96792009-06-13 07:38:31 -0400442//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000443static u32 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
444 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
445 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400446{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000447 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400448
Forest Bond92b96792009-06-13 07:38:31 -0400449 switch (byDurType) {
450
451 case RTSDUR_BB: //RTSDuration_bb
452 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
453 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
454 break;
455
456 case RTSDUR_BA: //RTSDuration_ba
457 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
458 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
459 break;
460
461 case RTSDUR_AA: //RTSDuration_aa
462 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
463 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
464 break;
465
466 case CTSDUR_BA: //CTSDuration_ba
467 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
468 break;
469
470 case RTSDUR_BA_F0: //RTSDuration_ba_f0
471 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
472 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
473 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
474 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
475 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
476 }
477 break;
478
479 case RTSDUR_AA_F0: //RTSDuration_aa_f0
480 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
481 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
482 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
483 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
484 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
485 }
486 break;
487
488 case RTSDUR_BA_F1: //RTSDuration_ba_f1
489 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
490 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
491 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
492 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
493 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
494 }
495 break;
496
497 case RTSDUR_AA_F1: //RTSDuration_aa_f1
498 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
499 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
500 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
501 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
502 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
503 }
504 break;
505
506 case CTSDUR_BA_F0: //CTSDuration_ba_f0
507 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
508 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
509 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
510 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
511 }
512 break;
513
514 case CTSDUR_BA_F1: //CTSDuration_ba_f1
515 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
516 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
517 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
518 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
519 }
520 break;
521
522 default:
523 break;
524 }
525
526 return uDurTime;
527
528}
529
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000530static u32 s_uFillDataHead(struct vnt_private *pDevice,
531 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
532 u32 uDMAIdx, int bNeedAck, u32 uFragIdx, u32 cbLastFragmentSize,
533 u32 uMACfragNum, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400534{
535
536 if (pTxDataHead == NULL) {
537 return 0;
538 }
539
540 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Andres Morebd2bc4c2010-08-02 23:35:57 -0300541 if ((uDMAIdx == TYPE_ATIMDMA) || (uDMAIdx == TYPE_BEACONDMA)) {
542 PSTxDataHead_ab pBuf = (PSTxDataHead_ab) pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400543 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700544 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500545 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400546 );
547 //Get Duration and TimeStampOff
Andres More3eaca0d2013-02-25 20:32:52 -0500548 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400549 wCurrentRate, bNeedAck, uFragIdx,
550 cbLastFragmentSize, uMACfragNum,
551 byFBOption); //1: 2.4GHz
552 if(uDMAIdx!=TYPE_ATIMDMA) {
553 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
554 }
555 return (pBuf->wDuration);
556 }
557 else { // DATA & MANAGE Frame
558 if (byFBOption == AUTO_FB_NONE) {
559 PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
560 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700561 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500562 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400563 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700564 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500565 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400566 );
567 //Get Duration and TimeStamp
Andres More3eaca0d2013-02-25 20:32:52 -0500568 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
Forest Bond92b96792009-06-13 07:38:31 -0400569 byPktType, wCurrentRate, bNeedAck, uFragIdx,
570 cbLastFragmentSize, uMACfragNum,
571 byFBOption); //1: 2.4GHz
Andres More3eaca0d2013-02-25 20:32:52 -0500572 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
Forest Bond92b96792009-06-13 07:38:31 -0400573 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
574 bNeedAck, uFragIdx, cbLastFragmentSize,
575 uMACfragNum, byFBOption); //1: 2.4GHz
576
577 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
578 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
579 return (pBuf->wDuration_a);
580 } else {
581 // Auto Fallback
582 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
583 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700584 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500585 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400586 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700587 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500588 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400589 );
590 //Get Duration and TimeStamp
Andres More3eaca0d2013-02-25 20:32:52 -0500591 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400592 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
Andres More3eaca0d2013-02-25 20:32:52 -0500593 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
Forest Bond92b96792009-06-13 07:38:31 -0400594 pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
Andres More3eaca0d2013-02-25 20:32:52 -0500595 pBuf->wDuration_a_f0 = (u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400596 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
Andres More3eaca0d2013-02-25 20:32:52 -0500597 pBuf->wDuration_a_f1 = (u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400598 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
599 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
600 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
601 return (pBuf->wDuration_a);
602 } //if (byFBOption == AUTO_FB_NONE)
603 }
604 }
605 else if (byPktType == PK_TYPE_11A) {
606 if ((byFBOption != AUTO_FB_NONE) && (uDMAIdx != TYPE_ATIMDMA) && (uDMAIdx != TYPE_BEACONDMA)) {
607 // Auto Fallback
608 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
609 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700610 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500611 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400612 );
613 //Get Duration and TimeStampOff
Andres More3eaca0d2013-02-25 20:32:52 -0500614 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400615 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
Andres More3eaca0d2013-02-25 20:32:52 -0500616 pBuf->wDuration_f0 = (u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400617 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
Andres More3eaca0d2013-02-25 20:32:52 -0500618 pBuf->wDuration_f1 = (u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400619 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
620 if(uDMAIdx!=TYPE_ATIMDMA) {
621 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
622 }
623 return (pBuf->wDuration);
624 } else {
625 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
626 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700627 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500628 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400629 );
630 //Get Duration and TimeStampOff
Andres More3eaca0d2013-02-25 20:32:52 -0500631 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400632 wCurrentRate, bNeedAck, uFragIdx,
633 cbLastFragmentSize, uMACfragNum,
634 byFBOption);
635
636 if(uDMAIdx!=TYPE_ATIMDMA) {
637 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
638 }
639 return (pBuf->wDuration);
640 }
641 }
642 else if (byPktType == PK_TYPE_11B) {
643 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
644 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700645 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500646 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400647 );
648 //Get Duration and TimeStampOff
Andres More3eaca0d2013-02-25 20:32:52 -0500649 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400650 wCurrentRate, bNeedAck, uFragIdx,
651 cbLastFragmentSize, uMACfragNum,
652 byFBOption);
653 if (uDMAIdx != TYPE_ATIMDMA) {
654 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
655 }
656 return (pBuf->wDuration);
657 }
658 return 0;
659}
660
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000661static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
662 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500663 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400664{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000665 u32 uRTSFrameLen = 20;
666 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400667
Forest Bond92b96792009-06-13 07:38:31 -0400668 if (pvRTS == NULL)
669 return;
670
671 if (bDisCRC) {
672 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
673 // in this case we need to decrease its length by 4.
674 uRTSFrameLen -= 4;
675 }
676
Masanari Iida93184692012-08-13 21:21:50 +0900677 // 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 -0400678 // Otherwise, we need to modified codes for them.
679 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
680 if (byFBOption == AUTO_FB_NONE) {
681 PSRTS_g pBuf = (PSRTS_g)pvRTS;
682 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700683 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500684 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400685 );
686 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700687 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500688 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400689 );
690 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
691 //Get Duration
Andres More3eaca0d2013-02-25 20:32:52 -0500692 pBuf->wDuration_bb = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
693 pBuf->wDuration_aa = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3: 2.4G OFDMData
694 pBuf->wDuration_ba = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
Malcolm Priestley07738932013-08-05 22:08:05 +0100695 pBuf->data.duration = pBuf->wDuration_aa;
696 /*Get RTS Frame body */
697 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400698
Malcolm Priestley07738932013-08-05 22:08:05 +0100699 if (pDevice->eOPMode == OP_MODE_ADHOC ||
700 pDevice->eOPMode == OP_MODE_AP)
701 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
702 else
703 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Andres More9a0e7562010-04-13 21:54:48 -0300704
Malcolm Priestley07738932013-08-05 22:08:05 +0100705 if (pDevice->eOPMode == OP_MODE_AP)
706 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
707 else
708 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400709 }
710 else {
711 PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
712 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700713 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500714 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400715 );
716 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700717 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500718 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400719 );
720 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
721 //Get Duration
Andres More3eaca0d2013-02-25 20:32:52 -0500722 pBuf->wDuration_bb = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
723 pBuf->wDuration_aa = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3:2.4G OFDMData
724 pBuf->wDuration_ba = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDMData
725 pBuf->wRTSDuration_ba_f0 = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //4:wRTSDuration_ba_f0, 1:2.4G, 1:CCKData
726 pBuf->wRTSDuration_aa_f0 = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:wRTSDuration_aa_f0, 1:2.4G, 1:CCKData
727 pBuf->wRTSDuration_ba_f1 = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //6:wRTSDuration_ba_f1, 1:2.4G, 1:CCKData
728 pBuf->wRTSDuration_aa_f1 = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:wRTSDuration_aa_f1, 1:2.4G, 1:CCKData
Malcolm Priestley07738932013-08-05 22:08:05 +0100729 pBuf->data.duration = pBuf->wDuration_aa;
730 /*Get RTS Frame body*/
731 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400732
Malcolm Priestley07738932013-08-05 22:08:05 +0100733 if (pDevice->eOPMode == OP_MODE_ADHOC ||
734 pDevice->eOPMode == OP_MODE_AP)
735 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
736 else
737 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400738
Malcolm Priestley07738932013-08-05 22:08:05 +0100739 if (pDevice->eOPMode == OP_MODE_AP)
740 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
741 else
742 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400743 } // if (byFBOption == AUTO_FB_NONE)
744 }
745 else if (byPktType == PK_TYPE_11A) {
746 if (byFBOption == AUTO_FB_NONE) {
747 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
748 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700749 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500750 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400751 );
752 pBuf->wTransmitLength = cpu_to_le16(wLen);
753 //Get Duration
Andres More3eaca0d2013-02-25 20:32:52 -0500754 pBuf->wDuration = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
Malcolm Priestley07738932013-08-05 22:08:05 +0100755 pBuf->data.duration = pBuf->wDuration;
756 /* Get RTS Frame body */
757 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400758
Malcolm Priestley07738932013-08-05 22:08:05 +0100759 if (pDevice->eOPMode == OP_MODE_ADHOC ||
760 pDevice->eOPMode == OP_MODE_AP)
761 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
762 else
763 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400764
Malcolm Priestley07738932013-08-05 22:08:05 +0100765 if (pDevice->eOPMode == OP_MODE_AP)
766 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
767 else
768 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400769 }
770 else {
771 PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
772 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700773 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500774 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400775 );
776 pBuf->wTransmitLength = cpu_to_le16(wLen);
777 //Get Duration
Andres More3eaca0d2013-02-25 20:32:52 -0500778 pBuf->wDuration = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
779 pBuf->wRTSDuration_f0 = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:RTSDuration_aa_f0, 0:5G, 0: 5G OFDMData
780 pBuf->wRTSDuration_f1 = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:RTSDuration_aa_f1, 0:5G, 0:
Malcolm Priestley07738932013-08-05 22:08:05 +0100781 pBuf->data.duration = pBuf->wDuration;
782 /* Get RTS Frame body */
783 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400784
Malcolm Priestley07738932013-08-05 22:08:05 +0100785 if (pDevice->eOPMode == OP_MODE_ADHOC ||
786 pDevice->eOPMode == OP_MODE_AP)
787 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
788 else
789 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
790
791 if (pDevice->eOPMode == OP_MODE_AP)
792 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
793 else
794 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400795 }
796 }
797 else if (byPktType == PK_TYPE_11B) {
798 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
799 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700800 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500801 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400802 );
803 pBuf->wTransmitLength = cpu_to_le16(wLen);
804 //Get Duration
Andres More3eaca0d2013-02-25 20:32:52 -0500805 pBuf->wDuration = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
Forest Bond92b96792009-06-13 07:38:31 -0400806
Malcolm Priestley07738932013-08-05 22:08:05 +0100807 pBuf->data.duration = pBuf->wDuration;
808 /* Get RTS Frame body */
809 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400810
Malcolm Priestley07738932013-08-05 22:08:05 +0100811 if (pDevice->eOPMode == OP_MODE_ADHOC ||
812 pDevice->eOPMode == OP_MODE_AP)
813 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
814 else
815 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
816
817 if (pDevice->eOPMode == OP_MODE_AP)
818 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
819 else
820 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400821 }
822}
823
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000824static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
825 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
826 int bDisCRC, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400827{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000828 u32 uCTSFrameLen = 14;
829 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400830
831 if (pvCTS == NULL) {
832 return;
833 }
834
835 if (bDisCRC) {
836 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
837 // in this case we need to decrease its length by 4.
838 uCTSFrameLen -= 4;
839 }
840
841 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
842 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
843 // Auto Fall back
844 PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
845 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700846 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500847 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400848 );
849 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Andres More3eaca0d2013-02-25 20:32:52 -0500850 pBuf->wDuration_ba = (u16)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
Forest Bond92b96792009-06-13 07:38:31 -0400851 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
852 //Get CTSDuration_ba_f0
Andres More3eaca0d2013-02-25 20:32:52 -0500853 pBuf->wCTSDuration_ba_f0 = (u16)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //8:CTSDuration_ba_f0, 1:2.4G, 2,3:2.4G OFDM Data
Forest Bond92b96792009-06-13 07:38:31 -0400854 pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
855 //Get CTSDuration_ba_f1
Andres More3eaca0d2013-02-25 20:32:52 -0500856 pBuf->wCTSDuration_ba_f1 = (u16)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //9:CTSDuration_ba_f1, 1:2.4G, 2,3:2.4G OFDM Data
Forest Bond92b96792009-06-13 07:38:31 -0400857 pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100858 /* Get CTS Frame body */
859 pBuf->data.duration = pBuf->wDuration_ba;
860 pBuf->data.frame_control = TYPE_CTL_CTS;
861 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400862 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
863 PSCTS pBuf = (PSCTS)pvCTS;
864 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700865 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500866 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400867 );
868 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
869 //Get CTSDuration_ba
Andres More3eaca0d2013-02-25 20:32:52 -0500870 pBuf->wDuration_ba = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
Forest Bond92b96792009-06-13 07:38:31 -0400871 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100872 /*Get CTS Frame body*/
873 pBuf->data.duration = pBuf->wDuration_ba;
874 pBuf->data.frame_control = TYPE_CTL_CTS;
875 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400876 }
877 }
878}
879
Forest Bond92b96792009-06-13 07:38:31 -0400880/*+
881 *
882 * Description:
883 * Generate FIFO control for MAC & Baseband controller
884 *
885 * Parameters:
886 * In:
887 * pDevice - Pointer to adpater
888 * pTxDataHead - Transmit Data Buffer
889 * pTxBufHead - pTxBufHead
890 * pvRrvTime - pvRrvTime
891 * pvRTS - RTS Buffer
892 * pCTS - CTS Buffer
893 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
894 * bNeedACK - If need ACK
895 * uDMAIdx - DMA Index
896 * Out:
897 * none
898 *
899 * Return Value: none
900 *
901-*/
Andres Morecc856e62010-05-17 21:34:01 -0300902
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000903static void s_vGenerateTxParameter(struct vnt_private *pDevice,
904 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
905 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500906 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400907{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000908 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
909 u16 wFifoCtl;
Andres Moree269fc22013-02-12 20:36:29 -0500910 int bDisCRC = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000911 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400912
913 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
914 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
915 pFifoHead->wReserved = wCurrentRate;
916 wFifoCtl = pFifoHead->wFIFOCtl;
917
918 if (wFifoCtl & FIFOCTL_CRCDIS) {
Andres More4e9b5e22013-02-12 20:36:30 -0500919 bDisCRC = true;
Forest Bond92b96792009-06-13 07:38:31 -0400920 }
921
922 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
923 byFBOption = AUTO_FB_0;
924 }
925 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
926 byFBOption = AUTO_FB_1;
927 }
928
929 if (pDevice->bLongHeader)
930 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
931
932 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
933
934 if (pvRTS != NULL) { //RTS_need
935 //Fill RsvTime
936 if (pvRrvTime) {
937 PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500938 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
939 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
940 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
941 pBuf->wTxRrvTime_a = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
942 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 -0400943 }
944 //Fill RTS
945 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
946 }
947 else {//RTS_needless, PCF mode
948
949 //Fill RsvTime
950 if (pvRrvTime) {
951 PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500952 pBuf->wTxRrvTime_a = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
953 pBuf->wTxRrvTime_b = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
954 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 -0400955 }
956 //Fill CTS
957 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
958 }
959 }
960 else if (byPktType == PK_TYPE_11A) {
961
962 if (pvRTS != NULL) {//RTS_need, non PCF mode
963 //Fill RsvTime
964 if (pvRrvTime) {
965 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500966 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
967 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400968 }
969 //Fill RTS
970 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
971 }
972 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
973 //Fill RsvTime
974 if (pvRrvTime) {
975 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500976 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400977 }
978 }
979 }
980 else if (byPktType == PK_TYPE_11B) {
981
982 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
983 //Fill RsvTime
984 if (pvRrvTime) {
985 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500986 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
987 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400988 }
989 //Fill RTS
990 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
991 }
992 else { //RTS_needless, non PCF mode
993 //Fill RsvTime
994 if (pvRrvTime) {
995 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500996 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400997 }
998 }
999 }
1000 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
1001}
1002/*
Andres Moreb902fbf2013-02-25 20:32:51 -05001003 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -05001004 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -03001005 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -04001006*/
1007
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001008static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
1009 u8 *usbPacketBuf, int bNeedEncryption, u32 uSkbPacketLen, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001010 struct ethhdr *psEthHeader, u8 *pPacket, PSKeyItem pTransmitKey,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001011 u32 uNodeIndex, u16 wCurrentRate, u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -04001012{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001013 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1014 u32 cbFrameSize, cbFrameBodySize;
1015 PTX_BUFFER pTxBufHead;
1016 u32 cb802_1_H_len;
1017 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
1018 u32 cbFCSlen = 4, cbMICHDR = 0;
1019 int bNeedACK, bRTS;
1020 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
1021 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1022 u8 abySNAP_Bridgetunnel[ETH_ALEN]
1023 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1024 u32 uDuration;
1025 u32 cbHeaderLength = 0, uPadding = 0;
1026 void *pvRrvTime;
1027 PSMICHDRHead pMICHDR;
1028 void *pvRTS;
1029 void *pvCTS;
1030 void *pvTxDataHd;
1031 u8 byFBOption = AUTO_FB_NONE, byFragType;
1032 u16 wTxBufSize;
1033 u32 dwMICKey0, dwMICKey1, dwMIC_Priority, dwCRC;
1034 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001035 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -04001036
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001037 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001038
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001039 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001040 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1041 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001042 }
Forest Bond92b96792009-06-13 07:38:31 -04001043
1044 pTxBufHead = (PTX_BUFFER) usbPacketBuf;
Forest Bond92b96792009-06-13 07:38:31 -04001045
1046 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001047 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001048 if (pDevice->dwDiagRefCount == 0) {
1049 cb802_1_H_len = 8;
1050 } else {
1051 cb802_1_H_len = 2;
1052 }
1053 } else {
1054 cb802_1_H_len = 0;
1055 }
1056
Charles Clément21ec51f2010-05-18 10:08:14 -07001057 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001058
1059 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001060 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001061
1062 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001063 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001064 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1065 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001066 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1067 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001068 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001069 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001070 pTxBufHead->wFIFOCtl =
1071 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1072 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001073 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001074 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1075 }
Forest Bond92b96792009-06-13 07:38:31 -04001076 }
1077 else {
1078 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001079 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001080 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1081 }
1082 } //if (pDevice->dwDiagRefCount != 0) {
1083
1084 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1085
1086 //Set FIFOCTL_LHEAD
1087 if (pDevice->bLongHeader)
1088 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1089
1090 if (pDevice->bSoftwareGenCrcErr) {
1091 pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS; // set tx descriptors to NO hardware CRC
1092 }
1093
1094 //Set FRAGCTL_MACHDCNT
1095 if (pDevice->bLongHeader) {
1096 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1097 } else {
1098 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1099 }
Andres More3eaca0d2013-02-25 20:32:52 -05001100 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001101
1102 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001103 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001104 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1105 }
1106
1107 //Set Auto Fallback Ctl
1108 if (wCurrentRate >= RATE_18M) {
1109 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1110 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1111 byFBOption = AUTO_FB_0;
1112 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1113 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1114 byFBOption = AUTO_FB_1;
1115 }
1116 }
1117
Andres More4e9b5e22013-02-12 20:36:30 -05001118 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001119 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1120 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1121 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1122 }
1123 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1124 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1125 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1126 }
1127 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1128 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1129 }
1130 }
1131 }
1132
Forest Bond92b96792009-06-13 07:38:31 -04001133 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1134 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1135 cbIVlen = 4;
1136 cbICVlen = 4;
1137 }
1138 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1139 cbIVlen = 8;//IV+ExtIV
1140 cbMIClen = 8;
1141 cbICVlen = 4;
1142 }
1143 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1144 cbIVlen = 8;//RSN Header
1145 cbICVlen = 8;//MIC
1146 cbMICHDR = sizeof(SMICHDRHead);
1147 }
Andres Moree269fc22013-02-12 20:36:29 -05001148 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001149 //MAC Header should be padding 0 to DW alignment.
1150 uPadding = 4 - (cbMACHdLen%4);
1151 uPadding %= 4;
1152 }
1153 }
1154
1155 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1156
Andres Moree269fc22013-02-12 20:36:29 -05001157 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1158 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001159 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001160 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001161 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1162 }
1163
Andres Moreb902fbf2013-02-25 20:32:51 -05001164 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001165 wTxBufSize = sizeof(STxBufHead);
1166 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1167 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001168 if (bRTS == true) {//RTS_need
Forest Bond92b96792009-06-13 07:38:31 -04001169 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1170 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1171 pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1172 pvCTS = NULL;
1173 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g));
1174 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g) + sizeof(STxDataHead_g);
1175 }
1176 else { //RTS_needless
1177 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1178 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1179 pvRTS = NULL;
1180 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1181 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
1182 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
1183 }
1184 } else {
1185 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001186 if (bRTS == true) {//RTS_need
Forest Bond92b96792009-06-13 07:38:31 -04001187 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1188 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1189 pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1190 pvCTS = NULL;
1191 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
1192 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
1193 }
Andres Moree269fc22013-02-12 20:36:29 -05001194 else if (bRTS == false) { //RTS_needless
Forest Bond92b96792009-06-13 07:38:31 -04001195 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1196 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1197 pvRTS = NULL;
1198 pvCTS = (PSCTS_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1199 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB));
1200 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB) + sizeof(STxDataHead_g_FB);
1201 }
1202 } // Auto Fall Back
1203 }
1204 else {//802.11a/b packet
1205 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001206 if (bRTS == true) {//RTS_need
Forest Bond92b96792009-06-13 07:38:31 -04001207 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1208 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1209 pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1210 pvCTS = NULL;
1211 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
1212 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
1213 }
Andres Moree269fc22013-02-12 20:36:29 -05001214 else if (bRTS == false) { //RTS_needless, no MICHDR
Forest Bond92b96792009-06-13 07:38:31 -04001215 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1216 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1217 pvRTS = NULL;
1218 pvCTS = NULL;
1219 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1220 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
1221 }
1222 } else {
1223 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001224 if (bRTS == true) {//RTS_need
Forest Bond92b96792009-06-13 07:38:31 -04001225 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1226 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1227 pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1228 pvCTS = NULL;
1229 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
1230 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
1231 }
Andres Moree269fc22013-02-12 20:36:29 -05001232 else if (bRTS == false) { //RTS_needless
Forest Bond92b96792009-06-13 07:38:31 -04001233 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1234 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1235 pvRTS = NULL;
1236 pvCTS = NULL;
1237 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1238 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
1239 }
1240 } // Auto Fall Back
1241 }
1242
Andres Moreb902fbf2013-02-25 20:32:51 -05001243 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1244 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1245 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001246
Forest Bond92b96792009-06-13 07:38:31 -04001247 //=========================
1248 // No Fragmentation
1249 //=========================
1250 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1251 byFragType = FRAGCTL_NONFRAG;
1252 //uDMAIdx = TYPE_AC0DMA;
1253 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1254
Forest Bond92b96792009-06-13 07:38:31 -04001255 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001256 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1257 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001258 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1259 //Fill DataHead
1260 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
1261 0, 0, 1/*uMACfragNum*/, byFBOption);
1262 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001263 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001264 byFragType, uDMAIdx, 0);
1265
Andres More4e9b5e22013-02-12 20:36:30 -05001266 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001267 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001268 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001269 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001270
1271 if (pDevice->bEnableHostWEP) {
1272 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1273 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1274 }
1275 }
1276
1277 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001278 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001279 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001280 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1281 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001282 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001283 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001284 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001285 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001286 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001287 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001288 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001289 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001290 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001291
1292 }
1293
1294 }
1295
Forest Bond92b96792009-06-13 07:38:31 -04001296 if (pPacket != NULL) {
1297 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001298 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001299 (pPacket + ETH_HLEN),
1300 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001301 );
1302
1303 } else {
1304 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001305 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001306 }
1307
Andres More4e9b5e22013-02-12 20:36:30 -05001308 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001309
1310 ///////////////////////////////////////////////////////////////////
1311
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001312 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1313 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1314 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1315 }
Forest Bond92b96792009-06-13 07:38:31 -04001316 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001317 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1318 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001319 }
1320 else {
Andres More52a7e642013-02-25 20:32:53 -05001321 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1322 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001323 }
1324 // DO Software Michael
1325 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001326 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001327 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001328 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001329 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1330 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001331
1332 ///////////////////////////////////////////////////////////////////
1333
1334 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1335 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001336 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001337 //}
1338 //DBG_PRN_GRP12(("\n\n\n"));
1339
1340 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1341
Andres More52a7e642013-02-25 20:32:53 -05001342 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1343 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001344
1345 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1346 MIC_vUnInit();
1347
Andres More4e9b5e22013-02-12 20:36:30 -05001348 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001349 *pdwMIC_L = 0;
1350 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001351 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001352 }
1353 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1354 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1355 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1356 }
1357
Andres More4e9b5e22013-02-12 20:36:30 -05001358 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001359
Andres More3eaca0d2013-02-25 20:32:52 -05001360 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001361
Andres More4e9b5e22013-02-12 20:36:30 -05001362 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1363 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1364 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001365 cbFrameSize -= cbICVlen;
1366 }
1367
Andres More4e9b5e22013-02-12 20:36:30 -05001368 if (pDevice->bSoftwareGenCrcErr == true) {
Andres Morecc856e62010-05-17 21:34:01 -03001369 unsigned int cbLen;
Andres More52a7e642013-02-25 20:32:53 -05001370 u32 * pdwCRC;
Forest Bond92b96792009-06-13 07:38:31 -04001371
1372 dwCRC = 0xFFFFFFFFL;
1373 cbLen = cbFrameSize - cbFCSlen;
1374 // calculate CRC, and wrtie CRC value to end of TD
1375 dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
Andres More52a7e642013-02-25 20:32:53 -05001376 pdwCRC = (u32 *)(pbyMacHdr + cbLen);
Forest Bond92b96792009-06-13 07:38:31 -04001377 // finally, we must invert dwCRC to get the correct answer
1378 *pdwCRC = ~dwCRC;
1379 // Force Error
1380 *pdwCRC -= 1;
1381 } else {
1382 cbFrameSize -= cbFCSlen;
1383 }
1384
1385 *pcbHeaderLen = cbHeaderLength;
1386 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1387
Forest Bond92b96792009-06-13 07:38:31 -04001388 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001389 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001390
Andres More4e9b5e22013-02-12 20:36:30 -05001391 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001392
1393}
1394
Forest Bond92b96792009-06-13 07:38:31 -04001395/*+
1396 *
1397 * Description:
1398 * Translate 802.3 to 802.11 header
1399 *
1400 * Parameters:
1401 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001402 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001403 * dwTxBufferAddr - Transmit Buffer
1404 * pPacket - Packet from upper layer
1405 * cbPacketSize - Transmit Data Length
1406 * Out:
1407 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1408 * pcbAppendPayload - size of append payload for 802.1H translation
1409 *
1410 * Return Value: none
1411 *
1412-*/
1413
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001414static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001415 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001416 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001417{
Andres More1cac4a42013-03-18 20:33:50 -05001418 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001419
Forest Bond92b96792009-06-13 07:38:31 -04001420 if (uDMAIdx == TYPE_ATIMDMA) {
Andres More1cac4a42013-03-18 20:33:50 -05001421 pMACHeader->frame_control = TYPE_802_11_ATIM;
Forest Bond92b96792009-06-13 07:38:31 -04001422 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001423 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001424 }
1425
1426 if (pDevice->eOPMode == OP_MODE_AP) {
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]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1431 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001432 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001433 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001434 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001435 } else {
1436 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001437 memcpy(&(pMACHeader->addr1[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->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001444 &(pDevice->abyBSSID[0]),
1445 ETH_ALEN);
1446 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001447 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001448 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001449 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001450 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001451 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001452 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001453 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001454 &(pDevice->abyBSSID[0]),
1455 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001456 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001457 }
1458 }
1459
1460 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001461 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001462
Andres More1cac4a42013-03-18 20:33:50 -05001463 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001464
1465 if (pDevice->bLongHeader) {
1466 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001467 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001468 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001469 }
Andres More1cac4a42013-03-18 20:33:50 -05001470 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001471
1472 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001473 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001474
1475 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1476 pDevice->wSeqCounter++;
1477 if (pDevice->wSeqCounter > 0x0fff)
1478 pDevice->wSeqCounter = 0;
1479 }
1480
1481 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001482 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001483 }
1484}
1485
Forest Bond92b96792009-06-13 07:38:31 -04001486/*+
1487 *
1488 * Description:
1489 * Request instructs a MAC to transmit a 802.11 management packet through
1490 * the adapter onto the medium.
1491 *
1492 * Parameters:
1493 * In:
1494 * hDeviceContext - Pointer to the adapter
1495 * pPacket - A pointer to a descriptor for the packet to transmit
1496 * Out:
1497 * none
1498 *
Andres Moree269fc22013-02-12 20:36:29 -05001499 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001500 *
1501-*/
1502
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001503CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1504 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001505{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001506 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1507 PTX_BUFFER pTX_Buffer;
1508 PSTxBufHead pTxBufHead;
1509 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001510 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001511 PSCTS pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001512 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001513 u8 byPktType, *pbyTxBufferAddr;
1514 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1515 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001516 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001517 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1518 u32 uPadding = 0;
1519 u16 wTxBufSize;
1520 u32 cbMacHdLen;
1521 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001522
Forest Bond92b96792009-06-13 07:38:31 -04001523 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1524
1525 if (NULL == pContext) {
1526 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1527 return CMD_STATUS_RESOURCES;
1528 }
1529
1530 pTX_Buffer = (PTX_BUFFER) (&pContext->Data[0]);
Andres Moreb902fbf2013-02-25 20:32:51 -05001531 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001532 cbFrameBodySize = pPacket->cbPayloadLen;
1533 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1534 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001535
1536 if (pDevice->byBBType == BB_TYPE_11A) {
1537 wCurrentRate = RATE_6M;
1538 byPktType = PK_TYPE_11A;
1539 } else {
1540 wCurrentRate = RATE_1M;
1541 byPktType = PK_TYPE_11B;
1542 }
1543
1544 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1545 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1546 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1547 // to set power here.
1548 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1549 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1550 } else {
1551 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1552 }
1553 pDevice->wCurrentRate = wCurrentRate;
1554
Forest Bond92b96792009-06-13 07:38:31 -04001555 //Set packet type
1556 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1557 pTxBufHead->wFIFOCtl = 0;
1558 }
1559 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1560 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1561 }
1562 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1563 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1564 }
1565 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1566 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1567 }
1568
1569 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1570 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1571
Andres More22040bb2010-08-02 20:21:44 -03001572 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001573 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001574 }
1575 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001576 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001577 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1578 };
1579
1580 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1581 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1582
1583 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1584 //Set Preamble type always long
1585 //pDevice->byPreambleType = PREAMBLE_LONG;
1586 // probe-response don't retry
1587 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001588 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001589 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1590 //}
1591 }
1592
1593 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1594
1595 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001596 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001597 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1598 } else {
1599 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1600 }
1601
1602 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001603 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001604
1605 // Notes:
1606 // Although spec says MMPDU can be fragmented; In most case,
1607 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001608 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001609
1610 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1611 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1612 cbIVlen = 4;
1613 cbICVlen = 4;
1614 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1615 }
1616 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1617 cbIVlen = 8;//IV+ExtIV
1618 cbMIClen = 8;
1619 cbICVlen = 4;
1620 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1621 //We need to get seed here for filling TxKey entry.
1622 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1623 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1624 }
1625 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1626 cbIVlen = 8;//RSN Header
1627 cbICVlen = 8;//MIC
1628 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001629 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001630 }
1631 //MAC Header should be padding 0 to DW alignment.
1632 uPadding = 4 - (cbMacHdLen%4);
1633 uPadding %= 4;
1634 }
1635
1636 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1637
1638 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001639 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001640 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1641 }
1642 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1643
1644 //Set RrvTime/RTS/CTS Buffer
1645 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1646
1647 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1648 pMICHDR = NULL;
1649 pvRTS = NULL;
1650 pCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1651 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS));
1652 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS) + sizeof(STxDataHead_g);
1653 }
1654 else { // 802.11a/b packet
1655 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1656 pMICHDR = NULL;
1657 pvRTS = NULL;
1658 pCTS = NULL;
1659 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1660 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
1661 }
1662
Andres Moreceb8c5d2013-03-18 20:33:49 -05001663 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001664 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1665 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001666 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001667 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1668 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001669 //=========================
1670 // No Fragmentation
1671 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001672 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001673
Forest Bond92b96792009-06-13 07:38:31 -04001674 //Fill FIFO,RrvTime,RTS,and CTS
1675 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1676 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1677
1678 //Fill DataHead
1679 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
1680 0, 0, 1, AUTO_FB_NONE);
1681
Andres More1cac4a42013-03-18 20:33:50 -05001682 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001683
1684 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1685
1686 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001687 u8 * pbyIVHead;
1688 u8 * pbyPayloadHead;
1689 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001690 PSKeyItem pTransmitKey = NULL;
1691
Andres Moreb902fbf2013-02-25 20:32:51 -05001692 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1693 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001694 do {
1695 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001696 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001697 pbyBSSID = pDevice->abyBSSID;
1698 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001699 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001700 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001701 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001702 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1703 break;
1704 }
1705 } else {
1706 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1707 break;
1708 }
1709 }
1710 // get group key
1711 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001712 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001713 pTransmitKey = NULL;
1714 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1715 } else {
1716 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1717 }
Andres Moree269fc22013-02-12 20:36:29 -05001718 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001719 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001720 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001721 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001722
Jim Lieb3e362592009-08-12 14:54:11 -07001723 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001724 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001725 cbFrameBodySize);
1726 }
1727 else {
1728 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001729 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001730 }
1731
Andres More1cac4a42013-03-18 20:33:50 -05001732 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001733 pDevice->wSeqCounter++ ;
1734 if (pDevice->wSeqCounter > 0x0fff)
1735 pDevice->wSeqCounter = 0;
1736
1737 if (bIsPSPOLL) {
1738 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001739 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001740 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1741 // in the same place of other packet's Duration-field).
1742 // And it will cause Cisco-AP to issue Disassociation-packet
1743 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1744 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1745 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1746 } else {
1747 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1748 }
1749 }
1750
Andres More3eaca0d2013-02-25 20:32:52 -05001751 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001752 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001753 pTX_Buffer->byType = 0x00;
1754
1755 pContext->pPacket = NULL;
1756 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001757 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001758
Andres More1cac4a42013-03-18 20:33:50 -05001759 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1760 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001761 }
1762 else {
Andres More1cac4a42013-03-18 20:33:50 -05001763 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001764 }
1765
1766 PIPEnsSendBulkOut(pDevice,pContext);
1767 return CMD_STATUS_PENDING;
1768}
1769
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001770CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1771 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001772{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001773 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1774 u32 cbHeaderSize = 0;
1775 u16 wTxBufSize = sizeof(STxShortBufHead);
1776 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001777 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001778 PSTxDataHead_ab pTxDataHead;
1779 u16 wCurrentRate;
1780 u32 cbFrameBodySize;
1781 u32 cbReqCount;
1782 PBEACON_BUFFER pTX_Buffer;
1783 u8 *pbyTxBufferAddr;
1784 PUSB_SEND_CONTEXT pContext;
1785 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001786
Forest Bond92b96792009-06-13 07:38:31 -04001787 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1788 if (NULL == pContext) {
1789 status = CMD_STATUS_RESOURCES;
1790 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1791 return status ;
1792 }
1793 pTX_Buffer = (PBEACON_BUFFER) (&pContext->Data[0]);
Andres Moreb902fbf2013-02-25 20:32:51 -05001794 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001795
1796 cbFrameBodySize = pPacket->cbPayloadLen;
1797
1798 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1799 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001800
1801 if (pDevice->byBBType == BB_TYPE_11A) {
1802 wCurrentRate = RATE_6M;
1803 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
1804 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001805 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
Andres More3eaca0d2013-02-25 20:32:52 -05001806 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001807 );
1808 //Get Duration and TimeStampOff
Andres More3eaca0d2013-02-25 20:32:52 -05001809 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, PK_TYPE_11A,
Andres Moree269fc22013-02-12 20:36:29 -05001810 wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
Forest Bond92b96792009-06-13 07:38:31 -04001811 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
1812 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
1813 } else {
1814 wCurrentRate = RATE_1M;
1815 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1816 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
1817 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001818 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -05001819 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001820 );
1821 //Get Duration and TimeStampOff
Andres More3eaca0d2013-02-25 20:32:52 -05001822 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, PK_TYPE_11B,
Andres Moree269fc22013-02-12 20:36:29 -05001823 wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
Forest Bond92b96792009-06-13 07:38:31 -04001824 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
1825 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
1826 }
1827
1828 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001829 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001830 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001831
Andres More1cac4a42013-03-18 20:33:50 -05001832 pMACHeader->duration_id = 0;
1833 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001834 pDevice->wSeqCounter++ ;
1835 if (pDevice->wSeqCounter > 0x0fff)
1836 pDevice->wSeqCounter = 0;
1837
1838 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1839
Andres More3eaca0d2013-02-25 20:32:52 -05001840 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001841 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001842 pTX_Buffer->byType = 0x01;
1843
1844 pContext->pPacket = NULL;
1845 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001846 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001847
1848 PIPEnsSendBulkOut(pDevice,pContext);
1849 return CMD_STATUS_PENDING;
1850
1851}
1852
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001853void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1854{
1855 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1856 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;
1883 PTX_BUFFER pTX_Buffer;
1884 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001885
Forest Bond92b96792009-06-13 07:38:31 -04001886 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1887
1888 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1889 cbFrameBodySize = 0;
1890 }
1891 else {
1892 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1893 }
1894 p80211Header = (PUWLAN_80211HDR)skb->data;
1895
1896 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1897
1898 if (NULL == pContext) {
1899 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1900 dev_kfree_skb_irq(skb);
1901 return ;
1902 }
1903
1904 pTX_Buffer = (PTX_BUFFER)(&pContext->Data[0]);
Andres Moreb902fbf2013-02-25 20:32:51 -05001905 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001906 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1907 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001908
1909 if (pDevice->byBBType == BB_TYPE_11A) {
1910 wCurrentRate = RATE_6M;
1911 byPktType = PK_TYPE_11A;
1912 } else {
1913 wCurrentRate = RATE_1M;
1914 byPktType = PK_TYPE_11B;
1915 }
1916
1917 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1918 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1919 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1920 // to set power here.
1921 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1922 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1923 } else {
1924 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1925 }
1926
1927 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1928
1929 //Set packet type
1930 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1931 pTxBufHead->wFIFOCtl = 0;
1932 }
1933 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1934 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1935 }
1936 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1937 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1938 }
1939 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1940 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1941 }
1942
1943 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1944 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1945
Andres More22040bb2010-08-02 20:21:44 -03001946 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001947 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001948 if (pDevice->bEnableHostWEP) {
1949 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001950 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001951 }
Forest Bond92b96792009-06-13 07:38:31 -04001952 }
1953 else {
1954 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001955 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001956 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001957 }
Andres More4e9b5e22013-02-12 20:36:30 -05001958 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001959 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1960 };
1961
1962 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1963 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1964
1965 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1966 //Set Preamble type always long
1967 //pDevice->byPreambleType = PREAMBLE_LONG;
1968
1969 // probe-response don't retry
1970 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001971 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001972 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1973 //}
1974 }
1975
1976 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1977
1978 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001979 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001980 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1981 } else {
1982 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1983 }
1984
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001985 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001986 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1987
1988 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1989 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1990 }
1991
1992 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1993 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1994 }
1995
1996 if (cbExtSuppRate >0) {
1997 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1998 }
1999 }
2000
Forest Bond92b96792009-06-13 07:38:31 -04002001 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05002002 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04002003
2004 // Notes:
2005 // Although spec says MMPDU can be fragmented; In most case,
2006 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05002007 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04002008
Forest Bond92b96792009-06-13 07:38:31 -04002009 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2010 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2011 cbIVlen = 4;
2012 cbICVlen = 4;
2013 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2014 }
2015 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2016 cbIVlen = 8;//IV+ExtIV
2017 cbMIClen = 8;
2018 cbICVlen = 4;
2019 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2020 //We need to get seed here for filling TxKey entry.
2021 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2022 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2023 }
2024 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2025 cbIVlen = 8;//RSN Header
2026 cbICVlen = 8;//MIC
2027 cbMICHDR = sizeof(SMICHDRHead);
2028 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002029 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002030 }
2031 //MAC Header should be padding 0 to DW alignment.
2032 uPadding = 4 - (cbMacHdLen%4);
2033 uPadding %= 4;
2034 }
2035
2036 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2037
2038 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002039 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002040 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2041 }
2042 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2043
Forest Bond92b96792009-06-13 07:38:31 -04002044 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
2045
2046 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2047 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2048 pvRTS = NULL;
2049 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
2050 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
2051 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
2052
2053 }
2054 else {//802.11a/b packet
2055
2056 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2057 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2058 pvRTS = NULL;
2059 pvCTS = NULL;
2060 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
2061 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
2062 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002063 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002064 &(p80211Header->sA3.abyAddr1[0]),
2065 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002066 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002067 &(p80211Header->sA3.abyAddr2[0]),
2068 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002069 //=========================
2070 // No Fragmentation
2071 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002072 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002073
Forest Bond92b96792009-06-13 07:38:31 -04002074 //Fill FIFO,RrvTime,RTS,and CTS
2075 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2076 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2077
2078 //Fill DataHead
2079 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2080 0, 0, 1, AUTO_FB_NONE);
2081
Andres More1cac4a42013-03-18 20:33:50 -05002082 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002083
2084 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2085
Andres Moreb902fbf2013-02-25 20:32:51 -05002086 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2087 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2088 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002089
2090 // Copy the Packet into a tx Buffer
2091 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2092
2093 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002094 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002095 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2096
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002097 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002098 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2099 if (cbExtSuppRate != 0) {
2100 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2101 memcpy((pbyPayloadHead + cbFrameBodySize),
2102 pMgmt->abyCurrSuppRates,
2103 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2104 );
2105 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2106 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2107 pMgmt->abyCurrExtSuppRates,
2108 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2109 );
2110 }
2111 }
2112
2113 // Set wep
2114 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2115
2116 if (pDevice->bEnableHostWEP) {
2117 pTransmitKey = &STempKey;
2118 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2119 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2120 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2121 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2122 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2123 memcpy(pTransmitKey->abyKey,
2124 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2125 pTransmitKey->uKeyLength
2126 );
2127 }
2128
2129 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2130
Andres More52a7e642013-02-25 20:32:53 -05002131 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2132 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002133
2134 // DO Software Michael
2135 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002136 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002137 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002138 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002139 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2140 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002141
2142 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2143
2144 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2145
Andres More52a7e642013-02-25 20:32:53 -05002146 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2147 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002148
2149 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2150 MIC_vUnInit();
2151
Andres More4e9b5e22013-02-12 20:36:30 -05002152 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002153 *pdwMIC_L = 0;
2154 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002155 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002156 }
2157
2158 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2159 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002160 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2161 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002162
2163 }
2164
Andres Moreb902fbf2013-02-25 20:32:51 -05002165 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05002166 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002167
2168 if (pDevice->bEnableHostWEP) {
2169 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2170 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2171 }
2172
2173 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002174 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002175 }
2176 }
2177
Andres More1cac4a42013-03-18 20:33:50 -05002178 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002179 pDevice->wSeqCounter++ ;
2180 if (pDevice->wSeqCounter > 0x0fff)
2181 pDevice->wSeqCounter = 0;
2182
Forest Bond92b96792009-06-13 07:38:31 -04002183 if (bIsPSPOLL) {
2184 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2185 // of FIFO control header.
2186 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2187 // in the same place of other packet's Duration-field).
2188 // And it will cause Cisco-AP to issue Disassociation-packet
2189 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2190 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
2191 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
2192 } else {
2193 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
2194 }
2195 }
2196
Andres More3eaca0d2013-02-25 20:32:52 -05002197 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002198 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002199 pTX_Buffer->byType = 0x00;
2200
2201 pContext->pPacket = skb;
2202 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002203 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002204
Andres More1cac4a42013-03-18 20:33:50 -05002205 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2206 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002207 }
2208 else {
Andres More1cac4a42013-03-18 20:33:50 -05002209 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002210 }
2211 PIPEnsSendBulkOut(pDevice,pContext);
2212 return ;
2213
2214}
2215
Forest Bond92b96792009-06-13 07:38:31 -04002216//TYPE_AC0DMA data tx
2217/*
2218 * Description:
2219 * Tx packet via AC0DMA(DMA1)
2220 *
2221 * Parameters:
2222 * In:
2223 * pDevice - Pointer to the adapter
2224 * skb - Pointer to tx skb packet
2225 * Out:
2226 * void
2227 *
2228 * Return Value: NULL
2229 */
2230
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002231int nsDMA_tx_packet(struct vnt_private *pDevice,
2232 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002233{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002234 struct net_device_stats *pStats = &pDevice->stats;
2235 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2236 u32 BytesToWrite = 0, uHeaderLen = 0;
2237 u32 uNodeIndex = 0;
2238 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2239 u16 wAID;
2240 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002241 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002242 PSKeyItem pTransmitKey = NULL;
2243 SKeyItem STempKey;
2244 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002245 int bTKIP_UseGTK = false;
2246 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002247 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002248 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002249 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002250 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002251 PTX_BUFFER pTX_Buffer;
2252 u32 status;
2253 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002254 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002255
Forest Bond92b96792009-06-13 07:38:31 -04002256 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2257
2258 if (pDevice->uAssocCount == 0) {
2259 dev_kfree_skb_irq(skb);
2260 return 0;
2261 }
2262
Andres Moreb902fbf2013-02-25 20:32:51 -05002263 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002264 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002265 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002266 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2267
2268 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2269 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2270 // set tx map
2271 pMgmt->abyPSTxMap[0] |= byMask[0];
2272 return 0;
2273 }
Masanari Iida93184692012-08-13 21:21:50 +09002274 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002275
2276 if (pDevice->byBBType != BB_TYPE_11A)
2277 pDevice->wCurrentRate = RATE_2M;
2278 else
2279 pDevice->wCurrentRate = RATE_24M;
2280 // long preamble type
2281 pDevice->byPreambleType = PREAMBLE_SHORT;
2282
2283 }else {
2284
Andres Moreb902fbf2013-02-25 20:32:51 -05002285 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002286
2287 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2288
2289 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2290
2291 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2292 // set tx map
2293 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2294 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2295 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2296 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2297
2298 return 0;
2299 }
2300 // AP rate decided from node
2301 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2302 // tx preamble decided from node
2303
2304 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2305 pDevice->byPreambleType = pDevice->byShortPreamble;
2306
2307 }else {
2308 pDevice->byPreambleType = PREAMBLE_LONG;
2309 }
Andres More4e9b5e22013-02-12 20:36:30 -05002310 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002311 }
2312 }
2313
Andres Moree269fc22013-02-12 20:36:29 -05002314 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002315 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2316 dev_kfree_skb_irq(skb);
2317 return 0;
2318 }
2319 }
2320
2321 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2322
2323 if (pContext == NULL) {
2324 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2325 dev_kfree_skb_irq(skb);
2326 return STATUS_RESOURCES;
2327 }
2328
Andres Moreceb8c5d2013-03-18 20:33:49 -05002329 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002330
2331//mike add:station mode check eapol-key challenge--->
2332{
Andres Moreb902fbf2013-02-25 20:32:51 -05002333 u8 Protocol_Version; //802.1x Authentication
2334 u8 Packet_Type; //802.1x Authentication
2335 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002336 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002337
Charles Clément21ec51f2010-05-18 10:08:14 -07002338 Protocol_Version = skb->data[ETH_HLEN];
2339 Packet_Type = skb->data[ETH_HLEN+1];
2340 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2341 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 -05002342 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002343 /* 802.1x OR eapol-key challenge frame transfer */
2344 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2345 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002346 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002347 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2348 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2349 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002350 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002351 PRINT_K("WPA ");
2352 }
2353 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002354 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002355 PRINT_K("WPA2(re-keying) ");
2356 }
2357 PRINT_K("Authentication completed!!\n");
2358 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002359 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002360 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002361 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002362 PRINT_K("WPA2 Authentication completed!!\n");
2363 }
2364 }
2365 }
2366}
2367//mike add:station mode check eapol-key challenge<---
2368
Andres More4e9b5e22013-02-12 20:36:30 -05002369 if (pDevice->bEncryptionEnable == true) {
2370 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002371 // get Transmit key
2372 do {
2373 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2374 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2375 pbyBSSID = pDevice->abyBSSID;
2376 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002377 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002378 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002379 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2380 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2382 break;
2383 }
2384 } else {
2385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2386 break;
2387 }
2388 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002389 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2390 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2392 for (ii = 0; ii< 6; ii++)
2393 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2394 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2395
2396 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002397 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002398 break;
2399 }
2400 // get group key
2401 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002402 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002403 pTransmitKey = NULL;
2404 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2406 }
2407 else
2408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2409 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002410 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002411 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2412 }
Andres Moree269fc22013-02-12 20:36:29 -05002413 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002414 }
2415
2416 if (pDevice->bEnableHostWEP) {
2417 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002418 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002419 pTransmitKey = &STempKey;
2420 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2421 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2422 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2423 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2424 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2425 memcpy(pTransmitKey->abyKey,
2426 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2427 pTransmitKey->uKeyLength
2428 );
2429 }
2430 }
2431
Andres Moreb902fbf2013-02-25 20:32:51 -05002432 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002433
2434 if (pDevice->bFixRate) {
2435 if (pDevice->byBBType == BB_TYPE_11B) {
2436 if (pDevice->uConnectionRate >= RATE_11M) {
2437 pDevice->wCurrentRate = RATE_11M;
2438 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002439 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002440 }
2441 } else {
2442 if ((pDevice->byBBType == BB_TYPE_11A) &&
2443 (pDevice->uConnectionRate <= RATE_6M)) {
2444 pDevice->wCurrentRate = RATE_6M;
2445 } else {
2446 if (pDevice->uConnectionRate >= RATE_54M)
2447 pDevice->wCurrentRate = RATE_54M;
2448 else
Andres More3eaca0d2013-02-25 20:32:52 -05002449 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002450 }
2451 }
2452 }
2453 else {
2454 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2455 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002456 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002457 // Multicast use highest data rate
2458 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2459 // preamble type
2460 pDevice->byPreambleType = pDevice->byShortPreamble;
2461 }
2462 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002463 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002464 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2465 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2466 pDevice->byPreambleType = pDevice->byShortPreamble;
2467
2468 }
2469 else {
2470 pDevice->byPreambleType = PREAMBLE_LONG;
2471 }
2472 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2473 }
2474 else {
2475 if (pDevice->byBBType != BB_TYPE_11A)
2476 pDevice->wCurrentRate = RATE_2M;
2477 else
2478 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2479 // abyCurrExtSuppRates[]
2480 pDevice->byPreambleType = PREAMBLE_SHORT;
2481 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2482 }
2483 }
2484 }
2485 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2486 // Infra STA rate decided from AP Node, index = 0
2487 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2488 }
2489 }
2490
Andres Moreceb8c5d2013-03-18 20:33:49 -05002491 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002492 if (pDevice->byBBType != BB_TYPE_11A) {
2493 pDevice->wCurrentRate = RATE_1M;
2494 pDevice->byACKRate = RATE_1M;
2495 pDevice->byTopCCKBasicRate = RATE_1M;
2496 pDevice->byTopOFDMBasicRate = RATE_6M;
2497 } else {
2498 pDevice->wCurrentRate = RATE_6M;
2499 pDevice->byACKRate = RATE_6M;
2500 pDevice->byTopCCKBasicRate = RATE_1M;
2501 pDevice->byTopOFDMBasicRate = RATE_6M;
2502 }
2503 }
Forest Bond92b96792009-06-13 07:38:31 -04002504
Andres More0cbd8d92010-05-06 20:34:29 -03002505 DBG_PRT(MSG_LEVEL_DEBUG,
2506 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2507 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002508
2509 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002510 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002511 }
2512
2513 if (pDevice->wCurrentRate <= RATE_11M) {
2514 byPktType = PK_TYPE_11B;
2515 }
2516
Andres More4e9b5e22013-02-12 20:36:30 -05002517 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002518 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2519 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002520 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002521 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002522 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2523 if (pTransmitKey == NULL) {
2524 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2525 }
2526 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002527 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002528 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2529 }
2530 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002531 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2532 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002533 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002534 }
2535 }
2536 }
2537
Forest Bond92b96792009-06-13 07:38:31 -04002538 if (pDevice->bEnableHostWEP) {
2539 if ((uNodeIndex != 0) &&
2540 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002541 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2542 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002543 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002544 }
2545 }
2546 }
2547 else {
2548
Forest Bond92b96792009-06-13 07:38:31 -04002549 if (pTransmitKey == NULL) {
2550 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002551 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002552 dev_kfree_skb_irq(skb);
2553 pStats->tx_dropped++;
2554 return STATUS_FAILURE;
2555 }
Forest Bond92b96792009-06-13 07:38:31 -04002556 }
2557 }
2558
2559 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Andres Moreb902fbf2013-02-25 20:32:51 -05002560 (u8 *)(&pContext->Data[0]), bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002561 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002562 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002563 pDevice->wCurrentRate,
2564 &uHeaderLen, &BytesToWrite
2565 );
2566
Andres Moree269fc22013-02-12 20:36:29 -05002567 if (fConvertedPacket == false) {
2568 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002569 dev_kfree_skb_irq(skb);
2570 return STATUS_FAILURE;
2571 }
2572
Andres More4e9b5e22013-02-12 20:36:30 -05002573 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002574 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002575 bScheduleCommand((void *) pDevice,
2576 WLAN_CMD_MAC_DISPOWERSAVING,
2577 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002578 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002579 }
2580 }
2581
2582 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
Andres Moreb902fbf2013-02-25 20:32:51 -05002583 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002584 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002585
2586 pContext->pPacket = skb;
2587 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002588 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002589
Andres Moreceb8c5d2013-03-18 20:33:49 -05002590 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 -04002591
2592 status = PIPEnsSendBulkOut(pDevice,pContext);
2593
Andres More4e9b5e22013-02-12 20:36:30 -05002594 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002595 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002596
Andres Moreb902fbf2013-02-25 20:32:51 -05002597 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002598 }
2599
2600 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002601 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002602 dev_kfree_skb_irq(skb);
2603 return STATUS_FAILURE;
2604 }
2605 else
2606 return 0;
2607
2608}
2609
Forest Bond92b96792009-06-13 07:38:31 -04002610/*
2611 * Description:
2612 * Relay packet send (AC1DMA) from rx dpc.
2613 *
2614 * Parameters:
2615 * In:
2616 * pDevice - Pointer to the adapter
2617 * pPacket - Pointer to rx packet
2618 * cbPacketSize - rx ethernet frame size
2619 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002620 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002621 *
Andres More4e9b5e22013-02-12 20:36:30 -05002622 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002623 */
2624
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002625int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2626 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002627{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002628 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2629 u32 BytesToWrite = 0, uHeaderLen = 0;
2630 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002631 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002632 SKeyItem STempKey;
2633 PSKeyItem pTransmitKey = NULL;
2634 u8 *pbyBSSID;
2635 PUSB_SEND_CONTEXT pContext;
2636 u8 byPktTyp;
2637 int fConvertedPacket;
2638 PTX_BUFFER pTX_Buffer;
2639 u32 status;
2640 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002641
Forest Bond92b96792009-06-13 07:38:31 -04002642 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2643
2644 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002645 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002646 }
2647
Andres Moreceb8c5d2013-03-18 20:33:49 -05002648 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002649
Andres More4e9b5e22013-02-12 20:36:30 -05002650 if (pDevice->bEncryptionEnable == true) {
2651 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002652 // get group key
2653 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002654 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002655 pTransmitKey = NULL;
2656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2657 } else {
2658 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2659 }
2660 }
2661
2662 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002663 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002664 pTransmitKey = &STempKey;
2665 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2666 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2667 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2668 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2669 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2670 memcpy(pTransmitKey->abyKey,
2671 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2672 pTransmitKey->uKeyLength
2673 );
2674 }
2675 }
2676
2677 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002678 pContext->bBoolInUse = false;
2679 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002680 }
2681
Andres Moreb902fbf2013-02-25 20:32:51 -05002682 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002683
2684 if (pDevice->bFixRate) {
2685 if (pDevice->byBBType == BB_TYPE_11B) {
2686 if (pDevice->uConnectionRate >= RATE_11M) {
2687 pDevice->wCurrentRate = RATE_11M;
2688 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002689 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002690 }
2691 } else {
2692 if ((pDevice->byBBType == BB_TYPE_11A) &&
2693 (pDevice->uConnectionRate <= RATE_6M)) {
2694 pDevice->wCurrentRate = RATE_6M;
2695 } else {
2696 if (pDevice->uConnectionRate >= RATE_54M)
2697 pDevice->wCurrentRate = RATE_54M;
2698 else
Andres More3eaca0d2013-02-25 20:32:52 -05002699 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002700 }
2701 }
2702 }
2703 else {
2704 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2705 }
2706
Forest Bond92b96792009-06-13 07:38:31 -04002707 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002708 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002709 }
2710
2711 if (pDevice->wCurrentRate <= RATE_11M)
2712 byPktType = PK_TYPE_11B;
2713
Andres Moreabad19d2010-07-12 16:28:32 -03002714 BytesToWrite = uDataLen + ETH_FCS_LEN;
2715
Forest Bond92b96792009-06-13 07:38:31 -04002716 // Convert the packet to an usb frame and copy into our buffer
2717 // and send the irp.
2718
2719 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Andres Moreb902fbf2013-02-25 20:32:51 -05002720 (u8 *)(&pContext->Data[0]), bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002721 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2722 pbySkbData, pTransmitKey, uNodeIndex,
2723 pDevice->wCurrentRate,
2724 &uHeaderLen, &BytesToWrite
2725 );
2726
Andres Moree269fc22013-02-12 20:36:29 -05002727 if (fConvertedPacket == false) {
2728 pContext->bBoolInUse = false;
2729 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002730 }
2731
2732 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
Andres Moreb902fbf2013-02-25 20:32:51 -05002733 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002734 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002735
2736 pContext->pPacket = NULL;
2737 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002738 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002739
Andres Moreceb8c5d2013-03-18 20:33:49 -05002740 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 -04002741
2742 status = PIPEnsSendBulkOut(pDevice,pContext);
2743
Andres More4e9b5e22013-02-12 20:36:30 -05002744 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002745}
2746