blob: 585a2e327151ce841fc8e4cab063edaaa3f39bed [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020034 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040035 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020038 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040039 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
44 *
45 * Revision History:
46 *
47 */
48
Forest Bond92b96792009-06-13 07:38:31 -040049#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "tether.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "baseband.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040064#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070065
Mariano Reingart4a499de2010-10-29 19:15:26 -030066static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040067
Andres More3eaca0d2013-02-25 20:32:52 -050068const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040069 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
70 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
71 };
72
Andres More3eaca0d2013-02-25 20:32:52 -050073const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040074 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
75 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
76 };
Andres More3eaca0d2013-02-25 20:32:52 -050077const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040078 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
79 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
80 };
81
Forest Bond92b96792009-06-13 07:38:31 -040082#define RTSDUR_BB 0
83#define RTSDUR_BA 1
84#define RTSDUR_AA 2
85#define CTSDUR_BA 3
86#define RTSDUR_BA_F0 4
87#define RTSDUR_AA_F0 5
88#define RTSDUR_BA_F1 6
89#define RTSDUR_AA_F1 7
90#define CTSDUR_BA_F0 8
91#define CTSDUR_BA_F1 9
92#define DATADUR_B 10
93#define DATADUR_A 11
94#define DATADUR_A_F0 12
95#define DATADUR_A_F1 13
96
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000097static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
98 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040099
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000100static void *s_vGetFreeContext(struct vnt_private *pDevice);
101
102static void s_vGenerateTxParameter(struct vnt_private *pDevice,
103 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
104 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500105 struct ethhdr *psEthHeader);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000106
107static u32 s_uFillDataHead(struct vnt_private *pDevice,
108 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100109 u32 uDMAIdx, int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400110
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000111static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500112 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000113 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400114
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000115static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
116 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
117 u8 *pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -0400118
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000119static void s_vSWencryption(struct vnt_private *pDevice,
120 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400121
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000122static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
123 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400124
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000125static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
126 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400127
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000128static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
129 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
130 int bDisCRC, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400131
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000132static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
133 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500134 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400135
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000136static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100137 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400138
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100139static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000140 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
141 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400142
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000143static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400144{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000145 PUSB_SEND_CONTEXT pContext = NULL;
146 PUSB_SEND_CONTEXT pReturnContext = NULL;
147 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400148
149 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
150
151 for (ii = 0; ii < pDevice->cbTD; ii++) {
152 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500153 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500154 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100155 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400156 pReturnContext = pContext;
157 break;
158 }
159 }
160 if ( ii == pDevice->cbTD ) {
161 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
162 }
Andres More8611a292010-05-01 14:25:00 -0300163 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400164}
165
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000166static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
167 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400168{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000169 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400170
Andres More4b50fb42010-06-22 21:57:42 -0300171 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400172 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300173 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400174 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
175 else
176 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
177
178 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
179 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300180 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
181 pbyDestAddr,
182 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400183}
184
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000185static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
186 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
187 u16 wPayloadLen, u8 *pMICHDR)
Forest Bond92b96792009-06-13 07:38:31 -0400188{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000189 u32 *pdwIV = (u32 *)pbyIVHead;
190 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
191 u16 wValue;
Andres More1cac4a42013-03-18 20:33:50 -0500192 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000193 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400194
Forest Bond92b96792009-06-13 07:38:31 -0400195 //Fill TXKEY
196 if (pTransmitKey == NULL)
197 return;
198
199 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
200 *pdwIV = pDevice->dwIVCounter;
201 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
202
203 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
204 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
Andres Moreb902fbf2013-02-25 20:32:51 -0500205 memcpy(pDevice->abyPRNG, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700206 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400207 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500208 memcpy(pbyBuf, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700209 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400210 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500211 memcpy(pbyBuf+8, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700212 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400213 }
Jim Lieb3e362592009-08-12 14:54:11 -0700214 memcpy(pDevice->abyPRNG, pbyBuf, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400215 }
216 // Append IV after Mac Header
217 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
Malcolm Priestleyd5bbef72012-11-11 15:53:14 +0000218 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
Forest Bond92b96792009-06-13 07:38:31 -0400219 *pdwIV = cpu_to_le32(*pdwIV);
220 pDevice->dwIVCounter++;
221 if (pDevice->dwIVCounter > WEP_IV_MASK) {
222 pDevice->dwIVCounter = 0;
223 }
224 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
225 pTransmitKey->wTSC15_0++;
226 if (pTransmitKey->wTSC15_0 == 0) {
227 pTransmitKey->dwTSC47_16++;
228 }
229 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
230 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
Jim Lieb3e362592009-08-12 14:54:11 -0700231 memcpy(pbyBuf, pDevice->abyPRNG, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400232 // Make IV
Jim Lieb3e362592009-08-12 14:54:11 -0700233 memcpy(pdwIV, pDevice->abyPRNG, 3);
Forest Bond92b96792009-06-13 07:38:31 -0400234
Andres Moreb902fbf2013-02-25 20:32:51 -0500235 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Forest Bond92b96792009-06-13 07:38:31 -0400236 // Append IV&ExtIV after Mac Header
237 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +0000238 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %x\n",
239 *pdwExtIV);
Forest Bond92b96792009-06-13 07:38:31 -0400240
241 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
242 pTransmitKey->wTSC15_0++;
243 if (pTransmitKey->wTSC15_0 == 0) {
244 pTransmitKey->dwTSC47_16++;
245 }
Jim Lieb3e362592009-08-12 14:54:11 -0700246 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400247
248 // Make IV
249 *pdwIV = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -0500250 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Andres More3eaca0d2013-02-25 20:32:52 -0500251 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
Forest Bond92b96792009-06-13 07:38:31 -0400252 //Append IV&ExtIV after Mac Header
253 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
254
255 //Fill MICHDR0
256 *pMICHDR = 0x59;
Andres Moreb902fbf2013-02-25 20:32:51 -0500257 *((u8 *)(pMICHDR+1)) = 0; // TxPriority
Andres More1cac4a42013-03-18 20:33:50 -0500258 memcpy(pMICHDR+2, &(pMACHeader->addr2[0]), 6);
Andres Moreb902fbf2013-02-25 20:32:51 -0500259 *((u8 *)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
260 *((u8 *)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
261 *((u8 *)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
262 *((u8 *)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
263 *((u8 *)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
264 *((u8 *)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
265 *((u8 *)(pMICHDR+14)) = HIBYTE(wPayloadLen);
266 *((u8 *)(pMICHDR+15)) = LOBYTE(wPayloadLen);
Forest Bond92b96792009-06-13 07:38:31 -0400267
268 //Fill MICHDR1
Andres Moreb902fbf2013-02-25 20:32:51 -0500269 *((u8 *)(pMICHDR+16)) = 0; // HLEN[15:8]
Forest Bond92b96792009-06-13 07:38:31 -0400270 if (pDevice->bLongHeader) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500271 *((u8 *)(pMICHDR+17)) = 28; // HLEN[7:0]
Forest Bond92b96792009-06-13 07:38:31 -0400272 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500273 *((u8 *)(pMICHDR+17)) = 22; // HLEN[7:0]
Forest Bond92b96792009-06-13 07:38:31 -0400274 }
Andres More1cac4a42013-03-18 20:33:50 -0500275 wValue = cpu_to_le16(pMACHeader->frame_control & 0xC78F);
Andres Moreb902fbf2013-02-25 20:32:51 -0500276 memcpy(pMICHDR+18, (u8 *)&wValue, 2); // MSKFRACTL
Andres More1cac4a42013-03-18 20:33:50 -0500277 memcpy(pMICHDR+20, &(pMACHeader->addr1[0]), 6);
278 memcpy(pMICHDR+26, &(pMACHeader->addr2[0]), 6);
Forest Bond92b96792009-06-13 07:38:31 -0400279
280 //Fill MICHDR2
Andres More1cac4a42013-03-18 20:33:50 -0500281 memcpy(pMICHDR+32, &(pMACHeader->addr3[0]), 6);
282 wValue = pMACHeader->seq_ctrl;
Forest Bond92b96792009-06-13 07:38:31 -0400283 wValue &= 0x000F;
284 wValue = cpu_to_le16(wValue);
Andres Moreb902fbf2013-02-25 20:32:51 -0500285 memcpy(pMICHDR+38, (u8 *)&wValue, 2); // MSKSEQCTL
Forest Bond92b96792009-06-13 07:38:31 -0400286 if (pDevice->bLongHeader) {
Andres More1cac4a42013-03-18 20:33:50 -0500287 memcpy(pMICHDR+40, &(pMACHeader->addr4[0]), 6);
Forest Bond92b96792009-06-13 07:38:31 -0400288 }
289 }
290}
291
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000292static void s_vSWencryption(struct vnt_private *pDevice,
293 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400294{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000295 u32 cbICVlen = 4;
296 u32 dwICV = 0xffffffff;
297 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400298
299 if (pTransmitKey == NULL)
300 return;
301
302 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
303 //=======================================================================
304 // Append ICV after payload
305 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500306 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400307 // finally, we must invert dwCRC to get the correct answer
308 *pdwICV = cpu_to_le32(~dwICV);
309 // RC4 encryption
310 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
311 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
312 //=======================================================================
313 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
314 //=======================================================================
315 //Append ICV after payload
316 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500317 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400318 // finally, we must invert dwCRC to get the correct answer
319 *pdwICV = cpu_to_le32(~dwICV);
320 // RC4 encryption
321 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
322 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
323 //=======================================================================
324 }
325}
326
Forest Bond92b96792009-06-13 07:38:31 -0400327/*byPktType : PK_TYPE_11A 0
328 PK_TYPE_11B 1
329 PK_TYPE_11GB 2
330 PK_TYPE_11GA 3
331*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000332static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
333 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400334{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000335 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400336
337 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
338 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500339 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400340 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500341 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400342 }
343
344 if (bNeedAck) {
345 return (uDataTime + pDevice->uSIFS + uAckTime);
346 }
347 else {
348 return uDataTime;
349 }
350}
351
352//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000353static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
354 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400355{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000356 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400357
358 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
359
Forest Bond92b96792009-06-13 07:38:31 -0400360 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
361 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
362 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
363 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
364 }
365 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
366 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
367 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
368 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
369 }
370 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
371 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
372 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
373 }
374 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
375 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
376 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
377 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
378 return uRrvTime;
379 }
380
381 //RTSRrvTime
382 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
383 return uRrvTime;
384}
385
386//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000387static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100388 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400389{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100390 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400391
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100392 if (bNeedAck) {
393 if (byDurType == DATADUR_B)
394 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
395 byPktType, 14, pDevice->byTopCCKBasicRate);
396 else
397 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
398 byPktType, 14, pDevice->byTopOFDMBasicRate);
399 return pDevice->uSIFS + uAckTime;
400 }
Forest Bond92b96792009-06-13 07:38:31 -0400401
Forest Bond92b96792009-06-13 07:38:31 -0400402 return 0;
403}
404
Forest Bond92b96792009-06-13 07:38:31 -0400405//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100406static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000407 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
408 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400409{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000410 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400411
Forest Bond92b96792009-06-13 07:38:31 -0400412 switch (byDurType) {
413
414 case RTSDUR_BB: //RTSDuration_bb
415 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
416 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
417 break;
418
419 case RTSDUR_BA: //RTSDuration_ba
420 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
421 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
422 break;
423
424 case RTSDUR_AA: //RTSDuration_aa
425 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
426 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
427 break;
428
429 case CTSDUR_BA: //CTSDuration_ba
430 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
431 break;
432
433 case RTSDUR_BA_F0: //RTSDuration_ba_f0
434 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
435 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
436 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
437 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
438 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
439 }
440 break;
441
442 case RTSDUR_AA_F0: //RTSDuration_aa_f0
443 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
444 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
445 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
446 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
447 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
448 }
449 break;
450
451 case RTSDUR_BA_F1: //RTSDuration_ba_f1
452 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
453 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
454 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
455 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
456 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
457 }
458 break;
459
460 case RTSDUR_AA_F1: //RTSDuration_aa_f1
461 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
462 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
463 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
464 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
465 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
466 }
467 break;
468
469 case CTSDUR_BA_F0: //CTSDuration_ba_f0
470 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
471 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
472 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
473 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
474 }
475 break;
476
477 case CTSDUR_BA_F1: //CTSDuration_ba_f1
478 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
479 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
480 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
481 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
482 }
483 break;
484
485 default:
486 break;
487 }
488
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100489 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400490}
491
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000492static u32 s_uFillDataHead(struct vnt_private *pDevice,
493 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100494 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400495{
496
497 if (pTxDataHead == NULL) {
498 return 0;
499 }
500
501 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Andres Morebd2bc4c2010-08-02 23:35:57 -0300502 if ((uDMAIdx == TYPE_ATIMDMA) || (uDMAIdx == TYPE_BEACONDMA)) {
503 PSTxDataHead_ab pBuf = (PSTxDataHead_ab) pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400504 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700505 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500506 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400507 );
508 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100509 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
510 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400511 if(uDMAIdx!=TYPE_ATIMDMA) {
512 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
513 }
514 return (pBuf->wDuration);
515 }
516 else { // DATA & MANAGE Frame
517 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +0100518 struct vnt_tx_datahead_g *pBuf =
519 (struct vnt_tx_datahead_g *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400520 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700521 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500522 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400523 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700524 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500525 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400526 );
527 //Get Duration and TimeStamp
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100528 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
529 byPktType, bNeedAck);
530 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
531 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400532
533 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
534 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
535 return (pBuf->wDuration_a);
536 } else {
537 // Auto Fallback
538 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
539 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700540 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500541 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400542 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700543 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500544 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400545 );
546 //Get Duration and TimeStamp
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100547 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
548 byPktType, bNeedAck);
549 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
550 PK_TYPE_11B, bNeedAck);
551 pBuf->wDuration_a_f0 = (u16)s_uGetDataDuration(pDevice,
552 DATADUR_A_F0, byPktType, bNeedAck);
553 pBuf->wDuration_a_f1 = (u16)s_uGetDataDuration(pDevice,
554 DATADUR_A_F1, byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400555 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
556 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
557 return (pBuf->wDuration_a);
558 } //if (byFBOption == AUTO_FB_NONE)
559 }
560 }
561 else if (byPktType == PK_TYPE_11A) {
562 if ((byFBOption != AUTO_FB_NONE) && (uDMAIdx != TYPE_ATIMDMA) && (uDMAIdx != TYPE_BEACONDMA)) {
563 // Auto Fallback
564 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
565 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700566 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500567 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400568 );
569 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100570 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
571 byPktType, bNeedAck);
572 pBuf->wDuration_f0 = (u16)s_uGetDataDuration(pDevice,
573 DATADUR_A_F0, byPktType, bNeedAck);
574 pBuf->wDuration_f1 = (u16)s_uGetDataDuration(pDevice,
575 DATADUR_A_F1, byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400576 if(uDMAIdx!=TYPE_ATIMDMA) {
577 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
578 }
579 return (pBuf->wDuration);
580 } else {
581 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
582 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700583 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500584 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400585 );
586 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100587 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
588 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400589
590 if(uDMAIdx!=TYPE_ATIMDMA) {
591 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
592 }
593 return (pBuf->wDuration);
594 }
595 }
596 else if (byPktType == PK_TYPE_11B) {
597 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
598 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700599 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500600 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400601 );
602 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100603 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
604 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400605 if (uDMAIdx != TYPE_ATIMDMA) {
606 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
607 }
608 return (pBuf->wDuration);
609 }
610 return 0;
611}
612
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000613static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
614 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500615 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400616{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000617 u32 uRTSFrameLen = 20;
618 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400619
Forest Bond92b96792009-06-13 07:38:31 -0400620 if (pvRTS == NULL)
621 return;
622
623 if (bDisCRC) {
624 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
625 // in this case we need to decrease its length by 4.
626 uRTSFrameLen -= 4;
627 }
628
Masanari Iida93184692012-08-13 21:21:50 +0900629 // 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 -0400630 // Otherwise, we need to modified codes for them.
631 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
632 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100633 struct vnt_rts_g *pBuf = (struct vnt_rts_g *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400634 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700635 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500636 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400637 );
638 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700639 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500640 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400641 );
642 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
643 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100644 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
645 cbFrameLength, PK_TYPE_11B,
646 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
647 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
648 cbFrameLength, byPktType,
649 wCurrentRate, bNeedAck, byFBOption);
650 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
651 cbFrameLength, byPktType,
652 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100653 pBuf->data.duration = pBuf->wDuration_aa;
654 /*Get RTS Frame body */
655 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400656
Malcolm Priestley07738932013-08-05 22:08:05 +0100657 if (pDevice->eOPMode == OP_MODE_ADHOC ||
658 pDevice->eOPMode == OP_MODE_AP)
659 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
660 else
661 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Andres More9a0e7562010-04-13 21:54:48 -0300662
Malcolm Priestley07738932013-08-05 22:08:05 +0100663 if (pDevice->eOPMode == OP_MODE_AP)
664 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
665 else
666 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400667 }
668 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100669 struct vnt_rts_g_fb *pBuf = (struct vnt_rts_g_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400670 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700671 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500672 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400673 );
674 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700675 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500676 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400677 );
678 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
679 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100680 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
681 cbFrameLength, PK_TYPE_11B,
682 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
683 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
684 cbFrameLength, byPktType,
685 wCurrentRate, bNeedAck, byFBOption);
686 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
687 cbFrameLength, byPktType,
688 wCurrentRate, bNeedAck, byFBOption);
689 pBuf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
690 RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
691 bNeedAck, byFBOption);
692 pBuf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(pDevice,
693 RTSDUR_AA_F0, cbFrameLength, byPktType,
694 wCurrentRate, bNeedAck, byFBOption);
695 pBuf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
696 RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
697 bNeedAck, byFBOption);
698 pBuf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(pDevice,
699 RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate,
700 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100701 pBuf->data.duration = pBuf->wDuration_aa;
702 /*Get RTS Frame body*/
703 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400704
Malcolm Priestley07738932013-08-05 22:08:05 +0100705 if (pDevice->eOPMode == OP_MODE_ADHOC ||
706 pDevice->eOPMode == OP_MODE_AP)
707 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
708 else
709 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400710
Malcolm Priestley07738932013-08-05 22:08:05 +0100711 if (pDevice->eOPMode == OP_MODE_AP)
712 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
713 else
714 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400715 } // if (byFBOption == AUTO_FB_NONE)
716 }
717 else if (byPktType == PK_TYPE_11A) {
718 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100719 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400720 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700721 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500722 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400723 );
724 pBuf->wTransmitLength = cpu_to_le16(wLen);
725 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100726 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
727 cbFrameLength, byPktType, wCurrentRate,
728 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100729 pBuf->data.duration = pBuf->wDuration;
730 /* Get RTS Frame body */
731 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400732
Malcolm Priestley07738932013-08-05 22:08:05 +0100733 if (pDevice->eOPMode == OP_MODE_ADHOC ||
734 pDevice->eOPMode == OP_MODE_AP)
735 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
736 else
737 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400738
Malcolm Priestley07738932013-08-05 22:08:05 +0100739 if (pDevice->eOPMode == OP_MODE_AP)
740 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
741 else
742 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400743 }
744 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100745 struct vnt_rts_a_fb *pBuf = (struct vnt_rts_a_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400746 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700747 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500748 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400749 );
750 pBuf->wTransmitLength = cpu_to_le16(wLen);
751 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100752 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
753 cbFrameLength, byPktType, wCurrentRate,
754 bNeedAck, byFBOption);
755 pBuf->wRTSDuration_f0 = s_uGetRTSCTSDuration(pDevice,
756 RTSDUR_AA_F0, cbFrameLength, byPktType,
757 wCurrentRate, bNeedAck, byFBOption);
758 pBuf->wRTSDuration_f1 = s_uGetRTSCTSDuration(pDevice,
759 RTSDUR_AA_F1, cbFrameLength, byPktType,
760 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100761 pBuf->data.duration = pBuf->wDuration;
762 /* Get RTS Frame body */
763 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400764
Malcolm Priestley07738932013-08-05 22:08:05 +0100765 if (pDevice->eOPMode == OP_MODE_ADHOC ||
766 pDevice->eOPMode == OP_MODE_AP)
767 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
768 else
769 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
770
771 if (pDevice->eOPMode == OP_MODE_AP)
772 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
773 else
774 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400775 }
776 }
777 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100778 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400779 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700780 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500781 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400782 );
783 pBuf->wTransmitLength = cpu_to_le16(wLen);
784 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100785 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
786 cbFrameLength, byPktType, wCurrentRate,
787 bNeedAck, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400788
Malcolm Priestley07738932013-08-05 22:08:05 +0100789 pBuf->data.duration = pBuf->wDuration;
790 /* Get RTS Frame body */
791 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400792
Malcolm Priestley07738932013-08-05 22:08:05 +0100793 if (pDevice->eOPMode == OP_MODE_ADHOC ||
794 pDevice->eOPMode == OP_MODE_AP)
795 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
796 else
797 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
798
799 if (pDevice->eOPMode == OP_MODE_AP)
800 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
801 else
802 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400803 }
804}
805
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000806static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
807 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
808 int bDisCRC, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400809{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000810 u32 uCTSFrameLen = 14;
811 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400812
813 if (pvCTS == NULL) {
814 return;
815 }
816
817 if (bDisCRC) {
818 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
819 // in this case we need to decrease its length by 4.
820 uCTSFrameLen -= 4;
821 }
822
823 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
824 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
825 // Auto Fall back
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100826 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Forest Bond92b96792009-06-13 07:38:31 -0400827 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700828 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500829 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400830 );
831 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100832 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
833 cbFrameLength, byPktType,
834 wCurrentRate, bNeedAck, byFBOption);
835 /* Get CTSDuration_ba_f0 */
836 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
837 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
838 bNeedAck, byFBOption);
839 /* Get CTSDuration_ba_f1 */
840 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
841 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
842 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100843 /* Get CTS Frame body */
844 pBuf->data.duration = pBuf->wDuration_ba;
845 pBuf->data.frame_control = TYPE_CTL_CTS;
846 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400847 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100848 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Forest Bond92b96792009-06-13 07:38:31 -0400849 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700850 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500851 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400852 );
853 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100854 /* Get CTSDuration_ba */
855 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
856 CTSDUR_BA, cbFrameLength, byPktType,
857 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100858 /*Get CTS Frame body*/
859 pBuf->data.duration = pBuf->wDuration_ba;
860 pBuf->data.frame_control = TYPE_CTL_CTS;
861 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400862 }
863 }
864}
865
Forest Bond92b96792009-06-13 07:38:31 -0400866/*+
867 *
868 * Description:
869 * Generate FIFO control for MAC & Baseband controller
870 *
871 * Parameters:
872 * In:
873 * pDevice - Pointer to adpater
874 * pTxDataHead - Transmit Data Buffer
875 * pTxBufHead - pTxBufHead
876 * pvRrvTime - pvRrvTime
877 * pvRTS - RTS Buffer
878 * pCTS - CTS Buffer
879 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
880 * bNeedACK - If need ACK
881 * uDMAIdx - DMA Index
882 * Out:
883 * none
884 *
885 * Return Value: none
886 *
887-*/
Andres Morecc856e62010-05-17 21:34:01 -0300888
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000889static void s_vGenerateTxParameter(struct vnt_private *pDevice,
890 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
891 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500892 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400893{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000894 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
895 u16 wFifoCtl;
Andres Moree269fc22013-02-12 20:36:29 -0500896 int bDisCRC = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000897 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400898
899 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
900 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
901 pFifoHead->wReserved = wCurrentRate;
902 wFifoCtl = pFifoHead->wFIFOCtl;
903
904 if (wFifoCtl & FIFOCTL_CRCDIS) {
Andres More4e9b5e22013-02-12 20:36:30 -0500905 bDisCRC = true;
Forest Bond92b96792009-06-13 07:38:31 -0400906 }
907
908 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
909 byFBOption = AUTO_FB_0;
910 }
911 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
912 byFBOption = AUTO_FB_1;
913 }
914
915 if (pDevice->bLongHeader)
916 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
917
918 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
919
920 if (pvRTS != NULL) { //RTS_need
921 //Fill RsvTime
922 if (pvRrvTime) {
Malcolm Priestley6398a592013-08-16 21:26:55 +0100923 struct vnt_rrv_time_rts *pBuf =
924 (struct vnt_rrv_time_rts *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500925 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
926 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
927 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
928 pBuf->wTxRrvTime_a = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
929 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 -0400930 }
931 //Fill RTS
932 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
933 }
934 else {//RTS_needless, PCF mode
935
936 //Fill RsvTime
937 if (pvRrvTime) {
Malcolm Priestley4f990052013-08-16 23:38:57 +0100938 struct vnt_rrv_time_cts *pBuf =
939 (struct vnt_rrv_time_cts *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500940 pBuf->wTxRrvTime_a = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
941 pBuf->wTxRrvTime_b = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
942 pBuf->wCTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
Forest Bond92b96792009-06-13 07:38:31 -0400943 }
944 //Fill CTS
945 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
946 }
947 }
948 else if (byPktType == PK_TYPE_11A) {
949
950 if (pvRTS != NULL) {//RTS_need, non PCF mode
951 //Fill RsvTime
952 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100953 struct vnt_rrv_time_ab *pBuf =
954 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500955 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
956 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400957 }
958 //Fill RTS
959 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
960 }
961 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
962 //Fill RsvTime
963 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100964 struct vnt_rrv_time_ab *pBuf =
965 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500966 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400967 }
968 }
969 }
970 else if (byPktType == PK_TYPE_11B) {
971
972 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
973 //Fill RsvTime
974 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100975 struct vnt_rrv_time_ab *pBuf =
976 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500977 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
978 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400979 }
980 //Fill RTS
981 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
982 }
983 else { //RTS_needless, non PCF mode
984 //Fill RsvTime
985 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100986 struct vnt_rrv_time_ab *pBuf =
987 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500988 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400989 }
990 }
991 }
992 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
993}
994/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500995 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500996 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300997 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400998*/
999
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001000static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01001001 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
1002 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
1003 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
1004 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -04001005{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001006 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1007 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001008 u32 cb802_1_H_len;
1009 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
1010 u32 cbFCSlen = 4, cbMICHDR = 0;
1011 int bNeedACK, bRTS;
1012 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
1013 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1014 u8 abySNAP_Bridgetunnel[ETH_ALEN]
1015 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1016 u32 uDuration;
1017 u32 cbHeaderLength = 0, uPadding = 0;
1018 void *pvRrvTime;
1019 PSMICHDRHead pMICHDR;
1020 void *pvRTS;
1021 void *pvCTS;
1022 void *pvTxDataHd;
1023 u8 byFBOption = AUTO_FB_NONE, byFragType;
1024 u16 wTxBufSize;
1025 u32 dwMICKey0, dwMICKey1, dwMIC_Priority, dwCRC;
1026 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001027 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -04001028
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001029 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001030
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001031 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001032 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1033 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001034 }
Forest Bond92b96792009-06-13 07:38:31 -04001035
Forest Bond92b96792009-06-13 07:38:31 -04001036 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001037 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001038 if (pDevice->dwDiagRefCount == 0) {
1039 cb802_1_H_len = 8;
1040 } else {
1041 cb802_1_H_len = 2;
1042 }
1043 } else {
1044 cb802_1_H_len = 0;
1045 }
1046
Charles Clément21ec51f2010-05-18 10:08:14 -07001047 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001048
1049 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001050 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001051
1052 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001053 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001054 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1055 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001056 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1057 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001058 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001059 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001060 pTxBufHead->wFIFOCtl =
1061 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1062 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001063 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001064 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1065 }
Forest Bond92b96792009-06-13 07:38:31 -04001066 }
1067 else {
1068 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001069 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001070 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1071 }
1072 } //if (pDevice->dwDiagRefCount != 0) {
1073
1074 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1075
1076 //Set FIFOCTL_LHEAD
1077 if (pDevice->bLongHeader)
1078 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1079
1080 if (pDevice->bSoftwareGenCrcErr) {
1081 pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS; // set tx descriptors to NO hardware CRC
1082 }
1083
1084 //Set FRAGCTL_MACHDCNT
1085 if (pDevice->bLongHeader) {
1086 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1087 } else {
1088 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1089 }
Andres More3eaca0d2013-02-25 20:32:52 -05001090 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001091
1092 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001093 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001094 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1095 }
1096
1097 //Set Auto Fallback Ctl
1098 if (wCurrentRate >= RATE_18M) {
1099 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1100 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1101 byFBOption = AUTO_FB_0;
1102 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1103 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1104 byFBOption = AUTO_FB_1;
1105 }
1106 }
1107
Andres More4e9b5e22013-02-12 20:36:30 -05001108 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001109 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1110 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1111 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1112 }
1113 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1114 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1115 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1116 }
1117 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1118 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1119 }
1120 }
1121 }
1122
Forest Bond92b96792009-06-13 07:38:31 -04001123 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1124 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1125 cbIVlen = 4;
1126 cbICVlen = 4;
1127 }
1128 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1129 cbIVlen = 8;//IV+ExtIV
1130 cbMIClen = 8;
1131 cbICVlen = 4;
1132 }
1133 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1134 cbIVlen = 8;//RSN Header
1135 cbICVlen = 8;//MIC
1136 cbMICHDR = sizeof(SMICHDRHead);
1137 }
Andres Moree269fc22013-02-12 20:36:29 -05001138 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001139 //MAC Header should be padding 0 to DW alignment.
1140 uPadding = 4 - (cbMACHdLen%4);
1141 uPadding %= 4;
1142 }
1143 }
1144
1145 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1146
Andres Moree269fc22013-02-12 20:36:29 -05001147 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1148 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001149 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001150 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001151 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1152 }
1153
Andres Moreb902fbf2013-02-25 20:32:51 -05001154 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001155 wTxBufSize = sizeof(STxBufHead);
1156 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1157 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001158 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001159 pvRrvTime = (struct vnt_rrv_time_rts *)
1160 (pbyTxBufferAddr + wTxBufSize);
1161 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1162 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001163 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001164 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001165 pvCTS = NULL;
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001166 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1167 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1168 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001169 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001170 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001171 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001172 }
1173 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001174 pvRrvTime = (struct vnt_rrv_time_cts *)
1175 (pbyTxBufferAddr + wTxBufSize);
1176 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1177 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001178 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001179 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001180 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001181 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1182 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1183 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001184 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1185 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001186 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001187 }
1188 } else {
1189 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001190 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001191 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1192 wTxBufSize);
1193 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1194 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001195 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001196 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001197 pvCTS = NULL;
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001198 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001199 sizeof(struct vnt_rrv_time_rts) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001200 sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001201 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1202 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
1203 sizeof(STxDataHead_g_FB);
Forest Bond92b96792009-06-13 07:38:31 -04001204 }
Andres Moree269fc22013-02-12 20:36:29 -05001205 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001206 pvRrvTime = (struct vnt_rrv_time_cts *)
1207 (pbyTxBufferAddr + wTxBufSize);
1208 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1209 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001210 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001211 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001212 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001213 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001214 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1215 cbMICHDR + sizeof(struct vnt_cts_fb));
1216 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001217 cbMICHDR + sizeof(struct vnt_cts_fb) +
1218 sizeof(STxDataHead_g_FB);
Forest Bond92b96792009-06-13 07:38:31 -04001219 }
1220 } // Auto Fall Back
1221 }
1222 else {//802.11a/b packet
1223 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001224 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001225 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1226 wTxBufSize);
1227 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1228 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001229 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001230 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001231 pvCTS = NULL;
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001232 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001233 sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001234 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001235 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1236 cbMICHDR + sizeof(struct vnt_rts_ab) +
1237 sizeof(STxDataHead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001238 }
Andres Moree269fc22013-02-12 20:36:29 -05001239 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001240 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1241 wTxBufSize);
1242 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1243 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001244 pvRTS = NULL;
1245 pvCTS = NULL;
Malcolm Priestley976467d2013-08-16 23:44:04 +01001246 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize +
1247 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1248 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1249 cbMICHDR + sizeof(STxDataHead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001250 }
1251 } else {
1252 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001253 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001254 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1255 wTxBufSize);
1256 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1257 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001258 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001259 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001260 pvCTS = NULL;
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001261 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001262 sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001263 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001264 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1265 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
1266 sizeof(STxDataHead_a_FB);
Forest Bond92b96792009-06-13 07:38:31 -04001267 }
Andres Moree269fc22013-02-12 20:36:29 -05001268 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001269 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1270 wTxBufSize);
1271 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1272 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001273 pvRTS = NULL;
1274 pvCTS = NULL;
Malcolm Priestley976467d2013-08-16 23:44:04 +01001275 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize +
1276 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1277 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1278 cbMICHDR + sizeof(STxDataHead_a_FB);
Forest Bond92b96792009-06-13 07:38:31 -04001279 }
1280 } // Auto Fall Back
1281 }
1282
Andres Moreb902fbf2013-02-25 20:32:51 -05001283 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1284 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1285 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001286
Forest Bond92b96792009-06-13 07:38:31 -04001287 //=========================
1288 // No Fragmentation
1289 //=========================
1290 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1291 byFragType = FRAGCTL_NONFRAG;
1292 //uDMAIdx = TYPE_AC0DMA;
1293 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1294
Forest Bond92b96792009-06-13 07:38:31 -04001295 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001296 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1297 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001298 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1299 //Fill DataHead
1300 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001301 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001302 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001303 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001304 byFragType, uDMAIdx, 0);
1305
Andres More4e9b5e22013-02-12 20:36:30 -05001306 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001307 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001308 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001309 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001310
1311 if (pDevice->bEnableHostWEP) {
1312 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1313 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1314 }
1315 }
1316
1317 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001318 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001319 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001320 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1321 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001322 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001323 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001324 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001325 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001326 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001327 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001328 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001329 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001330 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001331
1332 }
1333
1334 }
1335
Forest Bond92b96792009-06-13 07:38:31 -04001336 if (pPacket != NULL) {
1337 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001338 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001339 (pPacket + ETH_HLEN),
1340 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001341 );
1342
1343 } else {
1344 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001345 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001346 }
1347
Andres More4e9b5e22013-02-12 20:36:30 -05001348 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001349
1350 ///////////////////////////////////////////////////////////////////
1351
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001352 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1353 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1354 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1355 }
Forest Bond92b96792009-06-13 07:38:31 -04001356 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001357 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1358 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001359 }
1360 else {
Andres More52a7e642013-02-25 20:32:53 -05001361 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1362 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001363 }
1364 // DO Software Michael
1365 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001366 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001367 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001368 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001369 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1370 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001371
1372 ///////////////////////////////////////////////////////////////////
1373
1374 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1375 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001376 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001377 //}
1378 //DBG_PRN_GRP12(("\n\n\n"));
1379
1380 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1381
Andres More52a7e642013-02-25 20:32:53 -05001382 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1383 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001384
1385 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1386 MIC_vUnInit();
1387
Andres More4e9b5e22013-02-12 20:36:30 -05001388 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001389 *pdwMIC_L = 0;
1390 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001391 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001392 }
1393 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1394 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1395 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1396 }
1397
Andres More4e9b5e22013-02-12 20:36:30 -05001398 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001399
Andres More3eaca0d2013-02-25 20:32:52 -05001400 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001401
Andres More4e9b5e22013-02-12 20:36:30 -05001402 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1403 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1404 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001405 cbFrameSize -= cbICVlen;
1406 }
1407
Andres More4e9b5e22013-02-12 20:36:30 -05001408 if (pDevice->bSoftwareGenCrcErr == true) {
Andres Morecc856e62010-05-17 21:34:01 -03001409 unsigned int cbLen;
Andres More52a7e642013-02-25 20:32:53 -05001410 u32 * pdwCRC;
Forest Bond92b96792009-06-13 07:38:31 -04001411
1412 dwCRC = 0xFFFFFFFFL;
1413 cbLen = cbFrameSize - cbFCSlen;
1414 // calculate CRC, and wrtie CRC value to end of TD
1415 dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
Andres More52a7e642013-02-25 20:32:53 -05001416 pdwCRC = (u32 *)(pbyMacHdr + cbLen);
Forest Bond92b96792009-06-13 07:38:31 -04001417 // finally, we must invert dwCRC to get the correct answer
1418 *pdwCRC = ~dwCRC;
1419 // Force Error
1420 *pdwCRC -= 1;
1421 } else {
1422 cbFrameSize -= cbFCSlen;
1423 }
1424
1425 *pcbHeaderLen = cbHeaderLength;
1426 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1427
Forest Bond92b96792009-06-13 07:38:31 -04001428 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001429 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001430
Andres More4e9b5e22013-02-12 20:36:30 -05001431 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001432
1433}
1434
Forest Bond92b96792009-06-13 07:38:31 -04001435/*+
1436 *
1437 * Description:
1438 * Translate 802.3 to 802.11 header
1439 *
1440 * Parameters:
1441 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001442 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001443 * dwTxBufferAddr - Transmit Buffer
1444 * pPacket - Packet from upper layer
1445 * cbPacketSize - Transmit Data Length
1446 * Out:
1447 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1448 * pcbAppendPayload - size of append payload for 802.1H translation
1449 *
1450 * Return Value: none
1451 *
1452-*/
1453
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001454static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001455 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001456 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001457{
Andres More1cac4a42013-03-18 20:33:50 -05001458 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001459
Forest Bond92b96792009-06-13 07:38:31 -04001460 if (uDMAIdx == TYPE_ATIMDMA) {
Andres More1cac4a42013-03-18 20:33:50 -05001461 pMACHeader->frame_control = TYPE_802_11_ATIM;
Forest Bond92b96792009-06-13 07:38:31 -04001462 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001463 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001464 }
1465
1466 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001467 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001468 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001469 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001470 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1471 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001472 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001473 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001474 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001475 } else {
1476 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001477 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001478 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001479 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001480 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001481 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001482 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001483 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001484 &(pDevice->abyBSSID[0]),
1485 ETH_ALEN);
1486 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001487 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001488 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001489 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001490 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001491 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001492 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001493 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001494 &(pDevice->abyBSSID[0]),
1495 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001496 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001497 }
1498 }
1499
1500 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001501 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001502
Andres More1cac4a42013-03-18 20:33:50 -05001503 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001504
1505 if (pDevice->bLongHeader) {
1506 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001507 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001508 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001509 }
Andres More1cac4a42013-03-18 20:33:50 -05001510 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001511
1512 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001513 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001514
1515 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1516 pDevice->wSeqCounter++;
1517 if (pDevice->wSeqCounter > 0x0fff)
1518 pDevice->wSeqCounter = 0;
1519 }
1520
1521 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001522 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001523 }
1524}
1525
Forest Bond92b96792009-06-13 07:38:31 -04001526/*+
1527 *
1528 * Description:
1529 * Request instructs a MAC to transmit a 802.11 management packet through
1530 * the adapter onto the medium.
1531 *
1532 * Parameters:
1533 * In:
1534 * hDeviceContext - Pointer to the adapter
1535 * pPacket - A pointer to a descriptor for the packet to transmit
1536 * Out:
1537 * none
1538 *
Andres Moree269fc22013-02-12 20:36:29 -05001539 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001540 *
1541-*/
1542
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001543CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1544 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001545{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001546 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001547 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001548 PSTxBufHead pTxBufHead;
1549 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001550 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001551 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001552 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001553 u8 byPktType, *pbyTxBufferAddr;
1554 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1555 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001556 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001557 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1558 u32 uPadding = 0;
1559 u16 wTxBufSize;
1560 u32 cbMacHdLen;
1561 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001562
Forest Bond92b96792009-06-13 07:38:31 -04001563 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1564
1565 if (NULL == pContext) {
1566 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1567 return CMD_STATUS_RESOURCES;
1568 }
1569
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001570 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001571 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001572 cbFrameBodySize = pPacket->cbPayloadLen;
1573 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1574 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001575
1576 if (pDevice->byBBType == BB_TYPE_11A) {
1577 wCurrentRate = RATE_6M;
1578 byPktType = PK_TYPE_11A;
1579 } else {
1580 wCurrentRate = RATE_1M;
1581 byPktType = PK_TYPE_11B;
1582 }
1583
1584 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1585 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1586 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1587 // to set power here.
1588 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1589 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1590 } else {
1591 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1592 }
1593 pDevice->wCurrentRate = wCurrentRate;
1594
Forest Bond92b96792009-06-13 07:38:31 -04001595 //Set packet type
1596 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1597 pTxBufHead->wFIFOCtl = 0;
1598 }
1599 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1600 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1601 }
1602 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1603 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1604 }
1605 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1606 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1607 }
1608
1609 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1610 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1611
Andres More22040bb2010-08-02 20:21:44 -03001612 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001613 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001614 }
1615 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001616 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001617 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1618 };
1619
1620 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1621 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1622
1623 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1624 //Set Preamble type always long
1625 //pDevice->byPreambleType = PREAMBLE_LONG;
1626 // probe-response don't retry
1627 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001628 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001629 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1630 //}
1631 }
1632
1633 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1634
1635 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001636 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001637 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1638 } else {
1639 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1640 }
1641
1642 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001643 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001644
1645 // Notes:
1646 // Although spec says MMPDU can be fragmented; In most case,
1647 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001648 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001649
1650 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1651 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1652 cbIVlen = 4;
1653 cbICVlen = 4;
1654 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1655 }
1656 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1657 cbIVlen = 8;//IV+ExtIV
1658 cbMIClen = 8;
1659 cbICVlen = 4;
1660 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1661 //We need to get seed here for filling TxKey entry.
1662 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1663 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1664 }
1665 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1666 cbIVlen = 8;//RSN Header
1667 cbICVlen = 8;//MIC
1668 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001669 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001670 }
1671 //MAC Header should be padding 0 to DW alignment.
1672 uPadding = 4 - (cbMacHdLen%4);
1673 uPadding %= 4;
1674 }
1675
1676 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1677
1678 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001679 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001680 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1681 }
1682 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1683
1684 //Set RrvTime/RTS/CTS Buffer
1685 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1686
Malcolm Priestley4f990052013-08-16 23:38:57 +01001687 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001688 pMICHDR = NULL;
1689 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001690 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001691 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001692 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001693 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1694 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001695 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001696 }
1697 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001698 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001699 pMICHDR = NULL;
1700 pvRTS = NULL;
1701 pCTS = NULL;
Malcolm Priestley976467d2013-08-16 23:44:04 +01001702 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize +
1703 sizeof(struct vnt_rrv_time_ab));
1704 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1705 sizeof(STxDataHead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001706 }
1707
Andres Moreceb8c5d2013-03-18 20:33:49 -05001708 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001709 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1710 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001711 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001712 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1713 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001714 //=========================
1715 // No Fragmentation
1716 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001717 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001718
Forest Bond92b96792009-06-13 07:38:31 -04001719 //Fill FIFO,RrvTime,RTS,and CTS
1720 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1721 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1722
1723 //Fill DataHead
1724 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001725 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001726
Andres More1cac4a42013-03-18 20:33:50 -05001727 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001728
1729 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1730
1731 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001732 u8 * pbyIVHead;
1733 u8 * pbyPayloadHead;
1734 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001735 PSKeyItem pTransmitKey = NULL;
1736
Andres Moreb902fbf2013-02-25 20:32:51 -05001737 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1738 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001739 do {
1740 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001741 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001742 pbyBSSID = pDevice->abyBSSID;
1743 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001744 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001745 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001746 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001747 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1748 break;
1749 }
1750 } else {
1751 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1752 break;
1753 }
1754 }
1755 // get group key
1756 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001757 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001758 pTransmitKey = NULL;
1759 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1760 } else {
1761 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1762 }
Andres Moree269fc22013-02-12 20:36:29 -05001763 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001764 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001765 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001766 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001767
Jim Lieb3e362592009-08-12 14:54:11 -07001768 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001769 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001770 cbFrameBodySize);
1771 }
1772 else {
1773 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001774 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001775 }
1776
Andres More1cac4a42013-03-18 20:33:50 -05001777 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001778 pDevice->wSeqCounter++ ;
1779 if (pDevice->wSeqCounter > 0x0fff)
1780 pDevice->wSeqCounter = 0;
1781
1782 if (bIsPSPOLL) {
1783 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001784 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001785 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1786 // in the same place of other packet's Duration-field).
1787 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001788 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1789 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1790 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1791 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1792 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1793 } else {
Forest Bond92b96792009-06-13 07:38:31 -04001794 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1795 }
1796 }
1797
Andres More3eaca0d2013-02-25 20:32:52 -05001798 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001799 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001800 pTX_Buffer->byType = 0x00;
1801
1802 pContext->pPacket = NULL;
1803 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001804 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001805
Andres More1cac4a42013-03-18 20:33:50 -05001806 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1807 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001808 }
1809 else {
Andres More1cac4a42013-03-18 20:33:50 -05001810 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001811 }
1812
1813 PIPEnsSendBulkOut(pDevice,pContext);
1814 return CMD_STATUS_PENDING;
1815}
1816
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001817CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1818 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001819{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001820 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001821 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1822 u32 cbHeaderSize = 0;
1823 u16 wTxBufSize = sizeof(STxShortBufHead);
1824 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001825 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001826 PSTxDataHead_ab pTxDataHead;
1827 u16 wCurrentRate;
1828 u32 cbFrameBodySize;
1829 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001830 u8 *pbyTxBufferAddr;
1831 PUSB_SEND_CONTEXT pContext;
1832 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001833
Forest Bond92b96792009-06-13 07:38:31 -04001834 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1835 if (NULL == pContext) {
1836 status = CMD_STATUS_RESOURCES;
1837 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1838 return status ;
1839 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001840
1841 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001842 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001843
1844 cbFrameBodySize = pPacket->cbPayloadLen;
1845
1846 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1847 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001848
1849 if (pDevice->byBBType == BB_TYPE_11A) {
1850 wCurrentRate = RATE_6M;
1851 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
1852 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001853 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
Andres More3eaca0d2013-02-25 20:32:52 -05001854 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001855 );
1856 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +01001857 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice,
1858 DATADUR_A, PK_TYPE_11A, false));
Forest Bond92b96792009-06-13 07:38:31 -04001859 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
1860 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
1861 } else {
1862 wCurrentRate = RATE_1M;
1863 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1864 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
1865 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001866 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -05001867 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001868 );
1869 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +01001870 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice,
1871 DATADUR_B, PK_TYPE_11B, false));
Forest Bond92b96792009-06-13 07:38:31 -04001872 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
1873 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
1874 }
1875
1876 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001877 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001878 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001879
Andres More1cac4a42013-03-18 20:33:50 -05001880 pMACHeader->duration_id = 0;
1881 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001882 pDevice->wSeqCounter++ ;
1883 if (pDevice->wSeqCounter > 0x0fff)
1884 pDevice->wSeqCounter = 0;
1885
1886 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1887
Andres More3eaca0d2013-02-25 20:32:52 -05001888 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001889 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001890 pTX_Buffer->byType = 0x01;
1891
1892 pContext->pPacket = NULL;
1893 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001894 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001895
1896 PIPEnsSendBulkOut(pDevice,pContext);
1897 return CMD_STATUS_PENDING;
1898
1899}
1900
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001901void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1902{
1903 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001904 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001905 u8 byPktType;
1906 u8 *pbyTxBufferAddr;
1907 void *pvRTS, *pvCTS, *pvTxDataHd;
1908 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001909 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001910 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001911 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001912 PSTxBufHead pTxBufHead;
1913 u32 cbFrameSize;
1914 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1915 u32 uPadding = 0;
1916 u32 cbMICHDR = 0, uLength = 0;
1917 u32 dwMICKey0, dwMICKey1;
1918 u32 dwMIC_Priority;
1919 u32 *pdwMIC_L, *pdwMIC_R;
1920 u16 wTxBufSize;
1921 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001922 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001923 void *pvRrvTime, *pMICHDR;
1924 u32 wCurrentRate = RATE_1M;
1925 PUWLAN_80211HDR p80211Header;
1926 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001927 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001928 SKeyItem STempKey;
1929 PSKeyItem pTransmitKey = NULL;
1930 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1931 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001932 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001933
Forest Bond92b96792009-06-13 07:38:31 -04001934 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1935
1936 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1937 cbFrameBodySize = 0;
1938 }
1939 else {
1940 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1941 }
1942 p80211Header = (PUWLAN_80211HDR)skb->data;
1943
1944 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1945
1946 if (NULL == pContext) {
1947 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1948 dev_kfree_skb_irq(skb);
1949 return ;
1950 }
1951
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001952 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001953 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001954 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1955 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001956
1957 if (pDevice->byBBType == BB_TYPE_11A) {
1958 wCurrentRate = RATE_6M;
1959 byPktType = PK_TYPE_11A;
1960 } else {
1961 wCurrentRate = RATE_1M;
1962 byPktType = PK_TYPE_11B;
1963 }
1964
1965 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1966 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1967 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1968 // to set power here.
1969 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1970 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1971 } else {
1972 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1973 }
1974
1975 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1976
1977 //Set packet type
1978 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1979 pTxBufHead->wFIFOCtl = 0;
1980 }
1981 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1982 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1983 }
1984 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1985 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1986 }
1987 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1988 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1989 }
1990
1991 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1992 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1993
Andres More22040bb2010-08-02 20:21:44 -03001994 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001995 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001996 if (pDevice->bEnableHostWEP) {
1997 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001998 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001999 }
Forest Bond92b96792009-06-13 07:38:31 -04002000 }
2001 else {
2002 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05002003 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05002004 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07002005 }
Andres More4e9b5e22013-02-12 20:36:30 -05002006 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002007 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2008 };
2009
2010 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2011 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2012
2013 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2014 //Set Preamble type always long
2015 //pDevice->byPreambleType = PREAMBLE_LONG;
2016
2017 // probe-response don't retry
2018 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05002019 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04002020 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2021 //}
2022 }
2023
2024 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2025
2026 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05002027 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04002028 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2029 } else {
2030 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2031 }
2032
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002033 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04002034 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2035
2036 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
2037 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2038 }
2039
2040 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
2041 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2042 }
2043
2044 if (cbExtSuppRate >0) {
2045 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2046 }
2047 }
2048
Forest Bond92b96792009-06-13 07:38:31 -04002049 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05002050 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04002051
2052 // Notes:
2053 // Although spec says MMPDU can be fragmented; In most case,
2054 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05002055 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04002056
Forest Bond92b96792009-06-13 07:38:31 -04002057 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2058 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2059 cbIVlen = 4;
2060 cbICVlen = 4;
2061 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2062 }
2063 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2064 cbIVlen = 8;//IV+ExtIV
2065 cbMIClen = 8;
2066 cbICVlen = 4;
2067 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2068 //We need to get seed here for filling TxKey entry.
2069 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2070 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2071 }
2072 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2073 cbIVlen = 8;//RSN Header
2074 cbICVlen = 8;//MIC
2075 cbMICHDR = sizeof(SMICHDRHead);
2076 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002077 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002078 }
2079 //MAC Header should be padding 0 to DW alignment.
2080 uPadding = 4 - (cbMacHdLen%4);
2081 uPadding %= 4;
2082 }
2083
2084 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2085
2086 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002087 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002088 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2089 }
2090 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2091
Forest Bond92b96792009-06-13 07:38:31 -04002092 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002093 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
2094 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
2095 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002096 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002097 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002098 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002099 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2100 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002101 sizeof(struct vnt_cts));
2102 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002103 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002104
2105 }
2106 else {//802.11a/b packet
2107
Malcolm Priestley976467d2013-08-16 23:44:04 +01002108 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
2109 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
2110 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002111 pvRTS = NULL;
2112 pvCTS = NULL;
Malcolm Priestley976467d2013-08-16 23:44:04 +01002113 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize +
2114 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
2115 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
2116 sizeof(STxDataHead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002117 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002118 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002119 &(p80211Header->sA3.abyAddr1[0]),
2120 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002121 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002122 &(p80211Header->sA3.abyAddr2[0]),
2123 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002124 //=========================
2125 // No Fragmentation
2126 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002127 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002128
Forest Bond92b96792009-06-13 07:38:31 -04002129 //Fill FIFO,RrvTime,RTS,and CTS
2130 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2131 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2132
2133 //Fill DataHead
2134 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002135 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002136
Andres More1cac4a42013-03-18 20:33:50 -05002137 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002138
2139 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2140
Andres Moreb902fbf2013-02-25 20:32:51 -05002141 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2142 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2143 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002144
2145 // Copy the Packet into a tx Buffer
2146 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2147
2148 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002149 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002150 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2151
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002152 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002153 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2154 if (cbExtSuppRate != 0) {
2155 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2156 memcpy((pbyPayloadHead + cbFrameBodySize),
2157 pMgmt->abyCurrSuppRates,
2158 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2159 );
2160 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2161 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2162 pMgmt->abyCurrExtSuppRates,
2163 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2164 );
2165 }
2166 }
2167
2168 // Set wep
2169 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2170
2171 if (pDevice->bEnableHostWEP) {
2172 pTransmitKey = &STempKey;
2173 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2174 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2175 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2176 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2177 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2178 memcpy(pTransmitKey->abyKey,
2179 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2180 pTransmitKey->uKeyLength
2181 );
2182 }
2183
2184 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2185
Andres More52a7e642013-02-25 20:32:53 -05002186 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2187 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002188
2189 // DO Software Michael
2190 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002191 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002192 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002193 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002194 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2195 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002196
2197 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2198
2199 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2200
Andres More52a7e642013-02-25 20:32:53 -05002201 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2202 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002203
2204 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2205 MIC_vUnInit();
2206
Andres More4e9b5e22013-02-12 20:36:30 -05002207 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002208 *pdwMIC_L = 0;
2209 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002210 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002211 }
2212
2213 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2214 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002215 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2216 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002217
2218 }
2219
Andres Moreb902fbf2013-02-25 20:32:51 -05002220 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05002221 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002222
2223 if (pDevice->bEnableHostWEP) {
2224 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2225 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2226 }
2227
2228 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002229 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002230 }
2231 }
2232
Andres More1cac4a42013-03-18 20:33:50 -05002233 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002234 pDevice->wSeqCounter++ ;
2235 if (pDevice->wSeqCounter > 0x0fff)
2236 pDevice->wSeqCounter = 0;
2237
Forest Bond92b96792009-06-13 07:38:31 -04002238 if (bIsPSPOLL) {
2239 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2240 // of FIFO control header.
2241 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2242 // in the same place of other packet's Duration-field).
2243 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002244 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2245 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2246 cpu_to_le16(p80211Header->sA2.wDurationID);
2247 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2248 cpu_to_le16(p80211Header->sA2.wDurationID);
2249 } else {
Forest Bond92b96792009-06-13 07:38:31 -04002250 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
2251 }
2252 }
2253
Andres More3eaca0d2013-02-25 20:32:52 -05002254 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002255 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002256 pTX_Buffer->byType = 0x00;
2257
2258 pContext->pPacket = skb;
2259 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002260 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002261
Andres More1cac4a42013-03-18 20:33:50 -05002262 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2263 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002264 }
2265 else {
Andres More1cac4a42013-03-18 20:33:50 -05002266 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002267 }
2268 PIPEnsSendBulkOut(pDevice,pContext);
2269 return ;
2270
2271}
2272
Forest Bond92b96792009-06-13 07:38:31 -04002273//TYPE_AC0DMA data tx
2274/*
2275 * Description:
2276 * Tx packet via AC0DMA(DMA1)
2277 *
2278 * Parameters:
2279 * In:
2280 * pDevice - Pointer to the adapter
2281 * skb - Pointer to tx skb packet
2282 * Out:
2283 * void
2284 *
2285 * Return Value: NULL
2286 */
2287
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002288int nsDMA_tx_packet(struct vnt_private *pDevice,
2289 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002290{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002291 struct net_device_stats *pStats = &pDevice->stats;
2292 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002293 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002294 u32 BytesToWrite = 0, uHeaderLen = 0;
2295 u32 uNodeIndex = 0;
2296 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2297 u16 wAID;
2298 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002299 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002300 PSKeyItem pTransmitKey = NULL;
2301 SKeyItem STempKey;
2302 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002303 int bTKIP_UseGTK = false;
2304 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002305 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002306 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002307 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002308 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002309 u32 status;
2310 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002311 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002312
Forest Bond92b96792009-06-13 07:38:31 -04002313 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2314
2315 if (pDevice->uAssocCount == 0) {
2316 dev_kfree_skb_irq(skb);
2317 return 0;
2318 }
2319
Andres Moreb902fbf2013-02-25 20:32:51 -05002320 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002321 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002322 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002323 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2324
2325 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2326 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2327 // set tx map
2328 pMgmt->abyPSTxMap[0] |= byMask[0];
2329 return 0;
2330 }
Masanari Iida93184692012-08-13 21:21:50 +09002331 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002332
2333 if (pDevice->byBBType != BB_TYPE_11A)
2334 pDevice->wCurrentRate = RATE_2M;
2335 else
2336 pDevice->wCurrentRate = RATE_24M;
2337 // long preamble type
2338 pDevice->byPreambleType = PREAMBLE_SHORT;
2339
2340 }else {
2341
Andres Moreb902fbf2013-02-25 20:32:51 -05002342 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002343
2344 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2345
2346 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2347
2348 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2349 // set tx map
2350 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2351 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2352 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2353 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2354
2355 return 0;
2356 }
2357 // AP rate decided from node
2358 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2359 // tx preamble decided from node
2360
2361 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2362 pDevice->byPreambleType = pDevice->byShortPreamble;
2363
2364 }else {
2365 pDevice->byPreambleType = PREAMBLE_LONG;
2366 }
Andres More4e9b5e22013-02-12 20:36:30 -05002367 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002368 }
2369 }
2370
Andres Moree269fc22013-02-12 20:36:29 -05002371 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002372 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2373 dev_kfree_skb_irq(skb);
2374 return 0;
2375 }
2376 }
2377
2378 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2379
2380 if (pContext == NULL) {
2381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2382 dev_kfree_skb_irq(skb);
2383 return STATUS_RESOURCES;
2384 }
2385
Andres Moreceb8c5d2013-03-18 20:33:49 -05002386 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002387
2388//mike add:station mode check eapol-key challenge--->
2389{
Andres Moreb902fbf2013-02-25 20:32:51 -05002390 u8 Protocol_Version; //802.1x Authentication
2391 u8 Packet_Type; //802.1x Authentication
2392 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002393 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002394
Charles Clément21ec51f2010-05-18 10:08:14 -07002395 Protocol_Version = skb->data[ETH_HLEN];
2396 Packet_Type = skb->data[ETH_HLEN+1];
2397 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2398 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 -05002399 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002400 /* 802.1x OR eapol-key challenge frame transfer */
2401 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2402 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002403 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002404 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2405 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2406 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002407 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002408 PRINT_K("WPA ");
2409 }
2410 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002411 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002412 PRINT_K("WPA2(re-keying) ");
2413 }
2414 PRINT_K("Authentication completed!!\n");
2415 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002416 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002417 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002418 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002419 PRINT_K("WPA2 Authentication completed!!\n");
2420 }
2421 }
2422 }
2423}
2424//mike add:station mode check eapol-key challenge<---
2425
Andres More4e9b5e22013-02-12 20:36:30 -05002426 if (pDevice->bEncryptionEnable == true) {
2427 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002428 // get Transmit key
2429 do {
2430 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2431 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2432 pbyBSSID = pDevice->abyBSSID;
2433 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002434 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002435 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002436 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2437 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002438 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2439 break;
2440 }
2441 } else {
2442 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2443 break;
2444 }
2445 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002446 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2447 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002448 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2449 for (ii = 0; ii< 6; ii++)
2450 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2451 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2452
2453 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002454 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002455 break;
2456 }
2457 // get group key
2458 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002459 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002460 pTransmitKey = NULL;
2461 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2462 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2463 }
2464 else
2465 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2466 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002467 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002468 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2469 }
Andres Moree269fc22013-02-12 20:36:29 -05002470 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002471 }
2472
2473 if (pDevice->bEnableHostWEP) {
2474 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002475 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002476 pTransmitKey = &STempKey;
2477 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2478 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2479 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2480 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2481 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2482 memcpy(pTransmitKey->abyKey,
2483 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2484 pTransmitKey->uKeyLength
2485 );
2486 }
2487 }
2488
Andres Moreb902fbf2013-02-25 20:32:51 -05002489 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002490
2491 if (pDevice->bFixRate) {
2492 if (pDevice->byBBType == BB_TYPE_11B) {
2493 if (pDevice->uConnectionRate >= RATE_11M) {
2494 pDevice->wCurrentRate = RATE_11M;
2495 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002496 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002497 }
2498 } else {
2499 if ((pDevice->byBBType == BB_TYPE_11A) &&
2500 (pDevice->uConnectionRate <= RATE_6M)) {
2501 pDevice->wCurrentRate = RATE_6M;
2502 } else {
2503 if (pDevice->uConnectionRate >= RATE_54M)
2504 pDevice->wCurrentRate = RATE_54M;
2505 else
Andres More3eaca0d2013-02-25 20:32:52 -05002506 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002507 }
2508 }
2509 }
2510 else {
2511 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2512 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002513 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002514 // Multicast use highest data rate
2515 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2516 // preamble type
2517 pDevice->byPreambleType = pDevice->byShortPreamble;
2518 }
2519 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002520 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002521 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2522 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2523 pDevice->byPreambleType = pDevice->byShortPreamble;
2524
2525 }
2526 else {
2527 pDevice->byPreambleType = PREAMBLE_LONG;
2528 }
2529 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2530 }
2531 else {
2532 if (pDevice->byBBType != BB_TYPE_11A)
2533 pDevice->wCurrentRate = RATE_2M;
2534 else
2535 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2536 // abyCurrExtSuppRates[]
2537 pDevice->byPreambleType = PREAMBLE_SHORT;
2538 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2539 }
2540 }
2541 }
2542 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2543 // Infra STA rate decided from AP Node, index = 0
2544 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2545 }
2546 }
2547
Andres Moreceb8c5d2013-03-18 20:33:49 -05002548 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002549 if (pDevice->byBBType != BB_TYPE_11A) {
2550 pDevice->wCurrentRate = RATE_1M;
2551 pDevice->byACKRate = RATE_1M;
2552 pDevice->byTopCCKBasicRate = RATE_1M;
2553 pDevice->byTopOFDMBasicRate = RATE_6M;
2554 } else {
2555 pDevice->wCurrentRate = RATE_6M;
2556 pDevice->byACKRate = RATE_6M;
2557 pDevice->byTopCCKBasicRate = RATE_1M;
2558 pDevice->byTopOFDMBasicRate = RATE_6M;
2559 }
2560 }
Forest Bond92b96792009-06-13 07:38:31 -04002561
Andres More0cbd8d92010-05-06 20:34:29 -03002562 DBG_PRT(MSG_LEVEL_DEBUG,
2563 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2564 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002565
2566 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002567 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002568 }
2569
2570 if (pDevice->wCurrentRate <= RATE_11M) {
2571 byPktType = PK_TYPE_11B;
2572 }
2573
Andres More4e9b5e22013-02-12 20:36:30 -05002574 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002575 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2576 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002577 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002578 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002579 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2580 if (pTransmitKey == NULL) {
2581 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2582 }
2583 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002584 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002585 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2586 }
2587 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002588 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2589 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002590 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002591 }
2592 }
2593 }
2594
Forest Bond92b96792009-06-13 07:38:31 -04002595 if (pDevice->bEnableHostWEP) {
2596 if ((uNodeIndex != 0) &&
2597 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002598 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2599 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002600 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002601 }
2602 }
2603 }
2604 else {
2605
Forest Bond92b96792009-06-13 07:38:31 -04002606 if (pTransmitKey == NULL) {
2607 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002608 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002609 dev_kfree_skb_irq(skb);
2610 pStats->tx_dropped++;
2611 return STATUS_FAILURE;
2612 }
Forest Bond92b96792009-06-13 07:38:31 -04002613 }
2614 }
2615
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002616 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2617
Forest Bond92b96792009-06-13 07:38:31 -04002618 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002619 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002620 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002621 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002622 pDevice->wCurrentRate,
2623 &uHeaderLen, &BytesToWrite
2624 );
2625
Andres Moree269fc22013-02-12 20:36:29 -05002626 if (fConvertedPacket == false) {
2627 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002628 dev_kfree_skb_irq(skb);
2629 return STATUS_FAILURE;
2630 }
2631
Andres More4e9b5e22013-02-12 20:36:30 -05002632 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002633 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002634 bScheduleCommand((void *) pDevice,
2635 WLAN_CMD_MAC_DISPOWERSAVING,
2636 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002637 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002638 }
2639 }
2640
Andres Moreb902fbf2013-02-25 20:32:51 -05002641 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002642 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002643
2644 pContext->pPacket = skb;
2645 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002646 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002647
Andres Moreceb8c5d2013-03-18 20:33:49 -05002648 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 -04002649
2650 status = PIPEnsSendBulkOut(pDevice,pContext);
2651
Andres More4e9b5e22013-02-12 20:36:30 -05002652 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002653 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002654
Andres Moreb902fbf2013-02-25 20:32:51 -05002655 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002656 }
2657
2658 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002659 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002660 dev_kfree_skb_irq(skb);
2661 return STATUS_FAILURE;
2662 }
2663 else
2664 return 0;
2665
2666}
2667
Forest Bond92b96792009-06-13 07:38:31 -04002668/*
2669 * Description:
2670 * Relay packet send (AC1DMA) from rx dpc.
2671 *
2672 * Parameters:
2673 * In:
2674 * pDevice - Pointer to the adapter
2675 * pPacket - Pointer to rx packet
2676 * cbPacketSize - rx ethernet frame size
2677 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002678 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002679 *
Andres More4e9b5e22013-02-12 20:36:30 -05002680 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002681 */
2682
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002683int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2684 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002685{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002686 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002687 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002688 u32 BytesToWrite = 0, uHeaderLen = 0;
2689 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002690 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002691 SKeyItem STempKey;
2692 PSKeyItem pTransmitKey = NULL;
2693 u8 *pbyBSSID;
2694 PUSB_SEND_CONTEXT pContext;
2695 u8 byPktTyp;
2696 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002697 u32 status;
2698 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002699
Forest Bond92b96792009-06-13 07:38:31 -04002700 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2701
2702 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002703 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002704 }
2705
Andres Moreceb8c5d2013-03-18 20:33:49 -05002706 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002707
Andres More4e9b5e22013-02-12 20:36:30 -05002708 if (pDevice->bEncryptionEnable == true) {
2709 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002710 // get group key
2711 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002712 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002713 pTransmitKey = NULL;
2714 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2715 } else {
2716 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2717 }
2718 }
2719
2720 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002721 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002722 pTransmitKey = &STempKey;
2723 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2724 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2725 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2726 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2727 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2728 memcpy(pTransmitKey->abyKey,
2729 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2730 pTransmitKey->uKeyLength
2731 );
2732 }
2733 }
2734
2735 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002736 pContext->bBoolInUse = false;
2737 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002738 }
2739
Andres Moreb902fbf2013-02-25 20:32:51 -05002740 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002741
2742 if (pDevice->bFixRate) {
2743 if (pDevice->byBBType == BB_TYPE_11B) {
2744 if (pDevice->uConnectionRate >= RATE_11M) {
2745 pDevice->wCurrentRate = RATE_11M;
2746 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002747 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002748 }
2749 } else {
2750 if ((pDevice->byBBType == BB_TYPE_11A) &&
2751 (pDevice->uConnectionRate <= RATE_6M)) {
2752 pDevice->wCurrentRate = RATE_6M;
2753 } else {
2754 if (pDevice->uConnectionRate >= RATE_54M)
2755 pDevice->wCurrentRate = RATE_54M;
2756 else
Andres More3eaca0d2013-02-25 20:32:52 -05002757 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002758 }
2759 }
2760 }
2761 else {
2762 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2763 }
2764
Forest Bond92b96792009-06-13 07:38:31 -04002765 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002766 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002767 }
2768
2769 if (pDevice->wCurrentRate <= RATE_11M)
2770 byPktType = PK_TYPE_11B;
2771
Andres Moreabad19d2010-07-12 16:28:32 -03002772 BytesToWrite = uDataLen + ETH_FCS_LEN;
2773
Forest Bond92b96792009-06-13 07:38:31 -04002774 // Convert the packet to an usb frame and copy into our buffer
2775 // and send the irp.
2776
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002777 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2778
Forest Bond92b96792009-06-13 07:38:31 -04002779 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002780 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002781 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2782 pbySkbData, pTransmitKey, uNodeIndex,
2783 pDevice->wCurrentRate,
2784 &uHeaderLen, &BytesToWrite
2785 );
2786
Andres Moree269fc22013-02-12 20:36:29 -05002787 if (fConvertedPacket == false) {
2788 pContext->bBoolInUse = false;
2789 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002790 }
2791
Andres Moreb902fbf2013-02-25 20:32:51 -05002792 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002793 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002794
2795 pContext->pPacket = NULL;
2796 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002797 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002798
Andres Moreceb8c5d2013-03-18 20:33:49 -05002799 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 -04002800
2801 status = PIPEnsSendBulkOut(pDevice,pContext);
2802
Andres More4e9b5e22013-02-12 20:36:30 -05002803 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002804}
2805