blob: 9c52c313aba49d9104f72c26f5fa8855b95224c1 [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020034 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040035 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020038 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040039 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
44 *
45 * Revision History:
46 *
47 */
48
Forest Bond92b96792009-06-13 07:38:31 -040049#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "tether.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "baseband.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040064#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070065
Mariano Reingart4a499de2010-10-29 19:15:26 -030066static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040067
Andres More3eaca0d2013-02-25 20:32:52 -050068const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040069 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
70 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
71 };
72
Andres More3eaca0d2013-02-25 20:32:52 -050073const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040074 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
75 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
76 };
Andres More3eaca0d2013-02-25 20:32:52 -050077const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040078 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
79 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
80 };
81
Forest Bond92b96792009-06-13 07:38:31 -040082#define RTSDUR_BB 0
83#define RTSDUR_BA 1
84#define RTSDUR_AA 2
85#define CTSDUR_BA 3
86#define RTSDUR_BA_F0 4
87#define RTSDUR_AA_F0 5
88#define RTSDUR_BA_F1 6
89#define RTSDUR_AA_F1 7
90#define CTSDUR_BA_F0 8
91#define CTSDUR_BA_F1 9
92#define DATADUR_B 10
93#define DATADUR_A 11
94#define DATADUR_A_F0 12
95#define DATADUR_A_F1 13
96
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000097static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
98 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040099
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000100static void *s_vGetFreeContext(struct vnt_private *pDevice);
101
102static void s_vGenerateTxParameter(struct vnt_private *pDevice,
103 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
104 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500105 struct ethhdr *psEthHeader);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000106
107static u32 s_uFillDataHead(struct vnt_private *pDevice,
108 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100109 u32 uDMAIdx, int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400110
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000111static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500112 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000113 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400114
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000115static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
116 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
117 u8 *pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -0400118
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000119static void s_vSWencryption(struct vnt_private *pDevice,
120 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400121
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000122static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
123 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400124
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000125static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
126 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400127
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000128static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
129 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
130 int bDisCRC, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400131
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000132static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
133 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500134 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400135
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000136static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100137 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400138
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100139static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000140 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
141 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400142
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000143static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400144{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000145 PUSB_SEND_CONTEXT pContext = NULL;
146 PUSB_SEND_CONTEXT pReturnContext = NULL;
147 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400148
149 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
150
151 for (ii = 0; ii < pDevice->cbTD; ii++) {
152 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500153 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500154 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100155 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400156 pReturnContext = pContext;
157 break;
158 }
159 }
160 if ( ii == pDevice->cbTD ) {
161 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
162 }
Andres More8611a292010-05-01 14:25:00 -0300163 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400164}
165
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000166static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
167 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400168{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000169 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400170
Andres More4b50fb42010-06-22 21:57:42 -0300171 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400172 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300173 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400174 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
175 else
176 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
177
178 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
179 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300180 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
181 pbyDestAddr,
182 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400183}
184
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000185static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
186 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
187 u16 wPayloadLen, u8 *pMICHDR)
Forest Bond92b96792009-06-13 07:38:31 -0400188{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000189 u32 *pdwIV = (u32 *)pbyIVHead;
190 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
191 u16 wValue;
Andres More1cac4a42013-03-18 20:33:50 -0500192 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000193 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400194
Forest Bond92b96792009-06-13 07:38:31 -0400195 //Fill TXKEY
196 if (pTransmitKey == NULL)
197 return;
198
199 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
200 *pdwIV = pDevice->dwIVCounter;
201 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
202
203 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
204 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
Andres Moreb902fbf2013-02-25 20:32:51 -0500205 memcpy(pDevice->abyPRNG, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700206 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400207 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500208 memcpy(pbyBuf, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700209 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400210 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500211 memcpy(pbyBuf+8, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700212 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400213 }
Jim Lieb3e362592009-08-12 14:54:11 -0700214 memcpy(pDevice->abyPRNG, pbyBuf, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400215 }
216 // Append IV after Mac Header
217 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
Malcolm Priestleyd5bbef72012-11-11 15:53:14 +0000218 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
Forest Bond92b96792009-06-13 07:38:31 -0400219 *pdwIV = cpu_to_le32(*pdwIV);
220 pDevice->dwIVCounter++;
221 if (pDevice->dwIVCounter > WEP_IV_MASK) {
222 pDevice->dwIVCounter = 0;
223 }
224 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
225 pTransmitKey->wTSC15_0++;
226 if (pTransmitKey->wTSC15_0 == 0) {
227 pTransmitKey->dwTSC47_16++;
228 }
229 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
230 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
Jim Lieb3e362592009-08-12 14:54:11 -0700231 memcpy(pbyBuf, pDevice->abyPRNG, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400232 // Make IV
Jim Lieb3e362592009-08-12 14:54:11 -0700233 memcpy(pdwIV, pDevice->abyPRNG, 3);
Forest Bond92b96792009-06-13 07:38:31 -0400234
Andres Moreb902fbf2013-02-25 20:32:51 -0500235 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Forest Bond92b96792009-06-13 07:38:31 -0400236 // Append IV&ExtIV after Mac Header
237 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +0000238 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %x\n",
239 *pdwExtIV);
Forest Bond92b96792009-06-13 07:38:31 -0400240
241 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
242 pTransmitKey->wTSC15_0++;
243 if (pTransmitKey->wTSC15_0 == 0) {
244 pTransmitKey->dwTSC47_16++;
245 }
Jim Lieb3e362592009-08-12 14:54:11 -0700246 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400247
248 // Make IV
249 *pdwIV = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -0500250 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Andres More3eaca0d2013-02-25 20:32:52 -0500251 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
Forest Bond92b96792009-06-13 07:38:31 -0400252 //Append IV&ExtIV after Mac Header
253 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
254
255 //Fill MICHDR0
256 *pMICHDR = 0x59;
Andres Moreb902fbf2013-02-25 20:32:51 -0500257 *((u8 *)(pMICHDR+1)) = 0; // TxPriority
Andres More1cac4a42013-03-18 20:33:50 -0500258 memcpy(pMICHDR+2, &(pMACHeader->addr2[0]), 6);
Andres Moreb902fbf2013-02-25 20:32:51 -0500259 *((u8 *)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
260 *((u8 *)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
261 *((u8 *)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
262 *((u8 *)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
263 *((u8 *)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
264 *((u8 *)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
265 *((u8 *)(pMICHDR+14)) = HIBYTE(wPayloadLen);
266 *((u8 *)(pMICHDR+15)) = LOBYTE(wPayloadLen);
Forest Bond92b96792009-06-13 07:38:31 -0400267
268 //Fill MICHDR1
Andres Moreb902fbf2013-02-25 20:32:51 -0500269 *((u8 *)(pMICHDR+16)) = 0; // HLEN[15:8]
Forest Bond92b96792009-06-13 07:38:31 -0400270 if (pDevice->bLongHeader) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500271 *((u8 *)(pMICHDR+17)) = 28; // HLEN[7:0]
Forest Bond92b96792009-06-13 07:38:31 -0400272 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500273 *((u8 *)(pMICHDR+17)) = 22; // HLEN[7:0]
Forest Bond92b96792009-06-13 07:38:31 -0400274 }
Andres More1cac4a42013-03-18 20:33:50 -0500275 wValue = cpu_to_le16(pMACHeader->frame_control & 0xC78F);
Andres Moreb902fbf2013-02-25 20:32:51 -0500276 memcpy(pMICHDR+18, (u8 *)&wValue, 2); // MSKFRACTL
Andres More1cac4a42013-03-18 20:33:50 -0500277 memcpy(pMICHDR+20, &(pMACHeader->addr1[0]), 6);
278 memcpy(pMICHDR+26, &(pMACHeader->addr2[0]), 6);
Forest Bond92b96792009-06-13 07:38:31 -0400279
280 //Fill MICHDR2
Andres More1cac4a42013-03-18 20:33:50 -0500281 memcpy(pMICHDR+32, &(pMACHeader->addr3[0]), 6);
282 wValue = pMACHeader->seq_ctrl;
Forest Bond92b96792009-06-13 07:38:31 -0400283 wValue &= 0x000F;
284 wValue = cpu_to_le16(wValue);
Andres Moreb902fbf2013-02-25 20:32:51 -0500285 memcpy(pMICHDR+38, (u8 *)&wValue, 2); // MSKSEQCTL
Forest Bond92b96792009-06-13 07:38:31 -0400286 if (pDevice->bLongHeader) {
Andres More1cac4a42013-03-18 20:33:50 -0500287 memcpy(pMICHDR+40, &(pMACHeader->addr4[0]), 6);
Forest Bond92b96792009-06-13 07:38:31 -0400288 }
289 }
290}
291
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000292static void s_vSWencryption(struct vnt_private *pDevice,
293 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400294{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000295 u32 cbICVlen = 4;
296 u32 dwICV = 0xffffffff;
297 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400298
299 if (pTransmitKey == NULL)
300 return;
301
302 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
303 //=======================================================================
304 // Append ICV after payload
305 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500306 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400307 // finally, we must invert dwCRC to get the correct answer
308 *pdwICV = cpu_to_le32(~dwICV);
309 // RC4 encryption
310 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
311 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
312 //=======================================================================
313 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
314 //=======================================================================
315 //Append ICV after payload
316 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500317 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400318 // finally, we must invert dwCRC to get the correct answer
319 *pdwICV = cpu_to_le32(~dwICV);
320 // RC4 encryption
321 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
322 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
323 //=======================================================================
324 }
325}
326
Forest Bond92b96792009-06-13 07:38:31 -0400327/*byPktType : PK_TYPE_11A 0
328 PK_TYPE_11B 1
329 PK_TYPE_11GB 2
330 PK_TYPE_11GA 3
331*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000332static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
333 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400334{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000335 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400336
337 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
338 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500339 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400340 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500341 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400342 }
343
344 if (bNeedAck) {
345 return (uDataTime + pDevice->uSIFS + uAckTime);
346 }
347 else {
348 return uDataTime;
349 }
350}
351
352//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000353static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
354 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400355{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000356 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400357
358 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
359
Forest Bond92b96792009-06-13 07:38:31 -0400360 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
361 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
362 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
363 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
364 }
365 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
366 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
367 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
368 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
369 }
370 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
371 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
372 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
373 }
374 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
375 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
376 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
377 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
378 return uRrvTime;
379 }
380
381 //RTSRrvTime
382 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
383 return uRrvTime;
384}
385
386//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000387static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100388 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400389{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100390 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400391
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100392 if (bNeedAck) {
393 if (byDurType == DATADUR_B)
394 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
395 byPktType, 14, pDevice->byTopCCKBasicRate);
396 else
397 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
398 byPktType, 14, pDevice->byTopOFDMBasicRate);
399 return pDevice->uSIFS + uAckTime;
400 }
Forest Bond92b96792009-06-13 07:38:31 -0400401
Forest Bond92b96792009-06-13 07:38:31 -0400402 return 0;
403}
404
Forest Bond92b96792009-06-13 07:38:31 -0400405//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100406static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000407 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
408 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400409{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000410 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400411
Forest Bond92b96792009-06-13 07:38:31 -0400412 switch (byDurType) {
413
414 case RTSDUR_BB: //RTSDuration_bb
415 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
416 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
417 break;
418
419 case RTSDUR_BA: //RTSDuration_ba
420 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
421 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
422 break;
423
424 case RTSDUR_AA: //RTSDuration_aa
425 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
426 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
427 break;
428
429 case CTSDUR_BA: //CTSDuration_ba
430 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
431 break;
432
433 case RTSDUR_BA_F0: //RTSDuration_ba_f0
434 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
435 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
436 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
437 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
438 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
439 }
440 break;
441
442 case RTSDUR_AA_F0: //RTSDuration_aa_f0
443 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
444 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
445 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
446 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
447 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
448 }
449 break;
450
451 case RTSDUR_BA_F1: //RTSDuration_ba_f1
452 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
453 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
454 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
455 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
456 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
457 }
458 break;
459
460 case RTSDUR_AA_F1: //RTSDuration_aa_f1
461 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
462 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
463 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
464 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
465 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
466 }
467 break;
468
469 case CTSDUR_BA_F0: //CTSDuration_ba_f0
470 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
471 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
472 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
473 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
474 }
475 break;
476
477 case CTSDUR_BA_F1: //CTSDuration_ba_f1
478 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
479 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
480 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
481 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
482 }
483 break;
484
485 default:
486 break;
487 }
488
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100489 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400490}
491
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000492static u32 s_uFillDataHead(struct vnt_private *pDevice,
493 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100494 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400495{
496
497 if (pTxDataHead == NULL) {
498 return 0;
499 }
500
501 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Andres Morebd2bc4c2010-08-02 23:35:57 -0300502 if ((uDMAIdx == TYPE_ATIMDMA) || (uDMAIdx == TYPE_BEACONDMA)) {
503 PSTxDataHead_ab pBuf = (PSTxDataHead_ab) pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400504 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700505 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500506 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400507 );
508 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100509 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
510 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400511 if(uDMAIdx!=TYPE_ATIMDMA) {
512 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
513 }
514 return (pBuf->wDuration);
515 }
516 else { // DATA & MANAGE Frame
517 if (byFBOption == AUTO_FB_NONE) {
518 PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
519 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700520 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500521 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400522 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700523 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500524 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400525 );
526 //Get Duration and TimeStamp
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100527 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
528 byPktType, bNeedAck);
529 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
530 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400531
532 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
533 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
534 return (pBuf->wDuration_a);
535 } else {
536 // Auto Fallback
537 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
538 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700539 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500540 (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400541 );
Justin P. Mattockbda79782012-08-26 08:16:44 -0700542 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500543 (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400544 );
545 //Get Duration and TimeStamp
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100546 pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
547 byPktType, bNeedAck);
548 pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
549 PK_TYPE_11B, bNeedAck);
550 pBuf->wDuration_a_f0 = (u16)s_uGetDataDuration(pDevice,
551 DATADUR_A_F0, byPktType, bNeedAck);
552 pBuf->wDuration_a_f1 = (u16)s_uGetDataDuration(pDevice,
553 DATADUR_A_F1, byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400554 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
555 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
556 return (pBuf->wDuration_a);
557 } //if (byFBOption == AUTO_FB_NONE)
558 }
559 }
560 else if (byPktType == PK_TYPE_11A) {
561 if ((byFBOption != AUTO_FB_NONE) && (uDMAIdx != TYPE_ATIMDMA) && (uDMAIdx != TYPE_BEACONDMA)) {
562 // Auto Fallback
563 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
564 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700565 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500566 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400567 );
568 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100569 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
570 byPktType, bNeedAck);
571 pBuf->wDuration_f0 = (u16)s_uGetDataDuration(pDevice,
572 DATADUR_A_F0, byPktType, bNeedAck);
573 pBuf->wDuration_f1 = (u16)s_uGetDataDuration(pDevice,
574 DATADUR_A_F1, byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400575 if(uDMAIdx!=TYPE_ATIMDMA) {
576 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
577 }
578 return (pBuf->wDuration);
579 } else {
580 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
581 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700582 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500583 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400584 );
585 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100586 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
587 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400588
589 if(uDMAIdx!=TYPE_ATIMDMA) {
590 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
591 }
592 return (pBuf->wDuration);
593 }
594 }
595 else if (byPktType == PK_TYPE_11B) {
596 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
597 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700598 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500599 (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400600 );
601 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100602 pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
603 byPktType, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400604 if (uDMAIdx != TYPE_ATIMDMA) {
605 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
606 }
607 return (pBuf->wDuration);
608 }
609 return 0;
610}
611
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000612static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
613 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500614 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400615{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000616 u32 uRTSFrameLen = 20;
617 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400618
Forest Bond92b96792009-06-13 07:38:31 -0400619 if (pvRTS == NULL)
620 return;
621
622 if (bDisCRC) {
623 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
624 // in this case we need to decrease its length by 4.
625 uRTSFrameLen -= 4;
626 }
627
Masanari Iida93184692012-08-13 21:21:50 +0900628 // Note: So far RTSHead doesn't appear in ATIM & Beacom DMA, so we don't need to take them into account.
Forest Bond92b96792009-06-13 07:38:31 -0400629 // Otherwise, we need to modified codes for them.
630 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
631 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100632 struct vnt_rts_g *pBuf = (struct vnt_rts_g *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400633 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700634 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500635 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400636 );
637 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700638 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500639 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400640 );
641 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
642 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100643 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
644 cbFrameLength, PK_TYPE_11B,
645 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
646 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
647 cbFrameLength, byPktType,
648 wCurrentRate, bNeedAck, byFBOption);
649 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
650 cbFrameLength, byPktType,
651 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100652 pBuf->data.duration = pBuf->wDuration_aa;
653 /*Get RTS Frame body */
654 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400655
Malcolm Priestley07738932013-08-05 22:08:05 +0100656 if (pDevice->eOPMode == OP_MODE_ADHOC ||
657 pDevice->eOPMode == OP_MODE_AP)
658 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
659 else
660 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Andres More9a0e7562010-04-13 21:54:48 -0300661
Malcolm Priestley07738932013-08-05 22:08:05 +0100662 if (pDevice->eOPMode == OP_MODE_AP)
663 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
664 else
665 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400666 }
667 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100668 struct vnt_rts_g_fb *pBuf = (struct vnt_rts_g_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400669 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700670 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500671 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400672 );
673 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Justin P. Mattockbda79782012-08-26 08:16:44 -0700674 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500675 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
Forest Bond92b96792009-06-13 07:38:31 -0400676 );
677 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
678 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100679 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
680 cbFrameLength, PK_TYPE_11B,
681 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
682 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
683 cbFrameLength, byPktType,
684 wCurrentRate, bNeedAck, byFBOption);
685 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
686 cbFrameLength, byPktType,
687 wCurrentRate, bNeedAck, byFBOption);
688 pBuf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
689 RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
690 bNeedAck, byFBOption);
691 pBuf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(pDevice,
692 RTSDUR_AA_F0, cbFrameLength, byPktType,
693 wCurrentRate, bNeedAck, byFBOption);
694 pBuf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
695 RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
696 bNeedAck, byFBOption);
697 pBuf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(pDevice,
698 RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate,
699 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100700 pBuf->data.duration = pBuf->wDuration_aa;
701 /*Get RTS Frame body*/
702 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400703
Malcolm Priestley07738932013-08-05 22:08:05 +0100704 if (pDevice->eOPMode == OP_MODE_ADHOC ||
705 pDevice->eOPMode == OP_MODE_AP)
706 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
707 else
708 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400709
Malcolm Priestley07738932013-08-05 22:08:05 +0100710 if (pDevice->eOPMode == OP_MODE_AP)
711 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
712 else
713 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400714 } // if (byFBOption == AUTO_FB_NONE)
715 }
716 else if (byPktType == PK_TYPE_11A) {
717 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100718 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400719 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700720 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500721 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400722 );
723 pBuf->wTransmitLength = cpu_to_le16(wLen);
724 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100725 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
726 cbFrameLength, byPktType, wCurrentRate,
727 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100728 pBuf->data.duration = pBuf->wDuration;
729 /* Get RTS Frame body */
730 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400731
Malcolm Priestley07738932013-08-05 22:08:05 +0100732 if (pDevice->eOPMode == OP_MODE_ADHOC ||
733 pDevice->eOPMode == OP_MODE_AP)
734 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
735 else
736 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400737
Malcolm Priestley07738932013-08-05 22:08:05 +0100738 if (pDevice->eOPMode == OP_MODE_AP)
739 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
740 else
741 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400742 }
743 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100744 struct vnt_rts_a_fb *pBuf = (struct vnt_rts_a_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400745 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700746 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
Andres More3eaca0d2013-02-25 20:32:52 -0500747 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400748 );
749 pBuf->wTransmitLength = cpu_to_le16(wLen);
750 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100751 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
752 cbFrameLength, byPktType, wCurrentRate,
753 bNeedAck, byFBOption);
754 pBuf->wRTSDuration_f0 = s_uGetRTSCTSDuration(pDevice,
755 RTSDUR_AA_F0, cbFrameLength, byPktType,
756 wCurrentRate, bNeedAck, byFBOption);
757 pBuf->wRTSDuration_f1 = s_uGetRTSCTSDuration(pDevice,
758 RTSDUR_AA_F1, cbFrameLength, byPktType,
759 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100760 pBuf->data.duration = pBuf->wDuration;
761 /* Get RTS Frame body */
762 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400763
Malcolm Priestley07738932013-08-05 22:08:05 +0100764 if (pDevice->eOPMode == OP_MODE_ADHOC ||
765 pDevice->eOPMode == OP_MODE_AP)
766 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
767 else
768 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
769
770 if (pDevice->eOPMode == OP_MODE_AP)
771 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
772 else
773 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400774 }
775 }
776 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100777 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400778 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700779 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500780 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -0400781 );
782 pBuf->wTransmitLength = cpu_to_le16(wLen);
783 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100784 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
785 cbFrameLength, byPktType, wCurrentRate,
786 bNeedAck, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400787
Malcolm Priestley07738932013-08-05 22:08:05 +0100788 pBuf->data.duration = pBuf->wDuration;
789 /* Get RTS Frame body */
790 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400791
Malcolm Priestley07738932013-08-05 22:08:05 +0100792 if (pDevice->eOPMode == OP_MODE_ADHOC ||
793 pDevice->eOPMode == OP_MODE_AP)
794 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
795 else
796 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
797
798 if (pDevice->eOPMode == OP_MODE_AP)
799 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
800 else
801 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400802 }
803}
804
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000805static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
806 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
807 int bDisCRC, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400808{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000809 u32 uCTSFrameLen = 14;
810 u16 wLen = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400811
812 if (pvCTS == NULL) {
813 return;
814 }
815
816 if (bDisCRC) {
817 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
818 // in this case we need to decrease its length by 4.
819 uCTSFrameLen -= 4;
820 }
821
822 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
823 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
824 // Auto Fall back
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100825 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Forest Bond92b96792009-06-13 07:38:31 -0400826 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700827 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500828 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400829 );
830 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100831 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
832 cbFrameLength, byPktType,
833 wCurrentRate, bNeedAck, byFBOption);
834 /* Get CTSDuration_ba_f0 */
835 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
836 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
837 bNeedAck, byFBOption);
838 /* Get CTSDuration_ba_f1 */
839 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
840 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
841 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100842 /* Get CTS Frame body */
843 pBuf->data.duration = pBuf->wDuration_ba;
844 pBuf->data.frame_control = TYPE_CTL_CTS;
845 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400846 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100847 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Forest Bond92b96792009-06-13 07:38:31 -0400848 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -0700849 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -0500850 (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
Forest Bond92b96792009-06-13 07:38:31 -0400851 );
852 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100853 /* Get CTSDuration_ba */
854 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
855 CTSDUR_BA, cbFrameLength, byPktType,
856 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100857 /*Get CTS Frame body*/
858 pBuf->data.duration = pBuf->wDuration_ba;
859 pBuf->data.frame_control = TYPE_CTL_CTS;
860 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400861 }
862 }
863}
864
Forest Bond92b96792009-06-13 07:38:31 -0400865/*+
866 *
867 * Description:
868 * Generate FIFO control for MAC & Baseband controller
869 *
870 * Parameters:
871 * In:
872 * pDevice - Pointer to adpater
873 * pTxDataHead - Transmit Data Buffer
874 * pTxBufHead - pTxBufHead
875 * pvRrvTime - pvRrvTime
876 * pvRTS - RTS Buffer
877 * pCTS - CTS Buffer
878 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
879 * bNeedACK - If need ACK
880 * uDMAIdx - DMA Index
881 * Out:
882 * none
883 *
884 * Return Value: none
885 *
886-*/
Andres Morecc856e62010-05-17 21:34:01 -0300887
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000888static void s_vGenerateTxParameter(struct vnt_private *pDevice,
889 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
890 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500891 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400892{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000893 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
894 u16 wFifoCtl;
Andres Moree269fc22013-02-12 20:36:29 -0500895 int bDisCRC = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000896 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400897
898 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
899 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
900 pFifoHead->wReserved = wCurrentRate;
901 wFifoCtl = pFifoHead->wFIFOCtl;
902
903 if (wFifoCtl & FIFOCTL_CRCDIS) {
Andres More4e9b5e22013-02-12 20:36:30 -0500904 bDisCRC = true;
Forest Bond92b96792009-06-13 07:38:31 -0400905 }
906
907 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
908 byFBOption = AUTO_FB_0;
909 }
910 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
911 byFBOption = AUTO_FB_1;
912 }
913
914 if (pDevice->bLongHeader)
915 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
916
917 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
918
919 if (pvRTS != NULL) { //RTS_need
920 //Fill RsvTime
921 if (pvRrvTime) {
Malcolm Priestley6398a592013-08-16 21:26:55 +0100922 struct vnt_rrv_time_rts *pBuf =
923 (struct vnt_rrv_time_rts *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500924 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
925 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
926 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
927 pBuf->wTxRrvTime_a = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
928 pBuf->wTxRrvTime_b = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400929 }
930 //Fill RTS
931 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
932 }
933 else {//RTS_needless, PCF mode
934
935 //Fill RsvTime
936 if (pvRrvTime) {
Malcolm Priestley4f990052013-08-16 23:38:57 +0100937 struct vnt_rrv_time_cts *pBuf =
938 (struct vnt_rrv_time_cts *)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500939 pBuf->wTxRrvTime_a = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
940 pBuf->wTxRrvTime_b = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
941 pBuf->wCTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
Forest Bond92b96792009-06-13 07:38:31 -0400942 }
943 //Fill CTS
944 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
945 }
946 }
947 else if (byPktType == PK_TYPE_11A) {
948
949 if (pvRTS != NULL) {//RTS_need, non PCF mode
950 //Fill RsvTime
951 if (pvRrvTime) {
952 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500953 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
954 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400955 }
956 //Fill RTS
957 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
958 }
959 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
960 //Fill RsvTime
961 if (pvRrvTime) {
962 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500963 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
Forest Bond92b96792009-06-13 07:38:31 -0400964 }
965 }
966 }
967 else if (byPktType == PK_TYPE_11B) {
968
969 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
970 //Fill RsvTime
971 if (pvRrvTime) {
972 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500973 pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
974 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400975 }
976 //Fill RTS
977 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
978 }
979 else { //RTS_needless, non PCF mode
980 //Fill RsvTime
981 if (pvRrvTime) {
982 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
Andres More3eaca0d2013-02-25 20:32:52 -0500983 pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
Forest Bond92b96792009-06-13 07:38:31 -0400984 }
985 }
986 }
987 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
988}
989/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500990 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500991 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300992 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400993*/
994
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000995static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100996 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
997 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
998 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
999 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -04001000{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001001 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1002 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001003 u32 cb802_1_H_len;
1004 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
1005 u32 cbFCSlen = 4, cbMICHDR = 0;
1006 int bNeedACK, bRTS;
1007 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
1008 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1009 u8 abySNAP_Bridgetunnel[ETH_ALEN]
1010 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1011 u32 uDuration;
1012 u32 cbHeaderLength = 0, uPadding = 0;
1013 void *pvRrvTime;
1014 PSMICHDRHead pMICHDR;
1015 void *pvRTS;
1016 void *pvCTS;
1017 void *pvTxDataHd;
1018 u8 byFBOption = AUTO_FB_NONE, byFragType;
1019 u16 wTxBufSize;
1020 u32 dwMICKey0, dwMICKey1, dwMIC_Priority, dwCRC;
1021 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001022 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -04001023
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001024 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001025
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001026 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001027 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1028 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001029 }
Forest Bond92b96792009-06-13 07:38:31 -04001030
Forest Bond92b96792009-06-13 07:38:31 -04001031 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001032 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001033 if (pDevice->dwDiagRefCount == 0) {
1034 cb802_1_H_len = 8;
1035 } else {
1036 cb802_1_H_len = 2;
1037 }
1038 } else {
1039 cb802_1_H_len = 0;
1040 }
1041
Charles Clément21ec51f2010-05-18 10:08:14 -07001042 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001043
1044 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001045 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001046
1047 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001048 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001049 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1050 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001051 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1052 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001053 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001054 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001055 pTxBufHead->wFIFOCtl =
1056 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1057 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001058 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001059 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1060 }
Forest Bond92b96792009-06-13 07:38:31 -04001061 }
1062 else {
1063 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001064 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001065 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1066 }
1067 } //if (pDevice->dwDiagRefCount != 0) {
1068
1069 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1070
1071 //Set FIFOCTL_LHEAD
1072 if (pDevice->bLongHeader)
1073 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1074
1075 if (pDevice->bSoftwareGenCrcErr) {
1076 pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS; // set tx descriptors to NO hardware CRC
1077 }
1078
1079 //Set FRAGCTL_MACHDCNT
1080 if (pDevice->bLongHeader) {
1081 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1082 } else {
1083 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1084 }
Andres More3eaca0d2013-02-25 20:32:52 -05001085 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001086
1087 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001088 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001089 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1090 }
1091
1092 //Set Auto Fallback Ctl
1093 if (wCurrentRate >= RATE_18M) {
1094 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1095 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1096 byFBOption = AUTO_FB_0;
1097 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1098 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1099 byFBOption = AUTO_FB_1;
1100 }
1101 }
1102
Andres More4e9b5e22013-02-12 20:36:30 -05001103 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001104 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1105 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1106 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1107 }
1108 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1109 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1110 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1111 }
1112 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1113 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1114 }
1115 }
1116 }
1117
Forest Bond92b96792009-06-13 07:38:31 -04001118 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1119 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1120 cbIVlen = 4;
1121 cbICVlen = 4;
1122 }
1123 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1124 cbIVlen = 8;//IV+ExtIV
1125 cbMIClen = 8;
1126 cbICVlen = 4;
1127 }
1128 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1129 cbIVlen = 8;//RSN Header
1130 cbICVlen = 8;//MIC
1131 cbMICHDR = sizeof(SMICHDRHead);
1132 }
Andres Moree269fc22013-02-12 20:36:29 -05001133 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001134 //MAC Header should be padding 0 to DW alignment.
1135 uPadding = 4 - (cbMACHdLen%4);
1136 uPadding %= 4;
1137 }
1138 }
1139
1140 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1141
Andres Moree269fc22013-02-12 20:36:29 -05001142 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1143 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001144 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001145 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001146 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1147 }
1148
Andres Moreb902fbf2013-02-25 20:32:51 -05001149 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001150 wTxBufSize = sizeof(STxBufHead);
1151 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1152 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001153 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001154 pvRrvTime = (struct vnt_rrv_time_rts *)
1155 (pbyTxBufferAddr + wTxBufSize);
1156 pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
1157 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001158 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001159 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001160 pvCTS = NULL;
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001161 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001162 sizeof(struct vnt_rrv_time_rts) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001163 sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001164 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001165 cbMICHDR + sizeof(struct vnt_rts_g) +
1166 sizeof(STxDataHead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001167 }
1168 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001169 pvRrvTime = (struct vnt_rrv_time_cts *)
1170 (pbyTxBufferAddr + wTxBufSize);
1171 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1172 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001173 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001174 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001175 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001176 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001177 sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001178 sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001179 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1180 cbMICHDR + sizeof(struct vnt_cts) +
1181 sizeof(STxDataHead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001182 }
1183 } else {
1184 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001185 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001186 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1187 wTxBufSize);
1188 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1189 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001190 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001191 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001192 pvCTS = NULL;
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001193 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001194 sizeof(struct vnt_rrv_time_rts) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001195 sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001196 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1197 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
1198 sizeof(STxDataHead_g_FB);
Forest Bond92b96792009-06-13 07:38:31 -04001199 }
Andres Moree269fc22013-02-12 20:36:29 -05001200 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001201 pvRrvTime = (struct vnt_rrv_time_cts *)
1202 (pbyTxBufferAddr + wTxBufSize);
1203 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
1204 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001205 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001206 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001207 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001208 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001209 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1210 cbMICHDR + sizeof(struct vnt_cts_fb));
1211 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001212 cbMICHDR + sizeof(struct vnt_cts_fb) +
1213 sizeof(STxDataHead_g_FB);
Forest Bond92b96792009-06-13 07:38:31 -04001214 }
1215 } // Auto Fall Back
1216 }
1217 else {//802.11a/b packet
1218 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001219 if (bRTS == true) {//RTS_need
Forest Bond92b96792009-06-13 07:38:31 -04001220 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1221 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001222 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
1223 sizeof(SRrvTime_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001224 pvCTS = NULL;
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001225 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize +
1226 sizeof(SRrvTime_ab) + cbMICHDR +
1227 sizeof(struct vnt_rts_ab));
1228 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR +
1229 sizeof(struct vnt_rts_ab) + sizeof(STxDataHead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001230 }
Andres Moree269fc22013-02-12 20:36:29 -05001231 else if (bRTS == false) { //RTS_needless, no MICHDR
Forest Bond92b96792009-06-13 07:38:31 -04001232 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1233 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1234 pvRTS = NULL;
1235 pvCTS = NULL;
1236 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1237 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
1238 }
1239 } else {
1240 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001241 if (bRTS == true) {//RTS_need
Forest Bond92b96792009-06-13 07:38:31 -04001242 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1243 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001244 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
1245 sizeof(SRrvTime_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001246 pvCTS = NULL;
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001247 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize +
1248 sizeof(SRrvTime_ab) + cbMICHDR +
1249 sizeof(struct vnt_rts_a_fb));
1250 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR +
1251 sizeof(struct vnt_rts_a_fb) + sizeof(STxDataHead_a_FB);
Forest Bond92b96792009-06-13 07:38:31 -04001252 }
Andres Moree269fc22013-02-12 20:36:29 -05001253 else if (bRTS == false) { //RTS_needless
Forest Bond92b96792009-06-13 07:38:31 -04001254 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1255 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1256 pvRTS = NULL;
1257 pvCTS = NULL;
1258 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1259 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
1260 }
1261 } // Auto Fall Back
1262 }
1263
Andres Moreb902fbf2013-02-25 20:32:51 -05001264 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1265 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1266 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001267
Forest Bond92b96792009-06-13 07:38:31 -04001268 //=========================
1269 // No Fragmentation
1270 //=========================
1271 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1272 byFragType = FRAGCTL_NONFRAG;
1273 //uDMAIdx = TYPE_AC0DMA;
1274 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1275
Forest Bond92b96792009-06-13 07:38:31 -04001276 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001277 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1278 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001279 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1280 //Fill DataHead
1281 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001282 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001283 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001284 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001285 byFragType, uDMAIdx, 0);
1286
Andres More4e9b5e22013-02-12 20:36:30 -05001287 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001288 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001289 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001290 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001291
1292 if (pDevice->bEnableHostWEP) {
1293 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1294 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1295 }
1296 }
1297
1298 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001299 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001300 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001301 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1302 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001303 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001304 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001305 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001306 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001307 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001308 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001309 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001310 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001311 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001312
1313 }
1314
1315 }
1316
Forest Bond92b96792009-06-13 07:38:31 -04001317 if (pPacket != NULL) {
1318 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001319 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001320 (pPacket + ETH_HLEN),
1321 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001322 );
1323
1324 } else {
1325 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001326 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001327 }
1328
Andres More4e9b5e22013-02-12 20:36:30 -05001329 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001330
1331 ///////////////////////////////////////////////////////////////////
1332
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001333 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1334 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1335 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1336 }
Forest Bond92b96792009-06-13 07:38:31 -04001337 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001338 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1339 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001340 }
1341 else {
Andres More52a7e642013-02-25 20:32:53 -05001342 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1343 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001344 }
1345 // DO Software Michael
1346 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001347 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001348 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001349 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001350 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1351 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001352
1353 ///////////////////////////////////////////////////////////////////
1354
1355 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1356 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001357 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001358 //}
1359 //DBG_PRN_GRP12(("\n\n\n"));
1360
1361 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1362
Andres More52a7e642013-02-25 20:32:53 -05001363 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1364 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001365
1366 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1367 MIC_vUnInit();
1368
Andres More4e9b5e22013-02-12 20:36:30 -05001369 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001370 *pdwMIC_L = 0;
1371 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001372 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001373 }
1374 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1375 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1376 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1377 }
1378
Andres More4e9b5e22013-02-12 20:36:30 -05001379 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001380
Andres More3eaca0d2013-02-25 20:32:52 -05001381 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001382
Andres More4e9b5e22013-02-12 20:36:30 -05001383 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1384 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1385 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001386 cbFrameSize -= cbICVlen;
1387 }
1388
Andres More4e9b5e22013-02-12 20:36:30 -05001389 if (pDevice->bSoftwareGenCrcErr == true) {
Andres Morecc856e62010-05-17 21:34:01 -03001390 unsigned int cbLen;
Andres More52a7e642013-02-25 20:32:53 -05001391 u32 * pdwCRC;
Forest Bond92b96792009-06-13 07:38:31 -04001392
1393 dwCRC = 0xFFFFFFFFL;
1394 cbLen = cbFrameSize - cbFCSlen;
1395 // calculate CRC, and wrtie CRC value to end of TD
1396 dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
Andres More52a7e642013-02-25 20:32:53 -05001397 pdwCRC = (u32 *)(pbyMacHdr + cbLen);
Forest Bond92b96792009-06-13 07:38:31 -04001398 // finally, we must invert dwCRC to get the correct answer
1399 *pdwCRC = ~dwCRC;
1400 // Force Error
1401 *pdwCRC -= 1;
1402 } else {
1403 cbFrameSize -= cbFCSlen;
1404 }
1405
1406 *pcbHeaderLen = cbHeaderLength;
1407 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1408
Forest Bond92b96792009-06-13 07:38:31 -04001409 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001410 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001411
Andres More4e9b5e22013-02-12 20:36:30 -05001412 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001413
1414}
1415
Forest Bond92b96792009-06-13 07:38:31 -04001416/*+
1417 *
1418 * Description:
1419 * Translate 802.3 to 802.11 header
1420 *
1421 * Parameters:
1422 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001423 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001424 * dwTxBufferAddr - Transmit Buffer
1425 * pPacket - Packet from upper layer
1426 * cbPacketSize - Transmit Data Length
1427 * Out:
1428 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1429 * pcbAppendPayload - size of append payload for 802.1H translation
1430 *
1431 * Return Value: none
1432 *
1433-*/
1434
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001435static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001436 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001437 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001438{
Andres More1cac4a42013-03-18 20:33:50 -05001439 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001440
Forest Bond92b96792009-06-13 07:38:31 -04001441 if (uDMAIdx == TYPE_ATIMDMA) {
Andres More1cac4a42013-03-18 20:33:50 -05001442 pMACHeader->frame_control = TYPE_802_11_ATIM;
Forest Bond92b96792009-06-13 07:38:31 -04001443 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001444 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001445 }
1446
1447 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001448 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001449 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001450 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001451 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1452 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001453 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001454 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001455 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001456 } else {
1457 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001458 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001459 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001460 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001461 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001462 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001463 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001464 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001465 &(pDevice->abyBSSID[0]),
1466 ETH_ALEN);
1467 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001468 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001469 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001470 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001471 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001472 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001473 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001474 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001475 &(pDevice->abyBSSID[0]),
1476 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001477 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001478 }
1479 }
1480
1481 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001482 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001483
Andres More1cac4a42013-03-18 20:33:50 -05001484 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001485
1486 if (pDevice->bLongHeader) {
1487 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001488 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001489 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001490 }
Andres More1cac4a42013-03-18 20:33:50 -05001491 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001492
1493 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001494 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001495
1496 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1497 pDevice->wSeqCounter++;
1498 if (pDevice->wSeqCounter > 0x0fff)
1499 pDevice->wSeqCounter = 0;
1500 }
1501
1502 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001503 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001504 }
1505}
1506
Forest Bond92b96792009-06-13 07:38:31 -04001507/*+
1508 *
1509 * Description:
1510 * Request instructs a MAC to transmit a 802.11 management packet through
1511 * the adapter onto the medium.
1512 *
1513 * Parameters:
1514 * In:
1515 * hDeviceContext - Pointer to the adapter
1516 * pPacket - A pointer to a descriptor for the packet to transmit
1517 * Out:
1518 * none
1519 *
Andres Moree269fc22013-02-12 20:36:29 -05001520 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001521 *
1522-*/
1523
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001524CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1525 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001526{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001527 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001528 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001529 PSTxBufHead pTxBufHead;
1530 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001531 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001532 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001533 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001534 u8 byPktType, *pbyTxBufferAddr;
1535 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1536 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001537 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001538 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1539 u32 uPadding = 0;
1540 u16 wTxBufSize;
1541 u32 cbMacHdLen;
1542 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001543
Forest Bond92b96792009-06-13 07:38:31 -04001544 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1545
1546 if (NULL == pContext) {
1547 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1548 return CMD_STATUS_RESOURCES;
1549 }
1550
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001551 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001552 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001553 cbFrameBodySize = pPacket->cbPayloadLen;
1554 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1555 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001556
1557 if (pDevice->byBBType == BB_TYPE_11A) {
1558 wCurrentRate = RATE_6M;
1559 byPktType = PK_TYPE_11A;
1560 } else {
1561 wCurrentRate = RATE_1M;
1562 byPktType = PK_TYPE_11B;
1563 }
1564
1565 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1566 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1567 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1568 // to set power here.
1569 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1570 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1571 } else {
1572 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1573 }
1574 pDevice->wCurrentRate = wCurrentRate;
1575
Forest Bond92b96792009-06-13 07:38:31 -04001576 //Set packet type
1577 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1578 pTxBufHead->wFIFOCtl = 0;
1579 }
1580 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1581 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1582 }
1583 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1584 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1585 }
1586 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1587 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1588 }
1589
1590 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1591 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1592
Andres More22040bb2010-08-02 20:21:44 -03001593 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001594 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001595 }
1596 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001597 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001598 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1599 };
1600
1601 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1602 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1603
1604 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1605 //Set Preamble type always long
1606 //pDevice->byPreambleType = PREAMBLE_LONG;
1607 // probe-response don't retry
1608 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001609 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001610 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1611 //}
1612 }
1613
1614 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1615
1616 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001617 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001618 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1619 } else {
1620 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1621 }
1622
1623 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001624 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001625
1626 // Notes:
1627 // Although spec says MMPDU can be fragmented; In most case,
1628 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001629 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001630
1631 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1632 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1633 cbIVlen = 4;
1634 cbICVlen = 4;
1635 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1636 }
1637 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1638 cbIVlen = 8;//IV+ExtIV
1639 cbMIClen = 8;
1640 cbICVlen = 4;
1641 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1642 //We need to get seed here for filling TxKey entry.
1643 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1644 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1645 }
1646 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1647 cbIVlen = 8;//RSN Header
1648 cbICVlen = 8;//MIC
1649 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001650 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001651 }
1652 //MAC Header should be padding 0 to DW alignment.
1653 uPadding = 4 - (cbMacHdLen%4);
1654 uPadding %= 4;
1655 }
1656
1657 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1658
1659 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001660 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001661 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1662 }
1663 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1664
1665 //Set RrvTime/RTS/CTS Buffer
1666 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1667
Malcolm Priestley4f990052013-08-16 23:38:57 +01001668 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001669 pMICHDR = NULL;
1670 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001671 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001672 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001673 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001674 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1675 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001676 sizeof(struct vnt_cts) + sizeof(STxDataHead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001677 }
1678 else { // 802.11a/b packet
1679 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1680 pMICHDR = NULL;
1681 pvRTS = NULL;
1682 pCTS = NULL;
1683 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1684 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
1685 }
1686
Andres Moreceb8c5d2013-03-18 20:33:49 -05001687 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001688 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1689 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001690 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001691 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1692 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001693 //=========================
1694 // No Fragmentation
1695 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001696 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001697
Forest Bond92b96792009-06-13 07:38:31 -04001698 //Fill FIFO,RrvTime,RTS,and CTS
1699 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1700 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1701
1702 //Fill DataHead
1703 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001704 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001705
Andres More1cac4a42013-03-18 20:33:50 -05001706 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001707
1708 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1709
1710 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001711 u8 * pbyIVHead;
1712 u8 * pbyPayloadHead;
1713 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001714 PSKeyItem pTransmitKey = NULL;
1715
Andres Moreb902fbf2013-02-25 20:32:51 -05001716 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1717 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001718 do {
1719 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001720 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001721 pbyBSSID = pDevice->abyBSSID;
1722 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001723 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001724 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001725 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001726 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1727 break;
1728 }
1729 } else {
1730 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1731 break;
1732 }
1733 }
1734 // get group key
1735 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001736 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001737 pTransmitKey = NULL;
1738 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1739 } else {
1740 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1741 }
Andres Moree269fc22013-02-12 20:36:29 -05001742 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001743 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001744 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001745 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001746
Jim Lieb3e362592009-08-12 14:54:11 -07001747 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001748 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001749 cbFrameBodySize);
1750 }
1751 else {
1752 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001753 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001754 }
1755
Andres More1cac4a42013-03-18 20:33:50 -05001756 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001757 pDevice->wSeqCounter++ ;
1758 if (pDevice->wSeqCounter > 0x0fff)
1759 pDevice->wSeqCounter = 0;
1760
1761 if (bIsPSPOLL) {
1762 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001763 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001764 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1765 // in the same place of other packet's Duration-field).
1766 // And it will cause Cisco-AP to issue Disassociation-packet
1767 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1768 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1769 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1770 } else {
1771 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1772 }
1773 }
1774
Andres More3eaca0d2013-02-25 20:32:52 -05001775 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001776 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001777 pTX_Buffer->byType = 0x00;
1778
1779 pContext->pPacket = NULL;
1780 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001781 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001782
Andres More1cac4a42013-03-18 20:33:50 -05001783 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1784 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001785 }
1786 else {
Andres More1cac4a42013-03-18 20:33:50 -05001787 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001788 }
1789
1790 PIPEnsSendBulkOut(pDevice,pContext);
1791 return CMD_STATUS_PENDING;
1792}
1793
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001794CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1795 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001796{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001797 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001798 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1799 u32 cbHeaderSize = 0;
1800 u16 wTxBufSize = sizeof(STxShortBufHead);
1801 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001802 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001803 PSTxDataHead_ab pTxDataHead;
1804 u16 wCurrentRate;
1805 u32 cbFrameBodySize;
1806 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001807 u8 *pbyTxBufferAddr;
1808 PUSB_SEND_CONTEXT pContext;
1809 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001810
Forest Bond92b96792009-06-13 07:38:31 -04001811 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1812 if (NULL == pContext) {
1813 status = CMD_STATUS_RESOURCES;
1814 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1815 return status ;
1816 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001817
1818 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001819 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001820
1821 cbFrameBodySize = pPacket->cbPayloadLen;
1822
1823 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1824 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001825
1826 if (pDevice->byBBType == BB_TYPE_11A) {
1827 wCurrentRate = RATE_6M;
1828 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
1829 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001830 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
Andres More3eaca0d2013-02-25 20:32:52 -05001831 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001832 );
1833 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +01001834 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice,
1835 DATADUR_A, PK_TYPE_11A, false));
Forest Bond92b96792009-06-13 07:38:31 -04001836 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
1837 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
1838 } else {
1839 wCurrentRate = RATE_1M;
1840 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1841 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
1842 //Get SignalField,ServiceField,Length
Justin P. Mattockbda79782012-08-26 08:16:44 -07001843 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
Andres More3eaca0d2013-02-25 20:32:52 -05001844 (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
Forest Bond92b96792009-06-13 07:38:31 -04001845 );
1846 //Get Duration and TimeStampOff
Malcolm Priestley3ed210e2013-08-07 21:28:45 +01001847 pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice,
1848 DATADUR_B, PK_TYPE_11B, false));
Forest Bond92b96792009-06-13 07:38:31 -04001849 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
1850 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
1851 }
1852
1853 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001854 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001855 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001856
Andres More1cac4a42013-03-18 20:33:50 -05001857 pMACHeader->duration_id = 0;
1858 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001859 pDevice->wSeqCounter++ ;
1860 if (pDevice->wSeqCounter > 0x0fff)
1861 pDevice->wSeqCounter = 0;
1862
1863 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1864
Andres More3eaca0d2013-02-25 20:32:52 -05001865 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001866 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001867 pTX_Buffer->byType = 0x01;
1868
1869 pContext->pPacket = NULL;
1870 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001871 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001872
1873 PIPEnsSendBulkOut(pDevice,pContext);
1874 return CMD_STATUS_PENDING;
1875
1876}
1877
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001878void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1879{
1880 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001881 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001882 u8 byPktType;
1883 u8 *pbyTxBufferAddr;
1884 void *pvRTS, *pvCTS, *pvTxDataHd;
1885 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001886 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001887 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001888 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001889 PSTxBufHead pTxBufHead;
1890 u32 cbFrameSize;
1891 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1892 u32 uPadding = 0;
1893 u32 cbMICHDR = 0, uLength = 0;
1894 u32 dwMICKey0, dwMICKey1;
1895 u32 dwMIC_Priority;
1896 u32 *pdwMIC_L, *pdwMIC_R;
1897 u16 wTxBufSize;
1898 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001899 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001900 void *pvRrvTime, *pMICHDR;
1901 u32 wCurrentRate = RATE_1M;
1902 PUWLAN_80211HDR p80211Header;
1903 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001904 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001905 SKeyItem STempKey;
1906 PSKeyItem pTransmitKey = NULL;
1907 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1908 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001909 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001910
Forest Bond92b96792009-06-13 07:38:31 -04001911 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1912
1913 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1914 cbFrameBodySize = 0;
1915 }
1916 else {
1917 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1918 }
1919 p80211Header = (PUWLAN_80211HDR)skb->data;
1920
1921 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1922
1923 if (NULL == pContext) {
1924 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1925 dev_kfree_skb_irq(skb);
1926 return ;
1927 }
1928
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001929 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001930 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001931 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1932 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001933
1934 if (pDevice->byBBType == BB_TYPE_11A) {
1935 wCurrentRate = RATE_6M;
1936 byPktType = PK_TYPE_11A;
1937 } else {
1938 wCurrentRate = RATE_1M;
1939 byPktType = PK_TYPE_11B;
1940 }
1941
1942 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1943 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1944 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1945 // to set power here.
1946 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1947 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1948 } else {
1949 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1950 }
1951
1952 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1953
1954 //Set packet type
1955 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1956 pTxBufHead->wFIFOCtl = 0;
1957 }
1958 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1959 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1960 }
1961 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1962 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1963 }
1964 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1965 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1966 }
1967
1968 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1969 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1970
Andres More22040bb2010-08-02 20:21:44 -03001971 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001972 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001973 if (pDevice->bEnableHostWEP) {
1974 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001975 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001976 }
Forest Bond92b96792009-06-13 07:38:31 -04001977 }
1978 else {
1979 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001980 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001981 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001982 }
Andres More4e9b5e22013-02-12 20:36:30 -05001983 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001984 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1985 };
1986
1987 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1988 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1989
1990 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1991 //Set Preamble type always long
1992 //pDevice->byPreambleType = PREAMBLE_LONG;
1993
1994 // probe-response don't retry
1995 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001996 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001997 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1998 //}
1999 }
2000
2001 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2002
2003 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05002004 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04002005 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2006 } else {
2007 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2008 }
2009
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002010 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04002011 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2012
2013 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
2014 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2015 }
2016
2017 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
2018 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2019 }
2020
2021 if (cbExtSuppRate >0) {
2022 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2023 }
2024 }
2025
Forest Bond92b96792009-06-13 07:38:31 -04002026 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05002027 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04002028
2029 // Notes:
2030 // Although spec says MMPDU can be fragmented; In most case,
2031 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05002032 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04002033
Forest Bond92b96792009-06-13 07:38:31 -04002034 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2035 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2036 cbIVlen = 4;
2037 cbICVlen = 4;
2038 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2039 }
2040 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2041 cbIVlen = 8;//IV+ExtIV
2042 cbMIClen = 8;
2043 cbICVlen = 4;
2044 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2045 //We need to get seed here for filling TxKey entry.
2046 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2047 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2048 }
2049 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2050 cbIVlen = 8;//RSN Header
2051 cbICVlen = 8;//MIC
2052 cbMICHDR = sizeof(SMICHDRHead);
2053 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002054 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002055 }
2056 //MAC Header should be padding 0 to DW alignment.
2057 uPadding = 4 - (cbMacHdLen%4);
2058 uPadding %= 4;
2059 }
2060
2061 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2062
2063 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002064 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002065 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2066 }
2067 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2068
Forest Bond92b96792009-06-13 07:38:31 -04002069 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002070 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
2071 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
2072 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002073 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002074 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002075 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002076 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002077 sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
2078 sizeof(struct vnt_cts));
2079 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002080 sizeof(struct vnt_cts) + sizeof(STxDataHead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002081
2082 }
2083 else {//802.11a/b packet
2084
2085 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2086 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2087 pvRTS = NULL;
2088 pvCTS = NULL;
2089 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
2090 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
2091 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002092 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002093 &(p80211Header->sA3.abyAddr1[0]),
2094 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002095 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002096 &(p80211Header->sA3.abyAddr2[0]),
2097 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002098 //=========================
2099 // No Fragmentation
2100 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002101 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002102
Forest Bond92b96792009-06-13 07:38:31 -04002103 //Fill FIFO,RrvTime,RTS,and CTS
2104 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2105 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2106
2107 //Fill DataHead
2108 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002109 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002110
Andres More1cac4a42013-03-18 20:33:50 -05002111 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002112
2113 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2114
Andres Moreb902fbf2013-02-25 20:32:51 -05002115 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2116 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2117 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002118
2119 // Copy the Packet into a tx Buffer
2120 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2121
2122 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002123 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002124 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2125
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002126 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002127 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2128 if (cbExtSuppRate != 0) {
2129 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2130 memcpy((pbyPayloadHead + cbFrameBodySize),
2131 pMgmt->abyCurrSuppRates,
2132 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2133 );
2134 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2135 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2136 pMgmt->abyCurrExtSuppRates,
2137 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2138 );
2139 }
2140 }
2141
2142 // Set wep
2143 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2144
2145 if (pDevice->bEnableHostWEP) {
2146 pTransmitKey = &STempKey;
2147 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2148 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2149 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2150 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2151 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2152 memcpy(pTransmitKey->abyKey,
2153 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2154 pTransmitKey->uKeyLength
2155 );
2156 }
2157
2158 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2159
Andres More52a7e642013-02-25 20:32:53 -05002160 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2161 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002162
2163 // DO Software Michael
2164 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002165 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002166 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002167 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002168 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2169 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002170
2171 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2172
2173 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2174
Andres More52a7e642013-02-25 20:32:53 -05002175 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2176 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002177
2178 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2179 MIC_vUnInit();
2180
Andres More4e9b5e22013-02-12 20:36:30 -05002181 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002182 *pdwMIC_L = 0;
2183 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002184 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002185 }
2186
2187 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2188 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002189 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2190 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002191
2192 }
2193
Andres Moreb902fbf2013-02-25 20:32:51 -05002194 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05002195 pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002196
2197 if (pDevice->bEnableHostWEP) {
2198 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2199 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2200 }
2201
2202 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002203 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002204 }
2205 }
2206
Andres More1cac4a42013-03-18 20:33:50 -05002207 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002208 pDevice->wSeqCounter++ ;
2209 if (pDevice->wSeqCounter > 0x0fff)
2210 pDevice->wSeqCounter = 0;
2211
Forest Bond92b96792009-06-13 07:38:31 -04002212 if (bIsPSPOLL) {
2213 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2214 // of FIFO control header.
2215 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2216 // in the same place of other packet's Duration-field).
2217 // And it will cause Cisco-AP to issue Disassociation-packet
2218 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2219 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
2220 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
2221 } else {
2222 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
2223 }
2224 }
2225
Andres More3eaca0d2013-02-25 20:32:52 -05002226 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002227 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002228 pTX_Buffer->byType = 0x00;
2229
2230 pContext->pPacket = skb;
2231 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002232 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002233
Andres More1cac4a42013-03-18 20:33:50 -05002234 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2235 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002236 }
2237 else {
Andres More1cac4a42013-03-18 20:33:50 -05002238 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002239 }
2240 PIPEnsSendBulkOut(pDevice,pContext);
2241 return ;
2242
2243}
2244
Forest Bond92b96792009-06-13 07:38:31 -04002245//TYPE_AC0DMA data tx
2246/*
2247 * Description:
2248 * Tx packet via AC0DMA(DMA1)
2249 *
2250 * Parameters:
2251 * In:
2252 * pDevice - Pointer to the adapter
2253 * skb - Pointer to tx skb packet
2254 * Out:
2255 * void
2256 *
2257 * Return Value: NULL
2258 */
2259
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002260int nsDMA_tx_packet(struct vnt_private *pDevice,
2261 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002262{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002263 struct net_device_stats *pStats = &pDevice->stats;
2264 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002265 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002266 u32 BytesToWrite = 0, uHeaderLen = 0;
2267 u32 uNodeIndex = 0;
2268 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2269 u16 wAID;
2270 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002271 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002272 PSKeyItem pTransmitKey = NULL;
2273 SKeyItem STempKey;
2274 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002275 int bTKIP_UseGTK = false;
2276 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002277 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002278 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002279 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002280 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002281 u32 status;
2282 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002283 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002284
Forest Bond92b96792009-06-13 07:38:31 -04002285 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2286
2287 if (pDevice->uAssocCount == 0) {
2288 dev_kfree_skb_irq(skb);
2289 return 0;
2290 }
2291
Andres Moreb902fbf2013-02-25 20:32:51 -05002292 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002293 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002294 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002295 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2296
2297 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2298 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2299 // set tx map
2300 pMgmt->abyPSTxMap[0] |= byMask[0];
2301 return 0;
2302 }
Masanari Iida93184692012-08-13 21:21:50 +09002303 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002304
2305 if (pDevice->byBBType != BB_TYPE_11A)
2306 pDevice->wCurrentRate = RATE_2M;
2307 else
2308 pDevice->wCurrentRate = RATE_24M;
2309 // long preamble type
2310 pDevice->byPreambleType = PREAMBLE_SHORT;
2311
2312 }else {
2313
Andres Moreb902fbf2013-02-25 20:32:51 -05002314 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002315
2316 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2317
2318 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2319
2320 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2321 // set tx map
2322 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2323 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2324 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2325 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2326
2327 return 0;
2328 }
2329 // AP rate decided from node
2330 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2331 // tx preamble decided from node
2332
2333 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2334 pDevice->byPreambleType = pDevice->byShortPreamble;
2335
2336 }else {
2337 pDevice->byPreambleType = PREAMBLE_LONG;
2338 }
Andres More4e9b5e22013-02-12 20:36:30 -05002339 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002340 }
2341 }
2342
Andres Moree269fc22013-02-12 20:36:29 -05002343 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002344 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2345 dev_kfree_skb_irq(skb);
2346 return 0;
2347 }
2348 }
2349
2350 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2351
2352 if (pContext == NULL) {
2353 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2354 dev_kfree_skb_irq(skb);
2355 return STATUS_RESOURCES;
2356 }
2357
Andres Moreceb8c5d2013-03-18 20:33:49 -05002358 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002359
2360//mike add:station mode check eapol-key challenge--->
2361{
Andres Moreb902fbf2013-02-25 20:32:51 -05002362 u8 Protocol_Version; //802.1x Authentication
2363 u8 Packet_Type; //802.1x Authentication
2364 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002365 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002366
Charles Clément21ec51f2010-05-18 10:08:14 -07002367 Protocol_Version = skb->data[ETH_HLEN];
2368 Packet_Type = skb->data[ETH_HLEN+1];
2369 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2370 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 -05002371 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002372 /* 802.1x OR eapol-key challenge frame transfer */
2373 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2374 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002375 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002376 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2377 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2378 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002379 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002380 PRINT_K("WPA ");
2381 }
2382 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002383 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002384 PRINT_K("WPA2(re-keying) ");
2385 }
2386 PRINT_K("Authentication completed!!\n");
2387 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002388 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002389 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002390 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002391 PRINT_K("WPA2 Authentication completed!!\n");
2392 }
2393 }
2394 }
2395}
2396//mike add:station mode check eapol-key challenge<---
2397
Andres More4e9b5e22013-02-12 20:36:30 -05002398 if (pDevice->bEncryptionEnable == true) {
2399 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002400 // get Transmit key
2401 do {
2402 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2403 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2404 pbyBSSID = pDevice->abyBSSID;
2405 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002406 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002407 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002408 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2409 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002410 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2411 break;
2412 }
2413 } else {
2414 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2415 break;
2416 }
2417 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002418 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2419 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002420 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2421 for (ii = 0; ii< 6; ii++)
2422 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2423 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2424
2425 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002426 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002427 break;
2428 }
2429 // get group key
2430 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002431 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002432 pTransmitKey = NULL;
2433 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2434 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2435 }
2436 else
2437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2438 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002439 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002440 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2441 }
Andres Moree269fc22013-02-12 20:36:29 -05002442 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002443 }
2444
2445 if (pDevice->bEnableHostWEP) {
2446 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002447 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002448 pTransmitKey = &STempKey;
2449 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2450 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2451 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2452 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2453 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2454 memcpy(pTransmitKey->abyKey,
2455 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2456 pTransmitKey->uKeyLength
2457 );
2458 }
2459 }
2460
Andres Moreb902fbf2013-02-25 20:32:51 -05002461 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002462
2463 if (pDevice->bFixRate) {
2464 if (pDevice->byBBType == BB_TYPE_11B) {
2465 if (pDevice->uConnectionRate >= RATE_11M) {
2466 pDevice->wCurrentRate = RATE_11M;
2467 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002468 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002469 }
2470 } else {
2471 if ((pDevice->byBBType == BB_TYPE_11A) &&
2472 (pDevice->uConnectionRate <= RATE_6M)) {
2473 pDevice->wCurrentRate = RATE_6M;
2474 } else {
2475 if (pDevice->uConnectionRate >= RATE_54M)
2476 pDevice->wCurrentRate = RATE_54M;
2477 else
Andres More3eaca0d2013-02-25 20:32:52 -05002478 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002479 }
2480 }
2481 }
2482 else {
2483 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2484 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002485 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002486 // Multicast use highest data rate
2487 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2488 // preamble type
2489 pDevice->byPreambleType = pDevice->byShortPreamble;
2490 }
2491 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002492 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002493 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2494 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2495 pDevice->byPreambleType = pDevice->byShortPreamble;
2496
2497 }
2498 else {
2499 pDevice->byPreambleType = PREAMBLE_LONG;
2500 }
2501 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2502 }
2503 else {
2504 if (pDevice->byBBType != BB_TYPE_11A)
2505 pDevice->wCurrentRate = RATE_2M;
2506 else
2507 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2508 // abyCurrExtSuppRates[]
2509 pDevice->byPreambleType = PREAMBLE_SHORT;
2510 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2511 }
2512 }
2513 }
2514 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2515 // Infra STA rate decided from AP Node, index = 0
2516 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2517 }
2518 }
2519
Andres Moreceb8c5d2013-03-18 20:33:49 -05002520 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002521 if (pDevice->byBBType != BB_TYPE_11A) {
2522 pDevice->wCurrentRate = RATE_1M;
2523 pDevice->byACKRate = RATE_1M;
2524 pDevice->byTopCCKBasicRate = RATE_1M;
2525 pDevice->byTopOFDMBasicRate = RATE_6M;
2526 } else {
2527 pDevice->wCurrentRate = RATE_6M;
2528 pDevice->byACKRate = RATE_6M;
2529 pDevice->byTopCCKBasicRate = RATE_1M;
2530 pDevice->byTopOFDMBasicRate = RATE_6M;
2531 }
2532 }
Forest Bond92b96792009-06-13 07:38:31 -04002533
Andres More0cbd8d92010-05-06 20:34:29 -03002534 DBG_PRT(MSG_LEVEL_DEBUG,
2535 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2536 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002537
2538 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002539 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002540 }
2541
2542 if (pDevice->wCurrentRate <= RATE_11M) {
2543 byPktType = PK_TYPE_11B;
2544 }
2545
Andres More4e9b5e22013-02-12 20:36:30 -05002546 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002547 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2548 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002549 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002550 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002551 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2552 if (pTransmitKey == NULL) {
2553 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2554 }
2555 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002556 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002557 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2558 }
2559 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002560 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2561 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002562 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002563 }
2564 }
2565 }
2566
Forest Bond92b96792009-06-13 07:38:31 -04002567 if (pDevice->bEnableHostWEP) {
2568 if ((uNodeIndex != 0) &&
2569 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
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 else {
2577
Forest Bond92b96792009-06-13 07:38:31 -04002578 if (pTransmitKey == NULL) {
2579 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002580 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002581 dev_kfree_skb_irq(skb);
2582 pStats->tx_dropped++;
2583 return STATUS_FAILURE;
2584 }
Forest Bond92b96792009-06-13 07:38:31 -04002585 }
2586 }
2587
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002588 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2589
Forest Bond92b96792009-06-13 07:38:31 -04002590 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002591 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002592 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002593 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002594 pDevice->wCurrentRate,
2595 &uHeaderLen, &BytesToWrite
2596 );
2597
Andres Moree269fc22013-02-12 20:36:29 -05002598 if (fConvertedPacket == false) {
2599 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002600 dev_kfree_skb_irq(skb);
2601 return STATUS_FAILURE;
2602 }
2603
Andres More4e9b5e22013-02-12 20:36:30 -05002604 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002605 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002606 bScheduleCommand((void *) pDevice,
2607 WLAN_CMD_MAC_DISPOWERSAVING,
2608 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002609 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002610 }
2611 }
2612
Andres Moreb902fbf2013-02-25 20:32:51 -05002613 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002614 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002615
2616 pContext->pPacket = skb;
2617 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002618 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002619
Andres Moreceb8c5d2013-03-18 20:33:49 -05002620 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 -04002621
2622 status = PIPEnsSendBulkOut(pDevice,pContext);
2623
Andres More4e9b5e22013-02-12 20:36:30 -05002624 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002625 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002626
Andres Moreb902fbf2013-02-25 20:32:51 -05002627 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002628 }
2629
2630 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002631 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002632 dev_kfree_skb_irq(skb);
2633 return STATUS_FAILURE;
2634 }
2635 else
2636 return 0;
2637
2638}
2639
Forest Bond92b96792009-06-13 07:38:31 -04002640/*
2641 * Description:
2642 * Relay packet send (AC1DMA) from rx dpc.
2643 *
2644 * Parameters:
2645 * In:
2646 * pDevice - Pointer to the adapter
2647 * pPacket - Pointer to rx packet
2648 * cbPacketSize - rx ethernet frame size
2649 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002650 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002651 *
Andres More4e9b5e22013-02-12 20:36:30 -05002652 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002653 */
2654
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002655int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2656 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002657{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002658 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002659 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002660 u32 BytesToWrite = 0, uHeaderLen = 0;
2661 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002662 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002663 SKeyItem STempKey;
2664 PSKeyItem pTransmitKey = NULL;
2665 u8 *pbyBSSID;
2666 PUSB_SEND_CONTEXT pContext;
2667 u8 byPktTyp;
2668 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002669 u32 status;
2670 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002671
Forest Bond92b96792009-06-13 07:38:31 -04002672 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2673
2674 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002675 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002676 }
2677
Andres Moreceb8c5d2013-03-18 20:33:49 -05002678 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002679
Andres More4e9b5e22013-02-12 20:36:30 -05002680 if (pDevice->bEncryptionEnable == true) {
2681 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002682 // get group key
2683 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002684 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002685 pTransmitKey = NULL;
2686 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2687 } else {
2688 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2689 }
2690 }
2691
2692 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002693 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002694 pTransmitKey = &STempKey;
2695 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2696 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2697 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2698 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2699 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2700 memcpy(pTransmitKey->abyKey,
2701 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2702 pTransmitKey->uKeyLength
2703 );
2704 }
2705 }
2706
2707 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002708 pContext->bBoolInUse = false;
2709 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002710 }
2711
Andres Moreb902fbf2013-02-25 20:32:51 -05002712 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002713
2714 if (pDevice->bFixRate) {
2715 if (pDevice->byBBType == BB_TYPE_11B) {
2716 if (pDevice->uConnectionRate >= RATE_11M) {
2717 pDevice->wCurrentRate = RATE_11M;
2718 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002719 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002720 }
2721 } else {
2722 if ((pDevice->byBBType == BB_TYPE_11A) &&
2723 (pDevice->uConnectionRate <= RATE_6M)) {
2724 pDevice->wCurrentRate = RATE_6M;
2725 } else {
2726 if (pDevice->uConnectionRate >= RATE_54M)
2727 pDevice->wCurrentRate = RATE_54M;
2728 else
Andres More3eaca0d2013-02-25 20:32:52 -05002729 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002730 }
2731 }
2732 }
2733 else {
2734 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2735 }
2736
Forest Bond92b96792009-06-13 07:38:31 -04002737 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002738 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002739 }
2740
2741 if (pDevice->wCurrentRate <= RATE_11M)
2742 byPktType = PK_TYPE_11B;
2743
Andres Moreabad19d2010-07-12 16:28:32 -03002744 BytesToWrite = uDataLen + ETH_FCS_LEN;
2745
Forest Bond92b96792009-06-13 07:38:31 -04002746 // Convert the packet to an usb frame and copy into our buffer
2747 // and send the irp.
2748
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002749 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2750
Forest Bond92b96792009-06-13 07:38:31 -04002751 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002752 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002753 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2754 pbySkbData, pTransmitKey, uNodeIndex,
2755 pDevice->wCurrentRate,
2756 &uHeaderLen, &BytesToWrite
2757 );
2758
Andres Moree269fc22013-02-12 20:36:29 -05002759 if (fConvertedPacket == false) {
2760 pContext->bBoolInUse = false;
2761 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002762 }
2763
Andres Moreb902fbf2013-02-25 20:32:51 -05002764 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002765 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002766
2767 pContext->pPacket = NULL;
2768 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002769 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002770
Andres Moreceb8c5d2013-03-18 20:33:49 -05002771 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 -04002772
2773 status = PIPEnsSendBulkOut(pDevice,pContext);
2774
Andres More4e9b5e22013-02-12 20:36:30 -05002775 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002776}
2777