blob: 4f36ec89ff4207765b31fc4025aff24167668d28 [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020034 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040035 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020038 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040039 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
44 *
45 * Revision History:
46 *
47 */
48
Forest Bond92b96792009-06-13 07:38:31 -040049#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "tether.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070064
Mariano Reingart4a499de2010-10-29 19:15:26 -030065static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040066
Andres More3eaca0d2013-02-25 20:32:52 -050067const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040068 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
69 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
70 };
71
Andres More3eaca0d2013-02-25 20:32:52 -050072const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040073 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
74 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
75 };
Andres More3eaca0d2013-02-25 20:32:52 -050076const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040077 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
78 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
79 };
80
Forest Bond92b96792009-06-13 07:38:31 -040081#define RTSDUR_BB 0
82#define RTSDUR_BA 1
83#define RTSDUR_AA 2
84#define CTSDUR_BA 3
85#define RTSDUR_BA_F0 4
86#define RTSDUR_AA_F0 5
87#define RTSDUR_BA_F1 6
88#define RTSDUR_AA_F1 7
89#define CTSDUR_BA_F0 8
90#define CTSDUR_BA_F1 9
91#define DATADUR_B 10
92#define DATADUR_A 11
93#define DATADUR_A_F0 12
94#define DATADUR_A_F1 13
95
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000096static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
97 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000099static void *s_vGetFreeContext(struct vnt_private *pDevice);
100
101static void s_vGenerateTxParameter(struct vnt_private *pDevice,
102 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
103 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500104 struct ethhdr *psEthHeader);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000105
106static u32 s_uFillDataHead(struct vnt_private *pDevice,
107 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100108 u32 uDMAIdx, int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400109
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000110static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500111 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000112 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400113
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000114static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
115 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
116 u8 *pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000118static void s_vSWencryption(struct vnt_private *pDevice,
119 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400120
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000121static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
122 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100124static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000125 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400126
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000127static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
128 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
129 int bDisCRC, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400130
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000131static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
132 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500133 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400134
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100135static u16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100136 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400137
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100138static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000139 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
140 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400141
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000142static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400143{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000144 PUSB_SEND_CONTEXT pContext = NULL;
145 PUSB_SEND_CONTEXT pReturnContext = NULL;
146 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400147
148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
149
150 for (ii = 0; ii < pDevice->cbTD; ii++) {
151 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500152 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500153 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100154 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400155 pReturnContext = pContext;
156 break;
157 }
158 }
159 if ( ii == pDevice->cbTD ) {
160 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
161 }
Andres More8611a292010-05-01 14:25:00 -0300162 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400163}
164
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000165static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
166 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400167{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000168 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400169
Andres More4b50fb42010-06-22 21:57:42 -0300170 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400171 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300172 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400173 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
174 else
175 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
176
177 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
178 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300179 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
180 pbyDestAddr,
181 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400182}
183
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000184static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
185 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
186 u16 wPayloadLen, u8 *pMICHDR)
Forest Bond92b96792009-06-13 07:38:31 -0400187{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000188 u32 *pdwIV = (u32 *)pbyIVHead;
189 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
190 u16 wValue;
Andres More1cac4a42013-03-18 20:33:50 -0500191 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000192 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400193
Forest Bond92b96792009-06-13 07:38:31 -0400194 //Fill TXKEY
195 if (pTransmitKey == NULL)
196 return;
197
198 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
199 *pdwIV = pDevice->dwIVCounter;
200 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
201
202 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
203 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
Andres Moreb902fbf2013-02-25 20:32:51 -0500204 memcpy(pDevice->abyPRNG, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700205 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400206 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500207 memcpy(pbyBuf, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700208 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400209 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500210 memcpy(pbyBuf+8, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700211 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400212 }
Jim Lieb3e362592009-08-12 14:54:11 -0700213 memcpy(pDevice->abyPRNG, pbyBuf, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400214 }
215 // Append IV after Mac Header
216 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
Malcolm Priestleyd5bbef72012-11-11 15:53:14 +0000217 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
Forest Bond92b96792009-06-13 07:38:31 -0400218 *pdwIV = cpu_to_le32(*pdwIV);
219 pDevice->dwIVCounter++;
220 if (pDevice->dwIVCounter > WEP_IV_MASK) {
221 pDevice->dwIVCounter = 0;
222 }
223 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
224 pTransmitKey->wTSC15_0++;
225 if (pTransmitKey->wTSC15_0 == 0) {
226 pTransmitKey->dwTSC47_16++;
227 }
228 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
229 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
Jim Lieb3e362592009-08-12 14:54:11 -0700230 memcpy(pbyBuf, pDevice->abyPRNG, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400231 // Make IV
Jim Lieb3e362592009-08-12 14:54:11 -0700232 memcpy(pdwIV, pDevice->abyPRNG, 3);
Forest Bond92b96792009-06-13 07:38:31 -0400233
Andres Moreb902fbf2013-02-25 20:32:51 -0500234 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Forest Bond92b96792009-06-13 07:38:31 -0400235 // Append IV&ExtIV after Mac Header
236 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +0000237 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %x\n",
238 *pdwExtIV);
Forest Bond92b96792009-06-13 07:38:31 -0400239
240 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
241 pTransmitKey->wTSC15_0++;
242 if (pTransmitKey->wTSC15_0 == 0) {
243 pTransmitKey->dwTSC47_16++;
244 }
Jim Lieb3e362592009-08-12 14:54:11 -0700245 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400246
247 // Make IV
248 *pdwIV = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -0500249 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Andres More3eaca0d2013-02-25 20:32:52 -0500250 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
Forest Bond92b96792009-06-13 07:38:31 -0400251 //Append IV&ExtIV after Mac Header
252 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
253
254 //Fill MICHDR0
255 *pMICHDR = 0x59;
Andres Moreb902fbf2013-02-25 20:32:51 -0500256 *((u8 *)(pMICHDR+1)) = 0; // TxPriority
Andres More1cac4a42013-03-18 20:33:50 -0500257 memcpy(pMICHDR+2, &(pMACHeader->addr2[0]), 6);
Andres Moreb902fbf2013-02-25 20:32:51 -0500258 *((u8 *)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
259 *((u8 *)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
260 *((u8 *)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
261 *((u8 *)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
262 *((u8 *)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
263 *((u8 *)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
264 *((u8 *)(pMICHDR+14)) = HIBYTE(wPayloadLen);
265 *((u8 *)(pMICHDR+15)) = LOBYTE(wPayloadLen);
Forest Bond92b96792009-06-13 07:38:31 -0400266
267 //Fill MICHDR1
Andres Moreb902fbf2013-02-25 20:32:51 -0500268 *((u8 *)(pMICHDR+16)) = 0; // HLEN[15:8]
Forest Bond92b96792009-06-13 07:38:31 -0400269 if (pDevice->bLongHeader) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500270 *((u8 *)(pMICHDR+17)) = 28; // HLEN[7:0]
Forest Bond92b96792009-06-13 07:38:31 -0400271 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500272 *((u8 *)(pMICHDR+17)) = 22; // HLEN[7:0]
Forest Bond92b96792009-06-13 07:38:31 -0400273 }
Andres More1cac4a42013-03-18 20:33:50 -0500274 wValue = cpu_to_le16(pMACHeader->frame_control & 0xC78F);
Andres Moreb902fbf2013-02-25 20:32:51 -0500275 memcpy(pMICHDR+18, (u8 *)&wValue, 2); // MSKFRACTL
Andres More1cac4a42013-03-18 20:33:50 -0500276 memcpy(pMICHDR+20, &(pMACHeader->addr1[0]), 6);
277 memcpy(pMICHDR+26, &(pMACHeader->addr2[0]), 6);
Forest Bond92b96792009-06-13 07:38:31 -0400278
279 //Fill MICHDR2
Andres More1cac4a42013-03-18 20:33:50 -0500280 memcpy(pMICHDR+32, &(pMACHeader->addr3[0]), 6);
281 wValue = pMACHeader->seq_ctrl;
Forest Bond92b96792009-06-13 07:38:31 -0400282 wValue &= 0x000F;
283 wValue = cpu_to_le16(wValue);
Andres Moreb902fbf2013-02-25 20:32:51 -0500284 memcpy(pMICHDR+38, (u8 *)&wValue, 2); // MSKSEQCTL
Forest Bond92b96792009-06-13 07:38:31 -0400285 if (pDevice->bLongHeader) {
Andres More1cac4a42013-03-18 20:33:50 -0500286 memcpy(pMICHDR+40, &(pMACHeader->addr4[0]), 6);
Forest Bond92b96792009-06-13 07:38:31 -0400287 }
288 }
289}
290
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000291static void s_vSWencryption(struct vnt_private *pDevice,
292 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400293{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000294 u32 cbICVlen = 4;
295 u32 dwICV = 0xffffffff;
296 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400297
298 if (pTransmitKey == NULL)
299 return;
300
301 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
302 //=======================================================================
303 // Append ICV after payload
304 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500305 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400306 // finally, we must invert dwCRC to get the correct answer
307 *pdwICV = cpu_to_le32(~dwICV);
308 // RC4 encryption
309 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
310 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
311 //=======================================================================
312 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
313 //=======================================================================
314 //Append ICV after payload
315 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500316 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400317 // finally, we must invert dwCRC to get the correct answer
318 *pdwICV = cpu_to_le32(~dwICV);
319 // RC4 encryption
320 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
321 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
322 //=======================================================================
323 }
324}
325
Forest Bond92b96792009-06-13 07:38:31 -0400326/*byPktType : PK_TYPE_11A 0
327 PK_TYPE_11B 1
328 PK_TYPE_11GB 2
329 PK_TYPE_11GA 3
330*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000331static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
332 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400333{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000334 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400335
336 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
337 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500338 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400339 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500340 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400341 }
342
343 if (bNeedAck) {
344 return (uDataTime + pDevice->uSIFS + uAckTime);
345 }
346 else {
347 return uDataTime;
348 }
349}
350
351//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100352static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000353 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400354{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000355 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400356
357 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
358
Forest Bond92b96792009-06-13 07:38:31 -0400359 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
360 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
361 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
362 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
363 }
364 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
365 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
366 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
367 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
368 }
369 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
370 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
371 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
372 }
373 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
374 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
375 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
376 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
377 return uRrvTime;
378 }
379
380 //RTSRrvTime
381 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100382 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400383}
384
385//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100386static u16 s_uGetDataDuration(struct vnt_private *pDevice,
387 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400388{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100389 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400390
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100391 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100392 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100393 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
394 byPktType, 14, pDevice->byTopCCKBasicRate);
395 else
396 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
397 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100398 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100399 }
Forest Bond92b96792009-06-13 07:38:31 -0400400
Forest Bond92b96792009-06-13 07:38:31 -0400401 return 0;
402}
403
Forest Bond92b96792009-06-13 07:38:31 -0400404//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100405static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000406 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
407 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400408{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000409 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400410
Forest Bond92b96792009-06-13 07:38:31 -0400411 switch (byDurType) {
412
413 case RTSDUR_BB: //RTSDuration_bb
414 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
415 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
416 break;
417
418 case RTSDUR_BA: //RTSDuration_ba
419 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
420 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
421 break;
422
423 case RTSDUR_AA: //RTSDuration_aa
424 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
425 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
426 break;
427
428 case CTSDUR_BA: //CTSDuration_ba
429 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
430 break;
431
432 case RTSDUR_BA_F0: //RTSDuration_ba_f0
433 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
434 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
435 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
436 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
437 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
438 }
439 break;
440
441 case RTSDUR_AA_F0: //RTSDuration_aa_f0
442 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
443 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
444 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
445 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
446 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
447 }
448 break;
449
450 case RTSDUR_BA_F1: //RTSDuration_ba_f1
451 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
452 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
453 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
454 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
455 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
456 }
457 break;
458
459 case RTSDUR_AA_F1: //RTSDuration_aa_f1
460 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
461 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
462 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
463 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
464 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
465 }
466 break;
467
468 case CTSDUR_BA_F0: //CTSDuration_ba_f0
469 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
470 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
471 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
472 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
473 }
474 break;
475
476 case CTSDUR_BA_F1: //CTSDuration_ba_f1
477 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
478 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
479 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
480 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
481 }
482 break;
483
484 default:
485 break;
486 }
487
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100488 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400489}
490
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000491static u32 s_uFillDataHead(struct vnt_private *pDevice,
492 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100493 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400494{
495
496 if (pTxDataHead == NULL) {
497 return 0;
498 }
499
500 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Forest Bond92b96792009-06-13 07:38:31 -0400501 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +0100502 struct vnt_tx_datahead_g *pBuf =
503 (struct vnt_tx_datahead_g *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400504 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100505 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
506 byPktType, &pBuf->a);
507 BBvCalculateParameter(pDevice, cbFrameLength,
508 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400509 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100510 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100511 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100512 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100513 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400514
515 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
516 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
517 return (pBuf->wDuration_a);
518 } else {
519 // Auto Fallback
Malcolm Priestley7c05c542013-08-16 23:49:15 +0100520 struct vnt_tx_datahead_g_fb *pBuf =
521 (struct vnt_tx_datahead_g_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400522 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100523 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
524 byPktType, &pBuf->a);
525 BBvCalculateParameter(pDevice, cbFrameLength,
526 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400527 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100528 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100529 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100530 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100531 PK_TYPE_11B, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100532 pBuf->wDuration_a_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100533 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100534 pBuf->wDuration_a_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100535 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400536 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
537 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
538 return (pBuf->wDuration_a);
539 } //if (byFBOption == AUTO_FB_NONE)
Forest Bond92b96792009-06-13 07:38:31 -0400540 }
541 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100542 if (byFBOption != AUTO_FB_NONE) {
Malcolm Priestley1da4ee22013-08-16 23:51:38 +0100543 struct vnt_tx_datahead_a_fb *pBuf =
544 (struct vnt_tx_datahead_a_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400545 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100546 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
547 byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400548 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100549 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100550 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100551 pBuf->wDuration_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100552 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100553 pBuf->wDuration_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100554 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400555 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Forest Bond92b96792009-06-13 07:38:31 -0400556 return (pBuf->wDuration);
557 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100558 struct vnt_tx_datahead_ab *pBuf =
559 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400560 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100561 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
562 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400563 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100564 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100565 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400566 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100567
Forest Bond92b96792009-06-13 07:38:31 -0400568 return (pBuf->wDuration);
569 }
570 }
571 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100572 struct vnt_tx_datahead_ab *pBuf =
573 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400574 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100575 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
576 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400577 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100578 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100579 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400580 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100581
Forest Bond92b96792009-06-13 07:38:31 -0400582 return (pBuf->wDuration);
583 }
584 return 0;
585}
586
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000587static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
588 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500589 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400590{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000591 u32 uRTSFrameLen = 20;
Forest Bond92b96792009-06-13 07:38:31 -0400592
Forest Bond92b96792009-06-13 07:38:31 -0400593 if (pvRTS == NULL)
594 return;
595
596 if (bDisCRC) {
597 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
598 // in this case we need to decrease its length by 4.
599 uRTSFrameLen -= 4;
600 }
601
Masanari Iida93184692012-08-13 21:21:50 +0900602 // Note: So far RTSHead doesn't appear in ATIM & Beacom DMA, so we don't need to take them into account.
Forest Bond92b96792009-06-13 07:38:31 -0400603 // Otherwise, we need to modified codes for them.
604 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
605 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100606 struct vnt_rts_g *pBuf = (struct vnt_rts_g *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400607 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100608 BBvCalculateParameter(pDevice, uRTSFrameLen,
609 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
610 BBvCalculateParameter(pDevice, uRTSFrameLen,
611 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400612 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100613 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
614 cbFrameLength, PK_TYPE_11B,
615 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
616 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
617 cbFrameLength, byPktType,
618 wCurrentRate, bNeedAck, byFBOption);
619 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
620 cbFrameLength, byPktType,
621 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100622 pBuf->data.duration = pBuf->wDuration_aa;
623 /*Get RTS Frame body */
624 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400625
Malcolm Priestley07738932013-08-05 22:08:05 +0100626 if (pDevice->eOPMode == OP_MODE_ADHOC ||
627 pDevice->eOPMode == OP_MODE_AP)
628 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
629 else
630 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Andres More9a0e7562010-04-13 21:54:48 -0300631
Malcolm Priestley07738932013-08-05 22:08:05 +0100632 if (pDevice->eOPMode == OP_MODE_AP)
633 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
634 else
635 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400636 }
637 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100638 struct vnt_rts_g_fb *pBuf = (struct vnt_rts_g_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400639 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100640 BBvCalculateParameter(pDevice, uRTSFrameLen,
641 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
642 BBvCalculateParameter(pDevice, uRTSFrameLen,
643 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400644 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100645 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
646 cbFrameLength, PK_TYPE_11B,
647 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
648 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
649 cbFrameLength, byPktType,
650 wCurrentRate, bNeedAck, byFBOption);
651 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
652 cbFrameLength, byPktType,
653 wCurrentRate, bNeedAck, byFBOption);
654 pBuf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
655 RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
656 bNeedAck, byFBOption);
657 pBuf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(pDevice,
658 RTSDUR_AA_F0, cbFrameLength, byPktType,
659 wCurrentRate, bNeedAck, byFBOption);
660 pBuf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
661 RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
662 bNeedAck, byFBOption);
663 pBuf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(pDevice,
664 RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate,
665 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100666 pBuf->data.duration = pBuf->wDuration_aa;
667 /*Get RTS Frame body*/
668 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400669
Malcolm Priestley07738932013-08-05 22:08:05 +0100670 if (pDevice->eOPMode == OP_MODE_ADHOC ||
671 pDevice->eOPMode == OP_MODE_AP)
672 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
673 else
674 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400675
Malcolm Priestley07738932013-08-05 22:08:05 +0100676 if (pDevice->eOPMode == OP_MODE_AP)
677 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
678 else
679 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400680 } // if (byFBOption == AUTO_FB_NONE)
681 }
682 else if (byPktType == PK_TYPE_11A) {
683 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100684 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400685 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100686 BBvCalculateParameter(pDevice, uRTSFrameLen,
687 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400688 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100689 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
690 cbFrameLength, byPktType, wCurrentRate,
691 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100692 pBuf->data.duration = pBuf->wDuration;
693 /* Get RTS Frame body */
694 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400695
Malcolm Priestley07738932013-08-05 22:08:05 +0100696 if (pDevice->eOPMode == OP_MODE_ADHOC ||
697 pDevice->eOPMode == OP_MODE_AP)
698 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
699 else
700 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400701
Malcolm Priestley07738932013-08-05 22:08:05 +0100702 if (pDevice->eOPMode == OP_MODE_AP)
703 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
704 else
705 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400706 }
707 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100708 struct vnt_rts_a_fb *pBuf = (struct vnt_rts_a_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400709 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100710 BBvCalculateParameter(pDevice, uRTSFrameLen,
711 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400712 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100713 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
714 cbFrameLength, byPktType, wCurrentRate,
715 bNeedAck, byFBOption);
716 pBuf->wRTSDuration_f0 = s_uGetRTSCTSDuration(pDevice,
717 RTSDUR_AA_F0, cbFrameLength, byPktType,
718 wCurrentRate, bNeedAck, byFBOption);
719 pBuf->wRTSDuration_f1 = s_uGetRTSCTSDuration(pDevice,
720 RTSDUR_AA_F1, cbFrameLength, byPktType,
721 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100722 pBuf->data.duration = pBuf->wDuration;
723 /* Get RTS Frame body */
724 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400725
Malcolm Priestley07738932013-08-05 22:08:05 +0100726 if (pDevice->eOPMode == OP_MODE_ADHOC ||
727 pDevice->eOPMode == OP_MODE_AP)
728 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
729 else
730 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
731
732 if (pDevice->eOPMode == OP_MODE_AP)
733 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
734 else
735 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400736 }
737 }
738 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100739 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400740 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100741 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate,
742 PK_TYPE_11B, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400743 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100744 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
745 cbFrameLength, byPktType, wCurrentRate,
746 bNeedAck, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400747
Malcolm Priestley07738932013-08-05 22:08:05 +0100748 pBuf->data.duration = pBuf->wDuration;
749 /* Get RTS Frame body */
750 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400751
Malcolm Priestley07738932013-08-05 22:08:05 +0100752 if (pDevice->eOPMode == OP_MODE_ADHOC ||
753 pDevice->eOPMode == OP_MODE_AP)
754 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
755 else
756 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
757
758 if (pDevice->eOPMode == OP_MODE_AP)
759 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
760 else
761 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400762 }
763}
764
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000765static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
766 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
767 int bDisCRC, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400768{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000769 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400770
771 if (pvCTS == NULL) {
772 return;
773 }
774
775 if (bDisCRC) {
776 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
777 // in this case we need to decrease its length by 4.
778 uCTSFrameLen -= 4;
779 }
780
781 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100782 if (byFBOption != AUTO_FB_NONE) {
783 /* Auto Fall back */
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100784 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100785 /* Get SignalField,ServiceField,Length */
786 BBvCalculateParameter(pDevice, uCTSFrameLen,
787 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100788 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
789 cbFrameLength, byPktType,
790 wCurrentRate, bNeedAck, byFBOption);
791 /* Get CTSDuration_ba_f0 */
792 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
793 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
794 bNeedAck, byFBOption);
795 /* Get CTSDuration_ba_f1 */
796 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
797 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
798 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100799 /* Get CTS Frame body */
800 pBuf->data.duration = pBuf->wDuration_ba;
801 pBuf->data.frame_control = TYPE_CTL_CTS;
802 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100803 } else {
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100804 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100805 /* Get SignalField,ServiceField,Length */
806 BBvCalculateParameter(pDevice, uCTSFrameLen,
807 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100808 /* Get CTSDuration_ba */
809 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
810 CTSDUR_BA, cbFrameLength, byPktType,
811 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100812 /*Get CTS Frame body*/
813 pBuf->data.duration = pBuf->wDuration_ba;
814 pBuf->data.frame_control = TYPE_CTL_CTS;
815 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400816 }
817 }
818}
819
Forest Bond92b96792009-06-13 07:38:31 -0400820/*+
821 *
822 * Description:
823 * Generate FIFO control for MAC & Baseband controller
824 *
825 * Parameters:
826 * In:
827 * pDevice - Pointer to adpater
828 * pTxDataHead - Transmit Data Buffer
829 * pTxBufHead - pTxBufHead
830 * pvRrvTime - pvRrvTime
831 * pvRTS - RTS Buffer
832 * pCTS - CTS Buffer
833 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
834 * bNeedACK - If need ACK
835 * uDMAIdx - DMA Index
836 * Out:
837 * none
838 *
839 * Return Value: none
840 *
841-*/
Andres Morecc856e62010-05-17 21:34:01 -0300842
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000843static void s_vGenerateTxParameter(struct vnt_private *pDevice,
844 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
845 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500846 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400847{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000848 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
849 u16 wFifoCtl;
Andres Moree269fc22013-02-12 20:36:29 -0500850 int bDisCRC = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000851 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400852
853 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
854 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
855 pFifoHead->wReserved = wCurrentRate;
856 wFifoCtl = pFifoHead->wFIFOCtl;
857
858 if (wFifoCtl & FIFOCTL_CRCDIS) {
Andres More4e9b5e22013-02-12 20:36:30 -0500859 bDisCRC = true;
Forest Bond92b96792009-06-13 07:38:31 -0400860 }
861
862 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
863 byFBOption = AUTO_FB_0;
864 }
865 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
866 byFBOption = AUTO_FB_1;
867 }
868
869 if (pDevice->bLongHeader)
870 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
871
872 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
873
874 if (pvRTS != NULL) { //RTS_need
875 //Fill RsvTime
876 if (pvRrvTime) {
Malcolm Priestley6398a592013-08-16 21:26:55 +0100877 struct vnt_rrv_time_rts *pBuf =
878 (struct vnt_rrv_time_rts *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100879 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
880 byPktType, cbFrameSize, wCurrentRate);
881 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
882 byPktType, cbFrameSize, wCurrentRate);
883 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
884 byPktType, cbFrameSize, wCurrentRate);
Andres More3eaca0d2013-02-25 20:32:52 -0500885 pBuf->wTxRrvTime_a = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
886 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 -0400887 }
888 //Fill RTS
889 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
890 }
891 else {//RTS_needless, PCF mode
892
893 //Fill RsvTime
894 if (pvRrvTime) {
Malcolm Priestley4f990052013-08-16 23:38:57 +0100895 struct vnt_rrv_time_cts *pBuf =
896 (struct vnt_rrv_time_cts *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500897 pBuf->wTxRrvTime_a = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
898 pBuf->wTxRrvTime_b = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100899 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
900 byPktType, cbFrameSize, wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400901 }
902 //Fill CTS
903 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
904 }
905 }
906 else if (byPktType == PK_TYPE_11A) {
907
908 if (pvRTS != NULL) {//RTS_need, non PCF mode
909 //Fill RsvTime
910 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100911 struct vnt_rrv_time_ab *pBuf =
912 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100913 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
914 byPktType, cbFrameSize, wCurrentRate);
Andres More3eaca0d2013-02-25 20:32:52 -0500915 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400916 }
917 //Fill RTS
918 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
919 }
920 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
921 //Fill RsvTime
922 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100923 struct vnt_rrv_time_ab *pBuf =
924 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500925 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400926 }
927 }
928 }
929 else if (byPktType == PK_TYPE_11B) {
930
931 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
932 //Fill RsvTime
933 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100934 struct vnt_rrv_time_ab *pBuf =
935 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100936 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
937 byPktType, cbFrameSize, wCurrentRate);
Andres More3eaca0d2013-02-25 20:32:52 -0500938 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400939 }
940 //Fill RTS
941 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
942 }
943 else { //RTS_needless, non PCF mode
944 //Fill RsvTime
945 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100946 struct vnt_rrv_time_ab *pBuf =
947 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500948 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400949 }
950 }
951 }
952 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
953}
954/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500955 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500956 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300957 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400958*/
959
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000960static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100961 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
962 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
963 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
964 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400965{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000966 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
967 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000968 u32 cb802_1_H_len;
969 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
970 u32 cbFCSlen = 4, cbMICHDR = 0;
971 int bNeedACK, bRTS;
972 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
973 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
974 u8 abySNAP_Bridgetunnel[ETH_ALEN]
975 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
976 u32 uDuration;
977 u32 cbHeaderLength = 0, uPadding = 0;
978 void *pvRrvTime;
979 PSMICHDRHead pMICHDR;
980 void *pvRTS;
981 void *pvCTS;
982 void *pvTxDataHd;
983 u8 byFBOption = AUTO_FB_NONE, byFragType;
984 u16 wTxBufSize;
985 u32 dwMICKey0, dwMICKey1, dwMIC_Priority, dwCRC;
986 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500987 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -0400988
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000989 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400990
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000991 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500992 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
993 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000994 }
Forest Bond92b96792009-06-13 07:38:31 -0400995
Forest Bond92b96792009-06-13 07:38:31 -0400996 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -0500997 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -0400998 if (pDevice->dwDiagRefCount == 0) {
999 cb802_1_H_len = 8;
1000 } else {
1001 cb802_1_H_len = 2;
1002 }
1003 } else {
1004 cb802_1_H_len = 0;
1005 }
1006
Charles Clément21ec51f2010-05-18 10:08:14 -07001007 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001008
1009 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001010 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001011
1012 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001013 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001014 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1015 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001016 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1017 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001018 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001019 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001020 pTxBufHead->wFIFOCtl =
1021 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1022 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001023 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001024 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1025 }
Forest Bond92b96792009-06-13 07:38:31 -04001026 }
1027 else {
1028 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001029 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001030 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1031 }
1032 } //if (pDevice->dwDiagRefCount != 0) {
1033
1034 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1035
1036 //Set FIFOCTL_LHEAD
1037 if (pDevice->bLongHeader)
1038 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1039
1040 if (pDevice->bSoftwareGenCrcErr) {
1041 pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS; // set tx descriptors to NO hardware CRC
1042 }
1043
1044 //Set FRAGCTL_MACHDCNT
1045 if (pDevice->bLongHeader) {
1046 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1047 } else {
1048 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1049 }
Andres More3eaca0d2013-02-25 20:32:52 -05001050 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001051
1052 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001053 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001054 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1055 }
1056
1057 //Set Auto Fallback Ctl
1058 if (wCurrentRate >= RATE_18M) {
1059 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1060 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1061 byFBOption = AUTO_FB_0;
1062 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1063 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1064 byFBOption = AUTO_FB_1;
1065 }
1066 }
1067
Andres More4e9b5e22013-02-12 20:36:30 -05001068 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001069 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1070 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1071 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1072 }
1073 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1074 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1075 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1076 }
1077 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1078 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1079 }
1080 }
1081 }
1082
Forest Bond92b96792009-06-13 07:38:31 -04001083 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1084 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1085 cbIVlen = 4;
1086 cbICVlen = 4;
1087 }
1088 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1089 cbIVlen = 8;//IV+ExtIV
1090 cbMIClen = 8;
1091 cbICVlen = 4;
1092 }
1093 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1094 cbIVlen = 8;//RSN Header
1095 cbICVlen = 8;//MIC
1096 cbMICHDR = sizeof(SMICHDRHead);
1097 }
Andres Moree269fc22013-02-12 20:36:29 -05001098 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001099 //MAC Header should be padding 0 to DW alignment.
1100 uPadding = 4 - (cbMACHdLen%4);
1101 uPadding %= 4;
1102 }
1103 }
1104
1105 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1106
Andres Moree269fc22013-02-12 20:36:29 -05001107 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1108 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001109 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001110 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001111 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1112 }
1113
Andres Moreb902fbf2013-02-25 20:32:51 -05001114 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001115 wTxBufSize = sizeof(STxBufHead);
1116 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1117 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001118 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001119 pvRrvTime = (struct vnt_rrv_time_rts *)
1120 (pbyTxBufferAddr + wTxBufSize);
1121 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1122 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001123 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001124 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001125 pvCTS = NULL;
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001126 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1127 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1128 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001129 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001130 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001131 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001132 }
1133 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001134 pvRrvTime = (struct vnt_rrv_time_cts *)
1135 (pbyTxBufferAddr + wTxBufSize);
1136 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1137 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001138 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001139 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001140 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001141 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1142 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1143 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001144 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1145 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001146 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001147 }
1148 } else {
1149 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001150 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001151 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1152 wTxBufSize);
1153 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1154 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001155 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001156 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001157 pvCTS = NULL;
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001158 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1159 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1160 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001161 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1162 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001163 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001164 }
Andres Moree269fc22013-02-12 20:36:29 -05001165 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001166 pvRrvTime = (struct vnt_rrv_time_cts *)
1167 (pbyTxBufferAddr + wTxBufSize);
1168 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1169 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001170 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001171 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001172 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001173 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001174 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1175 cbMICHDR + sizeof(struct vnt_cts_fb));
1176 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001177 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001178 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001179 }
1180 } // Auto Fall Back
1181 }
1182 else {//802.11a/b packet
1183 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001184 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001185 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1186 wTxBufSize);
1187 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1188 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001189 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001190 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001191 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001192 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1193 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001194 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001195 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1196 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001197 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001198 }
Andres Moree269fc22013-02-12 20:36:29 -05001199 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001200 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1201 wTxBufSize);
1202 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1203 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001204 pvRTS = NULL;
1205 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001206 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1207 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001208 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001209 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001210 }
1211 } else {
1212 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001213 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001214 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1215 wTxBufSize);
1216 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1217 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001218 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001219 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001220 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001221 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1222 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001223 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001224 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1225 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001226 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001227 }
Andres Moree269fc22013-02-12 20:36:29 -05001228 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001229 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1230 wTxBufSize);
1231 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1232 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001233 pvRTS = NULL;
1234 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001235 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1236 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001237 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001238 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001239 }
1240 } // Auto Fall Back
1241 }
1242
Andres Moreb902fbf2013-02-25 20:32:51 -05001243 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1244 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1245 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001246
Forest Bond92b96792009-06-13 07:38:31 -04001247 //=========================
1248 // No Fragmentation
1249 //=========================
1250 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1251 byFragType = FRAGCTL_NONFRAG;
1252 //uDMAIdx = TYPE_AC0DMA;
1253 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1254
Forest Bond92b96792009-06-13 07:38:31 -04001255 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001256 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1257 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001258 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1259 //Fill DataHead
1260 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001261 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001262 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001263 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001264 byFragType, uDMAIdx, 0);
1265
Andres More4e9b5e22013-02-12 20:36:30 -05001266 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001267 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001268 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001269 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001270
1271 if (pDevice->bEnableHostWEP) {
1272 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1273 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1274 }
1275 }
1276
1277 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001278 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001279 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001280 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1281 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001282 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001283 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001284 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001285 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001286 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001287 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001288 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001289 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001290 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001291
1292 }
1293
1294 }
1295
Forest Bond92b96792009-06-13 07:38:31 -04001296 if (pPacket != NULL) {
1297 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001298 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001299 (pPacket + ETH_HLEN),
1300 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001301 );
1302
1303 } else {
1304 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001305 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001306 }
1307
Andres More4e9b5e22013-02-12 20:36:30 -05001308 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001309
1310 ///////////////////////////////////////////////////////////////////
1311
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001312 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1313 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1314 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1315 }
Forest Bond92b96792009-06-13 07:38:31 -04001316 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001317 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1318 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001319 }
1320 else {
Andres More52a7e642013-02-25 20:32:53 -05001321 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1322 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001323 }
1324 // DO Software Michael
1325 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001326 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001327 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001328 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001329 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1330 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001331
1332 ///////////////////////////////////////////////////////////////////
1333
1334 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1335 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001336 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001337 //}
1338 //DBG_PRN_GRP12(("\n\n\n"));
1339
1340 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1341
Andres More52a7e642013-02-25 20:32:53 -05001342 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1343 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001344
1345 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1346 MIC_vUnInit();
1347
Andres More4e9b5e22013-02-12 20:36:30 -05001348 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001349 *pdwMIC_L = 0;
1350 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001351 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001352 }
1353 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1354 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1355 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1356 }
1357
Andres More4e9b5e22013-02-12 20:36:30 -05001358 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001359
Andres More3eaca0d2013-02-25 20:32:52 -05001360 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001361
Andres More4e9b5e22013-02-12 20:36:30 -05001362 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1363 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1364 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001365 cbFrameSize -= cbICVlen;
1366 }
1367
Andres More4e9b5e22013-02-12 20:36:30 -05001368 if (pDevice->bSoftwareGenCrcErr == true) {
Andres Morecc856e62010-05-17 21:34:01 -03001369 unsigned int cbLen;
Andres More52a7e642013-02-25 20:32:53 -05001370 u32 * pdwCRC;
Forest Bond92b96792009-06-13 07:38:31 -04001371
1372 dwCRC = 0xFFFFFFFFL;
1373 cbLen = cbFrameSize - cbFCSlen;
1374 // calculate CRC, and wrtie CRC value to end of TD
1375 dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
Andres More52a7e642013-02-25 20:32:53 -05001376 pdwCRC = (u32 *)(pbyMacHdr + cbLen);
Forest Bond92b96792009-06-13 07:38:31 -04001377 // finally, we must invert dwCRC to get the correct answer
1378 *pdwCRC = ~dwCRC;
1379 // Force Error
1380 *pdwCRC -= 1;
1381 } else {
1382 cbFrameSize -= cbFCSlen;
1383 }
1384
1385 *pcbHeaderLen = cbHeaderLength;
1386 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1387
Forest Bond92b96792009-06-13 07:38:31 -04001388 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001389 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001390
Andres More4e9b5e22013-02-12 20:36:30 -05001391 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001392
1393}
1394
Forest Bond92b96792009-06-13 07:38:31 -04001395/*+
1396 *
1397 * Description:
1398 * Translate 802.3 to 802.11 header
1399 *
1400 * Parameters:
1401 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001402 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001403 * dwTxBufferAddr - Transmit Buffer
1404 * pPacket - Packet from upper layer
1405 * cbPacketSize - Transmit Data Length
1406 * Out:
1407 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1408 * pcbAppendPayload - size of append payload for 802.1H translation
1409 *
1410 * Return Value: none
1411 *
1412-*/
1413
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001414static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001415 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001416 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001417{
Andres More1cac4a42013-03-18 20:33:50 -05001418 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001419
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001420 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001421
1422 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001423 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001424 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001425 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001426 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1427 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001428 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001429 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001430 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001431 } else {
1432 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001433 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001434 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001435 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001436 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001437 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001438 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001439 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001440 &(pDevice->abyBSSID[0]),
1441 ETH_ALEN);
1442 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001443 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001444 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001445 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001446 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001447 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001448 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001449 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001450 &(pDevice->abyBSSID[0]),
1451 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001452 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001453 }
1454 }
1455
1456 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001457 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001458
Andres More1cac4a42013-03-18 20:33:50 -05001459 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001460
1461 if (pDevice->bLongHeader) {
1462 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001463 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001464 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001465 }
Andres More1cac4a42013-03-18 20:33:50 -05001466 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001467
1468 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001469 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001470
1471 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1472 pDevice->wSeqCounter++;
1473 if (pDevice->wSeqCounter > 0x0fff)
1474 pDevice->wSeqCounter = 0;
1475 }
1476
1477 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001478 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001479 }
1480}
1481
Forest Bond92b96792009-06-13 07:38:31 -04001482/*+
1483 *
1484 * Description:
1485 * Request instructs a MAC to transmit a 802.11 management packet through
1486 * the adapter onto the medium.
1487 *
1488 * Parameters:
1489 * In:
1490 * hDeviceContext - Pointer to the adapter
1491 * pPacket - A pointer to a descriptor for the packet to transmit
1492 * Out:
1493 * none
1494 *
Andres Moree269fc22013-02-12 20:36:29 -05001495 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001496 *
1497-*/
1498
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001499CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1500 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001501{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001502 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001503 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001504 PSTxBufHead pTxBufHead;
1505 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001506 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001507 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001508 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001509 u8 byPktType, *pbyTxBufferAddr;
1510 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1511 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001512 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001513 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1514 u32 uPadding = 0;
1515 u16 wTxBufSize;
1516 u32 cbMacHdLen;
1517 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001518
Forest Bond92b96792009-06-13 07:38:31 -04001519 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1520
1521 if (NULL == pContext) {
1522 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1523 return CMD_STATUS_RESOURCES;
1524 }
1525
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001526 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001527 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001528 cbFrameBodySize = pPacket->cbPayloadLen;
1529 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1530 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001531
1532 if (pDevice->byBBType == BB_TYPE_11A) {
1533 wCurrentRate = RATE_6M;
1534 byPktType = PK_TYPE_11A;
1535 } else {
1536 wCurrentRate = RATE_1M;
1537 byPktType = PK_TYPE_11B;
1538 }
1539
1540 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1541 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1542 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1543 // to set power here.
1544 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1545 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1546 } else {
1547 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1548 }
1549 pDevice->wCurrentRate = wCurrentRate;
1550
Forest Bond92b96792009-06-13 07:38:31 -04001551 //Set packet type
1552 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1553 pTxBufHead->wFIFOCtl = 0;
1554 }
1555 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1556 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1557 }
1558 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1559 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1560 }
1561 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1562 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1563 }
1564
1565 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1566 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1567
Andres More22040bb2010-08-02 20:21:44 -03001568 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001569 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001570 }
1571 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001572 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001573 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1574 };
1575
1576 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1577 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1578
1579 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1580 //Set Preamble type always long
1581 //pDevice->byPreambleType = PREAMBLE_LONG;
1582 // probe-response don't retry
1583 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001584 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001585 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1586 //}
1587 }
1588
1589 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1590
1591 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001592 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001593 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1594 } else {
1595 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1596 }
1597
1598 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001599 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001600
1601 // Notes:
1602 // Although spec says MMPDU can be fragmented; In most case,
1603 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001604 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001605
1606 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1607 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1608 cbIVlen = 4;
1609 cbICVlen = 4;
1610 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1611 }
1612 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1613 cbIVlen = 8;//IV+ExtIV
1614 cbMIClen = 8;
1615 cbICVlen = 4;
1616 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1617 //We need to get seed here for filling TxKey entry.
1618 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1619 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1620 }
1621 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1622 cbIVlen = 8;//RSN Header
1623 cbICVlen = 8;//MIC
1624 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001625 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001626 }
1627 //MAC Header should be padding 0 to DW alignment.
1628 uPadding = 4 - (cbMacHdLen%4);
1629 uPadding %= 4;
1630 }
1631
1632 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1633
1634 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001635 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001636 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1637 }
1638 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1639
1640 //Set RrvTime/RTS/CTS Buffer
1641 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1642
Malcolm Priestley4f990052013-08-16 23:38:57 +01001643 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001644 pMICHDR = NULL;
1645 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001646 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001647 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001648 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001649 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1650 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001651 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001652 }
1653 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001654 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001655 pMICHDR = NULL;
1656 pvRTS = NULL;
1657 pCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001658 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1659 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001660 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001661 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001662 }
1663
Andres Moreceb8c5d2013-03-18 20:33:49 -05001664 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001665 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1666 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001667 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001668 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1669 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001670 //=========================
1671 // No Fragmentation
1672 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001673 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001674
Forest Bond92b96792009-06-13 07:38:31 -04001675 //Fill FIFO,RrvTime,RTS,and CTS
1676 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1677 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1678
1679 //Fill DataHead
1680 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001681 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001682
Andres More1cac4a42013-03-18 20:33:50 -05001683 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001684
1685 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1686
1687 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001688 u8 * pbyIVHead;
1689 u8 * pbyPayloadHead;
1690 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001691 PSKeyItem pTransmitKey = NULL;
1692
Andres Moreb902fbf2013-02-25 20:32:51 -05001693 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1694 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001695 do {
1696 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001697 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001698 pbyBSSID = pDevice->abyBSSID;
1699 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001700 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001701 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001702 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001703 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1704 break;
1705 }
1706 } else {
1707 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1708 break;
1709 }
1710 }
1711 // get group key
1712 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001713 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001714 pTransmitKey = NULL;
1715 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1716 } else {
1717 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1718 }
Andres Moree269fc22013-02-12 20:36:29 -05001719 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001720 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001721 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001722 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001723
Jim Lieb3e362592009-08-12 14:54:11 -07001724 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001725 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001726 cbFrameBodySize);
1727 }
1728 else {
1729 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001730 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001731 }
1732
Andres More1cac4a42013-03-18 20:33:50 -05001733 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001734 pDevice->wSeqCounter++ ;
1735 if (pDevice->wSeqCounter > 0x0fff)
1736 pDevice->wSeqCounter = 0;
1737
1738 if (bIsPSPOLL) {
1739 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001740 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001741 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1742 // in the same place of other packet's Duration-field).
1743 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001744 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1745 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1746 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1747 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1748 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1749 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001750 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1751 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1752 }
Forest Bond92b96792009-06-13 07:38:31 -04001753 }
1754
Andres More3eaca0d2013-02-25 20:32:52 -05001755 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001756 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001757 pTX_Buffer->byType = 0x00;
1758
1759 pContext->pPacket = NULL;
1760 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001761 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001762
Andres More1cac4a42013-03-18 20:33:50 -05001763 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1764 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001765 }
1766 else {
Andres More1cac4a42013-03-18 20:33:50 -05001767 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001768 }
1769
1770 PIPEnsSendBulkOut(pDevice,pContext);
1771 return CMD_STATUS_PENDING;
1772}
1773
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001774CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1775 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001776{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001777 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001778 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1779 u32 cbHeaderSize = 0;
1780 u16 wTxBufSize = sizeof(STxShortBufHead);
1781 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001782 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001783 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001784 u16 wCurrentRate;
1785 u32 cbFrameBodySize;
1786 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001787 u8 *pbyTxBufferAddr;
1788 PUSB_SEND_CONTEXT pContext;
1789 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001790
Forest Bond92b96792009-06-13 07:38:31 -04001791 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1792 if (NULL == pContext) {
1793 status = CMD_STATUS_RESOURCES;
1794 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1795 return status ;
1796 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001797
1798 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001799 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001800
1801 cbFrameBodySize = pPacket->cbPayloadLen;
1802
1803 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1804 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001805
1806 if (pDevice->byBBType == BB_TYPE_11A) {
1807 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001808 pTxDataHead = (struct vnt_tx_datahead_ab *)
1809 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001810 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001811 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1812 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001813 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001814 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001815 PK_TYPE_11A, false);
Forest Bond92b96792009-06-13 07:38:31 -04001816 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestley558becf2013-08-16 23:50:32 +01001817 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001818 } else {
1819 wCurrentRate = RATE_1M;
1820 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001821 pTxDataHead = (struct vnt_tx_datahead_ab *)
1822 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001823 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001824 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1825 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001826 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001827 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001828 PK_TYPE_11B, false);
Forest Bond92b96792009-06-13 07:38:31 -04001829 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestley558becf2013-08-16 23:50:32 +01001830 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001831 }
1832
1833 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001834 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001835 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001836
Andres More1cac4a42013-03-18 20:33:50 -05001837 pMACHeader->duration_id = 0;
1838 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001839 pDevice->wSeqCounter++ ;
1840 if (pDevice->wSeqCounter > 0x0fff)
1841 pDevice->wSeqCounter = 0;
1842
1843 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1844
Andres More3eaca0d2013-02-25 20:32:52 -05001845 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001846 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001847 pTX_Buffer->byType = 0x01;
1848
1849 pContext->pPacket = NULL;
1850 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001851 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001852
1853 PIPEnsSendBulkOut(pDevice,pContext);
1854 return CMD_STATUS_PENDING;
1855
1856}
1857
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001858void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1859{
1860 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001861 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001862 u8 byPktType;
1863 u8 *pbyTxBufferAddr;
1864 void *pvRTS, *pvCTS, *pvTxDataHd;
1865 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001866 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001867 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001868 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001869 PSTxBufHead pTxBufHead;
1870 u32 cbFrameSize;
1871 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1872 u32 uPadding = 0;
1873 u32 cbMICHDR = 0, uLength = 0;
1874 u32 dwMICKey0, dwMICKey1;
1875 u32 dwMIC_Priority;
1876 u32 *pdwMIC_L, *pdwMIC_R;
1877 u16 wTxBufSize;
1878 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001879 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001880 void *pvRrvTime, *pMICHDR;
1881 u32 wCurrentRate = RATE_1M;
1882 PUWLAN_80211HDR p80211Header;
1883 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001884 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001885 SKeyItem STempKey;
1886 PSKeyItem pTransmitKey = NULL;
1887 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1888 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001889 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001890
Forest Bond92b96792009-06-13 07:38:31 -04001891 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1892
1893 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1894 cbFrameBodySize = 0;
1895 }
1896 else {
1897 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1898 }
1899 p80211Header = (PUWLAN_80211HDR)skb->data;
1900
1901 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1902
1903 if (NULL == pContext) {
1904 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1905 dev_kfree_skb_irq(skb);
1906 return ;
1907 }
1908
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001909 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001910 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001911 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1912 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001913
1914 if (pDevice->byBBType == BB_TYPE_11A) {
1915 wCurrentRate = RATE_6M;
1916 byPktType = PK_TYPE_11A;
1917 } else {
1918 wCurrentRate = RATE_1M;
1919 byPktType = PK_TYPE_11B;
1920 }
1921
1922 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1923 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1924 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1925 // to set power here.
1926 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1927 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1928 } else {
1929 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1930 }
1931
1932 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1933
1934 //Set packet type
1935 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1936 pTxBufHead->wFIFOCtl = 0;
1937 }
1938 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1939 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1940 }
1941 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1942 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1943 }
1944 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1945 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1946 }
1947
1948 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1949 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1950
Andres More22040bb2010-08-02 20:21:44 -03001951 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001952 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001953 if (pDevice->bEnableHostWEP) {
1954 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001955 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001956 }
Forest Bond92b96792009-06-13 07:38:31 -04001957 }
1958 else {
1959 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001960 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001961 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001962 }
Andres More4e9b5e22013-02-12 20:36:30 -05001963 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001964 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1965 };
1966
1967 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1968 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1969
1970 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1971 //Set Preamble type always long
1972 //pDevice->byPreambleType = PREAMBLE_LONG;
1973
1974 // probe-response don't retry
1975 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001976 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001977 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1978 //}
1979 }
1980
1981 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1982
1983 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001984 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001985 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1986 } else {
1987 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1988 }
1989
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001990 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001991 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1992
1993 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1994 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1995 }
1996
1997 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1998 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1999 }
2000
2001 if (cbExtSuppRate >0) {
2002 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2003 }
2004 }
2005
Forest Bond92b96792009-06-13 07:38:31 -04002006 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05002007 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04002008
2009 // Notes:
2010 // Although spec says MMPDU can be fragmented; In most case,
2011 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05002012 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04002013
Forest Bond92b96792009-06-13 07:38:31 -04002014 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2015 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2016 cbIVlen = 4;
2017 cbICVlen = 4;
2018 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2019 }
2020 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2021 cbIVlen = 8;//IV+ExtIV
2022 cbMIClen = 8;
2023 cbICVlen = 4;
2024 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2025 //We need to get seed here for filling TxKey entry.
2026 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2027 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2028 }
2029 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2030 cbIVlen = 8;//RSN Header
2031 cbICVlen = 8;//MIC
2032 cbMICHDR = sizeof(SMICHDRHead);
2033 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002034 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002035 }
2036 //MAC Header should be padding 0 to DW alignment.
2037 uPadding = 4 - (cbMacHdLen%4);
2038 uPadding %= 4;
2039 }
2040
2041 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2042
2043 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002044 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002045 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2046 }
2047 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2048
Forest Bond92b96792009-06-13 07:38:31 -04002049 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002050 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
2051 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
2052 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002053 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002054 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002055 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002056 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2057 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002058 sizeof(struct vnt_cts));
2059 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002060 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002061
2062 }
2063 else {//802.11a/b packet
2064
Malcolm Priestley976467d2013-08-16 23:44:04 +01002065 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
2066 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
2067 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002068 pvRTS = NULL;
2069 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01002070 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2071 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002072 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002073 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002074 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002075 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002076 &(p80211Header->sA3.abyAddr1[0]),
2077 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002078 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002079 &(p80211Header->sA3.abyAddr2[0]),
2080 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002081 //=========================
2082 // No Fragmentation
2083 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002084 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002085
Forest Bond92b96792009-06-13 07:38:31 -04002086 //Fill FIFO,RrvTime,RTS,and CTS
2087 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2088 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2089
2090 //Fill DataHead
2091 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002092 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002093
Andres More1cac4a42013-03-18 20:33:50 -05002094 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002095
2096 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2097
Andres Moreb902fbf2013-02-25 20:32:51 -05002098 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2099 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2100 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002101
2102 // Copy the Packet into a tx Buffer
2103 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2104
2105 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002106 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002107 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2108
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002109 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002110 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2111 if (cbExtSuppRate != 0) {
2112 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2113 memcpy((pbyPayloadHead + cbFrameBodySize),
2114 pMgmt->abyCurrSuppRates,
2115 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2116 );
2117 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2118 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2119 pMgmt->abyCurrExtSuppRates,
2120 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2121 );
2122 }
2123 }
2124
2125 // Set wep
2126 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2127
2128 if (pDevice->bEnableHostWEP) {
2129 pTransmitKey = &STempKey;
2130 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2131 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2132 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2133 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2134 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2135 memcpy(pTransmitKey->abyKey,
2136 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2137 pTransmitKey->uKeyLength
2138 );
2139 }
2140
2141 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2142
Andres More52a7e642013-02-25 20:32:53 -05002143 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2144 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002145
2146 // DO Software Michael
2147 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002148 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002149 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002150 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002151 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2152 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002153
2154 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2155
2156 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2157
Andres More52a7e642013-02-25 20:32:53 -05002158 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2159 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002160
2161 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2162 MIC_vUnInit();
2163
Andres More4e9b5e22013-02-12 20:36:30 -05002164 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002165 *pdwMIC_L = 0;
2166 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002167 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002168 }
2169
2170 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2171 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002172 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2173 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002174
2175 }
2176
Andres Moreb902fbf2013-02-25 20:32:51 -05002177 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05002178 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002179
2180 if (pDevice->bEnableHostWEP) {
2181 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2182 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2183 }
2184
2185 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002186 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002187 }
2188 }
2189
Andres More1cac4a42013-03-18 20:33:50 -05002190 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002191 pDevice->wSeqCounter++ ;
2192 if (pDevice->wSeqCounter > 0x0fff)
2193 pDevice->wSeqCounter = 0;
2194
Forest Bond92b96792009-06-13 07:38:31 -04002195 if (bIsPSPOLL) {
2196 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2197 // of FIFO control header.
2198 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2199 // in the same place of other packet's Duration-field).
2200 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002201 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2202 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2203 cpu_to_le16(p80211Header->sA2.wDurationID);
2204 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2205 cpu_to_le16(p80211Header->sA2.wDurationID);
2206 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002207 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2208 cpu_to_le16(p80211Header->sA2.wDurationID);
2209 }
Forest Bond92b96792009-06-13 07:38:31 -04002210 }
2211
Andres More3eaca0d2013-02-25 20:32:52 -05002212 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002213 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002214 pTX_Buffer->byType = 0x00;
2215
2216 pContext->pPacket = skb;
2217 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002218 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002219
Andres More1cac4a42013-03-18 20:33:50 -05002220 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2221 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002222 }
2223 else {
Andres More1cac4a42013-03-18 20:33:50 -05002224 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002225 }
2226 PIPEnsSendBulkOut(pDevice,pContext);
2227 return ;
2228
2229}
2230
Forest Bond92b96792009-06-13 07:38:31 -04002231//TYPE_AC0DMA data tx
2232/*
2233 * Description:
2234 * Tx packet via AC0DMA(DMA1)
2235 *
2236 * Parameters:
2237 * In:
2238 * pDevice - Pointer to the adapter
2239 * skb - Pointer to tx skb packet
2240 * Out:
2241 * void
2242 *
2243 * Return Value: NULL
2244 */
2245
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002246int nsDMA_tx_packet(struct vnt_private *pDevice,
2247 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002248{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002249 struct net_device_stats *pStats = &pDevice->stats;
2250 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002251 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002252 u32 BytesToWrite = 0, uHeaderLen = 0;
2253 u32 uNodeIndex = 0;
2254 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2255 u16 wAID;
2256 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002257 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002258 PSKeyItem pTransmitKey = NULL;
2259 SKeyItem STempKey;
2260 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002261 int bTKIP_UseGTK = false;
2262 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002263 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002264 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002265 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002266 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002267 u32 status;
2268 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002269 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002270
Forest Bond92b96792009-06-13 07:38:31 -04002271 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2272
2273 if (pDevice->uAssocCount == 0) {
2274 dev_kfree_skb_irq(skb);
2275 return 0;
2276 }
2277
Andres Moreb902fbf2013-02-25 20:32:51 -05002278 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002279 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002280 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002281 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2282
2283 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2284 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2285 // set tx map
2286 pMgmt->abyPSTxMap[0] |= byMask[0];
2287 return 0;
2288 }
Masanari Iida93184692012-08-13 21:21:50 +09002289 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002290
2291 if (pDevice->byBBType != BB_TYPE_11A)
2292 pDevice->wCurrentRate = RATE_2M;
2293 else
2294 pDevice->wCurrentRate = RATE_24M;
2295 // long preamble type
2296 pDevice->byPreambleType = PREAMBLE_SHORT;
2297
2298 }else {
2299
Andres Moreb902fbf2013-02-25 20:32:51 -05002300 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002301
2302 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2303
2304 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2305
2306 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2307 // set tx map
2308 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2309 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2310 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2311 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2312
2313 return 0;
2314 }
2315 // AP rate decided from node
2316 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2317 // tx preamble decided from node
2318
2319 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2320 pDevice->byPreambleType = pDevice->byShortPreamble;
2321
2322 }else {
2323 pDevice->byPreambleType = PREAMBLE_LONG;
2324 }
Andres More4e9b5e22013-02-12 20:36:30 -05002325 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002326 }
2327 }
2328
Andres Moree269fc22013-02-12 20:36:29 -05002329 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002330 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2331 dev_kfree_skb_irq(skb);
2332 return 0;
2333 }
2334 }
2335
2336 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2337
2338 if (pContext == NULL) {
2339 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2340 dev_kfree_skb_irq(skb);
2341 return STATUS_RESOURCES;
2342 }
2343
Andres Moreceb8c5d2013-03-18 20:33:49 -05002344 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002345
2346//mike add:station mode check eapol-key challenge--->
2347{
Andres Moreb902fbf2013-02-25 20:32:51 -05002348 u8 Protocol_Version; //802.1x Authentication
2349 u8 Packet_Type; //802.1x Authentication
2350 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002351 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002352
Charles Clément21ec51f2010-05-18 10:08:14 -07002353 Protocol_Version = skb->data[ETH_HLEN];
2354 Packet_Type = skb->data[ETH_HLEN+1];
2355 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2356 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 -05002357 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002358 /* 802.1x OR eapol-key challenge frame transfer */
2359 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2360 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002361 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002362 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2363 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2364 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002365 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002366 PRINT_K("WPA ");
2367 }
2368 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002369 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002370 PRINT_K("WPA2(re-keying) ");
2371 }
2372 PRINT_K("Authentication completed!!\n");
2373 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002374 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002375 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002376 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002377 PRINT_K("WPA2 Authentication completed!!\n");
2378 }
2379 }
2380 }
2381}
2382//mike add:station mode check eapol-key challenge<---
2383
Andres More4e9b5e22013-02-12 20:36:30 -05002384 if (pDevice->bEncryptionEnable == true) {
2385 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002386 // get Transmit key
2387 do {
2388 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2389 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2390 pbyBSSID = pDevice->abyBSSID;
2391 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002392 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002393 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002394 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2395 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002396 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2397 break;
2398 }
2399 } else {
2400 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2401 break;
2402 }
2403 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002404 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2405 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002406 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2407 for (ii = 0; ii< 6; ii++)
2408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2409 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2410
2411 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002412 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002413 break;
2414 }
2415 // get group key
2416 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002417 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002418 pTransmitKey = NULL;
2419 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2420 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2421 }
2422 else
2423 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2424 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002425 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002426 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2427 }
Andres Moree269fc22013-02-12 20:36:29 -05002428 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002429 }
2430
2431 if (pDevice->bEnableHostWEP) {
2432 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002433 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002434 pTransmitKey = &STempKey;
2435 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2436 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2437 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2438 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2439 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2440 memcpy(pTransmitKey->abyKey,
2441 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2442 pTransmitKey->uKeyLength
2443 );
2444 }
2445 }
2446
Andres Moreb902fbf2013-02-25 20:32:51 -05002447 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002448
2449 if (pDevice->bFixRate) {
2450 if (pDevice->byBBType == BB_TYPE_11B) {
2451 if (pDevice->uConnectionRate >= RATE_11M) {
2452 pDevice->wCurrentRate = RATE_11M;
2453 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002454 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002455 }
2456 } else {
2457 if ((pDevice->byBBType == BB_TYPE_11A) &&
2458 (pDevice->uConnectionRate <= RATE_6M)) {
2459 pDevice->wCurrentRate = RATE_6M;
2460 } else {
2461 if (pDevice->uConnectionRate >= RATE_54M)
2462 pDevice->wCurrentRate = RATE_54M;
2463 else
Andres More3eaca0d2013-02-25 20:32:52 -05002464 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002465 }
2466 }
2467 }
2468 else {
2469 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2470 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002471 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002472 // Multicast use highest data rate
2473 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2474 // preamble type
2475 pDevice->byPreambleType = pDevice->byShortPreamble;
2476 }
2477 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002478 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002479 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2480 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2481 pDevice->byPreambleType = pDevice->byShortPreamble;
2482
2483 }
2484 else {
2485 pDevice->byPreambleType = PREAMBLE_LONG;
2486 }
2487 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2488 }
2489 else {
2490 if (pDevice->byBBType != BB_TYPE_11A)
2491 pDevice->wCurrentRate = RATE_2M;
2492 else
2493 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2494 // abyCurrExtSuppRates[]
2495 pDevice->byPreambleType = PREAMBLE_SHORT;
2496 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2497 }
2498 }
2499 }
2500 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2501 // Infra STA rate decided from AP Node, index = 0
2502 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2503 }
2504 }
2505
Andres Moreceb8c5d2013-03-18 20:33:49 -05002506 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002507 if (pDevice->byBBType != BB_TYPE_11A) {
2508 pDevice->wCurrentRate = RATE_1M;
2509 pDevice->byACKRate = RATE_1M;
2510 pDevice->byTopCCKBasicRate = RATE_1M;
2511 pDevice->byTopOFDMBasicRate = RATE_6M;
2512 } else {
2513 pDevice->wCurrentRate = RATE_6M;
2514 pDevice->byACKRate = RATE_6M;
2515 pDevice->byTopCCKBasicRate = RATE_1M;
2516 pDevice->byTopOFDMBasicRate = RATE_6M;
2517 }
2518 }
Forest Bond92b96792009-06-13 07:38:31 -04002519
Andres More0cbd8d92010-05-06 20:34:29 -03002520 DBG_PRT(MSG_LEVEL_DEBUG,
2521 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2522 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002523
2524 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002525 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002526 }
2527
2528 if (pDevice->wCurrentRate <= RATE_11M) {
2529 byPktType = PK_TYPE_11B;
2530 }
2531
Andres More4e9b5e22013-02-12 20:36:30 -05002532 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002533 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2534 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002535 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002536 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002537 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2538 if (pTransmitKey == NULL) {
2539 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2540 }
2541 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002542 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002543 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2544 }
2545 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002546 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2547 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002548 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002549 }
2550 }
2551 }
2552
Forest Bond92b96792009-06-13 07:38:31 -04002553 if (pDevice->bEnableHostWEP) {
2554 if ((uNodeIndex != 0) &&
2555 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002556 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2557 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002558 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002559 }
2560 }
2561 }
2562 else {
2563
Forest Bond92b96792009-06-13 07:38:31 -04002564 if (pTransmitKey == NULL) {
2565 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002566 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002567 dev_kfree_skb_irq(skb);
2568 pStats->tx_dropped++;
2569 return STATUS_FAILURE;
2570 }
Forest Bond92b96792009-06-13 07:38:31 -04002571 }
2572 }
2573
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002574 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2575
Forest Bond92b96792009-06-13 07:38:31 -04002576 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002577 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002578 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002579 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002580 pDevice->wCurrentRate,
2581 &uHeaderLen, &BytesToWrite
2582 );
2583
Andres Moree269fc22013-02-12 20:36:29 -05002584 if (fConvertedPacket == false) {
2585 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002586 dev_kfree_skb_irq(skb);
2587 return STATUS_FAILURE;
2588 }
2589
Andres More4e9b5e22013-02-12 20:36:30 -05002590 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002591 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002592 bScheduleCommand((void *) pDevice,
2593 WLAN_CMD_MAC_DISPOWERSAVING,
2594 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002595 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002596 }
2597 }
2598
Andres Moreb902fbf2013-02-25 20:32:51 -05002599 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002600 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002601
2602 pContext->pPacket = skb;
2603 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002604 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002605
Andres Moreceb8c5d2013-03-18 20:33:49 -05002606 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 -04002607
2608 status = PIPEnsSendBulkOut(pDevice,pContext);
2609
Andres More4e9b5e22013-02-12 20:36:30 -05002610 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002611 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002612
Andres Moreb902fbf2013-02-25 20:32:51 -05002613 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002614 }
2615
2616 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002617 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002618 dev_kfree_skb_irq(skb);
2619 return STATUS_FAILURE;
2620 }
2621 else
2622 return 0;
2623
2624}
2625
Forest Bond92b96792009-06-13 07:38:31 -04002626/*
2627 * Description:
2628 * Relay packet send (AC1DMA) from rx dpc.
2629 *
2630 * Parameters:
2631 * In:
2632 * pDevice - Pointer to the adapter
2633 * pPacket - Pointer to rx packet
2634 * cbPacketSize - rx ethernet frame size
2635 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002636 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002637 *
Andres More4e9b5e22013-02-12 20:36:30 -05002638 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002639 */
2640
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002641int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2642 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002643{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002644 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002645 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002646 u32 BytesToWrite = 0, uHeaderLen = 0;
2647 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002648 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002649 SKeyItem STempKey;
2650 PSKeyItem pTransmitKey = NULL;
2651 u8 *pbyBSSID;
2652 PUSB_SEND_CONTEXT pContext;
2653 u8 byPktTyp;
2654 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002655 u32 status;
2656 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002657
Forest Bond92b96792009-06-13 07:38:31 -04002658 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2659
2660 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002661 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002662 }
2663
Andres Moreceb8c5d2013-03-18 20:33:49 -05002664 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002665
Andres More4e9b5e22013-02-12 20:36:30 -05002666 if (pDevice->bEncryptionEnable == true) {
2667 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002668 // get group key
2669 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002670 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002671 pTransmitKey = NULL;
2672 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2673 } else {
2674 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2675 }
2676 }
2677
2678 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002679 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002680 pTransmitKey = &STempKey;
2681 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2682 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2683 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2684 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2685 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2686 memcpy(pTransmitKey->abyKey,
2687 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2688 pTransmitKey->uKeyLength
2689 );
2690 }
2691 }
2692
2693 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002694 pContext->bBoolInUse = false;
2695 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002696 }
2697
Andres Moreb902fbf2013-02-25 20:32:51 -05002698 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002699
2700 if (pDevice->bFixRate) {
2701 if (pDevice->byBBType == BB_TYPE_11B) {
2702 if (pDevice->uConnectionRate >= RATE_11M) {
2703 pDevice->wCurrentRate = RATE_11M;
2704 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002705 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002706 }
2707 } else {
2708 if ((pDevice->byBBType == BB_TYPE_11A) &&
2709 (pDevice->uConnectionRate <= RATE_6M)) {
2710 pDevice->wCurrentRate = RATE_6M;
2711 } else {
2712 if (pDevice->uConnectionRate >= RATE_54M)
2713 pDevice->wCurrentRate = RATE_54M;
2714 else
Andres More3eaca0d2013-02-25 20:32:52 -05002715 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002716 }
2717 }
2718 }
2719 else {
2720 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2721 }
2722
Forest Bond92b96792009-06-13 07:38:31 -04002723 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002724 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002725 }
2726
2727 if (pDevice->wCurrentRate <= RATE_11M)
2728 byPktType = PK_TYPE_11B;
2729
Andres Moreabad19d2010-07-12 16:28:32 -03002730 BytesToWrite = uDataLen + ETH_FCS_LEN;
2731
Forest Bond92b96792009-06-13 07:38:31 -04002732 // Convert the packet to an usb frame and copy into our buffer
2733 // and send the irp.
2734
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002735 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2736
Forest Bond92b96792009-06-13 07:38:31 -04002737 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002738 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002739 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2740 pbySkbData, pTransmitKey, uNodeIndex,
2741 pDevice->wCurrentRate,
2742 &uHeaderLen, &BytesToWrite
2743 );
2744
Andres Moree269fc22013-02-12 20:36:29 -05002745 if (fConvertedPacket == false) {
2746 pContext->bBoolInUse = false;
2747 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002748 }
2749
Andres Moreb902fbf2013-02-25 20:32:51 -05002750 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002751 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002752
2753 pContext->pPacket = NULL;
2754 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002755 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002756
Andres Moreceb8c5d2013-03-18 20:33:49 -05002757 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 -04002758
2759 status = PIPEnsSendBulkOut(pDevice,pContext);
2760
Andres More4e9b5e22013-02-12 20:36:30 -05002761 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002762}
2763