blob: 07854316ca5938abc835d8f88940df48d358d328 [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,
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100129 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 Priestley5e67ee42013-08-26 11:04:50 +0100598static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
599 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
600 u16 duration)
601{
602 rts->duration = duration;
603 rts->frame_control = TYPE_CTL_RTS;
604
605 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
606 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
607 else
608 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
609
610 if (priv->eOPMode == OP_MODE_AP)
611 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
612 else
613 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
614
615 return 0;
616}
617
618static int vnt_rxtx_rts_g_head(struct vnt_private *priv,
619 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
620 u8 pkt_type, u32 frame_len, int need_ack,
621 u16 current_rate, u8 fb_option)
622{
623 u16 rts_frame_len = 20;
624
625 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
626 PK_TYPE_11B, &buf->b);
627 BBvCalculateParameter(priv, rts_frame_len,
628 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
629
630 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
631 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
632 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
633 pkt_type, current_rate, need_ack, fb_option);
634 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
635 pkt_type, current_rate, need_ack, fb_option);
636
637 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
638
639 return 0;
640}
641
Malcolm Priestleyec917132013-08-26 11:07:46 +0100642static int vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
643 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
644 u8 pkt_type, u32 frame_len, int need_ack,
645 u16 current_rate, u8 fb_option)
646{
647 u16 rts_frame_len = 20;
648
649 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
650 PK_TYPE_11B, &buf->b);
651 BBvCalculateParameter(priv, rts_frame_len,
652 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
653
654
655 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
656 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
657 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
658 pkt_type, current_rate, need_ack, fb_option);
659 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
660 pkt_type, current_rate, need_ack, fb_option);
661
662
663 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
664 frame_len, pkt_type, current_rate, need_ack, fb_option);
665 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
666 frame_len, pkt_type, current_rate, need_ack, fb_option);
667 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
668 frame_len, pkt_type, current_rate, need_ack, fb_option);
669 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
670 frame_len, pkt_type, current_rate, need_ack, fb_option);
671
672 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
673
674 return 0;
675}
676
Malcolm Priestley17126332013-08-26 11:09:38 +0100677static int vnt_rxtx_rts_ab_head(struct vnt_private *priv,
678 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
679 u8 pkt_type, u32 frame_len, int need_ack,
680 u16 current_rate, u8 fb_option)
681{
682 u16 rts_frame_len = 20;
683
684 BBvCalculateParameter(priv, rts_frame_len,
685 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
686
687 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
688 pkt_type, current_rate, need_ack, fb_option);
689
690 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
691
692 return 0;
693}
694
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100695static int vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
696 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
697 u8 pkt_type, u32 frame_len, int need_ack,
698 u16 current_rate, u8 fb_option)
699{
700 u16 rts_frame_len = 20;
701
702 BBvCalculateParameter(priv, rts_frame_len,
703 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
704
705 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
706 pkt_type, current_rate, need_ack, fb_option);
707
708 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
709 frame_len, pkt_type, current_rate, need_ack, fb_option);
710
711 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
712 frame_len, pkt_type, current_rate, need_ack, fb_option);
713
714 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
715
716 return 0;
717}
718
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000719static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100720 void *pvRTS, u32 cbFrameLength, int bNeedAck,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500721 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400722{
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100723 union vnt_tx_data_head *head = pvRTS;
Forest Bond92b96792009-06-13 07:38:31 -0400724
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100725 if (!head)
726 return;
Forest Bond92b96792009-06-13 07:38:31 -0400727
Masanari Iida93184692012-08-13 21:21:50 +0900728 // 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 -0400729 // Otherwise, we need to modified codes for them.
730 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
731 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100732 vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100733 psEthHeader, byPktType, cbFrameLength,
734 bNeedAck, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400735 }
736 else {
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100737 vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100738 psEthHeader, byPktType, cbFrameLength,
739 bNeedAck, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400740 } // if (byFBOption == AUTO_FB_NONE)
741 }
742 else if (byPktType == PK_TYPE_11A) {
743 if (byFBOption == AUTO_FB_NONE) {
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100744 vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100745 psEthHeader, byPktType, cbFrameLength,
746 bNeedAck, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400747 }
748 else {
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100749 vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
Malcolm Priestley9d2578c2013-08-26 11:12:00 +0100750 psEthHeader, byPktType, cbFrameLength,
751 bNeedAck, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400752 }
753 }
754 else if (byPktType == PK_TYPE_11B) {
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100755 vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100756 psEthHeader, byPktType, cbFrameLength,
757 bNeedAck, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400758 }
759}
760
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000761static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
762 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100763 u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400764{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000765 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400766
767 if (pvCTS == NULL) {
768 return;
769 }
770
Forest Bond92b96792009-06-13 07:38:31 -0400771 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100772 if (byFBOption != AUTO_FB_NONE) {
773 /* Auto Fall back */
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100774 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100775 /* Get SignalField,ServiceField,Length */
776 BBvCalculateParameter(pDevice, uCTSFrameLen,
777 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100778 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
779 cbFrameLength, byPktType,
780 wCurrentRate, bNeedAck, byFBOption);
781 /* Get CTSDuration_ba_f0 */
782 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
783 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
784 bNeedAck, byFBOption);
785 /* Get CTSDuration_ba_f1 */
786 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
787 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
788 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100789 /* Get CTS Frame body */
790 pBuf->data.duration = pBuf->wDuration_ba;
791 pBuf->data.frame_control = TYPE_CTL_CTS;
792 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100793 } else {
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100794 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100795 /* Get SignalField,ServiceField,Length */
796 BBvCalculateParameter(pDevice, uCTSFrameLen,
797 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100798 /* Get CTSDuration_ba */
799 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
800 CTSDUR_BA, cbFrameLength, byPktType,
801 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100802 /*Get CTS Frame body*/
803 pBuf->data.duration = pBuf->wDuration_ba;
804 pBuf->data.frame_control = TYPE_CTL_CTS;
805 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400806 }
807 }
808}
809
Forest Bond92b96792009-06-13 07:38:31 -0400810/*+
811 *
812 * Description:
813 * Generate FIFO control for MAC & Baseband controller
814 *
815 * Parameters:
816 * In:
817 * pDevice - Pointer to adpater
818 * pTxDataHead - Transmit Data Buffer
819 * pTxBufHead - pTxBufHead
820 * pvRrvTime - pvRrvTime
821 * pvRTS - RTS Buffer
822 * pCTS - CTS Buffer
823 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
824 * bNeedACK - If need ACK
825 * uDMAIdx - DMA Index
826 * Out:
827 * none
828 *
829 * Return Value: none
830 *
831-*/
Andres Morecc856e62010-05-17 21:34:01 -0300832
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000833static void s_vGenerateTxParameter(struct vnt_private *pDevice,
834 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
835 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500836 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400837{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000838 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
839 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000840 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400841
842 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
843 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
844 pFifoHead->wReserved = wCurrentRate;
845 wFifoCtl = pFifoHead->wFIFOCtl;
846
Forest Bond92b96792009-06-13 07:38:31 -0400847 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
848 byFBOption = AUTO_FB_0;
849 }
850 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
851 byFBOption = AUTO_FB_1;
852 }
853
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100854 if (!pvRrvTime)
855 return;
856
Forest Bond92b96792009-06-13 07:38:31 -0400857 if (pDevice->bLongHeader)
858 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
859
860 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
861
862 if (pvRTS != NULL) { //RTS_need
863 //Fill RsvTime
Malcolm Priestley6398a592013-08-16 21:26:55 +0100864 struct vnt_rrv_time_rts *pBuf =
865 (struct vnt_rrv_time_rts *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100866 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
867 byPktType, cbFrameSize, wCurrentRate);
868 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
869 byPktType, cbFrameSize, wCurrentRate);
870 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
871 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100872 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
873 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
874 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
875 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
876 bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400877 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100878 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
879 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400880 }
881 else {//RTS_needless, PCF mode
Forest Bond92b96792009-06-13 07:38:31 -0400882 //Fill RsvTime
Malcolm Priestley4f990052013-08-16 23:38:57 +0100883 struct vnt_rrv_time_cts *pBuf =
884 (struct vnt_rrv_time_cts *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100885 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
886 cbFrameSize, wCurrentRate, bNeedACK);
887 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
888 PK_TYPE_11B, cbFrameSize,
889 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100890 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
891 byPktType, cbFrameSize, wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400892 //Fill CTS
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100893 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize,
894 bNeedACK, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400895 }
896 }
897 else if (byPktType == PK_TYPE_11A) {
898
899 if (pvRTS != NULL) {//RTS_need, non PCF mode
900 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100901 struct vnt_rrv_time_ab *pBuf =
902 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100903 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
904 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100905 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
906 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400907 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100908 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
909 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400910 }
911 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
912 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100913 struct vnt_rrv_time_ab *pBuf =
914 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100915 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
916 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400917 }
918 }
919 else if (byPktType == PK_TYPE_11B) {
920
921 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
922 //Fill RsvTime
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, 0,
926 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100927 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
928 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400929 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100930 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
931 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400932 }
933 else { //RTS_needless, non PCF mode
934 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100935 struct vnt_rrv_time_ab *pBuf =
936 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100937 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
938 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400939 }
940 }
941 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
942}
943/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500944 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500945 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300946 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400947*/
948
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000949static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100950 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
951 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
952 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
953 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400954{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000955 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
956 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000957 u32 cb802_1_H_len;
958 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
959 u32 cbFCSlen = 4, cbMICHDR = 0;
960 int bNeedACK, bRTS;
961 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
962 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
963 u8 abySNAP_Bridgetunnel[ETH_ALEN]
964 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
965 u32 uDuration;
966 u32 cbHeaderLength = 0, uPadding = 0;
967 void *pvRrvTime;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100968 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000969 void *pvRTS;
970 void *pvCTS;
971 void *pvTxDataHd;
972 u8 byFBOption = AUTO_FB_NONE, byFragType;
973 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100974 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000975 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500976 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -0400977
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000978 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400979
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000980 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500981 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
982 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000983 }
Forest Bond92b96792009-06-13 07:38:31 -0400984
Forest Bond92b96792009-06-13 07:38:31 -0400985 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -0500986 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -0400987 if (pDevice->dwDiagRefCount == 0) {
988 cb802_1_H_len = 8;
989 } else {
990 cb802_1_H_len = 2;
991 }
992 } else {
993 cb802_1_H_len = 0;
994 }
995
Charles Clément21ec51f2010-05-18 10:08:14 -0700996 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400997
998 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500999 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -04001000
1001 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001002 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001003 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1004 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001005 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1006 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001007 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001008 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001009 pTxBufHead->wFIFOCtl =
1010 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1011 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001012 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001013 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1014 }
Forest Bond92b96792009-06-13 07:38:31 -04001015 }
1016 else {
1017 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001018 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001019 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1020 }
1021 } //if (pDevice->dwDiagRefCount != 0) {
1022
1023 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1024
1025 //Set FIFOCTL_LHEAD
1026 if (pDevice->bLongHeader)
1027 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1028
Forest Bond92b96792009-06-13 07:38:31 -04001029 //Set FRAGCTL_MACHDCNT
1030 if (pDevice->bLongHeader) {
1031 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1032 } else {
1033 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1034 }
Andres More3eaca0d2013-02-25 20:32:52 -05001035 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001036
1037 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001038 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001039 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1040 }
1041
1042 //Set Auto Fallback Ctl
1043 if (wCurrentRate >= RATE_18M) {
1044 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1045 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1046 byFBOption = AUTO_FB_0;
1047 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1048 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1049 byFBOption = AUTO_FB_1;
1050 }
1051 }
1052
Andres More4e9b5e22013-02-12 20:36:30 -05001053 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001054 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1055 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1056 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1057 }
1058 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1059 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1060 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1061 }
1062 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1063 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1064 }
1065 }
1066 }
1067
Forest Bond92b96792009-06-13 07:38:31 -04001068 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1069 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1070 cbIVlen = 4;
1071 cbICVlen = 4;
1072 }
1073 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1074 cbIVlen = 8;//IV+ExtIV
1075 cbMIClen = 8;
1076 cbICVlen = 4;
1077 }
1078 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1079 cbIVlen = 8;//RSN Header
1080 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001081 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001082 }
Andres Moree269fc22013-02-12 20:36:29 -05001083 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001084 //MAC Header should be padding 0 to DW alignment.
1085 uPadding = 4 - (cbMACHdLen%4);
1086 uPadding %= 4;
1087 }
1088 }
1089
1090 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1091
Andres Moree269fc22013-02-12 20:36:29 -05001092 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1093 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001094 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001095 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001096 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1097 }
1098
Andres Moreb902fbf2013-02-25 20:32:51 -05001099 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001100 wTxBufSize = sizeof(STxBufHead);
1101 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1102 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001103 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001104 pvRrvTime = (struct vnt_rrv_time_rts *)
1105 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001106 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001107 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001108 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001109 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001110 pvCTS = NULL;
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001111 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1112 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1113 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001114 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001115 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001116 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001117 }
1118 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001119 pvRrvTime = (struct vnt_rrv_time_cts *)
1120 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001121 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001122 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001123 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001124 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001125 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001126 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1127 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1128 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001129 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1130 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001131 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001132 }
1133 } else {
1134 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001135 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001136 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1137 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001138 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001139 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001140 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001141 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001142 pvCTS = NULL;
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001143 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1144 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1145 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001146 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1147 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001148 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001149 }
Andres Moree269fc22013-02-12 20:36:29 -05001150 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001151 pvRrvTime = (struct vnt_rrv_time_cts *)
1152 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001153 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001154 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001155 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001156 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001157 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001158 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001159 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1160 cbMICHDR + sizeof(struct vnt_cts_fb));
1161 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001162 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001163 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001164 }
1165 } // Auto Fall Back
1166 }
1167 else {//802.11a/b packet
1168 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001169 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001170 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1171 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001172 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001173 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001174 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001175 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001176 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001177 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1178 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001179 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001180 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1181 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001182 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001183 }
Andres Moree269fc22013-02-12 20:36:29 -05001184 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001185 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1186 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001187 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001188 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001189 pvRTS = NULL;
1190 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001191 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1192 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001193 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001194 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001195 }
1196 } else {
1197 // Auto Fall Back
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_a_fb *) (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 Priestley1da4ee22013-08-16 23:51:38 +01001206 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1207 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001208 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001209 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1210 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001211 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001212 }
Andres Moree269fc22013-02-12 20:36:29 -05001213 else if (bRTS == false) { //RTS_needless
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 Priestley1da4ee22013-08-16 23:51:38 +01001220 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(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 Priestley1da4ee22013-08-16 23:51:38 +01001223 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001224 }
1225 } // Auto Fall Back
1226 }
1227
Andres Moreb902fbf2013-02-25 20:32:51 -05001228 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1229 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1230 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001231
Forest Bond92b96792009-06-13 07:38:31 -04001232 //=========================
1233 // No Fragmentation
1234 //=========================
1235 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1236 byFragType = FRAGCTL_NONFRAG;
1237 //uDMAIdx = TYPE_AC0DMA;
1238 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1239
Forest Bond92b96792009-06-13 07:38:31 -04001240 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001241 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1242 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001243 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1244 //Fill DataHead
1245 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001246 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001247 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001248 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001249 byFragType, uDMAIdx, 0);
1250
Andres More4e9b5e22013-02-12 20:36:30 -05001251 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001252 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001253 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001254 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001255
1256 if (pDevice->bEnableHostWEP) {
1257 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1258 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1259 }
1260 }
1261
1262 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001263 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001264 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001265 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1266 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001267 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001268 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001269 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001270 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001271 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001272 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001273 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001274 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001275 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001276
1277 }
1278
1279 }
1280
Forest Bond92b96792009-06-13 07:38:31 -04001281 if (pPacket != NULL) {
1282 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001283 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001284 (pPacket + ETH_HLEN),
1285 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001286 );
1287
1288 } else {
1289 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001290 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001291 }
1292
Andres More4e9b5e22013-02-12 20:36:30 -05001293 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001294
1295 ///////////////////////////////////////////////////////////////////
1296
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001297 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1298 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1299 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1300 }
Forest Bond92b96792009-06-13 07:38:31 -04001301 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001302 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1303 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001304 }
1305 else {
Andres More52a7e642013-02-25 20:32:53 -05001306 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1307 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001308 }
1309 // DO Software Michael
1310 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001311 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001312 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001313 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001314 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1315 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001316
1317 ///////////////////////////////////////////////////////////////////
1318
1319 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1320 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001321 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001322 //}
1323 //DBG_PRN_GRP12(("\n\n\n"));
1324
1325 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1326
Andres More52a7e642013-02-25 20:32:53 -05001327 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1328 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001329
1330 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1331 MIC_vUnInit();
1332
Andres More4e9b5e22013-02-12 20:36:30 -05001333 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001334 *pdwMIC_L = 0;
1335 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001336 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001337 }
1338 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1339 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1340 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1341 }
1342
Andres More4e9b5e22013-02-12 20:36:30 -05001343 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001344
Andres More3eaca0d2013-02-25 20:32:52 -05001345 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001346
Andres More4e9b5e22013-02-12 20:36:30 -05001347 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1348 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1349 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001350 cbFrameSize -= cbICVlen;
1351 }
1352
Forest Bond92b96792009-06-13 07:38:31 -04001353 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001354
1355 *pcbHeaderLen = cbHeaderLength;
1356 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1357
Forest Bond92b96792009-06-13 07:38:31 -04001358 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001359 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001360
Andres More4e9b5e22013-02-12 20:36:30 -05001361 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001362
1363}
1364
Forest Bond92b96792009-06-13 07:38:31 -04001365/*+
1366 *
1367 * Description:
1368 * Translate 802.3 to 802.11 header
1369 *
1370 * Parameters:
1371 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001372 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001373 * dwTxBufferAddr - Transmit Buffer
1374 * pPacket - Packet from upper layer
1375 * cbPacketSize - Transmit Data Length
1376 * Out:
1377 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1378 * pcbAppendPayload - size of append payload for 802.1H translation
1379 *
1380 * Return Value: none
1381 *
1382-*/
1383
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001384static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001385 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001386 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001387{
Andres More1cac4a42013-03-18 20:33:50 -05001388 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001389
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001390 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001391
1392 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001393 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001394 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001395 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001396 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1397 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001398 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001399 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001400 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001401 } else {
1402 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001403 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001404 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001405 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001406 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001407 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001408 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001409 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001410 &(pDevice->abyBSSID[0]),
1411 ETH_ALEN);
1412 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001413 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001414 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001415 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001416 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001417 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001418 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001419 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001420 &(pDevice->abyBSSID[0]),
1421 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001422 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001423 }
1424 }
1425
1426 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001427 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001428
Andres More1cac4a42013-03-18 20:33:50 -05001429 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001430
1431 if (pDevice->bLongHeader) {
1432 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001433 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001434 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001435 }
Andres More1cac4a42013-03-18 20:33:50 -05001436 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001437
1438 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001439 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001440
1441 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1442 pDevice->wSeqCounter++;
1443 if (pDevice->wSeqCounter > 0x0fff)
1444 pDevice->wSeqCounter = 0;
1445 }
1446
1447 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001448 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001449 }
1450}
1451
Forest Bond92b96792009-06-13 07:38:31 -04001452/*+
1453 *
1454 * Description:
1455 * Request instructs a MAC to transmit a 802.11 management packet through
1456 * the adapter onto the medium.
1457 *
1458 * Parameters:
1459 * In:
1460 * hDeviceContext - Pointer to the adapter
1461 * pPacket - A pointer to a descriptor for the packet to transmit
1462 * Out:
1463 * none
1464 *
Andres Moree269fc22013-02-12 20:36:29 -05001465 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001466 *
1467-*/
1468
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001469CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1470 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001471{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001472 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001473 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001474 PSTxBufHead pTxBufHead;
1475 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001476 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001477 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001478 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001479 u8 byPktType, *pbyTxBufferAddr;
1480 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1481 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001482 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001483 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1484 u32 uPadding = 0;
1485 u16 wTxBufSize;
1486 u32 cbMacHdLen;
1487 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001488
Forest Bond92b96792009-06-13 07:38:31 -04001489 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1490
1491 if (NULL == pContext) {
1492 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1493 return CMD_STATUS_RESOURCES;
1494 }
1495
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001496 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001497 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001498 cbFrameBodySize = pPacket->cbPayloadLen;
1499 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1500 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001501
1502 if (pDevice->byBBType == BB_TYPE_11A) {
1503 wCurrentRate = RATE_6M;
1504 byPktType = PK_TYPE_11A;
1505 } else {
1506 wCurrentRate = RATE_1M;
1507 byPktType = PK_TYPE_11B;
1508 }
1509
1510 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1511 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1512 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1513 // to set power here.
1514 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1515 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1516 } else {
1517 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1518 }
1519 pDevice->wCurrentRate = wCurrentRate;
1520
Forest Bond92b96792009-06-13 07:38:31 -04001521 //Set packet type
1522 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1523 pTxBufHead->wFIFOCtl = 0;
1524 }
1525 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1526 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1527 }
1528 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1529 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1530 }
1531 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1532 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1533 }
1534
1535 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1536 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1537
Andres More22040bb2010-08-02 20:21:44 -03001538 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001539 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001540 }
1541 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001542 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001543 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1544 };
1545
1546 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1547 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1548
1549 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1550 //Set Preamble type always long
1551 //pDevice->byPreambleType = PREAMBLE_LONG;
1552 // probe-response don't retry
1553 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001554 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001555 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1556 //}
1557 }
1558
1559 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1560
1561 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001562 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001563 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1564 } else {
1565 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1566 }
1567
1568 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001569 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001570
1571 // Notes:
1572 // Although spec says MMPDU can be fragmented; In most case,
1573 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001574 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001575
1576 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1577 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1578 cbIVlen = 4;
1579 cbICVlen = 4;
1580 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1581 }
1582 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1583 cbIVlen = 8;//IV+ExtIV
1584 cbMIClen = 8;
1585 cbICVlen = 4;
1586 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1587 //We need to get seed here for filling TxKey entry.
1588 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1589 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1590 }
1591 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1592 cbIVlen = 8;//RSN Header
1593 cbICVlen = 8;//MIC
1594 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001595 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001596 }
1597 //MAC Header should be padding 0 to DW alignment.
1598 uPadding = 4 - (cbMacHdLen%4);
1599 uPadding %= 4;
1600 }
1601
1602 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1603
1604 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001605 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001606 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1607 }
1608 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1609
1610 //Set RrvTime/RTS/CTS Buffer
1611 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1612
Malcolm Priestley4f990052013-08-16 23:38:57 +01001613 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001614 pMICHDR = NULL;
1615 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001616 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001617 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001618 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001619 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1620 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001621 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001622 }
1623 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001624 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001625 pMICHDR = NULL;
1626 pvRTS = NULL;
1627 pCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001628 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1629 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001630 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001631 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001632 }
1633
Andres Moreceb8c5d2013-03-18 20:33:49 -05001634 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001635 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1636 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001637 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001638 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1639 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001640 //=========================
1641 // No Fragmentation
1642 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001643 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001644
Forest Bond92b96792009-06-13 07:38:31 -04001645 //Fill FIFO,RrvTime,RTS,and CTS
1646 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1647 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1648
1649 //Fill DataHead
1650 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001651 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001652
Andres More1cac4a42013-03-18 20:33:50 -05001653 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001654
1655 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1656
1657 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001658 u8 * pbyIVHead;
1659 u8 * pbyPayloadHead;
1660 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001661 PSKeyItem pTransmitKey = NULL;
1662
Andres Moreb902fbf2013-02-25 20:32:51 -05001663 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1664 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001665 do {
1666 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001667 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001668 pbyBSSID = pDevice->abyBSSID;
1669 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001670 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001671 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001672 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001673 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1674 break;
1675 }
1676 } else {
1677 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1678 break;
1679 }
1680 }
1681 // get group key
1682 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001683 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001684 pTransmitKey = NULL;
1685 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1686 } else {
1687 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1688 }
Andres Moree269fc22013-02-12 20:36:29 -05001689 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001690 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001691 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001692 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001693
Jim Lieb3e362592009-08-12 14:54:11 -07001694 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001695 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001696 cbFrameBodySize);
1697 }
1698 else {
1699 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001700 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001701 }
1702
Andres More1cac4a42013-03-18 20:33:50 -05001703 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001704 pDevice->wSeqCounter++ ;
1705 if (pDevice->wSeqCounter > 0x0fff)
1706 pDevice->wSeqCounter = 0;
1707
1708 if (bIsPSPOLL) {
1709 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001710 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001711 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1712 // in the same place of other packet's Duration-field).
1713 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001714 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1715 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1716 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1717 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1718 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1719 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001720 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1721 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1722 }
Forest Bond92b96792009-06-13 07:38:31 -04001723 }
1724
Andres More3eaca0d2013-02-25 20:32:52 -05001725 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001726 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001727 pTX_Buffer->byType = 0x00;
1728
1729 pContext->pPacket = NULL;
1730 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001731 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001732
Andres More1cac4a42013-03-18 20:33:50 -05001733 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1734 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001735 }
1736 else {
Andres More1cac4a42013-03-18 20:33:50 -05001737 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001738 }
1739
1740 PIPEnsSendBulkOut(pDevice,pContext);
1741 return CMD_STATUS_PENDING;
1742}
1743
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001744CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1745 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001746{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001747 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001748 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1749 u32 cbHeaderSize = 0;
1750 u16 wTxBufSize = sizeof(STxShortBufHead);
1751 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001752 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001753 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001754 u16 wCurrentRate;
1755 u32 cbFrameBodySize;
1756 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001757 u8 *pbyTxBufferAddr;
1758 PUSB_SEND_CONTEXT pContext;
1759 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001760
Forest Bond92b96792009-06-13 07:38:31 -04001761 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1762 if (NULL == pContext) {
1763 status = CMD_STATUS_RESOURCES;
1764 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1765 return status ;
1766 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001767
1768 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001769 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001770
1771 cbFrameBodySize = pPacket->cbPayloadLen;
1772
1773 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1774 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001775
1776 if (pDevice->byBBType == BB_TYPE_11A) {
1777 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001778 pTxDataHead = (struct vnt_tx_datahead_ab *)
1779 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001780 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001781 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1782 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001783 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001784 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001785 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001786 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001787 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001788 } else {
1789 wCurrentRate = RATE_1M;
1790 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001791 pTxDataHead = (struct vnt_tx_datahead_ab *)
1792 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001793 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001794 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1795 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001796 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001797 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001798 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001799 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001800 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001801 }
1802
1803 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001804 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001805 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001806
Andres More1cac4a42013-03-18 20:33:50 -05001807 pMACHeader->duration_id = 0;
1808 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001809 pDevice->wSeqCounter++ ;
1810 if (pDevice->wSeqCounter > 0x0fff)
1811 pDevice->wSeqCounter = 0;
1812
1813 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1814
Andres More3eaca0d2013-02-25 20:32:52 -05001815 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001816 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001817 pTX_Buffer->byType = 0x01;
1818
1819 pContext->pPacket = NULL;
1820 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001821 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001822
1823 PIPEnsSendBulkOut(pDevice,pContext);
1824 return CMD_STATUS_PENDING;
1825
1826}
1827
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001828void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1829{
1830 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001831 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001832 u8 byPktType;
1833 u8 *pbyTxBufferAddr;
1834 void *pvRTS, *pvCTS, *pvTxDataHd;
1835 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001836 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001837 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001838 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001839 PSTxBufHead pTxBufHead;
1840 u32 cbFrameSize;
1841 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1842 u32 uPadding = 0;
1843 u32 cbMICHDR = 0, uLength = 0;
1844 u32 dwMICKey0, dwMICKey1;
1845 u32 dwMIC_Priority;
1846 u32 *pdwMIC_L, *pdwMIC_R;
1847 u16 wTxBufSize;
1848 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001849 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001850 void *pvRrvTime, *pMICHDR;
1851 u32 wCurrentRate = RATE_1M;
1852 PUWLAN_80211HDR p80211Header;
1853 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001854 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001855 SKeyItem STempKey;
1856 PSKeyItem pTransmitKey = NULL;
1857 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1858 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001859 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001860
Forest Bond92b96792009-06-13 07:38:31 -04001861 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1862
1863 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1864 cbFrameBodySize = 0;
1865 }
1866 else {
1867 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1868 }
1869 p80211Header = (PUWLAN_80211HDR)skb->data;
1870
1871 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1872
1873 if (NULL == pContext) {
1874 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1875 dev_kfree_skb_irq(skb);
1876 return ;
1877 }
1878
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001879 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001880 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001881 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1882 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001883
1884 if (pDevice->byBBType == BB_TYPE_11A) {
1885 wCurrentRate = RATE_6M;
1886 byPktType = PK_TYPE_11A;
1887 } else {
1888 wCurrentRate = RATE_1M;
1889 byPktType = PK_TYPE_11B;
1890 }
1891
1892 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1893 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1894 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1895 // to set power here.
1896 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1897 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1898 } else {
1899 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1900 }
1901
1902 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1903
1904 //Set packet type
1905 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1906 pTxBufHead->wFIFOCtl = 0;
1907 }
1908 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1909 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1910 }
1911 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1912 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1913 }
1914 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1915 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1916 }
1917
1918 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1919 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1920
Andres More22040bb2010-08-02 20:21:44 -03001921 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001922 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001923 if (pDevice->bEnableHostWEP) {
1924 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001925 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001926 }
Forest Bond92b96792009-06-13 07:38:31 -04001927 }
1928 else {
1929 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001930 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001931 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001932 }
Andres More4e9b5e22013-02-12 20:36:30 -05001933 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001934 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1935 };
1936
1937 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1938 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1939
1940 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1941 //Set Preamble type always long
1942 //pDevice->byPreambleType = PREAMBLE_LONG;
1943
1944 // probe-response don't retry
1945 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001946 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001947 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1948 //}
1949 }
1950
1951 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1952
1953 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001954 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001955 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1956 } else {
1957 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1958 }
1959
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001960 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001961 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1962
1963 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1964 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1965 }
1966
1967 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1968 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1969 }
1970
1971 if (cbExtSuppRate >0) {
1972 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1973 }
1974 }
1975
Forest Bond92b96792009-06-13 07:38:31 -04001976 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001977 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001978
1979 // Notes:
1980 // Although spec says MMPDU can be fragmented; In most case,
1981 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001982 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001983
Forest Bond92b96792009-06-13 07:38:31 -04001984 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1985 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1986 cbIVlen = 4;
1987 cbICVlen = 4;
1988 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1989 }
1990 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1991 cbIVlen = 8;//IV+ExtIV
1992 cbMIClen = 8;
1993 cbICVlen = 4;
1994 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1995 //We need to get seed here for filling TxKey entry.
1996 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1997 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1998 }
1999 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2000 cbIVlen = 8;//RSN Header
2001 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002002 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04002003 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002004 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002005 }
2006 //MAC Header should be padding 0 to DW alignment.
2007 uPadding = 4 - (cbMacHdLen%4);
2008 uPadding %= 4;
2009 }
2010
2011 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2012
2013 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002014 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002015 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2016 }
2017 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2018
Forest Bond92b96792009-06-13 07:38:31 -04002019 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002020 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002021 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002022 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002023 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002024 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002025 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002026 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2027 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002028 sizeof(struct vnt_cts));
2029 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002030 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002031
2032 }
2033 else {//802.11a/b packet
2034
Malcolm Priestley976467d2013-08-16 23:44:04 +01002035 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002036 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01002037 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002038 pvRTS = NULL;
2039 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01002040 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2041 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002042 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002043 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002044 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002045 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002046 &(p80211Header->sA3.abyAddr1[0]),
2047 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002048 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002049 &(p80211Header->sA3.abyAddr2[0]),
2050 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002051 //=========================
2052 // No Fragmentation
2053 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002054 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002055
Forest Bond92b96792009-06-13 07:38:31 -04002056 //Fill FIFO,RrvTime,RTS,and CTS
2057 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2058 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2059
2060 //Fill DataHead
2061 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002062 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002063
Andres More1cac4a42013-03-18 20:33:50 -05002064 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002065
2066 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2067
Andres Moreb902fbf2013-02-25 20:32:51 -05002068 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2069 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2070 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002071
2072 // Copy the Packet into a tx Buffer
2073 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2074
2075 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002076 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002077 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2078
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002079 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002080 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2081 if (cbExtSuppRate != 0) {
2082 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2083 memcpy((pbyPayloadHead + cbFrameBodySize),
2084 pMgmt->abyCurrSuppRates,
2085 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2086 );
2087 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2088 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2089 pMgmt->abyCurrExtSuppRates,
2090 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2091 );
2092 }
2093 }
2094
2095 // Set wep
2096 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2097
2098 if (pDevice->bEnableHostWEP) {
2099 pTransmitKey = &STempKey;
2100 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2101 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2102 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2103 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2104 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2105 memcpy(pTransmitKey->abyKey,
2106 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2107 pTransmitKey->uKeyLength
2108 );
2109 }
2110
2111 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2112
Andres More52a7e642013-02-25 20:32:53 -05002113 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2114 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002115
2116 // DO Software Michael
2117 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002118 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002119 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002120 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002121 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2122 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002123
2124 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2125
2126 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2127
Andres More52a7e642013-02-25 20:32:53 -05002128 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2129 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002130
2131 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2132 MIC_vUnInit();
2133
Andres More4e9b5e22013-02-12 20:36:30 -05002134 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002135 *pdwMIC_L = 0;
2136 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002137 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002138 }
2139
2140 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2141 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002142 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2143 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002144
2145 }
2146
Andres Moreb902fbf2013-02-25 20:32:51 -05002147 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002148 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002149
2150 if (pDevice->bEnableHostWEP) {
2151 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2152 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2153 }
2154
2155 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002156 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002157 }
2158 }
2159
Andres More1cac4a42013-03-18 20:33:50 -05002160 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002161 pDevice->wSeqCounter++ ;
2162 if (pDevice->wSeqCounter > 0x0fff)
2163 pDevice->wSeqCounter = 0;
2164
Forest Bond92b96792009-06-13 07:38:31 -04002165 if (bIsPSPOLL) {
2166 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2167 // of FIFO control header.
2168 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2169 // in the same place of other packet's Duration-field).
2170 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002171 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2172 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2173 cpu_to_le16(p80211Header->sA2.wDurationID);
2174 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2175 cpu_to_le16(p80211Header->sA2.wDurationID);
2176 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002177 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2178 cpu_to_le16(p80211Header->sA2.wDurationID);
2179 }
Forest Bond92b96792009-06-13 07:38:31 -04002180 }
2181
Andres More3eaca0d2013-02-25 20:32:52 -05002182 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002183 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002184 pTX_Buffer->byType = 0x00;
2185
2186 pContext->pPacket = skb;
2187 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002188 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002189
Andres More1cac4a42013-03-18 20:33:50 -05002190 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2191 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002192 }
2193 else {
Andres More1cac4a42013-03-18 20:33:50 -05002194 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002195 }
2196 PIPEnsSendBulkOut(pDevice,pContext);
2197 return ;
2198
2199}
2200
Forest Bond92b96792009-06-13 07:38:31 -04002201//TYPE_AC0DMA data tx
2202/*
2203 * Description:
2204 * Tx packet via AC0DMA(DMA1)
2205 *
2206 * Parameters:
2207 * In:
2208 * pDevice - Pointer to the adapter
2209 * skb - Pointer to tx skb packet
2210 * Out:
2211 * void
2212 *
2213 * Return Value: NULL
2214 */
2215
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002216int nsDMA_tx_packet(struct vnt_private *pDevice,
2217 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002218{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002219 struct net_device_stats *pStats = &pDevice->stats;
2220 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002221 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002222 u32 BytesToWrite = 0, uHeaderLen = 0;
2223 u32 uNodeIndex = 0;
2224 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2225 u16 wAID;
2226 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002227 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002228 PSKeyItem pTransmitKey = NULL;
2229 SKeyItem STempKey;
2230 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002231 int bTKIP_UseGTK = false;
2232 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002233 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002234 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002235 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002236 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002237 u32 status;
2238 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002239 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002240
Forest Bond92b96792009-06-13 07:38:31 -04002241 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2242
2243 if (pDevice->uAssocCount == 0) {
2244 dev_kfree_skb_irq(skb);
2245 return 0;
2246 }
2247
Andres Moreb902fbf2013-02-25 20:32:51 -05002248 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002249 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002250 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002251 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2252
2253 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2254 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2255 // set tx map
2256 pMgmt->abyPSTxMap[0] |= byMask[0];
2257 return 0;
2258 }
Masanari Iida93184692012-08-13 21:21:50 +09002259 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002260
2261 if (pDevice->byBBType != BB_TYPE_11A)
2262 pDevice->wCurrentRate = RATE_2M;
2263 else
2264 pDevice->wCurrentRate = RATE_24M;
2265 // long preamble type
2266 pDevice->byPreambleType = PREAMBLE_SHORT;
2267
2268 }else {
2269
Andres Moreb902fbf2013-02-25 20:32:51 -05002270 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002271
2272 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2273
2274 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2275
2276 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2277 // set tx map
2278 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2279 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2280 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2281 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2282
2283 return 0;
2284 }
2285 // AP rate decided from node
2286 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2287 // tx preamble decided from node
2288
2289 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2290 pDevice->byPreambleType = pDevice->byShortPreamble;
2291
2292 }else {
2293 pDevice->byPreambleType = PREAMBLE_LONG;
2294 }
Andres More4e9b5e22013-02-12 20:36:30 -05002295 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002296 }
2297 }
2298
Andres Moree269fc22013-02-12 20:36:29 -05002299 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002300 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2301 dev_kfree_skb_irq(skb);
2302 return 0;
2303 }
2304 }
2305
2306 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2307
2308 if (pContext == NULL) {
2309 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2310 dev_kfree_skb_irq(skb);
2311 return STATUS_RESOURCES;
2312 }
2313
Andres Moreceb8c5d2013-03-18 20:33:49 -05002314 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002315
2316//mike add:station mode check eapol-key challenge--->
2317{
Andres Moreb902fbf2013-02-25 20:32:51 -05002318 u8 Protocol_Version; //802.1x Authentication
2319 u8 Packet_Type; //802.1x Authentication
2320 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002321 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002322
Charles Clément21ec51f2010-05-18 10:08:14 -07002323 Protocol_Version = skb->data[ETH_HLEN];
2324 Packet_Type = skb->data[ETH_HLEN+1];
2325 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2326 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 -05002327 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002328 /* 802.1x OR eapol-key challenge frame transfer */
2329 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2330 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002331 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002332 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2333 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2334 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002335 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002336 PRINT_K("WPA ");
2337 }
2338 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002339 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002340 PRINT_K("WPA2(re-keying) ");
2341 }
2342 PRINT_K("Authentication completed!!\n");
2343 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002344 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002345 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002346 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002347 PRINT_K("WPA2 Authentication completed!!\n");
2348 }
2349 }
2350 }
2351}
2352//mike add:station mode check eapol-key challenge<---
2353
Andres More4e9b5e22013-02-12 20:36:30 -05002354 if (pDevice->bEncryptionEnable == true) {
2355 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002356 // get Transmit key
2357 do {
2358 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2359 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2360 pbyBSSID = pDevice->abyBSSID;
2361 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002362 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002363 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002364 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2365 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002366 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2367 break;
2368 }
2369 } else {
2370 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2371 break;
2372 }
2373 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002374 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2375 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2377 for (ii = 0; ii< 6; ii++)
2378 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2380
2381 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002382 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002383 break;
2384 }
2385 // get group key
2386 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002387 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002388 pTransmitKey = NULL;
2389 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2391 }
2392 else
2393 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2394 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002395 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002396 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2397 }
Andres Moree269fc22013-02-12 20:36:29 -05002398 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002399 }
2400
2401 if (pDevice->bEnableHostWEP) {
2402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002403 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002404 pTransmitKey = &STempKey;
2405 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2406 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2407 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2408 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2409 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2410 memcpy(pTransmitKey->abyKey,
2411 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2412 pTransmitKey->uKeyLength
2413 );
2414 }
2415 }
2416
Andres Moreb902fbf2013-02-25 20:32:51 -05002417 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002418
2419 if (pDevice->bFixRate) {
2420 if (pDevice->byBBType == BB_TYPE_11B) {
2421 if (pDevice->uConnectionRate >= RATE_11M) {
2422 pDevice->wCurrentRate = RATE_11M;
2423 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002424 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002425 }
2426 } else {
2427 if ((pDevice->byBBType == BB_TYPE_11A) &&
2428 (pDevice->uConnectionRate <= RATE_6M)) {
2429 pDevice->wCurrentRate = RATE_6M;
2430 } else {
2431 if (pDevice->uConnectionRate >= RATE_54M)
2432 pDevice->wCurrentRate = RATE_54M;
2433 else
Andres More3eaca0d2013-02-25 20:32:52 -05002434 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002435 }
2436 }
2437 }
2438 else {
2439 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2440 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002441 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002442 // Multicast use highest data rate
2443 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2444 // preamble type
2445 pDevice->byPreambleType = pDevice->byShortPreamble;
2446 }
2447 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002448 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002449 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2450 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2451 pDevice->byPreambleType = pDevice->byShortPreamble;
2452
2453 }
2454 else {
2455 pDevice->byPreambleType = PREAMBLE_LONG;
2456 }
2457 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2458 }
2459 else {
2460 if (pDevice->byBBType != BB_TYPE_11A)
2461 pDevice->wCurrentRate = RATE_2M;
2462 else
2463 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2464 // abyCurrExtSuppRates[]
2465 pDevice->byPreambleType = PREAMBLE_SHORT;
2466 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2467 }
2468 }
2469 }
2470 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2471 // Infra STA rate decided from AP Node, index = 0
2472 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2473 }
2474 }
2475
Andres Moreceb8c5d2013-03-18 20:33:49 -05002476 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002477 if (pDevice->byBBType != BB_TYPE_11A) {
2478 pDevice->wCurrentRate = RATE_1M;
2479 pDevice->byACKRate = RATE_1M;
2480 pDevice->byTopCCKBasicRate = RATE_1M;
2481 pDevice->byTopOFDMBasicRate = RATE_6M;
2482 } else {
2483 pDevice->wCurrentRate = RATE_6M;
2484 pDevice->byACKRate = RATE_6M;
2485 pDevice->byTopCCKBasicRate = RATE_1M;
2486 pDevice->byTopOFDMBasicRate = RATE_6M;
2487 }
2488 }
Forest Bond92b96792009-06-13 07:38:31 -04002489
Andres More0cbd8d92010-05-06 20:34:29 -03002490 DBG_PRT(MSG_LEVEL_DEBUG,
2491 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2492 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002493
2494 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002495 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002496 }
2497
2498 if (pDevice->wCurrentRate <= RATE_11M) {
2499 byPktType = PK_TYPE_11B;
2500 }
2501
Andres More4e9b5e22013-02-12 20:36:30 -05002502 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002503 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2504 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002505 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002506 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002507 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2508 if (pTransmitKey == NULL) {
2509 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2510 }
2511 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002512 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002513 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2514 }
2515 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002516 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2517 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002518 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002519 }
2520 }
2521 }
2522
Forest Bond92b96792009-06-13 07:38:31 -04002523 if (pDevice->bEnableHostWEP) {
2524 if ((uNodeIndex != 0) &&
2525 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002526 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2527 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002528 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002529 }
2530 }
2531 }
2532 else {
2533
Forest Bond92b96792009-06-13 07:38:31 -04002534 if (pTransmitKey == NULL) {
2535 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002536 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002537 dev_kfree_skb_irq(skb);
2538 pStats->tx_dropped++;
2539 return STATUS_FAILURE;
2540 }
Forest Bond92b96792009-06-13 07:38:31 -04002541 }
2542 }
2543
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002544 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2545
Forest Bond92b96792009-06-13 07:38:31 -04002546 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002547 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002548 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002549 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002550 pDevice->wCurrentRate,
2551 &uHeaderLen, &BytesToWrite
2552 );
2553
Andres Moree269fc22013-02-12 20:36:29 -05002554 if (fConvertedPacket == false) {
2555 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002556 dev_kfree_skb_irq(skb);
2557 return STATUS_FAILURE;
2558 }
2559
Andres More4e9b5e22013-02-12 20:36:30 -05002560 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002561 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002562 bScheduleCommand((void *) pDevice,
2563 WLAN_CMD_MAC_DISPOWERSAVING,
2564 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002565 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002566 }
2567 }
2568
Andres Moreb902fbf2013-02-25 20:32:51 -05002569 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002570 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002571
2572 pContext->pPacket = skb;
2573 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002574 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002575
Andres Moreceb8c5d2013-03-18 20:33:49 -05002576 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 -04002577
2578 status = PIPEnsSendBulkOut(pDevice,pContext);
2579
Andres More4e9b5e22013-02-12 20:36:30 -05002580 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002581 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002582
Andres Moreb902fbf2013-02-25 20:32:51 -05002583 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002584 }
2585
2586 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002587 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002588 dev_kfree_skb_irq(skb);
2589 return STATUS_FAILURE;
2590 }
2591 else
2592 return 0;
2593
2594}
2595
Forest Bond92b96792009-06-13 07:38:31 -04002596/*
2597 * Description:
2598 * Relay packet send (AC1DMA) from rx dpc.
2599 *
2600 * Parameters:
2601 * In:
2602 * pDevice - Pointer to the adapter
2603 * pPacket - Pointer to rx packet
2604 * cbPacketSize - rx ethernet frame size
2605 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002606 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002607 *
Andres More4e9b5e22013-02-12 20:36:30 -05002608 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002609 */
2610
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002611int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2612 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002613{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002614 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002615 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002616 u32 BytesToWrite = 0, uHeaderLen = 0;
2617 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002618 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002619 SKeyItem STempKey;
2620 PSKeyItem pTransmitKey = NULL;
2621 u8 *pbyBSSID;
2622 PUSB_SEND_CONTEXT pContext;
2623 u8 byPktTyp;
2624 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002625 u32 status;
2626 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002627
Forest Bond92b96792009-06-13 07:38:31 -04002628 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2629
2630 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002631 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002632 }
2633
Andres Moreceb8c5d2013-03-18 20:33:49 -05002634 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002635
Andres More4e9b5e22013-02-12 20:36:30 -05002636 if (pDevice->bEncryptionEnable == true) {
2637 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002638 // get group key
2639 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002640 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002641 pTransmitKey = NULL;
2642 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2643 } else {
2644 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2645 }
2646 }
2647
2648 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002649 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002650 pTransmitKey = &STempKey;
2651 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2652 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2653 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2654 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2655 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2656 memcpy(pTransmitKey->abyKey,
2657 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2658 pTransmitKey->uKeyLength
2659 );
2660 }
2661 }
2662
2663 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002664 pContext->bBoolInUse = false;
2665 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002666 }
2667
Andres Moreb902fbf2013-02-25 20:32:51 -05002668 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002669
2670 if (pDevice->bFixRate) {
2671 if (pDevice->byBBType == BB_TYPE_11B) {
2672 if (pDevice->uConnectionRate >= RATE_11M) {
2673 pDevice->wCurrentRate = RATE_11M;
2674 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002675 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002676 }
2677 } else {
2678 if ((pDevice->byBBType == BB_TYPE_11A) &&
2679 (pDevice->uConnectionRate <= RATE_6M)) {
2680 pDevice->wCurrentRate = RATE_6M;
2681 } else {
2682 if (pDevice->uConnectionRate >= RATE_54M)
2683 pDevice->wCurrentRate = RATE_54M;
2684 else
Andres More3eaca0d2013-02-25 20:32:52 -05002685 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002686 }
2687 }
2688 }
2689 else {
2690 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2691 }
2692
Forest Bond92b96792009-06-13 07:38:31 -04002693 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002694 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002695 }
2696
2697 if (pDevice->wCurrentRate <= RATE_11M)
2698 byPktType = PK_TYPE_11B;
2699
Andres Moreabad19d2010-07-12 16:28:32 -03002700 BytesToWrite = uDataLen + ETH_FCS_LEN;
2701
Forest Bond92b96792009-06-13 07:38:31 -04002702 // Convert the packet to an usb frame and copy into our buffer
2703 // and send the irp.
2704
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002705 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2706
Forest Bond92b96792009-06-13 07:38:31 -04002707 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002708 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002709 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2710 pbySkbData, pTransmitKey, uNodeIndex,
2711 pDevice->wCurrentRate,
2712 &uHeaderLen, &BytesToWrite
2713 );
2714
Andres Moree269fc22013-02-12 20:36:29 -05002715 if (fConvertedPacket == false) {
2716 pContext->bBoolInUse = false;
2717 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002718 }
2719
Andres Moreb902fbf2013-02-25 20:32:51 -05002720 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002721 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002722
2723 pContext->pPacket = NULL;
2724 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002725 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002726
Andres Moreceb8c5d2013-03-18 20:33:49 -05002727 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 -04002728
2729 status = PIPEnsSendBulkOut(pDevice,pContext);
2730
Andres More4e9b5e22013-02-12 20:36:30 -05002731 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002732}
2733