blob: b21a4963f90ddb31312d9046f43eecaf02af63cf [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) {
518 PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
519 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700520 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500521 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400522 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700523 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500524 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400525 );
526 //Get Duration and TimeStamp
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100527 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
528 byPktType, bNeedAck);
529 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
530 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400531
532 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
533 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
534 return (pBuf->wDuration_a);
535 } else {
536 // Auto Fallback
537 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
538 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700539 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500540 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400541 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700542 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500543 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400544 );
545 //Get Duration and TimeStamp
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100546 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
547 byPktType, bNeedAck);
548 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
549 PK_TYPE_11B, bNeedAck);
550 pBuf->wDuration_a_f0 = (u16)s_uGetDataDuration(pDevice,
551 DATADUR_A_F0, byPktType, bNeedAck);
552 pBuf->wDuration_a_f1 = (u16)s_uGetDataDuration(pDevice,
553 DATADUR_A_F1, byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400554 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
555 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
556 return (pBuf->wDuration_a);
557 } //if (byFBOption == AUTO_FB_NONE)
558 }
559 }
560 else if (byPktType == PK_TYPE_11A) {
561 if ((byFBOption != AUTO_FB_NONE) && (uDMAIdx != TYPE_ATIMDMA) && (uDMAIdx != TYPE_BEACONDMA)) {
562 // Auto Fallback
563 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
564 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700565 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500566 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400567 );
568 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100569 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
570 byPktType, bNeedAck);
571 pBuf->wDuration_f0 = (u16)s_uGetDataDuration(pDevice,
572 DATADUR_A_F0, byPktType, bNeedAck);
573 pBuf->wDuration_f1 = (u16)s_uGetDataDuration(pDevice,
574 DATADUR_A_F1, byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400575 if(uDMAIdx!=TYPE_ATIMDMA) {
576 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
577 }
578 return (pBuf->wDuration);
579 } else {
580 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
581 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700582 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500583 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400584 );
585 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100586 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
587 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400588
589 if(uDMAIdx!=TYPE_ATIMDMA) {
590 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
591 }
592 return (pBuf->wDuration);
593 }
594 }
595 else if (byPktType == PK_TYPE_11B) {
596 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
597 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700598 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500599 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400600 );
601 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100602 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
603 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400604 if (uDMAIdx != TYPE_ATIMDMA) {
605 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
606 }
607 return (pBuf->wDuration);
608 }
609 return 0;
610}
611
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000612static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
613 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500614 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400615{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000616 u32 uRTSFrameLen = 20;
617 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400618
Forest Bond92b96792009-06-13 07:38:31 -0400619 if (pvRTS == NULL)
620 return;
621
622 if (bDisCRC) {
623 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
624 // in this case we need to decrease its length by 4.
625 uRTSFrameLen -= 4;
626 }
627
Masanari Iida93184692012-08-13 21:21:50 +0900628 // 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 -0400629 // Otherwise, we need to modified codes for them.
630 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
631 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100632 struct vnt_rts_g *pBuf = (struct vnt_rts_g *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400633 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700634 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500635 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400636 );
637 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700638 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500639 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400640 );
641 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
642 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100643 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
644 cbFrameLength, PK_TYPE_11B,
645 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
646 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
647 cbFrameLength, byPktType,
648 wCurrentRate, bNeedAck, byFBOption);
649 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
650 cbFrameLength, byPktType,
651 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100652 pBuf->data.duration = pBuf->wDuration_aa;
653 /*Get RTS Frame body */
654 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400655
Malcolm Priestley07738932013-08-05 22:08:05 +0100656 if (pDevice->eOPMode == OP_MODE_ADHOC ||
657 pDevice->eOPMode == OP_MODE_AP)
658 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
659 else
660 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Andres More9a0e7562010-04-13 21:54:48 -0300661
Malcolm Priestley07738932013-08-05 22:08:05 +0100662 if (pDevice->eOPMode == OP_MODE_AP)
663 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
664 else
665 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400666 }
667 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100668 struct vnt_rts_g_fb *pBuf = (struct vnt_rts_g_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400669 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700670 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500671 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400672 );
673 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700674 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500675 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400676 );
677 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
678 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100679 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
680 cbFrameLength, PK_TYPE_11B,
681 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
682 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
683 cbFrameLength, byPktType,
684 wCurrentRate, bNeedAck, byFBOption);
685 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
686 cbFrameLength, byPktType,
687 wCurrentRate, bNeedAck, byFBOption);
688 pBuf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
689 RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
690 bNeedAck, byFBOption);
691 pBuf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(pDevice,
692 RTSDUR_AA_F0, cbFrameLength, byPktType,
693 wCurrentRate, bNeedAck, byFBOption);
694 pBuf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
695 RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
696 bNeedAck, byFBOption);
697 pBuf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(pDevice,
698 RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate,
699 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100700 pBuf->data.duration = pBuf->wDuration_aa;
701 /*Get RTS Frame body*/
702 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400703
Malcolm Priestley07738932013-08-05 22:08:05 +0100704 if (pDevice->eOPMode == OP_MODE_ADHOC ||
705 pDevice->eOPMode == OP_MODE_AP)
706 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
707 else
708 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400709
Malcolm Priestley07738932013-08-05 22:08:05 +0100710 if (pDevice->eOPMode == OP_MODE_AP)
711 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
712 else
713 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400714 } // if (byFBOption == AUTO_FB_NONE)
715 }
716 else if (byPktType == PK_TYPE_11A) {
717 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100718 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400719 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700720 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500721 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400722 );
723 pBuf->wTransmitLength = cpu_to_le16(wLen);
724 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100725 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
726 cbFrameLength, byPktType, wCurrentRate,
727 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100728 pBuf->data.duration = pBuf->wDuration;
729 /* Get RTS Frame body */
730 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400731
Malcolm Priestley07738932013-08-05 22:08:05 +0100732 if (pDevice->eOPMode == OP_MODE_ADHOC ||
733 pDevice->eOPMode == OP_MODE_AP)
734 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
735 else
736 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400737
Malcolm Priestley07738932013-08-05 22:08:05 +0100738 if (pDevice->eOPMode == OP_MODE_AP)
739 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
740 else
741 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400742 }
743 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100744 struct vnt_rts_a_fb *pBuf = (struct vnt_rts_a_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400745 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700746 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500747 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400748 );
749 pBuf->wTransmitLength = cpu_to_le16(wLen);
750 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100751 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
752 cbFrameLength, byPktType, wCurrentRate,
753 bNeedAck, byFBOption);
754 pBuf->wRTSDuration_f0 = s_uGetRTSCTSDuration(pDevice,
755 RTSDUR_AA_F0, cbFrameLength, byPktType,
756 wCurrentRate, bNeedAck, byFBOption);
757 pBuf->wRTSDuration_f1 = s_uGetRTSCTSDuration(pDevice,
758 RTSDUR_AA_F1, cbFrameLength, byPktType,
759 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100760 pBuf->data.duration = pBuf->wDuration;
761 /* Get RTS Frame body */
762 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400763
Malcolm Priestley07738932013-08-05 22:08:05 +0100764 if (pDevice->eOPMode == OP_MODE_ADHOC ||
765 pDevice->eOPMode == OP_MODE_AP)
766 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
767 else
768 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
769
770 if (pDevice->eOPMode == OP_MODE_AP)
771 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
772 else
773 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400774 }
775 }
776 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100777 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400778 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700779 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500780 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400781 );
782 pBuf->wTransmitLength = cpu_to_le16(wLen);
783 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100784 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
785 cbFrameLength, byPktType, wCurrentRate,
786 bNeedAck, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400787
Malcolm Priestley07738932013-08-05 22:08:05 +0100788 pBuf->data.duration = pBuf->wDuration;
789 /* Get RTS Frame body */
790 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400791
Malcolm Priestley07738932013-08-05 22:08:05 +0100792 if (pDevice->eOPMode == OP_MODE_ADHOC ||
793 pDevice->eOPMode == OP_MODE_AP)
794 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
795 else
796 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
797
798 if (pDevice->eOPMode == OP_MODE_AP)
799 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
800 else
801 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400802 }
803}
804
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000805static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
806 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
807 int bDisCRC, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400808{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000809 u32 uCTSFrameLen = 14;
810 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400811
812 if (pvCTS == NULL) {
813 return;
814 }
815
816 if (bDisCRC) {
817 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
818 // in this case we need to decrease its length by 4.
819 uCTSFrameLen -= 4;
820 }
821
822 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
823 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
824 // Auto Fall back
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100825 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Forest Bond92b96792009-06-13 07:38:31 -0400826 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700827 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500828 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400829 );
830 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100831 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
832 cbFrameLength, byPktType,
833 wCurrentRate, bNeedAck, byFBOption);
834 /* Get CTSDuration_ba_f0 */
835 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
836 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
837 bNeedAck, byFBOption);
838 /* Get CTSDuration_ba_f1 */
839 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
840 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
841 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100842 /* Get CTS Frame body */
843 pBuf->data.duration = pBuf->wDuration_ba;
844 pBuf->data.frame_control = TYPE_CTL_CTS;
845 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400846 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100847 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Forest Bond92b96792009-06-13 07:38:31 -0400848 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700849 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500850 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400851 );
852 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100853 /* Get CTSDuration_ba */
854 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
855 CTSDUR_BA, cbFrameLength, byPktType,
856 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100857 /*Get CTS Frame body*/
858 pBuf->data.duration = pBuf->wDuration_ba;
859 pBuf->data.frame_control = TYPE_CTL_CTS;
860 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400861 }
862 }
863}
864
Forest Bond92b96792009-06-13 07:38:31 -0400865/*+
866 *
867 * Description:
868 * Generate FIFO control for MAC & Baseband controller
869 *
870 * Parameters:
871 * In:
872 * pDevice - Pointer to adpater
873 * pTxDataHead - Transmit Data Buffer
874 * pTxBufHead - pTxBufHead
875 * pvRrvTime - pvRrvTime
876 * pvRTS - RTS Buffer
877 * pCTS - CTS Buffer
878 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
879 * bNeedACK - If need ACK
880 * uDMAIdx - DMA Index
881 * Out:
882 * none
883 *
884 * Return Value: none
885 *
886-*/
Andres Morecc856e62010-05-17 21:34:01 -0300887
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000888static void s_vGenerateTxParameter(struct vnt_private *pDevice,
889 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
890 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500891 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400892{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000893 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
894 u16 wFifoCtl;
Andres Moree269fc22013-02-12 20:36:29 -0500895 int bDisCRC = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000896 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400897
898 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
899 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
900 pFifoHead->wReserved = wCurrentRate;
901 wFifoCtl = pFifoHead->wFIFOCtl;
902
903 if (wFifoCtl & FIFOCTL_CRCDIS) {
Andres More4e9b5e22013-02-12 20:36:30 -0500904 bDisCRC = true;
Forest Bond92b96792009-06-13 07:38:31 -0400905 }
906
907 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
908 byFBOption = AUTO_FB_0;
909 }
910 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
911 byFBOption = AUTO_FB_1;
912 }
913
914 if (pDevice->bLongHeader)
915 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
916
917 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
918
919 if (pvRTS != NULL) { //RTS_need
920 //Fill RsvTime
921 if (pvRrvTime) {
Malcolm Priestley6398a592013-08-16 21:26:55 +0100922 struct vnt_rrv_time_rts *pBuf =
923 (struct vnt_rrv_time_rts *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500924 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
925 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
926 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
927 pBuf->wTxRrvTime_a = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
928 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 -0400929 }
930 //Fill RTS
931 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
932 }
933 else {//RTS_needless, PCF mode
934
935 //Fill RsvTime
936 if (pvRrvTime) {
Malcolm Priestley4f990052013-08-16 23:38:57 +0100937 struct vnt_rrv_time_cts *pBuf =
938 (struct vnt_rrv_time_cts *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500939 pBuf->wTxRrvTime_a = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
940 pBuf->wTxRrvTime_b = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
941 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 -0400942 }
943 //Fill CTS
944 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
945 }
946 }
947 else if (byPktType == PK_TYPE_11A) {
948
949 if (pvRTS != NULL) {//RTS_need, non PCF mode
950 //Fill RsvTime
951 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100952 struct vnt_rrv_time_ab *pBuf =
953 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500954 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
955 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400956 }
957 //Fill RTS
958 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
959 }
960 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
961 //Fill RsvTime
962 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100963 struct vnt_rrv_time_ab *pBuf =
964 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500965 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400966 }
967 }
968 }
969 else if (byPktType == PK_TYPE_11B) {
970
971 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
972 //Fill RsvTime
973 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100974 struct vnt_rrv_time_ab *pBuf =
975 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500976 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
977 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400978 }
979 //Fill RTS
980 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
981 }
982 else { //RTS_needless, non PCF mode
983 //Fill RsvTime
984 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100985 struct vnt_rrv_time_ab *pBuf =
986 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500987 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400988 }
989 }
990 }
991 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
992}
993/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500994 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500995 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300996 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400997*/
998
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000999static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01001000 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
1001 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
1002 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
1003 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -04001004{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001005 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1006 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001007 u32 cb802_1_H_len;
1008 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
1009 u32 cbFCSlen = 4, cbMICHDR = 0;
1010 int bNeedACK, bRTS;
1011 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
1012 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1013 u8 abySNAP_Bridgetunnel[ETH_ALEN]
1014 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1015 u32 uDuration;
1016 u32 cbHeaderLength = 0, uPadding = 0;
1017 void *pvRrvTime;
1018 PSMICHDRHead pMICHDR;
1019 void *pvRTS;
1020 void *pvCTS;
1021 void *pvTxDataHd;
1022 u8 byFBOption = AUTO_FB_NONE, byFragType;
1023 u16 wTxBufSize;
1024 u32 dwMICKey0, dwMICKey1, dwMIC_Priority, dwCRC;
1025 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001026 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -04001027
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001028 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001029
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001030 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001031 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1032 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001033 }
Forest Bond92b96792009-06-13 07:38:31 -04001034
Forest Bond92b96792009-06-13 07:38:31 -04001035 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001036 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001037 if (pDevice->dwDiagRefCount == 0) {
1038 cb802_1_H_len = 8;
1039 } else {
1040 cb802_1_H_len = 2;
1041 }
1042 } else {
1043 cb802_1_H_len = 0;
1044 }
1045
Charles Clément21ec51f2010-05-18 10:08:14 -07001046 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001047
1048 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001049 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001050
1051 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001052 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001053 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1054 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001055 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1056 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001057 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001058 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001059 pTxBufHead->wFIFOCtl =
1060 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1061 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001062 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001063 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1064 }
Forest Bond92b96792009-06-13 07:38:31 -04001065 }
1066 else {
1067 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001068 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001069 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1070 }
1071 } //if (pDevice->dwDiagRefCount != 0) {
1072
1073 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1074
1075 //Set FIFOCTL_LHEAD
1076 if (pDevice->bLongHeader)
1077 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1078
1079 if (pDevice->bSoftwareGenCrcErr) {
1080 pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS; // set tx descriptors to NO hardware CRC
1081 }
1082
1083 //Set FRAGCTL_MACHDCNT
1084 if (pDevice->bLongHeader) {
1085 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1086 } else {
1087 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1088 }
Andres More3eaca0d2013-02-25 20:32:52 -05001089 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001090
1091 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001092 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001093 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1094 }
1095
1096 //Set Auto Fallback Ctl
1097 if (wCurrentRate >= RATE_18M) {
1098 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1099 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1100 byFBOption = AUTO_FB_0;
1101 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1102 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1103 byFBOption = AUTO_FB_1;
1104 }
1105 }
1106
Andres More4e9b5e22013-02-12 20:36:30 -05001107 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001108 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1109 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1110 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1111 }
1112 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1113 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1114 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1115 }
1116 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1117 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1118 }
1119 }
1120 }
1121
Forest Bond92b96792009-06-13 07:38:31 -04001122 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1123 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1124 cbIVlen = 4;
1125 cbICVlen = 4;
1126 }
1127 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1128 cbIVlen = 8;//IV+ExtIV
1129 cbMIClen = 8;
1130 cbICVlen = 4;
1131 }
1132 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1133 cbIVlen = 8;//RSN Header
1134 cbICVlen = 8;//MIC
1135 cbMICHDR = sizeof(SMICHDRHead);
1136 }
Andres Moree269fc22013-02-12 20:36:29 -05001137 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001138 //MAC Header should be padding 0 to DW alignment.
1139 uPadding = 4 - (cbMACHdLen%4);
1140 uPadding %= 4;
1141 }
1142 }
1143
1144 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1145
Andres Moree269fc22013-02-12 20:36:29 -05001146 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1147 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001148 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001149 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001150 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1151 }
1152
Andres Moreb902fbf2013-02-25 20:32:51 -05001153 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001154 wTxBufSize = sizeof(STxBufHead);
1155 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1156 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001157 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001158 pvRrvTime = (struct vnt_rrv_time_rts *)
1159 (pbyTxBufferAddr + wTxBufSize);
1160 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1161 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001162 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001163 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001164 pvCTS = NULL;
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001165 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001166 sizeof(struct vnt_rrv_time_rts) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001167 sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001168 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001169 cbMICHDR + sizeof(struct vnt_rts_g) +
1170 sizeof(STxDataHead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001171 }
1172 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001173 pvRrvTime = (struct vnt_rrv_time_cts *)
1174 (pbyTxBufferAddr + wTxBufSize);
1175 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1176 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001177 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001178 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001179 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001180 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001181 sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001182 sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001183 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1184 cbMICHDR + sizeof(struct vnt_cts) +
1185 sizeof(STxDataHead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001186 }
1187 } else {
1188 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001189 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001190 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1191 wTxBufSize);
1192 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1193 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001194 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001195 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001196 pvCTS = NULL;
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001197 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001198 sizeof(struct vnt_rrv_time_rts) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001199 sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001200 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1201 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
1202 sizeof(STxDataHead_g_FB);
Forest Bond92b96792009-06-13 07:38:31 -04001203 }
Andres Moree269fc22013-02-12 20:36:29 -05001204 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001205 pvRrvTime = (struct vnt_rrv_time_cts *)
1206 (pbyTxBufferAddr + wTxBufSize);
1207 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1208 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001209 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001210 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001211 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001212 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001213 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1214 cbMICHDR + sizeof(struct vnt_cts_fb));
1215 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001216 cbMICHDR + sizeof(struct vnt_cts_fb) +
1217 sizeof(STxDataHead_g_FB);
Forest Bond92b96792009-06-13 07:38:31 -04001218 }
1219 } // Auto Fall Back
1220 }
1221 else {//802.11a/b packet
1222 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001223 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001224 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1225 wTxBufSize);
1226 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1227 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001228 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001229 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001230 pvCTS = NULL;
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001231 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001232 sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001233 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001234 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1235 cbMICHDR + sizeof(struct vnt_rts_ab) +
1236 sizeof(STxDataHead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001237 }
Andres Moree269fc22013-02-12 20:36:29 -05001238 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001239 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1240 wTxBufSize);
1241 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1242 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001243 pvRTS = NULL;
1244 pvCTS = NULL;
Malcolm Priestley976467d2013-08-16 23:44:04 +01001245 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize +
1246 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1247 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1248 cbMICHDR + sizeof(STxDataHead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001249 }
1250 } else {
1251 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001252 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001253 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1254 wTxBufSize);
1255 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1256 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001257 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001258 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001259 pvCTS = NULL;
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001260 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001261 sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001262 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001263 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1264 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
1265 sizeof(STxDataHead_a_FB);
Forest Bond92b96792009-06-13 07:38:31 -04001266 }
Andres Moree269fc22013-02-12 20:36:29 -05001267 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001268 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1269 wTxBufSize);
1270 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1271 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001272 pvRTS = NULL;
1273 pvCTS = NULL;
Malcolm Priestley976467d2013-08-16 23:44:04 +01001274 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize +
1275 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1276 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1277 cbMICHDR + sizeof(STxDataHead_a_FB);
Forest Bond92b96792009-06-13 07:38:31 -04001278 }
1279 } // Auto Fall Back
1280 }
1281
Andres Moreb902fbf2013-02-25 20:32:51 -05001282 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1283 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1284 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001285
Forest Bond92b96792009-06-13 07:38:31 -04001286 //=========================
1287 // No Fragmentation
1288 //=========================
1289 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1290 byFragType = FRAGCTL_NONFRAG;
1291 //uDMAIdx = TYPE_AC0DMA;
1292 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1293
Forest Bond92b96792009-06-13 07:38:31 -04001294 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001295 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1296 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001297 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1298 //Fill DataHead
1299 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001300 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001301 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001302 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001303 byFragType, uDMAIdx, 0);
1304
Andres More4e9b5e22013-02-12 20:36:30 -05001305 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001306 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001307 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001308 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001309
1310 if (pDevice->bEnableHostWEP) {
1311 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1312 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1313 }
1314 }
1315
1316 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001317 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001318 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001319 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1320 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001321 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001322 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001323 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001324 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001325 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001326 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001327 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001328 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001329 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001330
1331 }
1332
1333 }
1334
Forest Bond92b96792009-06-13 07:38:31 -04001335 if (pPacket != NULL) {
1336 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001337 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001338 (pPacket + ETH_HLEN),
1339 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001340 );
1341
1342 } else {
1343 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001344 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001345 }
1346
Andres More4e9b5e22013-02-12 20:36:30 -05001347 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001348
1349 ///////////////////////////////////////////////////////////////////
1350
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001351 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1352 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1353 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1354 }
Forest Bond92b96792009-06-13 07:38:31 -04001355 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001356 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1357 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001358 }
1359 else {
Andres More52a7e642013-02-25 20:32:53 -05001360 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1361 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001362 }
1363 // DO Software Michael
1364 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001365 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001366 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001367 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001368 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1369 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001370
1371 ///////////////////////////////////////////////////////////////////
1372
1373 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1374 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001375 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001376 //}
1377 //DBG_PRN_GRP12(("\n\n\n"));
1378
1379 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1380
Andres More52a7e642013-02-25 20:32:53 -05001381 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1382 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001383
1384 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1385 MIC_vUnInit();
1386
Andres More4e9b5e22013-02-12 20:36:30 -05001387 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001388 *pdwMIC_L = 0;
1389 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001390 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001391 }
1392 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1393 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1394 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1395 }
1396
Andres More4e9b5e22013-02-12 20:36:30 -05001397 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001398
Andres More3eaca0d2013-02-25 20:32:52 -05001399 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001400
Andres More4e9b5e22013-02-12 20:36:30 -05001401 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1402 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1403 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001404 cbFrameSize -= cbICVlen;
1405 }
1406
Andres More4e9b5e22013-02-12 20:36:30 -05001407 if (pDevice->bSoftwareGenCrcErr == true) {
Andres Morecc856e62010-05-17 21:34:01 -03001408 unsigned int cbLen;
Andres More52a7e642013-02-25 20:32:53 -05001409 u32 * pdwCRC;
Forest Bond92b96792009-06-13 07:38:31 -04001410
1411 dwCRC = 0xFFFFFFFFL;
1412 cbLen = cbFrameSize - cbFCSlen;
1413 // calculate CRC, and wrtie CRC value to end of TD
1414 dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
Andres More52a7e642013-02-25 20:32:53 -05001415 pdwCRC = (u32 *)(pbyMacHdr + cbLen);
Forest Bond92b96792009-06-13 07:38:31 -04001416 // finally, we must invert dwCRC to get the correct answer
1417 *pdwCRC = ~dwCRC;
1418 // Force Error
1419 *pdwCRC -= 1;
1420 } else {
1421 cbFrameSize -= cbFCSlen;
1422 }
1423
1424 *pcbHeaderLen = cbHeaderLength;
1425 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1426
Forest Bond92b96792009-06-13 07:38:31 -04001427 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001428 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001429
Andres More4e9b5e22013-02-12 20:36:30 -05001430 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001431
1432}
1433
Forest Bond92b96792009-06-13 07:38:31 -04001434/*+
1435 *
1436 * Description:
1437 * Translate 802.3 to 802.11 header
1438 *
1439 * Parameters:
1440 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001441 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001442 * dwTxBufferAddr - Transmit Buffer
1443 * pPacket - Packet from upper layer
1444 * cbPacketSize - Transmit Data Length
1445 * Out:
1446 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1447 * pcbAppendPayload - size of append payload for 802.1H translation
1448 *
1449 * Return Value: none
1450 *
1451-*/
1452
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001453static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001454 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001455 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001456{
Andres More1cac4a42013-03-18 20:33:50 -05001457 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001458
Forest Bond92b96792009-06-13 07:38:31 -04001459 if (uDMAIdx == TYPE_ATIMDMA) {
Andres More1cac4a42013-03-18 20:33:50 -05001460 pMACHeader->frame_control = TYPE_802_11_ATIM;
Forest Bond92b96792009-06-13 07:38:31 -04001461 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001462 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001463 }
1464
1465 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001466 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001467 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001468 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001469 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1470 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001471 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001472 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001473 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001474 } else {
1475 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001476 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001477 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001478 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001479 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001480 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001481 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001482 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001483 &(pDevice->abyBSSID[0]),
1484 ETH_ALEN);
1485 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001486 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001487 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001488 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001489 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001490 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001491 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001492 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001493 &(pDevice->abyBSSID[0]),
1494 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001495 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001496 }
1497 }
1498
1499 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001500 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001501
Andres More1cac4a42013-03-18 20:33:50 -05001502 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001503
1504 if (pDevice->bLongHeader) {
1505 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001506 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001507 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001508 }
Andres More1cac4a42013-03-18 20:33:50 -05001509 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001510
1511 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001512 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001513
1514 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1515 pDevice->wSeqCounter++;
1516 if (pDevice->wSeqCounter > 0x0fff)
1517 pDevice->wSeqCounter = 0;
1518 }
1519
1520 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001521 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001522 }
1523}
1524
Forest Bond92b96792009-06-13 07:38:31 -04001525/*+
1526 *
1527 * Description:
1528 * Request instructs a MAC to transmit a 802.11 management packet through
1529 * the adapter onto the medium.
1530 *
1531 * Parameters:
1532 * In:
1533 * hDeviceContext - Pointer to the adapter
1534 * pPacket - A pointer to a descriptor for the packet to transmit
1535 * Out:
1536 * none
1537 *
Andres Moree269fc22013-02-12 20:36:29 -05001538 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001539 *
1540-*/
1541
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001542CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1543 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001544{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001545 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001546 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001547 PSTxBufHead pTxBufHead;
1548 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001549 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001550 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001551 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001552 u8 byPktType, *pbyTxBufferAddr;
1553 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1554 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001555 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001556 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1557 u32 uPadding = 0;
1558 u16 wTxBufSize;
1559 u32 cbMacHdLen;
1560 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001561
Forest Bond92b96792009-06-13 07:38:31 -04001562 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1563
1564 if (NULL == pContext) {
1565 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1566 return CMD_STATUS_RESOURCES;
1567 }
1568
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001569 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001570 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001571 cbFrameBodySize = pPacket->cbPayloadLen;
1572 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1573 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001574
1575 if (pDevice->byBBType == BB_TYPE_11A) {
1576 wCurrentRate = RATE_6M;
1577 byPktType = PK_TYPE_11A;
1578 } else {
1579 wCurrentRate = RATE_1M;
1580 byPktType = PK_TYPE_11B;
1581 }
1582
1583 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1584 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1585 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1586 // to set power here.
1587 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1588 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1589 } else {
1590 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1591 }
1592 pDevice->wCurrentRate = wCurrentRate;
1593
Forest Bond92b96792009-06-13 07:38:31 -04001594 //Set packet type
1595 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1596 pTxBufHead->wFIFOCtl = 0;
1597 }
1598 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1599 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1600 }
1601 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1602 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1603 }
1604 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1605 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1606 }
1607
1608 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1609 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1610
Andres More22040bb2010-08-02 20:21:44 -03001611 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001612 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001613 }
1614 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001615 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001616 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1617 };
1618
1619 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1620 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1621
1622 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1623 //Set Preamble type always long
1624 //pDevice->byPreambleType = PREAMBLE_LONG;
1625 // probe-response don't retry
1626 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001627 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001628 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1629 //}
1630 }
1631
1632 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1633
1634 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001635 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001636 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1637 } else {
1638 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1639 }
1640
1641 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001642 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001643
1644 // Notes:
1645 // Although spec says MMPDU can be fragmented; In most case,
1646 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001647 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001648
1649 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1650 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1651 cbIVlen = 4;
1652 cbICVlen = 4;
1653 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1654 }
1655 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1656 cbIVlen = 8;//IV+ExtIV
1657 cbMIClen = 8;
1658 cbICVlen = 4;
1659 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1660 //We need to get seed here for filling TxKey entry.
1661 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1662 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1663 }
1664 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1665 cbIVlen = 8;//RSN Header
1666 cbICVlen = 8;//MIC
1667 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001668 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001669 }
1670 //MAC Header should be padding 0 to DW alignment.
1671 uPadding = 4 - (cbMacHdLen%4);
1672 uPadding %= 4;
1673 }
1674
1675 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1676
1677 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001678 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001679 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1680 }
1681 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1682
1683 //Set RrvTime/RTS/CTS Buffer
1684 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1685
Malcolm Priestley4f990052013-08-16 23:38:57 +01001686 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001687 pMICHDR = NULL;
1688 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001689 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001690 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001691 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001692 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1693 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001694 sizeof(struct vnt_cts) + sizeof(STxDataHead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001695 }
1696 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001697 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001698 pMICHDR = NULL;
1699 pvRTS = NULL;
1700 pCTS = NULL;
Malcolm Priestley976467d2013-08-16 23:44:04 +01001701 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize +
1702 sizeof(struct vnt_rrv_time_ab));
1703 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1704 sizeof(STxDataHead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001705 }
1706
Andres Moreceb8c5d2013-03-18 20:33:49 -05001707 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001708 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1709 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001710 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001711 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1712 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001713 //=========================
1714 // No Fragmentation
1715 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001716 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001717
Forest Bond92b96792009-06-13 07:38:31 -04001718 //Fill FIFO,RrvTime,RTS,and CTS
1719 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1720 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1721
1722 //Fill DataHead
1723 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001724 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001725
Andres More1cac4a42013-03-18 20:33:50 -05001726 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001727
1728 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1729
1730 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001731 u8 * pbyIVHead;
1732 u8 * pbyPayloadHead;
1733 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001734 PSKeyItem pTransmitKey = NULL;
1735
Andres Moreb902fbf2013-02-25 20:32:51 -05001736 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1737 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001738 do {
1739 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001740 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001741 pbyBSSID = pDevice->abyBSSID;
1742 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001743 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001744 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001745 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001746 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1747 break;
1748 }
1749 } else {
1750 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1751 break;
1752 }
1753 }
1754 // get group key
1755 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001756 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001757 pTransmitKey = NULL;
1758 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1759 } else {
1760 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1761 }
Andres Moree269fc22013-02-12 20:36:29 -05001762 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001763 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001764 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001765 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001766
Jim Lieb3e362592009-08-12 14:54:11 -07001767 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001768 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001769 cbFrameBodySize);
1770 }
1771 else {
1772 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001773 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001774 }
1775
Andres More1cac4a42013-03-18 20:33:50 -05001776 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001777 pDevice->wSeqCounter++ ;
1778 if (pDevice->wSeqCounter > 0x0fff)
1779 pDevice->wSeqCounter = 0;
1780
1781 if (bIsPSPOLL) {
1782 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001783 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001784 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1785 // in the same place of other packet's Duration-field).
1786 // And it will cause Cisco-AP to issue Disassociation-packet
1787 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1788 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1789 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1790 } else {
1791 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1792 }
1793 }
1794
Andres More3eaca0d2013-02-25 20:32:52 -05001795 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001796 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001797 pTX_Buffer->byType = 0x00;
1798
1799 pContext->pPacket = NULL;
1800 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001801 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001802
Andres More1cac4a42013-03-18 20:33:50 -05001803 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1804 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001805 }
1806 else {
Andres More1cac4a42013-03-18 20:33:50 -05001807 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001808 }
1809
1810 PIPEnsSendBulkOut(pDevice,pContext);
1811 return CMD_STATUS_PENDING;
1812}
1813
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001814CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1815 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001816{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001817 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001818 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1819 u32 cbHeaderSize = 0;
1820 u16 wTxBufSize = sizeof(STxShortBufHead);
1821 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001822 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001823 PSTxDataHead_ab pTxDataHead;
1824 u16 wCurrentRate;
1825 u32 cbFrameBodySize;
1826 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001827 u8 *pbyTxBufferAddr;
1828 PUSB_SEND_CONTEXT pContext;
1829 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001830
Forest Bond92b96792009-06-13 07:38:31 -04001831 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1832 if (NULL == pContext) {
1833 status = CMD_STATUS_RESOURCES;
1834 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1835 return status ;
1836 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001837
1838 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001839 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001840
1841 cbFrameBodySize = pPacket->cbPayloadLen;
1842
1843 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1844 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001845
1846 if (pDevice->byBBType == BB_TYPE_11A) {
1847 wCurrentRate = RATE_6M;
1848 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
1849 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001850 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
Andres More3eaca0d2013-02-25 20:32:52 -05001851 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001852 );
1853 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +01001854 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice,
1855 DATADUR_A, PK_TYPE_11A, false));
Forest Bond92b96792009-06-13 07:38:31 -04001856 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
1857 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
1858 } else {
1859 wCurrentRate = RATE_1M;
1860 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1861 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
1862 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001863 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -05001864 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001865 );
1866 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +01001867 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice,
1868 DATADUR_B, PK_TYPE_11B, false));
Forest Bond92b96792009-06-13 07:38:31 -04001869 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
1870 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
1871 }
1872
1873 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001874 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001875 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001876
Andres More1cac4a42013-03-18 20:33:50 -05001877 pMACHeader->duration_id = 0;
1878 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001879 pDevice->wSeqCounter++ ;
1880 if (pDevice->wSeqCounter > 0x0fff)
1881 pDevice->wSeqCounter = 0;
1882
1883 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1884
Andres More3eaca0d2013-02-25 20:32:52 -05001885 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001886 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001887 pTX_Buffer->byType = 0x01;
1888
1889 pContext->pPacket = NULL;
1890 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001891 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001892
1893 PIPEnsSendBulkOut(pDevice,pContext);
1894 return CMD_STATUS_PENDING;
1895
1896}
1897
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001898void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1899{
1900 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001901 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001902 u8 byPktType;
1903 u8 *pbyTxBufferAddr;
1904 void *pvRTS, *pvCTS, *pvTxDataHd;
1905 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001906 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001907 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001908 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001909 PSTxBufHead pTxBufHead;
1910 u32 cbFrameSize;
1911 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1912 u32 uPadding = 0;
1913 u32 cbMICHDR = 0, uLength = 0;
1914 u32 dwMICKey0, dwMICKey1;
1915 u32 dwMIC_Priority;
1916 u32 *pdwMIC_L, *pdwMIC_R;
1917 u16 wTxBufSize;
1918 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001919 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001920 void *pvRrvTime, *pMICHDR;
1921 u32 wCurrentRate = RATE_1M;
1922 PUWLAN_80211HDR p80211Header;
1923 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001924 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001925 SKeyItem STempKey;
1926 PSKeyItem pTransmitKey = NULL;
1927 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1928 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001929 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001930
Forest Bond92b96792009-06-13 07:38:31 -04001931 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1932
1933 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1934 cbFrameBodySize = 0;
1935 }
1936 else {
1937 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1938 }
1939 p80211Header = (PUWLAN_80211HDR)skb->data;
1940
1941 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1942
1943 if (NULL == pContext) {
1944 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1945 dev_kfree_skb_irq(skb);
1946 return ;
1947 }
1948
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001949 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001950 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001951 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1952 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001953
1954 if (pDevice->byBBType == BB_TYPE_11A) {
1955 wCurrentRate = RATE_6M;
1956 byPktType = PK_TYPE_11A;
1957 } else {
1958 wCurrentRate = RATE_1M;
1959 byPktType = PK_TYPE_11B;
1960 }
1961
1962 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1963 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1964 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1965 // to set power here.
1966 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1967 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1968 } else {
1969 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1970 }
1971
1972 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1973
1974 //Set packet type
1975 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1976 pTxBufHead->wFIFOCtl = 0;
1977 }
1978 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1979 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1980 }
1981 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1982 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1983 }
1984 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1985 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1986 }
1987
1988 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1989 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1990
Andres More22040bb2010-08-02 20:21:44 -03001991 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001992 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001993 if (pDevice->bEnableHostWEP) {
1994 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001995 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001996 }
Forest Bond92b96792009-06-13 07:38:31 -04001997 }
1998 else {
1999 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05002000 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05002001 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07002002 }
Andres More4e9b5e22013-02-12 20:36:30 -05002003 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002004 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2005 };
2006
2007 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2008 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2009
2010 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2011 //Set Preamble type always long
2012 //pDevice->byPreambleType = PREAMBLE_LONG;
2013
2014 // probe-response don't retry
2015 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05002016 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04002017 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2018 //}
2019 }
2020
2021 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2022
2023 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05002024 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04002025 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2026 } else {
2027 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2028 }
2029
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002030 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04002031 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2032
2033 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
2034 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2035 }
2036
2037 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
2038 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2039 }
2040
2041 if (cbExtSuppRate >0) {
2042 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2043 }
2044 }
2045
Forest Bond92b96792009-06-13 07:38:31 -04002046 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05002047 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04002048
2049 // Notes:
2050 // Although spec says MMPDU can be fragmented; In most case,
2051 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05002052 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04002053
Forest Bond92b96792009-06-13 07:38:31 -04002054 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2055 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2056 cbIVlen = 4;
2057 cbICVlen = 4;
2058 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2059 }
2060 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2061 cbIVlen = 8;//IV+ExtIV
2062 cbMIClen = 8;
2063 cbICVlen = 4;
2064 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2065 //We need to get seed here for filling TxKey entry.
2066 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2067 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2068 }
2069 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2070 cbIVlen = 8;//RSN Header
2071 cbICVlen = 8;//MIC
2072 cbMICHDR = sizeof(SMICHDRHead);
2073 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002074 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002075 }
2076 //MAC Header should be padding 0 to DW alignment.
2077 uPadding = 4 - (cbMacHdLen%4);
2078 uPadding %= 4;
2079 }
2080
2081 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2082
2083 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002084 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002085 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2086 }
2087 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2088
Forest Bond92b96792009-06-13 07:38:31 -04002089 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002090 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
2091 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
2092 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002093 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002094 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002095 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002096 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002097 sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
2098 sizeof(struct vnt_cts));
2099 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002100 sizeof(struct vnt_cts) + sizeof(STxDataHead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002101
2102 }
2103 else {//802.11a/b packet
2104
Malcolm Priestley976467d2013-08-16 23:44:04 +01002105 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
2106 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
2107 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002108 pvRTS = NULL;
2109 pvCTS = NULL;
Malcolm Priestley976467d2013-08-16 23:44:04 +01002110 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize +
2111 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
2112 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
2113 sizeof(STxDataHead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002114 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002115 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002116 &(p80211Header->sA3.abyAddr1[0]),
2117 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002118 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002119 &(p80211Header->sA3.abyAddr2[0]),
2120 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002121 //=========================
2122 // No Fragmentation
2123 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002124 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002125
Forest Bond92b96792009-06-13 07:38:31 -04002126 //Fill FIFO,RrvTime,RTS,and CTS
2127 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2128 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2129
2130 //Fill DataHead
2131 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002132 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002133
Andres More1cac4a42013-03-18 20:33:50 -05002134 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002135
2136 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2137
Andres Moreb902fbf2013-02-25 20:32:51 -05002138 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2139 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2140 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002141
2142 // Copy the Packet into a tx Buffer
2143 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2144
2145 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002146 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002147 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2148
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002149 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002150 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2151 if (cbExtSuppRate != 0) {
2152 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2153 memcpy((pbyPayloadHead + cbFrameBodySize),
2154 pMgmt->abyCurrSuppRates,
2155 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2156 );
2157 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2158 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2159 pMgmt->abyCurrExtSuppRates,
2160 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2161 );
2162 }
2163 }
2164
2165 // Set wep
2166 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2167
2168 if (pDevice->bEnableHostWEP) {
2169 pTransmitKey = &STempKey;
2170 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2171 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2172 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2173 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2174 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2175 memcpy(pTransmitKey->abyKey,
2176 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2177 pTransmitKey->uKeyLength
2178 );
2179 }
2180
2181 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2182
Andres More52a7e642013-02-25 20:32:53 -05002183 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2184 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002185
2186 // DO Software Michael
2187 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002188 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002189 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002190 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002191 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2192 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002193
2194 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2195
2196 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2197
Andres More52a7e642013-02-25 20:32:53 -05002198 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2199 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002200
2201 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2202 MIC_vUnInit();
2203
Andres More4e9b5e22013-02-12 20:36:30 -05002204 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002205 *pdwMIC_L = 0;
2206 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002207 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002208 }
2209
2210 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2211 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002212 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2213 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002214
2215 }
2216
Andres Moreb902fbf2013-02-25 20:32:51 -05002217 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05002218 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002219
2220 if (pDevice->bEnableHostWEP) {
2221 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2222 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2223 }
2224
2225 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002226 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002227 }
2228 }
2229
Andres More1cac4a42013-03-18 20:33:50 -05002230 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002231 pDevice->wSeqCounter++ ;
2232 if (pDevice->wSeqCounter > 0x0fff)
2233 pDevice->wSeqCounter = 0;
2234
Forest Bond92b96792009-06-13 07:38:31 -04002235 if (bIsPSPOLL) {
2236 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2237 // of FIFO control header.
2238 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2239 // in the same place of other packet's Duration-field).
2240 // And it will cause Cisco-AP to issue Disassociation-packet
2241 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2242 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
2243 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
2244 } else {
2245 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
2246 }
2247 }
2248
Andres More3eaca0d2013-02-25 20:32:52 -05002249 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002250 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002251 pTX_Buffer->byType = 0x00;
2252
2253 pContext->pPacket = skb;
2254 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002255 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002256
Andres More1cac4a42013-03-18 20:33:50 -05002257 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2258 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002259 }
2260 else {
Andres More1cac4a42013-03-18 20:33:50 -05002261 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002262 }
2263 PIPEnsSendBulkOut(pDevice,pContext);
2264 return ;
2265
2266}
2267
Forest Bond92b96792009-06-13 07:38:31 -04002268//TYPE_AC0DMA data tx
2269/*
2270 * Description:
2271 * Tx packet via AC0DMA(DMA1)
2272 *
2273 * Parameters:
2274 * In:
2275 * pDevice - Pointer to the adapter
2276 * skb - Pointer to tx skb packet
2277 * Out:
2278 * void
2279 *
2280 * Return Value: NULL
2281 */
2282
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002283int nsDMA_tx_packet(struct vnt_private *pDevice,
2284 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002285{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002286 struct net_device_stats *pStats = &pDevice->stats;
2287 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002288 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002289 u32 BytesToWrite = 0, uHeaderLen = 0;
2290 u32 uNodeIndex = 0;
2291 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2292 u16 wAID;
2293 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002294 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002295 PSKeyItem pTransmitKey = NULL;
2296 SKeyItem STempKey;
2297 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002298 int bTKIP_UseGTK = false;
2299 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002300 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002301 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002302 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002303 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002304 u32 status;
2305 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002306 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002307
Forest Bond92b96792009-06-13 07:38:31 -04002308 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2309
2310 if (pDevice->uAssocCount == 0) {
2311 dev_kfree_skb_irq(skb);
2312 return 0;
2313 }
2314
Andres Moreb902fbf2013-02-25 20:32:51 -05002315 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002316 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002317 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002318 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2319
2320 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2321 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2322 // set tx map
2323 pMgmt->abyPSTxMap[0] |= byMask[0];
2324 return 0;
2325 }
Masanari Iida93184692012-08-13 21:21:50 +09002326 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002327
2328 if (pDevice->byBBType != BB_TYPE_11A)
2329 pDevice->wCurrentRate = RATE_2M;
2330 else
2331 pDevice->wCurrentRate = RATE_24M;
2332 // long preamble type
2333 pDevice->byPreambleType = PREAMBLE_SHORT;
2334
2335 }else {
2336
Andres Moreb902fbf2013-02-25 20:32:51 -05002337 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002338
2339 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2340
2341 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2342
2343 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2344 // set tx map
2345 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2346 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2347 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2348 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2349
2350 return 0;
2351 }
2352 // AP rate decided from node
2353 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2354 // tx preamble decided from node
2355
2356 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2357 pDevice->byPreambleType = pDevice->byShortPreamble;
2358
2359 }else {
2360 pDevice->byPreambleType = PREAMBLE_LONG;
2361 }
Andres More4e9b5e22013-02-12 20:36:30 -05002362 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002363 }
2364 }
2365
Andres Moree269fc22013-02-12 20:36:29 -05002366 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002367 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2368 dev_kfree_skb_irq(skb);
2369 return 0;
2370 }
2371 }
2372
2373 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2374
2375 if (pContext == NULL) {
2376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2377 dev_kfree_skb_irq(skb);
2378 return STATUS_RESOURCES;
2379 }
2380
Andres Moreceb8c5d2013-03-18 20:33:49 -05002381 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002382
2383//mike add:station mode check eapol-key challenge--->
2384{
Andres Moreb902fbf2013-02-25 20:32:51 -05002385 u8 Protocol_Version; //802.1x Authentication
2386 u8 Packet_Type; //802.1x Authentication
2387 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002388 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002389
Charles Clément21ec51f2010-05-18 10:08:14 -07002390 Protocol_Version = skb->data[ETH_HLEN];
2391 Packet_Type = skb->data[ETH_HLEN+1];
2392 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2393 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 -05002394 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002395 /* 802.1x OR eapol-key challenge frame transfer */
2396 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2397 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002398 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002399 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2400 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2401 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002402 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002403 PRINT_K("WPA ");
2404 }
2405 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002406 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002407 PRINT_K("WPA2(re-keying) ");
2408 }
2409 PRINT_K("Authentication completed!!\n");
2410 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002411 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002412 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002413 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002414 PRINT_K("WPA2 Authentication completed!!\n");
2415 }
2416 }
2417 }
2418}
2419//mike add:station mode check eapol-key challenge<---
2420
Andres More4e9b5e22013-02-12 20:36:30 -05002421 if (pDevice->bEncryptionEnable == true) {
2422 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002423 // get Transmit key
2424 do {
2425 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2426 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2427 pbyBSSID = pDevice->abyBSSID;
2428 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002429 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002430 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002431 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2432 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002433 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2434 break;
2435 }
2436 } else {
2437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2438 break;
2439 }
2440 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002441 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2442 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002443 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2444 for (ii = 0; ii< 6; ii++)
2445 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2446 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2447
2448 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002449 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002450 break;
2451 }
2452 // get group key
2453 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002454 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002455 pTransmitKey = NULL;
2456 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2457 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2458 }
2459 else
2460 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2461 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002462 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002463 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2464 }
Andres Moree269fc22013-02-12 20:36:29 -05002465 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002466 }
2467
2468 if (pDevice->bEnableHostWEP) {
2469 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002470 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002471 pTransmitKey = &STempKey;
2472 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2473 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2474 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2475 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2476 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2477 memcpy(pTransmitKey->abyKey,
2478 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2479 pTransmitKey->uKeyLength
2480 );
2481 }
2482 }
2483
Andres Moreb902fbf2013-02-25 20:32:51 -05002484 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002485
2486 if (pDevice->bFixRate) {
2487 if (pDevice->byBBType == BB_TYPE_11B) {
2488 if (pDevice->uConnectionRate >= RATE_11M) {
2489 pDevice->wCurrentRate = RATE_11M;
2490 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002491 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002492 }
2493 } else {
2494 if ((pDevice->byBBType == BB_TYPE_11A) &&
2495 (pDevice->uConnectionRate <= RATE_6M)) {
2496 pDevice->wCurrentRate = RATE_6M;
2497 } else {
2498 if (pDevice->uConnectionRate >= RATE_54M)
2499 pDevice->wCurrentRate = RATE_54M;
2500 else
Andres More3eaca0d2013-02-25 20:32:52 -05002501 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002502 }
2503 }
2504 }
2505 else {
2506 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2507 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002508 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002509 // Multicast use highest data rate
2510 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2511 // preamble type
2512 pDevice->byPreambleType = pDevice->byShortPreamble;
2513 }
2514 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002515 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002516 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2517 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2518 pDevice->byPreambleType = pDevice->byShortPreamble;
2519
2520 }
2521 else {
2522 pDevice->byPreambleType = PREAMBLE_LONG;
2523 }
2524 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2525 }
2526 else {
2527 if (pDevice->byBBType != BB_TYPE_11A)
2528 pDevice->wCurrentRate = RATE_2M;
2529 else
2530 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2531 // abyCurrExtSuppRates[]
2532 pDevice->byPreambleType = PREAMBLE_SHORT;
2533 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2534 }
2535 }
2536 }
2537 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2538 // Infra STA rate decided from AP Node, index = 0
2539 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2540 }
2541 }
2542
Andres Moreceb8c5d2013-03-18 20:33:49 -05002543 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002544 if (pDevice->byBBType != BB_TYPE_11A) {
2545 pDevice->wCurrentRate = RATE_1M;
2546 pDevice->byACKRate = RATE_1M;
2547 pDevice->byTopCCKBasicRate = RATE_1M;
2548 pDevice->byTopOFDMBasicRate = RATE_6M;
2549 } else {
2550 pDevice->wCurrentRate = RATE_6M;
2551 pDevice->byACKRate = RATE_6M;
2552 pDevice->byTopCCKBasicRate = RATE_1M;
2553 pDevice->byTopOFDMBasicRate = RATE_6M;
2554 }
2555 }
Forest Bond92b96792009-06-13 07:38:31 -04002556
Andres More0cbd8d92010-05-06 20:34:29 -03002557 DBG_PRT(MSG_LEVEL_DEBUG,
2558 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2559 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002560
2561 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002562 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002563 }
2564
2565 if (pDevice->wCurrentRate <= RATE_11M) {
2566 byPktType = PK_TYPE_11B;
2567 }
2568
Andres More4e9b5e22013-02-12 20:36:30 -05002569 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002570 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2571 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002572 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002573 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002574 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2575 if (pTransmitKey == NULL) {
2576 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2577 }
2578 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002579 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002580 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2581 }
2582 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002583 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2584 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002585 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002586 }
2587 }
2588 }
2589
Forest Bond92b96792009-06-13 07:38:31 -04002590 if (pDevice->bEnableHostWEP) {
2591 if ((uNodeIndex != 0) &&
2592 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002593 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2594 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002595 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002596 }
2597 }
2598 }
2599 else {
2600
Forest Bond92b96792009-06-13 07:38:31 -04002601 if (pTransmitKey == NULL) {
2602 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002603 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002604 dev_kfree_skb_irq(skb);
2605 pStats->tx_dropped++;
2606 return STATUS_FAILURE;
2607 }
Forest Bond92b96792009-06-13 07:38:31 -04002608 }
2609 }
2610
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002611 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2612
Forest Bond92b96792009-06-13 07:38:31 -04002613 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002614 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002615 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002616 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002617 pDevice->wCurrentRate,
2618 &uHeaderLen, &BytesToWrite
2619 );
2620
Andres Moree269fc22013-02-12 20:36:29 -05002621 if (fConvertedPacket == false) {
2622 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002623 dev_kfree_skb_irq(skb);
2624 return STATUS_FAILURE;
2625 }
2626
Andres More4e9b5e22013-02-12 20:36:30 -05002627 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002628 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002629 bScheduleCommand((void *) pDevice,
2630 WLAN_CMD_MAC_DISPOWERSAVING,
2631 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002632 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002633 }
2634 }
2635
Andres Moreb902fbf2013-02-25 20:32:51 -05002636 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002637 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002638
2639 pContext->pPacket = skb;
2640 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002641 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002642
Andres Moreceb8c5d2013-03-18 20:33:49 -05002643 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 -04002644
2645 status = PIPEnsSendBulkOut(pDevice,pContext);
2646
Andres More4e9b5e22013-02-12 20:36:30 -05002647 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002648 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002649
Andres Moreb902fbf2013-02-25 20:32:51 -05002650 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002651 }
2652
2653 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002654 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002655 dev_kfree_skb_irq(skb);
2656 return STATUS_FAILURE;
2657 }
2658 else
2659 return 0;
2660
2661}
2662
Forest Bond92b96792009-06-13 07:38:31 -04002663/*
2664 * Description:
2665 * Relay packet send (AC1DMA) from rx dpc.
2666 *
2667 * Parameters:
2668 * In:
2669 * pDevice - Pointer to the adapter
2670 * pPacket - Pointer to rx packet
2671 * cbPacketSize - rx ethernet frame size
2672 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002673 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002674 *
Andres More4e9b5e22013-02-12 20:36:30 -05002675 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002676 */
2677
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002678int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2679 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002680{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002681 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002682 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002683 u32 BytesToWrite = 0, uHeaderLen = 0;
2684 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002685 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002686 SKeyItem STempKey;
2687 PSKeyItem pTransmitKey = NULL;
2688 u8 *pbyBSSID;
2689 PUSB_SEND_CONTEXT pContext;
2690 u8 byPktTyp;
2691 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002692 u32 status;
2693 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002694
Forest Bond92b96792009-06-13 07:38:31 -04002695 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2696
2697 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002698 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002699 }
2700
Andres Moreceb8c5d2013-03-18 20:33:49 -05002701 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002702
Andres More4e9b5e22013-02-12 20:36:30 -05002703 if (pDevice->bEncryptionEnable == true) {
2704 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002705 // get group key
2706 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002707 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002708 pTransmitKey = NULL;
2709 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2710 } else {
2711 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2712 }
2713 }
2714
2715 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002716 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002717 pTransmitKey = &STempKey;
2718 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2719 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2720 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2721 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2722 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2723 memcpy(pTransmitKey->abyKey,
2724 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2725 pTransmitKey->uKeyLength
2726 );
2727 }
2728 }
2729
2730 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002731 pContext->bBoolInUse = false;
2732 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002733 }
2734
Andres Moreb902fbf2013-02-25 20:32:51 -05002735 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002736
2737 if (pDevice->bFixRate) {
2738 if (pDevice->byBBType == BB_TYPE_11B) {
2739 if (pDevice->uConnectionRate >= RATE_11M) {
2740 pDevice->wCurrentRate = RATE_11M;
2741 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002742 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002743 }
2744 } else {
2745 if ((pDevice->byBBType == BB_TYPE_11A) &&
2746 (pDevice->uConnectionRate <= RATE_6M)) {
2747 pDevice->wCurrentRate = RATE_6M;
2748 } else {
2749 if (pDevice->uConnectionRate >= RATE_54M)
2750 pDevice->wCurrentRate = RATE_54M;
2751 else
Andres More3eaca0d2013-02-25 20:32:52 -05002752 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002753 }
2754 }
2755 }
2756 else {
2757 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2758 }
2759
Forest Bond92b96792009-06-13 07:38:31 -04002760 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002761 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002762 }
2763
2764 if (pDevice->wCurrentRate <= RATE_11M)
2765 byPktType = PK_TYPE_11B;
2766
Andres Moreabad19d2010-07-12 16:28:32 -03002767 BytesToWrite = uDataLen + ETH_FCS_LEN;
2768
Forest Bond92b96792009-06-13 07:38:31 -04002769 // Convert the packet to an usb frame and copy into our buffer
2770 // and send the irp.
2771
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002772 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2773
Forest Bond92b96792009-06-13 07:38:31 -04002774 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002775 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002776 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2777 pbySkbData, pTransmitKey, uNodeIndex,
2778 pDevice->wCurrentRate,
2779 &uHeaderLen, &BytesToWrite
2780 );
2781
Andres Moree269fc22013-02-12 20:36:29 -05002782 if (fConvertedPacket == false) {
2783 pContext->bBoolInUse = false;
2784 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002785 }
2786
Andres Moreb902fbf2013-02-25 20:32:51 -05002787 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002788 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002789
2790 pContext->pPacket = NULL;
2791 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002792 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002793
Andres Moreceb8c5d2013-03-18 20:33:49 -05002794 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 -04002795
2796 status = PIPEnsSendBulkOut(pDevice,pContext);
2797
Andres More4e9b5e22013-02-12 20:36:30 -05002798 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002799}
2800