blob: 1b2effc050ee43c78a23e0c7d5af57513928b91c [file] [log] [blame]
Forest Bond92b96792009-06-13 07:38:31 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
Gilles Espinassef77f13e2010-03-29 15:41:47 +020028 * s_vGenerateTxParameter - Generate tx dma required parameter.
Forest Bond92b96792009-06-13 07:38:31 -040029 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020034 * s_uGetRTSCTSDuration- get rtx/cts required duration
Forest Bond92b96792009-06-13 07:38:31 -040035 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
Gilles Espinassef77f13e2010-03-29 15:41:47 +020038 * s_vFillFragParameter- Set fragment ctl parameter.
Forest Bond92b96792009-06-13 07:38:31 -040039 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
44 *
45 * Revision History:
46 *
47 */
48
Forest Bond92b96792009-06-13 07:38:31 -040049#include "device.h"
Forest Bond92b96792009-06-13 07:38:31 -040050#include "rxtx.h"
Forest Bond92b96792009-06-13 07:38:31 -040051#include "tether.h"
Forest Bond92b96792009-06-13 07:38:31 -040052#include "card.h"
Forest Bond92b96792009-06-13 07:38:31 -040053#include "bssdb.h"
Forest Bond92b96792009-06-13 07:38:31 -040054#include "mac.h"
Forest Bond92b96792009-06-13 07:38:31 -040055#include "michael.h"
Forest Bond92b96792009-06-13 07:38:31 -040056#include "tkip.h"
Forest Bond92b96792009-06-13 07:38:31 -040057#include "tcrc.h"
Forest Bond92b96792009-06-13 07:38:31 -040058#include "wctl.h"
Forest Bond92b96792009-06-13 07:38:31 -040059#include "hostap.h"
Forest Bond92b96792009-06-13 07:38:31 -040060#include "rf.h"
Forest Bond92b96792009-06-13 07:38:31 -040061#include "datarate.h"
Forest Bond92b96792009-06-13 07:38:31 -040062#include "usbpipe.h"
Forest Bond92b96792009-06-13 07:38:31 -040063#include "iocmd.h"
Jim Lieb9d26d602009-08-12 14:54:08 -070064
Mariano Reingart4a499de2010-10-29 19:15:26 -030065static int msglevel = MSG_LEVEL_INFO;
Forest Bond92b96792009-06-13 07:38:31 -040066
Andres More3eaca0d2013-02-25 20:32:52 -050067const u16 wTimeStampOff[2][MAX_RATE] = {
Forest Bond92b96792009-06-13 07:38:31 -040068 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
69 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
70 };
71
Andres More3eaca0d2013-02-25 20:32:52 -050072const u16 wFB_Opt0[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040073 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
74 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
75 };
Andres More3eaca0d2013-02-25 20:32:52 -050076const u16 wFB_Opt1[2][5] = {
Forest Bond92b96792009-06-13 07:38:31 -040077 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
78 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
79 };
80
Forest Bond92b96792009-06-13 07:38:31 -040081#define RTSDUR_BB 0
82#define RTSDUR_BA 1
83#define RTSDUR_AA 2
84#define CTSDUR_BA 3
85#define RTSDUR_BA_F0 4
86#define RTSDUR_AA_F0 5
87#define RTSDUR_BA_F1 6
88#define RTSDUR_AA_F1 7
89#define CTSDUR_BA_F0 8
90#define CTSDUR_BA_F1 9
91#define DATADUR_B 10
92#define DATADUR_A 11
93#define DATADUR_A_F0 12
94#define DATADUR_A_F1 13
95
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000096static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
97 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -040098
Malcolm Priestleyd56131d2013-01-17 23:15:22 +000099static void *s_vGetFreeContext(struct vnt_private *pDevice);
100
101static void s_vGenerateTxParameter(struct vnt_private *pDevice,
102 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
103 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500104 struct ethhdr *psEthHeader);
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000105
106static u32 s_uFillDataHead(struct vnt_private *pDevice,
107 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100108 u32 uDMAIdx, int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400109
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000110static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500111 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000112 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -0400113
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000114static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
115 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100116 struct vnt_mic_hdr *mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -0400117
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000118static void s_vSWencryption(struct vnt_private *pDevice,
119 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400120
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000121static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
122 u32 cbFrameLength, u16 wRate, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400123
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100124static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000125 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400126
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000127static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
128 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
129 int bDisCRC, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400130
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000131static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100132 void *pvRTS, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500133 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400134
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100135static u16 s_uGetDataDuration(struct vnt_private *pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100136 u8 byPktType, int bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400137
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100138static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000139 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
140 int bNeedAck, u8 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400141
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000142static void *s_vGetFreeContext(struct vnt_private *pDevice)
Forest Bond92b96792009-06-13 07:38:31 -0400143{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000144 PUSB_SEND_CONTEXT pContext = NULL;
145 PUSB_SEND_CONTEXT pReturnContext = NULL;
146 int ii;
Forest Bond92b96792009-06-13 07:38:31 -0400147
148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
149
150 for (ii = 0; ii < pDevice->cbTD; ii++) {
151 pContext = pDevice->apTD[ii];
Andres Moree269fc22013-02-12 20:36:29 -0500152 if (pContext->bBoolInUse == false) {
Andres More4e9b5e22013-02-12 20:36:30 -0500153 pContext->bBoolInUse = true;
Malcolm Priestleyc0de17e2013-08-05 21:09:14 +0100154 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
Forest Bond92b96792009-06-13 07:38:31 -0400155 pReturnContext = pContext;
156 break;
157 }
158 }
159 if ( ii == pDevice->cbTD ) {
160 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
161 }
Andres More8611a292010-05-01 14:25:00 -0300162 return (void *) pReturnContext;
Forest Bond92b96792009-06-13 07:38:31 -0400163}
164
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000165static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
166 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
Forest Bond92b96792009-06-13 07:38:31 -0400167{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000168 PSStatCounter pStatistic = &pDevice->scStatistic;
Forest Bond92b96792009-06-13 07:38:31 -0400169
Andres More4b50fb42010-06-22 21:57:42 -0300170 if (is_broadcast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400171 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
Andres More4b50fb42010-06-22 21:57:42 -0300172 else if (is_multicast_ether_addr(pbyDestAddr))
Forest Bond92b96792009-06-13 07:38:31 -0400173 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
174 else
175 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
176
177 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
178 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
Andres More9a0e7562010-04-13 21:54:48 -0300179 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
180 pbyDestAddr,
181 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400182}
183
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000184static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
185 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100186 u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr)
Forest Bond92b96792009-06-13 07:38:31 -0400187{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000188 u32 *pdwIV = (u32 *)pbyIVHead;
189 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
Andres More1cac4a42013-03-18 20:33:50 -0500190 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000191 u32 dwRevIVCounter;
Forest Bond92b96792009-06-13 07:38:31 -0400192
Forest Bond92b96792009-06-13 07:38:31 -0400193 //Fill TXKEY
194 if (pTransmitKey == NULL)
195 return;
196
197 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
198 *pdwIV = pDevice->dwIVCounter;
199 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
200
201 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
202 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
Andres Moreb902fbf2013-02-25 20:32:51 -0500203 memcpy(pDevice->abyPRNG, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700204 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400205 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -0500206 memcpy(pbyBuf, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700207 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400208 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
Andres Moreb902fbf2013-02-25 20:32:51 -0500209 memcpy(pbyBuf+8, (u8 *)&(dwRevIVCounter), 3);
Jim Lieb3e362592009-08-12 14:54:11 -0700210 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
Forest Bond92b96792009-06-13 07:38:31 -0400211 }
Jim Lieb3e362592009-08-12 14:54:11 -0700212 memcpy(pDevice->abyPRNG, pbyBuf, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400213 }
214 // Append IV after Mac Header
215 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
Malcolm Priestleyd5bbef72012-11-11 15:53:14 +0000216 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
Forest Bond92b96792009-06-13 07:38:31 -0400217 *pdwIV = cpu_to_le32(*pdwIV);
218 pDevice->dwIVCounter++;
219 if (pDevice->dwIVCounter > WEP_IV_MASK) {
220 pDevice->dwIVCounter = 0;
221 }
222 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
223 pTransmitKey->wTSC15_0++;
224 if (pTransmitKey->wTSC15_0 == 0) {
225 pTransmitKey->dwTSC47_16++;
226 }
227 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
228 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
Jim Lieb3e362592009-08-12 14:54:11 -0700229 memcpy(pbyBuf, pDevice->abyPRNG, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400230 // Make IV
Jim Lieb3e362592009-08-12 14:54:11 -0700231 memcpy(pdwIV, pDevice->abyPRNG, 3);
Forest Bond92b96792009-06-13 07:38:31 -0400232
Andres Moreb902fbf2013-02-25 20:32:51 -0500233 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Forest Bond92b96792009-06-13 07:38:31 -0400234 // Append IV&ExtIV after Mac Header
235 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +0000236 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %x\n",
237 *pdwExtIV);
Forest Bond92b96792009-06-13 07:38:31 -0400238
239 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
240 pTransmitKey->wTSC15_0++;
241 if (pTransmitKey->wTSC15_0 == 0) {
242 pTransmitKey->dwTSC47_16++;
243 }
Jim Lieb3e362592009-08-12 14:54:11 -0700244 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
Forest Bond92b96792009-06-13 07:38:31 -0400245
246 // Make IV
247 *pdwIV = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -0500248 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
Andres More3eaca0d2013-02-25 20:32:52 -0500249 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
Forest Bond92b96792009-06-13 07:38:31 -0400250 //Append IV&ExtIV after Mac Header
251 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
252
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100253 if (!mic_hdr)
254 return;
Forest Bond92b96792009-06-13 07:38:31 -0400255
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100256 /* MICHDR0 */
257 mic_hdr->id = 0x59;
258 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
259 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400260
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +0100261 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
262 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
263
264 /* MICHDR1 */
265 if (pDevice->bLongHeader)
266 mic_hdr->hlen = cpu_to_be16(28);
267 else
268 mic_hdr->hlen = cpu_to_be16(22);
269
270 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
271 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
272
273 /* MICHDR2 */
274 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
275 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
276 & 0xc78f);
277 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
278
279 if (pDevice->bLongHeader)
280 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400281 }
282}
283
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000284static void s_vSWencryption(struct vnt_private *pDevice,
285 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
Forest Bond92b96792009-06-13 07:38:31 -0400286{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000287 u32 cbICVlen = 4;
288 u32 dwICV = 0xffffffff;
289 u32 *pdwICV;
Forest Bond92b96792009-06-13 07:38:31 -0400290
291 if (pTransmitKey == NULL)
292 return;
293
294 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
295 //=======================================================================
296 // Append ICV after payload
297 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500298 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400299 // finally, we must invert dwCRC to get the correct answer
300 *pdwICV = cpu_to_le32(~dwICV);
301 // RC4 encryption
302 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
303 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
304 //=======================================================================
305 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
306 //=======================================================================
307 //Append ICV after payload
308 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
Andres More52a7e642013-02-25 20:32:53 -0500309 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
Forest Bond92b96792009-06-13 07:38:31 -0400310 // finally, we must invert dwCRC to get the correct answer
311 *pdwICV = cpu_to_le32(~dwICV);
312 // RC4 encryption
313 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
314 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
315 //=======================================================================
316 }
317}
318
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100319static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
320{
321 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
322 [rate % MAX_RATE]);
323}
324
Forest Bond92b96792009-06-13 07:38:31 -0400325/*byPktType : PK_TYPE_11A 0
326 PK_TYPE_11B 1
327 PK_TYPE_11GB 2
328 PK_TYPE_11GA 3
329*/
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000330static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
331 u32 cbFrameLength, u16 wRate, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400332{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000333 u32 uDataTime, uAckTime;
Forest Bond92b96792009-06-13 07:38:31 -0400334
335 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
336 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
Andres More3eaca0d2013-02-25 20:32:52 -0500337 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400338 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
Andres More3eaca0d2013-02-25 20:32:52 -0500339 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400340 }
341
342 if (bNeedAck) {
343 return (uDataTime + pDevice->uSIFS + uAckTime);
344 }
345 else {
346 return uDataTime;
347 }
348}
349
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100350static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
351 u32 frame_length, u16 rate, int need_ack)
352{
353 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
354 frame_length, rate, need_ack));
355}
356
Forest Bond92b96792009-06-13 07:38:31 -0400357//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100358static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000359 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
Forest Bond92b96792009-06-13 07:38:31 -0400360{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000361 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
Forest Bond92b96792009-06-13 07:38:31 -0400362
363 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
364
Forest Bond92b96792009-06-13 07:38:31 -0400365 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
366 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
367 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
368 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
369 }
370 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
371 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
372 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
373 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
374 }
375 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
376 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
377 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
378 }
379 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
380 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
381 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
382 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
383 return uRrvTime;
384 }
385
386 //RTSRrvTime
387 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100388 return cpu_to_le16((u16)uRrvTime);
Forest Bond92b96792009-06-13 07:38:31 -0400389}
390
391//byFreqType 0: 5GHz, 1:2.4Ghz
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100392static u16 s_uGetDataDuration(struct vnt_private *pDevice,
393 u8 byPktType, int bNeedAck)
Forest Bond92b96792009-06-13 07:38:31 -0400394{
Malcolm Priestley0005cb02013-08-07 21:26:12 +0100395 u32 uAckTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400396
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100397 if (bNeedAck) {
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100398 if (byPktType == PK_TYPE_11B)
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100399 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
400 byPktType, 14, pDevice->byTopCCKBasicRate);
401 else
402 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
403 byPktType, 14, pDevice->byTopOFDMBasicRate);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100404 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
Malcolm Priestleyb02ccd52013-08-13 19:59:31 +0100405 }
Forest Bond92b96792009-06-13 07:38:31 -0400406
Forest Bond92b96792009-06-13 07:38:31 -0400407 return 0;
408}
409
Forest Bond92b96792009-06-13 07:38:31 -0400410//byFreqType: 0=>5GHZ 1=>2.4GHZ
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100411static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000412 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
413 u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400414{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000415 u32 uCTSTime = 0, uDurTime = 0;
Forest Bond92b96792009-06-13 07:38:31 -0400416
Forest Bond92b96792009-06-13 07:38:31 -0400417 switch (byDurType) {
418
419 case RTSDUR_BB: //RTSDuration_bb
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_BA: //RTSDuration_ba
425 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
426 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
427 break;
428
429 case RTSDUR_AA: //RTSDuration_aa
430 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
431 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
432 break;
433
434 case CTSDUR_BA: //CTSDuration_ba
435 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
436 break;
437
438 case RTSDUR_BA_F0: //RTSDuration_ba_f0
439 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
440 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
441 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
442 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
443 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
444 }
445 break;
446
447 case RTSDUR_AA_F0: //RTSDuration_aa_f0
448 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
449 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
450 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
451 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
452 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
453 }
454 break;
455
456 case RTSDUR_BA_F1: //RTSDuration_ba_f1
457 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
458 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
459 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
460 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
461 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
462 }
463 break;
464
465 case RTSDUR_AA_F1: //RTSDuration_aa_f1
466 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
467 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
468 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
469 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
470 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
471 }
472 break;
473
474 case CTSDUR_BA_F0: //CTSDuration_ba_f0
475 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
476 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
477 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
478 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
479 }
480 break;
481
482 case CTSDUR_BA_F1: //CTSDuration_ba_f1
483 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
484 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
485 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
486 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
487 }
488 break;
489
490 default:
491 break;
492 }
493
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100494 return cpu_to_le16((u16)uDurTime);
Forest Bond92b96792009-06-13 07:38:31 -0400495}
496
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000497static u32 s_uFillDataHead(struct vnt_private *pDevice,
498 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +0100499 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400500{
501
502 if (pTxDataHead == NULL) {
503 return 0;
504 }
505
506 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Forest Bond92b96792009-06-13 07:38:31 -0400507 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +0100508 struct vnt_tx_datahead_g *pBuf =
509 (struct vnt_tx_datahead_g *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400510 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100511 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
512 byPktType, &pBuf->a);
513 BBvCalculateParameter(pDevice, cbFrameLength,
514 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400515 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100516 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100517 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100518 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100519 PK_TYPE_11B, bNeedAck);
Forest Bond92b96792009-06-13 07:38:31 -0400520
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100521 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
522 wCurrentRate);
523 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
524 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400525 return (pBuf->wDuration_a);
526 } else {
527 // Auto Fallback
Malcolm Priestley7c05c542013-08-16 23:49:15 +0100528 struct vnt_tx_datahead_g_fb *pBuf =
529 (struct vnt_tx_datahead_g_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400530 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100531 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
532 byPktType, &pBuf->a);
533 BBvCalculateParameter(pDevice, cbFrameLength,
534 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Forest Bond92b96792009-06-13 07:38:31 -0400535 //Get Duration and TimeStamp
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100536 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100537 byPktType, bNeedAck);
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100538 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100539 PK_TYPE_11B, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100540 pBuf->wDuration_a_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100541 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100542 pBuf->wDuration_a_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100543 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100544 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
545 wCurrentRate);
546 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
547 pDevice->byTopCCKBasicRate);
Forest Bond92b96792009-06-13 07:38:31 -0400548 return (pBuf->wDuration_a);
549 } //if (byFBOption == AUTO_FB_NONE)
Forest Bond92b96792009-06-13 07:38:31 -0400550 }
551 else if (byPktType == PK_TYPE_11A) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100552 if (byFBOption != AUTO_FB_NONE) {
Malcolm Priestley1da4ee22013-08-16 23:51:38 +0100553 struct vnt_tx_datahead_a_fb *pBuf =
554 (struct vnt_tx_datahead_a_fb *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400555 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100556 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
557 byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400558 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100559 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100560 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100561 pBuf->wDuration_f0 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100562 byPktType, bNeedAck);
Malcolm Priestleyd5005952013-08-21 21:58:37 +0100563 pBuf->wDuration_f1 = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100564 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100565 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
566 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400567 return (pBuf->wDuration);
568 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100569 struct vnt_tx_datahead_ab *pBuf =
570 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400571 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100572 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
573 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400574 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100575 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100576 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100577 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
578 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400579 return (pBuf->wDuration);
580 }
581 }
582 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley558becf2013-08-16 23:50:32 +0100583 struct vnt_tx_datahead_ab *pBuf =
584 (struct vnt_tx_datahead_ab *)pTxDataHead;
Forest Bond92b96792009-06-13 07:38:31 -0400585 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100586 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
587 byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400588 //Get Duration and TimeStampOff
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +0100589 pBuf->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley3ed210e2013-08-07 21:28:45 +0100590 byPktType, bNeedAck);
Malcolm Priestleyf115e762013-08-23 11:48:46 +0100591 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
592 wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400593 return (pBuf->wDuration);
594 }
595 return 0;
596}
597
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000598static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100599 void *pvRTS, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500600 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400601{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000602 u32 uRTSFrameLen = 20;
Forest Bond92b96792009-06-13 07:38:31 -0400603
Forest Bond92b96792009-06-13 07:38:31 -0400604 if (pvRTS == NULL)
605 return;
606
Masanari Iida93184692012-08-13 21:21:50 +0900607 // 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 -0400608 // Otherwise, we need to modified codes for them.
609 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
610 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100611 struct vnt_rts_g *pBuf = (struct vnt_rts_g *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400612 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100613 BBvCalculateParameter(pDevice, uRTSFrameLen,
614 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
615 BBvCalculateParameter(pDevice, uRTSFrameLen,
616 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400617 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100618 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
619 cbFrameLength, PK_TYPE_11B,
620 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
621 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
622 cbFrameLength, byPktType,
623 wCurrentRate, bNeedAck, byFBOption);
624 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
625 cbFrameLength, byPktType,
626 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100627 pBuf->data.duration = pBuf->wDuration_aa;
628 /*Get RTS Frame body */
629 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400630
Malcolm Priestley07738932013-08-05 22:08:05 +0100631 if (pDevice->eOPMode == OP_MODE_ADHOC ||
632 pDevice->eOPMode == OP_MODE_AP)
633 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
634 else
635 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Andres More9a0e7562010-04-13 21:54:48 -0300636
Malcolm Priestley07738932013-08-05 22:08:05 +0100637 if (pDevice->eOPMode == OP_MODE_AP)
638 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
639 else
640 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400641 }
642 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100643 struct vnt_rts_g_fb *pBuf = (struct vnt_rts_g_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400644 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100645 BBvCalculateParameter(pDevice, uRTSFrameLen,
646 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
647 BBvCalculateParameter(pDevice, uRTSFrameLen,
648 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400649 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100650 pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
651 cbFrameLength, PK_TYPE_11B,
652 pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
653 pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
654 cbFrameLength, byPktType,
655 wCurrentRate, bNeedAck, byFBOption);
656 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
657 cbFrameLength, byPktType,
658 wCurrentRate, bNeedAck, byFBOption);
659 pBuf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
660 RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
661 bNeedAck, byFBOption);
662 pBuf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(pDevice,
663 RTSDUR_AA_F0, cbFrameLength, byPktType,
664 wCurrentRate, bNeedAck, byFBOption);
665 pBuf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
666 RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
667 bNeedAck, byFBOption);
668 pBuf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(pDevice,
669 RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate,
670 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100671 pBuf->data.duration = pBuf->wDuration_aa;
672 /*Get RTS Frame body*/
673 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400674
Malcolm Priestley07738932013-08-05 22:08:05 +0100675 if (pDevice->eOPMode == OP_MODE_ADHOC ||
676 pDevice->eOPMode == OP_MODE_AP)
677 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
678 else
679 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400680
Malcolm Priestley07738932013-08-05 22:08:05 +0100681 if (pDevice->eOPMode == OP_MODE_AP)
682 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
683 else
684 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400685 } // if (byFBOption == AUTO_FB_NONE)
686 }
687 else if (byPktType == PK_TYPE_11A) {
688 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100689 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400690 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100691 BBvCalculateParameter(pDevice, uRTSFrameLen,
692 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400693 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100694 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
695 cbFrameLength, byPktType, wCurrentRate,
696 bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100697 pBuf->data.duration = pBuf->wDuration;
698 /* Get RTS Frame body */
699 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400700
Malcolm Priestley07738932013-08-05 22:08:05 +0100701 if (pDevice->eOPMode == OP_MODE_ADHOC ||
702 pDevice->eOPMode == OP_MODE_AP)
703 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
704 else
705 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400706
Malcolm Priestley07738932013-08-05 22:08:05 +0100707 if (pDevice->eOPMode == OP_MODE_AP)
708 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
709 else
710 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400711 }
712 else {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100713 struct vnt_rts_a_fb *pBuf = (struct vnt_rts_a_fb *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400714 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100715 BBvCalculateParameter(pDevice, uRTSFrameLen,
716 pDevice->byTopOFDMBasicRate, byPktType, &pBuf->a);
Forest Bond92b96792009-06-13 07:38:31 -0400717 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100718 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
719 cbFrameLength, byPktType, wCurrentRate,
720 bNeedAck, byFBOption);
721 pBuf->wRTSDuration_f0 = s_uGetRTSCTSDuration(pDevice,
722 RTSDUR_AA_F0, cbFrameLength, byPktType,
723 wCurrentRate, bNeedAck, byFBOption);
724 pBuf->wRTSDuration_f1 = s_uGetRTSCTSDuration(pDevice,
725 RTSDUR_AA_F1, cbFrameLength, byPktType,
726 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley07738932013-08-05 22:08:05 +0100727 pBuf->data.duration = pBuf->wDuration;
728 /* Get RTS Frame body */
729 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400730
Malcolm Priestley07738932013-08-05 22:08:05 +0100731 if (pDevice->eOPMode == OP_MODE_ADHOC ||
732 pDevice->eOPMode == OP_MODE_AP)
733 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
734 else
735 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
736
737 if (pDevice->eOPMode == OP_MODE_AP)
738 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
739 else
740 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400741 }
742 }
743 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestleyc521cb52013-08-15 21:23:25 +0100744 struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400745 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100746 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate,
747 PK_TYPE_11B, &pBuf->ab);
Forest Bond92b96792009-06-13 07:38:31 -0400748 //Get Duration
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100749 pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
750 cbFrameLength, byPktType, wCurrentRate,
751 bNeedAck, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400752
Malcolm Priestley07738932013-08-05 22:08:05 +0100753 pBuf->data.duration = pBuf->wDuration;
754 /* Get RTS Frame body */
755 pBuf->data.frame_control = TYPE_CTL_RTS;
Forest Bond92b96792009-06-13 07:38:31 -0400756
Malcolm Priestley07738932013-08-05 22:08:05 +0100757 if (pDevice->eOPMode == OP_MODE_ADHOC ||
758 pDevice->eOPMode == OP_MODE_AP)
759 memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
760 else
761 memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);
762
763 if (pDevice->eOPMode == OP_MODE_AP)
764 memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
765 else
766 memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400767 }
768}
769
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000770static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
771 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
772 int bDisCRC, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400773{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000774 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400775
776 if (pvCTS == NULL) {
777 return;
778 }
779
780 if (bDisCRC) {
781 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
782 // in this case we need to decrease its length by 4.
783 uCTSFrameLen -= 4;
784 }
785
786 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100787 if (byFBOption != AUTO_FB_NONE) {
788 /* Auto Fall back */
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100789 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100790 /* Get SignalField,ServiceField,Length */
791 BBvCalculateParameter(pDevice, uCTSFrameLen,
792 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100793 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
794 cbFrameLength, byPktType,
795 wCurrentRate, bNeedAck, byFBOption);
796 /* Get CTSDuration_ba_f0 */
797 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
798 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
799 bNeedAck, byFBOption);
800 /* Get CTSDuration_ba_f1 */
801 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
802 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
803 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100804 /* Get CTS Frame body */
805 pBuf->data.duration = pBuf->wDuration_ba;
806 pBuf->data.frame_control = TYPE_CTL_CTS;
807 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100808 } else {
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100809 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100810 /* Get SignalField,ServiceField,Length */
811 BBvCalculateParameter(pDevice, uCTSFrameLen,
812 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100813 /* Get CTSDuration_ba */
814 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
815 CTSDUR_BA, cbFrameLength, byPktType,
816 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100817 /*Get CTS Frame body*/
818 pBuf->data.duration = pBuf->wDuration_ba;
819 pBuf->data.frame_control = TYPE_CTL_CTS;
820 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400821 }
822 }
823}
824
Forest Bond92b96792009-06-13 07:38:31 -0400825/*+
826 *
827 * Description:
828 * Generate FIFO control for MAC & Baseband controller
829 *
830 * Parameters:
831 * In:
832 * pDevice - Pointer to adpater
833 * pTxDataHead - Transmit Data Buffer
834 * pTxBufHead - pTxBufHead
835 * pvRrvTime - pvRrvTime
836 * pvRTS - RTS Buffer
837 * pCTS - CTS Buffer
838 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
839 * bNeedACK - If need ACK
840 * uDMAIdx - DMA Index
841 * Out:
842 * none
843 *
844 * Return Value: none
845 *
846-*/
Andres Morecc856e62010-05-17 21:34:01 -0300847
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000848static void s_vGenerateTxParameter(struct vnt_private *pDevice,
849 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
850 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500851 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400852{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000853 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
854 u16 wFifoCtl;
Andres Moree269fc22013-02-12 20:36:29 -0500855 int bDisCRC = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000856 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400857
858 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
859 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
860 pFifoHead->wReserved = wCurrentRate;
861 wFifoCtl = pFifoHead->wFIFOCtl;
862
863 if (wFifoCtl & FIFOCTL_CRCDIS) {
Andres More4e9b5e22013-02-12 20:36:30 -0500864 bDisCRC = true;
Forest Bond92b96792009-06-13 07:38:31 -0400865 }
866
867 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
868 byFBOption = AUTO_FB_0;
869 }
870 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
871 byFBOption = AUTO_FB_1;
872 }
873
874 if (pDevice->bLongHeader)
875 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
876
877 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
878
879 if (pvRTS != NULL) { //RTS_need
880 //Fill RsvTime
881 if (pvRrvTime) {
Malcolm Priestley6398a592013-08-16 21:26:55 +0100882 struct vnt_rrv_time_rts *pBuf =
883 (struct vnt_rrv_time_rts *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100884 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
885 byPktType, cbFrameSize, wCurrentRate);
886 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
887 byPktType, cbFrameSize, wCurrentRate);
888 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
889 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100890 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
891 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
892 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
893 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
894 bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400895 }
896 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100897 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
898 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400899 }
900 else {//RTS_needless, PCF mode
901
902 //Fill RsvTime
903 if (pvRrvTime) {
Malcolm Priestley4f990052013-08-16 23:38:57 +0100904 struct vnt_rrv_time_cts *pBuf =
905 (struct vnt_rrv_time_cts *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100906 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
907 cbFrameSize, wCurrentRate, bNeedACK);
908 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
909 PK_TYPE_11B, cbFrameSize,
910 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100911 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
912 byPktType, cbFrameSize, wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400913 }
914 //Fill CTS
915 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
916 }
917 }
918 else if (byPktType == PK_TYPE_11A) {
919
920 if (pvRTS != NULL) {//RTS_need, non PCF mode
921 //Fill RsvTime
922 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100923 struct vnt_rrv_time_ab *pBuf =
924 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100925 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
926 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100927 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
928 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400929 }
930 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100931 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
932 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400933 }
934 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
935 //Fill RsvTime
936 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100937 struct vnt_rrv_time_ab *pBuf =
938 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100939 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
940 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400941 }
942 }
943 }
944 else if (byPktType == PK_TYPE_11B) {
945
946 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
947 //Fill RsvTime
948 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100949 struct vnt_rrv_time_ab *pBuf =
950 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100951 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
952 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100953 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
954 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400955 }
956 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100957 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
958 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400959 }
960 else { //RTS_needless, non PCF mode
961 //Fill RsvTime
962 if (pvRrvTime) {
Malcolm Priestley976467d2013-08-16 23:44:04 +0100963 struct vnt_rrv_time_ab *pBuf =
964 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100965 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
966 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400967 }
968 }
969 }
970 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
971}
972/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500973 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500974 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300975 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400976*/
977
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000978static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100979 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
980 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
981 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
982 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400983{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000984 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
985 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000986 u32 cb802_1_H_len;
987 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
988 u32 cbFCSlen = 4, cbMICHDR = 0;
989 int bNeedACK, bRTS;
990 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
991 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
992 u8 abySNAP_Bridgetunnel[ETH_ALEN]
993 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
994 u32 uDuration;
995 u32 cbHeaderLength = 0, uPadding = 0;
996 void *pvRrvTime;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100997 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000998 void *pvRTS;
999 void *pvCTS;
1000 void *pvTxDataHd;
1001 u8 byFBOption = AUTO_FB_NONE, byFragType;
1002 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +01001003 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001004 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -05001005 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -04001006
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001007 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -04001008
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001009 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -05001010 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1011 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +00001012 }
Forest Bond92b96792009-06-13 07:38:31 -04001013
Forest Bond92b96792009-06-13 07:38:31 -04001014 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -05001015 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -04001016 if (pDevice->dwDiagRefCount == 0) {
1017 cb802_1_H_len = 8;
1018 } else {
1019 cb802_1_H_len = 2;
1020 }
1021 } else {
1022 cb802_1_H_len = 0;
1023 }
1024
Charles Clément21ec51f2010-05-18 10:08:14 -07001025 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -04001026
1027 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -05001028 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001029
1030 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001031 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001032 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1033 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001034 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1035 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001036 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001037 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001038 pTxBufHead->wFIFOCtl =
1039 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1040 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001041 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001042 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1043 }
Forest Bond92b96792009-06-13 07:38:31 -04001044 }
1045 else {
1046 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001047 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001048 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1049 }
1050 } //if (pDevice->dwDiagRefCount != 0) {
1051
1052 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1053
1054 //Set FIFOCTL_LHEAD
1055 if (pDevice->bLongHeader)
1056 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1057
Forest Bond92b96792009-06-13 07:38:31 -04001058 //Set FRAGCTL_MACHDCNT
1059 if (pDevice->bLongHeader) {
1060 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1061 } else {
1062 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1063 }
Andres More3eaca0d2013-02-25 20:32:52 -05001064 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001065
1066 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001067 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001068 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1069 }
1070
1071 //Set Auto Fallback Ctl
1072 if (wCurrentRate >= RATE_18M) {
1073 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1074 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1075 byFBOption = AUTO_FB_0;
1076 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1077 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1078 byFBOption = AUTO_FB_1;
1079 }
1080 }
1081
Andres More4e9b5e22013-02-12 20:36:30 -05001082 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001083 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1084 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1085 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1086 }
1087 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1088 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1089 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1090 }
1091 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1092 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1093 }
1094 }
1095 }
1096
Forest Bond92b96792009-06-13 07:38:31 -04001097 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1098 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1099 cbIVlen = 4;
1100 cbICVlen = 4;
1101 }
1102 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1103 cbIVlen = 8;//IV+ExtIV
1104 cbMIClen = 8;
1105 cbICVlen = 4;
1106 }
1107 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1108 cbIVlen = 8;//RSN Header
1109 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001110 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001111 }
Andres Moree269fc22013-02-12 20:36:29 -05001112 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001113 //MAC Header should be padding 0 to DW alignment.
1114 uPadding = 4 - (cbMACHdLen%4);
1115 uPadding %= 4;
1116 }
1117 }
1118
1119 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1120
Andres Moree269fc22013-02-12 20:36:29 -05001121 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1122 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001123 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001124 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001125 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1126 }
1127
Andres Moreb902fbf2013-02-25 20:32:51 -05001128 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001129 wTxBufSize = sizeof(STxBufHead);
1130 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1131 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001132 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001133 pvRrvTime = (struct vnt_rrv_time_rts *)
1134 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001135 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001136 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001137 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001138 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001139 pvCTS = NULL;
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001140 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1141 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1142 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001143 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001144 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001145 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001146 }
1147 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001148 pvRrvTime = (struct vnt_rrv_time_cts *)
1149 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001150 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001151 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001152 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001153 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001154 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001155 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1156 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1157 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001158 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1159 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001160 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001161 }
1162 } else {
1163 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001164 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001165 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1166 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001167 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001168 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001169 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001170 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001171 pvCTS = NULL;
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001172 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1173 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1174 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001175 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1176 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001177 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001178 }
Andres Moree269fc22013-02-12 20:36:29 -05001179 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001180 pvRrvTime = (struct vnt_rrv_time_cts *)
1181 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001182 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001183 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001184 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001185 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001186 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001187 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001188 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1189 cbMICHDR + sizeof(struct vnt_cts_fb));
1190 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001191 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001192 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001193 }
1194 } // Auto Fall Back
1195 }
1196 else {//802.11a/b packet
1197 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001198 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001199 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1200 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001201 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001202 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001203 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001204 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001205 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001206 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1207 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001208 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001209 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1210 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001211 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001212 }
Andres Moree269fc22013-02-12 20:36:29 -05001213 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001214 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1215 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001216 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001217 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001218 pvRTS = NULL;
1219 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001220 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1221 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001222 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001223 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001224 }
1225 } else {
1226 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001227 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001228 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1229 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001230 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001231 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001232 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001233 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001234 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001235 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1236 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001237 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001238 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1239 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001240 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001241 }
Andres Moree269fc22013-02-12 20:36:29 -05001242 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001243 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1244 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001245 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001246 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001247 pvRTS = NULL;
1248 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001249 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1250 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001251 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001252 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001253 }
1254 } // Auto Fall Back
1255 }
1256
Andres Moreb902fbf2013-02-25 20:32:51 -05001257 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1258 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1259 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001260
Forest Bond92b96792009-06-13 07:38:31 -04001261 //=========================
1262 // No Fragmentation
1263 //=========================
1264 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1265 byFragType = FRAGCTL_NONFRAG;
1266 //uDMAIdx = TYPE_AC0DMA;
1267 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1268
Forest Bond92b96792009-06-13 07:38:31 -04001269 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001270 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1271 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001272 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1273 //Fill DataHead
1274 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001275 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001276 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001277 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001278 byFragType, uDMAIdx, 0);
1279
Andres More4e9b5e22013-02-12 20:36:30 -05001280 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001281 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001282 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001283 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001284
1285 if (pDevice->bEnableHostWEP) {
1286 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1287 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1288 }
1289 }
1290
1291 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001292 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001293 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001294 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1295 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001296 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001297 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001298 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001299 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001300 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001301 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001302 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001303 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001304 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001305
1306 }
1307
1308 }
1309
Forest Bond92b96792009-06-13 07:38:31 -04001310 if (pPacket != NULL) {
1311 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001312 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001313 (pPacket + ETH_HLEN),
1314 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001315 );
1316
1317 } else {
1318 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001319 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001320 }
1321
Andres More4e9b5e22013-02-12 20:36:30 -05001322 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001323
1324 ///////////////////////////////////////////////////////////////////
1325
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001326 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1327 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1328 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1329 }
Forest Bond92b96792009-06-13 07:38:31 -04001330 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001331 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1332 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001333 }
1334 else {
Andres More52a7e642013-02-25 20:32:53 -05001335 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1336 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001337 }
1338 // DO Software Michael
1339 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001340 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001341 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001342 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001343 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1344 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001345
1346 ///////////////////////////////////////////////////////////////////
1347
1348 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1349 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001350 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001351 //}
1352 //DBG_PRN_GRP12(("\n\n\n"));
1353
1354 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1355
Andres More52a7e642013-02-25 20:32:53 -05001356 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1357 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001358
1359 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1360 MIC_vUnInit();
1361
Andres More4e9b5e22013-02-12 20:36:30 -05001362 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001363 *pdwMIC_L = 0;
1364 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001365 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001366 }
1367 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1368 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1369 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1370 }
1371
Andres More4e9b5e22013-02-12 20:36:30 -05001372 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001373
Andres More3eaca0d2013-02-25 20:32:52 -05001374 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001375
Andres More4e9b5e22013-02-12 20:36:30 -05001376 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1377 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1378 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001379 cbFrameSize -= cbICVlen;
1380 }
1381
Forest Bond92b96792009-06-13 07:38:31 -04001382 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001383
1384 *pcbHeaderLen = cbHeaderLength;
1385 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1386
Forest Bond92b96792009-06-13 07:38:31 -04001387 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001388 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001389
Andres More4e9b5e22013-02-12 20:36:30 -05001390 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001391
1392}
1393
Forest Bond92b96792009-06-13 07:38:31 -04001394/*+
1395 *
1396 * Description:
1397 * Translate 802.3 to 802.11 header
1398 *
1399 * Parameters:
1400 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001401 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001402 * dwTxBufferAddr - Transmit Buffer
1403 * pPacket - Packet from upper layer
1404 * cbPacketSize - Transmit Data Length
1405 * Out:
1406 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1407 * pcbAppendPayload - size of append payload for 802.1H translation
1408 *
1409 * Return Value: none
1410 *
1411-*/
1412
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001413static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001414 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001415 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001416{
Andres More1cac4a42013-03-18 20:33:50 -05001417 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001418
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001419 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001420
1421 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001422 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001423 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001424 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001425 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1426 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001427 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001428 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001429 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001430 } else {
1431 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001432 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001433 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001434 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001435 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001436 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001437 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001438 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001439 &(pDevice->abyBSSID[0]),
1440 ETH_ALEN);
1441 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001442 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001443 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001444 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001445 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001446 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001447 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001448 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001449 &(pDevice->abyBSSID[0]),
1450 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001451 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001452 }
1453 }
1454
1455 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001456 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001457
Andres More1cac4a42013-03-18 20:33:50 -05001458 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001459
1460 if (pDevice->bLongHeader) {
1461 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001462 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001463 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001464 }
Andres More1cac4a42013-03-18 20:33:50 -05001465 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001466
1467 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001468 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001469
1470 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1471 pDevice->wSeqCounter++;
1472 if (pDevice->wSeqCounter > 0x0fff)
1473 pDevice->wSeqCounter = 0;
1474 }
1475
1476 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001477 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001478 }
1479}
1480
Forest Bond92b96792009-06-13 07:38:31 -04001481/*+
1482 *
1483 * Description:
1484 * Request instructs a MAC to transmit a 802.11 management packet through
1485 * the adapter onto the medium.
1486 *
1487 * Parameters:
1488 * In:
1489 * hDeviceContext - Pointer to the adapter
1490 * pPacket - A pointer to a descriptor for the packet to transmit
1491 * Out:
1492 * none
1493 *
Andres Moree269fc22013-02-12 20:36:29 -05001494 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001495 *
1496-*/
1497
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001498CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1499 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001500{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001501 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001502 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001503 PSTxBufHead pTxBufHead;
1504 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001505 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001506 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001507 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001508 u8 byPktType, *pbyTxBufferAddr;
1509 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1510 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001511 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001512 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1513 u32 uPadding = 0;
1514 u16 wTxBufSize;
1515 u32 cbMacHdLen;
1516 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001517
Forest Bond92b96792009-06-13 07:38:31 -04001518 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1519
1520 if (NULL == pContext) {
1521 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1522 return CMD_STATUS_RESOURCES;
1523 }
1524
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001525 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001526 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001527 cbFrameBodySize = pPacket->cbPayloadLen;
1528 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1529 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001530
1531 if (pDevice->byBBType == BB_TYPE_11A) {
1532 wCurrentRate = RATE_6M;
1533 byPktType = PK_TYPE_11A;
1534 } else {
1535 wCurrentRate = RATE_1M;
1536 byPktType = PK_TYPE_11B;
1537 }
1538
1539 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1540 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1541 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1542 // to set power here.
1543 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1544 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1545 } else {
1546 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1547 }
1548 pDevice->wCurrentRate = wCurrentRate;
1549
Forest Bond92b96792009-06-13 07:38:31 -04001550 //Set packet type
1551 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1552 pTxBufHead->wFIFOCtl = 0;
1553 }
1554 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1555 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1556 }
1557 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1558 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1559 }
1560 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1561 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1562 }
1563
1564 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1565 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1566
Andres More22040bb2010-08-02 20:21:44 -03001567 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001568 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001569 }
1570 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001571 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001572 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1573 };
1574
1575 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1576 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1577
1578 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1579 //Set Preamble type always long
1580 //pDevice->byPreambleType = PREAMBLE_LONG;
1581 // probe-response don't retry
1582 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001583 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001584 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1585 //}
1586 }
1587
1588 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1589
1590 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001591 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001592 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1593 } else {
1594 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1595 }
1596
1597 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001598 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001599
1600 // Notes:
1601 // Although spec says MMPDU can be fragmented; In most case,
1602 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001603 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001604
1605 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1606 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1607 cbIVlen = 4;
1608 cbICVlen = 4;
1609 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1610 }
1611 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1612 cbIVlen = 8;//IV+ExtIV
1613 cbMIClen = 8;
1614 cbICVlen = 4;
1615 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1616 //We need to get seed here for filling TxKey entry.
1617 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1618 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1619 }
1620 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1621 cbIVlen = 8;//RSN Header
1622 cbICVlen = 8;//MIC
1623 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001624 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001625 }
1626 //MAC Header should be padding 0 to DW alignment.
1627 uPadding = 4 - (cbMacHdLen%4);
1628 uPadding %= 4;
1629 }
1630
1631 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1632
1633 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001634 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001635 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1636 }
1637 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1638
1639 //Set RrvTime/RTS/CTS Buffer
1640 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1641
Malcolm Priestley4f990052013-08-16 23:38:57 +01001642 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001643 pMICHDR = NULL;
1644 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001645 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001646 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001647 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001648 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1649 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001650 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001651 }
1652 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001653 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001654 pMICHDR = NULL;
1655 pvRTS = NULL;
1656 pCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001657 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1658 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001659 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001660 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001661 }
1662
Andres Moreceb8c5d2013-03-18 20:33:49 -05001663 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001664 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1665 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001666 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001667 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1668 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001669 //=========================
1670 // No Fragmentation
1671 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001672 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001673
Forest Bond92b96792009-06-13 07:38:31 -04001674 //Fill FIFO,RrvTime,RTS,and CTS
1675 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1676 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1677
1678 //Fill DataHead
1679 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001680 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001681
Andres More1cac4a42013-03-18 20:33:50 -05001682 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001683
1684 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1685
1686 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001687 u8 * pbyIVHead;
1688 u8 * pbyPayloadHead;
1689 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001690 PSKeyItem pTransmitKey = NULL;
1691
Andres Moreb902fbf2013-02-25 20:32:51 -05001692 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1693 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001694 do {
1695 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001696 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001697 pbyBSSID = pDevice->abyBSSID;
1698 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001699 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001700 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001701 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001702 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1703 break;
1704 }
1705 } else {
1706 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1707 break;
1708 }
1709 }
1710 // get group key
1711 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001712 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001713 pTransmitKey = NULL;
1714 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1715 } else {
1716 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1717 }
Andres Moree269fc22013-02-12 20:36:29 -05001718 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001719 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001720 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001721 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001722
Jim Lieb3e362592009-08-12 14:54:11 -07001723 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001724 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001725 cbFrameBodySize);
1726 }
1727 else {
1728 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001729 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001730 }
1731
Andres More1cac4a42013-03-18 20:33:50 -05001732 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001733 pDevice->wSeqCounter++ ;
1734 if (pDevice->wSeqCounter > 0x0fff)
1735 pDevice->wSeqCounter = 0;
1736
1737 if (bIsPSPOLL) {
1738 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001739 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001740 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1741 // in the same place of other packet's Duration-field).
1742 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001743 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1744 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1745 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1746 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1747 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1748 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001749 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1750 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1751 }
Forest Bond92b96792009-06-13 07:38:31 -04001752 }
1753
Andres More3eaca0d2013-02-25 20:32:52 -05001754 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001755 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001756 pTX_Buffer->byType = 0x00;
1757
1758 pContext->pPacket = NULL;
1759 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001760 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001761
Andres More1cac4a42013-03-18 20:33:50 -05001762 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1763 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001764 }
1765 else {
Andres More1cac4a42013-03-18 20:33:50 -05001766 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001767 }
1768
1769 PIPEnsSendBulkOut(pDevice,pContext);
1770 return CMD_STATUS_PENDING;
1771}
1772
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001773CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1774 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001775{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001776 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001777 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1778 u32 cbHeaderSize = 0;
1779 u16 wTxBufSize = sizeof(STxShortBufHead);
1780 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001781 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001782 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001783 u16 wCurrentRate;
1784 u32 cbFrameBodySize;
1785 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001786 u8 *pbyTxBufferAddr;
1787 PUSB_SEND_CONTEXT pContext;
1788 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001789
Forest Bond92b96792009-06-13 07:38:31 -04001790 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1791 if (NULL == pContext) {
1792 status = CMD_STATUS_RESOURCES;
1793 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1794 return status ;
1795 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001796
1797 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001798 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001799
1800 cbFrameBodySize = pPacket->cbPayloadLen;
1801
1802 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1803 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001804
1805 if (pDevice->byBBType == BB_TYPE_11A) {
1806 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001807 pTxDataHead = (struct vnt_tx_datahead_ab *)
1808 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001809 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001810 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1811 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001812 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001813 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001814 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001815 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001816 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001817 } else {
1818 wCurrentRate = RATE_1M;
1819 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001820 pTxDataHead = (struct vnt_tx_datahead_ab *)
1821 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001822 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001823 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1824 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001825 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001826 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001827 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001828 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001829 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001830 }
1831
1832 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001833 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001834 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001835
Andres More1cac4a42013-03-18 20:33:50 -05001836 pMACHeader->duration_id = 0;
1837 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001838 pDevice->wSeqCounter++ ;
1839 if (pDevice->wSeqCounter > 0x0fff)
1840 pDevice->wSeqCounter = 0;
1841
1842 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1843
Andres More3eaca0d2013-02-25 20:32:52 -05001844 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001845 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001846 pTX_Buffer->byType = 0x01;
1847
1848 pContext->pPacket = NULL;
1849 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001850 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001851
1852 PIPEnsSendBulkOut(pDevice,pContext);
1853 return CMD_STATUS_PENDING;
1854
1855}
1856
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001857void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1858{
1859 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001860 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001861 u8 byPktType;
1862 u8 *pbyTxBufferAddr;
1863 void *pvRTS, *pvCTS, *pvTxDataHd;
1864 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001865 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001866 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001867 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001868 PSTxBufHead pTxBufHead;
1869 u32 cbFrameSize;
1870 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1871 u32 uPadding = 0;
1872 u32 cbMICHDR = 0, uLength = 0;
1873 u32 dwMICKey0, dwMICKey1;
1874 u32 dwMIC_Priority;
1875 u32 *pdwMIC_L, *pdwMIC_R;
1876 u16 wTxBufSize;
1877 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001878 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001879 void *pvRrvTime, *pMICHDR;
1880 u32 wCurrentRate = RATE_1M;
1881 PUWLAN_80211HDR p80211Header;
1882 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001883 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001884 SKeyItem STempKey;
1885 PSKeyItem pTransmitKey = NULL;
1886 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1887 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001888 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001889
Forest Bond92b96792009-06-13 07:38:31 -04001890 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1891
1892 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1893 cbFrameBodySize = 0;
1894 }
1895 else {
1896 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1897 }
1898 p80211Header = (PUWLAN_80211HDR)skb->data;
1899
1900 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1901
1902 if (NULL == pContext) {
1903 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1904 dev_kfree_skb_irq(skb);
1905 return ;
1906 }
1907
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001908 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001909 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001910 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1911 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001912
1913 if (pDevice->byBBType == BB_TYPE_11A) {
1914 wCurrentRate = RATE_6M;
1915 byPktType = PK_TYPE_11A;
1916 } else {
1917 wCurrentRate = RATE_1M;
1918 byPktType = PK_TYPE_11B;
1919 }
1920
1921 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1922 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1923 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1924 // to set power here.
1925 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1926 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1927 } else {
1928 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1929 }
1930
1931 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1932
1933 //Set packet type
1934 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1935 pTxBufHead->wFIFOCtl = 0;
1936 }
1937 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1938 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1939 }
1940 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1941 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1942 }
1943 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1944 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1945 }
1946
1947 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1948 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1949
Andres More22040bb2010-08-02 20:21:44 -03001950 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001951 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001952 if (pDevice->bEnableHostWEP) {
1953 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001954 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001955 }
Forest Bond92b96792009-06-13 07:38:31 -04001956 }
1957 else {
1958 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001959 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001960 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001961 }
Andres More4e9b5e22013-02-12 20:36:30 -05001962 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001963 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1964 };
1965
1966 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1967 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1968
1969 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1970 //Set Preamble type always long
1971 //pDevice->byPreambleType = PREAMBLE_LONG;
1972
1973 // probe-response don't retry
1974 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001975 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001976 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1977 //}
1978 }
1979
1980 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1981
1982 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001983 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001984 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1985 } else {
1986 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1987 }
1988
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001989 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001990 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1991
1992 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1993 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1994 }
1995
1996 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1997 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1998 }
1999
2000 if (cbExtSuppRate >0) {
2001 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2002 }
2003 }
2004
Forest Bond92b96792009-06-13 07:38:31 -04002005 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05002006 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04002007
2008 // Notes:
2009 // Although spec says MMPDU can be fragmented; In most case,
2010 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05002011 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04002012
Forest Bond92b96792009-06-13 07:38:31 -04002013 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2014 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2015 cbIVlen = 4;
2016 cbICVlen = 4;
2017 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2018 }
2019 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2020 cbIVlen = 8;//IV+ExtIV
2021 cbMIClen = 8;
2022 cbICVlen = 4;
2023 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2024 //We need to get seed here for filling TxKey entry.
2025 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2026 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2027 }
2028 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2029 cbIVlen = 8;//RSN Header
2030 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002031 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04002032 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002033 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002034 }
2035 //MAC Header should be padding 0 to DW alignment.
2036 uPadding = 4 - (cbMacHdLen%4);
2037 uPadding %= 4;
2038 }
2039
2040 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2041
2042 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002043 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002044 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2045 }
2046 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2047
Forest Bond92b96792009-06-13 07:38:31 -04002048 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002049 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002050 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002051 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002052 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002053 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002054 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002055 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2056 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002057 sizeof(struct vnt_cts));
2058 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002059 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002060
2061 }
2062 else {//802.11a/b packet
2063
Malcolm Priestley976467d2013-08-16 23:44:04 +01002064 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002065 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01002066 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002067 pvRTS = NULL;
2068 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01002069 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2070 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002071 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002072 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002073 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002074 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002075 &(p80211Header->sA3.abyAddr1[0]),
2076 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002077 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002078 &(p80211Header->sA3.abyAddr2[0]),
2079 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002080 //=========================
2081 // No Fragmentation
2082 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002083 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002084
Forest Bond92b96792009-06-13 07:38:31 -04002085 //Fill FIFO,RrvTime,RTS,and CTS
2086 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2087 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2088
2089 //Fill DataHead
2090 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002091 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002092
Andres More1cac4a42013-03-18 20:33:50 -05002093 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002094
2095 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2096
Andres Moreb902fbf2013-02-25 20:32:51 -05002097 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2098 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2099 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002100
2101 // Copy the Packet into a tx Buffer
2102 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2103
2104 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002105 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002106 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2107
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002108 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002109 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2110 if (cbExtSuppRate != 0) {
2111 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2112 memcpy((pbyPayloadHead + cbFrameBodySize),
2113 pMgmt->abyCurrSuppRates,
2114 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2115 );
2116 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2117 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2118 pMgmt->abyCurrExtSuppRates,
2119 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2120 );
2121 }
2122 }
2123
2124 // Set wep
2125 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2126
2127 if (pDevice->bEnableHostWEP) {
2128 pTransmitKey = &STempKey;
2129 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2130 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2131 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2132 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2133 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2134 memcpy(pTransmitKey->abyKey,
2135 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2136 pTransmitKey->uKeyLength
2137 );
2138 }
2139
2140 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2141
Andres More52a7e642013-02-25 20:32:53 -05002142 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2143 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002144
2145 // DO Software Michael
2146 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002147 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002148 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002149 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002150 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2151 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002152
2153 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2154
2155 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2156
Andres More52a7e642013-02-25 20:32:53 -05002157 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2158 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002159
2160 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2161 MIC_vUnInit();
2162
Andres More4e9b5e22013-02-12 20:36:30 -05002163 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002164 *pdwMIC_L = 0;
2165 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002166 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002167 }
2168
2169 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2170 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002171 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2172 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002173
2174 }
2175
Andres Moreb902fbf2013-02-25 20:32:51 -05002176 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002177 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002178
2179 if (pDevice->bEnableHostWEP) {
2180 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2181 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2182 }
2183
2184 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002185 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002186 }
2187 }
2188
Andres More1cac4a42013-03-18 20:33:50 -05002189 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002190 pDevice->wSeqCounter++ ;
2191 if (pDevice->wSeqCounter > 0x0fff)
2192 pDevice->wSeqCounter = 0;
2193
Forest Bond92b96792009-06-13 07:38:31 -04002194 if (bIsPSPOLL) {
2195 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2196 // of FIFO control header.
2197 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2198 // in the same place of other packet's Duration-field).
2199 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002200 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2201 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2202 cpu_to_le16(p80211Header->sA2.wDurationID);
2203 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2204 cpu_to_le16(p80211Header->sA2.wDurationID);
2205 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002206 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2207 cpu_to_le16(p80211Header->sA2.wDurationID);
2208 }
Forest Bond92b96792009-06-13 07:38:31 -04002209 }
2210
Andres More3eaca0d2013-02-25 20:32:52 -05002211 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002212 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002213 pTX_Buffer->byType = 0x00;
2214
2215 pContext->pPacket = skb;
2216 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002217 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002218
Andres More1cac4a42013-03-18 20:33:50 -05002219 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2220 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002221 }
2222 else {
Andres More1cac4a42013-03-18 20:33:50 -05002223 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002224 }
2225 PIPEnsSendBulkOut(pDevice,pContext);
2226 return ;
2227
2228}
2229
Forest Bond92b96792009-06-13 07:38:31 -04002230//TYPE_AC0DMA data tx
2231/*
2232 * Description:
2233 * Tx packet via AC0DMA(DMA1)
2234 *
2235 * Parameters:
2236 * In:
2237 * pDevice - Pointer to the adapter
2238 * skb - Pointer to tx skb packet
2239 * Out:
2240 * void
2241 *
2242 * Return Value: NULL
2243 */
2244
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002245int nsDMA_tx_packet(struct vnt_private *pDevice,
2246 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002247{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002248 struct net_device_stats *pStats = &pDevice->stats;
2249 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002250 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002251 u32 BytesToWrite = 0, uHeaderLen = 0;
2252 u32 uNodeIndex = 0;
2253 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2254 u16 wAID;
2255 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002256 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002257 PSKeyItem pTransmitKey = NULL;
2258 SKeyItem STempKey;
2259 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002260 int bTKIP_UseGTK = false;
2261 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002262 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002263 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002264 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002265 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002266 u32 status;
2267 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002268 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002269
Forest Bond92b96792009-06-13 07:38:31 -04002270 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2271
2272 if (pDevice->uAssocCount == 0) {
2273 dev_kfree_skb_irq(skb);
2274 return 0;
2275 }
2276
Andres Moreb902fbf2013-02-25 20:32:51 -05002277 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002278 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002279 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002280 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2281
2282 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2283 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2284 // set tx map
2285 pMgmt->abyPSTxMap[0] |= byMask[0];
2286 return 0;
2287 }
Masanari Iida93184692012-08-13 21:21:50 +09002288 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002289
2290 if (pDevice->byBBType != BB_TYPE_11A)
2291 pDevice->wCurrentRate = RATE_2M;
2292 else
2293 pDevice->wCurrentRate = RATE_24M;
2294 // long preamble type
2295 pDevice->byPreambleType = PREAMBLE_SHORT;
2296
2297 }else {
2298
Andres Moreb902fbf2013-02-25 20:32:51 -05002299 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002300
2301 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2302
2303 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2304
2305 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2306 // set tx map
2307 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2308 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2309 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2310 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2311
2312 return 0;
2313 }
2314 // AP rate decided from node
2315 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2316 // tx preamble decided from node
2317
2318 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2319 pDevice->byPreambleType = pDevice->byShortPreamble;
2320
2321 }else {
2322 pDevice->byPreambleType = PREAMBLE_LONG;
2323 }
Andres More4e9b5e22013-02-12 20:36:30 -05002324 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002325 }
2326 }
2327
Andres Moree269fc22013-02-12 20:36:29 -05002328 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002329 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2330 dev_kfree_skb_irq(skb);
2331 return 0;
2332 }
2333 }
2334
2335 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2336
2337 if (pContext == NULL) {
2338 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2339 dev_kfree_skb_irq(skb);
2340 return STATUS_RESOURCES;
2341 }
2342
Andres Moreceb8c5d2013-03-18 20:33:49 -05002343 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002344
2345//mike add:station mode check eapol-key challenge--->
2346{
Andres Moreb902fbf2013-02-25 20:32:51 -05002347 u8 Protocol_Version; //802.1x Authentication
2348 u8 Packet_Type; //802.1x Authentication
2349 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002350 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002351
Charles Clément21ec51f2010-05-18 10:08:14 -07002352 Protocol_Version = skb->data[ETH_HLEN];
2353 Packet_Type = skb->data[ETH_HLEN+1];
2354 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2355 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 -05002356 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002357 /* 802.1x OR eapol-key challenge frame transfer */
2358 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2359 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002360 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002361 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2362 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2363 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002364 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002365 PRINT_K("WPA ");
2366 }
2367 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002368 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002369 PRINT_K("WPA2(re-keying) ");
2370 }
2371 PRINT_K("Authentication completed!!\n");
2372 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002373 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002374 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002375 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002376 PRINT_K("WPA2 Authentication completed!!\n");
2377 }
2378 }
2379 }
2380}
2381//mike add:station mode check eapol-key challenge<---
2382
Andres More4e9b5e22013-02-12 20:36:30 -05002383 if (pDevice->bEncryptionEnable == true) {
2384 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002385 // get Transmit key
2386 do {
2387 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2388 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2389 pbyBSSID = pDevice->abyBSSID;
2390 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002391 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002392 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002393 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2394 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002395 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2396 break;
2397 }
2398 } else {
2399 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2400 break;
2401 }
2402 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002403 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2404 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2406 for (ii = 0; ii< 6; ii++)
2407 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2409
2410 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002411 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002412 break;
2413 }
2414 // get group key
2415 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002416 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002417 pTransmitKey = NULL;
2418 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2419 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2420 }
2421 else
2422 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2423 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002424 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002425 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2426 }
Andres Moree269fc22013-02-12 20:36:29 -05002427 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002428 }
2429
2430 if (pDevice->bEnableHostWEP) {
2431 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002432 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002433 pTransmitKey = &STempKey;
2434 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2435 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2436 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2437 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2438 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2439 memcpy(pTransmitKey->abyKey,
2440 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2441 pTransmitKey->uKeyLength
2442 );
2443 }
2444 }
2445
Andres Moreb902fbf2013-02-25 20:32:51 -05002446 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002447
2448 if (pDevice->bFixRate) {
2449 if (pDevice->byBBType == BB_TYPE_11B) {
2450 if (pDevice->uConnectionRate >= RATE_11M) {
2451 pDevice->wCurrentRate = RATE_11M;
2452 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002453 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002454 }
2455 } else {
2456 if ((pDevice->byBBType == BB_TYPE_11A) &&
2457 (pDevice->uConnectionRate <= RATE_6M)) {
2458 pDevice->wCurrentRate = RATE_6M;
2459 } else {
2460 if (pDevice->uConnectionRate >= RATE_54M)
2461 pDevice->wCurrentRate = RATE_54M;
2462 else
Andres More3eaca0d2013-02-25 20:32:52 -05002463 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002464 }
2465 }
2466 }
2467 else {
2468 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2469 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002470 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002471 // Multicast use highest data rate
2472 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2473 // preamble type
2474 pDevice->byPreambleType = pDevice->byShortPreamble;
2475 }
2476 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002477 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002478 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2479 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2480 pDevice->byPreambleType = pDevice->byShortPreamble;
2481
2482 }
2483 else {
2484 pDevice->byPreambleType = PREAMBLE_LONG;
2485 }
2486 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2487 }
2488 else {
2489 if (pDevice->byBBType != BB_TYPE_11A)
2490 pDevice->wCurrentRate = RATE_2M;
2491 else
2492 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2493 // abyCurrExtSuppRates[]
2494 pDevice->byPreambleType = PREAMBLE_SHORT;
2495 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2496 }
2497 }
2498 }
2499 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2500 // Infra STA rate decided from AP Node, index = 0
2501 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2502 }
2503 }
2504
Andres Moreceb8c5d2013-03-18 20:33:49 -05002505 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002506 if (pDevice->byBBType != BB_TYPE_11A) {
2507 pDevice->wCurrentRate = RATE_1M;
2508 pDevice->byACKRate = RATE_1M;
2509 pDevice->byTopCCKBasicRate = RATE_1M;
2510 pDevice->byTopOFDMBasicRate = RATE_6M;
2511 } else {
2512 pDevice->wCurrentRate = RATE_6M;
2513 pDevice->byACKRate = RATE_6M;
2514 pDevice->byTopCCKBasicRate = RATE_1M;
2515 pDevice->byTopOFDMBasicRate = RATE_6M;
2516 }
2517 }
Forest Bond92b96792009-06-13 07:38:31 -04002518
Andres More0cbd8d92010-05-06 20:34:29 -03002519 DBG_PRT(MSG_LEVEL_DEBUG,
2520 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2521 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002522
2523 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002524 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002525 }
2526
2527 if (pDevice->wCurrentRate <= RATE_11M) {
2528 byPktType = PK_TYPE_11B;
2529 }
2530
Andres More4e9b5e22013-02-12 20:36:30 -05002531 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002532 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2533 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002534 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002535 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002536 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2537 if (pTransmitKey == NULL) {
2538 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2539 }
2540 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002541 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002542 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2543 }
2544 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2546 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002547 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002548 }
2549 }
2550 }
2551
Forest Bond92b96792009-06-13 07:38:31 -04002552 if (pDevice->bEnableHostWEP) {
2553 if ((uNodeIndex != 0) &&
2554 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002555 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2556 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002557 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002558 }
2559 }
2560 }
2561 else {
2562
Forest Bond92b96792009-06-13 07:38:31 -04002563 if (pTransmitKey == NULL) {
2564 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002565 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002566 dev_kfree_skb_irq(skb);
2567 pStats->tx_dropped++;
2568 return STATUS_FAILURE;
2569 }
Forest Bond92b96792009-06-13 07:38:31 -04002570 }
2571 }
2572
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002573 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2574
Forest Bond92b96792009-06-13 07:38:31 -04002575 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002576 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002577 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002578 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002579 pDevice->wCurrentRate,
2580 &uHeaderLen, &BytesToWrite
2581 );
2582
Andres Moree269fc22013-02-12 20:36:29 -05002583 if (fConvertedPacket == false) {
2584 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002585 dev_kfree_skb_irq(skb);
2586 return STATUS_FAILURE;
2587 }
2588
Andres More4e9b5e22013-02-12 20:36:30 -05002589 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002590 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002591 bScheduleCommand((void *) pDevice,
2592 WLAN_CMD_MAC_DISPOWERSAVING,
2593 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002594 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002595 }
2596 }
2597
Andres Moreb902fbf2013-02-25 20:32:51 -05002598 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002599 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002600
2601 pContext->pPacket = skb;
2602 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002603 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002604
Andres Moreceb8c5d2013-03-18 20:33:49 -05002605 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 -04002606
2607 status = PIPEnsSendBulkOut(pDevice,pContext);
2608
Andres More4e9b5e22013-02-12 20:36:30 -05002609 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002610 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002611
Andres Moreb902fbf2013-02-25 20:32:51 -05002612 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002613 }
2614
2615 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002616 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002617 dev_kfree_skb_irq(skb);
2618 return STATUS_FAILURE;
2619 }
2620 else
2621 return 0;
2622
2623}
2624
Forest Bond92b96792009-06-13 07:38:31 -04002625/*
2626 * Description:
2627 * Relay packet send (AC1DMA) from rx dpc.
2628 *
2629 * Parameters:
2630 * In:
2631 * pDevice - Pointer to the adapter
2632 * pPacket - Pointer to rx packet
2633 * cbPacketSize - rx ethernet frame size
2634 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002635 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002636 *
Andres More4e9b5e22013-02-12 20:36:30 -05002637 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002638 */
2639
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002640int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2641 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002642{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002643 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002644 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002645 u32 BytesToWrite = 0, uHeaderLen = 0;
2646 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002647 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002648 SKeyItem STempKey;
2649 PSKeyItem pTransmitKey = NULL;
2650 u8 *pbyBSSID;
2651 PUSB_SEND_CONTEXT pContext;
2652 u8 byPktTyp;
2653 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002654 u32 status;
2655 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002656
Forest Bond92b96792009-06-13 07:38:31 -04002657 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2658
2659 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002660 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002661 }
2662
Andres Moreceb8c5d2013-03-18 20:33:49 -05002663 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002664
Andres More4e9b5e22013-02-12 20:36:30 -05002665 if (pDevice->bEncryptionEnable == true) {
2666 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002667 // get group key
2668 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002669 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002670 pTransmitKey = NULL;
2671 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2672 } else {
2673 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2674 }
2675 }
2676
2677 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002678 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002679 pTransmitKey = &STempKey;
2680 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2681 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2682 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2683 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2684 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2685 memcpy(pTransmitKey->abyKey,
2686 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2687 pTransmitKey->uKeyLength
2688 );
2689 }
2690 }
2691
2692 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002693 pContext->bBoolInUse = false;
2694 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002695 }
2696
Andres Moreb902fbf2013-02-25 20:32:51 -05002697 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002698
2699 if (pDevice->bFixRate) {
2700 if (pDevice->byBBType == BB_TYPE_11B) {
2701 if (pDevice->uConnectionRate >= RATE_11M) {
2702 pDevice->wCurrentRate = RATE_11M;
2703 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002704 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002705 }
2706 } else {
2707 if ((pDevice->byBBType == BB_TYPE_11A) &&
2708 (pDevice->uConnectionRate <= RATE_6M)) {
2709 pDevice->wCurrentRate = RATE_6M;
2710 } else {
2711 if (pDevice->uConnectionRate >= RATE_54M)
2712 pDevice->wCurrentRate = RATE_54M;
2713 else
Andres More3eaca0d2013-02-25 20:32:52 -05002714 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002715 }
2716 }
2717 }
2718 else {
2719 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2720 }
2721
Forest Bond92b96792009-06-13 07:38:31 -04002722 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002723 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002724 }
2725
2726 if (pDevice->wCurrentRate <= RATE_11M)
2727 byPktType = PK_TYPE_11B;
2728
Andres Moreabad19d2010-07-12 16:28:32 -03002729 BytesToWrite = uDataLen + ETH_FCS_LEN;
2730
Forest Bond92b96792009-06-13 07:38:31 -04002731 // Convert the packet to an usb frame and copy into our buffer
2732 // and send the irp.
2733
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002734 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2735
Forest Bond92b96792009-06-13 07:38:31 -04002736 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002737 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002738 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2739 pbySkbData, pTransmitKey, uNodeIndex,
2740 pDevice->wCurrentRate,
2741 &uHeaderLen, &BytesToWrite
2742 );
2743
Andres Moree269fc22013-02-12 20:36:29 -05002744 if (fConvertedPacket == false) {
2745 pContext->bBoolInUse = false;
2746 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002747 }
2748
Andres Moreb902fbf2013-02-25 20:32:51 -05002749 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002750 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002751
2752 pContext->pPacket = NULL;
2753 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002754 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002755
Andres Moreceb8c5d2013-03-18 20:33:49 -05002756 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 -04002757
2758 status = PIPEnsSendBulkOut(pDevice,pContext);
2759
Andres More4e9b5e22013-02-12 20:36:30 -05002760 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002761}
2762