blob: fd6f817fdda51ed04d50097fcce806e6cbb206fb [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 Priestleyd56131d2013-01-17 23:15:22 +0000395 int bLastFrag = 0;
396 u32 uAckTime = 0, uNextPktTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400397
398 if (uFragIdx == (uMACfragNum-1)) {
399 bLastFrag = 1;
400 }
401
402 switch (byDurType) {
403
404 case DATADUR_B: //DATADUR_B
405 if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
406 if (bNeedAck) {
407 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
408 return (pDevice->uSIFS + uAckTime);
409 } else {
410 return 0;
411 }
412 }
413 else {//First Frag or Mid Frag
414 if (uFragIdx == (uMACfragNum-2)) {
415 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
416 } else {
417 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
418 }
419 if (bNeedAck) {
420 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
421 return (pDevice->uSIFS + uAckTime + uNextPktTime);
422 } else {
423 return (pDevice->uSIFS + uNextPktTime);
424 }
425 }
426 break;
427
Forest Bond92b96792009-06-13 07:38:31 -0400428 case DATADUR_A: //DATADUR_A
429 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
430 if(bNeedAck){
431 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
432 return (pDevice->uSIFS + uAckTime);
433 } else {
434 return 0;
435 }
436 }
437 else {//First Frag or Mid Frag
438 if(uFragIdx == (uMACfragNum-2)){
439 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
440 } else {
441 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
442 }
443 if(bNeedAck){
444 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
445 return (pDevice->uSIFS + uAckTime + uNextPktTime);
446 } else {
447 return (pDevice->uSIFS + uNextPktTime);
448 }
449 }
450 break;
451
452 case DATADUR_A_F0: //DATADUR_A_F0
453 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
454 if(bNeedAck){
455 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
456 return (pDevice->uSIFS + uAckTime);
457 } else {
458 return 0;
459 }
460 }
461 else { //First Frag or Mid Frag
462 if (byFBOption == AUTO_FB_0) {
463 if (wRate < RATE_18M)
464 wRate = RATE_18M;
465 else if (wRate > RATE_54M)
466 wRate = RATE_54M;
467
468 if(uFragIdx == (uMACfragNum-2)){
469 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
470 } else {
471 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
472 }
473 } else { // (byFBOption == AUTO_FB_1)
474 if (wRate < RATE_18M)
475 wRate = RATE_18M;
476 else if (wRate > RATE_54M)
477 wRate = RATE_54M;
478
479 if(uFragIdx == (uMACfragNum-2)){
480 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
481 } else {
482 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
483 }
484 }
485
486 if(bNeedAck){
487 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
488 return (pDevice->uSIFS + uAckTime + uNextPktTime);
489 } else {
490 return (pDevice->uSIFS + uNextPktTime);
491 }
492 }
493 break;
494
495 case DATADUR_A_F1: //DATADUR_A_F1
496 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
497 if(bNeedAck){
498 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
499 return (pDevice->uSIFS + uAckTime);
500 } else {
501 return 0;
502 }
503 }
504 else { //First Frag or Mid Frag
505 if (byFBOption == AUTO_FB_0) {
506 if (wRate < RATE_18M)
507 wRate = RATE_18M;
508 else if (wRate > RATE_54M)
509 wRate = RATE_54M;
510
511 if(uFragIdx == (uMACfragNum-2)){
512 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
513 } else {
514 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
515 }
516
517 } else { // (byFBOption == AUTO_FB_1)
518 if (wRate < RATE_18M)
519 wRate = RATE_18M;
520 else if (wRate > RATE_54M)
521 wRate = RATE_54M;
522
523 if(uFragIdx == (uMACfragNum-2)){
524 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
525 } else {
526 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
527 }
528 }
529 if(bNeedAck){
530 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
531 return (pDevice->uSIFS + uAckTime + uNextPktTime);
532 } else {
533 return (pDevice->uSIFS + uNextPktTime);
534 }
535 }
536 break;
537
538 default:
539 break;
540 }
541
Forest Bond92b96792009-06-13 07:38:31 -0400542 return 0;
543}
544
Forest Bond92b96792009-06-13 07:38:31 -0400545//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000546static u32 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
547 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
548 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400549{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000550 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400551
Forest Bond92b96792009-06-13 07:38:31 -0400552 switch (byDurType) {
553
554 case RTSDUR_BB: //RTSDuration_bb
555 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
556 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
557 break;
558
559 case RTSDUR_BA: //RTSDuration_ba
560 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
561 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
562 break;
563
564 case RTSDUR_AA: //RTSDuration_aa
565 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
566 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
567 break;
568
569 case CTSDUR_BA: //CTSDuration_ba
570 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
571 break;
572
573 case RTSDUR_BA_F0: //RTSDuration_ba_f0
574 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
575 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
576 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
577 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
578 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
579 }
580 break;
581
582 case RTSDUR_AA_F0: //RTSDuration_aa_f0
583 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
584 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
585 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
586 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
587 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
588 }
589 break;
590
591 case RTSDUR_BA_F1: //RTSDuration_ba_f1
592 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
593 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
594 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
595 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
596 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
597 }
598 break;
599
600 case RTSDUR_AA_F1: //RTSDuration_aa_f1
601 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
602 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
603 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
604 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
605 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
606 }
607 break;
608
609 case CTSDUR_BA_F0: //CTSDuration_ba_f0
610 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
611 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
612 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
613 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
614 }
615 break;
616
617 case CTSDUR_BA_F1: //CTSDuration_ba_f1
618 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
619 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
620 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
621 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
622 }
623 break;
624
625 default:
626 break;
627 }
628
629 return uDurTime;
630
631}
632
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000633static u32 s_uFillDataHead(struct vnt_private *pDevice,
634 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
635 u32 uDMAIdx, int bNeedAck, u32 uFragIdx, u32 cbLastFragmentSize,
636 u32 uMACfragNum, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400637{
638
639 if (pTxDataHead == NULL) {
640 return 0;
641 }
642
643 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Andres Morebd2bc4c2010-08-02 23:35:57 -0300644 if ((uDMAIdx == TYPE_ATIMDMA) || (uDMAIdx == TYPE_BEACONDMA)) {
645 PSTxDataHead_ab pBuf = (PSTxDataHead_ab) pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400646 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700647 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500648 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400649 );
650 //Get Duration and TimeStampOff
Andres More3eaca0d2013-02-25 20:32:52 -0500651 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400652 wCurrentRate, bNeedAck, uFragIdx,
653 cbLastFragmentSize, uMACfragNum,
654 byFBOption); //1: 2.4GHz
655 if(uDMAIdx!=TYPE_ATIMDMA) {
656 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
657 }
658 return (pBuf->wDuration);
659 }
660 else { // DATA & MANAGE Frame
661 if (byFBOption == AUTO_FB_NONE) {
662 PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
663 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700664 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500665 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400666 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700667 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500668 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400669 );
670 //Get Duration and TimeStamp
Andres More3eaca0d2013-02-25 20:32:52 -0500671 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
Forest Bond92b96792009-06-13 07:38:31 -0400672 byPktType, wCurrentRate, bNeedAck, uFragIdx,
673 cbLastFragmentSize, uMACfragNum,
674 byFBOption); //1: 2.4GHz
Andres More3eaca0d2013-02-25 20:32:52 -0500675 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
Forest Bond92b96792009-06-13 07:38:31 -0400676 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
677 bNeedAck, uFragIdx, cbLastFragmentSize,
678 uMACfragNum, byFBOption); //1: 2.4GHz
679
680 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
681 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
682 return (pBuf->wDuration_a);
683 } else {
684 // Auto Fallback
685 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
686 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700687 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500688 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400689 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700690 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500691 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400692 );
693 //Get Duration and TimeStamp
Andres More3eaca0d2013-02-25 20:32:52 -0500694 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400695 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
Andres More3eaca0d2013-02-25 20:32:52 -0500696 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
Forest Bond92b96792009-06-13 07:38:31 -0400697 pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
Andres More3eaca0d2013-02-25 20:32:52 -0500698 pBuf->wDuration_a_f0 = (u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400699 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
Andres More3eaca0d2013-02-25 20:32:52 -0500700 pBuf->wDuration_a_f1 = (u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400701 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
702 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
703 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
704 return (pBuf->wDuration_a);
705 } //if (byFBOption == AUTO_FB_NONE)
706 }
707 }
708 else if (byPktType == PK_TYPE_11A) {
709 if ((byFBOption != AUTO_FB_NONE) && (uDMAIdx != TYPE_ATIMDMA) && (uDMAIdx != TYPE_BEACONDMA)) {
710 // Auto Fallback
711 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
712 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700713 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500714 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400715 );
716 //Get Duration and TimeStampOff
Andres More3eaca0d2013-02-25 20:32:52 -0500717 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400718 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
Andres More3eaca0d2013-02-25 20:32:52 -0500719 pBuf->wDuration_f0 = (u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400720 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
Andres More3eaca0d2013-02-25 20:32:52 -0500721 pBuf->wDuration_f1 = (u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400722 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
723 if(uDMAIdx!=TYPE_ATIMDMA) {
724 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
725 }
726 return (pBuf->wDuration);
727 } else {
728 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
729 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700730 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500731 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400732 );
733 //Get Duration and TimeStampOff
Andres More3eaca0d2013-02-25 20:32:52 -0500734 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400735 wCurrentRate, bNeedAck, uFragIdx,
736 cbLastFragmentSize, uMACfragNum,
737 byFBOption);
738
739 if(uDMAIdx!=TYPE_ATIMDMA) {
740 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
741 }
742 return (pBuf->wDuration);
743 }
744 }
745 else if (byPktType == PK_TYPE_11B) {
746 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
747 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700748 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500749 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400750 );
751 //Get Duration and TimeStampOff
Andres More3eaca0d2013-02-25 20:32:52 -0500752 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
Forest Bond92b96792009-06-13 07:38:31 -0400753 wCurrentRate, bNeedAck, uFragIdx,
754 cbLastFragmentSize, uMACfragNum,
755 byFBOption);
756 if (uDMAIdx != TYPE_ATIMDMA) {
757 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
758 }
759 return (pBuf->wDuration);
760 }
761 return 0;
762}
763
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000764static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
765 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500766 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400767{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000768 u32 uRTSFrameLen = 20;
769 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400770
Forest Bond92b96792009-06-13 07:38:31 -0400771 if (pvRTS == NULL)
772 return;
773
774 if (bDisCRC) {
775 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
776 // in this case we need to decrease its length by 4.
777 uRTSFrameLen -= 4;
778 }
779
Masanari Iida93184692012-08-13 21:21:50 +0900780 // 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 -0400781 // Otherwise, we need to modified codes for them.
782 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
783 if (byFBOption == AUTO_FB_NONE) {
784 PSRTS_g pBuf = (PSRTS_g)pvRTS;
785 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700786 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500787 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400788 );
789 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700790 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500791 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400792 );
793 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
794 //Get Duration
Andres More3eaca0d2013-02-25 20:32:52 -0500795 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
796 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
797 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 +0100798 pBuf->data.duration = pBuf->wDuration_aa;
799 /*Get RTS Frame body */
800 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400801
Malcolm Priestley07738932013-08-05 22:08:05 +0100802 if (pDevice->eOPMode == OP_MODE_ADHOC ||
803 pDevice->eOPMode == OP_MODE_AP)
804 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
805 else
806 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Andres More9a0e7562010-04-13 21:54:48 -0300807
Malcolm Priestley07738932013-08-05 22:08:05 +0100808 if (pDevice->eOPMode == OP_MODE_AP)
809 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
810 else
811 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400812 }
813 else {
814 PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
815 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700816 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500817 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400818 );
819 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700820 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500821 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400822 );
823 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
824 //Get Duration
Andres More3eaca0d2013-02-25 20:32:52 -0500825 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
826 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
827 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
828 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
829 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
830 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
831 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 +0100832 pBuf->data.duration = pBuf->wDuration_aa;
833 /*Get RTS Frame body*/
834 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400835
Malcolm Priestley07738932013-08-05 22:08:05 +0100836 if (pDevice->eOPMode == OP_MODE_ADHOC ||
837 pDevice->eOPMode == OP_MODE_AP)
838 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
839 else
840 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400841
Malcolm Priestley07738932013-08-05 22:08:05 +0100842 if (pDevice->eOPMode == OP_MODE_AP)
843 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
844 else
845 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400846 } // if (byFBOption == AUTO_FB_NONE)
847 }
848 else if (byPktType == PK_TYPE_11A) {
849 if (byFBOption == AUTO_FB_NONE) {
850 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
851 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700852 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500853 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400854 );
855 pBuf->wTransmitLength = cpu_to_le16(wLen);
856 //Get Duration
Andres More3eaca0d2013-02-25 20:32:52 -0500857 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 +0100858 pBuf->data.duration = pBuf->wDuration;
859 /* Get RTS Frame body */
860 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400861
Malcolm Priestley07738932013-08-05 22:08:05 +0100862 if (pDevice->eOPMode == OP_MODE_ADHOC ||
863 pDevice->eOPMode == OP_MODE_AP)
864 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
865 else
866 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400867
Malcolm Priestley07738932013-08-05 22:08:05 +0100868 if (pDevice->eOPMode == OP_MODE_AP)
869 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
870 else
871 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400872 }
873 else {
874 PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
875 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700876 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500877 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400878 );
879 pBuf->wTransmitLength = cpu_to_le16(wLen);
880 //Get Duration
Andres More3eaca0d2013-02-25 20:32:52 -0500881 pBuf->wDuration = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
882 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
883 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 +0100884 pBuf->data.duration = pBuf->wDuration;
885 /* Get RTS Frame body */
886 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400887
Malcolm Priestley07738932013-08-05 22:08:05 +0100888 if (pDevice->eOPMode == OP_MODE_ADHOC ||
889 pDevice->eOPMode == OP_MODE_AP)
890 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
891 else
892 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
893
894 if (pDevice->eOPMode == OP_MODE_AP)
895 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
896 else
897 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400898 }
899 }
900 else if (byPktType == PK_TYPE_11B) {
901 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
902 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700903 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500904 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400905 );
906 pBuf->wTransmitLength = cpu_to_le16(wLen);
907 //Get Duration
Andres More3eaca0d2013-02-25 20:32:52 -0500908 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 -0400909
Malcolm Priestley07738932013-08-05 22:08:05 +0100910 pBuf->data.duration = pBuf->wDuration;
911 /* Get RTS Frame body */
912 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400913
Malcolm Priestley07738932013-08-05 22:08:05 +0100914 if (pDevice->eOPMode == OP_MODE_ADHOC ||
915 pDevice->eOPMode == OP_MODE_AP)
916 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
917 else
918 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
919
920 if (pDevice->eOPMode == OP_MODE_AP)
921 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
922 else
923 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400924 }
925}
926
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000927static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
928 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
929 int bDisCRC, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400930{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000931 u32 uCTSFrameLen = 14;
932 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400933
934 if (pvCTS == NULL) {
935 return;
936 }
937
938 if (bDisCRC) {
939 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
940 // in this case we need to decrease its length by 4.
941 uCTSFrameLen -= 4;
942 }
943
944 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
945 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
946 // Auto Fall back
947 PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
948 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700949 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500950 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400951 );
952 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Andres More3eaca0d2013-02-25 20:32:52 -0500953 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 -0400954 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
955 //Get CTSDuration_ba_f0
Andres More3eaca0d2013-02-25 20:32:52 -0500956 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 -0400957 pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
958 //Get CTSDuration_ba_f1
Andres More3eaca0d2013-02-25 20:32:52 -0500959 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 -0400960 pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
961 //Get CTS Frame body
962 pBuf->Data.wDurationID = pBuf->wDuration_ba;
963 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
964 pBuf->Data.wReserved = 0x0000;
Andres More9a0e7562010-04-13 21:54:48 -0300965 memcpy(&(pBuf->Data.abyRA[0]),
966 &(pDevice->abyCurrentNetAddr[0]),
967 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400968 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
969 PSCTS pBuf = (PSCTS)pvCTS;
970 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700971 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500972 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400973 );
974 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
975 //Get CTSDuration_ba
Andres More3eaca0d2013-02-25 20:32:52 -0500976 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 -0400977 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
978
979 //Get CTS Frame body
980 pBuf->Data.wDurationID = pBuf->wDuration_ba;
981 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
982 pBuf->Data.wReserved = 0x0000;
Andres More9a0e7562010-04-13 21:54:48 -0300983 memcpy(&(pBuf->Data.abyRA[0]),
984 &(pDevice->abyCurrentNetAddr[0]),
985 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400986 }
987 }
988}
989
Forest Bond92b96792009-06-13 07:38:31 -0400990/*+
991 *
992 * Description:
993 * Generate FIFO control for MAC & Baseband controller
994 *
995 * Parameters:
996 * In:
997 * pDevice - Pointer to adpater
998 * pTxDataHead - Transmit Data Buffer
999 * pTxBufHead - pTxBufHead
1000 * pvRrvTime - pvRrvTime
1001 * pvRTS - RTS Buffer
1002 * pCTS - CTS Buffer
1003 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
1004 * bNeedACK - If need ACK
1005 * uDMAIdx - DMA Index
1006 * Out:
1007 * none
1008 *
1009 * Return Value: none
1010 *
1011-*/
Andres Morecc856e62010-05-17 21:34:01 -03001012
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001013static void s_vGenerateTxParameter(struct vnt_private *pDevice,
1014 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
1015 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001016 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -04001017{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001018 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
1019 u16 wFifoCtl;
Andres Moree269fc22013-02-12 20:36:29 -05001020 int bDisCRC = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001021 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -04001022
1023 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
1024 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
1025 pFifoHead->wReserved = wCurrentRate;
1026 wFifoCtl = pFifoHead->wFIFOCtl;
1027
1028 if (wFifoCtl & FIFOCTL_CRCDIS) {
Andres More4e9b5e22013-02-12 20:36:30 -05001029 bDisCRC = true;
Forest Bond92b96792009-06-13 07:38:31 -04001030 }
1031
1032 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
1033 byFBOption = AUTO_FB_0;
1034 }
1035 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
1036 byFBOption = AUTO_FB_1;
1037 }
1038
1039 if (pDevice->bLongHeader)
1040 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1041
1042 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1043
1044 if (pvRTS != NULL) { //RTS_need
1045 //Fill RsvTime
1046 if (pvRrvTime) {
1047 PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -05001048 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
1049 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
1050 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1051 pBuf->wTxRrvTime_a = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1052 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 -04001053 }
1054 //Fill RTS
1055 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1056 }
1057 else {//RTS_needless, PCF mode
1058
1059 //Fill RsvTime
1060 if (pvRrvTime) {
1061 PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -05001062 pBuf->wTxRrvTime_a = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1063 pBuf->wTxRrvTime_b = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1064 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 -04001065 }
1066 //Fill CTS
1067 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
1068 }
1069 }
1070 else if (byPktType == PK_TYPE_11A) {
1071
1072 if (pvRTS != NULL) {//RTS_need, non PCF mode
1073 //Fill RsvTime
1074 if (pvRrvTime) {
1075 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -05001076 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
1077 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -04001078 }
1079 //Fill RTS
1080 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1081 }
1082 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
1083 //Fill RsvTime
1084 if (pvRrvTime) {
1085 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -05001086 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -04001087 }
1088 }
1089 }
1090 else if (byPktType == PK_TYPE_11B) {
1091
1092 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
1093 //Fill RsvTime
1094 if (pvRrvTime) {
1095 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -05001096 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1097 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
Forest Bond92b96792009-06-13 07:38:31 -04001098 }
1099 //Fill RTS
1100 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1101 }
1102 else { //RTS_needless, non PCF mode
1103 //Fill RsvTime
1104 if (pvRrvTime) {
1105 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -05001106 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
Forest Bond92b96792009-06-13 07:38:31 -04001107 }
1108 }
1109 }
1110 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
1111}
1112/*
Andres Moreb902fbf2013-02-25 20:32:51 -05001113 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -05001114 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -03001115 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -04001116*/
1117
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001118static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
1119 u8 *usbPacketBuf, int bNeedEncryption, u32 uSkbPacketLen, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001120 struct ethhdr *psEthHeader, u8 *pPacket, PSKeyItem pTransmitKey,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001121 u32 uNodeIndex, u16 wCurrentRate, u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -04001122{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001123 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1124 u32 cbFrameSize, cbFrameBodySize;
1125 PTX_BUFFER pTxBufHead;
1126 u32 cb802_1_H_len;
1127 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
1128 u32 cbFCSlen = 4, cbMICHDR = 0;
1129 int bNeedACK, bRTS;
1130 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
1131 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1132 u8 abySNAP_Bridgetunnel[ETH_ALEN]
1133 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1134 u32 uDuration;
1135 u32 cbHeaderLength = 0, uPadding = 0;
1136 void *pvRrvTime;
1137 PSMICHDRHead pMICHDR;
1138 void *pvRTS;
1139 void *pvCTS;
1140 void *pvTxDataHd;
1141 u8 byFBOption = AUTO_FB_NONE, byFragType;
1142 u16 wTxBufSize;
1143 u32 dwMICKey0, dwMICKey1, dwMIC_Priority, dwCRC;
1144 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001145 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -04001146
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001147 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001148
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001149 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001150 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1151 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001152 }
Forest Bond92b96792009-06-13 07:38:31 -04001153
1154 pTxBufHead = (PTX_BUFFER) usbPacketBuf;
Forest Bond92b96792009-06-13 07:38:31 -04001155
1156 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001157 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001158 if (pDevice->dwDiagRefCount == 0) {
1159 cb802_1_H_len = 8;
1160 } else {
1161 cb802_1_H_len = 2;
1162 }
1163 } else {
1164 cb802_1_H_len = 0;
1165 }
1166
Charles Clément21ec51f2010-05-18 10:08:14 -07001167 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001168
1169 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001170 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001171
1172 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001173 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001174 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1175 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001176 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1177 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001178 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001179 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001180 pTxBufHead->wFIFOCtl =
1181 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1182 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001183 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001184 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1185 }
Forest Bond92b96792009-06-13 07:38:31 -04001186 }
1187 else {
1188 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001189 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001190 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1191 }
1192 } //if (pDevice->dwDiagRefCount != 0) {
1193
1194 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1195
1196 //Set FIFOCTL_LHEAD
1197 if (pDevice->bLongHeader)
1198 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1199
1200 if (pDevice->bSoftwareGenCrcErr) {
1201 pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS; // set tx descriptors to NO hardware CRC
1202 }
1203
1204 //Set FRAGCTL_MACHDCNT
1205 if (pDevice->bLongHeader) {
1206 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1207 } else {
1208 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1209 }
Andres More3eaca0d2013-02-25 20:32:52 -05001210 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001211
1212 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001213 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001214 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1215 }
1216
1217 //Set Auto Fallback Ctl
1218 if (wCurrentRate >= RATE_18M) {
1219 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1220 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1221 byFBOption = AUTO_FB_0;
1222 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1223 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1224 byFBOption = AUTO_FB_1;
1225 }
1226 }
1227
Andres More4e9b5e22013-02-12 20:36:30 -05001228 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001229 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1230 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1231 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1232 }
1233 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1234 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1235 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1236 }
1237 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1238 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1239 }
1240 }
1241 }
1242
Forest Bond92b96792009-06-13 07:38:31 -04001243 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1244 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1245 cbIVlen = 4;
1246 cbICVlen = 4;
1247 }
1248 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1249 cbIVlen = 8;//IV+ExtIV
1250 cbMIClen = 8;
1251 cbICVlen = 4;
1252 }
1253 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1254 cbIVlen = 8;//RSN Header
1255 cbICVlen = 8;//MIC
1256 cbMICHDR = sizeof(SMICHDRHead);
1257 }
Andres Moree269fc22013-02-12 20:36:29 -05001258 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001259 //MAC Header should be padding 0 to DW alignment.
1260 uPadding = 4 - (cbMACHdLen%4);
1261 uPadding %= 4;
1262 }
1263 }
1264
1265 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1266
Andres Moree269fc22013-02-12 20:36:29 -05001267 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1268 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001269 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001270 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001271 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1272 }
1273
Andres Moreb902fbf2013-02-25 20:32:51 -05001274 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001275 wTxBufSize = sizeof(STxBufHead);
1276 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1277 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001278 if (bRTS == true) {//RTS_need
Forest Bond92b96792009-06-13 07:38:31 -04001279 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1280 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1281 pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1282 pvCTS = NULL;
1283 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g));
1284 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g) + sizeof(STxDataHead_g);
1285 }
1286 else { //RTS_needless
1287 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1288 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1289 pvRTS = NULL;
1290 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1291 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
1292 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
1293 }
1294 } else {
1295 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001296 if (bRTS == true) {//RTS_need
Forest Bond92b96792009-06-13 07:38:31 -04001297 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1298 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1299 pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1300 pvCTS = NULL;
1301 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
1302 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
1303 }
Andres Moree269fc22013-02-12 20:36:29 -05001304 else if (bRTS == false) { //RTS_needless
Forest Bond92b96792009-06-13 07:38:31 -04001305 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1306 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1307 pvRTS = NULL;
1308 pvCTS = (PSCTS_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1309 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB));
1310 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB) + sizeof(STxDataHead_g_FB);
1311 }
1312 } // Auto Fall Back
1313 }
1314 else {//802.11a/b packet
1315 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001316 if (bRTS == true) {//RTS_need
Forest Bond92b96792009-06-13 07:38:31 -04001317 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1318 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1319 pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1320 pvCTS = NULL;
1321 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
1322 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
1323 }
Andres Moree269fc22013-02-12 20:36:29 -05001324 else if (bRTS == false) { //RTS_needless, no MICHDR
Forest Bond92b96792009-06-13 07:38:31 -04001325 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1326 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1327 pvRTS = NULL;
1328 pvCTS = NULL;
1329 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1330 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
1331 }
1332 } else {
1333 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001334 if (bRTS == true) {//RTS_need
Forest Bond92b96792009-06-13 07:38:31 -04001335 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1336 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1337 pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1338 pvCTS = NULL;
1339 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
1340 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
1341 }
Andres Moree269fc22013-02-12 20:36:29 -05001342 else if (bRTS == false) { //RTS_needless
Forest Bond92b96792009-06-13 07:38:31 -04001343 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1344 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1345 pvRTS = NULL;
1346 pvCTS = NULL;
1347 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1348 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
1349 }
1350 } // Auto Fall Back
1351 }
1352
Andres Moreb902fbf2013-02-25 20:32:51 -05001353 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1354 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1355 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001356
Forest Bond92b96792009-06-13 07:38:31 -04001357 //=========================
1358 // No Fragmentation
1359 //=========================
1360 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1361 byFragType = FRAGCTL_NONFRAG;
1362 //uDMAIdx = TYPE_AC0DMA;
1363 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1364
Forest Bond92b96792009-06-13 07:38:31 -04001365 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001366 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1367 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001368 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1369 //Fill DataHead
1370 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
1371 0, 0, 1/*uMACfragNum*/, byFBOption);
1372 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001373 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001374 byFragType, uDMAIdx, 0);
1375
Andres More4e9b5e22013-02-12 20:36:30 -05001376 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001377 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001378 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001379 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001380
1381 if (pDevice->bEnableHostWEP) {
1382 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1383 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1384 }
1385 }
1386
1387 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001388 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001389 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001390 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1391 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001392 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001393 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001394 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001395 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001396 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001397 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001398 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001399 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001400 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001401
1402 }
1403
1404 }
1405
Forest Bond92b96792009-06-13 07:38:31 -04001406 if (pPacket != NULL) {
1407 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001408 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001409 (pPacket + ETH_HLEN),
1410 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001411 );
1412
1413 } else {
1414 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001415 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001416 }
1417
Andres More4e9b5e22013-02-12 20:36:30 -05001418 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001419
1420 ///////////////////////////////////////////////////////////////////
1421
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001422 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1423 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1424 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1425 }
Forest Bond92b96792009-06-13 07:38:31 -04001426 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001427 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1428 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001429 }
1430 else {
Andres More52a7e642013-02-25 20:32:53 -05001431 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1432 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001433 }
1434 // DO Software Michael
1435 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001436 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001437 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001438 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001439 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1440 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001441
1442 ///////////////////////////////////////////////////////////////////
1443
1444 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1445 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001446 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001447 //}
1448 //DBG_PRN_GRP12(("\n\n\n"));
1449
1450 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1451
Andres More52a7e642013-02-25 20:32:53 -05001452 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1453 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001454
1455 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1456 MIC_vUnInit();
1457
Andres More4e9b5e22013-02-12 20:36:30 -05001458 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001459 *pdwMIC_L = 0;
1460 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001461 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001462 }
1463 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1464 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1465 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1466 }
1467
Andres More4e9b5e22013-02-12 20:36:30 -05001468 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001469
Andres More3eaca0d2013-02-25 20:32:52 -05001470 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001471
Andres More4e9b5e22013-02-12 20:36:30 -05001472 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1473 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1474 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001475 cbFrameSize -= cbICVlen;
1476 }
1477
Andres More4e9b5e22013-02-12 20:36:30 -05001478 if (pDevice->bSoftwareGenCrcErr == true) {
Andres Morecc856e62010-05-17 21:34:01 -03001479 unsigned int cbLen;
Andres More52a7e642013-02-25 20:32:53 -05001480 u32 * pdwCRC;
Forest Bond92b96792009-06-13 07:38:31 -04001481
1482 dwCRC = 0xFFFFFFFFL;
1483 cbLen = cbFrameSize - cbFCSlen;
1484 // calculate CRC, and wrtie CRC value to end of TD
1485 dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
Andres More52a7e642013-02-25 20:32:53 -05001486 pdwCRC = (u32 *)(pbyMacHdr + cbLen);
Forest Bond92b96792009-06-13 07:38:31 -04001487 // finally, we must invert dwCRC to get the correct answer
1488 *pdwCRC = ~dwCRC;
1489 // Force Error
1490 *pdwCRC -= 1;
1491 } else {
1492 cbFrameSize -= cbFCSlen;
1493 }
1494
1495 *pcbHeaderLen = cbHeaderLength;
1496 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1497
Forest Bond92b96792009-06-13 07:38:31 -04001498 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001499 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001500
Andres More4e9b5e22013-02-12 20:36:30 -05001501 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001502
1503}
1504
Forest Bond92b96792009-06-13 07:38:31 -04001505/*+
1506 *
1507 * Description:
1508 * Translate 802.3 to 802.11 header
1509 *
1510 * Parameters:
1511 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001512 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001513 * dwTxBufferAddr - Transmit Buffer
1514 * pPacket - Packet from upper layer
1515 * cbPacketSize - Transmit Data Length
1516 * Out:
1517 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1518 * pcbAppendPayload - size of append payload for 802.1H translation
1519 *
1520 * Return Value: none
1521 *
1522-*/
1523
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001524static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001525 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001526 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001527{
Andres More1cac4a42013-03-18 20:33:50 -05001528 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001529
Forest Bond92b96792009-06-13 07:38:31 -04001530 if (uDMAIdx == TYPE_ATIMDMA) {
Andres More1cac4a42013-03-18 20:33:50 -05001531 pMACHeader->frame_control = TYPE_802_11_ATIM;
Forest Bond92b96792009-06-13 07:38:31 -04001532 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001533 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001534 }
1535
1536 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001537 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001538 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001539 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001540 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1541 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001542 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001543 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001544 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001545 } else {
1546 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001547 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001548 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001549 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001550 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001551 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001552 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001553 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001554 &(pDevice->abyBSSID[0]),
1555 ETH_ALEN);
1556 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001557 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001558 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001559 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001560 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001561 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001562 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001563 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001564 &(pDevice->abyBSSID[0]),
1565 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001566 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001567 }
1568 }
1569
1570 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001571 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001572
Andres More1cac4a42013-03-18 20:33:50 -05001573 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001574
1575 if (pDevice->bLongHeader) {
1576 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001577 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001578 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001579 }
Andres More1cac4a42013-03-18 20:33:50 -05001580 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001581
1582 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001583 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001584
1585 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1586 pDevice->wSeqCounter++;
1587 if (pDevice->wSeqCounter > 0x0fff)
1588 pDevice->wSeqCounter = 0;
1589 }
1590
1591 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001592 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001593 }
1594}
1595
Forest Bond92b96792009-06-13 07:38:31 -04001596/*+
1597 *
1598 * Description:
1599 * Request instructs a MAC to transmit a 802.11 management packet through
1600 * the adapter onto the medium.
1601 *
1602 * Parameters:
1603 * In:
1604 * hDeviceContext - Pointer to the adapter
1605 * pPacket - A pointer to a descriptor for the packet to transmit
1606 * Out:
1607 * none
1608 *
Andres Moree269fc22013-02-12 20:36:29 -05001609 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001610 *
1611-*/
1612
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001613CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1614 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001615{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001616 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1617 PTX_BUFFER pTX_Buffer;
1618 PSTxBufHead pTxBufHead;
1619 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001620 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001621 PSCTS pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001622 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001623 u8 byPktType, *pbyTxBufferAddr;
1624 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1625 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001626 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001627 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1628 u32 uPadding = 0;
1629 u16 wTxBufSize;
1630 u32 cbMacHdLen;
1631 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001632
Forest Bond92b96792009-06-13 07:38:31 -04001633 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1634
1635 if (NULL == pContext) {
1636 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1637 return CMD_STATUS_RESOURCES;
1638 }
1639
1640 pTX_Buffer = (PTX_BUFFER) (&pContext->Data[0]);
Andres Moreb902fbf2013-02-25 20:32:51 -05001641 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001642 cbFrameBodySize = pPacket->cbPayloadLen;
1643 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1644 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001645
1646 if (pDevice->byBBType == BB_TYPE_11A) {
1647 wCurrentRate = RATE_6M;
1648 byPktType = PK_TYPE_11A;
1649 } else {
1650 wCurrentRate = RATE_1M;
1651 byPktType = PK_TYPE_11B;
1652 }
1653
1654 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1655 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1656 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1657 // to set power here.
1658 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1659 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1660 } else {
1661 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1662 }
1663 pDevice->wCurrentRate = wCurrentRate;
1664
Forest Bond92b96792009-06-13 07:38:31 -04001665 //Set packet type
1666 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1667 pTxBufHead->wFIFOCtl = 0;
1668 }
1669 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1670 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1671 }
1672 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1673 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1674 }
1675 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1676 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1677 }
1678
1679 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1680 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1681
Andres More22040bb2010-08-02 20:21:44 -03001682 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001683 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001684 }
1685 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001686 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001687 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1688 };
1689
1690 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1691 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1692
1693 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1694 //Set Preamble type always long
1695 //pDevice->byPreambleType = PREAMBLE_LONG;
1696 // probe-response don't retry
1697 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001698 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001699 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1700 //}
1701 }
1702
1703 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1704
1705 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001706 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001707 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1708 } else {
1709 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1710 }
1711
1712 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001713 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001714
1715 // Notes:
1716 // Although spec says MMPDU can be fragmented; In most case,
1717 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001718 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001719
1720 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1721 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1722 cbIVlen = 4;
1723 cbICVlen = 4;
1724 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1725 }
1726 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1727 cbIVlen = 8;//IV+ExtIV
1728 cbMIClen = 8;
1729 cbICVlen = 4;
1730 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1731 //We need to get seed here for filling TxKey entry.
1732 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1733 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1734 }
1735 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1736 cbIVlen = 8;//RSN Header
1737 cbICVlen = 8;//MIC
1738 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001739 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001740 }
1741 //MAC Header should be padding 0 to DW alignment.
1742 uPadding = 4 - (cbMacHdLen%4);
1743 uPadding %= 4;
1744 }
1745
1746 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1747
1748 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001749 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001750 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1751 }
1752 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1753
1754 //Set RrvTime/RTS/CTS Buffer
1755 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1756
1757 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1758 pMICHDR = NULL;
1759 pvRTS = NULL;
1760 pCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1761 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS));
1762 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS) + sizeof(STxDataHead_g);
1763 }
1764 else { // 802.11a/b packet
1765 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1766 pMICHDR = NULL;
1767 pvRTS = NULL;
1768 pCTS = NULL;
1769 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1770 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
1771 }
1772
Andres Moreceb8c5d2013-03-18 20:33:49 -05001773 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001774 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1775 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001776 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001777 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1778 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001779 //=========================
1780 // No Fragmentation
1781 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001782 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001783
Forest Bond92b96792009-06-13 07:38:31 -04001784 //Fill FIFO,RrvTime,RTS,and CTS
1785 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1786 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1787
1788 //Fill DataHead
1789 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
1790 0, 0, 1, AUTO_FB_NONE);
1791
Andres More1cac4a42013-03-18 20:33:50 -05001792 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001793
1794 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1795
1796 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001797 u8 * pbyIVHead;
1798 u8 * pbyPayloadHead;
1799 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001800 PSKeyItem pTransmitKey = NULL;
1801
Andres Moreb902fbf2013-02-25 20:32:51 -05001802 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1803 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001804 do {
1805 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001806 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001807 pbyBSSID = pDevice->abyBSSID;
1808 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001809 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001810 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001811 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001812 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1813 break;
1814 }
1815 } else {
1816 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1817 break;
1818 }
1819 }
1820 // get group key
1821 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001822 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001823 pTransmitKey = NULL;
1824 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1825 } else {
1826 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1827 }
Andres Moree269fc22013-02-12 20:36:29 -05001828 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001829 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001830 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001831 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001832
Jim Lieb3e362592009-08-12 14:54:11 -07001833 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001834 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001835 cbFrameBodySize);
1836 }
1837 else {
1838 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001839 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001840 }
1841
Andres More1cac4a42013-03-18 20:33:50 -05001842 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001843 pDevice->wSeqCounter++ ;
1844 if (pDevice->wSeqCounter > 0x0fff)
1845 pDevice->wSeqCounter = 0;
1846
1847 if (bIsPSPOLL) {
1848 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001849 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001850 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1851 // in the same place of other packet's Duration-field).
1852 // And it will cause Cisco-AP to issue Disassociation-packet
1853 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1854 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1855 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1856 } else {
1857 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1858 }
1859 }
1860
Andres More3eaca0d2013-02-25 20:32:52 -05001861 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001862 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001863 pTX_Buffer->byType = 0x00;
1864
1865 pContext->pPacket = NULL;
1866 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001867 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001868
Andres More1cac4a42013-03-18 20:33:50 -05001869 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1870 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001871 }
1872 else {
Andres More1cac4a42013-03-18 20:33:50 -05001873 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001874 }
1875
1876 PIPEnsSendBulkOut(pDevice,pContext);
1877 return CMD_STATUS_PENDING;
1878}
1879
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001880CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1881 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001882{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001883 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1884 u32 cbHeaderSize = 0;
1885 u16 wTxBufSize = sizeof(STxShortBufHead);
1886 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001887 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001888 PSTxDataHead_ab pTxDataHead;
1889 u16 wCurrentRate;
1890 u32 cbFrameBodySize;
1891 u32 cbReqCount;
1892 PBEACON_BUFFER pTX_Buffer;
1893 u8 *pbyTxBufferAddr;
1894 PUSB_SEND_CONTEXT pContext;
1895 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001896
Forest Bond92b96792009-06-13 07:38:31 -04001897 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1898 if (NULL == pContext) {
1899 status = CMD_STATUS_RESOURCES;
1900 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1901 return status ;
1902 }
1903 pTX_Buffer = (PBEACON_BUFFER) (&pContext->Data[0]);
Andres Moreb902fbf2013-02-25 20:32:51 -05001904 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001905
1906 cbFrameBodySize = pPacket->cbPayloadLen;
1907
1908 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1909 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001910
1911 if (pDevice->byBBType == BB_TYPE_11A) {
1912 wCurrentRate = RATE_6M;
1913 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
1914 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001915 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
Andres More3eaca0d2013-02-25 20:32:52 -05001916 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001917 );
1918 //Get Duration and TimeStampOff
Andres More3eaca0d2013-02-25 20:32:52 -05001919 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, PK_TYPE_11A,
Andres Moree269fc22013-02-12 20:36:29 -05001920 wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
Forest Bond92b96792009-06-13 07:38:31 -04001921 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
1922 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
1923 } else {
1924 wCurrentRate = RATE_1M;
1925 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1926 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
1927 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001928 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -05001929 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001930 );
1931 //Get Duration and TimeStampOff
Andres More3eaca0d2013-02-25 20:32:52 -05001932 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, PK_TYPE_11B,
Andres Moree269fc22013-02-12 20:36:29 -05001933 wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
Forest Bond92b96792009-06-13 07:38:31 -04001934 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
1935 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
1936 }
1937
1938 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001939 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001940 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001941
Andres More1cac4a42013-03-18 20:33:50 -05001942 pMACHeader->duration_id = 0;
1943 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001944 pDevice->wSeqCounter++ ;
1945 if (pDevice->wSeqCounter > 0x0fff)
1946 pDevice->wSeqCounter = 0;
1947
1948 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1949
Andres More3eaca0d2013-02-25 20:32:52 -05001950 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001951 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001952 pTX_Buffer->byType = 0x01;
1953
1954 pContext->pPacket = NULL;
1955 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001956 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001957
1958 PIPEnsSendBulkOut(pDevice,pContext);
1959 return CMD_STATUS_PENDING;
1960
1961}
1962
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001963void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1964{
1965 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1966 u8 byPktType;
1967 u8 *pbyTxBufferAddr;
1968 void *pvRTS, *pvCTS, *pvTxDataHd;
1969 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001970 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001971 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001972 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001973 PSTxBufHead pTxBufHead;
1974 u32 cbFrameSize;
1975 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1976 u32 uPadding = 0;
1977 u32 cbMICHDR = 0, uLength = 0;
1978 u32 dwMICKey0, dwMICKey1;
1979 u32 dwMIC_Priority;
1980 u32 *pdwMIC_L, *pdwMIC_R;
1981 u16 wTxBufSize;
1982 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001983 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001984 void *pvRrvTime, *pMICHDR;
1985 u32 wCurrentRate = RATE_1M;
1986 PUWLAN_80211HDR p80211Header;
1987 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001988 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001989 SKeyItem STempKey;
1990 PSKeyItem pTransmitKey = NULL;
1991 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1992 u32 cbExtSuppRate = 0;
1993 PTX_BUFFER pTX_Buffer;
1994 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001995
Forest Bond92b96792009-06-13 07:38:31 -04001996 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1997
1998 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1999 cbFrameBodySize = 0;
2000 }
2001 else {
2002 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
2003 }
2004 p80211Header = (PUWLAN_80211HDR)skb->data;
2005
2006 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2007
2008 if (NULL == pContext) {
2009 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
2010 dev_kfree_skb_irq(skb);
2011 return ;
2012 }
2013
2014 pTX_Buffer = (PTX_BUFFER)(&pContext->Data[0]);
Andres Moreb902fbf2013-02-25 20:32:51 -05002015 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04002016 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2017 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04002018
2019 if (pDevice->byBBType == BB_TYPE_11A) {
2020 wCurrentRate = RATE_6M;
2021 byPktType = PK_TYPE_11A;
2022 } else {
2023 wCurrentRate = RATE_1M;
2024 byPktType = PK_TYPE_11B;
2025 }
2026
2027 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2028 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2029 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2030 // to set power here.
2031 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
2032 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2033 } else {
2034 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2035 }
2036
2037 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
2038
2039 //Set packet type
2040 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2041 pTxBufHead->wFIFOCtl = 0;
2042 }
2043 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2044 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2045 }
2046 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2047 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2048 }
2049 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2050 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2051 }
2052
2053 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2054 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2055
Andres More22040bb2010-08-02 20:21:44 -03002056 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05002057 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04002058 if (pDevice->bEnableHostWEP) {
2059 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002060 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07002061 }
Forest Bond92b96792009-06-13 07:38:31 -04002062 }
2063 else {
2064 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05002065 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05002066 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07002067 }
Andres More4e9b5e22013-02-12 20:36:30 -05002068 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002069 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2070 };
2071
2072 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2073 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2074
2075 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2076 //Set Preamble type always long
2077 //pDevice->byPreambleType = PREAMBLE_LONG;
2078
2079 // probe-response don't retry
2080 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05002081 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04002082 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2083 //}
2084 }
2085
2086 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2087
2088 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05002089 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04002090 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2091 } else {
2092 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2093 }
2094
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002095 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04002096 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2097
2098 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
2099 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2100 }
2101
2102 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
2103 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2104 }
2105
2106 if (cbExtSuppRate >0) {
2107 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2108 }
2109 }
2110
Forest Bond92b96792009-06-13 07:38:31 -04002111 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05002112 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04002113
2114 // Notes:
2115 // Although spec says MMPDU can be fragmented; In most case,
2116 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05002117 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04002118
Forest Bond92b96792009-06-13 07:38:31 -04002119 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2120 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2121 cbIVlen = 4;
2122 cbICVlen = 4;
2123 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2124 }
2125 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2126 cbIVlen = 8;//IV+ExtIV
2127 cbMIClen = 8;
2128 cbICVlen = 4;
2129 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2130 //We need to get seed here for filling TxKey entry.
2131 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2132 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2133 }
2134 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2135 cbIVlen = 8;//RSN Header
2136 cbICVlen = 8;//MIC
2137 cbMICHDR = sizeof(SMICHDRHead);
2138 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002139 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002140 }
2141 //MAC Header should be padding 0 to DW alignment.
2142 uPadding = 4 - (cbMacHdLen%4);
2143 uPadding %= 4;
2144 }
2145
2146 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2147
2148 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002149 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002150 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2151 }
2152 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2153
Forest Bond92b96792009-06-13 07:38:31 -04002154 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
2155
2156 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2157 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2158 pvRTS = NULL;
2159 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
2160 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
2161 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
2162
2163 }
2164 else {//802.11a/b packet
2165
2166 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2167 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2168 pvRTS = NULL;
2169 pvCTS = NULL;
2170 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
2171 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
2172 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002173 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002174 &(p80211Header->sA3.abyAddr1[0]),
2175 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002176 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002177 &(p80211Header->sA3.abyAddr2[0]),
2178 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002179 //=========================
2180 // No Fragmentation
2181 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002182 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002183
Forest Bond92b96792009-06-13 07:38:31 -04002184 //Fill FIFO,RrvTime,RTS,and CTS
2185 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2186 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2187
2188 //Fill DataHead
2189 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2190 0, 0, 1, AUTO_FB_NONE);
2191
Andres More1cac4a42013-03-18 20:33:50 -05002192 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002193
2194 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2195
Andres Moreb902fbf2013-02-25 20:32:51 -05002196 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2197 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2198 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002199
2200 // Copy the Packet into a tx Buffer
2201 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2202
2203 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002204 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002205 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2206
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002207 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002208 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2209 if (cbExtSuppRate != 0) {
2210 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2211 memcpy((pbyPayloadHead + cbFrameBodySize),
2212 pMgmt->abyCurrSuppRates,
2213 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2214 );
2215 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2216 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2217 pMgmt->abyCurrExtSuppRates,
2218 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2219 );
2220 }
2221 }
2222
2223 // Set wep
2224 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2225
2226 if (pDevice->bEnableHostWEP) {
2227 pTransmitKey = &STempKey;
2228 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2229 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2230 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2231 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2232 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2233 memcpy(pTransmitKey->abyKey,
2234 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2235 pTransmitKey->uKeyLength
2236 );
2237 }
2238
2239 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2240
Andres More52a7e642013-02-25 20:32:53 -05002241 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2242 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002243
2244 // DO Software Michael
2245 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002246 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002247 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002248 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002249 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2250 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002251
2252 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2253
2254 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2255
Andres More52a7e642013-02-25 20:32:53 -05002256 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2257 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002258
2259 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2260 MIC_vUnInit();
2261
Andres More4e9b5e22013-02-12 20:36:30 -05002262 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002263 *pdwMIC_L = 0;
2264 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002265 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002266 }
2267
2268 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2269 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002270 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2271 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002272
2273 }
2274
Andres Moreb902fbf2013-02-25 20:32:51 -05002275 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05002276 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002277
2278 if (pDevice->bEnableHostWEP) {
2279 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2280 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2281 }
2282
2283 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002284 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002285 }
2286 }
2287
Andres More1cac4a42013-03-18 20:33:50 -05002288 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002289 pDevice->wSeqCounter++ ;
2290 if (pDevice->wSeqCounter > 0x0fff)
2291 pDevice->wSeqCounter = 0;
2292
Forest Bond92b96792009-06-13 07:38:31 -04002293 if (bIsPSPOLL) {
2294 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2295 // of FIFO control header.
2296 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2297 // in the same place of other packet's Duration-field).
2298 // And it will cause Cisco-AP to issue Disassociation-packet
2299 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2300 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
2301 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
2302 } else {
2303 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
2304 }
2305 }
2306
Andres More3eaca0d2013-02-25 20:32:52 -05002307 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002308 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002309 pTX_Buffer->byType = 0x00;
2310
2311 pContext->pPacket = skb;
2312 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002313 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002314
Andres More1cac4a42013-03-18 20:33:50 -05002315 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2316 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002317 }
2318 else {
Andres More1cac4a42013-03-18 20:33:50 -05002319 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002320 }
2321 PIPEnsSendBulkOut(pDevice,pContext);
2322 return ;
2323
2324}
2325
Forest Bond92b96792009-06-13 07:38:31 -04002326//TYPE_AC0DMA data tx
2327/*
2328 * Description:
2329 * Tx packet via AC0DMA(DMA1)
2330 *
2331 * Parameters:
2332 * In:
2333 * pDevice - Pointer to the adapter
2334 * skb - Pointer to tx skb packet
2335 * Out:
2336 * void
2337 *
2338 * Return Value: NULL
2339 */
2340
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002341int nsDMA_tx_packet(struct vnt_private *pDevice,
2342 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002343{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002344 struct net_device_stats *pStats = &pDevice->stats;
2345 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2346 u32 BytesToWrite = 0, uHeaderLen = 0;
2347 u32 uNodeIndex = 0;
2348 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2349 u16 wAID;
2350 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002351 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002352 PSKeyItem pTransmitKey = NULL;
2353 SKeyItem STempKey;
2354 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002355 int bTKIP_UseGTK = false;
2356 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002357 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002358 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002359 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002360 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002361 PTX_BUFFER pTX_Buffer;
2362 u32 status;
2363 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002364 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002365
Forest Bond92b96792009-06-13 07:38:31 -04002366 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2367
2368 if (pDevice->uAssocCount == 0) {
2369 dev_kfree_skb_irq(skb);
2370 return 0;
2371 }
2372
Andres Moreb902fbf2013-02-25 20:32:51 -05002373 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002374 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002375 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002376 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2377
2378 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2379 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2380 // set tx map
2381 pMgmt->abyPSTxMap[0] |= byMask[0];
2382 return 0;
2383 }
Masanari Iida93184692012-08-13 21:21:50 +09002384 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002385
2386 if (pDevice->byBBType != BB_TYPE_11A)
2387 pDevice->wCurrentRate = RATE_2M;
2388 else
2389 pDevice->wCurrentRate = RATE_24M;
2390 // long preamble type
2391 pDevice->byPreambleType = PREAMBLE_SHORT;
2392
2393 }else {
2394
Andres Moreb902fbf2013-02-25 20:32:51 -05002395 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002396
2397 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2398
2399 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2400
2401 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2402 // set tx map
2403 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2404 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2406 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2407
2408 return 0;
2409 }
2410 // AP rate decided from node
2411 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2412 // tx preamble decided from node
2413
2414 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2415 pDevice->byPreambleType = pDevice->byShortPreamble;
2416
2417 }else {
2418 pDevice->byPreambleType = PREAMBLE_LONG;
2419 }
Andres More4e9b5e22013-02-12 20:36:30 -05002420 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002421 }
2422 }
2423
Andres Moree269fc22013-02-12 20:36:29 -05002424 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002425 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2426 dev_kfree_skb_irq(skb);
2427 return 0;
2428 }
2429 }
2430
2431 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2432
2433 if (pContext == NULL) {
2434 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2435 dev_kfree_skb_irq(skb);
2436 return STATUS_RESOURCES;
2437 }
2438
Andres Moreceb8c5d2013-03-18 20:33:49 -05002439 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002440
2441//mike add:station mode check eapol-key challenge--->
2442{
Andres Moreb902fbf2013-02-25 20:32:51 -05002443 u8 Protocol_Version; //802.1x Authentication
2444 u8 Packet_Type; //802.1x Authentication
2445 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002446 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002447
Charles Clément21ec51f2010-05-18 10:08:14 -07002448 Protocol_Version = skb->data[ETH_HLEN];
2449 Packet_Type = skb->data[ETH_HLEN+1];
2450 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2451 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 -05002452 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002453 /* 802.1x OR eapol-key challenge frame transfer */
2454 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2455 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002456 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002457 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2458 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2459 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002460 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002461 PRINT_K("WPA ");
2462 }
2463 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002464 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002465 PRINT_K("WPA2(re-keying) ");
2466 }
2467 PRINT_K("Authentication completed!!\n");
2468 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002469 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002470 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002471 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002472 PRINT_K("WPA2 Authentication completed!!\n");
2473 }
2474 }
2475 }
2476}
2477//mike add:station mode check eapol-key challenge<---
2478
Andres More4e9b5e22013-02-12 20:36:30 -05002479 if (pDevice->bEncryptionEnable == true) {
2480 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002481 // get Transmit key
2482 do {
2483 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2484 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2485 pbyBSSID = pDevice->abyBSSID;
2486 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002487 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002488 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002489 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2490 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002491 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2492 break;
2493 }
2494 } else {
2495 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2496 break;
2497 }
2498 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002499 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2500 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002501 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2502 for (ii = 0; ii< 6; ii++)
2503 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2504 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2505
2506 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002507 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002508 break;
2509 }
2510 // get group key
2511 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002512 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002513 pTransmitKey = NULL;
2514 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2515 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2516 }
2517 else
2518 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2519 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002520 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002521 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2522 }
Andres Moree269fc22013-02-12 20:36:29 -05002523 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002524 }
2525
2526 if (pDevice->bEnableHostWEP) {
2527 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002528 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002529 pTransmitKey = &STempKey;
2530 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2531 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2532 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2533 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2534 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2535 memcpy(pTransmitKey->abyKey,
2536 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2537 pTransmitKey->uKeyLength
2538 );
2539 }
2540 }
2541
Andres Moreb902fbf2013-02-25 20:32:51 -05002542 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002543
2544 if (pDevice->bFixRate) {
2545 if (pDevice->byBBType == BB_TYPE_11B) {
2546 if (pDevice->uConnectionRate >= RATE_11M) {
2547 pDevice->wCurrentRate = RATE_11M;
2548 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002549 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002550 }
2551 } else {
2552 if ((pDevice->byBBType == BB_TYPE_11A) &&
2553 (pDevice->uConnectionRate <= RATE_6M)) {
2554 pDevice->wCurrentRate = RATE_6M;
2555 } else {
2556 if (pDevice->uConnectionRate >= RATE_54M)
2557 pDevice->wCurrentRate = RATE_54M;
2558 else
Andres More3eaca0d2013-02-25 20:32:52 -05002559 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002560 }
2561 }
2562 }
2563 else {
2564 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2565 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002566 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002567 // Multicast use highest data rate
2568 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2569 // preamble type
2570 pDevice->byPreambleType = pDevice->byShortPreamble;
2571 }
2572 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002573 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002574 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2575 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2576 pDevice->byPreambleType = pDevice->byShortPreamble;
2577
2578 }
2579 else {
2580 pDevice->byPreambleType = PREAMBLE_LONG;
2581 }
2582 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2583 }
2584 else {
2585 if (pDevice->byBBType != BB_TYPE_11A)
2586 pDevice->wCurrentRate = RATE_2M;
2587 else
2588 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2589 // abyCurrExtSuppRates[]
2590 pDevice->byPreambleType = PREAMBLE_SHORT;
2591 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2592 }
2593 }
2594 }
2595 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2596 // Infra STA rate decided from AP Node, index = 0
2597 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2598 }
2599 }
2600
Andres Moreceb8c5d2013-03-18 20:33:49 -05002601 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002602 if (pDevice->byBBType != BB_TYPE_11A) {
2603 pDevice->wCurrentRate = RATE_1M;
2604 pDevice->byACKRate = RATE_1M;
2605 pDevice->byTopCCKBasicRate = RATE_1M;
2606 pDevice->byTopOFDMBasicRate = RATE_6M;
2607 } else {
2608 pDevice->wCurrentRate = RATE_6M;
2609 pDevice->byACKRate = RATE_6M;
2610 pDevice->byTopCCKBasicRate = RATE_1M;
2611 pDevice->byTopOFDMBasicRate = RATE_6M;
2612 }
2613 }
Forest Bond92b96792009-06-13 07:38:31 -04002614
Andres More0cbd8d92010-05-06 20:34:29 -03002615 DBG_PRT(MSG_LEVEL_DEBUG,
2616 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2617 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002618
2619 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002620 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002621 }
2622
2623 if (pDevice->wCurrentRate <= RATE_11M) {
2624 byPktType = PK_TYPE_11B;
2625 }
2626
Andres More4e9b5e22013-02-12 20:36:30 -05002627 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002628 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2629 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002630 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002631 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002632 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2633 if (pTransmitKey == NULL) {
2634 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2635 }
2636 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002637 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002638 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2639 }
2640 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002641 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2642 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002643 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002644 }
2645 }
2646 }
2647
Forest Bond92b96792009-06-13 07:38:31 -04002648 if (pDevice->bEnableHostWEP) {
2649 if ((uNodeIndex != 0) &&
2650 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002651 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2652 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002653 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002654 }
2655 }
2656 }
2657 else {
2658
Forest Bond92b96792009-06-13 07:38:31 -04002659 if (pTransmitKey == NULL) {
2660 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002661 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002662 dev_kfree_skb_irq(skb);
2663 pStats->tx_dropped++;
2664 return STATUS_FAILURE;
2665 }
Forest Bond92b96792009-06-13 07:38:31 -04002666 }
2667 }
2668
2669 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Andres Moreb902fbf2013-02-25 20:32:51 -05002670 (u8 *)(&pContext->Data[0]), bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002671 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002672 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002673 pDevice->wCurrentRate,
2674 &uHeaderLen, &BytesToWrite
2675 );
2676
Andres Moree269fc22013-02-12 20:36:29 -05002677 if (fConvertedPacket == false) {
2678 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002679 dev_kfree_skb_irq(skb);
2680 return STATUS_FAILURE;
2681 }
2682
Andres More4e9b5e22013-02-12 20:36:30 -05002683 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002684 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002685 bScheduleCommand((void *) pDevice,
2686 WLAN_CMD_MAC_DISPOWERSAVING,
2687 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002688 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002689 }
2690 }
2691
2692 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
Andres Moreb902fbf2013-02-25 20:32:51 -05002693 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002694 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002695
2696 pContext->pPacket = skb;
2697 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002698 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002699
Andres Moreceb8c5d2013-03-18 20:33:49 -05002700 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 -04002701
2702 status = PIPEnsSendBulkOut(pDevice,pContext);
2703
Andres More4e9b5e22013-02-12 20:36:30 -05002704 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002705 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002706
Andres Moreb902fbf2013-02-25 20:32:51 -05002707 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002708 }
2709
2710 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002711 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002712 dev_kfree_skb_irq(skb);
2713 return STATUS_FAILURE;
2714 }
2715 else
2716 return 0;
2717
2718}
2719
Forest Bond92b96792009-06-13 07:38:31 -04002720/*
2721 * Description:
2722 * Relay packet send (AC1DMA) from rx dpc.
2723 *
2724 * Parameters:
2725 * In:
2726 * pDevice - Pointer to the adapter
2727 * pPacket - Pointer to rx packet
2728 * cbPacketSize - rx ethernet frame size
2729 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002730 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002731 *
Andres More4e9b5e22013-02-12 20:36:30 -05002732 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002733 */
2734
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002735int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2736 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002737{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002738 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2739 u32 BytesToWrite = 0, uHeaderLen = 0;
2740 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002741 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002742 SKeyItem STempKey;
2743 PSKeyItem pTransmitKey = NULL;
2744 u8 *pbyBSSID;
2745 PUSB_SEND_CONTEXT pContext;
2746 u8 byPktTyp;
2747 int fConvertedPacket;
2748 PTX_BUFFER pTX_Buffer;
2749 u32 status;
2750 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002751
Forest Bond92b96792009-06-13 07:38:31 -04002752 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2753
2754 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002755 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002756 }
2757
Andres Moreceb8c5d2013-03-18 20:33:49 -05002758 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002759
Andres More4e9b5e22013-02-12 20:36:30 -05002760 if (pDevice->bEncryptionEnable == true) {
2761 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002762 // get group key
2763 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002764 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002765 pTransmitKey = NULL;
2766 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2767 } else {
2768 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2769 }
2770 }
2771
2772 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002773 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002774 pTransmitKey = &STempKey;
2775 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2776 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2777 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2778 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2779 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2780 memcpy(pTransmitKey->abyKey,
2781 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2782 pTransmitKey->uKeyLength
2783 );
2784 }
2785 }
2786
2787 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002788 pContext->bBoolInUse = false;
2789 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002790 }
2791
Andres Moreb902fbf2013-02-25 20:32:51 -05002792 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002793
2794 if (pDevice->bFixRate) {
2795 if (pDevice->byBBType == BB_TYPE_11B) {
2796 if (pDevice->uConnectionRate >= RATE_11M) {
2797 pDevice->wCurrentRate = RATE_11M;
2798 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002799 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002800 }
2801 } else {
2802 if ((pDevice->byBBType == BB_TYPE_11A) &&
2803 (pDevice->uConnectionRate <= RATE_6M)) {
2804 pDevice->wCurrentRate = RATE_6M;
2805 } else {
2806 if (pDevice->uConnectionRate >= RATE_54M)
2807 pDevice->wCurrentRate = RATE_54M;
2808 else
Andres More3eaca0d2013-02-25 20:32:52 -05002809 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002810 }
2811 }
2812 }
2813 else {
2814 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2815 }
2816
Forest Bond92b96792009-06-13 07:38:31 -04002817 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002818 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002819 }
2820
2821 if (pDevice->wCurrentRate <= RATE_11M)
2822 byPktType = PK_TYPE_11B;
2823
Andres Moreabad19d2010-07-12 16:28:32 -03002824 BytesToWrite = uDataLen + ETH_FCS_LEN;
2825
Forest Bond92b96792009-06-13 07:38:31 -04002826 // Convert the packet to an usb frame and copy into our buffer
2827 // and send the irp.
2828
2829 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Andres Moreb902fbf2013-02-25 20:32:51 -05002830 (u8 *)(&pContext->Data[0]), bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002831 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2832 pbySkbData, pTransmitKey, uNodeIndex,
2833 pDevice->wCurrentRate,
2834 &uHeaderLen, &BytesToWrite
2835 );
2836
Andres Moree269fc22013-02-12 20:36:29 -05002837 if (fConvertedPacket == false) {
2838 pContext->bBoolInUse = false;
2839 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002840 }
2841
2842 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
Andres Moreb902fbf2013-02-25 20:32:51 -05002843 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002844 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002845
2846 pContext->pPacket = NULL;
2847 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002848 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002849
Andres Moreceb8c5d2013-03-18 20:33:49 -05002850 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 -04002851
2852 status = PIPEnsSendBulkOut(pDevice,pContext);
2853
Andres More4e9b5e22013-02-12 20:36:30 -05002854 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002855}
2856