blob: 463a8d5a096519cda9f5974cd88b1453644bafee [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
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100728 /* Note: So far RTSHead doesn't appear in ATIM
729 * & Beacom DMA, so we don't need to take them
730 * into account.
731 * Otherwise, we need to modified codes for them.
732 */
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100733 switch (byPktType) {
734 case PK_TYPE_11GB:
735 case PK_TYPE_11GA:
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100736 if (byFBOption == AUTO_FB_NONE)
737 vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
Malcolm Priestley5e67ee42013-08-26 11:04:50 +0100738 psEthHeader, byPktType, cbFrameLength,
739 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100740 else
741 vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
Malcolm Priestleyec917132013-08-26 11:07:46 +0100742 psEthHeader, byPktType, cbFrameLength,
743 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100744 break;
745 case PK_TYPE_11A:
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100746 if (byFBOption) {
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100747 vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
748 psEthHeader, byPktType, cbFrameLength,
749 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley2b83ebd2013-08-27 09:58:21 +0100750 break;
751 }
Malcolm Priestley0bddd302013-08-27 09:56:50 +0100752 case PK_TYPE_11B:
Malcolm Priestley13fe62a2013-08-26 11:17:52 +0100753 vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
Malcolm Priestley17126332013-08-26 11:09:38 +0100754 psEthHeader, byPktType, cbFrameLength,
755 bNeedAck, wCurrentRate, byFBOption);
Malcolm Priestley9d5829b2013-08-26 11:21:11 +0100756 }
Forest Bond92b96792009-06-13 07:38:31 -0400757}
758
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000759static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
760 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100761 u16 wCurrentRate, u8 byFBOption)
Forest Bond92b96792009-06-13 07:38:31 -0400762{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000763 u32 uCTSFrameLen = 14;
Forest Bond92b96792009-06-13 07:38:31 -0400764
765 if (pvCTS == NULL) {
766 return;
767 }
768
Forest Bond92b96792009-06-13 07:38:31 -0400769 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100770 if (byFBOption != AUTO_FB_NONE) {
771 /* Auto Fall back */
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100772 struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100773 /* Get SignalField,ServiceField,Length */
774 BBvCalculateParameter(pDevice, uCTSFrameLen,
775 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100776 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
777 cbFrameLength, byPktType,
778 wCurrentRate, bNeedAck, byFBOption);
779 /* Get CTSDuration_ba_f0 */
780 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
781 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
782 bNeedAck, byFBOption);
783 /* Get CTSDuration_ba_f1 */
784 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
785 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
786 bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100787 /* Get CTS Frame body */
788 pBuf->data.duration = pBuf->wDuration_ba;
789 pBuf->data.frame_control = TYPE_CTL_CTS;
790 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Malcolm Priestleyc921cc82013-08-20 20:47:49 +0100791 } else {
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +0100792 struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
Malcolm Priestleyaed387c2013-08-20 22:52:30 +0100793 /* Get SignalField,ServiceField,Length */
794 BBvCalculateParameter(pDevice, uCTSFrameLen,
795 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
Malcolm Priestleye34f9db2013-08-13 20:17:11 +0100796 /* Get CTSDuration_ba */
797 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
798 CTSDUR_BA, cbFrameLength, byPktType,
799 wCurrentRate, bNeedAck, byFBOption);
Malcolm Priestley14840cd2013-08-05 22:12:42 +0100800 /*Get CTS Frame body*/
801 pBuf->data.duration = pBuf->wDuration_ba;
802 pBuf->data.frame_control = TYPE_CTL_CTS;
803 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -0400804 }
805 }
806}
807
Forest Bond92b96792009-06-13 07:38:31 -0400808/*+
809 *
810 * Description:
811 * Generate FIFO control for MAC & Baseband controller
812 *
813 * Parameters:
814 * In:
815 * pDevice - Pointer to adpater
816 * pTxDataHead - Transmit Data Buffer
817 * pTxBufHead - pTxBufHead
818 * pvRrvTime - pvRrvTime
819 * pvRTS - RTS Buffer
820 * pCTS - CTS Buffer
821 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
822 * bNeedACK - If need ACK
823 * uDMAIdx - DMA Index
824 * Out:
825 * none
826 *
827 * Return Value: none
828 *
829-*/
Andres Morecc856e62010-05-17 21:34:01 -0300830
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000831static void s_vGenerateTxParameter(struct vnt_private *pDevice,
832 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
833 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
Andres Moreceb8c5d2013-03-18 20:33:49 -0500834 struct ethhdr *psEthHeader)
Forest Bond92b96792009-06-13 07:38:31 -0400835{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000836 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
837 u16 wFifoCtl;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000838 u8 byFBOption = AUTO_FB_NONE;
Forest Bond92b96792009-06-13 07:38:31 -0400839
840 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
841 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
842 pFifoHead->wReserved = wCurrentRate;
843 wFifoCtl = pFifoHead->wFIFOCtl;
844
Forest Bond92b96792009-06-13 07:38:31 -0400845 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
846 byFBOption = AUTO_FB_0;
847 }
848 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
849 byFBOption = AUTO_FB_1;
850 }
851
Malcolm Priestley2dc22d52013-08-24 13:15:32 +0100852 if (!pvRrvTime)
853 return;
854
Forest Bond92b96792009-06-13 07:38:31 -0400855 if (pDevice->bLongHeader)
856 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
857
858 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
859
860 if (pvRTS != NULL) { //RTS_need
861 //Fill RsvTime
Malcolm Priestley6398a592013-08-16 21:26:55 +0100862 struct vnt_rrv_time_rts *pBuf =
863 (struct vnt_rrv_time_rts *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100864 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
865 byPktType, cbFrameSize, wCurrentRate);
866 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
867 byPktType, cbFrameSize, wCurrentRate);
868 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
869 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100870 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
871 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
872 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
873 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
874 bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400875 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100876 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
877 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400878 }
879 else {//RTS_needless, PCF mode
Forest Bond92b96792009-06-13 07:38:31 -0400880 //Fill RsvTime
Malcolm Priestley4f990052013-08-16 23:38:57 +0100881 struct vnt_rrv_time_cts *pBuf =
882 (struct vnt_rrv_time_cts *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100883 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
884 cbFrameSize, wCurrentRate, bNeedACK);
885 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
886 PK_TYPE_11B, cbFrameSize,
887 pDevice->byTopCCKBasicRate, bNeedACK);
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100888 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
889 byPktType, cbFrameSize, wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -0400890 //Fill CTS
Malcolm Priestley09bd0f32013-08-24 12:56:11 +0100891 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize,
892 bNeedACK, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400893 }
894 }
895 else if (byPktType == PK_TYPE_11A) {
896
897 if (pvRTS != NULL) {//RTS_need, non PCF mode
898 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100899 struct vnt_rrv_time_ab *pBuf =
900 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100901 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
902 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100903 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
904 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400905 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100906 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
907 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400908 }
909 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
910 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100911 struct vnt_rrv_time_ab *pBuf =
912 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100913 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
914 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400915 }
916 }
917 else if (byPktType == PK_TYPE_11B) {
918
919 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
920 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100921 struct vnt_rrv_time_ab *pBuf =
922 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestleycfabe4b2013-08-22 21:03:40 +0100923 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
924 byPktType, cbFrameSize, wCurrentRate);
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100925 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
926 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400927 //Fill RTS
Malcolm Priestleyfedbfe72013-08-24 12:50:50 +0100928 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK,
929 psEthHeader, wCurrentRate, byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -0400930 }
931 else { //RTS_needless, non PCF mode
932 //Fill RsvTime
Malcolm Priestley976467d2013-08-16 23:44:04 +0100933 struct vnt_rrv_time_ab *pBuf =
934 (struct vnt_rrv_time_ab *)pvRrvTime;
Malcolm Priestley9c3806d2013-08-23 11:32:26 +0100935 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
936 cbFrameSize, wCurrentRate, bNeedACK);
Forest Bond92b96792009-06-13 07:38:31 -0400937 }
938 }
939 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
940}
941/*
Andres Moreb902fbf2013-02-25 20:32:51 -0500942 u8 * pbyBuffer,//point to pTxBufHead
Andres More3eaca0d2013-02-25 20:32:52 -0500943 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
Andres Morecc856e62010-05-17 21:34:01 -0300944 unsigned int cbFragmentSize,//Hdr+payoad+FCS
Forest Bond92b96792009-06-13 07:38:31 -0400945*/
946
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000947static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +0100948 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
949 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
950 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
951 u32 *pcbHeaderLen, u32 *pcbTotalLen)
Forest Bond92b96792009-06-13 07:38:31 -0400952{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000953 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
954 u32 cbFrameSize, cbFrameBodySize;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000955 u32 cb802_1_H_len;
956 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
957 u32 cbFCSlen = 4, cbMICHDR = 0;
958 int bNeedACK, bRTS;
959 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
960 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
961 u8 abySNAP_Bridgetunnel[ETH_ALEN]
962 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
963 u32 uDuration;
964 u32 cbHeaderLength = 0, uPadding = 0;
965 void *pvRrvTime;
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +0100966 struct vnt_mic_hdr *pMICHDR;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000967 void *pvRTS;
968 void *pvCTS;
969 void *pvTxDataHd;
970 u8 byFBOption = AUTO_FB_NONE, byFragType;
971 u16 wTxBufSize;
Malcolm Priestley4235f722013-08-24 12:42:01 +0100972 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000973 u32 *pdwMIC_L, *pdwMIC_R;
Andres Moree269fc22013-02-12 20:36:29 -0500974 int bSoftWEP = false;
Forest Bond92b96792009-06-13 07:38:31 -0400975
Malcolm Priestleyd56131d2013-01-17 23:15:22 +0000976 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
Forest Bond92b96792009-06-13 07:38:31 -0400977
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000978 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
Andres More4e9b5e22013-02-12 20:36:30 -0500979 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
980 bSoftWEP = true; /* WEP 256 */
Malcolm Priestleye2efba72012-11-11 15:20:52 +0000981 }
Forest Bond92b96792009-06-13 07:38:31 -0400982
Forest Bond92b96792009-06-13 07:38:31 -0400983 // Get pkt type
Andres Moreceb8c5d2013-03-18 20:33:49 -0500984 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Forest Bond92b96792009-06-13 07:38:31 -0400985 if (pDevice->dwDiagRefCount == 0) {
986 cb802_1_H_len = 8;
987 } else {
988 cb802_1_H_len = 2;
989 }
990 } else {
991 cb802_1_H_len = 0;
992 }
993
Charles Clément21ec51f2010-05-18 10:08:14 -0700994 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
Forest Bond92b96792009-06-13 07:38:31 -0400995
996 //Set packet type
Andres More3eaca0d2013-02-25 20:32:52 -0500997 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
Forest Bond92b96792009-06-13 07:38:31 -0400998
999 if (pDevice->dwDiagRefCount != 0) {
Andres Moree269fc22013-02-12 20:36:29 -05001000 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001001 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1002 } else { //if (pDevice->dwDiagRefCount != 0) {
Andres More22040bb2010-08-02 20:21:44 -03001003 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1004 (pDevice->eOPMode == OP_MODE_AP)) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001005 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
Andres Moree269fc22013-02-12 20:36:29 -05001006 bNeedACK = false;
Andres More22040bb2010-08-02 20:21:44 -03001007 pTxBufHead->wFIFOCtl =
1008 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1009 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001010 bNeedACK = true;
Andres More22040bb2010-08-02 20:21:44 -03001011 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1012 }
Forest Bond92b96792009-06-13 07:38:31 -04001013 }
1014 else {
1015 // MSDUs in Infra mode always need ACK
Andres More4e9b5e22013-02-12 20:36:30 -05001016 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001017 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1018 }
1019 } //if (pDevice->dwDiagRefCount != 0) {
1020
1021 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1022
1023 //Set FIFOCTL_LHEAD
1024 if (pDevice->bLongHeader)
1025 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1026
Forest Bond92b96792009-06-13 07:38:31 -04001027 //Set FRAGCTL_MACHDCNT
1028 if (pDevice->bLongHeader) {
1029 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1030 } else {
1031 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1032 }
Andres More3eaca0d2013-02-25 20:32:52 -05001033 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001034
1035 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001036 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001037 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1038 }
1039
1040 //Set Auto Fallback Ctl
1041 if (wCurrentRate >= RATE_18M) {
1042 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1043 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1044 byFBOption = AUTO_FB_0;
1045 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1046 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1047 byFBOption = AUTO_FB_1;
1048 }
1049 }
1050
Andres More4e9b5e22013-02-12 20:36:30 -05001051 if (bSoftWEP != true) {
Forest Bond92b96792009-06-13 07:38:31 -04001052 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1053 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1054 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1055 }
1056 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1057 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1058 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1059 }
1060 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1061 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1062 }
1063 }
1064 }
1065
Forest Bond92b96792009-06-13 07:38:31 -04001066 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1067 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1068 cbIVlen = 4;
1069 cbICVlen = 4;
1070 }
1071 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1072 cbIVlen = 8;//IV+ExtIV
1073 cbMIClen = 8;
1074 cbICVlen = 4;
1075 }
1076 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1077 cbIVlen = 8;//RSN Header
1078 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001079 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04001080 }
Andres Moree269fc22013-02-12 20:36:29 -05001081 if (bSoftWEP == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001082 //MAC Header should be padding 0 to DW alignment.
1083 uPadding = 4 - (cbMACHdLen%4);
1084 uPadding %= 4;
1085 }
1086 }
1087
1088 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1089
Andres Moree269fc22013-02-12 20:36:29 -05001090 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1091 bRTS = false;
Forest Bond92b96792009-06-13 07:38:31 -04001092 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05001093 bRTS = true;
Forest Bond92b96792009-06-13 07:38:31 -04001094 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1095 }
1096
Andres Moreb902fbf2013-02-25 20:32:51 -05001097 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001098 wTxBufSize = sizeof(STxBufHead);
1099 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1100 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001101 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001102 pvRrvTime = (struct vnt_rrv_time_rts *)
1103 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001104 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001105 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001106 pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001107 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001108 pvCTS = NULL;
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001109 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1110 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1111 cbMICHDR + sizeof(struct vnt_rts_g));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001112 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001113 cbMICHDR + sizeof(struct vnt_rts_g) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001114 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001115 }
1116 else { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001117 pvRrvTime = (struct vnt_rrv_time_cts *)
1118 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001119 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001120 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001121 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001122 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001123 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001124 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1125 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1126 cbMICHDR + sizeof(struct vnt_cts));
Malcolm Priestley4f990052013-08-16 23:38:57 +01001127 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1128 cbMICHDR + sizeof(struct vnt_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001129 sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001130 }
1131 } else {
1132 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001133 if (bRTS == true) {//RTS_need
Malcolm Priestley6398a592013-08-16 21:26:55 +01001134 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1135 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001136 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001137 sizeof(struct vnt_rrv_time_rts));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001138 pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley6398a592013-08-16 21:26:55 +01001139 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001140 pvCTS = NULL;
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001141 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1142 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1143 cbMICHDR + sizeof(struct vnt_rts_g_fb));
Malcolm Priestley6398a592013-08-16 21:26:55 +01001144 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1145 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001146 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001147 }
Andres Moree269fc22013-02-12 20:36:29 -05001148 else if (bRTS == false) { //RTS_needless
Malcolm Priestley4f990052013-08-16 23:38:57 +01001149 pvRrvTime = (struct vnt_rrv_time_cts *)
1150 (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001151 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001152 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04001153 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001154 pvCTS = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001155 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001156 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001157 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1158 cbMICHDR + sizeof(struct vnt_cts_fb));
1159 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001160 cbMICHDR + sizeof(struct vnt_cts_fb) +
Malcolm Priestley7c05c542013-08-16 23:49:15 +01001161 sizeof(struct vnt_tx_datahead_g_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001162 }
1163 } // Auto Fall Back
1164 }
1165 else {//802.11a/b packet
1166 if (byFBOption == AUTO_FB_NONE) {
Andres More4e9b5e22013-02-12 20:36:30 -05001167 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001168 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1169 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001170 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001171 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001172 pvRTS = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001173 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001174 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001175 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1176 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001177 sizeof(struct vnt_rts_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001178 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1179 cbMICHDR + sizeof(struct vnt_rts_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001180 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001181 }
Andres Moree269fc22013-02-12 20:36:29 -05001182 else if (bRTS == false) { //RTS_needless, no MICHDR
Malcolm Priestley976467d2013-08-16 23:44:04 +01001183 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1184 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001185 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001186 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001187 pvRTS = NULL;
1188 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001189 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1190 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001191 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001192 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001193 }
1194 } else {
1195 // Auto Fall Back
Andres More4e9b5e22013-02-12 20:36:30 -05001196 if (bRTS == true) {//RTS_need
Malcolm Priestley976467d2013-08-16 23:44:04 +01001197 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1198 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001199 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001200 sizeof(struct vnt_rrv_time_ab));
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001201 pvRTS = (struct vnt_rts_a_fb *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001202 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001203 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001204 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1205 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestleyc521cb52013-08-15 21:23:25 +01001206 sizeof(struct vnt_rts_a_fb));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001207 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1208 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001209 sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001210 }
Andres Moree269fc22013-02-12 20:36:29 -05001211 else if (bRTS == false) { //RTS_needless
Malcolm Priestley976467d2013-08-16 23:44:04 +01001212 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1213 wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01001214 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01001215 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04001216 pvRTS = NULL;
1217 pvCTS = NULL;
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001218 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1219 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01001220 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley1da4ee22013-08-16 23:51:38 +01001221 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
Forest Bond92b96792009-06-13 07:38:31 -04001222 }
1223 } // Auto Fall Back
1224 }
1225
Andres Moreb902fbf2013-02-25 20:32:51 -05001226 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1227 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1228 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001229
Forest Bond92b96792009-06-13 07:38:31 -04001230 //=========================
1231 // No Fragmentation
1232 //=========================
1233 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1234 byFragType = FRAGCTL_NONFRAG;
1235 //uDMAIdx = TYPE_AC0DMA;
1236 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1237
Forest Bond92b96792009-06-13 07:38:31 -04001238 //Fill FIFO,RrvTime,RTS,and CTS
Andres More8611a292010-05-01 14:25:00 -03001239 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1240 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
Forest Bond92b96792009-06-13 07:38:31 -04001241 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1242 //Fill DataHead
1243 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001244 byFBOption);
Forest Bond92b96792009-06-13 07:38:31 -04001245 // Generate TX MAC Header
Andres More3eaca0d2013-02-25 20:32:52 -05001246 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04001247 byFragType, uDMAIdx, 0);
1248
Andres More4e9b5e22013-02-12 20:36:30 -05001249 if (bNeedEncryption == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001250 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001251 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01001252 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04001253
1254 if (pDevice->bEnableHostWEP) {
1255 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1256 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1257 }
1258 }
1259
1260 // 802.1H
Andres Moreceb8c5d2013-03-18 20:33:49 -05001261 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
Andres More203e4612010-08-04 19:12:34 -03001262 if (pDevice->dwDiagRefCount == 0) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001263 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1264 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001265 memcpy((u8 *) (pbyPayloadHead),
Andres More203e4612010-08-04 19:12:34 -03001266 abySNAP_Bridgetunnel, 6);
Forest Bond92b96792009-06-13 07:38:31 -04001267 } else {
Andres Moreb902fbf2013-02-25 20:32:51 -05001268 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
Forest Bond92b96792009-06-13 07:38:31 -04001269 }
Andres Moreb902fbf2013-02-25 20:32:51 -05001270 pbyType = (u8 *) (pbyPayloadHead + 6);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001271 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001272 } else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05001273 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
Forest Bond92b96792009-06-13 07:38:31 -04001274
1275 }
1276
1277 }
1278
Forest Bond92b96792009-06-13 07:38:31 -04001279 if (pPacket != NULL) {
1280 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001281 memcpy((pbyPayloadHead + cb802_1_H_len),
Charles Clément21ec51f2010-05-18 10:08:14 -07001282 (pPacket + ETH_HLEN),
1283 uSkbPacketLen - ETH_HLEN
Forest Bond92b96792009-06-13 07:38:31 -04001284 );
1285
1286 } else {
1287 // while bRelayPacketSend psEthHeader is point to header+payload
Andres Moreb902fbf2013-02-25 20:32:51 -05001288 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04001289 }
1290
Andres More4e9b5e22013-02-12 20:36:30 -05001291 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
Forest Bond92b96792009-06-13 07:38:31 -04001292
1293 ///////////////////////////////////////////////////////////////////
1294
Malcolm Priestley14c5ef52013-01-17 23:19:37 +00001295 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1296 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1297 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1298 }
Forest Bond92b96792009-06-13 07:38:31 -04001299 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
Andres More52a7e642013-02-25 20:32:53 -05001300 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1301 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04001302 }
1303 else {
Andres More52a7e642013-02-25 20:32:53 -05001304 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1305 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
Forest Bond92b96792009-06-13 07:38:31 -04001306 }
1307 // DO Software Michael
1308 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001309 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04001310 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05001311 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00001312 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1313 dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04001314
1315 ///////////////////////////////////////////////////////////////////
1316
1317 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1318 //for (ii = 0; ii < cbFrameBodySize; ii++) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001319 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
Forest Bond92b96792009-06-13 07:38:31 -04001320 //}
1321 //DBG_PRN_GRP12(("\n\n\n"));
1322
1323 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1324
Andres More52a7e642013-02-25 20:32:53 -05001325 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1326 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04001327
1328 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1329 MIC_vUnInit();
1330
Andres More4e9b5e22013-02-12 20:36:30 -05001331 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001332 *pdwMIC_L = 0;
1333 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001334 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04001335 }
1336 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1337 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1338 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1339 }
1340
Andres More4e9b5e22013-02-12 20:36:30 -05001341 if (bSoftWEP == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001342
Andres More3eaca0d2013-02-25 20:32:52 -05001343 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04001344
Andres More4e9b5e22013-02-12 20:36:30 -05001345 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1346 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1347 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
Forest Bond92b96792009-06-13 07:38:31 -04001348 cbFrameSize -= cbICVlen;
1349 }
1350
Forest Bond92b96792009-06-13 07:38:31 -04001351 cbFrameSize -= cbFCSlen;
Forest Bond92b96792009-06-13 07:38:31 -04001352
1353 *pcbHeaderLen = cbHeaderLength;
1354 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1355
Forest Bond92b96792009-06-13 07:38:31 -04001356 //Set FragCtl in TxBufferHead
Andres More3eaca0d2013-02-25 20:32:52 -05001357 pTxBufHead->wFragCtl |= (u16)byFragType;
Forest Bond92b96792009-06-13 07:38:31 -04001358
Andres More4e9b5e22013-02-12 20:36:30 -05001359 return true;
Forest Bond92b96792009-06-13 07:38:31 -04001360
1361}
1362
Forest Bond92b96792009-06-13 07:38:31 -04001363/*+
1364 *
1365 * Description:
1366 * Translate 802.3 to 802.11 header
1367 *
1368 * Parameters:
1369 * In:
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001370 * pDevice - Pointer to adapter
Forest Bond92b96792009-06-13 07:38:31 -04001371 * dwTxBufferAddr - Transmit Buffer
1372 * pPacket - Packet from upper layer
1373 * cbPacketSize - Transmit Data Length
1374 * Out:
1375 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1376 * pcbAppendPayload - size of append payload for 802.1H translation
1377 *
1378 * Return Value: none
1379 *
1380-*/
1381
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001382static void s_vGenerateMACHeader(struct vnt_private *pDevice,
Andres Moreceb8c5d2013-03-18 20:33:49 -05001383 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001384 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
Forest Bond92b96792009-06-13 07:38:31 -04001385{
Andres More1cac4a42013-03-18 20:33:50 -05001386 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
Forest Bond92b96792009-06-13 07:38:31 -04001387
Malcolm Priestleyc921cc82013-08-20 20:47:49 +01001388 pMACHeader->frame_control = TYPE_802_11_DATA;
Forest Bond92b96792009-06-13 07:38:31 -04001389
1390 if (pDevice->eOPMode == OP_MODE_AP) {
Andres More1cac4a42013-03-18 20:33:50 -05001391 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001392 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001393 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001394 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1395 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001396 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001397 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001398 pMACHeader->frame_control |= FC_FROMDS;
Andres More9a0e7562010-04-13 21:54:48 -03001399 } else {
1400 if (pDevice->eOPMode == OP_MODE_ADHOC) {
Andres More1cac4a42013-03-18 20:33:50 -05001401 memcpy(&(pMACHeader->addr1[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001402 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001403 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001404 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001405 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001406 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001407 memcpy(&(pMACHeader->addr3[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001408 &(pDevice->abyBSSID[0]),
1409 ETH_ALEN);
1410 } else {
Andres More1cac4a42013-03-18 20:33:50 -05001411 memcpy(&(pMACHeader->addr3[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001412 &(psEthHeader->h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001413 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001414 memcpy(&(pMACHeader->addr2[0]),
Andres Moreceb8c5d2013-03-18 20:33:49 -05001415 &(psEthHeader->h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001416 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001417 memcpy(&(pMACHeader->addr1[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001418 &(pDevice->abyBSSID[0]),
1419 ETH_ALEN);
Andres More1cac4a42013-03-18 20:33:50 -05001420 pMACHeader->frame_control |= FC_TODS;
Forest Bond92b96792009-06-13 07:38:31 -04001421 }
1422 }
1423
1424 if (bNeedEncrypt)
Andres More1cac4a42013-03-18 20:33:50 -05001425 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
Forest Bond92b96792009-06-13 07:38:31 -04001426
Andres More1cac4a42013-03-18 20:33:50 -05001427 pMACHeader->duration_id = cpu_to_le16(wDuration);
Forest Bond92b96792009-06-13 07:38:31 -04001428
1429 if (pDevice->bLongHeader) {
1430 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
Andres More1cac4a42013-03-18 20:33:50 -05001431 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
Jim Lieb3e362592009-08-12 14:54:11 -07001432 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
Forest Bond92b96792009-06-13 07:38:31 -04001433 }
Andres More1cac4a42013-03-18 20:33:50 -05001434 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001435
1436 //Set FragNumber in Sequence Control
Andres More1cac4a42013-03-18 20:33:50 -05001437 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
Forest Bond92b96792009-06-13 07:38:31 -04001438
1439 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1440 pDevice->wSeqCounter++;
1441 if (pDevice->wSeqCounter > 0x0fff)
1442 pDevice->wSeqCounter = 0;
1443 }
1444
1445 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
Andres More1cac4a42013-03-18 20:33:50 -05001446 pMACHeader->frame_control |= FC_MOREFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001447 }
1448}
1449
Forest Bond92b96792009-06-13 07:38:31 -04001450/*+
1451 *
1452 * Description:
1453 * Request instructs a MAC to transmit a 802.11 management packet through
1454 * the adapter onto the medium.
1455 *
1456 * Parameters:
1457 * In:
1458 * hDeviceContext - Pointer to the adapter
1459 * pPacket - A pointer to a descriptor for the packet to transmit
1460 * Out:
1461 * none
1462 *
Andres Moree269fc22013-02-12 20:36:29 -05001463 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04001464 *
1465-*/
1466
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001467CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1468 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001469{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001470 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001471 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001472 PSTxBufHead pTxBufHead;
1473 PUSB_SEND_CONTEXT pContext;
Andres More1cac4a42013-03-18 20:33:50 -05001474 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001475 struct vnt_cts *pCTS;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001476 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001477 u8 byPktType, *pbyTxBufferAddr;
1478 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1479 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
Andres Moree269fc22013-02-12 20:36:29 -05001480 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001481 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1482 u32 uPadding = 0;
1483 u16 wTxBufSize;
1484 u32 cbMacHdLen;
1485 u16 wCurrentRate = RATE_1M;
Forest Bond92b96792009-06-13 07:38:31 -04001486
Forest Bond92b96792009-06-13 07:38:31 -04001487 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1488
1489 if (NULL == pContext) {
1490 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1491 return CMD_STATUS_RESOURCES;
1492 }
1493
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001494 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001495 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001496 cbFrameBodySize = pPacket->cbPayloadLen;
1497 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1498 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001499
1500 if (pDevice->byBBType == BB_TYPE_11A) {
1501 wCurrentRate = RATE_6M;
1502 byPktType = PK_TYPE_11A;
1503 } else {
1504 wCurrentRate = RATE_1M;
1505 byPktType = PK_TYPE_11B;
1506 }
1507
1508 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1509 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1510 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1511 // to set power here.
1512 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1513 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1514 } else {
1515 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1516 }
1517 pDevice->wCurrentRate = wCurrentRate;
1518
Forest Bond92b96792009-06-13 07:38:31 -04001519 //Set packet type
1520 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1521 pTxBufHead->wFIFOCtl = 0;
1522 }
1523 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1524 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1525 }
1526 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1527 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1528 }
1529 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1530 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1531 }
1532
1533 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1534 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1535
Andres More22040bb2010-08-02 20:21:44 -03001536 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001537 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001538 }
1539 else {
Andres More4e9b5e22013-02-12 20:36:30 -05001540 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001541 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1542 };
1543
1544 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1545 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1546
1547 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1548 //Set Preamble type always long
1549 //pDevice->byPreambleType = PREAMBLE_LONG;
1550 // probe-response don't retry
1551 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001552 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001553 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1554 //}
1555 }
1556
1557 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1558
1559 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001560 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001561 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1562 } else {
1563 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1564 }
1565
1566 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001567 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
Forest Bond92b96792009-06-13 07:38:31 -04001568
1569 // Notes:
1570 // Although spec says MMPDU can be fragmented; In most case,
1571 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001572 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001573
1574 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1575 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1576 cbIVlen = 4;
1577 cbICVlen = 4;
1578 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1579 }
1580 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1581 cbIVlen = 8;//IV+ExtIV
1582 cbMIClen = 8;
1583 cbICVlen = 4;
1584 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1585 //We need to get seed here for filling TxKey entry.
1586 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1587 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1588 }
1589 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1590 cbIVlen = 8;//RSN Header
1591 cbICVlen = 8;//MIC
1592 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05001593 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04001594 }
1595 //MAC Header should be padding 0 to DW alignment.
1596 uPadding = 4 - (cbMacHdLen%4);
1597 uPadding %= 4;
1598 }
1599
1600 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1601
1602 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05001603 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04001604 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1605 }
1606 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1607
1608 //Set RrvTime/RTS/CTS Buffer
1609 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1610
Malcolm Priestley4f990052013-08-16 23:38:57 +01001611 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001612 pMICHDR = NULL;
1613 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01001614 pCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001615 sizeof(struct vnt_rrv_time_cts));
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001616 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01001617 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1618 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001619 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04001620 }
1621 else { // 802.11a/b packet
Malcolm Priestley976467d2013-08-16 23:44:04 +01001622 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001623 pMICHDR = NULL;
1624 pvRTS = NULL;
1625 pCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001626 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1627 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
Malcolm Priestley976467d2013-08-16 23:44:04 +01001628 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
Malcolm Priestley558becf2013-08-16 23:50:32 +01001629 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001630 }
1631
Andres Moreceb8c5d2013-03-18 20:33:49 -05001632 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001633 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1634 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05001635 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03001636 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1637 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04001638 //=========================
1639 // No Fragmentation
1640 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05001641 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04001642
Forest Bond92b96792009-06-13 07:38:31 -04001643 //Fill FIFO,RrvTime,RTS,and CTS
1644 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1645 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
1646
1647 //Fill DataHead
1648 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01001649 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04001650
Andres More1cac4a42013-03-18 20:33:50 -05001651 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04001652
1653 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1654
1655 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001656 u8 * pbyIVHead;
1657 u8 * pbyPayloadHead;
1658 u8 * pbyBSSID;
Forest Bond92b96792009-06-13 07:38:31 -04001659 PSKeyItem pTransmitKey = NULL;
1660
Andres Moreb902fbf2013-02-25 20:32:51 -05001661 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1662 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
Forest Bond92b96792009-06-13 07:38:31 -04001663 do {
1664 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
Andres More4e9b5e22013-02-12 20:36:30 -05001665 (pDevice->bLinkPass == true)) {
Forest Bond92b96792009-06-13 07:38:31 -04001666 pbyBSSID = pDevice->abyBSSID;
1667 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05001668 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001669 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05001670 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
Forest Bond92b96792009-06-13 07:38:31 -04001671 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1672 break;
1673 }
1674 } else {
1675 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1676 break;
1677 }
1678 }
1679 // get group key
1680 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05001681 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04001682 pTransmitKey = NULL;
1683 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1684 } else {
1685 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1686 }
Andres Moree269fc22013-02-12 20:36:29 -05001687 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04001688 //Fill TXKEY
Andres Moreb902fbf2013-02-25 20:32:51 -05001689 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Andres More3eaca0d2013-02-25 20:32:52 -05001690 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04001691
Jim Lieb3e362592009-08-12 14:54:11 -07001692 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
Andres Moreb902fbf2013-02-25 20:32:51 -05001693 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
Forest Bond92b96792009-06-13 07:38:31 -04001694 cbFrameBodySize);
1695 }
1696 else {
1697 // Copy the Packet into a tx Buffer
Jim Lieb3e362592009-08-12 14:54:11 -07001698 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001699 }
1700
Andres More1cac4a42013-03-18 20:33:50 -05001701 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001702 pDevice->wSeqCounter++ ;
1703 if (pDevice->wSeqCounter > 0x0fff)
1704 pDevice->wSeqCounter = 0;
1705
1706 if (bIsPSPOLL) {
1707 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001708 // of FIFO control header.
Forest Bond92b96792009-06-13 07:38:31 -04001709 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1710 // in the same place of other packet's Duration-field).
1711 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01001712 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1713 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1714 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1715 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1716 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1717 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01001718 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1719 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1720 }
Forest Bond92b96792009-06-13 07:38:31 -04001721 }
1722
Andres More3eaca0d2013-02-25 20:32:52 -05001723 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05001724 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001725 pTX_Buffer->byType = 0x00;
1726
1727 pContext->pPacket = NULL;
1728 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001729 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001730
Andres More1cac4a42013-03-18 20:33:50 -05001731 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1732 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001733 }
1734 else {
Andres More1cac4a42013-03-18 20:33:50 -05001735 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001736 }
1737
1738 PIPEnsSendBulkOut(pDevice,pContext);
1739 return CMD_STATUS_PENDING;
1740}
1741
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001742CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1743 struct vnt_tx_mgmt *pPacket)
Forest Bond92b96792009-06-13 07:38:31 -04001744{
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001745 struct vnt_beacon_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001746 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1747 u32 cbHeaderSize = 0;
1748 u16 wTxBufSize = sizeof(STxShortBufHead);
1749 PSTxShortBufHead pTxBufHead;
Andres More1cac4a42013-03-18 20:33:50 -05001750 struct ieee80211_hdr *pMACHeader;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001751 struct vnt_tx_datahead_ab *pTxDataHead;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001752 u16 wCurrentRate;
1753 u32 cbFrameBodySize;
1754 u32 cbReqCount;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001755 u8 *pbyTxBufferAddr;
1756 PUSB_SEND_CONTEXT pContext;
1757 CMD_STATUS status;
Forest Bond92b96792009-06-13 07:38:31 -04001758
Forest Bond92b96792009-06-13 07:38:31 -04001759 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1760 if (NULL == pContext) {
1761 status = CMD_STATUS_RESOURCES;
1762 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1763 return status ;
1764 }
Malcolm Priestley01f865b2013-08-15 19:40:08 +01001765
1766 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001767 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04001768
1769 cbFrameBodySize = pPacket->cbPayloadLen;
1770
1771 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1772 wTxBufSize = sizeof(STxShortBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001773
1774 if (pDevice->byBBType == BB_TYPE_11A) {
1775 wCurrentRate = RATE_6M;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001776 pTxDataHead = (struct vnt_tx_datahead_ab *)
1777 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001778 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001779 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1780 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001781 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001782 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001783 PK_TYPE_11A, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001784 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001785 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001786 } else {
1787 wCurrentRate = RATE_1M;
1788 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
Malcolm Priestley558becf2013-08-16 23:50:32 +01001789 pTxDataHead = (struct vnt_tx_datahead_ab *)
1790 (pbyTxBufferAddr + wTxBufSize);
Forest Bond92b96792009-06-13 07:38:31 -04001791 //Get SignalField,ServiceField,Length
Malcolm Priestleyaed387c2013-08-20 22:52:30 +01001792 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1793 &pTxDataHead->ab);
Forest Bond92b96792009-06-13 07:38:31 -04001794 //Get Duration and TimeStampOff
Malcolm Priestleyd5005952013-08-21 21:58:37 +01001795 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
Malcolm Priestley6b5ad9d2013-08-21 22:16:04 +01001796 PK_TYPE_11B, false);
Malcolm Priestleyf115e762013-08-23 11:48:46 +01001797 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
Malcolm Priestley558becf2013-08-16 23:50:32 +01001798 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04001799 }
1800
1801 //Generate Beacon Header
Andres More1cac4a42013-03-18 20:33:50 -05001802 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
Jim Lieb3e362592009-08-12 14:54:11 -07001803 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
Forest Bond92b96792009-06-13 07:38:31 -04001804
Andres More1cac4a42013-03-18 20:33:50 -05001805 pMACHeader->duration_id = 0;
1806 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04001807 pDevice->wSeqCounter++ ;
1808 if (pDevice->wSeqCounter > 0x0fff)
1809 pDevice->wSeqCounter = 0;
1810
1811 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1812
Andres More3eaca0d2013-02-25 20:32:52 -05001813 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
Andres Moreb902fbf2013-02-25 20:32:51 -05001814 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04001815 pTX_Buffer->byType = 0x01;
1816
1817 pContext->pPacket = NULL;
1818 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05001819 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04001820
1821 PIPEnsSendBulkOut(pDevice,pContext);
1822 return CMD_STATUS_PENDING;
1823
1824}
1825
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001826void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1827{
1828 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001829 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001830 u8 byPktType;
1831 u8 *pbyTxBufferAddr;
1832 void *pvRTS, *pvCTS, *pvTxDataHd;
1833 u32 uDuration, cbReqCount;
Andres More1cac4a42013-03-18 20:33:50 -05001834 struct ieee80211_hdr *pMACHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001835 u32 cbHeaderSize, cbFrameBodySize;
Andres Moree269fc22013-02-12 20:36:29 -05001836 int bNeedACK, bIsPSPOLL = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001837 PSTxBufHead pTxBufHead;
1838 u32 cbFrameSize;
1839 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1840 u32 uPadding = 0;
1841 u32 cbMICHDR = 0, uLength = 0;
1842 u32 dwMICKey0, dwMICKey1;
1843 u32 dwMIC_Priority;
1844 u32 *pdwMIC_L, *pdwMIC_R;
1845 u16 wTxBufSize;
1846 u32 cbMacHdLen;
Andres Moreceb8c5d2013-03-18 20:33:49 -05001847 struct ethhdr sEthHeader;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001848 void *pvRrvTime, *pMICHDR;
1849 u32 wCurrentRate = RATE_1M;
1850 PUWLAN_80211HDR p80211Header;
1851 u32 uNodeIndex = 0;
Andres Moree269fc22013-02-12 20:36:29 -05001852 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001853 SKeyItem STempKey;
1854 PSKeyItem pTransmitKey = NULL;
1855 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1856 u32 cbExtSuppRate = 0;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00001857 PUSB_SEND_CONTEXT pContext;
Forest Bond92b96792009-06-13 07:38:31 -04001858
Forest Bond92b96792009-06-13 07:38:31 -04001859 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1860
1861 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1862 cbFrameBodySize = 0;
1863 }
1864 else {
1865 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1866 }
1867 p80211Header = (PUWLAN_80211HDR)skb->data;
1868
1869 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1870
1871 if (NULL == pContext) {
1872 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1873 dev_kfree_skb_irq(skb);
1874 return ;
1875 }
1876
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01001877 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
Andres Moreb902fbf2013-02-25 20:32:51 -05001878 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
Forest Bond92b96792009-06-13 07:38:31 -04001879 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1880 wTxBufSize = sizeof(STxBufHead);
Forest Bond92b96792009-06-13 07:38:31 -04001881
1882 if (pDevice->byBBType == BB_TYPE_11A) {
1883 wCurrentRate = RATE_6M;
1884 byPktType = PK_TYPE_11A;
1885 } else {
1886 wCurrentRate = RATE_1M;
1887 byPktType = PK_TYPE_11B;
1888 }
1889
1890 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1891 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1892 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1893 // to set power here.
1894 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1895 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1896 } else {
1897 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1898 }
1899
1900 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1901
1902 //Set packet type
1903 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1904 pTxBufHead->wFIFOCtl = 0;
1905 }
1906 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1907 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1908 }
1909 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1910 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1911 }
1912 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1913 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1914 }
1915
1916 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1917 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1918
Andres More22040bb2010-08-02 20:21:44 -03001919 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
Andres Moree269fc22013-02-12 20:36:29 -05001920 bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001921 if (pDevice->bEnableHostWEP) {
1922 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05001923 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001924 }
Forest Bond92b96792009-06-13 07:38:31 -04001925 }
1926 else {
1927 if (pDevice->bEnableHostWEP) {
Andres Moreb902fbf2013-02-25 20:32:51 -05001928 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
Andres More4e9b5e22013-02-12 20:36:30 -05001929 bNodeExist = true;
Joe Perches9fc86022011-04-10 14:31:32 -07001930 }
Andres More4e9b5e22013-02-12 20:36:30 -05001931 bNeedACK = true;
Forest Bond92b96792009-06-13 07:38:31 -04001932 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1933 };
1934
1935 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1936 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1937
1938 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1939 //Set Preamble type always long
1940 //pDevice->byPreambleType = PREAMBLE_LONG;
1941
1942 // probe-response don't retry
1943 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
Andres Moree269fc22013-02-12 20:36:29 -05001944 // bNeedACK = false;
Forest Bond92b96792009-06-13 07:38:31 -04001945 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1946 //}
1947 }
1948
1949 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1950
1951 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
Andres More4e9b5e22013-02-12 20:36:30 -05001952 bIsPSPOLL = true;
Forest Bond92b96792009-06-13 07:38:31 -04001953 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1954 } else {
1955 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1956 }
1957
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07001958 // hostapd daemon ext support rate patch
Forest Bond92b96792009-06-13 07:38:31 -04001959 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1960
1961 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1962 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1963 }
1964
1965 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1966 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1967 }
1968
1969 if (cbExtSuppRate >0) {
1970 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1971 }
1972 }
1973
Forest Bond92b96792009-06-13 07:38:31 -04001974 //Set FRAGCTL_MACHDCNT
Andres More3eaca0d2013-02-25 20:32:52 -05001975 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
Forest Bond92b96792009-06-13 07:38:31 -04001976
1977 // Notes:
1978 // Although spec says MMPDU can be fragmented; In most case,
1979 // no one will send a MMPDU under fragmentation. With RTS may occur.
Andres Moree269fc22013-02-12 20:36:29 -05001980 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
Forest Bond92b96792009-06-13 07:38:31 -04001981
Forest Bond92b96792009-06-13 07:38:31 -04001982 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1983 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1984 cbIVlen = 4;
1985 cbICVlen = 4;
1986 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1987 }
1988 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1989 cbIVlen = 8;//IV+ExtIV
1990 cbMIClen = 8;
1991 cbICVlen = 4;
1992 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1993 //We need to get seed here for filling TxKey entry.
1994 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1995 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1996 }
1997 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1998 cbIVlen = 8;//RSN Header
1999 cbICVlen = 8;//MIC
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002000 cbMICHDR = sizeof(struct vnt_mic_hdr);
Forest Bond92b96792009-06-13 07:38:31 -04002001 pTxBufHead->wFragCtl |= FRAGCTL_AES;
Andres More4e9b5e22013-02-12 20:36:30 -05002002 pDevice->bAES = true;
Forest Bond92b96792009-06-13 07:38:31 -04002003 }
2004 //MAC Header should be padding 0 to DW alignment.
2005 uPadding = 4 - (cbMacHdLen%4);
2006 uPadding %= 4;
2007 }
2008
2009 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2010
2011 //Set FIFOCTL_GrpAckPolicy
Andres More4e9b5e22013-02-12 20:36:30 -05002012 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
Forest Bond92b96792009-06-13 07:38:31 -04002013 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2014 }
2015 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2016
Forest Bond92b96792009-06-13 07:38:31 -04002017 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
Malcolm Priestley4f990052013-08-16 23:38:57 +01002018 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002019 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002020 sizeof(struct vnt_rrv_time_cts));
Forest Bond92b96792009-06-13 07:38:31 -04002021 pvRTS = NULL;
Malcolm Priestleyf0c5ba22013-08-15 21:27:22 +01002022 pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002023 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002024 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2025 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley4f990052013-08-16 23:38:57 +01002026 sizeof(struct vnt_cts));
2027 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002028 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
Forest Bond92b96792009-06-13 07:38:31 -04002029
2030 }
2031 else {//802.11a/b packet
2032
Malcolm Priestley976467d2013-08-16 23:44:04 +01002033 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
Malcolm Priestley5a5d6a82013-08-23 14:33:55 +01002034 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
Malcolm Priestley976467d2013-08-16 23:44:04 +01002035 sizeof(struct vnt_rrv_time_ab));
Forest Bond92b96792009-06-13 07:38:31 -04002036 pvRTS = NULL;
2037 pvCTS = NULL;
Malcolm Priestley558becf2013-08-16 23:50:32 +01002038 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2039 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
Malcolm Priestley976467d2013-08-16 23:44:04 +01002040 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
Malcolm Priestley558becf2013-08-16 23:50:32 +01002041 sizeof(struct vnt_tx_datahead_ab);
Forest Bond92b96792009-06-13 07:38:31 -04002042 }
Andres Moreceb8c5d2013-03-18 20:33:49 -05002043 memcpy(&(sEthHeader.h_dest[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002044 &(p80211Header->sA3.abyAddr1[0]),
2045 ETH_ALEN);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002046 memcpy(&(sEthHeader.h_source[0]),
Andres More9a0e7562010-04-13 21:54:48 -03002047 &(p80211Header->sA3.abyAddr2[0]),
2048 ETH_ALEN);
Forest Bond92b96792009-06-13 07:38:31 -04002049 //=========================
2050 // No Fragmentation
2051 //=========================
Andres More3eaca0d2013-02-25 20:32:52 -05002052 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
Forest Bond92b96792009-06-13 07:38:31 -04002053
Forest Bond92b96792009-06-13 07:38:31 -04002054 //Fill FIFO,RrvTime,RTS,and CTS
2055 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2056 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2057
2058 //Fill DataHead
2059 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
Malcolm Priestleyab01fed2013-08-07 21:31:48 +01002060 AUTO_FB_NONE);
Forest Bond92b96792009-06-13 07:38:31 -04002061
Andres More1cac4a42013-03-18 20:33:50 -05002062 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
Forest Bond92b96792009-06-13 07:38:31 -04002063
2064 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2065
Andres Moreb902fbf2013-02-25 20:32:51 -05002066 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2067 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2068 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
Forest Bond92b96792009-06-13 07:38:31 -04002069
2070 // Copy the Packet into a tx Buffer
2071 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2072
2073 // version set to 0, patch for hostapd deamon
Andres More1cac4a42013-03-18 20:33:50 -05002074 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
Forest Bond92b96792009-06-13 07:38:31 -04002075 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2076
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002077 // replace support rate, patch for hostapd daemon( only support 11M)
Forest Bond92b96792009-06-13 07:38:31 -04002078 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2079 if (cbExtSuppRate != 0) {
2080 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2081 memcpy((pbyPayloadHead + cbFrameBodySize),
2082 pMgmt->abyCurrSuppRates,
2083 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2084 );
2085 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2086 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2087 pMgmt->abyCurrExtSuppRates,
2088 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2089 );
2090 }
2091 }
2092
2093 // Set wep
2094 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2095
2096 if (pDevice->bEnableHostWEP) {
2097 pTransmitKey = &STempKey;
2098 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2099 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2100 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2101 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2102 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2103 memcpy(pTransmitKey->abyKey,
2104 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2105 pTransmitKey->uKeyLength
2106 );
2107 }
2108
2109 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2110
Andres More52a7e642013-02-25 20:32:53 -05002111 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2112 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
Forest Bond92b96792009-06-13 07:38:31 -04002113
2114 // DO Software Michael
2115 MIC_vInit(dwMICKey0, dwMICKey1);
Andres Moreceb8c5d2013-03-18 20:33:49 -05002116 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
Forest Bond92b96792009-06-13 07:38:31 -04002117 dwMIC_Priority = 0;
Andres Moreb902fbf2013-02-25 20:32:51 -05002118 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002119 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2120 " %X, %X\n", dwMICKey0, dwMICKey1);
Forest Bond92b96792009-06-13 07:38:31 -04002121
2122 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2123
2124 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2125
Andres More52a7e642013-02-25 20:32:53 -05002126 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2127 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
Forest Bond92b96792009-06-13 07:38:31 -04002128
2129 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2130 MIC_vUnInit();
2131
Andres More4e9b5e22013-02-12 20:36:30 -05002132 if (pDevice->bTxMICFail == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002133 *pdwMIC_L = 0;
2134 *pdwMIC_R = 0;
Andres Moree269fc22013-02-12 20:36:29 -05002135 pDevice->bTxMICFail = false;
Forest Bond92b96792009-06-13 07:38:31 -04002136 }
2137
2138 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2139 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002140 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2141 *pdwMIC_L, *pdwMIC_R);
Forest Bond92b96792009-06-13 07:38:31 -04002142
2143 }
2144
Andres Moreb902fbf2013-02-25 20:32:51 -05002145 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
Malcolm Priestleyec37d8b2013-08-23 14:37:48 +01002146 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
Forest Bond92b96792009-06-13 07:38:31 -04002147
2148 if (pDevice->bEnableHostWEP) {
2149 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2150 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2151 }
2152
2153 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
Andres More3eaca0d2013-02-25 20:32:52 -05002154 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
Forest Bond92b96792009-06-13 07:38:31 -04002155 }
2156 }
2157
Andres More1cac4a42013-03-18 20:33:50 -05002158 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
Forest Bond92b96792009-06-13 07:38:31 -04002159 pDevice->wSeqCounter++ ;
2160 if (pDevice->wSeqCounter > 0x0fff)
2161 pDevice->wSeqCounter = 0;
2162
Forest Bond92b96792009-06-13 07:38:31 -04002163 if (bIsPSPOLL) {
2164 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2165 // of FIFO control header.
2166 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2167 // in the same place of other packet's Duration-field).
2168 // And it will cause Cisco-AP to issue Disassociation-packet
Malcolm Priestley7e60a3de2013-08-16 23:48:03 +01002169 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2170 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2171 cpu_to_le16(p80211Header->sA2.wDurationID);
2172 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2173 cpu_to_le16(p80211Header->sA2.wDurationID);
2174 } else {
Malcolm Priestley558becf2013-08-16 23:50:32 +01002175 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2176 cpu_to_le16(p80211Header->sA2.wDurationID);
2177 }
Forest Bond92b96792009-06-13 07:38:31 -04002178 }
2179
Andres More3eaca0d2013-02-25 20:32:52 -05002180 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
Andres Moreb902fbf2013-02-25 20:32:51 -05002181 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Forest Bond92b96792009-06-13 07:38:31 -04002182 pTX_Buffer->byType = 0x00;
2183
2184 pContext->pPacket = skb;
2185 pContext->Type = CONTEXT_MGMT_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002186 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002187
Andres More1cac4a42013-03-18 20:33:50 -05002188 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2189 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002190 }
2191 else {
Andres More1cac4a42013-03-18 20:33:50 -05002192 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
Forest Bond92b96792009-06-13 07:38:31 -04002193 }
2194 PIPEnsSendBulkOut(pDevice,pContext);
2195 return ;
2196
2197}
2198
Forest Bond92b96792009-06-13 07:38:31 -04002199//TYPE_AC0DMA data tx
2200/*
2201 * Description:
2202 * Tx packet via AC0DMA(DMA1)
2203 *
2204 * Parameters:
2205 * In:
2206 * pDevice - Pointer to the adapter
2207 * skb - Pointer to tx skb packet
2208 * Out:
2209 * void
2210 *
2211 * Return Value: NULL
2212 */
2213
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002214int nsDMA_tx_packet(struct vnt_private *pDevice,
2215 u32 uDMAIdx, struct sk_buff *skb)
Forest Bond92b96792009-06-13 07:38:31 -04002216{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002217 struct net_device_stats *pStats = &pDevice->stats;
2218 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002219 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002220 u32 BytesToWrite = 0, uHeaderLen = 0;
2221 u32 uNodeIndex = 0;
2222 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2223 u16 wAID;
2224 u8 byPktType;
Andres Moree269fc22013-02-12 20:36:29 -05002225 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002226 PSKeyItem pTransmitKey = NULL;
2227 SKeyItem STempKey;
2228 int ii;
Andres Moree269fc22013-02-12 20:36:29 -05002229 int bTKIP_UseGTK = false;
2230 int bNeedDeAuth = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002231 u8 *pbyBSSID;
Andres Moree269fc22013-02-12 20:36:29 -05002232 int bNodeExist = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002233 PUSB_SEND_CONTEXT pContext;
Andres Moredfdcc422013-02-12 20:36:28 -05002234 bool fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002235 u32 status;
2236 u16 wKeepRate = pDevice->wCurrentRate;
Andres Moree269fc22013-02-12 20:36:29 -05002237 int bTxeapol_key = false;
Forest Bond92b96792009-06-13 07:38:31 -04002238
Forest Bond92b96792009-06-13 07:38:31 -04002239 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2240
2241 if (pDevice->uAssocCount == 0) {
2242 dev_kfree_skb_irq(skb);
2243 return 0;
2244 }
2245
Andres Moreb902fbf2013-02-25 20:32:51 -05002246 if (is_multicast_ether_addr((u8 *)(skb->data))) {
Forest Bond92b96792009-06-13 07:38:31 -04002247 uNodeIndex = 0;
Andres More4e9b5e22013-02-12 20:36:30 -05002248 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002249 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2250
2251 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2252 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2253 // set tx map
2254 pMgmt->abyPSTxMap[0] |= byMask[0];
2255 return 0;
2256 }
Masanari Iida93184692012-08-13 21:21:50 +09002257 // multicast/broadcast data rate
Forest Bond92b96792009-06-13 07:38:31 -04002258
2259 if (pDevice->byBBType != BB_TYPE_11A)
2260 pDevice->wCurrentRate = RATE_2M;
2261 else
2262 pDevice->wCurrentRate = RATE_24M;
2263 // long preamble type
2264 pDevice->byPreambleType = PREAMBLE_SHORT;
2265
2266 }else {
2267
Andres Moreb902fbf2013-02-25 20:32:51 -05002268 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002269
2270 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2271
2272 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2273
2274 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2275 // set tx map
2276 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2277 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2278 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2279 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2280
2281 return 0;
2282 }
2283 // AP rate decided from node
2284 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2285 // tx preamble decided from node
2286
2287 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2288 pDevice->byPreambleType = pDevice->byShortPreamble;
2289
2290 }else {
2291 pDevice->byPreambleType = PREAMBLE_LONG;
2292 }
Andres More4e9b5e22013-02-12 20:36:30 -05002293 bNodeExist = true;
Forest Bond92b96792009-06-13 07:38:31 -04002294 }
2295 }
2296
Andres Moree269fc22013-02-12 20:36:29 -05002297 if (bNodeExist == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002298 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2299 dev_kfree_skb_irq(skb);
2300 return 0;
2301 }
2302 }
2303
2304 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2305
2306 if (pContext == NULL) {
2307 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2308 dev_kfree_skb_irq(skb);
2309 return STATUS_RESOURCES;
2310 }
2311
Andres Moreceb8c5d2013-03-18 20:33:49 -05002312 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002313
2314//mike add:station mode check eapol-key challenge--->
2315{
Andres Moreb902fbf2013-02-25 20:32:51 -05002316 u8 Protocol_Version; //802.1x Authentication
2317 u8 Packet_Type; //802.1x Authentication
2318 u8 Descriptor_type;
Andres More3eaca0d2013-02-25 20:32:52 -05002319 u16 Key_info;
Forest Bond92b96792009-06-13 07:38:31 -04002320
Charles Clément21ec51f2010-05-18 10:08:14 -07002321 Protocol_Version = skb->data[ETH_HLEN];
2322 Packet_Type = skb->data[ETH_HLEN+1];
2323 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2324 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 -05002325 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002326 /* 802.1x OR eapol-key challenge frame transfer */
2327 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2328 (Packet_Type == 3)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002329 bTxeapol_key = true;
Forest Bond92b96792009-06-13 07:38:31 -04002330 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2331 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2332 if(Descriptor_type==254) {
Andres More4e9b5e22013-02-12 20:36:30 -05002333 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002334 PRINT_K("WPA ");
2335 }
2336 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002337 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002338 PRINT_K("WPA2(re-keying) ");
2339 }
2340 PRINT_K("Authentication completed!!\n");
2341 }
Justin P. Mattocka0a1f612012-08-26 08:16:43 -07002342 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
Forest Bond92b96792009-06-13 07:38:31 -04002343 (Key_info & BIT8) && (Key_info & BIT9)) {
Andres More4e9b5e22013-02-12 20:36:30 -05002344 pDevice->fWPA_Authened = true;
Forest Bond92b96792009-06-13 07:38:31 -04002345 PRINT_K("WPA2 Authentication completed!!\n");
2346 }
2347 }
2348 }
2349}
2350//mike add:station mode check eapol-key challenge<---
2351
Andres More4e9b5e22013-02-12 20:36:30 -05002352 if (pDevice->bEncryptionEnable == true) {
2353 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002354 // get Transmit key
2355 do {
2356 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2357 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2358 pbyBSSID = pDevice->abyBSSID;
2359 // get pairwise key
Andres Moree269fc22013-02-12 20:36:29 -05002360 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002361 // get group key
Andres More4e9b5e22013-02-12 20:36:30 -05002362 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2363 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002364 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2365 break;
2366 }
2367 } else {
2368 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2369 break;
2370 }
2371 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002372 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2373 pbyBSSID = pDevice->sTxEthHeader.h_dest;
Forest Bond92b96792009-06-13 07:38:31 -04002374 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2375 for (ii = 0; ii< 6; ii++)
2376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2377 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2378
2379 // get pairwise key
Andres More4e9b5e22013-02-12 20:36:30 -05002380 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
Forest Bond92b96792009-06-13 07:38:31 -04002381 break;
2382 }
2383 // get group key
2384 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002385 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002386 pTransmitKey = NULL;
2387 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2388 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2389 }
2390 else
2391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2392 } else {
Andres More4e9b5e22013-02-12 20:36:30 -05002393 bTKIP_UseGTK = true;
Forest Bond92b96792009-06-13 07:38:31 -04002394 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2395 }
Andres Moree269fc22013-02-12 20:36:29 -05002396 } while(false);
Forest Bond92b96792009-06-13 07:38:31 -04002397 }
2398
2399 if (pDevice->bEnableHostWEP) {
2400 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002401 if (pDevice->bEncryptionEnable == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002402 pTransmitKey = &STempKey;
2403 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2404 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2405 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2406 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2407 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2408 memcpy(pTransmitKey->abyKey,
2409 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2410 pTransmitKey->uKeyLength
2411 );
2412 }
2413 }
2414
Andres Moreb902fbf2013-02-25 20:32:51 -05002415 byPktType = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002416
2417 if (pDevice->bFixRate) {
2418 if (pDevice->byBBType == BB_TYPE_11B) {
2419 if (pDevice->uConnectionRate >= RATE_11M) {
2420 pDevice->wCurrentRate = RATE_11M;
2421 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002422 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002423 }
2424 } else {
2425 if ((pDevice->byBBType == BB_TYPE_11A) &&
2426 (pDevice->uConnectionRate <= RATE_6M)) {
2427 pDevice->wCurrentRate = RATE_6M;
2428 } else {
2429 if (pDevice->uConnectionRate >= RATE_54M)
2430 pDevice->wCurrentRate = RATE_54M;
2431 else
Andres More3eaca0d2013-02-25 20:32:52 -05002432 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002433 }
2434 }
2435 }
2436 else {
2437 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2438 // Adhoc Tx rate decided from node DB
Andres Moreceb8c5d2013-03-18 20:33:49 -05002439 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
Forest Bond92b96792009-06-13 07:38:31 -04002440 // Multicast use highest data rate
2441 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2442 // preamble type
2443 pDevice->byPreambleType = pDevice->byShortPreamble;
2444 }
2445 else {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002446 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
Forest Bond92b96792009-06-13 07:38:31 -04002447 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2448 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2449 pDevice->byPreambleType = pDevice->byShortPreamble;
2450
2451 }
2452 else {
2453 pDevice->byPreambleType = PREAMBLE_LONG;
2454 }
2455 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2456 }
2457 else {
2458 if (pDevice->byBBType != BB_TYPE_11A)
2459 pDevice->wCurrentRate = RATE_2M;
2460 else
2461 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2462 // abyCurrExtSuppRates[]
2463 pDevice->byPreambleType = PREAMBLE_SHORT;
2464 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2465 }
2466 }
2467 }
2468 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2469 // Infra STA rate decided from AP Node, index = 0
2470 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2471 }
2472 }
2473
Andres Moreceb8c5d2013-03-18 20:33:49 -05002474 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
Malcolm Priestleyaa209ee2012-08-29 23:08:21 +01002475 if (pDevice->byBBType != BB_TYPE_11A) {
2476 pDevice->wCurrentRate = RATE_1M;
2477 pDevice->byACKRate = RATE_1M;
2478 pDevice->byTopCCKBasicRate = RATE_1M;
2479 pDevice->byTopOFDMBasicRate = RATE_6M;
2480 } else {
2481 pDevice->wCurrentRate = RATE_6M;
2482 pDevice->byACKRate = RATE_6M;
2483 pDevice->byTopCCKBasicRate = RATE_1M;
2484 pDevice->byTopOFDMBasicRate = RATE_6M;
2485 }
2486 }
Forest Bond92b96792009-06-13 07:38:31 -04002487
Andres More0cbd8d92010-05-06 20:34:29 -03002488 DBG_PRT(MSG_LEVEL_DEBUG,
2489 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2490 pDevice->wCurrentRate);
Forest Bond92b96792009-06-13 07:38:31 -04002491
2492 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002493 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002494 }
2495
2496 if (pDevice->wCurrentRate <= RATE_11M) {
2497 byPktType = PK_TYPE_11B;
2498 }
2499
Andres More4e9b5e22013-02-12 20:36:30 -05002500 if (bNeedEncryption == true) {
Andres Moreceb8c5d2013-03-18 20:33:49 -05002501 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2502 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
Andres Moree269fc22013-02-12 20:36:29 -05002503 bNeedEncryption = false;
Andres Moreceb8c5d2013-03-18 20:33:49 -05002504 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
Forest Bond92b96792009-06-13 07:38:31 -04002505 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2506 if (pTransmitKey == NULL) {
2507 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2508 }
2509 else {
Andres More4e9b5e22013-02-12 20:36:30 -05002510 if (bTKIP_UseGTK == true) {
Forest Bond92b96792009-06-13 07:38:31 -04002511 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2512 }
2513 else {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002514 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2515 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002516 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002517 }
2518 }
2519 }
2520
Forest Bond92b96792009-06-13 07:38:31 -04002521 if (pDevice->bEnableHostWEP) {
2522 if ((uNodeIndex != 0) &&
2523 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
Malcolm Priestleyb4dc03a2012-11-11 15:45:52 +00002524 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2525 pTransmitKey->dwKeyIndex);
Andres More4e9b5e22013-02-12 20:36:30 -05002526 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002527 }
2528 }
2529 }
2530 else {
2531
Forest Bond92b96792009-06-13 07:38:31 -04002532 if (pTransmitKey == NULL) {
2533 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
Andres Moree269fc22013-02-12 20:36:29 -05002534 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002535 dev_kfree_skb_irq(skb);
2536 pStats->tx_dropped++;
2537 return STATUS_FAILURE;
2538 }
Forest Bond92b96792009-06-13 07:38:31 -04002539 }
2540 }
2541
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002542 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2543
Forest Bond92b96792009-06-13 07:38:31 -04002544 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002545 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002546 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
Andres Moreb902fbf2013-02-25 20:32:51 -05002547 (u8 *)skb->data, pTransmitKey, uNodeIndex,
Forest Bond92b96792009-06-13 07:38:31 -04002548 pDevice->wCurrentRate,
2549 &uHeaderLen, &BytesToWrite
2550 );
2551
Andres Moree269fc22013-02-12 20:36:29 -05002552 if (fConvertedPacket == false) {
2553 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002554 dev_kfree_skb_irq(skb);
2555 return STATUS_FAILURE;
2556 }
2557
Andres More4e9b5e22013-02-12 20:36:30 -05002558 if ( pDevice->bEnablePSMode == true ) {
Forest Bond92b96792009-06-13 07:38:31 -04002559 if ( !pDevice->bPSModeTxBurst ) {
Andres More0cbd8d92010-05-06 20:34:29 -03002560 bScheduleCommand((void *) pDevice,
2561 WLAN_CMD_MAC_DISPOWERSAVING,
2562 NULL);
Andres More4e9b5e22013-02-12 20:36:30 -05002563 pDevice->bPSModeTxBurst = true;
Forest Bond92b96792009-06-13 07:38:31 -04002564 }
2565 }
2566
Andres Moreb902fbf2013-02-25 20:32:51 -05002567 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002568 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002569
2570 pContext->pPacket = skb;
2571 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002572 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002573
Andres Moreceb8c5d2013-03-18 20:33:49 -05002574 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 -04002575
2576 status = PIPEnsSendBulkOut(pDevice,pContext);
2577
Andres More4e9b5e22013-02-12 20:36:30 -05002578 if (bNeedDeAuth == true) {
Andres More3eaca0d2013-02-25 20:32:52 -05002579 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
Forest Bond92b96792009-06-13 07:38:31 -04002580
Andres Moreb902fbf2013-02-25 20:32:51 -05002581 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
Forest Bond92b96792009-06-13 07:38:31 -04002582 }
2583
2584 if(status!=STATUS_PENDING) {
Andres Moree269fc22013-02-12 20:36:29 -05002585 pContext->bBoolInUse = false;
Forest Bond92b96792009-06-13 07:38:31 -04002586 dev_kfree_skb_irq(skb);
2587 return STATUS_FAILURE;
2588 }
2589 else
2590 return 0;
2591
2592}
2593
Forest Bond92b96792009-06-13 07:38:31 -04002594/*
2595 * Description:
2596 * Relay packet send (AC1DMA) from rx dpc.
2597 *
2598 * Parameters:
2599 * In:
2600 * pDevice - Pointer to the adapter
2601 * pPacket - Pointer to rx packet
2602 * cbPacketSize - rx ethernet frame size
2603 * Out:
Andres Moree269fc22013-02-12 20:36:29 -05002604 * TURE, false
Forest Bond92b96792009-06-13 07:38:31 -04002605 *
Andres More4e9b5e22013-02-12 20:36:30 -05002606 * Return Value: Return true if packet is copy to dma1; otherwise false
Forest Bond92b96792009-06-13 07:38:31 -04002607 */
2608
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002609int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2610 u32 uNodeIndex)
Forest Bond92b96792009-06-13 07:38:31 -04002611{
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002612 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
Malcolm Priestleyf39c0d82013-08-15 19:34:37 +01002613 struct vnt_tx_buffer *pTX_Buffer;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002614 u32 BytesToWrite = 0, uHeaderLen = 0;
2615 u8 byPktType = PK_TYPE_11B;
Andres Moree269fc22013-02-12 20:36:29 -05002616 int bNeedEncryption = false;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002617 SKeyItem STempKey;
2618 PSKeyItem pTransmitKey = NULL;
2619 u8 *pbyBSSID;
2620 PUSB_SEND_CONTEXT pContext;
2621 u8 byPktTyp;
2622 int fConvertedPacket;
Malcolm Priestleyd56131d2013-01-17 23:15:22 +00002623 u32 status;
2624 u16 wKeepRate = pDevice->wCurrentRate;
Forest Bond92b96792009-06-13 07:38:31 -04002625
Forest Bond92b96792009-06-13 07:38:31 -04002626 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2627
2628 if (NULL == pContext) {
Andres Moree269fc22013-02-12 20:36:29 -05002629 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002630 }
2631
Andres Moreceb8c5d2013-03-18 20:33:49 -05002632 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
Forest Bond92b96792009-06-13 07:38:31 -04002633
Andres More4e9b5e22013-02-12 20:36:30 -05002634 if (pDevice->bEncryptionEnable == true) {
2635 bNeedEncryption = true;
Forest Bond92b96792009-06-13 07:38:31 -04002636 // get group key
2637 pbyBSSID = pDevice->abyBroadcastAddr;
Andres Moree269fc22013-02-12 20:36:29 -05002638 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond92b96792009-06-13 07:38:31 -04002639 pTransmitKey = NULL;
2640 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2641 } else {
2642 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2643 }
2644 }
2645
2646 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +02002647 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond92b96792009-06-13 07:38:31 -04002648 pTransmitKey = &STempKey;
2649 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2650 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2651 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2652 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2653 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2654 memcpy(pTransmitKey->abyKey,
2655 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2656 pTransmitKey->uKeyLength
2657 );
2658 }
2659 }
2660
2661 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
Andres Moree269fc22013-02-12 20:36:29 -05002662 pContext->bBoolInUse = false;
2663 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002664 }
2665
Andres Moreb902fbf2013-02-25 20:32:51 -05002666 byPktTyp = (u8)pDevice->byPacketType;
Forest Bond92b96792009-06-13 07:38:31 -04002667
2668 if (pDevice->bFixRate) {
2669 if (pDevice->byBBType == BB_TYPE_11B) {
2670 if (pDevice->uConnectionRate >= RATE_11M) {
2671 pDevice->wCurrentRate = RATE_11M;
2672 } else {
Andres More3eaca0d2013-02-25 20:32:52 -05002673 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002674 }
2675 } else {
2676 if ((pDevice->byBBType == BB_TYPE_11A) &&
2677 (pDevice->uConnectionRate <= RATE_6M)) {
2678 pDevice->wCurrentRate = RATE_6M;
2679 } else {
2680 if (pDevice->uConnectionRate >= RATE_54M)
2681 pDevice->wCurrentRate = RATE_54M;
2682 else
Andres More3eaca0d2013-02-25 20:32:52 -05002683 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
Forest Bond92b96792009-06-13 07:38:31 -04002684 }
2685 }
2686 }
2687 else {
2688 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2689 }
2690
Forest Bond92b96792009-06-13 07:38:31 -04002691 if (wKeepRate != pDevice->wCurrentRate) {
Andres More0cbd8d92010-05-06 20:34:29 -03002692 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
Forest Bond92b96792009-06-13 07:38:31 -04002693 }
2694
2695 if (pDevice->wCurrentRate <= RATE_11M)
2696 byPktType = PK_TYPE_11B;
2697
Andres Moreabad19d2010-07-12 16:28:32 -03002698 BytesToWrite = uDataLen + ETH_FCS_LEN;
2699
Forest Bond92b96792009-06-13 07:38:31 -04002700 // Convert the packet to an usb frame and copy into our buffer
2701 // and send the irp.
2702
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002703 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2704
Forest Bond92b96792009-06-13 07:38:31 -04002705 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
Malcolm Priestleyd0a2b8f2013-08-15 19:37:04 +01002706 pTX_Buffer, bNeedEncryption,
Forest Bond92b96792009-06-13 07:38:31 -04002707 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2708 pbySkbData, pTransmitKey, uNodeIndex,
2709 pDevice->wCurrentRate,
2710 &uHeaderLen, &BytesToWrite
2711 );
2712
Andres Moree269fc22013-02-12 20:36:29 -05002713 if (fConvertedPacket == false) {
2714 pContext->bBoolInUse = false;
2715 return false;
Forest Bond92b96792009-06-13 07:38:31 -04002716 }
2717
Andres Moreb902fbf2013-02-25 20:32:51 -05002718 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
Andres More3eaca0d2013-02-25 20:32:52 -05002719 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
Forest Bond92b96792009-06-13 07:38:31 -04002720
2721 pContext->pPacket = NULL;
2722 pContext->Type = CONTEXT_DATA_PACKET;
Andres More3eaca0d2013-02-25 20:32:52 -05002723 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
Forest Bond92b96792009-06-13 07:38:31 -04002724
Andres Moreceb8c5d2013-03-18 20:33:49 -05002725 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 -04002726
2727 status = PIPEnsSendBulkOut(pDevice,pContext);
2728
Andres More4e9b5e22013-02-12 20:36:30 -05002729 return true;
Forest Bond92b96792009-06-13 07:38:31 -04002730}
2731