blob: 06950c409730f40bf9c10ee20942841cea389580 [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) {
Forest Bond92b96792009-06-13 07:38:31 -0400502 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +0100503 struct vnt_tx_datahead_g *pBuf =
504 (struct vnt_tx_datahead_g *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400505 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700506 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500507 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400508 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700509 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500510 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400511 );
512 //Get Duration and TimeStamp
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100513 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
514 byPktType, bNeedAck);
515 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
516 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400517
518 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
519 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
520 return (pBuf->wDuration_a);
521 } else {
522 // Auto Fallback
Malcolm Priestley7c05c542013-08-16 23:49:15 +0100523 struct vnt_tx_datahead_g_fb *pBuf =
524 (struct vnt_tx_datahead_g_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400525 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700526 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500527 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400528 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700529 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500530 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400531 );
532 //Get Duration and TimeStamp
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100533 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
534 byPktType, bNeedAck);
535 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
536 PK_TYPE_11B, bNeedAck);
537 pBuf->wDuration_a_f0 = (u16)s_uGetDataDuration(pDevice,
538 DATADUR_A_F0, byPktType, bNeedAck);
539 pBuf->wDuration_a_f1 = (u16)s_uGetDataDuration(pDevice,
540 DATADUR_A_F1, byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400541 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
542 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
543 return (pBuf->wDuration_a);
544 } //if (byFBOption == AUTO_FB_NONE)
Forest Bond92b96792009-06-13 07:38:31 -0400545 }
546 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100547 if (byFBOption != AUTO_FB_NONE) {
Malcolm Priestley1da4ee22013-08-16 23:51:38 +0100548 struct vnt_tx_datahead_a_fb *pBuf =
549 (struct vnt_tx_datahead_a_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400550 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700551 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500552 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400553 );
554 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100555 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
556 byPktType, bNeedAck);
557 pBuf->wDuration_f0 = (u16)s_uGetDataDuration(pDevice,
558 DATADUR_A_F0, byPktType, bNeedAck);
559 pBuf->wDuration_f1 = (u16)s_uGetDataDuration(pDevice,
560 DATADUR_A_F1, byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400561 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Forest Bond92b96792009-06-13 07:38:31 -0400562 return (pBuf->wDuration);
563 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100564 struct vnt_tx_datahead_ab *pBuf =
565 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400566 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700567 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500568 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400569 );
570 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100571 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
572 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400573 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100574
Forest Bond92b96792009-06-13 07:38:31 -0400575 return (pBuf->wDuration);
576 }
577 }
578 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100579 struct vnt_tx_datahead_ab *pBuf =
580 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400581 //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_B,
587 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400588 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100589
Forest Bond92b96792009-06-13 07:38:31 -0400590 return (pBuf->wDuration);
591 }
592 return 0;
593}
594
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000595static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
596 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500597 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400598{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000599 u32 uRTSFrameLen = 20;
600 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400601
Forest Bond92b96792009-06-13 07:38:31 -0400602 if (pvRTS == NULL)
603 return;
604
605 if (bDisCRC) {
606 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
607 // in this case we need to decrease its length by 4.
608 uRTSFrameLen -= 4;
609 }
610
Masanari Iida93184692012-08-13 21:21:50 +0900611 // 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 -0400612 // Otherwise, we need to modified codes for them.
613 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
614 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100615 struct vnt_rts_g *pBuf = (struct vnt_rts_g *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400616 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700617 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500618 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400619 );
620 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700621 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500622 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400623 );
624 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
625 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100626 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
627 cbFrameLength, PK_TYPE_11B,
628 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
629 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
630 cbFrameLength, byPktType,
631 wCurrentRate, bNeedAck, byFBOption);
632 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
633 cbFrameLength, byPktType,
634 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100635 pBuf->data.duration = pBuf->wDuration_aa;
636 /*Get RTS Frame body */
637 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400638
Malcolm Priestley07738932013-08-05 22:08:05 +0100639 if (pDevice->eOPMode == OP_MODE_ADHOC ||
640 pDevice->eOPMode == OP_MODE_AP)
641 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
642 else
643 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Andres More9a0e7562010-04-13 21:54:48 -0300644
Malcolm Priestley07738932013-08-05 22:08:05 +0100645 if (pDevice->eOPMode == OP_MODE_AP)
646 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
647 else
648 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400649 }
650 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100651 struct vnt_rts_g_fb *pBuf = (struct vnt_rts_g_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400652 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700653 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500654 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400655 );
656 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700657 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500658 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400659 );
660 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
661 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100662 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
663 cbFrameLength, PK_TYPE_11B,
664 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
665 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
666 cbFrameLength, byPktType,
667 wCurrentRate, bNeedAck, byFBOption);
668 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
669 cbFrameLength, byPktType,
670 wCurrentRate, bNeedAck, byFBOption);
671 pBuf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
672 RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
673 bNeedAck, byFBOption);
674 pBuf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(pDevice,
675 RTSDUR_AA_F0, cbFrameLength, byPktType,
676 wCurrentRate, bNeedAck, byFBOption);
677 pBuf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
678 RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
679 bNeedAck, byFBOption);
680 pBuf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(pDevice,
681 RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate,
682 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100683 pBuf->data.duration = pBuf->wDuration_aa;
684 /*Get RTS Frame body*/
685 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400686
Malcolm Priestley07738932013-08-05 22:08:05 +0100687 if (pDevice->eOPMode == OP_MODE_ADHOC ||
688 pDevice->eOPMode == OP_MODE_AP)
689 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
690 else
691 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400692
Malcolm Priestley07738932013-08-05 22:08:05 +0100693 if (pDevice->eOPMode == OP_MODE_AP)
694 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
695 else
696 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400697 } // if (byFBOption == AUTO_FB_NONE)
698 }
699 else if (byPktType == PK_TYPE_11A) {
700 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100701 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400702 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700703 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500704 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400705 );
706 pBuf->wTransmitLength = cpu_to_le16(wLen);
707 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100708 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
709 cbFrameLength, byPktType, wCurrentRate,
710 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100711 pBuf->data.duration = pBuf->wDuration;
712 /* Get RTS Frame body */
713 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400714
Malcolm Priestley07738932013-08-05 22:08:05 +0100715 if (pDevice->eOPMode == OP_MODE_ADHOC ||
716 pDevice->eOPMode == OP_MODE_AP)
717 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
718 else
719 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400720
Malcolm Priestley07738932013-08-05 22:08:05 +0100721 if (pDevice->eOPMode == OP_MODE_AP)
722 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
723 else
724 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400725 }
726 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100727 struct vnt_rts_a_fb *pBuf = (struct vnt_rts_a_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400728 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700729 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500730 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400731 );
732 pBuf->wTransmitLength = cpu_to_le16(wLen);
733 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100734 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
735 cbFrameLength, byPktType, wCurrentRate,
736 bNeedAck, byFBOption);
737 pBuf->wRTSDuration_f0 = s_uGetRTSCTSDuration(pDevice,
738 RTSDUR_AA_F0, cbFrameLength, byPktType,
739 wCurrentRate, bNeedAck, byFBOption);
740 pBuf->wRTSDuration_f1 = s_uGetRTSCTSDuration(pDevice,
741 RTSDUR_AA_F1, cbFrameLength, byPktType,
742 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100743 pBuf->data.duration = pBuf->wDuration;
744 /* Get RTS Frame body */
745 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400746
Malcolm Priestley07738932013-08-05 22:08:05 +0100747 if (pDevice->eOPMode == OP_MODE_ADHOC ||
748 pDevice->eOPMode == OP_MODE_AP)
749 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
750 else
751 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
752
753 if (pDevice->eOPMode == OP_MODE_AP)
754 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
755 else
756 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400757 }
758 }
759 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100760 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400761 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700762 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500763 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400764 );
765 pBuf->wTransmitLength = cpu_to_le16(wLen);
766 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100767 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
768 cbFrameLength, byPktType, wCurrentRate,
769 bNeedAck, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400770
Malcolm Priestley07738932013-08-05 22:08:05 +0100771 pBuf->data.duration = pBuf->wDuration;
772 /* Get RTS Frame body */
773 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400774
Malcolm Priestley07738932013-08-05 22:08:05 +0100775 if (pDevice->eOPMode == OP_MODE_ADHOC ||
776 pDevice->eOPMode == OP_MODE_AP)
777 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
778 else
779 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
780
781 if (pDevice->eOPMode == OP_MODE_AP)
782 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
783 else
784 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400785 }
786}
787
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000788static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
789 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
790 int bDisCRC, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400791{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000792 u32 uCTSFrameLen = 14;
793 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400794
795 if (pvCTS == NULL) {
796 return;
797 }
798
799 if (bDisCRC) {
800 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
801 // in this case we need to decrease its length by 4.
802 uCTSFrameLen -= 4;
803 }
804
805 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100806 if (byFBOption != AUTO_FB_NONE) {
807 /* Auto Fall back */
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100808 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Forest Bond92b96792009-06-13 07:38:31 -0400809 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700810 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500811 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400812 );
813 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100814 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
815 cbFrameLength, byPktType,
816 wCurrentRate, bNeedAck, byFBOption);
817 /* Get CTSDuration_ba_f0 */
818 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
819 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
820 bNeedAck, byFBOption);
821 /* Get CTSDuration_ba_f1 */
822 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
823 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
824 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100825 /* Get CTS Frame body */
826 pBuf->data.duration = pBuf->wDuration_ba;
827 pBuf->data.frame_control = TYPE_CTL_CTS;
828 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100829 } else {
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100830 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Forest Bond92b96792009-06-13 07:38:31 -0400831 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700832 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500833 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400834 );
835 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100836 /* Get CTSDuration_ba */
837 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
838 CTSDUR_BA, cbFrameLength, byPktType,
839 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100840 /*Get CTS Frame body*/
841 pBuf->data.duration = pBuf->wDuration_ba;
842 pBuf->data.frame_control = TYPE_CTL_CTS;
843 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400844 }
845 }
846}
847
Forest Bond92b96792009-06-13 07:38:31 -0400848/*+
849 *
850 * Description:
851 * Generate FIFO control for MAC & Baseband controller
852 *
853 * Parameters:
854 * In:
855 * pDevice - Pointer to adpater
856 * pTxDataHead - Transmit Data Buffer
857 * pTxBufHead - pTxBufHead
858 * pvRrvTime - pvRrvTime
859 * pvRTS - RTS Buffer
860 * pCTS - CTS Buffer
861 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
862 * bNeedACK - If need ACK
863 * uDMAIdx - DMA Index
864 * Out:
865 * none
866 *
867 * Return Value: none
868 *
869-*/
Andres Morecc856e62010-05-17 21:34:01 -0300870
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000871static void s_vGenerateTxParameter(struct vnt_private *pDevice,
872 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
873 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500874 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400875{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000876 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
877 u16 wFifoCtl;
Andres Moree269fc22013-02-12 20:36:29 -0500878 int bDisCRC = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000879 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400880
881 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
882 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
883 pFifoHead->wReserved = wCurrentRate;
884 wFifoCtl = pFifoHead->wFIFOCtl;
885
886 if (wFifoCtl & FIFOCTL_CRCDIS) {
Andres More4e9b5e22013-02-12 20:36:30 -0500887 bDisCRC = true;
Forest Bond92b96792009-06-13 07:38:31 -0400888 }
889
890 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
891 byFBOption = AUTO_FB_0;
892 }
893 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
894 byFBOption = AUTO_FB_1;
895 }
896
897 if (pDevice->bLongHeader)
898 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
899
900 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
901
902 if (pvRTS != NULL) { //RTS_need
903 //Fill RsvTime
904 if (pvRrvTime) {
Malcolm Priestley6398a592013-08-16 21:26:55 +0100905 struct vnt_rrv_time_rts *pBuf =
906 (struct vnt_rrv_time_rts *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500907 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
908 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
909 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
910 pBuf->wTxRrvTime_a = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
911 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 -0400912 }
913 //Fill RTS
914 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
915 }
916 else {//RTS_needless, PCF mode
917
918 //Fill RsvTime
919 if (pvRrvTime) {
Malcolm Priestley4f990052013-08-16 23:38:57 +0100920 struct vnt_rrv_time_cts *pBuf =
921 (struct vnt_rrv_time_cts *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500922 pBuf->wTxRrvTime_a = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
923 pBuf->wTxRrvTime_b = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
924 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 -0400925 }
926 //Fill CTS
927 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
928 }
929 }
930 else if (byPktType == PK_TYPE_11A) {
931
932 if (pvRTS != NULL) {//RTS_need, non PCF mode
933 //Fill RsvTime
934 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100935 struct vnt_rrv_time_ab *pBuf =
936 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500937 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
938 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400939 }
940 //Fill RTS
941 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
942 }
943 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
944 //Fill RsvTime
945 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100946 struct vnt_rrv_time_ab *pBuf =
947 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500948 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400949 }
950 }
951 }
952 else if (byPktType == PK_TYPE_11B) {
953
954 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
955 //Fill RsvTime
956 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100957 struct vnt_rrv_time_ab *pBuf =
958 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500959 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
960 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400961 }
962 //Fill RTS
963 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
964 }
965 else { //RTS_needless, non PCF mode
966 //Fill RsvTime
967 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100968 struct vnt_rrv_time_ab *pBuf =
969 (struct vnt_rrv_time_ab *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500970 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400971 }
972 }
973 }
974 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
975}
976/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500977 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500978 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300979 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400980*/
981
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000982static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100983 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
984 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
985 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
986 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400987{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000988 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
989 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000990 u32 cb802_1_H_len;
991 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
992 u32 cbFCSlen = 4, cbMICHDR = 0;
993 int bNeedACK, bRTS;
994 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
995 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
996 u8 abySNAP_Bridgetunnel[ETH_ALEN]
997 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
998 u32 uDuration;
999 u32 cbHeaderLength = 0, uPadding = 0;
1000 void *pvRrvTime;
1001 PSMICHDRHead pMICHDR;
1002 void *pvRTS;
1003 void *pvCTS;
1004 void *pvTxDataHd;
1005 u8 byFBOption = AUTO_FB_NONE, byFragType;
1006 u16 wTxBufSize;
1007 u32 dwMICKey0, dwMICKey1, dwMIC_Priority, dwCRC;
1008 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001009 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -04001010
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001011 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001012
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001013 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001014 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1015 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001016 }
Forest Bond92b96792009-06-13 07:38:31 -04001017
Forest Bond92b96792009-06-13 07:38:31 -04001018 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001019 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001020 if (pDevice->dwDiagRefCount == 0) {
1021 cb802_1_H_len = 8;
1022 } else {
1023 cb802_1_H_len = 2;
1024 }
1025 } else {
1026 cb802_1_H_len = 0;
1027 }
1028
Charles Clément21ec51f2010-05-18 10:08:14 -07001029 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001030
1031 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001032 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001033
1034 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001035 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001036 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1037 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001038 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1039 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001040 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001041 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001042 pTxBufHead->wFIFOCtl =
1043 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1044 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001045 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001046 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1047 }
Forest Bond92b96792009-06-13 07:38:31 -04001048 }
1049 else {
1050 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001051 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001052 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1053 }
1054 } //if (pDevice->dwDiagRefCount != 0) {
1055
1056 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1057
1058 //Set FIFOCTL_LHEAD
1059 if (pDevice->bLongHeader)
1060 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1061
1062 if (pDevice->bSoftwareGenCrcErr) {
1063 pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS; // set tx descriptors to NO hardware CRC
1064 }
1065
1066 //Set FRAGCTL_MACHDCNT
1067 if (pDevice->bLongHeader) {
1068 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1069 } else {
1070 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1071 }
Andres More3eaca0d2013-02-25 20:32:52 -05001072 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001073
1074 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001075 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001076 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1077 }
1078
1079 //Set Auto Fallback Ctl
1080 if (wCurrentRate >= RATE_18M) {
1081 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1082 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1083 byFBOption = AUTO_FB_0;
1084 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1085 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1086 byFBOption = AUTO_FB_1;
1087 }
1088 }
1089
Andres More4e9b5e22013-02-12 20:36:30 -05001090 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001091 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1092 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1093 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1094 }
1095 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1096 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1097 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1098 }
1099 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1100 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1101 }
1102 }
1103 }
1104
Forest Bond92b96792009-06-13 07:38:31 -04001105 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1106 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1107 cbIVlen = 4;
1108 cbICVlen = 4;
1109 }
1110 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1111 cbIVlen = 8;//IV+ExtIV
1112 cbMIClen = 8;
1113 cbICVlen = 4;
1114 }
1115 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1116 cbIVlen = 8;//RSN Header
1117 cbICVlen = 8;//MIC
1118 cbMICHDR = sizeof(SMICHDRHead);
1119 }
Andres Moree269fc22013-02-12 20:36:29 -05001120 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001121 //MAC Header should be padding 0 to DW alignment.
1122 uPadding = 4 - (cbMACHdLen%4);
1123 uPadding %= 4;
1124 }
1125 }
1126
1127 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1128
Andres Moree269fc22013-02-12 20:36:29 -05001129 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1130 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001131 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001132 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001133 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1134 }
1135
Andres Moreb902fbf2013-02-25 20:32:51 -05001136 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001137 wTxBufSize = sizeof(STxBufHead);
1138 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1139 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001140 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001141 pvRrvTime = (struct vnt_rrv_time_rts *)
1142 (pbyTxBufferAddr + wTxBufSize);
1143 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1144 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001145 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001146 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001147 pvCTS = NULL;
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001148 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1149 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1150 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001151 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001152 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001153 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001154 }
1155 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001156 pvRrvTime = (struct vnt_rrv_time_cts *)
1157 (pbyTxBufferAddr + wTxBufSize);
1158 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1159 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001160 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001161 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001162 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001163 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1164 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1165 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001166 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1167 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001168 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001169 }
1170 } else {
1171 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001172 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001173 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1174 wTxBufSize);
1175 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1176 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001177 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001178 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001179 pvCTS = NULL;
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001180 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1181 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1182 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001183 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1184 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001185 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001186 }
Andres Moree269fc22013-02-12 20:36:29 -05001187 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001188 pvRrvTime = (struct vnt_rrv_time_cts *)
1189 (pbyTxBufferAddr + wTxBufSize);
1190 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1191 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001192 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001193 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001194 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001195 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001196 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1197 cbMICHDR + sizeof(struct vnt_cts_fb));
1198 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001199 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001200 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001201 }
1202 } // Auto Fall Back
1203 }
1204 else {//802.11a/b packet
1205 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001206 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001207 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1208 wTxBufSize);
1209 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1210 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001211 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001212 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001213 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001214 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1215 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001216 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001217 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1218 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001219 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001220 }
Andres Moree269fc22013-02-12 20:36:29 -05001221 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001222 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1223 wTxBufSize);
1224 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1225 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001226 pvRTS = NULL;
1227 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001228 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1229 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001230 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001231 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001232 }
1233 } else {
1234 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001235 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001236 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1237 wTxBufSize);
1238 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1239 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001240 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001241 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001242 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001243 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1244 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001245 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001246 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1247 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001248 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001249 }
Andres Moree269fc22013-02-12 20:36:29 -05001250 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001251 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1252 wTxBufSize);
1253 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1254 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001255 pvRTS = NULL;
1256 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001257 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1258 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001259 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001260 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001261 }
1262 } // Auto Fall Back
1263 }
1264
Andres Moreb902fbf2013-02-25 20:32:51 -05001265 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1266 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1267 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001268
Forest Bond92b96792009-06-13 07:38:31 -04001269 //=========================
1270 // No Fragmentation
1271 //=========================
1272 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1273 byFragType = FRAGCTL_NONFRAG;
1274 //uDMAIdx = TYPE_AC0DMA;
1275 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1276
Forest Bond92b96792009-06-13 07:38:31 -04001277 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001278 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1279 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001280 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1281 //Fill DataHead
1282 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001283 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001284 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001285 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001286 byFragType, uDMAIdx, 0);
1287
Andres More4e9b5e22013-02-12 20:36:30 -05001288 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001289 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001290 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001291 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001292
1293 if (pDevice->bEnableHostWEP) {
1294 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1295 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1296 }
1297 }
1298
1299 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001300 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001301 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001302 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1303 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001304 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001305 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001306 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001307 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001308 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001309 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001310 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001311 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001312 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001313
1314 }
1315
1316 }
1317
Forest Bond92b96792009-06-13 07:38:31 -04001318 if (pPacket != NULL) {
1319 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001320 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001321 (pPacket + ETH_HLEN),
1322 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001323 );
1324
1325 } else {
1326 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001327 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001328 }
1329
Andres More4e9b5e22013-02-12 20:36:30 -05001330 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001331
1332 ///////////////////////////////////////////////////////////////////
1333
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001334 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1335 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1336 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1337 }
Forest Bond92b96792009-06-13 07:38:31 -04001338 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001339 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1340 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001341 }
1342 else {
Andres More52a7e642013-02-25 20:32:53 -05001343 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1344 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001345 }
1346 // DO Software Michael
1347 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001348 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001349 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001350 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001351 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1352 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001353
1354 ///////////////////////////////////////////////////////////////////
1355
1356 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1357 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001358 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001359 //}
1360 //DBG_PRN_GRP12(("\n\n\n"));
1361
1362 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1363
Andres More52a7e642013-02-25 20:32:53 -05001364 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1365 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001366
1367 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1368 MIC_vUnInit();
1369
Andres More4e9b5e22013-02-12 20:36:30 -05001370 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001371 *pdwMIC_L = 0;
1372 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001373 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001374 }
1375 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1376 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1377 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1378 }
1379
Andres More4e9b5e22013-02-12 20:36:30 -05001380 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001381
Andres More3eaca0d2013-02-25 20:32:52 -05001382 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001383
Andres More4e9b5e22013-02-12 20:36:30 -05001384 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1385 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1386 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001387 cbFrameSize -= cbICVlen;
1388 }
1389
Andres More4e9b5e22013-02-12 20:36:30 -05001390 if (pDevice->bSoftwareGenCrcErr == true) {
Andres Morecc856e62010-05-17 21:34:01 -03001391 unsigned int cbLen;
Andres More52a7e642013-02-25 20:32:53 -05001392 u32 * pdwCRC;
Forest Bond92b96792009-06-13 07:38:31 -04001393
1394 dwCRC = 0xFFFFFFFFL;
1395 cbLen = cbFrameSize - cbFCSlen;
1396 // calculate CRC, and wrtie CRC value to end of TD
1397 dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
Andres More52a7e642013-02-25 20:32:53 -05001398 pdwCRC = (u32 *)(pbyMacHdr + cbLen);
Forest Bond92b96792009-06-13 07:38:31 -04001399 // finally, we must invert dwCRC to get the correct answer
1400 *pdwCRC = ~dwCRC;
1401 // Force Error
1402 *pdwCRC -= 1;
1403 } else {
1404 cbFrameSize -= cbFCSlen;
1405 }
1406
1407 *pcbHeaderLen = cbHeaderLength;
1408 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1409
Forest Bond92b96792009-06-13 07:38:31 -04001410 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001411 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001412
Andres More4e9b5e22013-02-12 20:36:30 -05001413 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001414
1415}
1416
Forest Bond92b96792009-06-13 07:38:31 -04001417/*+
1418 *
1419 * Description:
1420 * Translate 802.3 to 802.11 header
1421 *
1422 * Parameters:
1423 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001424 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001425 * dwTxBufferAddr - Transmit Buffer
1426 * pPacket - Packet from upper layer
1427 * cbPacketSize - Transmit Data Length
1428 * Out:
1429 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1430 * pcbAppendPayload - size of append payload for 802.1H translation
1431 *
1432 * Return Value: none
1433 *
1434-*/
1435
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001436static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001437 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001438 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001439{
Andres More1cac4a42013-03-18 20:33:50 -05001440 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001441
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001442 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001443
1444 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001445 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001446 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001447 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001448 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1449 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001450 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001451 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001452 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001453 } else {
1454 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001455 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001456 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001457 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001458 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001459 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001460 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001461 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001462 &(pDevice->abyBSSID[0]),
1463 ETH_ALEN);
1464 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001465 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001466 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001467 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001468 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001469 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001470 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001471 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001472 &(pDevice->abyBSSID[0]),
1473 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001474 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001475 }
1476 }
1477
1478 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001479 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001480
Andres More1cac4a42013-03-18 20:33:50 -05001481 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001482
1483 if (pDevice->bLongHeader) {
1484 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001485 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001486 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001487 }
Andres More1cac4a42013-03-18 20:33:50 -05001488 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001489
1490 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001491 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001492
1493 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1494 pDevice->wSeqCounter++;
1495 if (pDevice->wSeqCounter > 0x0fff)
1496 pDevice->wSeqCounter = 0;
1497 }
1498
1499 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001500 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001501 }
1502}
1503
Forest Bond92b96792009-06-13 07:38:31 -04001504/*+
1505 *
1506 * Description:
1507 * Request instructs a MAC to transmit a 802.11 management packet through
1508 * the adapter onto the medium.
1509 *
1510 * Parameters:
1511 * In:
1512 * hDeviceContext - Pointer to the adapter
1513 * pPacket - A pointer to a descriptor for the packet to transmit
1514 * Out:
1515 * none
1516 *
Andres Moree269fc22013-02-12 20:36:29 -05001517 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001518 *
1519-*/
1520
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001521CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1522 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001523{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001524 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001525 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001526 PSTxBufHead pTxBufHead;
1527 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001528 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001529 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001530 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001531 u8 byPktType, *pbyTxBufferAddr;
1532 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1533 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001534 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001535 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1536 u32 uPadding = 0;
1537 u16 wTxBufSize;
1538 u32 cbMacHdLen;
1539 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001540
Forest Bond92b96792009-06-13 07:38:31 -04001541 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1542
1543 if (NULL == pContext) {
1544 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1545 return CMD_STATUS_RESOURCES;
1546 }
1547
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001548 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001549 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001550 cbFrameBodySize = pPacket->cbPayloadLen;
1551 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1552 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001553
1554 if (pDevice->byBBType == BB_TYPE_11A) {
1555 wCurrentRate = RATE_6M;
1556 byPktType = PK_TYPE_11A;
1557 } else {
1558 wCurrentRate = RATE_1M;
1559 byPktType = PK_TYPE_11B;
1560 }
1561
1562 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1563 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1564 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1565 // to set power here.
1566 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1567 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1568 } else {
1569 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1570 }
1571 pDevice->wCurrentRate = wCurrentRate;
1572
Forest Bond92b96792009-06-13 07:38:31 -04001573 //Set packet type
1574 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1575 pTxBufHead->wFIFOCtl = 0;
1576 }
1577 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1578 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1579 }
1580 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1581 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1582 }
1583 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1584 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1585 }
1586
1587 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1588 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1589
Andres More22040bb2010-08-02 20:21:44 -03001590 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001591 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001592 }
1593 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001594 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001595 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1596 };
1597
1598 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1599 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1600
1601 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1602 //Set Preamble type always long
1603 //pDevice->byPreambleType = PREAMBLE_LONG;
1604 // probe-response don't retry
1605 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001606 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001607 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1608 //}
1609 }
1610
1611 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1612
1613 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001614 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001615 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1616 } else {
1617 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1618 }
1619
1620 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001621 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001622
1623 // Notes:
1624 // Although spec says MMPDU can be fragmented; In most case,
1625 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001626 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001627
1628 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1629 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1630 cbIVlen = 4;
1631 cbICVlen = 4;
1632 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1633 }
1634 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1635 cbIVlen = 8;//IV+ExtIV
1636 cbMIClen = 8;
1637 cbICVlen = 4;
1638 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1639 //We need to get seed here for filling TxKey entry.
1640 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1641 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1642 }
1643 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1644 cbIVlen = 8;//RSN Header
1645 cbICVlen = 8;//MIC
1646 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001647 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001648 }
1649 //MAC Header should be padding 0 to DW alignment.
1650 uPadding = 4 - (cbMacHdLen%4);
1651 uPadding %= 4;
1652 }
1653
1654 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1655
1656 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001657 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001658 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1659 }
1660 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1661
1662 //Set RrvTime/RTS/CTS Buffer
1663 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1664
Malcolm Priestley4f990052013-08-16 23:38:57 +01001665 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001666 pMICHDR = NULL;
1667 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001668 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001669 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001670 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001671 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1672 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001673 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001674 }
1675 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001676 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001677 pMICHDR = NULL;
1678 pvRTS = NULL;
1679 pCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001680 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1681 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001682 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001683 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001684 }
1685
Andres Moreceb8c5d2013-03-18 20:33:49 -05001686 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001687 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1688 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001689 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001690 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1691 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001692 //=========================
1693 // No Fragmentation
1694 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001695 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001696
Forest Bond92b96792009-06-13 07:38:31 -04001697 //Fill FIFO,RrvTime,RTS,and CTS
1698 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1699 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1700
1701 //Fill DataHead
1702 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001703 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001704
Andres More1cac4a42013-03-18 20:33:50 -05001705 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001706
1707 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1708
1709 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001710 u8 * pbyIVHead;
1711 u8 * pbyPayloadHead;
1712 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001713 PSKeyItem pTransmitKey = NULL;
1714
Andres Moreb902fbf2013-02-25 20:32:51 -05001715 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1716 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001717 do {
1718 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001719 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001720 pbyBSSID = pDevice->abyBSSID;
1721 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001722 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001723 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001724 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001725 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1726 break;
1727 }
1728 } else {
1729 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1730 break;
1731 }
1732 }
1733 // get group key
1734 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001735 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001736 pTransmitKey = NULL;
1737 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1738 } else {
1739 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1740 }
Andres Moree269fc22013-02-12 20:36:29 -05001741 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001742 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001743 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001744 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001745
Jim Lieb3e362592009-08-12 14:54:11 -07001746 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001747 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001748 cbFrameBodySize);
1749 }
1750 else {
1751 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001752 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001753 }
1754
Andres More1cac4a42013-03-18 20:33:50 -05001755 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001756 pDevice->wSeqCounter++ ;
1757 if (pDevice->wSeqCounter > 0x0fff)
1758 pDevice->wSeqCounter = 0;
1759
1760 if (bIsPSPOLL) {
1761 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001762 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001763 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1764 // in the same place of other packet's Duration-field).
1765 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001766 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1767 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1768 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1769 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1770 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1771 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001772 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1773 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1774 }
Forest Bond92b96792009-06-13 07:38:31 -04001775 }
1776
Andres More3eaca0d2013-02-25 20:32:52 -05001777 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001778 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001779 pTX_Buffer->byType = 0x00;
1780
1781 pContext->pPacket = NULL;
1782 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001783 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001784
Andres More1cac4a42013-03-18 20:33:50 -05001785 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1786 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001787 }
1788 else {
Andres More1cac4a42013-03-18 20:33:50 -05001789 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001790 }
1791
1792 PIPEnsSendBulkOut(pDevice,pContext);
1793 return CMD_STATUS_PENDING;
1794}
1795
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001796CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1797 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001798{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001799 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001800 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1801 u32 cbHeaderSize = 0;
1802 u16 wTxBufSize = sizeof(STxShortBufHead);
1803 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001804 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001805 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001806 u16 wCurrentRate;
1807 u32 cbFrameBodySize;
1808 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001809 u8 *pbyTxBufferAddr;
1810 PUSB_SEND_CONTEXT pContext;
1811 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001812
Forest Bond92b96792009-06-13 07:38:31 -04001813 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1814 if (NULL == pContext) {
1815 status = CMD_STATUS_RESOURCES;
1816 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1817 return status ;
1818 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001819
1820 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001821 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001822
1823 cbFrameBodySize = pPacket->cbPayloadLen;
1824
1825 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1826 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001827
1828 if (pDevice->byBBType == BB_TYPE_11A) {
1829 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001830 pTxDataHead = (struct vnt_tx_datahead_ab *)
1831 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001832 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001833 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
Andres More3eaca0d2013-02-25 20:32:52 -05001834 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001835 );
1836 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +01001837 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice,
1838 DATADUR_A, PK_TYPE_11A, false));
Forest Bond92b96792009-06-13 07:38:31 -04001839 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestley558becf2013-08-16 23:50:32 +01001840 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001841 } else {
1842 wCurrentRate = RATE_1M;
1843 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001844 pTxDataHead = (struct vnt_tx_datahead_ab *)
1845 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001846 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001847 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -05001848 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001849 );
1850 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +01001851 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice,
1852 DATADUR_B, PK_TYPE_11B, false));
Forest Bond92b96792009-06-13 07:38:31 -04001853 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
Malcolm Priestley558becf2013-08-16 23:50:32 +01001854 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001855 }
1856
1857 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001858 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001859 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001860
Andres More1cac4a42013-03-18 20:33:50 -05001861 pMACHeader->duration_id = 0;
1862 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001863 pDevice->wSeqCounter++ ;
1864 if (pDevice->wSeqCounter > 0x0fff)
1865 pDevice->wSeqCounter = 0;
1866
1867 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1868
Andres More3eaca0d2013-02-25 20:32:52 -05001869 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001870 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001871 pTX_Buffer->byType = 0x01;
1872
1873 pContext->pPacket = NULL;
1874 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001875 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001876
1877 PIPEnsSendBulkOut(pDevice,pContext);
1878 return CMD_STATUS_PENDING;
1879
1880}
1881
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001882void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1883{
1884 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001885 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001886 u8 byPktType;
1887 u8 *pbyTxBufferAddr;
1888 void *pvRTS, *pvCTS, *pvTxDataHd;
1889 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001890 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001891 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001892 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001893 PSTxBufHead pTxBufHead;
1894 u32 cbFrameSize;
1895 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1896 u32 uPadding = 0;
1897 u32 cbMICHDR = 0, uLength = 0;
1898 u32 dwMICKey0, dwMICKey1;
1899 u32 dwMIC_Priority;
1900 u32 *pdwMIC_L, *pdwMIC_R;
1901 u16 wTxBufSize;
1902 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001903 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001904 void *pvRrvTime, *pMICHDR;
1905 u32 wCurrentRate = RATE_1M;
1906 PUWLAN_80211HDR p80211Header;
1907 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001908 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001909 SKeyItem STempKey;
1910 PSKeyItem pTransmitKey = NULL;
1911 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1912 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001913 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001914
Forest Bond92b96792009-06-13 07:38:31 -04001915 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1916
1917 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1918 cbFrameBodySize = 0;
1919 }
1920 else {
1921 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1922 }
1923 p80211Header = (PUWLAN_80211HDR)skb->data;
1924
1925 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1926
1927 if (NULL == pContext) {
1928 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1929 dev_kfree_skb_irq(skb);
1930 return ;
1931 }
1932
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001933 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001934 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001935 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1936 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001937
1938 if (pDevice->byBBType == BB_TYPE_11A) {
1939 wCurrentRate = RATE_6M;
1940 byPktType = PK_TYPE_11A;
1941 } else {
1942 wCurrentRate = RATE_1M;
1943 byPktType = PK_TYPE_11B;
1944 }
1945
1946 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1947 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1948 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1949 // to set power here.
1950 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1951 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1952 } else {
1953 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1954 }
1955
1956 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1957
1958 //Set packet type
1959 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1960 pTxBufHead->wFIFOCtl = 0;
1961 }
1962 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1963 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1964 }
1965 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1966 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1967 }
1968 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1969 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1970 }
1971
1972 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1973 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1974
Andres More22040bb2010-08-02 20:21:44 -03001975 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001976 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001977 if (pDevice->bEnableHostWEP) {
1978 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001979 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001980 }
Forest Bond92b96792009-06-13 07:38:31 -04001981 }
1982 else {
1983 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001984 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001985 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001986 }
Andres More4e9b5e22013-02-12 20:36:30 -05001987 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001988 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1989 };
1990
1991 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1992 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1993
1994 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1995 //Set Preamble type always long
1996 //pDevice->byPreambleType = PREAMBLE_LONG;
1997
1998 // probe-response don't retry
1999 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05002000 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04002001 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2002 //}
2003 }
2004
2005 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2006
2007 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05002008 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04002009 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2010 } else {
2011 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2012 }
2013
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002014 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04002015 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2016
2017 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
2018 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2019 }
2020
2021 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
2022 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2023 }
2024
2025 if (cbExtSuppRate >0) {
2026 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2027 }
2028 }
2029
Forest Bond92b96792009-06-13 07:38:31 -04002030 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05002031 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04002032
2033 // Notes:
2034 // Although spec says MMPDU can be fragmented; In most case,
2035 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05002036 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04002037
Forest Bond92b96792009-06-13 07:38:31 -04002038 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2039 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2040 cbIVlen = 4;
2041 cbICVlen = 4;
2042 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2043 }
2044 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2045 cbIVlen = 8;//IV+ExtIV
2046 cbMIClen = 8;
2047 cbICVlen = 4;
2048 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2049 //We need to get seed here for filling TxKey entry.
2050 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2051 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2052 }
2053 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2054 cbIVlen = 8;//RSN Header
2055 cbICVlen = 8;//MIC
2056 cbMICHDR = sizeof(SMICHDRHead);
2057 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002058 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002059 }
2060 //MAC Header should be padding 0 to DW alignment.
2061 uPadding = 4 - (cbMacHdLen%4);
2062 uPadding %= 4;
2063 }
2064
2065 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2066
2067 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002068 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002069 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2070 }
2071 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2072
Forest Bond92b96792009-06-13 07:38:31 -04002073 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002074 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
2075 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
2076 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002077 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002078 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002079 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002080 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2081 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002082 sizeof(struct vnt_cts));
2083 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002084 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002085
2086 }
2087 else {//802.11a/b packet
2088
Malcolm Priestley976467d2013-08-16 23:44:04 +01002089 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
2090 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
2091 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002092 pvRTS = NULL;
2093 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01002094 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2095 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002096 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002097 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002098 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002099 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002100 &(p80211Header->sA3.abyAddr1[0]),
2101 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002102 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002103 &(p80211Header->sA3.abyAddr2[0]),
2104 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002105 //=========================
2106 // No Fragmentation
2107 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002108 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002109
Forest Bond92b96792009-06-13 07:38:31 -04002110 //Fill FIFO,RrvTime,RTS,and CTS
2111 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2112 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2113
2114 //Fill DataHead
2115 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002116 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002117
Andres More1cac4a42013-03-18 20:33:50 -05002118 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002119
2120 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2121
Andres Moreb902fbf2013-02-25 20:32:51 -05002122 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2123 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2124 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002125
2126 // Copy the Packet into a tx Buffer
2127 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2128
2129 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002130 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002131 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2132
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002133 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002134 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2135 if (cbExtSuppRate != 0) {
2136 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2137 memcpy((pbyPayloadHead + cbFrameBodySize),
2138 pMgmt->abyCurrSuppRates,
2139 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2140 );
2141 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2142 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2143 pMgmt->abyCurrExtSuppRates,
2144 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2145 );
2146 }
2147 }
2148
2149 // Set wep
2150 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2151
2152 if (pDevice->bEnableHostWEP) {
2153 pTransmitKey = &STempKey;
2154 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2155 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2156 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2157 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2158 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2159 memcpy(pTransmitKey->abyKey,
2160 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2161 pTransmitKey->uKeyLength
2162 );
2163 }
2164
2165 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2166
Andres More52a7e642013-02-25 20:32:53 -05002167 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2168 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002169
2170 // DO Software Michael
2171 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002172 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002173 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002174 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002175 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2176 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002177
2178 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2179
2180 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2181
Andres More52a7e642013-02-25 20:32:53 -05002182 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2183 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002184
2185 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2186 MIC_vUnInit();
2187
Andres More4e9b5e22013-02-12 20:36:30 -05002188 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002189 *pdwMIC_L = 0;
2190 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002191 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002192 }
2193
2194 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2195 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002196 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2197 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002198
2199 }
2200
Andres Moreb902fbf2013-02-25 20:32:51 -05002201 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05002202 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002203
2204 if (pDevice->bEnableHostWEP) {
2205 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2206 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2207 }
2208
2209 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002210 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002211 }
2212 }
2213
Andres More1cac4a42013-03-18 20:33:50 -05002214 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002215 pDevice->wSeqCounter++ ;
2216 if (pDevice->wSeqCounter > 0x0fff)
2217 pDevice->wSeqCounter = 0;
2218
Forest Bond92b96792009-06-13 07:38:31 -04002219 if (bIsPSPOLL) {
2220 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2221 // of FIFO control header.
2222 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2223 // in the same place of other packet's Duration-field).
2224 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002225 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2226 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2227 cpu_to_le16(p80211Header->sA2.wDurationID);
2228 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2229 cpu_to_le16(p80211Header->sA2.wDurationID);
2230 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002231 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2232 cpu_to_le16(p80211Header->sA2.wDurationID);
2233 }
Forest Bond92b96792009-06-13 07:38:31 -04002234 }
2235
Andres More3eaca0d2013-02-25 20:32:52 -05002236 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002237 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002238 pTX_Buffer->byType = 0x00;
2239
2240 pContext->pPacket = skb;
2241 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002242 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002243
Andres More1cac4a42013-03-18 20:33:50 -05002244 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2245 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002246 }
2247 else {
Andres More1cac4a42013-03-18 20:33:50 -05002248 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002249 }
2250 PIPEnsSendBulkOut(pDevice,pContext);
2251 return ;
2252
2253}
2254
Forest Bond92b96792009-06-13 07:38:31 -04002255//TYPE_AC0DMA data tx
2256/*
2257 * Description:
2258 * Tx packet via AC0DMA(DMA1)
2259 *
2260 * Parameters:
2261 * In:
2262 * pDevice - Pointer to the adapter
2263 * skb - Pointer to tx skb packet
2264 * Out:
2265 * void
2266 *
2267 * Return Value: NULL
2268 */
2269
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002270int nsDMA_tx_packet(struct vnt_private *pDevice,
2271 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002272{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002273 struct net_device_stats *pStats = &pDevice->stats;
2274 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002275 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002276 u32 BytesToWrite = 0, uHeaderLen = 0;
2277 u32 uNodeIndex = 0;
2278 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2279 u16 wAID;
2280 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002281 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002282 PSKeyItem pTransmitKey = NULL;
2283 SKeyItem STempKey;
2284 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002285 int bTKIP_UseGTK = false;
2286 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002287 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002288 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002289 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002290 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002291 u32 status;
2292 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002293 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002294
Forest Bond92b96792009-06-13 07:38:31 -04002295 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2296
2297 if (pDevice->uAssocCount == 0) {
2298 dev_kfree_skb_irq(skb);
2299 return 0;
2300 }
2301
Andres Moreb902fbf2013-02-25 20:32:51 -05002302 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002303 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002304 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002305 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2306
2307 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2308 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2309 // set tx map
2310 pMgmt->abyPSTxMap[0] |= byMask[0];
2311 return 0;
2312 }
Masanari Iida93184692012-08-13 21:21:50 +09002313 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002314
2315 if (pDevice->byBBType != BB_TYPE_11A)
2316 pDevice->wCurrentRate = RATE_2M;
2317 else
2318 pDevice->wCurrentRate = RATE_24M;
2319 // long preamble type
2320 pDevice->byPreambleType = PREAMBLE_SHORT;
2321
2322 }else {
2323
Andres Moreb902fbf2013-02-25 20:32:51 -05002324 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002325
2326 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2327
2328 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2329
2330 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2331 // set tx map
2332 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2333 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2334 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2335 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2336
2337 return 0;
2338 }
2339 // AP rate decided from node
2340 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2341 // tx preamble decided from node
2342
2343 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2344 pDevice->byPreambleType = pDevice->byShortPreamble;
2345
2346 }else {
2347 pDevice->byPreambleType = PREAMBLE_LONG;
2348 }
Andres More4e9b5e22013-02-12 20:36:30 -05002349 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002350 }
2351 }
2352
Andres Moree269fc22013-02-12 20:36:29 -05002353 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002354 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2355 dev_kfree_skb_irq(skb);
2356 return 0;
2357 }
2358 }
2359
2360 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2361
2362 if (pContext == NULL) {
2363 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2364 dev_kfree_skb_irq(skb);
2365 return STATUS_RESOURCES;
2366 }
2367
Andres Moreceb8c5d2013-03-18 20:33:49 -05002368 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002369
2370//mike add:station mode check eapol-key challenge--->
2371{
Andres Moreb902fbf2013-02-25 20:32:51 -05002372 u8 Protocol_Version; //802.1x Authentication
2373 u8 Packet_Type; //802.1x Authentication
2374 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002375 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002376
Charles Clément21ec51f2010-05-18 10:08:14 -07002377 Protocol_Version = skb->data[ETH_HLEN];
2378 Packet_Type = skb->data[ETH_HLEN+1];
2379 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2380 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 -05002381 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002382 /* 802.1x OR eapol-key challenge frame transfer */
2383 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2384 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002385 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002386 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2387 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2388 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002389 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002390 PRINT_K("WPA ");
2391 }
2392 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002393 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002394 PRINT_K("WPA2(re-keying) ");
2395 }
2396 PRINT_K("Authentication completed!!\n");
2397 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002398 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002399 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002400 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002401 PRINT_K("WPA2 Authentication completed!!\n");
2402 }
2403 }
2404 }
2405}
2406//mike add:station mode check eapol-key challenge<---
2407
Andres More4e9b5e22013-02-12 20:36:30 -05002408 if (pDevice->bEncryptionEnable == true) {
2409 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002410 // get Transmit key
2411 do {
2412 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2413 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2414 pbyBSSID = pDevice->abyBSSID;
2415 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002416 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002417 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002418 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2419 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002420 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2421 break;
2422 }
2423 } else {
2424 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2425 break;
2426 }
2427 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002428 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2429 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002430 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2431 for (ii = 0; ii< 6; ii++)
2432 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2433 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2434
2435 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002436 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002437 break;
2438 }
2439 // get group key
2440 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002441 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002442 pTransmitKey = NULL;
2443 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2444 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2445 }
2446 else
2447 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2448 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002449 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002450 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2451 }
Andres Moree269fc22013-02-12 20:36:29 -05002452 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002453 }
2454
2455 if (pDevice->bEnableHostWEP) {
2456 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002457 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002458 pTransmitKey = &STempKey;
2459 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2460 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2461 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2462 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2463 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2464 memcpy(pTransmitKey->abyKey,
2465 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2466 pTransmitKey->uKeyLength
2467 );
2468 }
2469 }
2470
Andres Moreb902fbf2013-02-25 20:32:51 -05002471 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002472
2473 if (pDevice->bFixRate) {
2474 if (pDevice->byBBType == BB_TYPE_11B) {
2475 if (pDevice->uConnectionRate >= RATE_11M) {
2476 pDevice->wCurrentRate = RATE_11M;
2477 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002478 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002479 }
2480 } else {
2481 if ((pDevice->byBBType == BB_TYPE_11A) &&
2482 (pDevice->uConnectionRate <= RATE_6M)) {
2483 pDevice->wCurrentRate = RATE_6M;
2484 } else {
2485 if (pDevice->uConnectionRate >= RATE_54M)
2486 pDevice->wCurrentRate = RATE_54M;
2487 else
Andres More3eaca0d2013-02-25 20:32:52 -05002488 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002489 }
2490 }
2491 }
2492 else {
2493 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2494 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002495 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002496 // Multicast use highest data rate
2497 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2498 // preamble type
2499 pDevice->byPreambleType = pDevice->byShortPreamble;
2500 }
2501 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002502 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002503 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2504 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2505 pDevice->byPreambleType = pDevice->byShortPreamble;
2506
2507 }
2508 else {
2509 pDevice->byPreambleType = PREAMBLE_LONG;
2510 }
2511 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2512 }
2513 else {
2514 if (pDevice->byBBType != BB_TYPE_11A)
2515 pDevice->wCurrentRate = RATE_2M;
2516 else
2517 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2518 // abyCurrExtSuppRates[]
2519 pDevice->byPreambleType = PREAMBLE_SHORT;
2520 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2521 }
2522 }
2523 }
2524 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2525 // Infra STA rate decided from AP Node, index = 0
2526 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2527 }
2528 }
2529
Andres Moreceb8c5d2013-03-18 20:33:49 -05002530 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002531 if (pDevice->byBBType != BB_TYPE_11A) {
2532 pDevice->wCurrentRate = RATE_1M;
2533 pDevice->byACKRate = RATE_1M;
2534 pDevice->byTopCCKBasicRate = RATE_1M;
2535 pDevice->byTopOFDMBasicRate = RATE_6M;
2536 } else {
2537 pDevice->wCurrentRate = RATE_6M;
2538 pDevice->byACKRate = RATE_6M;
2539 pDevice->byTopCCKBasicRate = RATE_1M;
2540 pDevice->byTopOFDMBasicRate = RATE_6M;
2541 }
2542 }
Forest Bond92b96792009-06-13 07:38:31 -04002543
Andres More0cbd8d92010-05-06 20:34:29 -03002544 DBG_PRT(MSG_LEVEL_DEBUG,
2545 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2546 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002547
2548 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002549 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002550 }
2551
2552 if (pDevice->wCurrentRate <= RATE_11M) {
2553 byPktType = PK_TYPE_11B;
2554 }
2555
Andres More4e9b5e22013-02-12 20:36:30 -05002556 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002557 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2558 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002559 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002560 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002561 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2562 if (pTransmitKey == NULL) {
2563 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2564 }
2565 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002566 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002567 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2568 }
2569 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002570 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2571 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002572 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002573 }
2574 }
2575 }
2576
Forest Bond92b96792009-06-13 07:38:31 -04002577 if (pDevice->bEnableHostWEP) {
2578 if ((uNodeIndex != 0) &&
2579 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002580 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2581 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002582 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002583 }
2584 }
2585 }
2586 else {
2587
Forest Bond92b96792009-06-13 07:38:31 -04002588 if (pTransmitKey == NULL) {
2589 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002590 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002591 dev_kfree_skb_irq(skb);
2592 pStats->tx_dropped++;
2593 return STATUS_FAILURE;
2594 }
Forest Bond92b96792009-06-13 07:38:31 -04002595 }
2596 }
2597
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002598 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2599
Forest Bond92b96792009-06-13 07:38:31 -04002600 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002601 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002602 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002603 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002604 pDevice->wCurrentRate,
2605 &uHeaderLen, &BytesToWrite
2606 );
2607
Andres Moree269fc22013-02-12 20:36:29 -05002608 if (fConvertedPacket == false) {
2609 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002610 dev_kfree_skb_irq(skb);
2611 return STATUS_FAILURE;
2612 }
2613
Andres More4e9b5e22013-02-12 20:36:30 -05002614 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002615 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002616 bScheduleCommand((void *) pDevice,
2617 WLAN_CMD_MAC_DISPOWERSAVING,
2618 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002619 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002620 }
2621 }
2622
Andres Moreb902fbf2013-02-25 20:32:51 -05002623 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002624 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002625
2626 pContext->pPacket = skb;
2627 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002628 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002629
Andres Moreceb8c5d2013-03-18 20:33:49 -05002630 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 -04002631
2632 status = PIPEnsSendBulkOut(pDevice,pContext);
2633
Andres More4e9b5e22013-02-12 20:36:30 -05002634 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002635 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002636
Andres Moreb902fbf2013-02-25 20:32:51 -05002637 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002638 }
2639
2640 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002641 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002642 dev_kfree_skb_irq(skb);
2643 return STATUS_FAILURE;
2644 }
2645 else
2646 return 0;
2647
2648}
2649
Forest Bond92b96792009-06-13 07:38:31 -04002650/*
2651 * Description:
2652 * Relay packet send (AC1DMA) from rx dpc.
2653 *
2654 * Parameters:
2655 * In:
2656 * pDevice - Pointer to the adapter
2657 * pPacket - Pointer to rx packet
2658 * cbPacketSize - rx ethernet frame size
2659 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002660 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002661 *
Andres More4e9b5e22013-02-12 20:36:30 -05002662 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002663 */
2664
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002665int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2666 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002667{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002668 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002669 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002670 u32 BytesToWrite = 0, uHeaderLen = 0;
2671 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002672 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002673 SKeyItem STempKey;
2674 PSKeyItem pTransmitKey = NULL;
2675 u8 *pbyBSSID;
2676 PUSB_SEND_CONTEXT pContext;
2677 u8 byPktTyp;
2678 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002679 u32 status;
2680 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002681
Forest Bond92b96792009-06-13 07:38:31 -04002682 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2683
2684 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002685 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002686 }
2687
Andres Moreceb8c5d2013-03-18 20:33:49 -05002688 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002689
Andres More4e9b5e22013-02-12 20:36:30 -05002690 if (pDevice->bEncryptionEnable == true) {
2691 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002692 // get group key
2693 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002694 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002695 pTransmitKey = NULL;
2696 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2697 } else {
2698 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2699 }
2700 }
2701
2702 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002703 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002704 pTransmitKey = &STempKey;
2705 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2706 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2707 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2708 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2709 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2710 memcpy(pTransmitKey->abyKey,
2711 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2712 pTransmitKey->uKeyLength
2713 );
2714 }
2715 }
2716
2717 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002718 pContext->bBoolInUse = false;
2719 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002720 }
2721
Andres Moreb902fbf2013-02-25 20:32:51 -05002722 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002723
2724 if (pDevice->bFixRate) {
2725 if (pDevice->byBBType == BB_TYPE_11B) {
2726 if (pDevice->uConnectionRate >= RATE_11M) {
2727 pDevice->wCurrentRate = RATE_11M;
2728 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002729 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002730 }
2731 } else {
2732 if ((pDevice->byBBType == BB_TYPE_11A) &&
2733 (pDevice->uConnectionRate <= RATE_6M)) {
2734 pDevice->wCurrentRate = RATE_6M;
2735 } else {
2736 if (pDevice->uConnectionRate >= RATE_54M)
2737 pDevice->wCurrentRate = RATE_54M;
2738 else
Andres More3eaca0d2013-02-25 20:32:52 -05002739 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002740 }
2741 }
2742 }
2743 else {
2744 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2745 }
2746
Forest Bond92b96792009-06-13 07:38:31 -04002747 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002748 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002749 }
2750
2751 if (pDevice->wCurrentRate <= RATE_11M)
2752 byPktType = PK_TYPE_11B;
2753
Andres Moreabad19d2010-07-12 16:28:32 -03002754 BytesToWrite = uDataLen + ETH_FCS_LEN;
2755
Forest Bond92b96792009-06-13 07:38:31 -04002756 // Convert the packet to an usb frame and copy into our buffer
2757 // and send the irp.
2758
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002759 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2760
Forest Bond92b96792009-06-13 07:38:31 -04002761 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002762 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002763 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2764 pbySkbData, pTransmitKey, uNodeIndex,
2765 pDevice->wCurrentRate,
2766 &uHeaderLen, &BytesToWrite
2767 );
2768
Andres Moree269fc22013-02-12 20:36:29 -05002769 if (fConvertedPacket == false) {
2770 pContext->bBoolInUse = false;
2771 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002772 }
2773
Andres Moreb902fbf2013-02-25 20:32:51 -05002774 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002775 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002776
2777 pContext->pPacket = NULL;
2778 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002779 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002780
Andres Moreceb8c5d2013-03-18 20:33:49 -05002781 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 -04002782
2783 status = PIPEnsSendBulkOut(pDevice,pContext);
2784
Andres More4e9b5e22013-02-12 20:36:30 -05002785 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002786}
2787